Revision 935

View differences:

tags/org.gvsig.dwg-2.0.197/org.gvsig.dwg.lib/src/test/java/org/gvsig/dwg/lib/DwgTestSuite.java
1
/*
2
 * Created on 08-feb-2007
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. 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
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id: DwgTestSuite.java 28970 2009-05-25 13:27:14Z jmvivo $
47
* $Log$
48
* Revision 1.1.2.1  2007-02-28 07:35:10  jmvivo
49
* Actualizado desde el HEAD.
50
*
51
* Revision 1.1  2007/02/08 20:27:57  azabala
52
* *** empty log message ***
53
*
54
*
55
*/
56
package org.gvsig.dwg.lib;
57

  
58
import junit.framework.Test;
59
import junit.framework.TestSuite;
60

  
61
public class DwgTestSuite {
62

  
63
	public static Test suite() {
64
		TestSuite suite = new TestSuite("Test for com.iver.cit.jdwglib.dwg");
65
		//$JUnit-BEGIN$
66
		suite.addTestSuite(DwgFileTest.class);
67
		//$JUnit-END$
68
		return suite;
69
	}
70

  
71
}
72

  
tags/org.gvsig.dwg-2.0.197/org.gvsig.dwg.lib/src/test/java/org/gvsig/dwg/lib/DwgFileTest.java
1
package org.gvsig.dwg.lib;
2

  
3
import java.io.File;
4
import java.io.IOException;
5
import java.net.URL;
6

  
7
import junit.framework.TestCase;
8

  
9
public class DwgFileTest extends TestCase {
10
	private File baseDataPath;
11

  
12
	protected void setUp() throws Exception {
13
		super.setUp();
14
		URL url = this.getClass().getResource("data");
15
		if (url == null) {
16
			throw new Exception("Can't find 'data' dir");
17
		}
18

  
19
		baseDataPath = new File(url.getFile());
20
		if (!baseDataPath.exists()) {
21
			throw new Exception("Can't find 'data' dir");
22
		}
23

  
24
	}
25

  
26
	protected void tearDown() throws Exception {
27
		super.tearDown();
28
	}
29
	public void test1() throws IOException, DwgVersionNotSupportedException {
30
//		String fileName = baseDataPath.getAbsolutePath()+"/Un punto.dwg";
31
//		DwgFile dwg = new DwgFile(fileName);
32
//
33
//		dwg.read();
34
//		dwg.calculateGisModelDwgPolylines();
35
//		dwg.blockManagement();
36
//		LinkedList dwgObjects = dwg.getDwgObjects();
37
	}
38

  
39
	public void test2() throws RuntimeException, CorruptedDwgEntityException{
40
        //Dwg Object that is supposed to be
41
        //an LWPOLYLINE in V14 version
42
		/*
43
        int[] data = new int[]{61,64,64,183,19,227,104,16
44
                            ,0,5,8,59,72,32,252,47,90,142,
45
                            234,145,50,10,71,11,213,36,229,
46
                            162,130,10,228,126,23,174,130,
47
                            145,50,15,98,141,196,244,229,
48
                            162,130,12,126,23,169,66,58,
49
                            145,50,12,47,90,138,68,229,
50
                            162,130,8,0,0,4,7,74,137,50,
51
                            15,177,66,231,252,221,162,130,
52
                            9,130,151,21,242,151,21,190,
53
                            8,21,8,56};
54
         */
55
//		int[] data = new int[]{62,128,64,71,99,
56
//							   40,48,0,5,8,27,72,
57
//							   100,126,23,169,68,
58
//							   178,105,50,13,114,
59
//							   63,11,82,165,162,130,
60
//							   13,114,63,11,210,138,
61
//							   105,50,8,173,114,59,
62
//							   138,205,162,130,15,98,
63
//							   141,192,241,58,105,50,
64
//							   11,51,51,52,178,229,162,
65
//							   130,14,110,102,98,97,234,
66
//							   105,50,11,51,51,52,179,21,
67
//							   162,130,10,149,192,240,42,
68
//							   162,105,50,14,189,27,131,
69
//							   107,69,162,130,14,31,169,
70
//							   66,227,74,105,50,9,240,86,
71
//							   185,27,117,162,130,11,59,
72
//							   51,51,52,234,105,50,13,114,
73
//							   63,11,83,85,162,130,9,74,228,
74
//							   126,22,186,105,50,11,51,51,50,
75
//							   51,53,162,130,11,137,232,82,190,
76
//							   58,105,50,9,74,228,122,147,13,162,
77
//							   130,11,137,232,82,189,106,105,50,9,
78
//							   74,228,122,146,213,162,130,9,74,228,122,20,202,105,50,12,126,23,171,194,173,162,130,12,126,23,169,68,178,105,50,13,114,63,11,82,165,162,130,9,130,151,22,10,136,182,8,21,8,120};
79
//        //1er intento: suponemos que la LWPOLYLINE cumple la especificaci?n
80
//        //a rajatabla
81
//        int bitPos = 0;
82
//        List val = DwgUtil.getBitShort(data, bitPos);
83
//        bitPos = ((Integer) val.get(0)).intValue();
84
//        int type = ((Integer) val.get(1)).intValue();
85
//        System.out.println("type = " + type);
86
//
87
//        DwgHandleReference hr = new DwgHandleReference();
88
//        bitPos = hr.read(data, bitPos);
89
//        System.out.println("handle, code="+
90
//                    hr.getCode()+
91
//                    " ,offset="+
92
//                    hr.getOffset());
93
//
94
//        //Ahora pasamos a la extended data
95
//        val = DwgUtil.getBitShort(data, bitPos);
96
//        bitPos = ((Integer) val.get(0)).intValue();
97
//        int extendedDataSize = ((Integer) val.get(1)).intValue();
98
//        System.out.println("EED size="+extendedDataSize);
99
//        //como el size es 0, me lo salto
100
//
101
//        //ver si tiene datos graficos
102
//        val = DwgUtil.testBit(data, bitPos);
103
//        bitPos = ((Integer) val.get(0)).intValue();
104
//        boolean hasGraphicsData = ((Boolean) val.get(1))
105
//                .booleanValue();
106
//        System.out.println("graphics = "+hasGraphicsData);
107
//
108
//        //como se que no hay graphics me lo salto
109
//        //tama?o en bits
110
//        val = DwgUtil.getRawLong(data, bitPos);
111
//        bitPos = ((Integer) val.get(0)).intValue();
112
//        int sizeInBits = ((Integer) val.get(1)).intValue();
113
//        System.out.println("sizeInBits = "+sizeInBits);
114
//
115
//        /*
116
//         * Ahora, lo que viene es lo que en la spec se dice
117
//         * "Common entity data". Revisar bien pues PythonCAD no lo lee
118
//         * como en la spec.
119
//         *
120
//         * pag 42.
121
//          R13-R14 Only:
122
//          	RL	:	Size of object data in bits
123
//          	6B	:	Flags (FEDCBA)
124
//          	6B	:	Common parameters (CCSSII)
125
//          	Segun esto, deberia leer 6 bits y 6 bits
126
//
127
//          	FLAGS
128
//	      	Mas adelante (pag 43), dice:
129
//	      	DC	:	This is the number of reactors attached to an
130
//	      	entity as a bitshort.
131
//	      	This feature may have been dormant in R13,
132
//	      	but it appears in R14, and in files saved as R13 by R14.
133
//
134
//	      	Ahora bien, pythoncad las est? leyendo como bitLong
135
//          	?En que quedamos, son 2 bits, 1 bitLong o 1 bitShort?
136
//          	TODO REVISAR
137
//
138
//          	COMMON PARAMETERS
139
//          	Al principio, dice que son 6 bits (CC, SS, II)
140
//          	pero luego dice (pag 43):
141
//          	CC	:	Color bitshort
142
//          	SS	:	Linetype scale bitdouble
143
//          	II	:	"Invisible" flag bitshort
144
//
145
//			Pythoncad, en vez de como 2 bits, los est? leyendo
146
//			como BitShort, BitDouble y BitShort
147
//
148
//         * */
149
//
150
//        Integer mode = (Integer) DwgUtil.getBits(data, 2, bitPos);
151
//		bitPos += 2;
152
//		System.out.println("mode = "+mode);
153
//
154
//	/*
155
//		val = DwgUtil.getBitLong(data, bitPos);
156
//		bitPos = ((Integer) val.get(0)).intValue();
157
//		int rnum = ((Integer) val.get(1)).intValue();
158
//		System.out.println("numReactors = "+rnum);
159
//*/
160
//		val = DwgUtil.getBitShort(data, bitPos);
161
//		bitPos = ((Integer) val.get(0)).intValue();
162
//		int rnum = ((Integer) val.get(1)).intValue();
163
//		System.out.println("numReactors = "+rnum);
164
//
165
//
166
//		val = DwgUtil.testBit(data, bitPos);
167
//		bitPos = ((Integer) val.get(0)).intValue();
168
//		boolean isLyrByLineType = ((Boolean) val.get(1)).booleanValue();
169
//		System.out.println("isLyrByLineType="+isLyrByLineType);
170
//
171
//		val = DwgUtil.testBit(data, bitPos);
172
//		bitPos = ((Integer) val.get(0)).intValue();
173
//		boolean noLinks = ((Boolean) val.get(1)).booleanValue();
174
//		System.out.println("noLinks="+noLinks);
175
//
176
//
177
//		val = DwgUtil.getBitShort(data, bitPos);
178
//		bitPos = ((Integer) val.get(0)).intValue();
179
//		int color = ((Integer) val.get(1)).intValue();
180
//		System.out.println("color="+color);
181
//
182
//
183
//		val = DwgUtil.getBitDouble(data, bitPos);
184
//		bitPos = ((Integer) val.get(0)).intValue();
185
//		float ltscale = ((Double) val.get(1)).floatValue();
186
//		System.out.println("ltscale="+ltscale);
187
//
188
//		val = DwgUtil.getBitShort(data, bitPos);
189
//		bitPos = ((Integer) val.get(0)).intValue();
190
//		int invis = ((Integer) val.get(1)).intValue();
191
//		System.out.println("invis="+invis);
192
//
193
//		val = DwgUtil.getBitShort(data, bitPos);
194
//		bitPos = ((Integer) val.get(0)).intValue();
195
//		int flag = ((Integer) val.get(1)).intValue();
196
//		System.out.println("flag="+flag);
197
//
198
//		double dVal = 0d;
199
//		if((flag & 0x4) > 0){
200
//			val = DwgUtil.getBitDouble(data, bitPos);
201
//			bitPos = ((Integer) val.get(0)).intValue();
202
//			dVal = ((Double) val.get(1)).doubleValue();
203
//		}
204
//		System.out.println("constWidth="+dVal);
205
//
206
//		dVal = 0d;
207
//		if((flag & 0x8) > 0){
208
//			val = DwgUtil.getBitDouble(data, bitPos);
209
//			bitPos = ((Integer) val.get(0)).intValue();
210
//			dVal = ((Double) val.get(1)).doubleValue();
211
//		}
212
//		System.out.println("elevation="+dVal);
213
//
214
//		dVal = 0d;
215
//		if ((flag & 0x2) > 0){
216
//			val = DwgUtil.getBitDouble(data, bitPos);
217
//			bitPos = ((Integer) val.get(0)).intValue();
218
//			dVal = ((Double) val.get(1)).doubleValue();
219
//		}
220
//		System.out.println("thickness="+dVal);
221
//
222
//		double x, y, z ;
223
//		x = 0d;
224
//		y = 0d;
225
//		z = 0d;
226
//
227
//		if ((flag & 0x1) > 0){
228
//			val = DwgUtil.getBitDouble(data, bitPos);
229
//			bitPos = ((Integer) val.get(0)).intValue();
230
//			x = ((Double) val.get(1)).doubleValue();
231
//
232
//			val = DwgUtil.getBitDouble(data, bitPos);
233
//			bitPos = ((Integer) val.get(0)).intValue();
234
//			y = ((Double) val.get(1)).doubleValue();
235
//
236
//			val = DwgUtil.getBitDouble(data, bitPos);
237
//			bitPos = ((Integer) val.get(0)).intValue();
238
//			z = ((Double) val.get(1)).doubleValue();
239
//		}
240
//		System.out.println("normal="+x+","+y+","+z);
241
//
242
//		val = DwgUtil.getBitLong(data, bitPos);
243
//		bitPos = ((Integer) val.get(0)).intValue();
244
//		int np = ((Integer) val.get(1)).intValue();
245
//		System.out.println("numPoints="+np);
246
//
247
//		int nb = 0;
248
//		if((flag & 0x10) > 0){
249
//			val = DwgUtil.getBitLong(data, bitPos);
250
//			bitPos = ((Integer) val.get(0)).intValue();
251
//			nb = ((Integer) val.get(1)).intValue();
252
//		}
253
//		System.out.println("numBulges="+nb);
254
//		int nw = 0;
255
//		if((flag & 0x20) > 0){
256
//			val = DwgUtil.getBitLong(data, bitPos);
257
//			bitPos = ((Integer) val.get(0)).intValue();
258
//			nw = ((Integer) val.get(1)).intValue();
259
//		}
260
//		System.out.println("numWidths="+nw);
261
//		if(np > 0){
262
//			Point2D[] points = new Point2D[np];
263
//			for(int i = 0; i < np; i++){
264
//				val = DwgUtil.getRawDouble(data, bitPos);
265
//				bitPos = ((Integer) val.get(0)).intValue();
266
//				x = ((Double) val.get(1)).doubleValue();
267
//
268
//				val = DwgUtil.getRawDouble(data, bitPos);
269
//				bitPos = ((Integer) val.get(0)).intValue();
270
//				y = ((Double) val.get(1)).doubleValue();
271
//
272
//				points[i] = new Point2D.Double(x, y);
273
//				System.out.println("Punto"+i+"="+x+","+y);
274
//			}//for
275
//		}//if np
276
//
277
//		if(nb > 0){
278
//			double[] bulges = new double[nb];
279
//			for(int i = 0; i < nb; i++){
280
//				val = DwgUtil.getRawDouble(data, bitPos);
281
//				bitPos = ((Integer) val.get(0)).intValue();
282
//				bulges[i] = ((Double) val.get(1)).doubleValue();
283
//				System.out.println("Bulge"+i+"="+bulges[i]);
284
//			}//for
285
//
286
//		}//if nb
287
//
288
//		if(nw > 0){
289
//			double[][] widths = new double[nw][2];
290
//			for(int i = 0; i < nw; i++){
291
//				val = DwgUtil.getBitDouble(data, bitPos);
292
//				bitPos = ((Integer) val.get(0)).intValue();
293
//				double sw = ((Double) val.get(1)).doubleValue();
294
//
295
//				val = DwgUtil.getBitDouble(data, bitPos);
296
//				bitPos = ((Integer) val.get(0)).intValue();
297
//				double ew = ((Double) val.get(1)).doubleValue();
298
//
299
//				widths[i][0] = sw;
300
//				widths[i][1] = ew;
301
//				System.out.println("Width"+i+"="+sw+","+ew);
302
//			}//for
303
//		}
304
     }
305

  
306
	public void test3(){
307
		//test of extrusion
308
		double[] coord = null;
309
		double[] extrusion = null;
310
		double[] extrusion2 = new double[]{0, 0, 1};
311

  
312
		coord = new double[]{790089.65, 4477974.75, 9.560000000114087};
313
		extrusion = new double[]{-0.5037965987025721, 0.07005064807841195, 0.8609772899673451};
314
		//1. algoritmo original, vector normal distinto
315
//		double[] newCoord = AcadExtrusionCalculator.extrude(coord, extrusion);
316
//		newCoord = AcadExtrusionCalculator.extrude3(coord, extrusion);
317
//
318
		//2? ahora con vector normal coincidente con eje Z
319
//		newCoord = AcadExtrusionCalculator.extrude(coord, extrusion2);
320
//		newCoord = AcadExtrusionCalculator.extrude3(coord, extrusion2);
321
	}
322
}
tags/org.gvsig.dwg-2.0.197/org.gvsig.dwg.lib/src/main/java/org/gvsig/dwg/lib/util/ByteUtils.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.dwg.lib.util;
42
import java.math.BigInteger;
43

  
44

  
45
/**
46
 * Clase que engloba m?todos para trabajar con bytes. 
47
 *
48
 * @author Vicente Caballero Navarro
49
 */
