| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "SkParse.h" | 8 #include "SkParse.h" |
| 9 #include "SkParsePath.h" | 9 #include "SkParsePath.h" |
| 10 | 10 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 } | 177 } |
| 178 previousOp = op; | 178 previousOp = op; |
| 179 } | 179 } |
| 180 // we're good, go ahead and swap in the result | 180 // we're good, go ahead and swap in the result |
| 181 result->swap(path); | 181 result->swap(path); |
| 182 return true; | 182 return true; |
| 183 } | 183 } |
| 184 | 184 |
| 185 /////////////////////////////////////////////////////////////////////////////// | 185 /////////////////////////////////////////////////////////////////////////////// |
| 186 | 186 |
| 187 #include "SkGeometry.h" |
| 187 #include "SkString.h" | 188 #include "SkString.h" |
| 188 #include "SkStream.h" | 189 #include "SkStream.h" |
| 189 | 190 |
| 190 static void write_scalar(SkWStream* stream, SkScalar value) { | 191 static void write_scalar(SkWStream* stream, SkScalar value) { |
| 191 char buffer[64]; | 192 char buffer[64]; |
| 192 #ifdef SK_BUILD_FOR_WIN32 | 193 #ifdef SK_BUILD_FOR_WIN32 |
| 193 int len = _snprintf(buffer, sizeof(buffer), "%g", value); | 194 int len = _snprintf(buffer, sizeof(buffer), "%g", value); |
| 194 #else | 195 #else |
| 195 int len = snprintf(buffer, sizeof(buffer), "%g", value); | 196 int len = snprintf(buffer, sizeof(buffer), "%g", value); |
| 196 #endif | 197 #endif |
| (...skipping 12 matching lines...) Expand all Loading... |
| 209 } | 210 } |
| 210 | 211 |
| 211 void SkParsePath::ToSVGString(const SkPath& path, SkString* str) { | 212 void SkParsePath::ToSVGString(const SkPath& path, SkString* str) { |
| 212 SkDynamicMemoryWStream stream; | 213 SkDynamicMemoryWStream stream; |
| 213 | 214 |
| 214 SkPath::Iter iter(path, false); | 215 SkPath::Iter iter(path, false); |
| 215 SkPoint pts[4]; | 216 SkPoint pts[4]; |
| 216 | 217 |
| 217 for (;;) { | 218 for (;;) { |
| 218 switch (iter.next(pts, false)) { | 219 switch (iter.next(pts, false)) { |
| 219 case SkPath::kConic_Verb: | 220 case SkPath::kConic_Verb: { |
| 220 SkASSERT(0); | 221 const SkScalar tol = SK_Scalar1 / 1024; // how close to a quad |
| 221 break; | 222 SkAutoConicToQuads quadder; |
| 223 const SkPoint* quadPts = quadder.computeQuads(pts, iter.conicWei
ght(), tol); |
| 224 for (int i = 0; i < quadder.countQuads(); ++i) { |
| 225 append_scalars(&stream, 'Q', &quadPts[i*2 + 1].fX, 4); |
| 226 } |
| 227 } break; |
| 222 case SkPath::kMove_Verb: | 228 case SkPath::kMove_Verb: |
| 223 append_scalars(&stream, 'M', &pts[0].fX, 2); | 229 append_scalars(&stream, 'M', &pts[0].fX, 2); |
| 224 break; | 230 break; |
| 225 case SkPath::kLine_Verb: | 231 case SkPath::kLine_Verb: |
| 226 append_scalars(&stream, 'L', &pts[1].fX, 2); | 232 append_scalars(&stream, 'L', &pts[1].fX, 2); |
| 227 break; | 233 break; |
| 228 case SkPath::kQuad_Verb: | 234 case SkPath::kQuad_Verb: |
| 229 append_scalars(&stream, 'Q', &pts[1].fX, 4); | 235 append_scalars(&stream, 'Q', &pts[1].fX, 4); |
| 230 break; | 236 break; |
| 231 case SkPath::kCubic_Verb: | 237 case SkPath::kCubic_Verb: |
| 232 append_scalars(&stream, 'C', &pts[1].fX, 6); | 238 append_scalars(&stream, 'C', &pts[1].fX, 6); |
| 233 break; | 239 break; |
| 234 case SkPath::kClose_Verb: | 240 case SkPath::kClose_Verb: |
| 235 stream.write("Z", 1); | 241 stream.write("Z", 1); |
| 236 break; | 242 break; |
| 237 case SkPath::kDone_Verb: | 243 case SkPath::kDone_Verb: |
| 238 str->resize(stream.getOffset()); | 244 str->resize(stream.getOffset()); |
| 239 stream.copyTo(str->writable_str()); | 245 stream.copyTo(str->writable_str()); |
| 240 return; | 246 return; |
| 241 } | 247 } |
| 242 } | 248 } |
| 243 } | 249 } |
| OLD | NEW |