gfx/skia/trunk/src/svg/SkSVGSVG.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/svg/SkSVGSVG.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,76 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2006 The Android Open Source Project
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +
    1.13 +#include "SkSVGSVG.h"
    1.14 +#include "SkParse.h"
    1.15 +#include "SkRect.h"
    1.16 +#include "SkSVGParser.h"
    1.17 +
    1.18 +const SkSVGAttribute SkSVGSVG::gAttributes[] = {
    1.19 +    SVG_LITERAL_ATTRIBUTE(enable-background, f_enable_background),
    1.20 +    SVG_ATTRIBUTE(height),
    1.21 +    SVG_ATTRIBUTE(overflow),
    1.22 +    SVG_ATTRIBUTE(width),
    1.23 +    SVG_ATTRIBUTE(version),
    1.24 +    SVG_ATTRIBUTE(viewBox),
    1.25 +    SVG_ATTRIBUTE(x),
    1.26 +    SVG_LITERAL_ATTRIBUTE(xml:space, f_xml_space),
    1.27 +    SVG_ATTRIBUTE(xmlns),
    1.28 +    SVG_LITERAL_ATTRIBUTE(xmlns:xlink, f_xml_xlink),
    1.29 +    SVG_ATTRIBUTE(y),
    1.30 +};
    1.31 +
    1.32 +DEFINE_SVG_INFO(SVG)
    1.33 +
    1.34 +
    1.35 +bool SkSVGSVG::isFlushable() {
    1.36 +    return false;
    1.37 +}
    1.38 +
    1.39 +void SkSVGSVG::translate(SkSVGParser& parser, bool defState) {
    1.40 +    SkScalar height, width;
    1.41 +    SkScalar viewBox[4];
    1.42 +    const char* hSuffix = SkParse::FindScalar(f_height.c_str(), &height);
    1.43 +    if (strcmp(hSuffix, "pt") == 0)
    1.44 +        height = SkScalarMulDiv(height, SK_Scalar1 * 72, SK_Scalar1 * 96);
    1.45 +    const char* wSuffix = SkParse::FindScalar(f_width.c_str(), &width);
    1.46 +    if (strcmp(wSuffix, "pt") == 0)
    1.47 +        width = SkScalarMulDiv(width, SK_Scalar1 * 72, SK_Scalar1 * 96);
    1.48 +    SkParse::FindScalars(f_viewBox.c_str(), viewBox, 4);
    1.49 +    SkRect box;
    1.50 +    box.fLeft = SkScalarDiv(viewBox[0], width);
    1.51 +    box.fTop = SkScalarDiv(viewBox[1], height);
    1.52 +    box.fRight = SkScalarDiv(viewBox[2], width);
    1.53 +    box.fBottom = SkScalarDiv(viewBox[3], height);
    1.54 +    if (box.fLeft == 0 && box.fTop == 0 &&
    1.55 +        box.fRight == SK_Scalar1 && box.fBottom == SK_Scalar1)
    1.56 +            return;
    1.57 +    parser._startElement("matrix");
    1.58 +    if (box.fLeft != 0) {
    1.59 +        SkString x;
    1.60 +        x.appendScalar(box.fLeft);
    1.61 +        parser._addAttributeLen("translateX", x.c_str(), x.size());
    1.62 +    }
    1.63 +    if (box.fTop != 0) {
    1.64 +        SkString y;
    1.65 +        y.appendScalar(box.fTop);
    1.66 +        parser._addAttributeLen("translateY", y.c_str(), y.size());
    1.67 +    }
    1.68 +    if (box.fRight != SK_Scalar1) {
    1.69 +        SkString x;
    1.70 +        x.appendScalar(box.fRight);
    1.71 +        parser._addAttributeLen("scaleX", x.c_str(), x.size());
    1.72 +    }
    1.73 +    if (box.fBottom != SK_Scalar1) {
    1.74 +        SkString y;
    1.75 +        y.appendScalar(box.fBottom);
    1.76 +        parser._addAttributeLen("scaleY", y.c_str(), y.size());
    1.77 +    }
    1.78 +    parser._endElement();
    1.79 +}

mercurial