| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 void SimpleShaper::cacheFallbackFont(const SimpleFontData* fontData, | 92 void SimpleShaper::cacheFallbackFont(const SimpleFontData* fontData, |
| 93 const SimpleFontData* primaryFont) | 93 const SimpleFontData* primaryFont) |
| 94 { | 94 { |
| 95 if (fontData == primaryFont) | 95 if (fontData == primaryFont) |
| 96 return; | 96 return; |
| 97 | 97 |
| 98 m_fallbackFonts->add(fontData); | 98 m_fallbackFonts->add(fontData); |
| 99 } | 99 } |
| 100 | 100 |
| 101 float SimpleShaper::adjustSpacing(float width, const CharacterData& charData, | 101 float SimpleShaper::adjustSpacing(float width, const CharacterData& charData) |
| 102 const SimpleFontData& fontData, GlyphBuffer* glyphBuffer) | |
| 103 { | 102 { |
| 104 // Account for letter-spacing. | 103 // Account for letter-spacing. |
| 105 if (width) | 104 if (width) |
| 106 width += m_font->fontDescription().letterSpacing(); | 105 width += m_font->fontDescription().letterSpacing(); |
| 107 | 106 |
| 108 bool treatAsSpace = Character::treatAsSpace(charData.character); | 107 bool treatAsSpace = Character::treatAsSpace(charData.character); |
| 109 if (treatAsSpace) { | 108 if (treatAsSpace) { |
| 110 // Distribute the run's total expansion evenly over all expansion opport
unities in the run. | 109 // Distribute the run's total expansion evenly over all expansion opport
unities in the run. |
| 111 if (m_expansion) { | 110 if (m_expansion) { |
| 112 if (!treatAsSpace && !m_isAfterExpansion) { | 111 if (!treatAsSpace && !m_isAfterExpansion) { |
| 113 // Take the expansion opportunity before this ideograph. | 112 // Take the expansion opportunity before this ideograph. |
| 114 m_expansion -= m_expansionPerOpportunity; | 113 m_expansion -= m_expansionPerOpportunity; |
| 115 float expansionAtThisOpportunity = m_expansionPerOpportunity; | 114 m_runWidthSoFar += m_expansionPerOpportunity; |
| 116 m_runWidthSoFar += expansionAtThisOpportunity; | |
| 117 if (glyphBuffer) { | |
| 118 if (glyphBuffer->isEmpty()) { | |
| 119 if (m_forTextEmphasis) | |
| 120 glyphBuffer->add(fontData.zeroWidthSpaceGlyph(), &fo
ntData, m_expansionPerOpportunity); | |
| 121 else | |
| 122 glyphBuffer->add(fontData.spaceGlyph(), &fontData, e
xpansionAtThisOpportunity); | |
| 123 } else { | |
| 124 glyphBuffer->expandLastAdvance(expansionAtThisOpportunit
y); | |
| 125 } | |
| 126 } | |
| 127 } | 115 } |
| 128 if (m_run.allowsTrailingExpansion() | 116 if (m_run.allowsTrailingExpansion() |
| 129 || (m_run.ltr() && charData.characterOffset + charData.clusterLe
ngth < static_cast<size_t>(m_run.length())) | 117 || (m_run.ltr() && charData.characterOffset + charData.clusterLe
ngth < static_cast<size_t>(m_run.length())) |
| 130 || (m_run.rtl() && charData.characterOffset)) { | 118 || (m_run.rtl() && charData.characterOffset)) { |
| 131 m_expansion -= m_expansionPerOpportunity; | 119 m_expansion -= m_expansionPerOpportunity; |
| 132 width += m_expansionPerOpportunity; | 120 width += m_expansionPerOpportunity; |
| 133 m_isAfterExpansion = true; | 121 m_isAfterExpansion = true; |
| 134 } | 122 } |
| 135 } else { | 123 } else { |
| 136 m_isAfterExpansion = false; | 124 m_isAfterExpansion = false; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 Glyph glyph = glyphData.glyph; | 183 Glyph glyph = glyphData.glyph; |
| 196 const SimpleFontData* fontData = glyphData.fontData; | 184 const SimpleFontData* fontData = glyphData.fontData; |
| 197 ASSERT(fontData); | 185 ASSERT(fontData); |
| 198 | 186 |
| 199 if (m_fallbackFonts && lastFontData != fontData && width) { | 187 if (m_fallbackFonts && lastFontData != fontData && width) { |
| 200 lastFontData = fontData; | 188 lastFontData = fontData; |
| 201 cacheFallbackFont(fontData, primaryFont); | 189 cacheFallbackFont(fontData, primaryFont); |
| 202 } | 190 } |
| 203 | 191 |
| 204 if (hasExtraSpacing && !spaceUsedAsZeroWidthSpace) | 192 if (hasExtraSpacing && !spaceUsedAsZeroWidthSpace) |
| 205 width = adjustSpacing(width, charData, *fontData, glyphBuffer); | 193 width = adjustSpacing(width, charData); |
| 206 | 194 |
| 207 if (m_bounds) | 195 if (m_bounds) |
| 208 updateGlyphBounds(glyphData, width, !charData.characterOffset); | 196 updateGlyphBounds(glyphData, width, !charData.characterOffset); |
| 209 | 197 |
| 210 if (m_forTextEmphasis && !Character::canReceiveTextEmphasis(charData.cha
racter)) | 198 if (m_forTextEmphasis) { |
| 211 glyph = 0; | 199 if (!Character::canReceiveTextEmphasis(charData.character)) |
| 200 glyph = 0; |
| 201 |
| 202 // The emphasis code expects mid-glyph offsets. |
| 203 width /= 2; |
| 204 m_runWidthSoFar += width; |
| 205 } |
| 206 |
| 207 if (glyphBuffer) |
| 208 glyphBuffer->add(glyph, fontData, m_runWidthSoFar); |
| 212 | 209 |
| 213 // Advance past the character we just dealt with. | 210 // Advance past the character we just dealt with. |
| 214 textIterator.advance(charData.clusterLength); | 211 textIterator.advance(charData.clusterLength); |
| 215 m_runWidthSoFar += width; | 212 m_runWidthSoFar += width; |
| 216 | |
| 217 if (glyphBuffer) | |
| 218 glyphBuffer->add(glyph, fontData, width); | |
| 219 } | 213 } |
| 220 | 214 |
| 221 unsigned consumedCharacters = textIterator.currentCharacter() - m_currentCha
racter; | 215 unsigned consumedCharacters = textIterator.currentCharacter() - m_currentCha
racter; |
| 222 m_currentCharacter = textIterator.currentCharacter(); | 216 m_currentCharacter = textIterator.currentCharacter(); |
| 223 | 217 |
| 224 return consumedCharacters; | 218 return consumedCharacters; |
| 225 } | 219 } |
| 226 | 220 |
| 227 unsigned SimpleShaper::advance(unsigned offset, GlyphBuffer* glyphBuffer) | 221 unsigned SimpleShaper::advance(unsigned offset, GlyphBuffer* glyphBuffer) |
| 228 { | 222 { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 248 float initialWidth = m_runWidthSoFar; | 242 float initialWidth = m_runWidthSoFar; |
| 249 | 243 |
| 250 if (!advance(m_currentCharacter + 1)) | 244 if (!advance(m_currentCharacter + 1)) |
| 251 return false; | 245 return false; |
| 252 | 246 |
| 253 width = m_runWidthSoFar - initialWidth; | 247 width = m_runWidthSoFar - initialWidth; |
| 254 return true; | 248 return true; |
| 255 } | 249 } |
| 256 | 250 |
| 257 } // namespace blink | 251 } // namespace blink |
| OLD | NEW |