~ubuntu-branches/ubuntu/saucy/librecad/saucy

« back to all changes in this revision

Viewing changes to src/lib/engine/rs_text.h

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2013-09-13 21:52:29 UTC
  • mfrom: (1.1.7) (5.2.7 experimental)
  • Revision ID: package-import@ubuntu.com-20130913215229-b18g6qjb8nacro28
Tags: 2.0.0~rc2+nolibs-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
**
3
 
** This file is part of the LibreCAD project, a 2D CAD program
4
 
**
5
 
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6
 
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
7
 
**
8
 
**
9
 
** This file may be distributed and/or modified under the terms of the
10
 
** GNU General Public License version 2 as published by the Free Software 
11
 
** Foundation and appearing in the file gpl-2.0.txt included in the
12
 
** packaging of this file.
13
 
**
14
 
** This program is distributed in the hope that it will be useful,
15
 
** but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 
** GNU General Public License for more details.
18
 
** 
19
 
** You should have received a copy of the GNU General Public License
20
 
** along with this program; if not, write to the Free Software
21
 
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
 
**
23
 
** This copyright notice MUST APPEAR in all copies of the script!  
24
 
**
25
 
**********************************************************************/
26
 
 
27
 
 
28
 
#ifndef RS_TEXT_H
29
 
#define RS_TEXT_H
30
 
 
31
 
#include "rs_entitycontainer.h"
32
 
 
33
 
/**
34
 
 * Holds the data that defines a text entity.
35
 
 */
36
 
class RS_TextData {
37
 
public:
38
 
    /**
39
 
     * Default constructor. Leaves the data object uninitialized.
40
 
     */
41
 
    RS_TextData() {}
42
 
 
43
 
    /**
44
 
     * Constructor with initialisation.
45
 
     *
46
 
     * @param insertionPoint Insertion point
47
 
     * @param height Nominal (initial) text height
48
 
     * @param width Reference rectangle width
49
 
     * @param valign Vertical alignment
50
 
     * @param halign Horizontal alignment
51
 
     * @param drawingDirection Drawing direction
52
 
     * @param lineSpacingStyle Line spacing style
53
 
     * @param lineSpacingFactor Line spacing factor
54
 
     * @param text Text string
55
 
     * @param style Text style name
56
 
     * @param angle Rotation angle
57
 
     * @param updateMode RS2::Update will update the text entity instantly
58
 
     *    RS2::NoUpdate will not update the entity. You can update
59
 
     *    it later manually using the update() method. This is
60
 
     *    often the case since you might want to adjust attributes
61
 
     *    after creating a text entity.
62
 
     */
63
 
    RS_TextData(const RS_Vector& insertionPoint,
64
 
                double height,
65
 
                double width,
66
 
                RS2::VAlign valign,
67
 
                RS2::HAlign halign,
68
 
                RS2::TextDrawingDirection drawingDirection,
69
 
                RS2::TextLineSpacingStyle lineSpacingStyle,
70
 
                double lineSpacingFactor,
71
 
                const QString& text,
72
 
                const QString& style,
73
 
                double angle,
74
 
                RS2::UpdateMode updateMode = RS2::Update) {
75
 
        this->insertionPoint = insertionPoint;
76
 
        this->height = height;
77
 
        this->width = width;
78
 
        this->valign = valign;
79
 
        this->halign = halign;
80
 
        this->drawingDirection = drawingDirection;
81
 
        this->lineSpacingStyle = lineSpacingStyle;
82
 
        this->lineSpacingFactor = lineSpacingFactor;
83
 
        this->style = style;
84
 
        this->angle = angle;
85
 
        this->text = text;
86
 
        this->updateMode = updateMode;
87
 
    }
88
 
 
89
 
    friend class RS_Text;
90
 
 
91
 
    friend std::ostream& operator << (std::ostream& os, const RS_TextData& td) {
92
 
        os << "(" << td.text.toLatin1().data() << ")";
93
 
        return os;
94
 
    }
95
 
 
96
 
public:
97
 
    /** Insertion point */
98
 
    RS_Vector insertionPoint;
99
 
    /** Nominal (initial) text height */
100
 
    double height;
101
 
    /** Reference rectangle width */
102
 
    double width;
103
 
    /** Vertical alignment */
104
 
    RS2::VAlign valign;
105
 
    /** Horizontal alignment */
106
 
    RS2::HAlign halign;
107
 
    /** Drawing direction */
108
 
    RS2::TextDrawingDirection drawingDirection;
109
 
    /** Line spacing style */
110
 
    RS2::TextLineSpacingStyle lineSpacingStyle;
111
 
    /** Line spacing factor */
112
 
    double lineSpacingFactor;
113
 
    /** Text string */
114
 
    QString text;
115
 
    /** Text style name */
116
 
    QString style;
117
 
    /** Rotation angle */
118
 
    double angle;
119
 
    /** Update mode */
120
 
