Changeset 121102 in webkit
- Timestamp:
- Jun 23, 2012 2:23:12 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r121101 r121102 1 2012-06-23 Dan Bernstein <mitz@apple.com> 2 3 RenderText’s minimum preferred width is incorrect automatic hyphenation is used 4 https://bugs.webkit.org/show_bug.cgi?id=89814 5 6 Reviewed by Sam Weinig. 7 8 * fast/text/hyphen-min-preferred-width-expected.html: Added. 9 * fast/text/hyphen-min-preferred-width.html: Added. 10 1 11 2012-06-23 Kenneth Russell <kbr@google.com> 2 12 -
trunk/Source/WebCore/ChangeLog
r121098 r121102 1 2012-06-23 Dan Bernstein <mitz@apple.com> 2 3 RenderText’s minimum preferred width is incorrect automatic hyphenation is used 4 https://bugs.webkit.org/show_bug.cgi?id=89814 5 6 Reviewed by Sam Weinig. 7 8 Test: fast/text/hyphen-min-preferred-width.html 9 10 * rendering/RenderText.cpp: 11 (WebCore::maxWordFragmentWidth): Added this helper function. It returns the width of the 12 widest hyphenated fragment of the word (except for the suffix after the last hyphen) and 13 the offset of the last hyphenation opportunity. 14 (WebCore::RenderText::computePreferredLogicalWidths): Changed this function to consider the 15 widths of hyphenated word fragments rather than entire words when computing the minimum 16 width. Because hyphenating and measuring all fragments is expensive, hyphenation is only 17 attempted if the unhyphenated word is wider than the current minimum width. 18 1 19 2012-06-23 Sheriff Bot <webkit.review.bot@gmail.com> 2 20 -
trunk/Source/WebCore/rendering/RenderText.cpp
r121050 r121102 31 31 #include "FontTranscoder.h" 32 32 #include "FrameView.h" 33 #include "Hyphenation.h" 33 34 #include "InlineTextBox.h" 34 35 #include "Range.h" … … 889 890 } 890 891 892 static float maxWordFragmentWidth(RenderText* renderer, RenderStyle* style, const Font& font, const UChar* word, int wordLength, int minimumPrefixLength, int minimumSuffixLength, int& suffixStart) 893 { 894 suffixStart = 0; 895 if (wordLength <= minimumSuffixLength) 896 return 0; 897 898 Vector<int, 8> hyphenLocations; 899 int hyphenLocation = wordLength - minimumSuffixLength; 900 while ((hyphenLocation = lastHyphenLocation(word, wordLength, hyphenLocation, style->locale())) >= minimumPrefixLength) 901 hyphenLocations.append(hyphenLocation); 902 903 if (hyphenLocations.isEmpty()) 904 return 0; 905 906 hyphenLocations.reverse(); 907 908 float minimumFragmentWidthToConsider = font.pixelSize() * 5 / 4 + hyphenWidth(renderer, font); 909 float maxFragmentWidth = 0; 910 for (size_t k = 0; k < hyphenLocations.size(); ++k) { 911 int fragmentLength = hyphenLocations[k] - suffixStart; 912 StringBuilder fragmentWithHyphen; 913 fragmentWithHyphen.append(word + suffixStart, fragmentLength); 914 fragmentWithHyphen.append(style->hyphenString()); 915 916 TextRun run = RenderBlock::constructTextRun(renderer, font, fragmentWithHyphen.characters(), fragmentWithHyphen.length(), style); 917 run.setCharactersLength(fragmentWithHyphen.length()); 918 run.setCharacterScanForCodePath(!renderer->canUseSimpleFontCodePath()); 919 float fragmentWidth = font.width(run); 920 921 // Narrow prefixes are ignored. See tryHyphenating in RenderBlockLineLayout.cpp. 922 if (fragmentWidth <= minimumFragmentWidthToConsider) 923 continue; 924 925 suffixStart += fragmentLength; 926 maxFragmentWidth = max(maxFragmentWidth, fragmentWidth); 927 } 928 929 return maxFragmentWidth; 930 } 931 891 932 void RenderText::computePreferredLogicalWidths(float leadWidth, HashSet<const SimpleFontData*>& fallbackFonts, GlyphOverflow& glyphOverflow) 892 933 { … … 926 967 // space, then subtract its width. 927 968 float wordTrailingSpaceWidth = f.typesettingFeatures() & Kerning ? f.width(RenderBlock::constructTextRun(this, f, &space, 1, styleToUse)) : 0; 969 970 // If automatic hyphenation is allowed, we keep track of the width of the widest word (or word 971 // fragment) encountered so far, and only try hyphenating words that are wider. 972 float maxWordWidth = numeric_limits<float>::max(); 973 int minimumPrefixLength = 0; 974 int minimumSuffixLength = 0; 975 if (styleToUse->hyphens() == HyphensAuto && canHyphenate(styleToUse->locale())) { 976 maxWordWidth = 0; 977 978 // Map 'hyphenate-limit-{before,after}: auto;' to 2. 979 minimumPrefixLength = styleToUse->hyphenationLimitBefore(); 980 if (minimumPrefixLength < 0) 981 minimumPrefixLength = 2; 982 983 minimumSuffixLength = styleToUse->hyphenationLimitAfter(); 984 if (minimumSuffixLength < 0) 985 minimumSuffixLength = 2; 986 } 928 987 929 988 int firstGlyphLeftOverflow = -1; … … 1006 1065 } 1007 1066 1067 if (w > maxWordWidth) { 1068 int suffixStart; 1069 float maxFragmentWidth = maxWordFragmentWidth(this, styleToUse, f, txt + i, wordLen, minimumPrefixLength, minimumSuffixLength, suffixStart); 1070 1071 if (suffixStart) { 1072 float suffixWidth; 1073 if (wordTrailingSpaceWidth && isSpace) 1074 suffixWidth = widthFromCache(f, i + suffixStart, wordLen - suffixStart + 1, leadWidth + currMaxWidth, 0, 0) - wordTrailingSpaceWidth; 1075 else 1076 suffixWidth = widthFromCache(f, i + suffixStart, wordLen - suffixStart, leadWidth + currMaxWidth, 0, 0); 1077 1078 maxFragmentWidth = max(maxFragmentWidth, suffixWidth); 1079 1080 currMinWidth += maxFragmentWidth - w; 1081 maxWordWidth = max(maxWordWidth, maxFragmentWidth); 1082 } else 1083 maxWordWidth = w; 1084 } 1085 1008 1086 if (firstGlyphLeftOverflow < 0) 1009 1087 firstGlyphLeftOverflow = glyphOverflow.left; … … 1033 1111 if (hasBreak) 1034 1112 m_hasBreakableChar = true; 1035 m_beginMinWidth = hasBreak ? 0 : w;1113 m_beginMinWidth = hasBreak ? 0 : currMinWidth; 1036 1114 } 1037 m_endMinWidth = w;1115 m_endMinWidth = currMinWidth; 1038 1116 1039 1117 if (currMinWidth > m_minWidth)
Note: See TracChangeset
for help on using the changeset viewer.