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

Side by Side Diff: third_party/WebKit/WebCore/platform/graphics/SimpleFontData.cpp

Issue 18529: Removing unneeded code from SimpleFontData. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2008 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2005, 2008 Apple Computer, 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 SimpleFontData::SimpleFontData(const FontPlatformData& f, bool customFont, bool loading, SVGFontData* svgFontData) 45 SimpleFontData::SimpleFontData(const FontPlatformData& f, bool customFont, bool loading, SVGFontData* svgFontData)
46 : m_unitsPerEm(defaultUnitsPerEm) 46 : m_unitsPerEm(defaultUnitsPerEm)
47 , m_font(f) 47 , m_font(f)
48 , m_treatAsFixedPitch(false) 48 , m_treatAsFixedPitch(false)
49 #if ENABLE(SVG_FONTS) 49 #if ENABLE(SVG_FONTS)
50 , m_svgFontData(svgFontData) 50 , m_svgFontData(svgFontData)
51 #endif 51 #endif
52 , m_isCustomFont(customFont) 52 , m_isCustomFont(customFont)
53 , m_isLoading(loading) 53 , m_isLoading(loading)
54 , m_smallCapsFontData(0) 54 , m_smallCapsFontData(0)
55 , m_zeroWidthFontData(new ZeroWidthFontData())
56 , m_cjkWidthFontData(new CJKWidthFontData())
57 { 55 {
58 #if ENABLE(SVG_FONTS) 56 #if ENABLE(SVG_FONTS)
59 if (SVGFontFaceElement* svgFontFaceElement = svgFontData ? svgFontData->svgF ontFaceElement() : 0) { 57 if (SVGFontFaceElement* svgFontFaceElement = svgFontData ? svgFontData->svgF ontFaceElement() : 0) {
60 m_unitsPerEm = svgFontFaceElement->unitsPerEm(); 58 m_unitsPerEm = svgFontFaceElement->unitsPerEm();
61 59
62 double scale = f.size(); 60 double scale = f.size();
63 if (m_unitsPerEm) 61 if (m_unitsPerEm)
64 scale /= m_unitsPerEm; 62 scale /= m_unitsPerEm;
65 63
66 m_ascent = static_cast<int>(svgFontFaceElement->ascent() * scale); 64 m_ascent = static_cast<int>(svgFontFaceElement->ascent() * scale);
67 m_descent = static_cast<int>(svgFontFaceElement->descent() * scale); 65 m_descent = static_cast<int>(svgFontFaceElement->descent() * scale);
68 // TODO(ojan): What should SVG fonts use for avgCharWidth/maxCharWidth? 66 // TODO(ojan): What should SVG fonts use for avgCharWidth/maxCharWidth?
69 // This is currently only used in RenderTextControl.cpp for the width 67 // This is currently only used in RenderTextControl.cpp for the width
70 // of textareas with a non-fixed width. 68 // of textareas with a non-fixed width.
71 m_avgCharWidth = 0; 69 m_avgCharWidth = 0;
72 m_maxCharWidth = 0; 70 m_maxCharWidth = 0;
73 m_xHeight = static_cast<int>(svgFontFaceElement->xHeight() * scale); 71 m_xHeight = static_cast<int>(svgFontFaceElement->xHeight() * scale);
74 m_lineGap = 0.1f * f.size(); 72 m_lineGap = 0.1f * f.size();
75 m_lineSpacing = m_ascent + m_descent + m_lineGap; 73 m_lineSpacing = m_ascent + m_descent + m_lineGap;
76 74
77 m_spaceGlyph = 0; 75 m_spaceGlyph = 0;
78 m_spaceWidth = 0; 76 m_spaceWidth = 0;
79 m_adjustedSpaceWidth = 0; 77 m_adjustedSpaceWidth = 0;
80 determinePitch(); 78 determinePitch();
81 m_missingGlyphData.fontData = this; 79 m_missingGlyphData.fontData = this;
82 m_missingGlyphData.glyph = 0; 80 m_missingGlyphData.glyph = 0;
83 m_zeroWidthFontData->init(this);
84 m_cjkWidthFontData->init(this);
85 return; 81 return;
86 } 82 }
87 #endif 83 #endif
88 84
89 platformInit(); 85 platformInit();
90 platformGlyphInit(); 86 platformGlyphInit();
91 } 87 }
92 88
93 #if !PLATFORM(QT) 89 #if !PLATFORM(QT)
94 void SimpleFontData::platformGlyphInit() 90 void SimpleFontData::platformGlyphInit()
95 { 91 {
96 GlyphPage* glyphPageZero = GlyphPageTreeNode::getRootChild(this, 0)->page(); 92 GlyphPage* glyphPageZero = GlyphPageTreeNode::getRootChild(this, 0)->page();
97 if (!glyphPageZero) { 93 if (!glyphPageZero) {
98 LOG_ERROR("Failed to get glyph page zero."); 94 LOG_ERROR("Failed to get glyph page zero.");
99 m_spaceGlyph = 0; 95 m_spaceGlyph = 0;
100 m_spaceWidth = 0; 96 m_spaceWidth = 0;
101 m_adjustedSpaceWidth = 0; 97 m_adjustedSpaceWidth = 0;
102 determinePitch(); 98 determinePitch();
103 m_missingGlyphData.fontData = this; 99 m_missingGlyphData.fontData = this;
104 m_missingGlyphData.glyph = 0; 100 m_missingGlyphData.glyph = 0;
105 m_zeroWidthFontData->init(this);
106 m_cjkWidthFontData->init(this);
107 return; 101 return;
108 } 102 }
109 103
110 // Nasty hack to determine if we should round or ceil space widths. 104 // Nasty hack to determine if we should round or ceil space widths.
111 // If the font is monospace or fake monospace we ceil to ensure that 105 // If the font is monospace or fake monospace we ceil to ensure that
112 // every character and the space are the same width. Otherwise we round. 106 // every character and the space are the same width. Otherwise we round.
113 static const UChar32 space_char = ' '; 107 static const UChar32 space_char = ' ';
114 m_spaceGlyph = glyphPageZero->glyphDataForCharacter(space_char).glyph; 108 m_spaceGlyph = glyphPageZero->glyphDataForCharacter(space_char).glyph;
115 float width = widthForGlyph(m_spaceGlyph); 109 float width = widthForGlyph(m_spaceGlyph);
116 m_spaceWidth = width; 110 m_spaceWidth = width;
117 determinePitch(); 111 determinePitch();
118 m_adjustedSpaceWidth = m_treatAsFixedPitch ? ceilf(width) : roundf(width); 112 m_adjustedSpaceWidth = m_treatAsFixedPitch ? ceilf(width) : roundf(width);
119 113
120 // TODO(dglazkov): Investigate and implement across platforms, if needed
121 #if PLATFORM(WIN_OS)
122 // ZERO WIDTH SPACES are explicitly mapped to share the glyph
123 // with SPACE (with width adjusted to 0) during GlyphPage::fill
124 // This is currently only implemented for Windows port. The FontData
125 // remapping may very well be needed for other platforms.
126 #else
127 // Force the glyph for ZERO WIDTH SPACE to have zero width, unless it is sha red with SPACE. 114 // Force the glyph for ZERO WIDTH SPACE to have zero width, unless it is sha red with SPACE.
128 // Helvetica is an example of a non-zero width ZERO WIDTH SPACE glyph. 115 // Helvetica is an example of a non-zero width ZERO WIDTH SPACE glyph.
129 // See <http://bugs.webkit.org/show_bug.cgi?id=13178> 116 // See <http://bugs.webkit.org/show_bug.cgi?id=13178>
130 // Ask for the glyph for 0 to avoid paging in ZERO WIDTH SPACE. Control char acters, including 0, 117 // Ask for the glyph for 0 to avoid paging in ZERO WIDTH SPACE. Control char acters, including 0,
131 // are mapped to the ZERO WIDTH SPACE glyph. 118 // are mapped to the ZERO WIDTH SPACE glyph.
132 Glyph zeroWidthSpaceGlyph = glyphPageZero->glyphDataForCharacter(0).glyph; 119 Glyph zeroWidthSpaceGlyph = glyphPageZero->glyphDataForCharacter(0).glyph;
133 if (zeroWidthSpaceGlyph) { 120 if (zeroWidthSpaceGlyph) {
134 if (zeroWidthSpaceGlyph != m_spaceGlyph) 121 if (zeroWidthSpaceGlyph != m_spaceGlyph)
135 m_glyphToWidthMap.setWidthForGlyph(zeroWidthSpaceGlyph, 0); 122 m_glyphToWidthMap.setWidthForGlyph(zeroWidthSpaceGlyph, 0);
136 else 123 else
137 LOG_ERROR("Font maps SPACE and ZERO WIDTH SPACE to the same glyph. G lyph width not overridden."); 124 LOG_ERROR("Font maps SPACE and ZERO WIDTH SPACE to the same glyph. G lyph width not overridden.");
138 } 125 }
139 #endif
140 126
141 m_missingGlyphData.fontData = this; 127 m_missingGlyphData.fontData = this;
142 m_missingGlyphData.glyph = 0; 128 m_missingGlyphData.glyph = 0;
143 m_zeroWidthFontData->init(this);
144 m_cjkWidthFontData->init(this);
145 } 129 }
146 #endif 130 #endif
147 131
148 SimpleFontData::SimpleFontData()
149 : m_treatAsFixedPitch(false)
150 #if ENABLE(SVG_FONTS)
151 , m_svgFontData(0)
152 #endif
153 , m_isCustomFont(0)
154 , m_isLoading(0)
155 , m_smallCapsFontData(0)
156 {
157 }
158
159 SimpleFontData::~SimpleFontData() 132 SimpleFontData::~SimpleFontData()
160 { 133 {
161 if (!isCustomFont()) { 134 if (!isCustomFont()) {
162 if (m_smallCapsFontData) 135 if (m_smallCapsFontData)
163 fontCache()->releaseFontData(m_smallCapsFontData); 136 fontCache()->releaseFontData(m_smallCapsFontData);
164 GlyphPageTreeNode::pruneTreeFontData(this); 137 GlyphPageTreeNode::pruneTreeFontData(this);
165 } 138 }
166 139
167 #if ENABLE(SVG_FONTS) 140 #if ENABLE(SVG_FONTS)
168 if (!m_svgFontData || !m_svgFontData->svgFontFaceElement()) 141 if (!m_svgFontData || !m_svgFontData->svgFontFaceElement())
(...skipping 18 matching lines...) Expand all
187 const SimpleFontData* SimpleFontData::fontDataForCharacter(UChar32) const 160 const SimpleFontData* SimpleFontData::fontDataForCharacter(UChar32) const
188 { 161 {
189 return this; 162 return this;
190 } 163 }
191 164
192 bool SimpleFontData::isSegmented() const 165 bool SimpleFontData::isSegmented() const
193 { 166 {
194 return false; 167 return false;
195 } 168 }
196 169
197 const SimpleFontData* SimpleFontData::zeroWidthFontData() const
198 {
199 return m_zeroWidthFontData.get();
200 }
201
202 const SimpleFontData* SimpleFontData::cjkWidthFontData() const
203 {
204 return m_cjkWidthFontData.get();
205 }
206
207 void ZeroWidthFontData::init(SimpleFontData* fontData)
208 {
209 m_font = fontData->m_font;
210 m_smallCapsFontData = fontData->m_smallCapsFontData;
211 m_ascent = fontData->m_ascent;
212 m_descent = fontData->m_descent;
213 m_lineSpacing = fontData->m_lineSpacing;
214 m_lineGap = fontData->m_lineGap;
215 m_maxCharWidth = 0;
216 m_avgCharWidth = 0;
217 m_xHeight = fontData->m_xHeight;
218 m_unitsPerEm = fontData->m_unitsPerEm;
219 m_spaceWidth = 0;
220 m_spaceGlyph = 0;
221 m_adjustedSpaceWidth = fontData->m_adjustedSpaceWidth;
222 #if PLATFORM(WIN)
223 m_scriptCache = 0;
224 m_scriptFontProperties = 0;
225 #elif USE(ATSUI)
226 m_ATSUStyle = 0;
227 m_ATSUStyleInitialized = false;
228 m_ATSUMirrors = false;
229 m_checkedShapesArabic = false;
230 m_shapesArabic = false;
231 #endif
232 }
233
234 CJKWidthFontData::CJKWidthFontData()
235 : m_cjkGlyphWidth(cGlyphWidthUnknown)
236 {
237 }
238
239 float CJKWidthFontData::widthForGlyph(Glyph glyph) const
240 {
241 if (m_cjkGlyphWidth != cGlyphWidthUnknown)
242 return m_cjkGlyphWidth;
243
244 float width = platformWidthForGlyph(glyph);
245 m_cjkGlyphWidth = width;
246
247 #ifndef NDEBUG
248 // Test our optimization that assuming all CGK glyphs have the same width
249 const float actual_width = platformWidthForGlyph(glyph);
250 ASSERT((cGlyphWidthUnknown == width) || (actual_width == width));
251 #endif
252
253 return width;
254 }
255
256 // static
257 // TODO(dglazkov): Move to Font::isCJKCodePoint for consistency
258 bool SimpleFontData::isCJKCodePoint(UChar32 c)
259 {
260 // AC00..D7AF; Hangul Syllables
261 if ((0xAC00 <= c) && (c <= 0xD7AF))
262 return true;
263
264 // CJK ideographs
265 UErrorCode errorCode = U_ZERO_ERROR; // has to be initialized.
266 return uscript_getScript(c, &errorCode) == USCRIPT_HAN &&
267 U_SUCCESS(errorCode);
268 }
269
270
271 } // namespace WebCore 170 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698