/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BD-style license that can be
* found in the LICENSE file.
*/
#include "gm.h"
#include "SkParsePath.h"
#include "SkPath.h"
/*
The arcto test below should draw the same as this SVG:
(Note that Skia's arcTo Direction parameter value is opposite SVG's sweep value, e.g. 0 / 1)
*/
DEF_SIMPLE_GM(arcto, canvas, 500, 600) {
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(2);
paint.setColor(0xFF660000);
// canvas->scale(2, 2); // for testing on retina
SkRect oval = SkRect::MakeXYWH(100, 100, 100, 100);
SkPath svgArc;
for (int angle = 0; angle <= 45; angle += 45) {
for (int oHeight = 2; oHeight >= 1; --oHeight) {
SkScalar ovalHeight = oval.height() / oHeight;
svgArc.moveTo(oval.fLeft, oval.fTop);
svgArc.arcTo(oval.width() / 2, ovalHeight, SkIntToScalar(angle), SkPath::kSmall_ArcSize,
SkPath::kCW_Direction, oval.right(), oval.bottom());
canvas->drawPath(svgArc, paint);
svgArc.reset();
svgArc.moveTo(oval.fLeft + 100, oval.fTop + 100);
svgArc.arcTo(oval.width() / 2, ovalHeight, SkIntToScalar(angle), SkPath::kLarge_ArcSize,
SkPath::kCCW_Direction, oval.right(), oval.bottom() + 100);
canvas->drawPath(svgArc, paint);
oval.offset(50, 0);
svgArc.reset();
}
}
paint.setStrokeWidth(5);
const SkColor purple = 0xFF800080;
const SkColor darkgreen = 0xFF008000;
const SkColor colors[] = { SK_ColorRED, darkgreen, purple, SK_ColorBLUE };
const char* arcstrs[] = {
"M250,400 A120,80 0 0,0 250,500",
"M250,400 A120,80 0 1,1 250,500",
"M250,400 A120,80 0 1,0 250,500",
"M250,400 A120,80 0 0,1 250,500"
};
int cIndex = 0;
for (const char* arcstr : arcstrs) {
SkParsePath::FromSVGString(arcstr, &svgArc);
paint.setColor(colors[cIndex++]);
canvas->drawPath(svgArc, paint);
}
// test that zero length arcs still draw round cap
paint.setStrokeCap(SkPaint::kRound_Cap);
SkPath path;
path.moveTo(100, 100);
path.arcTo(0, 0, 0, SkPath::kLarge_ArcSize, SkPath::kCW_Direction, 200, 200);
canvas->drawPath(path, paint);
path.reset();
path.moveTo(200, 100);
path.arcTo(80, 80, 0, SkPath::kLarge_ArcSize, SkPath::kCW_Direction, 200, 100);
canvas->drawPath(path, paint);
}
#include "random_parse_path.h"
#include "SkRandom.h"
/* The test below generates a reference image using SVG. To compare the result for correctness,
enable the define below and then view the generated SVG in a browser.
*/
#define GENERATE_SVG_REFERENCE 0
#if GENERATE_SVG_REFERENCE
#include "SkOSFile.h"
#endif
enum {
kParsePathTestDimension = 500
};
DEF_SIMPLE_GM(parsedpaths, canvas, kParsePathTestDimension, kParsePathTestDimension) {
#if GENERATE_SVG_REFERENCE
FILE* file = sk_fopen("svgout.htm", kWrite_SkFILE_Flag);
SkString str;
str.printf("\n";
sk_fwrite(trailer, sizeof(trailer) - 1, file);
sk_fclose(file);
#endif
}