Changeset 204858 in webkit
- Timestamp:
- Aug 23, 2016, 2:11:20 PM (9 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 deleted
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r204855 r204858 1 2016-08-23 Myles C. Maxfield <mmaxfield@apple.com> 2 3 [Cocoa] Reduce uses of CGFonts 4 https://bugs.webkit.org/show_bug.cgi?id=160896 5 6 Reviewed by Darin Adler. 7 8 There are a few places where we unnecessarily use CGFonts instead of 9 CTFonts. We have had an ongoing effort throughout the past few years 10 of elliminating all of our uses of CGFonts, and this patch moves us 11 in that direction. 12 13 Most of the changes in this patch are straightforward (e.g. 14 CGFontGetUnitsPerEm() -> CTFontGetUnitsPerEm()). However, there is 15 one notable change: from CGContextShowGlyphsWithAdvances() to 16 CTFontDrawGlyphs(). This migration does not cause a performance 17 regression. 18 19 No new tests because there is no behavior change. 20 21 * WebCore.xcodeproj/project.pbxproj: Delete unnecessary 22 FontServicesIOS files. 23 * platform/graphics/FontMetrics.h: 24 (WebCore::FontMetrics::xHeight): Migrate to Optional<float> 25 (WebCore::FontMetrics::setXHeight): 26 (WebCore::FontMetrics::hasXHeight): 27 (WebCore::FontMetrics::hasCapHeight): Ditto. 28 (WebCore::FontMetrics::floatCapHeight): 29 (WebCore::FontMetrics::setCapHeight): 30 (WebCore::FontMetrics::capHeight): 31 (WebCore::FontMetrics::setZeroWidth): No one ever used the 32 m_hasZeroWidth variable, so this patch removes it. 33 (WebCore::FontMetrics::reset): 34 (WebCore::FontMetrics::FontMetrics): Deleted. 35 (WebCore::FontMetrics::setHasXHeight): Deleted. No one ever calls 36 this, so this patch removes it. 37 (WebCore::FontMetrics::hasZeroWidth): Deleted. 38 (WebCore::FontMetrics::setHasZeroWidth): Deleted. 39 * platform/graphics/cocoa/FontCascadeCocoa.mm: 40 (WebCore::TextMatrixRestorer::TextMatrixRestorer): Rather than leaving 41 the text matrix stale after using it, this class cleans it up after us. 42 This means that the text matrix doesn't have to be reset in other places 43 which draw text. 44 (WebCore::TextMatrixRestorer::~TextMatrixRestorer): 45 (WebCore::TextMatrixRestorer::savedMatrix): 46 (WebCore::showGlyphsWithAdvances): Migrate from 47 CGContextShowGlyphsWithAdvances() to CTFontDrawGlyphs() 48 (WebCore::FontCascade::drawGlyphs): See above comment about the text 49 matrix. 50 (WebCore::RenderingStyleSaver::RenderingStyleSaver): Deleted. 51 (WebCore::RenderingStyleSaver::~RenderingStyleSaver): Deleted. 52 * platform/graphics/cocoa/FontCocoa.mm: 53 (WebCore::shouldUseAdjustment): Taken from FontServicesIOS. 54 (WebCore::Font::platformInit): Migrate from CG to CT for some direct 55 replacement API calls. 56 (WebCore::Font::platformCharWidthInit): Ditto. 57 (WebCore::Font::determinePitch): Ditto. 58 * platform/graphics/cocoa/FontPlatformDataCocoa.mm: 59 (WebCore::FontPlatformData::openTypeTable): Ditto. 60 (WebCore::FontPlatformData::description): Ditto. 61 * platform/graphics/ios/FontServicesIOS.h: Removed. No longer needed 62 after migrating from CGContextShowGlyphsWithAdvances() to 63 CTFontDrawGlyphs(). 64 (WebCore::FontServicesIOS::ascent): Deleted. 65 (WebCore::FontServicesIOS::descent): Deleted. 66 (WebCore::FontServicesIOS::lineGap): Deleted. 67 (WebCore::FontServicesIOS::lineSpacing): Deleted. 68 (WebCore::FontServicesIOS::xHeight): Deleted. 69 (WebCore::FontServicesIOS::capHeight): Deleted. 70 (WebCore::FontServicesIOS::unitsPerEm): Deleted. 71 * platform/graphics/ios/FontServicesIOS.mm: Removed. Moved into 72 Font::platformInit(). 73 (WebCore::shouldUseAdjustment): Deleted. 74 (WebCore::isCourier): Deleted. 75 (WebCore::FontServicesIOS::FontServicesIOS): Deleted. 76 * platform/graphics/opentype/OpenTypeCG.cpp: 77 (WebCore::OpenType::tryGetTypoMetrics): Migrate from CG to CT for some 78 direct replacement API calls. 79 * platform/graphics/opentype/OpenTypeCG.h: Ditto. 80 * platform/graphics/win/FontCGWin.cpp: 81 (WebCore::FontCascade::drawGlyphs): Restore the text matrix. 82 * platform/graphics/win/SimpleFontDataCGWin.cpp: 83 (WebCore::Font::platformWidthForGlyph): Deleted. 84 * platform/spi/cg/CoreGraphicsSPI.h: 85 * platform/spi/cocoa/CoreTextSPI.h: 86 * rendering/RenderThemeIOS.mm: 87 (WebCore::paintAttachmentText): Deleted. 88 * rendering/RenderThemeMac.mm: 89 (WebCore::paintAttachmentTitle): Deleted. 90 (WebCore::paintAttachmentSubtitle): Deleted. 91 1 92 2016-08-23 Alex Christensen <achristensen@webkit.org> 2 93 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r204853 r204858 5441 5441 C572EE1F1201C9BC007D8F82 /* JSIDBIndex.h in Headers */ = {isa = PBXBuildFile; fileRef = C572EE1D1201C9BC007D8F82 /* JSIDBIndex.h */; }; 5442 5442 C57FEDE11212EE9C0097BE65 /* FileSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C57FEDE01212EE9C0097BE65 /* FileSystem.cpp */; }; 5443 C58361A91744523F00173511 /* FontServicesIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = C58361A71744523F00173511 /* FontServicesIOS.h */; };5444 C58361AA1744523F00173511 /* FontServicesIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = C58361A81744523F00173511 /* FontServicesIOS.mm */; };5445 5443 C585A66211D4FAC5004C3E4B /* IDBBindingUtilities.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C585A66011D4FAC5004C3E4B /* IDBBindingUtilities.cpp */; }; 5446 5444 C585A66311D4FAC5004C3E4B /* IDBBindingUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = C585A66111D4FAC5004C3E4B /* IDBBindingUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 12886 12884 C572EE1D1201C9BC007D8F82 /* JSIDBIndex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSIDBIndex.h; sourceTree = "<group>"; }; 12887 12885 C57FEDE01212EE9C0097BE65 /* FileSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileSystem.cpp; sourceTree = "<group>"; }; 12888 C58361A71744523F00173511 /* FontServicesIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FontServicesIOS.h; sourceTree = "<group>"; };12889 C58361A81744523F00173511 /* FontServicesIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FontServicesIOS.mm; sourceTree = "<group>"; };12890 12886 C585A66011D4FAC5004C3E4B /* IDBBindingUtilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IDBBindingUtilities.cpp; sourceTree = "<group>"; }; 12891 12887 C585A66111D4FAC5004C3E4B /* IDBBindingUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBBindingUtilities.h; sourceTree = "<group>"; }; … … 16020 16016 1AC2D89C1B1E291F00D52E87 /* FontAntialiasingStateSaver.h */, 16021 16017 3727DFD4142AAE4500D449CB /* FontCacheIOS.mm */, 16022 C58361A71744523F00173511 /* FontServicesIOS.h */,16023 C58361A81744523F00173511 /* FontServicesIOS.mm */,16024 16018 31AB4FFF122878A2001A7DB0 /* GraphicsContext3DIOS.h */, 16025 16019 FED13D3F0CEA939400D89466 /* IconIOS.mm */, … … 24333 24327 B2C3DA6B0D006CD600EF6F26 /* FontSelector.h in Headers */, 24334 24328 E419041F1CC6486B00C35F5D /* FontSelectorClient.h in Headers */, 24335 C58361A91744523F00173511 /* FontServicesIOS.h in Headers */,24336 24329 C2015C0A1BE6FEB200822389 /* FontVariantBuilder.h in Headers */, 24337 24330 4A0DA2FF129B241900AB61E1 /* FormAssociatedElement.h in Headers */, … … 27950 27943 B5320D6C122A24E9002D1440 /* FontPlatformDataCocoa.mm in Sources */, 27951 27944 371F4FFD0D25E7F300ECE0D5 /* FontRanges.cpp in Sources */, 27952 C58361AA1744523F00173511 /* FontServicesIOS.mm in Sources */,27953 27945 1C3249111C6D6A3B007EDB32 /* FontVariantBuilder.cpp in Sources */, 27954 27946 4A0DA2FE129B241900AB61E1 /* FormAssociatedElement.cpp in Sources */, -
trunk/Source/WebCore/platform/graphics/FontMetrics.h
r178940 r204858 23 23 #include "FontBaseline.h" 24 24 #include <wtf/MathExtras.h> 25 #include <wtf/Optional.h> 25 26 26 27 namespace WebCore { 27 28 28 const unsigned gDefaultUnitsPerEm = 1000;29 30 29 class FontMetrics { 31 30 public: 32 FontMetrics() 33 : m_unitsPerEm(gDefaultUnitsPerEm) 34 , m_ascent(0) 35 , m_descent(0) 36 , m_lineGap(0) 37 , m_lineSpacing(0) 38 , m_xHeight(0) 39 , m_zeroWidth(0) 40 , m_hasXHeight(false) 41 , m_hasZeroWidth(false) 42 { 43 } 31 static const unsigned defaultUnitsPerEm = 1000; 44 32 45 33 unsigned unitsPerEm() const { return m_unitsPerEm; } … … 76 64 77 65 float xHeight() const { return m_xHeight; } 78 void setXHeight(float xHeight) 79 { 80 m_xHeight = xHeight; 81 m_hasXHeight = true; 82 } 83 84 bool hasXHeight() const { return m_hasXHeight && m_xHeight > 0; } 85 void setHasXHeight(bool hasXHeight) { m_hasXHeight = hasXHeight; } 66 void setXHeight(float xHeight) { m_xHeight = xHeight; } 67 bool hasXHeight() const { return m_xHeight > 0; } 86 68 87 bool hasCapHeight() const { return m_ hasCapHeight && m_capHeight > 0; }69 bool hasCapHeight() const { return m_capHeight > 0; } 88 70 float floatCapHeight() const { return m_capHeight; } 89 void setCapHeight(float capHeight) 90 { 91 m_capHeight = capHeight; 92 m_hasCapHeight = true; 93 } 71 void setCapHeight(float capHeight) { m_capHeight = capHeight; } 94 72 95 73 // Integer variants of certain metrics, used for HTML rendering. … … 124 102 125 103 float zeroWidth() const { return m_zeroWidth; } 126 void setZeroWidth(float zeroWidth) 127 { 128 m_zeroWidth = zeroWidth; 129 m_hasZeroWidth = true; 130 } 131 132 bool hasZeroWidth() const { return m_hasZeroWidth; } 133 void setHasZeroWidth(bool hasZeroWidth) { m_hasZeroWidth = hasZeroWidth; } 104 void setZeroWidth(float zeroWidth) { m_zeroWidth = zeroWidth; } 134 105 135 106 private: … … 138 109 void reset() 139 110 { 140 m_unitsPerEm = gDefaultUnitsPerEm;111 m_unitsPerEm = defaultUnitsPerEm; 141 112 m_ascent = 0; 142 113 m_descent = 0; … … 144 115 m_lineSpacing = 0; 145 116 m_xHeight = 0; 146 m_hasXHeight = false; 117 m_capHeight = 0; 118 m_zeroWidth = 0; 147 119 } 148 120 149 unsigned m_unitsPerEm; 150 float m_ascent; 151 float m_descent; 152 float m_lineGap; 153 float m_lineSpacing; 154 float m_xHeight; 155 float m_capHeight; 156 float m_zeroWidth; 157 bool m_hasXHeight; 158 bool m_hasCapHeight; 159 bool m_hasZeroWidth; 121 unsigned m_unitsPerEm { defaultUnitsPerEm }; 122 float m_ascent { 0 }; 123 float m_descent { 0 }; 124 float m_lineGap { 0 }; 125 float m_lineSpacing { 0 }; 126 float m_zeroWidth { 0 }; 127 float m_xHeight { 0 }; 128 float m_capHeight { 0 }; 160 129 }; 161 130 -
trunk/Source/WebCore/platform/graphics/FontPlatformData.h
r200563 r204858 45 45 46 46 #if PLATFORM(COCOA) 47 #if PLATFORM(IOS)48 #import <CoreGraphics/CoreGraphics.h>49 #endif50 47 #if USE(APPKIT) 51 48 OBJC_CLASS NSFont; … … 57 54 58 55 #if USE(CG) 59 typedef struct CGFont* CGFontRef; 56 #include <CoreGraphics/CoreGraphics.h> 60 57 #endif 61 58 … … 293 290 #endif 294 291 292 #if USE(CG) 293 class ScopedTextMatrix { 294 public: 295 ScopedTextMatrix(CGAffineTransform newMatrix, CGContextRef context) 296 : m_context(context) 297 , m_textMatrix(CGContextGetTextMatrix(context)) 298 { 299 CGContextSetTextMatrix(m_context, newMatrix); 300 } 301 302 ~ScopedTextMatrix() 303 { 304 CGContextSetTextMatrix(m_context, m_textMatrix); 305 } 306 307 CGAffineTransform savedMatrix() const 308 { 309 return m_textMatrix; 310 } 311 312 private: 313 CGContextRef m_context; 314 CGAffineTransform m_textMatrix; 315 }; 316 #endif 317 295 318 } // namespace WebCore 296 319 -
trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm
r204400 r204858 132 132 } 133 133 134 class RenderingStyleSaver {135 public:136 #if !PLATFORM(MAC) || __MAC_OS_X_VERSION_MIN_REQUIRED <= 101000137 RenderingStyleSaver(CTFontRef, CGContextRef) { }138 #else139 RenderingStyleSaver(CTFontRef font, CGContextRef context)140 : m_context(context)141 {142 m_changed = CTFontSetRenderingStyle(font, context, &m_originalStyle, &m_originalDilation);143 }144 145 ~RenderingStyleSaver()146 {147 if (!m_changed)148 return;149 CGContextSetFontRenderingStyle(m_context, m_originalStyle);150 CGContextSetFontDilation(m_context, m_originalDilation);151 }152 153 private:154 bool m_changed;155 CGContextRef m_context;156 CGFontRenderingStyle m_originalStyle;157 CGSize m_originalDilation;158 #endif159 };160 161 134 static void showGlyphsWithAdvances(const FloatPoint& point, const Font& font, CGContextRef context, const CGGlyph* glyphs, const CGSize* advances, unsigned count) 162 135 { … … 168 141 const FontPlatformData& platformData = font.platformData(); 169 142 Vector<CGPoint, 256> positions(count); 170 if (platformData.isColorBitmapFont())171 fillVectorWithHorizontalGlyphPositions(positions, context, advances, count);172 143 if (platformData.orientation() == Vertical) { 173 CGAffineTransform savedMatrix;174 144 CGAffineTransform rotateLeftTransform = CGAffineTransformMake(0, -1, 1, 0, 0, 0); 175 savedMatrix = CGContextGetTextMatrix(context);176 CGAffineTransform runMatrix = CGAffineTransformConcat( savedMatrix, rotateLeftTransform);145 CGAffineTransform textMatrix = CGContextGetTextMatrix(context); 146 CGAffineTransform runMatrix = CGAffineTransformConcat(textMatrix, rotateLeftTransform); 177 147 CGContextSetTextMatrix(context, runMatrix); 178 148 … … 189 159 position.y += advances[i].height; 190 160 } 191 if (!platformData.isColorBitmapFont()) { 192 RenderingStyleSaver saver(platformData.ctFont(), context); 193 CGContextShowGlyphsAtPositions(context, glyphs, positions.data(), count); 194 } else 195 CTFontDrawGlyphs(platformData.ctFont(), glyphs, positions.data(), count, context); 196 CGContextSetTextMatrix(context, savedMatrix); 161 CTFontDrawGlyphs(platformData.ctFont(), glyphs, positions.data(), count, context); 197 162 } else { 198 if (!platformData.isColorBitmapFont()) { 199 RenderingStyleSaver saver(platformData.ctFont(), context); 200 #pragma clang diagnostic push 201 #pragma clang diagnostic ignored "-Wdeprecated-declarations" 202 CGContextShowGlyphsWithAdvances(context, glyphs, advances, count); 203 #pragma clang diagnostic pop 204 } else 205 CTFontDrawGlyphs(platformData.ctFont(), glyphs, positions.data(), count, context); 163 fillVectorWithHorizontalGlyphPositions(positions, context, advances, count); 164 CTFontDrawGlyphs(platformData.ctFont(), glyphs, positions.data(), count, context); 206 165 } 207 166 } … … 270 229 } 271 230 #endif 272 273 CGContextSetFont(cgContext, platformData.cgFont());274 231 275 232 bool useLetterpressEffect = shouldUseLetterpressEffect(context); … … 288 245 matrix = CGAffineTransformConcat(matrix, CGAffineTransformMake(1, 0, -obliqueSkew, 1, 0, 0)); 289 246 } 290 CGContextSetTextMatrix(cgContext, matrix);247 ScopedTextMatrix restorer(matrix, cgContext); 291 248 292 249 setCGFontRenderingMode(context); -
trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm
r204466 r204858 35 35 #import "FontCascade.h" 36 36 #import "FontDescription.h" 37 #import "OpenTypeCG.h" 37 38 #import "SharedBuffer.h" 38 39 #import "WebCoreSystemInterface.h" … … 47 48 #import <ApplicationServices/ApplicationServices.h> 48 49 #else 49 #import "FontServicesIOS.h"50 50 #import <CoreText/CoreText.h> 51 51 #endif … … 57 57 #endif 58 58 59 #if USE(APPKIT)60 #import "OpenTypeCG.h"61 #endif62 63 59 namespace WebCore { 60 61 static inline bool caseInsensitiveCompare(CFStringRef a, CFStringRef b) 62 { 63 return a && CFStringCompare(a, b, kCFCompareCaseInsensitive) == kCFCompareEqualTo; 64 } 64 65 65 66 static bool fontHasVerticalGlyphs(CTFontRef ctFont) … … 78 79 } 79 80 80 #if !USE(APPKIT)81 #if PLATFORM(IOS) 81 82 bool fontFamilyShouldNotBeUsedForArabic(CFStringRef fontFamilyName) 82 83 { … … 89 90 || (CFStringCompare(CFSTR("Arial"), fontFamilyName, 0) == kCFCompareEqualTo); 90 91 } 92 93 static const float kLineHeightAdjustment = 0.15f; 94 95 static bool shouldUseAdjustment(CTFontRef font) 96 { 97 RetainPtr<CFStringRef> familyName = adoptCF(CTFontCopyFamilyName(font)); 98 99 if (!familyName || !CFStringGetLength(familyName.get())) 100 return false; 101 102 return caseInsensitiveCompare(familyName.get(), CFSTR("Times")) 103 || caseInsensitiveCompare(familyName.get(), CFSTR("Helvetica")) 104 || caseInsensitiveCompare(familyName.get(), CFSTR(".Helvetica NeueUI")); 105 } 106 107 #else 108 109 static bool needsAscentAdjustment(CFStringRef familyName) 110 { 111 return familyName && (caseInsensitiveCompare(familyName, CFSTR("Times")) 112 || caseInsensitiveCompare(familyName, CFSTR("Helvetica")) 113 || caseInsensitiveCompare(familyName, CFSTR("Courier"))); 114 } 115 91 116 #endif 92 117 93 118 void Font::platformInit() 94 119 { 95 // FIXME: Unify these two codepaths 96 #if USE(APPKIT) 120 #if PLATFORM(IOS) 121 m_syntheticBoldOffset = m_platformData.syntheticBold() ? ceilf(m_platformData.size() / 24.0f) : 0.f; 122 #else 97 123 m_syntheticBoldOffset = m_platformData.syntheticBold() ? 1.0f : 0.f; 124 #endif 98 125 99 126 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101100 … … 104 131 #endif 105 132 106 unsigned unitsPerEm = CGFontGetUnitsPerEm(m_platformData.cgFont()); 107 108 // Some fonts erroneously specify a positive descender value. We follow Core Text in assuming that 109 // such fonts meant the same distance, but in the reverse direction. 133 unsigned unitsPerEm = CTFontGetUnitsPerEm(m_platformData.font()); 110 134 float pointSize = m_platformData.size(); 135 float capHeight = CTFontGetCapHeight(m_platformData.font()); 136 float lineGap = CTFontGetLeading(m_platformData.font()); 137 #if PLATFORM(IOS) 138 CGFloat ascent = CTFontGetAscent(m_platformData.font()); 139 CGFloat descent = CTFontGetDescent(m_platformData.font()); 140 #else 111 141 float ascent = scaleEmToUnits(CGFontGetAscent(m_platformData.cgFont()), unitsPerEm) * pointSize; 112 142 float descent = -scaleEmToUnits(-abs(CGFontGetDescent(m_platformData.cgFont())), unitsPerEm) * pointSize; 113 float capHeight = scaleEmToUnits(CGFontGetCapHeight(m_platformData.cgFont()), unitsPerEm) * pointSize; 114 115 float lineGap = scaleEmToUnits(CGFontGetLeading(m_platformData.cgFont()), unitsPerEm) * pointSize; 143 #endif 116 144 117 145 // The Open Font Format describes the OS/2 USE_TYPO_METRICS flag as follows: … … 120 148 if (OpenType::fontHasMathTable(m_platformData.ctFont())) { 121 149 short typoAscent, typoDescent, typoLineGap; 122 if (OpenType::tryGetTypoMetrics(m_platformData. cgFont(), typoAscent, typoDescent, typoLineGap)) {150 if (OpenType::tryGetTypoMetrics(m_platformData.font(), typoAscent, typoDescent, typoLineGap)) { 123 151 ascent = scaleEmToUnits(typoAscent, unitsPerEm) * pointSize; 124 152 descent = -scaleEmToUnits(typoDescent, unitsPerEm) * pointSize; … … 127 155 } 128 156 157 auto familyName = adoptCF(CTFontCopyFamilyName(m_platformData.font())); 158 #if PLATFORM(MAC) 129 159 // We need to adjust Times, Helvetica, and Courier to closely match the 130 160 // vertical metrics of their Microsoft counterparts that are the de facto … … 132 162 // incorrectly added to line spacing, so we use a 15% adjustment instead 133 163 // and add it to the ascent. 134 RetainPtr<CFStringRef> familyName = adoptCF(CTFontCopyFamilyName(m_platformData.font())); 135 if (!m_isCustomFont && familyName && (CFStringCompare(familyName.get(), CFSTR("Times"), kCFCompareCaseInsensitive) == kCFCompareEqualTo 136 || CFStringCompare(familyName.get(), CFSTR("Helvetica"), kCFCompareCaseInsensitive) == kCFCompareEqualTo 137 || CFStringCompare(familyName.get(), CFSTR("Courier"), kCFCompareCaseInsensitive) == kCFCompareEqualTo)) 138 ascent += floorf(((ascent + descent) * 0.15f) + 0.5f); 139 140 // Compute and store line spacing, before the line metrics hacks are applied. 141 m_fontMetrics.setLineSpacing(lroundf(ascent) + lroundf(descent) + lroundf(lineGap)); 142 164 if (!m_isCustomFont && needsAscentAdjustment(familyName.get())) 165 ascent += std::round((ascent + descent) * 0.15f); 166 #endif 167 168 // Compute line spacing before the line metrics hacks are applied. 169 float lineSpacing = lroundf(ascent) + lroundf(descent) + lroundf(lineGap); 170 171 #if !PLATFORM(IOS) 143 172 // Hack Hiragino line metrics to allow room for marked text underlines. 144 173 // <rdar://problem/5386183> … … 147 176 descent = 3; 148 177 } 178 #endif 149 179 150 180 if (platformData().orientation() == Vertical && !isTextOrientationFallback()) 151 181 m_hasVerticalGlyphs = fontHasVerticalGlyphs(m_platformData.ctFont()); 152 182 183 #if PLATFORM(IOS) 184 CGFloat adjustment = shouldUseAdjustment(m_platformData.font()) ? ceil((ascent + descent) * kLineHeightAdjustment) : 0; 185 186 CGFontDescriptor descriptor; 187 float xHeight = CGFontGetDescriptor(m_platformData.cgFont(), &descriptor) ? (descriptor.xHeight / 1000) * CTFontGetSize(m_platformData.font()) : 0; 188 lineGap = ceilf(lineGap); 189 lineSpacing = ceil(ascent) + adjustment + ceil(descent) + lineGap; 190 ascent = ceilf(ascent + adjustment); 191 descent = ceilf(descent); 192 193 m_shouldNotBeUsedForArabic = fontFamilyShouldNotBeUsedForArabic(adoptCF(CTFontCopyFamilyName(m_platformData.font())).get()); 194 #else 153 195 float xHeight; 154 155 196 if (platformData().orientation() == Horizontal) { 156 197 // Measure the actual character "x", since it's possible for it to extend below the baseline, and we need the … … 160 201 xHeight = -CGRectGetMinY(platformBoundsForGlyph(xGlyph)); 161 202 else 162 xHeight = scaleEmToUnits(CGFontGetXHeight(m_platformData.cgFont()), unitsPerEm) * pointSize;203 xHeight = CTFontGetXHeight(m_platformData.font()); 163 204 } else 164 205 xHeight = verticalRightOrientationFont().fontMetrics().xHeight(); 206 #endif 165 207 166 208 m_fontMetrics.setUnitsPerEm(unitsPerEm); … … 170 212 m_fontMetrics.setLineGap(lineGap); 171 213 m_fontMetrics.setXHeight(xHeight); 172 173 #else 174 175 m_syntheticBoldOffset = m_platformData.syntheticBold() ? ceilf(m_platformData.size() / 24.0f) : 0.f; 176 177 CTFontRef ctFont = m_platformData.font(); 178 FontServicesIOS fontService(ctFont); 179 m_fontMetrics.setUnitsPerEm(fontService.unitsPerEm()); 180 m_fontMetrics.setAscent(ceilf(fontService.ascent())); 181 m_fontMetrics.setDescent(ceilf(fontService.descent())); 182 m_fontMetrics.setLineGap(fontService.lineGap()); 183 m_fontMetrics.setLineSpacing(fontService.lineSpacing()); 184 m_fontMetrics.setXHeight(fontService.xHeight()); 185 m_fontMetrics.setCapHeight(fontService.capHeight()); 186 m_shouldNotBeUsedForArabic = fontFamilyShouldNotBeUsedForArabic(adoptCF(CTFontCopyFamilyName(ctFont)).get()); 187 188 if (platformData().orientation() == Vertical && !isTextOrientationFallback()) 189 m_hasVerticalGlyphs = fontHasVerticalGlyphs(m_platformData.ctFont()); 190 #endif 214 m_fontMetrics.setLineSpacing(lineSpacing); 191 215 } 192 216 … … 197 221 198 222 #if PLATFORM(MAC) 199 RetainPtr<CFDataRef> os2Table = adoptCF(CGFontCopyTableForTag(m_platformData.cgFont(), 'OS/2'));223 auto os2Table = adoptCF(CTFontCopyTable(m_platformData.font(), kCTFontTableOS2, kCTFontTableOptionNoOptions)); 200 224 if (os2Table && CFDataGetLength(os2Table.get()) >= 4) { 201 225 const UInt8* os2 = CFDataGetBytePtr(os2Table.get()); … … 204 228 } 205 229 206 RetainPtr<CFDataRef> headTable = adoptCF(CGFontCopyTableForTag(m_platformData.cgFont(), 'head'));230 auto headTable = adoptCF(CTFontCopyTable(m_platformData.font(), kCTFontTableHead, kCTFontTableOptionNoOptions)); 207 231 if (headTable && CFDataGetLength(headTable.get()) >= 42) { 208 232 const UInt8* head = CFDataGetBytePtr(headTable.get()); … … 524 548 } 525 549 526 static inline bool caseInsensitiveCompare(CFStringRef a, CFStringRef b) 527 { 528 return a && CFStringCompare(a, b, kCFCompareCaseInsensitive) == kCFCompareEqualTo; 550 static int extractNumber(CFNumberRef number) 551 { 552 int result = 0; 553 if (number) 554 CFNumberGetValue(number, kCFNumberIntType, &result); 555 return result; 529 556 } 530 557 … … 546 573 // Note that AppKit does report MonotypeCorsiva as fixed pitch. 547 574 548 RetainPtr<CFStringRef> fullName = adoptCF(CTFontCopyFullName(ctFont)); 549 RetainPtr<CFStringRef> familyName = adoptCF(CTFontCopyFamilyName(ctFont)); 550 551 m_treatAsFixedPitch = (CTFontGetSymbolicTraits(ctFont) & kCTFontMonoSpaceTrait) || CGFontIsFixedPitch(m_platformData.cgFont()) || (caseInsensitiveCompare(fullName.get(), CFSTR("Osaka-Mono")) || caseInsensitiveCompare(fullName.get(), CFSTR("MS-PGothic")) || caseInsensitiveCompare(fullName.get(), CFSTR("MonotypeCorsiva"))); 575 auto fullName = adoptCF(CTFontCopyFullName(ctFont)); 576 auto familyName = adoptCF(CTFontCopyFamilyName(ctFont)); 577 578 int fixedPitch = extractNumber(adoptCF(static_cast<CFNumberRef>(CTFontCopyAttribute(m_platformData.font(), kCTFontFixedAdvanceAttribute))).get()); 579 m_treatAsFixedPitch = (CTFontGetSymbolicTraits(ctFont) & kCTFontMonoSpaceTrait) || fixedPitch || (caseInsensitiveCompare(fullName.get(), CFSTR("Osaka-Mono")) || caseInsensitiveCompare(fullName.get(), CFSTR("MS-PGothic")) || caseInsensitiveCompare(fullName.get(), CFSTR("MonotypeCorsiva"))); 552 580 #if PLATFORM(IOS) 553 if (familyName && CFStringCompare(familyName.get(), CFSTR("Courier New"), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {581 if (familyName && caseInsensitiveCompare(familyName.get(), CFSTR("Courier New"))) { 554 582 // Special case Courier New to not be treated as fixed pitch, as this will make use of a hacked space width which is undesireable for iPhone (see rdar://6269783). 555 583 m_treatAsFixedPitch = false; -
trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm
r200563 r204858 158 158 RefPtr<SharedBuffer> FontPlatformData::openTypeTable(uint32_t table) const 159 159 { 160 if (RetainPtr<CFDataRef> data = adoptCF(C GFontCopyTableForTag(cgFont(), table)))160 if (RetainPtr<CFDataRef> data = adoptCF(CTFontCopyTable(font(), table, kCTFontTableOptionNoOptions))) 161 161 return SharedBuffer::wrapCFData(data.get()); 162 162 … … 167 167 String FontPlatformData::description() const 168 168 { 169 RetainPtr<CFStringRef> cgFontDescription = adoptCF(CFCopyDescription(cgFont()));170 return String( cgFontDescription.get()) + " " + String::number(m_size)169 auto fontDescription = adoptCF(CFCopyDescription(font())); 170 return String(fontDescription.get()) + " " + String::number(m_size) 171 171 + (m_syntheticBold ? " synthetic bold" : "") + (m_syntheticOblique ? " synthetic oblique" : "") + (m_orientation ? " vertical orientation" : ""); 172 172 } -
trunk/Source/WebCore/platform/graphics/opentype/OpenTypeCG.cpp
r193484 r204858 36 36 #endif 37 37 38 #if PLATFORM(COCOA)39 38 bool fontHasMathTable(CTFontRef ctFont) 40 39 { … … 50 49 return false; 51 50 } 52 #endif53 51 54 52 static inline short readShortFromTable(const UInt8* os2Data, CFIndex offset) … … 57 55 } 58 56 59 bool tryGetTypoMetrics(C GFontRef cgFont, short& ascent, short& descent, short& lineGap)57 bool tryGetTypoMetrics(CTFontRef font, short& ascent, short& descent, short& lineGap) 60 58 { 61 59 bool result = false; 62 if ( CFDataRef os2Table = CGFontCopyTableForTag(cgFont, kCTFontTableOS2)) {60 if (auto os2Table = adoptCF(CTFontCopyTable(font, kCTFontTableOS2, kCTFontTableOptionNoOptions))) { 63 61 // For the structure of the OS/2 table, see 64 62 // https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6OS2.html … … 67 65 const CFIndex sTypoDescenderOffset = sTypoAscenderOffset + 2; 68 66 const CFIndex sTypoLineGapOffset = sTypoDescenderOffset + 2; 69 if (CFDataGetLength(os2Table ) >= sTypoLineGapOffset + 2) {70 const UInt8* os2Data = CFDataGetBytePtr(os2Table );67 if (CFDataGetLength(os2Table.get()) >= sTypoLineGapOffset + 2) { 68 const UInt8* os2Data = CFDataGetBytePtr(os2Table.get()); 71 69 // We test the use typo bit on the least significant byte of fsSelection. 72 70 const UInt8 useTypoMetricsMask = 1 << 7; … … 78 76 } 79 77 } 80 CFRelease(os2Table);81 78 } 82 79 return result; -
trunk/Source/WebCore/platform/graphics/opentype/OpenTypeCG.h
r192017 r204858 28 28 29 29 #include <CoreGraphics/CoreGraphics.h> 30 #if PLATFORM(COCOA)31 30 #include <CoreText/CoreText.h> 31 32 #if PLATFORM(WIN) 33 #include "CoreTextSPIWin.h" 32 34 #endif 33 35 … … 35 37 namespace OpenType { 36 38 37 #if PLATFORM(COCOA)38 39 bool fontHasMathTable(CTFontRef); 39 #endif 40 bool tryGetTypoMetrics(CGFontRef, short& ascent, short& descent, short& lineGap); 40 bool tryGetTypoMetrics(CTFontRef, short& ascent, short& descent, short& lineGap); 41 41 42 42 } // namespace OpenType -
trunk/Source/WebCore/platform/graphics/win/FontCGWin.cpp
r204400 r204858 173 173 } 174 174 175 CGAffineTransform savedMatrix = CGContextGetTextMatrix(cgContext); 175 176 CGContextSetTextMatrix(cgContext, matrix); 176 177 … … 216 217 217 218 wkRestoreFontSmoothingStyle(cgContext, oldFontSmoothingStyle); 218 } 219 220 } 219 CGContextSetTextMatrix(cgContext, savedMatrix); 220 } 221 222 } -
trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCGWin.cpp
r199890 r204858 30 30 #include "Font.h" 31 31 32 #include "CoreTextSPIWin.h" 32 33 #include "FloatRect.h" 33 34 #include "FontCache.h" … … 68 69 // "If set, it is strongly recommended to use OS/2.sTypoAscender - OS/2.sTypoDescender+ OS/2.sTypoLineGap as a value for default line spacing for this font." 69 70 short typoAscent, typoDescent, typoLineGap; 70 if (OpenType::tryGetTypoMetrics( m_platformData.cgFont(), typoAscent, typoDescent, typoLineGap)) {71 if (OpenType::tryGetTypoMetrics(adoptCF(CTFontCreateWithGraphicsFont(m_platformData.cgFont(), m_platformData.size(), nullptr, nullptr)).get(), typoAscent, typoDescent, typoLineGap)) { 71 72 iAscent = typoAscent; 72 73 iDescent = typoDescent; … … 145 146 CGAffineTransform m = CGAffineTransformMakeScale(pointSize, pointSize); 146 147 147 // FIXME: Need to add real support for printer fonts.148 148 bool isPrinterFont = false; 149 149 wkGetGlyphAdvances(font, m, m_platformData.isSystemFont(), isPrinterFont, glyph, advance); -
trunk/Source/WebCore/platform/spi/cg/CoreGraphicsSPI.h
r203424 r204858 171 171 void CGContextResetClip(CGContextRef); 172 172 CGContextType CGContextGetType(CGContextRef); 173 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100174 void CGContextSetFontDilation(CGContextRef, CGSize);175 void CGContextSetFontRenderingStyle(CGContextRef, CGFontRenderingStyle);176 #endif177 173 178 174 CFStringRef CGFontCopyFamilyName(CGFontRef); -
trunk/Source/WebCore/platform/spi/cocoa/CoreTextSPI.h
r204456 r204858 68 68 CTTypesetterRef CTTypesetterCreateWithUniCharProviderAndOptions(CTUniCharProviderCallback provide, CTUniCharDisposeCallback dispose, void* refCon, CFDictionaryRef options); 69 69 bool CTFontGetVerticalGlyphsForCharacters(CTFontRef, const UniChar characters[], CGGlyph glyphs[], CFIndex count); 70 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED > 10100071 bool CTFontSetRenderingStyle(CTFontRef, CGContextRef, CGFontRenderingStyle* originalStyle, CGSize* originalDilation);72 #endif73 70 74 71 CTFontDescriptorRef CTFontDescriptorCreateForUIType(CTFontUIFontType, CGFloat size, CFStringRef language); -
trunk/Source/WebCore/platform/spi/win/CoreTextSPIWin.h
r204592 r204858 34 34 typedef const struct __CTFont* CTFontRef; 35 35 typedef const struct __CTLine* CTLineRef; 36 typedef UInt32 FourCharCode; 37 typedef FourCharCode CTFontTableTag; 36 38 37 39 extern const CFStringRef kCTFontAttributeName; 38 40 extern const CFStringRef kCTForegroundColorFromContextAttributeName; 39 41 40 CTFontRef CTFontCreateWithName(CFStringRef name, CGFloat size, const CGAffineTransform* matrix); 42 typedef CF_OPTIONS(uint32_t, CTFontTableOptions) 43 { 44 kCTFontTableOptionNoOptions = 0, 45 kCTFontTableOptionExcludeSynthetic = (1 << 0) 46 }; 47 48 CTFontRef CTFontCreateWithName(CFStringRef, CGFloat size, const CGAffineTransform*); 49 CTFontRef CTFontCreateWithGraphicsFont(CGFontRef, CGFloat size, const CGAffineTransform*, CTFontDescriptorRef attributes); 41 50 CTLineRef CTLineCreateWithAttributedString(CFAttributedStringRef); 42 51 void CTLineDraw(CTLineRef, CGContextRef); 52 CFDataRef CTFontCopyTable(CTFontRef, CTFontTableTag, CTFontTableOptions); 53 CFArrayRef CTFontCopyAvailableTables(CTFontRef, CTFontTableOptions); 43 54 44 55 } -
trunk/Source/WebCore/rendering/RenderThemeIOS.mm
r204005 r204858 1653 1653 context.scale(FloatSize(1, -1)); 1654 1654 1655 CGContextSetText Matrix(context.platformContext(), CGAffineTransformIdentity);1655 CGContextSetTextPosition(context.platformContext(), 0, 0); 1656 1656 CTLineDraw(line.line.get(), context.platformContext()); 1657 1657 } -
trunk/Source/WebCore/rendering/RenderThemeMac.mm
r203324 r204858 2511 2511 context.scale(FloatSize(1, -1)); 2512 2512 2513 CGContextSetText Matrix(context.platformContext(), CGAffineTransformIdentity);2513 CGContextSetTextPosition(context.platformContext(), 0, 0); 2514 2514 CTLineDraw(line.line.get(), context.platformContext()); 2515 2515 } … … 2523 2523 context.scale(FloatSize(1, -1)); 2524 2524 2525 CGContextSetText Matrix(context.platformContext(), CGAffineTransformIdentity);2525 CGContextSetTextPosition(context.platformContext(), 0, 0); 2526 2526 CTLineDraw(layout.subtitleLine.get(), context.platformContext()); 2527 2527 } -
trunk/Source/WebCore/svg/SVGFontFaceElement.cpp
r203324 r204858 77 77 const AtomicString& value = attributeWithoutSynchronization(units_per_emAttr); 78 78 if (value.isEmpty()) 79 return gDefaultUnitsPerEm;79 return FontMetrics::defaultUnitsPerEm; 80 80 81 81 return static_cast<unsigned>(ceilf(value.toFloat()));
Note:
See TracChangeset
for help on using the changeset viewer.