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

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: Removed a spurious header line 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 19 matching lines...) Expand all
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/TypesettingFeatures.h" 35 #include "platform/fonts/TypesettingFeatures.h"
36 #include "platform/fonts/opentype/OpenTypeVerticalData.h" 36 #include "platform/fonts/opentype/OpenTypeVerticalData.h"
37 #include "platform/geometry/FloatRect.h" 37 #include "platform/geometry/FloatRect.h"
38 #include "wtf/PtrUtil.h" 38 #include "wtf/PtrUtil.h"
39 #include "wtf/text/StringHash.h" 39 #include "wtf/text/StringHash.h"
40 #include <SkPaint.h>
40 #include <memory> 41 #include <memory>
41 42
42 namespace blink { 43 namespace blink {
43 44
44 class FontDescription; 45 class FontDescription;
45 46
46 enum FontDataVariant { AutoVariant, NormalVariant, SmallCapsVariant, EmphasisMar kVariant }; 47 enum FontDataVariant { AutoVariant, NormalVariant, SmallCapsVariant, EmphasisMar kVariant };
47 48
48 class PLATFORM_EXPORT SimpleFontData : public FontData { 49 class PLATFORM_EXPORT SimpleFontData : public FontData {
49 public: 50 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); } 89 float sizePerUnit() const { return platformData().size() / (getFontMetrics() .unitsPerEm() ? getFontMetrics().unitsPerEm() : 1); }
89 float internalLeading() const { return getFontMetrics().floatHeight() - plat formData().size(); } 90 float internalLeading() const { return getFontMetrics().floatHeight() - plat formData().size(); }
90 91
91 float maxCharWidth() const { return m_maxCharWidth; } 92 float maxCharWidth() const { return m_maxCharWidth; }
92 void setMaxCharWidth(float maxCharWidth) { m_maxCharWidth = maxCharWidth; } 93 void setMaxCharWidth(float maxCharWidth) { m_maxCharWidth = maxCharWidth; }
93 94
94 float avgCharWidth() const { return m_avgCharWidth; } 95 float avgCharWidth() const { return m_avgCharWidth; }
95 void setAvgCharWidth(float avgCharWidth) { m_avgCharWidth = avgCharWidth; } 96 void setAvgCharWidth(float avgCharWidth) { m_avgCharWidth = avgCharWidth; }
96 97
97 FloatRect boundsForGlyph(Glyph) const; 98 FloatRect boundsForGlyph(Glyph) const;
98 float widthForGlyph(Glyph glyph) const;
99 FloatRect platformBoundsForGlyph(Glyph) const; 99 FloatRect platformBoundsForGlyph(Glyph) const;
100 float widthForGlyph(Glyph) const;
100 float platformWidthForGlyph(Glyph) const; 101 float platformWidthForGlyph(Glyph) const;
101 102
102 float spaceWidth() const { return m_spaceWidth; } 103 float spaceWidth() const { return m_spaceWidth; }
103 void setSpaceWidth(float spaceWidth) { m_spaceWidth = spaceWidth; } 104 void setSpaceWidth(float spaceWidth) { m_spaceWidth = spaceWidth; }
104 105
105 Glyph spaceGlyph() const { return m_spaceGlyph; } 106 Glyph spaceGlyph() const { return m_spaceGlyph; }
106 void setSpaceGlyph(Glyph spaceGlyph) { m_spaceGlyph = spaceGlyph; } 107 void setSpaceGlyph(Glyph spaceGlyph) { m_spaceGlyph = spaceGlyph; }
107 Glyph zeroGlyph() const { return m_zeroGlyph; } 108 Glyph zeroGlyph() const { return m_zeroGlyph; }
108 void setZeroGlyph(Glyph zeroGlyph) { m_zeroGlyph = zeroGlyph; } 109 void setZeroGlyph(Glyph zeroGlyph) { m_zeroGlyph = zeroGlyph; }
109 110
(...skipping 26 matching lines...) Expand all
136 void platformInit(); 137 void platformInit();
137 void platformGlyphInit(); 138 void platformGlyphInit();
138 139
139 PassRefPtr<SimpleFontData> createScaledFontData(const FontDescription&, floa t scaleFactor) const; 140 PassRefPtr<SimpleFontData> createScaledFontData(const FontDescription&, floa t scaleFactor) const;
140 141
141 FontMetrics m_fontMetrics; 142 FontMetrics m_fontMetrics;
142 float m_maxCharWidth; 143 float m_maxCharWidth;
143 float m_avgCharWidth; 144 float m_avgCharWidth;
144 145
145 FontPlatformData m_platformData; 146 FontPlatformData m_platformData;
146
147 mutable std::unique_ptr<GlyphMetricsMap<FloatRect>> m_glyphToBoundsMap; 147 mutable std::unique_ptr<GlyphMetricsMap<FloatRect>> m_glyphToBoundsMap;
148 mutable GlyphMetricsMap<float> m_glyphToWidthMap; 148 mutable GlyphMetricsMap<float> m_glyphToWidthMap;
149 SkPaint m_paint;
149 150
150 bool m_isTextOrientationFallback; 151 bool m_isTextOrientationFallback;
151 RefPtr<OpenTypeVerticalData> m_verticalData; 152 RefPtr<OpenTypeVerticalData> m_verticalData;
152 bool m_hasVerticalGlyphs; 153 bool m_hasVerticalGlyphs;
153 154
154 Glyph m_spaceGlyph; 155 Glyph m_spaceGlyph;
155 float m_spaceWidth; 156 float m_spaceWidth;
156 Glyph m_zeroGlyph; 157 Glyph m_zeroGlyph;
157 158
158 GlyphData m_missingGlyphData; 159 GlyphData m_missingGlyphData;
(...skipping 16 matching lines...) Expand all
175 : forCustomFont(custom) 176 : forCustomFont(custom)
176 { 177 {
177 } 178 }
178 }; 179 };
179 180
180 mutable std::unique_ptr<DerivedFontData> m_derivedFontData; 181 mutable std::unique_ptr<DerivedFontData> m_derivedFontData;
181 182
182 RefPtr<CustomFontData> m_customFontData; 183 RefPtr<CustomFontData> m_customFontData;
183 }; 184 };
184 185
186
185 ALWAYS_INLINE FloatRect SimpleFontData::boundsForGlyph(Glyph glyph) const 187 ALWAYS_INLINE FloatRect SimpleFontData::boundsForGlyph(Glyph glyph) const
186 { 188 {
187 FloatRect bounds; 189 if (!m_platformData.size())
190 return FloatRect();
191
192 static_assert(sizeof(glyph) == 2, "Glyph id should not be truncated.");
193
194 FloatRect boundsResult;
188 if (m_glyphToBoundsMap) { 195 if (m_glyphToBoundsMap) {
189 bounds = m_glyphToBoundsMap->metricsForGlyph(glyph); 196 boundsResult = m_glyphToBoundsMap->metricsForGlyph(glyph);
190 if (bounds.width() != cGlyphSizeUnknown) 197 if (boundsResult.width() != cGlyphSizeUnknown)
191 return bounds; 198 return boundsResult;
192 } 199 }
193 200
194 bounds = platformBoundsForGlyph(glyph); 201 boundsResult = platformBoundsForGlyph(glyph);
195 if (!m_glyphToBoundsMap) 202 if (!m_glyphToBoundsMap)
196 m_glyphToBoundsMap = wrapUnique(new GlyphMetricsMap<FloatRect>); 203 m_glyphToBoundsMap = wrapUnique(new GlyphMetricsMap<FloatRect>);
197 m_glyphToBoundsMap->setMetricsForGlyph(glyph, bounds); 204 m_glyphToBoundsMap->setMetricsForGlyph(glyph, boundsResult);
198 return bounds; 205
206 return boundsResult;
199 } 207 }
200 208
201 ALWAYS_INLINE float SimpleFontData::widthForGlyph(Glyph glyph) const 209 ALWAYS_INLINE float SimpleFontData::widthForGlyph(Glyph glyph) const
202 { 210 {
211 if (!m_platformData.size())
212 return 0;
213 static_assert(sizeof(glyph) == 2, "Glyph id should not be truncated.");
214
203 float width = m_glyphToWidthMap.metricsForGlyph(glyph); 215 float width = m_glyphToWidthMap.metricsForGlyph(glyph);
204 if (width != cGlyphSizeUnknown) 216 if (width != cGlyphSizeUnknown)
205 return width; 217 return width;
206 218
207 width = platformWidthForGlyph(glyph); 219 width = platformWidthForGlyph(glyph);
208 220
209 m_glyphToWidthMap.setMetricsForGlyph(glyph, width); 221 m_glyphToWidthMap.setMetricsForGlyph(glyph, width);
210 return width; 222 return width;
211 } 223 }
212 224
213 DEFINE_FONT_DATA_TYPE_CASTS(SimpleFontData, false); 225 DEFINE_FONT_DATA_TYPE_CASTS(SimpleFontData, false);
214 226
215 } // namespace blink 227 } // namespace blink
216 #endif // SimpleFontData_h 228 #endif // SimpleFontData_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/blink_platform.gypi ('k') | third_party/WebKit/Source/platform/fonts/SimpleFontData.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698