1
/****************************************************************************
3
** This file is part of the LibreCAD project, a 2D CAD program
5
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
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.
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.
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
23
** This copyright notice MUST APPEAR in all copies of the script!
25
**********************************************************************/
31
#include "rs_entitycontainer.h"
34
* Holds the data that defines a text entity.
39
* Default constructor. Leaves the data object uninitialized.
44
* Constructor with initialisation.
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.
63
RS_TextData(const RS_Vector& insertionPoint,
68
RS2::TextDrawingDirection drawingDirection,
69
RS2::TextLineSpacingStyle lineSpacingStyle,
70
double lineSpacingFactor,
74
RS2::UpdateMode updateMode = RS2::Update) {
75
this->insertionPoint = insertionPoint;
76
this->height = height;
78
this->valign = valign;
79
this->halign = halign;
80
this->drawingDirection = drawingDirection;
81
this->lineSpacingStyle = lineSpacingStyle;
82
this->lineSpacingFactor = lineSpacingFactor;
86
this->updateMode = updateMode;
91
friend std::ostream& operator << (std::ostream& os, const RS_TextData& td) {
92
os << "(" << td.text.toLatin1().data() << ")";
97
/** Insertion point */
98
RS_Vector insertionPoint;
99
/** Nominal (initial) text height */
101
/** Reference rectangle width */
103
/** Vertical alignment */
105
/** Horizontal alignment */
107
/** Drawing direction */
108
RS2::TextDrawingDirection drawingDirection;
109
/** Line spacing style */
110
RS2::TextLineSpacingStyle lineSpacingStyle;
111
/** Line spacing factor */
112
double lineSpacingFactor;
115
/** Text style name */
117
/** Rotation angle */
120
RS2::UpdateMode updateMode;
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.
131
* @author Andrew Mustun
133
class RS_Text : public RS_EntityContainer {
135
RS_Text(RS_EntityContainer* parent,
136
const RS_TextData& d);
137
virtual ~RS_Text() {}
139
virtual RS_Entity* clone() {
140
RS_Text* t = new RS_Text(*this);
141
t->setOwner(isOwner());
147
/** @return RS2::EntityText */
148
virtual RS2::EntityType rtti() const {
149
return RS2::EntityText;
152
/** @return Copy of data that defines the text. */
153
RS_TextData getData() const {
158
void updateAddLine(RS_EntityContainer* textLine, int lineCounter);
160
int getNumberOfLines();
163
RS_Vector getInsertionPoint() {
164
return data.insertionPoint;
169
void setHeight(double h) {
175
void setAlignment(int a);
177
RS2::VAlign getVAlign() {
180
void setVAlign(RS2::VAlign va) {
183
RS2::HAlign getHAlign() {
186
void setHAlign(RS2::HAlign ha) {
189
RS2::TextDrawingDirection getDrawingDirection() {
190
return data.drawingDirection;
192
RS2::TextLineSpacingStyle getLineSpacingStyle() {
193
return data.lineSpacingStyle;
195
void setLineSpacingFactor(double f) {
196
data.lineSpacingFactor = f;
198
double getLineSpacingFactor() {
199
return data.lineSpacingFactor;
201
void setText(const QString& t);
205
void setStyle(const QString& s) {
211
void setAngle(double a) {
217
double getUsedTextWidth() {
218
return usedTextWidth;
220
double getUsedTextHeight() {
221
return usedTextHeight;
224
virtual double getLength() {
228
virtual RS_VectorSolutions getRefPoints();
229
virtual RS_Vector getNearestRef(const RS_Vector& coord,
230
double* dist = NULL);
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,
241
friend std::ostream& operator << (std::ostream& os, const RS_Text& p);
247
* Text width used by the current contents of this text entity.
248
* This property is updated by the update method.
251
double usedTextWidth;
253
* Text height used by the current contents of this text entity.
254
* This property is updated by the update method.
257
double usedTextHeight;