| 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 12 matching lines...) Expand all Loading... |
| 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" | 31 #include "platform/LayoutTestSupport.h" |
| 32 #include "platform/RuntimeEnabledFeatures.h" | 32 #include "platform/RuntimeEnabledFeatures.h" |
| 33 #include "platform/fonts/Font.h" |
| 33 #import "platform/fonts/shaping/HarfBuzzFace.h" | 34 #import "platform/fonts/shaping/HarfBuzzFace.h" |
| 34 #include "third_party/skia/include/ports/SkTypeface_mac.h" | 35 #include "third_party/skia/include/ports/SkTypeface_mac.h" |
| 35 | 36 |
| 36 | 37 |
| 37 | 38 |
| 38 namespace blink { | 39 namespace blink { |
| 39 | 40 |
| 40 unsigned FontPlatformData::hash() const | 41 unsigned FontPlatformData::hash() const |
| 41 { | 42 { |
| 42 ASSERT(m_font || !m_cgFont); | 43 ASSERT(m_font || !m_cgFont); |
| 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) }; | 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 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes); | 45 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void FontPlatformData::setupPaint(SkPaint* paint, GraphicsContext*) const | 48 void FontPlatformData::setupPaint(SkPaint* paint, GraphicsContext*, const Font*
font) const |
| 48 { | 49 { |
| 49 bool shouldSmoothFonts = true; | 50 bool shouldSmoothFonts = true; |
| 50 bool shouldAntialias = true; | 51 bool shouldAntialias = true; |
| 51 | 52 |
| 52 shouldAntialias = shouldAntialias && (!LayoutTestSupport::isRunningLayoutTes
t() | 53 shouldAntialias = shouldAntialias && (!LayoutTestSupport::isRunningLayoutTes
t() |
| 53 || LayoutTestSupport::isFontAntialiasingEnabledForTest()); | 54 || LayoutTestSupport::isFontAntialiasingEnabledForTest()); |
| 54 bool useSubpixelText = RuntimeEnabledFeatures::subpixelFontScalingEnabled(); | 55 bool useSubpixelText = RuntimeEnabledFeatures::subpixelFontScalingEnabled(); |
| 55 shouldSmoothFonts = shouldSmoothFonts && !LayoutTestSupport::isRunningLayout
Test(); | 56 shouldSmoothFonts = shouldSmoothFonts && !LayoutTestSupport::isRunningLayout
Test(); |
| 56 | 57 |
| 57 paint->setAntiAlias(shouldAntialias); | 58 paint->setAntiAlias(shouldAntialias); |
| 58 paint->setEmbeddedBitmapText(false); | 59 paint->setEmbeddedBitmapText(false); |
| 59 const float ts = m_textSize >= 0 ? m_textSize : 12; | 60 const float ts = m_textSize >= 0 ? m_textSize : 12; |
| 60 paint->setTextSize(SkFloatToScalar(ts)); | 61 paint->setTextSize(SkFloatToScalar(ts)); |
| 61 paint->setTypeface(typeface()); | 62 paint->setTypeface(typeface()); |
| 62 paint->setFakeBoldText(m_syntheticBold); | 63 paint->setFakeBoldText(m_syntheticBold); |
| 63 paint->setTextSkewX(m_syntheticItalic ? -SK_Scalar1 / 4 : 0); | 64 paint->setTextSkewX(m_syntheticItalic ? -SK_Scalar1 / 4 : 0); |
| 64 paint->setAutohinted(false); // freetype specific | |
| 65 paint->setLCDRenderText(shouldSmoothFonts); | 65 paint->setLCDRenderText(shouldSmoothFonts); |
| 66 paint->setSubpixelText(useSubpixelText); | 66 paint->setSubpixelText(useSubpixelText); |
| 67 paint->setHinting(SkPaint::kNo_Hinting); | 67 |
| 68 // When rendering using CoreGraphics, disable hinting when webkit-font-smoot
hing:antialiased or |
| 69 // text-rendering:geometricPrecision is used. |
| 70 // See crbug.com/152304 |
| 71 if (font && (font->fontDescription().fontSmoothing() == Antialiased || font-
>fontDescription().textRendering() == GeometricPrecision)) |
| 72 paint->setHinting(SkPaint::kNo_Hinting); |
| 68 } | 73 } |
| 69 | 74 |
| 70 // These CoreText Text Spacing feature selectors are not defined in CoreText. | 75 // These CoreText Text Spacing feature selectors are not defined in CoreText. |
| 71 enum TextSpacingCTFeatureSelector { TextSpacingProportional, TextSpacingFullWidt
h, TextSpacingHalfWidth, TextSpacingThirdWidth, TextSpacingQuarterWidth }; | 76 enum TextSpacingCTFeatureSelector { TextSpacingProportional, TextSpacingFullWidt
h, TextSpacingHalfWidth, TextSpacingThirdWidth, TextSpacingQuarterWidth }; |
| 72 | 77 |
| 73 FontPlatformData::FontPlatformData(NSFont *nsFont, float size, bool syntheticBol
d, bool syntheticItalic, FontOrientation orientation, FontWidthVariant widthVari
ant) | 78 FontPlatformData::FontPlatformData(NSFont *nsFont, float size, bool syntheticBol
d, bool syntheticItalic, FontOrientation orientation, FontWidthVariant widthVari
ant) |
| 74 : m_textSize(size) | 79 : m_textSize(size) |
| 75 , m_syntheticBold(syntheticBold) | 80 , m_syntheticBold(syntheticBold) |
| 76 , m_syntheticItalic(syntheticItalic) | 81 , m_syntheticItalic(syntheticItalic) |
| 77 , m_orientation(orientation) | 82 , m_orientation(orientation) |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 RetainPtr<CTFontRef> newFont(AdoptCF, CTFontCreateWithFontDescriptor(new
Descriptor.get(), m_textSize, 0)); | 290 RetainPtr<CTFontRef> newFont(AdoptCF, CTFontCreateWithFontDescriptor(new
Descriptor.get(), m_textSize, 0)); |
| 286 | 291 |
| 287 if (newFont) | 292 if (newFont) |
| 288 m_CTFont = newFont; | 293 m_CTFont = newFont; |
| 289 } | 294 } |
| 290 | 295 |
| 291 return m_CTFont.get(); | 296 return m_CTFont.get(); |
| 292 } | 297 } |
| 293 | 298 |
| 294 } // namespace blink | 299 } // namespace blink |
| OLD | NEW |