Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libDwg / src / org / gvsig / dwg / lib / util / TextToUnicodeConverter.java @ 28969

History | View | Annotate | Download (4.14 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 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
}