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