Changeset 200094 in webkit
- Timestamp:
- Apr 26, 2016 10:20:29 AM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r200093 r200094 1 2016-04-26 Myles C. Maxfield <mmaxfield@apple.com> 2 3 Make FontPlatformData immutable 4 https://bugs.webkit.org/show_bug.cgi?id=157024 5 6 Reviewed by Darin Adler. 7 8 This patch deletes all functions which modify a FontPlatformData once 9 it has been created. This makes for a cleaner design. 10 11 No new tests because there is no behavior change. 12 13 * platform/graphics/Font.cpp: 14 (WebCore::Font::verticalRightOrientationFont): 15 (WebCore::Font::nonSyntheticItalicFont): 16 * platform/graphics/FontPlatformData.cpp: 17 (WebCore::FontPlatformData::FontPlatformData): 18 (WebCore::FontPlatformData::cloneWithOrientation): 19 (WebCore::FontPlatformData::cloneWithSyntheticOblique): 20 * platform/graphics/FontPlatformData.h: 21 (WebCore::FontPlatformData::setIsSystemFont): Deleted. 22 (WebCore::FontPlatformData::setSize): Deleted. 23 (WebCore::FontPlatformData::setOrientation): Deleted. 24 (WebCore::FontPlatformData::setSyntheticOblique): Deleted. 25 * platform/graphics/cocoa/FontCacheCoreText.cpp: 26 (WebCore::FontCache::systemFallbackForCharacters): 27 * platform/graphics/cocoa/FontCascadeCocoa.mm: 28 (WebCore::FontCascade::drawGlyphs): 29 * platform/graphics/cocoa/FontCocoa.mm: 30 (WebCore::Font::platformInit): 31 (WebCore::Font::platformCharWidthInit): 32 (WebCore::createDerivativeFont): 33 (WebCore::Font::createFontWithoutSynthesizableFeatures): 34 (WebCore::Font::platformCreateScaledFont): 35 (WebCore::Font::platformWidthForGlyph): 36 * platform/graphics/cocoa/FontPlatformDataCocoa.mm: 37 (WebCore::FontPlatformData::openTypeTable): 38 * platform/graphics/win/FontPlatformDataCairoWin.cpp: 39 (WebCore::FontPlatformData::platformDataInit): 40 1 41 2016-04-26 Ryan Haddad <ryanhaddad@apple.com> 2 42 -
trunk/Source/WebCore/platform/graphics/Font.cpp
r198074 r200094 254 254 m_derivedFontData = std::make_unique<DerivedFontData>(isCustomFont()); 255 255 if (!m_derivedFontData->verticalRightOrientation) { 256 FontPlatformData verticalRightPlatformData(m_platformData); 257 verticalRightPlatformData.setOrientation(Horizontal); 256 auto verticalRightPlatformData = FontPlatformData::cloneWithOrientation(m_platformData, Horizontal); 258 257 m_derivedFontData->verticalRightOrientation = create(verticalRightPlatformData, isCustomFont(), false, true); 259 258 } … … 321 320 m_derivedFontData = std::make_unique<DerivedFontData>(isCustomFont()); 322 321 if (!m_derivedFontData->nonSyntheticItalic) { 322 #if PLATFORM(COCOA) || USE(CAIRO) 323 FontPlatformData nonSyntheticItalicFontPlatformData = FontPlatformData::cloneWithSyntheticOblique(m_platformData, false); 324 #else 323 325 FontPlatformData nonSyntheticItalicFontPlatformData(m_platformData); 324 #if PLATFORM(COCOA) || USE(CAIRO)325 nonSyntheticItalicFontPlatformData.setSyntheticOblique(false);326 326 #endif 327 327 m_derivedFontData->nonSyntheticItalic = create(nonSyntheticItalicFontPlatformData, isCustomFont()); -
trunk/Source/WebCore/platform/graphics/FontPlatformData.cpp
r200070 r200094 45 45 46 46 FontPlatformData::FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant, TextRenderingMode textRenderingMode) 47 : m_syntheticBold(syntheticBold) 48 , m_syntheticOblique(syntheticOblique) 47 : m_size(size) 49 48 , m_orientation(orientation) 50 , m_size(size)51 49 , m_widthVariant(widthVariant) 52 50 , m_textRenderingMode(textRenderingMode) 51 , m_syntheticBold(syntheticBold) 52 , m_syntheticOblique(syntheticOblique) 53 53 { 54 54 } … … 70 70 m_isSystemFont = source.m_isSystemFont; 71 71 platformDataInit(source); 72 } 73 74 FontPlatformData FontPlatformData::cloneWithOrientation(const FontPlatformData& source, FontOrientation orientation) 75 { 76 FontPlatformData copy(source); 77 copy.m_orientation = orientation; 78 return copy; 79 } 80 81 FontPlatformData FontPlatformData::cloneWithSyntheticOblique(const FontPlatformData& source, bool syntheticOblique) 82 { 83 FontPlatformData copy(source); 84 copy.m_syntheticOblique = syntheticOblique; 85 return copy; 86 } 87 88 FontPlatformData FontPlatformData::cloneWithSize(const FontPlatformData& source, float size) 89 { 90 FontPlatformData copy(source); 91 copy.m_size = size; 92 return copy; 72 93 } 73 94 -
trunk/Source/WebCore/platform/graphics/FontPlatformData.h
r200070 r200094 75 75 class SharedBuffer; 76 76 77 // This class is conceptually immutable. Once created, no instances should ever change (in an observable way). 77 78 class FontPlatformData { 78 79 WTF_MAKE_FAST_ALLOCATED; … … 88 89 #endif 89 90 91 static FontPlatformData cloneWithOrientation(const FontPlatformData&, FontOrientation); 92 static FontPlatformData cloneWithSyntheticOblique(const FontPlatformData&, bool); 93 static FontPlatformData cloneWithSize(const FontPlatformData&, float); 94 90 95 #if USE(CG) 91 96 FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOblique, FontOrientation, FontWidthVariant, TextRenderingMode); … … 125 130 #if PLATFORM(WIN) || PLATFORM(COCOA) 126 131 bool isSystemFont() const { return m_isSystemFont; } 127 void setIsSystemFont(bool isSystemFont) { m_isSystemFont = isSystemFont; }128 132 #endif 129 133 … … 134 138 bool isFixedPitch() const; 135 139 float size() const { return m_size; } 136 void setSize(float size) { m_size = size; }137 140 bool syntheticBold() const { return m_syntheticBold; } 138 141 bool syntheticOblique() const { return m_syntheticOblique; } … … 142 145 TextRenderingMode textRenderingMode() const { return m_textRenderingMode; } 143 146 bool isForTextCombine() const { return widthVariant() != RegularWidth; } // Keep in sync with callers of FontDescription::setWidthVariant(). 144 145 void setOrientation(FontOrientation orientation) { m_orientation = orientation; }146 void setSyntheticOblique(bool syntheticOblique) { m_syntheticOblique = syntheticOblique; }147 147 148 148 #if USE(CAIRO) … … 198 198 199 199 #if PLATFORM(COCOA) || PLATFORM(WIN) 200 PassRefPtr<SharedBuffer> openTypeTable(uint32_t table) const;200 RefPtr<SharedBuffer> openTypeTable(uint32_t table) const; 201 201 #endif 202 202 … … 216 216 #endif 217 217 218 public:219 bool m_syntheticBold { false };220 bool m_syntheticOblique { false };221 FontOrientation m_orientation { Horizontal };222 float m_size { 0 };223 FontWidthVariant m_widthVariant { RegularWidth };224 TextRenderingMode m_textRenderingMode { AutoTextRendering };225 226 private:227 218 #if PLATFORM(COCOA) 228 219 // FIXME: Get rid of one of these. These two fonts are subtly different, and it is not obvious which one to use where. … … 240 231 #endif 241 232 233 // The values below are common to all ports 234 // FIXME: If they're common to all ports, they should move to Font 235 float m_size { 0 }; 236 237 FontOrientation m_orientation { Horizontal }; 238 FontWidthVariant m_widthVariant { RegularWidth }; 239 TextRenderingMode m_textRenderingMode { AutoTextRendering }; 240 241 bool m_syntheticBold { false }; 242 bool m_syntheticOblique { false }; 242 243 bool m_isColorBitmapFont { false }; 243 244 bool m_isHashTableDeletedValue { false }; 244 245 bool m_isSystemFont { false }; 246 // The values above are common to all ports 247 245 248 #if PLATFORM(IOS) 246 249 bool m_isEmoji { false }; -
trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp
r196969 r200094 792 792 std::tie(syntheticBold, syntheticOblique) = computeNecessarySynthesis(substituteFont, description, isPlatformFont).boldObliquePair(); 793 793 794 FontPlatformData alternateFont(substituteFont, platformData.size(), syntheticBold, syntheticOblique, platformData. m_orientation, platformData.m_widthVariant, platformData.m_textRenderingMode);794 FontPlatformData alternateFont(substituteFont, platformData.size(), syntheticBold, syntheticOblique, platformData.orientation(), platformData.widthVariant(), platformData.textRenderingMode()); 795 795 796 796 return fontForPlatformData(alternateFont); -
trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm
r198074 r200094 281 281 matrix.b = -matrix.b; 282 282 matrix.d = -matrix.d; 283 if (platformData. m_syntheticOblique) {283 if (platformData.syntheticOblique()) { 284 284 static float obliqueSkew = tanf(SYNTHETIC_OBLIQUE_ANGLE * piFloat / 180); 285 285 if (platformData.orientation() == Vertical) -
trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm
r199890 r200094 97 97 // FIXME: Unify these two codepaths 98 98 #if USE(APPKIT) 99 m_syntheticBoldOffset = m_platformData. m_syntheticBold? 1.0f : 0.f;99 m_syntheticBoldOffset = m_platformData.syntheticBold() ? 1.0f : 0.f; 100 100 101 101 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101100 … … 110 110 // Some fonts erroneously specify a positive descender value. We follow Core Text in assuming that 111 111 // such fonts meant the same distance, but in the reverse direction. 112 float pointSize = m_platformData. m_size;112 float pointSize = m_platformData.size(); 113 113 float ascent = scaleEmToUnits(CGFontGetAscent(m_platformData.cgFont()), unitsPerEm) * pointSize; 114 114 float descent = -scaleEmToUnits(-abs(CGFontGetDescent(m_platformData.cgFont())), unitsPerEm) * pointSize; … … 175 175 #else 176 176 177 m_syntheticBoldOffset = m_platformData. m_syntheticBold? ceilf(m_platformData.size() / 24.0f) : 0.f;177 m_syntheticBoldOffset = m_platformData.syntheticBold() ? ceilf(m_platformData.size() / 24.0f) : 0.f; 178 178 179 179 CTFontRef ctFont = m_platformData.font(); … … 203 203 const UInt8* os2 = CFDataGetBytePtr(os2Table.get()); 204 204 SInt16 os2AvgCharWidth = os2[2] * 256 + os2[3]; 205 m_avgCharWidth = scaleEmToUnits(os2AvgCharWidth, m_fontMetrics.unitsPerEm()) * m_platformData. m_size;205 m_avgCharWidth = scaleEmToUnits(os2AvgCharWidth, m_fontMetrics.unitsPerEm()) * m_platformData.size(); 206 206 } 207 207 … … 214 214 SInt16 xMax = static_cast<SInt16>(uxMax); 215 215 float diff = static_cast<float>(xMax - xMin); 216 m_maxCharWidth = scaleEmToUnits(diff, m_fontMetrics.unitsPerEm()) * m_platformData. m_size;216 m_maxCharWidth = scaleEmToUnits(diff, m_fontMetrics.unitsPerEm()) * m_platformData.size(); 217 217 } 218 218 #endif … … 364 364 return nullptr; 365 365 366 FontPlatformData scaledFontData(font, size, false, false, orientation);367 368 366 if (syntheticBold) 369 367 fontTraits |= kCTFontBoldTrait; … … 371 369 fontTraits |= kCTFontItalicTrait; 372 370 373 CTFontSymbolicTraits scaledFontTraits = CTFontGetSymbolicTraits(scaledFontData.font()); 374 scaledFontData.m_syntheticBold = (fontTraits & kCTFontBoldTrait) && !(scaledFontTraits & kCTFontTraitBold); 375 scaledFontData.m_syntheticOblique = (fontTraits & kCTFontItalicTrait) && !(scaledFontTraits & kCTFontTraitItalic); 371 CTFontSymbolicTraits scaledFontTraits = CTFontGetSymbolicTraits(font); 372 373 bool usedSyntheticBold = (fontTraits & kCTFontBoldTrait) && !(scaledFontTraits & kCTFontTraitBold); 374 bool usedSyntheticOblique = (fontTraits & kCTFontItalicTrait) && !(scaledFontTraits & kCTFontTraitItalic); 375 FontPlatformData scaledFontData(font, size, usedSyntheticBold, usedSyntheticOblique, orientation); 376 376 377 377 return Font::create(scaledFontData); … … 513 513 CTFontSymbolicTraits fontTraits = CTFontGetSymbolicTraits(m_platformData.font()); 514 514 RetainPtr<CTFontRef> ctFont = createCTFontWithoutSynthesizableFeatures(m_platformData.font()); 515 return createDerivativeFont(ctFont.get(), size, m_platformData.orientation(), fontTraits, m_platformData. m_syntheticBold, m_platformData.m_syntheticOblique);515 return createDerivativeFont(ctFont.get(), size, m_platformData.orientation(), fontTraits, m_platformData.syntheticBold(), m_platformData.syntheticOblique()); 516 516 } 517 517 … … 523 523 RetainPtr<CTFontRef> scaledFont = adoptCF(CTFontCreateWithFontDescriptor(fontDescriptor.get(), size, nullptr)); 524 524 525 return createDerivativeFont(scaledFont.get(), size, m_platformData.orientation(), fontTraits, m_platformData. m_syntheticBold, m_platformData.m_syntheticOblique);525 return createDerivativeFont(scaledFont.get(), size, m_platformData.orientation(), fontTraits, m_platformData.syntheticBold(), m_platformData.syntheticOblique()); 526 526 } 527 527 … … 629 629 bool populatedAdvance = false; 630 630 if ((horizontal || m_isBrokenIdeographFallback) && canUseFastGlyphAdvanceGetter(this->platformData(), glyph, advance, populatedAdvance)) { 631 float pointSize = platformData(). m_size;631 float pointSize = platformData().size(); 632 632 CGAffineTransform m = CGAffineTransformMakeScale(pointSize, pointSize); 633 633 if (!CGFontGetGlyphAdvancesForStyle(platformData().cgFont(), &m, renderingStyle(platformData()), &glyph, 1, &advance)) { … … 636 636 advance.width = 0; 637 637 } 638 } else if (!populatedAdvance && platformData(). m_size)638 } else if (!populatedAdvance && platformData().size()) 639 639 CTFontGetAdvancesForGlyphs(m_platformData.ctFont(), horizontal ? kCTFontOrientationHorizontal : kCTFontOrientationVertical, &glyph, &advance, 1); 640 640 -
trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm
r200070 r200094 189 189 } 190 190 191 PassRefPtr<SharedBuffer> FontPlatformData::openTypeTable(uint32_t table) const191 RefPtr<SharedBuffer> FontPlatformData::openTypeTable(uint32_t table) const 192 192 { 193 193 if (RetainPtr<CFDataRef> data = adoptCF(CGFontCopyTableForTag(cgFont(), table))) -
trunk/Source/WebCore/platform/graphics/freetype/FontPlatformData.h
r199890 r200094 69 69 FontPlatformData(const FontPlatformData&, float size); 70 70 71 static FontPlatformData cloneWithOrientation(const FontPlatformData&, FontOrientation); 72 static FontPlatformData cloneWithSyntheticOblique(const FontPlatformData&, bool); 73 static FontPlatformData cloneWithSize(const FontPlatformData&, float); 74 71 75 ~FontPlatformData(); 72 76 -
trunk/Source/WebCore/platform/graphics/freetype/FontPlatformDataFreeType.cpp
r199890 r200094 266 266 } 267 267 268 FontPlatformData FontPlatformData::cloneWithOrientation(const FontPlatformData& source, FontOrientation orientation) 269 { 270 FontPlatformData copy(source); 271 copy.m_orientation = orientation; 272 return copy; 273 } 274 275 FontPlatformData FontPlatformData::cloneWithSyntheticOblique(const FontPlatformData& source, bool syntheticOblique) 276 { 277 FontPlatformData copy(source); 278 copy.m_syntheticOblique = syntheticOblique; 279 return copy; 280 } 281 282 FontPlatformData FontPlatformData::cloneWithSize(const FontPlatformData& source, float size) 283 { 284 FontPlatformData copy(source); 285 copy.m_size = size; 286 return copy; 287 } 288 268 289 HarfBuzzFace* FontPlatformData::harfBuzzFace() const 269 290 { -
trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCairoWin.cpp
r199890 r200094 47 47 cairo_matrix_init_scale(&sizeMatrix, size, size); 48 48 49 static cairo_font_options_t* fontOptions = 0;49 static cairo_font_options_t* fontOptions = nullptr; 50 50 if (!fontOptions) { 51 51 fontOptions = cairo_font_options_create(); … … 102 102 m_font = source.m_font; 103 103 m_useGDI = source.m_useGDI; 104 m_scaledFont = 0;104 m_scaledFont = nullptr; 105 105 106 106 if (source.m_scaledFont) -
trunk/Source/WebCore/platform/graphics/win/FontPlatformDataWin.cpp
r194496 r200094 75 75 } 76 76 77 PassRefPtr<SharedBuffer> FontPlatformData::openTypeTable(uint32_t table) const77 RefPtr<SharedBuffer> FontPlatformData::openTypeTable(uint32_t table) const 78 78 { 79 79 HWndDC hdc(0); -
trunk/Source/WebCore/platform/graphics/win/SimpleFontDataWin.cpp
r194496 r200094 136 136 { 137 137 float scaledSize = scaleFactor * m_platformData.size(); 138 if (isCustomFont()) { 139 FontPlatformData scaledFont(m_platformData); 140 scaledFont.setSize(scaledSize); 141 return Font::create(scaledFont, true, false); 142 } 138 if (isCustomFont()) 139 return Font::create(FontPlatformData::cloneWithSize(m_platformData, scaledSize), true, false); 143 140 144 141 LOGFONT winfont;
Note: See TracChangeset
for help on using the changeset viewer.