50
public class ByteUtils {
51
	public static final int SIZE_BOOL = 1;
52
	public static final int SIZE_SHORT = 2;
53
	public static final int SIZE_INT = 4;
54
	public static final int SIZE_LONG = 8;
55
	public static final int SIZE_DOUBLE = 8;
56

  
57
	/** A nibble->char mapping for printing out bytes. */
58
	public static final char[] digits = {
59
			'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',
60
			'e', 'f'
61
		};
62

  
63
	/**
64
	 * Return the <code>int</code> represented by the bytes in
65
	 * <code>data</code> staring at offset <code>offset[0]</code>.
66
	 *
67
	 * @param data the array from which to read
68
	 * @param offset A single element array whose first element is the index in
69
	 * 		  data from which to begin reading on function entry, and which on
70
	 * 		  function exit has been incremented by the number of bytes read.
71
	 *
72
	 * @return the value of the <code>int</code> decoded
73
	 */
74
	public static final int bytesToInt(byte[] data, int[] offset) {
75
		/**
76
		 * TODO: We use network-order within OceanStore, but temporarily
77
		 * supporting intel-order to work with some JNI code until JNI code is
78
		 * set to interoperate with network-order.
79
		 */
80
		int result = 0;
81

  
82
		for (int i = 0; i < SIZE_INT; ++i) {
83
			result <<= 8;
84
			result |= byteToUnsignedInt(data[offset[0]++]);
85
		}
86

  
87
		return result;
88
	}
89

  
90
	/**
91
	 * Write the bytes representing <code>i</code> into the byte array
92
	 * <code>data</code>, starting at index <code>offset [0]</code>, and
93
	 * increment <code>offset [0]</code> by the number of bytes written; if
94
	 * <code>data == null</code>, increment <code>offset [0]</code> by the
95
	 * number of bytes that would have been written otherwise.
96
	 *
97
	 * @param i the <code>int</code> to encode
98
	 * @param data The byte array to store into, or <code>null</code>.
99
	 * @param offset A single element array whose first element is the index in
100
	 * 		  data to begin writing at on function entry, and which on
101
	 * 		  function exit has been incremented by the number of bytes
102
	 * 		  written.
103
	 */
104
	public static final void intToBytes(int i, byte[] data, int[] offset) {
105
		/**
106
		 * TODO: We use network-order within OceanStore, but temporarily
107
		 * supporting intel-order to work with some JNI code until JNI code is
108
		 * set to interoperate with network-order.
109
		 */
110
		if (data != null) {
111
			for (int j = (offset[0] + SIZE_INT) - 1; j >= offset[0]; --j) {
112
				data[j] = (byte) i;
113
				i >>= 8;
114
			}
115
		}
116

  
117
		offset[0] += SIZE_INT;
118
	}
119

  
120
	/**
121
	 * Return the <code>short</code> represented by the bytes in
122
	 * <code>data</code> staring at offset <code>offset[0]</code>.
123
	 *
124
	 * @param data the array from which to read
125
	 * @param offset A single element array whose first element is the index in
126
	 * 		  data from which to begin reading on function entry, and which on
127
	 * 		  function exit has been incremented by the number of bytes read.
128
	 *
129
	 * @return the value of the <code>short</code> decoded
130
	 */
131
	public static final short bytesToShort(byte[] data, int[] offset) {
132
		/**
133
		 * TODO: We use network-order within OceanStore, but temporarily
134
		 * supporting intel-order to work with some JNI code until JNI code is
135
		 * set to interoperate with network-order.
136
		 */
137
		short result = 0;
138

  
139
		for (int i = 0; i < SIZE_SHORT; ++i) {
140
			result <<= 8;
141
			result |= (short) byteToUnsignedInt(data[offset[0]++]);
142
		}
143

  
144
		return result;
145
	}
146

  
147
	/**
148
	 * Write the bytes representing <code>s</code> into the byte array
149
	 * <code>data</code>, starting at index <code>offset [0]</code>, and
150
	 * increment <code>offset [0]</code> by the number of bytes written; if
151
	 * <code>data == null</code>, increment <code>offset [0]</code> by the
152
	 * number of bytes that would have been written otherwise.
153
	 *
154
	 * @param s the <code>short</code> to encode
155
	 * @param data The byte array to store into, or <code>null</code>.
156
	 * @param offset A single element array whose first element is the index in
157
	 * 		  data to begin writing at on function entry, and which on
158
	 * 		  function exit has been incremented by the number of bytes
159
	 * 		  written.
160
	 */
161
	public static final void shortToBytes(short s, byte[] data, int[] offset) {
162
		/**
163
		 * TODO: We use network-order within OceanStore, but temporarily
164
		 * supporting intel-order to work with some JNI code until JNI code is
165
		 * set to interoperate with network-order.
166
		 */
167
		if (data != null) {
168
			data[offset[0] + 1] = (byte) s;
169
			data[offset[0]] = (byte) (s >> 8);
170
		}
171

  
172
		offset[0] += SIZE_SHORT;
173
	}
174

  
175
	/**
176
	 * Return the <code>long</code> represented by the bytes in
177
	 * <code>data</code> staring at offset <code>offset[0]</code>.
178
	 *
179
	 * @param data the array from which to read
180
	 * @param offset A single element array whose first element is the index in
181
	 * 		  data from which to begin reading on  function entry, and which
182
	 * 		  on function exit has been incremented by the number of bytes
183
	 * 		  read.
184
	 *
185
	 * @return the value of the <code>long</code> decoded
186
	 */
187
	public static final long bytesToLong(byte[] data, int[] offset) {
188
		long result = 0;
189

  
190
		for (int i = 0; i < SIZE_LONG; ++i) {
191
			result <<= 8;
192

  
193
			int res = byteToUnsignedInt(data[offset[0]++]);
194
			result = result | res;
195
		}
196

  
197
		return result;
198
	}
199

  
200
	/**
201
	 * Write the bytes representing <code>l</code> into the byte array
202
	 * <code>data</code>, starting at index <code>offset [0]</code>, and
203
	 * increment <code>offset [0]</code> by the number of bytes written; if
204
	 * <code>data == null</code>, increment <code>offset [0]</code> by the
205
	 * number of bytes that would have been written otherwise.
206
	 *
207
	 * @param l the <code>long</code> to encode
208
	 * @param data The byte array to store into, or <code>null</code>.
209
	 * @param offset A single element array whose first element is the index in
210
	 * 		  data to begin writing at on function entry, and which on
211
	 * 		  function exit has been incremented by the number of bytes
212
	 * 		  written.
213
	 */
214
	public static final void longToBytes(long l, byte[] data, int[] offset) {
215
		/**
216
		 * TODO: We use network-order within OceanStore, but temporarily
217
		 * supporting intel-order to work with some JNI code until JNI code is
218
		 * set to interoperate with network-order.
219
		 */
220
		if (data != null) {
221
			for (int j = (offset[0] + SIZE_LONG) - 1; j >= offset[0]; --j) {
222
				data[j] = (byte) l;
223
				l >>= 8;
224
			}
225
		}
226

  
227
		offset[0] += SIZE_LONG;
228
	}
229

  
230
	/**
231
	 * Return the <code>double</code> represented by the bytes in
232
	 * <code>data</code> staring at offset <code>offset[0]</code>.
233
	 *
234
	 * @param data the array from which to read
235
	 * @param offset A single element array whose first element is the index in
236
	 * 		  data from which to begin reading on  function entry, and which
237
	 * 		  on function exit has been incremented by the number of bytes
238
	 * 		  read.
239
	 *
240
	 * @return the value of the <code>double</code> decoded
241
	 */
242
	public static final double bytesToDouble(byte[] data, int[] offset) {
243
		long bits = bytesToLong(data, offset);
244

  
245
		return Double.longBitsToDouble(bits);
246
	}
247

  
248
	/**
249
	 * Write the bytes representing <code>d</code> into the byte array
250
	 * <code>data</code>, starting at index <code>offset [0]</code>, and
251
	 * increment <code>offset [0]</code> by the number of bytes written; if
252
	 * <code>data == null</code>, increment <code>offset [0]</code> by the
253
	 * number of bytes that would have been written otherwise.
254
	 *
255
	 * @param d the <code>double</code> to encode
256
	 * @param data The byte array to store into, or <code>null</code>.
257
	 * @param offset A single element array whose first element is the index in
258
	 * 		  data to begin writing at on function entry, and which on
259
	 * 		  function exit has been incremented by the number of bytes
260
	 * 		  written.
261
	 */
262
	public static final void doubleToBytes(double d, byte[] data, int[] offset) {
263
		long bits = Double.doubleToLongBits(d);
264
		longToBytes(bits, data, offset);
265
	}
266

  
267
	/**
268
	 * Return the <code>String</code> represented by the bytes in
269
	 * <code>data</code> staring at offset <code>offset[0]</code>. This method
270
	 * relies on the user using the corresponding <code>stringToBytes</code>
271
	 * method to encode the <code>String</code>, so that it may properly
272
	 * retrieve the <code>String</code> length.
273
	 *
274
	 * @param data the array from which to read
275
	 * @param offset A single element array whose first element is the index in
276
	 * 		  data from which to begin reading on function entry, and which on
277
	 * 		  function exit has been incremented by the number of bytes read.
278
	 *
279
	 * @return the value of the <code>String</code> decoded
280
	 */
281
	public static final String bytesToString(byte[] data, int[] offset) {
282
		offset[0] = 0;
283

  
284
		int length = bytesToInt(data, offset);
285
		String st = null;
286

  
287
		if ((length < 0) || (length > data.length)) {
288
			st = new String(data);
289
		} else {
290
			st = new String(data, offset[0], length);
291
		}
292

  
293
		offset[0] += length;
294

  
295
		return st;
296
	}
297

  
298
	/**
299
	 * Write the bytes representing <code>s</code> into the byte array
300
	 * <code>data</code>, starting at index <code>offset [0]</code>, and
301
	 * increment <code>offset [0]</code> by the number of bytes written; if
302
	 * <code>data == null</code>, increment <code>offset [0]</code> by the
303
	 * number of bytes that would have been written otherwise.
304
	 *
305
	 * @param s the <code>String</code> to encode
306
	 * @param data The byte array to store into, or <code>null</code>.
307
	 * @param offset A single element array whose first element is the index in
308
	 * 		  data to begin writing at on function entry, and which on
309
	 * 		  function exit has been incremented by the number of bytes
310
	 * 		  written.
311
	 */
312
	public static final void stringToBytes(String s, byte[] data, int[] offset) {
313
		byte[] s_bytes = s.getBytes();
314

  
315
		if (data != null) {
316
			intToBytes(s_bytes.length, data, offset);
317
			memcpy(data, offset[0], s_bytes, 0, s_bytes.length);
318
		} else {
319
			offset[0] += SIZE_INT;
320
		}
321

  
322
		offset[0] += s_bytes.length;
323
	}
324

  
325
	/**
326
	 * Return the <code>boolean</code> represented by the bytes in
327
	 * <code>data</code> staring at offset <code>offset[0]</code>.
328
	 *
329
	 * @param data the array from which to read
330
	 * @param offset A single element array whose first element is the index in
331
	 * 		  data from which to begin reading on  function entry, and which
332
	 * 		  on function exit has been incremented by the number of bytes
333
	 * 		  read.
334
	 *
335
	 * @return the value of the <code>boolean</code> decoded
336
	 */
337
	public static final boolean bytesToBool(byte[] data, int[] offset) {
338
		boolean result = true;
339

  
340
		if (data[offset[0]] == 0) {
341
			result = false;
342
		}
343

  
344
		offset[0] += SIZE_BOOL;
345

  
346
		return result;
347
	}
348

  
349
	/**
350
	 * Write the bytes representing <code>b</code> into the byte array
351
	 * <code>data</code>, starting at index <code>offset [0]</code>, and
352
	 * increment <code>offset [0]</code> by the number of bytes written; if
353
	 * <code>data == null</code>, increment <code>offset [0]</code> by the
354
	 * number of bytes that would have been written otherwise.
355
	 *
356
	 * @param b the <code>boolean</code> to encode
357
	 * @param data The byte array to store into, or <code>null</code>.
358
	 * @param offset A single element array whose first element is the index in
359
	 * 		  data to begin writing at on function entry, and which on
360
	 * 		  function exit has been incremented by the number of bytes
361
	 * 		  written.
362
	 */
363
	public static final void boolToBytes(boolean b, byte[] data, int[] offset) {
364
		if (data != null) {
365
			data[offset[0]] = (byte) (b ? 1 : 0);
366
		}
367

  
368
		offset[0] += SIZE_BOOL;
369
	}
370

  
371
	/**
372
	 * Return the <code>BigInteger</code> represented by the bytes in
373
	 * <code>data</code> staring at offset <code>offset[0]</code>.
374
	 *
375
	 * @param data the array from which to read
376
	 * @param offset A single element array whose first element is the index in
377
	 * 		  data from which to begin reading on  function entry, and which
378
	 * 		  on function exit has been incremented by the number of bytes
379
	 * 		  read.
380
	 *
381
	 * @return the <code>BigInteger</code> decoded
382
	 */
383
	public static final BigInteger bytesToBigInteger(byte[] data, int[] offset) {
384
		int length = bytesToInt(data, offset);
385
		byte[] bytes = new byte[length];
386
		offset[0] += memcpy(bytes, 0, data, offset[0], length);
387

  
388
		return new BigInteger(bytes);
389
	}
390

  
391
	/**
392
	 * Write the bytes representing <code>n</code> into the byte array
393
	 * <code>data</code>, starting at index <code>offset [0]</code>, and
394
	 * increment <code>offset [0]</code> by the number of bytes written; if
395
	 * <code>data == null</code>, increment <code>offset [0]</code> by the
396
	 * number of bytes that would have been written otherwise.
397
	 *
398
	 * @param n the <code>BigInteger</code> to encode
399
	 * @param data The byte array to store into, or <code>null</code>.
400
	 * @param offset A single element array whose first element is the index in
401
	 * 		  data to begin writing at on function entry, and which on
402
	 * 		  function exit has been incremented by the number of bytes
403
	 * 		  written.
404
	 */
405
	public static final void bigIntegerToBytes(BigInteger n, byte[] data,
406
		int[] offset) {
407
		byte[] bytes = n.toByteArray();
408
		intToBytes(bytes.length, data, offset);
409
		offset[0] += memcpy(data, offset[0], bytes, 0, bytes.length);
410
	}
411

  
412
	/**
413
	 * Convert an array of <code>bytes</code>s into an array of
414
	 * <code>ints</code>.
415
	 *
416
	 * @param dst the array to write
417
	 * @param dst_offset the start offset in <code>dst</code>, times 4. This
418
	 * 		  measures the offset as if <code>dst</code> were an array of
419
	 * 		  <code>byte</code>s (rather than <code>int</code>s).
420
	 * @param src the array to read
421
	 * @param src_offset the start offset in <code>src</code>
422
	 * @param length the number of <code>byte</code>s to copy.
423
	 */
424
	public static final void bytesToInts(int[] dst, int dst_offset, byte[] src,
425
		int src_offset, int length) {
426
		if ((src == null) || (dst == null) ||
427
				((src_offset + length) > src.length) ||
428
				((dst_offset + length) > (dst.length * 4)) ||
429
				((dst_offset % 4) != 0) || ((length % 4) != 0)) {
430
			croak("bytesToInts parameters are invalid" + " src==" + src +
431
				" dst==" + dst +
432
				(((src == null) || (dst == null)) ? " "
433
												  : (" (src_offset+length)>src.length==" +
434
				(src_offset + length) + ">" + src.length +
435
				" (dst_offset+length)>(dst.length*4)==" +
436
				(dst_offset + length) + ">" + (dst.length * 4) +
437
				" (dst_offset%4)==" + (dst_offset % 4) + " (length%4)==" +
438
				(length % 4) + " dest.length==" + dst.length + " length==" +
439
				length)));
440
		}
441

  
442
		// Convert parameters to normal format
443
		int[] offset = new int[1];
444
		offset[0] = src_offset;
445

  
446
		int int_dst_offset = dst_offset / 4;
447

  
448
		for (int i = 0; i < (length / 4); ++i) {
449
			dst[int_dst_offset++] = bytesToInt(src, offset);
450
		}
451
	}
452

  
453
	/**
454
	 * Convert an array of <code>int</code>s into an array of
455
	 * <code>bytes</code>.
456
	 *
457
	 * @param dst the array to write
458
	 * @param dst_offset the start offset in <code>dst</code>
459
	 * @param src the array to read
460
	 * @param src_offset the start offset in <code>src</code>, times 4. This
461
	 * 		  measures the offset as if <code>src</code> were an array of
462
	 * 		  <code>byte</code>s (rather than <code>int</code>s).
463
	 * @param length the number of <code>byte</code>s to copy.
464
	 */
465
	public static final void intsToBytes(byte[] dst, int dst_offset, int[] src,
466
		int src_offset, int length) {
467
		if ((src == null) || (dst == null) ||
468
				((dst_offset + length) > dst.length) ||
469
				((src_offset + length) > (src.length * 4)) ||
470
				((src_offset % 4) != 0) || ((length % 4) != 0)) {
471
			croak("intsToBytes parameters are invalid:" + " src=" + src +
472
				" dst=" + dst + " (dst_offset=" + dst_offset + " + length=" +
473
				length + ")=" + (dst_offset + length) + " > dst.length=" +
474
				((dst == null) ? 0 : dst.length) + " (src_offset=" +
475
				src_offset + " + length=" + length + ")=" +
476
				(src_offset + length) + " > (src.length=" +
477
				((src == null) ? 0 : src.length) + "*4)=" +
478
				((src == null) ? 0 : (src.length * 4)) + " (src_offset=" +
479
				src_offset + " % 4)=" + (src_offset % 4) + " != 0" +
480
				" (length=" + length + " % 4)=" + (length % 4) + " != 0");
481
		}
482

  
483
		// Convert parameters to normal format
484
		int[] offset = new int[1];
485
		offset[0] = dst_offset;
486

  
487
		int int_src_offset = src_offset / 4;
488

  
489
		for (int i = 0; i < (length / 4); ++i) {
490
			intToBytes(src[int_src_offset++], dst, offset);
491
		}
492
	}
493

  
494
	/**
495
	 * Convert a <code>byte</code> into an unsigned integer.
496
	 *
497
	 * @param b the <code>byte</code> to cast
498
	 *
499
	 * @return a postiive <code>int</code> whose lowest byte contains the bits
500
	 * 		   of <code>b</code>.
501
	 */
502
	public static final int byteToUnsignedInt(byte b) {
503
		return ((int) b) & 0xff;
504
	}
505

  
506
	/**
507
	 * Copy contents of one array of <code>bytes</code> into another. If either
508
	 * array is <code>null</code>, simply return the <code>length</code>
509
	 * parameter directly.
510
	 *
511
	 * @param dst the array to write, or <code>null</code>
512
	 * @param dst_offset the start offset in <code>dst</code>
513
	 * @param src the array to read, or <code>null</code>
514
	 * @param src_offset the start offset in <code>src</code>
515
	 * @param length the number of <code>byte</code>s to copy.
516
	 *
517
	 * @return DOCUMENT ME!
518
	 */
519
	public static int memcpy(byte[] dst, int dst_offset, byte[] src,
520
		int src_offset, int length) {
521
		if ((dst != null) && (src != null)) {
522
			if (dst.length < (dst_offset + length)) {
523
				croak("dst.length = " + dst.length + ", but " +
524
					"dst_offset = " + dst_offset + " and length = " + length +
525
					".");
526
			}
527

  
528
			if (src.length < (src_offset + length)) {
529
				croak("src.length = " + src.length + ", but " +
530
					"src_offset = " + src_offset + " and length = " + length +
531
					".");
532
			}
533

  
534
			for (int i = 0; i < length; ++i, ++dst_offset, ++src_offset)
535
				dst[dst_offset] = src[src_offset];
536
		}
537

  
538
		return length;
539
	}
540

  
541
	/**
542
	 * Compare the contents of one array of <code>bytes</code> to another.
543
	 *
544
	 * @param a the first array
545
	 * @param a_offset the start offset in <code>a</code>
546
	 * @param b the second array
547
	 * @param b_offset the start offset in <code>b</code>
548
	 * @param length the number of <code>byte</code>s to compare.
549
	 *
550
	 * @return DOCUMENT ME!
551
	 */
552
	public static boolean memcmp(byte[] a, int a_offset, byte[] b,
553
		int b_offset, int length) {
554
		if ((a == null) && (b == null)) {
555
			return true;
556
		}
557

  
558
		if ((a == null) || (b == null)) {
559
			return false;
560
		}
561

  
562
		for (int i = 0; i < length; ++i, ++a_offset, ++b_offset)
563
			if (a[a_offset] != b[b_offset]) {
564
				return false;
565
			}
566

  
567
		return true;
568
	}
569

  
570
	/**
571
	 * Fill the given array with zeros.
572
	 *
573
	 * @param array the array to clear
574
	 * @param offset the start offset
575
	 * @param length the number of <code>byte</code>s to clear.
576
	 */
577
	public static void memclr(byte[] array, int offset, int length) {
578
		for (int i = 0; i < length; ++i, ++offset)
579
			array[offset] = 0;
580
	}
581

  
582
	/**
583
	 * Round a number up to a given multiple.
584
	 *
585
	 * @param value the number to be rounded
586
	 * @param multiple the number to which to be rounded
587
	 *
588
	 * @return the smallest <code>int</code> greater than or equal to
589
	 * 		   <code>value</code> which divides <code>multiple</code> exactly.
590
	 */
591
	public static int round_up(int value, int multiple) {
592
		return (((value - 1) / multiple) + 1) * multiple;
593
	}
594

  
595
	/**
596
	 * Return a new array equal to original except zero-padded to an integral
597
	 * mulitple of blocks.  If the original is already an integral multiple of
598
	 * blocks, just return it.
599
	 *
600
	 * @param original the array of <code>byte</code>s to be padded
601
	 * @param block_size the size of the blocks
602
	 *
603
	 * @return an array whose size divides <code>block_size</code> exactly. The
604
	 * 		   array is either <code>original</code> itself, or a copy whose
605
	 * 		   first <code>original.length</code> bytes are equal to
606
	 * 		   <code>original</code>.
607
	 */
608
	public static byte[] zero_pad(byte[] original, int block_size) {
609
		if ((original.length % block_size) == 0) {
610
			return original;
611
		}
612

  
613
		byte[] result = new byte[round_up(original.length, block_size)];
614
		memcpy(result, 0, original, 0, original.length);
615

  
616
		// Unnecessary - jvm sets bytes to 0.
617
		// memclr (result, original.length, result.length - original.length);
618
		return result;
619
	}
620

  
621
	/**
622
	 * Determines whether two arrays of <code>byte</code>s contain the same
623
	 * contents.
624
	 *
625
	 * @param b1 The first array
626
	 * @param b2 The second array
627
	 *
628
	 * @return <code>true</code> if both arrays are <code>null</code>, both
629
	 * 		   empty, or both of the same length with equal contents.
630
	 */
631
	public static boolean equals(byte[] b1, byte[] b2) {
632
		if (b1 == b2) {
633
			return true;
634
		}
635

  
636
		if ((b1 == null) || (b2 == null)) { // only one is null
637

  
638
			return false;
639
		}
640

  
641
		if (b1.length != b2.length) {
642
			return false;
643
		}
644

  
645
		for (int i = 0; i < b1.length; ++i)
646
			if (b1[i] != b2[i]) {
647
				return false;
648
			}
649

  
650
		return true;
651
	}
652

  
653
	/**
654
	 * Produce a <code>String</code> representation for the specified array of
655
	 * <code>byte</code>s.  Print each <code>byte</code> as two hexadecimal
656
	 * digits.
657
	 *
658
	 * @param data The array to print
659
	 * @param offset the start offset in <code>data</code>
660
	 * @param length the number of <code>byte</code>s to print
661
	 *
662
	 * @return DOCUMENT ME!
663
	 */
664
	public static String print_bytes(byte[] data, int offset, int length) {
665
		int size = 2 * length;
666
		size += ((size / 8) + (size / 64));
667

  
668
		char[] buf = new char[size];
669
		int low_mask = 0x0f;
670
		int high_mask = 0xf0;
671
		int buf_pos = 0;
672
		byte b;
673

  
674
		int j = 0;
675

  
676
		for (int i = offset; i < (offset + length); ++i) {
677
			b = data[i];
678
			buf[buf_pos++] = digits[(high_mask & b) >> 4];
679
			buf[buf_pos++] = digits[(low_mask & b)];
680

  
681
			if ((j % 4) == 3) {
682
				buf[buf_pos++] = ' ';
683
			}
684

  
685
			if ((j % 32) == 31) {
686
				buf[buf_pos++] = '\n';
687
			}
688

  
689
			++j;
690
		}
691

  
692
		return new String(buf);
693
	}
694

  
695
	/**
696
	 * DOCUMENT ME!
697
	 *
698
	 * @param data DOCUMENT ME!
699
	 * @param offset DOCUMENT ME!
700
	 * @param length DOCUMENT ME!
701
	 *
702
	 * @return DOCUMENT ME!
703
	 */
704
	public static String print_bytes_exact(byte[] data, int offset, int length) {
705
		int size = 2 * length;
706
		char[] buf = new char[size];
707
		int low_mask = 0x0f;
708
		int high_mask = 0xf0;
709
		int buf_pos = 0;
710
		byte b;
711

  
712
		int j = 0;
713

  
714
		for (int i = offset; i < (offset + length); ++i) {
715
			b = data[i];
716
			buf[buf_pos++] = digits[(high_mask & b) >> 4];
717
			buf[buf_pos++] = digits[(low_mask & b)];
718
			++j;
719
		}
720

  
721
		return new String(buf);
722
	}
723

  
724
	/**
725
	 * DOCUMENT ME!
726
	 *
727
	 * @param data DOCUMENT ME!
728
	 *
729
	 * @return DOCUMENT ME!
730
	 */
731
	public static String print_bytes(byte[] data) {
732
		return print_bytes(data, 0, data.length);
733
	}
734

  
735
	/**
736
	 * DOCUMENT ME!
737
	 *
738
	 * @param msg DOCUMENT ME!
739
	 */
740
	private static void croak(String msg) {
741
		// throw new java.AssertionViolatedException(msg);
742
	}
743

  
744
	/**
745
	 * DOCUMENT ME!
746
	 *
747
	 * @param b DOCUMENT ME!
748
	 *
749
	 * @return DOCUMENT ME!
750
	 */
751
	public static int getUnsigned(byte b) {
752
		return ((b & 0xff)); // >> 8);
753
	}
754
}
tags/org.gvsig.dwg-2.0.197/org.gvsig.dwg.lib/src/main/java/org/gvsig/dwg/lib/util/TextToUnicodeConverter.java
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 org.gvsig.dwg.lib.util;
36

  
37
import java.text.StringCharacterIterator;
38

  
39
/**
40
 * This class allows to convert an Autocad text in an Unicode text
41
 * 
42
 * @author jmorell
43
 */
