Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: trunk/Source/platform/fonts/WidthIterator.cpp

Issue 146503002: Revert 165189 "Rendering text-justify:distribute for 8 bit chara..." (Closed) Base URL: svn://svn.chromium.org/blink/
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 , m_isAfterExpansion(!run.allowsLeadingExpansion()) 42 , m_isAfterExpansion(!run.allowsLeadingExpansion())
43 , m_finalRoundingWidth(0) 43 , m_finalRoundingWidth(0)
44 , m_typesettingFeatures(font->typesettingFeatures()) 44 , m_typesettingFeatures(font->typesettingFeatures())
45 , m_fallbackFonts(fallbackFonts) 45 , m_fallbackFonts(fallbackFonts)
46 , m_accountForGlyphBounds(accountForGlyphBounds) 46 , m_accountForGlyphBounds(accountForGlyphBounds)
47 , m_maxGlyphBoundingBoxY(numeric_limits<float>::min()) 47 , m_maxGlyphBoundingBoxY(numeric_limits<float>::min())
48 , m_minGlyphBoundingBoxY(numeric_limits<float>::max()) 48 , m_minGlyphBoundingBoxY(numeric_limits<float>::max())
49 , m_firstGlyphOverflow(0) 49 , m_firstGlyphOverflow(0)
50 , m_lastGlyphOverflow(0) 50 , m_lastGlyphOverflow(0)
51 , m_forTextEmphasis(forTextEmphasis) 51 , m_forTextEmphasis(forTextEmphasis)
52 , m_distributeJustification(false)
53 { 52 {
54 // If the padding is non-zero, count the number of spaces in the run 53 // 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. 54 // and divide that by the padding for per space addition.
56 m_expansion = m_run.expansion(); 55 m_expansion = m_run.expansion();
57 m_distributeJustification = m_run.isDistributeJustification();
58 if (!m_expansion) 56 if (!m_expansion)
59 m_expansionPerOpportunity = 0; 57 m_expansionPerOpportunity = 0;
60 else { 58 else {
61 bool isAfterExpansion = m_isAfterExpansion; 59 bool isAfterExpansion = m_isAfterExpansion;
62 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); 60 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
64 if (isAfterExpansion && !m_run.allowsTrailingExpansion()) 61 if (isAfterExpansion && !m_run.allowsTrailingExpansion())
65 expansionOpportunityCount--; 62 expansionOpportunityCount--;
66 63
67 if (!expansionOpportunityCount) 64 if (!expansionOpportunityCount)
68 m_expansionPerOpportunity = 0; 65 m_expansionPerOpportunity = 0;
69 else 66 else
70 m_expansionPerOpportunity = m_expansion / expansionOpportunityCount; 67 m_expansionPerOpportunity = m_expansion / expansionOpportunityCount;
71 } 68 }
72 } 69 }
73 70
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 } 199 }
203 } 200 }
204 } 201 }
205 202
206 if (hasExtraSpacing) { 203 if (hasExtraSpacing) {
207 // Account for letter-spacing. 204 // Account for letter-spacing.
208 if (width && m_font->letterSpacing()) 205 if (width && m_font->letterSpacing())
209 width += m_font->letterSpacing(); 206 width += m_font->letterSpacing();
210 207
211 static bool expandAroundIdeographs = Font::canExpandAroundIdeographs InComplexText(); 208 static bool expandAroundIdeographs = Font::canExpandAroundIdeographs InComplexText();
212 bool isExpansionOpportunity = Font::treatAsSpace(character) || m_dis tributeJustification; 209 bool treatAsSpace = Font::treatAsSpace(character);
213 if (isExpansionOpportunity || (expandAroundIdeographs && Font::isCJK IdeographOrSymbol(character))) { 210 if (treatAsSpace || (expandAroundIdeographs && Font::isCJKIdeographO rSymbol(character))) {
214 // Distribute the run's total expansion evenly over all expansio n opportunities in the run. 211 // Distribute the run's total expansion evenly over all expansio n opportunities in the run.
215 if (m_expansion) { 212 if (m_expansion) {
216 float previousExpansion = m_expansion; 213 float previousExpansion = m_expansion;
217 if (!isExpansionOpportunity && !m_isAfterExpansion) { 214 if (!treatAsSpace && !m_isAfterExpansion) {
218 // Take the expansion opportunity before this ideograph. 215 // Take the expansion opportunity before this ideograph.
219 m_expansion -= m_expansionPerOpportunity; 216 m_expansion -= m_expansionPerOpportunity;
220 float expansionAtThisOpportunity = !m_run.applyWordRound ing() ? m_expansionPerOpportunity : roundf(previousExpansion) - roundf(m_expansi on); 217 float expansionAtThisOpportunity = !m_run.applyWordRound ing() ? m_expansionPerOpportunity : roundf(previousExpansion) - roundf(m_expansi on);
221 m_runWidthSoFar += expansionAtThisOpportunity; 218 m_runWidthSoFar += expansionAtThisOpportunity;
222 if (glyphBuffer) { 219 if (glyphBuffer) {
223 if (glyphBuffer->isEmpty()) { 220 if (glyphBuffer->isEmpty()) {
224 if (m_forTextEmphasis) 221 if (m_forTextEmphasis)
225 glyphBuffer->add(fontData->zeroWidthSpaceGly ph(), fontData, m_expansionPerOpportunity); 222 glyphBuffer->add(fontData->zeroWidthSpaceGly ph(), fontData, m_expansionPerOpportunity);
226 else 223 else
227 glyphBuffer->add(fontData->spaceGlyph(), fon tData, expansionAtThisOpportunity); 224 glyphBuffer->add(fontData->spaceGlyph(), fon tData, expansionAtThisOpportunity);
228 } else 225 } else
229 glyphBuffer->expandLastAdvance(expansionAtThisOp portunity); 226 glyphBuffer->expandLastAdvance(expansionAtThisOp portunity);
230 } 227 }
231 previousExpansion = m_expansion; 228 previousExpansion = m_expansion;
232 } 229 }
233 if (m_run.allowsTrailingExpansion() || (m_run.ltr() && textI terator.currentCharacter() + advanceLength < static_cast<size_t>(m_run.length()) ) 230 if (m_run.allowsTrailingExpansion() || (m_run.ltr() && textI terator.currentCharacter() + advanceLength < static_cast<size_t>(m_run.length()) )
234 || (m_run.rtl() && textIterator.currentCharacter())) { 231 || (m_run.rtl() && textIterator.currentCharacter())) {
235 m_expansion -= m_expansionPerOpportunity; 232 m_expansion -= m_expansionPerOpportunity;
236 width += !m_run.applyWordRounding() ? m_expansionPerOppo rtunity : roundf(previousExpansion) - roundf(m_expansion); 233 width += !m_run.applyWordRounding() ? m_expansionPerOppo rtunity : roundf(previousExpansion) - roundf(m_expansion);
237 m_isAfterExpansion = true; 234 m_isAfterExpansion = true;
238 } 235 }
239 } else 236 } else
240 m_isAfterExpansion = false; 237 m_isAfterExpansion = false;
241 238
242 // Account for word spacing. 239 // Account for word spacing.
243 // We apply additional space between "words" by adding width to the space character. 240 // We apply additional space between "words" by adding width to the space character.
244 if (isExpansionOpportunity && (character != '\t' || !m_run.allow Tabs()) && (textIterator.currentCharacter() || character == noBreakSpace) && m_f ont->wordSpacing()) 241 if (treatAsSpace && (character != '\t' || !m_run.allowTabs()) && (textIterator.currentCharacter() || character == noBreakSpace) && m_font->wordS pacing())
245 width += m_font->wordSpacing(); 242 width += m_font->wordSpacing();
246 } else 243 } else
247 m_isAfterExpansion = false; 244 m_isAfterExpansion = false;
248 } 245 }
249 246
250 if (shouldApplyFontTransforms() && glyphBuffer && Font::treatAsSpace(cha racter)) 247 if (shouldApplyFontTransforms() && glyphBuffer && Font::treatAsSpace(cha racter))
251 charactersTreatedAsSpace.append(make_pair(glyphBuffer->size(), 248 charactersTreatedAsSpace.append(make_pair(glyphBuffer->size(),
252 OriginalAdvancesForCharacterTreatedAsSpace(character == ' ', gly phBuffer->size() ? glyphBuffer->advanceAt(glyphBuffer->size() - 1) : 0, width))) ; 249 OriginalAdvancesForCharacterTreatedAsSpace(character == ' ', gly phBuffer->size() ? glyphBuffer->advanceAt(glyphBuffer->size() - 1) : 0, width))) ;
253 250
254 if (m_accountForGlyphBounds) { 251 if (m_accountForGlyphBounds) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 unsigned oldSize = glyphBuffer.size(); 334 unsigned oldSize = glyphBuffer.size();
338 advance(m_currentCharacter + 1, &glyphBuffer); 335 advance(m_currentCharacter + 1, &glyphBuffer);
339 float w = 0; 336 float w = 0;
340 for (unsigned i = oldSize; i < glyphBuffer.size(); ++i) 337 for (unsigned i = oldSize; i < glyphBuffer.size(); ++i)
341 w += glyphBuffer.advanceAt(i); 338 w += glyphBuffer.advanceAt(i);
342 width = w; 339 width = w;
343 return glyphBuffer.size() > oldSize; 340 return glyphBuffer.size() > oldSize;
344 } 341 }
345 342
346 } 343 }
OLDNEW
« no previous file with comments | « trunk/Source/platform/fonts/WidthIterator.h ('k') | trunk/Source/platform/fonts/mac/ComplexTextController.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698