LCOV - code coverage report
Current view: top level - xmloff/source/style - bordrhdl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 96 133 72.2 %
Date: 2012-08-25 Functions: 9 9 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 81 164 49.4 %

           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                 :            : 
      30                 :            : #include <bordrhdl.hxx>
      31                 :            : #include <sax/tools/converter.hxx>
      32                 :            : #include <xmloff/xmltoken.hxx>
      33                 :            : #include <xmloff/xmluconv.hxx>
      34                 :            : #include <rtl/ustrbuf.hxx>
      35                 :            : #include <com/sun/star/uno/Any.hxx>
      36                 :            : #include <com/sun/star/table/BorderLine2.hpp>
      37                 :            : 
      38                 :            : #if DEBUG
      39                 :            : #include <cstdio>
      40                 :            : #endif
      41                 :            : 
      42                 :            : using ::rtl::OUString;
      43                 :            : using ::rtl::OUStringBuffer;
      44                 :            : 
      45                 :            : using namespace ::com::sun::star;
      46                 :            : using namespace ::xmloff::token;
      47                 :            : 
      48                 :            : const sal_uInt16 API_LINE_SOLID   = 0;
      49                 :            : const sal_uInt16 API_LINE_DOTTED  = 1;
      50                 :            : const sal_uInt16 API_LINE_DASHED  = 2;
      51                 :            : const sal_uInt16 API_LINE_DOUBLE  = 3;
      52                 :            : const sal_uInt16 API_LINE_THINTHICK_SMALLGAP  = 4;
      53                 :            : const sal_uInt16 API_LINE_THINTHICK_MEDIUMGAP  = 5;
      54                 :            : const sal_uInt16 API_LINE_THINTHICK_LARGEGAP  = 6;
      55                 :            : const sal_uInt16 API_LINE_THICKTHIN_SMALLGAP  = 7;
      56                 :            : const sal_uInt16 API_LINE_THICKTHIN_MEDIUMGAP  = 8;
      57                 :            : const sal_uInt16 API_LINE_THICKTHIN_LARGEGAP  = 9;
      58                 :            : const sal_uInt16 API_LINE_EMBOSSED  = 10;
      59                 :            : const sal_uInt16 API_LINE_ENGRAVED  = 11;
      60                 :            : const sal_uInt16 API_LINE_OUTSET  = 12;
      61                 :            : const sal_uInt16 API_LINE_INSET  = 13;
      62                 :            : const sal_uInt16 API_LINE_NONE = USHRT_MAX;
      63                 :            : 
      64                 :            : #define DEF_LINE_WIDTH_0        1
      65                 :            : #define DEF_LINE_WIDTH_1        35
      66                 :            : #define DEF_LINE_WIDTH_2        88
      67                 :            : 
      68                 :            : #define SVX_XML_BORDER_WIDTH_THIN 0
      69                 :            : #define SVX_XML_BORDER_WIDTH_MIDDLE 1
      70                 :            : #define SVX_XML_BORDER_WIDTH_THICK 2
      71                 :            : 
      72                 :            : SvXMLEnumMapEntry pXML_BorderStyles[] =
      73                 :            : {
      74                 :            :     { XML_NONE,                 API_LINE_NONE   },
      75                 :            :     { XML_HIDDEN,               API_LINE_NONE   },
      76                 :            :     { XML_SOLID,                API_LINE_SOLID  },
      77                 :            :     { XML_DOUBLE,               API_LINE_DOUBLE },
      78                 :            :     { XML_DOTTED,               API_LINE_DOTTED },
      79                 :            :     { XML_DASHED,               API_LINE_DASHED },
      80                 :            :     { XML_GROOVE,               API_LINE_ENGRAVED },
      81                 :            :     { XML_RIDGE,                API_LINE_EMBOSSED },
      82                 :            :     { XML_INSET,                API_LINE_INSET  },
      83                 :            :     { XML_OUTSET,               API_LINE_OUTSET },
      84                 :            :     { XML_TOKEN_INVALID,        0 }
      85                 :            : };
      86                 :            : 
      87                 :            : SvXMLEnumMapEntry pXML_NamedBorderWidths[] =
      88                 :            : {
      89                 :            :     { XML_THIN,             SVX_XML_BORDER_WIDTH_THIN   },
      90                 :            :     { XML_MIDDLE,           SVX_XML_BORDER_WIDTH_MIDDLE },
      91                 :            :     { XML_THICK,            SVX_XML_BORDER_WIDTH_THICK  },
      92                 :            :     { XML_TOKEN_INVALID,    0 }
      93                 :            : };
      94                 :            : // mapping tables to map external xml input to intarnal box line widths
      95                 :            : 
      96                 :            : 
      97                 :            : static sal_uInt16 const aBorderWidths[] =
      98                 :            : {
      99                 :            :     DEF_LINE_WIDTH_0,
     100                 :            :     DEF_LINE_WIDTH_1,
     101                 :            :     DEF_LINE_WIDTH_2
     102                 :            : };
     103                 :            : 
     104                 :        614 : void lcl_frmitems_setXMLBorderStyle( table::BorderLine2 & rBorderLine, sal_uInt16 nStyle )
     105                 :            : {
     106                 :        614 :     sal_Int16 eStyle = -1; // None
     107         [ +  - ]:        614 :     if ( nStyle != API_LINE_NONE )
     108                 :        614 :         eStyle = sal_Int16( nStyle );
     109                 :            : 
     110                 :        614 :     rBorderLine.LineStyle = eStyle;
     111                 :        614 : }
     112                 :            : 
     113                 :            : 
     114                 :            : ///////////////////////////////////////////////////////////////////////////////
     115                 :            : //
     116                 :            : // class XMLEscapementPropHdl
     117                 :            : //
     118                 :            : 
     119                 :       3071 : XMLBorderWidthHdl::~XMLBorderWidthHdl()
     120                 :            : {
     121                 :            :     // nothing to do
     122         [ -  + ]:       6142 : }
     123                 :            : 
     124                 :         36 : sal_Bool XMLBorderWidthHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
     125                 :            : {
     126         [ +  - ]:         36 :     SvXMLTokenEnumerator aTokenEnum( rStrImpValue );
     127                 :            : 
     128                 :            :     sal_Int32 nInWidth, nDistance, nOutWidth;
     129                 :            : 
     130                 :         36 :     OUString aToken;
     131 [ -  + ][ +  - ]:         36 :     if( !aTokenEnum.getNextToken( aToken ) )
     132                 :          0 :         return sal_False;
     133                 :            : 
     134 [ +  - ][ -  + ]:         36 :     if (!rUnitConverter.convertMeasureToCore( nInWidth, aToken, 0, 500 ))
     135                 :          0 :         return sal_False;
     136                 :            : 
     137 [ +  - ][ -  + ]:         36 :     if( !aTokenEnum.getNextToken( aToken ) )
     138                 :          0 :         return sal_False;
     139                 :            : 
     140 [ +  - ][ -  + ]:         36 :     if (!rUnitConverter.convertMeasureToCore( nDistance, aToken, 0, 500 ))
     141                 :          0 :         return sal_False;
     142                 :            : 
     143 [ +  - ][ -  + ]:         36 :     if( !aTokenEnum.getNextToken( aToken ) )
     144                 :          0 :         return sal_False;
     145                 :            : 
     146 [ +  - ][ -  + ]:         36 :     if (!rUnitConverter.convertMeasureToCore( nOutWidth, aToken, 0, 500 ))
     147                 :          0 :         return sal_False;
     148                 :            : 
     149                 :         36 :     table::BorderLine2 aBorderLine;
     150 [ +  - ][ +  - ]:         36 :     if(!(rValue >>= aBorderLine))
     151                 :         36 :         aBorderLine.Color = 0;
     152                 :            : 
     153                 :         36 :     aBorderLine.InnerLineWidth = sal::static_int_cast< sal_Int16 >(nInWidth);
     154                 :         36 :     aBorderLine.OuterLineWidth = sal::static_int_cast< sal_Int16 >(nOutWidth);
     155                 :         36 :     aBorderLine.LineDistance   = sal::static_int_cast< sal_Int16 >(nDistance);
     156                 :            : 
     157         [ +  - ]:         36 :     rValue <<= aBorderLine;
     158                 :         36 :     return sal_True;
     159                 :            : }
     160                 :            : 
     161                 :          8 : sal_Bool XMLBorderWidthHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
     162                 :            : {
     163                 :          8 :     OUStringBuffer aOut;
     164                 :            : 
     165                 :          8 :     table::BorderLine2 aBorderLine;
     166 [ -  + ][ +  - ]:          8 :     if(!(rValue >>= aBorderLine))
     167                 :          0 :         return sal_False;
     168                 :            : 
     169                 :          8 :     bool bDouble = false;
     170         [ -  + ]:          8 :     switch ( aBorderLine.LineStyle )
     171                 :            :     {
     172                 :            :         case API_LINE_DOUBLE:
     173                 :            :         case API_LINE_THINTHICK_SMALLGAP:
     174                 :            :         case API_LINE_THINTHICK_MEDIUMGAP:
     175                 :            :         case API_LINE_THINTHICK_LARGEGAP:
     176                 :            :         case API_LINE_THICKTHIN_SMALLGAP:
     177                 :            :         case API_LINE_THICKTHIN_MEDIUMGAP:
     178                 :            :         case API_LINE_THICKTHIN_LARGEGAP:
     179                 :          0 :             bDouble = true;
     180                 :          0 :             break;
     181                 :            :         default:
     182                 :          8 :             break;
     183                 :            :     }
     184                 :            : 
     185 [ +  - ][ -  + ]:          8 :     if( ( aBorderLine.LineDistance == 0 && aBorderLine.InnerLineWidth == 0 ) || !bDouble )
                 [ #  # ]
     186                 :          8 :         return sal_False;
     187                 :            : 
     188         [ #  # ]:          0 :     rUnitConverter.convertMeasureToXML( aOut, aBorderLine.InnerLineWidth );
     189         [ #  # ]:          0 :     aOut.append( sal_Unicode( ' ' ) );
     190         [ #  # ]:          0 :     rUnitConverter.convertMeasureToXML( aOut, aBorderLine.LineDistance );
     191         [ #  # ]:          0 :     aOut.append( sal_Unicode( ' ' ) );
     192         [ #  # ]:          0 :     rUnitConverter.convertMeasureToXML( aOut, aBorderLine.OuterLineWidth );
     193                 :            : 
     194         [ #  # ]:          0 :     rStrExpValue = aOut.makeStringAndClear();
     195                 :          8 :     return sal_True;
     196                 :            : }
     197                 :            : 
     198                 :            : ///////////////////////////////////////////////////////////////////////////////
     199                 :            : //
     200                 :            : // class XMLEscapementHeightPropHdl
     201                 :            : //
     202                 :            : 
     203                 :       3071 : XMLBorderHdl::~XMLBorderHdl()
     204                 :            : {
     205                 :            :     // nothing to do
     206         [ -  + ]:       6142 : }
     207                 :            : 
     208                 :        916 : sal_Bool XMLBorderHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
     209                 :            : {
     210                 :        916 :     OUString aToken;
     211         [ +  - ]:        916 :     SvXMLTokenEnumerator aTokens( rStrImpValue );
     212                 :            : 
     213                 :        916 :     sal_Bool bHasStyle = sal_False;
     214                 :        916 :     sal_Bool bHasWidth = sal_False;
     215                 :        916 :     sal_Bool bHasColor = sal_False;
     216                 :            : 
     217                 :        916 :     sal_uInt16 nStyle = USHRT_MAX;
     218                 :        916 :     sal_uInt16 nWidth = 0;
     219                 :        916 :     sal_uInt16 nNamedWidth = USHRT_MAX;
     220                 :        916 :     sal_Int32 nColor = 0;
     221                 :            : 
     222                 :            :     sal_Int32 nTemp;
     223 [ +  - ][ +  + ]:       3060 :     while( aTokens.getNextToken( aToken ) && !aToken.isEmpty() )
         [ +  - ][ +  + ]
     224                 :            :     {
     225 [ +  + ][ -  + ]:       3060 :         if( !bHasWidth &&
                 [ -  + ]
     226                 :            :             rUnitConverter.convertEnum( nNamedWidth, aToken,
     227         [ +  - ]:        916 :                                         pXML_NamedBorderWidths ) )
     228                 :            :         {
     229                 :          0 :             bHasWidth = sal_True;
     230                 :            :         }
     231 [ +  + ][ +  + ]:       3674 :         else if( !bHasStyle &&
                 [ +  + ]
     232                 :            :                  rUnitConverter.convertEnum( nStyle, aToken,
     233         [ +  - ]:       1530 :                                               pXML_BorderStyles ) )
     234                 :            :         {
     235                 :        916 :             bHasStyle = sal_True;
     236                 :            :         }
     237 [ +  - ][ +  - ]:       1228 :         else if (!bHasColor && ::sax::Converter::convertColor(nColor, aToken))
         [ +  + ][ +  + ]
     238                 :            :         {
     239                 :        614 :             bHasColor = sal_True;
     240                 :            :         }
     241 [ +  - ][ +  - ]:       1228 :         else if( !bHasWidth &&
                 [ +  - ]
     242                 :            :                  rUnitConverter.convertMeasureToCore( nTemp, aToken, 0,
     243         [ +  - ]:        614 :                                                  USHRT_MAX ) )
     244                 :            :         {
     245                 :        614 :             nWidth = (sal_uInt16)nTemp;
     246                 :        614 :             bHasWidth = sal_True;
     247                 :            :         }
     248                 :            :         else
     249                 :            :         {
     250                 :            :             // missformed
     251                 :          0 :             return sal_False;
     252                 :            :         }
     253                 :            :     }
     254                 :            : 
     255                 :            :     // if there is no style or a different style than none but no width,
     256                 :            :        // then the declaration is not valid.
     257 [ +  - ][ +  + ]:        916 :     if( !bHasStyle || (API_LINE_NONE != nStyle && !bHasWidth) )
                 [ -  + ]
     258                 :          0 :         return sal_False;
     259                 :            : 
     260                 :        916 :     table::BorderLine2 aBorderLine;
     261 [ +  - ][ +  - ]:        916 :     if(!(rValue >>= aBorderLine))
     262                 :            :     {
     263                 :        916 :         aBorderLine.Color = 0;
     264                 :        916 :         aBorderLine.InnerLineWidth = 0;
     265                 :        916 :         aBorderLine.OuterLineWidth = 0;
     266                 :        916 :         aBorderLine.LineDistance   = 0;
     267                 :        916 :         aBorderLine.LineWidth      = 0;
     268                 :            :     }
     269                 :            : 
     270                 :            :     // first of all, delete an empty line
     271 [ +  - ][ +  + ]:        916 :     if( (bHasStyle && API_LINE_NONE == nStyle) ||
         [ +  - ][ +  - ]
                 [ -  + ]
     272                 :            :         (bHasWidth && USHRT_MAX == nNamedWidth && 0 == nWidth) )
     273                 :            :     {
     274                 :        302 :         aBorderLine.InnerLineWidth = 0;
     275                 :        302 :         aBorderLine.OuterLineWidth = 0;
     276                 :        302 :         aBorderLine.LineDistance   = 0;
     277                 :        302 :         aBorderLine.LineWidth = 0;
     278                 :            :     }
     279         [ +  - ]:        614 :     else if( bHasWidth )
     280                 :            :     {
     281         [ -  + ]:        614 :         if( USHRT_MAX != nNamedWidth )
     282                 :            :         {
     283                 :          0 :             aBorderLine.LineWidth = aBorderWidths[nNamedWidth];
     284                 :            :         }
     285                 :            :         else
     286                 :            :         {
     287                 :        614 :             aBorderLine.LineWidth = nWidth;
     288                 :        614 :             lcl_frmitems_setXMLBorderStyle( aBorderLine, nStyle );
     289                 :            :         }
     290                 :            :     }
     291                 :            :     else
     292                 :            :     {
     293                 :          0 :         aBorderLine.LineWidth = 0;
     294                 :          0 :         lcl_frmitems_setXMLBorderStyle( aBorderLine, nStyle );
     295                 :            :     }
     296                 :            : 
     297                 :            :     // set color
     298         [ +  + ]:        916 :     if( bHasColor )
     299                 :            :     {
     300                 :        614 :         aBorderLine.Color = nColor;
     301                 :            :     }
     302                 :            : 
     303         [ +  - ]:        916 :     rValue <<= aBorderLine;
     304                 :        916 :     return sal_True;
     305                 :            : }
     306                 :            : 
     307                 :          8 : sal_Bool XMLBorderHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& /* rUnitConverter */ ) const
     308                 :            : {
     309                 :          8 :     OUStringBuffer aOut;
     310                 :            : 
     311                 :          8 :     table::BorderLine2 aBorderLine;
     312 [ -  + ][ +  - ]:          8 :     if(!(rValue >>= aBorderLine))
     313                 :          0 :         return sal_False;
     314                 :            : 
     315                 :          8 :     sal_Int32 nWidth = aBorderLine.LineWidth;
     316                 :            : 
     317         [ -  + ]:          8 :     if( nWidth == 0 )
     318                 :            :     {
     319 [ #  # ][ #  # ]:          0 :         aOut.append( GetXMLToken( XML_NONE ) );
     320                 :            :     }
     321                 :            :     else
     322                 :            :     {
     323                 :            :         ::sax::Converter::convertMeasure( aOut, nWidth,
     324         [ +  - ]:          8 :                util::MeasureUnit::MM_100TH, util::MeasureUnit::POINT);
     325                 :            : 
     326         [ +  - ]:          8 :         aOut.append( sal_Unicode( ' ' ) );
     327                 :            : 
     328                 :          8 :         XMLTokenEnum eStyleToken = XML_SOLID;
     329   [ -  -  -  -  :          8 :         switch ( aBorderLine.LineStyle )
             -  -  -  + ]
     330                 :            :         {
     331                 :            :             case API_LINE_DASHED:
     332                 :          0 :                 eStyleToken = XML_DASHED;
     333                 :          0 :                 break;
     334                 :            :             case API_LINE_DOTTED:
     335                 :          0 :                 eStyleToken = XML_DOTTED;
     336                 :          0 :                 break;
     337                 :            :             case API_LINE_DOUBLE:
     338                 :            :             case API_LINE_THINTHICK_SMALLGAP:
     339                 :            :             case API_LINE_THINTHICK_MEDIUMGAP:
     340                 :            :             case API_LINE_THINTHICK_LARGEGAP:
     341                 :            :             case API_LINE_THICKTHIN_SMALLGAP:
     342                 :            :             case API_LINE_THICKTHIN_MEDIUMGAP:
     343                 :            :             case API_LINE_THICKTHIN_LARGEGAP:
     344                 :          0 :                 eStyleToken = XML_DOUBLE;
     345                 :          0 :                 break;
     346                 :            :             case API_LINE_EMBOSSED:
     347                 :          0 :                 eStyleToken = XML_RIDGE;
     348                 :          0 :                 break;
     349                 :            :             case API_LINE_ENGRAVED:
     350                 :          0 :                 eStyleToken = XML_GROOVE;
     351                 :          0 :                 break;
     352                 :            :             case API_LINE_OUTSET:
     353                 :          0 :                 eStyleToken = XML_OUTSET;
     354                 :          0 :                 break;
     355                 :            :             case API_LINE_INSET:
     356                 :          0 :                 eStyleToken = XML_INSET;
     357                 :          0 :                 break;
     358                 :            :             case API_LINE_SOLID:
     359                 :            :             default:
     360                 :          8 :                 break;
     361                 :            :         }
     362 [ +  - ][ +  - ]:          8 :         aOut.append( GetXMLToken( eStyleToken ) );
     363                 :            : 
     364         [ +  - ]:          8 :         aOut.append( sal_Unicode( ' ' ) );
     365                 :            : 
     366         [ +  - ]:          8 :         ::sax::Converter::convertColor( aOut, aBorderLine.Color );
     367                 :            :     }
     368                 :            : 
     369         [ +  - ]:          8 :     rStrExpValue = aOut.makeStringAndClear();
     370                 :            : 
     371                 :          8 :     return sal_True;
     372                 :            : }
     373                 :            : 
     374                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10