LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLLineNumberingExport.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 60 72 83.3 %
Date: 2015-06-13 12:38:46 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          72 : 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          72 : ,   rExport(rExp)
      53             : {
      54          72 : }
      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          72 : void XMLLineNumberingExport::Export()
      68             : {
      69             :     // export element if we have line numbering info
      70          72 :     Reference<XLineNumberingProperties> xSupplier(rExport.GetModel(),
      71          72 :                                                   UNO_QUERY);
      72          72 :     if (xSupplier.is())
      73             :     {
      74             :         Reference<XPropertySet> xLineNumbering =
      75          72 :             xSupplier->getLineNumberingProperties();
      76             : 
      77          72 :         if (xLineNumbering.is())
      78             :         {
      79          72 :             Any aAny;
      80             : 
      81             :             // char style
      82          72 :             aAny = xLineNumbering->getPropertyValue(sCharStyleName);
      83         144 :             OUString sTmp;
      84          72 :             aAny >>= sTmp;
      85          72 :             if (!sTmp.isEmpty())
      86             :             {
      87             :                 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME,
      88           0 :                                      rExport.EncodeStyleName( sTmp ));
      89             :             }
      90             : 
      91             :             // enable
      92          72 :             aAny = xLineNumbering->getPropertyValue(sIsOn);
      93          72 :             if (! *static_cast<sal_Bool const *>(aAny.getValue()))
      94             :             {
      95             :                 rExport.AddAttribute(XML_NAMESPACE_TEXT,
      96          72 :                                      XML_NUMBER_LINES, XML_FALSE);
      97             :             }
      98             : 
      99             :             // count empty lines
     100          72 :             aAny = xLineNumbering->getPropertyValue(sCountEmptyLines);
     101          72 :             if (! *static_cast<sal_Bool const *>(aAny.getValue()))
     102             :             {
     103             :                 rExport.AddAttribute(XML_NAMESPACE_TEXT,
     104           0 :                                      XML_COUNT_EMPTY_LINES, XML_FALSE);
     105             :             }
     106             : 
     107             :             // count in frames
     108          72 :             aAny = xLineNumbering->getPropertyValue(sCountLinesInFrames);
     109          72 :             if (*static_cast<sal_Bool const *>(aAny.getValue()))
     110             :             {
     111             :                 rExport.AddAttribute(XML_NAMESPACE_TEXT,
     112           0 :                                      XML_COUNT_IN_TEXT_BOXES, XML_TRUE);
     113             :             }
     114             : 
     115             :             // restart numbering
     116          72 :             aAny = xLineNumbering->getPropertyValue(sRestartAtEachPage);
     117          72 :             if (*static_cast<sal_Bool const *>(aAny.getValue()))
     118             :             {
     119             :                 rExport.AddAttribute(XML_NAMESPACE_TEXT,
     120           0 :                                      XML_RESTART_ON_PAGE, XML_TRUE);
     121             :             }
     122             : 
     123             :             // Distance
     124          72 :             aAny = xLineNumbering->getPropertyValue(sDistance);
     125          72 :             sal_Int32 nLength = 0;
     126          72 :             aAny >>= nLength;
     127          72 :             if (nLength != 0)
     128             :             {
     129          72 :                 OUStringBuffer sBuf;
     130          72 :                 rExport.GetMM100UnitConverter().convertMeasureToXML(
     131         144 :                         sBuf, nLength);
     132             :                 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_OFFSET,
     133          72 :                                      sBuf.makeStringAndClear());
     134             :             }
     135             : 
     136             :             // NumeringType
     137         144 :             OUStringBuffer sNumPosBuf;
     138          72 :             aAny = xLineNumbering->getPropertyValue(sNumberingType);
     139          72 :             sal_Int16 nFormat = 0;
     140          72 :             aAny >>= nFormat;
     141          72 :             rExport.GetMM100UnitConverter().convertNumFormat( sNumPosBuf, nFormat );
     142             :             rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
     143          72 :                                  sNumPosBuf.makeStringAndClear());
     144          72 :             SvXMLUnitConverter::convertNumLetterSync( sNumPosBuf, nFormat );
     145          72 :             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          72 :             aAny = xLineNumbering->getPropertyValue(sNumberPosition);
     154          72 :             sal_Int16 nPosition = 0;
     155          72 :             aAny >>= nPosition;
     156          72 :             if (SvXMLUnitConverter::convertEnum(sNumPosBuf, nPosition,
     157          72 :                                                 aLineNumberPositionMap))
     158             :             {
     159             :                 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_NUMBER_POSITION,
     160          72 :                                      sNumPosBuf.makeStringAndClear());
     161             :             }
     162             : 
     163             :             // sInterval
     164          72 :             aAny = xLineNumbering->getPropertyValue(sInterval);
     165          72 :             sal_Int16 nLineInterval = 0;
     166          72 :             aAny >>= nLineInterval;
     167         144 :             OUStringBuffer sBuf;
     168             :             ::sax::Converter::convertNumber(sBuf,
     169          72 :                                               (sal_Int32)nLineInterval);
     170             :             rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_INCREMENT,
     171          72 :                                  sBuf.makeStringAndClear());
     172             : 
     173             :             SvXMLElementExport aConfigElem(rExport, XML_NAMESPACE_TEXT,
     174             :                                            XML_LINENUMBERING_CONFIGURATION,
     175         144 :                                            true, true);
     176             : 
     177             :             // line separator
     178          72 :             aAny = xLineNumbering->getPropertyValue(sSeparatorText);
     179         144 :             OUString sSeparator;
     180          72 :             aAny >>= sSeparator;
     181          72 :             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          72 :             }
     198          72 :         }
     199             :         // else: no configuration: don't save -> default
     200          72 :     }
     201             :     // can't even get supplier: don't save -> default
     202          72 : }
     203             : 
     204             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11