Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: experimental/svg/SkSVGDevice.cpp

Issue 892533002: Initial SVG backend stubbing (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: optional output file arg Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « experimental/svg/SkSVGDevice.h ('k') | experimental/svg/skp2svg.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkSVGDevice.h"
9
10 #include "SkBitmap.h"
11 #include "SkDraw.h"
12 #include "SkPaint.h"
13 #include "SkParsePath.h"
14 #include "SkStream.h"
15 #include "SkXMLWriter.h"
16
17 namespace {
18
19 class AutoElement {
20 public:
21 AutoElement(const char name[], SkXMLWriter* writer)
22 : fWriter(writer) {
23 fWriter->startElement(name);
24 }
25
26 ~AutoElement() {
27 fWriter->endElement();
28 }
29
30 private:
31 SkXMLWriter* fWriter;
32 };
33
34 }
35
36 SkBaseDevice* SkSVGDevice::Create(const SkISize& size, SkWStream* wstream) {
37 if (!SkToBool(wstream)) {
38 return NULL;
39 }
40
41 return SkNEW_ARGS(SkSVGDevice, (size, wstream));
42 }
43
44 SkSVGDevice::SkSVGDevice(const SkISize& size, SkWStream* wstream)
45 : fWriter(SkNEW_ARGS(SkXMLStreamWriter, (wstream))) {
46
47 fLegacyBitmap.setInfo(SkImageInfo::MakeUnknown(size.width(), size.height())) ;
48
49 fWriter->writeHeader();
50 fWriter->startElement("svg");
51 fWriter->addAttribute("xmlns", "http://www.w3.org/2000/svg");
52 fWriter->addAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
53 fWriter->addS32Attribute("width", size.width());
54 fWriter->addS32Attribute("height", size.height());
55 }
56
57 SkSVGDevice::~SkSVGDevice() {
58 fWriter->endElement();
59 fWriter->flush();
60 SkDELETE(fWriter);
61 }
62
63 SkImageInfo SkSVGDevice::imageInfo() const {
64 return fLegacyBitmap.info();
65 }
66
67 const SkBitmap& SkSVGDevice::onAccessBitmap() {
68 return fLegacyBitmap;
69 }
70
71 void SkSVGDevice::addPaint(const SkPaint& paint) {
72 SkColor color = paint.getColor();
73 SkString colorStr;
74 colorStr.appendf("rgb(%u,%u,%u)", SkColorGetR(color), SkColorGetG(color), Sk ColorGetB(color));
75
76 SkPaint::Style style = paint.getStyle();
77 if (style == SkPaint::kFill_Style || style == SkPaint::kStrokeAndFill_Style) {
78 fWriter->addAttribute("fill", colorStr.c_str());
79 } else {
80 fWriter->addAttribute("fill", "none");
81 }
82
83 if (style == SkPaint::kStroke_Style || style == SkPaint::kStrokeAndFill_Styl e) {
84 fWriter->addAttribute("stroke", colorStr.c_str());
85 fWriter->addScalarAttribute("stroke-width", paint.getStrokeWidth());
86 } else {
87 fWriter->addAttribute("stroke", "none");
88 }
89 }
90
91 void SkSVGDevice::addTransform(const SkMatrix &t) {
92 if (t.isIdentity()) {
93 return;
94 }
95
96 SkString tstr;
97 tstr.appendf("matrix(%g %g %g %g %g %g)",
98 SkScalarToFloat(t.getScaleX()), SkScalarToFloat(t.getSkewY()),
99 SkScalarToFloat(t.getSkewX()), SkScalarToFloat(t.getScaleY()),
100 SkScalarToFloat(t.getTranslateX()), SkScalarToFloat(t.getTransl ateY()));
101 fWriter->addAttribute("transform", tstr.c_str());
102 }
103
104 void SkSVGDevice::drawPaint(const SkDraw&, const SkPaint& paint) {
105 // todo
106 }
107
108 void SkSVGDevice::drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t cou nt,
109 const SkPoint[], const SkPaint& paint) {
110 // todo
111 }
112
113 void SkSVGDevice::drawRect(const SkDraw& draw, const SkRect& r, const SkPaint& p aint) {
114 AutoElement elem("rect", fWriter);
115
116 fWriter->addScalarAttribute("x", r.fLeft);
117 fWriter->addScalarAttribute("y", r.fTop);
118 fWriter->addScalarAttribute("width", r.width());
119 fWriter->addScalarAttribute("height", r.height());
120
121 this->addPaint(paint);
122 this->addTransform(*draw.fMatrix);
123 }
124
125 void SkSVGDevice::drawOval(const SkDraw&, const SkRect& oval, const SkPaint& pai nt) {
126 // todo
127 }
128
129 void SkSVGDevice::drawRRect(const SkDraw&, const SkRRect& rr, const SkPaint& pai nt) {
130 // todo
131 }
132
133 void SkSVGDevice::drawPath(const SkDraw& draw, const SkPath& path, const SkPaint & paint,
134 const SkMatrix* prePathMatrix, bool pathIsMutable) {
135 AutoElement elem("path", fWriter);
136
137 SkString pathStr;
138 SkParsePath::ToSVGString(path, &pathStr);
139 fWriter->addAttribute("d", pathStr.c_str());
140
141 this->addPaint(paint);
142 this->addTransform(*draw.fMatrix);
143 }
144
145 void SkSVGDevice::drawBitmap(const SkDraw&, const SkBitmap& bitmap,
146 const SkMatrix& matrix, const SkPaint& paint) {
147 // todo
148 }
149
150 void SkSVGDevice::drawSprite(const SkDraw&, const SkBitmap& bitmap,
151 int x, int y, const SkPaint& paint) {
152 // todo
153 }
154
155 void SkSVGDevice::drawBitmapRect(const SkDraw&, const SkBitmap&, const SkRect* s rcOrNull,
156 const SkRect& dst, const SkPaint& paint,
157 SkCanvas::DrawBitmapRectFlags flags) {
158 // todo
159 }
160
161 void SkSVGDevice::drawText(const SkDraw&, const void* text, size_t len,
162 SkScalar x, SkScalar y, const SkPaint& paint) {
163 // todo
164 }
165
166 void SkSVGDevice::drawPosText(const SkDraw&, const void* text, size_t len,const SkScalar pos[],
167 int scalarsPerPos, const SkPoint& offset, const Sk Paint& paint) {
168 // todo
169 }
170
171 void SkSVGDevice::drawTextOnPath(const SkDraw&, const void* text, size_t len, co nst SkPath& path,
172 const SkMatrix* matrix, const SkPaint& paint) {
173 // todo
174 }
175
176 void SkSVGDevice::drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCo unt,
177 const SkPoint verts[], const SkPoint texs[],
178 const SkColor colors[], SkXfermode* xmode,
179 const uint16_t indices[], int indexCount,
180 const SkPaint& paint) {
181 // todo
182 }
183
184 void SkSVGDevice::drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
185 const SkPaint&) {
186 // todo
187 }
OLDNEW
« no previous file with comments | « experimental/svg/SkSVGDevice.h ('k') | experimental/svg/skp2svg.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698