LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLLineNumberingExport.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 60 72 83.3 %
Date: 2014-11-03 Functions: 2 2 100.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 "XMLLineNumberingExport.hxx"
      21             : #include <com/sun/star/beans/XPropertySet.hpp>
      22             : #include <com/sun/star/text/XLineNumberingProperties.hpp>
      23             : #include <com/sun/star/style/LineNumberPosition.hpp>
      24             : #include <sax/tools/converter.hxx>
      25             : #include <xmloff/xmlexp.hxx>
      26             : #include <xmloff/xmluconv.hxx>
      27             : #include <xmloff/xmlnmspe.hxx>
      28             : #include <xmloff/xmltoken.hxx>
      29             : #include <xmloff/xmlnume.hxx>
      30             : 
      31             : 
      32             : using namespace ::com::sun::star::uno;
      33             : using namespace ::com::sun::star;
      34             : using namespace ::xmloff::token;
      35             : 
      36             : using ::com::sun::star::beans::XPropertySet;
      37             : using ::com::sun::star::text::XLineNumberingProperties;
      38             : 
      39             : 
      40          58 : XMLLineNumberingExport::XMLLineNumberingExport(SvXMLExport& rExp)
      41             : :   sCharStyleName("CharStyleName")
      42             : ,   sCountEmptyLines("CountEmptyLines")
      43             : ,   sCountLinesInFrames("CountLinesInFrames")
      44             : ,   sDistance("Distance")
      45             : ,   sInterval("Interval")
      46             : ,   sSeparatorText("SeparatorText")
      47             : ,   sNumberPosition("NumberPosition")
      48             : ,   sNumberingType("NumberingType")
      49             : ,   sIsOn("IsOn")
      50             : ,   sRestartAtEachPage("RestartAtEachPage")
      51             : ,   sSeparatorInterval("SeparatorInterval")
      52          58 : ,   rExport(rExp)
      53             : {
      54          58 : }
      55             : 
      56             : SvXMLEnumMapEntry const aLineNumberPositionMap[] =
      57             : {
      58             :     { XML_LEFT,     style::LineNumberPosition::LEFT },
      59             :     { XML_RIGHT,    style::LineNumberPosition::RIGHT },
      60             :     { XML_INSIDE,   style::LineNumberPosition::INSIDE },
      61             :     { XML_OUTSIDE,  style::LineNumberPosition::OUTSIDE },
      62             :     { XML_TOKEN_INVALID, 0 }
      63             : };
      64             : 
      65             : 
      66             : 
      67          58 : void XMLLineNumberingExport::Export()
      68             : {
      69             :     // export element if we have line numbering info
      70          58 :     Reference<XLineNumberingProperties> xSupplier(rExport.GetModel(),
      71          58 :                                                   UNO_QUERY);
      72          58 :     if (xSupplier.is())
      73             :     {
      74             :         Reference<XPropertySet> xLineNumbering =
      75          58 :             xSupplier->getLineNumberingProperties();
      76             : 
      77          58 :         if (xLineNumbering.is())
      78             :         {
      79          58 :             Any aAny;
      80             : 
      81             :             // char style
      82          58 :             aAny = xLineNumbering->getPropertyValue(sCharStyleName);
      83         116 :             OUString sTmp;
      84          58 :             aAny >>= sTmp;
      85          58 :             if (!sTmp.isEmpty())
      86             :             {
      87             :                 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME,
      88           0 :                                      rExport.EncodeStyleName( sTmp ));
      89             :             }
      90             : 
      91             :             // enable
      92          58 :             aAny = xLineNumbering->getPropertyValue(sIsOn);
      93          58 :             if (! *(sal_Bool*)aAny.getValue())
      94             :             {
      95             :                 rExport.AddAttribute(XML_NAMESPACE_TEXT,
      96          58 :                                      XML_NUMBER_LINES, XML_FALSE);
      97             :             }
      98             : 
      99             :             // count empty lines
     100          58 :             aAny = xLineNumbering->getPropertyValue(sCountEmptyLines);
     101          58 :             if (! *(sal_Bool*)aAny.getValue())
     102             :             {
     103             :                 rExport.AddAttribute(XML_NAMESPACE_TEXT,
     104           0 :                                      XML_COUNT_EMPTY_LINES, XML_FALSE);
     105             :             }
     106             : 
     107             :             // count in frames
     108          58 :             aAny = xLineNumbering->getPropertyValue(sCountLinesInFrames);
     109          58 :             if (*(sal_Bool*)aAny.getValue())
     110             :             {
     111             :                 rExport.AddAttribute(XML_NAMESPACE_TEXT,
     112           0 :                                      XML_COUNT_IN_TEXT_BOXES, XML_TRUE);
     113             :             }
     114             : 
     115             :             // restart numbering
     116          58 :             aAny = xLineNumbering->getPropertyValue(sRestartAtEachPage);
     117          58 :             if (*(sal_Bool*)aAny.getValue())
     118             :             {
     119             :                 rExport.AddAttribute(XML_NAMESPACE_TEXT,
     120           0 :                                      XML_RESTART_ON_PAGE, XML_TRUE);
     121             :             }
     122             : 
     123             :             // Distance
     124          58 :             aAny = xLineNumbering->getPropertyValue(sDistance);
     125          58 :             sal_Int32 nLength = 0;
     126          58 :             aAny >>= nLength;
     127          58 :             if (nLength != 0)
     128             :             {
     129          58 :                 OUStringBuffer sBuf;
     130          58 :                 rExport.GetMM100UnitConverter().convertMeasureToXML(
     131         116 :                         sBuf, nLength);
     132             :                 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_OFFSET,
     133          58 :                                      sBuf.makeStringAndClear());
     134             :             }
     135             : 
     136             :             // NumeringType
     137         116 :             OUStringBuffer sNumPosBuf;
     138          58 :             aAny = xLineNumbering->getPropertyValue(sNumberingType);
     139          58 :             sal_Int16 nFormat = 0;
     140          58 :             aAny >>= nFormat;
     141          58 :             rExport.GetMM100UnitConverter().convertNumFormat( sNumPosBuf, nFormat );
     142             :             rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
     143          58 :                                  sNumPosBuf.makeStringAndClear());
     144          58 :             rExport.GetMM100UnitConverter().convertNumLetterSync( sNumPosBuf, nFormat );
     145          58 :             if( !sNumPosBuf.isEmpty() )
     146             :             {
     147             :                 rExport.AddAttribute(XML_NAMESPACE_STYLE,
     148             :                                      XML_NUM_LETTER_SYNC,
     149           0 :                                      sNumPosBuf.makeStringAndClear() );
     150             :             }
     151             : 
     152             :             // number position
     153          58 :             aAny = xLineNumbering->getPropertyValue(sNumberPosition);
     154          58 :             sal_Int16 nPosition = 0;
     155          58 :             aAny >>= nPosition;
     156          58 :             if (SvXMLUnitConverter::convertEnum(sNumPosBuf, nPosition,
     157          58 :                                                 aLineNumberPositionMap))
     158             :             {
     159             :                 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_NUMBER_POSITION,
     160          58 :                                      sNumPosBuf.makeStringAndClear());
     161             :             }
     162             : 
     163             :             // sInterval
     164          58 :             aAny = xLineNumbering->getPropertyValue(sInterval);
     165          58 :             sal_Int16 nLineInterval = 0;
     166          58 :             aAny >>= nLineInterval;
     167         116 :             OUStringBuffer sBuf;
     168             :             ::sax::Converter::convertNumber(sBuf,
     169          58 :                                               (sal_Int32)nLineInterval);
     170             :             rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_INCREMENT,
     171          58 :                                  sBuf.makeStringAndClear());
     172             : 
     173             :             SvXMLElementExport aConfigElem(rExport, XML_NAMESPACE_TEXT,
     174             :                                            XML_LINENUMBERING_CONFIGURATION,
     175         116 :                                            true, true);
     176             : 
     177             :             // line separator
     178          58 :             aAny = xLineNumbering->getPropertyValue(sSeparatorText);
     179         116 :             OUString sSeparator;
     180          58 :             aAny >>= sSeparator;
     181          58 :             if (!sSeparator.isEmpty())
     182             :             {
     183             : 
     184             :                 // SeparatorInterval
     185           0 :                 aAny = xLineNumbering->getPropertyValue(sSeparatorInterval);
     186           0 :                 sal_Int16 nLineDistance = 0;
     187           0 :                 aAny >>= nLineDistance;
     188             :                 ::sax::Converter::convertNumber(sBuf,
     189           0 :                                                   (sal_Int32)nLineDistance);
     190             :                 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_INCREMENT,
     191           0 :                                      sBuf.makeStringAndClear());
     192             : 
     193             :                 SvXMLElementExport aSeparatorElem(rExport, XML_NAMESPACE_TEXT,
     194             :                                                   XML_LINENUMBERING_SEPARATOR,
     195           0 :                                                   true, false);
     196           0 :                 rExport.Characters(sSeparator);
     197          58 :             }
     198          58 :         }
     199             :         // else: no configuration: don't save -> default
     200          58 :     }
     201             :     // can't even get supplier: don't save -> default
     202          58 : }
     203             : 
     204             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10