1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/*
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project
4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com *
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */
8ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkSVGSVG.h"
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkParse.h"
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRect.h"
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkSVGParser.h"
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comconst SkSVGAttribute SkSVGSVG::gAttributes[] = {
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SVG_LITERAL_ATTRIBUTE(enable-background, f_enable_background),
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SVG_ATTRIBUTE(height),
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SVG_ATTRIBUTE(overflow),
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SVG_ATTRIBUTE(width),
208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SVG_ATTRIBUTE(version),
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SVG_ATTRIBUTE(viewBox),
225ee64ad6b54edc07849fa04681801802b7102590reed@android.com    SVG_ATTRIBUTE(x),
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SVG_LITERAL_ATTRIBUTE(xml:space, f_xml_space),
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SVG_ATTRIBUTE(xmlns),
255ee64ad6b54edc07849fa04681801802b7102590reed@android.com    SVG_LITERAL_ATTRIBUTE(xmlns:xlink, f_xml_xlink),
265ee64ad6b54edc07849fa04681801802b7102590reed@android.com    SVG_ATTRIBUTE(y),
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comDEFINE_SVG_INFO(SVG)
308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.combool SkSVGSVG::isFlushable() {
338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    return false;
348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkSVGSVG::translate(SkSVGParser& parser, bool defState) {
378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkScalar height, width;
388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkScalar viewBox[4];
398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    const char* hSuffix = SkParse::FindScalar(f_height.c_str(), &height);
408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (strcmp(hSuffix, "pt") == 0)
418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        height = SkScalarMulDiv(height, SK_Scalar1 * 72, SK_Scalar1 * 96);
428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    const char* wSuffix = SkParse::FindScalar(f_width.c_str(), &width);
438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (strcmp(wSuffix, "pt") == 0)
448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        width = SkScalarMulDiv(width, SK_Scalar1 * 72, SK_Scalar1 * 96);
458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkParse::FindScalars(f_viewBox.c_str(), viewBox, 4);
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkRect box;
478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    box.fLeft = SkScalarDiv(viewBox[0], width);
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    box.fTop = SkScalarDiv(viewBox[1], height);
498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    box.fRight = SkScalarDiv(viewBox[2], width);
508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    box.fBottom = SkScalarDiv(viewBox[3], height);
51d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    if (box.fLeft == 0 && box.fTop == 0 &&
52d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com        box.fRight == SK_Scalar1 && box.fBottom == SK_Scalar1)
538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            return;
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    parser._startElement("matrix");
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (box.fLeft != 0) {
568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkString x;
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        x.appendScalar(box.fLeft);
588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        parser._addAttributeLen("translateX", x.c_str(), x.size());
598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (box.fTop != 0) {
618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkString y;
628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        y.appendScalar(box.fTop);
638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        parser._addAttributeLen("translateY", y.c_str(), y.size());
648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (box.fRight != SK_Scalar1) {
668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkString x;
678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        x.appendScalar(box.fRight);
688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        parser._addAttributeLen("scaleX", x.c_str(), x.size());
698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    if (box.fBottom != SK_Scalar1) {
718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkString y;
728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        y.appendScalar(box.fBottom);
738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        parser._addAttributeLen("scaleY", y.c_str(), y.size());
748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
75d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    parser._endElement();
768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}
77