Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: third_party/WebKit/Source/platform/fonts/SimpleFontData.cpp

Issue 2803483002: Adjust visual overflow rect for rounded/shifted ascent/descent (Closed)
Patch Set: - Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 overflowInflationForAscent = ascent < -metrics.fAscent ? 1 : 0;
149 int overflowInflationForDescent = descent < metrics.fDescent ? 1 : 0;
150 if (overflowInflationForDescent) {
151 #if OS(LINUX) || OS(ANDROID)
152 // When subpixel positioning is enabled, if the descent is rounded down,
153 // the descent part of the glyph may be truncated when displayed in a
154 // 'overflow: hidden' container. To avoid that, borrow 1 unit from the
155 // ascent when possible.
156 if (platformData().getFontRenderStyle().useSubpixelPositioning &&
157 ascent >= 1) {
158 ++descent;
159 --ascent;
160 // We should inflate overflow 1 more pixel for ascent instead.
161 overflowInflationForDescent = 0;
eae 2017/04/07 17:41:57 Why? The decent has already been inflated to accou
Xianzhu 2017/04/07 18:02:53 The descent is incremented above (line 158) so it'
162 ++overflowInflationForAscent;
163 }
164 #endif
147 } 165 }
148 #if OS(LINUX) || OS(ANDROID) 166 m_fontMetrics.setVisualOverflowInflations(overflowInflationForAscent,
149 // When subpixel positioning is enabled, if the descent is rounded down, the 167 overflowInflationForDescent);
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 } 168 }
161 169
162 #if OS(MACOSX) 170 #if OS(MACOSX)
163 // We are preserving this ascent hack to match Safari's ascent adjustment 171 // We are preserving this ascent hack to match Safari's ascent adjustment
164 // in their SimpleFontDataMac.mm, for details see crbug.com/445830. 172 // in their SimpleFontDataMac.mm, for details see crbug.com/445830.
165 // We need to adjust Times, Helvetica, and Courier to closely match the 173 // We need to adjust Times, Helvetica, and Courier to closely match the
166 // vertical metrics of their Microsoft counterparts that are the de facto 174 // vertical metrics of their Microsoft counterparts that are the de facto
167 // web standard. The AppKit adjustment of 20% is too big and is 175 // 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 176 // incorrectly added to line spacing, so we use a 15% adjustment instead
169 // and add it to the ascent. 177 // and add it to the ascent.
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const { 389 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const {
382 if (!m_platformData.size()) 390 if (!m_platformData.size())
383 return 0; 391 return 0;
384 392
385 static_assert(sizeof(glyph) == 2, "Glyph id should not be truncated."); 393 static_assert(sizeof(glyph) == 2, "Glyph id should not be truncated.");
386 394
387 return SkiaTextMetrics(&m_paint).getSkiaWidthForGlyph(glyph); 395 return SkiaTextMetrics(&m_paint).getSkiaWidthForGlyph(glyph);
388 } 396 }
389 397
390 } // namespace blink 398 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698