OLD | NEW |
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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } | 136 } |
137 | 137 |
138 void HarfBuzzFace::setScriptForVerticalGlyphSubstitution(hb_buffer_t* buffer) | 138 void HarfBuzzFace::setScriptForVerticalGlyphSubstitution(hb_buffer_t* buffer) |
139 { | 139 { |
140 if (m_scriptForVerticalText == HB_SCRIPT_INVALID) | 140 if (m_scriptForVerticalText == HB_SCRIPT_INVALID) |
141 m_scriptForVerticalText = findScriptForVerticalGlyphSubstitution(m_face)
; | 141 m_scriptForVerticalText = findScriptForVerticalGlyphSubstitution(m_face)
; |
142 hb_buffer_set_script(buffer, m_scriptForVerticalText); | 142 hb_buffer_set_script(buffer, m_scriptForVerticalText); |
143 } | 143 } |
144 | 144 |
145 struct HarfBuzzFontData { | 145 struct HarfBuzzFontData { |
146 HarfBuzzFontData(WTF::HashMap<uint32_t, uint16_t>* glyphCacheForFaceCacheEnt
ry, hb_face_t* face) | 146 HarfBuzzFontData(WTF::HashMap<uint32_t, uint16_t>* glyphCacheForFaceCacheEnt
ry) |
147 : m_glyphCacheForFaceCacheEntry(glyphCacheForFaceCacheEntry) | 147 : m_glyphCacheForFaceCacheEntry(glyphCacheForFaceCacheEntry) |
148 , m_face(face) | |
149 , m_hbOpenTypeFont(nullptr) | |
150 { } | 148 { } |
151 | |
152 ~HarfBuzzFontData() | |
153 { | |
154 if (m_hbOpenTypeFont) | |
155 hb_font_destroy(m_hbOpenTypeFont); | |
156 } | |
157 | |
158 SkPaint m_paint; | 149 SkPaint m_paint; |
159 RefPtr<SimpleFontData> m_simpleFontData; | 150 RefPtr<SimpleFontData> m_simpleFontData; |
160 WTF::HashMap<uint32_t, uint16_t>* m_glyphCacheForFaceCacheEntry; | 151 WTF::HashMap<uint32_t, uint16_t>* m_glyphCacheForFaceCacheEntry; |
161 hb_face_t* m_face; | |
162 hb_font_t* m_hbOpenTypeFont; | |
163 }; | 152 }; |
164 | 153 |
165 static hb_position_t SkiaScalarToHarfBuzzPosition(SkScalar value) | 154 static hb_position_t SkiaScalarToHarfBuzzPosition(SkScalar value) |
166 { | 155 { |
167 return SkScalarToFixed(value); | 156 return SkScalarToFixed(value); |
168 } | 157 } |
169 | 158 |
170 static void SkiaGetGlyphWidthAndExtents(SkPaint* paint, hb_codepoint_t codepoint
, hb_position_t* width, hb_glyph_extents_t* extents) | 159 static void SkiaGetGlyphWidthAndExtents(SkPaint* paint, hb_codepoint_t codepoint
, hb_position_t* width, hb_glyph_extents_t* extents) |
171 { | 160 { |
172 ASSERT(codepoint <= 0xFFFF); | 161 ASSERT(codepoint <= 0xFFFF); |
(...skipping 10 matching lines...) Expand all Loading... |
183 // Invert y-axis because Skia is y-grows-down but we set up HarfBuzz to
be y-grows-up. | 172 // Invert y-axis because Skia is y-grows-down but we set up HarfBuzz to
be y-grows-up. |
184 extents->x_bearing = SkiaScalarToHarfBuzzPosition(skBounds.fLeft); | 173 extents->x_bearing = SkiaScalarToHarfBuzzPosition(skBounds.fLeft); |
185 extents->y_bearing = SkiaScalarToHarfBuzzPosition(-skBounds.fTop); | 174 extents->y_bearing = SkiaScalarToHarfBuzzPosition(-skBounds.fTop); |
186 extents->width = SkiaScalarToHarfBuzzPosition(skBounds.width()); | 175 extents->width = SkiaScalarToHarfBuzzPosition(skBounds.width()); |
187 extents->height = SkiaScalarToHarfBuzzPosition(-skBounds.height()); | 176 extents->height = SkiaScalarToHarfBuzzPosition(-skBounds.height()); |
188 } | 177 } |
189 } | 178 } |
190 | 179 |
191 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) | 180 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) |
192 { | 181 { |
| 182 // Variation selectors not supported. |
| 183 if (variationSelector) |
| 184 return false; |
| 185 |
193 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData)
; | 186 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData)
; |
194 | 187 |
195 if (variationSelector) { | |
196 // Skia does not support variation selectors, but hb does. | |
197 // We're not fully ready to switch to hb-ot-font yet, | |
198 // but are good enough to get glyph IDs for OpenType fonts. | |
199 if (!hbFontData->m_hbOpenTypeFont) { | |
200 hbFontData->m_hbOpenTypeFont = hb_font_create(hbFontData->m_face); | |
201 hb_ot_font_set_funcs(hbFontData->m_hbOpenTypeFont); | |
202 } | |
203 return hb_font_get_glyph(hbFontData->m_hbOpenTypeFont, unicode, variatio
nSelector, glyph); | |
204 // When not found, glyph_func should return false rather than fallback t
o the base. | |
205 // http://lists.freedesktop.org/archives/harfbuzz/2015-May/004888.html | |
206 } | |
207 | |
208 WTF::HashMap<uint32_t, uint16_t>::AddResult result = hbFontData->m_glyphCach
eForFaceCacheEntry->add(unicode, 0); | 188 WTF::HashMap<uint32_t, uint16_t>::AddResult result = hbFontData->m_glyphCach
eForFaceCacheEntry->add(unicode, 0); |
209 if (result.isNewEntry) { | 189 if (result.isNewEntry) { |
210 SkPaint* paint = &hbFontData->m_paint; | 190 SkPaint* paint = &hbFontData->m_paint; |
211 paint->setTextEncoding(SkPaint::kUTF32_TextEncoding); | 191 paint->setTextEncoding(SkPaint::kUTF32_TextEncoding); |
212 uint16_t glyph16; | 192 uint16_t glyph16; |
213 paint->textToGlyphs(&unicode, sizeof(hb_codepoint_t), &glyph16); | 193 paint->textToGlyphs(&unicode, sizeof(hb_codepoint_t), &glyph16); |
214 result.storedValue->value = glyph16; | 194 result.storedValue->value = glyph16; |
215 *glyph = glyph16; | 195 *glyph = glyph16; |
216 } | 196 } |
217 *glyph = result.storedValue->value; | 197 *glyph = result.storedValue->value; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 hb_face_t* face = hb_coretext_face_create(m_platformData->cgFont()); | 326 hb_face_t* face = hb_coretext_face_create(m_platformData->cgFont()); |
347 #else | 327 #else |
348 hb_face_t* face = hb_face_create_for_tables(harfBuzzSkiaGetTable, m_platform
Data->typeface(), 0); | 328 hb_face_t* face = hb_face_create_for_tables(harfBuzzSkiaGetTable, m_platform
Data->typeface(), 0); |
349 #endif | 329 #endif |
350 ASSERT(face); | 330 ASSERT(face); |
351 return face; | 331 return face; |
352 } | 332 } |
353 | 333 |
354 hb_font_t* HarfBuzzFace::createFont() | 334 hb_font_t* HarfBuzzFace::createFont() |
355 { | 335 { |
356 HarfBuzzFontData* hbFontData = new HarfBuzzFontData(m_glyphCacheForFaceCache
Entry, m_face); | 336 HarfBuzzFontData* hbFontData = new HarfBuzzFontData(m_glyphCacheForFaceCache
Entry); |
357 m_platformData->setupPaint(&hbFontData->m_paint); | 337 m_platformData->setupPaint(&hbFontData->m_paint); |
358 hbFontData->m_simpleFontData = FontCache::fontCache()->fontDataFromFontPlatf
ormData(m_platformData); | 338 hbFontData->m_simpleFontData = FontCache::fontCache()->fontDataFromFontPlatf
ormData(m_platformData); |
359 ASSERT(hbFontData->m_simpleFontData); | 339 ASSERT(hbFontData->m_simpleFontData); |
360 hb_font_t* font = hb_font_create(m_face); | 340 hb_font_t* font = hb_font_create(m_face); |
361 hb_font_set_funcs(font, harfBuzzSkiaGetFontFuncs(), hbFontData, destroyHarfB
uzzFontData); | 341 hb_font_set_funcs(font, harfBuzzSkiaGetFontFuncs(), hbFontData, destroyHarfB
uzzFontData); |
362 float size = m_platformData->size(); | 342 float size = m_platformData->size(); |
363 int scale = SkiaScalarToHarfBuzzPosition(size); | 343 int scale = SkiaScalarToHarfBuzzPosition(size); |
364 hb_font_set_scale(font, scale, scale); | 344 hb_font_set_scale(font, scale, scale); |
365 hb_font_make_immutable(font); | 345 hb_font_make_immutable(font); |
366 return font; | 346 return font; |
367 } | 347 } |
368 | 348 |
369 } // namespace blink | 349 } // namespace blink |
OLD | NEW |