| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) |
| 3 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ight reserved. | 3 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ight reserved. |
| 4 * Copyright (C) 2010 Google Inc. All rights reserved. | 4 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 setMarginStartForChild(*layoutRubyRun, -startOverhang); | 363 setMarginStartForChild(*layoutRubyRun, -startOverhang); |
| 364 setMarginEndForChild(*layoutRubyRun, -endOverhang); | 364 setMarginEndForChild(*layoutRubyRun, -endOverhang); |
| 365 } | 365 } |
| 366 | 366 |
| 367 static inline void setLogicalWidthForTextRun(RootInlineBox* lineBox, BidiRun* ru
n, LayoutText* layoutText, LayoutUnit xPos, const LineInfo& lineInfo, | 367 static inline void setLogicalWidthForTextRun(RootInlineBox* lineBox, BidiRun* ru
n, LayoutText* layoutText, LayoutUnit xPos, const LineInfo& lineInfo, |
| 368 GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& ver
ticalPositionCache, WordMeasurements& wordMeasurements) | 368 GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& ver
ticalPositionCache, WordMeasurements& wordMeasurements) |
| 369 { | 369 { |
| 370 HashSet<const SimpleFontData*> fallbackFonts; | 370 HashSet<const SimpleFontData*> fallbackFonts; |
| 371 GlyphOverflow glyphOverflow; | 371 GlyphOverflow glyphOverflow; |
| 372 | 372 |
| 373 const Font& font = layoutText->style(lineInfo.isFirstLine())->font(); | 373 // Always compute glyph overflow bounds if the block's line-box-contain valu
e is "glyphs". |
| 374 // Always compute glyph overflow if the block's line-box-contain value is "g
lyphs". | 374 if (lineBox->fitsToGlyphs()) |
| 375 if (lineBox->fitsToGlyphs()) { | 375 glyphOverflow.computeBounds = true; |
| 376 // If we don't stick out of the root line's font box, then don't bother
computing our glyph overflow. This optimization | |
| 377 // will keep us from computing glyph bounds in nearly all cases. | |
| 378 bool includeRootLine = lineBox->includesRootLineBoxFontOrLeading(); | |
| 379 int baselineShift = lineBox->verticalPositionForBox(run->m_box, vertical
PositionCache); | |
| 380 int rootDescent = includeRootLine ? font.fontMetrics().descent() : 0; | |
| 381 int rootAscent = includeRootLine ? font.fontMetrics().ascent() : 0; | |
| 382 int boxAscent = font.fontMetrics().ascent() - baselineShift; | |
| 383 int boxDescent = font.fontMetrics().descent() + baselineShift; | |
| 384 if (boxAscent > rootDescent || boxDescent > rootAscent) | |
| 385 glyphOverflow.computeBounds = true; | |
| 386 } | |
| 387 | 376 |
| 388 LayoutUnit hyphenWidth = 0; | 377 LayoutUnit hyphenWidth = 0; |
| 389 if (toInlineTextBox(run->m_box)->hasHyphen()) { | 378 if (toInlineTextBox(run->m_box)->hasHyphen()) { |
| 390 const Font& font = layoutText->style(lineInfo.isFirstLine())->font(); | 379 const Font& font = layoutText->style(lineInfo.isFirstLine())->font(); |
| 391 hyphenWidth = measureHyphenWidth(layoutText, font, run->direction()); | 380 hyphenWidth = measureHyphenWidth(layoutText, font, run->direction()); |
| 392 } | 381 } |
| 393 float measuredWidth = 0; | |
| 394 | 382 |
| 395 bool kerningIsEnabled = font.fontDescription().typesettingFeatures() & Kerni
ng; | 383 float measuredWidth = layoutText->width(run->m_start, run->m_stop - run->m_s
tart, xPos, run->direction(), lineInfo.isFirstLine(), &fallbackFonts, &glyphOver
flow); |
| 396 | |
| 397 #if OS(MACOSX) | |
| 398 // FIXME: Having any font feature settings enabled can lead to selection gap
s on | |
| 399 // Chromium-mac. https://bugs.webkit.org/show_bug.cgi?id=113418 | |
| 400 bool canUseSimpleFontCodePath = layoutText->canUseSimpleFontCodePath() && !f
ont.fontDescription().featureSettings(); | |
| 401 #else | |
| 402 bool canUseSimpleFontCodePath = layoutText->canUseSimpleFontCodePath(); | |
| 403 #endif | |
| 404 | |
| 405 // For complex text we need to compute the glyph bounds as accents can exten
d outside the frameRect. | |
| 406 if (!canUseSimpleFontCodePath) | |
| 407 glyphOverflow.computeBounds = true; | |
| 408 | |
| 409 // Since we don't cache glyph overflows, we need to re-measure the run if | |
| 410 // the style is linebox-contain: glyph. | |
| 411 | |
| 412 if (!lineBox->fitsToGlyphs() && canUseSimpleFontCodePath) { | |
| 413 int lastEndOffset = run->m_start; | |
| 414 for (size_t i = 0, size = wordMeasurements.size(); i < size && lastEndOf
fset < run->m_stop; ++i) { | |
| 415 const WordMeasurement& wordMeasurement = wordMeasurements[i]; | |
| 416 if (wordMeasurement.width <=0 || wordMeasurement.startOffset == word
Measurement.endOffset) | |
| 417 continue; | |
| 418 if (wordMeasurement.layoutText != layoutText || wordMeasurement.star
tOffset != lastEndOffset || wordMeasurement.endOffset > run->m_stop) | |
| 419 continue; | |
| 420 | |
| 421 lastEndOffset = wordMeasurement.endOffset; | |
| 422 if (kerningIsEnabled && lastEndOffset == run->m_stop) { | |
| 423 int wordLength = lastEndOffset - wordMeasurement.startOffset; | |
| 424 measuredWidth += layoutText->width(wordMeasurement.startOffset,
wordLength, xPos, run->direction(), lineInfo.isFirstLine()); | |
| 425 if (i > 0 && wordLength == 1 && layoutText->characterAt(wordMeas
urement.startOffset) == ' ') | |
| 426 measuredWidth += layoutText->style()->wordSpacing(); | |
| 427 } else { | |
| 428 measuredWidth += wordMeasurement.width; | |
| 429 } | |
| 430 if (!wordMeasurement.fallbackFonts.isEmpty()) { | |
| 431 HashSet<const SimpleFontData*>::const_iterator end = wordMeasure
ment.fallbackFonts.end(); | |
| 432 for (HashSet<const SimpleFontData*>::const_iterator it = wordMea
surement.fallbackFonts.begin(); it != end; ++it) | |
| 433 fallbackFonts.add(*it); | |
| 434 } | |
| 435 } | |
| 436 if (measuredWidth && lastEndOffset != run->m_stop) { | |
| 437 // If we don't have enough cached data, we'll measure the run again. | |
| 438 measuredWidth = 0; | |
| 439 fallbackFonts.clear(); | |
| 440 } | |
| 441 } | |
| 442 | |
| 443 if (!measuredWidth) | |
| 444 measuredWidth = layoutText->width(run->m_start, run->m_stop - run->m_sta
rt, xPos, run->direction(), lineInfo.isFirstLine(), &fallbackFonts, &glyphOverfl
ow); | |
| 445 | 384 |
| 446 run->m_box->setLogicalWidth(measuredWidth + hyphenWidth); | 385 run->m_box->setLogicalWidth(measuredWidth + hyphenWidth); |
| 447 if (!fallbackFonts.isEmpty()) { | 386 if (!fallbackFonts.isEmpty()) { |
| 448 ASSERT(run->m_box->isText()); | 387 ASSERT(run->m_box->isText()); |
| 449 GlyphOverflowAndFallbackFontsMap::ValueType* it = textBoxDataMap.add(toI
nlineTextBox(run->m_box), std::make_pair(Vector<const SimpleFontData*>(), GlyphO
verflow())).storedValue; | 388 GlyphOverflowAndFallbackFontsMap::ValueType* it = textBoxDataMap.add(toI
nlineTextBox(run->m_box), std::make_pair(Vector<const SimpleFontData*>(), GlyphO
verflow())).storedValue; |
| 450 ASSERT(it->value.first.isEmpty()); | 389 ASSERT(it->value.first.isEmpty()); |
| 451 copyToVector(fallbackFonts, it->value.first); | 390 copyToVector(fallbackFonts, it->value.first); |
| 452 run->m_box->parent()->clearDescendantsHaveSameLineHeightAndBaseline(); | 391 run->m_box->parent()->clearDescendantsHaveSameLineHeightAndBaseline(); |
| 453 } | 392 } |
| 454 if (!glyphOverflow.isZero()) { | 393 if (!glyphOverflow.isZero()) { |
| (...skipping 1573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2028 LayoutUnit logicalLeft = logicalLeftOffsetForLine(logicalHeight(), false); | 1967 LayoutUnit logicalLeft = logicalLeftOffsetForLine(logicalHeight(), false); |
| 2029 LayoutUnit availableLogicalWidth = logicalRightOffsetForLine(logicalHeight()
, false) - logicalLeft; | 1968 LayoutUnit availableLogicalWidth = logicalRightOffsetForLine(logicalHeight()
, false) - logicalLeft; |
| 2030 updateLogicalWidthForAlignment(textAlign, 0, 0, logicalLeft, totalLogicalWid
th, availableLogicalWidth, 0); | 1969 updateLogicalWidthForAlignment(textAlign, 0, 0, logicalLeft, totalLogicalWid
th, availableLogicalWidth, 0); |
| 2031 | 1970 |
| 2032 if (!style()->isLeftToRightDirection()) | 1971 if (!style()->isLeftToRightDirection()) |
| 2033 return logicalWidth() - logicalLeft; | 1972 return logicalWidth() - logicalLeft; |
| 2034 return logicalLeft; | 1973 return logicalLeft; |
| 2035 } | 1974 } |
| 2036 | 1975 |
| 2037 } | 1976 } |
| OLD | NEW |