LCOV - code coverage report
Current view: top level - xmloff/source/style - bordrhdl.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 139 0.0 %
Date: 2014-04-14 Functions: 0 9 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <bordrhdl.hxx>
      21             : #include <sax/tools/converter.hxx>
      22             : #include <xmloff/xmltoken.hxx>
      23             : #include <xmloff/xmluconv.hxx>
      24             : #include <rtl/ustrbuf.hxx>
      25             : #include <com/sun/star/uno/Any.hxx>
      26             : #include <com/sun/star/table/BorderLine2.hpp>
      27             : #include <com/sun/star/table/BorderLineStyle.hpp>
      28             : 
      29             : using namespace ::com::sun::star;
      30             : using namespace ::xmloff::token;
      31             : 
      32             : #define DEF_LINE_WIDTH_0        1
      33             : #define DEF_LINE_WIDTH_1        35
      34             : #define DEF_LINE_WIDTH_2        88
      35             : 
      36             : #define SVX_XML_BORDER_WIDTH_THIN 0
      37             : #define SVX_XML_BORDER_WIDTH_MIDDLE 1
      38             : #define SVX_XML_BORDER_WIDTH_THICK 2
      39             : 
      40             : SvXMLEnumMapEntry pXML_BorderStyles[] =
      41             : {
      42             :     { XML_NONE,          table::BorderLineStyle::NONE   },
      43             :     { XML_HIDDEN,        table::BorderLineStyle::NONE   },
      44             :     { XML_SOLID,         table::BorderLineStyle::SOLID  },
      45             :     { XML_DOUBLE,        table::BorderLineStyle::DOUBLE },
      46             :     { XML_DOUBLE_THIN,   table::BorderLineStyle::DOUBLE_THIN },
      47             :     { XML_DOTTED,        table::BorderLineStyle::DOTTED },
      48             :     { XML_DASHED,        table::BorderLineStyle::DASHED },
      49             :     { XML_GROOVE,        table::BorderLineStyle::ENGRAVED },
      50             :     { XML_RIDGE,         table::BorderLineStyle::EMBOSSED },
      51             :     { XML_INSET,         table::BorderLineStyle::INSET  },
      52             :     { XML_OUTSET,        table::BorderLineStyle::OUTSET },
      53             :     { XML_FINE_DASHED,   table::BorderLineStyle::FINE_DASHED },
      54             :     { XML_DASH_DOT,      table::BorderLineStyle::DASH_DOT },
      55             :     { XML_DASH_DOT_DOT,  table::BorderLineStyle::DASH_DOT_DOT },
      56             :     { XML_TOKEN_INVALID, 0 }
      57             : };
      58             : 
      59             : SvXMLEnumMapEntry pXML_NamedBorderWidths[] =
      60             : {
      61             :     { XML_THIN,             SVX_XML_BORDER_WIDTH_THIN   },
      62             :     { XML_MIDDLE,           SVX_XML_BORDER_WIDTH_MIDDLE },
      63             :     { XML_THICK,            SVX_XML_BORDER_WIDTH_THICK  },
      64             :     { XML_TOKEN_INVALID,    0 }
      65             : };
      66             : // mapping tables to map external xml input to internal box line widths
      67             : 
      68             : static sal_uInt16 const aBorderWidths[] =
      69             : {
      70             :     DEF_LINE_WIDTH_0,
      71             :     DEF_LINE_WIDTH_1,
      72             :     DEF_LINE_WIDTH_2
      73             : };
      74             : 
      75           0 : static void lcl_frmitems_setXMLBorderStyle( table::BorderLine2 & rBorderLine, sal_uInt16 nStyle )
      76             : {
      77           0 :     sal_Int16 eStyle = -1; // None
      78           0 :     if (nStyle != table::BorderLineStyle::NONE)
      79           0 :         eStyle = sal_Int16( nStyle );
      80             : 
      81           0 :     rBorderLine.LineStyle = eStyle;
      82           0 : }
      83             : 
      84             : 
      85             : // class XMLEscapementPropHdl
      86             : 
      87             : 
      88           0 : XMLBorderWidthHdl::~XMLBorderWidthHdl()
      89             : {
      90             :     // nothing to do
      91           0 : }
      92             : 
      93           0 : bool XMLBorderWidthHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
      94             : {
      95           0 :     SvXMLTokenEnumerator aTokenEnum( rStrImpValue );
      96             : 
      97             :     sal_Int32 nInWidth, nDistance, nOutWidth;
      98             : 
      99           0 :     OUString aToken;
     100           0 :     if( !aTokenEnum.getNextToken( aToken ) )
     101           0 :         return false;
     102             : 
     103           0 :     if (!rUnitConverter.convertMeasureToCore( nInWidth, aToken, 0, 500 ))
     104           0 :         return false;
     105             : 
     106           0 :     if( !aTokenEnum.getNextToken( aToken ) )
     107           0 :         return false;
     108             : 
     109           0 :     if (!rUnitConverter.convertMeasureToCore( nDistance, aToken, 0, 500 ))
     110           0 :         return false;
     111             : 
     112           0 :     if( !aTokenEnum.getNextToken( aToken ) )
     113           0 :         return false;
     114             : 
     115           0 :     if (!rUnitConverter.convertMeasureToCore( nOutWidth, aToken, 0, 500 ))
     116           0 :         return false;
     117             : 
     118           0 :     table::BorderLine2 aBorderLine;
     119           0 :     if(!(rValue >>= aBorderLine))
     120           0 :         aBorderLine.Color = 0;
     121             : 
     122           0 :     aBorderLine.InnerLineWidth = sal::static_int_cast< sal_Int16 >(nInWidth);
     123           0 :     aBorderLine.OuterLineWidth = sal::static_int_cast< sal_Int16 >(nOutWidth);
     124           0 :     aBorderLine.LineDistance   = sal::static_int_cast< sal_Int16 >(nDistance);
     125             : 
     126           0 :     rValue <<= aBorderLine;
     127           0 :     return true;
     128             : }
     129             : 
     130           0 : bool XMLBorderWidthHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
     131             : {
     132           0 :     OUStringBuffer aOut;
     133             : 
     134           0 :     table::BorderLine2 aBorderLine;
     135           0 :     if(!(rValue >>= aBorderLine))
     136           0 :         return false;
     137             : 
     138           0 :     bool bDouble = false;
     139           0 :     switch ( aBorderLine.LineStyle )
     140             :     {
     141             :         case table::BorderLineStyle::DOUBLE:
     142             :         case table::BorderLineStyle::DOUBLE_THIN:
     143             :         case table::BorderLineStyle::THINTHICK_SMALLGAP:
     144             :         case table::BorderLineStyle::THINTHICK_MEDIUMGAP:
     145             :         case table::BorderLineStyle::THINTHICK_LARGEGAP:
     146             :         case table::BorderLineStyle::THICKTHIN_SMALLGAP:
     147             :         case table::BorderLineStyle::THICKTHIN_MEDIUMGAP:
     148             :         case table::BorderLineStyle::THICKTHIN_LARGEGAP:
     149           0 :             bDouble = true;
     150           0 :             break;
     151             :         default:
     152           0 :             break;
     153             :     }
     154             : 
     155           0 :     if( ( aBorderLine.LineDistance == 0 && aBorderLine.InnerLineWidth == 0 ) || !bDouble )
     156           0 :         return false;
     157             : 
     158           0 :     rUnitConverter.convertMeasureToXML( aOut, aBorderLine.InnerLineWidth );
     159           0 :     aOut.append( ' ' );
     160           0 :     rUnitConverter.convertMeasureToXML( aOut, aBorderLine.LineDistance );
     161           0 :     aOut.append( ' ' );
     162           0 :     rUnitConverter.convertMeasureToXML( aOut, aBorderLine.OuterLineWidth );
     163             : 
     164           0 :     rStrExpValue = aOut.makeStringAndClear();
     165           0 :     return true;
     166             : }
     167             : 
     168             : 
     169             : // class XMLEscapementHeightPropHdl
     170             : 
     171             : 
     172           0 : XMLBorderHdl::~XMLBorderHdl()
     173             : {
     174             :     // nothing to do
     175           0 : }
     176             : 
     177           0 : bool XMLBorderHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
     178             : {
     179           0 :     OUString aToken;
     180           0 :     SvXMLTokenEnumerator aTokens( rStrImpValue );
     181             : 
     182           0 :     bool bHasStyle = false;
     183           0 :     bool bHasWidth = false;
     184           0 :     bool bHasColor = false;
     185             : 
     186           0 :     sal_uInt16 nStyle = USHRT_MAX;
     187           0 :     sal_uInt16 nWidth = 0;
     188           0 :     sal_uInt16 nNamedWidth = USHRT_MAX;
     189           0 :     sal_Int32 nColor = 0;
     190             : 
     191             :     sal_Int32 nTemp;
     192           0 :     while( aTokens.getNextToken( aToken ) && !aToken.isEmpty() )
     193             :     {
     194           0 :         if( !bHasWidth &&
     195             :             rUnitConverter.convertEnum( nNamedWidth, aToken,
     196           0 :                                         pXML_NamedBorderWidths ) )
     197             :         {
     198           0 :             bHasWidth = true;
     199             :         }
     200           0 :         else if( !bHasStyle &&
     201             :                  rUnitConverter.convertEnum( nStyle, aToken,
     202           0 :                                               pXML_BorderStyles ) )
     203             :         {
     204           0 :             bHasStyle = true;
     205             :         }
     206           0 :         else if (!bHasColor && ::sax::Converter::convertColor(nColor, aToken))
     207             :         {
     208           0 :             bHasColor = true;
     209             :         }
     210           0 :         else if( !bHasWidth &&
     211             :                  rUnitConverter.convertMeasureToCore( nTemp, aToken, 0,
     212           0 :                                                  USHRT_MAX ) )
     213             :         {
     214           0 :             nWidth = (sal_uInt16)nTemp;
     215           0 :             bHasWidth = true;
     216             :         }
     217             :         else
     218             :         {
     219             :             // missformed
     220           0 :             return false;
     221             :         }
     222             :     }
     223             : 
     224             :     // if there is no style or a different style than none but no width,
     225             :     // then the declaration is not valid.
     226           0 :     if (!bHasStyle || (table::BorderLineStyle::NONE != nStyle && !bHasWidth))
     227           0 :         return false;
     228             : 
     229           0 :     table::BorderLine2 aBorderLine;
     230           0 :     if(!(rValue >>= aBorderLine))
     231             :     {
     232           0 :         aBorderLine.Color = 0;
     233           0 :         aBorderLine.InnerLineWidth = 0;
     234           0 :         aBorderLine.OuterLineWidth = 0;
     235           0 :         aBorderLine.LineDistance   = 0;
     236           0 :         aBorderLine.LineWidth      = 0;
     237             :     }
     238             : 
     239             :     // first of all, delete an empty line
     240           0 :     if (table::BorderLineStyle::NONE == nStyle ||
     241           0 :         (bHasWidth && USHRT_MAX == nNamedWidth && 0 == nWidth) )
     242             :     {
     243           0 :         aBorderLine.InnerLineWidth = 0;
     244           0 :         aBorderLine.OuterLineWidth = 0;
     245           0 :         aBorderLine.LineDistance   = 0;
     246           0 :         aBorderLine.LineWidth = 0;
     247             :     }
     248             :     else
     249             :     {
     250           0 :         if( USHRT_MAX != nNamedWidth )
     251             :         {
     252           0 :             aBorderLine.LineWidth = aBorderWidths[nNamedWidth];
     253             :         }
     254             :         else
     255             :         {
     256           0 :             aBorderLine.LineWidth = nWidth;
     257           0 :             lcl_frmitems_setXMLBorderStyle( aBorderLine, nStyle );
     258             :         }
     259             :     }
     260             : 
     261             :     // set color
     262           0 :     if( bHasColor )
     263             :     {
     264           0 :         aBorderLine.Color = nColor;
     265             :     }
     266             : 
     267           0 :     rValue <<= aBorderLine;
     268           0 :     return true;
     269             : }
     270             : 
     271           0 : bool XMLBorderHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& /* rUnitConverter */ ) const
     272             : {
     273           0 :     OUStringBuffer aOut;
     274             : 
     275           0 :     table::BorderLine2 aBorderLine;
     276           0 :     if(!(rValue >>= aBorderLine))
     277           0 :         return false;
     278             : 
     279           0 :     sal_Int32 nWidth = aBorderLine.LineWidth;
     280             : 
     281           0 :     if( nWidth == 0 )
     282             :     {
     283           0 :         aOut.append( GetXMLToken( XML_NONE ) );
     284             :     }
     285             :     else
     286             :     {
     287             :         ::sax::Converter::convertMeasure( aOut, nWidth,
     288           0 :                util::MeasureUnit::MM_100TH, util::MeasureUnit::POINT);
     289             : 
     290           0 :         aOut.append( ' ' );
     291             : 
     292           0 :         XMLTokenEnum eStyleToken = XML_SOLID;
     293           0 :         switch ( aBorderLine.LineStyle )
     294             :         {
     295             :             case table::BorderLineStyle::DASHED:
     296           0 :                 eStyleToken = XML_DASHED;
     297           0 :                 break;
     298             :             case table::BorderLineStyle::DOTTED:
     299           0 :                 eStyleToken = XML_DOTTED;
     300           0 :                 break;
     301             :             case table::BorderLineStyle::DOUBLE:
     302             :             case table::BorderLineStyle::THINTHICK_SMALLGAP:
     303             :             case table::BorderLineStyle::THINTHICK_MEDIUMGAP:
     304             :             case table::BorderLineStyle::THINTHICK_LARGEGAP:
     305             :             case table::BorderLineStyle::THICKTHIN_SMALLGAP:
     306             :             case table::BorderLineStyle::THICKTHIN_MEDIUMGAP:
     307             :             case table::BorderLineStyle::THICKTHIN_LARGEGAP:
     308           0 :                 eStyleToken = XML_DOUBLE;
     309           0 :                 break;
     310             :             case table::BorderLineStyle::EMBOSSED:
     311           0 :                 eStyleToken = XML_RIDGE;
     312           0 :                 break;
     313             :             case table::BorderLineStyle::ENGRAVED:
     314           0 :                 eStyleToken = XML_GROOVE;
     315           0 :                 break;
     316             :             case table::BorderLineStyle::OUTSET:
     317           0 :                 eStyleToken = XML_OUTSET;
     318           0 :                 break;
     319             :             case table::BorderLineStyle::INSET:
     320           0 :                 eStyleToken = XML_INSET;
     321           0 :                 break;
     322             :             case table::BorderLineStyle::FINE_DASHED:
     323           0 :                 eStyleToken = XML_FINE_DASHED;
     324           0 :                 break;
     325             :             case table::BorderLineStyle::DASH_DOT:
     326           0 :                 eStyleToken = XML_DASH_DOT;
     327           0 :                 break;
     328             :             case table::BorderLineStyle::DASH_DOT_DOT:
     329           0 :                 eStyleToken = XML_DASH_DOT_DOT;
     330           0 :                 break;
     331             :             case table::BorderLineStyle::DOUBLE_THIN:
     332           0 :                 eStyleToken = XML_DOUBLE_THIN;
     333           0 :                 break;
     334             :             case table::BorderLineStyle::SOLID:
     335             :             default:
     336           0 :                 break;
     337             :         }
     338           0 :         aOut.append( GetXMLToken( eStyleToken ) );
     339             : 
     340           0 :         aOut.append( ' ' );
     341             : 
     342           0 :         ::sax::Converter::convertColor( aOut, aBorderLine.Color );
     343             :     }
     344             : 
     345           0 :     rStrExpValue = aOut.makeStringAndClear();
     346             : 
     347           0 :     return true;
     348             : }
     349             : 
     350             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10