LCOV - code coverage report
Current view: top level - sw/source/filter/xml - xmlithlp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 52 86 60.5 %
Date: 2012-08-25 Functions: 4 6 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 65 142 45.8 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "xmlithlp.hxx"
      30                 :            : #include "hintids.hxx"
      31                 :            : #include "unomid.h"
      32                 :            : #include <sax/tools/converter.hxx>
      33                 :            : #include <svx/unomid.hxx>
      34                 :            : #include <editeng/lrspitem.hxx>
      35                 :            : #include <editeng/ulspitem.hxx>
      36                 :            : #include <editeng/shaditem.hxx>
      37                 :            : #include <editeng/boxitem.hxx>
      38                 :            : #include <editeng/brkitem.hxx>
      39                 :            : #include <editeng/keepitem.hxx>
      40                 :            : #include <editeng/brshitem.hxx>
      41                 :            : #include "fmtpdsc.hxx"
      42                 :            : #include "fmtornt.hxx"
      43                 :            : #include "fmtfsize.hxx"
      44                 :            : 
      45                 :            : #include "fmtlsplt.hxx"
      46                 :            : #include <xmloff/xmluconv.hxx>
      47                 :            : 
      48                 :            : using ::editeng::SvxBorderLine;
      49                 :            : using ::rtl::OUString;
      50                 :            : using namespace ::xmloff::token;
      51                 :            : using namespace ::com::sun::star;
      52                 :            : 
      53                 :            : 
      54                 :            : #define API_LINE_NONE 0x7FFF
      55                 :            : #define API_LINE_SOLID 0
      56                 :            : #define API_LINE_DOTTED 1
      57                 :            : #define API_LINE_DASHED 2
      58                 :            : #define API_LINE_DOUBLE 3
      59                 :            : #define API_LINE_EMBOSSED 10
      60                 :            : #define API_LINE_ENGRAVED 11
      61                 :            : #define API_LINE_OUTSET 12
      62                 :            : #define API_LINE_INSET 13
      63                 :            : 
      64                 :            : #define SVX_XML_BORDER_WIDTH_THIN 0
      65                 :            : #define SVX_XML_BORDER_WIDTH_MIDDLE 1
      66                 :            : #define SVX_XML_BORDER_WIDTH_THICK 2
      67                 :            : 
      68                 :            : 
      69                 :            : const struct SvXMLEnumMapEntry psXML_BorderStyles[] =
      70                 :            : {
      71                 :            :     { XML_NONE,       API_LINE_NONE },
      72                 :            :     { XML_HIDDEN,     API_LINE_NONE },
      73                 :            :     { XML_SOLID,      API_LINE_SOLID },
      74                 :            :     { XML_DOUBLE,     API_LINE_DOUBLE },
      75                 :            :     { XML_DOTTED,     API_LINE_DOTTED },
      76                 :            :     { XML_DASHED,     API_LINE_DASHED },
      77                 :            :     { XML_GROOVE,     API_LINE_ENGRAVED },
      78                 :            :     { XML_RIDGE,      API_LINE_EMBOSSED },
      79                 :            :     { XML_INSET,      API_LINE_INSET },
      80                 :            :     { XML_OUTSET,     API_LINE_OUTSET },
      81                 :            :     { XML_TOKEN_INVALID, 0 }
      82                 :            : };
      83                 :            : 
      84                 :            : const struct SvXMLEnumMapEntry psXML_NamedBorderWidths[] =
      85                 :            : {
      86                 :            :         { XML_THIN,         SVX_XML_BORDER_WIDTH_THIN   },
      87                 :            :         { XML_MIDDLE,   SVX_XML_BORDER_WIDTH_MIDDLE     },
      88                 :            :         { XML_THICK,    SVX_XML_BORDER_WIDTH_THICK      },
      89                 :            :         { XML_TOKEN_INVALID, 0 }
      90                 :            : };
      91                 :            : // mapping tables to map external xml input to intarnal box line widths
      92                 :            : 
      93                 :            : 
      94                 :            : const sal_uInt16 aBorderWidths[] =
      95                 :            : {
      96                 :            :         DEF_LINE_WIDTH_0,
      97                 :            :         DEF_LINE_WIDTH_5,
      98                 :            :         DEF_LINE_WIDTH_1,
      99                 :            : };
     100                 :            : 
     101                 :         51 : sal_Bool lcl_frmitems_parseXMLBorder( const OUString& rValue,
     102                 :            :                                       const SvXMLUnitConverter& rUnitConverter,
     103                 :            :                                       sal_Bool& rHasStyle, sal_uInt16& rStyle,
     104                 :            :                                       sal_Bool& rHasWidth, sal_uInt16& rWidth,
     105                 :            :                                       sal_uInt16& rNamedWidth,
     106                 :            :                                       sal_Bool& rHasColor, Color& rColor )
     107                 :            : {
     108                 :         51 :     OUString aToken;
     109         [ +  - ]:         51 :     SvXMLTokenEnumerator aTokens( rValue );
     110                 :            : 
     111                 :         51 :     rHasStyle = sal_False;
     112                 :         51 :     rHasWidth = sal_False;
     113                 :         51 :     rHasColor = sal_False;
     114                 :            : 
     115                 :         51 :     rStyle = USHRT_MAX;
     116                 :         51 :     rWidth = 0;
     117                 :         51 :     rNamedWidth = USHRT_MAX;
     118                 :            : 
     119                 :            :     sal_Int32 nTemp;
     120 [ +  - ][ +  + ]:        204 :     while( aTokens.getNextToken( aToken ) && !aToken.isEmpty() )
         [ +  - ][ +  + ]
     121                 :            :     {
     122 [ +  + ][ -  + ]:        204 :         if( !rHasWidth &&
                 [ -  + ]
     123                 :            :             rUnitConverter.convertEnum( rNamedWidth, aToken,
     124         [ +  - ]:         51 :                                         psXML_NamedBorderWidths ) )
     125                 :            :         {
     126                 :          0 :             rHasWidth = sal_True;
     127                 :            :         }
     128 [ +  + ][ +  + ]:        255 :         else if( !rHasStyle &&
                 [ +  + ]
     129                 :            :                  rUnitConverter.convertEnum( rStyle, aToken,
     130         [ +  - ]:        102 :                                              psXML_BorderStyles ) )
     131                 :            :         {
     132                 :         51 :             rHasStyle = sal_True;
     133                 :            :         }
     134 [ +  - ][ +  - ]:        102 :         else if (!rHasColor && ::sax::Converter::convertColor(nTemp, aToken))
         [ +  + ][ +  + ]
     135                 :            :         {
     136                 :         51 :             rColor.SetColor(nTemp);
     137                 :         51 :             rHasColor = sal_True;
     138                 :            :         }
     139 [ +  - ][ +  - ]:        102 :         else if( !rHasWidth &&
                 [ +  - ]
     140         [ +  - ]:         51 :              rUnitConverter.convertMeasureToCore(nTemp, aToken, 0, USHRT_MAX))
     141                 :            :         {
     142                 :         51 :             rWidth = (sal_uInt16)nTemp;
     143                 :         51 :             rHasWidth = sal_True;
     144                 :            :         }
     145                 :            :         else
     146                 :            :         {
     147                 :            :             // missformed
     148                 :          0 :             return sal_False;
     149                 :            :         }
     150                 :            :     }
     151                 :            : 
     152 [ -  + ][ #  # ]:         51 :     return rHasStyle || rHasWidth || rHasColor;
                 [ #  # ]
     153                 :            : }
     154                 :            : 
     155                 :         72 : void lcl_frmitems_setXMLBorderStyle( SvxBorderLine& rLine, sal_uInt16 nStyle )
     156                 :            : {
     157                 :         72 :     ::editeng::SvxBorderStyle eStyle = table::BorderLineStyle::NONE;
     158         [ +  - ]:         72 :     if ( nStyle != API_LINE_NONE )
     159                 :         72 :         eStyle = ::editeng::SvxBorderStyle( nStyle );
     160                 :         72 :     rLine.SetBorderLineStyle(eStyle);
     161                 :         72 : }
     162                 :            : 
     163                 :        204 : sal_Bool lcl_frmitems_setXMLBorder( SvxBorderLine*& rpLine,
     164                 :            :                                     sal_Bool bHasStyle, sal_uInt16 nStyle,
     165                 :            :                                     sal_Bool bHasWidth, sal_uInt16 nWidth,
     166                 :            :                                     sal_uInt16 nNamedWidth,
     167                 :            :                                     sal_Bool bHasColor, const Color& rColor )
     168                 :            : {
     169                 :            :     // first of all, delete an empty line
     170 [ +  - ][ +  - ]:        204 :     if( (bHasStyle && API_LINE_NONE == nStyle) ||
         [ +  - ][ +  - ]
                 [ -  + ]
     171                 :            :         (bHasWidth && USHRT_MAX == nNamedWidth && 0 == nWidth) )
     172                 :            :     {
     173                 :          0 :         sal_Bool bRet = 0 != rpLine;
     174         [ #  # ]:          0 :         if( rpLine )
     175                 :            :         {
     176                 :          0 :             delete rpLine;
     177                 :          0 :             rpLine = 0;
     178                 :            :         }
     179                 :            : 
     180                 :          0 :         return bRet;
     181                 :            :     }
     182                 :            : 
     183                 :            :     // if there is no line and no style and no with, there will never be a line
     184 [ +  + ][ +  - ]:        204 :     if( !rpLine && !(bHasStyle && bHasWidth) )
                 [ -  + ]
     185                 :          0 :         return sal_False;
     186                 :            : 
     187                 :            :     // We now do know that there will be a line
     188         [ +  + ]:        204 :     if( !rpLine )
     189         [ +  - ]:         72 :         rpLine = new SvxBorderLine;
     190                 :            : 
     191                 :            : 
     192         [ +  - ]:        540 :     if( ( bHasWidth &&
           [ +  -  +  + ]
                 [ +  - ]
           [ -  +  #  # ]
           [ +  -  -  + ]
                 [ +  + ]
     193                 :        204 :           (USHRT_MAX != nNamedWidth || (nWidth != rpLine->GetWidth() ) ) ) ||
     194                 :            :         ( bHasStyle &&
     195                 :          0 :           ((API_LINE_SOLID == nStyle && rpLine->GetDistance()) ||
     196                 :        132 :             (API_LINE_DOUBLE == nStyle && !rpLine->GetDistance())) ) )
     197                 :            :    {
     198                 :            :        sal_Bool bDouble = (bHasWidth && API_LINE_DOUBLE == nStyle ) ||
     199 [ +  - ][ +  - ]:         72 :            rpLine->GetDistance();
                 [ -  + ]
     200                 :            : 
     201                 :            :        // fdo#38542: for double borders, do not override the width
     202                 :            :        // set via style:border-line-width{,-left,-right,-top,-bottom}
     203 [ -  + ][ #  # ]:         72 :        if (!bDouble || !rpLine->GetWidth())
                 [ +  - ]
     204                 :            :        {
     205                 :            :            // The width has to be changed
     206 [ +  - ][ -  + ]:         72 :            if (bHasWidth && USHRT_MAX != nNamedWidth)
     207                 :            :            {
     208         [ #  # ]:          0 :                if (bDouble)
     209                 :            :                {
     210                 :          0 :                    rpLine->SetBorderLineStyle( table::BorderLineStyle::DOUBLE );
     211                 :            :                }
     212                 :          0 :                rpLine->SetWidth( aBorderWidths[nNamedWidth] );
     213                 :            :            }
     214                 :            :            else
     215                 :            :            {
     216         [ -  + ]:         72 :                if (!bHasWidth)
     217                 :          0 :                    nWidth = rpLine->GetInWidth() + rpLine->GetDistance() +
     218                 :          0 :                        rpLine->GetOutWidth();
     219                 :            : 
     220                 :         72 :                rpLine->SetWidth( nWidth );
     221                 :            :            }
     222                 :            :        }
     223                 :         72 :        lcl_frmitems_setXMLBorderStyle( *rpLine, nStyle );
     224                 :            :    }
     225                 :            : 
     226                 :            :     // set color
     227         [ +  - ]:        204 :     if( bHasColor )
     228                 :        204 :         rpLine->SetColor( rColor );
     229                 :            : 
     230                 :        204 :     return sal_True;
     231                 :            : }
     232                 :            : 
     233                 :        132 : void lcl_frmitems_setXMLBorder( SvxBorderLine*& rpLine,
     234                 :            :   sal_uInt16 nWidth, sal_uInt16 nOutWidth,
     235                 :            :   sal_uInt16 nInWidth, sal_uInt16 nDistance )
     236                 :            : {
     237         [ +  - ]:        132 :     if( !rpLine )
     238         [ +  - ]:        132 :         rpLine = new SvxBorderLine;
     239                 :            : 
     240         [ -  + ]:        132 :     if( nWidth > 0 )
     241                 :          0 :         rpLine->SetWidth( nWidth );
     242                 :            :     else
     243                 :            :         rpLine->GuessLinesWidths(table::BorderLineStyle::DOUBLE,
     244                 :        132 :                 nOutWidth, nInWidth, nDistance);
     245                 :        132 : }
     246                 :            : 
     247                 :            : const struct SvXMLEnumMapEntry psXML_BrushRepeat[] =
     248                 :            : {
     249                 :            :     { XML_BACKGROUND_REPEAT,        GPOS_TILED  },
     250                 :            :     { XML_BACKGROUND_NO_REPEAT,     GPOS_MM     },
     251                 :            :     { XML_BACKGROUND_STRETCH,       GPOS_AREA   },
     252                 :            :     { XML_TOKEN_INVALID, 0 }
     253                 :            : };
     254                 :            : 
     255                 :            : const struct SvXMLEnumMapEntry psXML_BrushHoriPos[] =
     256                 :            : {
     257                 :            :     { XML_LEFT,         GPOS_LM },
     258                 :            :     { XML_RIGHT,        GPOS_RM },
     259                 :            :     { XML_TOKEN_INVALID, 0 }
     260                 :            : };
     261                 :            : 
     262                 :            : const struct SvXMLEnumMapEntry psXML_BrushVertPos[] =
     263                 :            : {
     264                 :            :     { XML_TOP,          GPOS_MT },
     265                 :            :     { XML_BOTTOM,       GPOS_MB },
     266                 :            :     { XML_TOKEN_INVALID, 0 }
     267                 :            : };
     268                 :            : 
     269                 :          0 : void lcl_frmitems_MergeXMLHoriPos( SvxGraphicPosition& ePos,
     270                 :            :                                    SvxGraphicPosition eHori )
     271                 :            : {
     272                 :            :     OSL_ENSURE( GPOS_LM==eHori || GPOS_MM==eHori || GPOS_RM==eHori,
     273                 :            :                 "lcl_frmitems_MergeXMLHoriPos: vertical pos must be middle" );
     274                 :            : 
     275   [ #  #  #  # ]:          0 :     switch( ePos )
     276                 :            :     {
     277                 :            :     case GPOS_LT:
     278                 :            :     case GPOS_MT:
     279                 :            :     case GPOS_RT:
     280 [ #  # ][ #  # ]:          0 :         ePos = GPOS_LM==eHori ? GPOS_LT : (GPOS_MM==eHori ? GPOS_MT : GPOS_RT);
     281                 :          0 :         break;
     282                 :            : 
     283                 :            :     case GPOS_LM:
     284                 :            :     case GPOS_MM:
     285                 :            :     case GPOS_RM:
     286                 :          0 :         ePos = eHori;
     287                 :          0 :         break;
     288                 :            : 
     289                 :            :     case GPOS_LB:
     290                 :            :     case GPOS_MB:
     291                 :            :     case GPOS_RB:
     292 [ #  # ][ #  # ]:          0 :         ePos = GPOS_LM==eHori ? GPOS_LB : (GPOS_MM==eHori ? GPOS_MB : GPOS_RB);
     293                 :          0 :         break;
     294                 :            :     default:
     295                 :            :         ;
     296                 :            :     }
     297                 :          0 : }
     298                 :            : 
     299                 :          0 : void lcl_frmitems_MergeXMLVertPos( SvxGraphicPosition& ePos,
     300                 :            :                                      SvxGraphicPosition eVert )
     301                 :            : {
     302                 :            :     OSL_ENSURE( GPOS_MT==eVert || GPOS_MM==eVert || GPOS_MB==eVert,
     303                 :            :                 "lcl_frmitems_MergeXMLVertPos: horizontal pos must be middle" );
     304                 :            : 
     305   [ #  #  #  # ]:          0 :     switch( ePos )
     306                 :            :     {
     307                 :            :     case GPOS_LT:
     308                 :            :     case GPOS_LM:
     309                 :            :     case GPOS_LB:
     310 [ #  # ][ #  # ]:          0 :         ePos = GPOS_MT==eVert ? GPOS_LT : (GPOS_MM==eVert ? GPOS_LM : GPOS_LB);
     311                 :          0 :         ePos = eVert;
     312                 :          0 :         break;
     313                 :            : 
     314                 :            :     case GPOS_MT:
     315                 :            :     case GPOS_MM:
     316                 :            :     case GPOS_MB:
     317                 :          0 :         ePos = eVert;
     318                 :          0 :         break;
     319                 :            : 
     320                 :            :     case GPOS_RT:
     321                 :            :     case GPOS_RM:
     322                 :            :     case GPOS_RB:
     323 [ #  # ][ #  # ]:          0 :         ePos = GPOS_MT==eVert ? GPOS_RT : (GPOS_MM==eVert ? GPOS_RM : GPOS_RB);
     324                 :          0 :         break;
     325                 :            :     default:
     326                 :            :         ;
     327                 :            :     }
     328                 :          0 : }
     329                 :            : 
     330                 :            : 
     331                 :            : const struct SvXMLEnumMapEntry psXML_BreakType[] =
     332                 :            : {
     333                 :            :         { XML_AUTO,         0 },
     334                 :            :         { XML_COLUMN,       1 },
     335                 :            :         { XML_PAGE,         2 },
     336                 :            :         { XML_EVEN_PAGE,    2 },
     337                 :            :         { XML_ODD_PAGE,     2 },
     338                 :            :         { XML_TOKEN_INVALID, 0}
     339                 :            : };
     340                 :            : 
     341                 :            : const struct  SvXMLEnumMapEntry aXMLTableAlignMap[] =
     342                 :            : {
     343                 :            :     { XML_LEFT,             text::HoriOrientation::LEFT           },
     344                 :            :     { XML_LEFT,             text::HoriOrientation::LEFT_AND_WIDTH },
     345                 :            :     { XML_CENTER,           text::HoriOrientation::CENTER         },
     346                 :            :     { XML_RIGHT,            text::HoriOrientation::RIGHT          },
     347                 :            :     { XML_MARGINS,          text::HoriOrientation::FULL           },
     348                 :            :     { XML_MARGINS,          text::HoriOrientation::NONE           },
     349                 :            :     { XML_TOKEN_INVALID, 0 }
     350                 :            : };
     351                 :            : 
     352                 :            : const struct  SvXMLEnumMapEntry aXMLTableVAlignMap[] =
     353                 :            : {
     354                 :            :     { XML_TOP,                  text::VertOrientation::TOP        },
     355                 :            :     { XML_MIDDLE,               text::VertOrientation::CENTER     },
     356                 :            :     { XML_BOTTOM,               text::VertOrientation::BOTTOM     },
     357                 :            :     { XML_TOKEN_INVALID, 0 }
     358                 :            : };
     359                 :            : 
     360                 :            : const struct SvXMLEnumMapEntry aXML_KeepTogetherType[] =
     361                 :            : {
     362                 :            :         { XML_ALWAYS,       0 },
     363                 :            :         { XML_AUTO,         1 },
     364                 :            :         { XML_TOKEN_INVALID, 0}
     365                 :            : };
     366                 :            : 
     367                 :            : 
     368                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10