LCOV - code coverage report
Current view: top level - writerfilter/source/dmapper - ConversionHelper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 157 381 41.2 %
Date: 2015-06-13 12:38:46 Functions: 11 12 91.7 %
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             : #include <ConversionHelper.hxx>
      20             : #include <com/sun/star/table/BorderLine2.hpp>
      21             : #include <com/sun/star/table/BorderLineStyle.hpp>
      22             : #include <com/sun/star/lang/Locale.hpp>
      23             : #include <com/sun/star/text/HoriOrientation.hpp>
      24             : #include <com/sun/star/style/NumberingType.hpp>
      25             : #include <editeng/borderline.hxx>
      26             : #include <ooxml/resourceids.hxx>
      27             : #include <rtl/ustrbuf.hxx>
      28             : #include <tools/color.hxx>
      29             : #include <tools/mapunit.hxx>
      30             : #include <algorithm>
      31             : #include <functional>
      32             : 
      33             : using namespace com::sun::star;
      34             : 
      35             : namespace writerfilter {
      36             : namespace dmapper{
      37             : namespace ConversionHelper{
      38             : 
      39             : /// Convert OOXML border style to WW8 that editeng can handle.
      40       32567 : sal_Int32 lcl_convertBorderStyleFromToken(sal_Int32 nOOXMLType)
      41             : {
      42       32567 :     switch (nOOXMLType)
      43             :     {
      44        3476 :         case NS_ooxml::LN_Value_ST_Border_nil: return 255;
      45        5126 :         case NS_ooxml::LN_Value_ST_Border_none: return 0;
      46       23000 :         case NS_ooxml::LN_Value_ST_Border_single: return 1;
      47           0 :         case NS_ooxml::LN_Value_ST_Border_thick: return 2;
      48         185 :         case NS_ooxml::LN_Value_ST_Border_double: return 3;
      49           4 :         case NS_ooxml::LN_Value_ST_Border_dotted: return 6;
      50          24 :         case NS_ooxml::LN_Value_ST_Border_dashed: return 7;
      51           0 :         case NS_ooxml::LN_Value_ST_Border_dotDash: return 8;
      52           0 :         case NS_ooxml::LN_Value_ST_Border_dotDotDash: return 9;
      53           0 :         case NS_ooxml::LN_Value_ST_Border_triple: return 10;
      54          20 :         case NS_ooxml::LN_Value_ST_Border_thinThickSmallGap: return 11;
      55          34 :         case NS_ooxml::LN_Value_ST_Border_thickThinSmallGap: return 12;
      56           0 :         case NS_ooxml::LN_Value_ST_Border_thinThickThinSmallGap: return 13;
      57           4 :         case NS_ooxml::LN_Value_ST_Border_thinThickMediumGap: return 14;
      58          19 :         case NS_ooxml::LN_Value_ST_Border_thickThinMediumGap: return 15;
      59           0 :         case NS_ooxml::LN_Value_ST_Border_thinThickThinMediumGap: return 16;
      60          12 :         case NS_ooxml::LN_Value_ST_Border_thinThickLargeGap: return 17;
      61          69 :         case NS_ooxml::LN_Value_ST_Border_thickThinLargeGap: return 18;
      62           0 :         case NS_ooxml::LN_Value_ST_Border_thinThickThinLargeGap: return 19;
      63           0 :         case NS_ooxml::LN_Value_ST_Border_wave: return 20;
      64           0 :         case NS_ooxml::LN_Value_ST_Border_doubleWave: return 21;
      65          66 :         case NS_ooxml::LN_Value_ST_Border_dashSmallGap: return 22;
      66           0 :         case NS_ooxml::LN_Value_ST_Border_dashDotStroked: return 23;
      67          16 :         case NS_ooxml::LN_Value_ST_Border_threeDEmboss: return 24;
      68          16 :         case NS_ooxml::LN_Value_ST_Border_threeDEngrave: return 25;
      69         182 :         case NS_ooxml::LN_Value_ST_Border_outset: return 26;
      70          79 :         case NS_ooxml::LN_Value_ST_Border_inset: return 27;
      71           0 :         case NS_ooxml::LN_Value_ST_Border_apples: return 64;
      72           0 :         case NS_ooxml::LN_Value_ST_Border_archedScallops: return 65;
      73           0 :         case NS_ooxml::LN_Value_ST_Border_babyPacifier: return 66;
      74           0 :         case NS_ooxml::LN_Value_ST_Border_babyRattle: return 67;
      75           0 :         case NS_ooxml::LN_Value_ST_Border_balloons3Colors: return 68;
      76           0 :         case NS_ooxml::LN_Value_ST_Border_balloonsHotAir: return 69;
      77           0 :         case NS_ooxml::LN_Value_ST_Border_basicBlackDashes: return 70;
      78           0 :         case NS_ooxml::LN_Value_ST_Border_basicBlackDots: return 71;
      79           0 :         case NS_ooxml::LN_Value_ST_Border_basicBlackSquares: return 72;
      80           0 :         case NS_ooxml::LN_Value_ST_Border_basicThinLines: return 73;
      81           0 :         case NS_ooxml::LN_Value_ST_Border_basicWhiteDashes: return 74;
      82           0 :         case NS_ooxml::LN_Value_ST_Border_basicWhiteDots: return 75;
      83           0 :         case NS_ooxml::LN_Value_ST_Border_basicWhiteSquares: return 76;
      84           0 :         case NS_ooxml::LN_Value_ST_Border_basicWideInline: return 77;
      85           0 :         case NS_ooxml::LN_Value_ST_Border_basicWideMidline: return 78;
      86           0 :         case NS_ooxml::LN_Value_ST_Border_basicWideOutline: return 79;
      87           0 :         case NS_ooxml::LN_Value_ST_Border_bats: return 80;
      88           0 :         case NS_ooxml::LN_Value_ST_Border_birds: return 81;
      89           0 :         case NS_ooxml::LN_Value_ST_Border_birdsFlight: return 82;
      90           0 :         case NS_ooxml::LN_Value_ST_Border_cabins: return 83;
      91           0 :         case NS_ooxml::LN_Value_ST_Border_cakeSlice: return 84;
      92           0 :         case NS_ooxml::LN_Value_ST_Border_candyCorn: return 85;
      93           0 :         case NS_ooxml::LN_Value_ST_Border_celticKnotwork: return 86;
      94           0 :         case NS_ooxml::LN_Value_ST_Border_certificateBanner: return 87;
      95           0 :         case NS_ooxml::LN_Value_ST_Border_chainLink: return 88;
      96           0 :         case NS_ooxml::LN_Value_ST_Border_champagneBottle: return 89;
      97           0 :         case NS_ooxml::LN_Value_ST_Border_checkedBarBlack: return 90;
      98           0 :         case NS_ooxml::LN_Value_ST_Border_checkedBarColor: return 91;
      99           0 :         case NS_ooxml::LN_Value_ST_Border_checkered: return 92;
     100           0 :         case NS_ooxml::LN_Value_ST_Border_christmasTree: return 93;
     101           0 :         case NS_ooxml::LN_Value_ST_Border_circlesLines: return 94;
     102           0 :         case NS_ooxml::LN_Value_ST_Border_circlesRectangles: return 95;
     103           0 :         case NS_ooxml::LN_Value_ST_Border_classicalWave: return 96;
     104           0 :         case NS_ooxml::LN_Value_ST_Border_clocks: return 97;
     105           0 :         case NS_ooxml::LN_Value_ST_Border_compass: return 98;
     106           0 :         case NS_ooxml::LN_Value_ST_Border_confetti: return 99;
     107           0 :         case NS_ooxml::LN_Value_ST_Border_confettiGrays: return 100;
     108           0 :         case NS_ooxml::LN_Value_ST_Border_confettiOutline: return 101;
     109           0 :         case NS_ooxml::LN_Value_ST_Border_confettiStreamers: return 102;
     110           0 :         case NS_ooxml::LN_Value_ST_Border_confettiWhite: return 103;
     111           0 :         case NS_ooxml::LN_Value_ST_Border_cornerTriangles: return 104;
     112           0 :         case NS_ooxml::LN_Value_ST_Border_couponCutoutDashes: return 105;
     113           0 :         case NS_ooxml::LN_Value_ST_Border_couponCutoutDots: return 106;
     114           0 :         case NS_ooxml::LN_Value_ST_Border_crazyMaze: return 107;
     115           0 :         case NS_ooxml::LN_Value_ST_Border_creaturesButterfly: return 108;
     116           0 :         case NS_ooxml::LN_Value_ST_Border_creaturesFish: return 109;
     117           0 :         case NS_ooxml::LN_Value_ST_Border_creaturesInsects: return 110;
     118           0 :         case NS_ooxml::LN_Value_ST_Border_creaturesLadyBug: return 111;
     119           0 :         case NS_ooxml::LN_Value_ST_Border_crossStitch: return 112;
     120           0 :         case NS_ooxml::LN_Value_ST_Border_cup: return 113;
     121           0 :         case NS_ooxml::LN_Value_ST_Border_decoArch: return 114;
     122           0 :         case NS_ooxml::LN_Value_ST_Border_decoArchColor: return 115;
     123           0 :         case NS_ooxml::LN_Value_ST_Border_decoBlocks: return 116;
     124           0 :         case NS_ooxml::LN_Value_ST_Border_diamondsGray: return 117;
     125           0 :         case NS_ooxml::LN_Value_ST_Border_doubleD: return 118;
     126           0 :         case NS_ooxml::LN_Value_ST_Border_doubleDiamonds: return 119;
     127           0 :         case NS_ooxml::LN_Value_ST_Border_earth1: return 120;
     128           0 :         case NS_ooxml::LN_Value_ST_Border_earth2: return 121;
     129           0 :         case NS_ooxml::LN_Value_ST_Border_eclipsingSquares1: return 122;
     130           0 :         case NS_ooxml::LN_Value_ST_Border_eclipsingSquares2: return 123;
     131           0 :         case NS_ooxml::LN_Value_ST_Border_eggsBlack: return 124;
     132           0 :         case NS_ooxml::LN_Value_ST_Border_fans: return 125;
     133           0 :         case NS_ooxml::LN_Value_ST_Border_film: return 126;
     134           0 :         case NS_ooxml::LN_Value_ST_Border_firecrackers: return 127;
     135           0 :         case NS_ooxml::LN_Value_ST_Border_flowersBlockPrint: return 128;
     136           0 :         case NS_ooxml::LN_Value_ST_Border_flowersDaisies: return 129;
     137           0 :         case NS_ooxml::LN_Value_ST_Border_flowersModern1: return 130;
     138           0 :         case NS_ooxml::LN_Value_ST_Border_flowersModern2: return 131;
     139           0 :         case NS_ooxml::LN_Value_ST_Border_flowersPansy: return 132;
     140           0 :         case NS_ooxml::LN_Value_ST_Border_flowersRedRose: return 133;
     141           0 :         case NS_ooxml::LN_Value_ST_Border_flowersRoses: return 134;
     142           0 :         case NS_ooxml::LN_Value_ST_Border_flowersTeacup: return 135;
     143           0 :         case NS_ooxml::LN_Value_ST_Border_flowersTiny: return 136;
     144           0 :         case NS_ooxml::LN_Value_ST_Border_gems: return 137;
     145           0 :         case NS_ooxml::LN_Value_ST_Border_gingerbreadMan: return 138;
     146           0 :         case NS_ooxml::LN_Value_ST_Border_gradient: return 139;
     147           0 :         case NS_ooxml::LN_Value_ST_Border_handmade1: return 140;
     148           0 :         case NS_ooxml::LN_Value_ST_Border_handmade2: return 141;
     149           0 :         case NS_ooxml::LN_Value_ST_Border_heartBalloon: return 142;
     150           0 :         case NS_ooxml::LN_Value_ST_Border_heartGray: return 143;
     151           0 :         case NS_ooxml::LN_Value_ST_Border_hearts: return 144;
     152           0 :         case NS_ooxml::LN_Value_ST_Border_heebieJeebies: return 145;
     153           0 :         case NS_ooxml::LN_Value_ST_Border_holly: return 146;
     154           0 :         case NS_ooxml::LN_Value_ST_Border_houseFunky: return 147;
     155           0 :         case NS_ooxml::LN_Value_ST_Border_hypnotic: return 148;
     156           0 :         case NS_ooxml::LN_Value_ST_Border_iceCreamCones: return 149;
     157           0 :         case NS_ooxml::LN_Value_ST_Border_lightBulb: return 150;
     158           0 :         case NS_ooxml::LN_Value_ST_Border_lightning1: return 151;
     159           0 :         case NS_ooxml::LN_Value_ST_Border_lightning2: return 152;
     160           0 :         case NS_ooxml::LN_Value_ST_Border_mapPins: return 153;
     161           0 :         case NS_ooxml::LN_Value_ST_Border_mapleLeaf: return 154;
     162           0 :         case NS_ooxml::LN_Value_ST_Border_mapleMuffins: return 155;
     163           0 :         case NS_ooxml::LN_Value_ST_Border_marquee: return 156;
     164           0 :         case NS_ooxml::LN_Value_ST_Border_marqueeToothed: return 157;
     165           0 :         case NS_ooxml::LN_Value_ST_Border_moons: return 158;
     166           0 :         case NS_ooxml::LN_Value_ST_Border_mosaic: return 159;
     167           0 :         case NS_ooxml::LN_Value_ST_Border_musicNotes: return 160;
     168           0 :         case NS_ooxml::LN_Value_ST_Border_northwest: return 161;
     169           0 :         case NS_ooxml::LN_Value_ST_Border_ovals: return 162;
     170           0 :         case NS_ooxml::LN_Value_ST_Border_packages: return 163;
     171           0 :         case NS_ooxml::LN_Value_ST_Border_palmsBlack: return 164;
     172           0 :         case NS_ooxml::LN_Value_ST_Border_palmsColor: return 165;
     173           0 :         case NS_ooxml::LN_Value_ST_Border_paperClips: return 166;
     174           0 :         case NS_ooxml::LN_Value_ST_Border_papyrus: return 167;
     175           0 :         case NS_ooxml::LN_Value_ST_Border_partyFavor: return 168;
     176           0 :         case NS_ooxml::LN_Value_ST_Border_partyGlass: return 169;
     177           0 :         case NS_ooxml::LN_Value_ST_Border_pencils: return 170;
     178           0 :         case NS_ooxml::LN_Value_ST_Border_people: return 171;
     179           0 :         case NS_ooxml::LN_Value_ST_Border_peopleWaving: return 172;
     180           0 :         case NS_ooxml::LN_Value_ST_Border_peopleHats: return 173;
     181           0 :         case NS_ooxml::LN_Value_ST_Border_poinsettias: return 174;
     182           0 :         case NS_ooxml::LN_Value_ST_Border_postageStamp: return 175;
     183           0 :         case NS_ooxml::LN_Value_ST_Border_pumpkin1: return 176;
     184           0 :         case NS_ooxml::LN_Value_ST_Border_pushPinNote2: return 177;
     185           0 :         case NS_ooxml::LN_Value_ST_Border_pushPinNote1: return 178;
     186           0 :         case NS_ooxml::LN_Value_ST_Border_pyramids: return 179;
     187           0 :         case NS_ooxml::LN_Value_ST_Border_pyramidsAbove: return 180;
     188           0 :         case NS_ooxml::LN_Value_ST_Border_quadrants: return 181;
     189           0 :         case NS_ooxml::LN_Value_ST_Border_rings: return 182;
     190           0 :         case NS_ooxml::LN_Value_ST_Border_safari: return 183;
     191           0 :         case NS_ooxml::LN_Value_ST_Border_sawtooth: return 184;
     192           0 :         case NS_ooxml::LN_Value_ST_Border_sawtoothGray: return 185;
     193           0 :         case NS_ooxml::LN_Value_ST_Border_scaredCat: return 186;
     194           0 :         case NS_ooxml::LN_Value_ST_Border_seattle: return 187;
     195           0 :         case NS_ooxml::LN_Value_ST_Border_shadowedSquares: return 188;
     196           0 :         case NS_ooxml::LN_Value_ST_Border_sharksTeeth: return 189;
     197           0 :         case NS_ooxml::LN_Value_ST_Border_shorebirdTracks: return 190;
     198           0 :         case NS_ooxml::LN_Value_ST_Border_skyrocket: return 191;
     199           0 :         case NS_ooxml::LN_Value_ST_Border_snowflakeFancy: return 192;
     200           0 :         case NS_ooxml::LN_Value_ST_Border_snowflakes: return 193;
     201           0 :         case NS_ooxml::LN_Value_ST_Border_sombrero: return 194;
     202           0 :         case NS_ooxml::LN_Value_ST_Border_southwest: return 195;
     203           0 :         case NS_ooxml::LN_Value_ST_Border_stars: return 196;
     204           0 :         case NS_ooxml::LN_Value_ST_Border_starsTop: return 197;
     205           0 :         case NS_ooxml::LN_Value_ST_Border_stars3d: return 198;
     206           0 :         case NS_ooxml::LN_Value_ST_Border_starsBlack: return 199;
     207           0 :         case NS_ooxml::LN_Value_ST_Border_starsShadowed: return 200;
     208           0 :         case NS_ooxml::LN_Value_ST_Border_sun: return 201;
     209           0 :         case NS_ooxml::LN_Value_ST_Border_swirligig: return 202;
     210           0 :         case NS_ooxml::LN_Value_ST_Border_tornPaper: return 203;
     211           0 :         case NS_ooxml::LN_Value_ST_Border_tornPaperBlack: return 204;
     212           0 :         case NS_ooxml::LN_Value_ST_Border_trees: return 205;
     213           0 :         case NS_ooxml::LN_Value_ST_Border_triangleParty: return 206;
     214           0 :         case NS_ooxml::LN_Value_ST_Border_triangles: return 207;
     215           0 :         case NS_ooxml::LN_Value_ST_Border_tribal1: return 208;
     216           0 :         case NS_ooxml::LN_Value_ST_Border_tribal2: return 209;
     217           0 :         case NS_ooxml::LN_Value_ST_Border_tribal3: return 210;
     218           0 :         case NS_ooxml::LN_Value_ST_Border_tribal4: return 211;
     219           0 :         case NS_ooxml::LN_Value_ST_Border_tribal5: return 212;
     220           0 :         case NS_ooxml::LN_Value_ST_Border_tribal6: return 213;
     221           0 :         case NS_ooxml::LN_Value_ST_Border_twistedLines1: return 214;
     222           0 :         case NS_ooxml::LN_Value_ST_Border_twistedLines2: return 215;
     223           0 :         case NS_ooxml::LN_Value_ST_Border_vine: return 216;
     224           0 :         case NS_ooxml::LN_Value_ST_Border_waveline: return 217;
     225           0 :         case NS_ooxml::LN_Value_ST_Border_weavingAngles: return 218;
     226           0 :         case NS_ooxml::LN_Value_ST_Border_weavingBraid: return 219;
     227           0 :         case NS_ooxml::LN_Value_ST_Border_weavingRibbon: return 220;
     228           0 :         case NS_ooxml::LN_Value_ST_Border_weavingStrips: return 221;
     229           0 :         case NS_ooxml::LN_Value_ST_Border_whiteFlowers: return 222;
     230           0 :         case NS_ooxml::LN_Value_ST_Border_woodwork: return 223;
     231           0 :         case NS_ooxml::LN_Value_ST_Border_xIllusions: return 224;
     232           0 :         case NS_ooxml::LN_Value_ST_Border_zanyTriangles: return 225;
     233           0 :         case NS_ooxml::LN_Value_ST_Border_zigZag: return 226;
     234           0 :         case NS_ooxml::LN_Value_ST_Border_zigZagStitch: return 227;
     235         235 :         default: break;
     236             :     }
     237         235 :     return 0;
     238             : }
     239             : 
     240       32567 : void MakeBorderLine( sal_Int32 nLineThickness,   sal_Int32 nLineToken,
     241             :                                             sal_Int32 nLineColor,
     242             :                                             table::BorderLine2& rToFill, bool bIsOOXML )
     243             : {
     244             :     static const sal_Int32 aBorderDefColor[] =
     245             :     {
     246             :         // The first item means automatic color (COL_AUTO), but we
     247             :         // do not use it anyway (see the next statement) .-)
     248             :         0, COL_BLACK, COL_LIGHTBLUE, COL_LIGHTCYAN, COL_LIGHTGREEN,
     249             :         COL_LIGHTMAGENTA, COL_LIGHTRED, COL_YELLOW, COL_WHITE, COL_BLUE,
     250             :         COL_CYAN, COL_GREEN, COL_MAGENTA, COL_RED, COL_BROWN, COL_GRAY,
     251             :         COL_LIGHTGRAY
     252             :     };
     253             :     //no auto color for borders
     254       32567 :     if(!nLineColor)
     255        8062 :         ++nLineColor;
     256       32567 :     if(!bIsOOXML && sal::static_int_cast<sal_uInt32>(nLineColor) < SAL_N_ELEMENTS(aBorderDefColor))
     257           0 :         nLineColor = aBorderDefColor[nLineColor];
     258             : 
     259       32567 :     sal_Int32 nLineType = lcl_convertBorderStyleFromToken(nLineToken);
     260             : 
     261             :     // Map to our border types, we should use of one equal line
     262             :     // thickness, or one of smaller thickness. If too small we
     263             :     // can make the defecit up in additional white space or
     264             :     // object size
     265             :     ::editeng::SvxBorderStyle const nLineStyle(
     266       32567 :             ::editeng::ConvertBorderStyleFromWord(nLineType));
     267       32567 :     rToFill.LineStyle = nLineStyle;
     268             :     double const fConverted( (table::BorderLineStyle::NONE == nLineStyle) ? 0.0 :
     269             :         ::editeng::ConvertBorderWidthFromWord(nLineStyle, nLineThickness,
     270       32567 :             nLineType));
     271       32567 :     rToFill.LineWidth = convertTwipToMM100(fConverted);
     272       32567 :     rToFill.Color = nLineColor;
     273       32567 : }
     274             : 
     275             : namespace {
     276          13 : void lcl_SwapQuotesInField(OUString &rFmt)
     277             : {
     278             :     //Swap unescaped " and ' with ' and "
     279          13 :     sal_Int32 nLen = rFmt.getLength();
     280          13 :     OUStringBuffer aBuffer( rFmt.getStr() );
     281          13 :     const sal_Unicode* pFmt = rFmt.getStr();
     282         128 :     for (sal_Int32 nI = 0; nI < nLen; ++nI)
     283             :     {
     284         115 :         if ((pFmt[nI] == '\"') && (!nI || pFmt[nI-1] != '\\'))
     285           0 :             aBuffer[nI] = '\'';
     286         115 :         else if ((pFmt[nI] == '\'') && (!nI || pFmt[nI-1] != '\\'))
     287           6 :             aBuffer[nI] = '\"';
     288             :     }
     289          13 :     rFmt = aBuffer.makeStringAndClear();
     290          13 : }
     291           0 : bool lcl_IsNotAM(OUString& rFmt, sal_Int32 nPos)
     292             : {
     293             :     return (
     294           0 :             (nPos == rFmt.getLength() - 1) ||
     295             :             (
     296           0 :             (rFmt[nPos+1] != 'M') &&
     297           0 :             (rFmt[nPos+1] != 'm')
     298             :             )
     299           0 :         );
     300             : }
     301             : }
     302             : 
     303          13 : OUString ConvertMSFormatStringToSO(
     304             :         const OUString& rFormat, lang::Locale& rLocale, bool bHijri)
     305             : {
     306          13 :     OUString sFormat(rFormat);
     307          13 :     lcl_SwapQuotesInField(sFormat);
     308             : 
     309             :     //#102782#, #102815#, #108341# & #111944# have to work at the same time :-)
     310          13 :     bool bForceJapanese(false);
     311          13 :     bool bForceNatNum(false);
     312          13 :     sal_Int32 nLen = sFormat.getLength();
     313          13 :     sal_Int32 nI = 0;
     314             : //    const sal_Unicode* pFormat = sFormat.getStr();
     315          26 :     OUStringBuffer aNewFormat( sFormat );
     316         125 :     while (nI < nLen)
     317             :     {
     318          99 :         if (aNewFormat[nI] == '\\')
     319           7 :             nI++;
     320          92 :         else if (aNewFormat[nI] == '\"')
     321             :         {
     322           3 :             ++nI;
     323             :             //While not at the end and not at an unescaped end quote
     324          12 :             while ((nI < nLen) && (!(aNewFormat[nI] == '\"') && (aNewFormat[nI-1] != '\\')))
     325           6 :                 ++nI;
     326             :         }
     327             :         else //normal unquoted section
     328             :         {
     329          89 :             sal_Unicode nChar = aNewFormat[nI];
     330          89 :             if (nChar == 'O')
     331             :             {
     332           0 :                 aNewFormat[nI] = 'M';
     333           0 :                 bForceNatNum = true;
     334             :             }
     335          89 :             else if (nChar == 'o')
     336             :             {
     337           0 :                 aNewFormat[nI] = 'm';
     338           0 :                 bForceNatNum = true;
     339             :             }
     340          89 :             else if ((nChar == 'A') && lcl_IsNotAM(sFormat, nI))
     341             :             {
     342           0 :                 aNewFormat[nI] = 'D';
     343           0 :                 bForceNatNum = true;
     344             :             }
     345          89 :             else if ((nChar == 'g') || (nChar == 'G'))
     346           0 :                 bForceJapanese = true;
     347          89 :             else if ((nChar == 'a') && lcl_IsNotAM(sFormat, nI))
     348           0 :                 bForceJapanese = true;
     349          89 :             else if (nChar == 'E')
     350             :             {
     351           0 :                 if ((nI != nLen-1) && (aNewFormat[nI+1] == 'E'))
     352             :                 {
     353             :                     //todo: this cannot be the right way to replace a part of the string!
     354           0 :                     aNewFormat[nI] = 'Y';
     355           0 :                     aNewFormat[nI + 1] = 'Y';
     356           0 :                     aNewFormat.insert(nI + 2, "YY");
     357           0 :                     nLen+=2;
     358           0 :                     nI+=3;
     359             :                 }
     360           0 :                 bForceJapanese = true;
     361             :             }
     362          89 :             else if (nChar == 'e')
     363             :             {
     364           0 :                 if ((nI != nLen-1) && (aNewFormat[nI+1] == 'e'))
     365             :                 {
     366             :                     //todo: this cannot be the right way to replace a part of the string!
     367           0 :                     aNewFormat[nI] = 'y';
     368           0 :                     aNewFormat[nI + 1] = 'y';
     369           0 :                     aNewFormat.insert(nI + 2, "yy");
     370           0 :                     nLen+=2;
     371           0 :                     nI+=3;
     372             :                 }
     373           0 :                 bForceJapanese = true;
     374             :             }
     375          89 :             else if (nChar == '/')
     376             :             {
     377             :                 // MM We have to escape '/' in case it's used as a char
     378             :                 //todo: this cannot be the right way to replace a part of the string!
     379           8 :                 aNewFormat[nI] = '\\';
     380           8 :                 aNewFormat.insert(nI + 1, "/");
     381           8 :                 nI++;
     382           8 :                 nLen++;
     383             :             }
     384             :         }
     385          99 :         ++nI;
     386             :     }
     387             : 
     388          13 :     if (bForceNatNum)
     389           0 :         bForceJapanese = true;
     390             : 
     391          13 :     if (bForceJapanese)
     392             :     {
     393           0 :         rLocale.Language = "ja";
     394           0 :         rLocale.Country = "JP";
     395             :     }
     396             : 
     397          13 :     if (bForceNatNum)
     398             :     {
     399           0 :         aNewFormat.insert( 0, "[NatNum1][$-411]");
     400             :     }
     401             : 
     402          13 :     if (bHijri)
     403             :     {
     404           0 :         aNewFormat.insert( 0, "[~hijri]");
     405             :     }
     406          26 :     return aNewFormat.makeStringAndClear();
     407             : 
     408             : }
     409             : 
     410      284687 : sal_Int32 convertTwipToMM100(sal_Int32 _t)
     411             : {
     412             :     // It appears that MSO handles large twip values specially, probably legacy 16bit handling,
     413             :     // anything that's bigger than 32767 appears to be simply ignored.
     414      284687 :     if( _t >= 0x8000 )
     415          15 :         return 0;
     416      284672 :     return ::convertTwipToMm100( _t );
     417             : }
     418             : 
     419       16508 : sal_uInt32 convertTwipToMM100Unsigned(sal_Int32 _t)
     420             : {
     421       16508 :     if( _t < 0 )
     422          15 :         return 0;
     423       16493 :     return convertTwipToMM100( _t );
     424             : }
     425             : 
     426        1499 : sal_Int16 convertTableJustification( sal_Int32 nIntValue )
     427             : {
     428        1499 :     sal_Int16 nOrient = text::HoriOrientation::LEFT_AND_WIDTH;
     429        1499 :     switch( nIntValue )
     430             :     {
     431             :         case NS_ooxml::LN_Value_ST_Jc_center:
     432         724 :             nOrient = text::HoriOrientation::CENTER;
     433         724 :             break;
     434             :         case NS_ooxml::LN_Value_ST_Jc_right:
     435             :         case NS_ooxml::LN_Value_ST_Jc_end:
     436           6 :             nOrient = text::HoriOrientation::RIGHT;
     437           6 :             break;
     438             :         case NS_ooxml::LN_Value_ST_Jc_left:
     439             :         case NS_ooxml::LN_Value_ST_Jc_start:
     440             :         //no break
     441             :         default:;
     442             : 
     443             :     }
     444        1499 :     return nOrient;
     445             : }
     446             : 
     447       38853 : sal_Int16 ConvertNumberingType(sal_Int32 nFmt)
     448             : {
     449             :     sal_Int16 nRet;
     450       38853 :     switch(nFmt)
     451             :     {
     452             :         case NS_ooxml::LN_Value_ST_NumberFormat_decimal:
     453        8756 :             nRet = style::NumberingType::ARABIC;
     454        8756 :             break;
     455             :         case NS_ooxml::LN_Value_ST_NumberFormat_upperRoman:
     456          77 :             nRet = style::NumberingType::ROMAN_UPPER;
     457          77 :             break;
     458             :         case NS_ooxml::LN_Value_ST_NumberFormat_lowerRoman:
     459        4485 :             nRet = style::NumberingType::ROMAN_LOWER;
     460        4485 :             break;
     461             :         case NS_ooxml::LN_Value_ST_NumberFormat_ordinal:
     462           0 :             nRet = style::NumberingType::ARABIC;
     463           0 :             break;
     464             :         case NS_ooxml::LN_Value_ST_NumberFormat_bullet:
     465       18829 :             nRet = style::NumberingType::CHAR_SPECIAL;
     466       18829 :         break;
     467             :         case NS_ooxml::LN_Value_ST_NumberFormat_none:
     468        1053 :             nRet = style::NumberingType::NUMBER_NONE;
     469        1053 :             break;
     470             :         case NS_ooxml::LN_Value_ST_NumberFormat_upperLetter:
     471         145 :             nRet = style::NumberingType::CHARS_UPPER_LETTER_N;
     472         145 :             break;
     473             :         case  NS_ooxml::LN_Value_ST_NumberFormat_lowerLetter:
     474        4095 :             nRet = style::NumberingType::CHARS_LOWER_LETTER_N;
     475        4095 :             break;
     476             :         case NS_ooxml::LN_Value_ST_NumberFormat_iroha:
     477           3 :             nRet = style::NumberingType::IROHA_HALFWIDTH_JA;
     478           3 :             break;
     479             :         case NS_ooxml::LN_Value_ST_NumberFormat_irohaFullWidth:
     480           3 :             nRet = style::NumberingType::IROHA_FULLWIDTH_JA;
     481           3 :             break;
     482             :         case NS_ooxml::LN_Value_ST_NumberFormat_aiueo:
     483           3 :             nRet = style::NumberingType::AIU_HALFWIDTH_JA;
     484           3 :             break;
     485             :         case NS_ooxml::LN_Value_ST_NumberFormat_aiueoFullWidth:
     486           3 :             nRet = style::NumberingType::AIU_FULLWIDTH_JA;
     487           3 :             break;
     488             :         case NS_ooxml::LN_Value_ST_NumberFormat_hebrew2:
     489           0 :             nRet = style::NumberingType::CHARS_HEBREW;
     490           0 :             break;
     491             :         case NS_ooxml::LN_Value_ST_NumberFormat_thaiLetters:
     492           0 :             nRet = style::NumberingType::CHARS_THAI;
     493           0 :             break;
     494             :         case NS_ooxml::LN_Value_ST_NumberFormat_russianLower:
     495           0 :             nRet = style::NumberingType::CHARS_CYRILLIC_LOWER_LETTER_RU;
     496           0 :             break;
     497             :         case NS_ooxml::LN_Value_ST_NumberFormat_russianUpper:
     498           0 :             nRet = style::NumberingType::CHARS_CYRILLIC_UPPER_LETTER_RU;
     499           0 :             break;
     500             :         case NS_ooxml::LN_Value_ST_NumberFormat_decimalEnclosedCircleChinese:
     501             :         case NS_ooxml::LN_Value_ST_NumberFormat_ideographEnclosedCircle:
     502           0 :             nRet = style::NumberingType::CIRCLE_NUMBER;
     503           0 :             break;
     504             :         case NS_ooxml::LN_Value_ST_NumberFormat_ideographTraditional:
     505         164 :             nRet = style::NumberingType::TIAN_GAN_ZH;
     506         164 :             break;
     507             :         case NS_ooxml::LN_Value_ST_NumberFormat_ideographZodiac:
     508           6 :             nRet = style::NumberingType::DI_ZI_ZH;
     509           6 :             break;
     510             :         case NS_ooxml::LN_Value_ST_NumberFormat_ganada:
     511           3 :             nRet = style::NumberingType::HANGUL_SYLLABLE_KO;
     512           3 :             break;
     513             :         case NS_ooxml::LN_Value_ST_NumberFormat_chosung:
     514           3 :             nRet = style::NumberingType::HANGUL_JAMO_KO;
     515           3 :             break;
     516             :         case NS_ooxml::LN_Value_ST_NumberFormat_koreanLegal:
     517             :         case NS_ooxml::LN_Value_ST_NumberFormat_koreanDigital:
     518             :         case NS_ooxml::LN_Value_ST_NumberFormat_koreanCounting:
     519             :         case NS_ooxml::LN_Value_ST_NumberFormat_koreanDigital2:
     520           3 :             nRet = style::NumberingType::NUMBER_HANGUL_KO;
     521           3 :             break;
     522             :         case NS_ooxml::LN_Value_ST_NumberFormat_ideographLegalTraditional:
     523           6 :             nRet = style::NumberingType::NUMBER_UPPER_ZH_TW;
     524           6 :             break;
     525             :         case NS_ooxml::LN_Value_ST_NumberFormat_arabicAlpha:
     526           0 :             nRet = style::NumberingType::CHARS_ARABIC;
     527           0 :             break;
     528             :         case NS_ooxml::LN_Value_ST_NumberFormat_hindiVowels:
     529           0 :             nRet = style::NumberingType::CHARS_NEPALI;
     530           0 :             break;
     531             :         case NS_ooxml::LN_Value_ST_NumberFormat_japaneseLegal:
     532           3 :             nRet = style::NumberingType::NUMBER_TRADITIONAL_JA;
     533           3 :             break;
     534             :         case NS_ooxml::LN_Value_ST_NumberFormat_chineseCounting:
     535             :         case NS_ooxml::LN_Value_ST_NumberFormat_japaneseCounting:
     536             :         case NS_ooxml::LN_Value_ST_NumberFormat_taiwaneseCounting:
     537             :         case NS_ooxml::LN_Value_ST_NumberFormat_taiwaneseCountingThousand:
     538             :         case NS_ooxml::LN_Value_ST_NumberFormat_ideographDigital:
     539             :         case NS_ooxml::LN_Value_ST_NumberFormat_chineseCountingThousand:
     540          23 :             nRet = style::NumberingType::NUMBER_LOWER_ZH;
     541          23 :             break;
     542             :         case NS_ooxml::LN_Value_ST_NumberFormat_chineseLegalSimplified:
     543           3 :             nRet = style::NumberingType::NUMBER_UPPER_ZH;
     544           3 :             break;
     545             :         case NS_ooxml::LN_Value_ST_NumberFormat_hebrew1:
     546             :             //91726
     547           3 :             nRet = style::NumberingType::CHARS_HEBREW;
     548           3 :             break;
     549             :         case NS_ooxml::LN_Value_ST_NumberFormat_decimalFullWidth:
     550             :         case NS_ooxml::LN_Value_ST_NumberFormat_decimalFullWidth2:
     551           8 :             nRet = style::NumberingType::FULLWIDTH_ARABIC;
     552           8 :             break;
     553        1176 :         default: nRet = style::NumberingType::ARABIC;
     554             :     }
     555             : /*  TODO: Lots of additional values are available - some are supported in the I18 framework
     556             :     NS_ooxml::LN_Value_ST_NumberFormat_ordinal = 91682;
     557             :     NS_ooxml::LN_Value_ST_NumberFormat_cardinalText = 91683;
     558             :     NS_ooxml::LN_Value_ST_NumberFormat_ordinalText = 91684;
     559             :     NS_ooxml::LN_Value_ST_NumberFormat_hex = 91685;
     560             :     NS_ooxml::LN_Value_ST_NumberFormat_chicago = 91686;
     561             :     NS_ooxml::LN_Value_ST_NumberFormat_decimalFullWidth = 91691;
     562             :     NS_ooxml::LN_Value_ST_NumberFormat_decimalHalfWidth = 91692;
     563             :     NS_ooxml::LN_Value_ST_NumberFormat_japaneseDigitalTenThousand = 91694;
     564             :     NS_ooxml::LN_Value_ST_NumberFormat_decimalEnclosedCircle = 91695;
     565             :     NS_ooxml::LN_Value_ST_NumberFormat_decimalZero = 91699;
     566             :     NS_ooxml::LN_Value_ST_NumberFormat_decimalEnclosedFullstop = 91703;
     567             :     NS_ooxml::LN_Value_ST_NumberFormat_decimalEnclosedParen = 91704;
     568             :     NS_ooxml::LN_Value_ST_NumberFormat_ideographZodiacTraditional = 91709;
     569             :     NS_ooxml::LN_Value_ST_NumberFormat_taiwaneseDigital = 91713;
     570             :     NS_ooxml::LN_Value_ST_NumberFormat_chineseLegalSimplified = 91715;
     571             :     NS_ooxml::LN_Value_ST_NumberFormat_chineseCountingThousand = 91716;
     572             :     NS_ooxml::LN_Value_ST_NumberFormat_koreanLegal = 91719;
     573             :     NS_ooxml::LN_Value_ST_NumberFormat_vietnameseCounting = 91721;
     574             :     NS_ooxml::LN_Value_ST_NumberFormat_numberInDash = 91725;
     575             :     NS_ooxml::LN_Value_ST_NumberFormat_arabicAbjad:
     576             :     NS_ooxml::LN_Value_ST_NumberFormat_hindiConsonants = 91731;
     577             :     NS_ooxml::LN_Value_ST_NumberFormat_hindiNumbers = 91732;
     578             :     NS_ooxml::LN_Value_ST_NumberFormat_hindiCounting = 91733;
     579             :     NS_ooxml::LN_Value_ST_NumberFormat_thaiNumbers = 91735;
     580             :     NS_ooxml::LN_Value_ST_NumberFormat_thaiCounting = 91736;*/
     581       38853 :     return nRet;
     582             : }
     583             : 
     584        1517 : util::DateTime ConvertDateStringToDateTime( const OUString& rDateTime )
     585             : {
     586        1517 :     util::DateTime aDateTime;
     587             :     //xsd::DateTime in the format [-]CCYY-MM-DDThh:mm:ss[Z|(+|-)hh:mm] example: 2008-01-21T10:42:00Z
     588             :     //OUString getToken( sal_Int32 token, sal_Unicode cTok, sal_Int32& index ) const
     589        1517 :     sal_Int32 nIndex = 0;
     590        1517 :     OUString sDate = rDateTime.getToken( 0, 'T', nIndex );
     591             :     // HACK: this is broken according to the spec, but MSOffice always treats the time as local,
     592             :     // and writes it as Z (=UTC+0)
     593        3034 :     OUString sTime = rDateTime.getToken( 0, 'Z', nIndex );
     594        1517 :     nIndex = 0;
     595        1517 :     aDateTime.Year = sal_uInt16( sDate.getToken( 0, '-', nIndex ).toInt32() );
     596        1517 :     aDateTime.Month = sal_uInt16( sDate.getToken( 0, '-', nIndex ).toInt32() );
     597        1517 :     if (nIndex != -1)
     598        1497 :         aDateTime.Day = sal_uInt16( sDate.copy( nIndex ).toInt32() );
     599             : 
     600        1517 :     nIndex = 0;
     601        1517 :     aDateTime.Hours = sal_uInt16( sTime.getToken( 0, ':', nIndex ).toInt32() );
     602        1517 :     aDateTime.Minutes = sal_uInt16( sTime.getToken( 0, ':', nIndex ).toInt32() );
     603        1517 :     if (nIndex != -1)
     604        1497 :         aDateTime.Seconds = sal_uInt16( sTime.copy( nIndex ).toInt32() );
     605             : 
     606        3034 :     return aDateTime;
     607             : }
     608             : 
     609             : 
     610             : } // namespace ConversionHelper
     611             : } //namespace dmapper
     612          72 : } //namespace writerfilter
     613             : 
     614             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11