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

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

Issue 54743004: Rendering text-justify:distribute for 8 bit characters. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add the test case in the TestExpectaions as NeedsRebaseline 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
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)
52 { 53 {
53 // If the padding is non-zero, count the number of spaces in the run 54 // If the padding is non-zero, count the number of spaces in the run
54 // and divide that by the padding for per space addition. 55 // and divide that by the padding for per space addition.
55 m_expansion = m_run.expansion(); 56 m_expansion = m_run.expansion();
57 m_distributeJustification = m_run.isDistributeJustification();
56 if (!m_expansion) 58 if (!m_expansion)
57 m_expansionPerOpportunity = 0; 59 m_expansionPerOpportunity = 0;
58 else { 60 else {
59 bool isAfterExpansion = m_isAfterExpansion; 61 bool isAfterExpansion = m_isAfterExpansion;
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); 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);
63
61 if (isAfterExpansion && !m_run.allowsTrailingExpansion()) 64 if (isAfterExpansion && !m_run.allowsTrailingExpansion())
62 expansionOpportunityCount--; 65 expansionOpportunityCount--;
63 66
64 if (!expansionOpportunityCount) 67 if (!expansionOpportunityCount)
65 m_expansionPerOpportunity = 0; 68 m_expansionPerOpportunity = 0;
66 else 69 else
67 m_expansionPerOpportunity = m_expansion / expansionOpportunityCount; 70 m_expansionPerOpportunity = m_expansion / expansionOpportunityCount;
68 } 71 }
69 } 72 }
70 73
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 } 202 }
200 } 203 }
201 } 204 }
202 205
203 if (hasExtraSpacing) { 206 if (hasExtraSpacing) {
204 // Account for letter-spacing. 207 // Account for letter-spacing.
205 if (width && m_font->letterSpacing()) 208 if (width && m_font->letterSpacing())
206 width += m_font->letterSpacing(); 209 width += m_font->letterSpacing();
207 210
208 static bool expandAroundIdeographs = Font::canExpandAroundIdeographs InComplexText(); 211 static bool expandAroundIdeographs = Font::canExpandAroundIdeographs InComplexText();
209 bool treatAsSpace = Font::treatAsSpace(character); 212 bool isExpansionOpportunity = Font::treatAsSpace(character) || m_dis tributeJustification;
210 if (treatAsSpace || (expandAroundIdeographs && Font::isCJKIdeographO rSymbol(character))) { 213 if (isExpansionOpportunity || (expandAroundIdeographs && Font::isCJK IdeographOrSymbol(character))) {
211 // Distribute the run's total expansion evenly over all expansio n opportunities in the run. 214 // Distribute the run's total expansion evenly over all expansio n opportunities in the run.
212 if (m_expansion) { 215 if (m_expansion) {
213 float previousExpansion = m_expansion; 216 float previousExpansion = m_expansion;
214 if (!treatAsSpace && !m_isAfterExpansion) { 217 if (!isExpansionOpportunity && !m_isAfterExpansion) {
215 // Take the expansion opportunity before this ideograph. 218 // Take the expansion opportunity before this ideograph.
216 m_expansion -= m_expansionPerOpportunity; 219 m_expansion -= m_expansionPerOpportunity;
217 float expansionAtThisOpportunity = !m_run.applyWordRound ing() ? m_expansionPerOpportunity : roundf(previousExpansion) - roundf(m_expansi on); 220 float expansionAtThisOpportunity = !m_run.applyWordRound ing() ? m_expansionPerOpportunity : roundf(previousExpansion) - roundf(m_expansi on);
218 m_runWidthSoFar += expansionAtThisOpportunity; 221 m_runWidthSoFar += expansionAtThisOpportunity;
219 if (glyphBuffer) { 222 if (glyphBuffer) {
220 if (glyphBuffer->isEmpty()) { 223 if (glyphBuffer->isEmpty()) {
221 if (m_forTextEmphasis) 224 if (m_forTextEmphasis)
222 glyphBuffer->add(fontData->zeroWidthSpaceGly ph(), fontData, m_expansionPerOpportunity); 225 glyphBuffer->add(fontData->zeroWidthSpaceGly ph(), fontData, m_expansionPerOpportunity);
223 else 226 else
224 glyphBuffer->add(fontData->spaceGlyph(), fon tData, expansionAtThisOpportunity); 227 glyphBuffer->add(fontData->spaceGlyph(), fon tData, expansionAtThisOpportunity);
225 } else 228 } else
226 glyphBuffer->expandLastAdvance(expansionAtThisOp portunity); 229 glyphBuffer->expandLastAdvance(expansionAtThisOp portunity);
227 } 230 }
228 previousExpansion = m_expansion; 231 previousExpansion = m_expansion;
229 } 232 }
230 if (m_run.allowsTrailingExpansion() || (m_run.ltr() && textI terator.currentCharacter() + advanceLength < static_cast<size_t>(m_run.length()) ) 233 if (m_run.allowsTrailingExpansion() || (m_run.ltr() && textI terator.currentCharacter() + advanceLength < static_cast<size_t>(m_run.length()) )
231 || (m_run.rtl() && textIterator.currentCharacter())) { 234 || (m_run.rtl() && textIterator.currentCharacter())) {
232 m_expansion -= m_expansionPerOpportunity; 235 m_expansion -= m_expansionPerOpportunity;
233 width += !m_run.applyWordRounding() ? m_expansionPerOppo rtunity : roundf(previousExpansion) - roundf(m_expansion); 236 width += !m_run.applyWordRounding() ? m_expansionPerOppo rtunity : roundf(previousExpansion) - roundf(m_expansion);
234 m_isAfterExpansion = true; 237 m_isAfterExpansion = true;
235 } 238 }
236 } else 239 } else
237 m_isAfterExpansion = false; 240 m_isAfterExpansion = false;
238 241
239 // Account for word spacing. 242 // Account for word spacing.
240 // We apply additional space between "words" by adding width to the space character. 243 // We apply additional space between "words" by adding width to the space character.
241 if (treatAsSpace && (character != '\t' || !m_run.allowTabs()) && (textIterator.currentCharacter() || character == noBreakSpace) && m_font->wordS pacing()) 244 if (isExpansionOpportunity && (character != '\t' || !m_run.allow Tabs()) && (textIterator.currentCharacter() || character == noBreakSpace) && m_f ont->wordSpacing())
242 width += m_font->wordSpacing(); 245 width += m_font->wordSpacing();
243 } else 246 } else
244 m_isAfterExpansion = false; 247 m_isAfterExpansion = false;
245 } 248 }
246 249
247 if (shouldApplyFontTransforms() && glyphBuffer && Font::treatAsSpace(cha racter)) 250 if (shouldApplyFontTransforms() && glyphBuffer && Font::treatAsSpace(cha racter))
248 charactersTreatedAsSpace.append(make_pair(glyphBuffer->size(), 251 charactersTreatedAsSpace.append(make_pair(glyphBuffer->size(),
249 OriginalAdvancesForCharacterTreatedAsSpace(character == ' ', gly phBuffer->size() ? glyphBuffer->advanceAt(glyphBuffer->size() - 1) : 0, width))) ; 252 OriginalAdvancesForCharacterTreatedAsSpace(character == ' ', gly phBuffer->size() ? glyphBuffer->advanceAt(glyphBuffer->size() - 1) : 0, width))) ;
250 253
251 if (m_accountForGlyphBounds) { 254 if (m_accountForGlyphBounds) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 unsigned oldSize = glyphBuffer.size(); 337 unsigned oldSize = glyphBuffer.size();
335 advance(m_currentCharacter + 1, &glyphBuffer); 338 advance(m_currentCharacter + 1, &glyphBuffer);
336 float w = 0; 339 float w = 0;
337 for (unsigned i = oldSize; i < glyphBuffer.size(); ++i) 340 for (unsigned i = oldSize; i < glyphBuffer.size(); ++i)
338 w += glyphBuffer.advanceAt(i); 341 w += glyphBuffer.advanceAt(i);
339 width = w; 342 width = w;
340 return glyphBuffer.size() > oldSize; 343 return glyphBuffer.size() > oldSize;
341 } 344 }
342 345
343 } 346 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698