aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/path_stroke_with_zero_length.cpp
blob: dc52947da3b2f79bc07ab6c133b4a5461d4015ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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);
}