    RS2::UpdateMode updateMode;
121
 
};
122
 
 
123
 
 
124
 
 
125
 
/**
126
 
 * Class for a text entity.
127
 
 * Please note that text strings can contain special 
128
 
 * characters such as %%c for a diameter sign as well as unicode
129
 
 * characters. Line feeds are stored as real line feeds in the string.
130
 
 *
131
 
 * @author Andrew Mustun
132
 
 */
133
 
class RS_Text : public RS_EntityContainer {
134
 
public:
135
 
    RS_Text(RS_EntityContainer* parent,
136
 
            const RS_TextData& d);
137
 
    virtual ~RS_Text() {}
138
 
 
139
 
    virtual RS_Entity* clone() {
140
 
        RS_Text* t = new RS_Text(*this);
141
 
        t->setOwner(isOwner());
142
 
        t->initId();
143
 
        t->detach();
144
 
        return t;
145
 
    }
146
 
 
147
 
    /** @return RS2::EntityText */
148
 
    virtual RS2::EntityType rtti() const {
149
 
        return RS2::EntityText;
150
 
    }
151
 
 
152
 
    /** @return Copy of data that defines the text. */
153
 
    RS_TextData getData() const {
154
 
        return data;
155
 
    }
156
 
 
157
 
    void update();
158
 
    void updateAddLine(RS_EntityContainer* textLine, int lineCounter);
159
 
 
160
 
    int getNumberOfLines();
161
 
 
162
 
 
163
 
    RS_Vector getInsertionPoint() {
164
 
        return data.insertionPoint;
165
 
    }
166
 
    double getHeight() {
167
 
        return data.height;
168
 
    }
169
 
    void setHeight(double h) {
170
 
        data.height = h;
171
 
    }
172
 
    double getWidth() {
173
 
        return data.width;
174
 
    }
175
 
    void setAlignment(int a);
176
 
    int getAlignment();
177
 
    RS2::VAlign getVAlign() {
178
 
        return data.valign;
179
 
    }
180
 
        void setVAlign(RS2::VAlign va) {
181
 
                data.valign = va;
182
 
        }
183
 
    RS2::HAlign getHAlign() {
184
 
        return data.halign;
185
 
    }
186
 
        void setHAlign(RS2::HAlign ha) {
187
 
                data.halign = ha;
188
 
        }
189
 
    RS2::TextDrawingDirection getDrawingDirection() {
190
 
        return data.drawingDirection;
191
 
    }
192
 
    RS2::TextLineSpacingStyle getLineSpacingStyle() {
193
 
        return data.lineSpacingStyle;
194
 
    }
195
 
    void setLineSpacingFactor(double f) {
196
 
        data.lineSpacingFactor = f;
197
 
    }
198
 
    double getLineSpacingFactor() {
199
 
        return data.lineSpacingFactor;
200
 
    }
201
 
    void setText(const QString& t);
202
 
    QString getText() {
203
 
        return data.text;
204
 
    }
205
 
    void setStyle(const QString& s) {
206
 
        data.style = s;
207
 
    }
208
 
    QString getStyle() {
209
 
        return data.style;
210
 
    }
211
 
        void setAngle(double a) {
212
 
                data.angle = a;
213
 
        }
214
 
    double getAngle() {
215
 
        return data.angle;
216
 
    }
217
 
    double getUsedTextWidth() {
218
 
        return usedTextWidth;
219
 
    }
220
 
    double getUsedTextHeight() {
221
 
        return usedTextHeight;
222
 
    }
223
 
 
224
 
        virtual double getLength() {
225
 
                return -1.0;
226
 
        }
227
 
        
228
 
    virtual RS_VectorSolutions getRefPoints();
229
 
    virtual RS_Vector getNearestRef(const RS_Vector& coord,
230
 
                                     double* dist = NULL);
231
 
 
232
 
    virtual void move(RS_Vector offset);
233
 
    virtual void rotate(RS_Vector center, double angle);
234
 
    virtual void scale(RS_Vector center, RS_Vector factor);
235
 
    virtual void mirror(RS_Vector axisPoint1, RS_Vector axisPoint2);
236
 
        virtual bool hasEndpointsWithinWindow(RS_Vector v1, RS_Vector v2);
237
 
    virtual void stretch(RS_Vector firstCorner,
238
 
                         RS_Vector secondCorner,
239
 
                         RS_Vector offset);
240
 
 
241
 
    friend std::ostream& operator << (std::ostream& os, const RS_Text& p);
242
 
 
243
 
protected:
244
 
    RS_TextData data;
245
 
 
246
 
    /**
247
 
     * Text width used by the current contents of this text entity. 
248
 
     * This property is updated by the update method.
249
 
     * @see update
250
 
     */
251
 
    double usedTextWidth;
252
 
    /**
253
 
     * Text height used by the current contents of this text entity.
254
 
     * This property is updated by the update method.
255
 
     * @see update
256
 
     */
257
 
    double usedTextHeight;
258
 
};
259
 
 
260
 
#endif