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

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

Issue 1980913002: Unify glyph metrics to use the same Skia API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't remove glyphToBoundsMap yet Created 4 years, 4 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 14 matching lines...) Expand all
25 #define SimpleFontData_h 25 #define SimpleFontData_h
26 26
27 #include "platform/PlatformExport.h" 27 #include "platform/PlatformExport.h"
28 #include "platform/fonts/CustomFontData.h" 28 #include "platform/fonts/CustomFontData.h"
29 #include "platform/fonts/FontBaseline.h" 29 #include "platform/fonts/FontBaseline.h"
30 #include "platform/fonts/FontData.h" 30 #include "platform/fonts/FontData.h"
31 #include "platform/fonts/FontMetrics.h" 31 #include "platform/fonts/FontMetrics.h"
32 #include "platform/fonts/FontPlatformData.h" 32 #include "platform/fonts/FontPlatformData.h"
33 #include "platform/fonts/GlyphMetricsMap.h" 33 #include "platform/fonts/GlyphMetricsMap.h"
34 #include "platform/fonts/GlyphPageTreeNode.h" 34 #include "platform/fonts/GlyphPageTreeNode.h"
35 #include "platform/fonts/SimpleFontDataInlineHeaders.h"
35 #include "platform/fonts/TypesettingFeatures.h" 36 #include "platform/fonts/TypesettingFeatures.h"
36 #include "platform/fonts/opentype/OpenTypeVerticalData.h" 37 #include "platform/fonts/opentype/OpenTypeVerticalData.h"
37 #include "platform/geometry/FloatRect.h" 38 #include "platform/geometry/FloatRect.h"
38 #include "wtf/PtrUtil.h" 39 #include "wtf/PtrUtil.h"
39 #include "wtf/text/StringHash.h" 40 #include "wtf/text/StringHash.h"
41 #include <SkPaint.h>
40 #include <memory> 42 #include <memory>
41 43
42 namespace blink { 44 namespace blink {
43 45
44 class FontDescription; 46 class FontDescription;
45 47
46 enum FontDataVariant { AutoVariant, NormalVariant, SmallCapsVariant, EmphasisMar kVariant }; 48 enum FontDataVariant { AutoVariant, NormalVariant, SmallCapsVariant, EmphasisMar kVariant };
47 49
48 class PLATFORM_EXPORT SimpleFontData : public FontData { 50 class PLATFORM_EXPORT SimpleFontData : public FontData {
49 public: 51 public:
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 float sizePerUnit() const { return platformData().size() / (getFontMetrics() .unitsPerEm() ? getFontMetrics().unitsPerEm() : 1); } 90 float sizePerUnit() const { return platformData().size() / (getFontMetrics() .unitsPerEm() ? getFontMetrics().unitsPerEm() : 1); }
89 float internalLeading() const { return getFontMetrics().floatHeight() - plat formData().size(); } 91 float internalLeading() const { return getFontMetrics().floatHeight() - plat formData().size(); }
90 92
91 float maxCharWidth() const { return m_maxCharWidth; } 93 float maxCharWidth() const { return m_maxCharWidth; }
92 void setMaxCharWidth(float maxCharWidth) { m_maxCharWidth = maxCharWidth; } 94 void setMaxCharWidth(float maxCharWidth) { m_maxCharWidth = maxCharWidth; }
93 95
94 float avgCharWidth() const { return m_avgCharWidth; } 96 float avgCharWidth() const { return m_avgCharWidth; }
95 void setAvgCharWidth(float avgCharWidth) { m_avgCharWidth = avgCharWidth; } 97 void setAvgCharWidth(float avgCharWidth) { m_avgCharWidth = avgCharWidth; }
96 98
97 FloatRect boundsForGlyph(Glyph) const; 99 FloatRect boundsForGlyph(Glyph) const;
98 float widthForGlyph(Glyph glyph) const;
99 FloatRect platformBoundsForGlyph(Glyph) const; 100 FloatRect platformBoundsForGlyph(Glyph) const;
101 float widthForGlyph(Glyph) const;
100 float platformWidthForGlyph(Glyph) const; 102 float platformWidthForGlyph(Glyph) const;
101 103
102 float spaceWidth() const { return m_spaceWidth; } 104 float spaceWidth() const { return m_spaceWidth; }
103 void setSpaceWidth(float spaceWidth) { m_spaceWidth = spaceWidth; } 105 void setSpaceWidth(float spaceWidth) { m_spaceWidth = spaceWidth; }
104 106
105 Glyph spaceGlyph() const { return m_spaceGlyph; } 107 Glyph spaceGlyph() const { return m_spaceGlyph; }
106 void setSpaceGlyph(Glyph spaceGlyph) { m_spaceGlyph = spaceGlyph; } 108 void setSpaceGlyph(Glyph spaceGlyph) { m_spaceGlyph = spaceGlyph; }
107 Glyph zeroGlyph() const { return m_zeroGlyph; } 109 Glyph zeroGlyph() const { return m_zeroGlyph; }
108 void setZeroGlyph(Glyph zeroGlyph) { m_zeroGlyph = zeroGlyph; } 110 void setZeroGlyph(Glyph zeroGlyph) { m_zeroGlyph = zeroGlyph; }
109 111
(...skipping 26 matching lines...) Expand all
136 void platformInit(); 138 void platformInit();
137 void platformGlyphInit(); 139 void platformGlyphInit();
138 140
139 PassRefPtr<SimpleFontData> createScaledFontData(const FontDescription&, floa t scaleFactor) const; 141 PassRefPtr<SimpleFontData> createScaledFontData(const FontDescription&, floa t scaleFactor) const;
140 142
141 FontMetrics m_fontMetrics; 143 FontMetrics m_fontMetrics;
142 float m_maxCharWidth; 144 float m_maxCharWidth;
143 float m_avgCharWidth; 145 float m_avgCharWidth;
144 146
145 FontPlatformData m_platformData; 147 FontPlatformData m_platformData;
146
147 mutable std::unique_ptr<GlyphMetricsMap<FloatRect>> m_glyphToBoundsMap; 148 mutable std::unique_ptr<GlyphMetricsMap<FloatRect>> m_glyphToBoundsMap;
148 mutable GlyphMetricsMap<float> m_glyphToWidthMap; 149 mutable GlyphMetricsMap<float> m_glyphToWidthMap;
150 SkPaint m_paint;
149 151
150 bool m_isTextOrientationFallback; 152 bool m_isTextOrientationFallback;
151 RefPtr<OpenTypeVerticalData> m_verticalData; 153 RefPtr<OpenTypeVerticalData> m_verticalData;
152 bool m_hasVerticalGlyphs; 154 bool m_hasVerticalGlyphs;
153 155
154 Glyph m_spaceGlyph; 156 Glyph m_spaceGlyph;
155 float m_spaceWidth; 157 float m_spaceWidth;
156 Glyph m_zeroGlyph; 158 Glyph m_zeroGlyph;
157 159
158 GlyphData m_missingGlyphData; 160 GlyphData m_missingGlyphData;
(...skipping 16 matching lines...) Expand all
175 : forCustomFont(custom) 177 : forCustomFont(custom)
176 { 178 {
177 } 179 }
178 }; 180 };
179 181
180 mutable std::unique_ptr<DerivedFontData> m_derivedFontData; 182 mutable std::unique_ptr<DerivedFontData> m_derivedFontData;
181 183
182 RefPtr<CustomFontData> m_customFontData; 184 RefPtr<CustomFontData> m_customFontData;
183 }; 185 };
184 186
187
185 ALWAYS_INLINE FloatRect SimpleFontData::boundsForGlyph(Glyph glyph) const 188 ALWAYS_INLINE FloatRect SimpleFontData::boundsForGlyph(Glyph glyph) const
186 { 189 {
187 FloatRect bounds; 190 if (!m_platformData.size())
191 return FloatRect();
192
193 SkASSERT(sizeof(glyph) == 2); // compile-time assert
194
195 FloatRect boundsResult;
188 if (m_glyphToBoundsMap) { 196 if (m_glyphToBoundsMap) {
189 bounds = m_glyphToBoundsMap->metricsForGlyph(glyph); 197 boundsResult = m_glyphToBoundsMap->metricsForGlyph(glyph);
190 if (bounds.width() != cGlyphSizeUnknown) 198 if (boundsResult.width() != cGlyphSizeUnknown)
191 return bounds; 199 return boundsResult;
192 } 200 }
193 201
194 bounds = platformBoundsForGlyph(glyph); 202 boundsResult = platformBoundsForGlyph(glyph);
195 if (!m_glyphToBoundsMap) 203 if (!m_glyphToBoundsMap)
196 m_glyphToBoundsMap = wrapUnique(new GlyphMetricsMap<FloatRect>); 204 m_glyphToBoundsMap = wrapUnique(new GlyphMetricsMap<FloatRect>);
197 m_glyphToBoundsMap->setMetricsForGlyph(glyph, bounds); 205 m_glyphToBoundsMap->setMetricsForGlyph(glyph, boundsResult);
198 return bounds; 206
207 return boundsResult;
199 } 208 }
200 209
201 ALWAYS_INLINE float SimpleFontData::widthForGlyph(Glyph glyph) const 210 ALWAYS_INLINE float SimpleFontData::widthForGlyph(Glyph glyph) const
202 { 211 {
212 if (!m_platformData.size())
213 return 0;
214 SkASSERT(sizeof(glyph) == 2); // compile-time assert
kojii 2016/07/25 16:36:28 Our current style guide allows the use of static_a
drott 2016/07/26 07:49:35 Thanks, updated.
215
203 float width = m_glyphToWidthMap.metricsForGlyph(glyph); 216 float width = m_glyphToWidthMap.metricsForGlyph(glyph);
204 if (width != cGlyphSizeUnknown) 217 if (width != cGlyphSizeUnknown)
205 return width; 218 return width;
206 219
207 width = platformWidthForGlyph(glyph); 220 width = platformWidthForGlyph(glyph);
208 221
209 m_glyphToWidthMap.setMetricsForGlyph(glyph, width); 222 m_glyphToWidthMap.setMetricsForGlyph(glyph, width);
210 return width; 223 return width;
211 } 224 }
212 225
213 DEFINE_FONT_DATA_TYPE_CASTS(SimpleFontData, false); 226 DEFINE_FONT_DATA_TYPE_CASTS(SimpleFontData, false);
214 227
215 } // namespace blink 228 } // namespace blink
216 #endif // SimpleFontData_h 229 #endif // SimpleFontData_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698