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
* Vertical alignments.
43
VAMiddle, /**< Middle */
44
VABottom /**< Bottom */
48
* Horizontal alignments.
52
HACenter, /**< Centered */
57
* MText drawing direction.
59
enum MTextDrawingDirection {
60
LeftToRight, /**< Left to right */
61
TopToBottom, /**< Top to bottom */
62
ByStyle /**< Inherited from associated text style */
66
* Line spacing style for MTexts.
68
enum MTextLineSpacingStyle {
69
AtLeast, /**< Taller characters will override */
70
Exact /**< Taller characters will not override */
74
* Default constructor. Leaves the data object uninitialized.
79
* Constructor with initialisation.
81
* @param insertionPoint Insertion point
82
* @param height Nominal (initial) text height
83
* @param width Reference rectangle width
84
* @param valign Vertical alignment
85
* @param halign Horizontal alignment
86
* @param drawingDirection Drawing direction
87
* @param lineSpacingStyle Line spacing style
88
* @param lineSpacingFactor Line spacing factor
89
* @param text Text string
90
* @param style Text style name
91
* @param angle Rotation angle
92
* @param updateMode RS2::Update will update the text entity instantly
93
* RS2::NoUpdate will not update the entity. You can update
94
* it later manually using the update() method. This is
95
* often the case since you might want to adjust attributes
96
* after creating a text entity.
98
RS_MTextData(const RS_Vector& insertionPoint,
103
MTextDrawingDirection drawingDirection,
104
MTextLineSpacingStyle lineSpacingStyle,
105
double lineSpacingFactor,
107
const QString& style,
109
RS2::UpdateMode updateMode = RS2::Update) {
110
this->insertionPoint = insertionPoint;
111
this->height = height;
113
this->valign = valign;
114
this->halign = halign;
115
this->drawingDirection = drawingDirection;
116
this->lineSpacingStyle = lineSpacingStyle;
117
this->lineSpacingFactor = lineSpacingFactor;
121
this->updateMode = updateMode;
124
friend class RS_MText;
126
friend std::ostream& operator << (std::ostream& os, const RS_MTextData& td) {
127
os << "(" << td.text.toLatin1().data() << ")";
132
/** Insertion point */
133
RS_Vector insertionPoint;
134
/** Nominal (initial) text height */
136
/** Reference rectangle width */
138
/** Vertical alignment */
140
/** Horizontal alignment */
142
/** Drawing direction */
143
MTextDrawingDirection drawingDirection;
144
/** Line spacing style */
145
MTextLineSpacingStyle lineSpacingStyle;
146
/** Line spacing factor */
147
double lineSpacingFactor;
150
/** Text style name */
152
/** Rotation angle */
155
RS2::UpdateMode updateMode;
161
* Class for a text entity.
162
* Please note that text strings can contain special
163
* characters such as %%c for a diameter sign as well as unicode
164
* characters. Line feeds are stored as real line feeds in the string.
166
* @author Andrew Mustun
168
class RS_MText : public RS_EntityContainer {
170
RS_MText(RS_EntityContainer* parent,
171
const RS_MTextData& d);
172
virtual ~RS_MText() {}
174
virtual RS_Entity* clone() {
175
RS_MText* t = new RS_MText(*this);
176
t->setOwner(isOwner());
182
/** @return RS2::EntityText */
183
virtual RS2::EntityType rtti() const {
184
return RS2::EntityMText;
187
/** @return Copy of data that defines the text. */
188
RS_MTextData getData() const {
194
int getNumberOfLines();
197
RS_Vector getInsertionPoint() {
198
return data.insertionPoint;
203
void setHeight(double h) {
209
void setAlignment(int a);
211
RS_MTextData::VAlign getVAlign() {
214
void setVAlign(RS_MTextData::VAlign va) {
217
RS_MTextData::HAlign getHAlign() {
220
void setHAlign(RS_MTextData::HAlign ha) {
223
RS_MTextData::MTextDrawingDirection getDrawingDirection() {
224
return data.drawingDirection;
226
RS_MTextData::MTextLineSpacingStyle getLineSpacingStyle() {
227
return data.lineSpacingStyle;
229
void setLineSpacingFactor(double f) {
230
data.lineSpacingFactor = f;
232
double getLineSpacingFactor() {
233
return data.lineSpacingFactor;
235
void setText(const QString& t);
239
void setStyle(const QString& s) {
245
void setAngle(double a) {
251
double getUsedTextWidth() {
252
return usedTextWidth;
254
double getUsedTextHeight() {
255
return usedTextHeight;
258
// virtual double getLength() const {
263
* @return The insertion point as endpoint.
265
virtual RS_Vector getNearestEndpoint(const RS_Vector& coord,
266
double* dist = NULL)const;
267
virtual RS_VectorSolutions getRefPoints();
268
virtual RS_Vector getNearestRef(const RS_Vector& coord,
269
double* dist = NULL);
271
virtual void move(const RS_Vector& offset);
272
virtual void rotate(const RS_Vector& center, const double& angle);
273
virtual void rotate(const RS_Vector& center, const RS_Vector& angleVector);
274
virtual void scale(const RS_Vector& center, const RS_Vector& factor);
275
virtual void mirror(const RS_Vector& axisPoint1, const RS_Vector& axisPoint2);
276
virtual bool hasEndpointsWithinWindow(const RS_Vector& v1, const RS_Vector& v2);
277
virtual void stretch(const RS_Vector& firstCorner,
278
const RS_Vector& secondCorner,
279
const RS_Vector& offset);
281
friend std::ostream& operator << (std::ostream& os, const RS_Text& p);
284
double updateAddLine(RS_EntityContainer* textLine, int lineCounter);
290
* Text width used by the current contents of this text entity.
291
* This property is updated by the update method.
294
double usedTextWidth;
296
* Text height used by the current contents of this text entity.
297
* This property is updated by the update method.
300
double usedTextHeight;