5

Changeset 147170 – WebKit

 3 years ago
source link: https://trac.webkit.org/changeset/147170/webkit
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Changeset 147170 in webkit

View differences
Show lines around each change
Show the changes in full context
Ignore:
Blank lines
Case changes
White space changes
Timestamp: Mar 28, 2013 3:25:23 PM (9 years ago) Author: [email protected] Message:

[css3-text] Add platform support for "wavy" text decoration style
​https://bugs.webkit.org/show_bug.cgi?id=92868

Patch by Lamarque V. Souza <[email protected]> on 2013-03-28
Reviewed by Benjamin Poulain.

Source/WebCore:

This patch uses GraphicsContext::strokePath() to implement
wavy decoration for the CSS3 property "text-decoration-style".

No new tests as this is covered with existing tests.

  • rendering/InlineTextBox.cpp:

(WebCore::textDecorationStyleToStrokeStyle): Remove obsolete comment.
(WebCore::adjustStepToDecorationLength): Add function to adjust
variables used to calculate the lenght of Bezier curves.
(WebCore::strokeWavyTextDecoration): Add function to stroke wavy
decoration based on cubic Bezier curve.
(WebCore::InlineTextBox::paintDecoration): Call
strokeWavyTextDecoration when necessary.

LayoutTests:

Rebaseline chromium-linux expectation for
fast/css3-text/css3-text-decoration/text-decoration-style.html.

  • platform/chromium-linux/fast/css3-text/css3-text-decoration/text-decoration-style-expected.png: Added.
