OLD | NEW |
---|---|
1 /* | 1 /* |
2 * (C) 1999 Lars Knoll (knoll@kde.org) | 2 * (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 2000 Dirk Mueller (mueller@kde.org) | 3 * (C) 2000 Dirk Mueller (mueller@kde.org) |
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. | 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights 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 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
909 strokeStyle = DashedStroke; | 909 strokeStyle = DashedStroke; |
910 break; | 910 break; |
911 case TextDecorationStyleWavy: | 911 case TextDecorationStyleWavy: |
912 strokeStyle = WavyStroke; | 912 strokeStyle = WavyStroke; |
913 break; | 913 break; |
914 } | 914 } |
915 | 915 |
916 return strokeStyle; | 916 return strokeStyle; |
917 } | 917 } |
918 | 918 |
919 #if ENABLE(CSS3_TEXT) | 919 static int computeUnderlineOffset(const TextUnderlinePosition underlinePosition, const FontMetrics& fontMetrics, const InlineTextBox* inlineTextBox, const float textDecorationThickness) |
920 static int computeUnderlineOffset(const TextUnderlinePosition underlinePosition, const FontMetrics& fontMetrics, const InlineTextBox* inlineTextBox, const int t extDecorationThickness) | |
921 { | 920 { |
922 // Compute the gap between the font and the underline. Use at least one | 921 // Compute the gap between the font and the underline. Use at least one |
923 // pixel gap, if underline is thick then use a bigger gap. | 922 // pixel gap, if underline is thick then use a bigger gap. |
924 const int gap = max<int>(1, ceilf(textDecorationThickness / 2.0)); | 923 const int gap = max<int>(1, ceilf(textDecorationThickness / 2.0)); |
925 | 924 |
926 // According to the specification TextUnderlinePositionAuto should default t o 'alphabetic' for horizontal text | 925 // According to the specification TextUnderlinePositionAuto should default t o 'alphabetic' for horizontal text |
927 // and to 'under Left' for vertical text (e.g. japanese). We support only ho rizontal text for now. | 926 // and to 'under Left' for vertical text (e.g. japanese). We support only ho rizontal text for now. |
928 switch (underlinePosition) { | 927 switch (underlinePosition) { |
929 case TextUnderlinePositionAlphabetic: | 928 case TextUnderlinePositionAlphabetic: |
930 case TextUnderlinePositionAuto: | 929 case TextUnderlinePositionAuto: |
931 return fontMetrics.ascent() + gap; // Position underline near the alphab etic baseline. | 930 return fontMetrics.ascent() + gap; // Position underline near the alphab etic baseline. |
932 case TextUnderlinePositionUnder: { | 931 case TextUnderlinePositionUnder: { |
933 // Position underline relative to the under edge of the lowest element's content box. | 932 // Position underline relative to the under edge of the lowest element's content box. |
934 const float offset = inlineTextBox->root()->maxLogicalTop() - inlineText Box->logicalTop(); | 933 const float offset = inlineTextBox->root()->maxLogicalTop() - inlineText Box->logicalTop(); |
935 if (offset > 0) | 934 if (offset > 0) |
936 return inlineTextBox->logicalHeight() + gap + offset; | 935 return inlineTextBox->logicalHeight() + gap + offset; |
937 return inlineTextBox->logicalHeight() + gap; | 936 return inlineTextBox->logicalHeight() + gap; |
938 } | 937 } |
939 } | 938 } |
940 | 939 |
941 ASSERT_NOT_REACHED(); | 940 ASSERT_NOT_REACHED(); |
942 return fontMetrics.ascent() + gap; | 941 return fontMetrics.ascent() + gap; |
943 } | 942 } |
944 #endif // CSS3_TEXT | |
945 | 943 |
946 static void adjustStepToDecorationLength(float& step, float& controlPointDistanc e, float length) | 944 static void adjustStepToDecorationLength(float& step, float& controlPointDistanc e, float length) |
947 { | 945 { |
948 ASSERT(step > 0); | 946 ASSERT(step > 0); |
949 | 947 |
950 if (length <= 0) | 948 if (length <= 0) |
951 return; | 949 return; |
952 | 950 |
953 unsigned stepCount = static_cast<unsigned>(length / step); | 951 unsigned stepCount = static_cast<unsigned>(length / step); |
954 | 952 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1093 bool isPrinting = textRenderer()->document().printing(); | 1091 bool isPrinting = textRenderer()->document().printing(); |
1094 | 1092 |
1095 bool linesAreOpaque = !isPrinting && (!(deco & TextDecorationUnderline) || u nderline.alpha() == 255) && (!(deco & TextDecorationOverline) || overline.alpha( ) == 255) && (!(deco & TextDecorationLineThrough) || linethrough.alpha() == 255) ; | 1093 bool linesAreOpaque = !isPrinting && (!(deco & TextDecorationUnderline) || u nderline.alpha() == 255) && (!(deco & TextDecorationOverline) || overline.alpha( ) == 255) && (!(deco & TextDecorationLineThrough) || linethrough.alpha() == 255) ; |
1096 | 1094 |
1097 RenderStyle* styleToUse = renderer()->style(isFirstLineStyle()); | 1095 RenderStyle* styleToUse = renderer()->style(isFirstLineStyle()); |
1098 int baseline = styleToUse->fontMetrics().ascent(); | 1096 int baseline = styleToUse->fontMetrics().ascent(); |
1099 | 1097 |
1100 size_t shadowCount = shadowList ? shadowList->shadows().size() : 0; | 1098 size_t shadowCount = shadowList ? shadowList->shadows().size() : 0; |
1101 // Set the thick of the line to be 10% (or something else ?)of the computed font size and not less than 1px. | 1099 // Set the thick of the line to be 10% (or something else ?)of the computed font size and not less than 1px. |
1102 // Using computedFontSize should take care of zoom as well. | 1100 // Using computedFontSize should take care of zoom as well. |
1103 textDecorationThickness = max(textDecorationThickness, styleToUse->computedF ontSize() / 10.0f); | 1101 textDecorationThickness = max(textDecorationThickness, styleToUse->computedF ontSize() / 10.0f); |
Julien - ping for review
2013/10/31 22:54:07
Maybe be worth simplifying the code while removing
abinader
2013/11/01 12:16:42
Sure thing. Did the same for gap calculation insid
| |
1104 context->setStrokeThickness(textDecorationThickness); | 1102 context->setStrokeThickness(textDecorationThickness); |
1105 | 1103 |
1106 int extraOffset = 0; | 1104 int extraOffset = 0; |
1107 if (!linesAreOpaque && shadowCount > 1) { | 1105 if (!linesAreOpaque && shadowCount > 1) { |
1108 FloatRect clipRect(localOrigin, FloatSize(width, baseline + 2)); | 1106 FloatRect clipRect(localOrigin, FloatSize(width, baseline + 2)); |
1109 for (size_t i = shadowCount; i--; ) { | 1107 for (size_t i = shadowCount; i--; ) { |
1110 const ShadowData& s = shadowList->shadows()[i]; | 1108 const ShadowData& s = shadowList->shadows()[i]; |
1111 FloatRect shadowRect(localOrigin, FloatSize(width, baseline + 2)); | 1109 FloatRect shadowRect(localOrigin, FloatSize(width, baseline + 2)); |
1112 shadowRect.inflate(s.blur()); | 1110 shadowRect.inflate(s.blur()); |
1113 int shadowX = isHorizontal() ? s.x() : s.y(); | 1111 int shadowX = isHorizontal() ? s.x() : s.y(); |
(...skipping 19 matching lines...) Expand all Loading... | |
1133 int shadowX = isHorizontal() ? shadow.x() : shadow.y(); | 1131 int shadowX = isHorizontal() ? shadow.x() : shadow.y(); |
1134 int shadowY = isHorizontal() ? shadow.y() : -shadow.x(); | 1132 int shadowY = isHorizontal() ? shadow.y() : -shadow.x(); |
1135 context->setShadow(FloatSize(shadowX, shadowY - extraOffset), shadow .blur(), shadow.color()); | 1133 context->setShadow(FloatSize(shadowX, shadowY - extraOffset), shadow .blur(), shadow.color()); |
1136 } | 1134 } |
1137 | 1135 |
1138 // Offset between lines - always non-zero, so lines never cross each oth er. | 1136 // Offset between lines - always non-zero, so lines never cross each oth er. |
1139 float doubleOffset = textDecorationThickness + 1.f; | 1137 float doubleOffset = textDecorationThickness + 1.f; |
1140 context->setStrokeStyle(textDecorationStyleToStrokeStyle(decorationStyle )); | 1138 context->setStrokeStyle(textDecorationStyleToStrokeStyle(decorationStyle )); |
1141 if (deco & TextDecorationUnderline) { | 1139 if (deco & TextDecorationUnderline) { |
1142 context->setStrokeColor(underline); | 1140 context->setStrokeColor(underline); |
1143 #if ENABLE(CSS3_TEXT) | 1141 const int underlineOffset = computeUnderlineOffset(styleToUse->textU nderlinePosition(), styleToUse->fontMetrics(), this, textDecorationThickness); |
1144 TextUnderlinePosition underlinePosition = styleToUse->textUnderlineP osition(); | |
1145 const int underlineOffset = computeUnderlineOffset(underlinePosition , styleToUse->fontMetrics(), this, textDecorationThickness); | |
1146 #else | |
1147 const int underlineOffset = styleToUse->fontMetrics().ascent() + max <int>(1, ceilf(textDecorationThickness / 2.0)); | |
1148 #endif // CSS3_TEXT | |
1149 | |
1150 switch (decorationStyle) { | 1142 switch (decorationStyle) { |
1151 case TextDecorationStyleWavy: { | 1143 case TextDecorationStyleWavy: { |
1152 FloatPoint start(localOrigin.x(), localOrigin.y() + underlineOff set + doubleOffset); | 1144 FloatPoint start(localOrigin.x(), localOrigin.y() + underlineOff set + doubleOffset); |
1153 FloatPoint end(localOrigin.x() + width, localOrigin.y() + underl ineOffset + doubleOffset); | 1145 FloatPoint end(localOrigin.x() + width, localOrigin.y() + underl ineOffset + doubleOffset); |
1154 strokeWavyTextDecoration(context, start, end, textDecorationThic kness); | 1146 strokeWavyTextDecoration(context, start, end, textDecorationThic kness); |
1155 break; | 1147 break; |
1156 } | 1148 } |
1157 default: | 1149 default: |
1158 context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin .y() + underlineOffset), width, isPrinting); | 1150 context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin .y() + underlineOffset), width, isPrinting); |
1159 | 1151 |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1577 printedCharacters = fprintf(stderr, "\t%s %p", obj->renderName(), obj); | 1569 printedCharacters = fprintf(stderr, "\t%s %p", obj->renderName(), obj); |
1578 const int rendererCharacterOffset = 24; | 1570 const int rendererCharacterOffset = 24; |
1579 for (; printedCharacters < rendererCharacterOffset; printedCharacters++) | 1571 for (; printedCharacters < rendererCharacterOffset; printedCharacters++) |
1580 fputc(' ', stderr); | 1572 fputc(' ', stderr); |
1581 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata()); | 1573 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata()); |
1582 } | 1574 } |
1583 | 1575 |
1584 #endif | 1576 #endif |
1585 | 1577 |
1586 } // namespace WebCore | 1578 } // namespace WebCore |
OLD | NEW |