Changeset 239101 in webkit
- Timestamp:
- Dec 12, 2018 1:19:48 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 3 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r239100 r239101 1 2018-12-12 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [FreeType] Remove HarfBuzzFace 4 https://bugs.webkit.org/show_bug.cgi?id=192589 5 6 Reviewed by Michael Catanzaro. 7 8 Rebaseline test that now matches the firefox output. 9 10 * platform/gtk/mathml/opentype/opentype-stretchy-expected.png: 11 * platform/gtk/mathml/opentype/opentype-stretchy-expected.txt: 12 1 13 2018-12-12 Carlos Garcia Campos <cgarcia@igalia.com> 2 14 -
trunk/LayoutTests/platform/gtk/mathml/opentype/opentype-stretchy-expected.txt
r221675 r239101 1 1 layer at (0,0) size 800x600 2 2 RenderView at (0,0) size 800x600 3 layer at (0,0) size 800x3 394 RenderBlock {HTML} at (0,0) size 800x3 395 RenderBody {BODY} at (8,16) size 784x3 073 layer at (0,0) size 800x350 4 RenderBlock {HTML} at (0,0) size 800x350 5 RenderBody {BODY} at (8,16) size 784x318 6 6 RenderBlock {P} at (0,0) size 784x35 7 7 RenderMathMLMath {math} at (0,20) size 26x11 … … 36 36 text run at (0,-3) width 2: "\x{219F}" 37 37 RenderText {#text} at (0,0) size 0x0 38 RenderBlock {P} at (0,221) size 784x 8639 RenderMathMLMath {math} at (0,0) size 84x8240 RenderMathMLRow {mrow} at (0,0) size 84x8241 RenderMathMLOperator {mo} at (0,0) size 84x8238 RenderBlock {P} at (0,221) size 784x97 39 RenderMathMLMath {math} at (0,0) size 94x93 40 RenderMathMLRow {mrow} at (0,0) size 94x93 41 RenderMathMLOperator {mo} at (0,0) size 94x93 42 42 RenderBlock (anonymous) at (0,0) size 10x12 43 43 RenderText {#text} at (0,6) size 10x0 -
trunk/Source/WebCore/ChangeLog
r239100 r239101 1 2018-12-12 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [FreeType] Remove HarfBuzzFace 4 https://bugs.webkit.org/show_bug.cgi?id=192589 5 6 Reviewed by Michael Catanzaro. 7 8 This was used to share the common implementation with the chromium port, but now that only freetype based ports 9 use it, it can be removed and use hb_ft_face_create_cached() instead. We don't need the glyph cache either, 10 since we are already caching glyphs in Font. 11 12 * platform/FreeType.cmake: Remove HarfBuzzFaceCairo.cpp and HarfBuzzFace.cpp. 13 * platform/graphics/FontPlatformData.h: Remove HarfBuzzFace member. 14 * platform/graphics/freetype/FontCustomPlatformDataFreeType.cpp: Add missing include. 15 * platform/graphics/freetype/FontPlatformDataFreeType.cpp: 16 (WebCore::FontPlatformData::operator=): Remove m_harfBuzzFace handling. 17 (WebCore::FontPlatformData::createOpenTypeMathHarfBuzzFont const): New funtction to create a hb_font_t for 18 OpenType math. 19 * platform/graphics/harfbuzz/ComplexTextControllerHarfBuzz.cpp: 20 (WebCore::floatToHarfBuzzPosition): Moved from HarfBuzzFaceCairo.cpp. 21 (WebCore::doubleToHarfBuzzPosition): Ditto. 22 (WebCore::harfBuzzFontFunctions): Also moved from HarfBuzzFaceCairo.cpp, but implement get_nominal/variation 23 functions when using HarfBuzz >= 1.2.3 and use Font::glyphForCharacter() to make it simpler. 24 (WebCore::fontFeatures): Moved from HarfBuzzFaceCairo.cpp. 25 (WebCore::findScriptForVerticalGlyphSubstitution): Moved from HarfBuzzFace.cpp. 26 (WebCore::ComplexTextController::collectComplexTextRunsForCharacters): Create the HarfBuzz face and font here. 27 * platform/graphics/harfbuzz/HarfBuzzFace.cpp: Removed. 28 * platform/graphics/harfbuzz/HarfBuzzFace.h: Removed. 29 * platform/graphics/harfbuzz/HarfBuzzFaceCairo.cpp: Removed. 30 * platform/graphics/harfbuzz/HbUniquePtr.h: 31 (WebCore::HbPtrDeleter<hb_face_t>::operator() const): Add deleter for hb_face_t. 32 * platform/graphics/opentype/OpenTypeMathData.cpp: 33 (WebCore::OpenTypeMathData::OpenTypeMathData): Use FontPlatformData::createOpenTypeMathHarfBuzzFont(). 34 1 35 2018-12-12 Carlos Garcia Campos <cgarcia@igalia.com> 2 36 -
trunk/Source/WebCore/platform/FreeType.cmake
r237847 r239101 12 12 13 13 platform/graphics/harfbuzz/ComplexTextControllerHarfBuzz.cpp 14 platform/graphics/harfbuzz/HarfBuzzFace.cpp15 14 ) 16 15 … … 28 27 list(APPEND WebCore_SOURCES 29 28 platform/graphics/cairo/FontCairoHarfbuzzNG.cpp 30 31 platform/graphics/harfbuzz/HarfBuzzFaceCairo.cpp32 29 ) 33 30 endif () -
trunk/Source/WebCore/platform/graphics/FontPlatformData.h
r239100 r239101 41 41 #if USE(FREETYPE) 42 42 #include "FcUniquePtr.h" 43 #include "H arfBuzzFace.h"43 #include "HbUniquePtr.h" 44 44 #include "RefPtrFontconfig.h" 45 45 #include <memory> … … 169 169 170 170 #if USE(FREETYPE) 171 H arfBuzzFace& harfBuzzFace() const;171 HbUniquePtr<hb_font_t> createOpenTypeMathHarfBuzzFont() const; 172 172 bool hasCompatibleCharmap() const; 173 173 FcPattern* fcPattern() const; … … 250 250 #if USE(FREETYPE) 251 251 RefPtr<FcPattern> m_pattern; 252 mutable std::unique_ptr<HarfBuzzFace> m_harfBuzzFace;253 252 #endif 254 253 -
trunk/Source/WebCore/platform/graphics/freetype/FontCustomPlatformDataFreeType.cpp
r239100 r239101 32 32 #include <ft2build.h> 33 33 #include FT_MODULE_H 34 #include <mutex> 34 35 35 36 namespace WebCore { -
trunk/Source/WebCore/platform/graphics/freetype/FontPlatformDataFreeType.cpp
r239100 r239101 34 34 #include <ft2build.h> 35 35 #include FT_TRUETYPE_TABLES_H 36 #include <hb-ft.h> 37 #include <hb-ot.h> 36 38 #include <wtf/MathExtras.h> 37 39 #include <wtf/text/WTFString.h> … … 145 147 m_scaledFont = other.m_scaledFont; 146 148 147 // This will be re-created on demand.148 m_harfBuzzFace = nullptr;149 150 149 return *this; 151 150 } … … 183 182 copy.buildScaledFont(cairo_scaled_font_get_font_face(copy.m_scaledFont.get())); 184 183 return copy; 185 }186 187 HarfBuzzFace& FontPlatformData::harfBuzzFace() const188 {189 if (!m_harfBuzzFace)190 m_harfBuzzFace = std::make_unique<HarfBuzzFace>(const_cast<FontPlatformData&>(*this), hash());191 return *m_harfBuzzFace;192 184 } 193 185 … … 302 294 } 303 295 296 HbUniquePtr<hb_font_t> FontPlatformData::createOpenTypeMathHarfBuzzFont() const 297 { 298 CairoFtFaceLocker cairoFtFaceLocker(m_scaledFont.get()); 299 FT_Face ftFace = cairoFtFaceLocker.ftFace(); 300 if (!ftFace) 301 return nullptr; 302 303 HbUniquePtr<hb_face_t> face(hb_ft_face_create_cached(ftFace)); 304 if (!hb_ot_math_has_data(face.get())) 305 return nullptr; 306 307 return HbUniquePtr<hb_font_t>(hb_font_create(face.get())); 308 } 309 304 310 } // namespace WebCore -
trunk/Source/WebCore/platform/graphics/harfbuzz/ComplexTextControllerHarfBuzz.cpp
r236985 r239101 27 27 #include "ComplexTextController.h" 28 28 29 #include "CairoUtilities.h" 29 30 #include "FontCascade.h" 30 31 #include "HbUniquePtr.h" 31 32 #include "SurrogatePairAwareTextIterator.h" 33 #include <hb-ft.h> 32 34 #include <hb-icu.h> 33 35 36 #if ENABLE(VARIATION_FONTS) 37 #include FT_MULTIPLE_MASTERS_H 38 #endif 39 34 40 namespace WebCore { 35 41 … … 37 43 { 38 44 return static_cast<float>(value) / (1 << 16); 45 } 46 47 static inline hb_position_t floatToHarfBuzzPosition(float value) 48 { 49 return static_cast<hb_position_t>(value * (1 << 16)); 50 } 51 52 static inline hb_position_t doubleToHarfBuzzPosition(double value) 53 { 54 return static_cast<hb_position_t>(value * (1 << 16)); 55 } 56 57 static hb_font_funcs_t* harfBuzzFontFunctions() 58 { 59 static hb_font_funcs_t* fontFunctions = nullptr; 60 61 // We don't set callback functions which we can't support. 62 // Harfbuzz will use the fallback implementation if they aren't set. 63 if (!fontFunctions) { 64 fontFunctions = hb_font_funcs_create(); 65 #if HB_VERSION_ATLEAST(1, 2, 3) 66 hb_font_funcs_set_nominal_glyph_func(fontFunctions, [](hb_font_t*, void* context, hb_codepoint_t unicode, hb_codepoint_t* glyph, void*) -> hb_bool_t { 67 auto& font = *static_cast<Font*>(context); 68 *glyph = font.glyphForCharacter(unicode); 69 return !!*glyph; 70 }, nullptr, nullptr); 71 72 hb_font_funcs_set_variation_glyph_func(fontFunctions, [](hb_font_t*, void* context, hb_codepoint_t unicode, hb_codepoint_t variation, hb_codepoint_t* glyph, void*) -> hb_bool_t { 73 auto& font = *static_cast<Font*>(context); 74 auto* scaledFont = font.platformData().scaledFont(); 75 ASSERT(scaledFont); 76 77 CairoFtFaceLocker cairoFtFaceLocker(scaledFont); 78 if (FT_Face ftFace = cairoFtFaceLocker.ftFace()) { 79 *glyph = FT_Face_GetCharVariantIndex(ftFace, unicode, variation); 80 return true; 81 } 82 return false; 83 }, nullptr, nullptr); 84 #else 85 hb_font_funcs_set_glyph_func(fontFunctions, [](hb_font_t*, void* context, hb_codepoint_t unicode, hb_codepoint_t, hb_codepoint_t* glyph, void*) -> hb_bool_t { 86 auto& font = *static_cast<Font*>(context); 87 *glyph = font.glyphForCharacter(unicode); 88 return !!*glyph; 89 }, nullptr, nullptr); 90 #endif 91 hb_font_funcs_set_glyph_h_advance_func(fontFunctions, [](hb_font_t*, void* context, hb_codepoint_t point, void*) -> hb_bool_t { 92 auto& font = *static_cast<Font*>(context); 93 auto* scaledFont = font.platformData().scaledFont(); 94 ASSERT(scaledFont); 95 96 cairo_text_extents_t glyphExtents; 97 cairo_glyph_t glyph = { point, 0, 0 }; 98 cairo_scaled_font_glyph_extents(scaledFont, &glyph, 1, &glyphExtents); 99 100 bool hasVerticalGlyphs = glyphExtents.y_advance; 101 return doubleToHarfBuzzPosition(hasVerticalGlyphs ? -glyphExtents.y_advance : glyphExtents.x_advance); 102 }, nullptr, nullptr); 103 104 hb_font_funcs_set_glyph_h_origin_func(fontFunctions, [](hb_font_t*, void*, hb_codepoint_t, hb_position_t*, hb_position_t*, void*) -> hb_bool_t { 105 // Just return true, following the way that Harfbuzz-FreeType implementation does. 106 return true; 107 }, nullptr, nullptr); 108 109 hb_font_funcs_set_glyph_extents_func(fontFunctions, [](hb_font_t*, void* context, hb_codepoint_t point, hb_glyph_extents_t* extents, void*) -> hb_bool_t { 110 auto& font = *static_cast<Font*>(context); 111 auto* scaledFont = font.platformData().scaledFont(); 112 ASSERT(scaledFont); 113 114 cairo_text_extents_t glyphExtents; 115 cairo_glyph_t glyph = { point, 0, 0 }; 116 cairo_scaled_font_glyph_extents(scaledFont, &glyph, 1, &glyphExtents); 117 118 bool hasVerticalGlyphs = glyphExtents.y_advance; 119 extents->x_bearing = doubleToHarfBuzzPosition(glyphExtents.x_bearing); 120 extents->y_bearing = doubleToHarfBuzzPosition(hasVerticalGlyphs ? -glyphExtents.y_bearing : glyphExtents.y_bearing); 121 extents->width = doubleToHarfBuzzPosition(hasVerticalGlyphs ? -glyphExtents.height : glyphExtents.width); 122 extents->height = doubleToHarfBuzzPosition(hasVerticalGlyphs ? glyphExtents.width : glyphExtents.height); 123 return true; 124 }, nullptr, nullptr); 125 126 hb_font_funcs_make_immutable(fontFunctions); 127 } 128 return fontFunctions; 39 129 } 40 130 … … 84 174 } 85 175 86 static const unsigned hbEnd = static_cast<unsigned>(-1); 176 static const hb_tag_t s_vertTag = HB_TAG('v', 'e', 'r', 't'); 177 static const hb_tag_t s_vrt2Tag = HB_TAG('v', 'r', 't', '2'); 178 static const hb_tag_t s_kernTag = HB_TAG('k', 'e', 'r', 'n'); 179 static const unsigned s_hbEnd = static_cast<unsigned>(-1); 87 180 88 181 static Vector<hb_feature_t, 4> fontFeatures(const FontCascade& font, FontOrientation orientation) … … 91 184 92 185 if (orientation == FontOrientation::Vertical) { 93 features.append({ HarfBuzzFace::vertTag, 1, 0,hbEnd });94 features.append({ HarfBuzzFace::vrt2Tag, 1, 0,hbEnd });95 } 96 97 hb_feature_t kerning = { HarfBuzzFace::kernTag, 0, 0,hbEnd };186 features.append({ s_vertTag, 1, 0, s_hbEnd }); 187 features.append({ s_vrt2Tag, 1, 0, s_hbEnd }); 188 } 189 190 hb_feature_t kerning = { s_kernTag, 0, 0, s_hbEnd }; 98 191 if (font.enableKerning()) 99 192 kerning.value = 1; … … 102 195 for (auto& feature : font.fontDescription().featureSettings()) { 103 196 auto& tag = feature.tag(); 104 features.append({ HB_TAG(tag[0], tag[1], tag[2], tag[3]), static_cast<uint32_t>(feature.value()), 0, hbEnd });197 features.append({ HB_TAG(tag[0], tag[1], tag[2], tag[3]), static_cast<uint32_t>(feature.value()), 0, s_hbEnd }); 105 198 } 106 199 … … 169 262 } 170 263 264 static hb_script_t findScriptForVerticalGlyphSubstitution(hb_face_t* face) 265 { 266 static const unsigned maxCount = 32; 267 268 unsigned scriptCount = maxCount; 269 hb_tag_t scriptTags[maxCount]; 270 hb_ot_layout_table_get_script_tags(face, HB_OT_TAG_GSUB, 0, &scriptCount, scriptTags); 271 for (unsigned scriptIndex = 0; scriptIndex < scriptCount; ++scriptIndex) { 272 unsigned languageCount = maxCount; 273 hb_tag_t languageTags[maxCount]; 274 hb_ot_layout_script_get_language_tags(face, HB_OT_TAG_GSUB, scriptIndex, 0, &languageCount, languageTags); 275 for (unsigned languageIndex = 0; languageIndex < languageCount; ++languageIndex) { 276 unsigned featureIndex; 277 if (hb_ot_layout_language_find_feature(face, HB_OT_TAG_GSUB, scriptIndex, languageIndex, s_vertTag, &featureIndex) 278 || hb_ot_layout_language_find_feature(face, HB_OT_TAG_GSUB, scriptIndex, languageIndex, s_vrt2Tag, &featureIndex)) 279 return hb_ot_tag_to_script(scriptTags[scriptIndex]); 280 } 281 } 282 return HB_SCRIPT_INVALID; 283 } 284 171 285 void ComplexTextController::collectComplexTextRunsForCharacters(const UChar* characters, unsigned length, unsigned stringLocation, const Font* font) 172 286 { … … 192 306 193 307 const auto& fontPlatformData = font->platformData(); 308 auto* scaledFont = fontPlatformData.scaledFont(); 309 CairoFtFaceLocker cairoFtFaceLocker(scaledFont); 310 FT_Face ftFace = cairoFtFaceLocker.ftFace(); 311 if (!ftFace) 312 return; 313 314 HbUniquePtr<hb_face_t> face(hb_ft_face_create_cached(ftFace)); 315 HbUniquePtr<hb_font_t> harfBuzzFont(hb_font_create(face.get())); 316 hb_font_set_funcs(harfBuzzFont.get(), harfBuzzFontFunctions(), const_cast<Font*>(font), nullptr); 317 const float size = fontPlatformData.size(); 318 if (floorf(size) == size) 319 hb_font_set_ppem(harfBuzzFont.get(), size, size); 320 int scale = floatToHarfBuzzPosition(size); 321 hb_font_set_scale(harfBuzzFont.get(), scale, scale); 322 323 #if ENABLE(VARIATION_FONTS) 324 FT_MM_Var* ftMMVar; 325 if (!FT_Get_MM_Var(ftFace, &ftMMVar)) { 326 Vector<FT_Fixed, 4> coords; 327 coords.resize(ftMMVar->num_axis); 328 if (!FT_Get_Var_Design_Coordinates(ftFace, coords.size(), coords.data())) { 329 Vector<hb_variation_t, 4> variations(coords.size()); 330 for (FT_UInt i = 0; i < ftMMVar->num_axis; ++i) { 331 variations[i].tag = ftMMVar->axis[i].tag; 332 variations[i].value = coords[i] / 65536.0; 333 } 334 hb_font_set_variations(harfBuzzFont.get(), variations.data(), variations.size()); 335 } 336 FT_Done_MM_Var(ftFace->glyph->library, ftMMVar); 337 } 338 #endif 339 340 hb_font_make_immutable(harfBuzzFont.get()); 341 194 342 auto features = fontFeatures(m_font, fontPlatformData.orientation()); 195 343 HbUniquePtr<hb_buffer_t> buffer(hb_buffer_create()); 344 if (fontPlatformData.orientation() == FontOrientation::Vertical) 345 hb_buffer_set_script(buffer.get(), findScriptForVerticalGlyphSubstitution(face.get())); 196 346 197 347 for (unsigned i = 0; i < runCount; ++i) { 198 348 auto& run = runList[m_run.rtl() ? runCount - i - 1 : i]; 199 349 200 hb_buffer_set_script(buffer.get(), hb_icu_script_to_script(run.script)); 350 if (fontPlatformData.orientation() != FontOrientation::Vertical) 351 hb_buffer_set_script(buffer.get(), hb_icu_script_to_script(run.script)); 201 352 if (!m_mayUseNaturalWritingDirection || m_run.directionalOverride()) 202 353 hb_buffer_set_direction(buffer.get(), m_run.rtl() ? HB_DIRECTION_RTL : HB_DIRECTION_LTR); … … 207 358 hb_buffer_add_utf16(buffer.get(), reinterpret_cast<const uint16_t*>(characters), length, run.startIndex, run.endIndex - run.startIndex); 208 359 209 auto& face = fontPlatformData.harfBuzzFace();210 if (fontPlatformData.orientation() == FontOrientation::Vertical)211 face.setScriptForVerticalGlyphSubstitution(buffer.get());212 213 HbUniquePtr<hb_font_t> harfBuzzFont(face.createFont());214 360 hb_shape(harfBuzzFont.get(), buffer.get(), features.isEmpty() ? nullptr : features.data(), features.size()); 215 361 m_complexTextRuns.append(ComplexTextRun::create(buffer.get(), *font, characters, stringLocation, length, run.startIndex, run.endIndex)); -
trunk/Source/WebCore/platform/graphics/harfbuzz/HbUniquePtr.h
r222843 r239101 53 53 }; 54 54 55 template<> struct HbPtrDeleter<hb_face_t> { 56 void operator()(hb_face_t* ptr) const 57 { 58 hb_face_destroy(ptr); 59 } 60 }; 61 55 62 } // namespace WebCore 56 63 -
trunk/Source/WebCore/platform/graphics/opentype/OpenTypeMathData.cpp
r237394 r239101 35 35 #include "SharedBuffer.h" 36 36 37 38 37 namespace WebCore { 39 38 using namespace std; … … 258 257 #elif USE(HARFBUZZ) 259 258 OpenTypeMathData::OpenTypeMathData(const FontPlatformData& font) 260 : m_mathFont(font.harfBuzzFace().createFont()) 261 { 262 if (!hb_ot_math_has_data(hb_font_get_face(m_mathFont.get()))) 263 m_mathFont = nullptr; 259 : m_mathFont(font.createOpenTypeMathHarfBuzzFont()) 260 { 264 261 } 265 262 #elif USE(DIRECT2D) … … 297 294 return value * font.sizePerUnit(); 298 295 #elif USE(HARFBUZZ) 299 float OpenTypeMathData::getMathConstant(const Font& , MathConstant constant) const296 float OpenTypeMathData::getMathConstant(const Font& font, MathConstant constant) const 300 297 { 301 298 hb_position_t value = hb_ot_math_get_constant(m_mathFont.get(), static_cast<hb_ot_math_constant_t>(constant)); … … 303 300 return value / 100.0; 304 301 305 return value / 65536.0;302 return value * font.sizePerUnit(); 306 303 #else 307 304 float OpenTypeMathData::getMathConstant(const Font&, MathConstant) const … … 327 324 return mathItalicsCorrectionInfo->getItalicCorrection(*m_mathBuffer, glyph) * font.sizePerUnit(); 328 325 #elif USE(HARFBUZZ) 329 float OpenTypeMathData::getItalicCorrection(const Font& , Glyph glyph) const330 { 331 return hb_ot_math_get_glyph_italics_correction(m_mathFont.get(), glyph) / 65536.0;326 float OpenTypeMathData::getItalicCorrection(const Font& font, Glyph glyph) const 327 { 328 return hb_ot_math_get_glyph_italics_correction(m_mathFont.get(), glyph) * font.sizePerUnit(); 332 329 #else 333 330 float OpenTypeMathData::getItalicCorrection(const Font&, Glyph) const
Note: See TracChangeset
for help on using the changeset viewer.