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

Side by Side Diff: Source/core/layout/line/BreakingContextInlineHeaders.h

Issue 1179723002: Store glyph bounds in WordMeasurement to avoid slow path width calc (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 5 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/layout/LayoutTextCombine.cpp ('k') | Source/core/layout/line/GlyphOverflow.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 return font.width(constructTextRun(layoutText, font, 502 return font.width(constructTextRun(layoutText, font,
503 style.hyphenString().string(), style, style.direction())); 503 style.hyphenString().string(), style, style.direction()));
504 } 504 }
505 505
506 ALWAYS_INLINE TextDirection textDirectionFromUnicode(WTF::Unicode::Direction dir ection) 506 ALWAYS_INLINE TextDirection textDirectionFromUnicode(WTF::Unicode::Direction dir ection)
507 { 507 {
508 return direction == WTF::Unicode::RightToLeft 508 return direction == WTF::Unicode::RightToLeft
509 || direction == WTF::Unicode::RightToLeftArabic ? RTL : LTR; 509 || direction == WTF::Unicode::RightToLeftArabic ? RTL : LTR;
510 } 510 }
511 511
512 ALWAYS_INLINE float textWidth(LayoutText* text, unsigned from, unsigned len, con st Font& font, float xPos, bool collapseWhiteSpace, HashSet<const SimpleFontData *>* fallbackFonts = nullptr) 512 ALWAYS_INLINE float textWidth(LayoutText* text, unsigned from, unsigned len, con st Font& font, float xPos, bool collapseWhiteSpace, HashSet<const SimpleFontData *>* fallbackFonts = nullptr, FloatRect* glyphBounds = nullptr)
513 { 513 {
514 if ((!from && len == text->textLength()) || text->style()->hasTextCombine()) { 514 if ((!from && len == text->textLength()) || text->style()->hasTextCombine())
515 GlyphOverflow glyphOverflow; 515 return text->width(from, len, font, xPos, text->style()->direction(), fa llbackFonts, glyphBounds);
516 return text->width(from, len, font, xPos, text->style()->direction(), fa llbackFonts,
517 // LayoutText caches fallbackFonts and glyphOverflow together, and r equires them to be both null or both non-null.
518 fallbackFonts ? &glyphOverflow : nullptr);
519 }
520 516
521 TextRun run = constructTextRun(text, font, text, from, len, text->styleRef() ); 517 TextRun run = constructTextRun(text, font, text, from, len, text->styleRef() );
522 run.setCodePath(text->canUseSimpleFontCodePath() ? TextRun::ForceSimple : Te xtRun::ForceComplex); 518 run.setCodePath(text->canUseSimpleFontCodePath() ? TextRun::ForceSimple : Te xtRun::ForceComplex);
523 run.setTabSize(!collapseWhiteSpace, text->style()->tabSize()); 519 run.setTabSize(!collapseWhiteSpace, text->style()->tabSize());
524 run.setXPos(xPos); 520 run.setXPos(xPos);
525 return font.width(run, fallbackFonts, nullptr); 521 return font.width(run, fallbackFonts, glyphBounds);
526 } 522 }
527 523
528 inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool & hyphenated) 524 inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool & hyphenated)
529 { 525 {
530 if (!m_current.offset()) 526 if (!m_current.offset())
531 m_appliedStartWidth = false; 527 m_appliedStartWidth = false;
532 528
533 LayoutText* layoutText = toLayoutText(m_current.object()); 529 LayoutText* layoutText = toLayoutText(m_current.object());
534 530
535 bool isSVGText = layoutText->isSVGInlineText(); 531 bool isSVGText = layoutText->isSVGInlineText();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 632
637 wordMeasurements.grow(wordMeasurements.size() + 1); 633 wordMeasurements.grow(wordMeasurements.size() + 1);
638 WordMeasurement& wordMeasurement = wordMeasurements.last(); 634 WordMeasurement& wordMeasurement = wordMeasurements.last();
639 635
640 wordMeasurement.layoutText = layoutText; 636 wordMeasurement.layoutText = layoutText;
641 wordMeasurement.endOffset = m_current.offset(); 637 wordMeasurement.endOffset = m_current.offset();
642 wordMeasurement.startOffset = lastSpace; 638 wordMeasurement.startOffset = lastSpace;
643 639
644 float additionalTempWidth; 640 float additionalTempWidth;
645 if (wordTrailingSpaceWidth && c == spaceCharacter) 641 if (wordTrailingSpaceWidth && c == spaceCharacter)
646 additionalTempWidth = textWidth(layoutText, lastSpace, m_current .offset() + 1 - lastSpace, font, m_width.currentWidth(), m_collapseWhiteSpace, & wordMeasurement.fallbackFonts) - wordTrailingSpaceWidth; 642 additionalTempWidth = textWidth(layoutText, lastSpace, m_current .offset() + 1 - lastSpace, font, m_width.currentWidth(), m_collapseWhiteSpace, & wordMeasurement.fallbackFonts, &wordMeasurement.glyphBounds) - wordTrailingSpace Width;
647 else 643 else
648 additionalTempWidth = textWidth(layoutText, lastSpace, m_current .offset() - lastSpace, font, m_width.currentWidth(), m_collapseWhiteSpace, &word Measurement.fallbackFonts); 644 additionalTempWidth = textWidth(layoutText, lastSpace, m_current .offset() - lastSpace, font, m_width.currentWidth(), m_collapseWhiteSpace, &word Measurement.fallbackFonts, &wordMeasurement.glyphBounds);
649 645
650 wordMeasurement.width = additionalTempWidth + wordSpacingForWordMeas urement; 646 wordMeasurement.width = additionalTempWidth + wordSpacingForWordMeas urement;
651 additionalTempWidth += lastSpaceWordSpacing; 647 additionalTempWidth += lastSpaceWordSpacing;
652 m_width.addUncommittedWidth(additionalTempWidth); 648 m_width.addUncommittedWidth(additionalTempWidth);
653 649
654 if (m_collapseWhiteSpace && previousCharacterIsSpace && m_currentCha racterIsSpace && additionalTempWidth) 650 if (m_collapseWhiteSpace && previousCharacterIsSpace && m_currentCha racterIsSpace && additionalTempWidth)
655 m_width.setTrailingWhitespaceWidth(additionalTempWidth); 651 m_width.setTrailingWhitespaceWidth(additionalTempWidth);
656 652
657 if (!m_appliedStartWidth) { 653 if (!m_appliedStartWidth) {
658 m_width.addUncommittedWidth(inlineLogicalWidth(m_current.object( ), true, false).toFloat()); 654 m_width.addUncommittedWidth(inlineLogicalWidth(m_current.object( ), true, false).toFloat());
659 m_appliedStartWidth = true; 655 m_appliedStartWidth = true;
660 } 656 }
661 657
662 applyWordSpacing = wordSpacing && m_currentCharacterIsSpace; 658 applyWordSpacing = wordSpacing && m_currentCharacterIsSpace;
663 659
664 if (!m_width.committedWidth() && m_autoWrap && !m_width.fitsOnLine() ) 660 if (!m_width.committedWidth() && m_autoWrap && !m_width.fitsOnLine() )
665 m_width.fitBelowFloats(m_lineInfo.isFirstLine()); 661 m_width.fitBelowFloats(m_lineInfo.isFirstLine());
666 662
667 if (m_autoWrap || breakWords) { 663 if (m_autoWrap || breakWords) {
668 // If we break only after white-space, consider the current char acter 664 // If we break only after white-space, consider the current char acter
669 // as candidate width for this line. 665 // as candidate width for this line.
670 bool lineWasTooWide = false; 666 bool lineWasTooWide = false;
671 if (m_width.fitsOnLine() && m_currentCharacterIsSpace && m_curre ntStyle->breakOnlyAfterWhiteSpace() && !midWordBreak) { 667 if (m_width.fitsOnLine() && m_currentCharacterIsSpace && m_curre ntStyle->breakOnlyAfterWhiteSpace() && !midWordBreak) {
672 float charWidth = textWidth(layoutText, m_current.offset(), 1, font, m_width.currentWidth(), m_collapseWhiteSpace, &wordMeasurement.fallback Fonts) + (applyWordSpacing ? wordSpacing : 0); 668 float charWidth = textWidth(layoutText, m_current.offset(), 1, font, m_width.currentWidth(), m_collapseWhiteSpace, &wordMeasurement.fallback Fonts, &wordMeasurement.glyphBounds) + (applyWordSpacing ? wordSpacing : 0);
673 // Check if line is too big even without the extra space 669 // Check if line is too big even without the extra space
674 // at the end of the line. If it is not, do nothing. 670 // at the end of the line. If it is not, do nothing.
675 // If the line needs the extra whitespace to be too long, 671 // If the line needs the extra whitespace to be too long,
676 // then move the line break to the space and skip all 672 // then move the line break to the space and skip all
677 // additional whitespace. 673 // additional whitespace.
678 if (!m_width.fitsOnLine(charWidth)) { 674 if (!m_width.fitsOnLine(charWidth)) {
679 lineWasTooWide = true; 675 lineWasTooWide = true;
680 m_lineBreak.moveTo(m_current.object(), m_current.offset( ), m_current.nextBreakablePosition()); 676 m_lineBreak.moveTo(m_current.object(), m_current.offset( ), m_current.nextBreakablePosition());
681 skipTrailingWhitespace(m_lineBreak, m_lineInfo); 677 skipTrailingWhitespace(m_lineBreak, m_lineInfo);
682 } 678 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 nextCharacter(c, lastCharacter, secondToLastCharacter); 794 nextCharacter(c, lastCharacter, secondToLastCharacter);
799 } 795 }
800 796
801 m_layoutTextInfo.m_lineBreakIterator.setPriorContext(lastCharacter, secondTo LastCharacter); 797 m_layoutTextInfo.m_lineBreakIterator.setPriorContext(lastCharacter, secondTo LastCharacter);
802 798
803 wordMeasurements.grow(wordMeasurements.size() + 1); 799 wordMeasurements.grow(wordMeasurements.size() + 1);
804 WordMeasurement& wordMeasurement = wordMeasurements.last(); 800 WordMeasurement& wordMeasurement = wordMeasurements.last();
805 wordMeasurement.layoutText = layoutText; 801 wordMeasurement.layoutText = layoutText;
806 802
807 // IMPORTANT: current.m_pos is > length here! 803 // IMPORTANT: current.m_pos is > length here!
808 float additionalTempWidth = m_ignoringSpaces ? 0 : textWidth(layoutText, las tSpace, m_current.offset() - lastSpace, font, m_width.currentWidth(), m_collapse WhiteSpace, &wordMeasurement.fallbackFonts); 804 float additionalTempWidth = m_ignoringSpaces ? 0 : textWidth(layoutText, las tSpace, m_current.offset() - lastSpace, font, m_width.currentWidth(), m_collapse WhiteSpace, &wordMeasurement.fallbackFonts, &wordMeasurement.glyphBounds);
809 wordMeasurement.startOffset = lastSpace; 805 wordMeasurement.startOffset = lastSpace;
810 wordMeasurement.endOffset = m_current.offset(); 806 wordMeasurement.endOffset = m_current.offset();
811 wordMeasurement.width = m_ignoringSpaces ? 0 : additionalTempWidth + wordSpa cingForWordMeasurement; 807 wordMeasurement.width = m_ignoringSpaces ? 0 : additionalTempWidth + wordSpa cingForWordMeasurement;
812 additionalTempWidth += lastSpaceWordSpacing; 808 additionalTempWidth += lastSpaceWordSpacing;
813 809
814 LayoutUnit inlineLogicalTempWidth = inlineLogicalWidth(m_current.object(), ! m_appliedStartWidth, m_includeEndWidth); 810 LayoutUnit inlineLogicalTempWidth = inlineLogicalWidth(m_current.object(), ! m_appliedStartWidth, m_includeEndWidth);
815 m_width.addUncommittedWidth(additionalTempWidth + inlineLogicalTempWidth); 811 m_width.addUncommittedWidth(additionalTempWidth + inlineLogicalTempWidth);
816 812
817 if (m_collapseWhiteSpace && m_currentCharacterIsSpace && additionalTempWidth ) 813 if (m_collapseWhiteSpace && m_currentCharacterIsSpace && additionalTempWidth )
818 m_width.setTrailingWhitespaceWidth(additionalTempWidth + inlineLogicalTe mpWidth); 814 m_width.setTrailingWhitespaceWidth(additionalTempWidth + inlineLogicalTe mpWidth);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 898
903 if (style.textIndentType() == TextIndentHanging) 899 if (style.textIndentType() == TextIndentHanging)
904 shouldIndentText = shouldIndentText == IndentText ? DoNotIndentText : In dentText; 900 shouldIndentText = shouldIndentText == IndentText ? DoNotIndentText : In dentText;
905 901
906 return shouldIndentText; 902 return shouldIndentText;
907 } 903 }
908 904
909 } 905 }
910 906
911 #endif // BreakingContextInlineHeaders_h 907 #endif // BreakingContextInlineHeaders_h
OLDNEW
« no previous file with comments | « Source/core/layout/LayoutTextCombine.cpp ('k') | Source/core/layout/line/GlyphOverflow.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698