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 BD-style license that can be | 4 * Use of this source code is governed by a BD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkParsePath.h" | 9 #include "SkParsePath.h" |
10 #include "SkPath.h" | 10 #include "SkPath.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 SkPath path; | 95 SkPath path; |
96 path.moveTo(100, 100); | 96 path.moveTo(100, 100); |
97 path.arcTo(0, 0, 0, SkPath::kLarge_ArcSize, SkPath::kCW_Direction, 200, 200)
; | 97 path.arcTo(0, 0, 0, SkPath::kLarge_ArcSize, SkPath::kCW_Direction, 200, 200)
; |
98 canvas->drawPath(path, paint); | 98 canvas->drawPath(path, paint); |
99 | 99 |
100 path.reset(); | 100 path.reset(); |
101 path.moveTo(200, 100); | 101 path.moveTo(200, 100); |
102 path.arcTo(80, 80, 0, SkPath::kLarge_ArcSize, SkPath::kCW_Direction, 200, 10
0); | 102 path.arcTo(80, 80, 0, SkPath::kLarge_ArcSize, SkPath::kCW_Direction, 200, 10
0); |
103 canvas->drawPath(path, paint); | 103 canvas->drawPath(path, paint); |
104 } | 104 } |
| 105 |
| 106 #include "random_parse_path.h" |
| 107 #include "SkRandom.h" |
| 108 |
| 109 /* The test below generates a reference image using SVG. To compare the result f
or correctness, |
| 110 enable the define below and then view the generated SVG in a browser. |
| 111 */ |
| 112 #define GENERATE_SVG_REFERENCE 0 |
| 113 |
| 114 #if GENERATE_SVG_REFERENCE |
| 115 #include "SkOSFile.h" |
| 116 #endif |
| 117 |
| 118 enum { |
| 119 kParsePathTestDimension = 500 |
| 120 }; |
| 121 |
| 122 DEF_SIMPLE_GM(parsedpaths, canvas, kParsePathTestDimension, kParsePathTestDimens
ion) { |
| 123 #if GENERATE_SVG_REFERENCE |
| 124 FILE* file = sk_fopen("svgout.htm", kWrite_SkFILE_Flag); |
| 125 SkString str; |
| 126 str.printf("<svg width=\"%d\" height=\"%d\">\n", kParsePathTestDimension, |
| 127 kParsePathTestDimension); |
| 128 sk_fwrite(str.c_str(), str.size(), file); |
| 129 #endif |
| 130 SkRandom rand; |
| 131 SkPaint paint; |
| 132 paint.setAntiAlias(true); |
| 133 for (int xStart = 0; xStart < kParsePathTestDimension; xStart += 100) { |
| 134 canvas->save(); |
| 135 for (int yStart = 0; yStart < kParsePathTestDimension; yStart += 100) { |
| 136 #if GENERATE_SVG_REFERENCE |
| 137 str.printf("<g transform='translate(%d,%d) scale(%d,%d)'>\n", xStart
, yStart, |
| 138 1, 1); |
| 139 sk_fwrite(str.c_str(), str.size(), file); |
| 140 str.printf("<clipPath id='clip_%d_%d'>\n", xStart, yStart); |
| 141 sk_fwrite(str.c_str(), str.size(), file); |
| 142 str.printf("<rect width='100' height='100' x='0' y='0'></rect>\n"); |
| 143 sk_fwrite(str.c_str(), str.size(), file); |
| 144 str.printf("</clipPath>\n"); |
| 145 sk_fwrite(str.c_str(), str.size(), file); |
| 146 #endif |
| 147 int count = 3; |
| 148 do { |
| 149 SkPath path; |
| 150 SkString spec; |
| 151 spec.printf("M %d,%d\n", rand.nextRangeU(30, 70), rand.nextRange
U(30, 70)); |
| 152 uint32_t count = rand.nextRangeU(0, 10); |
| 153 for (uint32_t i = 0; i < count; ++i) { |
| 154 spec.append(MakeRandomParsePathPiece(&rand)); |
| 155 } |
| 156 SkAssertResult(SkParsePath::FromSVGString(spec.c_str(), &path)); |
| 157 paint.setColor(rand.nextU()); |
| 158 canvas->save(); |
| 159 canvas->clipRect(SkRect::MakeIWH(100, 100)); |
| 160 canvas->drawPath(path, paint); |
| 161 canvas->restore(); |
| 162 #if GENERATE_SVG_REFERENCE |
| 163 str.printf("<path d='\n"); |
| 164 sk_fwrite(str.c_str(), str.size(), file); |
| 165 sk_fwrite(spec.c_str(), spec.size(), file); |
| 166 str.printf("\n' fill='#%06x' fill-opacity='%g'", paint.getColor(
) & 0xFFFFFF, |
| 167 paint.getAlpha() / 255.f); |
| 168 sk_fwrite(str.c_str(), str.size(), file); |
| 169 str.printf(" clip-path='url(#clip_%d_%d)'/>\n", xStart, yStart); |
| 170 sk_fwrite(str.c_str(), str.size(), file); |
| 171 #endif |
| 172 } while (--count > 0); |
| 173 #if GENERATE_SVG_REFERENCE |
| 174 str.printf("</g>\n"); |
| 175 sk_fwrite(str.c_str(), str.size(), file); |
| 176 #endif |
| 177 canvas->translate(0, 100); |
| 178 } |
| 179 canvas->restore(); |
| 180 canvas->translate(100, 0); |
| 181 } |
| 182 #if GENERATE_SVG_REFERENCE |
| 183 const char trailer[] = "</svg>\n"; |
| 184 sk_fwrite(trailer, sizeof(trailer) - 1, file); |
| 185 sk_fclose(file); |
| 186 #endif |
| 187 } |
OLD | NEW |