Statistics
| Revision:

svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfConvTexts.java @ 2312

History | View | Annotate | Download (3.67 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.cresques.px.dxf;
25

    
26
import java.text.StringCharacterIterator;
27

    
28
/**
29
 * @author jmorell
30
 *
31
 */
32
public class DxfConvTexts {
33
        public static String ConvertText(String s) {
34
                
35
        StringCharacterIterator stringcharacteriterator = new StringCharacterIterator(s);
36
        StringBuffer stringbuffer = new StringBuffer();
37
        int ai[] = new int[s.length()];
38
        int i = 0;
39
        int j = 0;
40
        for(char c = stringcharacteriterator.first(); c != '\uFFFF'; c = stringcharacteriterator.next())
41
            if(c == '%')
42
            {
43
                c = stringcharacteriterator.next();
44
                if(c != '%')
45
                {
46
                    stringbuffer.append('%');
47
                    c = stringcharacteriterator.previous();
48
                } else
49
                {
50
                    c = stringcharacteriterator.next();
51
                    switch(c)
52
                    {
53
                    case 37: // '%'
54
                        stringbuffer.append('%');
55
                        break;
56

    
57
                    case 80: // 'P'
58
                    case 112: // 'p'
59
                        stringbuffer.append('\361');
60
                        break;
61

    
62
                    case 67: // 'C'
63
                    case 99: // 'c'
64
                        stringbuffer.append('\355');
65
                        break;
66

    
67
                    case 68: // 'D'
68
                    case 100: // 'd'
69
                        stringbuffer.append('\u00b0');
70
                        break;
71

    
72
                    case 85: // 'U'
73
                    case 117: // 'u'
74
                        ai[stringbuffer.length()] ^= 1;
75
                        i++;
76
                        break;
77

    
78
                    case 79: // 'O'
79
                    case 111: // 'o'
80
                        ai[stringbuffer.length()] ^= 2;
81
                        j++;
82
                        break;
83

    
84
                    default:
85
                        if(c >= '0' && c <= '9')
86
                        {
87
                            int k = 3;
88
                            char c1 = (char)(c - 48);
89
                            for(c = stringcharacteriterator.next(); c >= '0' && c <= '9' && --k > 0; c = stringcharacteriterator.next())
90
                                c1 = (char)(10 * c1 + (c - 48));
91

    
92
                            stringbuffer.append(c1);
93
                        }
94
                        c = stringcharacteriterator.previous();
95
                        break;
96
                    }
97
                }
98
            } else
99
            if(c == '^')
100
            {
101
                c = stringcharacteriterator.next();
102
                if(c == ' ')
103
                    stringbuffer.append('^');
104
            } else
105
            {
106
                stringbuffer.append(c);
107
            }
108
        s = Unicode.char2DOS437(stringbuffer, 2, '?');
109

    
110
                
111
                String ss = s;
112
                return ss;
113
        }
114

    
115
}