root / branches / v2_0_0_prep / libraries / libDXF / src / org / gvsig / dxf / px / dxf / DxfConvTexts.java @ 29630
History | View | Annotate | Download (4.08 KB)
1 |
/*
|
---|---|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
3 |
*
|
4 |
* Copyright (C) 2004-5.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* cresques@gmail.com
|
23 |
*/
|
24 |
package org.gvsig.dxf.px.dxf; |
25 |
|
26 |
import java.text.StringCharacterIterator; |
27 |
|
28 |
|
29 |
/**
|
30 |
* La clase DxfConvTexts se emplea para convertir los textos asociados a las entidades
|
31 |
* TEXT de un fichero DXF al alfabeto tradicional.
|
32 |
* @author jmorell
|
33 |
*/
|
34 |
public class DxfConvTexts { |
35 |
|
36 |
/**
|
37 |
* M?todo que permite transformar los textos asociados a entidades TEXT en un
|
38 |
* fichero DXF al alfabeto tradicional.
|
39 |
* @param s, texto extraido de un DXF.
|
40 |
* @return String, el mismo texto en alfabeto tradicional.
|
41 |
*/
|
42 |
public static String ConvertText(String s) { |
43 |
StringCharacterIterator stringcharacteriterator = new StringCharacterIterator(s); |
44 |
StringBuffer stringbuffer = new StringBuffer(); |
45 |
int[] ai = new int[s.length()]; |
46 |
int i = 0; |
47 |
int j = 0; |
48 |
|
49 |
for (char c = stringcharacteriterator.first(); c != '\uFFFF'; |
50 |
c = stringcharacteriterator.next()) |
51 |
if (c == '%') { |
52 |
c = stringcharacteriterator.next(); |
53 |
|
54 |
if (c != '%') { |
55 |
stringbuffer.append('%');
|
56 |
c = stringcharacteriterator.previous(); |
57 |
} else {
|
58 |
c = stringcharacteriterator.next(); |
59 |
|
60 |
switch (c) {
|
61 |
case 37: // '%' |
62 |
stringbuffer.append('%');
|
63 |
|
64 |
break;
|
65 |
|
66 |
case 80: // 'P' |
67 |
case 112: // 'p' |
68 |
stringbuffer.append('\361');
|
69 |
|
70 |
break;
|
71 |
|
72 |
case 67: // 'C' |
73 |
case 99: // 'c' |
74 |
stringbuffer.append('\355');
|
75 |
|
76 |
break;
|
77 |
|
78 |
case 68: // 'D' |
79 |
case 100: // 'd' |
80 |
stringbuffer.append('\u00b0');
|
81 |
|
82 |
break;
|
83 |
|
84 |
case 85: // 'U' |
85 |
case 117: // 'u' |
86 |
ai[stringbuffer.length()] ^= 1;
|
87 |
i++; |
88 |
|
89 |
break;
|
90 |
|
91 |
case 79: // 'O' |
92 |
case 111: // 'o' |
93 |
ai[stringbuffer.length()] ^= 2;
|
94 |
j++; |
95 |
|
96 |
break;
|
97 |
|
98 |
default:
|
99 |
|
100 |
if ((c >= '0') && (c <= '9')) { |
101 |
int k = 3; |
102 |
char c1 = (char) (c - 48); |
103 |
|
104 |
for (c = stringcharacteriterator.next();
|
105 |
(c >= '0') && (c <= '9') && (--k > 0); |
106 |
c = stringcharacteriterator.next()) |
107 |
c1 = (char) ((10 * c1) + (c - 48)); |
108 |
|
109 |
stringbuffer.append(c1); |
110 |
} |
111 |
|
112 |
c = stringcharacteriterator.previous(); |
113 |
|
114 |
break;
|
115 |
} |
116 |
} |
117 |
} else if (c == '^') { |
118 |
c = stringcharacteriterator.next(); |
119 |
|
120 |
if (c == ' ') { |
121 |
stringbuffer.append('^');
|
122 |
} |
123 |
} else {
|
124 |
stringbuffer.append(c); |
125 |
} |
126 |
|
127 |
s = Unicode.char2DOS437(stringbuffer, 2, '?'); |
128 |
|
129 |
String ss = s;
|
130 |
|
131 |
return ss;
|
132 |
} |
133 |
} |