OLD | NEW |
1 /* | 1 /* |
2 * This file is part of the internal font implementation. | 2 * This file is part of the internal font implementation. |
3 * | 3 * |
4 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. | 4 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. |
5 * Copyright (c) 2010 Google Inc. All rights reserved. | 5 * Copyright (c) 2010 Google Inc. All rights reserved. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 23 matching lines...) Expand all Loading... |
34 #import "platform/fonts/shaping/HarfBuzzFace.h" | 34 #import "platform/fonts/shaping/HarfBuzzFace.h" |
35 #include "third_party/skia/include/ports/SkTypeface_mac.h" | 35 #include "third_party/skia/include/ports/SkTypeface_mac.h" |
36 | 36 |
37 | 37 |
38 | 38 |
39 namespace blink { | 39 namespace blink { |
40 | 40 |
41 unsigned FontPlatformData::hash() const | 41 unsigned FontPlatformData::hash() const |
42 { | 42 { |
43 ASSERT(m_font || !m_cgFont); | 43 ASSERT(m_font || !m_cgFont); |
44 uintptr_t hashCodes[3] = { (uintptr_t)m_font, m_widthVariant, static_cast<ui
ntptr_t>(m_isHashTableDeletedValue << 3 | m_orientation << 2 | m_syntheticBold <
< 1 | m_syntheticItalic) }; | 44 uintptr_t hashCodes[2] = { (uintptr_t)m_font, static_cast<uintptr_t>(m_isHas
hTableDeletedValue << 3 | m_orientation << 2 | m_syntheticBold << 1 | m_syntheti
cItalic) }; |
45 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes); | 45 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes); |
46 } | 46 } |
47 | 47 |
48 void FontPlatformData::setupPaint(SkPaint* paint, GraphicsContext*, const Font*
font) const | 48 void FontPlatformData::setupPaint(SkPaint* paint, GraphicsContext*, const Font*
font) const |
49 { | 49 { |
50 bool shouldSmoothFonts = true; | 50 bool shouldSmoothFonts = true; |
51 bool shouldAntialias = true; | 51 bool shouldAntialias = true; |
52 | 52 |
53 shouldAntialias = shouldAntialias && (!LayoutTestSupport::isRunningLayoutTes
t() | 53 shouldAntialias = shouldAntialias && (!LayoutTestSupport::isRunningLayoutTes
t() |
54 || LayoutTestSupport::isFontAntialiasingEnabledForTest()); | 54 || LayoutTestSupport::isFontAntialiasingEnabledForTest()); |
(...skipping 10 matching lines...) Expand all Loading... |
65 paint->setLCDRenderText(shouldSmoothFonts); | 65 paint->setLCDRenderText(shouldSmoothFonts); |
66 paint->setSubpixelText(useSubpixelText); | 66 paint->setSubpixelText(useSubpixelText); |
67 | 67 |
68 // When rendering using CoreGraphics, disable hinting when webkit-font-smoot
hing:antialiased or | 68 // When rendering using CoreGraphics, disable hinting when webkit-font-smoot
hing:antialiased or |
69 // text-rendering:geometricPrecision is used. | 69 // text-rendering:geometricPrecision is used. |
70 // See crbug.com/152304 | 70 // See crbug.com/152304 |
71 if (font && (font->fontDescription().fontSmoothing() == Antialiased || font-
>fontDescription().textRendering() == GeometricPrecision)) | 71 if (font && (font->fontDescription().fontSmoothing() == Antialiased || font-
>fontDescription().textRendering() == GeometricPrecision)) |
72 paint->setHinting(SkPaint::kNo_Hinting); | 72 paint->setHinting(SkPaint::kNo_Hinting); |
73 } | 73 } |
74 | 74 |
75 // These CoreText Text Spacing feature selectors are not defined in CoreText. | 75 FontPlatformData::FontPlatformData(NSFont *nsFont, float size, bool syntheticBol
d, bool syntheticItalic, FontOrientation orientation) |
76 enum TextSpacingCTFeatureSelector { TextSpacingProportional, TextSpacingFullWidt
h, TextSpacingHalfWidth, TextSpacingThirdWidth, TextSpacingQuarterWidth }; | |
77 | |
78 FontPlatformData::FontPlatformData(NSFont *nsFont, float size, bool syntheticBol
d, bool syntheticItalic, FontOrientation orientation, FontWidthVariant widthVari
ant) | |
79 : m_textSize(size) | 76 : m_textSize(size) |
80 , m_syntheticBold(syntheticBold) | 77 , m_syntheticBold(syntheticBold) |
81 , m_syntheticItalic(syntheticItalic) | 78 , m_syntheticItalic(syntheticItalic) |
82 , m_orientation(orientation) | 79 , m_orientation(orientation) |
83 , m_isColorBitmapFont(false) | 80 , m_isColorBitmapFont(false) |
84 , m_isCompositeFontReference(false) | 81 , m_isCompositeFontReference(false) |
85 , m_widthVariant(widthVariant) | |
86 , m_font(nsFont) | 82 , m_font(nsFont) |
87 , m_isHashTableDeletedValue(false) | 83 , m_isHashTableDeletedValue(false) |
88 { | 84 { |
89 ASSERT_ARG(nsFont, nsFont); | 85 ASSERT_ARG(nsFont, nsFont); |
90 | 86 |
91 CGFontRef cgFont = 0; | 87 CGFontRef cgFont = 0; |
92 loadFont(nsFont, size, m_font, cgFont); | 88 loadFont(nsFont, size, m_font, cgFont); |
93 | 89 |
94 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 | 90 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 |
95 // FIXME: Chromium: The following code isn't correct for the Chromium port s
ince the sandbox might | 91 // FIXME: Chromium: The following code isn't correct for the Chromium port s
ince the sandbox might |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 bool FontPlatformData::roundsGlyphAdvances() const | 178 bool FontPlatformData::roundsGlyphAdvances() const |
183 { | 179 { |
184 return [m_font renderingMode] == NSFontAntialiasedIntegerAdvancementsRenderi
ngMode; | 180 return [m_font renderingMode] == NSFontAntialiasedIntegerAdvancementsRenderi
ngMode; |
185 } | 181 } |
186 | 182 |
187 bool FontPlatformData::allowsLigatures() const | 183 bool FontPlatformData::allowsLigatures() const |
188 { | 184 { |
189 return ![[m_font coveredCharacterSet] characterIsMember:'a']; | 185 return ![[m_font coveredCharacterSet] characterIsMember:'a']; |
190 } | 186 } |
191 | 187 |
192 inline int mapFontWidthVariantToCTFeatureSelector(FontWidthVariant variant) | |
193 { | |
194 switch(variant) { | |
195 case RegularWidth: | |
196 return TextSpacingProportional; | |
197 | |
198 case HalfWidth: | |
199 return TextSpacingHalfWidth; | |
200 | |
201 case ThirdWidth: | |
202 return TextSpacingThirdWidth; | |
203 | |
204 case QuarterWidth: | |
205 return TextSpacingQuarterWidth; | |
206 } | |
207 | |
208 ASSERT_NOT_REACHED(); | |
209 return TextSpacingProportional; | |
210 } | |
211 | |
212 static CFDictionaryRef createFeatureSettingDictionary(int featureTypeIdentifier,
int featureSelectorIdentifier) | 188 static CFDictionaryRef createFeatureSettingDictionary(int featureTypeIdentifier,
int featureSelectorIdentifier) |
213 { | 189 { |
214 RetainPtr<CFNumberRef> featureTypeIdentifierNumber(AdoptCF, CFNumberCreate(k
CFAllocatorDefault, kCFNumberIntType, &featureTypeIdentifier)); | 190 RetainPtr<CFNumberRef> featureTypeIdentifierNumber(AdoptCF, CFNumberCreate(k
CFAllocatorDefault, kCFNumberIntType, &featureTypeIdentifier)); |
215 RetainPtr<CFNumberRef> featureSelectorIdentifierNumber(AdoptCF, CFNumberCrea
te(kCFAllocatorDefault, kCFNumberIntType, &featureSelectorIdentifier)); | 191 RetainPtr<CFNumberRef> featureSelectorIdentifierNumber(AdoptCF, CFNumberCrea
te(kCFAllocatorDefault, kCFNumberIntType, &featureSelectorIdentifier)); |
216 | 192 |
217 const void* settingKeys[] = { kCTFontFeatureTypeIdentifierKey, kCTFontFeatur
eSelectorIdentifierKey }; | 193 const void* settingKeys[] = { kCTFontFeatureTypeIdentifierKey, kCTFontFeatur
eSelectorIdentifierKey }; |
218 const void* settingValues[] = { featureTypeIdentifierNumber.get(), featureSe
lectorIdentifierNumber.get() }; | 194 const void* settingValues[] = { featureTypeIdentifierNumber.get(), featureSe
lectorIdentifierNumber.get() }; |
219 | 195 |
220 return CFDictionaryCreate(kCFAllocatorDefault, settingKeys, settingValues, W
TF_ARRAY_LENGTH(settingKeys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionary
ValueCallBacks); | 196 return CFDictionaryCreate(kCFAllocatorDefault, settingKeys, settingValues, W
TF_ARRAY_LENGTH(settingKeys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionary
ValueCallBacks); |
221 } | 197 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 RetainPtr<CFStringRef> postScriptName(AdoptCF, CTFontCopyPostScriptName(
m_CTFont.get())); | 249 RetainPtr<CFStringRef> postScriptName(AdoptCF, CTFontCopyPostScriptName(
m_CTFont.get())); |
274 // Hoefler Text Italic has line-initial and -final swashes enabled by de
fault, so disable them. | 250 // Hoefler Text Italic has line-initial and -final swashes enabled by de
fault, so disable them. |
275 if (CFEqual(postScriptName.get(), CFSTR("HoeflerText-Italic")) || CFEqua
l(postScriptName.get(), CFSTR("HoeflerText-BlackItalic"))) | 251 if (CFEqual(postScriptName.get(), CFSTR("HoeflerText-Italic")) || CFEqua
l(postScriptName.get(), CFSTR("HoeflerText-BlackItalic"))) |
276 fontDescriptor = cascadeToLastResortAndDisableSwashesFontDescriptor(
); | 252 fontDescriptor = cascadeToLastResortAndDisableSwashesFontDescriptor(
); |
277 else | 253 else |
278 fontDescriptor = cascadeToLastResortFontDescriptor(); | 254 fontDescriptor = cascadeToLastResortFontDescriptor(); |
279 m_CTFont.adoptCF(CTFontCreateCopyWithAttributes(m_CTFont.get(), m_textSi
ze, 0, fontDescriptor)); | 255 m_CTFont.adoptCF(CTFontCreateCopyWithAttributes(m_CTFont.get(), m_textSi
ze, 0, fontDescriptor)); |
280 } else | 256 } else |
281 m_CTFont.adoptCF(CTFontCreateWithGraphicsFont(m_cgFont.get(), m_textSize
, 0, cascadeToLastResortFontDescriptor())); | 257 m_CTFont.adoptCF(CTFontCreateWithGraphicsFont(m_cgFont.get(), m_textSize
, 0, cascadeToLastResortFontDescriptor())); |
282 | 258 |
283 if (m_widthVariant != RegularWidth) { | |
284 int featureTypeValue = kTextSpacingType; | |
285 int featureSelectorValue = mapFontWidthVariantToCTFeatureSelector(m_widt
hVariant); | |
286 RetainPtr<CTFontDescriptorRef> sourceDescriptor(AdoptCF, CTFontCopyFontD
escriptor(m_CTFont.get())); | |
287 RetainPtr<CFNumberRef> featureType(AdoptCF, CFNumberCreate(kCFAllocatorD
efault, kCFNumberIntType, &featureTypeValue)); | |
288 RetainPtr<CFNumberRef> featureSelector(AdoptCF, CFNumberCreate(kCFAlloca
torDefault, kCFNumberIntType, &featureSelectorValue)); | |
289 RetainPtr<CTFontDescriptorRef> newDescriptor(AdoptCF, CTFontDescriptorCr
eateCopyWithFeature(sourceDescriptor.get(), featureType.get(), featureSelector.g
et())); | |
290 RetainPtr<CTFontRef> newFont(AdoptCF, CTFontCreateWithFontDescriptor(new
Descriptor.get(), m_textSize, 0)); | |
291 | |
292 if (newFont) | |
293 m_CTFont = newFont; | |
294 } | |
295 | |
296 return m_CTFont.get(); | 259 return m_CTFont.get(); |
297 } | 260 } |
298 | 261 |
299 } // namespace blink | 262 } // namespace blink |
OLD | NEW |