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