44
public class TextToUnicodeConverter {
45
    
46
    /**
47
     * This method allows to convert an Autocad text in an Unicode text
48
     * 
49
     * @param s Autocad text
50
     * @return String Unicode text
51
     */
52
	public static String convertText(String s) {
53
        StringCharacterIterator stringcharacteriterator = new StringCharacterIterator(s);
54
        StringBuffer stringbuffer = new StringBuffer();
55
        int ai[] = new int[s.length()];
56
        int i = 0;
57
        int j = 0;
58
        for(char c = stringcharacteriterator.first(); c != '\uFFFF'; c = stringcharacteriterator.next())
59
            if(c == '%')
60
            {
61
                c = stringcharacteriterator.next();
62
                if(c != '%')
63
                {
64
                    stringbuffer.append('%');
65
                    c = stringcharacteriterator.previous();
66
                } else
67
                {
68
                    c = stringcharacteriterator.next();
69
                    switch(c)
70
                    {
71
                    case 37: // '%'
72
                        stringbuffer.append('%');
73
                        break;
74

  
75
                    case 80: // 'P'
76
                    case 112: // 'p'
77
                        stringbuffer.append('\361');
78
                        break;
79

  
80
                    case 67: // 'C'
81
                    case 99: // 'c'
82
                        stringbuffer.append('\355');
83
                        break;
84

  
85
                    case 68: // 'D'
86
                    case 100: // 'd'
87
                        stringbuffer.append('\u00b0');
88
                        break;
89

  
90
                    case 85: // 'U'
91
                    case 117: // 'u'
92
                        ai[stringbuffer.length()] ^= 1;
93
                        i++;
94
                        break;
95

  
96
                    case 79: // 'O'
97
                    case 111: // 'o'
98
                        ai[stringbuffer.length()] ^= 2;
99
                        j++;
100
                        break;
101

  
102
                    default:
103
                        if(c >= '0' && c <= '9')
104
                        {
105
                            int k = 3;
106
                            char c1 = (char)(c - 48);
107
                            for(c = stringcharacteriterator.next(); c >= '0' && c <= '9' && --k > 0; c = stringcharacteriterator.next())
108
                                c1 = (char)(10 * c1 + (c - 48));
109

  
110
                            stringbuffer.append(c1);
111
                        }
112
                        c = stringcharacteriterator.previous();
113
                        break;
114
                    }
115
                }
116
            } else
117
            if(c == '^')
118
            {
119
                c = stringcharacteriterator.next();
120
                if(c == ' ')
121
                    stringbuffer.append('^');
122
            } else
123
            {
124
                stringbuffer.append(c);
125
            }
126
        s = Unicode.char2DOS437(stringbuffer, 2, '?');
127

  
128
		String ss = s;
129
		return ss;
130
	}
131
}
tags/org.gvsig.dwg-2.0.197/org.gvsig.dwg.lib/src/main/java/org/gvsig/dwg/lib/util/Unicode.java
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 org.gvsig.dwg.lib.util;
36

  
37
/**
38
 * Class that contains the tables for Autocad to Unicode text conversions
39
 * 
40
 * @author jmorell
41
 */
