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

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

Issue 1397423004: Improve shaping segmentation for grapheme cluster based font fallback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge TestExpectations with the HarfBuzz rebaselines Created 5 years, 1 month 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 { 105 {
106 HarfBuzzFaceCache::iterator result = harfBuzzFaceCache()->find(m_uniqueID); 106 HarfBuzzFaceCache::iterator result = harfBuzzFaceCache()->find(m_uniqueID);
107 ASSERT_WITH_SECURITY_IMPLICATION(result != harfBuzzFaceCache()->end()); 107 ASSERT_WITH_SECURITY_IMPLICATION(result != harfBuzzFaceCache()->end());
108 ASSERT(result.get()->value->refCount() > 1); 108 ASSERT(result.get()->value->refCount() > 1);
109 result.get()->value->deref(); 109 result.get()->value->deref();
110 if (result.get()->value->refCount() == 1) 110 if (result.get()->value->refCount() == 1)
111 harfBuzzFaceCache()->remove(m_uniqueID); 111 harfBuzzFaceCache()->remove(m_uniqueID);
112 } 112 }
113 113
114 struct HarfBuzzFontData { 114 struct HarfBuzzFontData {
115 HarfBuzzFontData(WTF::HashMap<uint32_t, uint16_t>* glyphCacheForFaceCacheEnt ry, hb_face_t* face) 115 HarfBuzzFontData(WTF::HashMap<uint32_t, uint16_t>* glyphCacheForFaceCacheEnt ry, hb_face_t* face, unsigned rangeFrom, unsigned rangeTo)
116 : m_glyphCacheForFaceCacheEntry(glyphCacheForFaceCacheEntry) 116 : m_glyphCacheForFaceCacheEntry(glyphCacheForFaceCacheEntry)
117 , m_face(face) 117 , m_face(face)
118 , m_hbOpenTypeFont(nullptr) 118 , m_hbOpenTypeFont(nullptr)
119 , m_rangeFrom(rangeFrom)
120 , m_rangeTo(rangeTo)
119 { } 121 { }
120 122
121 ~HarfBuzzFontData() 123 ~HarfBuzzFontData()
122 { 124 {
123 if (m_hbOpenTypeFont) 125 if (m_hbOpenTypeFont)
124 hb_font_destroy(m_hbOpenTypeFont); 126 hb_font_destroy(m_hbOpenTypeFont);
125 } 127 }
126 128
127 SkPaint m_paint; 129 SkPaint m_paint;
128 RefPtr<SimpleFontData> m_simpleFontData; 130 RefPtr<SimpleFontData> m_simpleFontData;
129 WTF::HashMap<uint32_t, uint16_t>* m_glyphCacheForFaceCacheEntry; 131 WTF::HashMap<uint32_t, uint16_t>* m_glyphCacheForFaceCacheEntry;
130 hb_face_t* m_face; 132 hb_face_t* m_face;
131 hb_font_t* m_hbOpenTypeFont; 133 hb_font_t* m_hbOpenTypeFont;
134 unsigned m_rangeFrom;
135 unsigned m_rangeTo;
132 }; 136 };
133 137
134 static hb_position_t SkiaScalarToHarfBuzzPosition(SkScalar value) 138 static hb_position_t SkiaScalarToHarfBuzzPosition(SkScalar value)
135 { 139 {
136 return SkScalarToFixed(value); 140 return SkScalarToFixed(value);
137 } 141 }
138 142
139 static void SkiaGetGlyphWidthAndExtents(SkPaint* paint, hb_codepoint_t codepoint , hb_position_t* width, hb_glyph_extents_t* extents) 143 static void SkiaGetGlyphWidthAndExtents(SkPaint* paint, hb_codepoint_t codepoint , hb_position_t* width, hb_glyph_extents_t* extents)
140 { 144 {
141 ASSERT(codepoint <= 0xFFFF); 145 ASSERT(codepoint <= 0xFFFF);
(...skipping 26 matching lines...) Expand all
168 } 172 }
169 173
170 #if !defined(HB_VERSION_ATLEAST) 174 #if !defined(HB_VERSION_ATLEAST)
171 #define HB_VERSION_ATLEAST(major, minor, micro) 0 175 #define HB_VERSION_ATLEAST(major, minor, micro) 0
172 #endif 176 #endif
173 177
174 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) 178 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)
175 { 179 {
176 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData) ; 180 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData) ;
177 181
182 RELEASE_ASSERT(hbFontData);
183 if (unicode < hbFontData->m_rangeFrom || unicode > hbFontData->m_rangeTo)
184 return false;
185
178 if (variationSelector) { 186 if (variationSelector) {
179 #if !HB_VERSION_ATLEAST(0, 9, 28) 187 #if !HB_VERSION_ATLEAST(0, 9, 28)
180 return false; 188 return false;
181 #else 189 #else
182 // Skia does not support variation selectors, but hb does. 190 // Skia does not support variation selectors, but hb does.
183 // We're not fully ready to switch to hb-ot-font yet, 191 // We're not fully ready to switch to hb-ot-font yet,
184 // but are good enough to get glyph IDs for OpenType fonts. 192 // but are good enough to get glyph IDs for OpenType fonts.
185 if (!hbFontData->m_hbOpenTypeFont) { 193 if (!hbFontData->m_hbOpenTypeFont) {
186 hbFontData->m_hbOpenTypeFont = hb_font_create(hbFontData->m_face); 194 hbFontData->m_hbOpenTypeFont = hb_font_create(hbFontData->m_face);
187 hb_ot_font_set_funcs(hbFontData->m_hbOpenTypeFont); 195 hb_ot_font_set_funcs(hbFontData->m_hbOpenTypeFont);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 { 339 {
332 #if OS(MACOSX) 340 #if OS(MACOSX)
333 hb_face_t* face = hb_coretext_face_create(m_platformData->cgFont()); 341 hb_face_t* face = hb_coretext_face_create(m_platformData->cgFont());
334 #else 342 #else
335 hb_face_t* face = hb_face_create_for_tables(harfBuzzSkiaGetTable, m_platform Data->typeface(), 0); 343 hb_face_t* face = hb_face_create_for_tables(harfBuzzSkiaGetTable, m_platform Data->typeface(), 0);
336 #endif 344 #endif
337 ASSERT(face); 345 ASSERT(face);
338 return face; 346 return face;
339 } 347 }
340 348
341 hb_font_t* HarfBuzzFace::createFont() const 349 hb_font_t* HarfBuzzFace::createFont(unsigned rangeFrom, unsigned rangeTo) const
342 { 350 {
343 HarfBuzzFontData* hbFontData = new HarfBuzzFontData(m_glyphCacheForFaceCache Entry, m_face); 351 HarfBuzzFontData* hbFontData = new HarfBuzzFontData(m_glyphCacheForFaceCache Entry, m_face, rangeFrom, rangeTo);
344 m_platformData->setupPaint(&hbFontData->m_paint); 352 m_platformData->setupPaint(&hbFontData->m_paint);
345 hbFontData->m_simpleFontData = FontCache::fontCache()->fontDataFromFontPlatf ormData(m_platformData); 353 hbFontData->m_simpleFontData = FontCache::fontCache()->fontDataFromFontPlatf ormData(m_platformData);
346 ASSERT(hbFontData->m_simpleFontData); 354 ASSERT(hbFontData->m_simpleFontData);
347 hb_font_t* font = hb_font_create(m_face); 355 hb_font_t* font = hb_font_create(m_face);
348 hb_font_set_funcs(font, harfBuzzSkiaGetFontFuncs(), hbFontData, destroyHarfB uzzFontData); 356 hb_font_set_funcs(font, harfBuzzSkiaGetFontFuncs(), hbFontData, destroyHarfB uzzFontData);
349 float size = m_platformData->size(); 357 float size = m_platformData->size();
350 int scale = SkiaScalarToHarfBuzzPosition(size); 358 int scale = SkiaScalarToHarfBuzzPosition(size);
351 hb_font_set_scale(font, scale, scale); 359 hb_font_set_scale(font, scale, scale);
352 hb_font_make_immutable(font); 360 hb_font_make_immutable(font);
353 return font; 361 return font;
354 } 362 }
355 363
356 } // namespace blink 364 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698