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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 float ascent; | 126 float ascent; |
127 float descent; | 127 float descent; |
128 | 128 |
129 // Beware those who step here: This code is designed to match Win32 font | 129 // Beware those who step here: This code is designed to match Win32 font |
130 // metrics *exactly* except: | 130 // metrics *exactly* except: |
131 // - the adjustment of ascent/descent on Linux/Android | 131 // - the adjustment of ascent/descent on Linux/Android |
132 // - metrics.fAscent and .fDesscent are not rounded to int for tiny fonts | 132 // - metrics.fAscent and .fDesscent are not rounded to int for tiny fonts |
133 if (isVDMXValid) { | 133 if (isVDMXValid) { |
134 ascent = vdmxAscent; | 134 ascent = vdmxAscent; |
135 descent = -vdmxDescent; | 135 descent = -vdmxDescent; |
136 } else { | 136 } else if (subpixelAscentDescent && |
137 (-metrics.fAscent < 3 || | |
138 -metrics.fAscent + metrics.fDescent < 2)) { | |
137 // For tiny fonts, the rounding of fAscent and fDescent results in equal | 139 // For tiny fonts, the rounding of fAscent and fDescent results in equal |
138 // baseline for different types of text baselines (crbug.com/338908). | 140 // baseline for different types of text baselines (crbug.com/338908). |
139 // Please see CanvasRenderingContext2D::getFontBaseline for the heuristic. | 141 // Please see CanvasRenderingContext2D::getFontBaseline for the heuristic. |
140 if (subpixelAscentDescent && | 142 ascent = -metrics.fAscent; |
141 (-metrics.fAscent < 3 || -metrics.fAscent + metrics.fDescent < 2)) { | 143 descent = metrics.fDescent; |
142 ascent = -metrics.fAscent; | 144 } else { |
143 descent = metrics.fDescent; | 145 ascent = SkScalarRoundToScalar(-metrics.fAscent); |
144 } else { | 146 descent = SkScalarRoundToScalar(metrics.fDescent); |
145 ascent = SkScalarRoundToScalar(-metrics.fAscent); | 147 |
146 descent = SkScalarRoundToScalar(metrics.fDescent); | 148 int overflowAdjustmentForAscent = 0; |
149 if (ascent < SkScalarToFloat(-metrics.fAscent)) | |
150 ++overflowAdjustmentForAscent; | |
151 int overflowAdjustmentForDescent = 0; | |
152 if (descent < SkScalarToFloat(metrics.fDescent)) { | |
153 ++overflowAdjustmentForDescent; | |
154 #if OS(LINUX) || OS(ANDROID) | |
chrishtr
2017/04/06 21:07:00
This Android/Linux part used to be conditioned on
Xianzhu
2017/04/06 21:20:47
Yes. The condition 'descent < SkScalarToFloat(metr
| |
155 // When subpixel positioning is enabled, if the descent is rounded down, | |
156 // the descent part of the glyph may be truncated when displayed in a | |
157 // 'overflow: hidden' container. To avoid that, borrow 1 unit from the | |
158 // ascent when possible. | |
159 if (platformData().getFontRenderStyle().useSubpixelPositioning && | |
160 ascent >= 1) { | |
161 ++descent; | |
162 --overflowAdjustmentForDescent; | |
163 --ascent; | |
164 ++overflowAdjustmentForAscent; | |
165 } | |
166 #endif | |
147 } | 167 } |
148 #if OS(LINUX) || OS(ANDROID) | 168 m_fontMetrics.setVisualOverflowAdjustments(overflowAdjustmentForAscent, |
149 // When subpixel positioning is enabled, if the descent is rounded down, the | 169 overflowAdjustmentForDescent); |
150 // descent part of the glyph may be truncated when displayed in a 'overflow: | |
151 // hidden' container. To avoid that, borrow 1 unit from the ascent when | |
152 // possible. | |
153 // FIXME: This can be removed if sub-pixel ascent/descent is supported. | |
154 if (platformData().getFontRenderStyle().useSubpixelPositioning && | |
155 descent < SkScalarToFloat(metrics.fDescent) && ascent >= 1) { | |
156 ++descent; | |
157 --ascent; | |
158 } | |
159 #endif | |
160 } | 170 } |
161 | 171 |
162 #if OS(MACOSX) | 172 #if OS(MACOSX) |
163 // We are preserving this ascent hack to match Safari's ascent adjustment | 173 // We are preserving this ascent hack to match Safari's ascent adjustment |
164 // in their SimpleFontDataMac.mm, for details see crbug.com/445830. | 174 // in their SimpleFontDataMac.mm, for details see crbug.com/445830. |
165 // We need to adjust Times, Helvetica, and Courier to closely match the | 175 // We need to adjust Times, Helvetica, and Courier to closely match the |
166 // vertical metrics of their Microsoft counterparts that are the de facto | 176 // vertical metrics of their Microsoft counterparts that are the de facto |
167 // web standard. The AppKit adjustment of 20% is too big and is | 177 // web standard. The AppKit adjustment of 20% is too big and is |
168 // incorrectly added to line spacing, so we use a 15% adjustment instead | 178 // incorrectly added to line spacing, so we use a 15% adjustment instead |
169 // and add it to the ascent. | 179 // and add it to the ascent. |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const { | 391 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const { |
382 if (!m_platformData.size()) | 392 if (!m_platformData.size()) |
383 return 0; | 393 return 0; |
384 | 394 |
385 static_assert(sizeof(glyph) == 2, "Glyph id should not be truncated."); | 395 static_assert(sizeof(glyph) == 2, "Glyph id should not be truncated."); |
386 | 396 |
387 return SkiaTextMetrics(&m_paint).getSkiaWidthForGlyph(glyph); | 397 return SkiaTextMetrics(&m_paint).getSkiaWidthForGlyph(glyph); |
388 } | 398 } |
389 | 399 |
390 } // namespace blink | 400 } // namespace blink |
OLD | NEW |