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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2006 The Android Open Source Project
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10 #include "SkSVGSVG.h"
michael@0 11 #include "SkParse.h"
michael@0 12 #include "SkRect.h"
michael@0 13 #include "SkSVGParser.h"
michael@0 14
michael@0 15 const SkSVGAttribute SkSVGSVG::gAttributes[] = {
michael@0 16 SVG_LITERAL_ATTRIBUTE(enable-background, f_enable_background),
michael@0 17 SVG_ATTRIBUTE(height),
michael@0 18 SVG_ATTRIBUTE(overflow),
michael@0 19 SVG_ATTRIBUTE(width),
michael@0 20 SVG_ATTRIBUTE(version),
michael@0 21 SVG_ATTRIBUTE(viewBox),
michael@0 22 SVG_ATTRIBUTE(x),
michael@0 23 SVG_LITERAL_ATTRIBUTE(xml:space, f_xml_space),
michael@0 24 SVG_ATTRIBUTE(xmlns),
michael@0 25 SVG_LITERAL_ATTRIBUTE(xmlns:xlink, f_xml_xlink),
michael@0 26 SVG_ATTRIBUTE(y),
michael@0 27 };
michael@0 28
michael@0 29 DEFINE_SVG_INFO(SVG)
michael@0 30
michael@0 31
michael@0 32 bool SkSVGSVG::isFlushable() {
michael@0 33 return false;
michael@0 34 }
michael@0 35
michael@0 36 void SkSVGSVG::translate(SkSVGParser& parser, bool defState) {
michael@0 37 SkScalar height, width;
michael@0 38 SkScalar viewBox[4];
michael@0 39 const char* hSuffix = SkParse::FindScalar(f_height.c_str(), &height);
michael@0 40 if (strcmp(hSuffix, "pt") == 0)
michael@0 41 height = SkScalarMulDiv(height, SK_Scalar1 * 72, SK_Scalar1 * 96);
michael@0 42 const char* wSuffix = SkParse::FindScalar(f_width.c_str(), &width);
michael@0 43 if (strcmp(wSuffix, "pt") == 0)
michael@0 44 width = SkScalarMulDiv(width, SK_Scalar1 * 72, SK_Scalar1 * 96);
michael@0 45 SkParse::FindScalars(f_viewBox.c_str(), viewBox, 4);
michael@0 46 SkRect box;
michael@0 47 box.fLeft = SkScalarDiv(viewBox[0], width);
michael@0 48 box.fTop = SkScalarDiv(viewBox[1], height);
michael@0 49 box.fRight = SkScalarDiv(viewBox[2], width);
michael@0 50 box.fBottom = SkScalarDiv(viewBox[3], height);
michael@0 51 if (box.fLeft == 0 && box.fTop == 0 &&
michael@0 52 box.fRight == SK_Scalar1 && box.fBottom == SK_Scalar1)
michael@0 53 return;
michael@0 54 parser._startElement("matrix");
michael@0 55 if (box.fLeft != 0) {
michael@0 56 SkString x;
michael@0 57 x.appendScalar(box.fLeft);
michael@0 58 parser._addAttributeLen("translateX", x.c_str(), x.size());
michael@0 59 }
michael@0 60 if (box.fTop != 0) {
michael@0 61 SkString y;
michael@0 62 y.appendScalar(box.fTop);
michael@0 63 parser._addAttributeLen("translateY", y.c_str(), y.size());
michael@0 64 }
michael@0 65 if (box.fRight != SK_Scalar1) {
michael@0 66 SkString x;
michael@0 67 x.appendScalar(box.fRight);
michael@0 68 parser._addAttributeLen("scaleX", x.c_str(), x.size());
michael@0 69 }
michael@0 70 if (box.fBottom != SK_Scalar1) {
michael@0 71 SkString y;
michael@0 72 y.appendScalar(box.fBottom);
michael@0 73 parser._addAttributeLen("scaleY", y.c_str(), y.size());
michael@0 74 }
michael@0 75 parser._endElement();
michael@0 76 }

mercurial