42
class Unicode {
43
    private static final char UCNONE = 65535;
44
    private static final char unicode[][] = {
45
        {
46
            '\0', '\001', '\002', '\003', '\004', '\005', '\006', '\007', '\b', '\t', 
47
            '\n', '\013', '\f', '\r', '\016', '\017', '\020', '\021', '\022', '\023', 
48
            '\024', '\025', '\026', '\027', '\030', '\031', '\032', '\033', '\034', '\035', 
49
            '\036', '\037', ' ', '!', '"', '#', '$', '%', '&', '\'', 
50
            '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', 
51
            '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', 
52
            '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 
53
            'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 
54
            'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 
55
            'Z', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c', 
56
            'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 
57
            'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 
58
            'x', 'y', 'z', '{', '|', '}', '~', '\177', '\200', '\201', 
59
            '\202', '\203', '\204', '\205', '\206', '\207', '\210', '\211', '\212', '\213', 
60
            '\214', '\215', '\216', '\217', '\220', '\221', '\222', '\223', '\224', '\225', 
61
            '\226', '\227', '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237', 
62
            '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247', '\250', '\251', 
63
            '\252', '\253', '\254', '\255', '\256', '\257', '\260', '\261', '\262', '\263', 
64
            '\264', '\265', '\266', '\267', '\270', '\271', '\272', '\273', '\274', '\275', 
65
            '\276', '\277', '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307', 
66
            '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317', '\320', '\321', 
67
            '\322', '\323', '\324', '\325', '\326', '\327', '\330', '\331', '\332', '\333', 
68
            '\334', '\335', '\336', '\337', '\340', '\341', '\342', '\343', '\344', '\345', 
69
            '\346', '\347', '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', 
70
            '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', '\370', '\371', 
71
            '\372', '\373', '\374', '\375', '\376', '\377'
72
        }, {
73
            '\0', '\001', '\002', '\003', '\004', '\005', '\006', '\007', '\b', '\t', 
74
            '\n', '\013', '\f', '\r', '\016', '\017', '\020', '\021', '\022', '\023', 
75
            '\024', '\025', '\026', '\027', '\030', '\031', '\032', '\033', '\034', '\035', 
76
            '\036', '\037', ' ', '!', '"', '#', '$', '%', '&', '\'', 
77
            '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', 
78
            '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', 
79
            '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 
80
            'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 
81
            'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 
82
            'Z', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c', 
83
            'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 
84
            'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 
85
            'x', 'y', 'z', '{', '|', '}', '~', '\177', '\200', '\201', 
86
            '\202', '\203', '\204', '\205', '\206', '\207', '\210', '\211', '\212', '\213', 
87
            '\214', '\215', '\216', '\217', '\220', '\221', '\222', '\223', '\224', '\225', 
88
            '\226', '\227', '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237', 
89
            '\240', '\u0104', '\u02D8', '\u0141', '\244', '\u013D', '\u015A', '\247', '\250', '\u0160', 
90
            '\u015E', '\u0164', '\u0179', '\255', '\u017D', '\u017B', '\260', '\u0105', '\u02DB', '\u0142', 
91
            '\264', '\u013E', '\u015B', '\u02C7', '\270', '\u0161', '\u015F', '\u0165', '\u017A', '\u02DD', 
92
            '\u017E', '\u017C', '\u0154', '\301', '\302', '\u0102', '\304', '\u0139', '\u0106', '\307', 
93
            '\u010C', '\311', '\u0118', '\313', '\u011A', '\315', '\316', '\u010E', '\u0110', '\u0143', 
94
            '\u0147', '\323', '\324', '\u0150', '\326', '\327', '\u0158', '\u016E', '\332', '\u0170', 
95
            '\334', '\335', '\u0162', '\337', '\u0155', '\341', '\342', '\u0103', '\344', '\u013A', 
96
            '\u0107', '\347', '\u010D', '\351', '\u0119', '\353', '\u011B', '\355', '\356', '\u010F', 
97
            '\u0111', '\u0144', '\u0148', '\363', '\364', '\u0151', '\366', '\367', '\u0159', '\u016F', 
98
            '\372', '\u0171', '\374', '\375', '\u0163', '\u02D9'
99
        }, {
100
            '\0', '\001', '\002', '\003', '\004', '\005', '\006', '\007', '\b', '\t', 
101
            '\n', '\013', '\f', '\r', '\016', '\017', '\020', '\021', '\022', '\023', 
102
            '\024', '\025', '\026', '\027', '\030', '\031', '\032', '\033', '\034', '\035', 
103
            '\036', '\037', ' ', '!', '"', '#', '$', '%', '&', '\'', 
104
            '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', 
105
            '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', 
106
            '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 
107
            'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 
108
            'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 
109
            'Z', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c', 
110
            'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 
111
            'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 
112
            'x', 'y', 'z', '{', '|', '}', '~', '\u2302', '\307', '\374', 
113
            '\351', '\342', '\344', '\340', '\345', '\347', '\352', '\353', '\350', '\357', 
114
            '\356', '\354', '\304', '\305', '\311', '\346', '\306', '\364', '\366', '\362', 
115
            '\373', '\371', '\377', '\326', '\334', '\242', '\243', '\245', '\u20A7', '\u0192', 
116
            '\341', '\355', '\363', '\372', '\361', '\321', '\252', '\272', '\277', '\u2310', 
117
            '\254', '\275', '\274', '\241', '\253', '\273', '\u2591', '\u2592', '\u2593', '\u2502', 
118
            '\u2524', '\u2561', '\u2562', '\u2556', '\u2555', '\u2563', '\u2551', '\u2557', '\u255D', '\u255C', 
119
            '\u255B', '\u2510', '\u2514', '\u2534', '\u252C', '\u251C', '\u2500', '\u253C', '\u255E', '\u255F', 
120
            '\u255A', '\u2554', '\u2569', '\u2566', '\u2560', '\u2550', '\u256C', '\u2567', '\u2568', '\u2564', 
121
            '\u2565', '\u2559', '\u2558', '\u2552', '\u2553', '\u256B', '\u256A', '\u2518', '\u250C', '\u2588', 
122
            '\u2584', '\u258C', '\u2590', '\u2580', '\u03B1', '\337', '\u0393', '\u03C0', '\u03A3', '\u03C3', 
123
            '\265', '\u03C4', '\u03A6', '\u0398', '\u03A9', '\u03B4', '\u221E', '\u03C6', '\u03B5', '\u2229', 
124
            '\u2261', '\261', '\u2265', '\u2264', '\u2320', '\u2321', '\367', '\u2248', '\260', '\u2219', 
125
            '\267', '\u221A', '\u207F', '\262', '\u25A0', '\240'
126
        }, {
127
            '\0', '\001', '\002', '\003', '\004', '\005', '\006', '\007', '\b', '\t', 
128
            '\n', '\013', '\f', '\r', '\016', '\017', '\020', '\021', '\022', '\023', 
129
            '\024', '\025', '\026', '\027', '\030', '\031', '\032', '\033', '\034', '\035', 
130
            '\036', '\037', ' ', '!', '"', '#', '$', '%', '&', '\'', 
131
            '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', 
132
            '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', 
133
            '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 
134
            'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 
135
            'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 
136
            'Z', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c', 
137
            'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 
138
            'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 
139
            'x', 'y', 'z', '{', '|', '}', '~', '\u2302', '\307', '\374', 
140
            '\351', '\342', '\344', '\340', '\345', '\347', '\352', '\353', '\350', '\357', 
141
            '\356', '\354', '\304', '\305', '\311', '\346', '\306', '\364', '\366', '\362', 
142
            '\373', '\371', '\377', '\326', '\334', '\370', '\243', '\330', '\327', '\u0192', 
143
            '\341', '\355', '\363', '\372', '\361', '\321', '\252', '\272', '\277', '\256', 
144
            '\254', '\275', '\274', '\241', '\253', '\273', '\u2591', '\u2592', '\u2593', '\u2502', 
145
            '\u2524', '\301', '\302', '\300', '\251', '\u2563', '\u2551', '\u2557', '\u255D', '\242', 
146
            '\245', '\u2510', '\u2514', '\u2534', '\u252C', '\u251C', '\u2500', '\u253C', '\343', '\303', 
147
            '\u255A', '\u2554', '\u2569', '\u2566', '\u2560', '\u2550', '\u256C', '\244', '\360', '\320', 
148
            '\312', '\313', '\310', '\u0131', '\315', '\316', '\317', '\u2518', '\u250C', '\u2588', 
149
            '\u2584', '\246', '\314', '\u2580', '\323', '\337', '\324', '\322', '\365', '\325', 
150
            '\265', '\376', '\336', '\332', '\333', '\331', '\375', '\335', '\257', '\264', 
151
            '\255', '\261', '\u2017', '\276', '\266', '\247', '\367', '\270', '\260', '\250', 
152
            '\267', '\271', '\263', '\262', '\u25A0', '\240'
153
        }, {
154
            '\0', '\001', '\002', '\003', '\004', '\005', '\006', '\007', '\b', '\t', 
155
            '\n', '\013', '\f', '\r', '\016', '\017', '\020', '\021', '\022', '\023', 
156
            '\024', '\025', '\026', '\027', '\030', '\031', '\032', '\033', '\034', '\035', 
157
            '\036', '\037', ' ', '!', '"', '#', '$', '%', '&', '\'', 
158
            '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', 
159
            '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', 
160
            '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 
161
            'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 
162
            'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 
163
            'Z', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c', 
164
            'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 
165
            'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 
166
            'x', 'y', 'z', '{', '|', '}', '~', '\u2302', '\307', '\374', 
167
            '\351', '\342', '\344', '\u016F', '\u0107', '\347', '\u0142', '\353', '\u0150', '\u0151', 
168
            '\356', '\u0179', '\304', '\u0106', '\311', '\u0139', '\u013A', '\364', '\366', '\u013D', 
169
            '\u013E', '\u015A', '\u015B', '\326', '\334', '\u0164', '\u0165', '\u0141', '\327', '\u010D', 
170
            '\341', '\355', '\363', '\372', '\u0104', '\u0105', '\u017D', '\u017E', '\u0118', '\u0119', 
171
            '\254', '\u017A', '\u010C', '\u015F', '\253', '\273', '\u2591', '\u2592', '\u2593', '\u2502', 
172
            '\u2524', '\301', '\302', '\u011A', '\u015E', '\u2563', '\u2551', '\u2557', '\u255D', '\u017B', 
173
            '\u017C', '\u2510', '\u2514', '\u2534', '\u252C', '\u251C', '\u2500', '\u253C', '\u0102', '\u0103', 
174
            '\u255A', '\u2554', '\u2569', '\u2566', '\u2560', '\u2550', '\u256C', '\244', '\u0111', '\u0110', 
175
            '\u010E', '\313', '\u010F', '\u0147', '\315', '\316', '\u011B', '\u2518', '\u250C', '\u2588', 
176
            '\u2584', '\u0162', '\u016E', '\u2580', '\323', '\337', '\324', '\u0143', '\u0144', '\u0148', 
177
            '\u0160', '\u0161', '\u0154', '\332', '\u0155', '\u0170', '\375', '\335', '\u0163', '\264', 
178
            '\255', '\u02DD', '\u02DB', '\u02C7', '\u02D8', '\247', '\367', '\270', '\260', '\250', 
179
            '\u02D9', '\u0171', '\u0158', '\u0159', '\u25A0', '\240'
180
        }, {
181
            '\0', '\001', '\002', '\003', '\004', '\005', '\006', '\007', '\b', '\t', 
182
            '\n', '\013', '\f', '\r', '\016', '\017', '\020', '\021', '\022', '\023', 
183
            '\024', '\025', '\026', '\027', '\030', '\031', '\032', '\033', '\034', '\035', 
184
            '\036', '\037', ' ', '!', '"', '#', '$', '%', '&', '\'', 
185
            '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', 
186
            '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', 
187
            '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff