LCOV - code coverage report
Current view: top level - sw/source/filter/xml - xmlithlp.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 58 88 65.9 %
Date: 2014-04-11 Functions: 4 6 66.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             : 
      20             : #include "xmlithlp.hxx"
      21             : #include "hintids.hxx"
      22             : #include "unomid.h"
      23             : #include <sax/tools/converter.hxx>
      24             : #include <svx/unomid.hxx>
      25             : #include <editeng/lrspitem.hxx>
      26             : #include <editeng/ulspitem.hxx>
      27             : #include <editeng/shaditem.hxx>
      28             : #include <editeng/boxitem.hxx>
      29             : #include <editeng/formatbreakitem.hxx>
      30             : #include <editeng/keepitem.hxx>
      31             : #include <editeng/brushitem.hxx>
      32             : #include "fmtpdsc.hxx"
      33             : #include "fmtornt.hxx"
      34             : #include "fmtfsize.hxx"
      35             : 
      36             : #include "fmtlsplt.hxx"
      37             : #include <xmloff/xmluconv.hxx>
      38             : 
      39             : using ::editeng::SvxBorderLine;
      40             : using namespace ::xmloff::token;
      41             : using namespace ::com::sun::star;
      42             : 
      43             : #define API_LINE_NONE 0x7FFF
      44             : #define API_LINE_SOLID 0
      45             : #define API_LINE_DOTTED 1
      46             : #define API_LINE_DASHED 2
      47             : #define API_LINE_DOUBLE 3
      48             : #define API_LINE_EMBOSSED 10
      49             : #define API_LINE_ENGRAVED 11
      50             : #define API_LINE_OUTSET 12
      51             : #define API_LINE_INSET 13
      52             : 
      53             : #define SVX_XML_BORDER_WIDTH_THIN 0
      54             : #define SVX_XML_BORDER_WIDTH_MIDDLE 1
      55             : #define SVX_XML_BORDER_WIDTH_THICK 2
      56             : 
      57             : const struct SvXMLEnumMapEntry psXML_BorderStyles[] =
      58             : {
      59             :     { XML_NONE,       API_LINE_NONE },
      60             :     { XML_HIDDEN,     API_LINE_NONE },
      61             :     { XML_SOLID,      API_LINE_SOLID },
      62             :     { XML_DOUBLE,     API_LINE_DOUBLE },
      63             :     { XML_DOTTED,     API_LINE_DOTTED },
      64             :     { XML_DASHED,     API_LINE_DASHED },
      65             :     { XML_GROOVE,     API_LINE_ENGRAVED },
      66             :     { XML_RIDGE,      API_LINE_EMBOSSED },
      67             :     { XML_INSET,      API_LINE_INSET },
      68             :     { XML_OUTSET,     API_LINE_OUTSET },
      69             :     { XML_TOKEN_INVALID, 0 }
      70             : };
      71             : 
      72             : const struct SvXMLEnumMapEntry psXML_NamedBorderWidths[] =
      73             : {
      74             :         { XML_THIN,         SVX_XML_BORDER_WIDTH_THIN   },
      75             :         { XML_MIDDLE,   SVX_XML_BORDER_WIDTH_MIDDLE     },
      76             :         { XML_THICK,    SVX_XML_BORDER_WIDTH_THICK      },
      77             :         { XML_TOKEN_INVALID, 0 }
      78             : };
      79             : // mapping tables to map external xml input to internal box line widths
      80             : 
      81             : const sal_uInt16 aBorderWidths[] =
      82             : {
      83             :         DEF_LINE_WIDTH_0,
      84             :         DEF_LINE_WIDTH_5,
      85             :         DEF_LINE_WIDTH_1,
      86             : };
      87             : 
      88         874 : bool sw_frmitems_parseXMLBorder( const OUString& rValue,
      89             :                                       const SvXMLUnitConverter& rUnitConverter,
      90             :                                       bool& rHasStyle, sal_uInt16& rStyle,
      91             :                                       bool& rHasWidth, sal_uInt16& rWidth,
      92             :                                       sal_uInt16& rNamedWidth,
      93             :                                       bool& rHasColor, Color& rColor )
      94             : {
      95         874 :     OUString aToken;
      96         874 :     SvXMLTokenEnumerator aTokens( rValue );
      97             : 
      98         874 :     rHasStyle = false;
      99         874 :     rHasWidth = false;
     100         874 :     rHasColor = false;
     101             : 
     102         874 :     rStyle = USHRT_MAX;
     103         874 :     rWidth = 0;
     104         874 :     rNamedWidth = USHRT_MAX;
     105             : 
     106             :     sal_Int32 nTemp;
     107        4203 :     while( aTokens.getNextToken( aToken ) && !aToken.isEmpty() )
     108             :     {
     109        3324 :         if( !rHasWidth &&
     110             :             rUnitConverter.convertEnum( rNamedWidth, aToken,
     111         869 :                                         psXML_NamedBorderWidths ) )
     112             :         {
     113           0 :             rHasWidth = true;
     114             :         }
     115        4117 :         else if( !rHasStyle &&
     116             :                  rUnitConverter.convertEnum( rStyle, aToken,
     117        1662 :                                              psXML_BorderStyles ) )
     118             :         {
     119         869 :             rHasStyle = true;
     120             :         }
     121        1586 :         else if (!rHasColor && ::sax::Converter::convertColor(nTemp, aToken))
     122             :         {
     123         793 :             rColor.SetColor(nTemp);
     124         793 :             rHasColor = true;
     125             :         }
     126        1586 :         else if( !rHasWidth &&
     127         793 :              rUnitConverter.convertMeasureToCore(nTemp, aToken, 0, USHRT_MAX))
     128             :         {
     129         793 :             rWidth = (sal_uInt16)nTemp;
     130         793 :             rHasWidth = true;
     131             :         }
     132             :         else
     133             :         {
     134             :             // missformed
     135           0 :             return false;
     136             :         }
     137             :     }
     138             : 
     139         874 :     return rHasStyle || rHasWidth || rHasColor;
     140             : }
     141             : 
     142         633 : void sw_frmitems_setXMLBorderStyle( SvxBorderLine& rLine, sal_uInt16 nStyle )
     143             : {
     144         633 :     ::editeng::SvxBorderStyle eStyle = table::BorderLineStyle::NONE;
     145         633 :     if ( nStyle != API_LINE_NONE )
     146         633 :         eStyle = ::editeng::SvxBorderStyle( nStyle );
     147         633 :     rLine.SetBorderLineStyle(eStyle);
     148         633 : }
     149             : 
     150         983 : bool sw_frmitems_setXMLBorder( SvxBorderLine*& rpLine,
     151             :                                     bool bHasStyle, sal_uInt16 nStyle,
     152             :                                     bool bHasWidth, sal_uInt16 nWidth,
     153             :                                     sal_uInt16 nNamedWidth,
     154             :                                     bool bHasColor, const Color& rColor )
     155             : {
     156             :     // first of all, delete an empty line
     157         983 :     if( (bHasStyle && API_LINE_NONE == nStyle) ||
     158         702 :         (bHasWidth && USHRT_MAX == nNamedWidth && 0 == nWidth) )
     159             :     {
     160         294 :         bool bRet = 0 != rpLine;
     161         294 :         if( rpLine )
     162             :         {
     163           0 :             delete rpLine;
     164           0 :             rpLine = 0;
     165             :         }
     166             : 
     167         294 :         return bRet;
     168             :     }
     169             : 
     170             :     // if there is no line and no style and no with, there will never be a line
     171         689 :     if( !rpLine && !(bHasStyle && bHasWidth) )
     172           0 :         return false;
     173             : 
     174             :     // We now do know that there will be a line
     175         689 :     if( !rpLine )
     176         633 :         rpLine = new SvxBorderLine;
     177             : 
     178        1378 :     if( ( bHasWidth &&
     179        2011 :           (USHRT_MAX != nNamedWidth || (nWidth != rpLine->GetWidth() ) ) ) ||
     180          56 :         ( bHasStyle &&
     181           0 :           ((API_LINE_SOLID == nStyle && rpLine->GetDistance()) ||
     182          56 :             (API_LINE_DOUBLE == nStyle && !rpLine->GetDistance())) ) )
     183             :    {
     184        1255 :        bool bDouble = (bHasWidth && API_LINE_DOUBLE == nStyle ) ||
     185        1255 :            rpLine->GetDistance();
     186             : 
     187             :        // fdo#38542: for double borders, do not override the width
     188             :        // set via style:border-line-width{,-left,-right,-top,-bottom}
     189         633 :        if (!bDouble || !rpLine->GetWidth())
     190             :        {
     191             :            // The width has to be changed
     192         633 :            if (bHasWidth && USHRT_MAX != nNamedWidth)
     193             :            {
     194           0 :                if (bDouble)
     195             :                {
     196           0 :                    rpLine->SetBorderLineStyle( table::BorderLineStyle::DOUBLE );
     197             :                }
     198           0 :                rpLine->SetWidth( aBorderWidths[nNamedWidth] );
     199             :            }
     200             :            else
     201             :            {
     202         633 :                if (!bHasWidth)
     203           0 :                    nWidth = rpLine->GetScaledWidth();
     204             : 
     205         633 :                rpLine->SetWidth( nWidth );
     206             :            }
     207             :        }
     208         633 :        sw_frmitems_setXMLBorderStyle( *rpLine, nStyle );
     209             :    }
     210             : 
     211             :     // set color
     212         689 :     if( bHasColor )
     213         689 :         rpLine->SetColor( rColor );
     214             : 
     215         689 :     return true;
     216             : }
     217             : 
     218          57 : void sw_frmitems_setXMLBorder( SvxBorderLine*& rpLine,
     219             :   sal_uInt16 nWidth, sal_uInt16 nOutWidth,
     220             :   sal_uInt16 nInWidth, sal_uInt16 nDistance )
     221             : {
     222          57 :     if( !rpLine )
     223          56 :         rpLine = new SvxBorderLine;
     224             : 
     225          57 :     if( nWidth > 0 )
     226           0 :         rpLine->SetWidth( nWidth );
     227             :     else
     228             :         rpLine->GuessLinesWidths(table::BorderLineStyle::DOUBLE,
     229          57 :                 nOutWidth, nInWidth, nDistance);
     230          57 : }
     231             : 
     232             : const struct SvXMLEnumMapEntry psXML_BrushRepeat[] =
     233             : {
     234             :     { XML_BACKGROUND_REPEAT,        GPOS_TILED  },
     235             :     { XML_BACKGROUND_NO_REPEAT,     GPOS_MM     },
     236             :     { XML_BACKGROUND_STRETCH,       GPOS_AREA   },
     237             :     { XML_TOKEN_INVALID, 0 }
     238             : };
     239             : 
     240             : const struct SvXMLEnumMapEntry psXML_BrushHoriPos[] =
     241             : {
     242             :     { XML_LEFT,         GPOS_LM },
     243             :     { XML_RIGHT,        GPOS_RM },
     244             :     { XML_TOKEN_INVALID, 0 }
     245             : };
     246             : 
     247             : const struct SvXMLEnumMapEntry psXML_BrushVertPos[] =
     248             : {
     249             :     { XML_TOP,          GPOS_MT },
     250             :     { XML_BOTTOM,       GPOS_MB },
     251             :     { XML_TOKEN_INVALID, 0 }
     252             : };
     253             : 
     254           0 : void sw_frmitems_MergeXMLHoriPos( SvxGraphicPosition& ePos,
     255             :                                    SvxGraphicPosition eHori )
     256             : {
     257             :     OSL_ENSURE( GPOS_LM==eHori || GPOS_MM==eHori || GPOS_RM==eHori,
     258             :                 "sw_frmitems_MergeXMLHoriPos: vertical pos must be middle" );
     259             : 
     260           0 :     switch( ePos )
     261             :     {
     262             :     case GPOS_LT:
     263             :     case GPOS_MT:
     264             :     case GPOS_RT:
     265           0 :         ePos = GPOS_LM==eHori ? GPOS_LT : (GPOS_MM==eHori ? GPOS_MT : GPOS_RT);
     266           0 :         break;
     267             : 
     268             :     case GPOS_LM:
     269             :     case GPOS_MM:
     270             :     case GPOS_RM:
     271           0 :         ePos = eHori;
     272           0 :         break;
     273             : 
     274             :     case GPOS_LB:
     275             :     case GPOS_MB:
     276             :     case GPOS_RB:
     277           0 :         ePos = GPOS_LM==eHori ? GPOS_LB : (GPOS_MM==eHori ? GPOS_MB : GPOS_RB);
     278           0 :         break;
     279             :     default:
     280             :         ;
     281             :     }
     282           0 : }
     283             : 
     284           0 : void sw_frmitems_MergeXMLVertPos( SvxGraphicPosition& ePos,
     285             :                                      SvxGraphicPosition eVert )
     286             : {
     287             :     OSL_ENSURE( GPOS_MT==eVert || GPOS_MM==eVert || GPOS_MB==eVert,
     288             :                 "sw_frmitems_MergeXMLVertPos: horizontal pos must be middle" );
     289             : 
     290           0 :     switch( ePos )
     291             :     {
     292             :     case GPOS_LT:
     293             :     case GPOS_LM:
     294             :     case GPOS_LB:
     295           0 :         ePos = GPOS_MT==eVert ? GPOS_LT : (GPOS_MM==eVert ? GPOS_LM : GPOS_LB);
     296           0 :         ePos = eVert;
     297           0 :         break;
     298             : 
     299             :     case GPOS_MT:
     300             :     case GPOS_MM:
     301             :     case GPOS_MB:
     302           0 :         ePos = eVert;
     303           0 :         break;
     304             : 
     305             :     case GPOS_RT:
     306             :     case GPOS_RM:
     307             :     case GPOS_RB:
     308           0 :         ePos = GPOS_MT==eVert ? GPOS_RT : (GPOS_MM==eVert ? GPOS_RM : GPOS_RB);
     309           0 :         break;
     310             :     default:
     311             :         ;
     312             :     }
     313           0 : }
     314             : 
     315             : const struct SvXMLEnumMapEntry psXML_BreakType[] =
     316             : {
     317             :         { XML_AUTO,         0 },
     318             :         { XML_COLUMN,       1 },
     319             :         { XML_PAGE,         2 },
     320             :         { XML_EVEN_PAGE,    2 },
     321             :         { XML_ODD_PAGE,     2 },
     322             :         { XML_TOKEN_INVALID, 0}
     323             : };
     324             : 
     325             : const struct  SvXMLEnumMapEntry aXMLTableAlignMap[] =
     326             : {
     327             :     { XML_LEFT,             text::HoriOrientation::LEFT           },
     328             :     { XML_LEFT,             text::HoriOrientation::LEFT_AND_WIDTH },
     329             :     { XML_CENTER,           text::HoriOrientation::CENTER         },
     330             :     { XML_RIGHT,            text::HoriOrientation::RIGHT          },
     331             :     { XML_MARGINS,          text::HoriOrientation::FULL           },
     332             :     { XML_MARGINS,          text::HoriOrientation::NONE           },
     333             :     { XML_TOKEN_INVALID, 0 }
     334             : };
     335             : 
     336             : const struct  SvXMLEnumMapEntry aXMLTableVAlignMap[] =
     337             : {
     338             :     { XML_TOP,                  text::VertOrientation::TOP        },
     339             :     { XML_MIDDLE,               text::VertOrientation::CENTER     },
     340             :     { XML_BOTTOM,               text::VertOrientation::BOTTOM     },
     341             :     { XML_TOKEN_INVALID, 0 }
     342             : };
     343             : 
     344             : const struct SvXMLEnumMapEntry aXML_KeepTogetherType[] =
     345             : {
     346             :         { XML_ALWAYS,       0 },
     347             :         { XML_AUTO,         1 },
     348             :         { XML_TOKEN_INVALID, 0}
     349             : };
     350             : 
     351             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10