OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2003, 2006, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2003, 2006, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv
ed. |
3 * Copyright (C) 2008 Holger Hans Peter Freyther | 3 * Copyright (C) 2008 Holger Hans Peter Freyther |
4 * Copyright (C) 2014 Google Inc. All rights reserved. | 4 * Copyright (C) 2014 Google Inc. All rights reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 if (isAfterExpansion && !m_run.allowsTrailingExpansion()) | 62 if (isAfterExpansion && !m_run.allowsTrailingExpansion()) |
63 expansionOpportunityCount--; | 63 expansionOpportunityCount--; |
64 | 64 |
65 if (!expansionOpportunityCount) | 65 if (!expansionOpportunityCount) |
66 m_expansionPerOpportunity = 0; | 66 m_expansionPerOpportunity = 0; |
67 else | 67 else |
68 m_expansionPerOpportunity = m_expansion / expansionOpportunityCount; | 68 m_expansionPerOpportunity = m_expansion / expansionOpportunityCount; |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 GlyphData WidthIterator::glyphDataForCharacter(CharacterData& charData) | 72 GlyphData WidthIterator::glyphDataForCharacter(CharacterData& charData, bool nor
malizeSpace) |
73 { | 73 { |
74 ASSERT(m_font); | 74 ASSERT(m_font); |
75 | 75 |
76 #if ENABLE(SVG_FONTS) | 76 #if ENABLE(SVG_FONTS) |
77 if (TextRun::RenderingContext* renderingContext = m_run.renderingContext())
{ | 77 if (TextRun::RenderingContext* renderingContext = m_run.renderingContext())
{ |
78 return renderingContext->glyphDataForCharacter(*m_font, m_run, *this, ch
arData.character, | 78 return renderingContext->glyphDataForCharacter(*m_font, m_run, *this, ch
arData.character, |
79 m_run.rtl(), charData.characterOffset, charData.clusterLength); | 79 m_run.rtl(), charData.characterOffset, charData.clusterLength); |
80 } | 80 } |
81 #endif | 81 #endif |
82 | 82 |
83 return m_font->glyphDataForCharacter(charData.character, m_run.rtl()); | 83 return m_font->glyphDataForCharacter(charData.character, m_run.rtl(), normal
izeSpace); |
84 } | 84 } |
85 | 85 |
86 float WidthIterator::characterWidth(UChar32 character, const GlyphData& glyphDat
a) const | 86 float WidthIterator::characterWidth(UChar32 character, const GlyphData& glyphDat
a) const |
87 { | 87 { |
88 const SimpleFontData* fontData = glyphData.fontData; | 88 const SimpleFontData* fontData = glyphData.fontData; |
89 ASSERT(fontData); | 89 ASSERT(fontData); |
90 | 90 |
91 if (UNLIKELY(character == '\t' && m_run.allowTabs())) | 91 if (UNLIKELY(character == '\t' && m_run.allowTabs())) |
92 return m_font->tabWidth(*fontData, m_run.tabSize(), m_run.xPos() + m_run
WidthSoFar); | 92 return m_font->tabWidth(*fontData, m_run.tabSize(), m_run.xPos() + m_run
WidthSoFar); |
93 | 93 |
94 float width = fontData->widthForGlyph(glyphData.glyph); | 94 float width = fontData->widthForGlyph(glyphData.glyph); |
95 | 95 |
96 // SVG uses horizontalGlyphStretch(), when textLength is used to stretch/squ
eeze text. | 96 // SVG uses horizontalGlyphStretch(), when textLength is used to stretch/squ
eeze text. |
97 if (UNLIKELY(m_run.horizontalGlyphStretch() != 1)) | 97 if (UNLIKELY(m_run.horizontalGlyphStretch() != 1)) |
98 width *= m_run.horizontalGlyphStretch(); | 98 width *= m_run.horizontalGlyphStretch(); |
99 | 99 |
100 return width; | 100 return width; |
101 } | 101 } |
102 | 102 |
103 void WidthIterator::cacheFallbackFont(UChar32 character, const SimpleFontData* f
ontData, | 103 void WidthIterator::cacheFallbackFont(const SimpleFontData* fontData, |
104 const SimpleFontData* primaryFont) | 104 const SimpleFontData* primaryFont) |
105 { | 105 { |
106 if (fontData == primaryFont) | 106 if (fontData == primaryFont) |
107 return; | 107 return; |
108 | 108 |
109 // FIXME: This does a little extra work that could be avoided if | 109 m_fallbackFonts->add(fontData); |
110 // glyphDataForCharacter() returned whether it chose to use a small caps fon
t. | |
111 if (m_font->fontDescription().variant() == FontVariantNormal || character ==
toUpper(character)) { | |
112 m_fallbackFonts->add(fontData); | |
113 } else { | |
114 ASSERT(m_font->fontDescription().variant() == FontVariantSmallCaps); | |
115 const GlyphData uppercaseGlyphData = m_font->glyphDataForCharacter(toUpp
er(character), | |
116 m_run.rtl()); | |
117 if (uppercaseGlyphData.fontData != primaryFont) | |
118 m_fallbackFonts->add(uppercaseGlyphData.fontData); | |
119 } | |
120 } | 110 } |
121 | 111 |
122 float WidthIterator::adjustSpacing(float width, const CharacterData& charData, | 112 float WidthIterator::adjustSpacing(float width, const CharacterData& charData, |
123 const SimpleFontData& fontData, GlyphBuffer* glyphBuffer) | 113 const SimpleFontData& fontData, GlyphBuffer* glyphBuffer) |
124 { | 114 { |
125 // Account for letter-spacing. | 115 // Account for letter-spacing. |
126 if (width) | 116 if (width) |
127 width += m_font->fontDescription().letterSpacing(); | 117 width += m_font->fontDescription().letterSpacing(); |
128 | 118 |
129 static bool expandAroundIdeographs = FontPlatformFeatures::canExpandAroundId
eographsInComplexText(); | 119 static bool expandAroundIdeographs = FontPlatformFeatures::canExpandAroundId
eographsInComplexText(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 } | 175 } |
186 | 176 |
187 template <typename TextIterator> | 177 template <typename TextIterator> |
188 unsigned WidthIterator::advanceInternal(TextIterator& textIterator, GlyphBuffer*
glyphBuffer) | 178 unsigned WidthIterator::advanceInternal(TextIterator& textIterator, GlyphBuffer*
glyphBuffer) |
189 { | 179 { |
190 bool hasExtraSpacing = (m_font->fontDescription().letterSpacing() || m_font-
>fontDescription().wordSpacing() || m_expansion) | 180 bool hasExtraSpacing = (m_font->fontDescription().letterSpacing() || m_font-
>fontDescription().wordSpacing() || m_expansion) |
191 && !m_run.spacingDisabled(); | 181 && !m_run.spacingDisabled(); |
192 | 182 |
193 const SimpleFontData* primaryFont = m_font->primaryFont(); | 183 const SimpleFontData* primaryFont = m_font->primaryFont(); |
194 const SimpleFontData* lastFontData = primaryFont; | 184 const SimpleFontData* lastFontData = primaryFont; |
| 185 bool normalizeSpace = m_run.normalizeSpace(); |
195 | 186 |
196 CharacterData charData; | 187 CharacterData charData; |
197 while (textIterator.consume(charData.character, charData.clusterLength)) { | 188 while (textIterator.consume(charData.character, charData.clusterLength)) { |
198 charData.characterOffset = textIterator.currentCharacter(); | 189 charData.characterOffset = textIterator.currentCharacter(); |
199 | 190 |
200 const GlyphData glyphData = glyphDataForCharacter(charData); | 191 const GlyphData glyphData = glyphDataForCharacter(charData, normalizeSpa
ce); |
201 Glyph glyph = glyphData.glyph; | 192 Glyph glyph = glyphData.glyph; |
202 const SimpleFontData* fontData = glyphData.fontData; | 193 const SimpleFontData* fontData = glyphData.fontData; |
203 ASSERT(fontData); | 194 ASSERT(fontData); |
204 | 195 |
205 // Now that we have a glyph and font data, get its width. | 196 // Now that we have a glyph and font data, get its width. |
206 float width = characterWidth(charData.character, glyphData); | 197 float width = characterWidth(charData.character, glyphData); |
207 | 198 |
208 if (m_fallbackFonts && lastFontData != fontData && width) { | 199 if (m_fallbackFonts && lastFontData != fontData && width) { |
209 lastFontData = fontData; | 200 lastFontData = fontData; |
210 cacheFallbackFont(charData.character, fontData, primaryFont); | 201 cacheFallbackFont(fontData, primaryFont); |
211 } | 202 } |
212 | 203 |
213 if (hasExtraSpacing) | 204 if (hasExtraSpacing) |
214 width = adjustSpacing(width, charData, *fontData, glyphBuffer); | 205 width = adjustSpacing(width, charData, *fontData, glyphBuffer); |
215 | 206 |
216 if (m_accountForGlyphBounds) | 207 if (m_accountForGlyphBounds) |
217 updateGlyphBounds(glyphData, width, !charData.characterOffset); | 208 updateGlyphBounds(glyphData, width, !charData.characterOffset); |
218 | 209 |
219 if (m_forTextEmphasis && !Character::canReceiveTextEmphasis(charData.cha
racter)) | 210 if (m_forTextEmphasis && !Character::canReceiveTextEmphasis(charData.cha
racter)) |
220 glyph = 0; | 211 glyph = 0; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 float initialWidth = m_runWidthSoFar; | 248 float initialWidth = m_runWidthSoFar; |
258 | 249 |
259 if (!advance(m_currentCharacter + 1)) | 250 if (!advance(m_currentCharacter + 1)) |
260 return false; | 251 return false; |
261 | 252 |
262 width = m_runWidthSoFar - initialWidth; | 253 width = m_runWidthSoFar - initialWidth; |
263 return true; | 254 return true; |
264 } | 255 } |
265 | 256 |
266 } // namespace blink | 257 } // namespace blink |
OLD | NEW |