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

Generated by: LCOV version 1.10