| 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 * Copyright (C) 2013 Adobe Systems Incorporated. | 5 * Copyright (C) 2013 Adobe Systems Incorporated. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 FloatRect rect = font.selectionRectForText(run, FloatPoint(), 0, 0, len); | 623 FloatRect rect = font.selectionRectForText(run, FloatPoint(), 0, 0, len); |
| 624 DCHECK(m_width.fitsOnLine(rect.width() - 1)); // avoid failure when rect is
rounded up. | 624 DCHECK(m_width.fitsOnLine(rect.width() - 1)); // avoid failure when rect is
rounded up. |
| 625 return rewindToMidWordBreak(wordMeasurement, end, rect.width()); | 625 return rewindToMidWordBreak(wordMeasurement, end, rect.width()); |
| 626 } | 626 } |
| 627 | 627 |
| 628 ALWAYS_INLINE bool BreakingContext::hyphenate(LineLayoutText text, | 628 ALWAYS_INLINE bool BreakingContext::hyphenate(LineLayoutText text, |
| 629 const ComputedStyle& style, const Font& font, | 629 const ComputedStyle& style, const Font& font, |
| 630 const Hyphenation& hyphenation, float lastSpaceWordSpacing, | 630 const Hyphenation& hyphenation, float lastSpaceWordSpacing, |
| 631 WordMeasurement& wordMeasurement) | 631 WordMeasurement& wordMeasurement) |
| 632 { | 632 { |
| 633 const unsigned minimumPrefixLength = 2; | |
| 634 const unsigned minimumSuffixLength = 2; | |
| 635 unsigned start = wordMeasurement.startOffset; | 633 unsigned start = wordMeasurement.startOffset; |
| 636 unsigned len = wordMeasurement.endOffset - start; | 634 unsigned len = wordMeasurement.endOffset - start; |
| 637 if (len <= minimumSuffixLength) | 635 if (len <= Hyphenation::minimumSuffixLength) |
| 638 return false; | 636 return false; |
| 639 | 637 |
| 640 float hyphenWidth = text.hyphenWidth(font, textDirectionFromUnicode(m_resolv
er.position().direction())); | 638 float hyphenWidth = text.hyphenWidth(font, textDirectionFromUnicode(m_resolv
er.position().direction())); |
| 641 float maxPrefixWidth = m_width.availableWidth() | 639 float maxPrefixWidth = m_width.availableWidth() |
| 642 - m_width.currentWidth() - hyphenWidth - lastSpaceWordSpacing; | 640 - m_width.currentWidth() - hyphenWidth - lastSpaceWordSpacing; |
| 643 | 641 |
| 644 // If the maximum width available for the prefix before the hyphen is small,
then it is very unlikely | 642 if (maxPrefixWidth <= Hyphenation::minimumPrefixWidth(font)) |
| 645 // that an hyphenation opportunity exists, so do not bother to look for it. | |
| 646 // These are heuristic numbers for performance added in http://wkb.ug/45606
. | |
| 647 const int minPrefixWidthNumerator = 5; | |
| 648 const int minPrefixWidthDenominator = 4; | |
| 649 if (maxPrefixWidth <= font.getFontDescription().computedSize() * minPrefixWi
dthNumerator / minPrefixWidthDenominator) | |
| 650 return false; | 643 return false; |
| 651 | 644 |
| 652 TextRun run = constructTextRun(font, text, start, len, style); | 645 TextRun run = constructTextRun(font, text, start, len, style); |
| 653 run.setTabSize(!m_collapseWhiteSpace, style.getTabSize()); | 646 run.setTabSize(!m_collapseWhiteSpace, style.getTabSize()); |
| 654 run.setXPos(m_width.currentWidth()); | 647 run.setXPos(m_width.currentWidth()); |
| 655 unsigned maxPrefixLength = font.offsetForPosition(run, maxPrefixWidth, false
); | 648 unsigned maxPrefixLength = font.offsetForPosition(run, maxPrefixWidth, false
); |
| 656 if (maxPrefixLength < minimumPrefixLength) | 649 if (maxPrefixLength < Hyphenation::minimumPrefixLength) |
| 657 return false; | 650 return false; |
| 658 | 651 |
| 659 unsigned prefixLength = hyphenation.lastHyphenLocation( | 652 unsigned prefixLength = hyphenation.lastHyphenLocation( |
| 660 text.text().createView(start, len), | 653 text.text().createView(start, len), |
| 661 std::min(maxPrefixLength, len - minimumSuffixLength) + 1); | 654 std::min(maxPrefixLength, len - Hyphenation::minimumSuffixLength) + 1); |
| 662 if (!prefixLength || prefixLength < minimumPrefixLength) | 655 if (!prefixLength || prefixLength < Hyphenation::minimumPrefixLength) |
| 663 return false; | 656 return false; |
| 664 | 657 |
| 665 CharacterRange range = font.getCharacterRange(run, 0, prefixLength); | 658 // TODO(kojii): getCharacterRange() measures as if the word were not broken |
| 666 return rewindToMidWordBreak(wordMeasurement, start + prefixLength, range.wid
th()); | 659 // as defined in the spec, and is faster than measuring each fragment, but |
| 660 // ignores the kerning between the last letter and the hyphen. |
| 661 return rewindToMidWordBreak(wordMeasurement, start + prefixLength, |
| 662 font.getCharacterRange(run, 0, prefixLength).width() + hyphenWidth); |
| 667 } | 663 } |
| 668 | 664 |
| 669 inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
& hyphenated) | 665 inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
& hyphenated) |
| 670 { | 666 { |
| 671 if (!m_current.offset()) | 667 if (!m_current.offset()) |
| 672 m_appliedStartWidth = false; | 668 m_appliedStartWidth = false; |
| 673 | 669 |
| 674 LineLayoutText layoutText(m_current.getLineLayoutItem()); | 670 LineLayoutText layoutText(m_current.getLineLayoutItem()); |
| 675 | 671 |
| 676 // If we have left a no-wrap inline and entered an autowrap inline while ign
oring spaces | 672 // If we have left a no-wrap inline and entered an autowrap inline while ign
oring spaces |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1156 | 1152 |
| 1157 if (style.getTextIndentType() == TextIndentHanging) | 1153 if (style.getTextIndentType() == TextIndentHanging) |
| 1158 indentText = indentText == IndentText ? DoNotIndentText : IndentText; | 1154 indentText = indentText == IndentText ? DoNotIndentText : IndentText; |
| 1159 | 1155 |
| 1160 return indentText; | 1156 return indentText; |
| 1161 } | 1157 } |
| 1162 | 1158 |
| 1163 } // namespace blink | 1159 } // namespace blink |
| 1164 | 1160 |
| 1165 #endif // BreakingContextInlineHeaders_h | 1161 #endif // BreakingContextInlineHeaders_h |
| OLD | NEW |