Changeset 36737 in webkit


Ignore:
Timestamp:
Sep 21, 2008 3:37:37 AM (16 years ago)
Author:
eric@webkit.org
Message:

2008-09-21 Dirk Schulze <vbs85@gmx.de>

Reviewed by eseidel. Landed by eseidel.

All platforms use the DashArray in the GraphicsContext.

  • svg/graphics/SVGPaintServer.h:
  • svg/graphics/cairo/SVGPaintServerGradientCairo.cpp: (WebCore::SVGPaintServerGradient::setup):
  • svg/graphics/cairo/SVGPaintServerPatternCairo.cpp: (WebCore::SVGPaintServerPattern::setup):
  • svg/graphics/cairo/SVGPaintServerSolidCairo.cpp: (WebCore::SVGPaintServerSolid::setup):
  • svg/graphics/qt/SVGPaintServerGradientQt.cpp: (WebCore::SVGPaintServerGradient::setup):
  • svg/graphics/qt/SVGPaintServerQt.cpp:
  • svg/graphics/qt/SVGPaintServerSolidQt.cpp: (WebCore::SVGPaintServerSolid::setup):
Location:
trunk/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r36734 r36737  
     12008-09-21  Dirk Schulze  <vbs85@gmx.de>
     2
     3        Reviewed by eseidel.  Landed by eseidel.
     4
     5        All platforms use the DashArray in the GraphicsContext.
     6
     7        * svg/graphics/SVGPaintServer.h:
     8        * svg/graphics/cairo/SVGPaintServerGradientCairo.cpp:
     9        (WebCore::SVGPaintServerGradient::setup):
     10        * svg/graphics/cairo/SVGPaintServerPatternCairo.cpp:
     11        (WebCore::SVGPaintServerPattern::setup):
     12        * svg/graphics/cairo/SVGPaintServerSolidCairo.cpp:
     13        (WebCore::SVGPaintServerSolid::setup):
     14        * svg/graphics/qt/SVGPaintServerGradientQt.cpp:
     15        (WebCore::SVGPaintServerGradient::setup):
     16        * svg/graphics/qt/SVGPaintServerQt.cpp:
     17        * svg/graphics/qt/SVGPaintServerSolidQt.cpp:
     18        (WebCore::SVGPaintServerSolid::setup):
     19
    1202008-09-21  Dirk Schulze  <vbs85@gmx.de>
    221
  • trunk/WebCore/svg/graphics/SVGPaintServer.h

    r36734 r36737  
    3434#if PLATFORM(CG)
    3535#include <ApplicationServices/ApplicationServices.h>
    36 #endif
    37 
    38 #if PLATFORM(QT)
    39 #include <qglobal.h>
    40 QT_BEGIN_NAMESPACE
    41 class QPen;
    42 QT_END_NAMESPACE
    4336#endif
    4437
     
    9285#endif
    9386
    94 #if PLATFORM(QT)
    95         void setPenProperties(const RenderObject*, const RenderStyle*, QPen&) const;
    96 #endif
    9787    protected:
    9888        SVGPaintServer();       
  • trunk/WebCore/svg/graphics/cairo/SVGPaintServerGradientCairo.cpp

    r35391 r36737  
    3131#include "RenderStyle.h"
    3232#include "SVGGradientElement.h"
    33 #include <wtf/OwnArrayPtr.h>
    3433
    3534namespace WebCore {
    36 
    37 // TODO: Share this code with all SVGPaintServers
    38 static void applyStrokeStyleToContext(GraphicsContext* context, const SVGRenderStyle* style, const RenderObject* object)
    39 {
    40     cairo_t* cr = context->platformContext();
    41 
    42     context->setStrokeThickness(SVGRenderStyle::cssPrimitiveToLength(object, style->strokeWidth(), 1.0));
    43     context->setLineCap(style->capStyle());
    44     context->setLineJoin(style->joinStyle());
    45     if (style->joinStyle() == MiterJoin)
    46         context->setMiterLimit(style->strokeMiterLimit());
    47 
    48     const DashArray& dashes = dashArrayFromRenderingStyle(object->style());
    49     OwnArrayPtr<double> dsh(new double[dashes.size()]);
    50     for (size_t i = 0 ; i < dashes.size() ; i++)
    51         dsh[i] = dashes[i];
    52     double dashOffset = SVGRenderStyle::cssPrimitiveToLength(object, style->strokeDashOffset(), 0.0);
    53     cairo_set_dash(cr, dsh.get(), dashes.size(), dashOffset);
    54 }
    5535
    5636bool SVGPaintServerGradient::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const
     
    6444    cairo_matrix_init_identity (&matrix);
    6545    const cairo_matrix_t gradient_matrix = gradientTransform();
    66     const SVGRenderStyle* style = object->style()->svgStyle();
     46
     47    const SVGRenderStyle* svgStyle = object->style()->svgStyle();
     48    RenderStyle* style = object->style();
    6749
    6850    if (this->type() == LinearGradientPaintServer) {
     
    162144    }
    163145
    164     if ((type & ApplyToFillTargetType) && style->hasFill())
    165         cairo_set_fill_rule(cr, style->fillRule() == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
     146    if ((type & ApplyToFillTargetType) && svgStyle->hasFill())
     147        context->setFillRule(svgStyle->fillRule());
    166148
    167     if ((type & ApplyToStrokeTargetType) && style->hasStroke())
     149    if ((type & ApplyToStrokeTargetType) && svgStyle->hasStroke())
    168150        applyStrokeStyleToContext(context, style, object);
    169151
  • trunk/WebCore/svg/graphics/cairo/SVGPaintServerPatternCairo.cpp

    r35731 r36737  
    3434namespace WebCore {
    3535
    36 // TODO: Share this code with all SVGPaintServers
    37 static void applyStrokeStyleToContext(GraphicsContext* context, const SVGRenderStyle* style, const RenderObject* object)
    38 {
    39     cairo_t* cr = context->platformContext();
    40 
    41     context->setStrokeThickness(SVGRenderStyle::cssPrimitiveToLength(object, style->strokeWidth(), 1.0));
    42     context->setLineCap(style->capStyle());
    43     context->setLineJoin(style->joinStyle());
    44     if (style->joinStyle() == MiterJoin)
    45         context->setMiterLimit(style->strokeMiterLimit());
    46 
    47     const DashArray& dashes = dashArrayFromRenderingStyle(object->style());
    48     OwnArrayPtr<double> dsh(new double[dashes.size()]);
    49     for (size_t i = 0; i < dashes.size() ; i++)
    50         dsh[i] = dashes[i];
    51     double dashOffset = SVGRenderStyle::cssPrimitiveToLength(object, style->strokeDashOffset(), 0.0);
    52     cairo_set_dash(cr, dsh.get(), dashes.size(), dashOffset);
    53 }
    54 
    5536bool SVGPaintServerPattern::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const
    5637{
    5738    FloatRect targetRect = object->relativeBBox(false);
    5839
    59     const SVGRenderStyle* style = object->style()->svgStyle();
     40    const SVGRenderStyle* svgStyle = object->style()->svgStyle();
     41    RenderStyle* style = object->style();
    6042
    61     float strokeWidth = SVGRenderStyle::cssPrimitiveToLength(object, style->strokeWidth(), 1.0);
     43    float strokeWidth = SVGRenderStyle::cssPrimitiveToLength(object, svgStyle->strokeWidth(), 1.0f);
    6244
    6345    if (targetRect.width() == 0)
     
    8466    cairo_pattern_set_matrix(pattern, &matrix);
    8567
    86     if ((type & ApplyToFillTargetType) && style->hasFill())
    87         cairo_set_fill_rule(cr, style->fillRule() == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
     68    if ((type & ApplyToFillTargetType) && svgStyle->hasFill())
     69        context->setFillRule(svgStyle->fillRule());
    8870
    89     if ((type & ApplyToStrokeTargetType) && style->hasStroke())
     71    if ((type & ApplyToStrokeTargetType) && svgStyle->hasStroke())
    9072        applyStrokeStyleToContext(context, style, object);
    9173
  • trunk/WebCore/svg/graphics/cairo/SVGPaintServerSolidCairo.cpp

    r29663 r36737  
    3232{
    3333    // TODO: share this code with other PaintServers
     34    cairo_t* cr = context->platformContext();
    3435
    35     cairo_t* cr = context->platformContext();
    36     const SVGRenderStyle* style = object->style()->svgStyle();
     36    const SVGRenderStyle* svgStyle = object->style()->svgStyle();
     37    RenderStyle* style = object->style();
    3738
    3839    float red, green, blue, alpha;
    3940    color().getRGBA(red, green, blue, alpha);
    4041
    41     if ((type & ApplyToFillTargetType) && style->hasFill()) {
    42         alpha = style->fillOpacity();
    43 
    44         cairo_set_fill_rule(cr, style->fillRule() == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
     42    if ((type & ApplyToFillTargetType) && svgStyle->hasFill()) {
     43        alpha = svgStyle->fillOpacity();
     44        context->setFillRule(svgStyle->fillRule());
    4545    }
    4646
    47     if ((type & ApplyToStrokeTargetType) && style->hasStroke()) {
    48         alpha = style->strokeOpacity();
    49 
    50         cairo_set_line_width(cr, SVGRenderStyle::cssPrimitiveToLength(object, style->strokeWidth(), 1.0));
    51         context->setLineCap(style->capStyle());
    52         context->setLineJoin(style->joinStyle());
    53         if (style->joinStyle() == MiterJoin)
    54             context->setMiterLimit(style->strokeMiterLimit());
    55 
    56         const DashArray& dashes = dashArrayFromRenderingStyle(object->style());
    57         double* dsh = new double[dashes.size()];
    58         for (unsigned i = 0 ; i < dashes.size() ; i++)
    59             dsh[i] = dashes[i];
    60         double dashOffset = SVGRenderStyle::cssPrimitiveToLength(object, style->strokeDashOffset(), 0.0);
    61         cairo_set_dash(cr, dsh, dashes.size(), dashOffset);
    62         delete[] dsh;
     47    if ((type & ApplyToStrokeTargetType) && svgStyle->hasStroke()) {
     48        alpha = svgStyle->strokeOpacity();
     49        applyStrokeStyleToContext(context, style, object);
    6350    }
    6451
  • trunk/WebCore/svg/graphics/qt/SVGPaintServerGradientQt.cpp

    r29663 r36737  
    6363    Q_ASSERT(path);
    6464
    65     RenderStyle* renderStyle = object->style();
     65    const SVGRenderStyle* svgStyle = object->style()->svgStyle();
     66    RenderStyle* style = object->style();
    6667
    6768    QGradient gradient = setupGradient(context, object);
     
    7879    double opacity = 1.0;
    7980
    80     if ((type & ApplyToFillTargetType) && renderStyle->svgStyle()->hasFill()) {
     81    if ((type & ApplyToFillTargetType) && svgStyle->hasFill()) {
    8182        fillColorArray(gradient, gradientStops(), opacity);
    8283
     
    8586
    8687        painter->setBrush(brush);
    87         context->setFillRule(renderStyle->svgStyle()->fillRule());
     88        context->setFillRule(svgStyle->fillRule());
    8889    }
    8990
    90     if ((type & ApplyToStrokeTargetType) && renderStyle->svgStyle()->hasStroke()) {
     91    if ((type & ApplyToStrokeTargetType) && svgStyle->hasStroke()) {
    9192        fillColorArray(gradient, gradientStops(), opacity);
    9293
     
    9495        QBrush brush(gradient);
    9596        brush.setMatrix(gradientTransform());
     97        pen.setBrush(brush);
     98        painter->setPen(pen);
    9699
    97         setPenProperties(object, renderStyle, pen);
    98         pen.setBrush(brush);
    99 
    100         painter->setPen(pen);
     100        applyStrokeStyleToContext(context, style, object);
    101101    }
    102102
  • trunk/WebCore/svg/graphics/qt/SVGPaintServerQt.cpp

    r35992 r36737  
    3434
    3535namespace WebCore {
    36 
    37 void SVGPaintServer::setPenProperties(const RenderObject* object, const RenderStyle* style, QPen& pen) const
    38 {
    39     pen.setWidthF(SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeWidth(), 1.0));
    40 
    41     if (style->svgStyle()->capStyle() == ButtCap)
    42         pen.setCapStyle(Qt::FlatCap);
    43     else if (style->svgStyle()->capStyle() == RoundCap)
    44         pen.setCapStyle(Qt::RoundCap);
    45 
    46     if (style->svgStyle()->joinStyle() == MiterJoin) {
    47         pen.setJoinStyle(Qt::MiterJoin);
    48         pen.setMiterLimit((qreal) style->svgStyle()->strokeMiterLimit());
    49     } else if(style->svgStyle()->joinStyle() == RoundJoin)
    50         pen.setJoinStyle(Qt::RoundJoin);
    51 
    52     const DashArray& dashes = WebCore::dashArrayFromRenderingStyle(style);
    53     double dashOffset = SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeDashOffset(), 0.0);
    54 
    55     unsigned int dashLength = !dashes.isEmpty() ? dashes.size() : 0;
    56     if(dashLength) {
    57         QVector<qreal> pattern;
    58         unsigned int count = (dashLength % 2) == 0 ? dashLength : dashLength * 2;
    59 
    60         for(unsigned int i = 0; i < count; i++)
    61             pattern.append(dashes[i % dashLength] / (float)pen.widthF());
    62 
    63         pen.setDashPattern(pattern);
    64 
    65         Q_UNUSED(dashOffset);
    66         // TODO: dash-offset, does/will qt4 API allow it? (Rob)
    67     }
    68 }
    6936
    7037void SVGPaintServer::draw(GraphicsContext*& context, const RenderObject* path, SVGPaintTargetType type) const
  • trunk/WebCore/svg/graphics/qt/SVGPaintServerSolidQt.cpp

    r35992 r36737  
    3838    Q_ASSERT(painter);
    3939
    40     RenderStyle* renderStyle = object ? object->style() : 0;
     40    const SVGRenderStyle* svgStyle = object->style()->svgStyle();
     41    RenderStyle* style = object ? object->style() : 0;
    4142    // TODO? painter->setOpacity(renderStyle->opacity());
    4243
    4344    QColor c = color();
    4445
    45     if ((type & ApplyToFillTargetType) && (!renderStyle || renderStyle->svgStyle()->hasFill())) {
    46         if (renderStyle)
    47             c.setAlphaF(renderStyle->svgStyle()->fillOpacity());
     46    if ((type & ApplyToFillTargetType) && (!style || svgStyle->hasFill())) {
     47        if (style)
     48            c.setAlphaF(svgStyle->fillOpacity());
    4849
    4950        QBrush brush(c);
    5051        painter->setBrush(brush);
    5152
    52         if (renderStyle)
    53             context->setFillRule(renderStyle->svgStyle()->fillRule());
     53        if (style)
     54            context->setFillRule(svgStyle->fillRule());
    5455
    5556        /* if(isPaintingText()) ... */
    5657    }
    5758
    58     if ((type & ApplyToStrokeTargetType) && (!renderStyle || renderStyle->svgStyle()->hasStroke())) {
    59         if (renderStyle)
    60             c.setAlphaF(renderStyle->svgStyle()->strokeOpacity());
     59    if ((type & ApplyToStrokeTargetType) && (!style || svgStyle->hasStroke())) {
     60        if (style)
     61            c.setAlphaF(svgStyle->strokeOpacity());
    6162
    6263        QPen pen(c);
    63         if (renderStyle)
    64             setPenProperties(object, renderStyle, pen);
    6564        painter->setPen(pen);
     65        if (style)
     66            applyStrokeStyleToContext(context, style, object);
    6667
    6768        /* if(isPaintingText()) ... */
Note: See TracChangeset for help on using the changeset viewer.