michael@0: michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #include "SkSVGSVG.h" michael@0: #include "SkParse.h" michael@0: #include "SkRect.h" michael@0: #include "SkSVGParser.h" michael@0: michael@0: const SkSVGAttribute SkSVGSVG::gAttributes[] = { michael@0: SVG_LITERAL_ATTRIBUTE(enable-background, f_enable_background), michael@0: SVG_ATTRIBUTE(height), michael@0: SVG_ATTRIBUTE(overflow), michael@0: SVG_ATTRIBUTE(width), michael@0: SVG_ATTRIBUTE(version), michael@0: SVG_ATTRIBUTE(viewBox), michael@0: SVG_ATTRIBUTE(x), michael@0: SVG_LITERAL_ATTRIBUTE(xml:space, f_xml_space), michael@0: SVG_ATTRIBUTE(xmlns), michael@0: SVG_LITERAL_ATTRIBUTE(xmlns:xlink, f_xml_xlink), michael@0: SVG_ATTRIBUTE(y), michael@0: }; michael@0: michael@0: DEFINE_SVG_INFO(SVG) michael@0: michael@0: michael@0: bool SkSVGSVG::isFlushable() { michael@0: return false; michael@0: } michael@0: michael@0: void SkSVGSVG::translate(SkSVGParser& parser, bool defState) { michael@0: SkScalar height, width; michael@0: SkScalar viewBox[4]; michael@0: const char* hSuffix = SkParse::FindScalar(f_height.c_str(), &height); michael@0: if (strcmp(hSuffix, "pt") == 0) michael@0: height = SkScalarMulDiv(height, SK_Scalar1 * 72, SK_Scalar1 * 96); michael@0: const char* wSuffix = SkParse::FindScalar(f_width.c_str(), &width); michael@0: if (strcmp(wSuffix, "pt") == 0) michael@0: width = SkScalarMulDiv(width, SK_Scalar1 * 72, SK_Scalar1 * 96); michael@0: SkParse::FindScalars(f_viewBox.c_str(), viewBox, 4); michael@0: SkRect box; michael@0: box.fLeft = SkScalarDiv(viewBox[0], width); michael@0: box.fTop = SkScalarDiv(viewBox[1], height); michael@0: box.fRight = SkScalarDiv(viewBox[2], width); michael@0: box.fBottom = SkScalarDiv(viewBox[3], height); michael@0: if (box.fLeft == 0 && box.fTop == 0 && michael@0: box.fRight == SK_Scalar1 && box.fBottom == SK_Scalar1) michael@0: return; michael@0: parser._startElement("matrix"); michael@0: if (box.fLeft != 0) { michael@0: SkString x; michael@0: x.appendScalar(box.fLeft); michael@0: parser._addAttributeLen("translateX", x.c_str(), x.size()); michael@0: } michael@0: if (box.fTop != 0) { michael@0: SkString y; michael@0: y.appendScalar(box.fTop); michael@0: parser._addAttributeLen("translateY", y.c_str(), y.size()); michael@0: } michael@0: if (box.fRight != SK_Scalar1) { michael@0: SkString x; michael@0: x.appendScalar(box.fRight); michael@0: parser._addAttributeLen("scaleX", x.c_str(), x.size()); michael@0: } michael@0: if (box.fBottom != SK_Scalar1) { michael@0: SkString y; michael@0: y.appendScalar(box.fBottom); michael@0: parser._addAttributeLen("scaleY", y.c_str(), y.size()); michael@0: } michael@0: parser._endElement(); michael@0: }