OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2005, 2008, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2008, 2010 Apple Inc. All rights reserved. |
3 * Copyright (C) 2006 Alexey Proskuryakov | 3 * Copyright (C) 2006 Alexey Proskuryakov |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 const float smallCapsFontSizeMultiplier = 0.7f; | 51 const float smallCapsFontSizeMultiplier = 0.7f; |
52 const float emphasisMarkFontSizeMultiplier = 0.5f; | 52 const float emphasisMarkFontSizeMultiplier = 0.5f; |
53 | 53 |
54 #if OS(LINUX) || OS(ANDROID) | 54 #if OS(LINUX) || OS(ANDROID) |
55 // This is the largest VDMX table which we'll try to load and parse. | 55 // This is the largest VDMX table which we'll try to load and parse. |
56 static const size_t maxVDMXTableSize = 1024 * 1024; // 1 MB | 56 static const size_t maxVDMXTableSize = 1024 * 1024; // 1 MB |
57 #endif | 57 #endif |
58 | 58 |
59 SimpleFontData::SimpleFontData(const FontPlatformData& platformData, | 59 SimpleFontData::SimpleFontData(const FontPlatformData& platformData, |
60 PassRefPtr<CustomFontData> customData, | 60 PassRefPtr<CustomFontData> customData, |
61 bool isTextOrientationFallback) | 61 bool isTextOrientationFallback, |
62 bool subpixelAscentDescent) | |
62 : m_maxCharWidth(-1), | 63 : m_maxCharWidth(-1), |
63 m_avgCharWidth(-1), | 64 m_avgCharWidth(-1), |
64 m_platformData(platformData), | 65 m_platformData(platformData), |
65 m_isTextOrientationFallback(isTextOrientationFallback), | 66 m_isTextOrientationFallback(isTextOrientationFallback), |
66 m_verticalData(nullptr), | 67 m_verticalData(nullptr), |
67 m_hasVerticalGlyphs(false), | 68 m_hasVerticalGlyphs(false), |
68 m_customFontData(customData) { | 69 m_customFontData(customData) { |
69 platformInit(); | 70 platformInit(subpixelAscentDescent); |
70 platformGlyphInit(); | 71 platformGlyphInit(); |
71 if (platformData.isVerticalAnyUpright() && !isTextOrientationFallback) { | 72 if (platformData.isVerticalAnyUpright() && !isTextOrientationFallback) { |
72 m_verticalData = platformData.verticalData(); | 73 m_verticalData = platformData.verticalData(); |
73 m_hasVerticalGlyphs = | 74 m_hasVerticalGlyphs = |
74 m_verticalData.get() && m_verticalData->hasVerticalMetrics(); | 75 m_verticalData.get() && m_verticalData->hasVerticalMetrics(); |
75 } | 76 } |
76 } | 77 } |
77 | 78 |
78 SimpleFontData::SimpleFontData(PassRefPtr<CustomFontData> customData, | 79 SimpleFontData::SimpleFontData(PassRefPtr<CustomFontData> customData, |
79 float fontSize, | 80 float fontSize, |
80 bool syntheticBold, | 81 bool syntheticBold, |
81 bool syntheticItalic) | 82 bool syntheticItalic) |
82 : m_platformData( | 83 : m_platformData( |
83 FontPlatformData(fontSize, syntheticBold, syntheticItalic)), | 84 FontPlatformData(fontSize, syntheticBold, syntheticItalic)), |
84 m_isTextOrientationFallback(false), | 85 m_isTextOrientationFallback(false), |
85 m_verticalData(nullptr), | 86 m_verticalData(nullptr), |
86 m_hasVerticalGlyphs(false), | 87 m_hasVerticalGlyphs(false), |
87 m_customFontData(customData) {} | 88 m_customFontData(customData) {} |
88 | 89 |
89 void SimpleFontData::platformInit() { | 90 void SimpleFontData::platformInit(bool subpixelAscentDescent) { |
90 if (!m_platformData.size()) { | 91 if (!m_platformData.size()) { |
91 m_fontMetrics.reset(); | 92 m_fontMetrics.reset(); |
92 m_avgCharWidth = 0; | 93 m_avgCharWidth = 0; |
93 m_maxCharWidth = 0; | 94 m_maxCharWidth = 0; |
94 return; | 95 return; |
95 } | 96 } |
96 | 97 |
97 SkPaint::FontMetrics metrics; | 98 SkPaint::FontMetrics metrics; |
98 | 99 |
99 m_platformData.setupPaint(&m_paint); | 100 m_platformData.setupPaint(&m_paint); |
(...skipping 24 matching lines...) Expand all Loading... | |
124 isVDMXValid = true; | 125 isVDMXValid = true; |
125 WTF::Partitions::fastFree(vdmxTable); | 126 WTF::Partitions::fastFree(vdmxTable); |
126 } | 127 } |
127 } | 128 } |
128 #endif | 129 #endif |
129 | 130 |
130 float ascent; | 131 float ascent; |
131 float descent; | 132 float descent; |
132 | 133 |
133 // Beware those who step here: This code is designed to match Win32 font | 134 // Beware those who step here: This code is designed to match Win32 font |
134 // metrics *exactly* (except the adjustment of ascent/descent on | 135 // metrics *exactly* except: |
135 // Linux/Android). | 136 // - the adjustment of ascent/descent on Linux/Android |
137 // - metrics.fAscent and .fDesscent are not rounded to int for tiny fonts | |
136 if (isVDMXValid) { | 138 if (isVDMXValid) { |
137 ascent = vdmxAscent; | 139 ascent = vdmxAscent; |
138 descent = -vdmxDescent; | 140 descent = -vdmxDescent; |
139 } else { | 141 } else { |
140 ascent = SkScalarRoundToInt(-metrics.fAscent); | 142 // For tiny fonts, the rounding of fAscent and fDescent results in equal |
141 descent = SkScalarRoundToInt(metrics.fDescent); | 143 // baseline for different types of text baselines (crbug.com/338908). |
144 // Please see CanvasRenderingContext2D::getFontBaseline for the heuristic. | |
145 if (subpixelAscentDescent && | |
drott
2016/10/18 10:42:17
zakerinasab, did you say the same problem applies
| |
146 (-metrics.fAscent < 3 || -metrics.fAscent + metrics.fDescent < 2)) { | |
147 ascent = -metrics.fAscent; | |
148 descent = metrics.fDescent; | |
149 } else { | |
150 ascent = SkScalarRoundToScalar(-metrics.fAscent); | |
151 descent = SkScalarRoundToScalar(metrics.fDescent); | |
152 } | |
142 #if OS(LINUX) || OS(ANDROID) | 153 #if OS(LINUX) || OS(ANDROID) |
143 // When subpixel positioning is enabled, if the descent is rounded down, the | 154 // When subpixel positioning is enabled, if the descent is rounded down, the |
144 // descent part of the glyph may be truncated when displayed in a 'overflow: | 155 // descent part of the glyph may be truncated when displayed in a 'overflow: |
145 // hidden' container. To avoid that, borrow 1 unit from the ascent when | 156 // hidden' container. To avoid that, borrow 1 unit from the ascent when |
146 // possible. | 157 // possible. |
147 // FIXME: This can be removed if sub-pixel ascent/descent is supported. | 158 // FIXME: This can be removed if sub-pixel ascent/descent is supported. |
148 if (platformData().getFontRenderStyle().useSubpixelPositioning && | 159 if (platformData().getFontRenderStyle().useSubpixelPositioning && |
149 descent < SkScalarToFloat(metrics.fDescent) && ascent >= 1) { | 160 descent < SkScalarToFloat(metrics.fDescent) && ascent >= 1) { |
150 ++descent; | 161 ++descent; |
151 --ascent; | 162 --ascent; |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
427 if (glyphs[i]) { | 438 if (glyphs[i]) { |
428 pageToFill->setGlyphDataForIndex(offset + i, glyphs[i], this); | 439 pageToFill->setGlyphDataForIndex(offset + i, glyphs[i], this); |
429 haveGlyphs = true; | 440 haveGlyphs = true; |
430 } | 441 } |
431 } | 442 } |
432 | 443 |
433 return haveGlyphs; | 444 return haveGlyphs; |
434 } | 445 } |
435 | 446 |
436 } // namespace blink | 447 } // namespace blink |
OLD | NEW |