LCOV - code coverage report
Current view: top level - i18npool/source/defaultnumberingprovider - defaultnumberingprovider.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 74 376 19.7 %
Date: 2014-11-03 Functions: 9 27 33.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10