1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: hw2fw.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_transex3.hxx"
34 #include <tools/string.hxx>
42 #define MAKE_PAIR(a,b) { a, b }
44 static struct hw_pair aHWPairs
[] =
46 MAKE_PAIR( 0xFF65, 0x30FB ), // HALFWIDTH KATAKANA MIDDLE DOT --> KATAKANA MIDDLE DOT
47 MAKE_PAIR( 0xFF66, 0x30F2 ), // HALFWIDTH KATAKANA LETTER WO --> KATAKANA LETTER WO
48 MAKE_PAIR( 0xFF67, 0x30A1 ), // HALFWIDTH KATAKANA LETTER SMALL A --> KATAKANA LETTER SMALL A
49 MAKE_PAIR( 0xFF68, 0x30A3 ), // HALFWIDTH KATAKANA LETTER SMALL I --> KATAKANA LETTER SMALL I
50 MAKE_PAIR( 0xFF69, 0x30A5 ), // HALFWIDTH KATAKANA LETTER SMALL U --> KATAKANA LETTER SMALL U
51 MAKE_PAIR( 0xFF6A, 0x30A7 ), // HALFWIDTH KATAKANA LETTER SMALL E --> KATAKANA LETTER SMALL E
52 MAKE_PAIR( 0xFF6B, 0x30A9 ), // HALFWIDTH KATAKANA LETTER SMALL O --> KATAKANA LETTER SMALL O
53 MAKE_PAIR( 0xFF6C, 0x30E3 ), // HALFWIDTH KATAKANA LETTER SMALL YA --> KATAKANA LETTER SMALL YA
54 MAKE_PAIR( 0xFF6D, 0x30E5 ), // HALFWIDTH KATAKANA LETTER SMALL YU --> KATAKANA LETTER SMALL YU
55 MAKE_PAIR( 0xFF6E, 0x30E7 ), // HALFWIDTH KATAKANA LETTER SMALL YO --> KATAKANA LETTER SMALL YO
56 MAKE_PAIR( 0xFF6F, 0x30C3 ), // HALFWIDTH KATAKANA LETTER SMALL TU --> KATAKANA LETTER SMALL TU
57 MAKE_PAIR( 0xFF70, 0x30FC ), // HALFWIDTH KATAKANA-HIRAGANA PROLONGED SOUND MARK --> KATAKANA-HIRAGANA PROLONGED SOUND MARK
58 MAKE_PAIR( 0xFF71, 0x30A2 ), // HALFWIDTH KATAKANA LETTER A --> KATAKANA LETTER A
59 MAKE_PAIR( 0xFF72, 0x30A4 ), // HALFWIDTH KATAKANA LETTER I --> KATAKANA LETTER I
60 MAKE_PAIR( 0xFF73, 0x30A6 ), // HALFWIDTH KATAKANA LETTER U --> KATAKANA LETTER U
61 MAKE_PAIR( 0xFF74, 0x30A8 ), // HALFWIDTH KATAKANA LETTER E --> KATAKANA LETTER E
62 MAKE_PAIR( 0xFF75, 0x30AA ), // HALFWIDTH KATAKANA LETTER O --> KATAKANA LETTER O
63 MAKE_PAIR( 0xFF76, 0x30AB ), // HALFWIDTH KATAKANA LETTER KA --> KATAKANA LETTER KA
64 MAKE_PAIR( 0xFF77, 0x30AD ), // HALFWIDTH KATAKANA LETTER KI --> KATAKANA LETTER KI
65 MAKE_PAIR( 0xFF78, 0x30AF ), // HALFWIDTH KATAKANA LETTER KU --> KATAKANA LETTER KU
66 MAKE_PAIR( 0xFF79, 0x30B1 ), // HALFWIDTH KATAKANA LETTER KE --> KATAKANA LETTER KE
67 MAKE_PAIR( 0xFF7A, 0x30B3 ), // HALFWIDTH KATAKANA LETTER KO --> KATAKANA LETTER KO
68 MAKE_PAIR( 0xFF7B, 0x30B5 ), // HALFWIDTH KATAKANA LETTER SA --> KATAKANA LETTER SA
69 MAKE_PAIR( 0xFF7C, 0x30B7 ), // HALFWIDTH KATAKANA LETTER SI --> KATAKANA LETTER SI
70 MAKE_PAIR( 0xFF7D, 0x30B9 ), // HALFWIDTH KATAKANA LETTER SU --> KATAKANA LETTER SU
71 MAKE_PAIR( 0xFF7E, 0x30BB ), // HALFWIDTH KATAKANA LETTER SE --> KATAKANA LETTER SE
72 MAKE_PAIR( 0xFF7F, 0x30BD ), // HALFWIDTH KATAKANA LETTER SO --> KATAKANA LETTER SO
73 MAKE_PAIR( 0xFF80, 0x30BF ), // HALFWIDTH KATAKANA LETTER TA --> KATAKANA LETTER TA
74 MAKE_PAIR( 0xFF81, 0x30C1 ), // HALFWIDTH KATAKANA LETTER TI --> KATAKANA LETTER TI
75 MAKE_PAIR( 0xFF82, 0x30C4 ), // HALFWIDTH KATAKANA LETTER TU --> KATAKANA LETTER TU
76 MAKE_PAIR( 0xFF83, 0x30C6 ), // HALFWIDTH KATAKANA LETTER TE --> KATAKANA LETTER TE
77 MAKE_PAIR( 0xFF84, 0x30C8 ), // HALFWIDTH KATAKANA LETTER TO --> KATAKANA LETTER TO
78 MAKE_PAIR( 0xFF85, 0x30CA ), // HALFWIDTH KATAKANA LETTER NA --> KATAKANA LETTER NA
79 MAKE_PAIR( 0xFF86, 0x30CB ), // HALFWIDTH KATAKANA LETTER NI --> KATAKANA LETTER NI
80 MAKE_PAIR( 0xFF87, 0x30CC ), // HALFWIDTH KATAKANA LETTER NU --> KATAKANA LETTER NU
81 MAKE_PAIR( 0xFF88, 0x30CD ), // HALFWIDTH KATAKANA LETTER NE --> KATAKANA LETTER NE
82 MAKE_PAIR( 0xFF89, 0x30CE ), // HALFWIDTH KATAKANA LETTER NO --> KATAKANA LETTER NO
83 MAKE_PAIR( 0xFF8A, 0x30CF ), // HALFWIDTH KATAKANA LETTER HA --> KATAKANA LETTER HA
84 MAKE_PAIR( 0xFF8B, 0x30D2 ), // HALFWIDTH KATAKANA LETTER HI --> KATAKANA LETTER HI
85 MAKE_PAIR( 0xFF8C, 0x30D5 ), // HALFWIDTH KATAKANA LETTER HU --> KATAKANA LETTER HU
86 MAKE_PAIR( 0xFF8D, 0x30D8 ), // HALFWIDTH KATAKANA LETTER HE --> KATAKANA LETTER HE
87 MAKE_PAIR( 0xFF8E, 0x30DB ), // HALFWIDTH KATAKANA LETTER HO --> KATAKANA LETTER HO
88 MAKE_PAIR( 0xFF8F, 0x30DE ), // HALFWIDTH KATAKANA LETTER MA --> KATAKANA LETTER MA
89 MAKE_PAIR( 0xFF90, 0x30DF ), // HALFWIDTH KATAKANA LETTER MI --> KATAKANA LETTER MI
90 MAKE_PAIR( 0xFF91, 0x30E0 ), // HALFWIDTH KATAKANA LETTER MU --> KATAKANA LETTER MU
91 MAKE_PAIR( 0xFF92, 0x30E1 ), // HALFWIDTH KATAKANA LETTER ME --> KATAKANA LETTER ME
92 MAKE_PAIR( 0xFF93, 0x30E2 ), // HALFWIDTH KATAKANA LETTER MO --> KATAKANA LETTER MO
93 MAKE_PAIR( 0xFF94, 0x30E4 ), // HALFWIDTH KATAKANA LETTER YA --> KATAKANA LETTER YA
94 MAKE_PAIR( 0xFF95, 0x30E6 ), // HALFWIDTH KATAKANA LETTER YU --> KATAKANA LETTER YU
95 MAKE_PAIR( 0xFF96, 0x30E8 ), // HALFWIDTH KATAKANA LETTER YO --> KATAKANA LETTER YO
96 MAKE_PAIR( 0xFF97, 0x30E9 ), // HALFWIDTH KATAKANA LETTER RA --> KATAKANA LETTER RA
97 MAKE_PAIR( 0xFF98, 0x30EA ), // HALFWIDTH KATAKANA LETTER RI --> KATAKANA LETTER RI
98 MAKE_PAIR( 0xFF99, 0x30EB ), // HALFWIDTH KATAKANA LETTER RU --> KATAKANA LETTER RU
99 MAKE_PAIR( 0xFF9A, 0x30EC ), // HALFWIDTH KATAKANA LETTER RE --> KATAKANA LETTER RE
100 MAKE_PAIR( 0xFF9B, 0x30ED ), // HALFWIDTH KATAKANA LETTER RO --> KATAKANA LETTER RO
101 MAKE_PAIR( 0xFF9C, 0x30EF ), // HALFWIDTH KATAKANA LETTER WA --> KATAKANA LETTER WA
102 MAKE_PAIR( 0xFF9D, 0x30F3 ), // HALFWIDTH KATAKANA LETTER N --> KATAKANA LETTER N
103 MAKE_PAIR( 0xFF9E, 0x3099 ), // HALFWIDTH KATAKANA VOICED SOUND MARK --> COMBINING KATAKANA-HIRAGANA VOICED SOUND MARK
104 MAKE_PAIR( 0xFF9F, 0x309A ) // HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK --> COMBINING KATAKANA-
108 static struct hw_pair aCombine3099
[] =
138 static struct hw_pair aCombine309A
[] =
147 USHORT
ImplReplaceFullWidth( sal_Unicode
* pString
, USHORT nLen
)
149 sal_Unicode
* pRead
= pString
;
150 sal_Unicode
* pWrite
= pRead
;
151 USHORT nNewLen
= nLen
;
153 while( (pRead
- pString
) < nLen
)
155 if( pWrite
!= pRead
)
158 if( *pRead
>= 0xff65 && *pRead
<= 0xff9f )
160 *pWrite
= aHWPairs
[ *pRead
- 0xff65 ].nTo
;
162 struct hw_pair
* pTable
= NULL
;
163 int nTableEntries
= 0;
164 if( *pWrite
== 0x3099 )
166 // replace 0x3099 combinations
167 pTable
= aCombine3099
;
168 nTableEntries
= sizeof(aCombine3099
)/sizeof(aCombine3099
[0]);
170 else if( *pWrite
== 0x309a )
172 // replace 0x309a combinations
173 pTable
= aCombine309A
;
174 nTableEntries
= sizeof(aCombine309A
)/sizeof(aCombine309A
[0]);
178 sal_Unicode c
= pWrite
[-1];
179 for( int i
= 0; i
< nTableEntries
; i
++ )
180 if( c
== pTable
[i
].nFrom
)
183 *pWrite
= pTable
[i
].nTo
;
198 void ConvertHalfwitdhToFullwidth( String
& rString
)
200 USHORT nNewLen
= ImplReplaceFullWidth( rString
.GetBufferAccess(), rString
.Len() );
201 rString
.ReleaseBufferAccess( nNewLen
);