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

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

Issue 2819953002: 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
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/SimpleFontData.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 static const size_t maxVDMXTableSize = 1024 * 1024; // 1 MB 55 static const size_t maxVDMXTableSize = 1024 * 1024; // 1 MB
56 #endif 56 #endif
57 57
58 SimpleFontData::SimpleFontData(const FontPlatformData& platformData, 58 SimpleFontData::SimpleFontData(const FontPlatformData& platformData,
59 PassRefPtr<CustomFontData> customData, 59 PassRefPtr<CustomFontData> customData,
60 bool isTextOrientationFallback, 60 bool isTextOrientationFallback,
61 bool subpixelAscentDescent) 61 bool subpixelAscentDescent)
62 : m_maxCharWidth(-1), 62 : m_maxCharWidth(-1),
63 m_avgCharWidth(-1), 63 m_avgCharWidth(-1),
64 m_platformData(platformData), 64 m_platformData(platformData),
65 m_verticalData(nullptr),
66 m_customFontData(customData),
65 m_isTextOrientationFallback(isTextOrientationFallback), 67 m_isTextOrientationFallback(isTextOrientationFallback),
66 m_verticalData(nullptr),
67 m_hasVerticalGlyphs(false), 68 m_hasVerticalGlyphs(false),
68 m_customFontData(customData) { 69 visual_overflow_inflation_for_ascent_(0),
70 visual_overflow_inflation_for_descent_(0) {
69 platformInit(subpixelAscentDescent); 71 platformInit(subpixelAscentDescent);
70 platformGlyphInit(); 72 platformGlyphInit();
71 if (platformData.isVerticalAnyUpright() && !isTextOrientationFallback) { 73 if (platformData.isVerticalAnyUpright() && !isTextOrientationFallback) {
72 m_verticalData = platformData.verticalData(); 74 m_verticalData = platformData.verticalData();
73 m_hasVerticalGlyphs = 75 m_hasVerticalGlyphs =
74 m_verticalData.get() && m_verticalData->hasVerticalMetrics(); 76 m_verticalData.get() && m_verticalData->hasVerticalMetrics();
75 } 77 }
76 } 78 }
77 79
78 SimpleFontData::SimpleFontData(PassRefPtr<CustomFontData> customData, 80 SimpleFontData::SimpleFontData(PassRefPtr<CustomFontData> customData,
79 float fontSize, 81 float fontSize,
80 bool syntheticBold, 82 bool syntheticBold,
81 bool syntheticItalic) 83 bool syntheticItalic)
82 : m_platformData( 84 : m_platformData(
83 FontPlatformData(fontSize, syntheticBold, syntheticItalic)), 85 FontPlatformData(fontSize, syntheticBold, syntheticItalic)),
86 m_verticalData(nullptr),
87 m_customFontData(customData),
84 m_isTextOrientationFallback(false), 88 m_isTextOrientationFallback(false),
85 m_verticalData(nullptr),
86 m_hasVerticalGlyphs(false), 89 m_hasVerticalGlyphs(false),
87 m_customFontData(customData) {} 90 visual_overflow_inflation_for_ascent_(0),
91 visual_overflow_inflation_for_descent_(0) {}
88 92
89 void SimpleFontData::platformInit(bool subpixelAscentDescent) { 93 void SimpleFontData::platformInit(bool subpixelAscentDescent) {
90 if (!m_platformData.size()) { 94 if (!m_platformData.size()) {
91 m_fontMetrics.reset(); 95 m_fontMetrics.reset();
92 m_avgCharWidth = 0; 96 m_avgCharWidth = 0;
93 m_maxCharWidth = 0; 97 m_maxCharWidth = 0;
94 return; 98 return;
95 } 99 }
96 100
97 SkPaint::FontMetrics metrics; 101 SkPaint::FontMetrics metrics;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 float ascent; 134 float ascent;
131 float descent; 135 float descent;
132 136
133 // Beware those who step here: This code is designed to match Win32 font 137 // Beware those who step here: This code is designed to match Win32 font
134 // metrics *exactly* except: 138 // metrics *exactly* except:
135 // - the adjustment of ascent/descent on Linux/Android 139 // - the adjustment of ascent/descent on Linux/Android
136 // - metrics.fAscent and .fDesscent are not rounded to int for tiny fonts 140 // - metrics.fAscent and .fDesscent are not rounded to int for tiny fonts
137 if (isVDMXValid) { 141 if (isVDMXValid) {
138 ascent = vdmxAscent; 142 ascent = vdmxAscent;
139 descent = -vdmxDescent; 143 descent = -vdmxDescent;
140 } else { 144 } else if (subpixelAscentDescent &&
145 (-metrics.fAscent < 3 ||
146 -metrics.fAscent + metrics.fDescent < 2)) {
141 // For tiny fonts, the rounding of fAscent and fDescent results in equal 147 // For tiny fonts, the rounding of fAscent and fDescent results in equal
142 // baseline for different types of text baselines (crbug.com/338908). 148 // baseline for different types of text baselines (crbug.com/338908).
143 // Please see CanvasRenderingContext2D::getFontBaseline for the heuristic. 149 // Please see CanvasRenderingContext2D::getFontBaseline for the heuristic.
144 if (subpixelAscentDescent && 150 ascent = -metrics.fAscent;
145 (-metrics.fAscent < 3 || -metrics.fAscent + metrics.fDescent < 2)) { 151 descent = metrics.fDescent;
146 ascent = -metrics.fAscent; 152 } else {
147 descent = metrics.fDescent; 153 ascent = SkScalarRoundToScalar(-metrics.fAscent);
148 } else { 154 descent = SkScalarRoundToScalar(metrics.fDescent);
149 ascent = SkScalarRoundToScalar(-metrics.fAscent); 155
150 descent = SkScalarRoundToScalar(metrics.fDescent); 156 if (ascent < -metrics.fAscent)
157 visual_overflow_inflation_for_ascent_ = 1;
158 if (descent < metrics.fDescent) {
159 visual_overflow_inflation_for_descent_ = 1;
160 #if OS(LINUX) || OS(ANDROID)
161 // When subpixel positioning is enabled, if the descent is rounded down,
162 // the descent part of the glyph may be truncated when displayed in a
163 // 'overflow: hidden' container. To avoid that, borrow 1 unit from the
164 // ascent when possible.
165 if (platformData().getFontRenderStyle().useSubpixelPositioning &&
166 ascent >= 1) {
167 ++descent;
168 --ascent;
169 // We should inflate overflow 1 more pixel for ascent instead.
170 visual_overflow_inflation_for_descent_ = 0;
171 ++visual_overflow_inflation_for_ascent_;
172 }
173 #endif
151 } 174 }
152 #if OS(LINUX) || OS(ANDROID)
153 // When subpixel positioning is enabled, if the descent is rounded down, the
154 // descent part of the glyph may be truncated when displayed in a 'overflow:
155 // hidden' container. To avoid that, borrow 1 unit from the ascent when
156 // possible.
157 // FIXME: This can be removed if sub-pixel ascent/descent is supported.
158 if (platformData().getFontRenderStyle().useSubpixelPositioning &&
159 descent < SkScalarToFloat(metrics.fDescent) && ascent >= 1) {
160 ++descent;
161 --ascent;
162 }
163 #endif
164 } 175 }
165 176
166 #if OS(MACOSX) 177 #if OS(MACOSX)
167 // We are preserving this ascent hack to match Safari's ascent adjustment 178 // We are preserving this ascent hack to match Safari's ascent adjustment
168 // in their SimpleFontDataMac.mm, for details see crbug.com/445830. 179 // in their SimpleFontDataMac.mm, for details see crbug.com/445830.
169 // We need to adjust Times, Helvetica, and Courier to closely match the 180 // We need to adjust Times, Helvetica, and Courier to closely match the
170 // vertical metrics of their Microsoft counterparts that are the de facto 181 // vertical metrics of their Microsoft counterparts that are the de facto
171 // web standard. The AppKit adjustment of 20% is too big and is 182 // web standard. The AppKit adjustment of 20% is too big and is
172 // incorrectly added to line spacing, so we use a 15% adjustment instead 183 // incorrectly added to line spacing, so we use a 15% adjustment instead
173 // and add it to the ascent. 184 // and add it to the ascent.
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const { 396 float SimpleFontData::platformWidthForGlyph(Glyph glyph) const {
386 if (!m_platformData.size()) 397 if (!m_platformData.size())
387 return 0; 398 return 0;
388 399
389 static_assert(sizeof(glyph) == 2, "Glyph id should not be truncated."); 400 static_assert(sizeof(glyph) == 2, "Glyph id should not be truncated.");
390 401
391 return SkiaTextMetrics(&m_paint).getSkiaWidthForGlyph(glyph); 402 return SkiaTextMetrics(&m_paint).getSkiaWidthForGlyph(glyph);
392 } 403 }
393 404
394 } // namespace blink 405 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/SimpleFontData.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698