Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgMText.java @ 2896

History | View | Annotate | Download (9.58 KB)

1
/* jdwglib. Java Library for reading Dwg files.
2
 * 
3
 * Author: Jose Morell Rama (jose.morell@gmail.com).
4
 * Port from the Pythoncad Dwg library by Art Haas.
5
 *
6
 * Copyright (C) 2005 Jose Morell, IVER TI S.A. and Generalitat Valenciana
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 * Jose Morell (jose.morell@gmail.com)
25
 * 
26
 * or
27
 *
28
 * IVER TI S.A.
29
 *  C/Salamanca, 50
30
 *  46005 Valencia
31
 *  Spain
32
 *  +34 963163400
33
 *  dac@iver.es
34
 */
35
package com.iver.cit.jdwglib.dwg.objects;
36

    
37
import java.util.Vector;
38

    
39
import com.iver.cit.jdwglib.dwg.DwgObject;
40
import com.iver.cit.jdwglib.dwg.DwgUtil;
41

    
42
/**
43
 * The DwgMText class represents a DWG MText
44
 * 
45
 * @author jmorell
46
 */
47
public class DwgMText extends DwgObject {
48
        private double[] insertionPoint;
49
        private double[] extrusion;
50
        private double[] xAxisDirection;
51
        private double width;
52
        private double height;
53
        private int attachment;
54
        private int drawingDir;
55
        private double extHeight;
56
        private double extWidth;
57
        private String text;
58
        private int lineSpacingStyle;
59
        private double lineSpacingFactor;
60
        private int styleHandle;
61
        
62
        /**
63
         * Read a MText in the DWG format Version 15
64
         * 
65
         * @param data Array of unsigned bytes obtained from the DWG binary file
66
         * @param offset The current bit offset where the value begins
67
         * @throws Exception If an unexpected bit value is found in the DWG file. Occurs
68
         *                    when we are looking for LwPolylines.
69
         */
70
        public void readDwgMTextV15(int[] data, int offset) throws Exception {
71
                int bitPos = offset;
72
                bitPos = readObjectHeaderV15(data, bitPos);
73
                Vector v = DwgUtil.getBitDouble(data, bitPos);
74
                bitPos = ((Integer)v.get(0)).intValue();
75
                double x = ((Double)v.get(1)).doubleValue();
76
                v = DwgUtil.getBitDouble(data, bitPos);
77
                bitPos = ((Integer)v.get(0)).intValue();
78
                double y = ((Double)v.get(1)).doubleValue();
79
                v = DwgUtil.getBitDouble(data, bitPos);
80
                bitPos = ((Integer)v.get(0)).intValue();
81
                double z = ((Double)v.get(1)).doubleValue();
82
                double[] coord = new double[]{x, y, z};
83
                insertionPoint = coord;
84
                v = DwgUtil.getBitDouble(data, bitPos);
85
                bitPos = ((Integer)v.get(0)).intValue();
86
                x = ((Double)v.get(1)).doubleValue();
87
                v = DwgUtil.getBitDouble(data, bitPos);
88
                bitPos = ((Integer)v.get(0)).intValue();
89
                y = ((Double)v.get(1)).doubleValue();
90
                v = DwgUtil.getBitDouble(data, bitPos);
91
                bitPos = ((Integer)v.get(0)).intValue();
92
                z = ((Double)v.get(1)).doubleValue();
93
                coord = new double[]{x, y, z};
94
                extrusion = coord;
95
                v = DwgUtil.getBitDouble(data, bitPos);
96
                bitPos = ((Integer)v.get(0)).intValue();
97
                x = ((Double)v.get(1)).doubleValue();
98
                v = DwgUtil.getBitDouble(data, bitPos);
99
                bitPos = ((Integer)v.get(0)).intValue();
100
                y = ((Double)v.get(1)).doubleValue();
101
                v = DwgUtil.getBitDouble(data, bitPos);
102
                bitPos = ((Integer)v.get(0)).intValue();
103
                z = ((Double)v.get(1)).doubleValue();
104
                coord = new double[]{x, y, z};
105
                xAxisDirection = coord;
106
                v = DwgUtil.getBitDouble(data, bitPos);
107
                bitPos = ((Integer)v.get(0)).intValue();
108
                double val = ((Double)v.get(1)).doubleValue();
109
                width = val;
110
                v = DwgUtil.getBitDouble(data, bitPos);
111
                bitPos = ((Integer)v.get(0)).intValue();
112
                val = ((Double)v.get(1)).doubleValue();
113
                height = val;
114
                v = DwgUtil.getBitShort(data, bitPos);
115
                bitPos = ((Integer)v.get(0)).intValue();
116
                int ival = ((Integer)v.get(1)).intValue();
117
                attachment = ival;
118
                v = DwgUtil.getBitShort(data, bitPos);
119
                bitPos = ((Integer)v.get(0)).intValue();
120
                ival = ((Integer)v.get(1)).intValue();
121
                drawingDir = ival;
122
                v = DwgUtil.getBitDouble(data, bitPos);
123
                bitPos = ((Integer)v.get(0)).intValue();
124
                val = ((Double)v.get(1)).doubleValue();
125
                extHeight = val;
126
                v = DwgUtil.getBitDouble(data, bitPos);
127
                bitPos = ((Integer)v.get(0)).intValue();
128
                val = ((Double)v.get(1)).doubleValue();
129
                extWidth = val;
130
                v = DwgUtil.getTextString(data, bitPos);
131
                bitPos = ((Integer)v.get(0)).intValue();
132
                String text = (String)v.get(1);
133
                this.text = text;
134
                v = DwgUtil.getBitShort(data, bitPos);
135
                bitPos = ((Integer)v.get(0)).intValue();
136
                ival = ((Integer)v.get(1)).intValue();
137
                lineSpacingStyle = ival;
138
                v = DwgUtil.getBitDouble(data, bitPos);
139
                bitPos = ((Integer)v.get(0)).intValue();
140
                val = ((Double)v.get(1)).doubleValue();
141
                lineSpacingFactor = val;
142
                v = DwgUtil.testBit(data, bitPos);
143
                bitPos = ((Integer)v.get(0)).intValue();
144
                boolean flag = ((Boolean)v.get(1)).booleanValue();
145
                bitPos = readObjectTailV15(data, bitPos);
146
                v = DwgUtil.getHandle(data, bitPos);
147
                bitPos = ((Integer)v.get(0)).intValue();
148
                int[] handle = new int[v.size()-1];
149
            for (int j=1;j<v.size();j++) {
150
                    handle[j-1] = ((Integer)v.get(j)).intValue();
151
            }
152
            Vector handleVect = new Vector();
153
            for (int i=0;i<handle.length;i++) {
154
                    handleVect.add(new Integer(handle[i]));
155
            }
156
            styleHandle = DwgUtil.handleBinToHandleInt(handleVect);
157
        }
158
        /**
159
         * @return Returns the height.
160
         */
161
        public double getHeight() {
162
                return height;
163
        }
164
        /**
165
         * @param height The height to set.
166
         */
167
        public void setHeight(double height) {
168
                this.height = height;
169
        }
170
        /**
171
         * @return Returns the insertionPoint.
172
         */
173
        public double[] getInsertionPoint() {
174
                return insertionPoint;
175
        }
176
        /**
177
         * @param insertionPoint The insertionPoint to set.
178
         */
179
        public void setInsertionPoint(double[] insertionPoint) {
180
                this.insertionPoint = insertionPoint;
181
        }
182
        /**
183
         * @return Returns the text.
184
         */
185
        public String getText() {
186
                return text;
187
        }
188
        /**
189
         * @param text The text to set.
190
         */
191
        public void setText(String text) {
192
                this.text = text;
193
        }
194
        /**
195
         * @return Returns the width.
196
         */
197
        public double getWidth() {
198
                return width;
199
        }
200
        /**
201
         * @param width The width to set.
202
         */
203
        public void setWidth(double width) {
204
                this.width = width;
205
        }
206
    /**
207
     * @return Returns the extrusion.
208
     */
209
    public double[] getExtrusion() {
210
        return extrusion;
211
    }
212
        /* (non-Javadoc)
213
         * @see java.lang.Object#clone()
214
         */
215
        public Object clone() {
216
                DwgMText dwgMText = new DwgMText();
217
                dwgMText.setType(type);
218
                dwgMText.setHandle(handle);
219
                dwgMText.setVersion(version);
220
                dwgMText.setMode(mode);
221
                dwgMText.setLayerHandle(layerHandle);
222
                dwgMText.setColor(color);
223
                dwgMText.setNumReactors(numReactors);
224
                dwgMText.setNoLinks(noLinks);
225
                dwgMText.setLinetypeFlags(linetypeFlags);
226
                dwgMText.setPlotstyleFlags(plotstyleFlags);
227
                dwgMText.setSizeInBits(sizeInBits);
228
                dwgMText.setExtendedData(extendedData);
229
                dwgMText.setGraphicData(graphicData);
230
                //dwgMText.setInsideBlock(insideBlock);
231
                dwgMText.setInsertionPoint(insertionPoint);
232
                dwgMText.setXAxisDirection(xAxisDirection);
233
                dwgMText.setExtrusion(extrusion);
234
                dwgMText.setWidth(width);
235
                dwgMText.setHeight(height);
236
                dwgMText.setAttachment(attachment);
237
                dwgMText.setDrawingDir(drawingDir);
238
                dwgMText.setExtHeight(extHeight);
239
                dwgMText.setExtWidth(extWidth);
240
                dwgMText.setText(text);
241
                dwgMText.setLineSpacingStyle(lineSpacingStyle);
242
                dwgMText.setLineSpacingFactor(lineSpacingFactor);
243
                dwgMText.setStyleHandle(styleHandle);
244
                return dwgMText;
245
        }
246
        /**
247
         * @return Returns the attachment.
248
         */
249
        public int getAttachment() {
250
                return attachment;
251
        }
252
        /**
253
         * @param attachment The attachment to set.
254
         */
255
        public void setAttachment(int attachment) {
256
                this.attachment = attachment;
257
        }
258
        /**
259
         * @return Returns the drawingDir.
260
         */
261
        public int getDrawingDir() {
262
                return drawingDir;
263
        }
264
        /**
265
         * @param drawingDir The drawingDir to set.
266
         */
267
        public void setDrawingDir(int drawingDir) {
268
                this.drawingDir = drawingDir;
269
        }
270
        /**
271
         * @return Returns the extHeight.
272
         */
273
        public double getExtHeight() {
274
                return extHeight;
275
        }
276
        /**
277
         * @param extHeight The extHeight to set.
278
         */
279
        public void setExtHeight(double extHeight) {
280
                this.extHeight = extHeight;
281
        }
282
        /**
283
         * @return Returns the extWidth.
284
         */
285
        public double getExtWidth() {
286
                return extWidth;
287
        }
288
        /**
289
         * @param extWidth The extWidth to set.
290
         */
291
        public void setExtWidth(double extWidth) {
292
                this.extWidth = extWidth;
293
        }
294
        /**
295
         * @return Returns the lineSpacingFactor.
296
         */
297
        public double getLineSpacingFactor() {
298
                return lineSpacingFactor;
299
        }
300
        /**
301
         * @param lineSpacingFactor The lineSpacingFactor to set.
302
         */
303
        public void setLineSpacingFactor(double lineSpacingFactor) {
304
                this.lineSpacingFactor = lineSpacingFactor;
305
        }
306
        /**
307
         * @return Returns the lineSpacingStyle.
308
         */
309
        public int getLineSpacingStyle() {
310
                return lineSpacingStyle;
311
        }
312
        /**
313
         * @param lineSpacingStyle The lineSpacingStyle to set.
314
         */
315
        public void setLineSpacingStyle(int lineSpacingStyle) {
316
                this.lineSpacingStyle = lineSpacingStyle;
317
        }
318
        /**
319
         * @return Returns the styleHandle.
320
         */
321
        public int getStyleHandle() {
322
                return styleHandle;
323
        }
324
        /**
325
         * @param styleHandle The styleHandle to set.
326
         */
327
        public void setStyleHandle(int styleHandle) {
328
                this.styleHandle = styleHandle;
329
        }
330
        /**
331
         * @return Returns the xAxisDirection.
332
         */
333
        public double[] getXAxisDirection() {
334
                return xAxisDirection;
335
        }
336
        /**
337
         * @param axisDirection The xAxisDirection to set.
338
         */
339
        public void setXAxisDirection(double[] axisDirection) {
340
                xAxisDirection = axisDirection;
341
        }
342
        /**
343
         * @param extrusion The extrusion to set.
344
         */
345
        public void setExtrusion(double[] extrusion) {
346
                this.extrusion = extrusion;
347
        }
348
}