Changeset 35390 in webkit


Ignore:
Timestamp:
Jul 26, 2008 10:38:28 PM (16 years ago)
Author:
mrowe@apple.com
Message:

2008-07-26 Dirk Schulze <vbs85@gmx.de>

Reviewed by Nikolas Zimmermann.

Added pattern-support for SVG in Cairo.

  • svg/graphics/cairo/SVGPaintServerPatternCairo.cpp: (WebCore::applyStrokeStyleToContext): (WebCore::SVGPaintServerPattern::setup):
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r35383 r35390  
     12008-07-26  Dirk Schulze  <vbs85@gmx.de>
     2
     3        Reviewed by Nikolas Zimmermann.
     4
     5        Added pattern-support for SVG in Cairo.
     6
     7        * svg/graphics/cairo/SVGPaintServerPatternCairo.cpp:
     8        (WebCore::applyStrokeStyleToContext):
     9        (WebCore::SVGPaintServerPattern::setup):
     10
    1112008-07-26  Keishi Hattori  <casey.hattori@gmail.com>
    212
  • trunk/WebCore/svg/graphics/cairo/SVGPaintServerPatternCairo.cpp

    r29663 r35390  
    11/*
    22 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
     3 * Copyright (C) 2008 Dirk Schulze <vbs85@gmx.de>
    34 *
    45 * This library is free software; you can redistribute it and/or
     
    2122
    2223#if ENABLE(SVG)
    23 #include "NotImplemented.h"
    2424#include "SVGPaintServerPattern.h"
     25
     26#include "GraphicsContext.h"
     27#include "ImageBuffer.h"
     28#include "RenderObject.h"
     29#include "SVGPatternElement.h"
     30#include <wtf/OwnArrayPtr.h>
    2531
    2632namespace WebCore {
    2733
     34// TODO: Share this code with all SVGPaintServers
     35static void applyStrokeStyleToContext(GraphicsContext* context, const SVGRenderStyle* style, const RenderObject* object)
     36{
     37    cairo_t* cr = context->platformContext();
     38
     39    context->setStrokeThickness(SVGRenderStyle::cssPrimitiveToLength(object, style->strokeWidth(), 1.0));
     40    context->setLineCap(style->capStyle());
     41    context->setLineJoin(style->joinStyle());
     42    if (style->joinStyle() == MiterJoin)
     43        context->setMiterLimit(style->strokeMiterLimit());
     44
     45    const DashArray& dashes = dashArrayFromRenderingStyle(object->style());
     46    OwnArrayPtr<double> dsh(new double[dashes.size()]);
     47    for (size_t i = 0; i < dashes.size() ; i++)
     48        dsh[i] = dashes[i];
     49    double dashOffset = SVGRenderStyle::cssPrimitiveToLength(object, style->strokeDashOffset(), 0.0);
     50    cairo_set_dash(cr, dsh.get(), dashes.size(), dashOffset);
     51}
     52
    2853bool SVGPaintServerPattern::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const
    2954{
    30     notImplemented();
     55    FloatRect targetRect = object->relativeBBox(false);
     56
     57    const SVGRenderStyle* style = object->style()->svgStyle();
     58
     59    float strokeWidth = SVGRenderStyle::cssPrimitiveToLength(object, style->strokeWidth(), 1.0);
     60
     61    if (targetRect.width() == 0)
     62        targetRect = FloatRect(targetRect.x(), targetRect.y(), strokeWidth, targetRect.height());
     63    if (targetRect.height() == 0)
     64        targetRect = FloatRect(targetRect.x(), targetRect.y(), targetRect.width(), strokeWidth);
     65
     66    m_ownerElement->buildPattern(targetRect);
     67
     68    cairo_surface_t* image = tile()->surface();
     69    if (!image)
     70        return false;
     71
     72    cairo_t* cr = context->platformContext();
     73
     74    cairo_pattern_t* pattern = cairo_pattern_create_for_surface(image);
     75    cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
     76
     77    cairo_pattern_set_filter(pattern, CAIRO_FILTER_BEST);
     78    cairo_matrix_t pattern_matrix = patternTransform();
     79    cairo_matrix_t matrix = {1, 0, 0, 1, patternBoundaries().x(), patternBoundaries().y()};
     80    cairo_matrix_multiply(&matrix, &matrix, &pattern_matrix);
     81    cairo_matrix_invert(&matrix);
     82    cairo_pattern_set_matrix(pattern, &matrix);
     83
     84    if ((type & ApplyToFillTargetType) && style->hasFill())
     85        cairo_set_fill_rule(cr, style->fillRule() == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
     86
     87    if ((type & ApplyToStrokeTargetType) && style->hasStroke())
     88        applyStrokeStyleToContext(context, style, object);
     89
     90    cairo_set_source(cr, pattern);
     91    cairo_pattern_destroy(pattern);
     92
    3193    return true;
    3294}
Note: See TracChangeset for help on using the changeset viewer.