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

Side by Side Diff: third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzFace.cpp

Issue 1806653002: Shape unicode-range: font faces in only one iteration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update UnicodeRangeSetTests to RefPtrtr, rm copy constructor and test Created 4 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 Google Inc. All rights reserved. 2 * Copyright (c) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 25 matching lines...) Expand all
36 #include "hb-coretext.h" 36 #include "hb-coretext.h"
37 #endif 37 #endif
38 #include "SkPaint.h" 38 #include "SkPaint.h"
39 #include "SkPath.h" 39 #include "SkPath.h"
40 #include "SkPoint.h" 40 #include "SkPoint.h"
41 #include "SkRect.h" 41 #include "SkRect.h"
42 #include "SkTypeface.h" 42 #include "SkTypeface.h"
43 #include "platform/fonts/FontCache.h" 43 #include "platform/fonts/FontCache.h"
44 #include "platform/fonts/FontPlatformData.h" 44 #include "platform/fonts/FontPlatformData.h"
45 #include "platform/fonts/SimpleFontData.h" 45 #include "platform/fonts/SimpleFontData.h"
46 #include "platform/fonts/UnicodeRangeSet.h"
46 #include "platform/fonts/shaping/HarfBuzzShaper.h" 47 #include "platform/fonts/shaping/HarfBuzzShaper.h"
47 #include "wtf/HashMap.h" 48 #include "wtf/HashMap.h"
48 #include "wtf/MathExtras.h" 49 #include "wtf/MathExtras.h"
49 50
50 namespace blink { 51 namespace blink {
51 52
52 const hb_tag_t HarfBuzzFace::vertTag = HB_TAG('v', 'e', 'r', 't'); 53 const hb_tag_t HarfBuzzFace::vertTag = HB_TAG('v', 'e', 'r', 't');
53 54
54 // Though we have FontCache class, which provides the cache mechanism for 55 // Though we have FontCache class, which provides the cache mechanism for
55 // WebKit's font objects, we also need additional caching layer for HarfBuzz 56 // WebKit's font objects, we also need additional caching layer for HarfBuzz
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 ASSERT(result.get()->value->refCount() > 1); 108 ASSERT(result.get()->value->refCount() > 1);
108 result.get()->value->deref(); 109 result.get()->value->deref();
109 if (result.get()->value->refCount() == 1) 110 if (result.get()->value->refCount() == 1)
110 harfBuzzFaceCache()->remove(m_uniqueID); 111 harfBuzzFaceCache()->remove(m_uniqueID);
111 } 112 }
112 113
113 struct HarfBuzzFontData { 114 struct HarfBuzzFontData {
114 USING_FAST_MALLOC(HarfBuzzFontData); 115 USING_FAST_MALLOC(HarfBuzzFontData);
115 WTF_MAKE_NONCOPYABLE(HarfBuzzFontData); 116 WTF_MAKE_NONCOPYABLE(HarfBuzzFontData);
116 public: 117 public:
117 HarfBuzzFontData(WTF::HashMap<uint32_t, uint16_t>* glyphCacheForFaceCacheEnt ry, hb_face_t* face, unsigned rangeFrom, unsigned rangeTo) 118 HarfBuzzFontData(WTF::HashMap<uint32_t, uint16_t>* glyphCacheForFaceCacheEnt ry, hb_face_t* face, PassRefPtr<UnicodeRangeSet> rangeSet)
118 : m_glyphCacheForFaceCacheEntry(glyphCacheForFaceCacheEntry) 119 : m_glyphCacheForFaceCacheEntry(glyphCacheForFaceCacheEntry)
119 , m_face(face) 120 , m_face(face)
120 , m_hbOpenTypeFont(nullptr) 121 , m_hbOpenTypeFont(nullptr)
121 , m_rangeFrom(rangeFrom) 122 , m_rangeSet(rangeSet)
122 , m_rangeTo(rangeTo) 123 {
123 { } 124 }
124 125
125 ~HarfBuzzFontData() 126 ~HarfBuzzFontData()
126 { 127 {
127 if (m_hbOpenTypeFont) 128 if (m_hbOpenTypeFont)
128 hb_font_destroy(m_hbOpenTypeFont); 129 hb_font_destroy(m_hbOpenTypeFont);
129 } 130 }
130 131
131 SkPaint m_paint; 132 SkPaint m_paint;
132 RefPtr<SimpleFontData> m_simpleFontData; 133 RefPtr<SimpleFontData> m_simpleFontData;
133 WTF::HashMap<uint32_t, uint16_t>* m_glyphCacheForFaceCacheEntry; 134 WTF::HashMap<uint32_t, uint16_t>* m_glyphCacheForFaceCacheEntry;
134 hb_face_t* m_face; 135 hb_face_t* m_face;
135 hb_font_t* m_hbOpenTypeFont; 136 hb_font_t* m_hbOpenTypeFont;
136 unsigned m_rangeFrom; 137 RefPtr<UnicodeRangeSet> m_rangeSet;
137 unsigned m_rangeTo;
138 }; 138 };
139 139
140 static hb_position_t SkiaScalarToHarfBuzzPosition(SkScalar value) 140 static hb_position_t SkiaScalarToHarfBuzzPosition(SkScalar value)
141 { 141 {
142 // We treat HarfBuzz hb_position_t as 16.16 fixed-point. 142 // We treat HarfBuzz hb_position_t as 16.16 fixed-point.
143 static const int kHbPosition1 = 1 << 16; 143 static const int kHbPosition1 = 1 << 16;
144 return clampTo<int>(value * kHbPosition1); 144 return clampTo<int>(value * kHbPosition1);
145 } 145 }
146 146
147 static void SkiaGetGlyphWidthAndExtents(SkPaint* paint, hb_codepoint_t codepoint , hb_position_t* width, hb_glyph_extents_t* extents) 147 static void SkiaGetGlyphWidthAndExtents(SkPaint* paint, hb_codepoint_t codepoint , hb_position_t* width, hb_glyph_extents_t* extents)
(...skipping 29 matching lines...) Expand all
177 177
178 #if !defined(HB_VERSION_ATLEAST) 178 #if !defined(HB_VERSION_ATLEAST)
179 #define HB_VERSION_ATLEAST(major, minor, micro) 0 179 #define HB_VERSION_ATLEAST(major, minor, micro) 0
180 #endif 180 #endif
181 181
182 static hb_bool_t harfBuzzGetGlyph(hb_font_t* hbFont, void* fontData, hb_codepoin t_t unicode, hb_codepoint_t variationSelector, hb_codepoint_t* glyph, void* user Data) 182 static hb_bool_t harfBuzzGetGlyph(hb_font_t* hbFont, void* fontData, hb_codepoin t_t unicode, hb_codepoint_t variationSelector, hb_codepoint_t* glyph, void* user Data)
183 { 183 {
184 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData) ; 184 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData) ;
185 185
186 RELEASE_ASSERT(hbFontData); 186 RELEASE_ASSERT(hbFontData);
187 if (unicode < hbFontData->m_rangeFrom || unicode > hbFontData->m_rangeTo) 187 if (hbFontData->m_rangeSet && !hbFontData->m_rangeSet->contains(unicode))
188 return false; 188 return false;
189 189
190 if (variationSelector) { 190 if (variationSelector) {
191 #if !HB_VERSION_ATLEAST(0, 9, 28) 191 #if !HB_VERSION_ATLEAST(0, 9, 28)
192 return false; 192 return false;
193 #else 193 #else
194 // Skia does not support variation selectors, but hb does. 194 // Skia does not support variation selectors, but hb does.
195 // We're not fully ready to switch to hb-ot-font yet, 195 // We're not fully ready to switch to hb-ot-font yet,
196 // but are good enough to get glyph IDs for OpenType fonts. 196 // but are good enough to get glyph IDs for OpenType fonts.
197 if (!hbFontData->m_hbOpenTypeFont) { 197 if (!hbFontData->m_hbOpenTypeFont) {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 { 343 {
344 #if OS(MACOSX) 344 #if OS(MACOSX)
345 hb_face_t* face = hb_coretext_face_create(m_platformData->cgFont()); 345 hb_face_t* face = hb_coretext_face_create(m_platformData->cgFont());
346 #else 346 #else
347 hb_face_t* face = hb_face_create_for_tables(harfBuzzSkiaGetTable, m_platform Data->typeface(), 0); 347 hb_face_t* face = hb_face_create_for_tables(harfBuzzSkiaGetTable, m_platform Data->typeface(), 0);
348 #endif 348 #endif
349 ASSERT(face); 349 ASSERT(face);
350 return face; 350 return face;
351 } 351 }
352 352
353 hb_font_t* HarfBuzzFace::createFont(unsigned rangeFrom, unsigned rangeTo) const 353 hb_font_t* HarfBuzzFace::createFont(PassRefPtr<UnicodeRangeSet> rangeSet) const
354 { 354 {
355 HarfBuzzFontData* hbFontData = new HarfBuzzFontData(m_glyphCacheForFaceCache Entry, m_face, rangeFrom, rangeTo); 355 HarfBuzzFontData* hbFontData = new HarfBuzzFontData(m_glyphCacheForFaceCache Entry, m_face, rangeSet);
356 m_platformData->setupPaint(&hbFontData->m_paint); 356 m_platformData->setupPaint(&hbFontData->m_paint);
357 hbFontData->m_simpleFontData = FontCache::fontCache()->fontDataFromFontPlatf ormData(m_platformData); 357 hbFontData->m_simpleFontData = FontCache::fontCache()->fontDataFromFontPlatf ormData(m_platformData);
358 ASSERT(hbFontData->m_simpleFontData); 358 ASSERT(hbFontData->m_simpleFontData);
359 hb_font_t* font = hb_font_create(m_face); 359 hb_font_t* font = hb_font_create(m_face);
360 hb_font_set_funcs(font, harfBuzzSkiaGetFontFuncs(), hbFontData, destroyHarfB uzzFontData); 360 hb_font_set_funcs(font, harfBuzzSkiaGetFontFuncs(), hbFontData, destroyHarfB uzzFontData);
361 float size = m_platformData->size(); 361 float size = m_platformData->size();
362 int scale = SkiaScalarToHarfBuzzPosition(size); 362 int scale = SkiaScalarToHarfBuzzPosition(size);
363 hb_font_set_scale(font, scale, scale); 363 hb_font_set_scale(font, scale, scale);
364 hb_font_make_immutable(font); 364 hb_font_make_immutable(font);
365 return font; 365 return font;
366 } 366 }
367 367
368 } // namespace blink 368 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698