diff options
author | halcanary <halcanary@google.com> | 2015-10-06 09:41:47 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-06 09:41:47 -0700 |
commit | 8b2bc252faed7c751cf9248c3833c0631f498b7d (patch) | |
tree | 0693d95235ab8657e306fa16939aec6a26135f93 /gm/path_stroke_with_zero_length.cpp | |
parent | 4a339529612a43871d021877e58698e067d6c4cd (diff) |
SkPDF: when drawing stroked path, draw using SVG rules for zero-length segments
The "zeroPath" and emptystroke GMs capture this issue.
This CL changes the following PDF GMs: emptystroke dashing4
lineclosepath dashing3 zeroPath linepath
complexclip3_complex complexclip3_simple roundrects
degeneratesegments filltypes strokerect pathfill
inverse_paths desk_chalkboard.skp
After this change, all PDF GMs look better (closer to 8888).
The dashing4, emptystroke, and zeroPath GMs still need a lot
of work to make them look right.
BUG=538726
Review URL: https://codereview.chromium.org/1374383004
Diffstat (limited to 'gm/path_stroke_with_zero_length.cpp')
-rw-r--r-- | gm/path_stroke_with_zero_length.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/gm/path_stroke_with_zero_length.cpp b/gm/path_stroke_with_zero_length.cpp new file mode 100644 index 0000000000..dc52947da3 --- /dev/null +++ b/gm/path_stroke_with_zero_length.cpp @@ -0,0 +1,54 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkPath.h" +#include "SkStream.h" +#include "gm.h" + +// Test how short paths are stroked with various caps +DEF_SIMPLE_GM(path_stroke_with_zero_length, canvas, 240, 120) { + SkPath paths[5]; + paths[0].moveTo(30.0f, 0); // single line segment + paths[0].rLineTo(30.0f, 0); + + paths[1].moveTo(90.0f, 0); // single line segment with close + paths[1].rLineTo(30.0f, 0); + paths[1].close(); + + paths[2].moveTo(150.0f, 0); // zero-length line + paths[2].rLineTo(0, 0); + + paths[3].moveTo(180.0f, 0); // zero-length line with close + paths[3].rLineTo(0, 0); + paths[3].close(); + + paths[4].moveTo(210.0f, 0); // close only, no line + paths[4].close(); + + auto drawPaths = [&](const SkPaint& paint) { + canvas->translate(0, 30.0f); + for (const SkPath& path : paths) { + canvas->drawPath(path, paint); + } + }; + + SkAutoCanvasRestore autoCanvasRestore(canvas, true); + + SkPaint butt; + butt.setStyle(SkPaint::kStroke_Style); + butt.setStrokeWidth(20.0f); + butt.setStrokeCap(SkPaint::kButt_Cap); + drawPaths(butt); + + SkPaint round(butt); + round.setStrokeCap(SkPaint::kRound_Cap); + drawPaths(round); + + SkPaint square(butt); + square.setStrokeCap(SkPaint::kSquare_Cap); + drawPaths(square); +} |