| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SampleCode.h" | 8 #include "SampleCode.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkDOM.h" | 10 #include "SkDOM.h" |
| 11 #include "SkOSFile.h" |
| 11 #include "SkStream.h" | 12 #include "SkStream.h" |
| 12 #include "SkSVGDOM.h" | 13 #include "SkSVGDOM.h" |
| 13 #include "SkView.h" | 14 #include "SkView.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 class SVGFileView : public SampleView { | 18 class SVGFileView : public SampleView { |
| 18 public: | 19 public: |
| 19 SVGFileView(const char path[]) { | 20 SVGFileView(const char path[]) |
| 21 : fLabel(SkStringPrintf("[%s]", SkOSPath::Basename(path).c_str())) { |
| 20 SkFILEStream svgStream(path); | 22 SkFILEStream svgStream(path); |
| 21 if (!svgStream.isValid()) { | 23 if (!svgStream.isValid()) { |
| 22 SkDebugf("file not found: \"path\"\n", path); | 24 SkDebugf("file not found: \"path\"\n", path); |
| 23 return; | 25 return; |
| 24 } | 26 } |
| 25 | 27 |
| 26 SkDOM xmlDom; | 28 SkDOM xmlDom; |
| 27 if (!xmlDom.build(svgStream)) { | 29 if (!xmlDom.build(svgStream)) { |
| 28 SkDebugf("XML parsing failed: \"path\"\n", path); | 30 SkDebugf("XML parsing failed: \"path\"\n", path); |
| 29 return; | 31 return; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 42 } | 44 } |
| 43 | 45 |
| 44 void onSizeChange() override { | 46 void onSizeChange() override { |
| 45 if (fDom) { | 47 if (fDom) { |
| 46 fDom->setContainerSize(SkSize::Make(this->width(), this->height())); | 48 fDom->setContainerSize(SkSize::Make(this->width(), this->height())); |
| 47 } | 49 } |
| 48 | 50 |
| 49 this->INHERITED::onSizeChange(); | 51 this->INHERITED::onSizeChange(); |
| 50 } | 52 } |
| 51 | 53 |
| 54 bool onQuery(SkEvent* evt) override { |
| 55 if (SampleCode::TitleQ(*evt)) { |
| 56 SampleCode::TitleR(evt, fLabel.c_str()); |
| 57 return true; |
| 58 } |
| 59 |
| 60 return this->INHERITED::onQuery(evt); |
| 61 } |
| 52 private: | 62 private: |
| 53 sk_sp<SkSVGDOM> fDom; | 63 sk_sp<SkSVGDOM> fDom; |
| 64 SkString fLabel; |
| 54 | 65 |
| 55 typedef SampleView INHERITED; | 66 typedef SampleView INHERITED; |
| 56 }; | 67 }; |
| 57 | 68 |
| 58 } // anonymous namespace | 69 } // anonymous namespace |
| 59 | 70 |
| 60 SampleView* CreateSampleSVGFileView(const char filename[]); | 71 SampleView* CreateSampleSVGFileView(const char filename[]); |
| 61 SampleView* CreateSampleSVGFileView(const char filename[]) { | 72 SampleView* CreateSampleSVGFileView(const char filename[]) { |
| 62 return new SVGFileView(filename); | 73 return new SVGFileView(filename); |
| 63 } | 74 } |
| OLD | NEW |