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

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

Issue 104813005: Explicitly set text direction for TextRuns (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Patch for landing Created 6 years, 11 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/rendering/RenderText.cpp ('k') | Source/platform/fonts/harfbuzz/HarfBuzzShaper.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 680 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 width.updateCurrentShapeSegment(); 691 width.updateCurrentShapeSegment();
692 width.updateAvailableWidth(); 692 width.updateAvailableWidth();
693 } 693 }
694 694
695 inline float measureHyphenWidth(RenderText* renderer, const Font& font) 695 inline float measureHyphenWidth(RenderText* renderer, const Font& font)
696 { 696 {
697 RenderStyle* style = renderer->style(); 697 RenderStyle* style = renderer->style();
698 return font.width(RenderBlockFlow::constructTextRun(renderer, font, style->h yphenString().string(), style)); 698 return font.width(RenderBlockFlow::constructTextRun(renderer, font, style->h yphenString().string(), style));
699 } 699 }
700 700
701 ALWAYS_INLINE float textWidth(RenderText* text, unsigned from, unsigned len, con st Font& font, float xPos, bool isFixedPitch, bool collapseWhiteSpace, HashSet<c onst SimpleFontData*>* fallbackFonts = 0, TextLayout* layout = 0) 701 ALWAYS_INLINE float textWidth(RenderText* text, unsigned from, unsigned len, con st Font& font, float xPos, bool isFixedPitch, WTF::Unicode::Direction direction, bool collapseWhiteSpace, HashSet<const SimpleFontData*>* fallbackFonts = 0, Tex tLayout* layout = 0)
702 { 702 {
703 TextDirection textDirection = direction == WTF::Unicode::RightToLeft
704 || direction == WTF::Unicode::RightToLeftArabic ? RTL : LTR;
703 GlyphOverflow glyphOverflow; 705 GlyphOverflow glyphOverflow;
704 if (isFixedPitch || (!from && len == text->textLength()) || text->style()->h asTextCombine()) 706 if (isFixedPitch || (!from && len == text->textLength()) || text->style()->h asTextCombine())
705 return text->width(from, len, font, xPos, fallbackFonts, &glyphOverflow) ; 707 return text->width(from, len, font, xPos, textDirection, fallbackFonts, &glyphOverflow);
706 708
707 if (layout) 709 if (layout)
708 return Font::width(*layout, from, len, fallbackFonts); 710 return Font::width(*layout, from, len, fallbackFonts);
709 711
710 TextRun run = RenderBlockFlow::constructTextRun(text, font, text, from, len, text->style()); 712 TextRun run = RenderBlockFlow::constructTextRun(text, font, text, from, len, text->style(), textDirection);
711 run.setCharactersLength(text->textLength() - from); 713 run.setCharactersLength(text->textLength() - from);
712 ASSERT(run.charactersLength() >= run.length()); 714 ASSERT(run.charactersLength() >= run.length());
713 715
714 run.setCharacterScanForCodePath(!text->canUseSimpleFontCodePath()); 716 run.setCharacterScanForCodePath(!text->canUseSimpleFontCodePath());
715 run.setTabSize(!collapseWhiteSpace, text->style()->tabSize()); 717 run.setTabSize(!collapseWhiteSpace, text->style()->tabSize());
716 run.setXPos(xPos); 718 run.setXPos(xPos);
717 return font.width(run, fallbackFonts, &glyphOverflow); 719 return font.width(run, fallbackFonts, &glyphOverflow);
718 } 720 }
719 721
720 inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool & hyphenated) 722 inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool & hyphenated)
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 if (c == softHyphen && m_autoWrap && !hyphenWidth) { 798 if (c == softHyphen && m_autoWrap && !hyphenWidth) {
797 hyphenWidth = measureHyphenWidth(renderText, font); 799 hyphenWidth = measureHyphenWidth(renderText, font);
798 m_width.addUncommittedWidth(hyphenWidth); 800 m_width.addUncommittedWidth(hyphenWidth);
799 } 801 }
800 802
801 bool applyWordSpacing = false; 803 bool applyWordSpacing = false;
802 804
803 if ((breakAll || breakWords) && !midWordBreak) { 805 if ((breakAll || breakWords) && !midWordBreak) {
804 wrapW += charWidth; 806 wrapW += charWidth;
805 bool midWordBreakIsBeforeSurrogatePair = U16_IS_LEAD(c) && m_current .offset() + 1 < renderText->textLength() && U16_IS_TRAIL((*renderText)[m_current .offset() + 1]); 807 bool midWordBreakIsBeforeSurrogatePair = U16_IS_LEAD(c) && m_current .offset() + 1 < renderText->textLength() && U16_IS_TRAIL((*renderText)[m_current .offset() + 1]);
806 charWidth = textWidth(renderText, m_current.offset(), midWordBreakIs BeforeSurrogatePair ? 2 : 1, font, m_width.committedWidth() + wrapW, isFixedPitc h, m_collapseWhiteSpace, 0, textLayout); 808 charWidth = textWidth(renderText, m_current.offset(), midWordBreakIs BeforeSurrogatePair ? 2 : 1, font, m_width.committedWidth() + wrapW, isFixedPitc h, m_resolver.position().direction(), m_collapseWhiteSpace, 0, textLayout);
807 midWordBreak = m_width.committedWidth() + wrapW + charWidth > m_widt h.availableWidth(); 809 midWordBreak = m_width.committedWidth() + wrapW + charWidth > m_widt h.availableWidth();
808 } 810 }
809 811
810 int nextBreakablePosition = m_current.nextBreakablePosition(); 812 int nextBreakablePosition = m_current.nextBreakablePosition();
811 bool betweenWords = c == '\n' || (m_currWS != PRE && !m_atStart && isBre akable(m_renderTextInfo.m_lineBreakIterator, m_current.offset(), nextBreakablePo sition)); 813 bool betweenWords = c == '\n' || (m_currWS != PRE && !m_atStart && isBre akable(m_renderTextInfo.m_lineBreakIterator, m_current.offset(), nextBreakablePo sition));
812 m_current.setNextBreakablePosition(nextBreakablePosition); 814 m_current.setNextBreakablePosition(nextBreakablePosition);
813 815
814 if (betweenWords || midWordBreak) { 816 if (betweenWords || midWordBreak) {
815 bool stoppedIgnoringSpaces = false; 817 bool stoppedIgnoringSpaces = false;
816 if (m_ignoringSpaces) { 818 if (m_ignoringSpaces) {
(...skipping 15 matching lines...) Expand all
832 834
833 wordMeasurements.grow(wordMeasurements.size() + 1); 835 wordMeasurements.grow(wordMeasurements.size() + 1);
834 WordMeasurement& wordMeasurement = wordMeasurements.last(); 836 WordMeasurement& wordMeasurement = wordMeasurements.last();
835 837
836 wordMeasurement.renderer = renderText; 838 wordMeasurement.renderer = renderText;
837 wordMeasurement.endOffset = m_current.offset(); 839 wordMeasurement.endOffset = m_current.offset();
838 wordMeasurement.startOffset = lastSpace; 840 wordMeasurement.startOffset = lastSpace;
839 841
840 float additionalTmpW; 842 float additionalTmpW;
841 if (wordTrailingSpaceWidth && c == ' ') 843 if (wordTrailingSpaceWidth && c == ' ')
842 additionalTmpW = textWidth(renderText, lastSpace, m_current.offs et() + 1 - lastSpace, font, m_width.currentWidth(), isFixedPitch, m_collapseWhit eSpace, &wordMeasurement.fallbackFonts, textLayout) - wordTrailingSpaceWidth; 844 additionalTmpW = textWidth(renderText, lastSpace, m_current.offs et() + 1 - lastSpace, font, m_width.currentWidth(), isFixedPitch, m_resolver.pos ition().direction(), m_collapseWhiteSpace, &wordMeasurement.fallbackFonts, textL ayout) - wordTrailingSpaceWidth;
843 else 845 else
844 additionalTmpW = textWidth(renderText, lastSpace, m_current.offs et() - lastSpace, font, m_width.currentWidth(), isFixedPitch, m_collapseWhiteSpa ce, &wordMeasurement.fallbackFonts, textLayout); 846 additionalTmpW = textWidth(renderText, lastSpace, m_current.offs et() - lastSpace, font, m_width.currentWidth(), isFixedPitch, m_resolver.positio n().direction(), m_collapseWhiteSpace, &wordMeasurement.fallbackFonts, textLayou t);
845 847
846 wordMeasurement.width = additionalTmpW + wordSpacingForWordMeasureme nt; 848 wordMeasurement.width = additionalTmpW + wordSpacingForWordMeasureme nt;
847 additionalTmpW += lastSpaceWordSpacing; 849 additionalTmpW += lastSpaceWordSpacing;
848 m_width.addUncommittedWidth(additionalTmpW); 850 m_width.addUncommittedWidth(additionalTmpW);
849 if (!m_appliedStartWidth) { 851 if (!m_appliedStartWidth) {
850 m_width.addUncommittedWidth(inlineLogicalWidth(m_current.object( ), true, false)); 852 m_width.addUncommittedWidth(inlineLogicalWidth(m_current.object( ), true, false));
851 m_appliedStartWidth = true; 853 m_appliedStartWidth = true;
852 } 854 }
853 855
854 if (m_lastFloatFromPreviousLine) 856 if (m_lastFloatFromPreviousLine)
855 updateSegmentsForShapes(m_block, m_lastFloatFromPreviousLine, wo rdMeasurements, m_width, m_lineInfo.isFirstLine()); 857 updateSegmentsForShapes(m_block, m_lastFloatFromPreviousLine, wo rdMeasurements, m_width, m_lineInfo.isFirstLine());
856 858
857 applyWordSpacing = wordSpacing && m_currentCharacterIsSpace; 859 applyWordSpacing = wordSpacing && m_currentCharacterIsSpace;
858 860
859 if (!m_width.committedWidth() && m_autoWrap && !m_width.fitsOnLine() ) 861 if (!m_width.committedWidth() && m_autoWrap && !m_width.fitsOnLine() )
860 m_width.fitBelowFloats(); 862 m_width.fitBelowFloats();
861 863
862 if (m_autoWrap || breakWords) { 864 if (m_autoWrap || breakWords) {
863 // If we break only after white-space, consider the current char acter 865 // If we break only after white-space, consider the current char acter
864 // as candidate width for this line. 866 // as candidate width for this line.
865 bool lineWasTooWide = false; 867 bool lineWasTooWide = false;
866 if (m_width.fitsOnLine() && m_currentCharacterIsSpace && m_curre ntStyle->breakOnlyAfterWhiteSpace() && !midWordBreak) { 868 if (m_width.fitsOnLine() && m_currentCharacterIsSpace && m_curre ntStyle->breakOnlyAfterWhiteSpace() && !midWordBreak) {
867 float charWidth = textWidth(renderText, m_current.offset(), 1, font, m_width.currentWidth(), isFixedPitch, m_collapseWhiteSpace, &wordMeasur ement.fallbackFonts, textLayout) + (applyWordSpacing ? wordSpacing : 0); 869 float charWidth = textWidth(renderText, m_current.offset(), 1, font, m_width.currentWidth(), isFixedPitch, m_resolver.position().direction() , m_collapseWhiteSpace, &wordMeasurement.fallbackFonts, textLayout) + (applyWord Spacing ? wordSpacing : 0);
868 // Check if line is too big even without the extra space 870 // Check if line is too big even without the extra space
869 // at the end of the line. If it is not, do nothing. 871 // at the end of the line. If it is not, do nothing.
870 // If the line needs the extra whitespace to be too long, 872 // If the line needs the extra whitespace to be too long,
871 // then move the line break to the space and skip all 873 // then move the line break to the space and skip all
872 // additional whitespace. 874 // additional whitespace.
873 if (!m_width.fitsOnLine(charWidth)) { 875 if (!m_width.fitsOnLine(charWidth)) {
874 lineWasTooWide = true; 876 lineWasTooWide = true;
875 m_lineBreak.moveTo(m_current.object(), m_current.offset( ), m_current.nextBreakablePosition()); 877 m_lineBreak.moveTo(m_current.object(), m_current.offset( ), m_current.nextBreakablePosition());
876 skipTrailingWhitespace(m_lineBreak, m_lineInfo); 878 skipTrailingWhitespace(m_lineBreak, m_lineInfo);
877 } 879 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 nextCharacter(c, lastCharacter, secondToLastCharacter); 990 nextCharacter(c, lastCharacter, secondToLastCharacter);
989 } 991 }
990 992
991 m_renderTextInfo.m_lineBreakIterator.setPriorContext(lastCharacter, secondTo LastCharacter); 993 m_renderTextInfo.m_lineBreakIterator.setPriorContext(lastCharacter, secondTo LastCharacter);
992 994
993 wordMeasurements.grow(wordMeasurements.size() + 1); 995 wordMeasurements.grow(wordMeasurements.size() + 1);
994 WordMeasurement& wordMeasurement = wordMeasurements.last(); 996 WordMeasurement& wordMeasurement = wordMeasurements.last();
995 wordMeasurement.renderer = renderText; 997 wordMeasurement.renderer = renderText;
996 998
997 // IMPORTANT: current.m_pos is > length here! 999 // IMPORTANT: current.m_pos is > length here!
998 float additionalTmpW = m_ignoringSpaces ? 0 : textWidth(renderText, lastSpac e, m_current.offset() - lastSpace, font, m_width.currentWidth(), isFixedPitch, m _collapseWhiteSpace, &wordMeasurement.fallbackFonts, textLayout); 1000 float additionalTmpW = m_ignoringSpaces ? 0 : textWidth(renderText, lastSpac e, m_current.offset() - lastSpace, font, m_width.currentWidth(), isFixedPitch, m _resolver.position().direction(), m_collapseWhiteSpace, &wordMeasurement.fallbac kFonts, textLayout);
999 wordMeasurement.startOffset = lastSpace; 1001 wordMeasurement.startOffset = lastSpace;
1000 wordMeasurement.endOffset = m_current.offset(); 1002 wordMeasurement.endOffset = m_current.offset();
1001 wordMeasurement.width = m_ignoringSpaces ? 0 : additionalTmpW + wordSpacingF orWordMeasurement; 1003 wordMeasurement.width = m_ignoringSpaces ? 0 : additionalTmpW + wordSpacingF orWordMeasurement;
1002 additionalTmpW += lastSpaceWordSpacing; 1004 additionalTmpW += lastSpaceWordSpacing;
1003 m_width.addUncommittedWidth(additionalTmpW + inlineLogicalWidth(m_current.ob ject(), !m_appliedStartWidth, m_includeEndWidth)); 1005 m_width.addUncommittedWidth(additionalTmpW + inlineLogicalWidth(m_current.ob ject(), !m_appliedStartWidth, m_includeEndWidth));
1004 m_includeEndWidth = false; 1006 m_includeEndWidth = false;
1005 1007
1006 if (!m_width.fitsOnLine()) { 1008 if (!m_width.fitsOnLine()) {
1007 if (!hyphenated && m_lineBreak.previousInSameNode() == softHyphen) { 1009 if (!hyphenated && m_lineBreak.previousInSameNode() == softHyphen) {
1008 hyphenated = true; 1010 hyphenated = true;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 m_lineBreak.increment(); 1140 m_lineBreak.increment();
1139 } while (!m_lineBreak.atEnd() && isEmptyInline(m_lineBreak.object())); 1141 } while (!m_lineBreak.atEnd() && isEmptyInline(m_lineBreak.object()));
1140 } 1142 }
1141 1143
1142 return m_lineBreak; 1144 return m_lineBreak;
1143 } 1145 }
1144 1146
1145 } 1147 }
1146 1148
1147 #endif // BreakingContextInlineHeaders_h 1149 #endif // BreakingContextInlineHeaders_h
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderText.cpp ('k') | Source/platform/fonts/harfbuzz/HarfBuzzShaper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698