summaryrefslogtreecommitdiffstats
path: root/src/helper/geom-pathstroke.h
blob: 73d35b40253e1d425918f3e5914901a6eba801f2 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// SPDX-License-Identifier: GPL-2.0-or-later
#ifndef INKSCAPE_HELPER_PATH_STROKE_H
#define INKSCAPE_HELPER_PATH_STROKE_H

/* Authors:
 *   Liam P. White
 *   Tavmjong Bah
 *
 * Copyright (C) 2014-2015 Authors
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#include <2geom/path.h>
#include <2geom/pathvector.h>

namespace Inkscape {

enum LineJoinType {
    JOIN_BEVEL,
    JOIN_ROUND,
    JOIN_MITER,
    JOIN_MITER_CLIP,
    JOIN_EXTRAPOLATE,
    JOIN_EXTRAPOLATE1,
    JOIN_EXTRAPOLATE2,
    JOIN_EXTRAPOLATE3,
};

enum LineCapType {
    BUTT_FLAT,
    BUTT_ROUND,
    BUTT_SQUARE,
    BUTT_PEAK, // This is not a line ending supported by the SVG standard.
};

/**
 * Strokes the path given by @a input.
 * Joins may behave oddly if the width is negative.
 *
 * @param[in] input Input path.
 * @param[in] width Stroke width.
 * @param[in] miter Miter limit. Only used when @a join is one of JOIN_MITER, JOIN_MITER_CLIP, and JOIN_EXTRAPOLATE.
 * @param[in] join  Line join type used during offset. Member of LineJoinType enum.
 * @param[in] cap   Line cap type used during stroking. Member of LineCapType enum.
 * @param[in] tolerance Tolerance, values smaller than 0 lead to automatic tolerance depending on width.
 *
 * @return Stroked path.
 *         If the input path is closed, the resultant vector will contain two paths.
 *         Otherwise, there should be only one in the output.
 */
Geom::PathVector outline(
        Geom::Path const& input,
        double width,
        double miter,
        LineJoinType join = JOIN_BEVEL,
        LineCapType cap = BUTT_FLAT,
        double tolerance = -1);

/**
 * Offset the input path by @a width.
 * Joins may behave oddly if the width is negative.
 *
 * @param[in] input Input path.
 * @param[in] width Amount to offset.
 * @param[in] miter Miter limit. Only used when @a join is one of JOIN_MITER, JOIN_MITER_CLIP, and JOIN_EXTRAPOLATE.
 * @param[in] join  Line join type used during offset. Member of LineJoinType enum.
 * @param[in] tolerance Tolerance, values smaller than 0 lead to automatic tolerance depending on width.
 *
 * @return Offsetted output.
 */
Geom::Path half_outline(
        Geom::Path const& input,
        double width,
        double miter,
        LineJoinType join = JOIN_BEVEL,
        double tolerance = -1);

/**
 * Builds a join on the provided path.
 * Joins may behave oddly if the width is negative.
 *
 * @param[inout] res      The path to build the join on. 
 *                        The outgoing path (or a portion thereof) will be appended after the join is created.
 *                        Previous segments may be modified as an optimization, beware!
 *
 * @param[in]    outgoing The segment to append on the outgoing portion of the join.
 * @param[in]    in_tang  The end tangent to consider on the input path.
 * @param[in]    out_tang The begin tangent to consider on the output path.
 * @param[in]    width
 * @param[in]    miter
 * @param[in]    join
 */
void outline_join(Geom::Path &res, Geom::Path const& outgoing, Geom::Point in_tang, Geom::Point out_tang, double width, double miter, LineJoinType join);

} // namespace Inkscape

#endif // INKSCAPE_HELPER_PATH_STROKE_H

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8 :