Changeset 60858 in webkit


Ignore:
Timestamp:
Jun 8, 2010 12:11:11 PM (14 years ago)
Author:
krit@webkit.org
Message:

2010-06-08 Dirk Schulze <krit@webkit.org>

Reviewed by Nikolas Zimmermann.

Implement non-scaling-stroke (from SVG Tiny 1.2, also in Opera)
https://bugs.webkit.org/show_bug.cgi?id=31438


This is the implementation of the SVG property vector-effect according
to the specification of SVG Tiny 1.2.
getScreenCTM() was not able to calculate the transformation matrix in
comparison to the host coordinate system for objects, that get refereced
by a use element. This is fixed and covered by the the new test as well.
This patch is based upon a patch of Jeff Schiller.

Test: svg/custom/non-scaling-stroke.svg

  • css/CSSComputedStyleDeclaration.cpp: Added CSSPropertyVectorEffect. (WebCore::):
  • css/CSSPrimitiveValueMappings.h: (WebCore::CSSPrimitiveValue::CSSPrimitiveValue): (WebCore::CSSPrimitiveValue::operator EVectorEffect):
  • css/SVGCSSComputedStyleDeclaration.cpp: (WebCore::CSSComputedStyleDeclaration::getSVGPropertyCSSValue):
  • css/SVGCSSParser.cpp: (WebCore::CSSParser::parseSVGValue):
  • css/SVGCSSPropertyNames.in:
  • css/SVGCSSStyleSelector.cpp: (WebCore::CSSStyleSelector::applySVGProperty):
  • css/SVGCSSValueKeywords.in: Add vector-effect value non-scaling-stroke.
  • rendering/RenderPath.cpp: Revert transformations to ctm and transform path instead. (WebCore::fillAndStrokePath):
  • rendering/RenderSVGResourceContainer.h: (WebCore::RenderSVGResourceContainer::transformOnNonScalingStroke):
  • rendering/RenderSVGResourceGradient.cpp: Transform the gradient with the screenCTM. (WebCore::RenderSVGResourceGradient::applyResource):
  • rendering/RenderSVGResourcePattern.cpp: Transform the pattern with the screenCTM. (WebCore::RenderSVGResourcePattern::applyResource):
  • rendering/style/SVGRenderStyle.h: Added vector-effect property, not interited. (WebCore::SVGRenderStyle::NonInheritedFlags::): (WebCore::SVGRenderStyle::setBitDefaults):
  • rendering/style/SVGRenderStyleDefs.h: Added enums for vector-effect. (WebCore::):
  • svg/SVGLocatable.cpp: Calculate screenCTM for <use> referenced objects. (WebCore::SVGLocatable::computeCTM):
  • svg/SVGStyledElement.cpp: (WebCore::SVGStyledElement::cssPropertyIdForSVGAttributeName):
  • svg/svgattrs.in:

2010-06-08 Dirk Schulze <krit@webkit.org>

Reviewed by Nikolas Zimmermann.

Implement non-scaling-stroke (from SVG Tiny 1.2, also in Opera)
https://bugs.webkit.org/show_bug.cgi?id=31438


Test for SVG property vector-effect. The stroke-width should not get influenced by
any transformation on the object or its parrent.

  • platform/mac/fast/css/getComputedStyle/computed-style-expected.txt:
  • platform/mac/fast/css/getComputedStyle/computed-style-without-renderer-expected.txt:
  • platform/mac/svg/custom/non-scaling-stroke-expected.checksum: Added.
  • platform/mac/svg/custom/non-scaling-stroke-expected.png: Added.
  • platform/mac/svg/custom/non-scaling-stroke-expected.txt: Added.
  • svg/css/getComputedStyle-basic-expected.txt:
  • svg/custom/non-scaling-stroke.svg: Added.
