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

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: use const parameter Created 6 years, 8 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 , m_isAfterExpansion(!run.allowsLeadingExpansion()) 44 , m_isAfterExpansion(!run.allowsLeadingExpansion())
45 , m_finalRoundingWidth(0) 45 , m_finalRoundingWidth(0)
46 , m_typesettingFeatures(font->fontDescription().typesettingFeatures()) 46 , m_typesettingFeatures(font->fontDescription().typesettingFeatures())
47 , m_fallbackFonts(fallbackFonts) 47 , m_fallbackFonts(fallbackFonts)
48 , m_accountForGlyphBounds(accountForGlyphBounds) 48 , m_accountForGlyphBounds(accountForGlyphBounds)
49 , m_maxGlyphBoundingBoxY(numeric_limits<float>::min()) 49 , m_maxGlyphBoundingBoxY(numeric_limits<float>::min())
50 , m_minGlyphBoundingBoxY(numeric_limits<float>::max()) 50 , m_minGlyphBoundingBoxY(numeric_limits<float>::max())
51 , m_firstGlyphOverflow(0) 51 , m_firstGlyphOverflow(0)
52 , m_lastGlyphOverflow(0) 52 , m_lastGlyphOverflow(0)
53 , m_forTextEmphasis(forTextEmphasis) 53 , m_forTextEmphasis(forTextEmphasis)
54 , m_distributeJustification(false)
54 { 55 {
55 // If the padding is non-zero, count the number of spaces in the run 56 // 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. 57 // and divide that by the padding for per space addition.
57 m_expansion = m_run.expansion(); 58 m_expansion = m_run.expansion();
59 m_distributeJustification = m_run.isDistributeJustification();
58 if (!m_expansion) 60 if (!m_expansion)
59 m_expansionPerOpportunity = 0; 61 m_expansionPerOpportunity = 0;
60 else { 62 else {
61 bool isAfterExpansion = m_isAfterExpansion; 63 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); 64 unsigned expansionOpportunityCount = m_run.is8Bit() ? Character::expansi onOpportunityCount(m_run.characters8(), m_run.length(), m_run.ltr() ? LTR : RTL, isAfterExpansion, m_distributeJustification) : Character::expansionOpportunityC ount(m_run.characters16(), m_run.length(), m_run.ltr() ? LTR : RTL, isAfterExpan sion, m_distributeJustification);
63 if (isAfterExpansion && !m_run.allowsTrailingExpansion()) 65 if (isAfterExpansion && !m_run.allowsTrailingExpansion())
64 expansionOpportunityCount--; 66 expansionOpportunityCount--;
65 67
66 if (!expansionOpportunityCount) 68 if (!expansionOpportunityCount)
67 m_expansionPerOpportunity = 0; 69 m_expansionPerOpportunity = 0;
68 else 70 else
69 m_expansionPerOpportunity = m_expansion / expansionOpportunityCount; 71 m_expansionPerOpportunity = m_expansion / expansionOpportunityCount;
70 } 72 }
71 } 73 }
72 74
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 } 203 }
202 } 204 }
203 } 205 }
204 206
205 if (hasExtraSpacing) { 207 if (hasExtraSpacing) {
206 // Account for letter-spacing. 208 // Account for letter-spacing.
207 if (width && m_font->fontDescription().letterSpacing()) 209 if (width && m_font->fontDescription().letterSpacing())
208 width += m_font->fontDescription().letterSpacing(); 210 width += m_font->fontDescription().letterSpacing();
209 211
210 static bool expandAroundIdeographs = FontPlatformFeatures::canExpand AroundIdeographsInComplexText(); 212 static bool expandAroundIdeographs = FontPlatformFeatures::canExpand AroundIdeographsInComplexText();
211 bool treatAsSpace = Character::treatAsSpace(character); 213 bool isExpansionOpportunity = Character::treatAsSpace(character) || m_distributeJustification;
212 if (treatAsSpace || (expandAroundIdeographs && Character::isCJKIdeog raphOrSymbol(character))) { 214 if (isExpansionOpportunity || (expandAroundIdeographs && Character:: isCJKIdeographOrSymbol(character))) {
213 // Distribute the run's total expansion evenly over all expansio n opportunities in the run. 215 // Distribute the run's total expansion evenly over all expansio n opportunities in the run.
214 if (m_expansion) { 216 if (m_expansion) {
215 float previousExpansion = m_expansion; 217 float previousExpansion = m_expansion;
216 if (!treatAsSpace && !m_isAfterExpansion) { 218 if (!isExpansionOpportunity && !m_isAfterExpansion) {
217 // Take the expansion opportunity before this ideograph. 219 // Take the expansion opportunity before this ideograph.
218 m_expansion -= m_expansionPerOpportunity; 220 m_expansion -= m_expansionPerOpportunity;
219 float expansionAtThisOpportunity = !m_run.applyWordRound ing() ? m_expansionPerOpportunity : roundf(previousExpansion) - roundf(m_expansi on); 221 float expansionAtThisOpportunity = !m_run.applyWordRound ing() ? m_expansionPerOpportunity : roundf(previousExpansion) - roundf(m_expansi on);
220 m_runWidthSoFar += expansionAtThisOpportunity; 222 m_runWidthSoFar += expansionAtThisOpportunity;
221 if (glyphBuffer) { 223 if (glyphBuffer) {
222 if (glyphBuffer->isEmpty()) { 224 if (glyphBuffer->isEmpty()) {
223 if (m_forTextEmphasis) 225 if (m_forTextEmphasis)
224 glyphBuffer->add(fontData->zeroWidthSpaceGly ph(), fontData, m_expansionPerOpportunity); 226 glyphBuffer->add(fontData->zeroWidthSpaceGly ph(), fontData, m_expansionPerOpportunity);
225 else 227 else
226 glyphBuffer->add(fontData->spaceGlyph(), fon tData, expansionAtThisOpportunity); 228 glyphBuffer->add(fontData->spaceGlyph(), fon tData, expansionAtThisOpportunity);
227 } else 229 } else
228 glyphBuffer->expandLastAdvance(expansionAtThisOp portunity); 230 glyphBuffer->expandLastAdvance(expansionAtThisOp portunity);
229 } 231 }
230 previousExpansion = m_expansion; 232 previousExpansion = m_expansion;
231 } 233 }
232 if (m_run.allowsTrailingExpansion() || (m_run.ltr() && textI terator.currentCharacter() + advanceLength < static_cast<size_t>(m_run.length()) ) 234 if (m_run.allowsTrailingExpansion() || (m_run.ltr() && textI terator.currentCharacter() + advanceLength < static_cast<size_t>(m_run.length()) )
233 || (m_run.rtl() && textIterator.currentCharacter())) { 235 || (m_run.rtl() && textIterator.currentCharacter())) {
234 m_expansion -= m_expansionPerOpportunity; 236 m_expansion -= m_expansionPerOpportunity;
235 width += !m_run.applyWordRounding() ? m_expansionPerOppo rtunity : roundf(previousExpansion) - roundf(m_expansion); 237 width += !m_run.applyWordRounding() ? m_expansionPerOppo rtunity : roundf(previousExpansion) - roundf(m_expansion);
236 m_isAfterExpansion = true; 238 m_isAfterExpansion = true;
237 } 239 }
238 } else 240 } else
239 m_isAfterExpansion = false; 241 m_isAfterExpansion = false;
240 242
241 // Account for word spacing. 243 // Account for word spacing.
242 // We apply additional space between "words" by adding width to the space character. 244 // We apply additional space between "words" by adding width to the space character.
243 if (treatAsSpace && (character != '\t' || !m_run.allowTabs()) && (textIterator.currentCharacter() || character == noBreakSpace) && m_font->fontD escription().wordSpacing()) 245 if (isExpansionOpportunity && (character != '\t' || !m_run.allow Tabs()) && (textIterator.currentCharacter() || character == noBreakSpace) && m_f ont->fontDescription().wordSpacing())
244 width += m_font->fontDescription().wordSpacing(); 246 width += m_font->fontDescription().wordSpacing();
245 } else 247 } else
246 m_isAfterExpansion = false; 248 m_isAfterExpansion = false;
247 } 249 }
248 250
249 if (shouldApplyFontTransforms() && glyphBuffer && Character::treatAsSpac e(character)) { 251 if (shouldApplyFontTransforms() && glyphBuffer && Character::treatAsSpac e(character)) {
250 charactersTreatedAsSpace.append(make_pair(glyphBuffer->size(), 252 charactersTreatedAsSpace.append(make_pair(glyphBuffer->size(),
251 OriginalAdvancesForCharacterTreatedAsSpace(character == ' ', 253 OriginalAdvancesForCharacterTreatedAsSpace(character == ' ',
252 glyphBuffer->size() ? glyphBuffer->advanceAt(glyphBuffer->si ze() - 1).width() : 0, 254 glyphBuffer->size() ? glyphBuffer->advanceAt(glyphBuffer->si ze() - 1).width() : 0,
253 width))); 255 width)));
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 unsigned oldSize = glyphBuffer.size(); 341 unsigned oldSize = glyphBuffer.size();
340 advance(m_currentCharacter + 1, &glyphBuffer); 342 advance(m_currentCharacter + 1, &glyphBuffer);
341 float w = 0; 343 float w = 0;
342 for (unsigned i = oldSize; i < glyphBuffer.size(); ++i) 344 for (unsigned i = oldSize; i < glyphBuffer.size(); ++i)
343 w += glyphBuffer.advanceAt(i).width(); 345 w += glyphBuffer.advanceAt(i).width();
344 width = w; 346 width = w;
345 return glyphBuffer.size() > oldSize; 347 return glyphBuffer.size() > oldSize;
346 } 348 }
347 349
348 } 350 }
OLDNEW
« no previous file with comments | « Source/platform/fonts/WidthIterator.h ('k') | Source/platform/fonts/mac/ComplexTextController.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698