summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/WebKit/Source/platform/fonts/WidthIterator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/WebKit/Source/platform/fonts/WidthIterator.cpp')
-rw-r--r--chromium/third_party/WebKit/Source/platform/fonts/WidthIterator.cpp56
1 files changed, 27 insertions, 29 deletions
diff --git a/chromium/third_party/WebKit/Source/platform/fonts/WidthIterator.cpp b/chromium/third_party/WebKit/Source/platform/fonts/WidthIterator.cpp
index b871cb95aa0..8816fd8158f 100644
--- a/chromium/third_party/WebKit/Source/platform/fonts/WidthIterator.cpp
+++ b/chromium/third_party/WebKit/Source/platform/fonts/WidthIterator.cpp
@@ -22,6 +22,8 @@
#include "config.h"
#include "platform/fonts/WidthIterator.h"
+#include "platform/fonts/Character.h"
+#include "platform/fonts/FontPlatformFeatures.h"
#include "platform/fonts/GlyphBuffer.h"
#include "platform/fonts/Latin1TextIterator.h"
#include "platform/fonts/SimpleFontData.h"
@@ -41,7 +43,7 @@ WidthIterator::WidthIterator(const Font* font, const TextRun& run, HashSet<const
, m_runWidthSoFar(0)
, m_isAfterExpansion(!run.allowsLeadingExpansion())
, m_finalRoundingWidth(0)
- , m_typesettingFeatures(font->typesettingFeatures())
+ , m_typesettingFeatures(font->fontDescription().typesettingFeatures())
, m_fallbackFonts(fallbackFonts)
, m_accountForGlyphBounds(accountForGlyphBounds)
, m_maxGlyphBoundingBoxY(numeric_limits<float>::min())
@@ -57,7 +59,7 @@ WidthIterator::WidthIterator(const Font* font, const TextRun& run, HashSet<const
m_expansionPerOpportunity = 0;
else {
bool isAfterExpansion = m_isAfterExpansion;
- unsigned expansionOpportunityCount = m_run.is8Bit() ? Font::expansionOpportunityCount(m_run.characters8(), m_run.length(), m_run.ltr() ? LTR : RTL, isAfterExpansion) : Font::expansionOpportunityCount(m_run.characters16(), m_run.length(), m_run.ltr() ? LTR : RTL, isAfterExpansion);
+ unsigned expansionOpportunityCount = m_run.is8Bit() ? Character::expansionOpportunityCount(m_run.characters8(), m_run.length(), m_run.direction(), isAfterExpansion) : Character::expansionOpportunityCount(m_run.characters16(), m_run.length(), m_run.direction(), isAfterExpansion);
if (isAfterExpansion && !m_run.allowsTrailingExpansion())
expansionOpportunityCount--;
@@ -96,7 +98,7 @@ public:
typedef Vector<pair<int, OriginalAdvancesForCharacterTreatedAsSpace>, 64> CharactersTreatedAsSpace;
-static inline float applyFontTransforms(GlyphBuffer* glyphBuffer, bool ltr, unsigned& lastGlyphCount, const SimpleFontData* fontData, TypesettingFeatures typesettingFeatures, CharactersTreatedAsSpace& charactersTreatedAsSpace)
+static inline float applyFontTransforms(GlyphBuffer* glyphBuffer, unsigned& lastGlyphCount, TypesettingFeatures typesettingFeatures, CharactersTreatedAsSpace& charactersTreatedAsSpace)
{
ASSERT(typesettingFeatures & (Kerning | Ligatures));
@@ -107,19 +109,11 @@ static inline float applyFontTransforms(GlyphBuffer* glyphBuffer, bool ltr, unsi
if (glyphBuffer->size() <= lastGlyphCount + 1)
return 0;
- GlyphBufferAdvance* advances = glyphBuffer->advances(0);
+ FloatSize* advances = glyphBuffer->advances(0);
float widthDifference = 0;
for (unsigned i = lastGlyphCount; i < glyphBufferSize; ++i)
widthDifference -= advances[i].width();
- if (!ltr)
- glyphBuffer->reverse(lastGlyphCount, glyphBufferSize - lastGlyphCount);
-
- fontData->applyTransforms(glyphBuffer->glyphs(lastGlyphCount), advances + lastGlyphCount, glyphBufferSize - lastGlyphCount, typesettingFeatures);
-
- if (!ltr)
- glyphBuffer->reverse(lastGlyphCount, glyphBufferSize - lastGlyphCount);
-
for (size_t i = 0; i < charactersTreatedAsSpace.size(); ++i) {
int spaceOffset = charactersTreatedAsSpace[i].first;
const OriginalAdvancesForCharacterTreatedAsSpace& originalAdvances = charactersTreatedAsSpace[i].second;
@@ -140,7 +134,7 @@ template <typename TextIterator>
inline unsigned WidthIterator::advanceInternal(TextIterator& textIterator, GlyphBuffer* glyphBuffer)
{
bool rtl = m_run.rtl();
- bool hasExtraSpacing = (m_font->letterSpacing() || m_font->wordSpacing() || m_expansion) && !m_run.spacingDisabled();
+ bool hasExtraSpacing = (m_font->fontDescription().letterSpacing() || m_font->fontDescription().wordSpacing() || m_expansion) && !m_run.spacingDisabled();
float widthSinceLastRounding = m_runWidthSoFar;
m_runWidthSoFar = floorf(m_runWidthSoFar);
@@ -184,15 +178,16 @@ inline unsigned WidthIterator::advanceInternal(TextIterator& textIterator, Glyph
if (fontData != lastFontData && width) {
if (shouldApplyFontTransforms())
- m_runWidthSoFar += applyFontTransforms(glyphBuffer, m_run.ltr(), lastGlyphCount, lastFontData, m_typesettingFeatures, charactersTreatedAsSpace);
+ m_runWidthSoFar += applyFontTransforms(glyphBuffer, lastGlyphCount, m_typesettingFeatures, charactersTreatedAsSpace);
lastFontData = fontData;
if (m_fallbackFonts && fontData != primaryFont) {
// FIXME: This does a little extra work that could be avoided if
// glyphDataForCharacter() returned whether it chose to use a small caps font.
- if (!m_font->isSmallCaps() || character == toUpper(character))
+ if (m_font->fontDescription().variant() == FontVariantNormal || character == toUpper(character))
m_fallbackFonts->add(fontData);
else {
+ ASSERT(m_font->fontDescription().variant() == FontVariantSmallCaps);
const GlyphData& uppercaseGlyphData = m_font->glyphDataForCharacter(toUpper(character), rtl);
if (uppercaseGlyphData.fontData != primaryFont)
m_fallbackFonts->add(uppercaseGlyphData.fontData);
@@ -202,12 +197,12 @@ inline unsigned WidthIterator::advanceInternal(TextIterator& textIterator, Glyph
if (hasExtraSpacing) {
// Account for letter-spacing.
- if (width && m_font->letterSpacing())
- width += m_font->letterSpacing();
+ if (width && m_font->fontDescription().letterSpacing())
+ width += m_font->fontDescription().letterSpacing();
- static bool expandAroundIdeographs = Font::canExpandAroundIdeographsInComplexText();
- bool treatAsSpace = Font::treatAsSpace(character);
- if (treatAsSpace || (expandAroundIdeographs && Font::isCJKIdeographOrSymbol(character))) {
+ static bool expandAroundIdeographs = FontPlatformFeatures::canExpandAroundIdeographsInComplexText();
+ bool treatAsSpace = Character::treatAsSpace(character);
+ if (treatAsSpace || (expandAroundIdeographs && Character::isCJKIdeographOrSymbol(character))) {
// Distribute the run's total expansion evenly over all expansion opportunities in the run.
if (m_expansion) {
float previousExpansion = m_expansion;
@@ -238,15 +233,18 @@ inline unsigned WidthIterator::advanceInternal(TextIterator& textIterator, Glyph
// Account for word spacing.
// We apply additional space between "words" by adding width to the space character.
- if (treatAsSpace && (character != '\t' || !m_run.allowTabs()) && (textIterator.currentCharacter() || character == noBreakSpace) && m_font->wordSpacing())
- width += m_font->wordSpacing();
+ if (treatAsSpace && (character != '\t' || !m_run.allowTabs()) && (textIterator.currentCharacter() || character == noBreakSpace) && m_font->fontDescription().wordSpacing())
+ width += m_font->fontDescription().wordSpacing();
} else
m_isAfterExpansion = false;
}
- if (shouldApplyFontTransforms() && glyphBuffer && Font::treatAsSpace(character))
+ if (shouldApplyFontTransforms() && glyphBuffer && Character::treatAsSpace(character)) {
charactersTreatedAsSpace.append(make_pair(glyphBuffer->size(),
- OriginalAdvancesForCharacterTreatedAsSpace(character == ' ', glyphBuffer->size() ? glyphBuffer->advanceAt(glyphBuffer->size() - 1) : 0, width)));
+ OriginalAdvancesForCharacterTreatedAsSpace(character == ' ',
+ glyphBuffer->size() ? glyphBuffer->advanceAt(glyphBuffer->size() - 1).width() : 0,
+ width)));
+ }
if (m_accountForGlyphBounds) {
bounds = fontData->boundsForGlyph(glyph);
@@ -254,7 +252,7 @@ inline unsigned WidthIterator::advanceInternal(TextIterator& textIterator, Glyph
m_firstGlyphOverflow = max<float>(0, -bounds.x());
}
- if (m_forTextEmphasis && !Font::canReceiveTextEmphasis(character))
+ if (m_forTextEmphasis && !Character::canReceiveTextEmphasis(character))
glyph = 0;
// Advance past the character we just dealt with.
@@ -264,7 +262,7 @@ inline unsigned WidthIterator::advanceInternal(TextIterator& textIterator, Glyph
// Force characters that are used to determine word boundaries for the rounding hack
// to be integer width, so following words will start on an integer boundary.
- if (m_run.applyWordRounding() && Font::isRoundingHackCharacter(character)) {
+ if (m_run.applyWordRounding() && Character::isRoundingHackCharacter(character)) {
width = ceilf(width);
// Since widthSinceLastRounding can lose precision if we include measurements for
@@ -277,7 +275,7 @@ inline unsigned WidthIterator::advanceInternal(TextIterator& textIterator, Glyph
} else {
// Check to see if the next character is a "rounding hack character", if so, adjust
// width so that the total run width will be on an integer boundary.
- if ((m_run.applyWordRounding() && textIterator.currentCharacter() < m_run.length() && Font::isRoundingHackCharacter(*(textIterator.characters())))
+ if ((m_run.applyWordRounding() && textIterator.currentCharacter() < m_run.length() && Character::isRoundingHackCharacter(*(textIterator.characters())))
|| (m_run.applyRunRounding() && textIterator.currentCharacter() >= m_run.length())) {
float totalWidth = widthSinceLastRounding + width;
widthSinceLastRounding = ceilf(totalWidth);
@@ -301,7 +299,7 @@ inline unsigned WidthIterator::advanceInternal(TextIterator& textIterator, Glyph
}
if (shouldApplyFontTransforms())
- m_runWidthSoFar += applyFontTransforms(glyphBuffer, m_run.ltr(), lastGlyphCount, lastFontData, m_typesettingFeatures, charactersTreatedAsSpace);
+ m_runWidthSoFar += applyFontTransforms(glyphBuffer, lastGlyphCount, m_typesettingFeatures, charactersTreatedAsSpace);
unsigned consumedCharacters = textIterator.currentCharacter() - m_currentCharacter;
m_currentCharacter = textIterator.currentCharacter();
@@ -335,7 +333,7 @@ bool WidthIterator::advanceOneCharacter(float& width, GlyphBuffer& glyphBuffer)
advance(m_currentCharacter + 1, &glyphBuffer);
float w = 0;
for (unsigned i = oldSize; i < glyphBuffer.size(); ++i)
- w += glyphBuffer.advanceAt(i);
+ w += glyphBuffer.advanceAt(i).width();
width = w;
return glyphBuffer.size() > oldSize;
}