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