Changeset 239157 in webkit
- Timestamp:
- Dec 13, 2018 1:43:46 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 3 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r239156 r239157 1 2018-12-13 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
r239122 r239157 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
r239156 r239157 1 2018-12-13 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
r239122 r239157 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
r239156 r239157 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
r239156 r239157 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
r239156 r239157 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 … … 305 297 } 306 298 299 HbUniquePtr<hb_font_t> FontPlatformData::createOpenTypeMathHarfBuzzFont() const 300 { 301 CairoFtFaceLocker cairoFtFaceLocker(m_scaledFont.get()); 302 FT_Face ftFace = cairoFtFaceLocker.ftFace(); 303 if (!ftFace) 304 return nullptr; 305 306 HbUniquePtr<hb_face_t> face(hb_ft_face_create_cached(ftFace)); 307 if (!hb_ot_math_has_data(face.get())) 308 return nullptr; 309 310 return HbUniquePtr<hb_font_t>(hb_font_create(face.get())); 311 } 312 307 313 } // namespace WebCore -
trunk/Source/WebCore/platform/graphics/harfbuzz/ComplexTextControllerHarfBuzz.cpp
r239122 r239157 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> 35 #include <hb-ot.h> 36 37 #if ENABLE(VARIATION_FONTS) 38 #include FT_MULTIPLE_MASTERS_H 39 #endif 33 40 34 41 namespace WebCore { … … 37 44 { 38 45 return static_cast<float>(value) / (1 << 16); 46 } 47 48 static inline hb_position_t floatToHarfBuzzPosition(float value) 49 { 50 return static_cast<hb_position_t>(value * (1 << 16)); 51 } 52 53 static inline hb_position_t doubleToHarfBuzzPosition(double value) 54 { 55 return static_cast<hb_position_t>(value * (1 << 16)); 56 } 57 58 static hb_font_funcs_t* harfBuzzFontFunctions() 59 { 60 static hb_font_funcs_t* fontFunctions = nullptr; 61 62 // We don't set callback functions which we can't support. 63 // Harfbuzz will use the fallback implementation if they aren't set. 64 if (!fontFunctions) { 65 fontFunctions = hb_font_funcs_create(); 66 #if HB_VERSION_ATLEAST(1, 2, 3) 67 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 { 68 auto& font = *static_cast<Font*>(context); 69 *glyph = font.glyphForCharacter(unicode); 70 return !!*glyph; 71 }, nullptr, nullptr); 72 73 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 { 74 auto& font = *static_cast<Font*>(context); 75 auto* scaledFont = font.platformData().scaledFont(); 76 ASSERT(scaledFont); 77 78 CairoFtFaceLocker cairoFtFaceLocker(scaledFont); 79 if (FT_Face ftFace = cairoFtFaceLocker.ftFace()) { 80 *glyph = FT_Face_GetCharVariantIndex(ftFace, unicode, variation); 81 return true; 82 } 83 return false; 84 }, nullptr, nullptr); 85 #else 86 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 { 87 auto& font = *static_cast<Font*>(context); 88 *glyph = font.glyphForCharacter(unicode); 89 return !!*glyph; 90 }, nullptr, nullptr); 91 #endif 92 hb_font_funcs_set_glyph_h_advance_func(fontFunctions, [](hb_font_t*, void* context, hb_codepoint_t point, void*) -> hb_bool_t { 93 auto& font = *static_cast<Font*>(context); 94 auto* scaledFont = font.platformData().scaledFont(); 95 ASSERT(scaledFont); 96 97 cairo_text_extents_t glyphExtents; 98 cairo_glyph_t glyph = { point, 0, 0 }; 99 cairo_scaled_font_glyph_extents(scaledFont, &glyph, 1, &glyphExtents); 100 101 bool hasVerticalGlyphs = glyphExtents.y_advance; 102 return doubleToHarfBuzzPosition(hasVerticalGlyphs ? -glyphExtents.y_advance : glyphExtents.x_advance); 103 }, nullptr, nullptr); 104 105 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 { 106 // Just return true, following the way that Harfbuzz-FreeType implementation does. 107 return true; 108 }, nullptr, nullptr); 109 110 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 { 111 auto& font = *static_cast<Font*>(context); 112 auto* scaledFont = font.platformData().scaledFont(); 113 ASSERT(scaledFont); 114 115 cairo_text_extents_t glyphExtents; 116 cairo_glyph_t glyph = { point, 0, 0 }; 117 cairo_scaled_font_glyph_extents(scaledFont, &glyph, 1, &glyphExtents); 118 119 bool hasVerticalGlyphs = glyphExtents.y_advance; 120 extents->x_bearing = doubleToHarfBuzzPosition(glyphExtents.x_bearing); 121 extents->y_bearing = doubleToHarfBuzzPosition(hasVerticalGlyphs ? -glyphExtents.y_bearing : glyphExtents.y_bearing); 122 extents->width = doubleToHarfBuzzPosition(hasVerticalGlyphs ? -glyphExtents.height : glyphExtents.width); 123 extents->height = doubleToHarfBuzzPosition(hasVerticalGlyphs ? glyphExtents.width : glyphExtents.height); 124 return true; 125 }, nullptr, nullptr); 126 127 hb_font_funcs_make_immutable(fontFunctions); 128 } 129 return fontFunctions; 39 130 } 40 131 … … 84 175 } 85 176 86 static const unsigned hbEnd = static_cast<unsigned>(-1); 177 static const hb_tag_t s_vertTag = HB_TAG('v', 'e', 'r', 't'); 178 static const hb_tag_t s_vrt2Tag = HB_TAG('v', 'r', 't', '2'); 179 static const hb_tag_t s_kernTag = HB_TAG('k', 'e', 'r', 'n'); 180 static const unsigned s_hbEnd = static_cast<unsigned>(-1); 87 181 88 182 static Vector<hb_feature_t, 4> fontFeatures(const FontCascade& font, FontOrientation orientation) … … 91 185 92 186 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 };187 features.append({ s_vertTag, 1, 0, s_hbEnd }); 188 features.append({ s_vrt2Tag, 1, 0, s_hbEnd }); 189 } 190 191 hb_feature_t kerning = { s_kernTag, 0, 0, s_hbEnd }; 98 192 if (font.enableKerning()) 99 193 kerning.value = 1; … … 102 196 for (auto& feature : font.fontDescription().featureSettings()) { 103 197 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 });198 features.append({ HB_TAG(tag[0], tag[1], tag[2], tag[3]), static_cast<uint32_t>(feature.value()), 0, s_hbEnd }); 105 199 } 106 200 … … 169 263 } 170 264 265 static hb_script_t findScriptForVerticalGlyphSubstitution(hb_face_t* face) 266 { 267 static const unsigned maxCount = 32; 268 269 unsigned scriptCount = maxCount; 270 hb_tag_t scriptTags[maxCount]; 271 hb_ot_layout_table_get_script_tags(face, HB_OT_TAG_GSUB, 0, &scriptCount, scriptTags); 272 for (unsigned scriptIndex = 0; scriptIndex < scriptCount; ++scriptIndex) { 273 unsigned languageCount = maxCount; 274 hb_tag_t languageTags[maxCount]; 275 hb_ot_layout_script_get_language_tags(face, HB_OT_TAG_GSUB, scriptIndex, 0, &languageCount, languageTags); 276 for (unsigned languageIndex = 0; languageIndex < languageCount; ++languageIndex) { 277 unsigned featureIndex; 278 if (hb_ot_layout_language_find_feature(face, HB_OT_TAG_GSUB, scriptIndex, languageIndex, s_vertTag, &featureIndex) 279 || hb_ot_layout_language_find_feature(face, HB_OT_TAG_GSUB, scriptIndex, languageIndex, s_vrt2Tag, &featureIndex)) 280 return hb_ot_tag_to_script(scriptTags[scriptIndex]); 281 } 282 } 283 return HB_SCRIPT_INVALID; 284 } 285 171 286 void ComplexTextController::collectComplexTextRunsForCharacters(const UChar* characters, unsigned length, unsigned stringLocation, const Font* font) 172 287 { … … 192 307 193 308 const auto& fontPlatformData = font->platformData(); 309 auto* scaledFont = fontPlatformData.scaledFont(); 310 CairoFtFaceLocker cairoFtFaceLocker(scaledFont); 311 FT_Face ftFace = cairoFtFaceLocker.ftFace(); 312 if (!ftFace) 313 return; 314 315 HbUniquePtr<hb_face_t> face(hb_ft_face_create_cached(ftFace)); 316 HbUniquePtr<hb_font_t> harfBuzzFont(hb_font_create(face.get())); 317 hb_font_set_funcs(harfBuzzFont.get(), harfBuzzFontFunctions(), const_cast<Font*>(font), nullptr); 318 const float size = fontPlatformData.size(); 319 if (floorf(size) == size) 320 hb_font_set_ppem(harfBuzzFont.get(), size, size); 321 int scale = floatToHarfBuzzPosition(size); 322 hb_font_set_scale(harfBuzzFont.get(), scale, scale); 323 324 #if ENABLE(VARIATION_FONTS) 325 FT_MM_Var* ftMMVar; 326 if (!FT_Get_MM_Var(ftFace, &ftMMVar)) { 327 Vector<FT_Fixed, 4> coords; 328 coords.resize(ftMMVar->num_axis); 329 if (!FT_Get_Var_Design_Coordinates(ftFace, coords.size(), coords.data())) { 330 Vector<hb_variation_t, 4> variations(coords.size()); 331 for (FT_UInt i = 0; i < ftMMVar->num_axis; ++i) { 332 variations[i].tag = ftMMVar->axis[i].tag; 333 variations[i].value = coords[i] / 65536.0; 334 } 335 hb_font_set_variations(harfBuzzFont.get(), variations.data(), variations.size()); 336 } 337 FT_Done_MM_Var(ftFace->glyph->library, ftMMVar); 338 } 339 #endif 340 341 hb_font_make_immutable(harfBuzzFont.get()); 342 194 343 auto features = fontFeatures(m_font, fontPlatformData.orientation()); 195 344 HbUniquePtr<hb_buffer_t> buffer(hb_buffer_create()); 345 if (fontPlatformData.orientation() == FontOrientation::Vertical) 346 hb_buffer_set_script(buffer.get(), findScriptForVerticalGlyphSubstitution(face.get())); 196 347 197 348 for (unsigned i = 0; i < runCount; ++i) { 198 349 auto& run = runList[m_run.rtl() ? runCount - i - 1 : i]; 199 350 200 hb_buffer_set_script(buffer.get(), hb_icu_script_to_script(run.script)); 351 if (fontPlatformData.orientation() != FontOrientation::Vertical) 352 hb_buffer_set_script(buffer.get(), hb_icu_script_to_script(run.script)); 201 353 if (!m_mayUseNaturalWritingDirection || m_run.directionalOverride()) 202 354 hb_buffer_set_direction(buffer.get(), m_run.rtl() ? HB_DIRECTION_RTL : HB_DIRECTION_LTR); … … 207 359 hb_buffer_add_utf16(buffer.get(), reinterpret_cast<const uint16_t*>(characters), length, run.startIndex, run.endIndex - run.startIndex); 208 360 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 361 hb_shape(harfBuzzFont.get(), buffer.get(), features.isEmpty() ? nullptr : features.data(), features.size()); 215 362 m_complexTextRuns.append(ComplexTextRun::create(buffer.get(), *font, characters, stringLocation, length, run.startIndex, run.endIndex)); -
trunk/Source/WebCore/platform/graphics/harfbuzz/HbUniquePtr.h
r239122 r239157 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
r239122 r239157 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.