| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright 2015 Google Inc. | 2  * Copyright 2015 Google Inc. | 
| 3  * | 3  * | 
| 4  * Use of this source code is governed by a BSD-style license that can be | 4  * Use of this source code is governed by a BSD-style license that can be | 
| 5  * found in the LICENSE file. | 5  * found in the LICENSE file. | 
| 6  */ | 6  */ | 
| 7 | 7 | 
| 8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" | 
| 9 #include "SkData.h" | 9 #include "SkData.h" | 
| 10 #include "SkDOM.h" | 10 #include "SkDOM.h" | 
| 11 #include "SkParse.h" | 11 #include "SkParse.h" | 
| 12 #include "SkStream.h" | 12 #include "SkStream.h" | 
| 13 #include "SkSVGCanvas.h" | 13 #include "SkSVGCanvas.h" | 
| 14 #include "SkXMLWriter.h" | 14 #include "SkXMLWriter.h" | 
| 15 #include "Test.h" | 15 #include "Test.h" | 
| 16 | 16 | 
| 17 #include <string.h> | 17 #include <string.h> | 
| 18 | 18 | 
| 19 namespace { | 19 namespace { | 
| 20 | 20 | 
| 21 void check_text_node(skiatest::Reporter* reporter, | 21 void check_text_node(skiatest::Reporter* reporter, | 
| 22                      const SkDOM& dom, | 22                      const SkDOM& dom, | 
| 23                      const SkDOM::Node* root, | 23                      const SkDOM::Node* root, | 
| 24                      const SkPoint& offset, | 24                      const SkPoint& offset, | 
| 25                      unsigned scalarsPerPos, | 25                      unsigned scalarsPerPos, | 
| 26                      const char* expected) { | 26                      const char* expected) { | 
| 27     if (root == NULL) { | 27     if (root == nullptr) { | 
| 28         ERRORF(reporter, "root element not found."); | 28         ERRORF(reporter, "root element not found."); | 
| 29         return; | 29         return; | 
| 30     } | 30     } | 
| 31 | 31 | 
| 32     const SkDOM::Node* textElem = dom.getFirstChild(root, "text"); | 32     const SkDOM::Node* textElem = dom.getFirstChild(root, "text"); | 
| 33     if (textElem == NULL) { | 33     if (textElem == nullptr) { | 
| 34         ERRORF(reporter, "<text> element not found."); | 34         ERRORF(reporter, "<text> element not found."); | 
| 35         return; | 35         return; | 
| 36     } | 36     } | 
| 37     REPORTER_ASSERT(reporter, dom.getType(textElem) == SkDOM::kElement_Type); | 37     REPORTER_ASSERT(reporter, dom.getType(textElem) == SkDOM::kElement_Type); | 
| 38 | 38 | 
| 39     const SkDOM::Node* textNode= dom.getFirstChild(textElem); | 39     const SkDOM::Node* textNode= dom.getFirstChild(textElem); | 
| 40     REPORTER_ASSERT(reporter, textNode != NULL); | 40     REPORTER_ASSERT(reporter, textNode != nullptr); | 
| 41     if (textNode != NULL) { | 41     if (textNode != nullptr) { | 
| 42         REPORTER_ASSERT(reporter, dom.getType(textNode) == SkDOM::kText_Type); | 42         REPORTER_ASSERT(reporter, dom.getType(textNode) == SkDOM::kText_Type); | 
| 43         REPORTER_ASSERT(reporter, strcmp(expected, dom.getName(textNode)) == 0); | 43         REPORTER_ASSERT(reporter, strcmp(expected, dom.getName(textNode)) == 0); | 
| 44     } | 44     } | 
| 45 | 45 | 
| 46     int textLen = SkToInt(strlen(expected)); | 46     int textLen = SkToInt(strlen(expected)); | 
| 47 | 47 | 
| 48     const char* x = dom.findAttr(textElem, "x"); | 48     const char* x = dom.findAttr(textElem, "x"); | 
| 49     REPORTER_ASSERT(reporter, x != NULL); | 49     REPORTER_ASSERT(reporter, x != nullptr); | 
| 50     if (x != NULL) { | 50     if (x != nullptr) { | 
| 51         int xposCount = (scalarsPerPos < 1) ? 1 : textLen; | 51         int xposCount = (scalarsPerPos < 1) ? 1 : textLen; | 
| 52         REPORTER_ASSERT(reporter, SkParse::Count(x) == xposCount); | 52         REPORTER_ASSERT(reporter, SkParse::Count(x) == xposCount); | 
| 53 | 53 | 
| 54         SkAutoTMalloc<SkScalar> xpos(xposCount); | 54         SkAutoTMalloc<SkScalar> xpos(xposCount); | 
| 55         SkParse::FindScalars(x, xpos.get(), xposCount); | 55         SkParse::FindScalars(x, xpos.get(), xposCount); | 
| 56         if (scalarsPerPos < 1) { | 56         if (scalarsPerPos < 1) { | 
| 57             REPORTER_ASSERT(reporter, xpos[0] == offset.x()); | 57             REPORTER_ASSERT(reporter, xpos[0] == offset.x()); | 
| 58         } else { | 58         } else { | 
| 59             for (int i = 0; i < xposCount; ++i) { | 59             for (int i = 0; i < xposCount; ++i) { | 
| 60                 REPORTER_ASSERT(reporter, xpos[i] == SkIntToScalar(expected[i]))
     ; | 60                 REPORTER_ASSERT(reporter, xpos[i] == SkIntToScalar(expected[i]))
     ; | 
| 61             } | 61             } | 
| 62         } | 62         } | 
| 63     } | 63     } | 
| 64 | 64 | 
| 65     const char* y = dom.findAttr(textElem, "y"); | 65     const char* y = dom.findAttr(textElem, "y"); | 
| 66     REPORTER_ASSERT(reporter, y != NULL); | 66     REPORTER_ASSERT(reporter, y != nullptr); | 
| 67     if (y != NULL) { | 67     if (y != nullptr) { | 
| 68         int yposCount = (scalarsPerPos < 2) ? 1 : textLen; | 68         int yposCount = (scalarsPerPos < 2) ? 1 : textLen; | 
| 69         REPORTER_ASSERT(reporter, SkParse::Count(y) == yposCount); | 69         REPORTER_ASSERT(reporter, SkParse::Count(y) == yposCount); | 
| 70 | 70 | 
| 71         SkAutoTMalloc<SkScalar> ypos(yposCount); | 71         SkAutoTMalloc<SkScalar> ypos(yposCount); | 
| 72         SkParse::FindScalars(y, ypos.get(), yposCount); | 72         SkParse::FindScalars(y, ypos.get(), yposCount); | 
| 73         if (scalarsPerPos < 2) { | 73         if (scalarsPerPos < 2) { | 
| 74             REPORTER_ASSERT(reporter, ypos[0] == offset.y()); | 74             REPORTER_ASSERT(reporter, ypos[0] == offset.y()); | 
| 75         } else { | 75         } else { | 
| 76             for (int i = 0; i < yposCount; ++i) { | 76             for (int i = 0; i < yposCount; ++i) { | 
| 77                 REPORTER_ASSERT(reporter, ypos[i] == -SkIntToScalar(expected[i])
     ); | 77                 REPORTER_ASSERT(reporter, ypos[i] == -SkIntToScalar(expected[i])
     ); | 
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 140         { "abcd "     , "abcd " }, // we allow one trailing whitespace char | 140         { "abcd "     , "abcd " }, // we allow one trailing whitespace char | 
| 141         { "abcd  "    , "abcd " }, // because it makes no difference and | 141         { "abcd  "    , "abcd " }, // because it makes no difference and | 
| 142         { "abcd\t  "  , "abcd\t" }, // simplifies the implementation | 142         { "abcd\t  "  , "abcd\t" }, // simplifies the implementation | 
| 143         { "\t\t  \t ab \t\t  \t cd \t\t   \t  ", "ab cd " }, | 143         { "\t\t  \t ab \t\t  \t cd \t\t   \t  ", "ab cd " }, | 
| 144     }; | 144     }; | 
| 145 | 145 | 
| 146     for (unsigned i = 0; i < SK_ARRAY_COUNT(tests); ++i) { | 146     for (unsigned i = 0; i < SK_ARRAY_COUNT(tests); ++i) { | 
| 147         test_whitespace_pos(reporter, tests[i].tst_in, tests[i].tst_out); | 147         test_whitespace_pos(reporter, tests[i].tst_in, tests[i].tst_out); | 
| 148     } | 148     } | 
| 149 } | 149 } | 
| OLD | NEW | 
|---|