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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 , m_accountForGlyphBounds(accountForGlyphBounds) | 52 , m_accountForGlyphBounds(accountForGlyphBounds) |
53 , m_forTextEmphasis(forTextEmphasis) | 53 , m_forTextEmphasis(forTextEmphasis) |
54 { | 54 { |
55 // If the padding is non-zero, count the number of spaces in the run | 55 // If the padding is non-zero, count the number of spaces in the run |
56 // and divide that by the padding for per space addition. | 56 // and divide that by the padding for per space addition. |
57 m_expansion = m_run.expansion(); | 57 m_expansion = m_run.expansion(); |
58 if (!m_expansion) | 58 if (!m_expansion) |
59 m_expansionPerOpportunity = 0; | 59 m_expansionPerOpportunity = 0; |
60 else { | 60 else { |
61 bool isAfterExpansion = m_isAfterExpansion; | 61 bool isAfterExpansion = m_isAfterExpansion; |
62 unsigned expansionOpportunityCount = m_run.is8Bit() ? Character::expansi
onOpportunityCount(m_run.characters8(), m_run.length(), m_run.direction(), isAft
erExpansion) : Character::expansionOpportunityCount(m_run.characters16(), m_run.
length(), m_run.direction(), isAfterExpansion); | 62 unsigned expansionOpportunityCount = m_run.is8Bit() ? Character::expansi
onOpportunityCount(m_run.characters8(), m_run.length(), m_run.direction(), isAft
erExpansion, m_run.textJustify()) : Character::expansionOpportunityCount(m_run.c
haracters16(), m_run.length(), m_run.direction(), isAfterExpansion, m_run.textJu
stify()); |
63 if (isAfterExpansion && !m_run.allowsTrailingExpansion()) | 63 if (isAfterExpansion && !m_run.allowsTrailingExpansion()) |
64 expansionOpportunityCount--; | 64 expansionOpportunityCount--; |
65 | 65 |
66 if (!expansionOpportunityCount) | 66 if (!expansionOpportunityCount) |
67 m_expansionPerOpportunity = 0; | 67 m_expansionPerOpportunity = 0; |
68 else | 68 else |
69 m_expansionPerOpportunity = m_expansion / expansionOpportunityCount; | 69 m_expansionPerOpportunity = m_expansion / expansionOpportunityCount; |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 } | 121 } |
122 | 122 |
123 float WidthIterator::adjustSpacing(float width, const CharacterData& charData, | 123 float WidthIterator::adjustSpacing(float width, const CharacterData& charData, |
124 const SimpleFontData& fontData, GlyphBuffer* glyphBuffer) | 124 const SimpleFontData& fontData, GlyphBuffer* glyphBuffer) |
125 { | 125 { |
126 // Account for letter-spacing. | 126 // Account for letter-spacing. |
127 if (width) | 127 if (width) |
128 width += m_font->fontDescription().letterSpacing(); | 128 width += m_font->fontDescription().letterSpacing(); |
129 | 129 |
130 static bool expandAroundIdeographs = FontPlatformFeatures::canExpandAroundId
eographsInComplexText(); | 130 static bool expandAroundIdeographs = FontPlatformFeatures::canExpandAroundId
eographsInComplexText(); |
131 bool treatAsSpace = Character::treatAsSpace(charData.character); | 131 bool isExpansionOpportunity = Character::treatAsSpace(charData.character) ||
(m_run.textJustify() == JustifyDistribute); |
132 if (treatAsSpace || (expandAroundIdeographs && Character::isCJKIdeographOrSy
mbol(charData.character))) { | 132 if (isExpansionOpportunity || (expandAroundIdeographs && Character::isCJKIde
ographOrSymbol(charData.character))) { |
| 133 |
133 // Distribute the run's total expansion evenly over all expansion opport
unities in the run. | 134 // Distribute the run's total expansion evenly over all expansion opport
unities in the run. |
134 if (m_expansion) { | 135 if (m_expansion) { |
135 if (!treatAsSpace && !m_isAfterExpansion) { | 136 if (!isExpansionOpportunity && !m_isAfterExpansion) { |
136 // Take the expansion opportunity before this ideograph. | 137 // Take the expansion opportunity before this ideograph. |
137 m_expansion -= m_expansionPerOpportunity; | 138 m_expansion -= m_expansionPerOpportunity; |
138 float expansionAtThisOpportunity = m_expansionPerOpportunity; | 139 float expansionAtThisOpportunity = m_expansionPerOpportunity; |
139 m_runWidthSoFar += expansionAtThisOpportunity; | 140 m_runWidthSoFar += expansionAtThisOpportunity; |
140 if (glyphBuffer) { | 141 if (glyphBuffer) { |
141 if (glyphBuffer->isEmpty()) { | 142 if (glyphBuffer->isEmpty()) { |
142 if (m_forTextEmphasis) | 143 if (m_forTextEmphasis) |
143 glyphBuffer->add(fontData.zeroWidthSpaceGlyph(), &fo
ntData, m_expansionPerOpportunity); | 144 glyphBuffer->add(fontData.zeroWidthSpaceGlyph(), &fo
ntData, m_expansionPerOpportunity); |
144 else | 145 else |
145 glyphBuffer->add(fontData.spaceGlyph(), &fontData, e
xpansionAtThisOpportunity); | 146 glyphBuffer->add(fontData.spaceGlyph(), &fontData, e
xpansionAtThisOpportunity); |
146 } else { | 147 } else { |
147 glyphBuffer->expandLastAdvance(expansionAtThisOpportunit
y); | 148 glyphBuffer->expandLastAdvance(expansionAtThisOpportunit
y); |
148 } | 149 } |
149 } | 150 } |
150 } | 151 } |
151 if (m_run.allowsTrailingExpansion() | 152 if (m_run.allowsTrailingExpansion() |
152 || (m_run.ltr() && charData.characterOffset + charData.clusterLe
ngth < static_cast<size_t>(m_run.length())) | 153 || (m_run.ltr() && charData.characterOffset + charData.clusterLe
ngth < static_cast<size_t>(m_run.length())) |
153 || (m_run.rtl() && charData.characterOffset)) { | 154 || (m_run.rtl() && charData.characterOffset)) { |
154 m_expansion -= m_expansionPerOpportunity; | 155 m_expansion -= m_expansionPerOpportunity; |
155 width += m_expansionPerOpportunity; | 156 width += m_expansionPerOpportunity; |
156 m_isAfterExpansion = true; | 157 m_isAfterExpansion = true; |
157 } | 158 } |
158 } else { | 159 } else { |
159 m_isAfterExpansion = false; | 160 m_isAfterExpansion = false; |
160 } | 161 } |
161 | 162 |
162 // Account for word spacing. | 163 // Account for word spacing. |
163 // We apply additional space between "words" by adding width to the spac
e character. | 164 // We apply additional space between "words" by adding width to the spac
e character. |
164 if (treatAsSpace && (charData.character != '\t' || !m_run.allowTabs()) | 165 if (isExpansionOpportunity && (charData.character != '\t' || !m_run.allo
wTabs()) |
165 && (charData.characterOffset || charData.character == noBreakSpace) | 166 && (charData.characterOffset || charData.character == noBreakSpace) |
166 && m_font->fontDescription().wordSpacing()) { | 167 && m_font->fontDescription().wordSpacing()) { |
167 width += m_font->fontDescription().wordSpacing(); | 168 width += m_font->fontDescription().wordSpacing(); |
168 } | 169 } |
169 } else { | 170 } else { |
170 m_isAfterExpansion = false; | 171 m_isAfterExpansion = false; |
171 } | 172 } |
172 | 173 |
173 return width; | 174 return width; |
174 } | 175 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 float initialWidth = m_runWidthSoFar; | 259 float initialWidth = m_runWidthSoFar; |
259 | 260 |
260 if (!advance(m_currentCharacter + 1)) | 261 if (!advance(m_currentCharacter + 1)) |
261 return false; | 262 return false; |
262 | 263 |
263 width = m_runWidthSoFar - initialWidth; | 264 width = m_runWidthSoFar - initialWidth; |
264 return true; | 265 return true; |
265 } | 266 } |
266 | 267 |
267 } | 268 } |
OLD | NEW |