using namespace std;
-namespace WebCore {
-
-static inline CGFloat roundCGFloat(CGFloat f)
-{
- if (sizeof(CGFloat) == sizeof(float))
- return roundf(static_cast<float>(f));
- return static_cast<CGFloat>(round(f));
-}
-
-static inline CGFloat ceilCGFloat(CGFloat f)
-{
- if (sizeof(CGFloat) == sizeof(float))
- return ceilf(static_cast<float>(f));
- return static_cast<CGFloat>(ceil(f));
-}
+namespace blink {
ComplexTextController::ComplexTextController(const Font* font, const TextRun& run, bool mayUseNaturalWritingDirection, HashSet<const SimpleFontData*>* fallbackFonts, bool forTextEmphasis)
: m_font(*font)
, m_currentRun(0)
, m_glyphInCurrentRun(0)
, m_characterInCurrentGlyph(0)
- , m_finalRoundingWidth(0)
, m_expansion(run.expansion())
, m_leadingExpansion(0)
, m_afterExpansion(!run.allowsLeadingExpansion())
, m_maxGlyphBoundingBoxX(numeric_limits<float>::min())
, m_minGlyphBoundingBoxY(numeric_limits<float>::max())
, m_maxGlyphBoundingBoxY(numeric_limits<float>::min())
- , m_lastRoundingGlyph(0)
{
if (!m_expansion)
m_expansionPerOpportunity = 0;
currentRunIndex = incrementCurrentRun(leftmostGlyph);
m_glyphInCurrentRun = 0;
}
- if (!m_run.ltr() && m_numGlyphsSoFar == m_adjustedAdvances.size())
- m_runWidthSoFar += m_finalRoundingWidth;
}
void ComplexTextController::adjustGlyphsAndAdvances()
bool lastRun = r + 1 == runCount;
bool roundsAdvances = fontData->platformData().roundsGlyphAdvances();
float spaceWidth = fontData->spaceWidth() - fontData->syntheticBoldOffset();
- CGFloat roundedSpaceWidth = roundCGFloat(spaceWidth);
const UChar* cp = complexTextRun.characters();
CGPoint glyphOrigin = CGPointZero;
CFIndex lastCharacterIndex = m_run.ltr() ? numeric_limits<CFIndex>::min() : numeric_limits<CFIndex>::max();
advance.width += fontData->syntheticBoldOffset();
-
- // We special case spaces in two ways when applying word rounding.
- // First, we round spaces to an adjusted width in all fonts.
- // Second, in fixed-pitch fonts we ensure that all glyphs that
- // match the width of the space glyph have the same width as the space glyph.
- if (m_run.applyWordRounding() && roundedAdvanceWidth == roundedSpaceWidth && (fontData->pitch() == FixedPitch || glyph == fontData->spaceGlyph()))
- advance.width = fontData->adjustedSpaceWidth();
-
if (hasExtraSpacing) {
// If we're a glyph with an advance, go ahead and add in letter-spacing.
// That way we weed out zero width lurkers. This behavior matches the fast text code path.
if (treatAsSpace || Character::isCJKIdeographOrSymbol(ch)) {
// Distribute the run's total expansion evenly over all expansion opportunities in the run.
if (m_expansion) {
- float previousExpansion = m_expansion;
if (!treatAsSpace && !m_afterExpansion) {
// Take the expansion opportunity before this ideograph.
m_expansion -= m_expansionPerOpportunity;
- float expansionAtThisOpportunity = !m_run.applyWordRounding() ? m_expansionPerOpportunity : roundf(previousExpansion) - roundf(m_expansion);
+ float expansionAtThisOpportunity = m_expansionPerOpportunity;
m_totalWidth += expansionAtThisOpportunity;
if (m_adjustedAdvances.isEmpty())
m_leadingExpansion = expansionAtThisOpportunity;
else
m_adjustedAdvances.last().width += expansionAtThisOpportunity;
- previousExpansion = m_expansion;
}
if (!lastGlyph || m_run.allowsTrailingExpansion()) {
m_expansion -= m_expansionPerOpportunity;
- advance.width += !m_run.applyWordRounding() ? m_expansionPerOpportunity : roundf(previousExpansion) - roundf(m_expansion);
+ advance.width += m_expansionPerOpportunity;
m_afterExpansion = true;
}
} else
m_afterExpansion = false;
}
- // Apply rounding hacks if needed.
- // We adjust the width of the last character of a "word" to ensure an integer width.
- // Force characters that are used to determine word boundaries for the rounding hack
- // to be integer width, so the following words will start on an integer boundary.
- if (m_run.applyWordRounding() && Character::isRoundingHackCharacter(ch))
- advance.width = ceilCGFloat(advance.width);
-
- // Check to see if the next character is a "rounding hack character", if so, adjust the
- // width so that the total run width will be on an integer boundary.
- if ((m_run.applyWordRounding() && !lastGlyph && Character::isRoundingHackCharacter(nextCh)) || (m_run.applyRunRounding() && lastGlyph)) {
- CGFloat totalWidth = widthSinceLastCommit + advance.width;
- widthSinceLastCommit = ceilCGFloat(totalWidth);
- CGFloat extraWidth = widthSinceLastCommit - totalWidth;
- if (m_run.ltr())
- advance.width += extraWidth;
- else {
- if (m_lastRoundingGlyph)
- m_adjustedAdvances[m_lastRoundingGlyph - 1].width += extraWidth;
- else
- m_finalRoundingWidth = extraWidth;
- m_lastRoundingGlyph = m_adjustedAdvances.size() + 1;
- }
- m_totalWidth += widthSinceLastCommit;
- widthSinceLastCommit = 0;
- } else
- widthSinceLastCommit += advance.width;
+ widthSinceLastCommit += advance.width;
// FIXME: Combining marks should receive a text emphasis mark if they are combine with a space.
if (m_forTextEmphasis && (!Character::canReceiveTextEmphasis(ch) || (U_GET_GC_MASK(ch) & U_GC_M_MASK)))
m_totalWidth += widthSinceLastCommit;
}
-} // namespace WebCore
+} // namespace blink