OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 | 137 |
138 unsigned offset = 0; | 138 unsigned offset = 0; |
139 TextRun run = constructTextRun(originalFont(), this, offset, textLength(), | 139 TextRun run = constructTextRun(originalFont(), this, offset, textLength(), |
140 styleRef(), style()->direction()); | 140 styleRef(), style()->direction()); |
141 FontDescription description = originalFont().getFontDescription(); | 141 FontDescription description = originalFont().getFontDescription(); |
142 float emWidth = description.computedSize(); | 142 float emWidth = description.computedSize(); |
143 if (!(style()->textDecorationsInEffect() & | 143 if (!(style()->textDecorationsInEffect() & |
144 (TextDecorationUnderline | TextDecorationOverline))) | 144 (TextDecorationUnderline | TextDecorationOverline))) |
145 emWidth *= textCombineMargin; | 145 emWidth *= textCombineMargin; |
146 | 146 |
147 description.setOrientation( | 147 // We are going to draw combined text horizontally. |
148 FontOrientation:: | 148 description.setOrientation(FontOrientation::Horizontal); |
149 Horizontal); // We are going to draw combined text horizontally. | |
150 m_combinedTextWidth = originalFont().width(run); | 149 m_combinedTextWidth = originalFont().width(run); |
151 | 150 |
152 FontSelector* fontSelector = style()->font().getFontSelector(); | 151 FontSelector* fontSelector = style()->font().getFontSelector(); |
153 | 152 |
154 bool shouldUpdateFont = mutableStyleRef().setFontDescription( | 153 bool shouldUpdateFont = mutableStyleRef().setFontDescription( |
155 description); // Need to change font orientation to horizontal. | 154 description); // Need to change font orientation to horizontal. |
156 | 155 |
157 if (m_combinedTextWidth <= emWidth) { | 156 if (m_combinedTextWidth <= emWidth) { |
158 m_scaleX = 1.0f; | 157 m_scaleX = 1.0f; |
159 } else { | 158 } else { |
160 // Need to try compressed glyphs. | 159 // Need to try compressed glyphs. |
161 static const FontWidthVariant widthVariants[] = {HalfWidth, ThirdWidth, | 160 static const FontWidthVariant widthVariants[] = {HalfWidth, ThirdWidth, |
162 QuarterWidth}; | 161 QuarterWidth}; |
163 for (size_t i = 0; i < WTF_ARRAY_LENGTH(widthVariants); ++i) { | 162 for (size_t i = 0; i < WTF_ARRAY_LENGTH(widthVariants); ++i) { |
164 description.setWidthVariant(widthVariants[i]); | 163 description.setWidthVariant(widthVariants[i]); |
165 Font compressedFont = Font(description); | 164 Font compressedFont = Font(description); |
166 compressedFont.update(fontSelector); | 165 compressedFont.update(fontSelector); |
167 float runWidth = compressedFont.width(run); | 166 float runWidth = compressedFont.width(run); |
168 if (runWidth <= emWidth) { | 167 if (runWidth <= emWidth) { |
169 m_combinedTextWidth = runWidth; | 168 m_combinedTextWidth = runWidth; |
170 | 169 |
171 // Replace my font with the new one. | 170 // Replace my font with the new one. |
172 shouldUpdateFont = mutableStyleRef().setFontDescription(description); | 171 shouldUpdateFont = mutableStyleRef().setFontDescription(description); |
173 break; | 172 break; |
174 } | 173 } |
175 } | 174 } |
176 | 175 |
177 // If width > ~1em, shrink to fit within ~1em, otherwise render without scal
ing (no expansion) | 176 // If width > ~1em, shrink to fit within ~1em, otherwise render without |
| 177 // scaling (no expansion). |
178 // http://dev.w3.org/csswg/css-writing-modes-3/#text-combine-compression | 178 // http://dev.w3.org/csswg/css-writing-modes-3/#text-combine-compression |
179 if (m_combinedTextWidth > emWidth) { | 179 if (m_combinedTextWidth > emWidth) { |
180 m_scaleX = emWidth / m_combinedTextWidth; | 180 m_scaleX = emWidth / m_combinedTextWidth; |
181 m_combinedTextWidth = emWidth; | 181 m_combinedTextWidth = emWidth; |
182 } else { | 182 } else { |
183 m_scaleX = 1.0f; | 183 m_scaleX = 1.0f; |
184 } | 184 } |
185 } | 185 } |
186 | 186 |
187 if (shouldUpdateFont) | 187 if (shouldUpdateFont) |
188 style()->font().update(fontSelector); | 188 style()->font().update(fontSelector); |
189 } | 189 } |
190 | 190 |
191 } // namespace blink | 191 } // namespace blink |
OLD | NEW |