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 10 matching lines...) Expand all Loading... |
21 * | 21 * |
22 */ | 22 */ |
23 | 23 |
24 #import "config.h" | 24 #import "config.h" |
25 #import "platform/fonts/FontPlatformData.h" | 25 #import "platform/fonts/FontPlatformData.h" |
26 | 26 |
27 #import <AppKit/NSFont.h> | 27 #import <AppKit/NSFont.h> |
28 #import <AvailabilityMacros.h> | 28 #import <AvailabilityMacros.h> |
29 #import <wtf/text/WTFString.h> | 29 #import <wtf/text/WTFString.h> |
30 | 30 |
| 31 #include "platform/LayoutTestSupport.h" |
| 32 #include "platform/RuntimeEnabledFeatures.h" |
31 #import "platform/fonts/harfbuzz/HarfBuzzFace.h" | 33 #import "platform/fonts/harfbuzz/HarfBuzzFace.h" |
32 #include "third_party/skia/include/ports/SkTypeface_mac.h" | 34 #include "third_party/skia/include/ports/SkTypeface_mac.h" |
33 | 35 |
| 36 |
| 37 |
34 namespace blink { | 38 namespace blink { |
35 | 39 |
36 unsigned FontPlatformData::hash() const | 40 unsigned FontPlatformData::hash() const |
37 { | 41 { |
38 ASSERT(m_font || !m_cgFont); | 42 ASSERT(m_font || !m_cgFont); |
39 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) }; | 43 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) }; |
40 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes); | 44 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes); |
41 } | 45 } |
42 | 46 |
| 47 void FontPlatformData::setupPaint(SkPaint* paint, GraphicsContext*) const |
| 48 { |
| 49 bool shouldSmoothFonts = true; |
| 50 bool shouldAntialias = true; |
| 51 |
| 52 shouldAntialias = shouldAntialias && (!LayoutTestSupport::isRunningLayoutTes
t() |
| 53 || LayoutTestSupport::isFontAntialiasingEnabledForTest()); |
| 54 bool useSubpixelText = RuntimeEnabledFeatures::subpixelFontScalingEnabled(); |
| 55 shouldSmoothFonts = shouldSmoothFonts && !LayoutTestSupport::isRunningLayout
Test(); |
| 56 |
| 57 paint->setAntiAlias(shouldAntialias); |
| 58 paint->setEmbeddedBitmapText(false); |
| 59 const float ts = m_textSize >= 0 ? m_textSize : 12; |
| 60 paint->setTextSize(SkFloatToScalar(ts)); |
| 61 paint->setTypeface(typeface()); |
| 62 paint->setFakeBoldText(m_syntheticBold); |
| 63 paint->setTextSkewX(m_syntheticItalic ? -SK_Scalar1 / 4 : 0); |
| 64 paint->setAutohinted(false); // freetype specific |
| 65 paint->setLCDRenderText(shouldSmoothFonts); |
| 66 paint->setSubpixelText(useSubpixelText); |
| 67 paint->setHinting(SkPaint::kNo_Hinting); |
| 68 } |
| 69 |
43 // These CoreText Text Spacing feature selectors are not defined in CoreText. | 70 // These CoreText Text Spacing feature selectors are not defined in CoreText. |
44 enum TextSpacingCTFeatureSelector { TextSpacingProportional, TextSpacingFullWidt
h, TextSpacingHalfWidth, TextSpacingThirdWidth, TextSpacingQuarterWidth }; | 71 enum TextSpacingCTFeatureSelector { TextSpacingProportional, TextSpacingFullWidt
h, TextSpacingHalfWidth, TextSpacingThirdWidth, TextSpacingQuarterWidth }; |
45 | 72 |
46 FontPlatformData::FontPlatformData(NSFont *nsFont, float size, bool syntheticBol
d, bool syntheticItalic, FontOrientation orientation, FontWidthVariant widthVari
ant) | 73 FontPlatformData::FontPlatformData(NSFont *nsFont, float size, bool syntheticBol
d, bool syntheticItalic, FontOrientation orientation, FontWidthVariant widthVari
ant) |
47 : m_textSize(size) | 74 : m_textSize(size) |
48 , m_syntheticBold(syntheticBold) | 75 , m_syntheticBold(syntheticBold) |
49 , m_syntheticItalic(syntheticItalic) | 76 , m_syntheticItalic(syntheticItalic) |
50 , m_orientation(orientation) | 77 , m_orientation(orientation) |
51 , m_isColorBitmapFont(false) | 78 , m_isColorBitmapFont(false) |
52 , m_isCompositeFontReference(false) | 79 , m_isCompositeFontReference(false) |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 RetainPtr<CTFontDescriptorRef> newDescriptor(AdoptCF, CTFontDescriptorCr
eateCopyWithFeature(sourceDescriptor.get(), featureType.get(), featureSelector.g
et())); | 284 RetainPtr<CTFontDescriptorRef> newDescriptor(AdoptCF, CTFontDescriptorCr
eateCopyWithFeature(sourceDescriptor.get(), featureType.get(), featureSelector.g
et())); |
258 RetainPtr<CTFontRef> newFont(AdoptCF, CTFontCreateWithFontDescriptor(new
Descriptor.get(), m_textSize, 0)); | 285 RetainPtr<CTFontRef> newFont(AdoptCF, CTFontCreateWithFontDescriptor(new
Descriptor.get(), m_textSize, 0)); |
259 | 286 |
260 if (newFont) | 287 if (newFont) |
261 m_CTFont = newFont; | 288 m_CTFont = newFont; |
262 } | 289 } |
263 | 290 |
264 return m_CTFont.get(); | 291 return m_CTFont.get(); |
265 } | 292 } |
266 | 293 |
267 bool FontPlatformData::isAATFont(CTFontRef ctFont) const | |
268 { | |
269 CFDataRef table = CTFontCopyTable(ctFont, kCTFontTableMort, 0); | |
270 if (table) { | |
271 CFRelease(table); | |
272 return true; | |
273 } | |
274 table = CTFontCopyTable(ctFont, kCTFontTableMorx, 0); | |
275 if (table) { | |
276 CFRelease(table); | |
277 return true; | |
278 } | |
279 return false; | |
280 } | |
281 | |
282 } // namespace blink | 294 } // namespace blink |
OLD | NEW |