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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 , m_bounds(bounds) | 48 , m_bounds(bounds) |
49 , m_forTextEmphasis(forTextEmphasis) | 49 , m_forTextEmphasis(forTextEmphasis) |
50 { | 50 { |
51 // If the padding is non-zero, count the number of spaces in the run | 51 // If the padding is non-zero, count the number of spaces in the run |
52 // and divide that by the padding for per space addition. | 52 // and divide that by the padding for per space addition. |
53 m_expansion = m_run.expansion(); | 53 m_expansion = m_run.expansion(); |
54 if (!m_expansion) { | 54 if (!m_expansion) { |
55 m_expansionPerOpportunity = 0; | 55 m_expansionPerOpportunity = 0; |
56 } else { | 56 } else { |
57 bool isAfterExpansion = m_isAfterExpansion; | 57 bool isAfterExpansion = m_isAfterExpansion; |
58 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); | 58 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()); |
59 if (isAfterExpansion && !m_run.allowsTrailingExpansion()) | 59 if (isAfterExpansion && !m_run.allowsTrailingExpansion()) |
60 expansionOpportunityCount--; | 60 expansionOpportunityCount--; |
61 | 61 |
62 if (!expansionOpportunityCount) | 62 if (!expansionOpportunityCount) |
63 m_expansionPerOpportunity = 0; | 63 m_expansionPerOpportunity = 0; |
64 else | 64 else |
65 m_expansionPerOpportunity = m_expansion / expansionOpportunityCount; | 65 m_expansionPerOpportunity = m_expansion / expansionOpportunityCount; |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
(...skipping 28 matching lines...) Expand all Loading... |
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 { | 102 { |
103 // Account for letter-spacing. | 103 // Account for letter-spacing. |
104 if (width) | 104 if (width) |
105 width += m_font->fontDescription().letterSpacing(); | 105 width += m_font->fontDescription().letterSpacing(); |
106 | 106 |
107 bool treatAsSpace = Character::treatAsSpace(charData.character); | 107 bool isExpansionOpportunity = Character::treatAsSpace(charData.character) ||
(m_run.textJustify() == TextJustifyDistribute); |
108 if (treatAsSpace) { | 108 if (isExpansionOpportunity) { |
109 // 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. |
110 if (m_expansion) { | 110 if (m_expansion) { |
111 if (!treatAsSpace && !m_isAfterExpansion) { | 111 if (!isExpansionOpportunity && !m_isAfterExpansion) { |
112 // Take the expansion opportunity before this ideograph. | 112 // Take the expansion opportunity before this ideograph. |
113 m_expansion -= m_expansionPerOpportunity; | 113 m_expansion -= m_expansionPerOpportunity; |
114 m_runWidthSoFar += m_expansionPerOpportunity; | 114 m_runWidthSoFar += m_expansionPerOpportunity; |
115 } | 115 } |
116 if (m_run.allowsTrailingExpansion() | 116 if (m_run.allowsTrailingExpansion() |
117 || (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())) |
118 || (m_run.rtl() && charData.characterOffset)) { | 118 || (m_run.rtl() && charData.characterOffset)) { |
119 m_expansion -= m_expansionPerOpportunity; | 119 m_expansion -= m_expansionPerOpportunity; |
120 width += m_expansionPerOpportunity; | 120 width += m_expansionPerOpportunity; |
121 m_isAfterExpansion = true; | 121 m_isAfterExpansion = true; |
122 } | 122 } |
123 } else { | 123 } else { |
124 m_isAfterExpansion = false; | 124 m_isAfterExpansion = false; |
125 } | 125 } |
126 | 126 |
127 // Account for word spacing. | 127 // Account for word spacing. |
128 // We apply additional space between "words" by adding width to the spac
e character. | 128 // We apply additional space between "words" by adding width to the spac
e character. |
129 if (treatAsSpace && (charData.character != '\t' || !m_run.allowTabs()) | 129 if (isExpansionOpportunity && (charData.character != '\t' || !m_run.allo
wTabs()) |
130 && (charData.characterOffset || charData.character == noBreakSpace) | 130 && (charData.characterOffset || charData.character == noBreakSpace) |
131 && m_font->fontDescription().wordSpacing()) { | 131 && m_font->fontDescription().wordSpacing()) { |
132 width += m_font->fontDescription().wordSpacing(); | 132 width += m_font->fontDescription().wordSpacing(); |
133 } | 133 } |
134 } else { | 134 } else { |
135 m_isAfterExpansion = false; | 135 m_isAfterExpansion = false; |
136 } | 136 } |
137 | 137 |
138 return width; | 138 return width; |
139 } | 139 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 float initialWidth = m_runWidthSoFar; | 242 float initialWidth = m_runWidthSoFar; |
243 | 243 |
244 if (!advance(m_currentCharacter + 1)) | 244 if (!advance(m_currentCharacter + 1)) |
245 return false; | 245 return false; |
246 | 246 |
247 width = m_runWidthSoFar - initialWidth; | 247 width = m_runWidthSoFar - initialWidth; |
248 return true; | 248 return true; |
249 } | 249 } |
250 | 250 |
251 } // namespace blink | 251 } // namespace blink |
OLD | NEW |