| 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 |
| 3 * reserved. |
| 3 * Copyright (C) 2008 Holger Hans Peter Freyther | 4 * Copyright (C) 2008 Holger Hans Peter Freyther |
| 4 * Copyright (C) 2014 Google Inc. All rights reserved. | 5 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 5 * | 6 * |
| 6 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 9 * 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. |
| 10 * | 11 * |
| 11 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 const GlyphData& glyphData) const { | 82 const GlyphData& glyphData) const { |
| 82 const SimpleFontData* fontData = glyphData.fontData; | 83 const SimpleFontData* fontData = glyphData.fontData; |
| 83 ASSERT(fontData); | 84 ASSERT(fontData); |
| 84 | 85 |
| 85 if (UNLIKELY(character == tabulationCharacter && m_textRun.allowTabs())) | 86 if (UNLIKELY(character == tabulationCharacter && m_textRun.allowTabs())) |
| 86 return m_font->tabWidth(*fontData, m_textRun.getTabSize(), | 87 return m_font->tabWidth(*fontData, m_textRun.getTabSize(), |
| 87 m_textRun.xPos() + m_runWidthSoFar); | 88 m_textRun.xPos() + m_runWidthSoFar); |
| 88 | 89 |
| 89 float width = fontData->widthForGlyph(glyphData.glyph); | 90 float width = fontData->widthForGlyph(glyphData.glyph); |
| 90 | 91 |
| 91 // SVG uses horizontalGlyphStretch(), when textLength is used to stretch/squee
ze text. | 92 // SVG uses horizontalGlyphStretch(), when textLength is used to |
| 93 // stretch/squeeze text. |
| 92 if (UNLIKELY(m_textRun.horizontalGlyphStretch() != 1)) | 94 if (UNLIKELY(m_textRun.horizontalGlyphStretch() != 1)) |
| 93 width *= m_textRun.horizontalGlyphStretch(); | 95 width *= m_textRun.horizontalGlyphStretch(); |
| 94 | 96 |
| 95 return width; | 97 return width; |
| 96 } | 98 } |
| 97 | 99 |
| 98 float SimpleShaper::adjustSpacing(float width, const CharacterData& charData) { | 100 float SimpleShaper::adjustSpacing(float width, const CharacterData& charData) { |
| 99 // Account for letter-spacing. | 101 // Account for letter-spacing. |
| 100 if (width) | 102 if (width) |
| 101 width += m_font->getFontDescription().letterSpacing(); | 103 width += m_font->getFontDescription().letterSpacing(); |
| 102 | 104 |
| 103 bool isExpansionOpportunity = | 105 bool isExpansionOpportunity = |
| 104 Character::treatAsSpace(charData.character) || | 106 Character::treatAsSpace(charData.character) || |
| 105 (m_textRun.getTextJustify() == TextJustifyDistribute); | 107 (m_textRun.getTextJustify() == TextJustifyDistribute); |
| 106 if (isExpansionOpportunity || | 108 if (isExpansionOpportunity || |
| 107 (m_textRun.getTextJustify() == TextJustifyAuto && | 109 (m_textRun.getTextJustify() == TextJustifyAuto && |
| 108 Character::isCJKIdeographOrSymbol(charData.character))) { | 110 Character::isCJKIdeographOrSymbol(charData.character))) { |
| 109 // Distribute the run's total expansion evenly over all expansion opportunit
ies in the run. | 111 // Distribute the run's total expansion evenly over all expansion |
| 112 // opportunities in the run. |
| 110 if (m_expansion) { | 113 if (m_expansion) { |
| 111 if (!isExpansionOpportunity && !m_isAfterExpansion) { | 114 if (!isExpansionOpportunity && !m_isAfterExpansion) { |
| 112 // Take the expansion opportunity before this ideograph. | 115 // Take the expansion opportunity before this ideograph. |
| 113 m_expansion -= m_expansionPerOpportunity; | 116 m_expansion -= m_expansionPerOpportunity; |
| 114 m_runWidthSoFar += m_expansionPerOpportunity; | 117 m_runWidthSoFar += m_expansionPerOpportunity; |
| 115 } | 118 } |
| 116 if (m_textRun.allowsTrailingExpansion() || | 119 if (m_textRun.allowsTrailingExpansion() || |
| 117 (m_textRun.ltr() && | 120 (m_textRun.ltr() && |
| 118 charData.characterOffset + charData.clusterLength < | 121 charData.characterOffset + charData.clusterLength < |
| 119 m_textRun.length()) || | 122 m_textRun.length()) || |
| 120 (m_textRun.rtl() && charData.characterOffset)) { | 123 (m_textRun.rtl() && charData.characterOffset)) { |
| 121 m_expansion -= m_expansionPerOpportunity; | 124 m_expansion -= m_expansionPerOpportunity; |
| 122 width += m_expansionPerOpportunity; | 125 width += m_expansionPerOpportunity; |
| 123 m_isAfterExpansion = true; | 126 m_isAfterExpansion = true; |
| 124 } | 127 } |
| 125 } else { | 128 } else { |
| 126 m_isAfterExpansion = false; | 129 m_isAfterExpansion = false; |
| 127 } | 130 } |
| 128 | 131 |
| 129 // Account for word spacing. | 132 // Account for word spacing. |
| 130 // We apply additional space between "words" by adding width to the space ch
aracter. | 133 // We apply additional space between "words" by adding width to the space |
| 134 // character. |
| 131 if (isExpansionOpportunity && | 135 if (isExpansionOpportunity && |
| 132 (charData.character != tabulationCharacter || !m_textRun.allowTabs()) && | 136 (charData.character != tabulationCharacter || !m_textRun.allowTabs()) && |
| 133 (charData.characterOffset || | 137 (charData.characterOffset || |
| 134 charData.character == noBreakSpaceCharacter) && | 138 charData.character == noBreakSpaceCharacter) && |
| 135 m_font->getFontDescription().wordSpacing()) { | 139 m_font->getFontDescription().wordSpacing()) { |
| 136 width += m_font->getFontDescription().wordSpacing(); | 140 width += m_font->getFontDescription().wordSpacing(); |
| 137 } | 141 } |
| 138 } else { | 142 } else { |
| 139 m_isAfterExpansion = false; | 143 m_isAfterExpansion = false; |
| 140 } | 144 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 } | 188 } |
| 185 | 189 |
| 186 if (hasExtraSpacing && !spaceUsedAsZeroWidthSpace) | 190 if (hasExtraSpacing && !spaceUsedAsZeroWidthSpace) |
| 187 width = adjustSpacing(width, charData); | 191 width = adjustSpacing(width, charData); |
| 188 | 192 |
| 189 if (m_glyphBoundingBox) { | 193 if (m_glyphBoundingBox) { |
| 190 ASSERT(glyphData.fontData); | 194 ASSERT(glyphData.fontData); |
| 191 FloatRect glyphBounds = | 195 FloatRect glyphBounds = |
| 192 glyphData.fontData->boundsForGlyph(glyphData.glyph); | 196 glyphData.fontData->boundsForGlyph(glyphData.glyph); |
| 193 // We are handling simple text run here, so Y-Offset will be zero. | 197 // We are handling simple text run here, so Y-Offset will be zero. |
| 194 // FIXME: Computing bounds relative to the initial advance seems odd. Are
we adjusting | 198 // FIXME: Computing bounds relative to the initial advance seems odd. Are |
| 195 // these someplace else? If not, we'll end up with different bounds depend
ing on how | 199 // we adjusting these someplace else? If not, we'll end up with different |
| 196 // we segment our advance() calls. | 200 // bounds depending on how we segment our advance() calls. |
| 197 glyphBounds.move(m_runWidthSoFar - initialRunWidth, 0); | 201 glyphBounds.move(m_runWidthSoFar - initialRunWidth, 0); |
| 198 m_glyphBoundingBox->unite(glyphBounds); | 202 m_glyphBoundingBox->unite(glyphBounds); |
| 199 } | 203 } |
| 200 | 204 |
| 201 if (glyphBuffer) { | 205 if (glyphBuffer) { |
| 202 if (!forTextEmphasis()) { | 206 if (!forTextEmphasis()) { |
| 203 glyphBuffer->add(glyph, fontData, m_runWidthSoFar); | 207 glyphBuffer->add(glyph, fontData, m_runWidthSoFar); |
| 204 } else if (Character::canReceiveTextEmphasis(charData.character)) { | 208 } else if (Character::canReceiveTextEmphasis(charData.character)) { |
| 205 addEmphasisMark(glyphBuffer, m_runWidthSoFar + width / 2); | 209 addEmphasisMark(glyphBuffer, m_runWidthSoFar + width / 2); |
| 206 } | 210 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 float initialWidth = m_runWidthSoFar; | 245 float initialWidth = m_runWidthSoFar; |
| 242 | 246 |
| 243 if (!advance(m_currentCharacter + 1)) | 247 if (!advance(m_currentCharacter + 1)) |
| 244 return false; | 248 return false; |
| 245 | 249 |
| 246 width = m_runWidthSoFar - initialWidth; | 250 width = m_runWidthSoFar - initialWidth; |
| 247 return true; | 251 return true; |
| 248 } | 252 } |
| 249 | 253 |
| 250 } // namespace blink | 254 } // namespace blink |
| OLD | NEW |