Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: ui/gfx/harfbuzz_font_skia.cc

Issue 2640983002: Rename paint data structures (Closed)
Patch Set: DrawingDisplayItem Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/color_utils_unittest.cc ('k') | ui/gfx/image/image_skia_operations.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/harfbuzz_font_skia.h" 5 #include "ui/gfx/harfbuzz_font_skia.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <limits> 10 #include <limits>
11 #include <map> 11 #include <map>
12 12
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "third_party/skia/include/core/SkPaint.h" 16 #include "cc/paint/paint_flags.h"
17 #include "third_party/skia/include/core/SkTypeface.h" 17 #include "third_party/skia/include/core/SkTypeface.h"
18 #include "ui/gfx/render_text.h" 18 #include "ui/gfx/render_text.h"
19 #include "ui/gfx/skia_util.h" 19 #include "ui/gfx/skia_util.h"
20 20
21 namespace gfx { 21 namespace gfx {
22 22
23 namespace { 23 namespace {
24 24
25 class HarfBuzzFace; 25 class HarfBuzzFace;
26 26
27 // Maps from code points to glyph indices in a font. 27 // Maps from code points to glyph indices in a font.
28 typedef std::map<uint32_t, uint16_t> GlyphCache; 28 typedef std::map<uint32_t, uint16_t> GlyphCache;
29 29
30 typedef std::pair<HarfBuzzFace, GlyphCache> FaceCache; 30 typedef std::pair<HarfBuzzFace, GlyphCache> FaceCache;
31 31
32 // Font data provider for HarfBuzz using Skia. Copied from Blink. 32 // Font data provider for HarfBuzz using Skia. Copied from Blink.
33 // TODO(ckocagil): Eliminate the duplication. http://crbug.com/368375 33 // TODO(ckocagil): Eliminate the duplication. http://crbug.com/368375
34 struct FontData { 34 struct FontData {
35 FontData(GlyphCache* glyph_cache) : glyph_cache_(glyph_cache) {} 35 FontData(GlyphCache* glyph_cache) : glyph_cache_(glyph_cache) {}
36 36
37 SkPaint paint_; 37 cc::PaintFlags paint_;
38 GlyphCache* glyph_cache_; 38 GlyphCache* glyph_cache_;
39 }; 39 };
40 40
41 // Deletes the object at the given pointer after casting it to the given type. 41 // Deletes the object at the given pointer after casting it to the given type.
42 template<typename Type> 42 template<typename Type>
43 void DeleteByType(void* data) { 43 void DeleteByType(void* data) {
44 Type* typed_data = reinterpret_cast<Type*>(data); 44 Type* typed_data = reinterpret_cast<Type*>(data);
45 delete typed_data; 45 delete typed_data;
46 } 46 }
47 47
48 template<typename Type> 48 template<typename Type>
49 void DeleteArrayByType(void* data) { 49 void DeleteArrayByType(void* data) {
50 Type* typed_data = reinterpret_cast<Type*>(data); 50 Type* typed_data = reinterpret_cast<Type*>(data);
51 delete[] typed_data; 51 delete[] typed_data;
52 } 52 }
53 53
54 // Outputs the |width| and |extents| of the glyph with index |codepoint| in 54 // Outputs the |width| and |extents| of the glyph with index |codepoint| in
55 // |paint|'s font. 55 // |paint|'s font.
56 void GetGlyphWidthAndExtents(SkPaint* paint, 56 void GetGlyphWidthAndExtents(cc::PaintFlags* paint,
57 hb_codepoint_t codepoint, 57 hb_codepoint_t codepoint,
58 hb_position_t* width, 58 hb_position_t* width,
59 hb_glyph_extents_t* extents) { 59 hb_glyph_extents_t* extents) {
60 DCHECK_LE(codepoint, std::numeric_limits<uint16_t>::max()); 60 DCHECK_LE(codepoint, std::numeric_limits<uint16_t>::max());
61 paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding); 61 paint->setTextEncoding(cc::PaintFlags::kGlyphID_TextEncoding);
62 62
63 SkScalar sk_width; 63 SkScalar sk_width;
64 SkRect sk_bounds; 64 SkRect sk_bounds;
65 uint16_t glyph = static_cast<uint16_t>(codepoint); 65 uint16_t glyph = static_cast<uint16_t>(codepoint);
66 66
67 paint->getTextWidths(&glyph, sizeof(glyph), &sk_width, &sk_bounds); 67 paint->getTextWidths(&glyph, sizeof(glyph), &sk_width, &sk_bounds);
68 if (width) 68 if (width)
69 *width = SkiaScalarToHarfBuzzUnits(sk_width); 69 *width = SkiaScalarToHarfBuzzUnits(sk_width);
70 if (extents) { 70 if (extents) {
71 // Invert y-axis because Skia is y-grows-down but we set up HarfBuzz to be 71 // Invert y-axis because Skia is y-grows-down but we set up HarfBuzz to be
(...skipping 11 matching lines...) Expand all
83 void* data, 83 void* data,
84 hb_codepoint_t unicode, 84 hb_codepoint_t unicode,
85 hb_codepoint_t variation_selector, 85 hb_codepoint_t variation_selector,
86 hb_codepoint_t* glyph, 86 hb_codepoint_t* glyph,
87 void* user_data) { 87 void* user_data) {
88 FontData* font_data = reinterpret_cast<FontData*>(data); 88 FontData* font_data = reinterpret_cast<FontData*>(data);
89 GlyphCache* cache = font_data->glyph_cache_; 89 GlyphCache* cache = font_data->glyph_cache_;
90 90
91 bool exists = cache->count(unicode) != 0; 91 bool exists = cache->count(unicode) != 0;
92 if (!exists) { 92 if (!exists) {
93 SkPaint* paint = &font_data->paint_; 93 cc::PaintFlags* paint = &font_data->paint_;
94 paint->setTextEncoding(SkPaint::kUTF32_TextEncoding); 94 paint->setTextEncoding(cc::PaintFlags::kUTF32_TextEncoding);
95 paint->textToGlyphs(&unicode, sizeof(hb_codepoint_t), &(*cache)[unicode]); 95 paint->textToGlyphs(&unicode, sizeof(hb_codepoint_t), &(*cache)[unicode]);
96 } 96 }
97 *glyph = (*cache)[unicode]; 97 *glyph = (*cache)[unicode];
98 return !!*glyph; 98 return !!*glyph;
99 } 99 }
100 100
101 // Returns the horizontal advance value of the |glyph|. 101 // Returns the horizontal advance value of the |glyph|.
102 hb_position_t GetGlyphHorizontalAdvance(hb_font_t* font, 102 hb_position_t GetGlyphHorizontalAdvance(hb_font_t* font,
103 void* data, 103 void* data,
104 hb_codepoint_t glyph, 104 hb_codepoint_t glyph,
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 // TODO(ckocagil): Do we need to update these params later? 280 // TODO(ckocagil): Do we need to update these params later?
281 internal::ApplyRenderParams(params, subpixel_rendering_suppressed, 281 internal::ApplyRenderParams(params, subpixel_rendering_suppressed,
282 &hb_font_data->paint_); 282 &hb_font_data->paint_);
283 hb_font_set_funcs(harfbuzz_font, g_font_funcs.Get().get(), hb_font_data, 283 hb_font_set_funcs(harfbuzz_font, g_font_funcs.Get().get(), hb_font_data,
284 DeleteByType<FontData>); 284 DeleteByType<FontData>);
285 hb_font_make_immutable(harfbuzz_font); 285 hb_font_make_immutable(harfbuzz_font);
286 return harfbuzz_font; 286 return harfbuzz_font;
287 } 287 }
288 288
289 } // namespace gfx 289 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/color_utils_unittest.cc ('k') | ui/gfx/image/image_skia_operations.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698