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

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

Issue 2643413002: Fix 'text-underline-position: under' to use em height ascent/descent (Closed)
Patch Set: Rebaseline Created 3 years, 7 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 * 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, 2008, 2010 Apple Inc. All rights reserved. 4 * Copyright (C) 2006, 2008, 2010 Apple Inc. All rights reserved.
5 * Copyright (C) 2007-2008 Torch Mobile, Inc. 5 * Copyright (C) 2007-2008 Torch Mobile, Inc.
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 FontMetrics& GetFontMetrics() { return font_metrics_; } 111 FontMetrics& GetFontMetrics() { return font_metrics_; }
112 const FontMetrics& GetFontMetrics() const { return font_metrics_; } 112 const FontMetrics& GetFontMetrics() const { return font_metrics_; }
113 float SizePerUnit() const { 113 float SizePerUnit() const {
114 return PlatformData().size() / 114 return PlatformData().size() /
115 (GetFontMetrics().UnitsPerEm() ? GetFontMetrics().UnitsPerEm() : 1); 115 (GetFontMetrics().UnitsPerEm() ? GetFontMetrics().UnitsPerEm() : 1);
116 } 116 }
117 float InternalLeading() const { 117 float InternalLeading() const {
118 return GetFontMetrics().FloatHeight() - PlatformData().size(); 118 return GetFontMetrics().FloatHeight() - PlatformData().size();
119 } 119 }
120 120
121 // "em height" metrics.
122 // https://drafts.css-houdini.org/font-metrics-api-1/#fontmetrics
123 LayoutUnit EmHeightAscent(FontBaseline = kAlphabeticBaseline) const;
124 LayoutUnit EmHeightDescent(FontBaseline = kAlphabeticBaseline) const;
125
121 float MaxCharWidth() const { return max_char_width_; } 126 float MaxCharWidth() const { return max_char_width_; }
122 void SetMaxCharWidth(float max_char_width) { 127 void SetMaxCharWidth(float max_char_width) {
123 max_char_width_ = max_char_width; 128 max_char_width_ = max_char_width;
124 } 129 }
125 130
126 float AvgCharWidth() const { return avg_char_width_; } 131 float AvgCharWidth() const { return avg_char_width_; }
127 void SetAvgCharWidth(float avg_char_width) { 132 void SetAvgCharWidth(float avg_char_width) {
128 avg_char_width_ = avg_char_width; 133 avg_char_width_ = avg_char_width;
129 } 134 }
130 135
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // Only used for testing. 185 // Only used for testing.
181 SimpleFontData(const FontPlatformData&, PassRefPtr<OpenTypeVerticalData>); 186 SimpleFontData(const FontPlatformData&, PassRefPtr<OpenTypeVerticalData>);
182 187
183 private: 188 private:
184 void PlatformInit(bool subpixel_ascent_descent); 189 void PlatformInit(bool subpixel_ascent_descent);
185 void PlatformGlyphInit(); 190 void PlatformGlyphInit();
186 191
187 PassRefPtr<SimpleFontData> CreateScaledFontData(const FontDescription&, 192 PassRefPtr<SimpleFontData> CreateScaledFontData(const FontDescription&,
188 float scale_factor) const; 193 float scale_factor) const;
189 194
195 void ComputeEmHeightMetrics() const;
196 bool NormalizeEmHeightMetrics(float, float) const;
197
190 FontMetrics font_metrics_; 198 FontMetrics font_metrics_;
191 float max_char_width_; 199 float max_char_width_;
192 float avg_char_width_; 200 float avg_char_width_;
193 201
194 FontPlatformData platform_data_; 202 FontPlatformData platform_data_;
195 SkPaint paint_; 203 SkPaint paint_;
196 204
197 RefPtr<OpenTypeVerticalData> vertical_data_; 205 RefPtr<OpenTypeVerticalData> vertical_data_;
198 206
199 Glyph space_glyph_; 207 Glyph space_glyph_;
(...skipping 24 matching lines...) Expand all
224 232
225 unsigned is_text_orientation_fallback_ : 1; 233 unsigned is_text_orientation_fallback_ : 1;
226 unsigned has_vertical_glyphs_ : 1; 234 unsigned has_vertical_glyphs_ : 1;
227 235
228 // These are set to non-zero when ascent or descent is rounded or shifted 236 // These are set to non-zero when ascent or descent is rounded or shifted
229 // to be smaller than the actual ascent or descent. When calculating visual 237 // to be smaller than the actual ascent or descent. When calculating visual
230 // overflows, we should add the inflations. 238 // overflows, we should add the inflations.
231 unsigned visual_overflow_inflation_for_ascent_ : 2; 239 unsigned visual_overflow_inflation_for_ascent_ : 2;
232 unsigned visual_overflow_inflation_for_descent_ : 2; 240 unsigned visual_overflow_inflation_for_descent_ : 2;
233 241
242 mutable LayoutUnit em_height_ascent_;
243 mutable LayoutUnit em_height_descent_;
244
234 // See discussion on crbug.com/631032 and Skiaissue 245 // See discussion on crbug.com/631032 and Skiaissue
235 // https://bugs.chromium.org/p/skia/issues/detail?id=5328 : 246 // https://bugs.chromium.org/p/skia/issues/detail?id=5328 :
236 // On Mac we're still using path based glyph metrics, and they seem to be 247 // On Mac we're still using path based glyph metrics, and they seem to be
237 // too slow to be able to remove the caching layer we have here. 248 // too slow to be able to remove the caching layer we have here.
238 #if OS(MACOSX) 249 #if OS(MACOSX)
239 mutable std::unique_ptr<GlyphMetricsMap<FloatRect>> glyph_to_bounds_map_; 250 mutable std::unique_ptr<GlyphMetricsMap<FloatRect>> glyph_to_bounds_map_;
240 mutable GlyphMetricsMap<float> glyph_to_width_map_; 251 mutable GlyphMetricsMap<float> glyph_to_width_map_;
241 #endif 252 #endif
242 }; 253 };
243 254
(...skipping 29 matching lines...) Expand all
273 284
274 glyph_to_width_map_.SetMetricsForGlyph(glyph, width); 285 glyph_to_width_map_.SetMetricsForGlyph(glyph, width);
275 return width; 286 return width;
276 #endif 287 #endif
277 } 288 }
278 289
279 DEFINE_FONT_DATA_TYPE_CASTS(SimpleFontData, false); 290 DEFINE_FONT_DATA_TYPE_CASTS(SimpleFontData, false);
280 291
281 } // namespace blink 292 } // namespace blink
282 #endif // SimpleFontData_h 293 #endif // SimpleFontData_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698