reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* libs/graphics/svg/SkSVGSVG.cpp |
| 2 | ** |
| 3 | ** Copyright 2006, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include "SkSVGSVG.h" |
| 19 | #include "SkParse.h" |
| 20 | #include "SkRect.h" |
| 21 | #include "SkSVGParser.h" |
| 22 | |
| 23 | const SkSVGAttribute SkSVGSVG::gAttributes[] = { |
| 24 | SVG_LITERAL_ATTRIBUTE(enable-background, f_enable_background), |
| 25 | SVG_ATTRIBUTE(height), |
| 26 | SVG_ATTRIBUTE(overflow), |
| 27 | SVG_ATTRIBUTE(width), |
| 28 | SVG_ATTRIBUTE(version), |
| 29 | SVG_ATTRIBUTE(viewBox), |
reed@android.com | 5ee64ad | 2010-05-17 14:34:13 +0000 | [diff] [blame^] | 30 | SVG_ATTRIBUTE(x), |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 31 | SVG_LITERAL_ATTRIBUTE(xml:space, f_xml_space), |
| 32 | SVG_ATTRIBUTE(xmlns), |
reed@android.com | 5ee64ad | 2010-05-17 14:34:13 +0000 | [diff] [blame^] | 33 | SVG_LITERAL_ATTRIBUTE(xmlns:xlink, f_xml_xlink), |
| 34 | SVG_ATTRIBUTE(y), |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | DEFINE_SVG_INFO(SVG) |
| 38 | |
| 39 | |
| 40 | bool SkSVGSVG::isFlushable() { |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | void SkSVGSVG::translate(SkSVGParser& parser, bool defState) { |
| 45 | SkScalar height, width; |
| 46 | SkScalar viewBox[4]; |
| 47 | const char* hSuffix = SkParse::FindScalar(f_height.c_str(), &height); |
| 48 | if (strcmp(hSuffix, "pt") == 0) |
| 49 | height = SkScalarMulDiv(height, SK_Scalar1 * 72, SK_Scalar1 * 96); |
| 50 | const char* wSuffix = SkParse::FindScalar(f_width.c_str(), &width); |
| 51 | if (strcmp(wSuffix, "pt") == 0) |
| 52 | width = SkScalarMulDiv(width, SK_Scalar1 * 72, SK_Scalar1 * 96); |
| 53 | SkParse::FindScalars(f_viewBox.c_str(), viewBox, 4); |
| 54 | SkRect box; |
| 55 | box.fLeft = SkScalarDiv(viewBox[0], width); |
| 56 | box.fTop = SkScalarDiv(viewBox[1], height); |
| 57 | box.fRight = SkScalarDiv(viewBox[2], width); |
| 58 | box.fBottom = SkScalarDiv(viewBox[3], height); |
| 59 | if (box.fLeft == 0 && box.fTop == 0 && |
| 60 | box.fRight == SK_Scalar1 && box.fBottom == SK_Scalar1) |
| 61 | return; |
| 62 | parser._startElement("matrix"); |
| 63 | if (box.fLeft != 0) { |
| 64 | SkString x; |
| 65 | x.appendScalar(box.fLeft); |
| 66 | parser._addAttributeLen("translateX", x.c_str(), x.size()); |
| 67 | } |
| 68 | if (box.fTop != 0) { |
| 69 | SkString y; |
| 70 | y.appendScalar(box.fTop); |
| 71 | parser._addAttributeLen("translateY", y.c_str(), y.size()); |
| 72 | } |
| 73 | if (box.fRight != SK_Scalar1) { |
| 74 | SkString x; |
| 75 | x.appendScalar(box.fRight); |
| 76 | parser._addAttributeLen("scaleX", x.c_str(), x.size()); |
| 77 | } |
| 78 | if (box.fBottom != SK_Scalar1) { |
| 79 | SkString y; |
| 80 | y.appendScalar(box.fBottom); |
| 81 | parser._addAttributeLen("scaleY", y.c_str(), y.size()); |
| 82 | } |
| 83 | parser._endElement(); |
| 84 | } |