File: xfigobjects.h

package info (click to toggle)
fig2sxd 0.23-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,508 kB
  • sloc: cpp: 2,345; makefile: 39
file content (188 lines) | stat: -rw-r--r-- 5,720 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// -*-c++-*-

// fixg2sxd - a utility to convert fig to sxd format

// Copyright (C) 2003-2022 Alexander Bürger, acfb@users.sourceforge.net

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

#ifndef XFIGOBJCECT_H
#define XFIGOBJCECT_H

#include <set>
#include <string>
#include <iostream>

#include "vector2.h"
#include "styles.h"

class XfigObject {
public:
    virtual ~XfigObject() { }
    int depth;

    virtual std::ostream& write( std::ostream& out ) = 0;
};

// ------------------------------------------------------------------------

class Arc : public XfigObject
{
public:
    int sub_type; // (1: open ended arc 2: pie-wedge (closed) )
    lfsset::iterator lfs;
    int cap_style; // (enumeration type)
    int direction; // (0: clockwise, 1: counterclockwise)
    int forward_arrow; // (0: no forward arrow, 1: on)
    int backward_arrow; // (0: no backward arrow, 1: on)
    float center_x, center_y; // (center of the arc)
    float x1, y1; // (Fig units, the 1st point the user entered)
    float x2, y2; // (Fig units, the 2nd point)
    float x3, y3; // (Fig units, the last point)

    std::istream& read( std::istream& in );
    virtual std::ostream& write( std::ostream& out );
};

// ------------------------------------------------------------------------

class OpenCompound : public XfigObject
{
public:
    float upperleft_corner_x; // (Fig units)
    float upperleft_corner_y; // (Fig units)
    float lowerright_corner_x; // (Fig units)
    float lowerright_corner_y; // (Fig units)

    std::istream& read( std::istream& in );
    virtual std::ostream& write( std::ostream& out );
};

// ------------------------------------------------------------------------

class CloseCompound : public XfigObject
{
public:
    std::istream& read( std::istream& in );
    virtual std::ostream& write( std::ostream& out );
};

// ------------------------------------------------------------------------

class Ellipse : public XfigObject
{
public:
    int sub_type; // (1: ellipse defined by radii
    // 2: ellipse defined by diameters
    // 3: circle defined by radius
    // 4: circle defined by diameter)
    lfsset::iterator lfs;
    int direction; // (always 1)
    float angle; // (radians, the angle of the x-axis)
    float center_x, center_y; // (Fig units)
    float radius_x, radius_y; // (Fig units)
    float start_x, start_y; // (Fig units; the 1st point entered)
    float end_x, end_y; // (Fig units; the last point entered)

    std::istream& read( std::istream& in );
    virtual std::ostream& write( std::ostream& out );
};

// ------------------------------------------------------------------------

class Poly : public XfigObject
{
public:
    int sub_type; // (1: polyline, 2: box, 3: polygon, 4: arc-box
    // 5: imported-picture bounding-box)
    lfsset::iterator lfs;

    int cap_style; // (enumeration type, only used for POLYLINE)
    int radius; // (1/80 inch, radius of arc-boxes)
    int forward_arrow; // (0: off, 1: on)
    int backward_arrow; // (0: off, 1: on)
    int npoints; // (number of points in line)

    // for images
    int flipped; // orientation = normal (0) or flipped (1)
    std::string file; // name of picture file to import

    float *x;
    float *y;

    std::istream& read( std::istream& in );
    virtual std::ostream& write( std::ostream& out );

    Poly() : x(0), y(0) { }
    ~Poly();

private:
    std::ostream& write_rectangle( std::ostream& out );
    std::ostream& write_image( std::ostream& out );
    std::ostream& write_poly( std::ostream& out );

    void find_min_max( float& maxx, float& minx, float& maxy, float& miny, int begin, int end );
};

// ------------------------------------------------------------------------

class Spline : public XfigObject
{
public:
    int sub_type;
    // 0: open approximated spline,
    // 1: closed approximated spline
    // 2: open   interpolated spline
    // 3: closed interpolated spline
    // 4: open   x-spline
    // 5: closed x-spline
    lfsset::iterator lfs;

    int cap_style; // (enumeration type, only used for POLYLINE)
    int forward_arrow; // (0: off, 1: on)
    int backward_arrow; // (0: off, 1: on)
    int npoints; // (number of points in line)

    Vector2f *p;

    float *shapefactors;

    std::istream& read( std::istream& in );
    virtual std::ostream& write( std::ostream& out );

    Spline() : p(0), shapefactors(0) { }
    ~Spline();
};

// ------------------------------------------------------------------------

class Text : public XfigObject
{
public:
    tsset::iterator textstyle;
    float angle; // (radians, the angle of the text)
    float height; // (Fig units)
    float length; // (Fig units)
    float x, y; // (Fig units, coordinate of the origin
    // of the string.  If sub_type = 0, it is the lower left corner of
    // the string.  If sub_type = 1, it is the lower center.
    // Otherwise it is the lower right corner of the string.)
    std::string text;

    std::istream& read( std::istream& in );
    virtual std::ostream& write( std::ostream& out );
};

#endif // XFIGOBJCECT_H