Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include <defaultnumberingprovider.hxx>
21 : : #include <com/sun/star/style/NumberingType.hpp>
22 : : #include <com/sun/star/beans/PropertyValue.hpp>
23 : : #include <com/sun/star/text/HoriOrientation.hpp>
24 : : #include <localedata.hxx>
25 : : #include <nativenumbersupplier.hxx>
26 : : #include <stdio.h>
27 : : #include <string.h>
28 : :
29 : : // Cyrillic upper case
30 : : #define C_CYR_A "\xD0\x90"
31 : : #define C_CYR_B "\xD0\x91"
32 : : // Cyrillic lower case
33 : : #define S_CYR_A "\xD0\xB0"
34 : : #define S_CYR_B "\xD0\xB1"
35 : :
36 : : //Greek upper case
37 : : #define C_GR_A "\xCE\x91"
38 : : #define C_GR_B "\xCE\x92"
39 : : //Greek lower case
40 : : #define S_GR_A "\xCE\xB1"
41 : : #define S_GR_B "\xCE\xB2"
42 : :
43 : : #include <math.h>
44 : : #include <sal/macros.h>
45 : : #include <rtl/ustring.hxx>
46 : : #include <rtl/ustrbuf.hxx>
47 : : #include <com/sun/star/i18n/XTransliteration.hpp>
48 : : #include <com/sun/star/i18n/TransliterationType.hpp>
49 : : #include <com/sun/star/i18n/TransliterationModulesNew.hpp>
50 : : #include <com/sun/star/i18n/XLocaleData.hpp>
51 : :
52 : : #include <bullet.h>
53 : :
54 : : using namespace com::sun::star;
55 : : using namespace com::sun::star::uno;
56 : : using namespace com::sun::star::lang;
57 : : using namespace ::rtl;
58 : :
59 : : namespace com { namespace sun { namespace star { namespace i18n {
60 : :
61 : : static sal_Unicode table_Alphabet_ar[] = {
62 : : 0x0623, 0x0628, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E,
63 : : 0x062F, 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635,
64 : : 0x0636, 0x0637, 0x0638, 0x0639, 0x063A, 0x0641, 0x0642,
65 : : 0x0643, 0x0644, 0x0645, 0x0646, 0x0647, 0x0648, 0x0649
66 : : };
67 : :
68 : : static sal_Unicode table_Alphabet_ar_abjad[] = {
69 : : 0x0627, 0x0628, 0x062c, 0x062f, 0x0647, 0x0648, 0x0632, 0x062d,
70 : : 0x0637, 0x064a, 0x0643, 0x0644, 0x0645, 0x0646, 0x0633, 0x0639,
71 : : 0x0641, 0x0635, 0x0642, 0x0631, 0x0634, 0x062a, 0x062b, 0x062e,
72 : : 0x0630, 0x0636, 0x0638, 0x063a
73 : : };
74 : :
75 : : static sal_Unicode table_Alphabet_th[] = {
76 : : 0x0E01, 0x0E02, 0x0E04, 0x0E07,
77 : : 0x0E08, 0x0E09, 0x0E0A, 0x0E0B, 0x0E0C, 0x0E0D, 0x0E0E, 0x0E0F,
78 : : 0x0E10, 0x0E11, 0x0E12, 0x0E13, 0x0E14, 0x0E15, 0x0E16, 0x0E17,
79 : : 0x0E18, 0x0E19, 0x0E1A, 0x0E1B, 0x0E1C, 0x0E1D, 0x0E1E, 0x0E1F,
80 : : 0x0E20, 0x0E21, 0x0E22, 0x0E23, 0x0E24, 0x0E25, 0x0E26, 0x0E27,
81 : : 0x0E28, 0x0E29, 0x0E2A, 0x0E2B, 0x0E2C, 0x0E2D, 0x0E2E
82 : : };
83 : :
84 : : static sal_Unicode table_Alphabet_he[] = {
85 : : 0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7,
86 : : 0x05D8, 0x05D9, 0x05DB, 0x05DC, 0x05DE, 0x05E0, 0x05E1, 0x05E2,
87 : : 0x05E4, 0x05E6, 0x05E7, 0x05E8, 0x05E9, 0x05EA
88 : : };
89 : :
90 : : static sal_Unicode table_Alphabet_ne[] = {
91 : : 0x0915, 0x0916, 0x0917, 0x0918, 0x0919, 0x091A, 0x091B, 0x091C,
92 : : 0x091D, 0x091E, 0x091F, 0x0920, 0x0921, 0x0922, 0x0923, 0x0924,
93 : : 0x0925, 0x0926, 0x0927, 0x0928, 0x092A, 0x092B, 0x092C, 0x092D,
94 : : 0x092E, 0x092F, 0x0930, 0x0932, 0x0935, 0x0936, 0x0937, 0x0938,
95 : : 0x0939
96 : : };
97 : :
98 : : static sal_Unicode table_Alphabet_km[] = {
99 : : 0x1780, 0x1781, 0x1782, 0x1783, 0x1784, 0x1785, 0x1786, 0x1787,
100 : : 0x1788, 0x1789, 0x178A, 0x178B, 0x178C, 0x178D, 0x178E, 0x178F,
101 : : 0x1790, 0x1791, 0x1792, 0x1793, 0x1794, 0x1795, 0x1796, 0x1797,
102 : : 0x1798, 0x1799, 0x179A, 0x179B, 0x179C, 0x179F,
103 : : 0x17A0, 0x17A1, 0x17A2
104 : : };
105 : :
106 : : static sal_Unicode table_Alphabet_lo[] = {
107 : : 0x0E81, 0x0E82, 0x0E84, 0x0E87, 0x0E88, 0x0E8A, 0x0E8D, 0x0E94,
108 : : 0x0E95, 0x0E96, 0x0E97, 0x0E99, 0x0E9A, 0x0E9B, 0x0E9C,
109 : : 0x0E9D, 0x0E9E, 0x0E9F, 0x0EA1, 0x0EA2, 0x0EA3, 0x0EA5, 0x0EA7,
110 : : 0x0EAA, 0x0EAB, 0x0EAD, 0x0EAE, 0x0EAF, 0x0EAE, 0x0EDC, 0x0EDD
111 : : };
112 : :
113 : : static sal_Unicode table_Alphabet_dz[] = {
114 : : 0x0F40, 0x0F41, 0x0F42, 0x0F44, 0x0F45, 0x0F46, 0x0F47, 0x0F49,
115 : : 0x0F4F, 0x0F50, 0x0F51, 0x0F53, 0x0F54, 0x0F55, 0x0F56, 0x0F58,
116 : : 0x0F59, 0x0F5A, 0x0F5B, 0x0F5D, 0x0F5E, 0x0F5F, 0x0F60, 0x0F61,
117 : : 0x0F62, 0x0F63, 0x0F64, 0x0F66, 0x0F67, 0x0F68
118 : : };
119 : :
120 : : static sal_Unicode table_Alphabet_my[] = {
121 : : 0x1000, 0x1001, 0x1002, 0x1003, 0x1004, 0x1005, 0x1006, 0x1007,
122 : : 0x1008,/*0x1009,*/0x100A, 0x100B, 0x100C, 0x100D, 0x100E, 0x100F,
123 : : 0x1010, 0x1011, 0x1012, 0x1013, 0x1014, 0x1015, 0x1016, 0x1017,
124 : : 0x1018, 0x1019, 0x101A, 0x101B, 0x101C, 0x101D, 0x101E, 0x101F,
125 : : 0x1020, 0x1021
126 : : };
127 : :
128 : : // Bulgarian Cyrillic upper case letters
129 : : static sal_Unicode table_CyrillicUpperLetter_bg[] = {
130 : : 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418,
131 : : 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F, 0x0420, 0x0421, 0x0422,
132 : : 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042A, 0x042E,
133 : : 0x042F
134 : : };
135 : :
136 : : // Bulgarian cyrillic lower case letters
137 : : static sal_Unicode table_CyrillicLowerLetter_bg[] = {
138 : : 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438,
139 : : 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F, 0x0440, 0x0441, 0x0442,
140 : : 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044A, 0x044E,
141 : : 0x044F
142 : : };
143 : :
144 : : // Russian Cyrillic upper letters
145 : : static sal_Unicode table_CyrillicUpperLetter_ru[] = {
146 : : 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
147 : : 0x0418, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F, 0x0420,
148 : : 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428,
149 : : 0x0429, 0x042B, 0x042D, 0x042E, 0x042F
150 : : };
151 : :
152 : : // Russian cyrillic lower letters
153 : : static sal_Unicode table_CyrillicLowerLetter_ru[] = {
154 : : 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437,
155 : : 0x0438, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F, 0x0440,
156 : : 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448,
157 : : 0x0449, 0x044B, 0x044D, 0x044E, 0x044F
158 : : };
159 : :
160 : : // Serbian Cyrillic upper letters
161 : : static sal_Unicode table_CyrillicUpperLetter_sr[] = {
162 : : 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0402, 0x0415, 0x0416,
163 : : 0x0417, 0x0418, 0x0408, 0x041A, 0x041B, 0x0409, 0x041C, 0x041D,
164 : : 0x040A, 0x041E, 0x041F, 0x0420, 0x0421, 0x0422, 0x040B, 0x0423,
165 : : 0x0424, 0x0425, 0x0426, 0x0427, 0x040F, 0x0428
166 : : };
167 : :
168 : : // Serbian cyrillic lower letters
169 : : static sal_Unicode table_CyrillicLowerLetter_sr[] = {
170 : : 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0452, 0x0435, 0x0436,
171 : : 0x0437, 0x0438, 0x0458, 0x043A, 0x043B, 0x0459, 0x043C, 0x043D,
172 : : 0x045A, 0x043E, 0x043F, 0x0440, 0x0441, 0x0442, 0x045B, 0x0443,
173 : : 0x0444, 0x0445, 0x0446, 0x0447, 0x045F, 0x0448
174 : : };
175 : :
176 : : static sal_Unicode table_GreekUpperLetter[] = {
177 : : 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x03DB, 0x0396, 0x0397, 0x0398,
178 : : 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F, 0x03A0, 0x03DF,
179 : : 0x03A1, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7, 0x03A8, 0x03A9, 0x03E0
180 : : };
181 : :
182 : : static sal_Unicode table_GreekLowerLetter[] = {
183 : : 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03DB, 0x03B6, 0x03B7, 0x03B8,
184 : : 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF, 0x03C0, 0x03DF,
185 : : 0x03C1, 0x03C3, 0x03C4, 0x03C5, 0x03C6, 0x03C7, 0x03C8, 0x03C9, 0x03E1
186 : : };
187 : :
188 : : static sal_Unicode table_Alphabet_fa[] = {
189 : : 0x0622, 0x0628, 0x067E, 0x062A, 0x062B, 0x062C, 0x0686, 0x062D,
190 : : 0x062E, 0x062F, 0x0630, 0x0631, 0x0632, 0x0698, 0x0633, 0x0634,
191 : : 0x0635, 0x0636, 0x0637, 0x0638, 0x0639, 0x0640, 0x0641, 0x0642,
192 : : 0x06A9, 0x06AF, 0x0644, 0x0645, 0x0646, 0x0648, 0x0647, 0x06CC
193 : : };
194 : :
195 : : static sal_Unicode upperLetter[] = {
196 : : 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
197 : : 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52,
198 : : 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A
199 : : };
200 : :
201 : : static sal_Unicode lowerLetter[] = {
202 : : 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
203 : : 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72,
204 : : 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A
205 : : };
206 : :
207 : : // Tables used for numbering in persian words
208 : : static sal_Unicode table_PersianWord_decade1[][7]={
209 : : {0}, // 0
210 : : {0x06cc, 0x06a9, 0}, // 1
211 : : {0x062f, 0x0648, 0}, // 2
212 : : {0x0633, 0x0647, 0}, // 3
213 : : {0x0686, 0x0647, 0x0627, 0x0631, 0}, // 4
214 : : {0x067e, 0x0646, 0x062c, 0}, // 5
215 : : {0x0634, 0x0634, 0}, // 6
216 : : {0x0647, 0x0641, 0x062a, 0}, // 7
217 : : {0x0647, 0x0634, 0x062a, 0}, // 8
218 : : {0x0646, 0x0647, 0}, // 9
219 : : {0x062f, 0x0647, 0}, // 10
220 : : {0x06cc, 0x0627, 0x0632, 0x062f, 0x0647, 0}, // 11
221 : : {0x062f, 0x0648, 0x0627, 0x0632, 0x062f, 0x0647, 0}, // 12
222 : : {0x0633, 0x06cc, 0x0632, 0x062f, 0x0647, 0}, // 13
223 : : {0x0686, 0x0647, 0x0627, 0x0631, 0x062f, 0x0647, 0}, // 14
224 : : {0x067e, 0x0627, 0x0646, 0x0632, 0x062f, 0x0647, 0}, // 15
225 : : {0x0634, 0x0627, 0x0646, 0x0632, 0x062f, 0x0647, 0}, // 16
226 : : {0x0647, 0x0641, 0x062f, 0x0647, 0}, // 17
227 : : {0x0647, 0x062c, 0x062f, 0x0647, 0}, // 18
228 : : {0x0646, 0x0648, 0x0632, 0x062f, 0x0647, 0} // 19
229 : : };
230 : :
231 : : static sal_Unicode table_PersianWord_decade2[][6]={
232 : : {0x0628, 0x06cc, 0x0633, 0x062a, 0}, // 20
233 : : {0x0633, 0x06cc, 0}, // 30
234 : : {0x0686, 0x0647, 0x0644, 0}, // 40
235 : : {0x067e, 0x0646, 0x062c, 0x0627, 0x0647, 0}, // 50
236 : : {0x0634, 0x0635, 0x062a, 0}, // 60
237 : : {0x0647, 0x0641, 0x062a, 0x0627, 0x062f, 0}, // 70
238 : : {0x0647, 0x0634, 0x062a, 0x0627, 0x062f, 0}, // 80
239 : : {0x0646, 0x0648, 0x062f, 0} // 90
240 : : };
241 : :
242 : : static sal_Unicode table_PersianWord_decade3[][7]={
243 : : {0x0635, 0x062f, 0}, // 100
244 : : {0x062f, 0x0648, 0x06cc, 0x0633, 0x062a, 0}, // 200
245 : : {0x0633, 0x06cc, 0x0635, 0x062f, 0}, // 300
246 : : {0x0686, 0x0647, 0x0627, 0x0631, 0x0635, 0x062f, 0}, // 400
247 : : {0x067e, 0x0627, 0x0646, 0x0635, 0x062f, 0}, // 500
248 : : {0x0634, 0x0635, 0x062f, 0}, // 600
249 : : {0x0647, 0x0641, 0x062a, 0x0635, 0x062f, 0}, // 700
250 : : {0x0647, 0x0634, 0x062a, 0x0635, 0x062f, 0}, // 800
251 : : {0x0646, 0x0647, 0x0635, 0x062f, 0} // 900
252 : : };
253 : :
254 : : static sal_Unicode table_PersianWord_decadeX[][8]={
255 : : {0x0647, 0x0632, 0x0627, 0x0631, 0}, // 1000
256 : : {0x0645, 0x06cc, 0x0644, 0x06cc, 0x0648, 0x0646, 0}, // 1000000
257 : : {0x0645, 0x06cc, 0x0644, 0x06cc, 0x0627, 0x0631, 0x062f, 0} // 1000000000
258 : : };
259 : :
260 : :
261 : 59 : DefaultNumberingProvider::DefaultNumberingProvider( const Reference < XMultiServiceFactory >& xMSF ) : xSMgr(xMSF),translit(NULL)
262 : : {
263 : :
264 : 59 : }
265 : :
266 : 53 : DefaultNumberingProvider::~DefaultNumberingProvider()
267 : : {
268 [ - + ][ # # ]: 53 : delete translit;
269 [ - + ]: 106 : }
270 : :
271 : 0 : void DefaultNumberingProvider::impl_loadTranslit()
272 : : {
273 [ # # ]: 0 : if ( !translit )
274 [ # # ]: 0 : translit = new TransliterationImpl(xSMgr);
275 : 0 : }
276 : :
277 : : Sequence< Reference<container::XIndexAccess> >
278 : 0 : DefaultNumberingProvider::getDefaultOutlineNumberings(const Locale& rLocale ) throw(RuntimeException)
279 : : {
280 [ # # ]: 0 : return LocaleData().getOutlineNumberingLevels( rLocale );
281 : : }
282 : :
283 : : Sequence< Sequence<beans::PropertyValue> >
284 : 0 : DefaultNumberingProvider::getDefaultContinuousNumberingLevels( const Locale& rLocale ) throw(RuntimeException)
285 : : {
286 [ # # ]: 0 : return LocaleData().getContinuousNumberingLevels( rLocale );
287 : : }
288 : :
289 : 232 : OUString toRoman( sal_Int32 n )
290 : : {
291 : :
292 : : // i, ii, iii, iv, v, vi, vii, vii, viii, ix
293 : : // (Dummy),1000,500,100,50,10,5,1
294 : : static const sal_Char coRomanArr[] = "MDCLXVI--"; // +2 Dummy entries !!
295 : 232 : const sal_Char* cRomanStr = coRomanArr;
296 : 232 : sal_uInt16 nMask = 1000;
297 : 232 : sal_uInt32 nOver1000 = n / nMask;
298 : 232 : n -= ( nOver1000 * nMask );
299 : :
300 : 232 : OUStringBuffer sTmp;
301 [ - + ]: 232 : while(nOver1000--)
302 [ # # ]: 0 : sTmp.append(sal_Unicode(*coRomanArr));
303 : :
304 [ + + ]: 1160 : while( nMask )
305 : : {
306 : 928 : sal_uInt8 nZahl = sal_uInt8( n / nMask );
307 : 928 : sal_uInt8 nDiff = 1;
308 : 928 : n %= nMask;
309 : :
310 [ - + ]: 928 : if( 5 < nZahl )
311 : : {
312 [ # # ]: 0 : if( nZahl < 9 )
313 [ # # ]: 0 : sTmp.append(sal_Unicode(*(cRomanStr-1)));
314 : 0 : ++nDiff;
315 : 0 : nZahl -= 5;
316 : : }
317 [ - + + - : 928 : switch( nZahl )
- + ]
318 : : {
319 [ # # ]: 0 : case 3: sTmp.append(sal_Unicode(*cRomanStr)); //no break!
320 [ + - ]: 18 : case 2: sTmp.append(sal_Unicode(*cRomanStr)); //no break!
321 [ + - ]: 232 : case 1: sTmp.append(sal_Unicode(*cRomanStr)); break;
322 [ # # ][ # # ]: 0 : case 4: sTmp.append(sal_Unicode(*cRomanStr)).append(sal_Unicode(*(cRomanStr-nDiff))); break;
323 [ # # ]: 0 : case 5: sTmp.append(sal_Unicode(*(cRomanStr-nDiff))); break;
324 : : }
325 : :
326 : 928 : nMask /= 10; // to the next decade
327 : 928 : cRomanStr += 2;
328 : : }
329 [ + - ]: 232 : return sTmp.makeStringAndClear();
330 : : }
331 : :
332 : : // not used:
333 : :
334 : : static
335 : 200 : void lcl_formatChars( sal_Unicode table[], int tableSize, int n, OUString& s )
336 : : {
337 : : // string representation of n is appended to s.
338 : : // if A=='A' then 0=>A, 1=>B, ..., 25=>Z, 26=>AA, 27=>AB, ...
339 : : // if A=='a' then 0=>a, 1=>b, ..., 25=>z, 26=>aa, 27=>ab, ...
340 : :
341 [ - + ]: 200 : if( n>=tableSize ) lcl_formatChars( table, tableSize, (n-tableSize)/tableSize, s );
342 : :
343 : 200 : s += OUString::valueOf( table[ n % tableSize ] );
344 : 200 : }
345 : :
346 : : static
347 : 0 : void lcl_formatChars1( sal_Unicode table[], int tableSize, int n, OUString& s )
348 : : {
349 : : // string representation of n is appended to s.
350 : : // if A=='A' then 0=>A, 1=>B, ..., 25=>Z, 26=>AA, 27=>BB, ...
351 : : // if A=='a' then 0=>a, 1=>b, ..., 25=>z, 26=>aa, 27=>bb, ...
352 : :
353 : 0 : int repeat_count = n / tableSize + 1;
354 : :
355 [ # # ]: 0 : for( int i=0; i<repeat_count; i++ )
356 : 0 : s += OUString::valueOf( table[ n%tableSize ] );
357 : 0 : }
358 : :
359 : : static
360 : 0 : void lcl_formatChars2( sal_Unicode table_capital[], sal_Unicode table_small[], int tableSize, int n, OUString& s )
361 : : {
362 : : // string representation of n is appended to s.
363 : : // if A=='A' then 0=>A, 1=>B, ..., 25=>Z, 26=>Aa, 27=>Ab, ...
364 : :
365 [ # # ]: 0 : if( n>=tableSize )
366 : : {
367 : 0 : lcl_formatChars2( table_capital, table_small, tableSize, (n-tableSize)/tableSize, s );
368 : 0 : s += OUString::valueOf( table_small[ n % tableSize ] );
369 : : } else
370 : 0 : s += OUString::valueOf( table_capital[ n % tableSize ] );
371 : 0 : }
372 : :
373 : : static
374 : 0 : void lcl_formatChars3( sal_Unicode table_capital[], sal_Unicode table_small[], int tableSize, int n, OUString& s )
375 : : {
376 : : // string representation of n is appended to s.
377 : : // if A=='A' then 0=>A, 1=>B, ..., 25=>Z, 26=>Aa, 27=>Bb, ...
378 : :
379 : 0 : int repeat_count = n / tableSize + 1;
380 : 0 : s += OUString::valueOf( table_capital[ n%tableSize ] );
381 : :
382 [ # # ]: 0 : for( int i=1; i<repeat_count; i++ )
383 : 0 : s += OUString::valueOf( table_small[ n%tableSize ] );
384 : 0 : }
385 : :
386 : :
387 : : /** Returns number's representation in persian words up to 999999999999
388 : : respectively limited by sal_Int32 >=0.
389 : : The caller assures that nNumber is not negative.
390 : : */
391 : : static
392 : 0 : void lcl_formatPersianWord( sal_Int32 nNumber, OUString& rsResult )
393 : : throw( IllegalArgumentException, RuntimeException )
394 : : {
395 : 0 : OUStringBuffer aTemp(64);
396 : : unsigned int nDigit;
397 : 0 : sal_Unicode asPersianWord_conjunction_data[] = {0x20,0x0648,0x20,0};
398 : 0 : OUString asPersianWord_conjunction( asPersianWord_conjunction_data );
399 : 0 : unsigned char nSection = 0;
400 : :
401 [ # # ]: 0 : while (int nPart = nNumber % 1000)
402 : : {
403 [ # # ]: 0 : if (nSection)
404 : : {
405 [ # # ]: 0 : if (nSection > SAL_N_ELEMENTS( table_PersianWord_decadeX))
406 [ # # ]: 0 : throw IllegalArgumentException(); // does not happen with sal_Int32
407 [ # # ][ # # ]: 0 : aTemp.insert( 0, asPersianWord_conjunction).insert( 0, table_PersianWord_decadeX[nSection-1]);
408 : : }
409 : :
410 [ # # ]: 0 : if ((nDigit = nPart % 100) < 20)
411 : : {
412 [ # # ]: 0 : if (aTemp.getLength())
413 [ # # ]: 0 : aTemp.insert( 0, sal_Unicode(0x0020));
414 [ # # ]: 0 : aTemp.insert( 0, table_PersianWord_decade1[nDigit]);
415 : : }
416 : : else
417 : : {
418 [ # # ]: 0 : if ((nDigit = nPart % 10) != 0)
419 : : {
420 [ # # ]: 0 : if (aTemp.getLength())
421 [ # # ]: 0 : aTemp.insert( 0, asPersianWord_conjunction);
422 [ # # ]: 0 : aTemp.insert( 0, table_PersianWord_decade1[nDigit]);
423 : : }
424 [ # # ]: 0 : if ((nDigit = (nPart / 10) % 10) != 0)
425 : : {
426 [ # # ]: 0 : if (aTemp.getLength())
427 [ # # ]: 0 : aTemp.insert( 0, asPersianWord_conjunction);
428 [ # # ]: 0 : aTemp.insert( 0, table_PersianWord_decade2[nDigit-2]);
429 : : }
430 : : }
431 : :
432 [ # # ]: 0 : if ((nDigit = nPart / 100) != 0)
433 : : {
434 [ # # ]: 0 : if (aTemp.getLength())
435 [ # # ]: 0 : aTemp.insert( 0, asPersianWord_conjunction);
436 [ # # ]: 0 : aTemp.insert( 0, table_PersianWord_decade3[nDigit-1]);
437 : : }
438 : :
439 : 0 : nNumber /= 1000;
440 : 0 : nSection++;
441 : : }
442 [ # # ]: 0 : rsResult += aTemp.makeStringAndClear();
443 : 0 : }
444 : :
445 : :
446 : : // Greek Letter Numbering
447 : :
448 : : // KERAIA separates numerals from other text
449 : : #define STIGMA (sal_Unicode) 0x03DB
450 : : #define LEFT_KERAIA (sal_Unicode) 0x0375
451 : : #define MYRIAD_SYM (sal_Unicode) 0x039C
452 : : #define DOT_SYM (sal_Unicode) 0x002E
453 : : #define SIGMA_OFFSET 19
454 : : #define TAU_OFFSET 20
455 : : #define MYRIAD 10000
456 : :
457 : : /*
458 : : * Return the 1-999999 number's representation in the Greek numbering system.
459 : : * Adding a "left keraia" to represent numbers in the range 10000 ... 999999 is
460 : : * not orthodox, so it's better to use the myriad notation and call this method
461 : : * only for numbers up to 9999.
462 : : */
463 : : static
464 : 0 : OUString gr_smallNum(sal_Unicode table[], int n)
465 : : {
466 [ # # ]: 0 : if (n > 9999)
467 [ # # ]: 0 : throw IllegalArgumentException();
468 : :
469 : 0 : int i = 0;
470 : 0 : OUStringBuffer sb;
471 [ # # ]: 0 : for (int v = n; v > 0; v /= 10, i++) {
472 : 0 : int digit = v % 10;
473 [ # # ]: 0 : if (digit == 0)
474 : 0 : continue;
475 : :
476 : 0 : sal_Unicode sign = table[(digit - 1) + 9 * (i % 3)];
477 [ # # ]: 0 : if (sign == STIGMA) {
478 [ # # ]: 0 : sb.insert(0, table[TAU_OFFSET]);
479 [ # # ]: 0 : sb.insert(0, table[SIGMA_OFFSET]);
480 : : } else {
481 [ # # ]: 0 : sb.insert(0, sign);
482 : : }
483 : :
484 [ # # ]: 0 : if (i > 2)
485 [ # # ]: 0 : sb.insert(0, LEFT_KERAIA);
486 : : }
487 : :
488 [ # # ]: 0 : return sb.makeStringAndClear();
489 : : }
490 : :
491 : : static
492 : 0 : void lcl_formatCharsGR( sal_Unicode table[], int n, OUString& s )
493 : : {
494 : 0 : OUStringBuffer sb;
495 : 0 : int myriadPower = 2;
496 : :
497 [ # # ]: 0 : for (int divisor = MYRIAD * MYRIAD; divisor > 1; divisor /= MYRIAD, myriadPower--) {
498 [ # # ]: 0 : if (n > divisor - 1) {
499 : : /*
500 : : * Follow the Diophantus representation of:
501 : : * A myriad sign, M(10000) as many times as the power
502 : : * followed by the multiplier for the myriad
503 : : * followed by a dot
504 : : * followed by the rest
505 : : * This is enough for 32-bit integers
506 : : */
507 [ # # ]: 0 : for (int i = 0; i < myriadPower; i++)
508 [ # # ]: 0 : sb.append(MYRIAD_SYM);
509 : :
510 [ # # ][ # # ]: 0 : sb.append(gr_smallNum(table, n/divisor));
511 : 0 : n %= divisor;
512 : :
513 [ # # ]: 0 : if (n > 0)
514 [ # # ]: 0 : sb.append(DOT_SYM);
515 : : }
516 : : }
517 [ # # ][ # # ]: 0 : sb.append(gr_smallNum(table,n));
518 : :
519 [ # # ]: 0 : s += sb.makeStringAndClear();
520 : 0 : }
521 : :
522 : : static
523 : 5250 : int should_ignore( OUString s )
524 : : {
525 : : // return true if blank or null
526 [ + - ][ - + ]: 5250 : return s.compareToAscii(" ")==0 || (!s.isEmpty() && s[0]==0);
[ # # ]
527 : : }
528 : :
529 : : static
530 : 10500 : Any getPropertyByName( const Sequence<beans::PropertyValue>& aProperties,
531 : : const char* name, sal_Bool bRequired )
532 : : {
533 [ + + ]: 23625 : for( int i=0; i<aProperties.getLength(); i++ )
534 [ + + ]: 18375 : if( aProperties[i].Name.equalsAscii(name) )
535 : 5250 : return aProperties[i].Value;
536 [ - + ]: 5250 : if(bRequired)
537 [ # # ]: 0 : throw IllegalArgumentException();
538 : 10500 : return Any();
539 : : }
540 : :
541 : : //XNumberingFormatter
542 : : OUString
543 : 2625 : DefaultNumberingProvider::makeNumberingString( const Sequence<beans::PropertyValue>& aProperties,
544 : : const Locale& aLocale )
545 : : throw( IllegalArgumentException, RuntimeException )
546 : : {
547 : : // the Sequence of PropertyValues is expected to have at least 4 elements:
548 : : // elt Name Type purpose
549 : : // -----------------------------------------------------------------
550 : : //
551 : : // 0. "Prefix" OUString
552 : : // 1. "NumberingType" sal_Int16 type of formatting from style::NumberingType (roman, arabic, etc)
553 : : // 2. "Suffix" OUString
554 : : // ... ... ...
555 : : // n. "Value" sal_Int32 the number to be formatted
556 : : // example:
557 : : // given the Sequence { '(', NumberingType::ROMAN_UPPER, ')', ..., 7 }
558 : : // makeNumberingString() returns the string "(VII)".
559 : :
560 : : // Q: why is the type of numType sal_Int16 instead of style::NumberingType?
561 : : // A: an Any can't hold a style::NumberingType for some reason.
562 : : // add.: style::NumberingType holds constants of type sal_Int16, it's not an enum type
563 : :
564 : 2625 : sal_Int16 natNum = 0;
565 : 2625 : sal_Int16 tableSize = 0;
566 : 2625 : sal_Unicode *table = NULL; // initialize to avoid compiler warning
567 : 2625 : sal_Bool recycleSymbol = sal_False;
568 : 2625 : Locale locale;
569 : :
570 : 2625 : OUString prefix;
571 : 2625 : sal_Int16 numType = -1; // type of formatting from style::NumberingType (roman, arabic, etc)
572 : 2625 : OUString suffix;
573 : 2625 : sal_Int32 number = -12345; // the number that needs to be formatted.
574 : :
575 : : // int nProperties = aProperties.getLength();
576 : : // int last = nProperties-1;
577 : :
578 : : try {
579 [ + - ]: 2625 : getPropertyByName(aProperties, "Prefix", sal_False) >>=prefix;
580 [ # # # # ]: 0 : } catch (Exception&) {
581 : : //prefix _must_ be empty here!
582 : : }
583 : : try {
584 [ + - ]: 2625 : getPropertyByName(aProperties, "Suffix", sal_False) >>=suffix;
585 [ # # # # ]: 0 : } catch (Exception&) {
586 : : //suffix _must_ be empty here!
587 : : }
588 : : try {
589 [ + - ]: 2625 : getPropertyByName(aProperties, "NumberingType", sal_True) >>=numType;
590 [ # # # # ]: 0 : } catch (Exception& ) {
591 : 0 : numType = -1;
592 : : }
593 : : try {
594 [ + - ]: 2625 : getPropertyByName(aProperties, "Value", sal_True) >>=number;
595 [ # # ]: 0 : } catch (Exception& ) {
596 : 0 : number = -1;
597 : : }
598 : :
599 [ - + ]: 2625 : if( number <= 0 )
600 [ # # ]: 0 : throw IllegalArgumentException();
601 : :
602 : : // start empty
603 : 2625 : OUString result;
604 : :
605 : : // append prefix
606 [ + - ]: 2625 : if( !should_ignore(prefix) ) result += prefix;
607 : :
608 : : // append formatted number
609 : : using namespace style::NumberingType;
610 [ + + + + : 2625 : switch( numType )
+ - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - ]
611 : : {
612 : : case CHARS_UPPER_LETTER:
613 [ + - ]: 80 : lcl_formatChars( upperLetter, 26, number-1, result ); // 1=>A, 2=>B, ..., 26=>Z, 27=>AA, 28=>AB, ...
614 : 80 : break;
615 : : case CHARS_LOWER_LETTER:
616 [ + - ]: 120 : lcl_formatChars( lowerLetter, 26, number-1, result );
617 : 120 : break;
618 : : case ROMAN_UPPER:
619 [ + - ]: 13 : result += toRoman( number );
620 : 13 : break;
621 : : case ROMAN_LOWER:
622 [ + - ]: 219 : result += toRoman( number ).toAsciiLowerCase();
623 : 219 : break;
624 : : case ARABIC:
625 : 2193 : result += OUString::valueOf( number );
626 : 2193 : break;
627 : : case NUMBER_NONE:
628 : 0 : return OUString(""); // ignore prefix and suffix
629 : : case CHAR_SPECIAL:
630 : : // apparently, we're supposed to return an empty string in this case...
631 : 0 : return OUString(""); // ignore prefix and suffix
632 : : case PAGE_DESCRIPTOR:
633 : : case BITMAP:
634 : : OSL_ASSERT(0);
635 [ # # ]: 0 : throw IllegalArgumentException();
636 : : case CHARS_UPPER_LETTER_N:
637 : 0 : lcl_formatChars1( upperLetter, 26, number-1, result ); // 1=>A, 2=>B, ..., 26=>Z, 27=>AA, 28=>BB, ...
638 : 0 : break;
639 : : case CHARS_LOWER_LETTER_N:
640 : 0 : lcl_formatChars1( lowerLetter, 26, number-1, result ); // 1=>A, 2=>B, ..., 26=>Z, 27=>AA, 28=>BB, ...
641 : 0 : break;
642 : : case TRANSLITERATION:
643 : : try {
644 : 0 : const OUString &tmp = OUString::valueOf( number );
645 : 0 : OUString transliteration;
646 [ # # ]: 0 : getPropertyByName(aProperties, "Transliteration", sal_True) >>= transliteration;
647 [ # # ]: 0 : impl_loadTranslit();
648 [ # # ]: 0 : translit->loadModuleByImplName(transliteration, aLocale);
649 [ # # ][ # # ]: 0 : result += translit->transliterateString2String(tmp, 0, tmp.getLength());
650 [ # # ]: 0 : } catch (Exception& ) {
651 : : // When translteration property is missing, return default number (bug #101141#)
652 : 0 : result += OUString::valueOf( number );
653 : : // OSL_ASSERT(0);
654 : : // throw IllegalArgumentException();
655 : : }
656 : 0 : break;
657 : : case NATIVE_NUMBERING:
658 : 0 : natNum = NativeNumberMode::NATNUM1;
659 : 0 : locale = aLocale;
660 : 0 : break;
661 : : case FULLWIDTH_ARABIC:
662 : 0 : natNum = NativeNumberMode::NATNUM3;
663 : 0 : locale = aLocale;
664 : 0 : break;
665 : : case NUMBER_LOWER_ZH:
666 : 0 : natNum = NativeNumberMode::NATNUM7;
667 : 0 : locale.Language = OUString("zh");
668 : 0 : break;
669 : : case NUMBER_UPPER_ZH_TW:
670 : 0 : locale.Country = OUString("TW");
671 : : case NUMBER_UPPER_ZH:
672 : 0 : natNum = NativeNumberMode::NATNUM8;
673 : 0 : locale.Language = OUString("zh");
674 : 0 : break;
675 : : case NUMBER_TRADITIONAL_JA:
676 : 0 : natNum = NativeNumberMode::NATNUM8;
677 : 0 : locale.Language = OUString("ja");
678 : 0 : break;
679 : : case NUMBER_UPPER_KO:
680 : 0 : natNum = NativeNumberMode::NATNUM8;
681 : 0 : locale.Language = OUString("ko");
682 : 0 : break;
683 : : case NUMBER_HANGUL_KO:
684 : 0 : natNum = NativeNumberMode::NATNUM11;
685 : 0 : locale.Language = OUString("ko");
686 : 0 : break;
687 : :
688 : : case CIRCLE_NUMBER:
689 : 0 : table = table_CircledNumber;
690 : 0 : tableSize = SAL_N_ELEMENTS(table_CircledNumber);
691 : 0 : break;
692 : : case TIAN_GAN_ZH:
693 : 0 : table = table_TianGan_zh;
694 : 0 : tableSize = SAL_N_ELEMENTS(table_TianGan_zh);
695 : 0 : break;
696 : : case DI_ZI_ZH:
697 : 0 : table = table_DiZi_zh;
698 : 0 : tableSize = SAL_N_ELEMENTS(table_DiZi_zh);
699 : 0 : break;
700 : : case AIU_FULLWIDTH_JA:
701 : 0 : table = table_AIUFullWidth_ja_JP;
702 : 0 : tableSize = SAL_N_ELEMENTS(table_AIUFullWidth_ja_JP);
703 : 0 : recycleSymbol = sal_True;
704 : 0 : break;
705 : : case AIU_HALFWIDTH_JA:
706 : 0 : table = table_AIUHalfWidth_ja_JP;
707 : 0 : tableSize = SAL_N_ELEMENTS(table_AIUHalfWidth_ja_JP);
708 : 0 : recycleSymbol = sal_True;
709 : 0 : break;
710 : : case IROHA_FULLWIDTH_JA:
711 : 0 : table = table_IROHAFullWidth_ja_JP;
712 : 0 : tableSize = SAL_N_ELEMENTS(table_IROHAFullWidth_ja_JP);
713 : 0 : recycleSymbol = sal_True;
714 : 0 : break;
715 : : case IROHA_HALFWIDTH_JA:
716 : 0 : table = table_IROHAHalfWidth_ja_JP;
717 : 0 : tableSize = SAL_N_ELEMENTS(table_IROHAHalfWidth_ja_JP);
718 : 0 : recycleSymbol = sal_True;
719 : 0 : break;
720 : : case HANGUL_JAMO_KO:
721 : 0 : table = table_HangulJamo_ko;
722 : 0 : tableSize = SAL_N_ELEMENTS(table_HangulJamo_ko);
723 : 0 : recycleSymbol = sal_True;
724 : 0 : break;
725 : : case HANGUL_SYLLABLE_KO:
726 : 0 : table = table_HangulSyllable_ko;
727 : 0 : tableSize = SAL_N_ELEMENTS(table_HangulSyllable_ko);
728 : 0 : recycleSymbol = sal_True;
729 : 0 : break;
730 : : case HANGUL_CIRCLED_JAMO_KO:
731 : 0 : table = table_HangulCircledJamo_ko;
732 : 0 : tableSize = SAL_N_ELEMENTS(table_HangulCircledJamo_ko);
733 : 0 : recycleSymbol = sal_True;
734 : 0 : break;
735 : : case HANGUL_CIRCLED_SYLLABLE_KO:
736 : 0 : table = table_HangulCircledSyllable_ko;
737 : 0 : tableSize = SAL_N_ELEMENTS(table_HangulCircledSyllable_ko);
738 : 0 : recycleSymbol = sal_True;
739 : 0 : break;
740 : : case CHARS_ARABIC:
741 [ # # ]: 0 : lcl_formatChars(table_Alphabet_ar, SAL_N_ELEMENTS(table_Alphabet_ar), number - 1, result);
742 : 0 : break;
743 : : case CHARS_ARABIC_ABJAD:
744 [ # # ]: 0 : lcl_formatChars(table_Alphabet_ar_abjad, SAL_N_ELEMENTS(table_Alphabet_ar_abjad), number - 1, result);
745 : 0 : break;
746 : : case CHARS_THAI:
747 [ # # ]: 0 : lcl_formatChars(table_Alphabet_th, SAL_N_ELEMENTS(table_Alphabet_th), number - 1, result);
748 : 0 : break;
749 : : case CHARS_HEBREW:
750 [ # # ]: 0 : lcl_formatChars(table_Alphabet_he, SAL_N_ELEMENTS(table_Alphabet_he), number - 1, result);
751 : 0 : break;
752 : : case CHARS_NEPALI:
753 [ # # ]: 0 : lcl_formatChars(table_Alphabet_ne, SAL_N_ELEMENTS(table_Alphabet_ne), number - 1, result);
754 : 0 : break;
755 : : case CHARS_KHMER:
756 [ # # ]: 0 : lcl_formatChars(table_Alphabet_km, SAL_N_ELEMENTS(table_Alphabet_km), number - 1, result);
757 : 0 : break;
758 : : case CHARS_LAO:
759 [ # # ]: 0 : lcl_formatChars(table_Alphabet_lo, SAL_N_ELEMENTS(table_Alphabet_lo), number - 1, result);
760 : 0 : break;
761 : : case CHARS_MYANMAR:
762 [ # # ]: 0 : lcl_formatChars(table_Alphabet_my, SAL_N_ELEMENTS(table_Alphabet_my), number - 1, result);
763 : 0 : break;
764 : : case CHARS_TIBETAN:
765 [ # # ]: 0 : lcl_formatChars(table_Alphabet_dz, SAL_N_ELEMENTS(table_Alphabet_dz), number - 1, result);
766 : 0 : break;
767 : : case CHARS_CYRILLIC_UPPER_LETTER_BG:
768 : : lcl_formatChars2( table_CyrillicUpperLetter_bg,
769 : : table_CyrillicLowerLetter_bg,
770 : : SAL_N_ELEMENTS(table_CyrillicLowerLetter_bg), number-1,
771 [ # # ]: 0 : result); // 1=>a, 2=>b, ..., 28=>z, 29=>Aa, 30=>Ab, ...
772 : 0 : break;
773 : : case CHARS_CYRILLIC_LOWER_LETTER_BG:
774 : : lcl_formatChars( table_CyrillicLowerLetter_bg,
775 : : SAL_N_ELEMENTS(table_CyrillicLowerLetter_bg), number-1,
776 [ # # ]: 0 : result); // 1=>a, 2=>b, ..., 28=>z, 29=>aa, 30=>ab, ...
777 : 0 : break;
778 : : case CHARS_CYRILLIC_UPPER_LETTER_N_BG:
779 : : lcl_formatChars3( table_CyrillicUpperLetter_bg,
780 : : table_CyrillicLowerLetter_bg,
781 : : SAL_N_ELEMENTS(table_CyrillicLowerLetter_bg), number-1,
782 : 0 : result); // 1=>a, 2=>b, ..., 28=>z, 29=>Aa, 30=>Bb, ...
783 : 0 : break;
784 : : case CHARS_CYRILLIC_LOWER_LETTER_N_BG:
785 : : lcl_formatChars1( table_CyrillicLowerLetter_bg,
786 : : SAL_N_ELEMENTS(table_CyrillicLowerLetter_bg), number-1,
787 : 0 : result); // 1=>a, 2=>b, ..., 28=>z, 29=>aa, 30=>bb, ...
788 : 0 : break;
789 : : case CHARS_CYRILLIC_UPPER_LETTER_RU:
790 : : lcl_formatChars2( table_CyrillicUpperLetter_ru,
791 : : table_CyrillicLowerLetter_ru,
792 : : SAL_N_ELEMENTS(table_CyrillicLowerLetter_ru), number-1,
793 [ # # ]: 0 : result); // 1=>a, 2=>b, ..., 27=>z, 28=>Aa, 29=>Ab, ...
794 : 0 : break;
795 : : case CHARS_CYRILLIC_LOWER_LETTER_RU:
796 : : lcl_formatChars( table_CyrillicLowerLetter_ru,
797 : : SAL_N_ELEMENTS(table_CyrillicLowerLetter_ru), number-1,
798 [ # # ]: 0 : result); // 1=>a, 2=>b, ..., 27=>z, 28=>aa, 29=>ab, ...
799 : 0 : break;
800 : : case CHARS_CYRILLIC_UPPER_LETTER_N_RU:
801 : : lcl_formatChars3( table_CyrillicUpperLetter_ru,
802 : : table_CyrillicLowerLetter_ru,
803 : : SAL_N_ELEMENTS(table_CyrillicLowerLetter_ru), number-1,
804 : 0 : result); // 1=>a, 2=>b, ..., 27=>z, 28=>Aa, 29=>Bb, ...
805 : 0 : break;
806 : : case CHARS_CYRILLIC_LOWER_LETTER_N_RU:
807 : : lcl_formatChars1( table_CyrillicLowerLetter_ru,
808 : : SAL_N_ELEMENTS(table_CyrillicLowerLetter_ru), number-1,
809 : 0 : result); // 1=>a, 2=>b, ..., 27=>z, 28=>aa, 29=>bb, ...
810 : 0 : break;
811 : : case CHARS_CYRILLIC_UPPER_LETTER_SR:
812 : : lcl_formatChars2( table_CyrillicUpperLetter_sr,
813 : : table_CyrillicLowerLetter_sr,
814 : : SAL_N_ELEMENTS(table_CyrillicLowerLetter_sr), number-1,
815 [ # # ]: 0 : result); // 1=>a, 2=>b, ..., 27=>z, 28=>Aa, 29=>Ab, ...
816 : 0 : break;
817 : : case CHARS_CYRILLIC_LOWER_LETTER_SR:
818 : : lcl_formatChars( table_CyrillicLowerLetter_sr,
819 : : SAL_N_ELEMENTS(table_CyrillicLowerLetter_sr), number-1,
820 [ # # ]: 0 : result); // 1=>a, 2=>b, ..., 27=>z, 28=>aa, 29=>ab, ...
821 : 0 : break;
822 : : case CHARS_CYRILLIC_UPPER_LETTER_N_SR:
823 : : lcl_formatChars3( table_CyrillicUpperLetter_sr,
824 : : table_CyrillicLowerLetter_sr,
825 : : SAL_N_ELEMENTS(table_CyrillicLowerLetter_sr), number-1,
826 : 0 : result); // 1=>a, 2=>b, ..., 27=>z, 28=>Aa, 29=>Bb, ...
827 : 0 : break;
828 : : case CHARS_CYRILLIC_LOWER_LETTER_N_SR:
829 : : lcl_formatChars1( table_CyrillicLowerLetter_sr,
830 : : SAL_N_ELEMENTS(table_CyrillicLowerLetter_sr), number-1,
831 : 0 : result); // 1=>a, 2=>b, ..., 27=>z, 28=>aa, 29=>bb, ...
832 : 0 : break;
833 : :
834 : : case CHARS_GREEK_LOWER_LETTER:
835 [ # # ]: 0 : lcl_formatCharsGR( table_GreekLowerLetter, number, result);
836 : 0 : break;
837 : :
838 : : case CHARS_GREEK_UPPER_LETTER:
839 [ # # ]: 0 : lcl_formatCharsGR( table_GreekUpperLetter, number, result);
840 : 0 : break;
841 : :
842 : : case CHARS_PERSIAN:
843 [ # # ]: 0 : lcl_formatChars(table_Alphabet_fa, SAL_N_ELEMENTS(table_Alphabet_fa), number - 1, result);
844 : 0 : break;
845 : :
846 : : case CHARS_PERSIAN_WORD:
847 [ # # ]: 0 : lcl_formatPersianWord(number, result);
848 : 0 : break;
849 : :
850 : : default:
851 : : OSL_ASSERT(0);
852 [ # # ]: 0 : throw IllegalArgumentException();
853 : : }
854 : :
855 [ - + ]: 2625 : if (natNum) {
856 [ # # ]: 0 : NativeNumberSupplier sNatNum;
857 [ # # ][ # # ]: 0 : result += sNatNum.getNativeNumberString(OUString::valueOf( number ), locale, natNum);
858 [ - + ]: 2625 : } else if (tableSize) {
859 [ # # ][ # # ]: 0 : if ( number > tableSize && !recycleSymbol)
860 : 0 : result += OUString::valueOf( number);
861 : : else
862 : 0 : result += OUString(&table[--number % tableSize], 1);
863 : : }
864 : :
865 : : // append suffix
866 [ + - ]: 2625 : if( !should_ignore(suffix) ) result += suffix;
867 : :
868 [ # # ]: 2625 : return result;
869 : : }
870 : :
871 : : #define LANG_ALL (1 << 0)
872 : : #define LANG_CJK (1 << 1)
873 : : #define LANG_CTL (1 << 2)
874 : :
875 : : struct Supported_NumberingType
876 : : {
877 : : sal_Int16 nType;
878 : : const sal_Char* cSymbol;
879 : : sal_Int16 langOption;
880 : : };
881 : : static const Supported_NumberingType aSupportedTypes[] =
882 : : {
883 : : {style::NumberingType::CHARS_UPPER_LETTER, "A", LANG_ALL},
884 : : {style::NumberingType::CHARS_LOWER_LETTER, "a", LANG_ALL},
885 : : {style::NumberingType::ROMAN_UPPER, "I", LANG_ALL},
886 : : {style::NumberingType::ROMAN_LOWER, "i", LANG_ALL},
887 : : {style::NumberingType::ARABIC, "1", LANG_ALL},
888 : : {style::NumberingType::NUMBER_NONE, "''", LANG_ALL},
889 : : {style::NumberingType::CHAR_SPECIAL, "Bullet", LANG_ALL},
890 : : {style::NumberingType::PAGE_DESCRIPTOR, "Page", LANG_ALL},
891 : : {style::NumberingType::BITMAP, "Bitmap", LANG_ALL},
892 : : {style::NumberingType::CHARS_UPPER_LETTER_N, "AAA", LANG_ALL},
893 : : {style::NumberingType::CHARS_LOWER_LETTER_N, "aaa", LANG_ALL},
894 : : {style::NumberingType::NATIVE_NUMBERING, "Native Numbering", LANG_CJK|LANG_CTL},
895 : : {style::NumberingType::FULLWIDTH_ARABIC, NULL, LANG_CJK},
896 : : {style::NumberingType::CIRCLE_NUMBER, NULL, LANG_CJK},
897 : : {style::NumberingType::NUMBER_LOWER_ZH, NULL, LANG_CJK},
898 : : {style::NumberingType::NUMBER_UPPER_ZH, NULL, LANG_CJK},
899 : : {style::NumberingType::NUMBER_UPPER_ZH_TW, NULL, LANG_CJK},
900 : : {style::NumberingType::TIAN_GAN_ZH, NULL, LANG_CJK},
901 : : {style::NumberingType::DI_ZI_ZH, NULL, LANG_CJK},
902 : : {style::NumberingType::NUMBER_TRADITIONAL_JA, NULL, LANG_CJK},
903 : : {style::NumberingType::AIU_FULLWIDTH_JA, NULL, LANG_CJK},
904 : : {style::NumberingType::AIU_HALFWIDTH_JA, NULL, LANG_CJK},
905 : : {style::NumberingType::IROHA_FULLWIDTH_JA, NULL, LANG_CJK},
906 : : {style::NumberingType::IROHA_HALFWIDTH_JA, NULL, LANG_CJK},
907 : : {style::NumberingType::NUMBER_UPPER_KO, NULL, LANG_CJK},
908 : : {style::NumberingType::NUMBER_HANGUL_KO, NULL, LANG_CJK},
909 : : {style::NumberingType::HANGUL_JAMO_KO, NULL, LANG_CJK},
910 : : {style::NumberingType::HANGUL_SYLLABLE_KO, NULL, LANG_CJK},
911 : : {style::NumberingType::HANGUL_CIRCLED_JAMO_KO, NULL, LANG_CJK},
912 : : {style::NumberingType::HANGUL_CIRCLED_SYLLABLE_KO, NULL, LANG_CJK},
913 : : {style::NumberingType::CHARS_ARABIC, NULL, LANG_CTL},
914 : : {style::NumberingType::CHARS_ARABIC_ABJAD, NULL, LANG_CTL},
915 : : {style::NumberingType::CHARS_THAI, NULL, LANG_CTL},
916 : : {style::NumberingType::CHARS_HEBREW, NULL, LANG_CTL},
917 : : {style::NumberingType::CHARS_NEPALI, NULL, LANG_CTL},
918 : : {style::NumberingType::CHARS_KHMER, NULL, LANG_CTL},
919 : : {style::NumberingType::CHARS_LAO, NULL, LANG_CTL},
920 : : {style::NumberingType::CHARS_MYANMAR, NULL, LANG_CTL},
921 : : {style::NumberingType::CHARS_TIBETAN, NULL, LANG_CTL},
922 : : {style::NumberingType::CHARS_CYRILLIC_UPPER_LETTER_BG, C_CYR_A ", " C_CYR_B ", .., " C_CYR_A S_CYR_A ", " C_CYR_A S_CYR_B ", ... (bg)", LANG_ALL},
923 : : {style::NumberingType::CHARS_CYRILLIC_LOWER_LETTER_BG, S_CYR_A ", " S_CYR_B ", .., " S_CYR_A S_CYR_A ", " S_CYR_A S_CYR_B ", ... (bg)", LANG_ALL},
924 : : {style::NumberingType::CHARS_CYRILLIC_UPPER_LETTER_N_BG, C_CYR_A ", " C_CYR_B ", .., " C_CYR_A S_CYR_A ", " C_CYR_B S_CYR_B ", ... (bg)", LANG_ALL},
925 : : {style::NumberingType::CHARS_CYRILLIC_LOWER_LETTER_N_BG, S_CYR_A ", " S_CYR_B ", .., " S_CYR_A S_CYR_A ", " S_CYR_B S_CYR_B ", ... (bg)", LANG_ALL},
926 : : {style::NumberingType::CHARS_CYRILLIC_UPPER_LETTER_RU, C_CYR_A ", " C_CYR_B ", .., " C_CYR_A S_CYR_A ", " C_CYR_A S_CYR_B ", ... (ru)", LANG_ALL},
927 : : {style::NumberingType::CHARS_CYRILLIC_LOWER_LETTER_RU, S_CYR_A ", " S_CYR_B ", .., " S_CYR_A S_CYR_A ", " S_CYR_A S_CYR_B ", ... (ru)", LANG_ALL},
928 : : {style::NumberingType::CHARS_CYRILLIC_UPPER_LETTER_N_RU, C_CYR_A ", " C_CYR_B ", .., " C_CYR_A S_CYR_A ", " C_CYR_B S_CYR_B ", ... (ru)", LANG_ALL},
929 : : {style::NumberingType::CHARS_CYRILLIC_LOWER_LETTER_N_RU, S_CYR_A ", " S_CYR_B ", .., " S_CYR_A S_CYR_A ", " S_CYR_B S_CYR_B ", ... (ru)", LANG_ALL},
930 : : {style::NumberingType::CHARS_CYRILLIC_UPPER_LETTER_SR, C_CYR_A ", " C_CYR_B ", .., " C_CYR_A S_CYR_A ", " C_CYR_A S_CYR_B ", ... (sr)", LANG_ALL},
931 : : {style::NumberingType::CHARS_CYRILLIC_LOWER_LETTER_SR, S_CYR_A ", " S_CYR_B ", .., " S_CYR_A S_CYR_A ", " S_CYR_A S_CYR_B ", ... (sr)", LANG_ALL},
932 : : {style::NumberingType::CHARS_CYRILLIC_UPPER_LETTER_N_SR, C_CYR_A ", " C_CYR_B ", .., " C_CYR_A S_CYR_A ", " C_CYR_B S_CYR_B ", ... (sr)", LANG_ALL},
933 : : {style::NumberingType::CHARS_CYRILLIC_LOWER_LETTER_N_SR, S_CYR_A ", " S_CYR_B ", .., " S_CYR_A S_CYR_A ", " S_CYR_B S_CYR_B ", ... (sr)", LANG_ALL},
934 : : {style::NumberingType::CHARS_PERSIAN, NULL, LANG_CTL},
935 : : {style::NumberingType::CHARS_PERSIAN_WORD, NULL, LANG_CTL},
936 : : {style::NumberingType::CHARS_GREEK_LOWER_LETTER, C_GR_A ", " C_GR_B ", ... (gr)", LANG_ALL},
937 : : {style::NumberingType::CHARS_GREEK_UPPER_LETTER, S_GR_A ", " S_GR_B ", ... (gr)", LANG_ALL},
938 : : };
939 : : static const sal_Int32 nSupported_NumberingTypes = sizeof(aSupportedTypes) / sizeof(Supported_NumberingType);
940 : :
941 : 0 : OUString DefaultNumberingProvider::makeNumberingIdentifier(sal_Int16 index)
942 : : throw(RuntimeException)
943 : : {
944 [ # # ]: 0 : if (aSupportedTypes[index].cSymbol)
945 : 0 : return OUString(aSupportedTypes[index].cSymbol, strlen(aSupportedTypes[index].cSymbol), RTL_TEXTENCODING_UTF8);
946 : : // return OUString::createFromAscii(aSupportedTypes[index].cSymbol);
947 : : else {
948 : 0 : OUString result;
949 : 0 : Locale aLocale(OUString("en"), OUString(), OUString());
950 [ # # ]: 0 : Sequence<beans::PropertyValue> aProperties(2);
951 [ # # ]: 0 : aProperties[0].Name = OUString("NumberingType");
952 [ # # ][ # # ]: 0 : aProperties[0].Value <<= aSupportedTypes[index].nType;
953 [ # # ]: 0 : aProperties[1].Name = OUString("Value");
954 [ # # ]: 0 : for (sal_Int32 j = 1; j <= 3; j++) {
955 [ # # ][ # # ]: 0 : aProperties[1].Value <<= j;
956 [ # # ]: 0 : result += makeNumberingString( aProperties, aLocale );
957 : 0 : result += OUString(", ");
958 : : }
959 : 0 : result += OUString("...");
960 [ # # ]: 0 : return result;
961 : : }
962 : : }
963 : :
964 : : sal_Bool SAL_CALL
965 : 0 : DefaultNumberingProvider::isScriptFlagEnabled(const OUString& aName) throw(RuntimeException)
966 : : {
967 [ # # ]: 0 : if (! xHierarchicalNameAccess.is()) {
968 : 0 : Reference< XInterface > xInterface;
969 : :
970 [ # # ][ # # ]: 0 : xInterface = xSMgr->createInstance(OUString("com.sun.star.configuration.ConfigurationProvider"));
[ # # ]
971 : : Reference< XMultiServiceFactory > xConfigProvider =
972 [ # # ]: 0 : Reference< XMultiServiceFactory >(xInterface, UNO_QUERY );
973 : :
974 [ # # ]: 0 : if (! xConfigProvider.is())
975 [ # # ]: 0 : throw RuntimeException();
976 : :
977 [ # # ]: 0 : Sequence< Any > aArgs(1);
978 : 0 : beans::PropertyValue aPath;
979 : 0 : aPath.Name = OUString("nodepath");
980 [ # # ]: 0 : aPath.Value <<= OUString("/org.openoffice.Office.Common/I18N"),
981 [ # # ][ # # ]: 0 : aArgs[0] <<= aPath;
982 : :
983 [ # # ]: 0 : xInterface = xConfigProvider->createInstanceWithArguments(
984 [ # # ][ # # ]: 0 : OUString("com.sun.star.configuration.ConfigurationAccess"), aArgs);
985 : :
986 [ # # ]: 0 : xHierarchicalNameAccess.set(xInterface, UNO_QUERY);
987 : :
988 [ # # ]: 0 : if (! xHierarchicalNameAccess.is())
989 [ # # ][ # # ]: 0 : throw RuntimeException();
990 : : }
991 : :
992 [ # # ][ # # ]: 0 : Any aEnabled = xHierarchicalNameAccess->getByHierarchicalName(aName);
993 : :
994 : 0 : sal_Bool enabled = sal_False;
995 : :
996 : 0 : aEnabled >>= enabled;
997 : :
998 : 0 : return enabled;
999 : : }
1000 : :
1001 : 0 : Sequence< sal_Int16 > DefaultNumberingProvider::getSupportedNumberingTypes( )
1002 : : throw(RuntimeException)
1003 : : {
1004 : 0 : Sequence< sal_Int16 > aRet(nSupported_NumberingTypes );
1005 [ # # ]: 0 : sal_Int16* pArray = aRet.getArray();
1006 : :
1007 [ # # ]: 0 : sal_Bool cjkEnabled = isScriptFlagEnabled(OUString("CJK/CJKFont"));
1008 [ # # ]: 0 : sal_Bool ctlEnabled = isScriptFlagEnabled(OUString("CTL/CTLFont"));
1009 : :
1010 [ # # ]: 0 : for(sal_Int16 i = 0; i < nSupported_NumberingTypes; i++) {
1011 [ # # ][ # # ]: 0 : if ( (aSupportedTypes[i].langOption & LANG_ALL) ||
[ # # ][ # # ]
[ # # ]
1012 : : ((aSupportedTypes[i].langOption & LANG_CJK) && cjkEnabled) ||
1013 : : ((aSupportedTypes[i].langOption & LANG_CTL) && ctlEnabled) )
1014 : 0 : pArray[i] = aSupportedTypes[i].nType;
1015 : : }
1016 : 0 : return aRet;
1017 : : }
1018 : :
1019 : 0 : sal_Int16 DefaultNumberingProvider::getNumberingType( const OUString& rNumberingIdentifier )
1020 : : throw(RuntimeException)
1021 : : {
1022 [ # # ]: 0 : for(sal_Int16 i = 0; i < nSupported_NumberingTypes; i++)
1023 [ # # ]: 0 : if(rNumberingIdentifier.equals(makeNumberingIdentifier(i)))
1024 : 0 : return aSupportedTypes[i].nType;
1025 [ # # ]: 0 : throw RuntimeException();
1026 : : }
1027 : :
1028 : 0 : sal_Bool DefaultNumberingProvider::hasNumberingType( const OUString& rNumberingIdentifier )
1029 : : throw(RuntimeException)
1030 : : {
1031 [ # # ]: 0 : for(sal_Int16 i = 0; i < nSupported_NumberingTypes; i++)
1032 [ # # ]: 0 : if(rNumberingIdentifier.equals(makeNumberingIdentifier(i)))
1033 : 0 : return sal_True;
1034 : 0 : return sal_False;
1035 : : }
1036 : :
1037 : 0 : OUString DefaultNumberingProvider::getNumberingIdentifier( sal_Int16 nNumberingType )
1038 : : throw(RuntimeException)
1039 : : {
1040 [ # # ]: 0 : for(sal_Int16 i = 0; i < nSupported_NumberingTypes; i++)
1041 [ # # ]: 0 : if(nNumberingType == aSupportedTypes[i].nType)
1042 : 0 : return makeNumberingIdentifier(i);
1043 : 0 : return OUString();
1044 : : }
1045 : :
1046 : : const sal_Char cDefaultNumberingProvider[] = "com.sun.star.text.DefaultNumberingProvider";
1047 : 0 : OUString DefaultNumberingProvider::getImplementationName(void)
1048 : : throw( RuntimeException )
1049 : : {
1050 : 0 : return OUString::createFromAscii(cDefaultNumberingProvider);
1051 : : }
1052 : :
1053 : 0 : sal_Bool DefaultNumberingProvider::supportsService(const rtl::OUString& rServiceName)
1054 : : throw( RuntimeException )
1055 : : {
1056 : 0 : return rServiceName.equalsAscii(cDefaultNumberingProvider);
1057 : : }
1058 : :
1059 : 0 : Sequence< OUString > DefaultNumberingProvider::getSupportedServiceNames(void)
1060 : : throw( RuntimeException )
1061 : : {
1062 : 0 : Sequence< OUString > aRet(1);
1063 [ # # ]: 0 : aRet[0] = OUString::createFromAscii(cDefaultNumberingProvider);
1064 : 0 : return aRet;
1065 : : }
1066 : :
1067 : : } } } }
1068 : :
1069 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|