Location: trunk Files:
1 added 3 edited
  • TabularUnified trunk/LayoutTests/ChangeLog

    r147165 r147170   12013-03-28  Lamarque V. Souza  <[email protected]> 2 3        [css3-text] Add platform support for "wavy" text decoration style 4        https://bugs.webkit.org/show_bug.cgi?id=92868 5 6        Reviewed by Benjamin Poulain. 7 8        Rebaseline chromium-linux expectation for 9        fast/css3-text/css3-text-decoration/text-decoration-style.html. 10 11        * platform/chromium-linux/fast/css3-text/css3-text-decoration/text-decoration-style-expected.png: Added. 12 1132013-03-28  Nate Chapin  <[email protected]> 214
  • TabularUnified trunk/Source/WebCore/ChangeLog

    r147169 r147170   12013-03-28  Lamarque V. Souza  <[email protected]> 2 3        [css3-text] Add platform support for "wavy" text decoration style 4        https://bugs.webkit.org/show_bug.cgi?id=92868 5 6        Reviewed by Benjamin Poulain. 7 8        This patch uses GraphicsContext::strokePath() to implement 9        wavy decoration for the CSS3 property "text-decoration-style". 10 11        No new tests as this is covered with existing tests. 12 13        * rendering/InlineTextBox.cpp: 14        (WebCore::textDecorationStyleToStrokeStyle): Remove obsolete comment. 15        (WebCore::adjustStepToDecorationLength): Add function to adjust 16        variables used to calculate the lenght of Bezier curves. 17        (WebCore::strokeWavyTextDecoration): Add function to stroke wavy 18        decoration based on cubic Bezier curve. 19        (WebCore::InlineTextBox::paintDecoration): Call 20        strokeWavyTextDecoration when necessary. 21 1222013-03-28  Arnaud Renevier  <[email protected]> 223
  • TabularUnified trunk/Source/WebCore/rendering/InlineTextBox.cpp

    r147008 r147170   955955        break; 956956    case TextDecorationStyleWavy: 957        // FIXME: https://bugs.webkit.org/show_bug.cgi?id=92868 - Needs platform support. 958957        strokeStyle = WavyStroke; 959958        break;   991990#endif // CSS3_TEXT 992991 992#if ENABLE(CSS3_TEXT) 993static void adjustStepToDecorationLength(float& step, float& controlPointDistance, float length) 994{ 995    ASSERT(step > 0); 996 997    if (length <= 0) 998        return; 999 1000    unsigned stepCount = static_cast<unsigned>(length / step); 1001 1002    // Each Bezier curve starts at the same pixel that the previous one 1003    // ended. We need to subtract (stepCount - 1) pixels when calculating the 1004    // length covered to account for that. 1005    float uncoveredLength = length - (stepCount * step - (stepCount - 1)); 1006    float adjustment = uncoveredLength / stepCount; 1007    step += adjustment; 1008    controlPointDistance += adjustment; 1009} 1010 1011/* 1012 * Draw one cubic Bezier curve and repeat the same pattern long the the decoration's axis. 1013 * The start point (p1), controlPoint1, controlPoint2 and end point (p2) of the Bezier curve 1014 * form a diamond shape: 1015 * 1016 *                              step 1017 *                         |-----------| 1018 * 1019 *                   controlPoint1 1020 *                         + 1021 * 1022 * 1023 *                  . . 1024 *                .     . 1025 *              .         . 1026 * (x1, y1) p1 +           .            + p2 (x2, y2) - <--- Decoration's axis 1027 *                          .         .               | 1028 *                            .     .                 | 1029 *                              . .                   | controlPointDistance 1030 *                                                    | 1031 *                                                    | 1032 *                         +                          - 1033 *                   controlPoint2 1034 * 1035 *             |-----------| 1036 *                 step 1037 */ 1038static void strokeWavyTextDecoration(GraphicsContext* context, FloatPoint& p1, FloatPoint& p2, float strokeThickness) 1039{ 1040    context->adjustLineToPixelBoundaries(p1, p2, strokeThickness, context->strokeStyle()); 1041 1042    Path path; 1043    path.moveTo(p1); 1044 1045    // Distance between decoration's axis and Bezier curve's control points. 1046    // The height of the curve is based on this distance. Use a minimum of 6 pixels distance since 1047    // the actual curve passes approximately at half of that distance, that is 3 pixels. 1048    // The minimum height of the curve is also approximately 3 pixels. Increases the curve's height 1049    // as strockThickness increases to make the curve looks better. 1050    float controlPointDistance = 3 * max<float>(2, strokeThickness); 1051 1052    // Increment used to form the diamond shape between start point (p1), control 1053    // points and end point (p2) along the axis of the decoration. Makes the 1054    // curve wider as strockThickness increases to make the curve looks better. 1055    float step = 2 * max<float>(2, strokeThickness); 1056 1057    bool isVerticalLine = (p1.x() == p2.x()); 1058 1059    if (isVerticalLine) { 1060        ASSERT(p1.x() == p2.x()); 1061 1062        float xAxis = p1.x(); 1063        float y1; 1064        float y2; 1065 1066        if (p1.y() < p2.y()) { 1067            y1 = p1.y(); 1068            y2 = p2.y(); 1069        } else { 1070            y1 = p2.y(); 1071            y2 = p1.y(); 1072        } 1073 1074        adjustStepToDecorationLength(step, controlPointDistance, y2 - y1); 1075        FloatPoint controlPoint1(xAxis + controlPointDistance, 0); 1076        FloatPoint controlPoint2(xAxis - controlPointDistance, 0); 1077 1078        for (float y = y1; y + 2 * step <= y2;) { 1079            controlPoint1.setY(y + step); 1080            controlPoint2.setY(y + step); 1081            y += 2 * step; 1082            path.addBezierCurveTo(controlPoint1, controlPoint2, FloatPoint(xAxis, y)); 1083        } 1084    } else { 1085        ASSERT(p1.y() == p2.y()); 1086 1087        float yAxis = p1.y(); 1088        float x1; 1089        float x2; 1090 1091        if (p1.x() < p2.x()) { 1092            x1 = p1.x(); 1093            x2 = p2.x(); 1094        } else { 1095            x1 = p2.x(); 1096            x2 = p1.x(); 1097        } 1098 1099        adjustStepToDecorationLength(step, controlPointDistance, x2 - x1); 1100        FloatPoint controlPoint1(0, yAxis + controlPointDistance); 1101        FloatPoint controlPoint2(0, yAxis - controlPointDistance); 1102 1103        for (float x = x1; x + 2 * step <= x2;) { 1104            controlPoint1.setX(x + step); 1105            controlPoint2.setX(x + step); 1106            x += 2 * step; 1107            path.addBezierCurveTo(controlPoint1, controlPoint2, FloatPoint(x, yAxis)); 1108        } 1109    } 1110 1111    context->setShouldAntialias(true); 1112    context->strokePath(path); 1113} 1114#endif // CSS3_TEXT 1115 9931116void InlineTextBox::paintDecoration(GraphicsContext* context, const FloatPoint& boxOrigin, ETextDecoration deco, TextDecorationStyle decorationStyle, const ShadowData* shadow) 9941117{   10701193            TextUnderlinePosition underlinePosition = styleToUse->textUnderlinePosition(); 10711194            const int underlineOffset = computeUnderlineOffset(underlinePosition, styleToUse->fontMetrics(), this, textDecorationThickness); 1072            context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin.y() + underlineOffset), width, isPrinting); 1073 1074            if (decorationStyle == TextDecorationStyleDouble) 1075                context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin.y() + underlineOffset + doubleOffset), width, isPrinting); 1195 1196            switch (decorationStyle) { 1197            case TextDecorationStyleWavy: { 1198                FloatPoint start(localOrigin.x(), localOrigin.y() + underlineOffset + doubleOffset); 1199                FloatPoint end(localOrigin.x() + width, localOrigin.y() + underlineOffset + doubleOffset); 1200                strokeWavyTextDecoration(context, start, end, textDecorationThickness); 1201                break; 1202            } 1203            default: 1204                context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin.y() + underlineOffset), width, isPrinting); 1205 1206                if (decorationStyle == TextDecorationStyleDouble) 1207                    context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin.y() + underlineOffset + doubleOffset), width, isPrinting); 1208            } 10761209#else 10771210            // Leave one pixel of white between the baseline and the underline.   10811214        if (deco & OVERLINE) { 10821215            context->setStrokeColor(overline, colorSpace); 1083            context->drawLineForText(localOrigin, width, isPrinting); 10841216#if ENABLE(CSS3_TEXT) 1085            if (decorationStyle == TextDecorationStyleDouble) 1086                context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin.y() - doubleOffset), width, isPrinting); 1217            switch (decorationStyle) { 1218            case TextDecorationStyleWavy: { 1219                FloatPoint start(localOrigin.x(), localOrigin.y() - doubleOffset); 1220                FloatPoint end(localOrigin.x() + width, localOrigin.y() - doubleOffset); 1221                strokeWavyTextDecoration(context, start, end, textDecorationThickness); 1222                break; 1223            } 1224            default: 1225#endif // CSS3_TEXT 1226                context->drawLineForText(localOrigin, width, isPrinting); 1227#if ENABLE(CSS3_TEXT) 1228                if (decorationStyle == TextDecorationStyleDouble) 1229                    context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin.y() - doubleOffset), width, isPrinting); 1230            } 10871231#endif // CSS3_TEXT 10881232        } 10891233        if (deco & LINE_THROUGH) { 10901234            context->setStrokeColor(linethrough, colorSpace); 1091            context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin.y() + 2 * baseline / 3), width, isPrinting); 10921235#if ENABLE(CSS3_TEXT) 1093            if (decorationStyle == TextDecorationStyleDouble) 1094                context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin.y() + doubleOffset + 2 * baseline / 3), width, isPrinting); 1236            switch (decorationStyle) { 1237            case TextDecorationStyleWavy: { 1238                FloatPoint start(localOrigin.x(), localOrigin.y() + 2 * baseline / 3); 1239                FloatPoint end(localOrigin.x() + width, localOrigin.y() + 2 * baseline / 3); 1240                strokeWavyTextDecoration(context, start, end, textDecorationThickness); 1241                break; 1242            } 1243            default: 1244#endif // CSS3_TEXT 1245                context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin.y() + 2 * baseline / 3), width, isPrinting); 1246#if ENABLE(CSS3_TEXT) 1247                if (decorationStyle == TextDecorationStyleDouble) 1248                    context->drawLineForText(FloatPoint(localOrigin.x(), localOrigin.y() + doubleOffset + 2 * baseline / 3), width, isPrinting); 1249            } 10951250#endif // CSS3_TEXT 10961251        }
Note: See TracChangeset for help on using the changeset viewer.

Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK