File: SplashPath.h

package info (click to toggle)
poppler 20.09.0-3.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 16,092 kB
  • sloc: cpp: 151,577; ansic: 30,155; python: 367; makefile: 42; sh: 36
file content (142 lines) | stat: -rw-r--r-- 4,406 bytes parent folder | download
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//========================================================================
//
// SplashPath.h
//
//========================================================================

//========================================================================
//
// Modified under the Poppler project - http://poppler.freedesktop.org
//
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
// Copyright (C) 2018, 2019 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2018 Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
//
//========================================================================

#ifndef SPLASHPATH_H
#define SPLASHPATH_H

#include "SplashTypes.h"

//------------------------------------------------------------------------
// SplashPathPoint
//------------------------------------------------------------------------

struct SplashPathPoint
{
    SplashCoord x, y;
};

//------------------------------------------------------------------------
// SplashPath.flags
//------------------------------------------------------------------------

// first point on each subpath sets this flag
#define splashPathFirst 0x01

// last point on each subpath sets this flag
#define splashPathLast 0x02

// if the subpath is closed, its first and last points must be
// identical, and must set this flag
#define splashPathClosed 0x04

// curve control points set this flag
#define splashPathCurve 0x08

//------------------------------------------------------------------------
// SplashPathHint
//------------------------------------------------------------------------

struct SplashPathHint
{
    int ctrl0, ctrl1;
    int firstPt, lastPt;
};

//------------------------------------------------------------------------
// SplashPath
//------------------------------------------------------------------------

class SplashPath
{
public:
    // Create an empty path.
    SplashPath();

    // Copy a path.
    SplashPath *copy() { return new SplashPath(this); }

    ~SplashPath();

    SplashPath(const SplashPath &) = delete;
    SplashPath &operator=(const SplashPath &) = delete;
    SplashPath(SplashPath &&path) noexcept;

    // Append <path> to <this>.
    void append(SplashPath *path);

    // Start a new subpath.
    SplashError moveTo(SplashCoord x, SplashCoord y);

    // Add a line segment to the last subpath.
    SplashError lineTo(SplashCoord x, SplashCoord y);

    // Add a third-order (cubic) Bezier curve segment to the last
    // subpath.
    SplashError curveTo(SplashCoord x1, SplashCoord y1, SplashCoord x2, SplashCoord y2, SplashCoord x3, SplashCoord y3);

    // Close the last subpath, adding a line segment if necessary.  If
    // <force> is true, this adds a line segment even if the current
    // point is equal to the first point in the subpath.
    SplashError close(bool force = false);

    // Add a stroke adjustment hint.  The controlling segments are
    // <ctrl0> and <ctrl1> (where segments are identified by their first
    // point), and the points to be adjusted are <firstPt> .. <lastPt>.
    void addStrokeAdjustHint(int ctrl0, int ctrl1, int firstPt, int lastPt);

    // Add (<dx>, <dy>) to every point on this path.
    void offset(SplashCoord dx, SplashCoord dy);

    // Get the points on the path.
    int getLength() { return length; }
    void getPoint(int i, double *x, double *y, unsigned char *f)
    {
        *x = pts[i].x;
        *y = pts[i].y;
        *f = flags[i];
    }

    // Get the current point.
    bool getCurPt(SplashCoord *x, SplashCoord *y);

    // Reserve space for at least n points
    void reserve(int n);

protected:
    SplashPath(SplashPath *path);
    void grow(int nPts);
    bool noCurrentPoint() { return curSubpath == length; }
    bool onePointSubpath() { return curSubpath == length - 1; }
    bool openSubpath() { return curSubpath < length - 1; }

    SplashPathPoint *pts; // array of points
    unsigned char *flags; // array of flags
    int length, size; // length/size of the pts and flags arrays
    int curSubpath; // index of first point in last subpath

    SplashPathHint *hints; // list of hints
    int hintsLength, hintsSize;

    friend class SplashXPath;
    friend class Splash;
};

#endif