1*63bba73cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*63bba73cSAndrew Rist * distributed with this work for additional information 6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance 9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*63bba73cSAndrew Rist * software distributed under the License is distributed on an 15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the 17*63bba73cSAndrew Rist * specific language governing permissions and limitations 18*63bba73cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*63bba73cSAndrew Rist *************************************************************/ 21*63bba73cSAndrew Rist 22*63bba73cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_xmloff.hxx" 26cdf0e10cSrcweir #include <tools/debug.hxx> 27cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 28cdf0e10cSrcweir 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <com/sun/star/text/XTextColumns.hpp> 31cdf0e10cSrcweir #include <com/sun/star/text/TextColumn.hpp> 32cdf0e10cSrcweir #include <com/sun/star/style/VerticalAlignment.hpp> 33cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 34cdf0e10cSrcweir 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <xmloff/xmltoken.hxx> 37cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx" 38cdf0e10cSrcweir #include <xmloff/xmluconv.hxx> 39cdf0e10cSrcweir #include <xmloff/xmlexp.hxx> 40cdf0e10cSrcweir #include "XMLTextColumnsExport.hxx" 41cdf0e10cSrcweir 42cdf0e10cSrcweir using namespace ::com::sun::star::style; 43cdf0e10cSrcweir using namespace ::com::sun::star::text; 44cdf0e10cSrcweir using namespace ::com::sun::star::uno; 45cdf0e10cSrcweir using namespace ::com::sun::star::beans; 46cdf0e10cSrcweir using ::rtl::OUString; 47cdf0e10cSrcweir using ::rtl::OUStringBuffer; 48cdf0e10cSrcweir using namespace ::xmloff::token; 49cdf0e10cSrcweir 50cdf0e10cSrcweir 51cdf0e10cSrcweir XMLTextColumnsExport::XMLTextColumnsExport( SvXMLExport& rExp ) : 52cdf0e10cSrcweir rExport( rExp ), 53cdf0e10cSrcweir sSeparatorLineIsOn(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineIsOn")), 54cdf0e10cSrcweir sSeparatorLineWidth(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineWidth")), 55cdf0e10cSrcweir sSeparatorLineColor(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineColor")), 56cdf0e10cSrcweir sSeparatorLineRelativeHeight(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineRelativeHeight")), 57cdf0e10cSrcweir sSeparatorLineVerticalAlignment(RTL_CONSTASCII_USTRINGPARAM("SeparatorLineVerticalAlignment")), 58cdf0e10cSrcweir sIsAutomatic(RTL_CONSTASCII_USTRINGPARAM("IsAutomatic")), 59cdf0e10cSrcweir sAutomaticDistance(RTL_CONSTASCII_USTRINGPARAM("AutomaticDistance")) 60cdf0e10cSrcweir { 61cdf0e10cSrcweir } 62cdf0e10cSrcweir 63cdf0e10cSrcweir void XMLTextColumnsExport::exportXML( const Any& rAny ) 64cdf0e10cSrcweir { 65cdf0e10cSrcweir Reference < XTextColumns > xColumns; 66cdf0e10cSrcweir rAny >>= xColumns; 67cdf0e10cSrcweir 68cdf0e10cSrcweir Sequence < TextColumn > aColumns = xColumns->getColumns(); 69cdf0e10cSrcweir const TextColumn *pColumns = aColumns.getArray(); 70cdf0e10cSrcweir sal_Int32 nCount = aColumns.getLength(); 71cdf0e10cSrcweir 72cdf0e10cSrcweir OUStringBuffer sValue; 73cdf0e10cSrcweir GetExport().GetMM100UnitConverter().convertNumber( sValue, nCount ? nCount : 1 ); 74cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_FO, XML_COLUMN_COUNT, 75cdf0e10cSrcweir sValue.makeStringAndClear() ); 76cdf0e10cSrcweir 77cdf0e10cSrcweir // handle 'automatic' columns 78cdf0e10cSrcweir Reference < XPropertySet > xPropSet( xColumns, UNO_QUERY ); 79cdf0e10cSrcweir if( xPropSet.is() ) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir Any aAny = xPropSet->getPropertyValue( sIsAutomatic ); 82cdf0e10cSrcweir if ( *(sal_Bool*)aAny.getValue() ) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir aAny = xPropSet->getPropertyValue( sAutomaticDistance ); 85cdf0e10cSrcweir sal_Int32 nDistance = 0; 86cdf0e10cSrcweir aAny >>= nDistance; 87cdf0e10cSrcweir OUStringBuffer aBuffer; 88cdf0e10cSrcweir GetExport().GetMM100UnitConverter().convertMeasure( 89cdf0e10cSrcweir aBuffer, nDistance ); 90cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_FO, 91cdf0e10cSrcweir XML_COLUMN_GAP, 92cdf0e10cSrcweir aBuffer.makeStringAndClear() ); 93cdf0e10cSrcweir } 94cdf0e10cSrcweir } 95cdf0e10cSrcweir 96cdf0e10cSrcweir SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, XML_COLUMNS, 97cdf0e10cSrcweir sal_True, sal_True ); 98cdf0e10cSrcweir 99cdf0e10cSrcweir if( xPropSet.is() ) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir Any aAny = xPropSet->getPropertyValue( sSeparatorLineIsOn ); 102cdf0e10cSrcweir if( *(sal_Bool *)aAny.getValue() ) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir // style:width 105cdf0e10cSrcweir aAny = xPropSet->getPropertyValue( sSeparatorLineWidth ); 106cdf0e10cSrcweir sal_Int32 nWidth = 0; 107cdf0e10cSrcweir aAny >>= nWidth; 108cdf0e10cSrcweir GetExport().GetMM100UnitConverter().convertMeasure( sValue, 109cdf0e10cSrcweir nWidth ); 110cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_WIDTH, 111cdf0e10cSrcweir sValue.makeStringAndClear() ); 112cdf0e10cSrcweir 113cdf0e10cSrcweir // style:color 114cdf0e10cSrcweir aAny = xPropSet->getPropertyValue( sSeparatorLineColor ); 115cdf0e10cSrcweir sal_Int32 nColor = 0; 116cdf0e10cSrcweir aAny >>= nColor; 117cdf0e10cSrcweir GetExport().GetMM100UnitConverter().convertColor( sValue, 118cdf0e10cSrcweir nColor ); 119cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_COLOR, 120cdf0e10cSrcweir sValue.makeStringAndClear() ); 121cdf0e10cSrcweir 122cdf0e10cSrcweir // style:height 123cdf0e10cSrcweir aAny = xPropSet->getPropertyValue( sSeparatorLineRelativeHeight ); 124cdf0e10cSrcweir sal_Int8 nHeight = 0; 125cdf0e10cSrcweir aAny >>= nHeight; 126cdf0e10cSrcweir GetExport().GetMM100UnitConverter().convertPercent( sValue, 127cdf0e10cSrcweir nHeight ); 128cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_HEIGHT, 129cdf0e10cSrcweir sValue.makeStringAndClear() ); 130cdf0e10cSrcweir 131cdf0e10cSrcweir // style:vertical-align 132cdf0e10cSrcweir aAny = xPropSet->getPropertyValue( sSeparatorLineVerticalAlignment ); 133cdf0e10cSrcweir VerticalAlignment eVertAlign; 134cdf0e10cSrcweir aAny >>= eVertAlign; 135cdf0e10cSrcweir 136cdf0e10cSrcweir enum XMLTokenEnum eStr = XML_TOKEN_INVALID; 137cdf0e10cSrcweir switch( eVertAlign ) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir // case VerticalAlignment_TOP: eStr = XML_TOP; 140cdf0e10cSrcweir case VerticalAlignment_MIDDLE: eStr = XML_MIDDLE; break; 141cdf0e10cSrcweir case VerticalAlignment_BOTTOM: eStr = XML_BOTTOM; break; 142cdf0e10cSrcweir default: 143cdf0e10cSrcweir break; 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir if( eStr != XML_TOKEN_INVALID) 147cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_STYLE, 148cdf0e10cSrcweir XML_VERTICAL_ALIGN, eStr ); 149cdf0e10cSrcweir 150cdf0e10cSrcweir // style:column-sep 151cdf0e10cSrcweir SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE, 152cdf0e10cSrcweir XML_COLUMN_SEP, 153cdf0e10cSrcweir sal_True, sal_True ); 154cdf0e10cSrcweir } 155cdf0e10cSrcweir } 156cdf0e10cSrcweir 157cdf0e10cSrcweir while( nCount-- ) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir // style:rel-width 160cdf0e10cSrcweir GetExport().GetMM100UnitConverter().convertNumber( sValue, 161cdf0e10cSrcweir pColumns->Width ); 162cdf0e10cSrcweir sValue.append( (sal_Unicode)'*' ); 163cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REL_WIDTH, 164cdf0e10cSrcweir sValue.makeStringAndClear() ); 165cdf0e10cSrcweir 166cdf0e10cSrcweir // fo:margin-left 167cdf0e10cSrcweir GetExport().GetMM100UnitConverter().convertMeasure( sValue, 168cdf0e10cSrcweir pColumns->LeftMargin ); 169cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_FO, XML_START_INDENT, 170cdf0e10cSrcweir sValue.makeStringAndClear() ); 171cdf0e10cSrcweir 172cdf0e10cSrcweir // fo:margin-right 173cdf0e10cSrcweir GetExport().GetMM100UnitConverter().convertMeasure( sValue, 174cdf0e10cSrcweir pColumns->RightMargin ); 175cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_FO, XML_END_INDENT, 176cdf0e10cSrcweir sValue.makeStringAndClear() ); 177cdf0e10cSrcweir 178cdf0e10cSrcweir // style:column 179cdf0e10cSrcweir SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE, XML_COLUMN, 180cdf0e10cSrcweir sal_True, sal_True ); 181cdf0e10cSrcweir pColumns++; 182cdf0e10cSrcweir } 183cdf0e10cSrcweir } 184cdf0e10cSrcweir 185cdf0e10cSrcweir 186