Location:
trunk
Files:
4 added
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r60856 r60858  
     12010-06-08  Dirk Schulze  <krit@webkit.org>
     2
     3        Reviewed by Nikolas Zimmermann.
     4
     5        Implement non-scaling-stroke (from SVG Tiny 1.2, also in Opera)
     6        https://bugs.webkit.org/show_bug.cgi?id=31438
     7       
     8        Test for SVG property vector-effect. The stroke-width should not get influenced by
     9        any transformation on the object or its parrent.
     10
     11        * platform/mac/fast/css/getComputedStyle/computed-style-expected.txt:
     12        * platform/mac/fast/css/getComputedStyle/computed-style-without-renderer-expected.txt:
     13        * platform/mac/svg/custom/non-scaling-stroke-expected.checksum: Added.
     14        * platform/mac/svg/custom/non-scaling-stroke-expected.png: Added.
     15        * platform/mac/svg/custom/non-scaling-stroke-expected.txt: Added.
     16        * svg/css/getComputedStyle-basic-expected.txt:
     17        * svg/custom/non-scaling-stroke.svg: Added.
     18
    1192010-06-08  Martin Robinson  <mrobinson@igalia.com>
    220
  • trunk/LayoutTests/platform/mac/fast/css/getComputedStyle/computed-style-expected.txt

    r59968 r60858  
    210210glyph-orientation-vertical: auto;
    211211-webkit-svg-shadow: none;
     212vector-effect: none;
    212213
    213214Other attributes that the computed style class supports:
  • trunk/LayoutTests/platform/mac/fast/css/getComputedStyle/computed-style-without-renderer-expected.txt

    r59968 r60858  
    209209    glyph-orientation-vertical: auto
    210210    -webkit-svg-shadow: none
     211    vector-effect: none
    211212    background-position-x: 0%
    212213    background-position-y: 0%
  • trunk/LayoutTests/svg/css/getComputedStyle-basic-expected.txt

    r59968 r60858  
    417417rect: style.getPropertyValue(-webkit-svg-shadow) : none
    418418rect: style.getPropertyCSSValue(-webkit-svg-shadow) : [object CSSPrimitiveValue]
     419rect: style.getPropertyValue(vector-effect) : none
     420rect: style.getPropertyCSSValue(vector-effect) : [object CSSPrimitiveValue]
    419421g: style.getPropertyValue(background-attachment) : scroll
    420422g: style.getPropertyCSSValue(background-attachment) : [object CSSPrimitiveValue]
     
    835837g: style.getPropertyValue(-webkit-svg-shadow) : none
    836838g: style.getPropertyCSSValue(-webkit-svg-shadow) : [object CSSPrimitiveValue]
     839g: style.getPropertyValue(vector-effect) : none
     840g: style.getPropertyCSSValue(vector-effect) : [object CSSPrimitiveValue]
    837841
  • trunk/WebCore/ChangeLog

    r60855 r60858  
     12010-06-08  Dirk Schulze  <krit@webkit.org>
     2
     3        Reviewed by Nikolas Zimmermann.
     4
     5        Implement non-scaling-stroke (from SVG Tiny 1.2, also in Opera)
     6        https://bugs.webkit.org/show_bug.cgi?id=31438
     7       
     8        This is the implementation of the SVG property vector-effect according
     9        to the specification of SVG Tiny 1.2.
     10        getScreenCTM() was not able to calculate the transformation matrix in
     11        comparison to the host coordinate system for objects, that get refereced
     12        by a use element. This is fixed and covered by the the new test as well.
     13        This patch is based upon a patch of Jeff Schiller.
     14
     15        Test: svg/custom/non-scaling-stroke.svg
     16
     17        * css/CSSComputedStyleDeclaration.cpp: Added CSSPropertyVectorEffect.
     18        (WebCore::):
     19        * css/CSSPrimitiveValueMappings.h:
     20        (WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
     21        (WebCore::CSSPrimitiveValue::operator EVectorEffect):
     22        * css/SVGCSSComputedStyleDeclaration.cpp:
     23        (WebCore::CSSComputedStyleDeclaration::getSVGPropertyCSSValue):
     24        * css/SVGCSSParser.cpp:
     25        (WebCore::CSSParser::parseSVGValue):
     26        * css/SVGCSSPropertyNames.in:
     27        * css/SVGCSSStyleSelector.cpp:
     28        (WebCore::CSSStyleSelector::applySVGProperty):
     29        * css/SVGCSSValueKeywords.in: Add vector-effect value non-scaling-stroke.
     30        * rendering/RenderPath.cpp: Revert transformations to ctm and transform path instead.
     31        (WebCore::fillAndStrokePath):
     32        * rendering/RenderSVGResourceContainer.h:
     33        (WebCore::RenderSVGResourceContainer::transformOnNonScalingStroke):
     34        * rendering/RenderSVGResourceGradient.cpp: Transform the gradient with the screenCTM.
     35        (WebCore::RenderSVGResourceGradient::applyResource):
     36        * rendering/RenderSVGResourcePattern.cpp: Transform the pattern with the screenCTM.
     37        (WebCore::RenderSVGResourcePattern::applyResource):
     38        * rendering/style/SVGRenderStyle.h: Added vector-effect property, not interited.
     39        (WebCore::SVGRenderStyle::NonInheritedFlags::):
     40        (WebCore::SVGRenderStyle::setBitDefaults):
     41        * rendering/style/SVGRenderStyleDefs.h: Added enums for vector-effect.
     42        (WebCore::):
     43        * svg/SVGLocatable.cpp: Calculate screenCTM for <use> referenced objects.
     44        (WebCore::SVGLocatable::computeCTM):
     45        * svg/SVGStyledElement.cpp:
     46        (WebCore::SVGStyledElement::cssPropertyIdForSVGAttributeName):
     47        * svg/svgattrs.in:
     48
    1492010-06-08  Alexey Proskuryakov  <ap@apple.com>
    250
  • trunk/WebCore/css/CSSComputedStyleDeclaration.cpp

    r59968 r60858  
    265265    CSSPropertyGlyphOrientationHorizontal,
    266266    CSSPropertyGlyphOrientationVertical,
    267     CSSPropertyWebkitSvgShadow
     267    CSSPropertyWebkitSvgShadow,
     268    CSSPropertyVectorEffect
    268269#endif
    269270};
  • trunk/WebCore/css/CSSPrimitiveValueMappings.h

    r60822 r60858  
    33 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
    44 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
     5 * Copyright (C) 2009 Jeff Schiller <codedread@gmail.com>
     6 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
    57 *
    68 * Redistribution and use in source and binary forms, with or without
     
    26002602}
    26012603
     2604template<> inline CSSPrimitiveValue::CSSPrimitiveValue(EVectorEffect e)
     2605    : m_type(CSS_IDENT)
     2606    , m_hasCachedCSSText(false)
     2607{
     2608    switch (e) {
     2609    case VE_NONE:
     2610        m_value.ident = CSSValueNone;
     2611        break;
     2612    case VE_NON_SCALING_STROKE:
     2613        m_value.ident = CSSValueNonScalingStroke;
     2614        break;
     2615    }
     2616}
     2617
     2618template<> inline CSSPrimitiveValue::operator EVectorEffect() const
     2619{
     2620    switch (m_value.ident) {
     2621    case CSSValueNone:
     2622        return VE_NONE;
     2623    case CSSValueNonScalingStroke:
     2624        return VE_NON_SCALING_STROKE;
     2625    default:
     2626        ASSERT_NOT_REACHED();
     2627        return VE_NONE;
     2628    }
     2629}
     2630
    26022631#endif
    26032632
  • trunk/WebCore/css/SVGCSSComputedStyleDeclaration.cpp

    r57575 r60858  
    169169        case CSSPropertyWebkitSvgShadow:
    170170            return valueForShadow(svgStyle->shadow(), propertyID);
     171        case CSSPropertyVectorEffect:
     172            return CSSPrimitiveValue::create(svgStyle->vectorEffect());
    171173        case CSSPropertyMarker:
    172174        case CSSPropertyEnableBackground:
  • trunk/WebCore/css/SVGCSSParser.cpp

    r60752 r60858  
    221221            m_valueList->next();
    222222
     223        break;
     224       
     225    case CSSPropertyVectorEffect: // none | non-scaling-stroke | inherit
     226        if (id == CSSValueNone || id == CSSValueNonScalingStroke)
     227            valid_primitive = true;
    223228        break;
    224229
  • trunk/WebCore/css/SVGCSSPropertyNames.in

    r53157 r60858  
    4646kerning
    4747text-anchor
     48vector-effect
    4849writing-mode
    4950
  • trunk/WebCore/css/SVGCSSStyleSelector.cpp

    r59956 r60858  
    553553            return;
    554554        }
     555        case CSSPropertyVectorEffect: {
     556            HANDLE_INHERIT_AND_INITIAL(vectorEffect, VectorEffect)
     557            if (!primitiveValue)
     558                break;
     559
     560            svgstyle->setVectorEffect(*primitiveValue);
     561            break;
     562        }
    555563        default:
    556564            // If you crash here, it's because you added a css property and are not handling it
  • trunk/WebCore/css/SVGCSSValueKeywords.in

    r50760 r60858  
    274274# end
    275275
     276# CSS_PROP_VECTOR_EFFECT
     277# none
     278non-scaling-stroke
     279
     280
    276281# CSS_PROP_WRITING_MODE
    277282lr-tb
  • trunk/WebCore/rendering/RenderPath.cpp

    r60761 r60858  
    66                  2009 Dirk Schulze <krit@webkit.org>
    77    Copyright (C) Research In Motion Limited 2010. All rights reserved.
     8                  2009 Jeff Schiller <codedread@gmail.com>
    89
    910    This library is free software; you can redistribute it and/or
     
    132133{
    133134    context->beginPath();
    134 
    135     if (RenderSVGResource* fillPaintingResource = RenderSVGResource::fillPaintingResource(object, object->style())) {
     135    RenderStyle* style = object->style();
     136
     137    if (RenderSVGResource* fillPaintingResource = RenderSVGResource::fillPaintingResource(object, style)) {
    136138        context->addPath(path);
    137         if (fillPaintingResource->applyResource(object, object->style(), context, ApplyToFillMode))
     139        if (fillPaintingResource->applyResource(object, style, context, ApplyToFillMode))
    138140            fillPaintingResource->postApplyResource(object, context, ApplyToFillMode);
    139141    }
    140142
    141     if (RenderSVGResource* strokePaintingResource = RenderSVGResource::strokePaintingResource(object, object->style())) {
    142         context->addPath(path);
    143         if (strokePaintingResource->applyResource(object, object->style(), context, ApplyToStrokeMode))
     143    if (RenderSVGResource* strokePaintingResource = RenderSVGResource::strokePaintingResource(object, style)) {
     144        if (style->svgStyle()->vectorEffect() == VE_NON_SCALING_STROKE) {
     145            SVGStyledTransformableElement* element = static_cast<SVGStyledTransformableElement*>(object->node());
     146            AffineTransform transform = element->getScreenCTM();
     147            if (!transform.isInvertible())
     148                return;
     149
     150            Path transformedPath = path;
     151            context->concatCTM(transform.inverse());
     152            transformedPath.transform(transform);
     153            context->addPath(transformedPath);
     154        } else
     155            context->addPath(path);
     156        if (strokePaintingResource->applyResource(object, style, context, ApplyToStrokeMode))
    144157            strokePaintingResource->postApplyResource(object, context, ApplyToStrokeMode);
    145158    }
  • trunk/WebCore/rendering/RenderSVGResourceContainer.h

    r58212 r60858  
    2424#if ENABLE(SVG)
    2525#include "RenderSVGHiddenContainer.h"
     26
     27#include "SVGStyledTransformableElement.h"
    2628#include "RenderSVGResource.h"
    2729
     
    8183
    8284    virtual RenderSVGResourceContainer* toRenderSVGResourceContainer() { return this; }
     85   
     86    static AffineTransform transformOnNonScalingStroke(RenderObject* object, const AffineTransform resourceTransform)
     87    {
     88        if (!object->isRenderPath())
     89            return resourceTransform;
     90
     91        SVGStyledTransformableElement* element = static_cast<SVGStyledTransformableElement*>(object->node());
     92        AffineTransform transform = resourceTransform;
     93        transform.multiply(element->getScreenCTM());
     94        return transform;
     95    }
    8396
    8497private:
  • trunk/WebCore/rendering/RenderSVGResourceGradient.cpp

    r60760 r60858  
    208208        context->setFillRule(svgStyle->fillRule());
    209209    } else if (resourceMode & ApplyToStrokeMode) {
     210        if (svgStyle->vectorEffect() == VE_NON_SCALING_STROKE)
     211            gradientData->gradient->setGradientSpaceTransform(transformOnNonScalingStroke(object, gradientData->userspaceTransform));
    210212        context->setAlpha(svgStyle->strokeOpacity());
    211213        context->setStrokeGradient(gradientData->gradient);
  • trunk/WebCore/rendering/RenderSVGResourcePattern.cpp

    r60760 r60858  
    117117        context->setFillRule(svgStyle->fillRule());
    118118    } else if (resourceMode & ApplyToStrokeMode) {
     119        if (svgStyle->vectorEffect() == VE_NON_SCALING_STROKE)
     120            patternData->pattern->setPatternSpaceTransform(transformOnNonScalingStroke(object, patternData->transform));
    119121        context->setAlpha(svgStyle->strokeOpacity());
    120122        context->setStrokePattern(patternData->pattern);
  • trunk/WebCore/rendering/style/SVGRenderStyle.h

    r60541 r60858  
    5959    SVG_RS_DEFINE_ATTRIBUTE(EDominantBaseline, DominantBaseline, dominantBaseline, DB_AUTO)
    6060    SVG_RS_DEFINE_ATTRIBUTE(EBaselineShift, BaselineShift, baselineShift, BS_BASELINE)
     61    SVG_RS_DEFINE_ATTRIBUTE(EVectorEffect, VectorEffect, vectorEffect, VE_NONE)
    6162
    6263    SVG_RS_DEFINE_ATTRIBUTE_INHERITED(LineCap, CapStyle, capStyle, ButtCap)
     
    169170                unsigned _dominantBaseline : 4; // EDominantBaseline
    170171                unsigned _baselineShift : 2; // EBaselineShift
    171                 // 22 bits unused
     172                unsigned _vectorEffect: 1; // EVectorEffect
     173                // 21 bits unused
    172174            } f;
    173175            uint32_t _niflags;
     
    214216        svg_noninherited_flags.f._dominantBaseline = initialDominantBaseline();
    215217        svg_noninherited_flags.f._baselineShift = initialBaselineShift();
     218        svg_noninherited_flags.f._vectorEffect = initialVectorEffect();
    216219    }
    217220};
  • trunk/WebCore/rendering/style/SVGRenderStyleDefs.h

    r57575 r60858  
    122122        DB_CENTRAL, DB_MIDDLE, DB_TEXT_AFTER_EDGE, DB_TEXT_BEFORE_EDGE
    123123    };
     124   
     125    enum EVectorEffect {
     126        VE_NONE,
     127        VE_NON_SCALING_STROKE
     128    };
    124129
    125130    class CSSValue;
  • trunk/WebCore/svg/SVGLocatable.cpp

    r56905 r60858  
    9292
    9393    SVGElement* stopAtElement = mode == NearestViewportScope ? nearestViewportElement(element) : 0;
    94     for (const Node* current = element; current && current->isSVGElement(); current = current->parentNode()) {
    95         const SVGElement* currentElement = static_cast<const SVGElement*>(current);
     94
     95    Node* current = const_cast<SVGElement*>(element);
     96    while (current && current->isSVGElement()) {
     97        SVGElement* currentElement = static_cast<SVGElement*>(current);
    9698        if (currentElement->isStyled())
    97             ctm = static_cast<const SVGStyledElement*>(currentElement)->localCoordinateSpaceTransform(mode).multLeft(ctm);
     99            ctm = static_cast<SVGStyledElement*>(currentElement)->localCoordinateSpaceTransform(mode).multLeft(ctm);
    98100
    99101        // For getCTM() computation, stop at the nearest viewport element
    100102        if (currentElement == stopAtElement)
    101103            break;
     104
     105        current = current->isShadowNode() ? current->shadowParentNode() : current->parentNode();
    102106    }
    103107
  • trunk/WebCore/svg/SVGStyledElement.cpp

    r59773 r60858  
    186186        mapAttributeToCSSProperty(propertyNameToIdMap, text_renderingAttr);
    187187        mapAttributeToCSSProperty(propertyNameToIdMap, unicode_bidiAttr);
     188        mapAttributeToCSSProperty(propertyNameToIdMap, vector_effectAttr);
    188189        mapAttributeToCSSProperty(propertyNameToIdMap, visibilityAttr);
    189190        mapAttributeToCSSProperty(propertyNameToIdMap, word_spacingAttr);
  • trunk/WebCore/svg/svgattrs.in

    r53879 r60858  
    229229v-mathematical
    230230values
     231vector-effect
    231232version
    232233vert-adv-y
Note: See TracChangeset for help on using the changeset viewer.