1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_xmloff.hxx" 26 #include "XMLLineNumberingExport.hxx" 27 #include "com/sun/star/beans/XPropertySet.hpp" 28 #include "com/sun/star/text/XLineNumberingProperties.hpp" 29 #include <com/sun/star/style/LineNumberPosition.hpp> 30 #include <xmloff/xmlexp.hxx> 31 #include <xmloff/xmluconv.hxx> 32 #include "xmloff/xmlnmspe.hxx" 33 #include <xmloff/xmltoken.hxx> 34 #include <xmloff/xmlnume.hxx> 35 36 37 using namespace ::com::sun::star::uno; 38 using namespace ::com::sun::star; 39 using namespace ::xmloff::token; 40 41 using ::rtl::OUString; 42 using ::rtl::OUStringBuffer; 43 using ::com::sun::star::beans::XPropertySet; 44 using ::com::sun::star::text::XLineNumberingProperties; 45 46 47 XMLLineNumberingExport::XMLLineNumberingExport(SvXMLExport& rExp) 48 : sCharStyleName(RTL_CONSTASCII_USTRINGPARAM("CharStyleName")) 49 , sCountEmptyLines(RTL_CONSTASCII_USTRINGPARAM("CountEmptyLines")) 50 , sCountLinesInFrames(RTL_CONSTASCII_USTRINGPARAM("CountLinesInFrames")) 51 , sDistance(RTL_CONSTASCII_USTRINGPARAM("Distance")) 52 , sInterval(RTL_CONSTASCII_USTRINGPARAM("Interval")) 53 , sSeparatorText(RTL_CONSTASCII_USTRINGPARAM("SeparatorText")) 54 , sNumberPosition(RTL_CONSTASCII_USTRINGPARAM("NumberPosition")) 55 , sNumberingType(RTL_CONSTASCII_USTRINGPARAM("NumberingType")) 56 , sIsOn(RTL_CONSTASCII_USTRINGPARAM("IsOn")) 57 , sRestartAtEachPage(RTL_CONSTASCII_USTRINGPARAM("RestartAtEachPage")) 58 , sSeparatorInterval(RTL_CONSTASCII_USTRINGPARAM("SeparatorInterval")) 59 , rExport(rExp) 60 { 61 } 62 63 SvXMLEnumMapEntry __READONLY_DATA aLineNumberPositionMap[] = 64 { 65 { XML_LEFT, style::LineNumberPosition::LEFT }, 66 { XML_RIGHT, style::LineNumberPosition::RIGHT }, 67 { XML_INSIDE, style::LineNumberPosition::INSIDE }, 68 { XML_OUTSIDE, style::LineNumberPosition::OUTSIDE }, 69 { XML_TOKEN_INVALID, 0 } 70 }; 71 72 73 74 void XMLLineNumberingExport::Export() 75 { 76 // export element if we have line numbering info 77 Reference<XLineNumberingProperties> xSupplier(rExport.GetModel(), 78 UNO_QUERY); 79 if (xSupplier.is()) 80 { 81 Reference<XPropertySet> xLineNumbering = 82 xSupplier->getLineNumberingProperties(); 83 84 if (xLineNumbering.is()) 85 { 86 Any aAny; 87 88 // char style 89 aAny = xLineNumbering->getPropertyValue(sCharStyleName); 90 OUString sTmp; 91 aAny >>= sTmp; 92 if (sTmp.getLength() > 0) 93 { 94 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME, 95 rExport.EncodeStyleName( sTmp )); 96 } 97 98 // enable 99 aAny = xLineNumbering->getPropertyValue(sIsOn); 100 if (! *(sal_Bool*)aAny.getValue()) 101 { 102 rExport.AddAttribute(XML_NAMESPACE_TEXT, 103 XML_NUMBER_LINES, XML_FALSE); 104 } 105 106 // count empty lines 107 aAny = xLineNumbering->getPropertyValue(sCountEmptyLines); 108 if (! *(sal_Bool*)aAny.getValue()) 109 { 110 rExport.AddAttribute(XML_NAMESPACE_TEXT, 111 XML_COUNT_EMPTY_LINES, XML_FALSE); 112 } 113 114 // count in frames 115 aAny = xLineNumbering->getPropertyValue(sCountLinesInFrames); 116 if (*(sal_Bool*)aAny.getValue()) 117 { 118 rExport.AddAttribute(XML_NAMESPACE_TEXT, 119 XML_COUNT_IN_TEXT_BOXES, XML_TRUE); 120 } 121 122 // restart numbering 123 aAny = xLineNumbering->getPropertyValue(sRestartAtEachPage); 124 if (*(sal_Bool*)aAny.getValue()) 125 { 126 rExport.AddAttribute(XML_NAMESPACE_TEXT, 127 XML_RESTART_ON_PAGE, XML_TRUE); 128 } 129 130 // Distance 131 aAny = xLineNumbering->getPropertyValue(sDistance); 132 sal_Int32 nLength = 0; 133 aAny >>= nLength; 134 if (nLength != 0) 135 { 136 OUStringBuffer sBuf; 137 rExport.GetMM100UnitConverter().convertMeasure(sBuf, nLength); 138 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_OFFSET, 139 sBuf.makeStringAndClear()); 140 } 141 142 // NumeringType 143 OUStringBuffer sNumPosBuf; 144 aAny = xLineNumbering->getPropertyValue(sNumberingType); 145 sal_Int16 nFormat = 0; 146 aAny >>= nFormat; 147 rExport.GetMM100UnitConverter().convertNumFormat( sNumPosBuf, nFormat ); 148 rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT, 149 sNumPosBuf.makeStringAndClear()); 150 rExport.GetMM100UnitConverter().convertNumLetterSync( sNumPosBuf, nFormat ); 151 if( sNumPosBuf.getLength() ) 152 { 153 rExport.AddAttribute(XML_NAMESPACE_STYLE, 154 XML_NUM_LETTER_SYNC, 155 sNumPosBuf.makeStringAndClear() ); 156 } 157 158 // number position 159 aAny = xLineNumbering->getPropertyValue(sNumberPosition); 160 sal_Int16 nPosition = 0; 161 aAny >>= nPosition; 162 if (SvXMLUnitConverter::convertEnum(sNumPosBuf, nPosition, 163 aLineNumberPositionMap)) 164 { 165 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_NUMBER_POSITION, 166 sNumPosBuf.makeStringAndClear()); 167 } 168 169 // sInterval 170 aAny = xLineNumbering->getPropertyValue(sInterval); 171 sal_Int16 nLineInterval = 0; 172 aAny >>= nLineInterval; 173 OUStringBuffer sBuf; 174 SvXMLUnitConverter::convertNumber(sBuf, 175 (sal_Int32)nLineInterval); 176 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_INCREMENT, 177 sBuf.makeStringAndClear()); 178 179 SvXMLElementExport aConfigElem(rExport, XML_NAMESPACE_TEXT, 180 XML_LINENUMBERING_CONFIGURATION, 181 sal_True, sal_True); 182 183 // line separator 184 aAny = xLineNumbering->getPropertyValue(sSeparatorText); 185 OUString sSeparator; 186 aAny >>= sSeparator; 187 if (sSeparator.getLength() > 0) 188 { 189 190 // SeparatorInterval 191 aAny = xLineNumbering->getPropertyValue(sSeparatorInterval); 192 sal_Int16 nLineDistance = 0; 193 aAny >>= nLineDistance; 194 SvXMLUnitConverter::convertNumber(sBuf, 195 (sal_Int32)nLineDistance); 196 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_INCREMENT, 197 sBuf.makeStringAndClear()); 198 199 SvXMLElementExport aSeparatorElem(rExport, XML_NAMESPACE_TEXT, 200 XML_LINENUMBERING_SEPARATOR, 201 sal_True, sal_False); 202 rExport.Characters(sSeparator); 203 } 204 } 205 // else: no configuration: don't save -> default 206 } 207 // can't even get supplier: don't save -> default 208 } 209