update dev300-m58
[ooovba.git] / i18npool / source / defaultnumberingprovider / defaultnumberingprovider.cxx
blob82ae543b450b8bd51cf69a19454bc16902d443b7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: defaultnumberingprovider.cxx,v $
10 * $Revision: 1.30.24.2 $
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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_i18npool.hxx"
33 #include <defaultnumberingprovider.hxx>
34 #include <com/sun/star/style/NumberingType.hpp>
35 #include <com/sun/star/beans/PropertyValue.hpp>
36 #include <com/sun/star/text/HoriOrientation.hpp>
37 #include <localedata.hxx>
38 #include <nativenumbersupplier.hxx>
39 #include <stdio.h>
40 #include <string.h>
42 #if OSL_DEBUG_LEVEL == 0 && !defined(NDEBUG)
43 #define NDEBUG
44 #endif
45 #include <assert.h>
47 // Cyrillic upper case
48 #define C_CYR_A "\xD0\x90"
49 #define C_CYR_B "\xD0\x91"
50 // Cyrillic lower case
51 #define S_CYR_A "\xD0\xB0"
52 #define S_CYR_B "\xD0\xB1"
54 #include <math.h>
55 #include <rtl/ustring.hxx>
56 #include <rtl/ustrbuf.hxx>
57 #include <com/sun/star/i18n/XTransliteration.hpp>
58 #include <com/sun/star/i18n/TransliterationType.hpp>
59 #include <com/sun/star/i18n/TransliterationModulesNew.hpp>
60 #include <com/sun/star/i18n/XLocaleData.hpp>
62 #include <bullet.h>
64 using namespace com::sun::star;
65 using namespace com::sun::star::uno;
66 using namespace com::sun::star::lang;
67 using namespace ::rtl;
69 namespace com { namespace sun { namespace star { namespace i18n {
71 static sal_Unicode table_Alphabet_ar[] = {
72 0x0623, 0x0628, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E,
73 0x062F, 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635,
74 0x0636, 0x0637, 0x0638, 0x0639, 0x063A, 0x0641, 0x0642,
75 0x0643, 0x0644, 0x0645, 0x0646, 0x0647, 0x0648, 0x0649
78 static sal_Unicode table_Alphabet_th[] = {
79 0x0E01, 0x0E02, 0x0E04, 0x0E07,
80 0x0E08, 0x0E09, 0x0E0A, 0x0E0B, 0x0E0C, 0x0E0D, 0x0E0E, 0x0E0F,
81 0x0E10, 0x0E11, 0x0E12, 0x0E13, 0x0E14, 0x0E15, 0x0E16, 0x0E17,
82 0x0E18, 0x0E19, 0x0E1A, 0x0E1B, 0x0E1C, 0x0E1D, 0x0E1E, 0x0E1F,
83 0x0E20, 0x0E21, 0x0E22, 0x0E23, 0x0E24, 0x0E25, 0x0E26, 0x0E27,
84 0x0E28, 0x0E29, 0x0E2A, 0x0E2B, 0x0E2C, 0x0E2D, 0x0E2E
87 static sal_Unicode table_Alphabet_he[] = {
88 0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7,
89 0x05D8, 0x05D9, 0x05DB, 0x05DC, 0x05DE, 0x05E0, 0x05E1, 0x05E2,
90 0x05E4, 0x05E6, 0x05E7, 0x05E8, 0x05E9, 0x05EA
93 static sal_Unicode table_Alphabet_ne[] = {
94 0x0915, 0x0916, 0x0917, 0x0918, 0x0919, 0x091A, 0x091B, 0x091C,
95 0x091D, 0x091E, 0x091F, 0x0920, 0x0921, 0x0922, 0x0923, 0x0924,
96 0x0925, 0x0926, 0x0927, 0x0928, 0x092A, 0x092B, 0x092C, 0x092D,
97 0x092E, 0x092F, 0x0930, 0x0932, 0x0935, 0x0936, 0x0937, 0x0938,
98 0x0939
101 static sal_Unicode table_Alphabet_km[] = {
102 0x1780, 0x1781, 0x1782, 0x1783, 0x1784, 0x1785, 0x1786, 0x1787,
103 0x1788, 0x1789, 0x178A, 0x178B, 0x178C, 0x178D, 0x178E, 0x178F,
104 0x1790, 0x1791, 0x1792, 0x1793, 0x1794, 0x1795, 0x1796, 0x1797,
105 0x1798, 0x1799, 0x179A, 0x179B, 0x179C, 0x179F,
106 0x17A0, 0x17A1, 0x17A2
109 static sal_Unicode table_Alphabet_lo[] = {
110 0x0E81, 0x0E82, 0x0E84, 0x0E87, 0x0E88, 0x0E8A, 0x0E8D, 0x0E94,
111 0x0E95, 0x0E96, 0x0E97, 0x0E99, 0x0E9A, 0x0E9B, 0x0E9C,
112 0x0E9D, 0x0E9E, 0x0E9F, 0x0EA1, 0x0EA2, 0x0EA3, 0x0EA5, 0x0EA7,
113 0x0EAA, 0x0EAB, 0x0EAD, 0x0EAE, 0x0EAF, 0x0EAE, 0x0EDC, 0x0EDD
116 static sal_Unicode table_Alphabet_dz[] = {
117 0x0F40, 0x0F41, 0x0F42, 0x0F44, 0x0F45, 0x0F46, 0x0F47, 0x0F49,
118 0x0F4F, 0x0F50, 0x0F51, 0x0F53, 0x0F54, 0x0F55, 0x0F56, 0x0F58,
119 0x0F59, 0x0F5A, 0x0F5B, 0x0F5D, 0x0F5E, 0x0F5F, 0x0F60, 0x0F61,
120 0x0F62, 0x0F63, 0x0F64, 0x0F66, 0x0F67, 0x0F68
123 static sal_Unicode table_Alphabet_my[] = {
124 0x1000, 0x1001, 0x1002, 0x1003, 0x1004, 0x1005, 0x1006, 0x1007,
125 0x1008,/*0x1009,*/0x100A, 0x100B, 0x100C, 0x100D, 0x100E, 0x100F,
126 0x1010, 0x1011, 0x1012, 0x1013, 0x1014, 0x1015, 0x1016, 0x1017,
127 0x1018, 0x1019, 0x101A, 0x101B, 0x101C, 0x101D, 0x101E, 0x101F,
128 0x1020, 0x1021
131 // Bulgarian Cyrillic upper case letters
132 static sal_Unicode table_CyrillicUpperLetter_bg[] = {
133 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418,
134 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F, 0x0420, 0x0421, 0x0422,
135 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042A, 0x042E,
136 0x042F
139 // Bulgarian cyrillic lower case letters
140 static sal_Unicode table_CyrillicLowerLetter_bg[] = {
141 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438,
142 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F, 0x0440, 0x0441, 0x0442,
143 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044A, 0x044E,
144 0x044F
147 // Russian Cyrillic upper letters
148 static sal_Unicode table_CyrillicUpperLetter_ru[] = {
149 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
150 0x0418, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F, 0x0420,
151 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428,
152 0x0429, 0x042B, 0x042D, 0x042E, 0x042F
155 // Russian cyrillic lower letters
156 static sal_Unicode table_CyrillicLowerLetter_ru[] = {
157 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437,
158 0x0438, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F, 0x0440,
159 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448,
160 0x0449, 0x044B, 0x044D, 0x044E, 0x044F
163 // Serbian Cyrillic upper letters
164 static sal_Unicode table_CyrillicUpperLetter_sr[] = {
165 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0402, 0x0415, 0x0416,
166 0x0417, 0x0418, 0x0408, 0x041A, 0x041B, 0x0409, 0x041C, 0x041D,
167 0x040A, 0x041E, 0x041F, 0x0420, 0x0421, 0x0422, 0x040B, 0x0423,
168 0x0424, 0x0425, 0x0426, 0x0427, 0x040F, 0x0428
171 // Serbian cyrillic lower letters
172 static sal_Unicode table_CyrillicLowerLetter_sr[] = {
173 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0452, 0x0435, 0x0436,
174 0x0437, 0x0438, 0x0458, 0x043A, 0x043B, 0x0459, 0x043C, 0x043D,
175 0x045A, 0x043E, 0x043F, 0x0440, 0x0441, 0x0442, 0x045B, 0x0443,
176 0x0444, 0x0445, 0x0446, 0x0447, 0x045F, 0x0448
179 static sal_Unicode table_Alphabet_fa[] = {
180 0x0622, 0x0628, 0x067E, 0x062A, 0x062B, 0x062C, 0x0686, 0x062D,
181 0x062E, 0x062F, 0x0630, 0x0631, 0x0632, 0x0698, 0x0633, 0x0634,
182 0x0635, 0x0636, 0x0637, 0x0638, 0x0639, 0x0640, 0x0641, 0x0642,
183 0x06A9, 0x06AF, 0x0644, 0x0645, 0x0646, 0x0648, 0x0647, 0x06CC
186 static sal_Unicode upperLetter[] = {
187 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
188 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52,
189 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A
192 static sal_Unicode lowerLetter[] = {
193 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
194 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72,
195 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A
198 DefaultNumberingProvider::DefaultNumberingProvider( const Reference < XMultiServiceFactory >& xMSF ) : xSMgr(xMSF),translit(NULL)
203 DefaultNumberingProvider::~DefaultNumberingProvider()
205 delete translit;
208 void DefaultNumberingProvider::impl_loadTranslit()
210 if ( !translit )
211 translit = new TransliterationImpl(xSMgr);
214 Sequence< Reference<container::XIndexAccess> >
215 DefaultNumberingProvider::getDefaultOutlineNumberings(const Locale& rLocale ) throw(RuntimeException)
217 return LocaleData().getOutlineNumberingLevels( rLocale );
220 Sequence< Sequence<beans::PropertyValue> >
221 DefaultNumberingProvider::getDefaultContinuousNumberingLevels( const Locale& rLocale ) throw(RuntimeException)
223 return LocaleData().getContinuousNumberingLevels( rLocale );
226 OUString toRoman( sal_Int32 n )
229 // i, ii, iii, iv, v, vi, vii, vii, viii, ix
230 // (Dummy),1000,500,100,50,10,5,1
231 static const sal_Char coRomanArr[] = "MDCLXVI--"; // +2 Dummy entries !!
232 const sal_Char* cRomanStr = coRomanArr;
233 sal_uInt16 nMask = 1000;
234 sal_uInt32 nOver1000 = n / nMask;
235 n -= ( nOver1000 * nMask );
237 OUStringBuffer sTmp;
238 while(nOver1000--)
239 sTmp.append(sal_Unicode(*coRomanArr));
241 while( nMask )
243 sal_uInt8 nZahl = sal_uInt8( n / nMask );
244 sal_uInt8 nDiff = 1;
245 n %= nMask;
247 if( 5 < nZahl )
249 if( nZahl < 9 )
250 sTmp.append(sal_Unicode(*(cRomanStr-1)));
251 ++nDiff;
252 nZahl -= 5;
254 switch( nZahl )
256 case 3: sTmp.append(sal_Unicode(*cRomanStr)); //no break!
257 case 2: sTmp.append(sal_Unicode(*cRomanStr)); //no break!
258 case 1: sTmp.append(sal_Unicode(*cRomanStr)); break;
259 case 4: sTmp.append(sal_Unicode(*cRomanStr)).append(sal_Unicode(*(cRomanStr-nDiff))); break;
260 case 5: sTmp.append(sal_Unicode(*(cRomanStr-nDiff))); break;
263 nMask /= 10; // to the next decade
264 cRomanStr += 2;
266 return sTmp.makeStringAndClear();
269 // not used:
270 #if 0
272 static
273 const char* expected_name( int i, int last )
275 if(0);
276 else if( i==0 ) return "Prefix";
277 else if( i==1 ) return "NumberingType";
278 else if( i==2 ) return "Suffix";
279 else if( i==last ) return "Value";
280 else { assert(0); return ""; }
282 static
283 const char* expected_type( int i, int last )
285 if(0);
286 else if( i==0 ) return "OUString";
287 else if( i==1 ) return "sal_Int16";
288 else if( i==2 ) return "OUString";
289 else if( i==last ) return "sal_Int32";
290 else { assert(0); return ""; }
292 static
293 void failedToConvert( int i, int last )
295 throw IllegalArgumentException();
298 #endif
300 static
301 void lcl_formatChars( sal_Unicode table[], int tableSize, int n, OUString& s )
303 // string representation of n is appended to s.
304 // if A=='A' then 0=>A, 1=>B, ..., 25=>Z, 26=>AA, 27=>AB, ...
305 // if A=='a' then 0=>a, 1=>b, ..., 25=>z, 26=>aa, 27=>ab, ...
307 if( n>=tableSize ) lcl_formatChars( table, tableSize, (n-tableSize)/tableSize, s );
309 s += OUString::valueOf( table[ n % tableSize ] );
312 static
313 void lcl_formatChars1( sal_Unicode table[], int tableSize, int n, OUString& s )
315 // string representation of n is appended to s.
316 // if A=='A' then 0=>A, 1=>B, ..., 25=>Z, 26=>AA, 27=>BB, ...
317 // if A=='a' then 0=>a, 1=>b, ..., 25=>z, 26=>aa, 27=>bb, ...
319 int repeat_count = n / tableSize + 1;
321 for( int i=0; i<repeat_count; i++ )
322 s += OUString::valueOf( table[ n%tableSize ] );
325 static
326 void lcl_formatChars2( sal_Unicode table_capital[], sal_Unicode table_small[], int tableSize, int n, OUString& s )
328 // string representation of n is appended to s.
329 // if A=='A' then 0=>A, 1=>B, ..., 25=>Z, 26=>Aa, 27=>Ab, ...
331 if( n>=tableSize )
333 lcl_formatChars2( table_capital, table_small, tableSize, (n-tableSize)/tableSize, s );
334 s += OUString::valueOf( table_small[ n % tableSize ] );
335 } else
336 s += OUString::valueOf( table_capital[ n % tableSize ] );
339 static
340 void lcl_formatChars3( sal_Unicode table_capital[], sal_Unicode table_small[], int tableSize, int n, OUString& s )
342 // string representation of n is appended to s.
343 // if A=='A' then 0=>A, 1=>B, ..., 25=>Z, 26=>Aa, 27=>Bb, ...
345 int repeat_count = n / tableSize + 1;
346 s += OUString::valueOf( table_capital[ n%tableSize ] );
348 for( int i=1; i<repeat_count; i++ )
349 s += OUString::valueOf( table_small[ n%tableSize ] );
352 static
353 int should_ignore( OUString s )
355 // return true if blank or null
356 return s.compareToAscii(" ")==0 || (s.getLength()>0 && s[0]==0);
359 static
360 Any getPropertyByName( const Sequence<beans::PropertyValue>& aProperties,
361 const char* name, sal_Bool bRequired )
363 for( int i=0; i<aProperties.getLength(); i++ )
364 if( aProperties[i].Name.equalsAscii(name) )
365 return aProperties[i].Value;
366 if(bRequired)
367 throw IllegalArgumentException();
368 return Any();
371 //XNumberingFormatter
372 OUString
373 DefaultNumberingProvider::makeNumberingString( const Sequence<beans::PropertyValue>& aProperties,
374 const Locale& aLocale )
375 throw( IllegalArgumentException, RuntimeException )
377 // the Sequence of PropertyValues is expected to have at least 4 elements:
378 // elt Name Type purpose
379 // -----------------------------------------------------------------
381 // 0. "Prefix" OUString
382 // 1. "NumberingType" sal_Int16 type of formatting from style::NumberingType (roman, arabic, etc)
383 // 2. "Suffix" OUString
384 // ... ... ...
385 // n. "Value" sal_Int32 the number to be formatted
386 // example:
387 // given the Sequence { '(', NumberingType::ROMAN_UPPER, ')', ..., 7 }
388 // makeNumberingString() returns the string "(VII)".
390 // Q: why is the type of numType sal_Int16 instead of style::NumberingType?
391 // A: an Any can't hold a style::NumberingType for some reason.
392 // add.: style::NumberingType holds constants of type sal_Int16, it's not an enum type
394 sal_Int16 natNum = 0;
395 sal_Int16 tableSize = 0;
396 sal_Unicode *table = NULL; // initialize to avoid compiler warning
397 sal_Bool recycleSymbol = sal_False;
398 Locale locale;
400 OUString prefix;
401 sal_Int16 numType = -1; // type of formatting from style::NumberingType (roman, arabic, etc)
402 OUString suffix;
403 sal_Int32 number = -12345; // the number that needs to be formatted.
405 // int nProperties = aProperties.getLength();
406 // int last = nProperties-1;
408 try {
409 getPropertyByName(aProperties, "Prefix", sal_False) >>=prefix;
410 } catch (Exception&) {
411 //prefix _must_ be empty here!
413 try {
414 getPropertyByName(aProperties, "Suffix", sal_False) >>=suffix;
415 } catch (Exception&) {
416 //suffix _must_ be empty here!
418 try {
419 getPropertyByName(aProperties, "NumberingType", sal_True) >>=numType;
420 } catch (Exception& ) {
421 numType = -1;
423 try {
424 getPropertyByName(aProperties, "Value", sal_True) >>=number;
425 } catch (Exception& ) {
426 number = -1;
429 if( number <= 0 )
430 throw IllegalArgumentException();
432 // start empty
433 OUString result;
435 // append prefix
436 if( !should_ignore(prefix) ) result += prefix;
438 // append formatted number
439 using namespace style::NumberingType;
440 switch( numType )
442 case CHARS_UPPER_LETTER:
443 lcl_formatChars( upperLetter, 26, number-1, result ); // 1=>A, 2=>B, ..., 26=>Z, 27=>AA, 28=>AB, ...
444 break;
445 case CHARS_LOWER_LETTER:
446 lcl_formatChars( lowerLetter, 26, number-1, result );
447 break;
448 case ROMAN_UPPER:
449 result += toRoman( number );
450 break;
451 case ROMAN_LOWER:
452 result += toRoman( number ).toAsciiLowerCase();
453 break;
454 case ARABIC:
455 result += OUString::valueOf( number );
456 break;
457 case NUMBER_NONE:
458 return OUString::createFromAscii(""); // ignore prefix and suffix
459 case CHAR_SPECIAL:
460 // apparently, we're supposed to return an empty string in this case...
461 return OUString::createFromAscii(""); // ignore prefix and suffix
462 case PAGE_DESCRIPTOR:
463 case BITMAP:
464 assert(0);
465 throw IllegalArgumentException();
466 case CHARS_UPPER_LETTER_N:
467 lcl_formatChars1( upperLetter, 26, number-1, result ); // 1=>A, 2=>B, ..., 26=>Z, 27=>AA, 28=>BB, ...
468 break;
469 case CHARS_LOWER_LETTER_N:
470 lcl_formatChars1( lowerLetter, 26, number-1, result ); // 1=>A, 2=>B, ..., 26=>Z, 27=>AA, 28=>BB, ...
471 break;
472 case TRANSLITERATION:
473 try {
474 const OUString &tmp = OUString::valueOf( number );
475 OUString transliteration;
476 getPropertyByName(aProperties, "Transliteration", sal_True) >>= transliteration;
477 impl_loadTranslit();
478 translit->loadModuleByImplName(transliteration, aLocale);
479 result += translit->transliterateString2String(tmp, 0, tmp.getLength());
480 } catch (Exception& ) {
481 // When translteration property is missing, return default number (bug #101141#)
482 result += OUString::valueOf( number );
483 // assert(0);
484 // throw IllegalArgumentException();
486 break;
487 case NATIVE_NUMBERING:
488 natNum = NativeNumberMode::NATNUM1;
489 locale = aLocale;
490 break;
491 case FULLWIDTH_ARABIC:
492 natNum = NativeNumberMode::NATNUM3;
493 locale = aLocale;
494 break;
495 case NUMBER_LOWER_ZH:
496 natNum = NativeNumberMode::NATNUM7;
497 locale.Language = OUString::createFromAscii("zh");
498 break;
499 case NUMBER_UPPER_ZH_TW:
500 locale.Country = OUString::createFromAscii("TW");
501 case NUMBER_UPPER_ZH:
502 natNum = NativeNumberMode::NATNUM8;
503 locale.Language = OUString::createFromAscii("zh");
504 break;
505 case NUMBER_TRADITIONAL_JA:
506 natNum = NativeNumberMode::NATNUM8;
507 locale.Language = OUString::createFromAscii("ja");
508 break;
509 case NUMBER_UPPER_KO:
510 natNum = NativeNumberMode::NATNUM8;
511 locale.Language = OUString::createFromAscii("ko");
512 break;
513 case NUMBER_HANGUL_KO:
514 natNum = NativeNumberMode::NATNUM11;
515 locale.Language = OUString::createFromAscii("ko");
516 break;
518 case CIRCLE_NUMBER:
519 table = table_CircledNumber;
520 tableSize = sizeof(table_CircledNumber) / sizeof(sal_Unicode);
521 break;
522 case TIAN_GAN_ZH:
523 table = table_TianGan_zh;
524 tableSize = sizeof(table_TianGan_zh) / sizeof(sal_Unicode);
525 break;
526 case DI_ZI_ZH:
527 table = table_DiZi_zh;
528 tableSize = sizeof(table_DiZi_zh) / sizeof(sal_Unicode);
529 break;
530 case AIU_FULLWIDTH_JA:
531 table = table_AIUFullWidth_ja_JP;
532 tableSize = sizeof(table_AIUFullWidth_ja_JP) / sizeof(sal_Unicode);
533 recycleSymbol = sal_True;
534 break;
535 case AIU_HALFWIDTH_JA:
536 table = table_AIUHalfWidth_ja_JP;
537 tableSize = sizeof(table_AIUHalfWidth_ja_JP) / sizeof(sal_Unicode);
538 recycleSymbol = sal_True;
539 break;
540 case IROHA_FULLWIDTH_JA:
541 table = table_IROHAFullWidth_ja_JP;
542 tableSize = sizeof(table_IROHAFullWidth_ja_JP) / sizeof(sal_Unicode);
543 recycleSymbol = sal_True;
544 break;
545 case IROHA_HALFWIDTH_JA:
546 table = table_IROHAHalfWidth_ja_JP;
547 tableSize = sizeof(table_IROHAHalfWidth_ja_JP) / sizeof(sal_Unicode);
548 recycleSymbol = sal_True;
549 break;
550 case HANGUL_JAMO_KO:
551 table = table_HangulJamo_ko;
552 tableSize = sizeof(table_HangulJamo_ko) / sizeof(sal_Unicode);
553 recycleSymbol = sal_True;
554 break;
555 case HANGUL_SYLLABLE_KO:
556 table = table_HangulSyllable_ko;
557 tableSize = sizeof(table_HangulSyllable_ko) / sizeof(sal_Unicode);
558 recycleSymbol = sal_True;
559 break;
560 case HANGUL_CIRCLED_JAMO_KO:
561 table = table_HangulCircledJamo_ko;
562 tableSize = sizeof(table_HangulCircledJamo_ko) / sizeof(sal_Unicode);
563 recycleSymbol = sal_True;
564 break;
565 case HANGUL_CIRCLED_SYLLABLE_KO:
566 table = table_HangulCircledSyllable_ko;
567 tableSize = sizeof(table_HangulCircledSyllable_ko) / sizeof(sal_Unicode);
568 recycleSymbol = sal_True;
569 break;
570 case CHARS_ARABIC:
571 lcl_formatChars(table_Alphabet_ar, sizeof(table_Alphabet_ar) / sizeof(sal_Unicode), number - 1, result);
572 break;
573 case CHARS_THAI:
574 lcl_formatChars(table_Alphabet_th, sizeof(table_Alphabet_th) / sizeof(sal_Unicode), number - 1, result);
575 break;
576 case CHARS_HEBREW:
577 lcl_formatChars(table_Alphabet_he, sizeof(table_Alphabet_he) / sizeof(sal_Unicode), number - 1, result);
578 break;
579 case CHARS_NEPALI:
580 lcl_formatChars(table_Alphabet_ne, sizeof(table_Alphabet_ne) / sizeof(sal_Unicode), number - 1, result);
581 break;
582 case CHARS_KHMER:
583 lcl_formatChars(table_Alphabet_km, sizeof(table_Alphabet_km) / sizeof(sal_Unicode), number - 1, result);
584 break;
585 case CHARS_LAO:
586 lcl_formatChars(table_Alphabet_lo, sizeof(table_Alphabet_lo) / sizeof(sal_Unicode), number - 1, result);
587 break;
588 case CHARS_MYANMAR:
589 lcl_formatChars(table_Alphabet_my, sizeof(table_Alphabet_my) / sizeof(sal_Unicode), number - 1, result);
590 break;
591 case CHARS_TIBETAN:
592 lcl_formatChars(table_Alphabet_dz, sizeof(table_Alphabet_dz) / sizeof(sal_Unicode), number - 1, result);
593 break;
594 case CHARS_CYRILLIC_UPPER_LETTER_BG:
595 lcl_formatChars2( table_CyrillicUpperLetter_bg,
596 table_CyrillicLowerLetter_bg,
597 sizeof(table_CyrillicLowerLetter_bg) /
598 sizeof(table_CyrillicLowerLetter_bg[0]), number-1,
599 result); // 1=>a, 2=>b, ..., 28=>z, 29=>Aa, 30=>Ab, ...
600 break;
601 case CHARS_CYRILLIC_LOWER_LETTER_BG:
602 lcl_formatChars( table_CyrillicLowerLetter_bg,
603 sizeof(table_CyrillicLowerLetter_bg) /
604 sizeof(table_CyrillicLowerLetter_bg[0]), number-1,
605 result); // 1=>a, 2=>b, ..., 28=>z, 29=>aa, 30=>ab, ...
606 break;
607 case CHARS_CYRILLIC_UPPER_LETTER_N_BG:
608 lcl_formatChars3( table_CyrillicUpperLetter_bg,
609 table_CyrillicLowerLetter_bg,
610 sizeof(table_CyrillicLowerLetter_bg) /
611 sizeof(table_CyrillicLowerLetter_bg[0]), number-1,
612 result); // 1=>a, 2=>b, ..., 28=>z, 29=>Aa, 30=>Bb, ...
613 break;
614 case CHARS_CYRILLIC_LOWER_LETTER_N_BG:
615 lcl_formatChars1( table_CyrillicLowerLetter_bg,
616 sizeof(table_CyrillicLowerLetter_bg) /
617 sizeof(table_CyrillicLowerLetter_bg[0]), number-1,
618 result); // 1=>a, 2=>b, ..., 28=>z, 29=>aa, 30=>bb, ...
619 break;
620 case CHARS_CYRILLIC_UPPER_LETTER_RU:
621 lcl_formatChars2( table_CyrillicUpperLetter_ru,
622 table_CyrillicLowerLetter_ru,
623 sizeof(table_CyrillicLowerLetter_ru) /
624 sizeof(table_CyrillicLowerLetter_ru[0]), number-1,
625 result); // 1=>a, 2=>b, ..., 27=>z, 28=>Aa, 29=>Ab, ...
626 break;
627 case CHARS_CYRILLIC_LOWER_LETTER_RU:
628 lcl_formatChars( table_CyrillicLowerLetter_ru,
629 sizeof(table_CyrillicLowerLetter_ru) /
630 sizeof(table_CyrillicLowerLetter_ru[0]), number-1,
631 result); // 1=>a, 2=>b, ..., 27=>z, 28=>aa, 29=>ab, ...
632 break;
633 case CHARS_CYRILLIC_UPPER_LETTER_N_RU:
634 lcl_formatChars3( table_CyrillicUpperLetter_ru,
635 table_CyrillicLowerLetter_ru,
636 sizeof(table_CyrillicLowerLetter_ru) /
637 sizeof(table_CyrillicLowerLetter_ru[0]), number-1,
638 result); // 1=>a, 2=>b, ..., 27=>z, 28=>Aa, 29=>Bb, ...
639 break;
640 case CHARS_CYRILLIC_LOWER_LETTER_N_RU:
641 lcl_formatChars1( table_CyrillicLowerLetter_ru,
642 sizeof(table_CyrillicLowerLetter_ru) /
643 sizeof(table_CyrillicLowerLetter_ru[0]), number-1,
644 result); // 1=>a, 2=>b, ..., 27=>z, 28=>aa, 29=>bb, ...
645 break;
646 case CHARS_CYRILLIC_UPPER_LETTER_SR:
647 lcl_formatChars2( table_CyrillicUpperLetter_sr,
648 table_CyrillicLowerLetter_sr,
649 sizeof(table_CyrillicLowerLetter_sr) /
650 sizeof(table_CyrillicLowerLetter_sr[0]), number-1,
651 result); // 1=>a, 2=>b, ..., 27=>z, 28=>Aa, 29=>Ab, ...
652 break;
653 case CHARS_CYRILLIC_LOWER_LETTER_SR:
654 lcl_formatChars( table_CyrillicLowerLetter_sr,
655 sizeof(table_CyrillicLowerLetter_sr) /
656 sizeof(table_CyrillicLowerLetter_sr[0]), number-1,
657 result); // 1=>a, 2=>b, ..., 27=>z, 28=>aa, 29=>ab, ...
658 break;
659 case CHARS_CYRILLIC_UPPER_LETTER_N_SR:
660 lcl_formatChars3( table_CyrillicUpperLetter_sr,
661 table_CyrillicLowerLetter_sr,
662 sizeof(table_CyrillicLowerLetter_sr) /
663 sizeof(table_CyrillicLowerLetter_sr[0]), number-1,
664 result); // 1=>a, 2=>b, ..., 27=>z, 28=>Aa, 29=>Bb, ...
665 break;
666 case CHARS_CYRILLIC_LOWER_LETTER_N_SR:
667 lcl_formatChars1( table_CyrillicLowerLetter_sr,
668 sizeof(table_CyrillicLowerLetter_sr) /
669 sizeof(table_CyrillicLowerLetter_sr[0]), number-1,
670 result); // 1=>a, 2=>b, ..., 27=>z, 28=>aa, 29=>bb, ...
671 break;
672 case CHARS_PERSIAN:
673 lcl_formatChars(table_Alphabet_fa, sizeof(table_Alphabet_fa) / sizeof(sal_Unicode), number - 1, result);
674 break;
676 default:
677 assert(0);
678 throw IllegalArgumentException();
681 if (natNum) {
682 NativeNumberSupplier sNatNum;
683 result += sNatNum.getNativeNumberString(OUString::valueOf( number ), locale, natNum);
684 } else if (tableSize) {
685 if ( number > tableSize && !recycleSymbol)
686 result += OUString::valueOf( number);
687 else
688 result += OUString(&table[--number % tableSize], 1);
691 // append suffix
692 if( !should_ignore(suffix) ) result += suffix;
694 return result;
696 /* -----------------------------21.02.01 15:57--------------------------------
698 ---------------------------------------------------------------------------*/
700 #define LANG_ALL (1 << 0)
701 #define LANG_CJK (1 << 1)
702 #define LANG_CTL (1 << 2)
704 struct Supported_NumberingType
706 sal_Int16 nType;
707 const sal_Char* cSymbol;
708 sal_Int16 langOption;
710 static const Supported_NumberingType aSupportedTypes[] =
712 {style::NumberingType::CHARS_UPPER_LETTER, "A", LANG_ALL},
713 {style::NumberingType::CHARS_LOWER_LETTER, "a", LANG_ALL},
714 {style::NumberingType::ROMAN_UPPER, "I", LANG_ALL},
715 {style::NumberingType::ROMAN_LOWER, "i", LANG_ALL},
716 {style::NumberingType::ARABIC, "1", LANG_ALL},
717 {style::NumberingType::NUMBER_NONE, "''", LANG_ALL},
718 {style::NumberingType::CHAR_SPECIAL, "Bullet", LANG_ALL},
719 {style::NumberingType::PAGE_DESCRIPTOR, "Page", LANG_ALL},
720 {style::NumberingType::BITMAP, "Bitmap", LANG_ALL},
721 {style::NumberingType::CHARS_UPPER_LETTER_N, "AAA", LANG_ALL},
722 {style::NumberingType::CHARS_LOWER_LETTER_N, "aaa", LANG_ALL},
723 {style::NumberingType::NATIVE_NUMBERING, "Native Numbering", LANG_CJK|LANG_CTL},
724 {style::NumberingType::FULLWIDTH_ARABIC, NULL, LANG_CJK},
725 {style::NumberingType::CIRCLE_NUMBER, NULL, LANG_CJK},
726 {style::NumberingType::NUMBER_LOWER_ZH, NULL, LANG_CJK},
727 {style::NumberingType::NUMBER_UPPER_ZH, NULL, LANG_CJK},
728 {style::NumberingType::NUMBER_UPPER_ZH_TW, NULL, LANG_CJK},
729 {style::NumberingType::TIAN_GAN_ZH, NULL, LANG_CJK},
730 {style::NumberingType::DI_ZI_ZH, NULL, LANG_CJK},
731 {style::NumberingType::NUMBER_TRADITIONAL_JA, NULL, LANG_CJK},
732 {style::NumberingType::AIU_FULLWIDTH_JA, NULL, LANG_CJK},
733 {style::NumberingType::AIU_HALFWIDTH_JA, NULL, LANG_CJK},
734 {style::NumberingType::IROHA_FULLWIDTH_JA, NULL, LANG_CJK},
735 {style::NumberingType::IROHA_HALFWIDTH_JA, NULL, LANG_CJK},
736 {style::NumberingType::NUMBER_UPPER_KO, NULL, LANG_CJK},
737 {style::NumberingType::NUMBER_HANGUL_KO, NULL, LANG_CJK},
738 {style::NumberingType::HANGUL_JAMO_KO, NULL, LANG_CJK},
739 {style::NumberingType::HANGUL_SYLLABLE_KO, NULL, LANG_CJK},
740 {style::NumberingType::HANGUL_CIRCLED_JAMO_KO, NULL, LANG_CJK},
741 {style::NumberingType::HANGUL_CIRCLED_SYLLABLE_KO, NULL, LANG_CJK},
742 {style::NumberingType::CHARS_ARABIC, NULL, LANG_CTL},
743 {style::NumberingType::CHARS_THAI, NULL, LANG_CTL},
744 {style::NumberingType::CHARS_HEBREW, NULL, LANG_CTL},
745 {style::NumberingType::CHARS_NEPALI, NULL, LANG_CTL},
746 {style::NumberingType::CHARS_KHMER, NULL, LANG_CTL},
747 {style::NumberingType::CHARS_LAO, NULL, LANG_CTL},
748 {style::NumberingType::CHARS_MYANMAR, NULL, LANG_CTL},
749 {style::NumberingType::CHARS_TIBETAN, NULL, LANG_CTL},
750 {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},
751 {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},
752 {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},
753 {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},
754 {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},
755 {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},
756 {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},
757 {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},
758 {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},
759 {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},
760 {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},
761 {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},
762 {style::NumberingType::CHARS_PERSIAN, NULL, LANG_CTL},
764 static const sal_Int32 nSupported_NumberingTypes = sizeof(aSupportedTypes) / sizeof(Supported_NumberingType);
765 /* -----------------------------21.02.01 15:57--------------------------------
767 ---------------------------------------------------------------------------*/
769 OUString DefaultNumberingProvider::makeNumberingIdentifier(sal_Int16 index)
770 throw(RuntimeException)
772 if (aSupportedTypes[index].cSymbol)
773 return OUString(aSupportedTypes[index].cSymbol, strlen(aSupportedTypes[index].cSymbol), RTL_TEXTENCODING_UTF8);
774 // return OUString::createFromAscii(aSupportedTypes[index].cSymbol);
775 else {
776 OUString result;
777 Locale aLocale(OUString::createFromAscii("en"), OUString(), OUString());
778 Sequence<beans::PropertyValue> aProperties(2);
779 aProperties[0].Name = OUString::createFromAscii("NumberingType");
780 aProperties[0].Value <<= aSupportedTypes[index].nType;
781 aProperties[1].Name = OUString::createFromAscii("Value");
782 for (sal_Int32 j = 1; j <= 3; j++) {
783 aProperties[1].Value <<= j;
784 result += makeNumberingString( aProperties, aLocale );
785 result += OUString::createFromAscii(", ");
787 result += OUString::createFromAscii("...");
788 return result;
792 sal_Bool SAL_CALL
793 DefaultNumberingProvider::isScriptFlagEnabled(const OUString& aName) throw(RuntimeException)
795 if (! xHierarchicalNameAccess.is()) {
796 Reference< XInterface > xInterface;
798 xInterface = xSMgr->createInstance(OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider"));
799 Reference< XMultiServiceFactory > xConfigProvider =
800 Reference< XMultiServiceFactory >(xInterface, UNO_QUERY );
802 if (! xConfigProvider.is())
803 throw RuntimeException();
805 Sequence< Any > aArgs(1);
806 beans::PropertyValue aPath;
807 aPath.Name = OUString::createFromAscii("nodepath");
808 aPath.Value <<= OUString::createFromAscii("/org.openoffice.Office.Common/I18N"),
809 aArgs[0] <<= aPath;
811 xInterface = xConfigProvider->createInstanceWithArguments(
812 OUString::createFromAscii("com.sun.star.configuration.ConfigurationAccess"), aArgs);
814 xHierarchicalNameAccess.set(xInterface, UNO_QUERY);
816 if (! xHierarchicalNameAccess.is())
817 throw RuntimeException();
820 Any aEnabled = xHierarchicalNameAccess->getByHierarchicalName(aName);
822 sal_Bool enabled = sal_False;
824 aEnabled >>= enabled;
826 return enabled;
829 Sequence< sal_Int16 > DefaultNumberingProvider::getSupportedNumberingTypes( )
830 throw(RuntimeException)
832 Sequence< sal_Int16 > aRet(nSupported_NumberingTypes );
833 sal_Int16* pArray = aRet.getArray();
835 sal_Bool cjkEnabled = isScriptFlagEnabled(OUString::createFromAscii("CJK/CJKFont"));
836 sal_Bool ctlEnabled = isScriptFlagEnabled(OUString::createFromAscii("CTL/CTLFont"));
838 for(sal_Int16 i = 0; i < nSupported_NumberingTypes; i++) {
839 if ( (aSupportedTypes[i].langOption & LANG_ALL) ||
840 ((aSupportedTypes[i].langOption & LANG_CJK) && cjkEnabled) ||
841 ((aSupportedTypes[i].langOption & LANG_CTL) && ctlEnabled) )
842 pArray[i] = aSupportedTypes[i].nType;
844 return aRet;
846 /* -----------------------------21.02.01 15:57--------------------------------
848 ---------------------------------------------------------------------------*/
849 sal_Int16 DefaultNumberingProvider::getNumberingType( const OUString& rNumberingIdentifier )
850 throw(RuntimeException)
852 for(sal_Int16 i = 0; i < nSupported_NumberingTypes; i++)
853 if(rNumberingIdentifier.equals(makeNumberingIdentifier(i)))
854 return aSupportedTypes[i].nType;
855 throw RuntimeException();
857 /* -----------------------------21.02.01 15:57--------------------------------
859 ---------------------------------------------------------------------------*/
860 sal_Bool DefaultNumberingProvider::hasNumberingType( const OUString& rNumberingIdentifier )
861 throw(RuntimeException)
863 for(sal_Int16 i = 0; i < nSupported_NumberingTypes; i++)
864 if(rNumberingIdentifier.equals(makeNumberingIdentifier(i)))
865 return sal_True;
866 return sal_False;
868 /* -----------------------------21.02.01 15:57--------------------------------
870 ---------------------------------------------------------------------------*/
871 OUString DefaultNumberingProvider::getNumberingIdentifier( sal_Int16 nNumberingType )
872 throw(RuntimeException)
874 for(sal_Int16 i = 0; i < nSupported_NumberingTypes; i++)
875 if(nNumberingType == aSupportedTypes[i].nType)
876 return makeNumberingIdentifier(i);
877 return OUString();
879 /* -----------------------------05.07.01 13:34--------------------------------
881 ---------------------------------------------------------------------------*/
882 const sal_Char cDefaultNumberingProvider[] = "com.sun.star.text.DefaultNumberingProvider";
883 OUString DefaultNumberingProvider::getImplementationName(void)
884 throw( RuntimeException )
886 return OUString::createFromAscii(cDefaultNumberingProvider);
888 /* -----------------------------05.07.01 13:34--------------------------------
890 ---------------------------------------------------------------------------*/
891 sal_Bool DefaultNumberingProvider::supportsService(const rtl::OUString& rServiceName)
892 throw( RuntimeException )
894 return rServiceName.equalsAscii(cDefaultNumberingProvider);
896 /* -----------------------------05.07.01 13:34--------------------------------
898 ---------------------------------------------------------------------------*/
899 Sequence< OUString > DefaultNumberingProvider::getSupportedServiceNames(void)
900 throw( RuntimeException )
902 Sequence< OUString > aRet(1);
903 aRet[0] = OUString::createFromAscii(cDefaultNumberingProvider);
904 return aRet;
907 } } } }