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 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 , m_lastGlyphOverflow(0) | 52 , m_lastGlyphOverflow(0) |
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.ltr() ? LTR : RTL,
isAfterExpansion) : Character::expansionOpportunityCount(m_run.characters16(),
m_run.length(), m_run.ltr() ? LTR : RTL, 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); |
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 18 matching lines...) Expand all Loading... |
91 { | 91 { |
92 } | 92 } |
93 | 93 |
94 bool characterIsSpace; | 94 bool characterIsSpace; |
95 float advanceBeforeCharacter; | 95 float advanceBeforeCharacter; |
96 float advanceAtCharacter; | 96 float advanceAtCharacter; |
97 }; | 97 }; |
98 | 98 |
99 typedef Vector<pair<int, OriginalAdvancesForCharacterTreatedAsSpace>, 64> Charac
tersTreatedAsSpace; | 99 typedef Vector<pair<int, OriginalAdvancesForCharacterTreatedAsSpace>, 64> Charac
tersTreatedAsSpace; |
100 | 100 |
101 static inline float applyFontTransforms(GlyphBuffer* glyphBuffer, bool ltr, unsi
gned& lastGlyphCount, const SimpleFontData* fontData, TypesettingFeatures typese
ttingFeatures, CharactersTreatedAsSpace& charactersTreatedAsSpace) | 101 static inline float applyFontTransforms(GlyphBuffer* glyphBuffer, unsigned& last
GlyphCount, TypesettingFeatures typesettingFeatures, CharactersTreatedAsSpace& c
haractersTreatedAsSpace) |
102 { | 102 { |
103 ASSERT(typesettingFeatures & (Kerning | Ligatures)); | 103 ASSERT(typesettingFeatures & (Kerning | Ligatures)); |
104 | 104 |
105 if (!glyphBuffer) | 105 if (!glyphBuffer) |
106 return 0; | 106 return 0; |
107 | 107 |
108 unsigned glyphBufferSize = glyphBuffer->size(); | 108 unsigned glyphBufferSize = glyphBuffer->size(); |
109 if (glyphBuffer->size() <= lastGlyphCount + 1) | 109 if (glyphBuffer->size() <= lastGlyphCount + 1) |
110 return 0; | 110 return 0; |
111 | 111 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 // We special case spaces in two ways when applying word rounding. | 171 // We special case spaces in two ways when applying word rounding. |
172 // First, we round spaces to an adjusted width in all fonts. | 172 // First, we round spaces to an adjusted width in all fonts. |
173 // Second, in fixed-pitch fonts we ensure that all characters that | 173 // Second, in fixed-pitch fonts we ensure that all characters that |
174 // match the width of the space character have the same width as the
space character. | 174 // match the width of the space character have the same width as the
space character. |
175 if (m_run.applyWordRounding() && width == fontData->spaceWidth() &&
(fontData->pitch() == FixedPitch || glyph == fontData->spaceGlyph())) | 175 if (m_run.applyWordRounding() && width == fontData->spaceWidth() &&
(fontData->pitch() == FixedPitch || glyph == fontData->spaceGlyph())) |
176 width = fontData->adjustedSpaceWidth(); | 176 width = fontData->adjustedSpaceWidth(); |
177 } | 177 } |
178 | 178 |
179 if (fontData != lastFontData && width) { | 179 if (fontData != lastFontData && width) { |
180 if (shouldApplyFontTransforms()) | 180 if (shouldApplyFontTransforms()) |
181 m_runWidthSoFar += applyFontTransforms(glyphBuffer, m_run.ltr(),
lastGlyphCount, lastFontData, m_typesettingFeatures, charactersTreatedAsSpace); | 181 m_runWidthSoFar += applyFontTransforms(glyphBuffer, lastGlyphCou
nt, m_typesettingFeatures, charactersTreatedAsSpace); |
182 | 182 |
183 lastFontData = fontData; | 183 lastFontData = fontData; |
184 if (m_fallbackFonts && fontData != primaryFont) { | 184 if (m_fallbackFonts && fontData != primaryFont) { |
185 // FIXME: This does a little extra work that could be avoided if | 185 // FIXME: This does a little extra work that could be avoided if |
186 // glyphDataForCharacter() returned whether it chose to use a sm
all caps font. | 186 // glyphDataForCharacter() returned whether it chose to use a sm
all caps font. |
187 if (m_font->fontDescription().variant() == FontVariantNormal ||
character == toUpper(character)) | 187 if (m_font->fontDescription().variant() == FontVariantNormal ||
character == toUpper(character)) |
188 m_fallbackFonts->add(fontData); | 188 m_fallbackFonts->add(fontData); |
189 else { | 189 else { |
190 ASSERT(m_font->fontDescription().variant() == FontVariantSma
llCaps); | 190 ASSERT(m_font->fontDescription().variant() == FontVariantSma
llCaps); |
191 const GlyphData& uppercaseGlyphData = m_font->glyphDataForCh
aracter(toUpper(character), rtl); | 191 const GlyphData& uppercaseGlyphData = m_font->glyphDataForCh
aracter(toUpper(character), rtl); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 lastRoundingWidth = width - oldWidth; | 292 lastRoundingWidth = width - oldWidth; |
293 | 293 |
294 if (m_accountForGlyphBounds) { | 294 if (m_accountForGlyphBounds) { |
295 m_maxGlyphBoundingBoxY = max(m_maxGlyphBoundingBoxY, bounds.maxY()); | 295 m_maxGlyphBoundingBoxY = max(m_maxGlyphBoundingBoxY, bounds.maxY()); |
296 m_minGlyphBoundingBoxY = min(m_minGlyphBoundingBoxY, bounds.y()); | 296 m_minGlyphBoundingBoxY = min(m_minGlyphBoundingBoxY, bounds.y()); |
297 m_lastGlyphOverflow = max<float>(0, bounds.maxX() - width); | 297 m_lastGlyphOverflow = max<float>(0, bounds.maxX() - width); |
298 } | 298 } |
299 } | 299 } |
300 | 300 |
301 if (shouldApplyFontTransforms()) | 301 if (shouldApplyFontTransforms()) |
302 m_runWidthSoFar += applyFontTransforms(glyphBuffer, m_run.ltr(), lastGly
phCount, lastFontData, m_typesettingFeatures, charactersTreatedAsSpace); | 302 m_runWidthSoFar += applyFontTransforms(glyphBuffer, lastGlyphCount, m_ty
pesettingFeatures, charactersTreatedAsSpace); |
303 | 303 |
304 unsigned consumedCharacters = textIterator.currentCharacter() - m_currentCha
racter; | 304 unsigned consumedCharacters = textIterator.currentCharacter() - m_currentCha
racter; |
305 m_currentCharacter = textIterator.currentCharacter(); | 305 m_currentCharacter = textIterator.currentCharacter(); |
306 m_runWidthSoFar += widthSinceLastRounding; | 306 m_runWidthSoFar += widthSinceLastRounding; |
307 m_finalRoundingWidth = lastRoundingWidth; | 307 m_finalRoundingWidth = lastRoundingWidth; |
308 return consumedCharacters; | 308 return consumedCharacters; |
309 } | 309 } |
310 | 310 |
311 unsigned WidthIterator::advance(int offset, GlyphBuffer* glyphBuffer) | 311 unsigned WidthIterator::advance(int offset, GlyphBuffer* glyphBuffer) |
312 { | 312 { |
(...skipping 19 matching lines...) Expand all Loading... |
332 unsigned oldSize = glyphBuffer.size(); | 332 unsigned oldSize = glyphBuffer.size(); |
333 advance(m_currentCharacter + 1, &glyphBuffer); | 333 advance(m_currentCharacter + 1, &glyphBuffer); |
334 float w = 0; | 334 float w = 0; |
335 for (unsigned i = oldSize; i < glyphBuffer.size(); ++i) | 335 for (unsigned i = oldSize; i < glyphBuffer.size(); ++i) |
336 w += glyphBuffer.advanceAt(i).width(); | 336 w += glyphBuffer.advanceAt(i).width(); |
337 width = w; | 337 width = w; |
338 return glyphBuffer.size() > oldSize; | 338 return glyphBuffer.size() > oldSize; |
339 } | 339 } |
340 | 340 |
341 } | 341 } |
OLD | NEW |