Chromium Code Reviews| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 , m_isAfterExpansion(!run.allowsLeadingExpansion()) | 43 , m_isAfterExpansion(!run.allowsLeadingExpansion()) |
| 44 , m_finalRoundingWidth(0) | 44 , m_finalRoundingWidth(0) |
| 45 , m_typesettingFeatures(font->typesettingFeatures()) | 45 , m_typesettingFeatures(font->typesettingFeatures()) |
| 46 , m_fallbackFonts(fallbackFonts) | 46 , m_fallbackFonts(fallbackFonts) |
| 47 , m_accountForGlyphBounds(accountForGlyphBounds) | 47 , m_accountForGlyphBounds(accountForGlyphBounds) |
| 48 , m_maxGlyphBoundingBoxY(numeric_limits<float>::min()) | 48 , m_maxGlyphBoundingBoxY(numeric_limits<float>::min()) |
| 49 , m_minGlyphBoundingBoxY(numeric_limits<float>::max()) | 49 , m_minGlyphBoundingBoxY(numeric_limits<float>::max()) |
| 50 , m_firstGlyphOverflow(0) | 50 , m_firstGlyphOverflow(0) |
| 51 , m_lastGlyphOverflow(0) | 51 , m_lastGlyphOverflow(0) |
| 52 , m_forTextEmphasis(forTextEmphasis) | 52 , m_forTextEmphasis(forTextEmphasis) |
| 53 , m_distributeJustification(false) | |
| 53 { | 54 { |
| 54 // 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 |
| 55 // and divide that by the padding for per space addition. | 56 // and divide that by the padding for per space addition. |
| 56 m_expansion = m_run.expansion(); | 57 m_expansion = m_run.expansion(); |
| 58 m_distributeJustification = m_run.isDistributeJustification(); | |
| 57 if (!m_expansion) | 59 if (!m_expansion) |
| 58 m_expansionPerOpportunity = 0; | 60 m_expansionPerOpportunity = 0; |
| 59 else { | 61 else { |
| 60 bool isAfterExpansion = m_isAfterExpansion; | 62 bool isAfterExpansion = m_isAfterExpansion; |
| 61 unsigned expansionOpportunityCount = m_run.is8Bit() ? Font::expansionOpp ortunityCount(m_run.characters8(), m_run.length(), m_run.ltr() ? LTR : RTL, isAf terExpansion) : Font::expansionOpportunityCount(m_run.characters16(), m_run.leng th(), m_run.ltr() ? LTR : RTL, isAfterExpansion); | 63 unsigned expansionOpportunityCount = m_run.is8Bit() ? Font::expansionOpp ortunityCount(m_run.characters8(), m_run.length(), m_run.ltr() ? LTR : RTL, isAf terExpansion, m_distributeJustification) : Font::expansionOpportunityCount(m_run .characters16(), m_run.length(), m_run.ltr() ? LTR : RTL, isAfterExpansion, m_di stributeJustification); |
| 64 | |
| 62 if (isAfterExpansion && !m_run.allowsTrailingExpansion()) | 65 if (isAfterExpansion && !m_run.allowsTrailingExpansion()) |
| 63 expansionOpportunityCount--; | 66 expansionOpportunityCount--; |
| 64 | 67 |
| 65 if (!expansionOpportunityCount) | 68 if (!expansionOpportunityCount) |
| 66 m_expansionPerOpportunity = 0; | 69 m_expansionPerOpportunity = 0; |
| 67 else | 70 else |
| 68 m_expansionPerOpportunity = m_expansion / expansionOpportunityCount; | 71 m_expansionPerOpportunity = m_expansion / expansionOpportunityCount; |
| 69 } | 72 } |
| 70 } | 73 } |
| 71 | 74 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 } | 206 } |
| 204 } | 207 } |
| 205 } | 208 } |
| 206 | 209 |
| 207 if (hasExtraSpacing) { | 210 if (hasExtraSpacing) { |
| 208 // Account for letter-spacing. | 211 // Account for letter-spacing. |
| 209 if (width && m_font->letterSpacing()) | 212 if (width && m_font->letterSpacing()) |
| 210 width += m_font->letterSpacing(); | 213 width += m_font->letterSpacing(); |
| 211 | 214 |
| 212 static bool expandAroundIdeographs = Font::canExpandAroundIdeographs InComplexText(); | 215 static bool expandAroundIdeographs = Font::canExpandAroundIdeographs InComplexText(); |
| 213 bool treatAsSpace = Font::treatAsSpace(character); | 216 bool needExpansion = Font::treatAsSpace(character) || m_distributeJu stification; |
|
leviw_travelin_and_unemployed
2013/11/01 20:39:14
how about something like isExpansionOpportunity in
dw.im
2013/11/02 03:13:01
could be better name.. :)
dw.im
2013/11/04 02:11:09
Done.
| |
| 214 if (treatAsSpace || (expandAroundIdeographs && Font::isCJKIdeographO rSymbol(character))) { | 217 if (needExpansion || (expandAroundIdeographs && Font::isCJKIdeograph OrSymbol(character))) { |
| 215 // Distribute the run's total expansion evenly over all expansio n opportunities in the run. | 218 // Distribute the run's total expansion evenly over all expansio n opportunities in the run. |
| 216 if (m_expansion) { | 219 if (m_expansion) { |
| 217 float previousExpansion = m_expansion; | 220 float previousExpansion = m_expansion; |
| 218 if (!treatAsSpace && !m_isAfterExpansion) { | 221 if (!needExpansion && !m_isAfterExpansion) { |
| 219 // Take the expansion opportunity before this ideograph. | 222 // Take the expansion opportunity before this ideograph. |
| 220 m_expansion -= m_expansionPerOpportunity; | 223 m_expansion -= m_expansionPerOpportunity; |
| 221 float expansionAtThisOpportunity = !m_run.applyWordRound ing() ? m_expansionPerOpportunity : roundf(previousExpansion) - roundf(m_expansi on); | 224 float expansionAtThisOpportunity = !m_run.applyWordRound ing() ? m_expansionPerOpportunity : roundf(previousExpansion) - roundf(m_expansi on); |
| 222 m_runWidthSoFar += expansionAtThisOpportunity; | 225 m_runWidthSoFar += expansionAtThisOpportunity; |
| 223 if (glyphBuffer) { | 226 if (glyphBuffer) { |
| 224 if (glyphBuffer->isEmpty()) { | 227 if (glyphBuffer->isEmpty()) { |
| 225 if (m_forTextEmphasis) | 228 if (m_forTextEmphasis) |
| 226 glyphBuffer->add(fontData->zeroWidthSpaceGly ph(), fontData, m_expansionPerOpportunity); | 229 glyphBuffer->add(fontData->zeroWidthSpaceGly ph(), fontData, m_expansionPerOpportunity); |
| 227 else | 230 else |
| 228 glyphBuffer->add(fontData->spaceGlyph(), fon tData, expansionAtThisOpportunity); | 231 glyphBuffer->add(fontData->spaceGlyph(), fon tData, expansionAtThisOpportunity); |
| 229 } else | 232 } else |
| 230 glyphBuffer->expandLastAdvance(expansionAtThisOp portunity); | 233 glyphBuffer->expandLastAdvance(expansionAtThisOp portunity); |
| 231 } | 234 } |
| 232 previousExpansion = m_expansion; | 235 previousExpansion = m_expansion; |
| 233 } | 236 } |
| 234 if (m_run.allowsTrailingExpansion() || (m_run.ltr() && textI terator.currentCharacter() + advanceLength < static_cast<size_t>(m_run.length()) ) | 237 if (m_run.allowsTrailingExpansion() || (m_run.ltr() && textI terator.currentCharacter() + advanceLength < static_cast<size_t>(m_run.length()) ) |
| 235 || (m_run.rtl() && textIterator.currentCharacter())) { | 238 || (m_run.rtl() && textIterator.currentCharacter())) { |
| 236 m_expansion -= m_expansionPerOpportunity; | 239 m_expansion -= m_expansionPerOpportunity; |
| 237 width += !m_run.applyWordRounding() ? m_expansionPerOppo rtunity : roundf(previousExpansion) - roundf(m_expansion); | 240 width += !m_run.applyWordRounding() ? m_expansionPerOppo rtunity : roundf(previousExpansion) - roundf(m_expansion); |
| 238 m_isAfterExpansion = true; | 241 m_isAfterExpansion = true; |
| 239 } | 242 } |
| 240 } else | 243 } else |
| 241 m_isAfterExpansion = false; | 244 m_isAfterExpansion = false; |
| 242 | 245 |
| 243 // Account for word spacing. | 246 // Account for word spacing. |
| 244 // We apply additional space between "words" by adding width to the space character. | 247 // We apply additional space between "words" by adding width to the space character. |
| 245 if (treatAsSpace && (character != '\t' || !m_run.allowTabs()) && (textIterator.currentCharacter() || character == noBreakSpace) && m_font->wordS pacing()) | 248 if (needExpansion && (character != '\t' || !m_run.allowTabs()) & & (textIterator.currentCharacter() || character == noBreakSpace) && m_font->word Spacing()) |
| 246 width += m_font->wordSpacing(); | 249 width += m_font->wordSpacing(); |
| 247 } else | 250 } else |
| 248 m_isAfterExpansion = false; | 251 m_isAfterExpansion = false; |
| 249 } | 252 } |
| 250 | 253 |
| 251 if (shouldApplyFontTransforms() && glyphBuffer && Font::treatAsSpace(cha racter)) | 254 if (shouldApplyFontTransforms() && glyphBuffer && Font::treatAsSpace(cha racter)) |
| 252 charactersTreatedAsSpace.append(make_pair(glyphBuffer->size(), | 255 charactersTreatedAsSpace.append(make_pair(glyphBuffer->size(), |
| 253 OriginalAdvancesForCharacterTreatedAsSpace(character == ' ', gly phBuffer->size() ? glyphBuffer->advanceAt(glyphBuffer->size() - 1) : 0, width))) ; | 256 OriginalAdvancesForCharacterTreatedAsSpace(character == ' ', gly phBuffer->size() ? glyphBuffer->advanceAt(glyphBuffer->size() - 1) : 0, width))) ; |
| 254 | 257 |
| 255 if (m_accountForGlyphBounds) { | 258 if (m_accountForGlyphBounds) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 int oldSize = glyphBuffer.size(); | 341 int oldSize = glyphBuffer.size(); |
| 339 advance(m_currentCharacter + 1, &glyphBuffer); | 342 advance(m_currentCharacter + 1, &glyphBuffer); |
| 340 float w = 0; | 343 float w = 0; |
| 341 for (int i = oldSize; i < glyphBuffer.size(); ++i) | 344 for (int i = oldSize; i < glyphBuffer.size(); ++i) |
| 342 w += glyphBuffer.advanceAt(i); | 345 w += glyphBuffer.advanceAt(i); |
| 343 width = w; | 346 width = w; |
| 344 return glyphBuffer.size() > oldSize; | 347 return glyphBuffer.size() > oldSize; |
| 345 } | 348 } |
| 346 | 349 |
| 347 } | 350 } |
| OLD | NEW |