OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2000 Dirk Mueller (mueller@kde.org) | 4 * (C) 2000 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2003, 2006, 2010, 2011 Apple Inc. All rights reserved. | 5 * Copyright (C) 2003, 2006, 2010, 2011 Apple Inc. All rights reserved. |
6 * Copyright (c) 2007, 2008, 2010 Google Inc. All rights reserved. | 6 * Copyright (c) 2007, 2008, 2010 Google Inc. All rights reserved. |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #include "wtf/MainThread.h" | 43 #include "wtf/MainThread.h" |
44 #include "wtf/StdLibExtras.h" | 44 #include "wtf/StdLibExtras.h" |
45 #include "wtf/unicode/CharacterNames.h" | 45 #include "wtf/unicode/CharacterNames.h" |
46 #include "wtf/unicode/Unicode.h" | 46 #include "wtf/unicode/Unicode.h" |
47 | 47 |
48 using namespace WTF; | 48 using namespace WTF; |
49 using namespace Unicode; | 49 using namespace Unicode; |
50 | 50 |
51 namespace blink { | 51 namespace blink { |
52 | 52 |
53 CodePath Font::s_codePath = AutoPath; | |
54 | |
55 Font::Font() | 53 Font::Font() |
56 { | 54 { |
57 } | 55 } |
58 | 56 |
59 Font::Font(const FontDescription& fd) | 57 Font::Font(const FontDescription& fd) |
60 : m_fontDescription(fd) | 58 : m_fontDescription(fd) |
61 { | 59 { |
62 } | 60 } |
63 | 61 |
64 Font::Font(const Font& other) | 62 Font::Font(const Font& other) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 } | 101 } |
104 | 102 |
105 float Font::drawText(GraphicsContext* context, const TextRunPaintInfo& runInfo,
const FloatPoint& point, CustomFontNotReadyAction customFontNotReadyAction) cons
t | 103 float Font::drawText(GraphicsContext* context, const TextRunPaintInfo& runInfo,
const FloatPoint& point, CustomFontNotReadyAction customFontNotReadyAction) cons
t |
106 { | 104 { |
107 // Don't draw anything while we are using custom fonts that are in the proce
ss of loading, | 105 // Don't draw anything while we are using custom fonts that are in the proce
ss of loading, |
108 // except if the 'force' argument is set to true (in which case it will use
a fallback | 106 // except if the 'force' argument is set to true (in which case it will use
a fallback |
109 // font). | 107 // font). |
110 if (shouldSkipDrawing() && customFontNotReadyAction == DoNotPaintIfFontNotRe
ady) | 108 if (shouldSkipDrawing() && customFontNotReadyAction == DoNotPaintIfFontNotRe
ady) |
111 return 0; | 109 return 0; |
112 | 110 |
113 CodePath codePathToUse = codePath(runInfo.run); | 111 if (codePath(runInfo) != ComplexPath) |
114 // FIXME: Use the fast code path once it handles partial runs with kerning a
nd ligatures. See http://webkit.org/b/100050 | |
115 if (codePathToUse != ComplexPath && fontDescription().typesettingFeatures()
&& (runInfo.from || runInfo.to != runInfo.run.length())) | |
116 codePathToUse = ComplexPath; | |
117 | |
118 if (codePathToUse != ComplexPath) | |
119 return drawSimpleText(context, runInfo, point); | 112 return drawSimpleText(context, runInfo, point); |
120 | 113 |
121 return drawComplexText(context, runInfo, point); | 114 return drawComplexText(context, runInfo, point); |
122 } | 115 } |
123 | 116 |
124 void Font::drawEmphasisMarks(GraphicsContext* context, const TextRunPaintInfo& r
unInfo, const AtomicString& mark, const FloatPoint& point) const | 117 void Font::drawEmphasisMarks(GraphicsContext* context, const TextRunPaintInfo& r
unInfo, const AtomicString& mark, const FloatPoint& point) const |
125 { | 118 { |
126 if (shouldSkipDrawing()) | 119 if (shouldSkipDrawing()) |
127 return; | 120 return; |
128 | 121 |
129 CodePath codePathToUse = codePath(runInfo.run); | 122 if (codePath(runInfo) != ComplexPath) |
130 // FIXME: Use the fast code path once it handles partial runs with kerning a
nd ligatures. See http://webkit.org/b/100050 | |
131 if (codePathToUse != ComplexPath && fontDescription().typesettingFeatures()
&& (runInfo.from || runInfo.to != runInfo.run.length())) | |
132 codePathToUse = ComplexPath; | |
133 | |
134 if (codePathToUse != ComplexPath) | |
135 drawEmphasisMarksForSimpleText(context, runInfo, mark, point); | 123 drawEmphasisMarksForSimpleText(context, runInfo, mark, point); |
136 else | 124 else |
137 drawEmphasisMarksForComplexText(context, runInfo, mark, point); | 125 drawEmphasisMarksForComplexText(context, runInfo, mark, point); |
138 } | 126 } |
139 | 127 |
140 static inline void updateGlyphOverflowFromBounds(const IntRectExtent& glyphBound
s, | 128 static inline void updateGlyphOverflowFromBounds(const IntRectExtent& glyphBound
s, |
141 const FontMetrics& fontMetrics, GlyphOverflow* glyphOverflow) | 129 const FontMetrics& fontMetrics, GlyphOverflow* glyphOverflow) |
142 { | 130 { |
143 glyphOverflow->top = std::max<int>(glyphOverflow->top, | 131 glyphOverflow->top = std::max<int>(glyphOverflow->top, |
144 glyphBounds.top() - (glyphOverflow->computeBounds ? 0 : fontMetrics.asce
nt())); | 132 glyphBounds.top() - (glyphOverflow->computeBounds ? 0 : fontMetrics.asce
nt())); |
145 glyphOverflow->bottom = std::max<int>(glyphOverflow->bottom, | 133 glyphOverflow->bottom = std::max<int>(glyphOverflow->bottom, |
146 glyphBounds.bottom() - (glyphOverflow->computeBounds ? 0 : fontMetrics.d
escent())); | 134 glyphBounds.bottom() - (glyphOverflow->computeBounds ? 0 : fontMetrics.d
escent())); |
147 glyphOverflow->left = glyphBounds.left(); | 135 glyphOverflow->left = glyphBounds.left(); |
148 glyphOverflow->right = glyphBounds.right(); | 136 glyphOverflow->right = glyphBounds.right(); |
149 } | 137 } |
150 | 138 |
151 float Font::width(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFo
nts, GlyphOverflow* glyphOverflow) const | 139 float Font::width(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFo
nts, GlyphOverflow* glyphOverflow) const |
152 { | 140 { |
153 CodePath codePathToUse = codePath(run); | 141 CodePath codePathToUse = codePath(TextRunPaintInfo(run)); |
154 if (codePathToUse != ComplexPath) { | 142 if (codePathToUse != ComplexPath) { |
155 // The simple path can optimize the case where glyph overflow is not obs
ervable. | 143 // The simple path can optimize the case where glyph overflow is not obs
ervable. |
156 if (codePathToUse != SimpleWithGlyphOverflowPath && (glyphOverflow && !g
lyphOverflow->computeBounds)) | 144 if (codePathToUse != SimpleWithGlyphOverflowPath && (glyphOverflow && !g
lyphOverflow->computeBounds)) |
157 glyphOverflow = 0; | 145 glyphOverflow = 0; |
158 } | 146 } |
159 | 147 |
160 bool hasWordSpacingOrLetterSpacing = fontDescription().wordSpacing() || font
Description().letterSpacing(); | 148 bool hasWordSpacingOrLetterSpacing = fontDescription().wordSpacing() || font
Description().letterSpacing(); |
161 bool isCacheable = codePathToUse == ComplexPath | 149 bool isCacheable = codePathToUse == ComplexPath |
162 && !hasWordSpacingOrLetterSpacing // Word spacing and letter spacing can
change the width of a word. | 150 && !hasWordSpacingOrLetterSpacing // Word spacing and letter spacing can
change the width of a word. |
163 && !run.allowTabs(); // If we allow tabs and a tab occurs inside a word,
the width of the word varies based on its position on the line. | 151 && !run.allowTabs(); // If we allow tabs and a tab occurs inside a word,
the width of the word varies based on its position on the line. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 192 |
205 PassTextBlobPtr Font::buildTextBlob(const TextRunPaintInfo& runInfo, const Float
Point& textOrigin, bool couldUseLCDRenderedText, CustomFontNotReadyAction custom
FontNotReadyAction) const | 193 PassTextBlobPtr Font::buildTextBlob(const TextRunPaintInfo& runInfo, const Float
Point& textOrigin, bool couldUseLCDRenderedText, CustomFontNotReadyAction custom
FontNotReadyAction) const |
206 { | 194 { |
207 ASSERT(RuntimeEnabledFeatures::textBlobEnabled()); | 195 ASSERT(RuntimeEnabledFeatures::textBlobEnabled()); |
208 | 196 |
209 // FIXME: Some logic in common with Font::drawText. Would be nice to | 197 // FIXME: Some logic in common with Font::drawText. Would be nice to |
210 // deduplicate. | 198 // deduplicate. |
211 if (shouldSkipDrawing() && customFontNotReadyAction == DoNotPaintIfFontNotRe
ady) | 199 if (shouldSkipDrawing() && customFontNotReadyAction == DoNotPaintIfFontNotRe
ady) |
212 return nullptr; | 200 return nullptr; |
213 | 201 |
214 CodePath codePathToUse = codePath(runInfo.run); | 202 if (codePath(runInfo) != ComplexPath) |
215 // FIXME: Use the fast code path once it handles partial runs with kerning a
nd ligatures. See http://webkit.org/b/100050 | |
216 if (codePathToUse != ComplexPath && fontDescription().typesettingFeatures()
&& (runInfo.from || runInfo.to != runInfo.run.length())) | |
217 codePathToUse = ComplexPath; | |
218 | |
219 if (codePathToUse != ComplexPath) | |
220 return buildTextBlobForSimpleText(runInfo, textOrigin, couldUseLCDRender
edText); | 203 return buildTextBlobForSimpleText(runInfo, textOrigin, couldUseLCDRender
edText); |
221 | 204 |
222 return nullptr; | 205 return nullptr; |
223 } | 206 } |
224 | 207 |
225 PassTextBlobPtr Font::buildTextBlobForSimpleText(const TextRunPaintInfo& runInfo
, const FloatPoint& textOrigin, bool couldUseLCDRenderedText) const | 208 PassTextBlobPtr Font::buildTextBlobForSimpleText(const TextRunPaintInfo& runInfo
, const FloatPoint& textOrigin, bool couldUseLCDRenderedText) const |
226 { | 209 { |
227 GlyphBuffer glyphBuffer; | 210 GlyphBuffer glyphBuffer; |
228 float initialAdvance = getGlyphsAndAdvancesForSimpleText(runInfo, glyphBuffe
r); | 211 float initialAdvance = getGlyphsAndAdvancesForSimpleText(runInfo, glyphBuffe
r); |
229 | 212 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 | 273 |
291 advance = x; | 274 advance = x; |
292 return adoptRef(builder.build()); | 275 return adoptRef(builder.build()); |
293 } | 276 } |
294 | 277 |
295 | 278 |
296 FloatRect Font::selectionRectForText(const TextRun& run, const FloatPoint& point
, int h, int from, int to, bool accountForGlyphBounds) const | 279 FloatRect Font::selectionRectForText(const TextRun& run, const FloatPoint& point
, int h, int from, int to, bool accountForGlyphBounds) const |
297 { | 280 { |
298 to = (to == -1 ? run.length() : to); | 281 to = (to == -1 ? run.length() : to); |
299 | 282 |
300 CodePath codePathToUse = codePath(run); | 283 TextRunPaintInfo runInfo(run); |
301 // FIXME: Use the fast code path once it handles partial runs with kerning a
nd ligatures. See http://webkit.org/b/100050 | 284 runInfo.from = from; |
302 if (codePathToUse != ComplexPath && fontDescription().typesettingFeatures()
&& (from || to != run.length())) | 285 runInfo.to = to; |
303 codePathToUse = ComplexPath; | |
304 | 286 |
305 if (codePathToUse != ComplexPath) | 287 if (codePath(runInfo) != ComplexPath) |
306 return selectionRectForSimpleText(run, point, h, from, to, accountForGly
phBounds); | 288 return selectionRectForSimpleText(run, point, h, from, to, accountForGly
phBounds); |
307 | 289 |
308 return selectionRectForComplexText(run, point, h, from, to); | 290 return selectionRectForComplexText(run, point, h, from, to); |
309 } | 291 } |
310 | 292 |
311 int Font::offsetForPosition(const TextRun& run, float x, bool includePartialGlyp
hs) const | 293 int Font::offsetForPosition(const TextRun& run, float x, bool includePartialGlyp
hs) const |
312 { | 294 { |
313 // FIXME: Use the fast code path once it handles partial runs with kerning a
nd ligatures. See http://webkit.org/b/100050 | 295 if (codePath(TextRunPaintInfo(run)) != ComplexPath && !fontDescription().typ
esettingFeatures()) |
314 if (codePath(run) != ComplexPath && !fontDescription().typesettingFeatures()
) | |
315 return offsetForPositionForSimpleText(run, x, includePartialGlyphs); | 296 return offsetForPositionForSimpleText(run, x, includePartialGlyphs); |
316 | 297 |
317 return offsetForPositionForComplexText(run, x, includePartialGlyphs); | 298 return offsetForPositionForComplexText(run, x, includePartialGlyphs); |
318 } | 299 } |
319 | 300 |
320 void Font::setCodePath(CodePath p) | 301 CodePath Font::codePath(const TextRunPaintInfo& runInfo) const |
321 { | 302 { |
322 s_codePath = p; | 303 const TextRun& run = runInfo.run; |
323 } | |
324 | 304 |
325 CodePath Font::codePath() | 305 if (fontDescription().typesettingFeatures() && (runInfo.from || runInfo.to !
= run.length())) |
326 { | 306 return ComplexPath; |
327 return s_codePath; | |
328 } | |
329 | |
330 CodePath Font::codePath(const TextRun& run) const | |
331 { | |
332 if (s_codePath != AutoPath) | |
333 return s_codePath; | |
334 | 307 |
335 #if ENABLE(SVG_FONTS) | 308 #if ENABLE(SVG_FONTS) |
336 if (run.renderingContext()) | 309 if (run.renderingContext()) |
337 return SimplePath; | 310 return SimplePath; |
338 #endif | 311 #endif |
339 | 312 |
340 if (m_fontDescription.featureSettings() && m_fontDescription.featureSettings
()->size() > 0 && m_fontDescription.letterSpacing() == 0) | 313 if (m_fontDescription.featureSettings() && m_fontDescription.featureSettings
()->size() > 0 && m_fontDescription.letterSpacing() == 0) |
341 return ComplexPath; | 314 return ComplexPath; |
342 | 315 |
343 if (m_fontDescription.widthVariant() != RegularWidth) | 316 if (m_fontDescription.widthVariant() != RegularWidth) |
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 if (delta <= 0) | 1155 if (delta <= 0) |
1183 break; | 1156 break; |
1184 } | 1157 } |
1185 } | 1158 } |
1186 } | 1159 } |
1187 | 1160 |
1188 return offset; | 1161 return offset; |
1189 } | 1162 } |
1190 | 1163 |
1191 } // namespace blink | 1164 } // namespace blink |
OLD | NEW |