diff options
Diffstat (limited to 'xmloff/source/style')
118 files changed, 28787 insertions, 0 deletions
diff --git a/xmloff/source/style/AttributeContainerHandler.cxx b/xmloff/source/style/AttributeContainerHandler.cxx new file mode 100644 index 000000000000..94c0f2e25ef2 --- /dev/null +++ b/xmloff/source/style/AttributeContainerHandler.cxx @@ -0,0 +1,107 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/xml/AttributeData.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/text/GraphicCrop.hpp> + +#include "AttributeContainerHandler.hxx" + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::container; + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLAttributeContainerHandler +// + +XMLAttributeContainerHandler::~XMLAttributeContainerHandler() +{ + // nothing to do +} + +bool XMLAttributeContainerHandler::equals( + const Any& r1, + const Any& r2 ) const +{ + Reference< XNameContainer > xContainer1; + Reference< XNameContainer > xContainer2; + + if( ( r1 >>= xContainer1 ) && ( r2 >>= xContainer2 ) ) + { + uno::Sequence< OUString > aAttribNames1( xContainer1->getElementNames() ); + uno::Sequence< OUString > aAttribNames2( xContainer2->getElementNames() ); + const sal_Int32 nCount = aAttribNames1.getLength(); + + if( aAttribNames2.getLength() == nCount ) + { + const OUString* pAttribName = aAttribNames1.getConstArray(); + + xml::AttributeData aData1; + xml::AttributeData aData2; + + for( sal_Int32 i=0; i < nCount; i++, pAttribName++ ) + { + if( !xContainer2->hasByName( *pAttribName ) ) + return sal_False; + + xContainer1->getByName( *pAttribName ) >>= aData1; + xContainer2->getByName( *pAttribName ) >>= aData2; + + if( ( aData1.Namespace != aData2.Namespace ) || + ( aData1.Type != aData2.Type ) || + ( aData1.Value != aData2.Value ) ) + return sal_False; + } + + return sal_True; + } + } + + return sal_False; +} + +sal_Bool XMLAttributeContainerHandler::importXML( const OUString& /*rStrImpValue*/, Any& /*rValue*/, const SvXMLUnitConverter& /*rUnitConverter*/ ) const +{ + return sal_True; +} + +sal_Bool XMLAttributeContainerHandler::exportXML( OUString& /*rStrExpValue*/, const Any& /*rValue*/, const SvXMLUnitConverter& /*rUnitConverter*/ ) const +{ + return sal_True; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/DashStyle.cxx b/xmloff/source/style/DashStyle.cxx new file mode 100644 index 000000000000..97f187b5178e --- /dev/null +++ b/xmloff/source/style/DashStyle.cxx @@ -0,0 +1,331 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <com/sun/star/drawing/DashStyle.hpp> +#include <com/sun/star/drawing/LineDash.hpp> +#include "xmloff/DashStyle.hxx" +#include <xmloff/attrlist.hxx> +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmluconv.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlexp.hxx> +#include <xmloff/xmlimp.hxx> +#include <rtl/ustrbuf.hxx> +#include <rtl/ustring.hxx> +#include <tools/debug.hxx> +#include <xmloff/xmltkmap.hxx> + +using namespace ::com::sun::star; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::xmloff::token; + +enum SvXMLTokenMapAttrs +{ + XML_TOK_DASH_NAME, + XML_TOK_DASH_DISPLAY_NAME, + XML_TOK_DASH_STYLE, + XML_TOK_DASH_DOTS1, + XML_TOK_DASH_DOTS1LEN, + XML_TOK_DASH_DOTS2, + XML_TOK_DASH_DOTS2LEN, + XML_TOK_DASH_DISTANCE, + XML_TOK_DASH_END=XML_TOK_UNKNOWN +}; + +static SvXMLTokenMapEntry aDashStyleAttrTokenMap[] = +{ + { XML_NAMESPACE_DRAW, XML_NAME, XML_TOK_DASH_NAME }, + { XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, XML_TOK_DASH_DISPLAY_NAME }, + { XML_NAMESPACE_DRAW, XML_STYLE, XML_TOK_DASH_STYLE }, + { XML_NAMESPACE_DRAW, XML_DOTS1, XML_TOK_DASH_DOTS1 }, + { XML_NAMESPACE_DRAW, XML_DOTS1_LENGTH, XML_TOK_DASH_DOTS1LEN }, + { XML_NAMESPACE_DRAW, XML_DOTS2, XML_TOK_DASH_DOTS2 }, + { XML_NAMESPACE_DRAW, XML_DOTS2_LENGTH, XML_TOK_DASH_DOTS2LEN }, + { XML_NAMESPACE_DRAW, XML_DISTANCE, XML_TOK_DASH_DISTANCE }, + XML_TOKEN_MAP_END +}; + +SvXMLEnumMapEntry const pXML_DashStyle_Enum[] = +{ + { XML_RECT, drawing::DashStyle_RECT }, + { XML_ROUND, drawing::DashStyle_ROUND }, + { XML_RECT, drawing::DashStyle_RECTRELATIVE }, + { XML_ROUND, drawing::DashStyle_ROUNDRELATIVE }, + { XML_TOKEN_INVALID, 0 } +}; + +//------------------------------------------------------------- +// Import +//------------------------------------------------------------- + +XMLDashStyleImport::XMLDashStyleImport( SvXMLImport& rImp ) + : rImport(rImp) +{ +} + +XMLDashStyleImport::~XMLDashStyleImport() +{ +} + +sal_Bool XMLDashStyleImport::importXML( + const uno::Reference< xml::sax::XAttributeList >& xAttrList, + uno::Any& rValue, + OUString& rStrName ) +{ + drawing::LineDash aLineDash; + aLineDash.Style = drawing::DashStyle_RECT; + aLineDash.Dots = 0; + aLineDash.DotLen = 0; + aLineDash.Dashes = 0; + aLineDash.DashLen = 0; + aLineDash.Distance = 20; + OUString aDisplayName; + + sal_Bool bIsRel = sal_False; + + SvXMLNamespaceMap& rNamespaceMap = rImport.GetNamespaceMap(); + SvXMLUnitConverter& rUnitConverter = rImport.GetMM100UnitConverter(); + + SvXMLTokenMap aTokenMap( aDashStyleAttrTokenMap ); + + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rFullAttrName = xAttrList->getNameByIndex( i ); + OUString aStrAttrName; + sal_uInt16 nPrefix = rNamespaceMap.GetKeyByAttrName( rFullAttrName, &aStrAttrName ); + const OUString& rStrValue = xAttrList->getValueByIndex( i ); + + switch( aTokenMap.Get( nPrefix, aStrAttrName ) ) + { + case XML_TOK_DASH_NAME: + { + rStrName = rStrValue; + } + break; + case XML_TOK_DASH_DISPLAY_NAME: + { + aDisplayName = rStrValue; + } + break; + case XML_TOK_DASH_STYLE: + { + sal_uInt16 eValue; + if( rUnitConverter.convertEnum( eValue, rStrValue, pXML_DashStyle_Enum ) ) + { + aLineDash.Style = (drawing::DashStyle) eValue; + } + } + break; + case XML_TOK_DASH_DOTS1: + aLineDash.Dots = (sal_Int16)rStrValue.toInt32(); + break; + + case XML_TOK_DASH_DOTS1LEN: + { + if( rStrValue.indexOf( sal_Unicode('%') ) != -1 ) // its a percentage + { + bIsRel = sal_True; + rUnitConverter.convertPercent( aLineDash.DotLen, rStrValue ); + } + else + { + rUnitConverter.convertMeasure( aLineDash.DotLen, rStrValue ); + } + } + break; + + case XML_TOK_DASH_DOTS2: + aLineDash.Dashes = (sal_Int16)rStrValue.toInt32(); + break; + + case XML_TOK_DASH_DOTS2LEN: + { + if( rStrValue.indexOf( sal_Unicode('%') ) != -1 ) // its a percentage + { + bIsRel = sal_True; + rUnitConverter.convertPercent( aLineDash.DashLen, rStrValue ); + } + else + { + rUnitConverter.convertMeasure( aLineDash.DashLen, rStrValue ); + } + } + break; + + case XML_TOK_DASH_DISTANCE: + { + if( rStrValue.indexOf( sal_Unicode('%') ) != -1 ) // its a percentage + { + bIsRel = sal_True; + rUnitConverter.convertPercent( aLineDash.Distance, rStrValue ); + } + else + { + rUnitConverter.convertMeasure( aLineDash.Distance, rStrValue ); + } + } + break; + default: + DBG_WARNING( "Unknown token at import gradient style" ); + } + } + + if( bIsRel ) + aLineDash.Style = aLineDash.Style == drawing::DashStyle_RECT ? drawing::DashStyle_RECTRELATIVE : drawing::DashStyle_ROUNDRELATIVE; + + rValue <<= aLineDash; + + if( aDisplayName.getLength() ) + { + rImport.AddStyleDisplayName( XML_STYLE_FAMILY_SD_STROKE_DASH_ID, + rStrName, aDisplayName ); + rStrName = aDisplayName; + } + + return sal_True; +} + + +//------------------------------------------------------------- +// Export +//------------------------------------------------------------- + +XMLDashStyleExport::XMLDashStyleExport( SvXMLExport& rExp ) + : rExport(rExp) +{ +} + +XMLDashStyleExport::~XMLDashStyleExport() +{ +} + +sal_Bool XMLDashStyleExport::exportXML( + const OUString& rStrName, + const uno::Any& rValue ) +{ + sal_Bool bRet = sal_False; + + SvXMLUnitConverter rUnitConverter = rExport.GetMM100UnitConverter(); + + drawing::LineDash aLineDash; + + if( rStrName.getLength() ) + { + if( rValue >>= aLineDash ) + { + sal_Bool bIsRel = aLineDash.Style == drawing::DashStyle_RECTRELATIVE || aLineDash.Style == drawing::DashStyle_ROUNDRELATIVE; + + OUString aStrValue; + OUStringBuffer aOut; + + // Name + sal_Bool bEncoded = sal_False; + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME, + rExport.EncodeStyleName( rStrName, + &bEncoded ) ); + if( bEncoded ) + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, + rStrName ); + + // Style + rUnitConverter.convertEnum( aOut, aLineDash.Style, pXML_DashStyle_Enum ); + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_STYLE, aStrValue ); + + + // dots + if( aLineDash.Dots ) + { + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DOTS1, OUString::valueOf( (sal_Int32)aLineDash.Dots ) ); + + if( aLineDash.DotLen ) + { + // dashes length + if( bIsRel ) + { + rUnitConverter.convertPercent( aOut, aLineDash.DotLen ); + } + else + { + rUnitConverter.convertMeasure( aOut, aLineDash.DotLen ); + } + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DOTS1_LENGTH, aStrValue ); + } + } + + // dashes + if( aLineDash.Dashes ) + { + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DOTS2, OUString::valueOf( (sal_Int32)aLineDash.Dashes ) ); + + if( aLineDash.DashLen ) + { + // dashes length + if( bIsRel ) + { + rUnitConverter.convertPercent( aOut, aLineDash.DashLen ); + } + else + { + rUnitConverter.convertMeasure( aOut, aLineDash.DashLen ); + } + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DOTS2_LENGTH, aStrValue ); + } + } + + // distance + if( bIsRel ) + { + rUnitConverter.convertPercent( aOut, aLineDash.Distance ); + } + else + { + rUnitConverter.convertMeasure( aOut, aLineDash.Distance ); + } + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISTANCE, aStrValue ); + + + // do Write + SvXMLElementExport rElem( rExport, + XML_NAMESPACE_DRAW, XML_STROKE_DASH, + sal_True, sal_False ); + } + } + return bRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/DrawAspectHdl.cxx b/xmloff/source/style/DrawAspectHdl.cxx new file mode 100644 index 000000000000..754e22b27d47 --- /dev/null +++ b/xmloff/source/style/DrawAspectHdl.cxx @@ -0,0 +1,91 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <com/sun/star/uno/Any.hxx> +#include <rtl/ustrbuf.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/xmltoken.hxx> +#include "DrawAspectHdl.hxx" + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::xmloff::token; + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLMeasurePropHdl +// + +SvXMLEnumMapEntry const pXML_DrawAspect_Enum[] = +{ + { XML_CONTENT, 1 }, + { XML_THUMBNAIL, 2 }, + { XML_ICON, 4 }, + { XML_PRINT, 8 }, + { XML_TOKEN_INVALID, 0 } +}; + +DrawAspectHdl::~DrawAspectHdl() +{ + // nothing to do +} + +sal_Bool DrawAspectHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Int64 nAspect = 0; + + SvXMLUnitConverter::convertNumber64( nAspect, rStrImpValue ); + rValue <<= nAspect; + + return nAspect > 0; +} + +sal_Bool DrawAspectHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + OUStringBuffer aOut; + + sal_Int64 nAspect = 0; + if( ( rValue >>= nAspect ) && nAspect > 0 ) + { + // store the aspect as an integer value + aOut.append( nAspect ); + + rStrExpValue = aOut.makeStringAndClear(); + + bRet = sal_True; + } + + return bRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/DrawAspectHdl.hxx b/xmloff/source/style/DrawAspectHdl.hxx new file mode 100644 index 000000000000..c644c0dc85fb --- /dev/null +++ b/xmloff/source/style/DrawAspectHdl.hxx @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_DRAWASPECTHDL_HXX +#define _XMLOFF_DRAWASPECTHDL_HXX + +#include <xmloff/xmlprhdl.hxx> + +/** + PropertyHandler for the XML-data-type: +*/ +class DrawAspectHdl : public XMLPropertyHandler +{ +public: + virtual ~DrawAspectHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +#endif // _XMLOFF_DRAWASPECTHDL_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/EnumPropertyHdl.cxx b/xmloff/source/style/EnumPropertyHdl.cxx new file mode 100644 index 000000000000..55c3a60491ad --- /dev/null +++ b/xmloff/source/style/EnumPropertyHdl.cxx @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include <xmloff/EnumPropertyHdl.hxx> +#include <xmloff/xmluconv.hxx> +#include <comphelper/extract.hxx> +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/Any.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star::uno; + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLEnumPropertyHdl +// + +XMLEnumPropertyHdl::~XMLEnumPropertyHdl() +{ + // Nothing to do +} + +sal_Bool XMLEnumPropertyHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_uInt16 nValue = 0; + + if( SvXMLUnitConverter::convertEnum( nValue, rStrImpValue, mpEnumMap ) ) + { + switch( mrType.getTypeClass() ) + { + case TypeClass_ENUM: + rValue = ::cppu::int2enum( nValue, mrType ); + break; + case TypeClass_LONG: + rValue <<= (sal_Int32) nValue; + break; + case TypeClass_SHORT: + rValue <<= (sal_Int16) nValue; + break; + case TypeClass_BYTE: + rValue <<= (sal_Int8) nValue; + break; + default: + OSL_FAIL( "Wrong type for enum property handler!" ); + return sal_False; + } + return sal_True; + } + + return sal_False; +} + +sal_Bool XMLEnumPropertyHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Int32 nValue = 0; + if(!(rValue >>= nValue )) + if(!::cppu::enum2int(nValue, rValue) ) + return sal_False; + + OUStringBuffer aOut; + + if(!SvXMLUnitConverter::convertEnum( aOut, nValue, mpEnumMap )) + return sal_False; + + rStrExpValue = aOut.makeStringAndClear(); + return sal_True; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/FillStyleContext.cxx b/xmloff/source/style/FillStyleContext.cxx new file mode 100644 index 000000000000..305b4932a2db --- /dev/null +++ b/xmloff/source/style/FillStyleContext.cxx @@ -0,0 +1,362 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <com/sun/star/container/XNameContainer.hpp> +#include "FillStyleContext.hxx" +#include <xmloff/xmlimp.hxx> +#include "xmloff/GradientStyle.hxx" +#include "xmloff/HatchStyle.hxx" +#include "xmloff/ImageStyle.hxx" +#include "TransGradientStyle.hxx" +#include "xmloff/MarkerStyle.hxx" +#include "xmloff/DashStyle.hxx" +#include <xmloff/families.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/XMLBase64ImportContext.hxx> + +using namespace ::com::sun::star; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + + +////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +TYPEINIT1( XMLGradientStyleContext, SvXMLStyleContext ); + +XMLGradientStyleContext::XMLGradientStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const uno::Reference< xml::sax::XAttributeList >& xAttrList) +: SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList) +{ + + // start import + XMLGradientStyleImport aGradientStyle( GetImport() ); + aGradientStyle.importXML( xAttrList, maAny, maStrName ); +} + +XMLGradientStyleContext::~XMLGradientStyleContext() +{ +} + +void XMLGradientStyleContext::EndElement() +{ + uno::Reference< container::XNameContainer > xGradient( GetImport().GetGradientHelper() ); + + try + { + if(xGradient.is()) + { + if( xGradient->hasByName( maStrName ) ) + { + xGradient->replaceByName( maStrName, maAny ); + } + else + { + xGradient->insertByName( maStrName, maAny ); + } + } + } + catch( container::ElementExistException& ) + {} +} + +sal_Bool XMLGradientStyleContext::IsTransient() const +{ + return sal_True; +} + +////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +TYPEINIT1( XMLHatchStyleContext, SvXMLStyleContext ); + +XMLHatchStyleContext::XMLHatchStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const uno::Reference< xml::sax::XAttributeList >& xAttrList) +: SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList) +{ + // start import + XMLHatchStyleImport aHatchStyle( GetImport() ); + aHatchStyle.importXML( xAttrList, maAny, maStrName ); +} + +XMLHatchStyleContext::~XMLHatchStyleContext() +{ +} + +void XMLHatchStyleContext::EndElement() +{ + uno::Reference< container::XNameContainer > xHatch( GetImport().GetHatchHelper() ); + + try + { + if(xHatch.is()) + { + if( xHatch->hasByName( maStrName ) ) + { + xHatch->replaceByName( maStrName, maAny ); + } + else + { + xHatch->insertByName( maStrName, maAny ); + } + } + } + catch( container::ElementExistException& ) + {} +} + +sal_Bool XMLHatchStyleContext::IsTransient() const +{ + return sal_True; +} + +////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +TYPEINIT1( XMLBitmapStyleContext, SvXMLStyleContext ); + +XMLBitmapStyleContext::XMLBitmapStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const uno::Reference< xml::sax::XAttributeList >& xAttrList) +: SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList) +{ + // start import + XMLImageStyle aBitmapStyle; + aBitmapStyle.importXML( xAttrList, maAny, maStrName, rImport ); +} + +XMLBitmapStyleContext::~XMLBitmapStyleContext() +{ +} + +SvXMLImportContext* XMLBitmapStyleContext::CreateChildContext( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + if( (XML_NAMESPACE_OFFICE == nPrefix) && xmloff::token::IsXMLToken( rLocalName, xmloff::token::XML_BINARY_DATA ) ) + { + OUString sURL; + maAny >>= sURL; + if( !sURL.getLength() && !mxBase64Stream.is() ) + { + mxBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64(); + if( mxBase64Stream.is() ) + pContext = new XMLBase64ImportContext( GetImport(), nPrefix, + rLocalName, xAttrList, + mxBase64Stream ); + } + } + if( !pContext ) + { + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + } + + return pContext; +} + +void XMLBitmapStyleContext::EndElement() +{ + OUString sURL; + maAny >>= sURL; + + if( !sURL.getLength() && mxBase64Stream.is() ) + { + sURL = GetImport().ResolveGraphicObjectURLFromBase64( mxBase64Stream ); + mxBase64Stream = 0; + maAny <<= sURL; + } + + uno::Reference< container::XNameContainer > xBitmap( GetImport().GetBitmapHelper() ); + + try + { + if(xBitmap.is()) + { + if( xBitmap->hasByName( maStrName ) ) + { + xBitmap->replaceByName( maStrName, maAny ); + } + else + { + xBitmap->insertByName( maStrName, maAny ); + } + } + } + catch( container::ElementExistException& ) + {} +} + +sal_Bool XMLBitmapStyleContext::IsTransient() const +{ + return sal_True; +} + + +////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +TYPEINIT1( XMLTransGradientStyleContext, SvXMLStyleContext ); + +XMLTransGradientStyleContext::XMLTransGradientStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const uno::Reference< xml::sax::XAttributeList >& xAttrList) +: SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList) +{ + // start import + XMLTransGradientStyleImport aTransGradientStyle( GetImport() ); + aTransGradientStyle.importXML( xAttrList, maAny, maStrName ); +} + +XMLTransGradientStyleContext::~XMLTransGradientStyleContext() +{ +} + +void XMLTransGradientStyleContext::EndElement() +{ + uno::Reference< container::XNameContainer > xTransGradient( GetImport().GetTransGradientHelper() ); + + try + { + if(xTransGradient.is()) + { + if( xTransGradient->hasByName( maStrName ) ) + { + xTransGradient->replaceByName( maStrName, maAny ); + } + else + { + xTransGradient->insertByName( maStrName, maAny ); + } + } + } + catch( container::ElementExistException& ) + {} +} + +sal_Bool XMLTransGradientStyleContext::IsTransient() const +{ + return sal_True; +} + +////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +TYPEINIT1( XMLMarkerStyleContext, SvXMLStyleContext ); + +XMLMarkerStyleContext::XMLMarkerStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const uno::Reference< xml::sax::XAttributeList >& xAttrList) +: SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList) +{ + // start import + XMLMarkerStyleImport aMarkerStyle( GetImport() ); + aMarkerStyle.importXML( xAttrList, maAny, maStrName ); +} + +XMLMarkerStyleContext::~XMLMarkerStyleContext() +{ +} + +void XMLMarkerStyleContext::EndElement() +{ + uno::Reference< container::XNameContainer > xMarker( GetImport().GetMarkerHelper() ); + + try + { + if(xMarker.is()) + { + if( xMarker->hasByName( maStrName ) ) + { + xMarker->replaceByName( maStrName, maAny ); + } + else + { + xMarker->insertByName( maStrName, maAny ); + } + } + } + catch( container::ElementExistException& ) + {} +} + +sal_Bool XMLMarkerStyleContext::IsTransient() const +{ + return sal_True; +} + +////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +TYPEINIT1( XMLDashStyleContext, SvXMLStyleContext ); + +XMLDashStyleContext::XMLDashStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const uno::Reference< xml::sax::XAttributeList >& xAttrList) +: SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList) +{ + // start import + XMLDashStyleImport aDashStyle( GetImport() ); + aDashStyle.importXML( xAttrList, maAny, maStrName ); +} + +XMLDashStyleContext::~XMLDashStyleContext() +{ +} + +void XMLDashStyleContext::EndElement() +{ + uno::Reference< container::XNameContainer > xDashes( GetImport().GetDashHelper() ); + + try + { + if(xDashes.is()) + { + if( xDashes->hasByName( maStrName ) ) + { + xDashes->replaceByName( maStrName, maAny ); + } + else + { + xDashes->insertByName( maStrName, maAny ); + } + } + } + catch( container::ElementExistException& ) + {} +} + +sal_Bool XMLDashStyleContext::IsTransient() const +{ + return sal_True; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/FillStyleContext.hxx b/xmloff/source/style/FillStyleContext.hxx new file mode 100644 index 000000000000..b047ea42b5ef --- /dev/null +++ b/xmloff/source/style/FillStyleContext.hxx @@ -0,0 +1,170 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_FILLSTYLECONTEXTS_HXX_ +#define _XMLOFF_FILLSTYLECONTEXTS_HXX_ + +#include <com/sun/star/io/XOutputStream.hpp> +#include <xmloff/xmlstyle.hxx> +#include<rtl/ustring.hxx> + +////////////////////////////////////////////////////////////////////////////// +// draw:gardient context + +class XMLGradientStyleContext: public SvXMLStyleContext +{ +private: + ::com::sun::star::uno::Any maAny; + rtl::OUString maStrName; + +public: + TYPEINFO(); + + XMLGradientStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLName, + const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList ); + virtual ~XMLGradientStyleContext(); + + virtual void EndElement(); + + virtual sal_Bool IsTransient() const; +}; + +////////////////////////////////////////////////////////////////////////////// +// draw:hatch context + +class XMLHatchStyleContext: public SvXMLStyleContext +{ +private: + ::com::sun::star::uno::Any maAny; + rtl::OUString maStrName; + +public: + TYPEINFO(); + + XMLHatchStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLName, + const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList ); + virtual ~XMLHatchStyleContext(); + + virtual void EndElement(); + + virtual sal_Bool IsTransient() const; +}; + +////////////////////////////////////////////////////////////////////////////// +// draw:fill-image context + +class XMLBitmapStyleContext: public SvXMLStyleContext +{ +private: + ::com::sun::star::uno::Any maAny; + rtl::OUString maStrName; + ::com::sun::star::uno::Reference < ::com::sun::star::io::XOutputStream > mxBase64Stream; + +public: + TYPEINFO(); + + XMLBitmapStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLName, + const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList ); + virtual ~XMLBitmapStyleContext(); + + virtual SvXMLImportContext *CreateChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); + + virtual void EndElement(); + + virtual sal_Bool IsTransient() const; +}; + +////////////////////////////////////////////////////////////////////////////// +// draw:transparency context + +class XMLTransGradientStyleContext: public SvXMLStyleContext +{ +private: + ::com::sun::star::uno::Any maAny; + rtl::OUString maStrName; + +public: + TYPEINFO(); + + XMLTransGradientStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLName, + const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList ); + virtual ~XMLTransGradientStyleContext(); + + virtual void EndElement(); + + virtual sal_Bool IsTransient() const; +}; + +////////////////////////////////////////////////////////////////////////////// +// draw:marker context + +class XMLMarkerStyleContext: public SvXMLStyleContext +{ +private: + ::com::sun::star::uno::Any maAny; + rtl::OUString maStrName; + +public: + TYPEINFO(); + + XMLMarkerStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLName, + const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList ); + virtual ~XMLMarkerStyleContext(); + + virtual void EndElement(); + + virtual sal_Bool IsTransient() const; +}; + +////////////////////////////////////////////////////////////////////////////// +// draw:marker context + +class XMLDashStyleContext: public SvXMLStyleContext +{ +private: + ::com::sun::star::uno::Any maAny; + rtl::OUString maStrName; + +public: + TYPEINFO(); + + XMLDashStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLName, + const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList ); + virtual ~XMLDashStyleContext(); + + virtual void EndElement(); + + virtual sal_Bool IsTransient() const; +}; + +#endif // _XMLOFF_FILLSTYLECONTEXTS_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/GradientStyle.cxx b/xmloff/source/style/GradientStyle.cxx new file mode 100644 index 000000000000..c468f2907d1e --- /dev/null +++ b/xmloff/source/style/GradientStyle.cxx @@ -0,0 +1,343 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "xmloff/GradientStyle.hxx" +#include <com/sun/star/awt/Gradient.hpp> +#include <xmloff/attrlist.hxx> +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmluconv.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <rtl/ustrbuf.hxx> +#include <rtl/ustring.hxx> +#include <tools/debug.hxx> +#include <xmloff/xmltkmap.hxx> +#include <xmloff/xmlexp.hxx> +#include <xmloff/xmlimp.hxx> + + + +using namespace ::com::sun::star; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::xmloff::token; + +enum SvXMLTokenMapAttrs +{ + XML_TOK_GRADIENT_NAME, + XML_TOK_GRADIENT_DISPLAY_NAME, + XML_TOK_GRADIENT_STYLE, + XML_TOK_GRADIENT_CX, + XML_TOK_GRADIENT_CY, + XML_TOK_GRADIENT_STARTCOLOR, + XML_TOK_GRADIENT_ENDCOLOR, + XML_TOK_GRADIENT_STARTINT, + XML_TOK_GRADIENT_ENDINT, + XML_TOK_GRADIENT_ANGLE, + XML_TOK_GRADIENT_BORDER, + XML_TOK_TABSTOP_END=XML_TOK_UNKNOWN +}; + + +SvXMLEnumMapEntry const pXML_GradientStyle_Enum[] = +{ + { XML_GRADIENTSTYLE_LINEAR, awt::GradientStyle_LINEAR }, + { XML_GRADIENTSTYLE_AXIAL, awt::GradientStyle_AXIAL }, + { XML_GRADIENTSTYLE_RADIAL, awt::GradientStyle_RADIAL }, + { XML_GRADIENTSTYLE_ELLIPSOID, awt::GradientStyle_ELLIPTICAL }, + { XML_GRADIENTSTYLE_SQUARE, awt::GradientStyle_SQUARE }, + { XML_GRADIENTSTYLE_RECTANGULAR, awt::GradientStyle_RECT }, + { XML_TOKEN_INVALID, 0 } +}; + +//------------------------------------------------------------- +// Import +//------------------------------------------------------------- +XMLGradientStyleImport::XMLGradientStyleImport( + SvXMLImport& rImp ) + : rImport(rImp) +{ +} + +XMLGradientStyleImport::~XMLGradientStyleImport() +{ +} + +sal_Bool XMLGradientStyleImport::importXML( + const uno::Reference< xml::sax::XAttributeList >& xAttrList, + uno::Any& rValue, + OUString& rStrName ) +{ + sal_Bool bRet = sal_False; + sal_Bool bHasName = sal_False; + sal_Bool bHasStyle = sal_False; + sal_Bool bHasStartColor = sal_False; + sal_Bool bHasEndColor = sal_False; + OUString aDisplayName; + + awt::Gradient aGradient; + aGradient.XOffset = 0; + aGradient.YOffset = 0; + aGradient.StartIntensity = 100; + aGradient.EndIntensity = 100; + aGradient.Angle = 0; + aGradient.Border = 0; + + { + static SvXMLTokenMapEntry aGradientAttrTokenMap[] = +{ + { XML_NAMESPACE_DRAW, XML_NAME, XML_TOK_GRADIENT_NAME }, + { XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, XML_TOK_GRADIENT_DISPLAY_NAME }, + { XML_NAMESPACE_DRAW, XML_STYLE, XML_TOK_GRADIENT_STYLE }, + { XML_NAMESPACE_DRAW, XML_CX, XML_TOK_GRADIENT_CX }, + { XML_NAMESPACE_DRAW, XML_CY, XML_TOK_GRADIENT_CY }, + { XML_NAMESPACE_DRAW, XML_START_COLOR, XML_TOK_GRADIENT_STARTCOLOR }, + { XML_NAMESPACE_DRAW, XML_END_COLOR, XML_TOK_GRADIENT_ENDCOLOR }, + { XML_NAMESPACE_DRAW, XML_START_INTENSITY, XML_TOK_GRADIENT_STARTINT }, + { XML_NAMESPACE_DRAW, XML_END_INTENSITY, XML_TOK_GRADIENT_ENDINT }, + { XML_NAMESPACE_DRAW, XML_GRADIENT_ANGLE, XML_TOK_GRADIENT_ANGLE }, + { XML_NAMESPACE_DRAW, XML_GRADIENT_BORDER, XML_TOK_GRADIENT_BORDER }, + XML_TOKEN_MAP_END +}; + + SvXMLTokenMap aTokenMap( aGradientAttrTokenMap ); + SvXMLNamespaceMap& rNamespaceMap = rImport.GetNamespaceMap(); + + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rFullAttrName = xAttrList->getNameByIndex( i ); + OUString aStrAttrName; + sal_uInt16 nPrefix = rNamespaceMap.GetKeyByAttrName( rFullAttrName, &aStrAttrName ); + const OUString& rStrValue = xAttrList->getValueByIndex( i ); + + sal_Int32 nTmpValue; + + switch( aTokenMap.Get( nPrefix, aStrAttrName ) ) + { + case XML_TOK_GRADIENT_NAME: + { + rStrName = rStrValue; + bHasName = sal_True; + } + break; + case XML_TOK_GRADIENT_DISPLAY_NAME: + { + aDisplayName = rStrValue; + } + break; + case XML_TOK_GRADIENT_STYLE: + { + sal_uInt16 eValue; + if( SvXMLUnitConverter::convertEnum( eValue, rStrValue, pXML_GradientStyle_Enum ) ) + { + aGradient.Style = (awt::GradientStyle) eValue; + bHasStyle = sal_True; + } + } + break; + case XML_TOK_GRADIENT_CX: + SvXMLUnitConverter::convertPercent( nTmpValue, rStrValue ); + aGradient.XOffset = static_cast< sal_Int16 >( nTmpValue ); + break; + case XML_TOK_GRADIENT_CY: + SvXMLUnitConverter::convertPercent( nTmpValue, rStrValue ); + aGradient.YOffset = static_cast< sal_Int16 >( nTmpValue ); + break; + case XML_TOK_GRADIENT_STARTCOLOR: + { + Color aColor; + bHasStartColor = SvXMLUnitConverter::convertColor( aColor, rStrValue ); + if( bHasStartColor ) + aGradient.StartColor = (sal_Int32)( aColor.GetColor() ); + } + break; + case XML_TOK_GRADIENT_ENDCOLOR: + { + Color aColor; + bHasStartColor = SvXMLUnitConverter::convertColor( aColor, rStrValue ); + if( bHasStartColor ) + aGradient.EndColor = (sal_Int32)( aColor.GetColor() ); + } + break; + case XML_TOK_GRADIENT_STARTINT: + SvXMLUnitConverter::convertPercent( nTmpValue, rStrValue ); + aGradient.StartIntensity = static_cast< sal_Int16 >( nTmpValue ); + break; + case XML_TOK_GRADIENT_ENDINT: + SvXMLUnitConverter::convertPercent( nTmpValue, rStrValue ); + aGradient.EndIntensity = static_cast< sal_Int16 >( nTmpValue ); + break; + case XML_TOK_GRADIENT_ANGLE: + { + sal_Int32 nValue; + SvXMLUnitConverter::convertNumber( nValue, rStrValue, 0, 3600 ); + aGradient.Angle = sal_Int16( nValue ); + } + break; + case XML_TOK_GRADIENT_BORDER: + SvXMLUnitConverter::convertPercent( nTmpValue, rStrValue ); + aGradient.Border = static_cast< sal_Int16 >( nTmpValue ); + break; + + default: + DBG_WARNING( "Unknown token at import gradient style" ) + ; + } + } + + rValue <<= aGradient; + + if( aDisplayName.getLength() ) + { + rImport.AddStyleDisplayName( XML_STYLE_FAMILY_SD_GRADIENT_ID, rStrName, + aDisplayName ); + rStrName = aDisplayName; + } + + bRet = bHasName && bHasStyle && bHasStartColor && bHasEndColor; + + } + + return bRet; +} + + +//------------------------------------------------------------- +// Export +//------------------------------------------------------------- + +XMLGradientStyleExport::XMLGradientStyleExport( + SvXMLExport& rExp ) + : rExport(rExp) +{ +} + +XMLGradientStyleExport::~XMLGradientStyleExport() +{ +} + +sal_Bool XMLGradientStyleExport::exportXML( + const OUString& rStrName, + const uno::Any& rValue ) +{ + sal_Bool bRet = sal_False; + awt::Gradient aGradient; + + if( rStrName.getLength() ) + { + if( rValue >>= aGradient ) + { + OUString aStrValue; + OUStringBuffer aOut; + + // Style + if( !SvXMLUnitConverter::convertEnum( aOut, aGradient.Style, pXML_GradientStyle_Enum ) ) + { + bRet = sal_False; + } + else + { + // Name + sal_Bool bEncoded = sal_False; + OUString aStrName( rStrName ); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME, + rExport.EncodeStyleName( aStrName, + &bEncoded ) ); + if( bEncoded ) + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, + aStrName ); + + + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_STYLE, aStrValue ); + + // Center x/y + if( aGradient.Style != awt::GradientStyle_LINEAR && + aGradient.Style != awt::GradientStyle_AXIAL ) + { + SvXMLUnitConverter::convertPercent( aOut, aGradient.XOffset ); + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_CX, aStrValue ); + + SvXMLUnitConverter::convertPercent( aOut, aGradient.YOffset ); + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_CY, aStrValue ); + } + + Color aColor; + + // Color start + aColor.SetColor( aGradient.StartColor ); + SvXMLUnitConverter::convertColor( aOut, aColor ); + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_START_COLOR, aStrValue ); + + // Color end + aColor.SetColor( aGradient.EndColor ); + SvXMLUnitConverter::convertColor( aOut, aColor ); + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_END_COLOR, aStrValue ); + + // Intensity start + SvXMLUnitConverter::convertPercent( aOut, aGradient.StartIntensity ); + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_START_INTENSITY, aStrValue ); + + // Intensity end + SvXMLUnitConverter::convertPercent( aOut, aGradient.EndIntensity ); + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_END_INTENSITY, aStrValue ); + + // Angle + if( aGradient.Style != awt::GradientStyle_RADIAL ) + { + SvXMLUnitConverter::convertNumber( aOut, sal_Int32( aGradient.Angle ) ); + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_GRADIENT_ANGLE, aStrValue ); + } + + // Border + SvXMLUnitConverter::convertPercent( aOut, aGradient.Border ); + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_GRADIENT_BORDER, aStrValue ); + + // Do Write + SvXMLElementExport aElem( rExport, XML_NAMESPACE_DRAW, XML_GRADIENT, + sal_True, sal_False ); + } + } + } + + return bRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/HatchStyle.cxx b/xmloff/source/style/HatchStyle.cxx new file mode 100644 index 000000000000..ded1ad105cb7 --- /dev/null +++ b/xmloff/source/style/HatchStyle.cxx @@ -0,0 +1,262 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "xmloff/HatchStyle.hxx" +#include <com/sun/star/drawing/Hatch.hpp> +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmluconv.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlexp.hxx> +#include <xmloff/xmlimp.hxx> +#include <rtl/ustrbuf.hxx> +#include <rtl/ustring.hxx> +#include <tools/debug.hxx> +#include <xmloff/xmltkmap.hxx> + +using namespace ::com::sun::star; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::xmloff::token; + +enum SvXMLTokenMapAttrs +{ + XML_TOK_HATCH_NAME, + XML_TOK_HATCH_DISPLAY_NAME, + XML_TOK_HATCH_STYLE, + XML_TOK_HATCH_COLOR, + XML_TOK_HATCH_DISTANCE, + XML_TOK_HATCH_ROTATION, + XML_TOK_TABSTOP_END=XML_TOK_UNKNOWN +}; + + +SvXMLEnumMapEntry const pXML_HatchStyle_Enum[] = +{ + { XML_HATCHSTYLE_SINGLE, drawing::HatchStyle_SINGLE }, + { XML_HATCHSTYLE_DOUBLE, drawing::HatchStyle_DOUBLE }, + { XML_HATCHSTYLE_TRIPLE, drawing::HatchStyle_TRIPLE }, + { XML_TOKEN_INVALID, 0 } +}; + + +//------------------------------------------------------------- +// Import +//------------------------------------------------------------- + +XMLHatchStyleImport::XMLHatchStyleImport( SvXMLImport& rImp ) + : rImport(rImp) +{ +} + +XMLHatchStyleImport::~XMLHatchStyleImport() +{ +} + +sal_Bool XMLHatchStyleImport::importXML( + const uno::Reference< xml::sax::XAttributeList >& xAttrList, + uno::Any& rValue, + OUString& rStrName ) +{ + sal_Bool bRet = sal_False; + + sal_Bool bHasName = sal_False; + sal_Bool bHasStyle = sal_False; + sal_Bool bHasColor = sal_False; + sal_Bool bHasDist = sal_False; + OUString aDisplayName; + + drawing::Hatch aHatch; + aHatch.Style = drawing::HatchStyle_SINGLE; + aHatch.Color = 0; + aHatch.Distance = 0; + aHatch.Angle = 0; + + { + static SvXMLTokenMapEntry aHatchAttrTokenMap[] = +{ + { XML_NAMESPACE_DRAW, XML_NAME, XML_TOK_HATCH_NAME }, + { XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, XML_TOK_HATCH_DISPLAY_NAME }, + { XML_NAMESPACE_DRAW, XML_STYLE, XML_TOK_HATCH_STYLE }, + { XML_NAMESPACE_DRAW, XML_COLOR, XML_TOK_HATCH_COLOR }, + { XML_NAMESPACE_DRAW, XML_HATCH_DISTANCE, XML_TOK_HATCH_DISTANCE }, + { XML_NAMESPACE_DRAW, XML_ROTATION, XML_TOK_HATCH_ROTATION }, + XML_TOKEN_MAP_END +}; + + SvXMLTokenMap aTokenMap( aHatchAttrTokenMap ); + SvXMLNamespaceMap rNamespaceMap = rImport.GetNamespaceMap(); + SvXMLUnitConverter& rUnitConverter = rImport.GetMM100UnitConverter(); + + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rFullAttrName = xAttrList->getNameByIndex( i ); + OUString aStrAttrName; + sal_uInt16 nPrefix = rNamespaceMap.GetKeyByAttrName( rFullAttrName, &aStrAttrName ); + const OUString& rStrValue = xAttrList->getValueByIndex( i ); + + switch( aTokenMap.Get( nPrefix, aStrAttrName ) ) + { + case XML_TOK_HATCH_NAME: + { + rStrName = rStrValue; + bHasName = sal_True; + } + break; + case XML_TOK_HATCH_DISPLAY_NAME: + aDisplayName = rStrValue; + break; + case XML_TOK_HATCH_STYLE: + { + sal_uInt16 eValue; + bHasStyle = rUnitConverter.convertEnum( eValue, rStrValue, pXML_HatchStyle_Enum ); + if( bHasStyle ) + aHatch.Style = (drawing::HatchStyle) eValue; + } + break; + case XML_TOK_HATCH_COLOR: + { + Color aColor; + bHasColor = rUnitConverter.convertColor( aColor, rStrValue ); + if( bHasColor ) + aHatch.Color = (sal_Int32)( aColor.GetColor() ); + } + break; + case XML_TOK_HATCH_DISTANCE: + bHasDist = rUnitConverter.convertMeasure( (sal_Int32&)aHatch.Distance, rStrValue ); + break; + case XML_TOK_HATCH_ROTATION: + { + sal_Int32 nValue; + rUnitConverter.convertNumber( nValue, rStrValue, 0, 3600 ); + aHatch.Angle = sal_Int16( nValue ); + } + break; + + default: + DBG_WARNING( "Unknown token at import hatch style" ) + ; + } + } + + rValue <<= aHatch; + + if( aDisplayName.getLength() ) + { + rImport.AddStyleDisplayName( XML_STYLE_FAMILY_SD_HATCH_ID, rStrName, + aDisplayName ); + rStrName = aDisplayName; + } + + bRet = bHasName && bHasStyle && bHasColor && bHasDist; + + } + + return bRet; +} + + +//------------------------------------------------------------- +// Export +//------------------------------------------------------------- + +XMLHatchStyleExport::XMLHatchStyleExport( SvXMLExport& rExp ) + : rExport(rExp) +{ +} + +XMLHatchStyleExport::~XMLHatchStyleExport() +{ +} + +sal_Bool XMLHatchStyleExport::exportXML( + const OUString& rStrName, + const uno::Any& rValue ) +{ + sal_Bool bRet = sal_False; + drawing::Hatch aHatch; + + if( rStrName.getLength() ) + { + if( rValue >>= aHatch ) + { + OUString aStrValue; + OUStringBuffer aOut; + + SvXMLUnitConverter& rUnitConverter = + rExport.GetMM100UnitConverter(); + + // Style + if( !rUnitConverter.convertEnum( aOut, aHatch.Style, pXML_HatchStyle_Enum ) ) + { + bRet = sal_False; + } + else + { + // Name + sal_Bool bEncoded = sal_False; + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME, + rExport.EncodeStyleName( rStrName, + &bEncoded ) ); + if( bEncoded ) + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, + rStrName ); + + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_STYLE, aStrValue ); + + // Color + rUnitConverter.convertColor( aOut, Color( aHatch.Color ) ); + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_COLOR, aStrValue ); + + // Distance + rUnitConverter.convertMeasure( aOut, aHatch.Distance ); + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_HATCH_DISTANCE, aStrValue ); + + // Angle + rUnitConverter.convertNumber( aOut, sal_Int32( aHatch.Angle ) ); + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_ROTATION, aStrValue ); + + // Do Write + SvXMLElementExport rElem( rExport, XML_NAMESPACE_DRAW, XML_HATCH, + sal_True, sal_False ); + } + } + } + + return bRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/ImageStyle.cxx b/xmloff/source/style/ImageStyle.cxx new file mode 100644 index 000000000000..f306ede9eaa3 --- /dev/null +++ b/xmloff/source/style/ImageStyle.cxx @@ -0,0 +1,209 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "xmloff/ImageStyle.hxx" +#include <com/sun/star/awt/XBitmap.hpp> +#include <xmloff/attrlist.hxx> +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmluconv.hxx> +#include"xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlexp.hxx> +#include <xmloff/xmlimp.hxx> +#include <rtl/ustrbuf.hxx> +#include <rtl/ustring.hxx> +#include <tools/debug.hxx> +#include <xmloff/xmltkmap.hxx> + +using namespace ::com::sun::star; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::xmloff::token; + +enum SvXMLTokenMapAttrs +{ + XML_TOK_IMAGE_NAME, + XML_TOK_IMAGE_DISPLAY_NAME, + XML_TOK_IMAGE_URL, + XML_TOK_IMAGE_TYPE, + XML_TOK_IMAGE_SHOW, + XML_TOK_IMAGE_ACTUATE, + XML_TOK_TABSTOP_END=XML_TOK_UNKNOWN +}; + + +XMLImageStyle::XMLImageStyle() +{ +} + +XMLImageStyle::~XMLImageStyle() +{ +} + +sal_Bool XMLImageStyle::exportXML( const OUString& rStrName, const ::com::sun::star::uno::Any& rValue, SvXMLExport& rExport ) +{ + return ImpExportXML( rStrName, rValue, rExport ); +} + +sal_Bool XMLImageStyle::ImpExportXML( const OUString& rStrName, const uno::Any& rValue, SvXMLExport& rExport ) +{ + sal_Bool bRet = sal_False; + + OUString sImageURL; + + if( rStrName.getLength() ) + { + if( rValue >>= sImageURL ) + { + OUString aStrValue; + OUStringBuffer aOut; + + // Name + sal_Bool bEncoded = sal_False; + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME, + rExport.EncodeStyleName( rStrName, + &bEncoded ) ); + if( bEncoded ) + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, + rStrName ); + + // uri + const OUString aStr( rExport.AddEmbeddedGraphicObject( sImageURL ) ); + if( aStr.getLength() ) + { + rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, aStr ); + rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE ); + rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED ); + rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD ); + } + + // Do Write + SvXMLElementExport aElem( rExport, XML_NAMESPACE_DRAW, XML_FILL_IMAGE, sal_True, sal_True ); + + if( sImageURL.getLength() ) + { + // optional office:binary-data + rExport.AddEmbeddedGraphicObjectAsBase64( sImageURL ); + } + } + } + + return bRet; +} + +sal_Bool XMLImageStyle::importXML( const uno::Reference< xml::sax::XAttributeList >& xAttrList, uno::Any& rValue, OUString& rStrName, SvXMLImport& rImport ) +{ + return ImpImportXML( xAttrList, rValue, rStrName, rImport ); +} + +sal_Bool XMLImageStyle::ImpImportXML( const uno::Reference< xml::sax::XAttributeList >& xAttrList, + uno::Any& rValue, OUString& rStrName, + SvXMLImport& rImport ) +{ + sal_Bool bRet = sal_False; + sal_Bool bHasHRef = sal_False; + sal_Bool bHasName = sal_False; + OUString aStrURL; + OUString aDisplayName; + + { + static SvXMLTokenMapEntry aHatchAttrTokenMap[] = +{ + { XML_NAMESPACE_DRAW, XML_NAME, XML_TOK_IMAGE_NAME }, + { XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, XML_TOK_IMAGE_DISPLAY_NAME }, + { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_IMAGE_URL }, + { XML_NAMESPACE_XLINK, XML_TYPE, XML_TOK_IMAGE_TYPE }, + { XML_NAMESPACE_XLINK, XML_SHOW, XML_TOK_IMAGE_SHOW }, + { XML_NAMESPACE_XLINK, XML_ACTUATE, XML_TOK_IMAGE_ACTUATE }, + XML_TOKEN_MAP_END +}; + + SvXMLTokenMap aTokenMap( aHatchAttrTokenMap ); + + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rFullAttrName = xAttrList->getNameByIndex( i ); + OUString aStrAttrName; + sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( rFullAttrName, &aStrAttrName ); + const OUString& rStrValue = xAttrList->getValueByIndex( i ); + + switch( aTokenMap.Get( nPrefix, aStrAttrName ) ) + { + case XML_TOK_IMAGE_NAME: + { + rStrName = rStrValue; + bHasName = sal_True; + } + break; + case XML_TOK_IMAGE_DISPLAY_NAME: + { + aDisplayName = rStrValue; + } + break; + case XML_TOK_IMAGE_URL: + { + aStrURL = rImport.ResolveGraphicObjectURL( rStrValue, sal_False ); + bHasHRef = sal_True; + } + break; + case XML_TOK_IMAGE_TYPE: + // ignore + break; + case XML_TOK_IMAGE_SHOW: + // ignore + break; + case XML_TOK_IMAGE_ACTUATE: + // ignore + break; + default: + DBG_WARNING( "Unknown token at import fill bitmap style" ) + ; + } + } + + rValue <<= aStrURL; + + if( aDisplayName.getLength() ) + { + rImport.AddStyleDisplayName( XML_STYLE_FAMILY_SD_FILL_IMAGE_ID, + rStrName, aDisplayName ); + rStrName = aDisplayName; + } + + bRet = bHasName && bHasHRef; + + } + + return bRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/MarkerStyle.cxx b/xmloff/source/style/MarkerStyle.cxx new file mode 100644 index 000000000000..5cacaf44b08b --- /dev/null +++ b/xmloff/source/style/MarkerStyle.cxx @@ -0,0 +1,285 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "xmloff/MarkerStyle.hxx" +#include "xexptran.hxx" +#include <xmloff/attrlist.hxx> +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmluconv.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlexp.hxx> +#include <xmloff/xmlimp.hxx> +#include <rtl/ustrbuf.hxx> +#include <rtl/ustring.hxx> +#include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp> + +using namespace ::com::sun::star; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::xmloff::token; + + +//------------------------------------------------------------- +// Import +//------------------------------------------------------------- + +XMLMarkerStyleImport::XMLMarkerStyleImport( SvXMLImport& rImp ) + : rImport( rImp ) +{ +} + +XMLMarkerStyleImport::~XMLMarkerStyleImport() +{ +} + +sal_Bool XMLMarkerStyleImport::importXML( + const uno::Reference< xml::sax::XAttributeList >& xAttrList, + uno::Any& rValue, + OUString& rStrName ) +{ + sal_Bool bHasViewBox = sal_False; + sal_Bool bHasPathData = sal_False; + OUString aDisplayName; + + SdXMLImExViewBox* pViewBox = NULL; + + SvXMLNamespaceMap& rNamespaceMap = rImport.GetNamespaceMap(); + SvXMLUnitConverter& rUnitConverter = rImport.GetMM100UnitConverter(); + + OUString strPathData; + + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i = 0; i < nAttrCount; i++ ) + { + OUString aStrFullAttrName = xAttrList->getNameByIndex( i ); + OUString aStrAttrName; + rNamespaceMap.GetKeyByAttrName( aStrFullAttrName, &aStrAttrName ); + OUString aStrValue = xAttrList->getValueByIndex( i ); + + if( IsXMLToken( aStrAttrName, XML_NAME ) ) + { + rStrName = aStrValue; + } + else if( IsXMLToken( aStrAttrName, XML_DISPLAY_NAME ) ) + { + aDisplayName = aStrValue; + } + else if( IsXMLToken( aStrAttrName, XML_VIEWBOX ) ) + { + pViewBox = new SdXMLImExViewBox( aStrValue, rUnitConverter ); + bHasViewBox = sal_True; + + } + else if( IsXMLToken( aStrAttrName, XML_D ) ) + { + strPathData = aStrValue; + bHasPathData = sal_True; + } + } + + if( bHasViewBox && bHasPathData ) + { + SdXMLImExSvgDElement aPoints(strPathData, *pViewBox, awt::Point( 0, 0 ), + awt::Size( pViewBox->GetWidth(), pViewBox->GetHeight() ), + rUnitConverter ); + + if(aPoints.IsCurve()) + { + drawing::PolyPolygonBezierCoords aSourcePolyPolygon( + aPoints.GetPointSequenceSequence(), + aPoints.GetFlagSequenceSequence()); + rValue <<= aSourcePolyPolygon; + } + else + { + drawing::PolyPolygonBezierCoords aSourcePolyPolygon; + aSourcePolyPolygon.Coordinates = aPoints.GetPointSequenceSequence(); + aSourcePolyPolygon.Flags.realloc(aSourcePolyPolygon.Coordinates.getLength()); + + // Zeiger auf innere sequences holen + const drawing::PointSequence* pInnerSequence = aSourcePolyPolygon.Coordinates.getConstArray(); + drawing::FlagSequence* pInnerSequenceFlags = aSourcePolyPolygon.Flags.getArray(); + + for(sal_Int32 a(0); a < aSourcePolyPolygon.Coordinates.getLength(); a++) + { + pInnerSequenceFlags->realloc(pInnerSequence->getLength()); + drawing::PolygonFlags* pPolyFlags = pInnerSequenceFlags->getArray(); + + for(sal_Int32 b(0); b < pInnerSequence->getLength(); b++) + *pPolyFlags++ = drawing::PolygonFlags_NORMAL; + + // next run + pInnerSequence++; + pInnerSequenceFlags++; + } + + rValue <<= aSourcePolyPolygon; + } + + if( aDisplayName.getLength() ) + { + rImport.AddStyleDisplayName( XML_STYLE_FAMILY_SD_MARKER_ID, rStrName, + aDisplayName ); + rStrName = aDisplayName; + } + + } + + if( pViewBox ) + delete pViewBox; + + return bHasViewBox && bHasPathData; +} + + +//------------------------------------------------------------- +// Export +//------------------------------------------------------------- + +XMLMarkerStyleExport::XMLMarkerStyleExport( SvXMLExport& rExp ) + : rExport( rExp ) +{ +} + +XMLMarkerStyleExport::~XMLMarkerStyleExport() +{ +} + +sal_Bool XMLMarkerStyleExport::exportXML( + const OUString& rStrName, + const uno::Any& rValue ) +{ + sal_Bool bRet(sal_False); + + if(rStrName.getLength()) + { + drawing::PolyPolygonBezierCoords aBezier; + + if(rValue >>= aBezier) + { + OUString aStrValue; + OUStringBuffer aOut; + + ///////////////// + // Name + sal_Bool bEncoded = sal_False; + OUString aStrName( rStrName ); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME, + rExport.EncodeStyleName( aStrName, + &bEncoded ) ); + if( bEncoded ) + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, + aStrName ); + + ///////////////// + // Viewbox (viewBox="0 0 1500 1000") + sal_Int32 nMinX(0x7fffffff); + sal_Int32 nMaxX(0x80000000); + sal_Int32 nMinY(0x7fffffff); + sal_Int32 nMaxY(0x80000000); + sal_Int32 nOuterCnt(aBezier.Coordinates.getLength()); + drawing::PointSequence* pOuterSequence = aBezier.Coordinates.getArray(); + sal_Int32 a, b; + sal_Bool bClosed(sal_False); + + for (a = 0; a < nOuterCnt; a++) + { + drawing::PointSequence* pSequence = pOuterSequence++; + const awt::Point *pPoints = pSequence->getConstArray(); + sal_Int32 nPointCount(pSequence->getLength()); + + if(nPointCount) + { + const awt::Point aStart = pPoints[0]; + const awt::Point aEnd = pPoints[nPointCount - 1]; + + if(aStart.X == aEnd.X && aStart.Y == aEnd.Y) + { + bClosed = sal_True; + } + } + + for (b = 0; b < nPointCount; b++) + { + const awt::Point aPoint = pPoints[b]; + + if( aPoint.X < nMinX ) + nMinX = aPoint.X; + + if( aPoint.X > nMaxX ) + nMaxX = aPoint.X; + + if( aPoint.Y < nMinY ) + nMinY = aPoint.Y; + + if( aPoint.Y > nMaxY ) + nMaxY = aPoint.Y; + } + } + + sal_Int32 nDifX(nMaxX - nMinX); + sal_Int32 nDifY(nMaxY - nMinY); + + SdXMLImExViewBox aViewBox( 0, 0, nDifX, nDifY ); + rExport.AddAttribute( XML_NAMESPACE_SVG, XML_VIEWBOX, aViewBox.GetExportString() ); + + ///////////////// + // Pathdata + pOuterSequence = aBezier.Coordinates.getArray(); + drawing::FlagSequence* pOuterFlags = aBezier.Flags.getArray(); + SdXMLImExSvgDElement aSvgDElement(aViewBox); + + for (a = 0; a < nOuterCnt; a++) + { + drawing::PointSequence* pSequence = pOuterSequence++; + drawing::FlagSequence* pFlags = pOuterFlags++; + + aSvgDElement.AddPolygon(pSequence, pFlags, + awt::Point( 0, 0 ), + awt::Size( aViewBox.GetWidth(), aViewBox.GetHeight() ), + bClosed); + } + + // write point array + rExport.AddAttribute(XML_NAMESPACE_SVG, XML_D, aSvgDElement.GetExportString()); + + ///////////////// + // Do Write + SvXMLElementExport rElem( rExport, XML_NAMESPACE_DRAW, XML_MARKER, + sal_True, sal_False ); + } + } + + return bRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/MultiPropertySetHelper.cxx b/xmloff/source/style/MultiPropertySetHelper.cxx new file mode 100644 index 000000000000..dc5e2eee6cc7 --- /dev/null +++ b/xmloff/source/style/MultiPropertySetHelper.cxx @@ -0,0 +1,217 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + +#include "MultiPropertySetHelper.hxx" +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XMultiPropertySet.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <comphelper/stl_types.hxx> + +// STL includes +#include <algorithm> + + +using ::com::sun::star::beans::XMultiPropertySet; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::beans::XPropertySetInfo; +using ::com::sun::star::lang::XServiceInfo; +using ::com::sun::star::uno::Any; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::UNO_QUERY; +using ::comphelper::UStringLess; +using ::rtl::OUString; +using ::std::sort; + + +MultiPropertySetHelper::MultiPropertySetHelper( + const sal_Char** pNames ) : + pPropertyNames( NULL ), + nLength( 0 ), + aPropertySequence(), + pSequenceIndex( NULL ), + aValues(), + pValues( NULL ) +{ + // first count the elements + for( const sal_Char** pPtr = pNames; *pPtr != NULL; pPtr++ ) + nLength++; + + // allocate array and create strings + pPropertyNames = new OUString[nLength]; + for( sal_Int16 i = 0; i < nLength; i++ ) + pPropertyNames[i] = OUString::createFromAscii( pNames[i] ); +} + +MultiPropertySetHelper::MultiPropertySetHelper( + const OUString* pNames ) : + pPropertyNames( NULL ), + nLength( 0 ), + aPropertySequence(), + pSequenceIndex( NULL ), + aValues(), + pValues( NULL ) +{ + // count elements + for( const OUString* pPtr = pNames; pPtr != NULL; pPtr++ ) + nLength++; + + // allocate array and assign strings + pPropertyNames = new OUString[nLength]; + for( sal_Int16 i = 0; i < nLength; i++ ) + pPropertyNames[i] = pNames[i]; +} + + +MultiPropertySetHelper::~MultiPropertySetHelper() +{ + pValues = NULL; // memory 'owned' by aValues + + delete[] pSequenceIndex; + delete[] pPropertyNames; +} + + + +void MultiPropertySetHelper::hasProperties( + const Reference<XPropertySetInfo> & rInfo ) +{ + DBG_ASSERT( rInfo.is(), "I'd really like an XPropertySetInfo here." ); + + // allocate sequence index + if ( NULL == pSequenceIndex ) + pSequenceIndex = new sal_Int16[nLength] ; + + // construct pSequenceIndex + sal_Int16 nNumberOfProperties = 0; + sal_Int16 i; + + for( i = 0; i < nLength; i++ ) + { + // ask for property + sal_Bool bHasProperty = + rInfo->hasPropertyByName( pPropertyNames[i] ); + + // set index and increment (if appropriate) + pSequenceIndex[i]= bHasProperty ? nNumberOfProperties : -1; + if ( bHasProperty ) + nNumberOfProperties++; + } + + // construct property sequence from index array + if ( aPropertySequence.getLength() != nNumberOfProperties ) + aPropertySequence.realloc( nNumberOfProperties ); + OUString* pPropertySequence = aPropertySequence.getArray(); + for( i = 0; i < nLength; i ++ ) + { + sal_Int16 nIndex = pSequenceIndex[i]; + if ( nIndex != -1 ) + pPropertySequence[nIndex] = pPropertyNames[i]; + } +} + +sal_Bool MultiPropertySetHelper::checkedProperties() +{ + return (NULL != pSequenceIndex); +} + + + +void MultiPropertySetHelper::getValues( + const Reference<XMultiPropertySet> & rMultiPropertySet ) +{ + DBG_ASSERT( rMultiPropertySet.is(), "We need an XMultiPropertySet." ); + + aValues = rMultiPropertySet->getPropertyValues( aPropertySequence ); + pValues = aValues.getConstArray(); +} + +void MultiPropertySetHelper::getValues( + const Reference<XPropertySet> & rPropertySet ) +{ + DBG_ASSERT( rPropertySet.is(), "We need an XPropertySet." ); + + // re-alloc aValues (if necessary) and fill with values from XPropertySet + sal_Int16 nSupportedPropertiesCount = + (sal_Int16)aPropertySequence.getLength(); + if ( aValues.getLength() != nSupportedPropertiesCount ) + aValues.realloc( nSupportedPropertiesCount ); + Any* pMutableArray = aValues.getArray(); + for( sal_Int16 i = 0; i < nSupportedPropertiesCount; i++ ) + { + pMutableArray[i] = rPropertySet->getPropertyValue( + pPropertyNames[ pSequenceIndex[ i ] ] ); + } + + // re-establish pValues pointer + pValues = aValues.getConstArray(); +} + + +const Any& MultiPropertySetHelper::getValue( sal_Int16 nIndex, + const Reference< XPropertySet> & rPropSet, + sal_Bool bTryMulti ) +{ + if( !pValues ) + { + if( bTryMulti ) + { + Reference < XMultiPropertySet > xMultiPropSet( rPropSet, + UNO_QUERY ); + if( xMultiPropSet.is() ) + getValues( xMultiPropSet ); + else + getValues( rPropSet ); + } + else + { + getValues( rPropSet ); + } + } + + return getValue( nIndex ); +} + +const Any& MultiPropertySetHelper::getValue( sal_Int16 nIndex, + const Reference< XMultiPropertySet> & rMultiPropSet ) +{ + if( !pValues ) + getValues( rMultiPropSet ); + + return getValue( nIndex ); +} + +// inline methods defined in header: +// inline Any& MultiPropertySetHelper::getValue( sal_Int16 nIndex ) +// inline sal_Bool MultiPropertySetHelper::hasProperty( sal_Int16 nValueNo ) + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/NamedBoolPropertyHdl.cxx b/xmloff/source/style/NamedBoolPropertyHdl.cxx new file mode 100644 index 000000000000..8f008a65751e --- /dev/null +++ b/xmloff/source/style/NamedBoolPropertyHdl.cxx @@ -0,0 +1,84 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <xmloff/NamedBoolPropertyHdl.hxx> +#include <xmloff/xmluconv.hxx> +#include <comphelper/extract.hxx> +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/Any.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star::uno; + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLNamedBoolPropertyHdl +// + +XMLNamedBoolPropertyHdl::~XMLNamedBoolPropertyHdl() +{ + // Nothing to do +} + +sal_Bool XMLNamedBoolPropertyHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const +{ + if( rStrImpValue == maTrueStr ) + { + rValue = ::cppu::bool2any( sal_True ); + return sal_True; + } + + if( rStrImpValue == maFalseStr ) + { + rValue = ::cppu::bool2any( sal_False ); + return sal_True; + } + + return sal_False; +} + +sal_Bool XMLNamedBoolPropertyHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + if( ::cppu::any2bool( rValue ) ) + { + rStrExpValue = maTrueStr; + } + else + { + rStrExpValue = maFalseStr; + } + + return sal_True; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/PageHeaderFooterContext.cxx b/xmloff/source/style/PageHeaderFooterContext.cxx new file mode 100644 index 000000000000..5661ec44c16a --- /dev/null +++ b/xmloff/source/style/PageHeaderFooterContext.cxx @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + + + +// INCLUDE --------------------------------------------------------------- + +#include "PageHeaderFooterContext.hxx" +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include "PagePropertySetContext.hxx" + +using namespace com::sun::star; +using ::xmloff::token::IsXMLToken; +using ::xmloff::token::XML_HEADER_FOOTER_PROPERTIES; + +//------------------------------------------------------------------ + +PageHeaderFooterContext::PageHeaderFooterContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, + const rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList>&, + ::std::vector< XMLPropertyState > & rTempProperties, + const UniReference < SvXMLImportPropertyMapper > &rTempMap, + sal_Int32 nStart, sal_Int32 nEnd, + const sal_Bool bTempHeader ) : + SvXMLImportContext( rImport, nPrfx, rLName ), + rProperties(rTempProperties), + nStartIndex(nStart), + nEndIndex(nEnd), + rMap(rTempMap) +{ + bHeader = bTempHeader; +} + +PageHeaderFooterContext::~PageHeaderFooterContext() +{ +} + +SvXMLImportContext *PageHeaderFooterContext::CreateChildContext( sal_uInt16 nPrefix, + const rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList>& xAttrList ) +{ + SvXMLImportContext *pContext = 0; + + if( XML_NAMESPACE_STYLE == nPrefix && IsXMLToken( rLName, XML_HEADER_FOOTER_PROPERTIES ) ) + { + PageContextType aType = Header; + if (!bHeader) + aType = Footer; + pContext = new PagePropertySetContext( GetImport(), nPrefix, + rLName, xAttrList, + XML_TYPE_PROP_HEADER_FOOTER, + rProperties, + rMap, nStartIndex, nEndIndex, aType); + } + + + if( !pContext ) + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName ); + + return pContext; +} + +void PageHeaderFooterContext::EndElement() +{ +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/PageHeaderFooterContext.hxx b/xmloff/source/style/PageHeaderFooterContext.hxx new file mode 100644 index 000000000000..b47b99577ccd --- /dev/null +++ b/xmloff/source/style/PageHeaderFooterContext.hxx @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _XMLOFF_PAGEHEADERFOOTERCONTEXT_HXX +#define _XMLOFF_PAGEHEADERFOOTERCONTEXT_HXX + +#include <xmloff/xmlimp.hxx> + +class PageHeaderFooterContext : public SvXMLImportContext +{ + ::std::vector< XMLPropertyState > & rProperties; + sal_Int32 nStartIndex; + sal_Int32 nEndIndex; + sal_Bool bHeader; + const UniReference < SvXMLImportPropertyMapper > rMap; + +public: + + PageHeaderFooterContext( SvXMLImport& rImport, sal_uInt16 nPrfx, + const rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList>& xAttrList, + ::std::vector< XMLPropertyState > & rProperties, + const UniReference < SvXMLImportPropertyMapper > &rMap, + sal_Int32 nStartIndex, sal_Int32 nEndIndex, + const sal_Bool bHeader); + + virtual ~PageHeaderFooterContext(); + + virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList>& xAttrList ); + + virtual void EndElement(); +}; + +#endif + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/PageMasterExportPropMapper.cxx b/xmloff/source/style/PageMasterExportPropMapper.cxx new file mode 100644 index 000000000000..6a9b9d1d7a2f --- /dev/null +++ b/xmloff/source/style/PageMasterExportPropMapper.cxx @@ -0,0 +1,446 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "PageMasterExportPropMapper.hxx" +#include <xmloff/xmltoken.hxx> +#include <comphelper/types.hxx> +#include <com/sun/star/table/BorderLine2.hpp> +#include <xmloff/PageMasterStyleMap.hxx> +#include <tools/debug.hxx> +#include <rtl/ustrbuf.hxx> +#include <comphelper/extract.hxx> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::comphelper; +using namespace ::xmloff::token; + + +//______________________________________________________________________________ + +inline sal_Bool lcl_HasSameLineWidth( const table::BorderLine2& rLine1, const table::BorderLine2& rLine2 ) +{ + return (rLine1.InnerLineWidth == rLine2.InnerLineWidth) && + (rLine1.OuterLineWidth == rLine2.OuterLineWidth) && + (rLine1.LineDistance == rLine2.LineDistance) && + (rLine1.LineWidth == rLine2.LineWidth); +} + +inline sal_Bool operator==( const table::BorderLine2& rLine1, const table::BorderLine2& rLine2 ) +{ + return (rLine1.Color == rLine2.Color) && + lcl_HasSameLineWidth( rLine1, rLine2 ) && + ( rLine1.LineStyle == rLine2.LineStyle ); +} + +inline void lcl_RemoveState( XMLPropertyState* pState ) +{ + pState->mnIndex = -1; + pState->maValue.clear(); +} + +void lcl_RemoveStateIfZero16( XMLPropertyState* pState ) +{ + sal_Int16 nValue = sal_Int16(); + if( (pState->maValue >>= nValue) && !nValue ) + lcl_RemoveState( pState ); +} + +void lcl_AddState(::std::vector< XMLPropertyState >& rPropState, sal_Int32 nIndex, const rtl::OUString& rProperty, uno::Reference< beans::XPropertySet >& xProps) +{ + if(::cppu::any2bool(xProps->getPropertyValue(rProperty))) + rPropState.push_back(XMLPropertyState (nIndex, cppu::bool2any(sal_True))); +} + +//______________________________________________________________________________ +// helper struct to handle equal XMLPropertyState's for page, header and footer + +struct XMLPropertyStateBuffer +{ + XMLPropertyState* pPMBorderAll; + XMLPropertyState* pPMBorderTop; + XMLPropertyState* pPMBorderBottom; + XMLPropertyState* pPMBorderLeft; + XMLPropertyState* pPMBorderRight; + + XMLPropertyState* pPMBorderWidthAll; + XMLPropertyState* pPMBorderWidthTop; + XMLPropertyState* pPMBorderWidthBottom; + XMLPropertyState* pPMBorderWidthLeft; + XMLPropertyState* pPMBorderWidthRight; + + XMLPropertyState* pPMPaddingAll; + XMLPropertyState* pPMPaddingTop; + XMLPropertyState* pPMPaddingBottom; + XMLPropertyState* pPMPaddingLeft; + XMLPropertyState* pPMPaddingRight; + + XMLPropertyStateBuffer(); + void ContextFilter( ::std::vector< XMLPropertyState >& rPropState ); +}; + +XMLPropertyStateBuffer::XMLPropertyStateBuffer() : + pPMBorderAll( NULL ), + pPMBorderTop( NULL ), + pPMBorderBottom( NULL ), + pPMBorderLeft( NULL ), + pPMBorderRight( NULL ), + + pPMBorderWidthAll( NULL ), + pPMBorderWidthTop( NULL ), + pPMBorderWidthBottom( NULL ), + pPMBorderWidthLeft( NULL ), + pPMBorderWidthRight( NULL ), + + pPMPaddingAll( NULL ), + pPMPaddingTop( NULL ), + pPMPaddingBottom( NULL ), + pPMPaddingLeft( NULL ), + pPMPaddingRight( NULL ) +{ +} + +void XMLPropertyStateBuffer::ContextFilter( ::std::vector< XMLPropertyState >& ) +{ + if( pPMBorderAll ) + { + if( pPMBorderTop && pPMBorderBottom && pPMBorderLeft && pPMBorderRight ) + { + table::BorderLine2 aLineTop, aLineBottom, aLineLeft, aLineRight; + + pPMBorderTop->maValue >>= aLineTop; + pPMBorderBottom->maValue >>= aLineBottom; + pPMBorderLeft->maValue >>= aLineLeft; + pPMBorderRight->maValue >>= aLineRight; + + if( (aLineTop == aLineBottom) && (aLineBottom == aLineLeft) && (aLineLeft == aLineRight) ) + { + lcl_RemoveState( pPMBorderTop ); + lcl_RemoveState( pPMBorderBottom ); + lcl_RemoveState( pPMBorderLeft ); + lcl_RemoveState( pPMBorderRight ); + } + else + lcl_RemoveState( pPMBorderAll ); + } + else + lcl_RemoveState( pPMBorderAll ); + } + + if( pPMBorderWidthAll ) + { + if( pPMBorderWidthTop && pPMBorderWidthBottom && pPMBorderWidthLeft && pPMBorderWidthRight ) + { + table::BorderLine2 aLineTop, aLineBottom, aLineLeft, aLineRight; + + pPMBorderWidthTop->maValue >>= aLineTop; + pPMBorderWidthBottom->maValue >>= aLineBottom; + pPMBorderWidthLeft->maValue >>= aLineLeft; + pPMBorderWidthRight->maValue >>= aLineRight; + + if( lcl_HasSameLineWidth( aLineTop, aLineBottom ) && + lcl_HasSameLineWidth( aLineBottom, aLineLeft ) && + lcl_HasSameLineWidth( aLineLeft, aLineRight ) ) + { + lcl_RemoveState( pPMBorderWidthTop ); + lcl_RemoveState( pPMBorderWidthBottom ); + lcl_RemoveState( pPMBorderWidthLeft ); + lcl_RemoveState( pPMBorderWidthRight ); + } + else + lcl_RemoveState( pPMBorderWidthAll ); + } + else + lcl_RemoveState( pPMBorderWidthAll ); + } + + if( pPMPaddingAll ) + { + if( pPMPaddingTop && pPMPaddingBottom && pPMPaddingLeft && pPMPaddingRight ) + { + sal_Int32 nTop = 0, nBottom = 0, nLeft = 0, nRight = 0; + + pPMPaddingTop->maValue >>= nTop; + pPMPaddingBottom->maValue >>= nBottom; + pPMPaddingLeft->maValue >>= nLeft; + pPMPaddingRight->maValue >>= nRight; + + if( (nTop == nBottom) && (nBottom == nLeft) && (nLeft == nRight) ) + { + lcl_RemoveState( pPMPaddingTop ); + lcl_RemoveState( pPMPaddingBottom ); + lcl_RemoveState( pPMPaddingLeft ); + lcl_RemoveState( pPMPaddingRight ); + } + else + lcl_RemoveState( pPMPaddingAll ); + } + else + lcl_RemoveState( pPMPaddingAll ); + } +} + +//______________________________________________________________________________ + +XMLPageMasterExportPropMapper::XMLPageMasterExportPropMapper( + const UniReference< XMLPropertySetMapper >& rMapper, + SvXMLExport& rExport ) : + SvXMLExportPropertyMapper( rMapper ), + aBackgroundImageExport( rExport ), + aTextColumnsExport( rExport ), + aFootnoteSeparatorExport( rExport ) +{ +} + +XMLPageMasterExportPropMapper::~XMLPageMasterExportPropMapper() +{ +} + +void XMLPageMasterExportPropMapper::handleElementItem( + SvXMLExport&, + const XMLPropertyState& rProperty, + sal_uInt16 /*nFlags*/, + const ::std::vector< XMLPropertyState >* pProperties, + sal_uInt32 nIdx ) const +{ + XMLPageMasterExportPropMapper* pThis = (XMLPageMasterExportPropMapper*) this; + + sal_uInt32 nContextId = getPropertySetMapper()->GetEntryContextId( rProperty.mnIndex ); + switch( nContextId ) + { + case CTF_PM_GRAPHICURL: + case CTF_PM_HEADERGRAPHICURL: + case CTF_PM_FOOTERGRAPHICURL: + { + DBG_ASSERT( pProperties && (nIdx >= 2), "property vector missing" ); + sal_Int32 nPos; + sal_Int32 nFilter; + switch( nContextId ) + { + case CTF_PM_GRAPHICURL: + nPos = CTF_PM_GRAPHICPOSITION; + nFilter = CTF_PM_GRAPHICFILTER; + break; + case CTF_PM_HEADERGRAPHICURL: + nPos = CTF_PM_HEADERGRAPHICPOSITION; + nFilter = CTF_PM_HEADERGRAPHICFILTER; + break; + case CTF_PM_FOOTERGRAPHICURL: + nPos = CTF_PM_FOOTERGRAPHICPOSITION; + nFilter = CTF_PM_FOOTERGRAPHICFILTER; + break; + default: + nPos = 0; // TODO What values should this be? + nFilter = 0; + } + const Any* pPos = NULL; + const Any* pFilter = NULL; + if( pProperties && (nIdx >= 2) ) + { + const XMLPropertyState& rPos = (*pProperties)[nIdx - 2]; + DBG_ASSERT( getPropertySetMapper()->GetEntryContextId( rPos.mnIndex ) == nPos, + "invalid property map: pos expected" ); + if( getPropertySetMapper()->GetEntryContextId( rPos.mnIndex ) == nPos ) + pPos = &rPos.maValue; + + const XMLPropertyState& rFilter = (*pProperties)[nIdx - 1]; + DBG_ASSERT( getPropertySetMapper()->GetEntryContextId( rFilter.mnIndex ) == nFilter, + "invalid property map: filter expected" ); + if( getPropertySetMapper()->GetEntryContextId( rFilter.mnIndex ) == nFilter ) + pFilter = &rFilter.maValue; + } + sal_uInt32 nPropIndex = rProperty.mnIndex; + pThis->aBackgroundImageExport.exportXML( rProperty.maValue, pPos, pFilter, NULL, + getPropertySetMapper()->GetEntryNameSpace( nPropIndex ), + getPropertySetMapper()->GetEntryXMLName( nPropIndex ) ); + } + break; + case CTF_PM_TEXTCOLUMNS: + pThis->aTextColumnsExport.exportXML( rProperty.maValue ); + break; + case CTF_PM_FTN_LINE_WEIGTH: + pThis->aFootnoteSeparatorExport.exportXML( pProperties, nIdx, + getPropertySetMapper()); + break; + } +} + +void XMLPageMasterExportPropMapper::handleSpecialItem( + SvXMLAttributeList&, + const XMLPropertyState&, + const SvXMLUnitConverter&, + const SvXMLNamespaceMap&, + const ::std::vector< XMLPropertyState >*, + sal_uInt32 /*nIdx*/) const +{ +} + +void XMLPageMasterExportPropMapper::ContextFilter( + ::std::vector< XMLPropertyState >& rPropState, + Reference< XPropertySet > rPropSet ) const +{ + XMLPropertyStateBuffer aPageBuffer; + XMLPropertyStateBuffer aHeaderBuffer; + XMLPropertyStateBuffer aFooterBuffer; + + XMLPropertyState* pPMHeaderHeight = NULL; + XMLPropertyState* pPMHeaderMinHeight = NULL; + XMLPropertyState* pPMHeaderDynamic = NULL; + + XMLPropertyState* pPMFooterHeight = NULL; + XMLPropertyState* pPMFooterMinHeight = NULL; + XMLPropertyState* pPMFooterDynamic = NULL; + + XMLPropertyState* pPMScaleTo = NULL; + XMLPropertyState* pPMScaleToPages = NULL; + XMLPropertyState* pPMScaleToX = NULL; + XMLPropertyState* pPMScaleToY = NULL; + XMLPropertyState* pPMStandardMode = NULL; + XMLPropertyState* pPMGridBaseWidth = NULL; + XMLPropertyState* pPMGridSnapToChars = NULL; + + XMLPropertyState* pPrint = NULL; + + UniReference < XMLPropertySetMapper > aPropMapper(getPropertySetMapper()); + + for( ::std::vector< XMLPropertyState >::iterator aIter = rPropState.begin(); aIter != rPropState.end(); ++aIter ) + { + XMLPropertyState *pProp = &(*aIter); + sal_Int16 nContextId = aPropMapper->GetEntryContextId( pProp->mnIndex ); + sal_Int16 nFlag = nContextId & CTF_PM_FLAGMASK; + sal_Int16 nSimpleId = nContextId & (~CTF_PM_FLAGMASK | XML_PM_CTF_START); + sal_Int16 nPrintId = nContextId & CTF_PM_PRINTMASK; + + XMLPropertyStateBuffer* pBuffer; + switch( nFlag ) + { + case CTF_PM_HEADERFLAG: pBuffer = &aHeaderBuffer; break; + case CTF_PM_FOOTERFLAG: pBuffer = &aFooterBuffer; break; + default: pBuffer = &aPageBuffer; break; + } + + switch( nSimpleId ) + { + case CTF_PM_BORDERALL: pBuffer->pPMBorderAll = pProp; break; + case CTF_PM_BORDERTOP: pBuffer->pPMBorderTop = pProp; break; + case CTF_PM_BORDERBOTTOM: pBuffer->pPMBorderBottom = pProp; break; + case CTF_PM_BORDERLEFT: pBuffer->pPMBorderLeft = pProp; break; + case CTF_PM_BORDERRIGHT: pBuffer->pPMBorderRight = pProp; break; + case CTF_PM_BORDERWIDTHALL: pBuffer->pPMBorderWidthAll = pProp; break; + case CTF_PM_BORDERWIDTHTOP: pBuffer->pPMBorderWidthTop = pProp; break; + case CTF_PM_BORDERWIDTHBOTTOM: pBuffer->pPMBorderWidthBottom = pProp; break; + case CTF_PM_BORDERWIDTHLEFT: pBuffer->pPMBorderWidthLeft = pProp; break; + case CTF_PM_BORDERWIDTHRIGHT: pBuffer->pPMBorderWidthRight = pProp; break; + case CTF_PM_PADDINGALL: pBuffer->pPMPaddingAll = pProp; break; + case CTF_PM_PADDINGTOP: pBuffer->pPMPaddingTop = pProp; break; + case CTF_PM_PADDINGBOTTOM: pBuffer->pPMPaddingBottom = pProp; break; + case CTF_PM_PADDINGLEFT: pBuffer->pPMPaddingLeft = pProp; break; + case CTF_PM_PADDINGRIGHT: pBuffer->pPMPaddingRight = pProp; break; + } + + switch( nContextId ) + { + case CTF_PM_HEADERHEIGHT: pPMHeaderHeight = pProp; break; + case CTF_PM_HEADERMINHEIGHT: pPMHeaderMinHeight = pProp; break; + case CTF_PM_HEADERDYNAMIC: pPMHeaderDynamic = pProp; break; + case CTF_PM_FOOTERHEIGHT: pPMFooterHeight = pProp; break; + case CTF_PM_FOOTERMINHEIGHT: pPMFooterMinHeight = pProp; break; + case CTF_PM_FOOTERDYNAMIC: pPMFooterDynamic = pProp; break; + case CTF_PM_SCALETO: pPMScaleTo = pProp; break; + case CTF_PM_SCALETOPAGES: pPMScaleToPages = pProp; break; + case CTF_PM_SCALETOX: pPMScaleToX = pProp; break; + case CTF_PM_SCALETOY: pPMScaleToY = pProp; break; + case CTF_PM_STANDARD_MODE: pPMStandardMode = pProp; break; + case CTP_PM_GRID_BASE_WIDTH: pPMGridBaseWidth = pProp; break; + case CTP_PM_GRID_SNAP_TO_CHARS: pPMGridSnapToChars = pProp; break; + } + if (nPrintId == CTF_PM_PRINTMASK) + { + pPrint = pProp; + lcl_RemoveState(pPrint); + } + } + + if( pPMStandardMode && !getBOOL(pPMStandardMode->maValue) ) + { + lcl_RemoveState(pPMStandardMode); + if( pPMGridBaseWidth ) + lcl_RemoveState(pPMGridBaseWidth); + if( pPMGridSnapToChars ) + lcl_RemoveState(pPMGridSnapToChars); + } + + if( pPMGridBaseWidth && pPMStandardMode ) + lcl_RemoveState(pPMStandardMode); + + aPageBuffer.ContextFilter( rPropState ); + aHeaderBuffer.ContextFilter( rPropState ); + aFooterBuffer.ContextFilter( rPropState ); + + if( pPMHeaderHeight && (!pPMHeaderDynamic || (pPMHeaderDynamic && getBOOL( pPMHeaderDynamic->maValue ))) ) + lcl_RemoveState( pPMHeaderHeight ); + if( pPMHeaderMinHeight && pPMHeaderDynamic && !getBOOL( pPMHeaderDynamic->maValue ) ) + lcl_RemoveState( pPMHeaderMinHeight ); + if( pPMHeaderDynamic ) + lcl_RemoveState( pPMHeaderDynamic ); + + if( pPMFooterHeight && (!pPMFooterDynamic || (pPMFooterDynamic && getBOOL( pPMFooterDynamic->maValue ))) ) + lcl_RemoveState( pPMFooterHeight ); + if( pPMFooterMinHeight && pPMFooterDynamic && !getBOOL( pPMFooterDynamic->maValue ) ) + lcl_RemoveState( pPMFooterMinHeight ); + if( pPMFooterDynamic ) + lcl_RemoveState( pPMFooterDynamic ); + + if( pPMScaleTo ) + lcl_RemoveStateIfZero16( pPMScaleTo ); + if( pPMScaleToPages ) + lcl_RemoveStateIfZero16( pPMScaleToPages ); + if( pPMScaleToX ) + lcl_RemoveStateIfZero16( pPMScaleToX ); + if( pPMScaleToY ) + lcl_RemoveStateIfZero16( pPMScaleToY ); + + if (pPrint) + { + lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_ANNOTATIONS), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintAnnotations")), rPropSet); + lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_CHARTS), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintCharts")), rPropSet); + lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_DRAWING), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintDrawing")), rPropSet); + lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_FORMULAS), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintFormulas")), rPropSet); + lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_GRID), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintGrid")), rPropSet); + lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_HEADERS), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintHeaders")), rPropSet); + lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_OBJECTS), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintObjects")), rPropSet); + lcl_AddState(rPropState, aPropMapper->FindEntryIndex(CTF_PM_PRINT_ZEROVALUES), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PrintZeroValues")), rPropSet); + } + + SvXMLExportPropertyMapper::ContextFilter(rPropState,rPropSet); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/PageMasterExportPropMapper.hxx b/xmloff/source/style/PageMasterExportPropMapper.hxx new file mode 100644 index 000000000000..20617b0726de --- /dev/null +++ b/xmloff/source/style/PageMasterExportPropMapper.hxx @@ -0,0 +1,81 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PAGEMASTEREXPORTPROPMAPPER_HXX +#define _XMLOFF_PAGEMASTEREXPORTPROPMAPPER_HXX + +#include <xmloff/xmlexppr.hxx> +#include "XMLBackgroundImageExport.hxx" +#include "XMLTextColumnsExport.hxx" +#include "XMLFootnoteSeparatorExport.hxx" + +//______________________________________________________________________________ + +class XMLPageMasterExportPropMapper : public SvXMLExportPropertyMapper +{ +protected: + XMLBackgroundImageExport aBackgroundImageExport; + XMLTextColumnsExport aTextColumnsExport; + XMLFootnoteSeparatorExport aFootnoteSeparatorExport; + + virtual void ContextFilter( + ::std::vector< XMLPropertyState >& rProperties, + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rPropSet + ) const; + +public: + XMLPageMasterExportPropMapper( + const UniReference< XMLPropertySetMapper >& rMapper, + SvXMLExport& rExport + ); + virtual ~XMLPageMasterExportPropMapper(); + + virtual void handleElementItem( + SvXMLExport& rExport, + const XMLPropertyState& rProperty, + sal_uInt16 nFlags, + const ::std::vector< XMLPropertyState >* pProperties = 0, + sal_uInt32 nIdx = 0 + ) const; + virtual void handleSpecialItem( + SvXMLAttributeList& rAttrList, + const XMLPropertyState& rProperty, + const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& rNamespaceMap, + const ::std::vector< XMLPropertyState >* pProperties = 0, + sal_uInt32 nIdx = 0 + ) const; + + inline XMLBackgroundImageExport& GetBackgroundImageExport() + { return aBackgroundImageExport; } + +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/PageMasterImportContext.cxx b/xmloff/source/style/PageMasterImportContext.cxx new file mode 100644 index 000000000000..fbaff859da3f --- /dev/null +++ b/xmloff/source/style/PageMasterImportContext.cxx @@ -0,0 +1,197 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include "PageMasterImportContext.hxx" +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include "PageMasterPropHdl.hxx" +#include "PagePropertySetContext.hxx" +#include "PageHeaderFooterContext.hxx" +#include "PageMasterPropMapper.hxx" +#include "PageMasterImportPropMapper.hxx" +#include <xmloff/PageMasterStyleMap.hxx> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +using namespace ::com::sun::star; +using namespace ::xmloff::token; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; + +void PageStyleContext::SetAttribute( sal_uInt16 nPrefixKey, + const rtl::OUString& rLocalName, + const rtl::OUString& rValue ) +{ + // TODO: use a map here + if( XML_NAMESPACE_STYLE == nPrefixKey && IsXMLToken( rLocalName, XML_PAGE_USAGE ) ) + { + sPageUsage = rValue; + } + else + { + XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue ); + } +} + +TYPEINIT1( PageStyleContext, XMLPropStyleContext ); + +PageStyleContext::PageStyleContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, const rtl::OUString& rLName, + const uno::Reference< xml::sax::XAttributeList > & xAttrList, + SvXMLStylesContext& rStyles, + sal_Bool bDefaultStyle) : + XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, XML_STYLE_FAMILY_PAGE_MASTER, bDefaultStyle), + sPageUsage() +{ +} + +PageStyleContext::~PageStyleContext() +{ +} + +SvXMLImportContext *PageStyleContext::CreateChildContext( + sal_uInt16 nPrefix, + const rtl::OUString& rLocalName, + const uno::Reference< xml::sax::XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = NULL; + + if( XML_NAMESPACE_STYLE == nPrefix && + ((IsXMLToken(rLocalName, XML_HEADER_STYLE )) || + (IsXMLToken(rLocalName, XML_FOOTER_STYLE )) ) ) + { + sal_Bool bHeader = IsXMLToken(rLocalName, XML_HEADER_STYLE); + UniReference < SvXMLImportPropertyMapper > xImpPrMap = + GetStyles()->GetImportPropertyMapper( GetFamily() ); + if( xImpPrMap.is() ) + { + const UniReference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper(); + sal_Int32 nFlag; + if (bHeader) + nFlag = CTF_PM_HEADERFLAG; + else + nFlag = CTF_PM_FOOTERFLAG; + sal_Int32 nStartIndex (-1); + sal_Int32 nEndIndex (-1); + sal_Bool bFirst(sal_False); + sal_Bool bEnd(sal_False); + sal_Int32 nIndex = 0; + while ( nIndex < rMapper->GetEntryCount() && !bEnd) + { + if ((rMapper->GetEntryContextId( nIndex ) & CTF_PM_FLAGMASK) == nFlag) + { + if (!bFirst) + { + bFirst = sal_True; + nStartIndex = nIndex; + } + } + else if (bFirst) + { + bEnd = sal_True; + nEndIndex = nIndex; + } + nIndex++; + } + if (!bEnd) + nEndIndex = nIndex; + pContext = new PageHeaderFooterContext(GetImport(), nPrefix, rLocalName, + xAttrList, GetProperties(), xImpPrMap, nStartIndex, nEndIndex, bHeader); + } + } + if( XML_NAMESPACE_STYLE == nPrefix && + IsXMLToken(rLocalName, XML_PAGE_LAYOUT_PROPERTIES) ) + { + UniReference < SvXMLImportPropertyMapper > xImpPrMap = + GetStyles()->GetImportPropertyMapper( GetFamily() ); + if( xImpPrMap.is() ) + { + const UniReference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper(); + sal_Int32 nEndIndex (-1); + sal_Bool bEnd(sal_False); + sal_Int32 nIndex = 0; + sal_Int16 nContextID; + while ( nIndex < rMapper->GetEntryCount() && !bEnd) + { + nContextID = rMapper->GetEntryContextId( nIndex ); + if (nContextID && ((nContextID & CTF_PM_FLAGMASK) != XML_PM_CTF_START)) + { + nEndIndex = nIndex; + bEnd = sal_True; + } + nIndex++; + } + if (!bEnd) + nEndIndex = nIndex; + PageContextType aType = Page; + pContext = new PagePropertySetContext( GetImport(), nPrefix, + rLocalName, xAttrList, + XML_TYPE_PROP_PAGE_LAYOUT, + GetProperties(), + xImpPrMap, 0, nEndIndex, aType); + } + } + + if (!pContext) + pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName, + xAttrList ); + return pContext; +} + +void PageStyleContext::FillPropertySet( + const uno::Reference<beans::XPropertySet > & rPropSet ) +{ + XMLPropStyleContext::FillPropertySet(rPropSet); + if (sPageUsage.getLength()) + { + uno::Any aPageUsage; + XMLPMPropHdl_PageStyleLayout aPageUsageHdl; + if (aPageUsageHdl.importXML(sPageUsage, aPageUsage, GetImport().GetMM100UnitConverter())) + rPropSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PageStyleLayout")), aPageUsage); + } +} + +// text grid enhancement for better CJK support +//set default page layout style +void PageStyleContext::SetDefaults( ) +{ + Reference < XMultiServiceFactory > xFactory ( GetImport().GetModel(), UNO_QUERY); + if (xFactory.is()) + { + Reference < XInterface > xInt = xFactory->createInstance ( + rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.text.Defaults" ) ) ); + Reference < beans::XPropertySet > xProperties ( xInt, UNO_QUERY ); + if ( xProperties.is() ) + FillPropertySet ( xProperties ); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/PageMasterImportPropMapper.cxx b/xmloff/source/style/PageMasterImportPropMapper.cxx new file mode 100644 index 000000000000..e8c82edb7f5b --- /dev/null +++ b/xmloff/source/style/PageMasterImportPropMapper.cxx @@ -0,0 +1,342 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include "PageMasterImportPropMapper.hxx" +#include "PageMasterPropMapper.hxx" +#include <xmloff/PageMasterStyleMap.hxx> +#include <xmloff/maptype.hxx> +#include <com/sun/star/table/BorderLine2.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <xmloff/xmlimp.hxx> + +#define XML_LINE_LEFT 0 +#define XML_LINE_RIGHT 1 +#define XML_LINE_TOP 2 +#define XML_LINE_BOTTOM 3 + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::container; + +PageMasterImportPropertyMapper::PageMasterImportPropertyMapper( + const UniReference< XMLPropertySetMapper >& rMapper, + SvXMLImport& rImp ) : + SvXMLImportPropertyMapper( rMapper, rImp ), + rImport( rImp ) +{ +} + +PageMasterImportPropertyMapper::~PageMasterImportPropertyMapper() +{ +} + +bool PageMasterImportPropertyMapper::handleSpecialItem( + XMLPropertyState& rProperty, + ::std::vector< XMLPropertyState >& rProperties, + const ::rtl::OUString& rValue, + const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& rNamespaceMap ) const +{ + sal_Bool bRet = sal_False; + sal_Int16 nContextID = + getPropertySetMapper()->GetEntryContextId(rProperty.mnIndex); + + if( CTF_PM_REGISTER_STYLE==nContextID ) + { + ::rtl::OUString sDisplayName( rImport.GetStyleDisplayName( + XML_STYLE_FAMILY_TEXT_PARAGRAPH, rValue ) ); + Reference < XNameContainer > xParaStyles = + rImport.GetTextImport()->GetParaStyles(); + if( xParaStyles.is() && xParaStyles->hasByName( sDisplayName ) ) + { + rProperty.maValue <<= sDisplayName; + bRet = sal_True; + } + } + else + { + bRet = SvXMLImportPropertyMapper::handleSpecialItem( + rProperty, rProperties, rValue, + rUnitConverter, rNamespaceMap ); + } + + return bRet; +} + + +void PageMasterImportPropertyMapper::finished(::std::vector< XMLPropertyState >& rProperties, sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const +{ + SvXMLImportPropertyMapper::finished(rProperties, nStartIndex, nEndIndex); + XMLPropertyState* pAllPaddingProperty = NULL; + XMLPropertyState* pPadding[4] = { NULL, NULL, NULL, NULL }; + XMLPropertyState* pNewPadding[4] = { NULL, NULL, NULL, NULL }; + XMLPropertyState* pAllBorderProperty = NULL; + XMLPropertyState* pBorders[4] = { NULL, NULL, NULL, NULL }; + XMLPropertyState* pNewBorders[4] = { NULL, NULL, NULL, NULL }; + XMLPropertyState* pAllBorderWidthProperty = NULL; + XMLPropertyState* pBorderWidths[4] = { NULL, NULL, NULL, NULL }; + XMLPropertyState* pAllHeaderPaddingProperty = NULL; + XMLPropertyState* pHeaderPadding[4] = { NULL, NULL, NULL, NULL }; + XMLPropertyState* pHeaderNewPadding[4] = { NULL, NULL, NULL, NULL }; + XMLPropertyState* pAllHeaderBorderProperty = NULL; + XMLPropertyState* pHeaderBorders[4] = { NULL, NULL, NULL, NULL }; + XMLPropertyState* pHeaderNewBorders[4] = { NULL, NULL, NULL, NULL }; + XMLPropertyState* pAllHeaderBorderWidthProperty = NULL; + XMLPropertyState* pHeaderBorderWidths[4] = { NULL, NULL, NULL, NULL }; + XMLPropertyState* pAllFooterPaddingProperty = NULL; + XMLPropertyState* pFooterPadding[4] = { NULL, NULL, NULL, NULL }; + XMLPropertyState* pFooterNewPadding[4] = { NULL, NULL, NULL, NULL }; + XMLPropertyState* pAllFooterBorderProperty = NULL; + XMLPropertyState* pFooterBorders[4] = { NULL, NULL, NULL, NULL }; + XMLPropertyState* pFooterNewBorders[4] = { NULL, NULL, NULL, NULL }; + XMLPropertyState* pAllFooterBorderWidthProperty = NULL; + XMLPropertyState* pFooterBorderWidths[4] = { NULL, NULL, NULL, NULL }; + XMLPropertyState* pHeaderHeight = NULL; + XMLPropertyState* pHeaderMinHeight = NULL; + XMLPropertyState* pHeaderDynamic = NULL; + XMLPropertyState* pFooterHeight = NULL; + XMLPropertyState* pFooterMinHeight = NULL; + XMLPropertyState* pFooterDynamic = NULL; + sal_uInt16 i; // for the "for" loop + + ::std::vector< XMLPropertyState >::iterator aEnd = rProperties.end(); + for (::std::vector< XMLPropertyState >::iterator aIter = rProperties.begin(); aIter != aEnd; ++aIter) + { + XMLPropertyState *property = &(*aIter); + sal_Int16 nContextID = getPropertySetMapper()->GetEntryContextId(property->mnIndex); + if (property->mnIndex >= nStartIndex && property->mnIndex < nEndIndex) + { + switch (nContextID) + { + case CTF_PM_PADDINGALL : pAllPaddingProperty = property; break; + case CTF_PM_PADDINGLEFT : pPadding[XML_LINE_LEFT] = property; break; + case CTF_PM_PADDINGRIGHT : pPadding[XML_LINE_RIGHT] = property; break; + case CTF_PM_PADDINGTOP : pPadding[XML_LINE_TOP] = property; break; + case CTF_PM_PADDINGBOTTOM : pPadding[XML_LINE_BOTTOM] = property; break; + case CTF_PM_BORDERALL : pAllBorderProperty = property; break; + case CTF_PM_BORDERLEFT : pBorders[XML_LINE_LEFT] = property; break; + case CTF_PM_BORDERRIGHT : pBorders[XML_LINE_RIGHT] = property; break; + case CTF_PM_BORDERTOP : pBorders[XML_LINE_TOP] = property; break; + case CTF_PM_BORDERBOTTOM : pBorders[XML_LINE_BOTTOM] = property; break; + case CTF_PM_BORDERWIDTHALL : pAllBorderWidthProperty = property; break; + case CTF_PM_BORDERWIDTHLEFT : pBorderWidths[XML_LINE_LEFT] = property; break; + case CTF_PM_BORDERWIDTHRIGHT : pBorderWidths[XML_LINE_RIGHT] = property; break; + case CTF_PM_BORDERWIDTHTOP : pBorderWidths[XML_LINE_TOP] = property; break; + case CTF_PM_BORDERWIDTHBOTTOM : pBorderWidths[XML_LINE_BOTTOM] = property; break; + case CTF_PM_HEADERPADDINGALL : pAllHeaderPaddingProperty = property; break; + case CTF_PM_HEADERPADDINGLEFT : pHeaderPadding[XML_LINE_LEFT] = property; break; + case CTF_PM_HEADERPADDINGRIGHT : pHeaderPadding[XML_LINE_RIGHT] = property; break; + case CTF_PM_HEADERPADDINGTOP : pHeaderPadding[XML_LINE_TOP] = property; break; + case CTF_PM_HEADERPADDINGBOTTOM : pHeaderPadding[XML_LINE_BOTTOM] = property; break; + case CTF_PM_HEADERBORDERALL : pAllHeaderBorderProperty = property; break; + case CTF_PM_HEADERBORDERLEFT : pHeaderBorders[XML_LINE_LEFT] = property; break; + case CTF_PM_HEADERBORDERRIGHT : pHeaderBorders[XML_LINE_RIGHT] = property; break; + case CTF_PM_HEADERBORDERTOP : pHeaderBorders[XML_LINE_TOP] = property; break; + case CTF_PM_HEADERBORDERBOTTOM : pHeaderBorders[XML_LINE_BOTTOM] = property; break; + case CTF_PM_HEADERBORDERWIDTHALL : pAllHeaderBorderWidthProperty = property; break; + case CTF_PM_HEADERBORDERWIDTHLEFT : pHeaderBorderWidths[XML_LINE_LEFT] = property; break; + case CTF_PM_HEADERBORDERWIDTHRIGHT : pHeaderBorderWidths[XML_LINE_RIGHT] = property; break; + case CTF_PM_HEADERBORDERWIDTHTOP : pHeaderBorderWidths[XML_LINE_TOP] = property; break; + case CTF_PM_HEADERBORDERWIDTHBOTTOM : pHeaderBorderWidths[XML_LINE_BOTTOM] = property; break; + case CTF_PM_FOOTERPADDINGALL : pAllFooterPaddingProperty = property; break; + case CTF_PM_FOOTERPADDINGLEFT : pFooterPadding[XML_LINE_LEFT] = property; break; + case CTF_PM_FOOTERPADDINGRIGHT : pFooterPadding[XML_LINE_RIGHT] = property; break; + case CTF_PM_FOOTERPADDINGTOP : pFooterPadding[XML_LINE_TOP] = property; break; + case CTF_PM_FOOTERPADDINGBOTTOM : pFooterPadding[XML_LINE_BOTTOM] = property; break; + case CTF_PM_FOOTERBORDERALL : pAllFooterBorderProperty = property; break; + case CTF_PM_FOOTERBORDERLEFT : pFooterBorders[XML_LINE_LEFT] = property; break; + case CTF_PM_FOOTERBORDERRIGHT : pFooterBorders[XML_LINE_RIGHT] = property; break; + case CTF_PM_FOOTERBORDERTOP : pFooterBorders[XML_LINE_TOP] = property; break; + case CTF_PM_FOOTERBORDERBOTTOM : pFooterBorders[XML_LINE_BOTTOM] = property; break; + case CTF_PM_FOOTERBORDERWIDTHALL : pAllFooterBorderWidthProperty = property; break; + case CTF_PM_FOOTERBORDERWIDTHLEFT : pFooterBorderWidths[XML_LINE_LEFT] = property; break; + case CTF_PM_FOOTERBORDERWIDTHRIGHT : pFooterBorderWidths[XML_LINE_RIGHT] = property; break; + case CTF_PM_FOOTERBORDERWIDTHTOP : pFooterBorderWidths[XML_LINE_TOP] = property; break; + case CTF_PM_FOOTERBORDERWIDTHBOTTOM : pFooterBorderWidths[XML_LINE_BOTTOM] = property; break; + case CTF_PM_HEADERHEIGHT : pHeaderHeight = property; break; + case CTF_PM_HEADERMINHEIGHT : pHeaderMinHeight = property; break; + case CTF_PM_FOOTERHEIGHT : pFooterHeight = property; break; + case CTF_PM_FOOTERMINHEIGHT : pFooterMinHeight = property; break; + } + } + } + + for ( i = 0; i < 4; i++) + { + if (pAllPaddingProperty && !pPadding[i]) + pNewPadding[i] = new XMLPropertyState(pAllPaddingProperty->mnIndex + 1 + i, pAllPaddingProperty->maValue); + if (pAllBorderProperty && !pBorders[i]) + { + pNewBorders[i] = new XMLPropertyState(pAllBorderProperty->mnIndex + 1 + i, pAllBorderProperty->maValue); + pBorders[i] = pNewBorders[i]; + } + if( !pBorderWidths[i] ) + pBorderWidths[i] = pAllBorderWidthProperty; + else + pBorderWidths[i]->mnIndex = -1; + if( pBorders[i] ) + { + table::BorderLine2 aBorderLine; + pBorders[i]->maValue >>= aBorderLine; + if( pBorderWidths[i] ) + { + table::BorderLine2 aBorderLineWidth; + pBorderWidths[i]->maValue >>= aBorderLineWidth; + aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth; + aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth; + aBorderLine.LineDistance = aBorderLineWidth.LineDistance; + aBorderLine.LineWidth = aBorderLineWidth.LineWidth; + pBorders[i]->maValue <<= aBorderLine; + } + } + if (pAllHeaderPaddingProperty && !pHeaderPadding[i]) + pHeaderNewPadding[i] = new XMLPropertyState(pAllHeaderPaddingProperty->mnIndex + 1 + i, pAllHeaderPaddingProperty->maValue); + if (pAllHeaderBorderProperty && !pHeaderBorders[i]) + pHeaderNewBorders[i] = new XMLPropertyState(pAllHeaderBorderProperty->mnIndex + 1 + i, pAllHeaderBorderProperty->maValue); + if( !pHeaderBorderWidths[i] ) + pHeaderBorderWidths[i] = pAllHeaderBorderWidthProperty; + else + pHeaderBorderWidths[i]->mnIndex = -1; + if( pHeaderBorders[i] ) + { + table::BorderLine2 aBorderLine; + pHeaderBorders[i]->maValue >>= aBorderLine; + if( pHeaderBorderWidths[i] ) + { + table::BorderLine2 aBorderLineWidth; + pHeaderBorderWidths[i]->maValue >>= aBorderLineWidth; + aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth; + aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth; + aBorderLine.LineDistance = aBorderLineWidth.LineDistance; + aBorderLine.LineWidth = aBorderLineWidth.LineWidth; + pHeaderBorders[i]->maValue <<= aBorderLine; + } + } + if (pAllFooterPaddingProperty && !pFooterPadding[i]) + pFooterNewPadding[i] = new XMLPropertyState(pAllFooterPaddingProperty->mnIndex + 1 + i, pAllFooterPaddingProperty->maValue); + if (pAllFooterBorderProperty && !pFooterBorders[i]) + pFooterNewBorders[i] = new XMLPropertyState(pAllFooterBorderProperty->mnIndex + 1 + i, pAllFooterBorderProperty->maValue); + if( !pFooterBorderWidths[i] ) + pFooterBorderWidths[i] = pAllFooterBorderWidthProperty; + else + pFooterBorderWidths[i]->mnIndex = -1; + if( pFooterBorders[i] ) + { + table::BorderLine2 aBorderLine; + pFooterBorders[i]->maValue >>= aBorderLine; + if( pFooterBorderWidths[i] ) + { + table::BorderLine2 aBorderLineWidth; + pFooterBorderWidths[i]->maValue >>= aBorderLineWidth; + aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth; + aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth; + aBorderLine.LineDistance = aBorderLineWidth.LineDistance; + aBorderLine.LineWidth = aBorderLineWidth.LineWidth; + pFooterBorders[i]->maValue <<= aBorderLine; + } + } + } + + if (pHeaderHeight) + { + sal_Bool bValue(sal_False); + uno::Any aAny; + aAny.setValue( &bValue, ::getBooleanCppuType() ); + pHeaderDynamic = new XMLPropertyState(pHeaderHeight->mnIndex + 2, aAny); + } + if (pHeaderMinHeight) + { + sal_Bool bValue(sal_True); + uno::Any aAny; + aAny.setValue( &bValue, ::getBooleanCppuType() ); + pHeaderDynamic = new XMLPropertyState(pHeaderMinHeight->mnIndex + 1, aAny); + } + if (pFooterHeight) + { + sal_Bool bValue(sal_False); + uno::Any aAny; + aAny.setValue( &bValue, ::getBooleanCppuType() ); + pFooterDynamic = new XMLPropertyState(pFooterHeight->mnIndex + 2, aAny); + } + if (pFooterMinHeight) + { + sal_Bool bValue(sal_True); + uno::Any aAny; + aAny.setValue( &bValue, ::getBooleanCppuType() ); + pFooterDynamic = new XMLPropertyState(pFooterMinHeight->mnIndex + 1, aAny); + } + for (i = 0; i < 4; i++) + { + if (pNewPadding[i]) + { + rProperties.push_back(*pNewPadding[i]); + delete pNewPadding[i]; + } + if (pNewBorders[i]) + { + rProperties.push_back(*pNewBorders[i]); + delete pNewBorders[i]; + } + if (pHeaderNewPadding[i]) + { + rProperties.push_back(*pHeaderNewPadding[i]); + delete pHeaderNewPadding[i]; + } + if (pHeaderNewBorders[i]) + { + rProperties.push_back(*pHeaderNewBorders[i]); + delete pHeaderNewBorders[i]; + } + if (pFooterNewPadding[i]) + { + rProperties.push_back(*pFooterNewPadding[i]); + delete pFooterNewPadding[i]; + } + if (pFooterNewBorders[i]) + { + rProperties.push_back(*pFooterNewBorders[i]); + delete pFooterNewBorders[i]; + } + } + if(pHeaderDynamic) + { + rProperties.push_back(*pHeaderDynamic); + delete pHeaderDynamic; + } + if(pFooterDynamic) + { + rProperties.push_back(*pFooterDynamic); + delete pFooterDynamic; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/PageMasterImportPropMapper.hxx b/xmloff/source/style/PageMasterImportPropMapper.hxx new file mode 100644 index 000000000000..e386104ed8c9 --- /dev/null +++ b/xmloff/source/style/PageMasterImportPropMapper.hxx @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PAGEMASTERIMPORTPROPMAPPER_HXX +#define _XMLOFF_PAGEMASTERIMPORTPROPMAPPER_HXX + +#include <xmloff/xmlimppr.hxx> + +class SvXMLImport; + +class PageMasterImportPropertyMapper : public SvXMLImportPropertyMapper +{ + SvXMLImport& rImport; + +protected: + +public: + + PageMasterImportPropertyMapper( + const UniReference< XMLPropertySetMapper >& rMapper, + SvXMLImport& rImp); + virtual ~PageMasterImportPropertyMapper(); + + /** this method is called for every item that has the MID_FLAG_SPECIAL_ITEM_IMPORT flag set */ + virtual bool handleSpecialItem( + XMLPropertyState& rProperty, + ::std::vector< XMLPropertyState >& rProperties, + const ::rtl::OUString& rValue, + const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& rNamespaceMap ) const; + + /** This method is called when all attributes have been processed. It may be used to remove items that are incomplete */ + virtual void finished( + ::std::vector< XMLPropertyState >& rProperties, + sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/PageMasterPropHdl.cxx b/xmloff/source/style/PageMasterPropHdl.cxx new file mode 100644 index 000000000000..4fb090f32662 --- /dev/null +++ b/xmloff/source/style/PageMasterPropHdl.cxx @@ -0,0 +1,428 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "PageMasterPropHdl.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/xmlnumi.hxx> +#include <xmloff/xmlnume.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/style/PageStyleLayout.hpp> +#include <comphelper/types.hxx> +#include <comphelper/extract.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::style; +using namespace ::comphelper; +using namespace ::xmloff::token; + + +//______________________________________________________________________________ + +#define DEFAULT_PAPERTRAY (sal_Int32(-1)) + + +//______________________________________________________________________________ +// property handler for style:page-usage (style::PageStyleLayout) + +XMLPMPropHdl_PageStyleLayout::~XMLPMPropHdl_PageStyleLayout() +{ +} + +bool XMLPMPropHdl_PageStyleLayout::equals( const Any& rAny1, const Any& rAny2 ) const +{ + style::PageStyleLayout eLayout1, eLayout2; + return ((rAny1 >>= eLayout1) && (rAny2 >>= eLayout2)) ? (eLayout1 == eLayout2) : sal_False; +} + +sal_Bool XMLPMPropHdl_PageStyleLayout::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_True; + + if( IsXMLToken( rStrImpValue, XML_ALL ) ) + rValue <<= PageStyleLayout_ALL; + else if( IsXMLToken( rStrImpValue, XML_LEFT ) ) + rValue <<= PageStyleLayout_LEFT; + else if( IsXMLToken( rStrImpValue, XML_RIGHT ) ) + rValue <<= PageStyleLayout_RIGHT; + else if( IsXMLToken( rStrImpValue, XML_MIRRORED ) ) + rValue <<= PageStyleLayout_MIRRORED; + else + bRet = sal_False; + + return bRet; +} + +sal_Bool XMLPMPropHdl_PageStyleLayout::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + PageStyleLayout eLayout; + + if( rValue >>= eLayout ) + { + bRet = sal_True; + switch( eLayout ) + { + case PageStyleLayout_ALL: + rStrExpValue = GetXMLToken( XML_ALL ); + break; + case PageStyleLayout_LEFT: + rStrExpValue = GetXMLToken( XML_LEFT ); + break; + case PageStyleLayout_RIGHT: + rStrExpValue = GetXMLToken( XML_RIGHT ); + break; + case PageStyleLayout_MIRRORED: + rStrExpValue = GetXMLToken( XML_MIRRORED ); + break; + default: + bRet = sal_False; + } + } + + return bRet; +} + + +//______________________________________________________________________________ +// property handler for style:num-format (style::NumberingType) + +XMLPMPropHdl_NumFormat::~XMLPMPropHdl_NumFormat() +{ +} + +sal_Bool XMLPMPropHdl_NumFormat::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& rUnitConverter ) const +{ + sal_Int16 nSync = sal_Int16(); + sal_Int16 nNumType = NumberingType::NUMBER_NONE; + rUnitConverter.convertNumFormat( nNumType, rStrImpValue, OUString(), + sal_True ); + + if( !(rValue >>= nSync) ) + nSync = NumberingType::NUMBER_NONE; + + // if num-letter-sync appears before num-format, the function + // XMLPMPropHdl_NumLetterSync::importXML() sets the value + // NumberingType::CHARS_LOWER_LETTER_N + if( nSync == NumberingType::CHARS_LOWER_LETTER_N ) + { + switch( nNumType ) + { + case NumberingType::CHARS_LOWER_LETTER: + nNumType = NumberingType::CHARS_LOWER_LETTER_N; + break; + case NumberingType::CHARS_UPPER_LETTER: + nNumType = NumberingType::CHARS_UPPER_LETTER_N; + break; + } + } + rValue <<= nNumType; + + return sal_True; +} + +sal_Bool XMLPMPropHdl_NumFormat::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& rUnitConverter ) const +{ + sal_Bool bRet = sal_False; + sal_Int16 nNumType = sal_Int16(); + + if( rValue >>= nNumType ) + { + OUStringBuffer aBuffer( 10 ); + rUnitConverter.convertNumFormat( aBuffer, nNumType ); + rStrExpValue = aBuffer.makeStringAndClear(); + bRet = sal_True; + } + return bRet; +} + + +//______________________________________________________________________________ +// property handler for style:num-letter-sync (style::NumberingType) + +XMLPMPropHdl_NumLetterSync::~XMLPMPropHdl_NumLetterSync() +{ +} + +sal_Bool XMLPMPropHdl_NumLetterSync::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& rUnitConverter ) const +{ + sal_Int16 nNumType; + sal_Int16 nSync = NumberingType::NUMBER_NONE; + rUnitConverter.convertNumFormat( nSync, rStrImpValue, + GetXMLToken( XML_A ), sal_True ); + + if( !(rValue >>= nNumType) ) + nNumType = NumberingType::NUMBER_NONE; + + if( nSync == NumberingType::CHARS_LOWER_LETTER_N ) + { + switch( nNumType ) + { + case NumberingType::CHARS_LOWER_LETTER: + nNumType = NumberingType::CHARS_LOWER_LETTER_N; + break; + case NumberingType::CHARS_UPPER_LETTER: + nNumType = NumberingType::CHARS_UPPER_LETTER_N; + break; + } + } + rValue <<= nNumType; + + return sal_True; +} + +sal_Bool XMLPMPropHdl_NumLetterSync::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& rUnitConverter ) const +{ + sal_Bool bRet = sal_False; + sal_Int16 nNumType = sal_Int16(); + + if( rValue >>= nNumType ) + { + OUStringBuffer aBuffer( 5 ); + rUnitConverter.convertNumLetterSync( aBuffer, nNumType ); + rStrExpValue = aBuffer.makeStringAndClear(); + bRet = rStrExpValue.getLength() > 0; + } + return bRet; +} + + +//______________________________________________________________________________ +// property handler for style:paper-tray-number + +XMLPMPropHdl_PaperTrayNumber::~XMLPMPropHdl_PaperTrayNumber() +{ +} + +sal_Bool XMLPMPropHdl_PaperTrayNumber::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + if( IsXMLToken( rStrImpValue, XML_DEFAULT ) ) + { + rValue <<= DEFAULT_PAPERTRAY; + bRet = sal_True; + } + else + { + sal_Int32 nPaperTray; + if( SvXMLUnitConverter::convertNumber( nPaperTray, rStrImpValue, 0 ) ) + { + rValue <<= nPaperTray; + bRet = sal_True; + } + } + + return bRet; +} + +sal_Bool XMLPMPropHdl_PaperTrayNumber::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + sal_Int32 nPaperTray = 0; + + if( rValue >>= nPaperTray ) + { + if( nPaperTray == DEFAULT_PAPERTRAY ) + rStrExpValue = GetXMLToken( XML_DEFAULT ); + else + { + OUStringBuffer aBuffer; + SvXMLUnitConverter::convertNumber( aBuffer, nPaperTray ); + rStrExpValue = aBuffer.makeStringAndClear(); + } + bRet = sal_True; + } + return bRet; +} + + +//______________________________________________________________________________ +// property handler for style:print + +XMLPMPropHdl_Print::XMLPMPropHdl_Print( enum XMLTokenEnum eValue ) : + sAttrValue( GetXMLToken( eValue ) ) +{ +} + +XMLPMPropHdl_Print::~XMLPMPropHdl_Print() +{ +} + +sal_Bool XMLPMPropHdl_Print::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Unicode cToken = ' '; + sal_Int32 nTokenIndex = 0; + sal_Bool bFound = sal_False; + + do + { + bFound = (sAttrValue == rStrImpValue.getToken( 0, cToken, nTokenIndex )); + } + while ( (nTokenIndex >= 0) && !bFound ); + + setBOOL( rValue, bFound ); + return sal_True; +} + +sal_Bool XMLPMPropHdl_Print::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& ) const +{ + if( getBOOL( rValue ) ) + { + if( rStrExpValue.getLength() ) + rStrExpValue += OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) ); + rStrExpValue += sAttrValue; + } + + return sal_True; +} + +//______________________________________________________________________________ +// property handler for style:table-centering + +XMLPMPropHdl_CenterHorizontal::~XMLPMPropHdl_CenterHorizontal() +{ +} + +sal_Bool XMLPMPropHdl_CenterHorizontal::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + if (rStrImpValue.getLength()) + if (IsXMLToken( rStrImpValue, XML_BOTH) || + IsXMLToken( rStrImpValue, XML_HORIZONTAL)) + { + rValue = ::cppu::bool2any(sal_True); + bRet = sal_True; + } + + + return bRet; +} + +sal_Bool XMLPMPropHdl_CenterHorizontal::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + if ( ::cppu::any2bool( rValue ) ) + { + bRet = sal_True; + if (rStrExpValue.getLength()) + rStrExpValue = GetXMLToken(XML_BOTH); + else + rStrExpValue = GetXMLToken(XML_HORIZONTAL); + } + + return bRet; +} + +XMLPMPropHdl_CenterVertical::~XMLPMPropHdl_CenterVertical() +{ +} + +sal_Bool XMLPMPropHdl_CenterVertical::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + if (rStrImpValue.getLength()) + if (IsXMLToken(rStrImpValue, XML_BOTH) || + IsXMLToken(rStrImpValue, XML_VERTICAL) ) + { + rValue = ::cppu::bool2any(sal_True); + bRet = sal_True; + } + + return bRet; +} + +sal_Bool XMLPMPropHdl_CenterVertical::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + if ( ::cppu::any2bool( rValue ) ) + { + bRet = sal_True; + if (rStrExpValue.getLength()) + rStrExpValue = GetXMLToken(XML_BOTH); + else + rStrExpValue = GetXMLToken(XML_VERTICAL); + } + + return bRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/PageMasterPropHdl.hxx b/xmloff/source/style/PageMasterPropHdl.hxx new file mode 100644 index 000000000000..b2e1b6ade887 --- /dev/null +++ b/xmloff/source/style/PageMasterPropHdl.hxx @@ -0,0 +1,182 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PAGEMASTERPROPHDL_HXX_ +#define _XMLOFF_PAGEMASTERPROPHDL_HXX_ + +#include <xmloff/xmlprhdl.hxx> +#include <rtl/ustring.hxx> +#include <xmloff/xmltoken.hxx> + + +//______________________________________________________________________________ +// property handler for style:page-usage (style::PageStyleLayout) + +class XMLPMPropHdl_PageStyleLayout : public XMLPropertyHandler +{ +public: + virtual ~XMLPMPropHdl_PageStyleLayout(); + virtual bool equals( + const ::com::sun::star::uno::Any& rAny1, + const ::com::sun::star::uno::Any& rAny2 + ) const; + virtual sal_Bool importXML( + const ::rtl::OUString& rStrImpValue, + ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& rUnitConverter + ) const; + virtual sal_Bool exportXML( + ::rtl::OUString& rStrExpValue, + const ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& rUnitConverter + ) const; +}; + + +//______________________________________________________________________________ +// property handler for style:num-format (style::NumberingType) + +class XMLPMPropHdl_NumFormat : public XMLPropertyHandler +{ +public: + virtual ~XMLPMPropHdl_NumFormat(); + virtual sal_Bool importXML( + const ::rtl::OUString& rStrImpValue, + ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& rUnitConverter + ) const; + virtual sal_Bool exportXML( + ::rtl::OUString& rStrExpValue, + const ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& rUnitConverter + ) const; +}; + + +//______________________________________________________________________________ +// property handler for style:num-letter-sync (style::NumberingType) + +class XMLPMPropHdl_NumLetterSync : public XMLPropertyHandler +{ +public: + virtual ~XMLPMPropHdl_NumLetterSync(); + virtual sal_Bool importXML( + const ::rtl::OUString& rStrImpValue, + ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& rUnitConverter + ) const; + virtual sal_Bool exportXML( + ::rtl::OUString& rStrExpValue, + const ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& rUnitConverter + ) const; +}; + + +//______________________________________________________________________________ +// property handler for style:paper-tray-number + +class XMLPMPropHdl_PaperTrayNumber : public XMLPropertyHandler +{ +public: + virtual ~XMLPMPropHdl_PaperTrayNumber(); + virtual sal_Bool importXML( + const ::rtl::OUString& rStrImpValue, + ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& rUnitConverter + ) const; + virtual sal_Bool exportXML( + ::rtl::OUString& rStrExpValue, + const ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& rUnitConverter + ) const; +}; + + +//______________________________________________________________________________ +// property handler for style:print + +class XMLPMPropHdl_Print : public XMLPropertyHandler +{ +protected: + ::rtl::OUString sAttrValue; + +public: + XMLPMPropHdl_Print( enum ::xmloff::token::XMLTokenEnum eValue ); + virtual ~XMLPMPropHdl_Print(); + + virtual sal_Bool importXML( + const ::rtl::OUString& rStrImpValue, + ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& rUnitConverter + ) const; + virtual sal_Bool exportXML( + ::rtl::OUString& rStrExpValue, + const ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& rUnitConverter + ) const; +}; + +//______________________________________________________________________________ +// property handler for style:table-centering + +class XMLPMPropHdl_CenterHorizontal : public XMLPropertyHandler +{ +public: + virtual ~XMLPMPropHdl_CenterHorizontal(); + virtual sal_Bool importXML( + const ::rtl::OUString& rStrImpValue, + ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& rUnitConverter + ) const; + virtual sal_Bool exportXML( + ::rtl::OUString& rStrExpValue, + const ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& rUnitConverter + ) const; +}; + +class XMLPMPropHdl_CenterVertical : public XMLPropertyHandler +{ +public: + virtual ~XMLPMPropHdl_CenterVertical(); + virtual sal_Bool importXML( + const ::rtl::OUString& rStrImpValue, + ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& rUnitConverter + ) const; + virtual sal_Bool exportXML( + ::rtl::OUString& rStrExpValue, + const ::com::sun::star::uno::Any& rValue, + const SvXMLUnitConverter& rUnitConverter + ) const; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/PageMasterPropHdlFactory.cxx b/xmloff/source/style/PageMasterPropHdlFactory.cxx new file mode 100644 index 000000000000..3ff8a9c1a75d --- /dev/null +++ b/xmloff/source/style/PageMasterPropHdlFactory.cxx @@ -0,0 +1,148 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "PageMasterPropHdlFactory.hxx" +#include <xmloff/xmltypes.hxx> +#include <xmloff/xmltoken.hxx> +#include "xmlbahdl.hxx" +#include <xmloff/NamedBoolPropertyHdl.hxx> +#include "XMLTextColumnsPropertyHandler.hxx" +#include <xmloff/XMLConstantsPropertyHandler.hxx> +#include "PageMasterPropHdl.hxx" +#include <xmloff/PageMasterStyleMap.hxx> +#include <com/sun/star/text/TextGridMode.hpp> + + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::xmloff::token; +using namespace ::com::sun::star; + + +SvXMLEnumMapEntry aXML_TextGridMode_ConstantMap[] = +{ + { XML_NONE, text::TextGridMode::NONE }, + { XML_LINE, text::TextGridMode::LINES }, + { XML_BOTH, text::TextGridMode::LINES_AND_CHARS }, + { XML_TOKEN_INVALID, 0 } +}; + +//______________________________________________________________________________ + +XMLPageMasterPropHdlFactory::XMLPageMasterPropHdlFactory() : + XMLPropertyHandlerFactory() +{ +} + +XMLPageMasterPropHdlFactory::~XMLPageMasterPropHdlFactory() +{ +} + +const XMLPropertyHandler* XMLPageMasterPropHdlFactory::GetPropertyHandler( sal_Int32 nType ) const +{ + nType &= MID_FLAG_MASK; + + XMLPropertyHandler* pHdl = (XMLPropertyHandler*) XMLPropertyHandlerFactory::GetPropertyHandler( nType ); + if( !pHdl ) + { + switch( nType ) + { + case XML_PM_TYPE_PAGESTYLELAYOUT: + pHdl = new XMLPMPropHdl_PageStyleLayout(); + break; + case XML_PM_TYPE_NUMFORMAT: + pHdl = new XMLPMPropHdl_NumFormat(); + break; + case XML_PM_TYPE_NUMLETTERSYNC: + pHdl = new XMLPMPropHdl_NumLetterSync(); + break; + case XML_PM_TYPE_PAPERTRAYNUMBER: + pHdl = new XMLPMPropHdl_PaperTrayNumber(); + break; + case XML_PM_TYPE_PRINTORIENTATION: + pHdl = new XMLNamedBoolPropertyHdl( + GetXMLToken( XML_LANDSCAPE ), + GetXMLToken( XML_PORTRAIT ) ); + break; + case XML_PM_TYPE_PRINTANNOTATIONS: + pHdl = new XMLPMPropHdl_Print( XML_ANNOTATIONS ); + break; + case XML_PM_TYPE_PRINTCHARTS: + pHdl = new XMLPMPropHdl_Print( XML_CHARTS ); + break; + case XML_PM_TYPE_PRINTDRAWING: + pHdl = new XMLPMPropHdl_Print( XML_DRAWINGS ); + break; + case XML_PM_TYPE_PRINTFORMULAS: + pHdl = new XMLPMPropHdl_Print( XML_FORMULAS ); + break; + case XML_PM_TYPE_PRINTGRID: + pHdl = new XMLPMPropHdl_Print( XML_GRID ); + break; + case XML_PM_TYPE_PRINTHEADERS: + pHdl = new XMLPMPropHdl_Print( XML_HEADERS ); + break; + case XML_PM_TYPE_PRINTOBJECTS: + pHdl = new XMLPMPropHdl_Print( XML_OBJECTS ); + break; + case XML_PM_TYPE_PRINTZEROVALUES: + pHdl = new XMLPMPropHdl_Print( XML_ZERO_VALUES ); + break; + case XML_PM_TYPE_PRINTPAGEORDER: + pHdl = new XMLNamedBoolPropertyHdl( GetXMLToken( XML_TTB ), + GetXMLToken( XML_LTR ) ); + break; + case XML_PM_TYPE_FIRSTPAGENUMBER: + pHdl = new XMLNumberNonePropHdl( XML_CONTINUE, 2 ); + break; + case XML_PM_TYPE_CENTER_HORIZONTAL: + pHdl = new XMLPMPropHdl_CenterHorizontal(); + break; + case XML_PM_TYPE_CENTER_VERTICAL: + pHdl = new XMLPMPropHdl_CenterVertical(); + break; + case XML_TYPE_TEXT_COLUMNS: + pHdl = new XMLTextColumnsPropertyHandler; + break; + case XML_TYPE_LAYOUT_GRID_MODE: + pHdl = new XMLConstantsPropertyHandler( + aXML_TextGridMode_ConstantMap, XML_NONE ); + break; + } + + if( pHdl ) + PutHdlCache( nType, pHdl ); + } + return pHdl; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/PageMasterPropHdlFactory.hxx b/xmloff/source/style/PageMasterPropHdlFactory.hxx new file mode 100644 index 000000000000..10b796c59640 --- /dev/null +++ b/xmloff/source/style/PageMasterPropHdlFactory.hxx @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PAGEMASTERPROPHDLFACTORY_HXX +#define _XMLOFF_PAGEMASTERPROPHDLFACTORY_HXX + +#include <xmloff/prhdlfac.hxx> + + +//______________________________________________________________________________ + +class XMLPageMasterPropHdlFactory : public XMLPropertyHandlerFactory +{ +public: + XMLPageMasterPropHdlFactory(); + virtual ~XMLPageMasterPropHdlFactory(); + + virtual const XMLPropertyHandler* + GetPropertyHandler( sal_Int32 nType ) const; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/PageMasterPropMapper.cxx b/xmloff/source/style/PageMasterPropMapper.cxx new file mode 100644 index 000000000000..97159c698f9c --- /dev/null +++ b/xmloff/source/style/PageMasterPropMapper.cxx @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + +#include "PageMasterPropMapper.hxx" + + +#include <xmloff/PageMasterStyleMap.hxx> +#include "PageMasterPropHdlFactory.hxx" + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; + + +//______________________________________________________________________________ + +XMLPageMasterPropSetMapper::XMLPageMasterPropSetMapper(): + XMLPropertySetMapper( aXMLPageMasterStyleMap, new XMLPageMasterPropHdlFactory()) +{ +} + +XMLPageMasterPropSetMapper::XMLPageMasterPropSetMapper( + const XMLPropertyMapEntry* pEntries, + const UniReference< XMLPropertyHandlerFactory >& rFactory ) : + XMLPropertySetMapper( pEntries, rFactory ) +{ +} + +XMLPageMasterPropSetMapper::~XMLPageMasterPropSetMapper() +{ +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/PageMasterPropMapper.hxx b/xmloff/source/style/PageMasterPropMapper.hxx new file mode 100644 index 000000000000..2b48501b75d7 --- /dev/null +++ b/xmloff/source/style/PageMasterPropMapper.hxx @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PAGEMASTERPROPMAPPER_HXX_ +#define _XMLOFF_PAGEMASTERPROPMAPPER_HXX_ + +#include <xmloff/xmlprmap.hxx> + + +//______________________________________________________________________________ + +class XMLPageMasterPropSetMapper : public XMLPropertySetMapper +{ +public: + XMLPageMasterPropSetMapper(); + XMLPageMasterPropSetMapper( + const XMLPropertyMapEntry* pEntries, + const UniReference< XMLPropertyHandlerFactory >& rFactory ); + virtual ~XMLPageMasterPropSetMapper(); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/PageMasterStyleMap.cxx b/xmloff/source/style/PageMasterStyleMap.cxx new file mode 100644 index 000000000000..af5feb81d61c --- /dev/null +++ b/xmloff/source/style/PageMasterStyleMap.cxx @@ -0,0 +1,193 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + +#include <xmloff/PageMasterStyleMap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> + +using namespace ::xmloff::token; + +#define _MAP(name,prefix,token,type,context) { name, sizeof(name)-1, prefix, token, type, context, SvtSaveOptions::ODFVER_010 } +#define PLMAP(name,prefix,token,type,context) \ + _MAP(name,prefix,token,type|XML_TYPE_PROP_PAGE_LAYOUT,context) +#define HFMAP(name,prefix,token,type,context) \ + _MAP(name,prefix,token,type|XML_TYPE_PROP_HEADER_FOOTER,context) + +//______________________________________________________________________________ + +const XMLPropertyMapEntry aXMLPageMasterStyleMap[] = +{ +// page master + PLMAP( "PageStyleLayout", XML_NAMESPACE_STYLE, XML_PAGE_USAGE, XML_PM_TYPE_PAGESTYLELAYOUT | MID_FLAG_SPECIAL_ITEM, CTF_PM_PAGEUSAGE ), + PLMAP( "Width", XML_NAMESPACE_FO, XML_PAGE_WIDTH, XML_TYPE_MEASURE, 0 ), + PLMAP( "Height", XML_NAMESPACE_FO, XML_PAGE_HEIGHT, XML_TYPE_MEASURE, 0 ), + PLMAP( "NumberingType", XML_NAMESPACE_STYLE, XML_NUM_FORMAT, XML_PM_TYPE_NUMFORMAT | MID_FLAG_MERGE_PROPERTY, 0 ), + PLMAP( "NumberingType", XML_NAMESPACE_STYLE, XML_NUM_LETTER_SYNC, XML_PM_TYPE_NUMLETTERSYNC, 0 ), + PLMAP( "PrinterPaperTray", XML_NAMESPACE_STYLE, XML_PAPER_TRAY_NAME, XML_TYPE_STRING | MID_FLAG_PROPERTY_MAY_EXCEPT, 0 ), + PLMAP( "IsLandscape", XML_NAMESPACE_STYLE, XML_PRINT_ORIENTATION, XML_PM_TYPE_PRINTORIENTATION, 0 ), + PLMAP( "TopMargin", XML_NAMESPACE_FO, XML_MARGIN_TOP, XML_TYPE_MEASURE, 0 ), + PLMAP( "BottomMargin", XML_NAMESPACE_FO, XML_MARGIN_BOTTOM, XML_TYPE_MEASURE, 0 ), + PLMAP( "LeftMargin", XML_NAMESPACE_FO, XML_MARGIN_LEFT, XML_TYPE_MEASURE, 0 ), + PLMAP( "RightMargin", XML_NAMESPACE_FO, XML_MARGIN_RIGHT, XML_TYPE_MEASURE, 0 ), + PLMAP( "TopBorder", XML_NAMESPACE_FO, XML_BORDER, XML_TYPE_BORDER, CTF_PM_BORDERALL ), + PLMAP( "TopBorder", XML_NAMESPACE_FO, XML_BORDER_TOP, XML_TYPE_BORDER, CTF_PM_BORDERTOP ), + PLMAP( "BottomBorder", XML_NAMESPACE_FO, XML_BORDER_BOTTOM, XML_TYPE_BORDER, CTF_PM_BORDERBOTTOM ), + PLMAP( "LeftBorder", XML_NAMESPACE_FO, XML_BORDER_LEFT, XML_TYPE_BORDER, CTF_PM_BORDERLEFT ), + PLMAP( "RightBorder", XML_NAMESPACE_FO, XML_BORDER_RIGHT, XML_TYPE_BORDER, CTF_PM_BORDERRIGHT ), + PLMAP( "TopBorder", XML_NAMESPACE_STYLE, XML_BORDER_LINE_WIDTH, XML_TYPE_BORDER_WIDTH, CTF_PM_BORDERWIDTHALL ), + PLMAP( "TopBorder", XML_NAMESPACE_STYLE, XML_BORDER_LINE_WIDTH_TOP, XML_TYPE_BORDER_WIDTH, CTF_PM_BORDERWIDTHTOP ), + PLMAP( "BottomBorder", XML_NAMESPACE_STYLE, XML_BORDER_LINE_WIDTH_BOTTOM, XML_TYPE_BORDER_WIDTH, CTF_PM_BORDERWIDTHBOTTOM ), + PLMAP( "LeftBorder", XML_NAMESPACE_STYLE, XML_BORDER_LINE_WIDTH_LEFT, XML_TYPE_BORDER_WIDTH, CTF_PM_BORDERWIDTHLEFT ), + PLMAP( "RightBorder", XML_NAMESPACE_STYLE, XML_BORDER_LINE_WIDTH_RIGHT, XML_TYPE_BORDER_WIDTH, CTF_PM_BORDERWIDTHRIGHT ), + PLMAP( "TopBorderDistance", XML_NAMESPACE_FO, XML_PADDING, XML_TYPE_MEASURE, CTF_PM_PADDINGALL ), + PLMAP( "TopBorderDistance", XML_NAMESPACE_FO, XML_PADDING_TOP, XML_TYPE_MEASURE, CTF_PM_PADDINGTOP ), + PLMAP( "BottomBorderDistance", XML_NAMESPACE_FO, XML_PADDING_BOTTOM, XML_TYPE_MEASURE, CTF_PM_PADDINGBOTTOM ), + PLMAP( "LeftBorderDistance", XML_NAMESPACE_FO, XML_PADDING_LEFT, XML_TYPE_MEASURE, CTF_PM_PADDINGLEFT ), + PLMAP( "RightBorderDistance", XML_NAMESPACE_FO, XML_PADDING_RIGHT, XML_TYPE_MEASURE, CTF_PM_PADDINGRIGHT ), + PLMAP( "ShadowFormat", XML_NAMESPACE_STYLE, XML_SHADOW, XML_TYPE_TEXT_SHADOW, 0 ), + PLMAP( "BackColor", XML_NAMESPACE_FO, XML_BACKGROUND_COLOR, XML_TYPE_COLORTRANSPARENT | MID_FLAG_MULTI_PROPERTY, 0 ), + PLMAP( "BackTransparent", XML_NAMESPACE_FO, XML_BACKGROUND_COLOR, XML_TYPE_ISTRANSPARENT | MID_FLAG_MERGE_ATTRIBUTE, 0 ), + PLMAP( "BackGraphicLocation", XML_NAMESPACE_STYLE, XML_POSITION, XML_TYPE_BUILDIN_CMP_ONLY | MID_FLAG_SPECIAL_ITEM, CTF_PM_GRAPHICPOSITION ), + PLMAP( "BackGraphicFilter", XML_NAMESPACE_STYLE, XML_FILTER_NAME, XML_TYPE_STRING | MID_FLAG_SPECIAL_ITEM, CTF_PM_GRAPHICFILTER ), + PLMAP( "BackGraphicURL", XML_NAMESPACE_STYLE, XML_BACKGROUND_IMAGE, XML_TYPE_STRING | MID_FLAG_ELEMENT_ITEM, CTF_PM_GRAPHICURL ), + PLMAP( "PrintAnnotations", XML_NAMESPACE_STYLE, XML_PRINT, XML_PM_TYPE_PRINTANNOTATIONS | MID_FLAG_MULTI_PROPERTY, CTF_PM_PRINT_ANNOTATIONS ), + PLMAP( "PrintCharts", XML_NAMESPACE_STYLE, XML_PRINT, XML_PM_TYPE_PRINTCHARTS | MID_FLAG_MULTI_PROPERTY | MID_FLAG_MERGE_ATTRIBUTE, CTF_PM_PRINT_CHARTS ), + PLMAP( "PrintDrawing", XML_NAMESPACE_STYLE, XML_PRINT, XML_PM_TYPE_PRINTDRAWING | MID_FLAG_MULTI_PROPERTY | MID_FLAG_MERGE_ATTRIBUTE, CTF_PM_PRINT_DRAWING ), + PLMAP( "PrintFormulas", XML_NAMESPACE_STYLE, XML_PRINT, XML_PM_TYPE_PRINTFORMULAS | MID_FLAG_MULTI_PROPERTY | MID_FLAG_MERGE_ATTRIBUTE, CTF_PM_PRINT_FORMULAS ), + PLMAP( "PrintGrid", XML_NAMESPACE_STYLE, XML_PRINT, XML_PM_TYPE_PRINTGRID | MID_FLAG_MULTI_PROPERTY | MID_FLAG_MERGE_ATTRIBUTE, CTF_PM_PRINT_GRID ), + PLMAP( "PrintHeaders", XML_NAMESPACE_STYLE, XML_PRINT, XML_PM_TYPE_PRINTHEADERS | MID_FLAG_MULTI_PROPERTY | MID_FLAG_MERGE_ATTRIBUTE, CTF_PM_PRINT_HEADERS ), + PLMAP( "PrintObjects", XML_NAMESPACE_STYLE, XML_PRINT, XML_PM_TYPE_PRINTOBJECTS | MID_FLAG_MULTI_PROPERTY | MID_FLAG_MERGE_ATTRIBUTE, CTF_PM_PRINT_OBJECTS ), + PLMAP( "PrintZeroValues", XML_NAMESPACE_STYLE, XML_PRINT, XML_PM_TYPE_PRINTZEROVALUES | MID_FLAG_MERGE_ATTRIBUTE, CTF_PM_PRINT_ZEROVALUES ), + PLMAP( "PrintDownFirst", XML_NAMESPACE_STYLE, XML_PRINT_PAGE_ORDER, XML_PM_TYPE_PRINTPAGEORDER, 0 ), + PLMAP( "FirstPageNumber", XML_NAMESPACE_STYLE, XML_FIRST_PAGE_NUMBER, XML_PM_TYPE_FIRSTPAGENUMBER, 0 ), + PLMAP( "PageScale", XML_NAMESPACE_STYLE, XML_SCALE_TO, XML_TYPE_PERCENT16, CTF_PM_SCALETO ), + PLMAP( "ScaleToPages", XML_NAMESPACE_STYLE, XML_SCALE_TO_PAGES, XML_TYPE_NUMBER16, CTF_PM_SCALETOPAGES ), + PLMAP( "ScaleToPagesX", XML_NAMESPACE_STYLE, XML_SCALE_TO_X, XML_TYPE_NUMBER16, CTF_PM_SCALETOX ), + PLMAP( "ScaleToPagesY", XML_NAMESPACE_STYLE, XML_SCALE_TO_Y, XML_TYPE_NUMBER16, CTF_PM_SCALETOY ), + PLMAP( "CenterHorizontally", XML_NAMESPACE_STYLE, XML_TABLE_CENTERING, XML_PM_TYPE_CENTER_HORIZONTAL | MID_FLAG_MULTI_PROPERTY | MID_FLAG_MERGE_ATTRIBUTE, 0 ), + PLMAP( "CenterVertically", XML_NAMESPACE_STYLE, XML_TABLE_CENTERING, XML_PM_TYPE_CENTER_VERTICAL | MID_FLAG_MULTI_PROPERTY | MID_FLAG_MERGE_ATTRIBUTE, 0 ), + PLMAP( "TextColumns", XML_NAMESPACE_STYLE, XML_COLUMNS, MID_FLAG_ELEMENT_ITEM|XML_TYPE_TEXT_COLUMNS, CTF_PM_TEXTCOLUMNS ), + PLMAP( "RegisterModeActive", XML_NAMESPACE_STYLE, XML_REGISTER_TRUE, XML_TYPE_BOOL, 0 ), + PLMAP( "RegisterParagraphStyle", XML_NAMESPACE_STYLE, XML_REGISTER_TRUTH_REF_STYLE_NAME, XML_TYPE_STYLENAME| MID_FLAG_SPECIAL_ITEM_IMPORT, CTF_PM_REGISTER_STYLE ), + PLMAP( "WritingMode", XML_NAMESPACE_STYLE, XML_WRITING_MODE, XML_TYPE_TEXT_WRITING_MODE, 0 ), + + PLMAP( "GridColor", XML_NAMESPACE_STYLE, XML_LAYOUT_GRID_COLOR, XML_TYPE_COLOR, 0 ), + PLMAP( "GridLines", XML_NAMESPACE_STYLE, XML_LAYOUT_GRID_LINES, XML_TYPE_NUMBER16, 0 ), + PLMAP( "GridBaseHeight", XML_NAMESPACE_STYLE, XML_LAYOUT_GRID_BASE_HEIGHT, XML_TYPE_MEASURE, 0 ), + PLMAP( "GridRubyHeight", XML_NAMESPACE_STYLE, XML_LAYOUT_GRID_RUBY_HEIGHT, XML_TYPE_MEASURE, 0 ), + PLMAP( "GridMode", XML_NAMESPACE_STYLE, XML_LAYOUT_GRID_MODE, XML_TYPE_LAYOUT_GRID_MODE, 0 ), + PLMAP( "RubyBelow", XML_NAMESPACE_STYLE, XML_LAYOUT_GRID_RUBY_BELOW, XML_TYPE_BOOL, 0 ), + PLMAP( "GridPrint", XML_NAMESPACE_STYLE, XML_LAYOUT_GRID_PRINT, XML_TYPE_BOOL, 0 ), + PLMAP( "GridDisplay", XML_NAMESPACE_STYLE, XML_LAYOUT_GRID_DISPLAY, XML_TYPE_BOOL, 0 ), + + //text grid enhancement for better CJK support + PLMAP( "GridBaseWidth", XML_NAMESPACE_STYLE, XML_LAYOUT_GRID_BASE_WIDTH, XML_TYPE_MEASURE, CTP_PM_GRID_BASE_WIDTH ), + PLMAP( "GridSnapToChars", XML_NAMESPACE_STYLE, XML_LAYOUT_GRID_SNAP_TO, XML_TYPE_BOOL, CTP_PM_GRID_SNAP_TO_CHARS ), + PLMAP( "GridSnapToChars", XML_NAMESPACE_STYLE, XML_LAYOUT_GRID_SNAP_TO_CHARS, XML_TYPE_BOOL, CTP_PM_GRID_SNAP_TO_CHARS ), + //export as a default attribute + PLMAP( "StandardPageMode", XML_NAMESPACE_STYLE, XML_LAYOUT_GRID_STANDARD_MODE, XML_TYPE_BOOL|MID_FLAG_DEFAULT_ITEM_EXPORT, CTF_PM_STANDARD_MODE ), + + PLMAP( "UserDefinedAttributes", XML_NAMESPACE_TEXT, XML_XMLNS, XML_TYPE_ATTRIBUTE_CONTAINER | MID_FLAG_SPECIAL_ITEM, 0 ), + +// footnote + PLMAP( "FootnoteHeight", XML_NAMESPACE_STYLE, XML_FOOTNOTE_MAX_HEIGHT, XML_TYPE_MEASURE, CTF_PM_FTN_HEIGTH ), + PLMAP( "FootnoteLineAdjust", XML_NAMESPACE_STYLE, XML__EMPTY, XML_TYPE_TEXT_HORIZONTAL_ADJUST|MID_FLAG_SPECIAL_ITEM, CTF_PM_FTN_LINE_ADJUST ), + PLMAP( "FootnoteLineColor", XML_NAMESPACE_STYLE, XML__EMPTY, XML_TYPE_COLOR|MID_FLAG_SPECIAL_ITEM, CTF_PM_FTN_LINE_COLOR ), + PLMAP( "FootnoteLineDistance", XML_NAMESPACE_STYLE, XML__EMPTY, XML_TYPE_MEASURE|MID_FLAG_SPECIAL_ITEM,CTF_PM_FTN_DISTANCE ), + PLMAP( "FootnoteLineRelativeWidth", XML_NAMESPACE_STYLE, XML__EMPTY, XML_TYPE_PERCENT8|MID_FLAG_SPECIAL_ITEM, CTF_PM_FTN_LINE_WIDTH ), + PLMAP( "FootnoteLineTextDistance", XML_NAMESPACE_STYLE, XML__EMPTY, XML_TYPE_MEASURE|MID_FLAG_SPECIAL_ITEM, CTF_PM_FTN_LINE_DISTANCE ), + PLMAP( "FootnoteLineWeight", XML_NAMESPACE_STYLE, XML_FOOTNOTE_SEP, XML_TYPE_MEASURE16|MID_FLAG_ELEMENT_ITEM, CTF_PM_FTN_LINE_WEIGTH ), + PLMAP( "FootnoteLineStyle", XML_NAMESPACE_STYLE, XML_EMPTY, XML_TYPE_STRING|MID_FLAG_ELEMENT_ITEM, CTF_PM_FTN_LINE_STYLE ), + +// header + HFMAP( "HeaderHeight", XML_NAMESPACE_SVG, XML_HEIGHT, XML_TYPE_MEASURE, CTF_PM_HEADERHEIGHT ), + HFMAP( "HeaderHeight", XML_NAMESPACE_FO, XML_MIN_HEIGHT, XML_TYPE_MEASURE, CTF_PM_HEADERMINHEIGHT ), + HFMAP( "HeaderIsDynamicHeight", XML_NAMESPACE_STYLE, XML__EMPTY, XML_TYPE_BOOL, CTF_PM_HEADERDYNAMIC ), + HFMAP( "HeaderLeftMargin", XML_NAMESPACE_FO, XML_MARGIN_LEFT, XML_TYPE_MEASURE, CTF_PM_HEADERFLAG ), + HFMAP( "HeaderRightMargin", XML_NAMESPACE_FO, XML_MARGIN_RIGHT, XML_TYPE_MEASURE, CTF_PM_HEADERFLAG ), + HFMAP( "HeaderBodyDistance", XML_NAMESPACE_FO, XML_MARGIN_BOTTOM, XML_TYPE_MEASURE, CTF_PM_HEADERFLAG ), + HFMAP( "HeaderTopBorder", XML_NAMESPACE_FO, XML_BORDER, XML_TYPE_BORDER, CTF_PM_HEADERBORDERALL ), + HFMAP( "HeaderTopBorder", XML_NAMESPACE_FO, XML_BORDER_TOP, XML_TYPE_BORDER, CTF_PM_HEADERBORDERTOP ), + HFMAP( "HeaderBottomBorder", XML_NAMESPACE_FO, XML_BORDER_BOTTOM, XML_TYPE_BORDER, CTF_PM_HEADERBORDERBOTTOM ), + HFMAP( "HeaderLeftBorder", XML_NAMESPACE_FO, XML_BORDER_LEFT, XML_TYPE_BORDER, CTF_PM_HEADERBORDERLEFT ), + HFMAP( "HeaderRightBorder", XML_NAMESPACE_FO, XML_BORDER_RIGHT, XML_TYPE_BORDER, CTF_PM_HEADERBORDERRIGHT ), + HFMAP( "HeaderTopBorder", XML_NAMESPACE_STYLE, XML_BORDER_LINE_WIDTH, XML_TYPE_BORDER_WIDTH, CTF_PM_HEADERBORDERWIDTHALL ), + HFMAP( "HeaderTopBorder", XML_NAMESPACE_STYLE, XML_BORDER_LINE_WIDTH_TOP, XML_TYPE_BORDER_WIDTH, CTF_PM_HEADERBORDERWIDTHTOP ), + HFMAP( "HeaderBottomBorder", XML_NAMESPACE_STYLE, XML_BORDER_LINE_WIDTH_BOTTOM, XML_TYPE_BORDER_WIDTH, CTF_PM_HEADERBORDERWIDTHBOTTOM ), + HFMAP( "HeaderLeftBorder", XML_NAMESPACE_STYLE, XML_BORDER_LINE_WIDTH_LEFT, XML_TYPE_BORDER_WIDTH, CTF_PM_HEADERBORDERWIDTHLEFT ), + HFMAP( "HeaderRightBorder", XML_NAMESPACE_STYLE, XML_BORDER_LINE_WIDTH_RIGHT, XML_TYPE_BORDER_WIDTH, CTF_PM_HEADERBORDERWIDTHRIGHT ), + HFMAP( "HeaderTopBorderDistance", XML_NAMESPACE_FO, XML_PADDING, XML_TYPE_MEASURE, CTF_PM_HEADERPADDINGALL ), + HFMAP( "HeaderTopBorderDistance", XML_NAMESPACE_FO, XML_PADDING_TOP, XML_TYPE_MEASURE, CTF_PM_HEADERPADDINGTOP ), + HFMAP( "HeaderBottomBorderDistance", XML_NAMESPACE_FO, XML_PADDING_BOTTOM, XML_TYPE_MEASURE, CTF_PM_HEADERPADDINGBOTTOM ), + HFMAP( "HeaderLeftBorderDistance", XML_NAMESPACE_FO, XML_PADDING_LEFT, XML_TYPE_MEASURE, CTF_PM_HEADERPADDINGLEFT ), + HFMAP( "HeaderRightBorderDistance", XML_NAMESPACE_FO, XML_PADDING_RIGHT, XML_TYPE_MEASURE, CTF_PM_HEADERPADDINGRIGHT ), + HFMAP( "HeaderShadowFormat", XML_NAMESPACE_STYLE, XML_SHADOW, XML_TYPE_TEXT_SHADOW, CTF_PM_HEADERFLAG ), + HFMAP( "HeaderBackColor", XML_NAMESPACE_FO, XML_BACKGROUND_COLOR, XML_TYPE_COLORTRANSPARENT | MID_FLAG_MULTI_PROPERTY, CTF_PM_HEADERFLAG ), + HFMAP( "HeaderBackTransparent", XML_NAMESPACE_FO, XML_BACKGROUND_COLOR, XML_TYPE_ISTRANSPARENT | MID_FLAG_MERGE_ATTRIBUTE, CTF_PM_HEADERFLAG ), + HFMAP( "HeaderBackGraphicLocation", XML_NAMESPACE_STYLE, XML_POSITION, XML_TYPE_BUILDIN_CMP_ONLY | MID_FLAG_SPECIAL_ITEM, CTF_PM_HEADERGRAPHICPOSITION ), + HFMAP( "HeaderBackGraphicFilter", XML_NAMESPACE_STYLE, XML_FILTER_NAME, XML_TYPE_STRING | MID_FLAG_SPECIAL_ITEM, CTF_PM_HEADERGRAPHICFILTER ), + HFMAP( "HeaderBackGraphicURL", XML_NAMESPACE_STYLE, XML_BACKGROUND_IMAGE, XML_TYPE_STRING | MID_FLAG_ELEMENT_ITEM, CTF_PM_HEADERGRAPHICURL ), + HFMAP( "HeaderDynamicSpacing", XML_NAMESPACE_STYLE, XML_DYNAMIC_SPACING, XML_TYPE_BOOL, CTF_PM_HEADERFLAG ), + +// footer + HFMAP( "FooterHeight", XML_NAMESPACE_SVG, XML_HEIGHT, XML_TYPE_MEASURE, CTF_PM_FOOTERHEIGHT ), + HFMAP( "FooterHeight", XML_NAMESPACE_FO, XML_MIN_HEIGHT, XML_TYPE_MEASURE, CTF_PM_FOOTERMINHEIGHT ), + HFMAP( "FooterIsDynamicHeight", XML_NAMESPACE_STYLE, XML__EMPTY, XML_TYPE_BOOL, CTF_PM_FOOTERDYNAMIC ), + HFMAP( "FooterLeftMargin", XML_NAMESPACE_FO, XML_MARGIN_LEFT, XML_TYPE_MEASURE, CTF_PM_FOOTERFLAG ), + HFMAP( "FooterRightMargin", XML_NAMESPACE_FO, XML_MARGIN_RIGHT, XML_TYPE_MEASURE, CTF_PM_FOOTERFLAG ), + HFMAP( "FooterBodyDistance", XML_NAMESPACE_FO, XML_MARGIN_TOP, XML_TYPE_MEASURE, CTF_PM_FOOTERFLAG ), + HFMAP( "FooterTopBorder", XML_NAMESPACE_FO, XML_BORDER, XML_TYPE_BORDER, CTF_PM_FOOTERBORDERALL ), + HFMAP( "FooterTopBorder", XML_NAMESPACE_FO, XML_BORDER_TOP, XML_TYPE_BORDER, CTF_PM_FOOTERBORDERTOP ), + HFMAP( "FooterBottomBorder", XML_NAMESPACE_FO, XML_BORDER_BOTTOM, XML_TYPE_BORDER, CTF_PM_FOOTERBORDERBOTTOM ), + HFMAP( "FooterLeftBorder", XML_NAMESPACE_FO, XML_BORDER_LEFT, XML_TYPE_BORDER, CTF_PM_FOOTERBORDERLEFT ), + HFMAP( "FooterRightBorder", XML_NAMESPACE_FO, XML_BORDER_RIGHT, XML_TYPE_BORDER, CTF_PM_FOOTERBORDERRIGHT ), + HFMAP( "FooterTopBorder", XML_NAMESPACE_STYLE, XML_BORDER_LINE_WIDTH, XML_TYPE_BORDER_WIDTH, CTF_PM_FOOTERBORDERWIDTHALL ), + HFMAP( "FooterTopBorder", XML_NAMESPACE_STYLE, XML_BORDER_LINE_WIDTH_TOP, XML_TYPE_BORDER_WIDTH, CTF_PM_FOOTERBORDERWIDTHTOP ), + HFMAP( "FooterBottomBorder", XML_NAMESPACE_STYLE, XML_BORDER_LINE_WIDTH_BOTTOM, XML_TYPE_BORDER_WIDTH, CTF_PM_FOOTERBORDERWIDTHBOTTOM ), + HFMAP( "FooterLeftBorder", XML_NAMESPACE_STYLE, XML_BORDER_LINE_WIDTH_LEFT, XML_TYPE_BORDER_WIDTH, CTF_PM_FOOTERBORDERWIDTHLEFT ), + HFMAP( "FooterRightBorder", XML_NAMESPACE_STYLE, XML_BORDER_LINE_WIDTH_RIGHT, XML_TYPE_BORDER_WIDTH, CTF_PM_FOOTERBORDERWIDTHRIGHT ), + HFMAP( "FooterTopBorderDistance", XML_NAMESPACE_FO, XML_PADDING, XML_TYPE_MEASURE, CTF_PM_FOOTERPADDINGALL ), + HFMAP( "FooterTopBorderDistance", XML_NAMESPACE_FO, XML_PADDING_TOP, XML_TYPE_MEASURE, CTF_PM_FOOTERPADDINGTOP ), + HFMAP( "FooterBottomBorderDistance", XML_NAMESPACE_FO, XML_PADDING_BOTTOM, XML_TYPE_MEASURE, CTF_PM_FOOTERPADDINGBOTTOM ), + HFMAP( "FooterLeftBorderDistance", XML_NAMESPACE_FO, XML_PADDING_LEFT, XML_TYPE_MEASURE, CTF_PM_FOOTERPADDINGLEFT ), + HFMAP( "FooterRightBorderDistance", XML_NAMESPACE_FO, XML_PADDING_RIGHT, XML_TYPE_MEASURE, CTF_PM_FOOTERPADDINGRIGHT ), + HFMAP( "FooterShadowFormat", XML_NAMESPACE_STYLE, XML_SHADOW, XML_TYPE_TEXT_SHADOW, CTF_PM_FOOTERFLAG ), + HFMAP( "FooterBackColor", XML_NAMESPACE_FO, XML_BACKGROUND_COLOR, XML_TYPE_COLORTRANSPARENT | MID_FLAG_MULTI_PROPERTY, CTF_PM_FOOTERFLAG ), + HFMAP( "FooterBackTransparent", XML_NAMESPACE_FO, XML_BACKGROUND_COLOR, XML_TYPE_ISTRANSPARENT | MID_FLAG_MERGE_ATTRIBUTE, CTF_PM_FOOTERFLAG ), + HFMAP( "FooterBackGraphicLocation", XML_NAMESPACE_STYLE, XML_POSITION, XML_TYPE_BUILDIN_CMP_ONLY | MID_FLAG_SPECIAL_ITEM, CTF_PM_FOOTERGRAPHICPOSITION ), + HFMAP( "FooterBackGraphicFilter", XML_NAMESPACE_STYLE, XML_FILTER_NAME, XML_TYPE_STRING | MID_FLAG_SPECIAL_ITEM, CTF_PM_FOOTERGRAPHICFILTER ), + HFMAP( "FooterBackGraphicURL", XML_NAMESPACE_STYLE, XML_BACKGROUND_IMAGE, XML_TYPE_STRING | MID_FLAG_ELEMENT_ITEM, CTF_PM_FOOTERGRAPHICURL ), + HFMAP( "FooterDynamicSpacing", XML_NAMESPACE_STYLE, XML_DYNAMIC_SPACING, XML_TYPE_BOOL, CTF_PM_FOOTERFLAG ), + + { 0L, 0, 0, XML_EMPTY, 0, 0, SvtSaveOptions::ODFVER_010 } +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/PagePropertySetContext.cxx b/xmloff/source/style/PagePropertySetContext.cxx new file mode 100644 index 000000000000..21c2c09ec31a --- /dev/null +++ b/xmloff/source/style/PagePropertySetContext.cxx @@ -0,0 +1,136 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include "PagePropertySetContext.hxx" +#include "XMLBackgroundImageContext.hxx" +#include "XMLTextColumnsContext.hxx" +#include <xmloff/PageMasterStyleMap.hxx> +#include "XMLFootnoteSeparatorImport.hxx" + +using ::rtl::OUString; + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star; + +PagePropertySetContext::PagePropertySetContext( + SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > & xAttrList, + sal_uInt32 nFam, + ::std::vector< XMLPropertyState > &rProps, + const UniReference < SvXMLImportPropertyMapper > &rMap, + sal_Int32 nStartIndex, sal_Int32 nEndIndex, + const PageContextType aTempType ) : + SvXMLPropertySetContext( rImport, nPrfx, rLName, xAttrList, nFam, + rProps, rMap, nStartIndex, nEndIndex ) +{ + aType = aTempType; +} + +PagePropertySetContext::~PagePropertySetContext() +{ +} + +SvXMLImportContext *PagePropertySetContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference< xml::sax::XAttributeList > & xAttrList, + ::std::vector< XMLPropertyState > &rProperties, + const XMLPropertyState& rProp ) +{ + sal_Int32 nPos = CTF_PM_GRAPHICPOSITION; + sal_Int32 nFil = CTF_PM_GRAPHICFILTER; + switch ( aType ) + { + case Header: + { + nPos = CTF_PM_HEADERGRAPHICPOSITION; + nFil = CTF_PM_HEADERGRAPHICFILTER; + } + break; + case Footer: + { + nPos = CTF_PM_FOOTERGRAPHICPOSITION; + nFil = CTF_PM_FOOTERGRAPHICFILTER; + } + break; + default: + break; + } + SvXMLImportContext *pContext = 0; + + switch( mxMapper->getPropertySetMapper() + ->GetEntryContextId( rProp.mnIndex ) ) + { + case CTF_PM_GRAPHICURL: + case CTF_PM_HEADERGRAPHICURL: + case CTF_PM_FOOTERGRAPHICURL: + DBG_ASSERT( rProp.mnIndex >= 2 && + nPos == mxMapper->getPropertySetMapper() + ->GetEntryContextId( rProp.mnIndex-2 ) && + nFil == mxMapper->getPropertySetMapper() + ->GetEntryContextId( rProp.mnIndex-1 ), + "invalid property map!"); + (void)nPos; + (void)nFil; + pContext = + new XMLBackgroundImageContext( GetImport(), nPrefix, + rLocalName, xAttrList, + rProp, + rProp.mnIndex-2, + rProp.mnIndex-1, + -1, + rProperties ); + break; + + case CTF_PM_TEXTCOLUMNS: + pContext = new XMLTextColumnsContext( GetImport(), nPrefix, + rLocalName, xAttrList, rProp, + rProperties ); + break; + + case CTF_PM_FTN_LINE_WEIGTH: + pContext = new XMLFootnoteSeparatorImport( + GetImport(), nPrefix, rLocalName, rProperties, + mxMapper->getPropertySetMapper(), rProp.mnIndex); + break; + } + + if( !pContext ) + pContext = SvXMLPropertySetContext::CreateChildContext( nPrefix, rLocalName, + xAttrList, + rProperties, rProp ); + + return pContext; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/PagePropertySetContext.hxx b/xmloff/source/style/PagePropertySetContext.hxx new file mode 100644 index 000000000000..cfa2e554f77b --- /dev/null +++ b/xmloff/source/style/PagePropertySetContext.hxx @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PAGEPROPERTYSETCONTEXT_HXX +#define _XMLOFF_PAGEPROPERTYSETCONTEXT_HXX + +#include <xmloff/xmlprcon.hxx> + +enum PageContextType +{ + Page, + Header, + Footer +}; + +class PagePropertySetContext : public SvXMLPropertySetContext +{ + PageContextType aType; + +public: + PagePropertySetContext( SvXMLImport& rImport, sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList >& xAttrList, + sal_uInt32 nFam, + ::std::vector< XMLPropertyState > &rProps, + const UniReference < SvXMLImportPropertyMapper > &rMap, + sal_Int32 nStartIndex, sal_Int32 nEndIndex, + const PageContextType aType ); + + virtual ~PagePropertySetContext(); + + using SvXMLPropertySetContext::CreateChildContext; + virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList, + ::std::vector< XMLPropertyState > &rProperties, + const XMLPropertyState& rProp); +}; + + +#endif // _XMLOFF_XMLTEXTPROPERTYSETCONTEXT_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/SinglePropertySetInfoCache.cxx b/xmloff/source/style/SinglePropertySetInfoCache.cxx new file mode 100644 index 000000000000..6282828e162f --- /dev/null +++ b/xmloff/source/style/SinglePropertySetInfoCache.cxx @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <com/sun/star/lang/XTypeProvider.hpp> +#include <cppuhelper/weakref.hxx> + +#include <xmloff/SinglePropertySetInfoCache.hxx> + +using namespace ::com::sun::star::uno; +using ::com::sun::star::lang::XTypeProvider; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::beans::XPropertySetInfo; + +sal_Bool SinglePropertySetInfoCache::hasProperty( + const Reference< XPropertySet >& rPropSet, + Reference< XPropertySetInfo >& rPropSetInfo ) +{ + if( !rPropSetInfo.is() ) + rPropSetInfo = rPropSet->getPropertySetInfo(); + sal_Bool bRet = sal_False, bValid = sal_False; + Reference < XTypeProvider > xTypeProv( rPropSet, UNO_QUERY ); + Sequence< sal_Int8 > aImplId; + if( xTypeProv.is() ) + { + aImplId = xTypeProv->getImplementationId(); + if( aImplId.getLength() == 16 ) + { + // The key must not be created outside this block, because it + // keeps a reference to the property set info. + PropertySetInfoKey aKey( rPropSetInfo, aImplId ); + iterator aIter = find( aKey ); + if( aIter != end() ) + { + bRet = (*aIter).second; + bValid = sal_True; + } + } + } + if( !bValid ) + { + bRet = rPropSetInfo->hasPropertyByName( sName ); + if( xTypeProv.is() && aImplId.getLength() == 16 ) + { + // Check whether the property set info is destroyed if it is + // assigned to a weak reference only. If it is destroyed, then + // every instance of getPropertySetInfo returns a new object. + // Such property set infos must not be cached. + WeakReference < XPropertySetInfo > xWeakInfo( rPropSetInfo ); + rPropSetInfo = 0; + rPropSetInfo = xWeakInfo; + if( rPropSetInfo.is() ) + { + PropertySetInfoKey aKey( rPropSetInfo, aImplId ); + value_type aValue( aKey, bRet ); + insert( aValue ); + } + } + } + + return bRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/StyleMap.cxx b/xmloff/source/style/StyleMap.cxx new file mode 100644 index 000000000000..66b9453f4bb8 --- /dev/null +++ b/xmloff/source/style/StyleMap.cxx @@ -0,0 +1,96 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <osl/mutex.hxx> +#include <rtl/uuid.h> +#include <rtl/memory.h> + +#include "StyleMap.hxx" + +using namespace ::osl; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; + + +StyleMap::StyleMap() +{ +} + + + +StyleMap::~StyleMap() +{ +} + + +// XUnoTunnel & co +const Sequence< sal_Int8 > & StyleMap::getUnoTunnelId() throw() +{ + static Sequence< sal_Int8 > * pSeq = 0; + if( !pSeq ) + { + Guard< Mutex > aGuard( Mutex::getGlobalMutex() ); + if( !pSeq ) + { + static Sequence< sal_Int8 > aSeq( 16 ); + rtl_createUuid( reinterpret_cast<sal_uInt8*>( aSeq.getArray() ), + 0, sal_True ); + pSeq = &aSeq; + } + } + return *pSeq; +} + +StyleMap* StyleMap::getImplementation( Reference< XInterface > xInt ) throw() +{ + Reference< XUnoTunnel > xUT( xInt, UNO_QUERY ); + if( xUT.is() ) + return reinterpret_cast<StyleMap *>( + xUT->getSomething( StyleMap::getUnoTunnelId() ) ); + else + return 0; +} + +// XUnoTunnel +sal_Int64 SAL_CALL StyleMap::getSomething( + const Sequence< sal_Int8 >& rId ) + throw( RuntimeException ) +{ + if( rId.getLength() == 16 && + 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), + rId.getConstArray(), 16 ) ) + { + return reinterpret_cast<sal_Int64>( this ); + } + return 0; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/TransGradientStyle.cxx b/xmloff/source/style/TransGradientStyle.cxx new file mode 100644 index 000000000000..cf0ab56d0225 --- /dev/null +++ b/xmloff/source/style/TransGradientStyle.cxx @@ -0,0 +1,328 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "TransGradientStyle.hxx" +#include <com/sun/star/awt/Gradient.hpp> +#include <xmloff/attrlist.hxx> +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmluconv.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <rtl/ustrbuf.hxx> +#include <rtl/ustring.hxx> +#include <tools/debug.hxx> +#include <xmloff/xmltkmap.hxx> +#include <xmloff/xmlexp.hxx> +#include <xmloff/xmlimp.hxx> + + +using namespace ::com::sun::star; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::xmloff::token; + +enum SvXMLTokenMapAttrs +{ + XML_TOK_GRADIENT_NAME, + XML_TOK_GRADIENT_DISPLAY_NAME, + XML_TOK_GRADIENT_STYLE, + XML_TOK_GRADIENT_CX, + XML_TOK_GRADIENT_CY, + XML_TOK_GRADIENT_START, + XML_TOK_GRADIENT_END, + XML_TOK_GRADIENT_ANGLE, + XML_TOK_GRADIENT_BORDER, + XML_TOK_TABSTOP_END=XML_TOK_UNKNOWN +}; + + +SvXMLEnumMapEntry const pXML_GradientStyle_Enum[] = +{ + { XML_GRADIENTSTYLE_LINEAR, awt::GradientStyle_LINEAR }, + { XML_GRADIENTSTYLE_AXIAL, awt::GradientStyle_AXIAL }, + { XML_GRADIENTSTYLE_RADIAL, awt::GradientStyle_RADIAL }, + { XML_GRADIENTSTYLE_ELLIPSOID, awt::GradientStyle_ELLIPTICAL }, + { XML_GRADIENTSTYLE_SQUARE, awt::GradientStyle_SQUARE }, + { XML_GRADIENTSTYLE_RECTANGULAR, awt::GradientStyle_RECT }, + { XML_TOKEN_INVALID, 0 } +}; + + +//------------------------------------------------------------- +// Import +//------------------------------------------------------------- + +XMLTransGradientStyleImport::XMLTransGradientStyleImport( SvXMLImport& rImp ) + : rImport(rImp) +{ +} + +XMLTransGradientStyleImport::~XMLTransGradientStyleImport() +{ +} + +sal_Bool XMLTransGradientStyleImport::importXML( + const uno::Reference< xml::sax::XAttributeList >& xAttrList, + uno::Any& rValue, + OUString& rStrName ) +{ + sal_Bool bRet = sal_False; + sal_Bool bHasName = sal_False; + sal_Bool bHasStyle = sal_False; + OUString aDisplayName; + + awt::Gradient aGradient; + aGradient.XOffset = 0; + aGradient.YOffset = 0; + aGradient.StartIntensity = 100; + aGradient.EndIntensity = 100; + aGradient.Angle = 0; + aGradient.Border = 0; + + { + static SvXMLTokenMapEntry aTrGradientAttrTokenMap[] = +{ + { XML_NAMESPACE_DRAW, XML_NAME, XML_TOK_GRADIENT_NAME }, + { XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, XML_TOK_GRADIENT_DISPLAY_NAME }, + { XML_NAMESPACE_DRAW, XML_STYLE, XML_TOK_GRADIENT_STYLE }, + { XML_NAMESPACE_DRAW, XML_CX, XML_TOK_GRADIENT_CX }, + { XML_NAMESPACE_DRAW, XML_CY, XML_TOK_GRADIENT_CY }, + { XML_NAMESPACE_DRAW, XML_START, XML_TOK_GRADIENT_START }, + { XML_NAMESPACE_DRAW, XML_END, XML_TOK_GRADIENT_END }, + { XML_NAMESPACE_DRAW, XML_GRADIENT_ANGLE, XML_TOK_GRADIENT_ANGLE }, + { XML_NAMESPACE_DRAW, XML_GRADIENT_BORDER, XML_TOK_GRADIENT_BORDER }, + XML_TOKEN_MAP_END +}; + + SvXMLTokenMap aTokenMap( aTrGradientAttrTokenMap ); + SvXMLNamespaceMap& rNamespaceMap = rImport.GetNamespaceMap(); + + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rFullAttrName = xAttrList->getNameByIndex( i ); + OUString aStrAttrName; + sal_uInt16 nPrefix = rNamespaceMap.GetKeyByAttrName( rFullAttrName, &aStrAttrName ); + const OUString& rStrValue = xAttrList->getValueByIndex( i ); + + sal_Int32 nTmpValue; + + switch( aTokenMap.Get( nPrefix, aStrAttrName ) ) + { + case XML_TOK_GRADIENT_NAME: + { + rStrName = rStrValue; + bHasName = sal_True; + } + break; + case XML_TOK_GRADIENT_DISPLAY_NAME: + { + aDisplayName = rStrValue; + } + break; + case XML_TOK_GRADIENT_STYLE: + { + sal_uInt16 eValue; + if( SvXMLUnitConverter::convertEnum( eValue, rStrValue, pXML_GradientStyle_Enum ) ) + { + aGradient.Style = (awt::GradientStyle) eValue; + bHasStyle = sal_True; + } + } + break; + case XML_TOK_GRADIENT_CX: + SvXMLUnitConverter::convertPercent( nTmpValue, rStrValue ); + aGradient.XOffset = sal::static_int_cast< sal_Int16 >(nTmpValue); + break; + case XML_TOK_GRADIENT_CY: + SvXMLUnitConverter::convertPercent( nTmpValue, rStrValue ); + aGradient.YOffset = sal::static_int_cast< sal_Int16 >(nTmpValue); + break; + case XML_TOK_GRADIENT_START: + { + sal_Int32 aStartTransparency; + SvXMLUnitConverter::convertPercent( aStartTransparency, rStrValue ); + + sal_uInt8 n = sal::static_int_cast< sal_uInt8 >( + ( (100 - aStartTransparency) * 255 ) / 100 ); + + Color aColor( n, n, n ); + aGradient.StartColor = (sal_Int32)( aColor.GetColor() ); + } + break; + case XML_TOK_GRADIENT_END: + { + sal_Int32 aEndTransparency; + SvXMLUnitConverter::convertPercent( aEndTransparency, rStrValue ); + + sal_uInt8 n = sal::static_int_cast< sal_uInt8 >( + ( (100 - aEndTransparency) * 255 ) / 100 ); + + Color aColor( n, n, n ); + aGradient.EndColor = (sal_Int32)( aColor.GetColor() ); + } + break; + case XML_TOK_GRADIENT_ANGLE: + { + sal_Int32 nValue; + SvXMLUnitConverter::convertNumber( nValue, rStrValue, 0, 3600 ); + aGradient.Angle = sal_Int16( nValue ); + } + break; + case XML_TOK_GRADIENT_BORDER: + SvXMLUnitConverter::convertPercent( nTmpValue, rStrValue ); + aGradient.Border = sal::static_int_cast< sal_Int16 >(nTmpValue); + break; + + default: + DBG_WARNING( "Unknown token at import transparency gradient style" ) + ; + } + } + + rValue <<= aGradient; + + if( aDisplayName.getLength() ) + { + rImport.AddStyleDisplayName( XML_STYLE_FAMILY_SD_GRADIENT_ID, rStrName, + aDisplayName ); + rStrName = aDisplayName; + } + + bRet = bHasName && bHasStyle; + + } + + return bRet; +} + + +//------------------------------------------------------------- +// Export +//------------------------------------------------------------- + +XMLTransGradientStyleExport::XMLTransGradientStyleExport( SvXMLExport& rExp ) + : rExport(rExp) +{ +} + +XMLTransGradientStyleExport::~XMLTransGradientStyleExport() +{ +} + + +sal_Bool XMLTransGradientStyleExport::exportXML( + const OUString& rStrName, + const uno::Any& rValue ) +{ + sal_Bool bRet = sal_False; + awt::Gradient aGradient; + + if( rStrName.getLength() ) + { + if( rValue >>= aGradient ) + { + OUString aStrValue; + OUStringBuffer aOut; + + // Style + if( !SvXMLUnitConverter::convertEnum( aOut, aGradient.Style, pXML_GradientStyle_Enum ) ) + { + bRet = sal_False; + } + else + { + // Name + sal_Bool bEncoded = sal_False; + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME, + rExport.EncodeStyleName( rStrName, + &bEncoded ) ); + if( bEncoded ) + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, + rStrName ); + + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_STYLE, aStrValue ); + + // Center x/y + if( aGradient.Style != awt::GradientStyle_LINEAR && + aGradient.Style != awt::GradientStyle_AXIAL ) + { + SvXMLUnitConverter::convertPercent( aOut, aGradient.XOffset ); + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_CX, aStrValue ); + + SvXMLUnitConverter::convertPercent( aOut, aGradient.YOffset ); + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_CY, aStrValue ); + } + + + Color aColor; + + // Transparency start + aColor.SetColor( aGradient.StartColor ); + sal_Int32 aStartValue = 100 - (sal_Int32)(((aColor.GetRed() + 1) * 100) / 255); + SvXMLUnitConverter::convertPercent( aOut, aStartValue ); + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_START, aStrValue ); + + // Transparency end + aColor.SetColor( aGradient.EndColor ); + sal_Int32 aEndValue = 100 - (sal_Int32)(((aColor.GetRed() + 1) * 100) / 255); + SvXMLUnitConverter::convertPercent( aOut, aEndValue ); + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_END, aStrValue ); + + // Angle + if( aGradient.Style != awt::GradientStyle_RADIAL ) + { + SvXMLUnitConverter::convertNumber( aOut, sal_Int32( aGradient.Angle ) ); + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_GRADIENT_ANGLE, aStrValue ); + } + + // Border + SvXMLUnitConverter::convertPercent( aOut, aGradient.Border ); + aStrValue = aOut.makeStringAndClear(); + rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_GRADIENT_BORDER, aStrValue ); + + // Do Write + SvXMLElementExport rElem( rExport, + XML_NAMESPACE_DRAW, XML_OPACITY, + sal_True, sal_False ); + } + } + } + + return bRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/VisAreaContext.cxx b/xmloff/source/style/VisAreaContext.cxx new file mode 100644 index 000000000000..727d09293025 --- /dev/null +++ b/xmloff/source/style/VisAreaContext.cxx @@ -0,0 +1,137 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + + + +// INCLUDE --------------------------------------------------------------- +#include "xmloff/VisAreaContext.hxx" +#include <xmloff/xmltoken.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/xmlimp.hxx> +#include <tools/gen.hxx> + +using namespace com::sun::star; +using namespace ::xmloff::token; + +//------------------------------------------------------------------ + +XMLVisAreaContext::XMLVisAreaContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, + const rtl::OUString& rLName, + const uno::Reference<xml::sax::XAttributeList>& xAttrList, + Rectangle& rRect, const MapUnit aMapUnit ) : + SvXMLImportContext( rImport, nPrfx, rLName ) +{ + awt::Rectangle rAwtRect( rRect.getX(), rRect.getY(), rRect.getWidth(), rRect.getHeight() ); + process( xAttrList, rAwtRect, (sal_Int16)aMapUnit ); + + rRect.setX( rAwtRect.X ); + rRect.setY( rAwtRect.Y ); + rRect.setWidth( rAwtRect.Width ); + rRect.setHeight( rAwtRect.Height ); +} + +XMLVisAreaContext::XMLVisAreaContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, + const rtl::OUString& rLName, + const uno::Reference<xml::sax::XAttributeList>& xAttrList, + ::com::sun::star::awt::Rectangle& rRect, const sal_Int16 nMeasureUnit ) : + SvXMLImportContext( rImport, nPrfx, rLName ) +{ + process( xAttrList, rRect, nMeasureUnit ); +} + +XMLVisAreaContext::~XMLVisAreaContext() +{ +} + +void XMLVisAreaContext::process( const uno::Reference< xml::sax::XAttributeList>& xAttrList, awt::Rectangle& rRect, const sal_Int16 nMeasureUnit ) +{ + MapUnit aMapUnit = (MapUnit)nMeasureUnit; + + sal_Int32 nX(0); + sal_Int32 nY(0); + sal_Int32 nWidth(0); + sal_Int32 nHeight(0); + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + rtl::OUString sAttrName = xAttrList->getNameByIndex( i ); + rtl::OUString aLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( + sAttrName, &aLocalName ); + rtl::OUString sValue = xAttrList->getValueByIndex( i ); + + if (nPrefix == XML_NAMESPACE_OFFICE) + { + if (IsXMLToken( aLocalName, XML_X )) + { + SvXMLUnitConverter::convertMeasure(nX, sValue, aMapUnit); + rRect.X = nX; + } + else if (IsXMLToken( aLocalName, XML_Y )) + { + SvXMLUnitConverter::convertMeasure(nY, sValue, aMapUnit); + rRect.Y = nY; + } + else if (IsXMLToken( aLocalName, XML_WIDTH )) + { + SvXMLUnitConverter::convertMeasure(nWidth, sValue, aMapUnit); + rRect.Width = nWidth; + } + else if (IsXMLToken( aLocalName, XML_HEIGHT )) + { + SvXMLUnitConverter::convertMeasure(nHeight, sValue, aMapUnit); + rRect.Height = nHeight; + } + } + } +} + +SvXMLImportContext *XMLVisAreaContext::CreateChildContext( sal_uInt16 nPrefix, + const rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList>& ) +{ + // here is no context + SvXMLImportContext *pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + + return pContext; +} + +void XMLVisAreaContext::EndElement() +{ +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/VisAreaExport.cxx b/xmloff/source/style/VisAreaExport.cxx new file mode 100644 index 000000000000..5ed8dbb2a801 --- /dev/null +++ b/xmloff/source/style/VisAreaExport.cxx @@ -0,0 +1,86 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <com/sun/star/awt/Rectangle.hpp> +#include "xmloff/VisAreaExport.hxx" +#include <xmloff/xmlexp.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <tools/gen.hxx> + +using namespace ::xmloff::token; + + +XMLVisAreaExport::XMLVisAreaExport(SvXMLExport& rExport, const sal_Char *pName, + const Rectangle& aRect, const MapUnit aMapUnit) +{ + SvXMLUnitConverter& rUnitConv = rExport.GetMM100UnitConverter(); + + // write VisArea Element and its Attributes + rtl::OUStringBuffer sBuffer; + rUnitConv.convertMeasure(sBuffer, aRect.getX(), aMapUnit); + rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_X, sBuffer.makeStringAndClear()); + rUnitConv.convertMeasure(sBuffer, aRect.getY(), aMapUnit); + rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_Y, sBuffer.makeStringAndClear()); + rUnitConv.convertMeasure(sBuffer, aRect.getWidth(), aMapUnit); + rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_WIDTH, sBuffer.makeStringAndClear()); + rUnitConv.convertMeasure(sBuffer, aRect.getHeight(), aMapUnit); + rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_HEIGHT, sBuffer.makeStringAndClear()); + SvXMLElementExport aVisAreaElem(rExport, XML_NAMESPACE_OFFICE, pName, sal_True, sal_True); +} + +XMLVisAreaExport::XMLVisAreaExport(SvXMLExport& rExport, const sal_Char *pName, + const com::sun::star::awt::Rectangle& aRect, const sal_Int16 nMeasureUnit ) +{ + MapUnit aMapUnit = (MapUnit)nMeasureUnit; + + SvXMLUnitConverter& rUnitConv = rExport.GetMM100UnitConverter(); + + // write VisArea Element and its Attributes + rtl::OUStringBuffer sBuffer; + rUnitConv.convertMeasure(sBuffer, aRect.X, aMapUnit); + rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_X, sBuffer.makeStringAndClear()); + rUnitConv.convertMeasure(sBuffer, aRect.Y, aMapUnit); + rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_Y, sBuffer.makeStringAndClear()); + rUnitConv.convertMeasure(sBuffer, aRect.Width, aMapUnit); + rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_WIDTH, sBuffer.makeStringAndClear()); + rUnitConv.convertMeasure(sBuffer, aRect.Height, aMapUnit); + rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_HEIGHT, sBuffer.makeStringAndClear()); + SvXMLElementExport aVisAreaElem(rExport, XML_NAMESPACE_OFFICE, pName, sal_True, sal_True); +} + +XMLVisAreaExport::~XMLVisAreaExport() +{ +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/WordWrapPropertyHdl.cxx b/xmloff/source/style/WordWrapPropertyHdl.cxx new file mode 100644 index 000000000000..c7fc2b26c8b0 --- /dev/null +++ b/xmloff/source/style/WordWrapPropertyHdl.cxx @@ -0,0 +1,104 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <xmloff/xmlimp.hxx> +#include <xmloff/WordWrapPropertyHdl.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <comphelper/extract.hxx> +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/Any.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star::uno; + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLWordWrapPropertyHdl +// + +XMLWordWrapPropertyHdl::XMLWordWrapPropertyHdl( SvXMLImport* pImport ) +: mpImport( pImport ) +{ +} + +XMLWordWrapPropertyHdl::~XMLWordWrapPropertyHdl() +{ + // Nothing to do +} + +sal_Bool XMLWordWrapPropertyHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bValue = sal_False, bRetValue = sal_False; + if( rStrImpValue == GetXMLToken( xmloff::token::XML_WRAP ) ) + { + bValue = sal_True; + bRetValue = sal_True; + } + if( rStrImpValue == GetXMLToken( xmloff::token::XML_NO_WRAP ) ) + { + bValue = sal_False; + bRetValue = sal_True; + } + if ( bRetValue && mpImport ) + { + sal_Int32 nUPD, nBuildId; + if( mpImport->getBuildIds( nUPD, nBuildId ) ) + { + if( nUPD == 300 ) + { + if( ( nBuildId > 0 ) && (nBuildId < 9316 ) ) + bValue = bValue ? sal_False : sal_True; // treat OOo 3.0 beta1 as OOo 2.x + } + else if( ( nUPD == 680 ) || ( nUPD >= 640 && nUPD <= 645 ) ) + bValue = bValue ? sal_False : sal_True; + } + rValue <<= bValue; + } + return bRetValue; +} + +sal_Bool XMLWordWrapPropertyHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + if( ::cppu::any2bool( rValue ) ) + { + rStrExpValue = GetXMLToken( xmloff::token::XML_WRAP ); + } + else + { + rStrExpValue = GetXMLToken( xmloff::token::XML_NO_WRAP ); + } + return sal_True; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/XMLBackgroundImageContext.cxx b/xmloff/source/style/XMLBackgroundImageContext.cxx new file mode 100644 index 000000000000..4f3bd37d8a21 --- /dev/null +++ b/xmloff/source/style/XMLBackgroundImageContext.cxx @@ -0,0 +1,417 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include <com/sun/star/io/XOutputStream.hpp> +#include <xmloff/xmltkmap.hxx> +#include <xmloff/xmluconv.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/nmspmap.hxx> +#include <xmloff/XMLBase64ImportContext.hxx> +#include "XMLBackgroundImageContext.hxx" + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::style; +using namespace ::com::sun::star::io; +using namespace ::xmloff::token; + +enum SvXMLTokenMapAttrs +{ + XML_TOK_BGIMG_HREF, + XML_TOK_BGIMG_TYPE, + XML_TOK_BGIMG_ACTUATE, + XML_TOK_BGIMG_SHOW, + XML_TOK_BGIMG_POSITION, + XML_TOK_BGIMG_REPEAT, + XML_TOK_BGIMG_FILTER, + XML_TOK_BGIMG_OPACITY, + XML_TOK_NGIMG_END=XML_TOK_UNKNOWN +}; +const SvXMLTokenMapEntry* lcl_getBGImgAttributesAttrTokenMap() +{ + static SvXMLTokenMapEntry aBGImgAttributesAttrTokenMap[] = + { + { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_BGIMG_HREF }, + { XML_NAMESPACE_XLINK, XML_TYPE, XML_TOK_BGIMG_TYPE }, + { XML_NAMESPACE_XLINK, XML_ACTUATE, XML_TOK_BGIMG_ACTUATE }, + { XML_NAMESPACE_XLINK, XML_SHOW, XML_TOK_BGIMG_SHOW }, + { XML_NAMESPACE_STYLE, XML_POSITION, XML_TOK_BGIMG_POSITION }, + { XML_NAMESPACE_STYLE, XML_REPEAT, XML_TOK_BGIMG_REPEAT }, + { XML_NAMESPACE_STYLE, XML_FILTER_NAME, XML_TOK_BGIMG_FILTER }, + { XML_NAMESPACE_DRAW, XML_OPACITY, XML_TOK_BGIMG_OPACITY }, + XML_TOKEN_MAP_END + }; + return aBGImgAttributesAttrTokenMap; +} + + + +SvXMLEnumMapEntry psXML_BrushHoriPos[] = +{ + { XML_LEFT, GraphicLocation_LEFT_MIDDLE }, + { XML_RIGHT, GraphicLocation_RIGHT_MIDDLE }, + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLEnumMapEntry psXML_BrushVertPos[] = +{ + { XML_TOP, GraphicLocation_MIDDLE_TOP }, + { XML_BOTTOM, GraphicLocation_MIDDLE_BOTTOM }, + { XML_TOKEN_INVALID, 0 } +}; + +void lcl_xmlbic_MergeHoriPos( GraphicLocation& ePos, + GraphicLocation eHori ) +{ + DBG_ASSERT( GraphicLocation_LEFT_MIDDLE==eHori || + GraphicLocation_MIDDLE_MIDDLE==eHori || + GraphicLocation_RIGHT_MIDDLE==eHori, + "lcl_xmlbic_MergeHoriPos: vertical pos must be middle" ); + + switch( ePos ) + { + case GraphicLocation_LEFT_TOP: + case GraphicLocation_MIDDLE_TOP: + case GraphicLocation_RIGHT_TOP: + ePos = GraphicLocation_LEFT_MIDDLE==eHori + ? GraphicLocation_LEFT_TOP + : (GraphicLocation_MIDDLE_MIDDLE==eHori + ? GraphicLocation_MIDDLE_TOP + : GraphicLocation_RIGHT_TOP); + break; + + case GraphicLocation_LEFT_MIDDLE: + case GraphicLocation_MIDDLE_MIDDLE: + case GraphicLocation_RIGHT_MIDDLE: + ePos = eHori; + break; + + case GraphicLocation_LEFT_BOTTOM: + case GraphicLocation_MIDDLE_BOTTOM: + case GraphicLocation_RIGHT_BOTTOM: + ePos = GraphicLocation_LEFT_MIDDLE==eHori + ? GraphicLocation_LEFT_BOTTOM + : (GraphicLocation_MIDDLE_MIDDLE==eHori + ? GraphicLocation_MIDDLE_BOTTOM + : GraphicLocation_RIGHT_BOTTOM); + break; + default: + break; + } +} + +void lcl_xmlbic_MergeVertPos( GraphicLocation& ePos, + GraphicLocation eVert ) +{ + DBG_ASSERT( GraphicLocation_MIDDLE_TOP==eVert || + GraphicLocation_MIDDLE_MIDDLE==eVert || + GraphicLocation_MIDDLE_BOTTOM==eVert, + "lcl_xmlbic_MergeVertPos: horizontal pos must be middle" ); + + switch( ePos ) + { + case GraphicLocation_LEFT_TOP: + case GraphicLocation_LEFT_MIDDLE: + case GraphicLocation_LEFT_BOTTOM: + ePos = GraphicLocation_MIDDLE_TOP==eVert + ? GraphicLocation_LEFT_TOP + : (GraphicLocation_MIDDLE_MIDDLE==eVert + ? GraphicLocation_LEFT_MIDDLE + : GraphicLocation_LEFT_BOTTOM); + ePos = eVert; + break; + + case GraphicLocation_MIDDLE_TOP: + case GraphicLocation_MIDDLE_MIDDLE: + case GraphicLocation_MIDDLE_BOTTOM: + ePos = eVert; + break; + + case GraphicLocation_RIGHT_TOP: + case GraphicLocation_RIGHT_MIDDLE: + case GraphicLocation_RIGHT_BOTTOM: + ePos = GraphicLocation_MIDDLE_TOP==eVert + ? GraphicLocation_RIGHT_TOP + : (GraphicLocation_MIDDLE_MIDDLE==eVert + ? GraphicLocation_RIGHT_MIDDLE + : GraphicLocation_RIGHT_BOTTOM); + break; + default: + break; + } +} + +TYPEINIT1( XMLBackgroundImageContext, XMLElementPropertyContext ); + +void XMLBackgroundImageContext::ProcessAttrs( + const Reference< xml::sax::XAttributeList >& xAttrList ) +{ + SvXMLTokenMap aTokenMap( lcl_getBGImgAttributesAttrTokenMap() ); + + ePos = GraphicLocation_NONE; + + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + OUString aLocalName; + sal_uInt16 nPrefix = + GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, + &aLocalName ); + const OUString& rValue = xAttrList->getValueByIndex( i ); + + switch( aTokenMap.Get( nPrefix, aLocalName ) ) + { + case XML_TOK_BGIMG_HREF: + sURL = rValue; + if( GraphicLocation_NONE == ePos ) + ePos = GraphicLocation_TILED; + break; + case XML_TOK_BGIMG_TYPE: + case XML_TOK_BGIMG_ACTUATE: + case XML_TOK_BGIMG_SHOW: + break; + case XML_TOK_BGIMG_POSITION: + { + GraphicLocation eNewPos = GraphicLocation_NONE, eTmp; + sal_uInt16 nTmp; + SvXMLTokenEnumerator aTokenEnum( rValue ); + OUString aToken; + sal_Bool bHori = sal_False, bVert = sal_False; + sal_Bool bOK = sal_True; + while( bOK && aTokenEnum.getNextToken( aToken ) ) + { + if( bHori && bVert ) + { + bOK = sal_False; + } + else if( -1 != aToken.indexOf( sal_Unicode('%') ) ) + { + sal_Int32 nPrc = 50; + if( SvXMLUnitConverter::convertPercent( nPrc, aToken ) ) + { + if( !bHori ) + { + eNewPos = nPrc < 25 + ? GraphicLocation_LEFT_TOP + : (nPrc < 75 ? GraphicLocation_MIDDLE_MIDDLE + : GraphicLocation_RIGHT_BOTTOM); + bHori = sal_True; + } + else + { + eTmp = nPrc < 25 + ? GraphicLocation_LEFT_TOP + : (nPrc < 75 ? GraphicLocation_LEFT_MIDDLE + : GraphicLocation_LEFT_BOTTOM); + lcl_xmlbic_MergeVertPos( eNewPos, eTmp ); + bVert = sal_True; + } + } + else + { + // wrong percentage + bOK = sal_False; + } + } + else if( IsXMLToken( aToken, XML_CENTER ) ) + { + if( bHori ) + lcl_xmlbic_MergeVertPos( eNewPos, + GraphicLocation_MIDDLE_MIDDLE ); + else if ( bVert ) + lcl_xmlbic_MergeHoriPos( eNewPos, + GraphicLocation_MIDDLE_MIDDLE ); + else + eNewPos = GraphicLocation_MIDDLE_MIDDLE; + } + else if( SvXMLUnitConverter::convertEnum( nTmp, aToken, + psXML_BrushHoriPos ) ) + { + if( bVert ) + lcl_xmlbic_MergeHoriPos( eNewPos, + (GraphicLocation)nTmp ); + else if( !bHori ) + eNewPos = (GraphicLocation)nTmp; + else + bOK = sal_False; + bHori = sal_True; + } + else if( SvXMLUnitConverter::convertEnum( nTmp, aToken, + psXML_BrushVertPos ) ) + { + if( bHori ) + lcl_xmlbic_MergeVertPos( eNewPos, + (GraphicLocation)nTmp ); + else if( !bVert ) + eNewPos = (GraphicLocation)nTmp; + else + bOK = sal_False; + bVert = sal_True; + } + else + { + bOK = sal_False; + } + } + + bOK &= GraphicLocation_NONE != eNewPos; + if( bOK ) + ePos = eNewPos; + } + break; + case XML_TOK_BGIMG_REPEAT: + { + sal_uInt16 nPos = GraphicLocation_NONE; + static SvXMLEnumMapEntry psXML_BrushRepeat[] = + { + { XML_BACKGROUND_REPEAT, GraphicLocation_TILED }, + { XML_BACKGROUND_NO_REPEAT, GraphicLocation_MIDDLE_MIDDLE }, + { XML_BACKGROUND_STRETCH, GraphicLocation_AREA }, + { XML_TOKEN_INVALID, 0 } + }; + if( SvXMLUnitConverter::convertEnum( nPos, rValue, + psXML_BrushRepeat ) ) + { + if( GraphicLocation_MIDDLE_MIDDLE != nPos || + GraphicLocation_NONE == ePos || + GraphicLocation_AREA == ePos || + GraphicLocation_TILED == ePos ) + ePos = (GraphicLocation)nPos; + } + } + break; + case XML_TOK_BGIMG_FILTER: + sFilter = rValue; + break; + case XML_TOK_BGIMG_OPACITY: + { + sal_Int32 nTmp; + // convert from percent and clip + if( SvXMLUnitConverter::convertPercent( nTmp, rValue ) ) + { + if( (nTmp >= 0) && (nTmp <= 100) ) + nTransparency = static_cast<sal_Int8>( 100-nTmp ); + } + } + break; + } + } + +} + +XMLBackgroundImageContext::XMLBackgroundImageContext( + SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > & xAttrList, + const XMLPropertyState& rProp, + sal_Int32 nPosIdx, + sal_Int32 nFilterIdx, + sal_Int32 nTransparencyIdx, + ::std::vector< XMLPropertyState > &rProps ) : + XMLElementPropertyContext( rImport, nPrfx, rLName, rProp, rProps ), + aPosProp( nPosIdx ), + aFilterProp( nFilterIdx ), + aTransparencyProp( nTransparencyIdx ), + nTransparency( 0 ) +{ + ProcessAttrs( xAttrList ); +} + +XMLBackgroundImageContext::~XMLBackgroundImageContext() +{ +} + +SvXMLImportContext *XMLBackgroundImageContext::CreateChildContext( + sal_uInt16 nPrefix, const OUString& rLocalName, + const Reference< xml::sax::XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = NULL; + if( (XML_NAMESPACE_OFFICE == nPrefix) && + xmloff::token::IsXMLToken( rLocalName, + xmloff::token::XML_BINARY_DATA ) ) + { + if( !sURL.getLength() && !xBase64Stream.is() ) + { + xBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64(); + if( xBase64Stream.is() ) + pContext = new XMLBase64ImportContext( GetImport(), nPrefix, + rLocalName, xAttrList, + xBase64Stream ); + } + } + if( !pContext ) + { + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + } + + return pContext; +} + +void XMLBackgroundImageContext::EndElement() +{ + if( sURL.getLength() ) + { + sURL = GetImport().ResolveGraphicObjectURL( sURL, sal_False ); + } + else if( xBase64Stream.is() ) + { + sURL = GetImport().ResolveGraphicObjectURLFromBase64( xBase64Stream ); + xBase64Stream = 0; + } + + if( !sURL.getLength() ) + ePos = GraphicLocation_NONE; + else if( GraphicLocation_NONE == ePos ) + ePos = GraphicLocation_TILED; + + aProp.maValue <<= sURL; + aPosProp.maValue <<= ePos; + aFilterProp.maValue <<= sFilter; + aTransparencyProp.maValue <<= nTransparency; + + SetInsert( sal_True ); + XMLElementPropertyContext::EndElement(); + + if( -1 != aPosProp.mnIndex ) + rProperties.push_back( aPosProp ); + if( -1 != aFilterProp.mnIndex ) + rProperties.push_back( aFilterProp ); + if( -1 != aTransparencyProp.mnIndex ) + rProperties.push_back( aTransparencyProp ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/XMLBackgroundImageExport.cxx b/xmloff/source/style/XMLBackgroundImageExport.cxx new file mode 100644 index 000000000000..adeb55009ea4 --- /dev/null +++ b/xmloff/source/style/XMLBackgroundImageExport.cxx @@ -0,0 +1,177 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <com/sun/star/style/GraphicLocation.hpp> + +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/xmltoken.hxx> +#include <rtl/ustrbuf.hxx> +#include <xmloff/xmlexp.hxx> +#include "XMLBackgroundImageExport.hxx" +#include <xmloff/xmluconv.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::style; +using namespace ::xmloff::token; + +XMLBackgroundImageExport::XMLBackgroundImageExport( SvXMLExport& rExp ) : + rExport( rExp ) +{ +} + +XMLBackgroundImageExport::~XMLBackgroundImageExport() +{ +} + +void XMLBackgroundImageExport::exportXML( const Any& rURL, + const Any *pPos, + const Any *pFilter, + const Any *pTransparency, + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName ) +{ + GraphicLocation ePos; + if( !(pPos && ((*pPos) >>= ePos)) ) + ePos = GraphicLocation_AREA; + + OUString sURL; + rURL >>= sURL; + if( sURL.getLength() && GraphicLocation_NONE != ePos ) + { + OUString sTempURL( GetExport().AddEmbeddedGraphicObject( sURL ) ); + if( sTempURL.getLength() ) + { + GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sTempURL ); + GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, + XML_SIMPLE ); + GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, + XML_ONLOAD ); + } + + OUStringBuffer aOut; + switch( ePos ) + { + case GraphicLocation_LEFT_TOP: + case GraphicLocation_MIDDLE_TOP: + case GraphicLocation_RIGHT_TOP: + aOut.append( GetXMLToken(XML_TOP) ); + break; + case GraphicLocation_LEFT_MIDDLE: + case GraphicLocation_MIDDLE_MIDDLE: + case GraphicLocation_RIGHT_MIDDLE: + aOut.append( GetXMLToken(XML_CENTER) ); + break; + case GraphicLocation_LEFT_BOTTOM: + case GraphicLocation_MIDDLE_BOTTOM: + case GraphicLocation_RIGHT_BOTTOM: + aOut.append( GetXMLToken(XML_BOTTOM) ); + break; + default: + break; + } + + if( aOut.getLength() ) + { + aOut.append( sal_Unicode( ' ' ) ); + + switch( ePos ) + { + case GraphicLocation_LEFT_TOP: + case GraphicLocation_LEFT_BOTTOM: + case GraphicLocation_LEFT_MIDDLE: + aOut.append( GetXMLToken(XML_LEFT) ); + break; + case GraphicLocation_MIDDLE_TOP: + case GraphicLocation_MIDDLE_MIDDLE: + case GraphicLocation_MIDDLE_BOTTOM: + aOut.append( GetXMLToken(XML_CENTER) ); + break; + case GraphicLocation_RIGHT_MIDDLE: + case GraphicLocation_RIGHT_TOP: + case GraphicLocation_RIGHT_BOTTOM: + aOut.append( GetXMLToken(XML_RIGHT) ); + break; + default: + break; + } + } + if( aOut.getLength() ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_POSITION, aOut.makeStringAndClear() ); + + if( GraphicLocation_AREA == ePos ) + { + aOut.append( GetXMLToken(XML_BACKGROUND_STRETCH) ); + } + else if( GraphicLocation_NONE != ePos && GraphicLocation_TILED != ePos ) + { + aOut.append( GetXMLToken(XML_BACKGROUND_NO_REPEAT) ); + } + if( aOut.getLength() ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REPEAT, + aOut.makeStringAndClear() ); + + if( pFilter ) + { + OUString sFilter; + (*pFilter) >>= sFilter; + if( sFilter.getLength() ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_FILTER_NAME, + sFilter ); + } + + if( pTransparency ) + { + sal_Int8 nTransparency = sal_Int8(); + if( (*pTransparency) >>= nTransparency ) + { + OUStringBuffer aTransOut; + SvXMLUnitConverter::convertPercent( aTransOut, 100-nTransparency ); + GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_OPACITY, + aTransOut.makeStringAndClear() ); + } + } + } + + { + SvXMLElementExport aElem( GetExport(), nPrefix, rLocalName, sal_True, sal_True ); + if( sURL.getLength() && GraphicLocation_NONE != ePos ) + { + // optional office:binary-data + GetExport().AddEmbeddedGraphicObjectAsBase64( sURL ); + } + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/XMLBitmapLogicalSizePropertyHandler.cxx b/xmloff/source/style/XMLBitmapLogicalSizePropertyHandler.cxx new file mode 100644 index 000000000000..72fedc3c2081 --- /dev/null +++ b/xmloff/source/style/XMLBitmapLogicalSizePropertyHandler.cxx @@ -0,0 +1,68 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <xmloff/xmluconv.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/Any.hxx> +#include "XMLBitmapLogicalSizePropertyHandler.hxx" +#include <comphelper/extract.hxx> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + + +XMLBitmapLogicalSizePropertyHandler::XMLBitmapLogicalSizePropertyHandler() +{ +} + +XMLBitmapLogicalSizePropertyHandler::~XMLBitmapLogicalSizePropertyHandler() +{ +} + +sal_Bool XMLBitmapLogicalSizePropertyHandler::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + rValue = ::cppu::bool2any( rStrImpValue.indexOf( sal_Unicode('%') ) == -1 ); + return sal_True; +} + +sal_Bool XMLBitmapLogicalSizePropertyHandler::exportXML( + OUString&, + const Any&, + const SvXMLUnitConverter& ) const +{ + return sal_False; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/XMLBitmapRepeatOffsetPropertyHandler.cxx b/xmloff/source/style/XMLBitmapRepeatOffsetPropertyHandler.cxx new file mode 100644 index 000000000000..6f7143d62da3 --- /dev/null +++ b/xmloff/source/style/XMLBitmapRepeatOffsetPropertyHandler.cxx @@ -0,0 +1,107 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/Any.hxx> +#include "XMLBitmapRepeatOffsetPropertyHandler.hxx" + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + + +using ::xmloff::token::GetXMLToken; +using ::xmloff::token::XML_VERTICAL; +using ::xmloff::token::XML_HORIZONTAL; + + +XMLBitmapRepeatOffsetPropertyHandler::XMLBitmapRepeatOffsetPropertyHandler( sal_Bool bX ) +: mbX( bX ), + msVertical( GetXMLToken(XML_VERTICAL) ), + msHorizontal( GetXMLToken(XML_HORIZONTAL) ) +{ +} + +XMLBitmapRepeatOffsetPropertyHandler::~XMLBitmapRepeatOffsetPropertyHandler() +{ +} + +sal_Bool XMLBitmapRepeatOffsetPropertyHandler::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + SvXMLTokenEnumerator aTokenEnum( rStrImpValue ); + OUString aToken; + if( aTokenEnum.getNextToken( aToken ) ) + { + sal_Int32 nValue; + if( SvXMLUnitConverter::convertPercent( nValue, aToken ) ) + { + if( aTokenEnum.getNextToken( aToken ) ) + { + if( ( mbX && ( aToken == msHorizontal ) ) || ( !mbX && ( aToken == msVertical ) ) ) + { + rValue <<= nValue; + return sal_True; + } + } + } + } + + return sal_False; + +} + +sal_Bool XMLBitmapRepeatOffsetPropertyHandler::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& ) const +{ + OUStringBuffer aOut; + + sal_Int32 nValue = 0; + if( rValue >>= nValue ) + { + SvXMLUnitConverter::convertPercent( aOut, nValue ); + aOut.append( sal_Unicode( ' ' ) ); + aOut.append( mbX ? msHorizontal : msVertical ); + rStrExpValue = aOut.makeStringAndClear(); + + return sal_True; + } + + return sal_False; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/XMLClipPropertyHandler.cxx b/xmloff/source/style/XMLClipPropertyHandler.cxx new file mode 100644 index 000000000000..af36556370ec --- /dev/null +++ b/xmloff/source/style/XMLClipPropertyHandler.cxx @@ -0,0 +1,149 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLClipPropertyHandler.hxx" +#include <com/sun/star/uno/Any.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/text/GraphicCrop.hpp> +#include <xmloff/xmluconv.hxx> +#include <xmloff/xmltoken.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::text; +using namespace ::xmloff::token; + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLMeasurePropHdl +// + +XMLClipPropertyHandler::XMLClipPropertyHandler( sal_Bool bODF11 ) : + m_bODF11( bODF11 ) +{ +} + +XMLClipPropertyHandler::~XMLClipPropertyHandler() +{ + // nothing to do +} + +bool XMLClipPropertyHandler::equals( + const Any& r1, + const Any& r2 ) const +{ + GraphicCrop aCrop1, aCrop2; + r1 >>= aCrop1; + r2 >>= aCrop2; + + return aCrop1.Top == aCrop2.Top && + aCrop1.Bottom == aCrop2.Bottom && + aCrop1.Left == aCrop2.Left && + aCrop1.Right == aCrop2.Right; +} + +sal_Bool XMLClipPropertyHandler::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const +{ + sal_Bool bRet = sal_False; + sal_Int32 nLen = rStrImpValue.getLength(); + if( nLen > 6 && + 0 == rStrImpValue.compareTo( GetXMLToken(XML_RECT), 4 ) && + rStrImpValue[4] == '(' && + rStrImpValue[nLen-1] == ')' ) + { + GraphicCrop aCrop; + OUString sTmp( rStrImpValue.copy( 5, nLen-6 ) ); + + sal_Bool bHasComma = sTmp.indexOf( ',' ) != -1; + SvXMLTokenEnumerator aTokenEnum( sTmp, bHasComma ? ',' : ' ' ); + + sal_uInt16 nPos = 0; + OUString aToken; + while( aTokenEnum.getNextToken( aToken ) ) + { + sal_Int32 nVal = 0; + if( !IsXMLToken(aToken, XML_AUTO) && + !rUnitConverter.convertMeasure( nVal, aToken ) ) + break; + + switch( nPos ) + { + case 0: aCrop.Top = nVal; break; + case 1: aCrop.Right = nVal; break; + case 2: aCrop.Bottom = nVal; break; + case 3: aCrop.Left = nVal; break; + } + nPos++; + } + + bRet = (4 == nPos ); + if( bRet ) + rValue <<= aCrop; + } + + return bRet; +} + +sal_Bool XMLClipPropertyHandler::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const +{ + sal_Bool bRet = sal_False; + OUStringBuffer aOut(30); + GraphicCrop aCrop; + + if( rValue >>= aCrop ) + { + aOut.append( GetXMLToken(XML_RECT) ); + aOut.append( (sal_Unicode)'(' ); + rUnitConverter.convertMeasure( aOut, aCrop.Top ); + if( !m_bODF11 ) + aOut.append( (sal_Unicode)',' ); + aOut.append( (sal_Unicode)' ' ); + rUnitConverter.convertMeasure( aOut, aCrop.Right ); + if( !m_bODF11 ) + aOut.append( (sal_Unicode)',' ); + aOut.append( (sal_Unicode)' ' ); + rUnitConverter.convertMeasure( aOut, aCrop.Bottom ); + if( !m_bODF11 ) + aOut.append( (sal_Unicode)',' ); + aOut.append( (sal_Unicode)' ' ); + rUnitConverter.convertMeasure( aOut, aCrop.Left ); + aOut.append( (sal_Unicode)')' ); + rStrExpValue = aOut.makeStringAndClear(); + + bRet = sal_True; + } + + return bRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/XMLConstantsPropertyHandler.cxx b/xmloff/source/style/XMLConstantsPropertyHandler.cxx new file mode 100644 index 000000000000..55c62fc8d810 --- /dev/null +++ b/xmloff/source/style/XMLConstantsPropertyHandler.cxx @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include <xmloff/xmluconv.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <xmloff/XMLConstantsPropertyHandler.hxx> + +using namespace ::com::sun::star::uno; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using ::xmloff::token::XMLTokenEnum; + +XMLConstantsPropertyHandler::XMLConstantsPropertyHandler( + const SvXMLEnumMapEntry *pM, + enum XMLTokenEnum eDflt ) : + pMap( pM ), + eDefault( eDflt ) +{ +} + +XMLConstantsPropertyHandler::~XMLConstantsPropertyHandler() +{ +} + +sal_Bool XMLConstantsPropertyHandler::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_uInt16 nEnum; + sal_Bool bRet = SvXMLUnitConverter::convertEnum( + nEnum, rStrImpValue, pMap ); + + if( bRet ) + rValue <<= (sal_Int16)nEnum; + + return bRet; +} + +sal_Bool XMLConstantsPropertyHandler::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& ) const +{ + OUStringBuffer aOut; + + sal_Bool bRet = false; + + sal_Int32 nEnum = 0; + + if( rValue.hasValue() && (rValue.getValueTypeClass() == TypeClass_ENUM)) + { + nEnum = *((sal_Int32*)rValue.getValue()); + bRet = true; + } + else + { + bRet = (rValue >>= nEnum ); + } + + if( bRet ) + { + if( (nEnum >= 0) && (nEnum <= 0xffff) ) + { + sal_uInt16 nConst = static_cast<sal_uInt16>( nEnum ); + + bRet = SvXMLUnitConverter::convertEnum( + aOut, nConst, pMap, eDefault ); + + rStrExpValue = aOut.makeStringAndClear(); + } + else + { + OSL_FAIL("XMLConstantsPropertyHandler::exportXML() constant is out of range for implementation using sal_uInt16"); + } + } + else + { + OSL_FAIL("XMLConstantsPropertyHandler::exportXML() could not convert any to sal_Int32"); + } + + return bRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/XMLElementPropertyContext.cxx b/xmloff/source/style/XMLElementPropertyContext.cxx new file mode 100644 index 000000000000..1a9bf554a8e5 --- /dev/null +++ b/xmloff/source/style/XMLElementPropertyContext.cxx @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include "XMLElementPropertyContext.hxx" + +using ::rtl::OUString; + +TYPEINIT1( XMLElementPropertyContext , SvXMLImportContext ); + +XMLElementPropertyContext::XMLElementPropertyContext ( + SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const XMLPropertyState& rProp, + ::std::vector< XMLPropertyState > &rProps ) : + SvXMLImportContext( rImport, nPrfx, rLName ), + bInsert( sal_False ), + rProperties( rProps ), + aProp( rProp ) +{ +} + +XMLElementPropertyContext::~XMLElementPropertyContext() +{ +} + +void XMLElementPropertyContext::EndElement( ) +{ + if( bInsert ) + rProperties.push_back( aProp ); +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/XMLFillBitmapSizePropertyHandler.cxx b/xmloff/source/style/XMLFillBitmapSizePropertyHandler.cxx new file mode 100644 index 000000000000..ac23035e9683 --- /dev/null +++ b/xmloff/source/style/XMLFillBitmapSizePropertyHandler.cxx @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <com/sun/star/uno/Any.hxx> +#include <xmloff/xmluconv.hxx> +#include <rtl/ustrbuf.hxx> +#include "XMLFillBitmapSizePropertyHandler.hxx" +#include <comphelper/extract.hxx> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + + +XMLFillBitmapSizePropertyHandler::XMLFillBitmapSizePropertyHandler() +{ +} + +XMLFillBitmapSizePropertyHandler::~XMLFillBitmapSizePropertyHandler() +{ +} + +sal_Bool XMLFillBitmapSizePropertyHandler::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& rUnitConverter ) const +{ + sal_Int32 nValue; + sal_Bool bRet; + + if( rStrImpValue.indexOf( sal_Unicode('%') ) != -1 ) + { + bRet = rUnitConverter.convertPercent( nValue, rStrImpValue ); + nValue *= -1; + } + else + { + bRet = rUnitConverter.convertMeasure( nValue, rStrImpValue ); + } + + if( bRet ) + rValue <<= nValue; + + return bRet; +} + +sal_Bool XMLFillBitmapSizePropertyHandler::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& rUnitConverter ) const +{ + OUStringBuffer aOut; + + sal_Int32 nValue = 0; + if( rValue >>= nValue ) + { + if( nValue < 0 ) + { + rUnitConverter.convertPercent( aOut, -nValue ); + } + else + { + rUnitConverter.convertMeasure( aOut, nValue ); + } + + rStrExpValue = aOut.makeStringAndClear(); + return sal_True; + } + + return sal_False; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/XMLFontAutoStylePool.cxx b/xmloff/source/style/XMLFontAutoStylePool.cxx new file mode 100644 index 000000000000..fb749e6f4edc --- /dev/null +++ b/xmloff/source/style/XMLFontAutoStylePool.cxx @@ -0,0 +1,294 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include <svl/cntnrsrt.hxx> +#include <tools/fontenum.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include "fonthdl.hxx" +#include <xmloff/xmlexp.hxx> +#include <xmloff/XMLFontAutoStylePool.hxx> + + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star::uno; +using namespace ::xmloff::token; + +int XMLFontAutoStylePoolNameCmp_Impl( const OUString& r1, + const OUString& r2 ) +{ + return (int)r1.compareTo( r2 ); +} + +DECLARE_CONTAINER_SORT_DEL( XMLFontAutoStylePoolNames_Impl, + OUString ) +IMPL_CONTAINER_SORT( XMLFontAutoStylePoolNames_Impl, + OUString, + XMLFontAutoStylePoolNameCmp_Impl ) + +class XMLFontAutoStylePoolEntry_Impl +{ + OUString sName; + OUString sFamilyName; + OUString sStyleName; + sal_Int16 nFamily; + sal_Int16 nPitch; + rtl_TextEncoding eEnc; + +public: + + inline XMLFontAutoStylePoolEntry_Impl( + const ::rtl::OUString& rName, + const ::rtl::OUString& rFamilyName, + const ::rtl::OUString& rStyleName, + sal_Int16 nFamily, + sal_Int16 nPitch, + rtl_TextEncoding eEnc ); + + inline XMLFontAutoStylePoolEntry_Impl( + const ::rtl::OUString& rFamilyName, + const ::rtl::OUString& rStyleName, + sal_Int16 nFamily, + sal_Int16 nPitch, + rtl_TextEncoding eEnc ); + + const OUString& GetName() const { return sName; } + const OUString& GetFamilyName() const { return sFamilyName; } + const OUString& GetStyleName() const { return sStyleName; } + sal_Int16 GetFamily() const { return nFamily; } + sal_Int16 GetPitch() const { return nPitch; } + rtl_TextEncoding GetEncoding() const { return eEnc; } +}; + + +inline XMLFontAutoStylePoolEntry_Impl::XMLFontAutoStylePoolEntry_Impl( + const ::rtl::OUString& rName, + const ::rtl::OUString& rFamilyName, + const ::rtl::OUString& rStyleName, + sal_Int16 nFam, + sal_Int16 nP, + rtl_TextEncoding eE ) : + sName( rName ), + sFamilyName( rFamilyName ), + sStyleName( rStyleName ), + nFamily( nFam ), + nPitch( nP ), + eEnc( eE ) +{ +} + +inline XMLFontAutoStylePoolEntry_Impl::XMLFontAutoStylePoolEntry_Impl( + const ::rtl::OUString& rFamilyName, + const ::rtl::OUString& rStyleName, + sal_Int16 nFam, + sal_Int16 nP, + rtl_TextEncoding eE ) : + sFamilyName( rFamilyName ), + sStyleName( rStyleName ), + nFamily( nFam ), + nPitch( nP ), + eEnc( eE ) +{ +} +int XMLFontAutoStylePoolEntryCmp_Impl( + const XMLFontAutoStylePoolEntry_Impl& r1, + const XMLFontAutoStylePoolEntry_Impl& r2 ) +{ + sal_Int8 nEnc1(r1.GetEncoding() != RTL_TEXTENCODING_SYMBOL); + sal_Int8 nEnc2(r2.GetEncoding() != RTL_TEXTENCODING_SYMBOL); + if( nEnc1 != nEnc2 ) + return nEnc1 - nEnc2; + else if( r1.GetPitch() != r2.GetPitch() ) + return (int)r1.GetPitch() - (int)r2.GetPitch(); + else if( r1.GetFamily() != r2.GetFamily() ) + return (int)r1.GetFamily() - (int)r2.GetFamily(); + else + { + sal_Int32 nCmp = r1.GetFamilyName().compareTo( r2.GetFamilyName() ); + if( 0 == nCmp ) + return (int)r1.GetStyleName().compareTo( r2.GetStyleName() ); + else + return (int)nCmp; + } +} + +typedef XMLFontAutoStylePoolEntry_Impl *XMLFontAutoStylePoolEntryPtr; +DECLARE_CONTAINER_SORT_DEL( XMLFontAutoStylePool_Impl, + XMLFontAutoStylePoolEntry_Impl ) +IMPL_CONTAINER_SORT( XMLFontAutoStylePool_Impl, + XMLFontAutoStylePoolEntry_Impl, + XMLFontAutoStylePoolEntryCmp_Impl ) + +XMLFontAutoStylePool::XMLFontAutoStylePool( SvXMLExport& rExp ) : + rExport( rExp ), + pPool( new XMLFontAutoStylePool_Impl( 5, 5 ) ), + pNames( new XMLFontAutoStylePoolNames_Impl( 5, 5 ) ) +{ +} + +XMLFontAutoStylePool::~XMLFontAutoStylePool() +{ + delete pPool; + delete pNames; +} + +OUString XMLFontAutoStylePool::Add( + const OUString& rFamilyName, + const OUString& rStyleName, + sal_Int16 nFamily, + sal_Int16 nPitch, + rtl_TextEncoding eEnc ) +{ + OUString sPoolName; + XMLFontAutoStylePoolEntry_Impl aTmp( rFamilyName, rStyleName, nFamily, + nPitch, eEnc ); + sal_uLong nPos; + if( pPool->Seek_Entry( &aTmp, &nPos ) ) + { + sPoolName = pPool->GetObject( nPos )->GetName(); + } + else + { + OUString sName; + sal_Int32 nLen = rFamilyName.indexOf( sal_Unicode(';'), 0 ); + if( -1 == nLen ) + { + sName = rFamilyName; + } + else if( nLen > 0 ) + { + sName = rFamilyName.copy( 0, nLen ); + sName.trim(); + } + + if( !sName.getLength() ) + sName = OUString::valueOf( sal_Unicode( 'F' ) ); + + if( pNames->Seek_Entry( &sName, 0 ) ) + { + sal_Int32 nCount = 1; + OUString sPrefix( sName ); + sName += OUString::valueOf( nCount ); + while( pNames->Seek_Entry( &sName, 0 ) ) + { + sName = sPrefix; + sName += OUString::valueOf( ++nCount ); + } + } + + XMLFontAutoStylePoolEntry_Impl *pEntry = + new XMLFontAutoStylePoolEntry_Impl( sName, rFamilyName, rStyleName, + nFamily, nPitch, eEnc ); + pPool->Insert( pEntry ); + pNames->Insert( new OUString( sName ) ); + } + + return sPoolName; +} + +::rtl::OUString XMLFontAutoStylePool::Find( + const OUString& rFamilyName, + const OUString& rStyleName, + sal_Int16 nFamily, + sal_Int16 nPitch, + rtl_TextEncoding eEnc ) const +{ + OUString sName; + XMLFontAutoStylePoolEntry_Impl aTmp( rFamilyName, rStyleName, nFamily, + nPitch, eEnc ); + sal_uLong nPos; + if( pPool->Seek_Entry( &aTmp, &nPos ) ) + { + sName = pPool->GetObject( nPos )->GetName(); + } + + return sName; +} + + +void XMLFontAutoStylePool::exportXML() +{ + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_OFFICE, + XML_FONT_FACE_DECLS, + sal_True, sal_True ); + Any aAny; + OUString sTmp; + XMLFontFamilyNamePropHdl aFamilyNameHdl; + XMLFontFamilyPropHdl aFamilyHdl; + XMLFontPitchPropHdl aPitchHdl; + XMLFontEncodingPropHdl aEncHdl; + const SvXMLUnitConverter& rUnitConv = GetExport().GetMM100UnitConverter(); + + sal_uInt32 nCount = pPool->Count(); + for( sal_uInt32 i=0; i<nCount; i++ ) + { + const XMLFontAutoStylePoolEntry_Impl *pEntry = pPool->GetObject( i ); + + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_NAME, pEntry->GetName() ); + + aAny <<= pEntry->GetFamilyName(); + if( aFamilyNameHdl.exportXML( sTmp, aAny, rUnitConv ) ) + GetExport().AddAttribute( XML_NAMESPACE_SVG, + XML_FONT_FAMILY, sTmp ); + + const OUString& rStyleName = pEntry->GetStyleName(); + if( rStyleName.getLength() ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_FONT_ADORNMENTS, + rStyleName ); + + aAny <<= (sal_Int16)pEntry->GetFamily(); + if( aFamilyHdl.exportXML( sTmp, aAny, rUnitConv ) ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_FONT_FAMILY_GENERIC, sTmp ); + + aAny <<= (sal_Int16)pEntry->GetPitch(); + if( aPitchHdl.exportXML( sTmp, aAny, rUnitConv ) ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_FONT_PITCH, sTmp ); + + aAny <<= (sal_Int16)pEntry->GetEncoding(); + if( aEncHdl.exportXML( sTmp, aAny, rUnitConv ) ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_FONT_CHARSET, sTmp ); + + SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE, + XML_FONT_FACE, + sal_True, sal_True ); + } +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/XMLFontStylesContext.cxx b/xmloff/source/style/XMLFontStylesContext.cxx new file mode 100644 index 000000000000..d4823ccf03ee --- /dev/null +++ b/xmloff/source/style/XMLFontStylesContext.cxx @@ -0,0 +1,288 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + +#include <com/sun/star/awt/FontFamily.hpp> +#include <com/sun/star/awt/FontPitch.hpp> + +#include <rtl/logfile.hxx> + +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include "fonthdl.hxx" +#include <xmloff/xmlimp.hxx> +#include <xmloff/maptype.hxx> +#include <xmloff/XMLFontStylesContext.hxx> + + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::xml::sax; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::awt; +using namespace ::xmloff::token; + + +#define XML_STYLE_FAMILY_FONT 1 + +enum XMLFontStyleAttrTokens +{ + XML_TOK_FONT_STYLE_ATTR_FAMILY, + XML_TOK_FONT_STYLE_ATTR_FAMILY_GENERIC, + XML_TOK_FONT_STYLE_ATTR_STYLENAME, + XML_TOK_FONT_STYLE_ATTR_PITCH, + XML_TOK_FONT_STYLE_ATTR_CHARSET, + + XML_TOK_FONT_STYLE_ATTR_END=XML_TOK_UNKNOWN +}; + +const SvXMLTokenMapEntry* lcl_getFontStyleAttrTokenMap() +{ + static SvXMLTokenMapEntry aFontStyleAttrTokenMap[] = + { + { XML_NAMESPACE_SVG, XML_FONT_FAMILY, + XML_TOK_FONT_STYLE_ATTR_FAMILY }, + { XML_NAMESPACE_STYLE, XML_FONT_FAMILY_GENERIC, + XML_TOK_FONT_STYLE_ATTR_FAMILY_GENERIC }, + { XML_NAMESPACE_STYLE, XML_FONT_ADORNMENTS, + XML_TOK_FONT_STYLE_ATTR_STYLENAME }, + { XML_NAMESPACE_STYLE, XML_FONT_PITCH, + XML_TOK_FONT_STYLE_ATTR_PITCH }, + { XML_NAMESPACE_STYLE, XML_FONT_CHARSET, + XML_TOK_FONT_STYLE_ATTR_CHARSET }, + + XML_TOKEN_MAP_END + }; + return aFontStyleAttrTokenMap; +} + +class XMLFontStyleContext_Impl : public SvXMLStyleContext +{ + Any aFamilyName; + Any aStyleName; + Any aFamily; + Any aPitch; + Any aEnc; + + SvXMLImportContextRef xStyles; + + XMLFontStylesContext *GetStyles() + { + return ((XMLFontStylesContext *)&xStyles); + } + +public: + + TYPEINFO(); + + XMLFontStyleContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & xAttrList, + XMLFontStylesContext& rStyles ); + virtual ~XMLFontStyleContext_Impl(); + + void SetAttribute( sal_uInt16 nPrefixKey, const OUString& rLocalName, + const OUString& rValue ); + + void FillProperties( ::std::vector< XMLPropertyState > &rProps, + sal_Int32 nFamilyNameIdx, + sal_Int32 nStyleNameIdx, + sal_Int32 nFamilyIdx, + sal_Int32 nPitchIdx, + sal_Int32 nCharsetIdx ) const; + +}; + +TYPEINIT1( XMLFontStyleContext_Impl, SvXMLStyleContext ); + +XMLFontStyleContext_Impl::XMLFontStyleContext_Impl( SvXMLImport& rImport, + sal_uInt16 nPrfx, const OUString& rLName, + const Reference< XAttributeList > & xAttrList, + XMLFontStylesContext& rStyles ) : + SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList, XML_STYLE_FAMILY_FONT ), + xStyles( &rStyles ) +{ + OUString sEmpty; + aFamilyName <<= sEmpty; + aStyleName <<= sEmpty; + aFamily <<= (sal_Int16)FontFamily::DONTKNOW; + aPitch <<= (sal_Int16)FontPitch::DONTKNOW; + aEnc <<= (sal_Int16)rStyles.GetDfltCharset(); +} + +void XMLFontStyleContext_Impl::SetAttribute( sal_uInt16 nPrefixKey, + const OUString& rLocalName, + const OUString& rValue ) +{ + SvXMLUnitConverter& rUnitConv = GetImport().GetMM100UnitConverter(); + const SvXMLTokenMap& rTokenMap = GetStyles()->GetFontStyleAttrTokenMap(); + Any aAny; + + switch( rTokenMap.Get( nPrefixKey, rLocalName ) ) + { + case XML_TOK_FONT_STYLE_ATTR_FAMILY: + if( GetStyles()->GetFamilyNameHdl().importXML( rValue, aAny, + rUnitConv ) ) + aFamilyName = aAny; + break; + case XML_TOK_FONT_STYLE_ATTR_STYLENAME: + aStyleName <<= rValue; + break; + case XML_TOK_FONT_STYLE_ATTR_FAMILY_GENERIC: + if( GetStyles()->GetFamilyHdl().importXML( rValue, aAny, + rUnitConv ) ) + aFamily = aAny; + break; + case XML_TOK_FONT_STYLE_ATTR_PITCH: + if( GetStyles()->GetPitchHdl().importXML( rValue, aAny, + rUnitConv ) ) + aPitch = aAny; + break; + case XML_TOK_FONT_STYLE_ATTR_CHARSET: + if( GetStyles()->GetEncodingHdl().importXML( rValue, aAny, + rUnitConv ) ) + aEnc = aAny; + break; + default: + SvXMLStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue ); + break; + } +} + +XMLFontStyleContext_Impl::~XMLFontStyleContext_Impl() +{ +} + +void XMLFontStyleContext_Impl::FillProperties( + ::std::vector< XMLPropertyState > &rProps, + sal_Int32 nFamilyNameIdx, + sal_Int32 nStyleNameIdx, + sal_Int32 nFamilyIdx, + sal_Int32 nPitchIdx, + sal_Int32 nCharsetIdx ) const +{ + if( nFamilyNameIdx != -1 ) + { + XMLPropertyState aPropState( nFamilyNameIdx, aFamilyName ); + rProps.push_back( aPropState ); + } + if( nStyleNameIdx != -1 ) + { + XMLPropertyState aPropState( nStyleNameIdx, aStyleName ); + rProps.push_back( aPropState ); + } + if( nFamilyIdx != -1 ) + { + XMLPropertyState aPropState( nFamilyIdx, aFamily ); + rProps.push_back( aPropState ); + } + if( nPitchIdx != -1 ) + { + XMLPropertyState aPropState( nPitchIdx, aPitch ); + rProps.push_back( aPropState ); + } + if( nCharsetIdx != -1 ) + { + XMLPropertyState aPropState( nCharsetIdx, aEnc ); + rProps.push_back( aPropState ); + } +} + +SvXMLStyleContext *XMLFontStylesContext::CreateStyleChildContext( + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList > & xAttrList ) +{ + SvXMLStyleContext *pStyle; + if( XML_NAMESPACE_STYLE == nPrefix && + IsXMLToken( rLocalName, XML_FONT_FACE ) ) + { + pStyle = new XMLFontStyleContext_Impl( GetImport(), nPrefix, + rLocalName, xAttrList, *this ); + } + else + { + pStyle = SvXMLStylesContext::CreateStyleChildContext( nPrefix, + rLocalName, xAttrList ); + } + + return pStyle; +} + +TYPEINIT1( XMLFontStylesContext, SvXMLStylesContext ); + +XMLFontStylesContext::XMLFontStylesContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, const OUString& rLName, + const Reference< XAttributeList > & xAttrList, + rtl_TextEncoding eDfltEnc ) : + SvXMLStylesContext( rImport, nPrfx, rLName, xAttrList ), + pFamilyNameHdl( new XMLFontFamilyNamePropHdl ), + pFamilyHdl( new XMLFontFamilyPropHdl ), + pPitchHdl( new XMLFontPitchPropHdl ), + pEncHdl( new XMLFontEncodingPropHdl ), + pFontStyleAttrTokenMap( new SvXMLTokenMap(lcl_getFontStyleAttrTokenMap()) ), + eDfltEncoding( eDfltEnc ) +{ +} + +XMLFontStylesContext::~XMLFontStylesContext() +{ + delete pFamilyNameHdl; + delete pFamilyHdl; + delete pPitchHdl; + delete pEncHdl; + delete pFontStyleAttrTokenMap; +} + +sal_Bool XMLFontStylesContext::FillProperties( const OUString& rName, + ::std::vector< XMLPropertyState > &rProps, + sal_Int32 nFamilyNameIdx, + sal_Int32 nStyleNameIdx, + sal_Int32 nFamilyIdx, + sal_Int32 nPitchIdx, + sal_Int32 nCharsetIdx ) const +{ + const SvXMLStyleContext* pStyle = FindStyleChildContext( XML_STYLE_FAMILY_FONT, rName, sal_True ); + const XMLFontStyleContext_Impl *pFontStyle = PTR_CAST( XMLFontStyleContext_Impl,pStyle);// use temp var, PTR_CAST is a bad macro, FindStyleChildContext will be called twice + if( pFontStyle ) + pFontStyle->FillProperties( rProps, nFamilyNameIdx, nStyleNameIdx, + nFamilyIdx, nPitchIdx, nCharsetIdx ); + return 0 != pFontStyle; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/XMLFootnoteSeparatorExport.cxx b/xmloff/source/style/XMLFootnoteSeparatorExport.cxx new file mode 100644 index 000000000000..a7f5e0c1bf3a --- /dev/null +++ b/xmloff/source/style/XMLFootnoteSeparatorExport.cxx @@ -0,0 +1,190 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLFootnoteSeparatorExport.hxx" +#include <tools/debug.hxx> +#include <xmloff/xmlexp.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmluconv.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlprmap.hxx> + +#include <xmloff/PageMasterStyleMap.hxx> +#include <com/sun/star/text/HorizontalAdjust.hpp> +#include <rtl/ustrbuf.hxx> + + +using namespace ::com::sun::star; +using namespace ::xmloff::token; +using ::rtl::OUStringBuffer; +using ::std::vector; + +XMLFootnoteSeparatorExport::XMLFootnoteSeparatorExport(SvXMLExport& rExp) : + rExport(rExp) +{ +} + +XMLFootnoteSeparatorExport::~XMLFootnoteSeparatorExport() +{ +} + + +void XMLFootnoteSeparatorExport::exportXML( + const vector<XMLPropertyState> * pProperties, + sal_uInt32 + #ifdef DBG_UTIL + nIdx + #endif + , + const UniReference<XMLPropertySetMapper> & rMapper) +{ + DBG_ASSERT(NULL != pProperties, "Need property states"); + + // intialize values + sal_Int16 eLineAdjust = text::HorizontalAdjust_LEFT; + sal_Int32 nLineColor = 0; + sal_Int32 nLineDistance = 0; + sal_Int8 nLineRelWidth = 0; + sal_Int32 nLineTextDistance = 0; + sal_Int16 nLineWeight = 0; + sal_Int8 nLineStyle = 0; + + // find indices into property map and get values + sal_uInt32 nCount = pProperties->size(); + for(sal_uInt32 i = 0; i < nCount; i++) + { + const XMLPropertyState& rState = (*pProperties)[i]; + + if( rState.mnIndex == -1 ) + continue; + + switch (rMapper->GetEntryContextId(rState.mnIndex)) + { + case CTF_PM_FTN_LINE_ADJUST: + rState.maValue >>= eLineAdjust; + break; + case CTF_PM_FTN_LINE_COLOR: + rState.maValue >>= nLineColor; + break; + case CTF_PM_FTN_DISTANCE: + rState.maValue >>= nLineDistance; + break; + case CTF_PM_FTN_LINE_WIDTH: + rState.maValue >>= nLineRelWidth; + break; + case CTF_PM_FTN_LINE_DISTANCE: + rState.maValue >>= nLineTextDistance; + break; + case CTF_PM_FTN_LINE_WEIGTH: + DBG_ASSERT( i == nIdx, + "received wrong property state index" ); + rState.maValue >>= nLineWeight; + break; + case CTF_PM_FTN_LINE_STYLE: + rState.maValue >>= nLineStyle; + break; + } + } + + OUStringBuffer sBuf; + + // weight/width + if (nLineWeight > 0) + { + rExport.GetMM100UnitConverter().convertMeasure(sBuf, nLineWeight); + rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_WIDTH, + sBuf.makeStringAndClear()); + } + + // line text distance + if (nLineTextDistance > 0) + { + rExport.GetMM100UnitConverter().convertMeasure(sBuf,nLineTextDistance); + rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_DISTANCE_BEFORE_SEP, + sBuf.makeStringAndClear()); + } + + // line distance + if (nLineDistance > 0) + { + rExport.GetMM100UnitConverter().convertMeasure(sBuf, nLineDistance); + rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_DISTANCE_AFTER_SEP, + sBuf.makeStringAndClear()); + } + + // line style + static const SvXMLEnumMapEntry aXML_LineStyle_Enum[] = + { + { XML_NONE, 0 }, + { XML_SOLID, 1 }, + { XML_DOTTED, 2 }, + { XML_DASH, 3 }, + { XML_TOKEN_INVALID, 0 } + }; + if (rExport.GetMM100UnitConverter().convertEnum( + sBuf, nLineStyle, aXML_LineStyle_Enum ) ) + { + rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_LINE_STYLE, + sBuf.makeStringAndClear()); + } + + // adjustment + static const SvXMLEnumMapEntry aXML_HorizontalAdjust_Enum[] = + { + { XML_LEFT, text::HorizontalAdjust_LEFT }, + { XML_CENTER, text::HorizontalAdjust_CENTER }, + { XML_RIGHT, text::HorizontalAdjust_RIGHT }, + { XML_TOKEN_INVALID, 0 } + }; + + if (rExport.GetMM100UnitConverter().convertEnum( + sBuf, eLineAdjust, aXML_HorizontalAdjust_Enum)) + { + rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_ADJUSTMENT, + sBuf.makeStringAndClear()); + } + + // relative line width + SvXMLUnitConverter::convertPercent(sBuf, nLineRelWidth); + rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_REL_WIDTH, + sBuf.makeStringAndClear()); + + // color + rExport.GetMM100UnitConverter().convertColor(sBuf, nLineColor); + rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_COLOR, + sBuf.makeStringAndClear()); + + // line-style + + SvXMLElementExport aElem(rExport, XML_NAMESPACE_STYLE, + XML_FOOTNOTE_SEP, sal_True, sal_True); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/XMLFootnoteSeparatorExport.hxx b/xmloff/source/style/XMLFootnoteSeparatorExport.hxx new file mode 100644 index 000000000000..6d268e16e40f --- /dev/null +++ b/xmloff/source/style/XMLFootnoteSeparatorExport.hxx @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLFOOTNOTESEPARATOREXPORT_HXX +#define _XMLOFF_XMLFOOTNOTESEPARATOREXPORT_HXX + +#include <sal/types.h> + +class SvXMLExport; +class XMLPropertySetMapper; +struct XMLPropertyState; +template<class X> class UniReference; + + +#include <vector> + + +/** + * export footnote separator element in page styles + */ +class XMLFootnoteSeparatorExport +{ + SvXMLExport& rExport; + +public: + + XMLFootnoteSeparatorExport(SvXMLExport& rExp); + + ~XMLFootnoteSeparatorExport(); + + void exportXML( + const ::std::vector<XMLPropertyState> * pProperties, + sal_uInt32 nIdx, + /// used only for debugging + const UniReference<XMLPropertySetMapper> & rMapper); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/XMLFootnoteSeparatorImport.cxx b/xmloff/source/style/XMLFootnoteSeparatorImport.cxx new file mode 100644 index 000000000000..4c579c78bed5 --- /dev/null +++ b/xmloff/source/style/XMLFootnoteSeparatorImport.cxx @@ -0,0 +1,217 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "XMLFootnoteSeparatorImport.hxx" + +#ifndef _RTL_USTRING +#include <rtl/ustring.hxx> +#endif +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/xml/sax/XAttributeList.hpp> +#include <com/sun/star/text/HorizontalAdjust.hpp> +#include <xmloff/xmlimp.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/xmlprmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/nmspmap.hxx> +#include <xmloff/maptype.hxx> + +#include <xmloff/PageMasterStyleMap.hxx> +#include <tools/debug.hxx> +#include <tools/color.hxx> + +#include <vector> + + +using namespace ::com::sun::star; +using namespace ::xmloff::token; + +using ::rtl::OUString; +using ::std::vector; +using ::com::sun::star::uno::Any; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::xml::sax::XAttributeList; + + +TYPEINIT1(XMLFootnoteSeparatorImport, SvXMLImportContext); + + +XMLFootnoteSeparatorImport::XMLFootnoteSeparatorImport( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + vector<XMLPropertyState> & rProps, + const UniReference<XMLPropertySetMapper> & rMapperRef, + sal_Int32 nIndex) : + SvXMLImportContext(rImport, nPrefix, rLocalName), + rProperties(rProps), + rMapper(rMapperRef), + nPropIndex(nIndex) +{ +} + +XMLFootnoteSeparatorImport::~XMLFootnoteSeparatorImport() +{ +} + +void XMLFootnoteSeparatorImport::StartElement( + const Reference<XAttributeList> & xAttrList) +{ + // get the values from the properties + sal_Int16 nLineWeight = 0; + sal_Int32 nLineColor = 0; + sal_Int8 nLineRelWidth = 0; + sal_Int16 eLineAdjust = text::HorizontalAdjust_LEFT; // enum text::HorizontalAdjust + sal_Int32 nLineTextDistance = 0; + sal_Int32 nLineDistance = 0; + sal_Int8 nLineStyle = 0; + + // iterate over xattribute list and fill values + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + + if (XML_NAMESPACE_STYLE == nPrefix) + { + OUString sAttrValue = xAttrList->getValueByIndex(nAttr); + sal_Int32 nTmp; + if (IsXMLToken( sLocalName, XML_WIDTH )) + { + if (GetImport().GetMM100UnitConverter().convertMeasure( + nTmp, sAttrValue)) + { + nLineWeight = (sal_Int16)nTmp; + } + } + else if (IsXMLToken( sLocalName, XML_DISTANCE_BEFORE_SEP )) + { + if (GetImport().GetMM100UnitConverter().convertMeasure( + nTmp, sAttrValue)) + nLineTextDistance = nTmp; + } + else if (IsXMLToken( sLocalName, XML_DISTANCE_AFTER_SEP )) + { + if (GetImport().GetMM100UnitConverter().convertMeasure( + nTmp, sAttrValue)) + nLineDistance = nTmp; + } + else if (IsXMLToken( sLocalName, XML_ADJUSTMENT )) + { + sal_uInt16 nTmpU; + static const SvXMLEnumMapEntry aXML_HorizontalAdjust_Enum[] = + { + { XML_LEFT, text::HorizontalAdjust_LEFT }, + { XML_CENTER, text::HorizontalAdjust_CENTER }, + { XML_RIGHT, text::HorizontalAdjust_RIGHT }, + { XML_TOKEN_INVALID, 0 } + }; + + if (SvXMLUnitConverter::convertEnum( + nTmpU, sAttrValue, aXML_HorizontalAdjust_Enum)) + eLineAdjust = (sal_Int16)nTmpU; + } + else if (IsXMLToken( sLocalName, XML_REL_WIDTH )) + { + if (SvXMLUnitConverter::convertPercent(nTmp, sAttrValue)) + nLineRelWidth = (sal_uInt8)nTmp; + } + else if (IsXMLToken( sLocalName, XML_COLOR )) + { + Color aColor; + if (SvXMLUnitConverter::convertColor(aColor, sAttrValue)) + nLineColor = (sal_Int32)aColor.GetColor(); + } + else if (IsXMLToken( sLocalName, XML_LINE_STYLE )) + { + sal_uInt16 nTmpU; + static const SvXMLEnumMapEntry aXML_LineStyle_Enum[] = + { + { XML_NONE, 0 }, + { XML_SOLID, 1 }, + { XML_DOTTED, 2 }, + { XML_DASH, 3 }, + { XML_TOKEN_INVALID, 0 } + }; + + if (SvXMLUnitConverter::convertEnum( + nTmpU, sAttrValue, aXML_LineStyle_Enum)) + nLineStyle = (sal_Int8)nTmpU; + + } + } + } + + // OK, now we have all values and can fill the XMLPropertyState vector + Any aAny; + sal_Int32 nIndex; + + aAny <<= eLineAdjust; + nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_ADJUST); + XMLPropertyState aLineAdjust( nIndex, aAny); + rProperties.push_back(aLineAdjust); + + aAny <<= nLineColor; + nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_COLOR); + XMLPropertyState aLineColor( nIndex, aAny ); + rProperties.push_back(aLineColor); + + aAny <<= nLineStyle; + nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_STYLE); + XMLPropertyState aLineStyle( nIndex, aAny ); + rProperties.push_back(aLineStyle); + + aAny <<= nLineDistance; + nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_DISTANCE); + XMLPropertyState aLineDistance( nIndex, aAny ); + rProperties.push_back(aLineDistance); + + aAny <<= nLineRelWidth; + nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_WIDTH); + XMLPropertyState aLineRelWidth( nIndex, aAny); + rProperties.push_back(aLineRelWidth); + + aAny <<= nLineTextDistance; + nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_DISTANCE); + XMLPropertyState aLineTextDistance( nIndex, aAny); + rProperties.push_back(aLineTextDistance); + + DBG_ASSERT( rMapper->FindEntryIndex(CTF_PM_FTN_LINE_WEIGTH) == nPropIndex, + "Received wrong property map index!" ); + aAny <<= nLineWeight; + XMLPropertyState aLineWeight( nPropIndex, aAny ); + rProperties.push_back(aLineWeight); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/XMLFootnoteSeparatorImport.hxx b/xmloff/source/style/XMLFootnoteSeparatorImport.hxx new file mode 100644 index 000000000000..9c929c15315c --- /dev/null +++ b/xmloff/source/style/XMLFootnoteSeparatorImport.hxx @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLFOOTNOTESEPARATORIMPORT_HXX +#define _XMLOFF_XMLFOOTNOTESEPARATORIMPORT_HXX + + + +#include <xmloff/xmlictxt.hxx> +#include <xmloff/uniref.hxx> + +#include <vector> + + +class SvXMLImport; +struct XMLPropertyState; +class XMLPropertySetMapper; +namespace rtl { class OUString; } +namespace com { namespace sun { namespace star { + namespace uno { template<class X> class Reference; } + namespace xml { namespace sax { class XAttributeList; } } +} } } + + +/** + * Import the footnote-separator element in page styles. + */ +class XMLFootnoteSeparatorImport : public SvXMLImportContext +{ + ::std::vector<XMLPropertyState> & rProperties; + UniReference<XMLPropertySetMapper> rMapper; + sal_Int32 nPropIndex; + +public: + + TYPEINFO(); + + XMLFootnoteSeparatorImport( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + ::std::vector<XMLPropertyState> & rProperties, + const UniReference<XMLPropertySetMapper> & rMapperRef, + sal_Int32 nIndex); + + ~XMLFootnoteSeparatorImport(); + + virtual void StartElement( + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/XMLIsPercentagePropertyHandler.cxx b/xmloff/source/style/XMLIsPercentagePropertyHandler.cxx new file mode 100644 index 000000000000..96836b738d7c --- /dev/null +++ b/xmloff/source/style/XMLIsPercentagePropertyHandler.cxx @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <rtl/ustrbuf.hxx> +#include "XMLIsPercentagePropertyHandler.hxx" + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + + +XMLIsPercentagePropertyHandler::~XMLIsPercentagePropertyHandler() +{ +} + +sal_Bool XMLIsPercentagePropertyHandler::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + rValue <<= (sal_Bool)(rStrImpValue.indexOf( sal_Unicode('%') ) != -1); + return sal_True; +} + +sal_Bool XMLIsPercentagePropertyHandler::exportXML( + OUString&, + const Any&, + const SvXMLUnitConverter& ) const +{ + OSL_FAIL( "XMLIsPercentagePropertyHandler is not for export!" ); + return sal_False; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/XMLPageExport.cxx b/xmloff/source/style/XMLPageExport.cxx new file mode 100644 index 000000000000..7def49621b27 --- /dev/null +++ b/xmloff/source/style/XMLPageExport.cxx @@ -0,0 +1,272 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <xmloff/XMLPageExport.hxx> +#include <tools/debug.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/container/XIndexReplace.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <xmloff/families.hxx> +#include <xmloff/xmlexp.hxx> +#include "PageMasterPropHdlFactory.hxx" +#include <xmloff/PageMasterStyleMap.hxx> +#include "PageMasterPropMapper.hxx" +#include "PageMasterExportPropMapper.hxx" +#include "PageMasterExportPropMapper.hxx" + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::style; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::beans; +using namespace ::xmloff::token; + + +//______________________________________________________________________________ + +sal_Bool XMLPageExport::findPageMasterName( const OUString& rStyleName, OUString& rPMName ) const +{ + for( ::std::vector< XMLPageExportNameEntry >::const_iterator pEntry = aNameVector.begin(); + pEntry != aNameVector.end(); pEntry++ ) + { + if( pEntry->sStyleName == rStyleName ) + { + rPMName = pEntry->sPageMasterName; + return sal_True; + } + } + return sal_False; +} + +void XMLPageExport::collectPageMasterAutoStyle( + const Reference < XPropertySet > & rPropSet, + OUString& rPageMasterName ) +{ + DBG_ASSERT( xPageMasterPropSetMapper.is(), "page master family/XMLPageMasterPropSetMapper not found" ); + if( xPageMasterPropSetMapper.is() ) + { + ::std::vector<XMLPropertyState> xPropStates = xPageMasterExportPropMapper->Filter( rPropSet ); + if( !xPropStates.empty()) + { + OUString sParent; + rPageMasterName = rExport.GetAutoStylePool()->Find( XML_STYLE_FAMILY_PAGE_MASTER, sParent, xPropStates ); + if (!rPageMasterName.getLength()) + rPageMasterName = rExport.GetAutoStylePool()->Add(XML_STYLE_FAMILY_PAGE_MASTER, sParent, xPropStates); + } + } +} + +void XMLPageExport::exportMasterPageContent( + const Reference < XPropertySet > &, + sal_Bool /*bAutoStyles*/ ) +{ + +} + +sal_Bool XMLPageExport::exportStyle( + const Reference< XStyle >& rStyle, + sal_Bool bAutoStyles ) +{ + Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY ); + Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo(); + + // Don't export styles that aren't existing really. This may be the + // case for StarOffice Writer's pool styles. + if( xPropSetInfo->hasPropertyByName( sIsPhysical ) ) + { + Any aAny = xPropSet->getPropertyValue( sIsPhysical ); + if( !*(sal_Bool *)aAny.getValue() ) + return sal_False; + } + + if( bAutoStyles ) + { + XMLPageExportNameEntry aEntry; + collectPageMasterAutoStyle( xPropSet, aEntry.sPageMasterName ); + aEntry.sStyleName = rStyle->getName(); + aNameVector.push_back( aEntry ); + + exportMasterPageContent( xPropSet, sal_True ); + } + else + { + OUString sName( rStyle->getName() ); + sal_Bool bEncoded = sal_False; + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME, + GetExport().EncodeStyleName( sName, &bEncoded ) ); + + if( bEncoded ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME, + sName); + + OUString sPMName; + if( findPageMasterName( sName, sPMName ) ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_PAGE_LAYOUT_NAME, GetExport().EncodeStyleName( sPMName ) ); + + Reference<XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo(); + if ( xInfo.is() && xInfo->hasPropertyByName(sFollowStyle) ) + { + OUString sNextName; + xPropSet->getPropertyValue( sFollowStyle ) >>= sNextName; + + if( sName != sNextName && sNextName.getLength() ) + { + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NEXT_STYLE_NAME, + GetExport().EncodeStyleName( sNextName ) ); + } + } + + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, + XML_MASTER_PAGE, sal_True, sal_True ); + + exportMasterPageContent( xPropSet, sal_False ); + } + + return sal_True; +} + +XMLPageExport::XMLPageExport( SvXMLExport& rExp ) : + rExport( rExp ), + sIsPhysical( RTL_CONSTASCII_USTRINGPARAM( "IsPhysical" ) ), + sFollowStyle( RTL_CONSTASCII_USTRINGPARAM( "FollowStyle" ) ) +{ + xPageMasterPropHdlFactory = new XMLPageMasterPropHdlFactory; + xPageMasterPropSetMapper = new XMLPageMasterPropSetMapper( + (XMLPropertyMapEntry*) aXMLPageMasterStyleMap, + xPageMasterPropHdlFactory ); + xPageMasterExportPropMapper = new XMLPageMasterExportPropMapper( + xPageMasterPropSetMapper, rExp); + + rExport.GetAutoStylePool()->AddFamily( XML_STYLE_FAMILY_PAGE_MASTER, OUString( RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_PAGE_MASTER_NAME ) ), + xPageMasterExportPropMapper, OUString( RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_PAGE_MASTER_PREFIX ) ), sal_False ); + + Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetExport().GetModel(), + UNO_QUERY ); + DBG_ASSERT( xFamiliesSupp.is(), + "No XStyleFamiliesSupplier from XModel for export!" ); + if( xFamiliesSupp.is() ) + { + Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() ); + DBG_ASSERT( xFamiliesSupp.is(), + "getStyleFamilies() from XModel failed for export!" ); + if( xFamilies.is() ) + { + const OUString aPageStyleName( + RTL_CONSTASCII_USTRINGPARAM( "PageStyles" )); + + if( xFamilies->hasByName( aPageStyleName ) ) + { + xPageStyles.set(xFamilies->getByName( aPageStyleName ),uno::UNO_QUERY); + + DBG_ASSERT( xPageStyles.is(), + "Page Styles not found for export!" ); + } + } + } +} + +XMLPageExport::~XMLPageExport() +{ +} + +void XMLPageExport::exportStyles( sal_Bool bUsed, sal_Bool bAutoStyles ) +{ + if( xPageStyles.is() ) + { + uno::Sequence< ::rtl::OUString> aSeq = xPageStyles->getElementNames(); + const ::rtl::OUString* pIter = aSeq.getConstArray(); + const ::rtl::OUString* pEnd = pIter + aSeq.getLength(); + for(;pIter != pEnd;++pIter) + { + Reference< XStyle > xStyle(xPageStyles->getByName( *pIter ),uno::UNO_QUERY); + if( !bUsed || xStyle->isInUse() ) + exportStyle( xStyle, bAutoStyles ); + } + } +} + +void XMLPageExport::exportAutoStyles() +{ + rExport.GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_PAGE_MASTER + , rExport.GetDocHandler(), rExport.GetMM100UnitConverter(), + rExport.GetNamespaceMap() + ); +} + +void XMLPageExport::exportDefaultStyle() +{ + Reference < lang::XMultiServiceFactory > xFactory (GetExport().GetModel(), UNO_QUERY); + if (xFactory.is()) + { + OUString sTextDefaults ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.text.Defaults" ) ); + Reference < XPropertySet > xPropSet (xFactory->createInstance ( sTextDefaults ), UNO_QUERY); + if (xPropSet.is()) + { + // <style:default-style ...> + GetExport().CheckAttrList(); + + ::std::vector< XMLPropertyState > xPropStates = + xPageMasterExportPropMapper->FilterDefaults( xPropSet ); + + sal_Bool bExport = sal_False; + UniReference < XMLPropertySetMapper > aPropMapper(xPageMasterExportPropMapper->getPropertySetMapper()); + for( ::std::vector< XMLPropertyState >::iterator aIter = xPropStates.begin(); aIter != xPropStates.end(); ++aIter ) + { + XMLPropertyState *pProp = &(*aIter); + sal_Int16 nContextId = aPropMapper->GetEntryContextId( pProp->mnIndex ); + if( nContextId == CTF_PM_STANDARD_MODE ) + { + bExport = sal_True; + break; + } + } + + if( bExport ) + { + //<style:default-page-layout> + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, + XML_DEFAULT_PAGE_LAYOUT, + sal_True, sal_True ); + + xPageMasterExportPropMapper->exportXML( GetExport(), xPropStates, + XML_EXPORT_FLAG_IGN_WS ); + } + } + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/XMLPercentOrMeasurePropertyHandler.cxx b/xmloff/source/style/XMLPercentOrMeasurePropertyHandler.cxx new file mode 100644 index 000000000000..b3f147cbbdcb --- /dev/null +++ b/xmloff/source/style/XMLPercentOrMeasurePropertyHandler.cxx @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <rtl/ustrbuf.hxx> +#include "XMLPercentOrMeasurePropertyHandler.hxx" +#include <xmloff/xmluconv.hxx> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + + +XMLPercentOrMeasurePropertyHandler::XMLPercentOrMeasurePropertyHandler( sal_Bool bPercent ) +: mbPercent( bPercent ) +{ +} + +XMLPercentOrMeasurePropertyHandler::~XMLPercentOrMeasurePropertyHandler() +{ +} + +sal_Bool XMLPercentOrMeasurePropertyHandler::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& rUnitConverter ) const +{ + if( (rStrImpValue.indexOf( sal_Unicode('%') ) != -1) != mbPercent ) + return sal_False; + + sal_Int32 nValue; + + if( mbPercent ) + { + if( !rUnitConverter.convertPercent( nValue, rStrImpValue ) ) + return sal_False; + } + else + { + if( !rUnitConverter.convertMeasure( nValue, rStrImpValue ) ) + return sal_False; + } + + rValue <<= nValue; + return sal_True; +} + +sal_Bool XMLPercentOrMeasurePropertyHandler::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& rUnitConverter ) const +{ + OUStringBuffer aOut; + + sal_Int32 nValue = 0; + if( !(rValue >>= nValue ) ) + return sal_False; + + if( mbPercent ) + { + rUnitConverter.convertPercent( aOut, nValue ); + } + else + { + rUnitConverter.convertMeasure( aOut, nValue ); + } + + rStrExpValue = aOut.makeStringAndClear(); + return sal_True; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/XMLRectangleMembersHandler.cxx b/xmloff/source/style/XMLRectangleMembersHandler.cxx new file mode 100644 index 000000000000..9e9fef6d9c96 --- /dev/null +++ b/xmloff/source/style/XMLRectangleMembersHandler.cxx @@ -0,0 +1,125 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <xmloff/xmluconv.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/Any.hxx> + +#include <com/sun/star/awt/Rectangle.hdl> +#include "XMLRectangleMembersHandler.hxx" +#include <xmloff/xmltypes.hxx> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + + +XMLRectangleMembersHdl::XMLRectangleMembersHdl( sal_Int32 nType ) +: mnType( nType ) +{ +} + +XMLRectangleMembersHdl::~XMLRectangleMembersHdl() +{ +} + +sal_Bool XMLRectangleMembersHdl::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& rUnitConverter ) const +{ + awt::Rectangle aRect( 0, 0, 0, 0 ); + if( rValue.hasValue() ) + rValue >>= aRect; + + sal_Int32 nValue; + + if( rUnitConverter.convertMeasure( nValue, rStrImpValue ) ) + { + switch( mnType ) + { + case XML_TYPE_RECTANGLE_LEFT : + aRect.X = nValue; + break; + case XML_TYPE_RECTANGLE_TOP : + aRect.Y = nValue; + break; + case XML_TYPE_RECTANGLE_WIDTH : + aRect.Width = nValue; + break; + case XML_TYPE_RECTANGLE_HEIGHT : + aRect.Height = nValue; + break; + } + + rValue <<= aRect; + return sal_True; + } + + return sal_False; +} + +sal_Bool XMLRectangleMembersHdl::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& rUnitConverter ) const +{ + awt::Rectangle aRect( 0, 0, 0, 0 ); + rValue >>= aRect; + + sal_Int32 nValue; + + switch( mnType ) + { + case XML_TYPE_RECTANGLE_LEFT : + nValue = aRect.X; + break; + case XML_TYPE_RECTANGLE_TOP : + nValue = aRect.Y; + break; + case XML_TYPE_RECTANGLE_WIDTH : + nValue = aRect.Width; + break; + case XML_TYPE_RECTANGLE_HEIGHT : + nValue = aRect.Height; + break; + default: + nValue = 0; // TODO What value should this be? + break; + } + + rtl::OUStringBuffer sBuffer; + rUnitConverter.convertMeasure( sBuffer, nValue ); + rStrExpValue = sBuffer.makeStringAndClear(); + return sal_True; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/adjushdl.cxx b/xmloff/source/style/adjushdl.cxx new file mode 100644 index 000000000000..fd050d028111 --- /dev/null +++ b/xmloff/source/style/adjushdl.cxx @@ -0,0 +1,138 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <adjushdl.hxx> +#include <tools/solar.h> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/style/ParagraphAdjust.hpp> +#include <com/sun/star/uno/Any.hxx> + +using namespace ::com::sun::star; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::xmloff::token; + +SvXMLEnumMapEntry const pXML_Para_Adjust_Enum[] = +{ + { XML_START, style::ParagraphAdjust_LEFT }, + { XML_END, style::ParagraphAdjust_RIGHT }, + { XML_CENTER, style::ParagraphAdjust_CENTER }, + { XML_JUSTIFY, style::ParagraphAdjust_BLOCK }, + { XML_JUSTIFIED, style::ParagraphAdjust_BLOCK }, // obsolete + { XML_LEFT, style::ParagraphAdjust_LEFT }, + { XML_RIGHT, style::ParagraphAdjust_RIGHT }, + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLEnumMapEntry const pXML_Para_Align_Last_Enum[] = +{ + { XML_START, style::ParagraphAdjust_LEFT }, + { XML_CENTER, style::ParagraphAdjust_CENTER }, + { XML_JUSTIFY, style::ParagraphAdjust_BLOCK }, + { XML_JUSTIFIED, style::ParagraphAdjust_BLOCK }, // obsolete + { XML_TOKEN_INVALID, 0 } +}; + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLParaAdjustPropHdl +// + +XMLParaAdjustPropHdl::~XMLParaAdjustPropHdl() +{ + // nothing to do +} + +sal_Bool XMLParaAdjustPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_uInt16 eAdjust; + sal_Bool bRet = SvXMLUnitConverter::convertEnum( eAdjust, rStrImpValue, pXML_Para_Adjust_Enum ); + if( bRet ) + rValue <<= (sal_Int16)eAdjust; + + return bRet; +} + +sal_Bool XMLParaAdjustPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + if(!rValue.hasValue()) + return sal_False; + OUStringBuffer aOut; + sal_Int16 nVal = 0; + + rValue >>= nVal; + + sal_Bool bRet = SvXMLUnitConverter::convertEnum( aOut, nVal, pXML_Para_Adjust_Enum, XML_START ); + + rStrExpValue = aOut.makeStringAndClear(); + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLLastLineAdjustPropHdl +// + +XMLLastLineAdjustPropHdl::~XMLLastLineAdjustPropHdl() +{ + // nothing to do +} + +sal_Bool XMLLastLineAdjustPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_uInt16 eAdjust; + sal_Bool bRet = SvXMLUnitConverter::convertEnum( eAdjust, rStrImpValue, pXML_Para_Align_Last_Enum ); + if( bRet ) + rValue <<= (sal_Int16)eAdjust; + + return bRet; +} + +sal_Bool XMLLastLineAdjustPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + OUStringBuffer aOut; + sal_Int16 nVal = 0; + sal_Bool bRet = sal_False; + + rValue >>= nVal; + + if( nVal != style::ParagraphAdjust_LEFT ) + bRet = SvXMLUnitConverter::convertEnum( aOut, nVal, pXML_Para_Align_Last_Enum, XML_START ); + + rStrExpValue = aOut.makeStringAndClear(); + + return bRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/adjushdl.hxx b/xmloff/source/style/adjushdl.hxx new file mode 100644 index 000000000000..20a5c04207b5 --- /dev/null +++ b/xmloff/source/style/adjushdl.hxx @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PROPERTYHANDLER_ADJUSTTYPES_HXX +#define _XMLOFF_PROPERTYHANDLER_ADJUSTTYPES_HXX + +#include <xmloff/xmlprhdl.hxx> + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLParaAdjustPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLParaAdjustPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLLastLineAdjustPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLLastLineAdjustPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +#endif // _XMLOFF_PROPERTYHANDLER_ADJUSTTYPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/backhdl.cxx b/xmloff/source/style/backhdl.cxx new file mode 100644 index 000000000000..e6743dd9609e --- /dev/null +++ b/xmloff/source/style/backhdl.cxx @@ -0,0 +1,300 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include <backhdl.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <rtl/ustrbuf.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::xmloff::token; + +SvXMLEnumMapEntry pXML_BrushHorizontalPos[] = +{ + { XML_LEFT, style::GraphicLocation_LEFT_MIDDLE }, + { XML_RIGHT, style::GraphicLocation_RIGHT_MIDDLE }, + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLEnumMapEntry pXML_BrushVerticalPos[] = +{ + { XML_TOP, style::GraphicLocation_MIDDLE_TOP }, + { XML_BOTTOM, style::GraphicLocation_MIDDLE_BOTTOM }, + { XML_TOKEN_INVALID, 0 } +}; + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLBackGraphicPositionPropHdl +// + +XMLBackGraphicPositionPropHdl::~XMLBackGraphicPositionPropHdl() +{ + // Nothing to do +} + +sal_Bool XMLBackGraphicPositionPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_True; + style::GraphicLocation ePos = style::GraphicLocation_NONE, eTmp; + sal_uInt16 nTmp; + SvXMLTokenEnumerator aTokenEnum( rStrImpValue ); + OUString aToken; + sal_Bool bHori = sal_False, bVert = sal_False; + + while( bRet && aTokenEnum.getNextToken( aToken ) ) + { + if( bHori && bVert ) + { + bRet = sal_False; + } + else if( -1 != aToken.indexOf( sal_Unicode('%') ) ) + { + sal_Int32 nPrc = 50; + if( SvXMLUnitConverter::convertPercent( nPrc, aToken ) ) + { + if( !bHori ) + { + ePos = nPrc < 25 ? style::GraphicLocation_LEFT_TOP : + (nPrc < 75 ? style::GraphicLocation_MIDDLE_MIDDLE : + style::GraphicLocation_RIGHT_BOTTOM); + bHori = sal_True; + } + else + { + eTmp = nPrc < 25 ? style::GraphicLocation_LEFT_TOP: + (nPrc < 75 ? style::GraphicLocation_LEFT_MIDDLE : + style::GraphicLocation_LEFT_BOTTOM); + MergeXMLVertPos( ePos, eTmp ); + bVert = sal_True; + } + } + else + { + // wrong percentage + bRet = sal_False; + } + } + else if( IsXMLToken( aToken, XML_CENTER ) ) + { + if( bHori ) + MergeXMLVertPos( ePos, style::GraphicLocation_MIDDLE_MIDDLE ); + else if ( bVert ) + MergeXMLHoriPos( ePos, style::GraphicLocation_MIDDLE_MIDDLE ); + else + ePos = style::GraphicLocation_MIDDLE_MIDDLE; + } + else if( SvXMLUnitConverter::convertEnum( nTmp, aToken, pXML_BrushHorizontalPos ) ) + { + if( bVert ) + MergeXMLHoriPos( ePos, (style::GraphicLocation)nTmp ); + else if( !bHori ) + ePos = (style::GraphicLocation)nTmp; + else + bRet = sal_False; + + bHori = sal_True; + } + else if( SvXMLUnitConverter::convertEnum( nTmp, aToken, pXML_BrushVerticalPos ) ) + { + if( bHori ) + MergeXMLVertPos( ePos, (style::GraphicLocation)nTmp ); + else if( !bVert ) + ePos = (style::GraphicLocation)nTmp; + else + bRet = sal_False; + bVert = sal_True; + } + else + { + bRet = sal_False; + } + } + + bRet &= style::GraphicLocation_NONE != ePos; + if( bRet ) + rValue <<= (style::GraphicLocation)(sal_uInt16)ePos; + + return bRet; +} + +sal_Bool XMLBackGraphicPositionPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_True; + OUStringBuffer aOut; + + style::GraphicLocation eLocation; + if( !( rValue >>= eLocation ) ) + { + sal_Int32 nValue = 0; + if( rValue >>= nValue ) + eLocation = (style::GraphicLocation)nValue; + else + bRet = sal_False; + } + + if( bRet ) + { + bRet = sal_False; + + switch( eLocation ) + { + case style::GraphicLocation_LEFT_TOP: + case style::GraphicLocation_MIDDLE_TOP: + case style::GraphicLocation_RIGHT_TOP: + aOut.append( GetXMLToken(XML_TOP) ); + bRet = sal_True; + break; + case style::GraphicLocation_LEFT_MIDDLE: + case style::GraphicLocation_MIDDLE_MIDDLE: + case style::GraphicLocation_RIGHT_MIDDLE: + aOut.append( GetXMLToken(XML_CENTER) ); + bRet = sal_True; + break; + case style::GraphicLocation_LEFT_BOTTOM: + case style::GraphicLocation_MIDDLE_BOTTOM: + case style::GraphicLocation_RIGHT_BOTTOM: + aOut.append( GetXMLToken(XML_BOTTOM) ); + bRet = sal_True; + break; + default: + break; + } + + if( bRet ) + { + aOut.append( sal_Unicode( ' ' ) ); + + switch( eLocation ) + { + case style::GraphicLocation_LEFT_TOP: + case style::GraphicLocation_LEFT_BOTTOM: + case style::GraphicLocation_LEFT_MIDDLE: + aOut.append( GetXMLToken(XML_LEFT) ); + break; + case style::GraphicLocation_MIDDLE_TOP: + case style::GraphicLocation_MIDDLE_MIDDLE: + case style::GraphicLocation_MIDDLE_BOTTOM: + aOut.append( GetXMLToken(XML_CENTER) ); + break; + case style::GraphicLocation_RIGHT_MIDDLE: + case style::GraphicLocation_RIGHT_TOP: + case style::GraphicLocation_RIGHT_BOTTOM: + aOut.append( GetXMLToken(XML_RIGHT) ); + break; + default: + break; + } + } + } + + rStrExpValue = aOut.makeStringAndClear(); + + return bRet; +} + +void XMLBackGraphicPositionPropHdl::MergeXMLVertPos( style::GraphicLocation& ePos, style::GraphicLocation eVert ) const +{ + switch( ePos ) + { + case style::GraphicLocation_LEFT_TOP: + case style::GraphicLocation_LEFT_MIDDLE: + case style::GraphicLocation_LEFT_BOTTOM: + ePos = style::GraphicLocation_MIDDLE_TOP==eVert ? + style::GraphicLocation_LEFT_TOP : + (style::GraphicLocation_MIDDLE_MIDDLE==eVert ? + style::GraphicLocation_LEFT_MIDDLE : + style::GraphicLocation_LEFT_BOTTOM); + ePos = eVert; + break; + + case style::GraphicLocation_MIDDLE_TOP: + case style::GraphicLocation_MIDDLE_MIDDLE: + case style::GraphicLocation_MIDDLE_BOTTOM: + ePos = eVert; + break; + + case style::GraphicLocation_RIGHT_TOP: + case style::GraphicLocation_RIGHT_MIDDLE: + case style::GraphicLocation_RIGHT_BOTTOM: + ePos = style::GraphicLocation_MIDDLE_TOP==eVert ? + style::GraphicLocation_RIGHT_TOP : + (style::GraphicLocation_MIDDLE_MIDDLE==eVert ? + style::GraphicLocation_RIGHT_MIDDLE : + style::GraphicLocation_RIGHT_BOTTOM); + break; + default: + break; + } +} + +void XMLBackGraphicPositionPropHdl::MergeXMLHoriPos( style::GraphicLocation& ePos, style::GraphicLocation eHori ) const +{ + DBG_ASSERT( style::GraphicLocation_LEFT_MIDDLE==eHori || style::GraphicLocation_MIDDLE_MIDDLE==eHori || style::GraphicLocation_RIGHT_MIDDLE==eHori, + "lcl_frmitems_MergeXMLHoriPos: vertical pos must be middle" ); + + switch( ePos ) + { + case style::GraphicLocation_LEFT_TOP: + case style::GraphicLocation_MIDDLE_TOP: + case style::GraphicLocation_RIGHT_TOP: + ePos = style::GraphicLocation_LEFT_MIDDLE==eHori ? + style::GraphicLocation_LEFT_TOP : + (style::GraphicLocation_MIDDLE_MIDDLE==eHori ? + style::GraphicLocation_MIDDLE_TOP : + style::GraphicLocation_RIGHT_TOP); + break; + + case style::GraphicLocation_LEFT_MIDDLE: + case style::GraphicLocation_MIDDLE_MIDDLE: + case style::GraphicLocation_RIGHT_MIDDLE: + ePos = eHori; + break; + + case style::GraphicLocation_LEFT_BOTTOM: + case style::GraphicLocation_MIDDLE_BOTTOM: + case style::GraphicLocation_RIGHT_BOTTOM: + ePos = style::GraphicLocation_LEFT_MIDDLE==eHori ? + style::GraphicLocation_LEFT_BOTTOM : + (style::GraphicLocation_MIDDLE_MIDDLE==eHori ? + style::GraphicLocation_MIDDLE_BOTTOM : + style::GraphicLocation_RIGHT_BOTTOM); + break; + default: + break; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/backhdl.hxx b/xmloff/source/style/backhdl.hxx new file mode 100644 index 000000000000..bef4912cb5e9 --- /dev/null +++ b/xmloff/source/style/backhdl.hxx @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PROPERTYHANDLER_BRUSHTYPES_HXX +#define _XMLOFF_PROPERTYHANDLER_BRUSHTYPES_HXX + +#include <xmloff/xmlprhdl.hxx> +#include <com/sun/star/style/GraphicLocation.hpp> +#include <com/sun/star/style/GraphicLocation.hpp> + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLBackGraphicPositionPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLBackGraphicPositionPropHdl(); + + /// TabStops will be imported/exported as XML-Elements. So the Import/Export-work must be done at another place. + using XMLPropertyHandler::importXML; + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + +private: + void MergeXMLHoriPos( ::com::sun::star::style::GraphicLocation& ePos, ::com::sun::star::style::GraphicLocation eHori ) const; + void MergeXMLVertPos( ::com::sun::star::style::GraphicLocation& ePos, ::com::sun::star::style::GraphicLocation eVert ) const; +}; + +#endif // _XMLOFF_PROPERTYHANDLER_BRUSHTYPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/bordrhdl.cxx b/xmloff/source/style/bordrhdl.cxx new file mode 100644 index 000000000000..230f1082fe2e --- /dev/null +++ b/xmloff/source/style/bordrhdl.cxx @@ -0,0 +1,374 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include <bordrhdl.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/table/BorderLine2.hpp> + +#if DEBUG +#include <cstdio> +#endif + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::xmloff::token; + +const sal_uInt16 API_LINE_SOLID = 0; +const sal_uInt16 API_LINE_DOTTED = 1; +const sal_uInt16 API_LINE_DASHED = 2; +const sal_uInt16 API_LINE_DOUBLE = 3; +const sal_uInt16 API_LINE_THINTHICK_SMALLGAP = 4; +const sal_uInt16 API_LINE_THINTHICK_MEDIUMGAP = 5; +const sal_uInt16 API_LINE_THINTHICK_LARGEGAP = 6; +const sal_uInt16 API_LINE_THICKTHIN_SMALLGAP = 7; +const sal_uInt16 API_LINE_THICKTHIN_MEDIUMGAP = 8; +const sal_uInt16 API_LINE_THICKTHIN_LARGEGAP = 9; +const sal_uInt16 API_LINE_EMBOSSED = 10; +const sal_uInt16 API_LINE_ENGRAVED = 11; +const sal_uInt16 API_LINE_OUTSET = 12; +const sal_uInt16 API_LINE_INSET = 13; +const sal_uInt16 API_LINE_NONE = USHRT_MAX; + +#define DEF_LINE_WIDTH_0 1 +#define DEF_LINE_WIDTH_1 35 +#define DEF_LINE_WIDTH_2 88 + +#define SVX_XML_BORDER_WIDTH_THIN 0 +#define SVX_XML_BORDER_WIDTH_MIDDLE 1 +#define SVX_XML_BORDER_WIDTH_THICK 2 + +SvXMLEnumMapEntry pXML_BorderStyles[] = +{ + { XML_NONE, API_LINE_NONE }, + { XML_HIDDEN, API_LINE_NONE }, + { XML_SOLID, API_LINE_SOLID }, + { XML_DOUBLE, API_LINE_DOUBLE }, + { XML_DOTTED, API_LINE_DOTTED }, + { XML_DASHED, API_LINE_DASHED }, + { XML_GROOVE, API_LINE_ENGRAVED }, + { XML_RIDGE, API_LINE_EMBOSSED }, + { XML_INSET, API_LINE_INSET }, + { XML_OUTSET, API_LINE_OUTSET }, + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLEnumMapEntry pXML_NamedBorderWidths[] = +{ + { XML_THIN, SVX_XML_BORDER_WIDTH_THIN }, + { XML_MIDDLE, SVX_XML_BORDER_WIDTH_MIDDLE }, + { XML_THICK, SVX_XML_BORDER_WIDTH_THICK }, + { XML_TOKEN_INVALID, 0 } +}; +// mapping tables to map external xml input to intarnal box line widths + + +static sal_uInt16 const aBorderWidths[] = +{ + DEF_LINE_WIDTH_0, + DEF_LINE_WIDTH_1, + DEF_LINE_WIDTH_2 +}; + +void lcl_frmitems_setXMLBorderStyle( table::BorderLine2 & rBorderLine, sal_uInt16 nStyle ) +{ + sal_Int16 eStyle = -1; // None + if ( nStyle != API_LINE_NONE ) + eStyle = sal_Int16( nStyle ); + + rBorderLine.LineStyle = eStyle; +} + + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLEscapementPropHdl +// + +XMLBorderWidthHdl::~XMLBorderWidthHdl() +{ + // nothing to do +} + +sal_Bool XMLBorderWidthHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const +{ + SvXMLTokenEnumerator aTokenEnum( rStrImpValue ); + + sal_Int32 nInWidth, nDistance, nOutWidth; + + OUString aToken; + if( !aTokenEnum.getNextToken( aToken ) ) + return sal_False; + + if( !rUnitConverter.convertMeasure( nInWidth, aToken, 0, 500 ) ) + return sal_False; + + if( !aTokenEnum.getNextToken( aToken ) ) + return sal_False; + + if( !rUnitConverter.convertMeasure( nDistance, aToken, 0, 500 ) ) + return sal_False; + + if( !aTokenEnum.getNextToken( aToken ) ) + return sal_False; + + if( !rUnitConverter.convertMeasure( nOutWidth, aToken, 0, 500 ) ) + return sal_False; + + table::BorderLine2 aBorderLine; + if(!(rValue >>= aBorderLine)) + aBorderLine.Color = 0; + + aBorderLine.InnerLineWidth = sal::static_int_cast< sal_Int16 >(nInWidth); + aBorderLine.OuterLineWidth = sal::static_int_cast< sal_Int16 >(nOutWidth); + aBorderLine.LineDistance = sal::static_int_cast< sal_Int16 >(nDistance); + + rValue <<= aBorderLine; + return sal_True; +} + +sal_Bool XMLBorderWidthHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const +{ + OUStringBuffer aOut; + + table::BorderLine2 aBorderLine; + if(!(rValue >>= aBorderLine)) + return sal_False; + + bool bDouble = false; + switch ( aBorderLine.LineStyle ) + { + case API_LINE_DOUBLE: + case API_LINE_THINTHICK_SMALLGAP: + case API_LINE_THINTHICK_MEDIUMGAP: + case API_LINE_THINTHICK_LARGEGAP: + case API_LINE_THICKTHIN_SMALLGAP: + case API_LINE_THICKTHIN_MEDIUMGAP: + case API_LINE_THICKTHIN_LARGEGAP: + bDouble = true; + break; + default: + break; + } + + if( ( aBorderLine.LineDistance == 0 && aBorderLine.InnerLineWidth == 0 ) || !bDouble ) + return sal_False; + + rUnitConverter.convertMeasure( aOut, aBorderLine.InnerLineWidth ); + aOut.append( sal_Unicode( ' ' ) ); + rUnitConverter.convertMeasure( aOut, aBorderLine.LineDistance ); + aOut.append( sal_Unicode( ' ' ) ); + rUnitConverter.convertMeasure( aOut, aBorderLine.OuterLineWidth ); + + rStrExpValue = aOut.makeStringAndClear(); + return sal_True; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLEscapementHeightPropHdl +// + +XMLBorderHdl::~XMLBorderHdl() +{ + // nothing to do +} + +sal_Bool XMLBorderHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const +{ + OUString aToken; + SvXMLTokenEnumerator aTokens( rStrImpValue ); + + sal_Bool bHasStyle = sal_False; + sal_Bool bHasWidth = sal_False; + sal_Bool bHasColor = sal_False; + + sal_uInt16 nStyle = USHRT_MAX; + sal_uInt16 nWidth = 0; + sal_uInt16 nNamedWidth = USHRT_MAX; + Color aColor; + + sal_Int32 nTemp; + while( aTokens.getNextToken( aToken ) && aToken.getLength() != 0 ) + { + if( !bHasWidth && + rUnitConverter.convertEnum( nNamedWidth, aToken, + pXML_NamedBorderWidths ) ) + { + bHasWidth = sal_True; + } + else if( !bHasStyle && + rUnitConverter.convertEnum( nStyle, aToken, + pXML_BorderStyles ) ) + { + bHasStyle = sal_True; + } + else if( !bHasColor && rUnitConverter.convertColor( aColor, aToken ) ) + { + bHasColor = sal_True; + } + else if( !bHasWidth && + rUnitConverter.convertMeasure( nTemp, aToken, 0, + USHRT_MAX ) ) + { + nWidth = (sal_uInt16)nTemp; + bHasWidth = sal_True; + } + else + { + // missformed + return sal_False; + } + } + + // if there is no style or a different style than none but no width, + // then the declaration is not valid. + if( !bHasStyle || (API_LINE_NONE != nStyle && !bHasWidth) ) + return sal_False; + + table::BorderLine2 aBorderLine; + if(!(rValue >>= aBorderLine)) + { + aBorderLine.Color = 0; + aBorderLine.InnerLineWidth = 0; + aBorderLine.OuterLineWidth = 0; + aBorderLine.LineDistance = 0; + aBorderLine.LineWidth = 0; + } + + // first of all, delete an empty line + if( (bHasStyle && API_LINE_NONE == nStyle) || + (bHasWidth && USHRT_MAX == nNamedWidth && 0 == nWidth) ) + { + aBorderLine.InnerLineWidth = 0; + aBorderLine.OuterLineWidth = 0; + aBorderLine.LineDistance = 0; + aBorderLine.LineWidth = 0; + } + else if( bHasWidth ) + { + if( USHRT_MAX != nNamedWidth ) + { + aBorderLine.LineWidth = aBorderWidths[nNamedWidth]; + } + else + { + aBorderLine.LineWidth = nWidth; + lcl_frmitems_setXMLBorderStyle( aBorderLine, nStyle ); + } + } + else + { + aBorderLine.LineWidth = 0; + lcl_frmitems_setXMLBorderStyle( aBorderLine, nStyle ); + } + + // set color + if( bHasColor ) + aBorderLine.Color = (sal_Int32)aColor.GetRGBColor(); + + rValue <<= aBorderLine; + return sal_True; +} + +sal_Bool XMLBorderHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const +{ + OUStringBuffer aOut; + + table::BorderLine2 aBorderLine; + if(!(rValue >>= aBorderLine)) + return sal_False; + + sal_Int32 nWidth = aBorderLine.LineWidth; + + if( nWidth == 0 ) + { + aOut.append( GetXMLToken( XML_NONE ) ); + } + else + { + rUnitConverter.convertMeasure( aOut, nWidth, + MAP_100TH_MM, MAP_POINT ); + + aOut.append( sal_Unicode( ' ' ) ); + + XMLTokenEnum eStyleToken = XML_SOLID; + switch ( aBorderLine.LineStyle ) + { + case API_LINE_DASHED: + eStyleToken = XML_DASHED; + break; + case API_LINE_DOTTED: + eStyleToken = XML_DOTTED; + break; + case API_LINE_DOUBLE: + case API_LINE_THINTHICK_SMALLGAP: + case API_LINE_THINTHICK_MEDIUMGAP: + case API_LINE_THINTHICK_LARGEGAP: + case API_LINE_THICKTHIN_SMALLGAP: + case API_LINE_THICKTHIN_MEDIUMGAP: + case API_LINE_THICKTHIN_LARGEGAP: + eStyleToken = XML_DOUBLE; + break; + case API_LINE_EMBOSSED: + eStyleToken = XML_RIDGE; + break; + case API_LINE_ENGRAVED: + eStyleToken = XML_GROOVE; + break; + case API_LINE_OUTSET: + eStyleToken = XML_OUTSET; + break; + case API_LINE_INSET: + eStyleToken = XML_INSET; + break; + case API_LINE_SOLID: + default: + break; + } + aOut.append( GetXMLToken( eStyleToken ) ); + + aOut.append( sal_Unicode( ' ' ) ); + + rUnitConverter.convertColor( aOut, aBorderLine.Color ); + } + + rStrExpValue = aOut.makeStringAndClear(); + + return sal_True; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/bordrhdl.hxx b/xmloff/source/style/bordrhdl.hxx new file mode 100644 index 000000000000..eef72569c715 --- /dev/null +++ b/xmloff/source/style/bordrhdl.hxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PROPERTYHANDLER_BORDERTYPES_HXX +#define _XMLOFF_PROPERTYHANDLER_BORDERTYPES_HXX + +#include <xmloff/xmlprhdl.hxx> + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLBorderWidthHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLBorderWidthHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +class XMLBorderHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLBorderHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +#endif // _XMLOFF_PROPERTYHANDLER_CHARLOCALETYPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/breakhdl.cxx b/xmloff/source/style/breakhdl.cxx new file mode 100644 index 000000000000..dacbc0e81be6 --- /dev/null +++ b/xmloff/source/style/breakhdl.cxx @@ -0,0 +1,196 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <breakhdl.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/style/BreakType.hpp> +#include <com/sun/star/uno/Any.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::xmloff::token; + +SvXMLEnumMapEntry pXML_BreakTypes[] = +{ + { XML_AUTO, 0 }, + { XML_COLUMN, 1 }, + { XML_PAGE, 2 }, + { XML_EVEN_PAGE, 2 }, + { XML_ODD_PAGE, 2 }, + { XML_TOKEN_INVALID, 0} +}; + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLFmtBreakBeforePropHdl +// + +XMLFmtBreakBeforePropHdl::~XMLFmtBreakBeforePropHdl() +{ + // Nothing to do +} + +sal_Bool XMLFmtBreakBeforePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_uInt16 nEnum; + sal_Bool bRet = SvXMLUnitConverter::convertEnum( nEnum, rStrImpValue, pXML_BreakTypes ); + if( bRet ) + { + style::BreakType eBreak; + switch ( nEnum ) + { + case 0: + eBreak = style::BreakType_NONE; + break; + case 1: + eBreak = style::BreakType_COLUMN_BEFORE; + break; + default: + eBreak = style::BreakType_PAGE_BEFORE; + break; + } + rValue <<= eBreak; + } + + return bRet; +} + +sal_Bool XMLFmtBreakBeforePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + style::BreakType eBreak; + + if( !( rValue >>= eBreak ) ) + { + sal_Int32 nValue = 0; + if( !( rValue >>= nValue ) ) + return sal_False; + + eBreak = (style::BreakType) nValue; + } + + sal_uInt16 nEnum = 0; + switch( eBreak ) + { + case style::BreakType_COLUMN_BEFORE: + nEnum = 1; + break; + case style::BreakType_PAGE_BEFORE: + nEnum = 2; + break; + case style::BreakType_NONE: + nEnum = 0; + break; + default: + return sal_False; + } + + OUStringBuffer aOut; + /* sal_Bool bOk = */ SvXMLUnitConverter::convertEnum( aOut, nEnum, pXML_BreakTypes ); + rStrExpValue = aOut.makeStringAndClear(); + + return sal_True; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLFmtBreakBeforePropHdl +// + +XMLFmtBreakAfterPropHdl::~XMLFmtBreakAfterPropHdl() +{ + // Nothing to do +} + +sal_Bool XMLFmtBreakAfterPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_uInt16 nEnum; + sal_Bool bRet = SvXMLUnitConverter::convertEnum( nEnum, rStrImpValue, pXML_BreakTypes ); + if( bRet ) + { + style::BreakType eBreak; + switch ( nEnum ) + { + case 0: + eBreak = style::BreakType_NONE; + break; + case 1: + eBreak = style::BreakType_COLUMN_AFTER; + break; + default: + eBreak = style::BreakType_PAGE_AFTER; + break; + } + rValue <<= eBreak; + } + + return bRet; +} + +sal_Bool XMLFmtBreakAfterPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + style::BreakType eBreak; + + if( !( rValue >>= eBreak ) ) + { + sal_Int32 nValue = 0; + if( !( rValue >>= nValue ) ) + return sal_False; + + eBreak = (style::BreakType) nValue; + } + + sal_uInt16 nEnum = 0; + switch( eBreak ) + { + case style::BreakType_COLUMN_AFTER: + nEnum = 1; + break; + case style::BreakType_PAGE_AFTER: + nEnum = 2; + break; + case style::BreakType_NONE: + nEnum = 0; + break; + default: + return sal_False; + } + + OUStringBuffer aOut; + /* sal_Bool bOk = */ SvXMLUnitConverter::convertEnum( aOut, nEnum, pXML_BreakTypes ); + rStrExpValue = aOut.makeStringAndClear(); + + return sal_True; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/breakhdl.hxx b/xmloff/source/style/breakhdl.hxx new file mode 100644 index 000000000000..48c9ca12cc08 --- /dev/null +++ b/xmloff/source/style/breakhdl.hxx @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PROPERTYHANDLER_BREAKTYPES_HXX +#define _XMLOFF_PROPERTYHANDLER_BREAKTYPES_HXX + +#include <xmloff/xmlprhdl.hxx> + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLFmtBreakBeforePropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLFmtBreakBeforePropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLFmtBreakAfterPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLFmtBreakAfterPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +#endif // _XMLOFF_PROPERTYHANDLER_BREAKTYPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/cdouthdl.cxx b/xmloff/source/style/cdouthdl.cxx new file mode 100644 index 000000000000..cf1577adceee --- /dev/null +++ b/xmloff/source/style/cdouthdl.cxx @@ -0,0 +1,332 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <cdouthdl.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <rtl/ustrbuf.hxx> + +#include <com/sun/star/awt/FontStrikeout.hpp> +#include <com/sun/star/uno/Any.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::awt; +using namespace ::xmloff::token; + +SvXMLEnumMapEntry pXML_CrossedoutType_Enum[] = +{ + { XML_NONE, FontStrikeout::NONE }, + { XML_SINGLE, FontStrikeout::SINGLE }, + { XML_DOUBLE, FontStrikeout::DOUBLE }, + { XML_SINGLE, FontStrikeout::BOLD }, + { XML_SINGLE, FontStrikeout::SLASH }, + { XML_SINGLE, FontStrikeout::X }, + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLEnumMapEntry pXML_CrossedoutStyle_Enum[] = +{ + { XML_NONE, FontStrikeout::NONE }, + { XML_SOLID, FontStrikeout::SINGLE }, + { XML_SOLID, FontStrikeout::DOUBLE }, + { XML_SOLID, FontStrikeout::BOLD }, + { XML_SOLID, FontStrikeout::SLASH }, + { XML_SOLID, FontStrikeout::X }, + { XML_DOTTED, FontStrikeout::SINGLE }, + { XML_DASH, FontStrikeout::SINGLE }, + { XML_LONG_DASH, FontStrikeout::SINGLE }, + { XML_DOT_DASH, FontStrikeout::SINGLE }, + { XML_DOT_DOT_DASH, FontStrikeout::SINGLE }, + { XML_WAVE, FontStrikeout::SINGLE }, + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLEnumMapEntry pXML_CrossedoutWidth_Enum[] = +{ + { XML_AUTO, FontStrikeout::NONE }, + { XML_AUTO, FontStrikeout::SINGLE }, + { XML_AUTO, FontStrikeout::DOUBLE }, + { XML_BOLD, FontStrikeout::BOLD }, + { XML_AUTO, FontStrikeout::SLASH }, + { XML_AUTO, FontStrikeout::X }, + { XML_THIN, FontStrikeout::NONE }, + { XML_MEDIUM, FontStrikeout::NONE }, + { XML_THICK, FontStrikeout::NONE }, + { XML_TOKEN_INVALID, 0 } +}; + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLCrossedOutTypePropHdl +// + +XMLCrossedOutTypePropHdl::~XMLCrossedOutTypePropHdl() +{ + // nothing to do +} + +sal_Bool XMLCrossedOutTypePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_uInt16 eNewStrikeout; + sal_Bool bRet = SvXMLUnitConverter::convertEnum( + eNewStrikeout, rStrImpValue, pXML_CrossedoutType_Enum ); + if( bRet ) + { + // multi property: style and width might be set already. + // If the old value is NONE, the new is used unchanged. + sal_Int16 eStrikeout = sal_Int16(); + if( (rValue >>= eStrikeout) && FontStrikeout::NONE!=eStrikeout ) + { + switch( eNewStrikeout ) + { + case FontStrikeout::NONE: + case FontStrikeout::SINGLE: + // keep existing line style + eNewStrikeout = eStrikeout; + break; + case FontStrikeout::DOUBLE: + // A double line style has priority over a solid or a bold + // line style, + // but not about any other line style + switch( eStrikeout ) + { + case FontStrikeout::SINGLE: + case FontStrikeout::BOLD: + break; + default: + // If a double line style is not supported for the existing + // value, keep the new one + eNewStrikeout = eStrikeout; + break; + } + break; + default: + OSL_ENSURE( bRet, "unexpected line type value" ); + break; + } + if( eNewStrikeout != eStrikeout ) + rValue <<= (sal_Int16)eNewStrikeout; + } + else + { + rValue <<= (sal_Int16)eNewStrikeout; + } + } + + return bRet; +} + +sal_Bool XMLCrossedOutTypePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + sal_Int16 nValue = sal_Int16(); + OUStringBuffer aOut; + + if( (rValue >>= nValue) && FontStrikeout::DOUBLE==nValue ) + { + bRet = SvXMLUnitConverter::convertEnum( + aOut, (sal_uInt16)nValue, pXML_CrossedoutType_Enum ); + if( bRet ) + rStrExpValue = aOut.makeStringAndClear(); + } + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLCrossedOutStylePropHdl +// + +XMLCrossedOutStylePropHdl::~XMLCrossedOutStylePropHdl() +{ + // nothing to do +} + +sal_Bool XMLCrossedOutStylePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_uInt16 eNewStrikeout; + sal_Bool bRet = SvXMLUnitConverter::convertEnum( + eNewStrikeout, rStrImpValue, pXML_CrossedoutStyle_Enum ); + if( bRet ) + { + // multi property: style and width might be set already. + // If the old value is NONE, the new is used unchanged. + sal_Int16 eStrikeout = sal_Int16(); + if( (rValue >>= eStrikeout) && FontStrikeout::NONE!=eStrikeout ) + { + // one NONE a SINGLE are possible new values. For both, the + // existing value is kept. + } + else + { + rValue <<= (sal_Int16)eNewStrikeout; + } + } + + return bRet; +} + +sal_Bool XMLCrossedOutStylePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + sal_Int16 nValue = sal_Int16(); + OUStringBuffer aOut; + + if( rValue >>= nValue ) + { + bRet = SvXMLUnitConverter::convertEnum( + aOut, (sal_uInt16)nValue, pXML_CrossedoutStyle_Enum ); + if( bRet ) + rStrExpValue = aOut.makeStringAndClear(); + } + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLCrossedOutWidthPropHdl +// + +XMLCrossedOutWidthPropHdl::~XMLCrossedOutWidthPropHdl() +{ + // nothing to do +} + +sal_Bool XMLCrossedOutWidthPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_uInt16 eNewStrikeout; + sal_Bool bRet = SvXMLUnitConverter::convertEnum( + eNewStrikeout, rStrImpValue, pXML_CrossedoutWidth_Enum ); + if( bRet ) + { + // multi property: style and width might be set already. + // If the old value is NONE, the new is used unchanged. + sal_Int16 eStrikeout = sal_Int16(); + if( (rValue >>= eStrikeout) && FontStrikeout::NONE!=eStrikeout ) + { + switch( eNewStrikeout ) + { + case FontStrikeout::NONE: + // keep existing line style + eNewStrikeout = eStrikeout; + break; + case FontStrikeout::BOLD: + switch( eStrikeout ) + { + case FontStrikeout::SINGLE: + break; + default: + // If a double line style is not supported for the existing + // value, keep the new one + eNewStrikeout = eStrikeout; + break; + } + default: + OSL_ENSURE( bRet, "unexpected line type value" ); + break; + } + if( eNewStrikeout != eStrikeout ) + rValue <<= (sal_Int16)eNewStrikeout; + } + else + { + rValue <<= (sal_Int16)eNewStrikeout; + } + } + + return bRet; +} + +sal_Bool XMLCrossedOutWidthPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + sal_Int16 nValue = sal_Int16(); + OUStringBuffer aOut; + + if( (rValue >>= nValue) && (FontStrikeout::BOLD == nValue) ) + { + bRet = SvXMLUnitConverter::convertEnum( + aOut, (sal_uInt16)nValue, pXML_CrossedoutWidth_Enum ); + if( bRet ) + rStrExpValue = aOut.makeStringAndClear(); + } + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLCrossedOutTextPropHdl +// + +XMLCrossedOutTextPropHdl::~XMLCrossedOutTextPropHdl() +{ + // nothing to do +} + +sal_Bool XMLCrossedOutTextPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + if( rStrImpValue.getLength() ) + { + sal_Int16 eStrikeout = ('/' == rStrImpValue[0] + ? FontStrikeout::SLASH + : FontStrikeout::X); + rValue <<= (sal_Int16)eStrikeout; + bRet = sal_True; + } + + return bRet; +} + +sal_Bool XMLCrossedOutTextPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + sal_Int16 nValue = sal_Int16(); + + if( (rValue >>= nValue) && + (FontStrikeout::SLASH == nValue || FontStrikeout::X == nValue) ) + { + rStrExpValue = OUString::valueOf( + static_cast< sal_Unicode>( FontStrikeout::SLASH == nValue ? '/' + : 'X' ) ); + bRet = sal_True; + } + + return bRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/cdouthdl.hxx b/xmloff/source/style/cdouthdl.hxx new file mode 100644 index 000000000000..46779e10c70c --- /dev/null +++ b/xmloff/source/style/cdouthdl.hxx @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PROPERTYHANDLER_CROSSEDOUTTYPES_HXX +#define _XMLOFF_PROPERTYHANDLER_CROSSEDOUTTYPES_HXX + +#include <xmloff/xmlprhdl.hxx> + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLCrossedOutTypePropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLCrossedOutTypePropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +class XMLCrossedOutStylePropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLCrossedOutStylePropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +class XMLCrossedOutWidthPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLCrossedOutWidthPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +class XMLCrossedOutTextPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLCrossedOutTextPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +#endif // _XMLOFF_PROPERTYHANDLER_CROSSEDOUTTYPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/chrhghdl.cxx b/xmloff/source/style/chrhghdl.cxx new file mode 100644 index 000000000000..d805d9a1274b --- /dev/null +++ b/xmloff/source/style/chrhghdl.cxx @@ -0,0 +1,169 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include <chrhghdl.hxx> +#include <xmloff/xmluconv.hxx> +#include "xmlehelp.hxx" +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/Any.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; + +// this is a copy of defines in svx/inc/escpitem.hxx +#define DFLT_ESC_PROP 58 +#define DFLT_ESC_AUTO_SUPER 101 +#define DFLT_ESC_AUTO_SUB -101 + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLEscapementPropHdl +// + +XMLCharHeightHdl::~XMLCharHeightHdl() +{ + // nothing to do +} + +sal_Bool XMLCharHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + double fSize; + + if( rStrImpValue.indexOf( sal_Unicode('%') ) == -1 ) + { + MapUnit eSrcUnit = SvXMLExportHelper::GetUnitFromString( rStrImpValue, MAP_POINT ); + if( SvXMLUnitConverter::convertDouble( fSize, rStrImpValue, eSrcUnit, MAP_POINT )) + { + rValue <<= (float)fSize; + return sal_True; + } + } + + return sal_False; +} + +sal_Bool XMLCharHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + OUStringBuffer aOut; + + float fSize = 0; + if( rValue >>= fSize ) + { + SvXMLUnitConverter::convertDouble( aOut, (double)fSize, sal_True, MAP_POINT, MAP_POINT ); + aOut.append( sal_Unicode('p')); + aOut.append( sal_Unicode('t')); + } + + rStrExpValue = aOut.makeStringAndClear(); + return rStrExpValue.getLength() != 0; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLEscapementHeightPropHdl +// + +XMLCharHeightPropHdl::~XMLCharHeightPropHdl() +{ + // nothing to do +} + +sal_Bool XMLCharHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Int32 nPrc = 100; + + if( rStrImpValue.indexOf( sal_Unicode('%') ) != -1 ) + { + if( SvXMLUnitConverter::convertPercent( nPrc, rStrImpValue ) ) + { + rValue <<= (sal_Int16)nPrc; + return sal_True; + } + } + + return sal_False; +} + +sal_Bool XMLCharHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + OUStringBuffer aOut( rStrExpValue ); + + sal_Int16 nValue = sal_Int16(); + if( rValue >>= nValue ) + { + SvXMLUnitConverter::convertPercent( aOut, nValue ); + } + + rStrExpValue = aOut.makeStringAndClear(); + return rStrExpValue.getLength() != 0; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLEscapementPropHdl +// + +XMLCharHeightDiffHdl::~XMLCharHeightDiffHdl() +{ + // nothing to do +} + +sal_Bool XMLCharHeightDiffHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Int32 nRel = 0; + + if( SvXMLUnitConverter::convertMeasure( nRel, rStrImpValue, MAP_POINT ) ) + { + rValue <<= (float)nRel; + return sal_True; + } + + return sal_False; +} + +sal_Bool XMLCharHeightDiffHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + OUStringBuffer aOut; + + float nRel = 0; + if( (rValue >>= nRel) && (nRel != 0) ) + { + SvXMLUnitConverter::convertMeasure( aOut, (sal_Int32)nRel, MAP_POINT, MAP_POINT ); + rStrExpValue = aOut.makeStringAndClear(); + } + + return rStrExpValue.getLength() != 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/chrhghdl.hxx b/xmloff/source/style/chrhghdl.hxx new file mode 100644 index 000000000000..9d39294eb6c7 --- /dev/null +++ b/xmloff/source/style/chrhghdl.hxx @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PROPERTYHANDLER_CHARHEIGHTTYPES_HXX +#define _XMLOFF_PROPERTYHANDLER_CHARHEIGHTTYPES_HXX + +#include <xmloff/xmlprhdl.hxx> + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLCharHeightHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLCharHeightHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +class XMLCharHeightPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLCharHeightPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +class XMLCharHeightDiffHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLCharHeightDiffHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +#endif // _XMLOFF_PROPERTYHANDLER_CHARHEIGHTTYPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/chrlohdl.cxx b/xmloff/source/style/chrlohdl.cxx new file mode 100644 index 000000000000..a7fedf6456a4 --- /dev/null +++ b/xmloff/source/style/chrlohdl.cxx @@ -0,0 +1,147 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include <chrlohdl.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/lang/Locale.hpp> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::xmloff::token; + +// this is a copy of defines in svx/inc/escpitem.hxx +#define DFLT_ESC_PROP 58 +#define DFLT_ESC_AUTO_SUPER 101 +#define DFLT_ESC_AUTO_SUB -101 + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLEscapementPropHdl +// + +XMLCharLanguageHdl::~XMLCharLanguageHdl() +{ + // nothing to do +} + +bool XMLCharLanguageHdl::equals( const ::com::sun::star::uno::Any& r1, const ::com::sun::star::uno::Any& r2 ) const +{ + sal_Bool bRet = sal_False; + lang::Locale aLocale1, aLocale2; + + if( ( r1 >>= aLocale1 ) && ( r2 >>= aLocale2 ) ) + bRet = ( aLocale1.Language == aLocale2.Language ); + + return bRet; +} + +sal_Bool XMLCharLanguageHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + lang::Locale aLocale; + + rValue >>= aLocale; + + if( !IsXMLToken(rStrImpValue, XML_NONE) ) + aLocale.Language = rStrImpValue; + + rValue <<= aLocale; + return sal_True; +} + +sal_Bool XMLCharLanguageHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + lang::Locale aLocale; + if(!(rValue >>= aLocale)) + return sal_False; + + rStrExpValue = aLocale.Language; + + if( !rStrExpValue.getLength() ) + rStrExpValue = GetXMLToken( XML_NONE ); + + return sal_True; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLEscapementHeightPropHdl +// + +XMLCharCountryHdl::~XMLCharCountryHdl() +{ + // nothing to do +} + +bool XMLCharCountryHdl::equals( const ::com::sun::star::uno::Any& r1, const ::com::sun::star::uno::Any& r2 ) const +{ + sal_Bool bRet = sal_False; + lang::Locale aLocale1, aLocale2; + + if( ( r1 >>= aLocale1 ) && ( r2 >>= aLocale2 ) ) + bRet = ( aLocale1.Country == aLocale2.Country ); + + return bRet; +} + +sal_Bool XMLCharCountryHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + lang::Locale aLocale; + + rValue >>= aLocale; + + if( !IsXMLToken( rStrImpValue, XML_NONE ) ) + aLocale.Country = rStrImpValue; + + rValue <<= aLocale; + return sal_True; +} + +sal_Bool XMLCharCountryHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + lang::Locale aLocale; + if(!(rValue >>= aLocale)) + return sal_False; + + rStrExpValue = aLocale.Country; + + if( !rStrExpValue.getLength() ) + rStrExpValue = GetXMLToken( XML_NONE ); + + return sal_True; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/chrlohdl.hxx b/xmloff/source/style/chrlohdl.hxx new file mode 100644 index 000000000000..1b1f46b3e08f --- /dev/null +++ b/xmloff/source/style/chrlohdl.hxx @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PROPERTYHANDLER_CHARLOCALETYPES_HXX +#define _XMLOFF_PROPERTYHANDLER_CHARLOCALETYPES_HXX + +#include <xmloff/xmlprhdl.hxx> + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLCharLanguageHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLCharLanguageHdl(); + + virtual bool equals( const ::com::sun::star::uno::Any& r1, const ::com::sun::star::uno::Any& r2 ) const; + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +class XMLCharCountryHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLCharCountryHdl(); + + virtual bool equals( const ::com::sun::star::uno::Any& r1, const ::com::sun::star::uno::Any& r2 ) const; + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +#endif // _XMLOFF_PROPERTYHANDLER_CHARLOCALETYPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/csmaphdl.cxx b/xmloff/source/style/csmaphdl.cxx new file mode 100644 index 000000000000..6bbd31057319 --- /dev/null +++ b/xmloff/source/style/csmaphdl.cxx @@ -0,0 +1,141 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <csmaphdl.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/style/CaseMap.hpp> +#include <com/sun/star/uno/Any.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::xmloff::token; + +static SvXMLEnumMapEntry pXML_Casemap_Enum[] = +{ + { XML_NONE, style::CaseMap::NONE }, + { XML_CASEMAP_LOWERCASE, style::CaseMap::LOWERCASE }, + { XML_CASEMAP_UPPERCASE, style::CaseMap::UPPERCASE }, + { XML_CASEMAP_CAPITALIZE, style::CaseMap::TITLE }, + { XML_TOKEN_INVALID, 0 } +}; + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLPosturePropHdl +// + +XMLCaseMapPropHdl::~XMLCaseMapPropHdl() +{ + // nothing to do +} + +sal_Bool XMLCaseMapPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_uInt16 nVal; + sal_Bool bRet = SvXMLUnitConverter::convertEnum( + nVal, rStrImpValue, pXML_Casemap_Enum ); + if( ( bRet ) ) + rValue <<= nVal; + + return bRet; +} + +sal_Bool XMLCaseMapPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + sal_uInt16 nValue = sal_uInt16(); + OUStringBuffer aOut; + + if( rValue >>= nValue ) + { + bRet = SvXMLUnitConverter::convertEnum( + aOut, nValue, pXML_Casemap_Enum ); + if( bRet ) + rStrExpValue = aOut.makeStringAndClear(); + } + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLCaseMapVariantHdl +// + +XMLCaseMapVariantHdl::~XMLCaseMapVariantHdl() +{ + // nothing to do +} + +sal_Bool XMLCaseMapVariantHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + if( IsXMLToken( rStrImpValue, XML_CASEMAP_SMALL_CAPS ) ) + { + rValue <<= (sal_Int16)style::CaseMap::SMALLCAPS; + bRet = sal_True; + } + else if( IsXMLToken( rStrImpValue, XML_CASEMAP_NORMAL ) ) + { + rValue <<= (sal_Int16)style::CaseMap::NONE; + bRet = sal_True; + } + + return bRet; +} + +sal_Bool XMLCaseMapVariantHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_uInt16 nValue = sal_uInt16(); + OUStringBuffer aOut; + + if( rValue >>= nValue ) + { + switch( nValue ) + { + case style::CaseMap::NONE: + aOut.append( GetXMLToken(XML_CASEMAP_NORMAL) ); + break; + case style::CaseMap::SMALLCAPS: + aOut.append( GetXMLToken(XML_CASEMAP_SMALL_CAPS) ); + break; + } + } + + rStrExpValue = aOut.makeStringAndClear(); + return rStrExpValue.getLength() != 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/csmaphdl.hxx b/xmloff/source/style/csmaphdl.hxx new file mode 100644 index 000000000000..d437d1a7e559 --- /dev/null +++ b/xmloff/source/style/csmaphdl.hxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PROPERTYHANDLER_CASEMAPTYPES_HXX +#define _XMLOFF_PROPERTYHANDLER_CASEMAPTYPES_HXX + +#include <xmloff/xmlprhdl.hxx> + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLCaseMapPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLCaseMapPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +class XMLCaseMapVariantHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLCaseMapVariantHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +#endif // _XMLOFF_PROPERTYHANDLER_CASEMAPTYPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/durationhdl.cxx b/xmloff/source/style/durationhdl.cxx new file mode 100644 index 000000000000..d25dcb6f911d --- /dev/null +++ b/xmloff/source/style/durationhdl.cxx @@ -0,0 +1,84 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "durationhdl.hxx" +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/util/DateTime.hpp> +#include <rtl/ustrbuf.hxx> +#include <xmloff/xmluconv.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::util; + +// --------------------------------------------------------------------------- + + +sal_Bool XMLDurationMS16PropHdl_Impl::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + DateTime aTime; + if( !SvXMLUnitConverter::convertTime( aTime, rStrImpValue ) ) + return false; + + const sal_Int16 nMS = ( ( aTime.Hours * 60 + aTime.Minutes ) * 60 + aTime.Seconds ) * 100 + aTime.HundredthSeconds; + rValue <<= nMS; + + return sal_True; +} + +sal_Bool XMLDurationMS16PropHdl_Impl::exportXML( + OUString& rStrExpValue, + const Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Int16 nMS = sal_Int16(); + + if(rValue >>= nMS) + { + OUStringBuffer aOut; + DateTime aTime( nMS, 0, 0, 0, 0, 0, 0 ); + SvXMLUnitConverter::convertTime( aOut, aTime ); + rStrExpValue = aOut.makeStringAndClear(); + return sal_True; + } + + return sal_False; +} + +XMLDurationMS16PropHdl_Impl::~XMLDurationMS16PropHdl_Impl() +{ +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/durationhdl.hxx b/xmloff/source/style/durationhdl.hxx new file mode 100644 index 000000000000..356c5ddf5df1 --- /dev/null +++ b/xmloff/source/style/durationhdl.hxx @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PROPERTYHANDLER_DURATIONS_HXX +#define _XMLOFF_PROPERTYHANDLER_DURATIONS_HXX + +#include <xmloff/xmlprhdl.hxx> + +/** + PropertyHandler for a sal_int16 duration in ms: +*/ +class XMLDurationMS16PropHdl_Impl : public XMLPropertyHandler +{ +public: + virtual ~XMLDurationMS16PropHdl_Impl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +#endif // _XMLOFF_PROPERTYHANDLER_FMTSPLITTYPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/escphdl.cxx b/xmloff/source/style/escphdl.cxx new file mode 100644 index 000000000000..f0bbd43f793b --- /dev/null +++ b/xmloff/source/style/escphdl.cxx @@ -0,0 +1,175 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include <escphdl.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/Any.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::xmloff::token; + +// this is a copy of defines in svx/inc/escpitem.hxx +#define DFLT_ESC_PROP 58 +#define DFLT_ESC_AUTO_SUPER 101 +#define DFLT_ESC_AUTO_SUB -101 + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLEscapementPropHdl +// + +XMLEscapementPropHdl::~XMLEscapementPropHdl() +{ + // nothing to do +} + +sal_Bool XMLEscapementPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Int16 nVal; + + SvXMLTokenEnumerator aTokens( rStrImpValue ); + + OUString aToken; + if( ! aTokens.getNextToken( aToken ) ) + return sal_False; + + if( IsXMLToken( aToken, XML_ESCAPEMENT_SUB ) ) + { + nVal = DFLT_ESC_AUTO_SUB; + } + else if( IsXMLToken( aToken, XML_ESCAPEMENT_SUPER ) ) + { + nVal = DFLT_ESC_AUTO_SUPER; + } + else + { + sal_Int32 nNewEsc; + if( !SvXMLUnitConverter::convertPercent( nNewEsc, aToken ) ) + return sal_False; + + nVal = (sal_Int16) nNewEsc; + } + + rValue <<= nVal; + return sal_True; +} + +sal_Bool XMLEscapementPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Int32 nValue = 0; + OUStringBuffer aOut; + + if( rValue >>= nValue ) + { + if( nValue == DFLT_ESC_AUTO_SUPER ) + { + aOut.append( GetXMLToken(XML_ESCAPEMENT_SUPER) ); + } + else if( nValue == DFLT_ESC_AUTO_SUB ) + { + aOut.append( GetXMLToken(XML_ESCAPEMENT_SUB) ); + } + else + { + SvXMLUnitConverter::convertPercent( aOut, nValue ); + } + } + + rStrExpValue = aOut.makeStringAndClear(); + return sal_True; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLEscapementHeightPropHdl +// + +XMLEscapementHeightPropHdl::~XMLEscapementHeightPropHdl() +{ + // nothing to do +} + +sal_Bool XMLEscapementHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + if( IsXMLToken( rStrImpValue, XML_CASEMAP_SMALL_CAPS ) ) + return sal_False; + + SvXMLTokenEnumerator aTokens( rStrImpValue ); + + OUString aToken; + if( ! aTokens.getNextToken( aToken ) ) + return sal_False; + + sal_Int8 nProp; + if( aTokens.getNextToken( aToken ) ) + { + sal_Int32 nNewProp; + if( !SvXMLUnitConverter::convertPercent( nNewProp, aToken ) ) + return sal_False; + nProp = (sal_Int8)nNewProp; + } + else + { + sal_Int32 nEscapementPosition=0; + if( SvXMLUnitConverter::convertPercent( nEscapementPosition, aToken ) && nEscapementPosition==0 ) + nProp = 100; //if escapement position is zero and no escapement height is given the default height should be 100percent and not something smaller (#i91800#) + else + nProp = (sal_Int8) DFLT_ESC_PROP; + } + + rValue <<= nProp; + return sal_True; +} + +sal_Bool XMLEscapementHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + OUStringBuffer aOut( rStrExpValue ); + + sal_Int32 nValue = 0; + if( rValue >>= nValue ) + { + if( rStrExpValue.getLength() ) + aOut.append( sal_Unicode(' ')); + + SvXMLUnitConverter::convertPercent( aOut, nValue ); + } + + rStrExpValue = aOut.makeStringAndClear(); + return rStrExpValue.getLength() != 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/escphdl.hxx b/xmloff/source/style/escphdl.hxx new file mode 100644 index 000000000000..e3021e3b26dc --- /dev/null +++ b/xmloff/source/style/escphdl.hxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PROPERTYHANDLER_ESCAPETYPES_HXX +#define _XMLOFF_PROPERTYHANDLER_ESCAPETYPES_HXX + +#include <xmloff/xmlprhdl.hxx> + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLEscapementPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLEscapementPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +class XMLEscapementHeightPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLEscapementHeightPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +#endif // _XMLOFF_PROPERTYHANDLER_ESCAPETYPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/fonthdl.cxx b/xmloff/source/style/fonthdl.cxx new file mode 100644 index 000000000000..03f0ccfb69ee --- /dev/null +++ b/xmloff/source/style/fonthdl.cxx @@ -0,0 +1,322 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + +#include <fonthdl.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <tools/fontenum.hxx> + +#include <tools/string.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::xmloff::token; + +const SvXMLEnumMapEntry* lcl_getFontFamilyGenericMapping() +{ + static SvXMLEnumMapEntry const aFontFamilyGenericMapping[] = + { + { XML_DECORATIVE, FAMILY_DECORATIVE }, + + { XML_MODERN, FAMILY_MODERN }, + { XML_ROMAN, FAMILY_ROMAN }, + { XML_SCRIPT, FAMILY_SCRIPT }, + { XML_SWISS, FAMILY_SWISS }, + { XML_SYSTEM, FAMILY_SYSTEM }, + { XML_TOKEN_INVALID, 0 } + }; + return aFontFamilyGenericMapping; +} + +static SvXMLEnumMapEntry const aFontPitchMapping[] = +{ + { XML_FIXED, PITCH_FIXED }, + { XML_VARIABLE, PITCH_VARIABLE }, + { XML_TOKEN_INVALID, 0 } +}; +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLFontFamilyNamePropHdl +// + +XMLFontFamilyNamePropHdl::~XMLFontFamilyNamePropHdl() +{ + // Nothing to do +} + +sal_Bool XMLFontFamilyNamePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + String sValue; + sal_Int32 nPos = 0; + + do + { + sal_Int32 nFirst = nPos; + nPos = SvXMLUnitConverter::indexOfComma( rStrImpValue, nPos ); + sal_Int32 nLast = (-1 == nPos ? rStrImpValue.getLength() : nPos); + if( nLast > 0 ) + nLast--; + + // skip trailing blanks + while( sal_Unicode(' ') == rStrImpValue[nLast] && nLast > nFirst ) + nLast--; + + // skip leading blanks + while( sal_Unicode(' ') == rStrImpValue[nFirst] && nFirst <= nLast ) + nFirst++; + + // remove quotes + sal_Unicode c = rStrImpValue[nFirst]; + if( nFirst < nLast && (sal_Unicode('\'') == c || sal_Unicode('\"') == c) && rStrImpValue[nLast] == c ) + { + nFirst++; + nLast--; + } + + if( nFirst <= nLast ) + { + if( sValue.Len() != 0 ) + sValue += sal_Unicode(';'); + + OUString sTemp = rStrImpValue.copy( nFirst, nLast-nFirst+1 ); + sValue += sTemp.getStr(); + } + + if( -1 != nPos ) + nPos++; + } + while( -1 != nPos ); + + if( sValue.Len() ) + { + rValue <<= OUString(sValue.GetBuffer()); + bRet = sal_True; + } + + return bRet; +} + +sal_Bool XMLFontFamilyNamePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + OUString aStrFamilyName; + + if( rValue >>= aStrFamilyName ) + { + OUStringBuffer sValue( aStrFamilyName.getLength() + 2L ); + sal_Int32 nPos = 0; + do + { + sal_Int32 nFirst = nPos; + nPos = aStrFamilyName.indexOf( sal_Unicode(';'), nPos ); + sal_Int32 nLast = (-1 == nPos ? aStrFamilyName.getLength() : nPos); + + // Set position to the character behind the ';', so we won't + // forget this. + if( -1L != nPos ) + nPos++; + + // If the property value was empty, we stop now. + // If there is a ';' at the first position, the empty name + // at the start will be removed. + if( 0L == nLast ) + continue; + + // nFirst and nLast now denote the first and last character of + // one font name. + nLast--; + + // skip trailing blanks + while( sal_Unicode(' ') == aStrFamilyName[nLast] && nLast > nFirst ) + nLast--; + + // skip leading blanks + while( sal_Unicode(' ') == aStrFamilyName[nFirst] && nFirst <= nLast ) + nFirst++; + + if( nFirst <= nLast ) + { + if( sValue.getLength() != 0L ) + { + sValue.append( sal_Unicode( ',' ) ); + sValue.append( sal_Unicode( ' ' )); + } + sal_Int32 nLen = nLast-nFirst+1; + OUString sFamily( aStrFamilyName.copy( nFirst, nLen ) ); + sal_Bool bQuote = sal_False; + for( sal_Int32 i=0; i < nLen; i++ ) + { + sal_Unicode c = sFamily[i]; + if( sal_Unicode(' ') == c || sal_Unicode(',') == c ) + { + bQuote = sal_True; + break; + } + } + if( bQuote ) + sValue.append( sal_Unicode('\'') ); + sValue.append( sFamily ); + if( bQuote ) + sValue.append( sal_Unicode('\'') ); + } + } + while( -1L != nPos ); + + rStrExpValue = sValue.makeStringAndClear(); + + bRet = sal_True; + } + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLFontFamilyPropHdl +// + +XMLFontFamilyPropHdl::~XMLFontFamilyPropHdl() +{ + // Nothing to do +} + +sal_Bool XMLFontFamilyPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_uInt16 eNewFamily; + sal_Bool bRet = SvXMLUnitConverter::convertEnum( eNewFamily, rStrImpValue, lcl_getFontFamilyGenericMapping() ); + if( bRet ) + rValue <<= (sal_Int16)eNewFamily; + + return bRet; +} + +sal_Bool XMLFontFamilyPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + OUStringBuffer aOut; + + sal_Int16 nFamily = sal_Int16(); + if( rValue >>= nFamily ) + { + FontFamily eFamily = (FontFamily)nFamily; + if( eFamily != FAMILY_DONTKNOW ) + bRet = SvXMLUnitConverter::convertEnum( aOut, eFamily, lcl_getFontFamilyGenericMapping() ); + } + + rStrExpValue = aOut.makeStringAndClear(); + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLFontEncodingPropHdl +// + +XMLFontEncodingPropHdl::~XMLFontEncodingPropHdl() +{ + // Nothing to do +} + +sal_Bool XMLFontEncodingPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_True; + + if( IsXMLToken( rStrImpValue, XML_X_SYMBOL ) ) + rValue <<= (sal_Int16) RTL_TEXTENCODING_SYMBOL; + + return bRet; +} + +sal_Bool XMLFontEncodingPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + OUStringBuffer aOut; + sal_Int16 nSet = sal_Int16(); + + if( rValue >>= nSet ) + { + if( (rtl_TextEncoding)nSet == RTL_TEXTENCODING_SYMBOL ) + { + aOut.append( GetXMLToken(XML_X_SYMBOL) ); + rStrExpValue = aOut.makeStringAndClear(); + bRet = sal_True; + } + } + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLFontPitchPropHdl +// + +XMLFontPitchPropHdl::~XMLFontPitchPropHdl() +{ + // Nothing to do +} + +sal_Bool XMLFontPitchPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_uInt16 eNewPitch; + sal_Bool bRet = SvXMLUnitConverter::convertEnum( eNewPitch, rStrImpValue, aFontPitchMapping ); + if( bRet ) + rValue <<= (sal_Int16)eNewPitch; + + return bRet; +} + +sal_Bool XMLFontPitchPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + sal_Int16 nPitch = sal_Int16(); + OUStringBuffer aOut; + + FontPitch ePitch = PITCH_DONTKNOW; + if( rValue >>= nPitch ) + ePitch = (FontPitch)nPitch; + + if( PITCH_DONTKNOW != ePitch ) + { + bRet = SvXMLUnitConverter::convertEnum( aOut, ePitch, aFontPitchMapping, XML_FIXED ); + rStrExpValue = aOut.makeStringAndClear(); + } + + return bRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/fonthdl.hxx b/xmloff/source/style/fonthdl.hxx new file mode 100644 index 000000000000..3efb801ae3ac --- /dev/null +++ b/xmloff/source/style/fonthdl.hxx @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef XMLOFF_PROPERTYHANDLER_FONTTYPES_HXX +#define XMLOFF_PROPERTYHANDLER_FONTTYPES_HXX + +#include <xmloff/xmlprhdl.hxx> + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLFontFamilyNamePropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLFontFamilyNamePropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLFontFamilyPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLFontFamilyPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLFontEncodingPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLFontEncodingPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLFontPitchPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLFontPitchPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + + +#endif // XMLOFF_PROPERTYHANDLER_FONTTYPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/impastp1.cxx b/xmloff/source/style/impastp1.cxx new file mode 100644 index 000000000000..8cfdcb3d994a --- /dev/null +++ b/xmloff/source/style/impastp1.cxx @@ -0,0 +1,135 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include "impastpl.hxx" + +using ::rtl::OUString; + +//############################################################################# +// +// Class XMLFamilyData_Impl +// + +/////////////////////////////////////////////////////////////////////////////// +// +// ctor/dtor class XMLFamilyData_Impl +// + +XMLFamilyData_Impl::XMLFamilyData_Impl( + sal_Int32 nFamily, + const ::rtl::OUString& rStrName, + const UniReference < SvXMLExportPropertyMapper > &rMapper, + const OUString& rStrPrefix, + sal_Bool bAsFam ) + : pCache( 0 ), mnFamily( nFamily ), maStrFamilyName( rStrName), mxMapper( rMapper ), + mnCount( 0 ), mnName( 0 ), maStrPrefix( rStrPrefix ), bAsFamily( bAsFam ) + +{ + mpParentList = new SvXMLAutoStylePoolParentsP_Impl( 5, 5 ); + mpNameList = new SvXMLAutoStylePoolNamesP_Impl( 5, 5 ); +} + +XMLFamilyData_Impl::~XMLFamilyData_Impl() +{ + if( mpParentList ) delete mpParentList; + if( mpNameList ) delete mpNameList; + DBG_ASSERT( !pCache || !pCache->size(), "auto style pool cache is not empty!" ); + if( pCache ) + { + for ( size_t i = 0, n = pCache->size(); i < n; ++i ) + delete (*pCache)[ i ]; + pCache->clear(); + delete pCache; + } +} + +void XMLFamilyData_Impl::ClearEntries() +{ + if( mpParentList ) + delete mpParentList; + mpParentList = new SvXMLAutoStylePoolParentsP_Impl( 5, 5 ); + DBG_ASSERT( !pCache || !pCache->size(), "auto style pool cache is not empty!" ); + if( pCache ) + { + for ( size_t i = 0, n = pCache->size(); i < n; ++i ) + delete (*pCache)[ i ]; + pCache->clear(); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// +// friendfunction of class XMLFamilyData_Impl for sorting listelements +// + +int XMLFamilyDataSort_Impl( const XMLFamilyData_Impl& r1, const XMLFamilyData_Impl& r2 ) +{ + int nRet = 0; + + if( r1.mnFamily != r2.mnFamily ) + nRet = ( r1.mnFamily > r2.mnFamily ? 1 : -1 ); + + return nRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// Implementation of sorted list of XMLFamilyData_Impl - elements +// + +IMPL_CONTAINER_SORT( XMLFamilyDataList_Impl, XMLFamilyData_Impl, XMLFamilyDataSort_Impl ) + +//############################################################################# +// +// Sorted list of OUString - elements +// + +/////////////////////////////////////////////////////////////////////////////// +// +// Sort-function for OUString-list +// + +int SvXMLAutoStylePoolNamesPCmp_Impl( const OUString& r1, + const OUString& r2 ) +{ + return (int)r1.compareTo( r2 ); +} + +/////////////////////////////////////////////////////////////////////////////// +// +// Implementation of sorted OUString-list +// + +IMPL_CONTAINER_SORT( SvXMLAutoStylePoolNamesP_Impl, + OUString, + SvXMLAutoStylePoolNamesPCmp_Impl ) + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/impastp2.cxx b/xmloff/source/style/impastp2.cxx new file mode 100644 index 000000000000..d152fe0c70bb --- /dev/null +++ b/xmloff/source/style/impastp2.cxx @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <rtl/ustrbuf.hxx> +#include "impastpl.hxx" + +using namespace std; + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +//############################################################################# +// +// Class SvXMLAutoStylePoolProperties_Impl +// + +/////////////////////////////////////////////////////////////////////////////// +// +// ctor class SvXMLAutoStylePoolProperties_Impl +// + +SvXMLAutoStylePoolPropertiesP_Impl::SvXMLAutoStylePoolPropertiesP_Impl( XMLFamilyData_Impl* pFamilyData, const vector< XMLPropertyState >& rProperties ) +: maProperties( rProperties ), + mnPos ( pFamilyData->mnCount ) +{ + // create a name that hasn't been used before. The created name has not + // to be added to the array, because it will never tried again + OUStringBuffer sBuffer( 7 ); + do + { + pFamilyData->mnName++; + sBuffer.append( pFamilyData->maStrPrefix ); + sBuffer.append( OUString::valueOf( (sal_Int32)pFamilyData->mnName ) ); + msName = sBuffer.makeStringAndClear(); + } + while( pFamilyData->mpNameList->Seek_Entry( &msName, 0 ) ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/impastp3.cxx b/xmloff/source/style/impastp3.cxx new file mode 100644 index 000000000000..0c51db505b17 --- /dev/null +++ b/xmloff/source/style/impastp3.cxx @@ -0,0 +1,194 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "impastpl.hxx" +#include <xmloff/xmlprmap.hxx> + +using namespace std; + +using ::rtl::OUString; + +//############################################################################# +// +// Class SvXMLAutoStylePoolParent_Impl +// + +/////////////////////////////////////////////////////////////////////////////// +// +// dtor class SvXMLAutoStylePoolParent_Impl +// + +SvXMLAutoStylePoolParentP_Impl::~SvXMLAutoStylePoolParentP_Impl() +{ + for( size_t i = maPropertiesList.size(); i > 0; ) + delete maPropertiesList[ --i ]; + maPropertiesList.clear(); +} + +/////////////////////////////////////////////////////////////////////////////// +// +// Adds a array of XMLPropertyState ( vector< XMLPropertyState > ) to list +// if not added, yet. +// + +sal_Bool SvXMLAutoStylePoolParentP_Impl::Add( XMLFamilyData_Impl* pFamilyData, const vector< XMLPropertyState >& rProperties, OUString& rName, bool bDontSeek ) +{ + sal_Bool bAdded = sal_False; + SvXMLAutoStylePoolPropertiesP_Impl *pProperties = 0; + size_t i = 0; + sal_Int32 nProperties = rProperties.size(); + size_t nCount = maPropertiesList.size(); + + for( i = 0; i < nCount; i++ ) + { + SvXMLAutoStylePoolPropertiesP_Impl *pIS = maPropertiesList[ i ]; + if( nProperties > (sal_Int32)pIS->GetProperties().size() ) + { + continue; + } + else if( nProperties < (sal_Int32)pIS->GetProperties().size() ) + { + break; + } + else if( !bDontSeek && pFamilyData->mxMapper->Equals( pIS->GetProperties(), rProperties ) ) + { + pProperties = pIS; + break; + } + } + + if( !pProperties ) + { + pProperties = new SvXMLAutoStylePoolPropertiesP_Impl( pFamilyData, rProperties ); + SvXMLAutoStylePoolPropertiesPList_Impl::iterator it = maPropertiesList.begin(); + ::std::advance( it, i ); + maPropertiesList.insert( it, pProperties ); + bAdded = sal_True; + } + + rName = pProperties->GetName(); + + return bAdded; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// Adds a array of XMLPropertyState ( vector< XMLPropertyState > ) with a given name. +// If the name exists already, nothing is done. If a style with a different name and +// the same properties exists, a new one is added (like with bDontSeek). +// + +sal_Bool SvXMLAutoStylePoolParentP_Impl::AddNamed( XMLFamilyData_Impl* pFamilyData, const vector< XMLPropertyState >& rProperties, const OUString& rName ) +{ + sal_Bool bAdded = sal_False; + size_t i = 0; + sal_Int32 nProperties = rProperties.size(); + size_t nCount = maPropertiesList.size(); + + for( i = 0; i < nCount; i++ ) + { + SvXMLAutoStylePoolPropertiesP_Impl *pIS = maPropertiesList[ i ]; + if( nProperties > (sal_Int32)pIS->GetProperties().size() ) + { + continue; + } + else if( nProperties < (sal_Int32)pIS->GetProperties().size() ) + { + break; + } + } + + if( !pFamilyData->mpNameList->Seek_Entry( &rName, 0 ) ) + { + SvXMLAutoStylePoolPropertiesP_Impl* pProperties = + new SvXMLAutoStylePoolPropertiesP_Impl( pFamilyData, rProperties ); + // ignore the generated name + pProperties->SetName( rName ); + SvXMLAutoStylePoolPropertiesPList_Impl::iterator it = maPropertiesList.begin(); + ::std::advance( it, i ); + maPropertiesList.insert( it, pProperties ); + bAdded = sal_True; + } + + return bAdded; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// Search for a array of XMLPropertyState ( vector< XMLPropertyState > ) in list +// + +OUString SvXMLAutoStylePoolParentP_Impl::Find( const XMLFamilyData_Impl* pFamilyData, const vector< XMLPropertyState >& rProperties ) const +{ + OUString sName; + vector< XMLPropertyState>::size_type nItems = rProperties.size(); + size_t nCount = maPropertiesList.size(); + for( size_t i = 0; i < nCount; i++ ) + { + SvXMLAutoStylePoolPropertiesP_Impl *pIS = maPropertiesList[ i ]; + if( nItems > pIS->GetProperties().size() ) + { + continue; + } + else if( nItems < pIS->GetProperties().size() ) + { + break; + } + else if( pFamilyData->mxMapper->Equals( pIS->GetProperties(), rProperties ) ) + { + sName = pIS->GetName(); + break; + } + } + + return sName; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// Sort-function for sorted list of SvXMLAutoStylePoolParent_Impl-elements +// + +int SvXMLAutoStylePoolParentPCmp_Impl( const SvXMLAutoStylePoolParentP_Impl& r1, + const SvXMLAutoStylePoolParentP_Impl& r2) +{ + return (int)r1.GetParent().compareTo( r2.GetParent() ); +} + +/////////////////////////////////////////////////////////////////////////////// +// +// Implementation of sorted list of SvXMLAutoStylePoolParent_Impl-elements +// + +IMPL_CONTAINER_SORT( SvXMLAutoStylePoolParentsP_Impl, + SvXMLAutoStylePoolParentP_Impl, + SvXMLAutoStylePoolParentPCmp_Impl ) + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/impastp4.cxx b/xmloff/source/style/impastp4.cxx new file mode 100644 index 000000000000..d6032f54b4ce --- /dev/null +++ b/xmloff/source/style/impastp4.cxx @@ -0,0 +1,523 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include <xmloff/xmlaustp.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/attrlist.hxx> +#include "impastpl.hxx" +#include <xmloff/xmlexppr.hxx> +#include <xmloff/xmlexp.hxx> +#include <xmloff/families.hxx> +#include <xmloff/PageMasterStyleMap.hxx> + +using namespace ::std; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::xmloff::token; + +//############################################################################# +// +// Class SvXMLAutoStylePool_Impl +// + +/////////////////////////////////////////////////////////////////////////////// +// +// ctor/dtor class SvXMLAutoStylePool_Impl +// + +SvXMLAutoStylePoolP_Impl::SvXMLAutoStylePoolP_Impl( SvXMLExport& rExp) + : rExport( rExp ), + maFamilyList( 5, 5 ) +{ +} + +SvXMLAutoStylePoolP_Impl::~SvXMLAutoStylePoolP_Impl() +{ + for (;;) { + XMLFamilyData_Impl* pData = maFamilyList.Remove( sal_uLong(0) ); + if (pData == NULL) { + break; + } + delete pData; + } +} + +/////////////////////////////////////////////////////////////////////////////// +// +// Adds stylefamily-informations to sorted list +// + +void SvXMLAutoStylePoolP_Impl::AddFamily( + sal_Int32 nFamily, + const OUString& rStrName, + const UniReference < SvXMLExportPropertyMapper > & rMapper, + const OUString& rStrPrefix, + sal_Bool bAsFamily ) +{ + // store family in a list if not already stored + sal_uLong nPos; + + sal_uInt16 nExportFlags = GetExport().getExportFlags(); + sal_Bool bStylesOnly = (nExportFlags & EXPORT_STYLES) != 0 && (nExportFlags & EXPORT_CONTENT) == 0; + + OUString aPrefix( rStrPrefix ); + if( bStylesOnly ) + { + aPrefix = OUString( 'M' ); + aPrefix += rStrPrefix; + } + + XMLFamilyData_Impl *pFamily = new XMLFamilyData_Impl( nFamily, rStrName, rMapper, aPrefix, bAsFamily ); + if( !maFamilyList.Seek_Entry( pFamily, &nPos ) ) + maFamilyList.Insert( pFamily ); + else + delete pFamily; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// Adds a name to list +// + +void SvXMLAutoStylePoolP_Impl::RegisterName( sal_Int32 nFamily, const OUString& rName ) +{ + SvXMLAutoStylePoolNamesP_Impl *pNames = 0; + + sal_uLong nPos; + XMLFamilyData_Impl aTmp( nFamily ); + if( maFamilyList.Seek_Entry( &aTmp, &nPos ) ) + pNames = maFamilyList.GetObject( nPos )->mpNameList; + + DBG_ASSERT( pNames, + "SvXMLAutoStylePool_Impl::RegisterName: unknown family" ); + if( pNames ) + { + OUString *pName = new OUString( rName ); + if( !pNames->Insert( pName ) ) + delete pName; + } +} + +/////////////////////////////////////////////////////////////////////////////// +// +// Retrieve the list of registered names +// + +void SvXMLAutoStylePoolP_Impl::GetRegisteredNames( + uno::Sequence<sal_Int32>& rFamilies, + uno::Sequence<OUString>& rNames ) +{ + // collect registered names + families + vector<sal_Int32> aFamilies; + vector<OUString> aNames; + + // iterate over families + sal_uInt32 nCount = maFamilyList.Count(); + for( sal_uInt32 i = 0; i < nCount; i++ ) + { + XMLFamilyData_Impl* pFamily = maFamilyList.GetObject( i ); + + // iterate over names + SvXMLAutoStylePoolNamesP_Impl* pNames = pFamily->mpNameList; + sal_uInt32 nNames = ( pNames != NULL ) ? pNames->Count() : 0; + for( sal_uInt32 j = 0; j < nNames; j++ ) + { + aFamilies.push_back( pFamily->mnFamily ); + aNames.push_back( *pNames->GetObject( j ) ); + } + } + + // copy the families + names into the sequence types + DBG_ASSERT( aFamilies.size() == aNames.size(), "families != names" ); + + rFamilies.realloc( aFamilies.size() ); + std::copy( aFamilies.begin(), aFamilies.end(), rFamilies.getArray() ); + + rNames.realloc( aNames.size() ); + std::copy( aNames.begin(), aNames.end(), rNames.getArray() ); +} + +/////////////////////////////////////////////////////////////////////////////// +// +// Adds a array of XMLPropertyState ( vector< XMLPropertyState > ) to list +// if not added, yet. +// + +sal_Bool SvXMLAutoStylePoolP_Impl::Add(OUString& rName, sal_Int32 nFamily, + const OUString& rParent, + const ::std::vector< XMLPropertyState >& rProperties, + sal_Bool bCache, + bool bDontSeek ) +{ + sal_Bool bRet(sal_False); + sal_uLong nPos; + + XMLFamilyData_Impl *pFamily = 0; + XMLFamilyData_Impl aTemporary( nFamily ); + if( maFamilyList.Seek_Entry( &aTemporary, &nPos ) ) + { + pFamily = maFamilyList.GetObject( nPos ); + } + + DBG_ASSERT( pFamily, "SvXMLAutoStylePool_Impl::Add: unknown family" ); + if( pFamily ) + { + SvXMLAutoStylePoolParentP_Impl aTmp( rParent ); + SvXMLAutoStylePoolParentP_Impl *pParent = 0; + + SvXMLAutoStylePoolParentsP_Impl *pParents = pFamily->mpParentList; + if( pParents->Seek_Entry( &aTmp, &nPos ) ) + { + pParent = pParents->GetObject( nPos ); + } + else + { + pParent = new SvXMLAutoStylePoolParentP_Impl( rParent ); + pParents->Insert( pParent ); + } + + if( pParent->Add( pFamily, rProperties, rName, bDontSeek ) ) + { + pFamily->mnCount++; + bRet = sal_True; + } + + if( bCache ) + { + if( !pFamily->pCache ) + pFamily->pCache = new SvXMLAutoStylePoolCache_Impl(); + if( pFamily->pCache->size() < MAX_CACHE_SIZE ) + pFamily->pCache->push_back( new OUString( rName ) ); + } + } + + return bRet; +} + +sal_Bool SvXMLAutoStylePoolP_Impl::AddNamed(const OUString& rName, sal_Int32 nFamily, + const OUString& rParent, const ::std::vector< XMLPropertyState >& rProperties ) +{ + // get family and parent the same way as in Add() + sal_Bool bRet(sal_False); + sal_uLong nPos; + + XMLFamilyData_Impl *pFamily = 0; + XMLFamilyData_Impl aTemporary( nFamily ); + if( maFamilyList.Seek_Entry( &aTemporary, &nPos ) ) + { + pFamily = maFamilyList.GetObject( nPos ); + } + + DBG_ASSERT( pFamily, "SvXMLAutoStylePool_Impl::Add: unknown family" ); + if( pFamily ) + { + SvXMLAutoStylePoolParentP_Impl aTmp( rParent ); + SvXMLAutoStylePoolParentP_Impl *pParent = 0; + + SvXMLAutoStylePoolParentsP_Impl *pParents = pFamily->mpParentList; + if( pParents->Seek_Entry( &aTmp, &nPos ) ) + { + pParent = pParents->GetObject( nPos ); + } + else + { + pParent = new SvXMLAutoStylePoolParentP_Impl( rParent ); + pParents->Insert( pParent ); + } + + if( pParent->AddNamed( pFamily, rProperties, rName ) ) + { + pFamily->mnCount++; + bRet = sal_True; + } + } + + return bRet; +} + +OUString SvXMLAutoStylePoolP_Impl::AddToCache( sal_Int32 nFamily, + const OUString& rParent ) +{ + sal_uLong nPos; + + XMLFamilyData_Impl *pFamily = 0; + XMLFamilyData_Impl aTmp( nFamily ); + if( maFamilyList.Seek_Entry( &aTmp, &nPos ) ) + { + pFamily = maFamilyList.GetObject( nPos ); + } + + DBG_ASSERT( pFamily, "SvXMLAutoStylePool_Impl::Add: unknown family" ); + if( pFamily ) + { + if( !pFamily->pCache ) + pFamily->pCache = new SvXMLAutoStylePoolCache_Impl(); + if( pFamily->pCache->size() < MAX_CACHE_SIZE ) + pFamily->pCache->push_back( new OUString( rParent ) ); + } + + return rParent; +} +/////////////////////////////////////////////////////////////////////////////// +// +// Search for a array of XMLPropertyState ( vector< XMLPropertyState > ) in list +// + +OUString SvXMLAutoStylePoolP_Impl::Find( sal_Int32 nFamily, + const OUString& rParent, + const vector< XMLPropertyState >& rProperties ) const +{ + OUString sName; + + sal_uLong nPos; + XMLFamilyData_Impl aTemporary( nFamily ); + XMLFamilyData_Impl *pFamily = 0; + if( maFamilyList.Seek_Entry( &aTemporary, &nPos ) ) + { + pFamily = maFamilyList.GetObject( nPos ); + } + + DBG_ASSERT( pFamily, "SvXMLAutoStylePool_Impl::Find: unknown family" ); + + if( pFamily ) + { + SvXMLAutoStylePoolParentP_Impl aTmp( rParent ); + + const SvXMLAutoStylePoolParentsP_Impl* pParents = + pFamily->mpParentList; + if( pParents->Seek_Entry( &aTmp, &nPos ) ) + sName = pParents->GetObject( nPos )->Find( pFamily, rProperties ); + } + + return sName; +} + +OUString SvXMLAutoStylePoolP_Impl::FindAndRemoveCached( sal_Int32 nFamily ) const +{ + OUString sName; + + sal_uLong nPos; + XMLFamilyData_Impl aTmp( nFamily ); + XMLFamilyData_Impl *pFamily = 0; + if( maFamilyList.Seek_Entry( &aTmp, &nPos ) ) + { + pFamily = maFamilyList.GetObject( nPos ); + } + + DBG_ASSERT( pFamily, "SvXMLAutoStylePool_Impl::Find: unknown family" ); + + if( pFamily ) + { + DBG_ASSERT( pFamily->pCache, "family doesn't have a cache" ); + + // The cache may be empty already. This happens if it was filled + // completly. + if( pFamily->pCache && !pFamily->pCache->empty() ) + { + OUString *pName = (*pFamily->pCache)[ 0 ]; + pFamily->pCache->erase( pFamily->pCache->begin() ); + sName = *pName; + delete pName; + } + } + + return sName; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// export +// + +void SvXMLAutoStylePoolP_Impl::exportXML( + sal_Int32 nFamily, + const uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > &, + const SvXMLUnitConverter&, + const SvXMLNamespaceMap&, + const SvXMLAutoStylePoolP *pAntiImpl) const +{ + sal_uInt32 nCount = 0; + + // Get list of parents for current family (nFamily) + sal_uLong nPos; + XMLFamilyData_Impl aTmp( nFamily ); + XMLFamilyData_Impl *pFamily = 0; + if( maFamilyList.Seek_Entry( &aTmp, &nPos ) ) + { + pFamily = maFamilyList.GetObject( nPos ); + nCount = pFamily->mnCount; + } + + DBG_ASSERT( pFamily, + "SvXMLAutoStylePool_Impl::exportXML: unknown family" ); + if( pFamily && nCount > 0 ) + { + ///////////////////////////////////////////////////////////////////////////////////// + // create, initialize and fill helper-structure (SvXMLAutoStylePoolProperties_Impl) + // wich contains a parent-name and a SvXMLAutoStylePoolProperties_Impl + // + const SvXMLAutoStylePoolParentsP_Impl *pParents = + pFamily->mpParentList; + + SvXMLAutoStylePoolPExport_Impl* aExpStyles = + new SvXMLAutoStylePoolPExport_Impl[nCount]; + + sal_uInt32 i; + for( i=0; i < nCount; i++ ) + { + aExpStyles[i].mpParent = 0; + aExpStyles[i].mpProperties = 0; + } + + sal_uInt32 nParents = pParents->Count(); + for( i=0; i < nParents; i++ ) + { + const SvXMLAutoStylePoolParentP_Impl* pParent = + pParents->GetObject( i ); + size_t nProperties = pParent->GetPropertiesList().size(); + for( size_t j = 0; j < nProperties; j++ ) + { + const SvXMLAutoStylePoolPropertiesP_Impl* pProperties = + pParent->GetPropertiesList()[ j ]; + nPos = pProperties->GetPos(); + DBG_ASSERT( nPos < nCount, + "SvXMLAutoStylePool_Impl::exportXML: wrong position" ); + if( nPos < nCount ) + { + DBG_ASSERT( !aExpStyles[nPos].mpProperties, + "SvXMLAutoStylePool_Impl::exportXML: double position" ); + aExpStyles[nPos].mpProperties = pProperties; + aExpStyles[nPos].mpParent = &pParent->GetParent(); + } + } + } + + ///////////////////////////////////////////////////////////////////////////////////// + // + // create string to export for each XML-style. That means for each property-list + // + OUString aStrFamilyName = pFamily->maStrFamilyName; + + for( i=0; i<nCount; i++ ) + { + DBG_ASSERT( aExpStyles[i].mpProperties, + "SvXMLAutoStylePool_Impl::exportXML: empty position" ); + + if( aExpStyles[i].mpProperties ) + { + GetExport().AddAttribute( + XML_NAMESPACE_STYLE, XML_NAME, + aExpStyles[i].mpProperties->GetName() ); + + if( pFamily->bAsFamily ) + { + GetExport().AddAttribute( + XML_NAMESPACE_STYLE, XML_FAMILY, aStrFamilyName ); + } + + if( aExpStyles[i].mpParent->getLength() ) + { + GetExport().AddAttribute( + XML_NAMESPACE_STYLE, XML_PARENT_STYLE_NAME, + GetExport().EncodeStyleName( + *aExpStyles[i].mpParent ) ); + } + + OUString sName; + if( pFamily->bAsFamily ) + sName = GetXMLToken(XML_STYLE); + else + sName = pFamily->maStrFamilyName; + + pAntiImpl->exportStyleAttributes( + GetExport().GetAttrList(), + nFamily, + aExpStyles[i].mpProperties->GetProperties(), + *pFamily->mxMapper.get() + , GetExport().GetMM100UnitConverter(), + GetExport().GetNamespaceMap() + ); + + SvXMLElementExport aElem( GetExport(), + XML_NAMESPACE_STYLE, sName, + sal_True, sal_True ); + + sal_Int32 nStart(-1); + sal_Int32 nEnd(-1); + if (nFamily == XML_STYLE_FAMILY_PAGE_MASTER) + { + nStart = 0; + sal_Int32 nIndex = 0; + UniReference< XMLPropertySetMapper > aPropMapper = + pFamily->mxMapper->getPropertySetMapper(); + sal_Int16 nContextID; + while(nIndex < aPropMapper->GetEntryCount() && nEnd == -1) + { + nContextID = aPropMapper->GetEntryContextId( nIndex ); + if (nContextID && ((nContextID & CTF_PM_FLAGMASK) != XML_PM_CTF_START)) + nEnd = nIndex; + nIndex++; + } + if (nEnd == -1) + nEnd = nIndex; + } + + pFamily->mxMapper->exportXML( + GetExport(), + aExpStyles[i].mpProperties->GetProperties(), + nStart, nEnd, XML_EXPORT_FLAG_IGN_WS ); + + pAntiImpl->exportStyleContent( + GetExport().GetDocHandler(), + nFamily, + aExpStyles[i].mpProperties->GetProperties(), + *pFamily->mxMapper.get(), + GetExport().GetMM100UnitConverter(), + GetExport().GetNamespaceMap() + ); + } + } + + delete[] aExpStyles; + } +} + +void SvXMLAutoStylePoolP_Impl::ClearEntries() +{ + for(sal_uInt32 a = 0L; a < maFamilyList.Count(); a++) + maFamilyList[a]->ClearEntries(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/impastpl.hxx b/xmloff/source/style/impastpl.hxx new file mode 100644 index 000000000000..77597257803a --- /dev/null +++ b/xmloff/source/style/impastpl.hxx @@ -0,0 +1,227 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_XMLASTPL_IMPL_HXX +#define _XMLOFF_XMLASTPL_IMPL_HXX + +#include <sal/types.h> +#include <svl/cntnrsrt.hxx> +#include <rtl/ustring.hxx> +#include <vector> +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/xml/sax/XAttributeList.hpp> +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +#include <xmloff/maptype.hxx> +#include <xmloff/xmlexppr.hxx> +#include <vector> + +class SvXMLAutoStylePoolP; +class SvXMLAutoStylePoolParentsP_Impl; +class SvXMLAutoStylePoolNamesP_Impl; +class SvXMLAttributeList; +class SvXMLExportPropertyMapper; +class SvXMLExport; + +#define MAX_CACHE_SIZE 65536 + +/////////////////////////////////////////////////////////////////////////////// +// +// Implementationclass for stylefamily-information +// + +typedef ::rtl::OUString* OUStringPtr; +typedef ::std::vector< OUStringPtr > SvXMLAutoStylePoolCache_Impl; + +class XMLFamilyData_Impl +{ +public: + SvXMLAutoStylePoolCache_Impl *pCache; + sal_uInt32 mnFamily; + ::rtl::OUString maStrFamilyName; + UniReference < SvXMLExportPropertyMapper > mxMapper; + + SvXMLAutoStylePoolParentsP_Impl* mpParentList; + SvXMLAutoStylePoolNamesP_Impl* mpNameList; + sal_uInt32 mnCount; + sal_uInt32 mnName; + ::rtl::OUString maStrPrefix; + sal_Bool bAsFamily; + +public: + XMLFamilyData_Impl( sal_Int32 nFamily, const ::rtl::OUString& rStrName, + const UniReference < SvXMLExportPropertyMapper > & rMapper, + const ::rtl::OUString& rStrPrefix, sal_Bool bAsFamily = sal_True ); + + XMLFamilyData_Impl( sal_Int32 nFamily ) : + pCache( 0 ), + mnFamily( nFamily ), mpParentList( NULL ), + mpNameList( NULL ), mnCount( 0 ), mnName( 0 ) + + {} + ~XMLFamilyData_Impl(); + + friend int XMLFamilyDataSort_Impl( const XMLFamilyData_Impl& r1, const XMLFamilyData_Impl& r2 ); + + void ClearEntries(); +}; + +DECLARE_CONTAINER_SORT( XMLFamilyDataList_Impl, XMLFamilyData_Impl ) + +/////////////////////////////////////////////////////////////////////////////// +// +// +// + +DECLARE_CONTAINER_SORT_DEL( SvXMLAutoStylePoolNamesP_Impl, + ::rtl::OUString ) + +/////////////////////////////////////////////////////////////////////////////// +// +// Properties of a pool +// + +class SvXMLAutoStylePoolPropertiesP_Impl +{ + ::rtl::OUString msName; + ::std::vector< XMLPropertyState > maProperties; + sal_uInt32 mnPos; + +public: + + SvXMLAutoStylePoolPropertiesP_Impl( XMLFamilyData_Impl* pFamilyData, const ::std::vector< XMLPropertyState >& rProperties ); + + ~SvXMLAutoStylePoolPropertiesP_Impl() + { + } + + const ::rtl::OUString& GetName() const { return msName; } + const ::std::vector< XMLPropertyState >& GetProperties() const { return maProperties; } + sal_uInt32 GetPos() const { return mnPos; } + + void SetName( const ::rtl::OUString& rNew ) { msName = rNew; } +}; + +typedef SvXMLAutoStylePoolPropertiesP_Impl* SvXMLAutoStylePoolPropertiesPPtr; +typedef ::std::vector< SvXMLAutoStylePoolPropertiesPPtr > SvXMLAutoStylePoolPropertiesPList_Impl; + +/////////////////////////////////////////////////////////////////////////////// +// +// Parents of AutoStylePool's +// + +class SvXMLAutoStylePoolParentP_Impl +{ + ::rtl::OUString msParent; + SvXMLAutoStylePoolPropertiesPList_Impl maPropertiesList; + +public: + + SvXMLAutoStylePoolParentP_Impl( const ::rtl::OUString & rParent ) : + msParent( rParent ) + { + } + + ~SvXMLAutoStylePoolParentP_Impl(); + + sal_Bool Add( XMLFamilyData_Impl* pFamilyData, const ::std::vector< XMLPropertyState >& rProperties, ::rtl::OUString& rName, bool bDontSeek = false ); + + sal_Bool AddNamed( XMLFamilyData_Impl* pFamilyData, const ::std::vector< XMLPropertyState >& rProperties, const ::rtl::OUString& rName ); + + ::rtl::OUString Find( const XMLFamilyData_Impl* pFamilyData, const ::std::vector< XMLPropertyState >& rProperties ) const; + + const ::rtl::OUString& GetParent() const { return msParent; } + + const SvXMLAutoStylePoolPropertiesPList_Impl& GetPropertiesList() const + { + return maPropertiesList; + } +}; + +DECLARE_CONTAINER_SORT_DEL( SvXMLAutoStylePoolParentsP_Impl, + SvXMLAutoStylePoolParentP_Impl ) + +/////////////////////////////////////////////////////////////////////////////// +// +// Implementationclass of SvXMLAutoStylePool +// + +class SvXMLAutoStylePoolP_Impl +{ + SvXMLExport& rExport; + + XMLFamilyDataList_Impl maFamilyList; + +public: + + SvXMLAutoStylePoolP_Impl( SvXMLExport& rExport ); + ~SvXMLAutoStylePoolP_Impl(); + + SvXMLExport& GetExport() const { return rExport; } + + void AddFamily( sal_Int32 nFamily, const ::rtl::OUString& rStrName, + const UniReference < SvXMLExportPropertyMapper > & rMapper, + const ::rtl::OUString& rStrPrefix, sal_Bool bAsFamily = sal_True ); + void RegisterName( sal_Int32 nFamily, const ::rtl::OUString& rName ); + void GetRegisteredNames( + com::sun::star::uno::Sequence<sal_Int32>& aFamilies, + com::sun::star::uno::Sequence<rtl::OUString>& aNames ); + + sal_Bool Add( ::rtl::OUString& rName, sal_Int32 nFamily, + const ::rtl::OUString& rParent, + const ::std::vector< XMLPropertyState >& rProperties, + sal_Bool bCache = sal_False, + bool bDontSeek = false ); + sal_Bool AddNamed( const ::rtl::OUString& rName, sal_Int32 nFamily, + const ::rtl::OUString& rParent, + const ::std::vector< XMLPropertyState >& rProperties ); + + ::rtl::OUString AddToCache( sal_Int32 nFamily, + const ::rtl::OUString& rParent ); + ::rtl::OUString Find( sal_Int32 nFamily, const ::rtl::OUString& rParent, + const ::std::vector< XMLPropertyState >& rProperties ) const; + + ::rtl::OUString FindAndRemoveCached( sal_Int32 nFamily ) const; + + void exportXML( sal_Int32 nFamily, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > & rHandler, + const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& rNamespaceMap, + const SvXMLAutoStylePoolP *pAntiImpl) const; + + void ClearEntries(); +}; + +struct SvXMLAutoStylePoolPExport_Impl +{ + const ::rtl::OUString *mpParent; + const SvXMLAutoStylePoolPropertiesP_Impl *mpProperties; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/kernihdl.cxx b/xmloff/source/style/kernihdl.cxx new file mode 100644 index 000000000000..27ed1a5a318f --- /dev/null +++ b/xmloff/source/style/kernihdl.cxx @@ -0,0 +1,92 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "kernihdl.hxx" +#include <com/sun/star/uno/Any.hxx> +#include <rtl/ustrbuf.hxx> + +// -- +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star::uno; +using namespace ::xmloff::token; + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLKerningPropHdl +// + +XMLKerningPropHdl::~XMLKerningPropHdl() +{ + // nothing to do +} + +sal_Bool XMLKerningPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const +{ + sal_Bool bRet = sal_True; + sal_Int32 nKerning = 0; + + if( ! IsXMLToken( rStrImpValue, XML_KERNING_NORMAL ) ) + { + bRet = rUnitConverter.convertMeasure( nKerning, rStrImpValue ); + } + + rValue <<= (sal_Int16)nKerning; + + return bRet; +} + +sal_Bool XMLKerningPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const +{ + sal_Bool bRet = sal_False; + sal_Int16 nValue = sal_Int16(); + + if( rValue >>= nValue ) + { + OUStringBuffer aOut; + + if( nValue == 0 ) + aOut.append( GetXMLToken(XML_KERNING_NORMAL) ); + else + rUnitConverter.convertMeasure( aOut, nValue ); + + rStrExpValue = aOut.makeStringAndClear(); + + bRet = sal_True; + } + + return bRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/kernihdl.hxx b/xmloff/source/style/kernihdl.hxx new file mode 100644 index 000000000000..958aabc3b479 --- /dev/null +++ b/xmloff/source/style/kernihdl.hxx @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PROPERTYHANDLER_KERNINGTYPES_HXX +#define _XMLOFF_PROPERTYHANDLER_KERNINGTYPES_HXX + +#include <xmloff/xmlprhdl.hxx> + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLKerningPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLKerningPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +#endif // _XMLOFF_PROPERTYHANDLER_KERNINGTYPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/lspachdl.cxx b/xmloff/source/style/lspachdl.cxx new file mode 100644 index 000000000000..27fa7582cf46 --- /dev/null +++ b/xmloff/source/style/lspachdl.cxx @@ -0,0 +1,198 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include <lspachdl.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/style/LineSpacing.hpp> +#include <com/sun/star/style/LineSpacingMode.hpp> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using ::xmloff::token::IsXMLToken; +using ::xmloff::token::XML_CASEMAP_NORMAL; + +// this is a copy of defines in svx/inc/escpitem.hxx +#define DFLT_ESC_PROP 58 +#define DFLT_ESC_AUTO_SUPER 101 +#define DFLT_ESC_AUTO_SUB -101 + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLEscapementPropHdl +// + +XMLLineHeightHdl::~XMLLineHeightHdl() +{ + // nothing to do +} + +sal_Bool XMLLineHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const +{ + style::LineSpacing aLSp; + sal_Int32 nTemp = 0; + + if( -1 != rStrImpValue.indexOf( sal_Unicode( '%' ) ) ) + { + aLSp.Mode = style::LineSpacingMode::PROP; + if(!rUnitConverter.convertPercent( nTemp, rStrImpValue )) + return sal_False; + aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp); + } + else if( IsXMLToken( rStrImpValue, XML_CASEMAP_NORMAL) ) + { + aLSp.Mode = style::LineSpacingMode::PROP; + aLSp.Height = 100; + } + else + { + aLSp.Mode = style::LineSpacingMode::FIX; + if(!rUnitConverter.convertMeasure( nTemp, rStrImpValue, 0x0000, 0xffff )) + return sal_False; + aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp); + } + + rValue <<= aLSp; + return sal_True; +} + +sal_Bool XMLLineHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const +{ + OUStringBuffer aOut; + + style::LineSpacing aLSp; + if(!(rValue >>= aLSp)) + return sal_False; + + if( style::LineSpacingMode::PROP != aLSp.Mode && style::LineSpacingMode::FIX != aLSp.Mode ) + return sal_False; + + if( style::LineSpacingMode::PROP == aLSp.Mode ) + { + rUnitConverter.convertPercent( aOut, aLSp.Height ); + } + else + { + rUnitConverter.convertMeasure( aOut, aLSp.Height ); + } + + rStrExpValue = aOut.makeStringAndClear(); + return rStrExpValue.getLength() != 0; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLLineHeightAtLeastHdl +// + +XMLLineHeightAtLeastHdl::~XMLLineHeightAtLeastHdl() +{ + // nothing to do +} + +sal_Bool XMLLineHeightAtLeastHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const +{ + style::LineSpacing aLSp; + + sal_Int32 nTemp; + aLSp.Mode = style::LineSpacingMode::MINIMUM; + if(!rUnitConverter.convertMeasure( nTemp, rStrImpValue, 0x0000, 0xffff )) + return sal_False; + aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp); + + rValue <<= aLSp; + return sal_True; +} + +sal_Bool XMLLineHeightAtLeastHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const +{ + OUStringBuffer aOut; + + style::LineSpacing aLSp; + if(!(rValue >>= aLSp)) + return sal_False; + + if( style::LineSpacingMode::MINIMUM != aLSp.Mode ) + return sal_False; + + rUnitConverter.convertMeasure( aOut, aLSp.Height ); + + rStrExpValue = aOut.makeStringAndClear(); + return rStrExpValue.getLength() != 0; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLLineSpacingHdl +// + +XMLLineSpacingHdl::~XMLLineSpacingHdl() +{ + // nothing to do +} + +sal_Bool XMLLineSpacingHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const +{ + style::LineSpacing aLSp; + sal_Int32 nTemp; + + aLSp.Mode = style::LineSpacingMode::LEADING; + if(!rUnitConverter.convertMeasure( nTemp, rStrImpValue, 0x0000, 0xffff )) + return sal_False; + aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp); + + rValue <<= aLSp; + return sal_True; +} + +sal_Bool XMLLineSpacingHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const +{ + OUStringBuffer aOut; + + style::LineSpacing aLSp; + if(!(rValue >>= aLSp)) + return sal_False; + + if( style::LineSpacingMode::LEADING != aLSp.Mode ) + return sal_False; + + rUnitConverter.convertMeasure( aOut, aLSp.Height ); + + rStrExpValue = aOut.makeStringAndClear(); + return rStrExpValue.getLength() != 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/lspachdl.hxx b/xmloff/source/style/lspachdl.hxx new file mode 100644 index 000000000000..ab1fc8f53541 --- /dev/null +++ b/xmloff/source/style/lspachdl.hxx @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PROPERTYHANDLER_LINESPACETYPES_HXX +#define _XMLOFF_PROPERTYHANDLER_LINESPACETYPES_HXX + +#include <xmloff/xmlprhdl.hxx> + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLLineHeightHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLLineHeightHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +class XMLLineHeightAtLeastHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLLineHeightAtLeastHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +class XMLLineSpacingHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLLineSpacingHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +#endif // _XMLOFF_PROPERTYHANDLER_CHARHEIGHTTYPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/numehelp.cxx b/xmloff/source/style/numehelp.cxx new file mode 100644 index 000000000000..a5c1680ede53 --- /dev/null +++ b/xmloff/source/style/numehelp.cxx @@ -0,0 +1,561 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + +#include "xmloff/numehelp.hxx" + +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmluconv.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlexp.hxx> +#include <com/sun/star/uno/Reference.h> +#include <rtl/ustring.hxx> +#include <svl/zforlist.hxx> +#include <com/sun/star/util/NumberFormat.hpp> +#include <rtl/math.hxx> +#include <tools/debug.hxx> +#include <rtl/ustrbuf.hxx> + +using namespace com::sun::star; +using namespace xmloff::token; + +#define XML_TYPE "Type" +#define XML_CURRENCYSYMBOL "CurrencySymbol" +#define XML_CURRENCYABBREVIATION "CurrencyAbbreviation" +#define XML_STANDARDFORMAT "StandardFormat" + +XMLNumberFormatAttributesExportHelper::XMLNumberFormatAttributesExportHelper( + ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >& xTempNumberFormatsSupplier) + : xNumberFormats(xTempNumberFormatsSupplier.is() ? xTempNumberFormatsSupplier->getNumberFormats() : ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats > ()), + pExport(NULL), + sStandardFormat(RTL_CONSTASCII_USTRINGPARAM(XML_STANDARDFORMAT)), + sType(RTL_CONSTASCII_USTRINGPARAM(XML_TYPE)), + msCurrencySymbol(RTL_CONSTASCII_USTRINGPARAM(XML_CURRENCYSYMBOL)), + msCurrencyAbbreviation(RTL_CONSTASCII_USTRINGPARAM(XML_CURRENCYABBREVIATION)), + aNumberFormats() +{ +} + +XMLNumberFormatAttributesExportHelper::XMLNumberFormatAttributesExportHelper( + ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >& xTempNumberFormatsSupplier, + SvXMLExport& rTempExport ) +: xNumberFormats(xTempNumberFormatsSupplier.is() ? xTempNumberFormatsSupplier->getNumberFormats() : ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats > ()), + pExport(&rTempExport), + sStandardFormat(RTL_CONSTASCII_USTRINGPARAM(XML_STANDARDFORMAT)), + sType(RTL_CONSTASCII_USTRINGPARAM(XML_TYPE)), + sAttrValueType(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_VALUE_TYPE))), + sAttrValue(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_VALUE))), + sAttrDateValue(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_DATE_VALUE))), + sAttrTimeValue(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_TIME_VALUE))), + sAttrBooleanValue(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_BOOLEAN_VALUE))), + sAttrStringValue(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_STRING_VALUE))), + sAttrCurrency(rTempExport.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OFFICE, GetXMLToken(XML_CURRENCY))), + msCurrencySymbol(RTL_CONSTASCII_USTRINGPARAM(XML_CURRENCYSYMBOL)), + msCurrencyAbbreviation(RTL_CONSTASCII_USTRINGPARAM(XML_CURRENCYABBREVIATION)), + aNumberFormats() +{ +} + +XMLNumberFormatAttributesExportHelper::~XMLNumberFormatAttributesExportHelper() +{ +} + +sal_Int16 XMLNumberFormatAttributesExportHelper::GetCellType(const sal_Int32 nNumberFormat, rtl::OUString& sCurrency, sal_Bool& bIsStandard) +{ + XMLNumberFormat aFormat(sEmpty, nNumberFormat, 0); + XMLNumberFormatSet::iterator aItr(aNumberFormats.find(aFormat)); + XMLNumberFormatSet::iterator aEndItr(aNumberFormats.end()); + if (aItr != aEndItr) + { + bIsStandard = aItr->bIsStandard; + sCurrency = aItr->sCurrency; + return aItr->nType; + } + else + { + aFormat.nType = GetCellType(nNumberFormat, bIsStandard); + aFormat.bIsStandard = bIsStandard; + if ((aFormat.nType & ~util::NumberFormat::DEFINED) == util::NumberFormat::CURRENCY) + if (GetCurrencySymbol(nNumberFormat, aFormat.sCurrency)) + sCurrency = aFormat.sCurrency; + aNumberFormats.insert(aFormat); + return aFormat.nType; + } +} + +void XMLNumberFormatAttributesExportHelper::WriteAttributes(SvXMLExport& rXMLExport, + const sal_Int16 nTypeKey, + const double& rValue, + const rtl::OUString& rCurrency, + sal_Bool bExportValue) +{ + sal_Bool bWasSetTypeAttribute = sal_False; + switch(nTypeKey & ~util::NumberFormat::DEFINED) + { + case 0: + case util::NumberFormat::NUMBER: + case util::NumberFormat::SCIENTIFIC: + case util::NumberFormat::FRACTION: + { + if (!bWasSetTypeAttribute) + { + rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_FLOAT); + bWasSetTypeAttribute = sal_True; + } + } // No Break + case util::NumberFormat::PERCENT: + { + if (!bWasSetTypeAttribute) + { + rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_PERCENTAGE); + bWasSetTypeAttribute = sal_True; + } + } // No Break + case util::NumberFormat::CURRENCY: + { + if (!bWasSetTypeAttribute) + { + rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_CURRENCY); + if (rCurrency.getLength() > 0) + rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_CURRENCY, rCurrency); + bWasSetTypeAttribute = sal_True; + } + + if (bExportValue) + { + rtl::OUString sValue( ::rtl::math::doubleToUString( rValue, + rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', sal_True)); + rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE, sValue); + } + } + break; + case util::NumberFormat::DATE: + case util::NumberFormat::DATETIME: + { + if (!bWasSetTypeAttribute) + { + rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_DATE); + bWasSetTypeAttribute = sal_True; + } + if (bExportValue) + { + if ( rXMLExport.SetNullDateOnUnitConverter() ) + { + rtl::OUStringBuffer sBuffer; + rXMLExport.GetMM100UnitConverter().convertDateTime(sBuffer, rValue); + rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_DATE_VALUE, sBuffer.makeStringAndClear()); + } + } + } + break; + case util::NumberFormat::TIME: + { + if (!bWasSetTypeAttribute) + { + rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_TIME); + bWasSetTypeAttribute = sal_True; + } + if (bExportValue) + { + rtl::OUStringBuffer sBuffer; + rXMLExport.GetMM100UnitConverter().convertTime(sBuffer, rValue); + rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_TIME_VALUE, sBuffer.makeStringAndClear()); + } + } + break; + case util::NumberFormat::LOGICAL: + { + if (!bWasSetTypeAttribute) + { + rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_BOOLEAN); + bWasSetTypeAttribute = sal_True; + } + if (bExportValue) + { + double fTempValue = rValue; + if (::rtl::math::approxEqual( fTempValue, 1.0 )) + { + rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_BOOLEAN_VALUE, XML_TRUE); + } + else + { + if (::rtl::math::approxEqual( rValue, 0.0 )) + { + rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_BOOLEAN_VALUE, XML_FALSE); + } + else + { + rtl::OUString sValue( ::rtl::math::doubleToUString( + fTempValue, + rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', + sal_True)); + rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_BOOLEAN_VALUE, sValue); + } + } + } + } + break; + case util::NumberFormat::TEXT: + { + if (!bWasSetTypeAttribute) + { + rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_FLOAT); + bWasSetTypeAttribute = sal_True; + if (bExportValue) + { + rtl::OUString sValue( ::rtl::math::doubleToUString( rValue, + rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', sal_True)); + rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE, sValue); + } + } + } + break; + } +} + +sal_Bool XMLNumberFormatAttributesExportHelper::GetCurrencySymbol(const sal_Int32 nNumberFormat, rtl::OUString& sCurrencySymbol, + uno::Reference <util::XNumberFormatsSupplier>& xNumberFormatsSupplier) +{ + if (xNumberFormatsSupplier.is()) + { + uno::Reference <util::XNumberFormats> xNumberFormats(xNumberFormatsSupplier->getNumberFormats()); + if (xNumberFormats.is()) + { + try + { + uno::Reference <beans::XPropertySet> xNumberPropertySet(xNumberFormats->getByKey(nNumberFormat)); + if ( xNumberPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_CURRENCYSYMBOL))) >>= sCurrencySymbol) + { + rtl::OUString sCurrencyAbbreviation; + if ( xNumberPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_CURRENCYABBREVIATION))) >>= sCurrencyAbbreviation) + { + if ( sCurrencyAbbreviation.getLength() != 0 ) + sCurrencySymbol = sCurrencyAbbreviation; + else + { + if ( sCurrencySymbol.getLength() == 1 && sCurrencySymbol.toChar() == NfCurrencyEntry::GetEuroSymbol() ) + sCurrencySymbol = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EUR")); + } + } + return sal_True; + } + } + catch ( uno::Exception& ) + { + OSL_FAIL("Numberformat not found"); + } + } + } + return sal_False; +} + + +sal_Int16 XMLNumberFormatAttributesExportHelper::GetCellType(const sal_Int32 nNumberFormat, sal_Bool& bIsStandard, + uno::Reference <util::XNumberFormatsSupplier>& xNumberFormatsSupplier) +{ + if (xNumberFormatsSupplier.is()) + { + uno::Reference <util::XNumberFormats> xNumberFormats(xNumberFormatsSupplier->getNumberFormats()); + if (xNumberFormats.is()) + { + try + { + uno::Reference <beans::XPropertySet> xNumberPropertySet(xNumberFormats->getByKey(nNumberFormat)); + xNumberPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STANDARDFORMAT))) >>= bIsStandard; + sal_Int16 nNumberType = sal_Int16(); + if ( xNumberPropertySet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(XML_TYPE))) >>= nNumberType ) + { + return nNumberType; + } + } + catch ( uno::Exception& ) + { + OSL_FAIL("Numberformat not found"); + } + } + } + return 0; +} + +void XMLNumberFormatAttributesExportHelper::SetNumberFormatAttributes(SvXMLExport& rXMLExport, + const sal_Int32 nNumberFormat, const double& rValue, sal_Bool bExportValue) +{ + sal_Bool bIsStandard; + sal_Int16 nTypeKey = GetCellType(nNumberFormat, bIsStandard, rXMLExport.GetNumberFormatsSupplier()); + rtl::OUString sCurrency; + if ((nTypeKey & ~util::NumberFormat::DEFINED) == util::NumberFormat::CURRENCY) + GetCurrencySymbol(nNumberFormat, sCurrency, rXMLExport.GetNumberFormatsSupplier()); + WriteAttributes(rXMLExport, nTypeKey, rValue, sCurrency, bExportValue); +} + +void XMLNumberFormatAttributesExportHelper::SetNumberFormatAttributes(SvXMLExport& rXMLExport, + const rtl::OUString& rValue, const rtl::OUString& rCharacters, + sal_Bool bExportValue, sal_Bool bExportTypeAttribute) +{ + if (bExportTypeAttribute) + rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_STRING); + if (bExportValue && rValue.getLength() && (rValue != rCharacters)) + rXMLExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_STRING_VALUE, rValue); +} + +sal_Bool XMLNumberFormatAttributesExportHelper::GetCurrencySymbol(const sal_Int32 nNumberFormat, rtl::OUString& rCurrencySymbol) +{ + if (!xNumberFormats.is() && pExport && pExport->GetNumberFormatsSupplier().is()) + xNumberFormats.set(pExport->GetNumberFormatsSupplier()->getNumberFormats()); + + if (xNumberFormats.is()) + { + try + { + uno::Reference <beans::XPropertySet> xNumberPropertySet(xNumberFormats->getByKey(nNumberFormat)); + if ( xNumberPropertySet->getPropertyValue(msCurrencySymbol) >>= rCurrencySymbol) + { + rtl::OUString sCurrencyAbbreviation; + if ( xNumberPropertySet->getPropertyValue(msCurrencyAbbreviation) >>= sCurrencyAbbreviation) + { + if ( sCurrencyAbbreviation.getLength() != 0 ) + rCurrencySymbol = sCurrencyAbbreviation; + else + { + if ( rCurrencySymbol.getLength() == 1 && rCurrencySymbol.toChar() == NfCurrencyEntry::GetEuroSymbol() ) + rCurrencySymbol = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EUR")); + } + } + return sal_True; + } + } + catch ( uno::Exception& ) + { + OSL_FAIL("Numberformat not found"); + } + } + return sal_False; +} + +sal_Int16 XMLNumberFormatAttributesExportHelper::GetCellType(const sal_Int32 nNumberFormat, sal_Bool& bIsStandard) +{ + if (!xNumberFormats.is() && pExport && pExport->GetNumberFormatsSupplier().is()) + xNumberFormats.set(pExport->GetNumberFormatsSupplier()->getNumberFormats()); + + if (xNumberFormats.is()) + { + try + { + uno::Reference <beans::XPropertySet> xNumberPropertySet(xNumberFormats->getByKey(nNumberFormat)); + if (xNumberPropertySet.is()) + { + xNumberPropertySet->getPropertyValue(sStandardFormat) >>= bIsStandard; + sal_Int16 nNumberType = sal_Int16(); + if ( xNumberPropertySet->getPropertyValue(sType) >>= nNumberType ) + { + return nNumberType; + } + } + } + catch ( uno::Exception& ) + { + OSL_FAIL("Numberformat not found"); + } + } + return 0; +} + +void XMLNumberFormatAttributesExportHelper::WriteAttributes( + const sal_Int16 nTypeKey, + const double& rValue, + const rtl::OUString& rCurrency, + sal_Bool bExportValue) +{ + if (!pExport) + return; + + sal_Bool bWasSetTypeAttribute = sal_False; + switch(nTypeKey & ~util::NumberFormat::DEFINED) + { + case 0: + case util::NumberFormat::NUMBER: + case util::NumberFormat::SCIENTIFIC: + case util::NumberFormat::FRACTION: + { + if (!bWasSetTypeAttribute) + { + pExport->AddAttribute(sAttrValueType, XML_FLOAT); + bWasSetTypeAttribute = sal_True; + } + } // No Break + case util::NumberFormat::PERCENT: + { + if (!bWasSetTypeAttribute) + { + pExport->AddAttribute(sAttrValueType, XML_PERCENTAGE); + bWasSetTypeAttribute = sal_True; + } + } // No Break + case util::NumberFormat::CURRENCY: + { + if (!bWasSetTypeAttribute) + { + pExport->AddAttribute(sAttrValueType, XML_CURRENCY); + if (rCurrency.getLength() > 0) + pExport->AddAttribute(sAttrCurrency, rCurrency); + bWasSetTypeAttribute = sal_True; + } + + if (bExportValue) + { + rtl::OUString sValue( ::rtl::math::doubleToUString( rValue, + rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', sal_True)); + pExport->AddAttribute(sAttrValue, sValue); + } + } + break; + case util::NumberFormat::DATE: + case util::NumberFormat::DATETIME: + { + if (!bWasSetTypeAttribute) + { + pExport->AddAttribute(sAttrValueType, XML_DATE); + bWasSetTypeAttribute = sal_True; + } + if (bExportValue) + { + if ( pExport->SetNullDateOnUnitConverter() ) + { + rtl::OUStringBuffer sBuffer; + pExport->GetMM100UnitConverter().convertDateTime(sBuffer, rValue); + pExport->AddAttribute(sAttrDateValue, sBuffer.makeStringAndClear()); + } + } + } + break; + case util::NumberFormat::TIME: + { + if (!bWasSetTypeAttribute) + { + pExport->AddAttribute(sAttrValueType, XML_TIME); + bWasSetTypeAttribute = sal_True; + } + if (bExportValue) + { + rtl::OUStringBuffer sBuffer; + pExport->GetMM100UnitConverter().convertTime(sBuffer, rValue); + pExport->AddAttribute(sAttrTimeValue, sBuffer.makeStringAndClear()); + } + } + break; + case util::NumberFormat::LOGICAL: + { + if (!bWasSetTypeAttribute) + { + pExport->AddAttribute(sAttrValueType, XML_BOOLEAN); + bWasSetTypeAttribute = sal_True; + } + if (bExportValue) + { + double fTempValue = rValue; + if (::rtl::math::approxEqual( fTempValue, 1.0 )) + { + pExport->AddAttribute(sAttrBooleanValue, XML_TRUE); + } + else + { + if (::rtl::math::approxEqual( rValue, 0.0 )) + { + pExport->AddAttribute(sAttrBooleanValue, XML_FALSE); + } + else + { + rtl::OUString sValue( ::rtl::math::doubleToUString( + fTempValue, + rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', + sal_True)); + pExport->AddAttribute(sAttrBooleanValue, sValue); + } + } + } + } + break; + case util::NumberFormat::TEXT: + { + if (!bWasSetTypeAttribute) + { + pExport->AddAttribute(sAttrValueType, XML_FLOAT); + bWasSetTypeAttribute = sal_True; + if (bExportValue) + { + rtl::OUString sValue( ::rtl::math::doubleToUString( rValue, + rtl_math_StringFormat_Automatic, + rtl_math_DecimalPlaces_Max, '.', sal_True)); + pExport->AddAttribute(sAttrValue, sValue); + } + } + } + break; + } +} + +void XMLNumberFormatAttributesExportHelper::SetNumberFormatAttributes( + const sal_Int32 nNumberFormat, const double& rValue, sal_Bool bExportValue) +{ + if (pExport) + { + sal_Bool bIsStandard; + rtl::OUString sCurrency; + sal_Int16 nTypeKey = GetCellType(nNumberFormat, sCurrency, bIsStandard); + WriteAttributes(nTypeKey, rValue, sCurrency, bExportValue); + } + else { + OSL_FAIL("no SvXMLExport given"); + } +} + +void XMLNumberFormatAttributesExportHelper::SetNumberFormatAttributes( + const rtl::OUString& rValue, const rtl::OUString& rCharacters, + sal_Bool bExportValue, sal_Bool bExportTypeAttribute) +{ + if (pExport) + { + if (bExportTypeAttribute) + pExport->AddAttribute(sAttrValueType, XML_STRING); + if (bExportValue && rValue.getLength() && (rValue != rCharacters)) + pExport->AddAttribute(sAttrStringValue, rValue); + } + else { + OSL_FAIL("no SvXMLExport given"); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/opaquhdl.cxx b/xmloff/source/style/opaquhdl.cxx new file mode 100644 index 000000000000..8ef05d56894d --- /dev/null +++ b/xmloff/source/style/opaquhdl.cxx @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "opaquhdl.hxx" +#include <com/sun/star/uno/Any.hxx> +#include <rtl/ustrbuf.hxx> + +// -- +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star::uno; +using namespace ::xmloff::token; + + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLOpaquePropHdl +// + +XMLOpaquePropHdl::~XMLOpaquePropHdl() +{ + // nothing to do +} + +sal_Bool XMLOpaquePropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_True; + + sal_Bool bValue = IsXMLToken( rStrImpValue, XML_OPAQUE_FOREGROUND ); + rValue <<= sal_Bool(bValue); + bRet = sal_True; + + return bRet; +} + +sal_Bool XMLOpaquePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + sal_Bool bValue = sal_Bool(); + + if (rValue >>= bValue) + { + if( bValue ) + rStrExpValue = GetXMLToken( XML_OPAQUE_FOREGROUND ); + else + rStrExpValue = GetXMLToken( XML_OPAQUE_BACKGROUND ); + + bRet = sal_True; + } + + return bRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/opaquhdl.hxx b/xmloff/source/style/opaquhdl.hxx new file mode 100644 index 000000000000..0c013936fda0 --- /dev/null +++ b/xmloff/source/style/opaquhdl.hxx @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PROPERTYHANDLER_OPAQUETYPES_HXX +#define _XMLOFF_PROPERTYHANDLER_OPAQUETYPES_HXX + +#include <xmloff/xmlprhdl.hxx> + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLOpaquePropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLOpaquePropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +#endif // _XMLOFF_PROPERTYHANDLER_OPAQUETYPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/postuhdl.cxx b/xmloff/source/style/postuhdl.cxx new file mode 100644 index 000000000000..6a8c104fca3a --- /dev/null +++ b/xmloff/source/style/postuhdl.cxx @@ -0,0 +1,95 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <postuhdl.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/awt/FontSlant.hpp> +#include <tools/fontenum.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::xmloff::token; + +SvXMLEnumMapEntry const aPostureGenericMapping[] = +{ + { XML_POSTURE_NORMAL, ITALIC_NONE }, + { XML_POSTURE_ITALIC, ITALIC_NORMAL }, + { XML_POSTURE_OBLIQUE, ITALIC_OBLIQUE }, + { XML_TOKEN_INVALID, 0 } +}; + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLPosturePropHdl +// + +XMLPosturePropHdl::~XMLPosturePropHdl() +{ + // nothing to do +} + +sal_Bool XMLPosturePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_uInt16 ePosture; + sal_Bool bRet = SvXMLUnitConverter::convertEnum( ePosture, rStrImpValue, aPostureGenericMapping ); + if( bRet ) + rValue <<= (awt::FontSlant)ePosture; + + return bRet; +} + +sal_Bool XMLPosturePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + awt::FontSlant eSlant; + + if( !( rValue >>= eSlant ) ) + { + sal_Int32 nValue = 0; + + if( !( rValue >>= nValue ) ) + return sal_False; + + eSlant = (awt::FontSlant)nValue; + } + + OUStringBuffer aOut; + sal_Bool bRet = SvXMLUnitConverter::convertEnum( aOut, (sal_Int32)eSlant, aPostureGenericMapping ); + if( bRet ) + rStrExpValue = aOut.makeStringAndClear(); + + return bRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/postuhdl.hxx b/xmloff/source/style/postuhdl.hxx new file mode 100644 index 000000000000..fffe77ee7f72 --- /dev/null +++ b/xmloff/source/style/postuhdl.hxx @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PROPERTYHANDLER_POSTURETYPES_HXX +#define _XMLOFF_PROPERTYHANDLER_POSTURETYPES_HXX + +#include <xmloff/xmlprhdl.hxx> + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLPosturePropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLPosturePropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +#endif // _XMLOFF_PROPERTYHANDLER_POSTURETYPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/prhdlfac.cxx b/xmloff/source/style/prhdlfac.cxx new file mode 100644 index 000000000000..b0652788a927 --- /dev/null +++ b/xmloff/source/style/prhdlfac.cxx @@ -0,0 +1,453 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + +#include <com/sun/star/drawing/ColorMode.hpp> +#include <com/sun/star/text/HorizontalAdjust.hpp> +#include <com/sun/star/text/WritingMode2.hpp> + +#include <tools/debug.hxx> + +#include <xmloff/prhdlfac.hxx> +#include <xmloff/xmltypes.hxx> +#include <xmloff/xmltoken.hxx> +#include "xmlbahdl.hxx" +#include <xmloff/NamedBoolPropertyHdl.hxx> +#include <xmloff/XMLConstantsPropertyHandler.hxx> +#include "cdouthdl.hxx" +#include "csmaphdl.hxx" +#include "fonthdl.hxx" +#include "kernihdl.hxx" +#include <postuhdl.hxx> +#include "shadwhdl.hxx" +#include "shdwdhdl.hxx" +#include "undlihdl.hxx" +#include "weighhdl.hxx" +#include "breakhdl.hxx" +#include <adjushdl.hxx> +#include <escphdl.hxx> +#include <chrhghdl.hxx> +#include <chrlohdl.hxx> +#include <lspachdl.hxx> +#include <bordrhdl.hxx> +#include <tabsthdl.hxx> +#include <xmloff/EnumPropertyHdl.hxx> +#include "AttributeContainerHandler.hxx" +#include "durationhdl.hxx" +#include "XMLRectangleMembersHandler.hxx" +#include "DrawAspectHdl.hxx" + +using namespace ::com::sun::star; +using namespace ::xmloff::token; + +SvXMLEnumMapEntry aXML_ColorMode_EnumMap[] = +{ + { XML_GREYSCALE, drawing::ColorMode_GREYS }, + { XML_MONO, drawing::ColorMode_MONO }, + { XML_WATERMARK, drawing::ColorMode_WATERMARK }, + { XML_STANDARD, drawing::ColorMode_STANDARD }, + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLEnumMapEntry const aXML_HorizontalAdjust_Enum[] = +{ + { XML_LEFT, text::HorizontalAdjust_LEFT }, + { XML_CENTER, text::HorizontalAdjust_CENTER }, + { XML_RIGHT, text::HorizontalAdjust_RIGHT }, + { XML_TOKEN_INVALID, 0 } +}; + +// aXML_WritingDirection_Enum is used with and without 'page' +// attribute, so you'll find uses of aXML_WritingDirection_Enum +// directly, as well as &(aXML_WritingDirection_Enum[1]) +SvXMLEnumMapEntry const aXML_WritingDirection_Enum[] = +{ + // aXML_WritingDirection_Enum + { XML_PAGE, text::WritingMode2::PAGE }, + + // &(aXML_WritingDirection_Enum[1]) + { XML_LR_TB, text::WritingMode2::LR_TB }, + { XML_RL_TB, text::WritingMode2::RL_TB }, + { XML_TB_RL, text::WritingMode2::TB_RL }, + { XML_TB_LR, text::WritingMode2::TB_LR }, + + // alternative names of the above, as accepted by XSL + { XML_LR, text::WritingMode2::LR_TB }, + { XML_RL, text::WritingMode2::RL_TB }, + { XML_TB, text::WritingMode2::TB_RL }, + + { XML_TOKEN_INVALID, 0 } +}; + + +/////////////////////////////////////////////////////////////////////////// +// +// Dtor +// +XMLPropertyHandlerFactory::~XMLPropertyHandlerFactory() +{ + for( CacheMap::iterator pPos = maHandlerCache.begin(); pPos != maHandlerCache.end(); ++pPos ) + delete pPos->second; +} + +/////////////////////////////////////////////////////////////////////////// +// +// Interface +// +const XMLPropertyHandler* XMLPropertyHandlerFactory::GetPropertyHandler( sal_Int32 nType ) const +{ + DBG_ASSERT( (nType & ~((sal_uInt32)MID_FLAG_MASK)) == 0, + "GetPropertyHandler called with flags in type" ); + return GetBasicHandler( nType ); +} + +/////////////////////////////////////////////////////////////////////////// +// +// Helper-methods to create and cache PropertyHandler +// +XMLPropertyHandler* XMLPropertyHandlerFactory::GetHdlCache( sal_Int32 nType ) const +{ + XMLPropertyHandler* pRet = NULL; + + if( maHandlerCache.find( nType ) != maHandlerCache.end() ) + pRet = maHandlerCache.find( nType )->second; + + return pRet; +} + +void XMLPropertyHandlerFactory::PutHdlCache( sal_Int32 nType, const XMLPropertyHandler* pHdl ) const +{ + // Don't be wondered about the following construct. The sense is to be able to provide a const- + // method as class-interface. + ((XMLPropertyHandlerFactory*)this)->maHandlerCache[ nType ] = (XMLPropertyHandler*)pHdl; +} + +const XMLPropertyHandler* XMLPropertyHandlerFactory::GetBasicHandler( sal_Int32 nType ) const +{ + const XMLPropertyHandler* pPropHdl = GetHdlCache( nType ); + + if( !pPropHdl ) + { + pPropHdl = CreatePropertyHandler( nType ); + + if( pPropHdl ) + PutHdlCache( nType, pPropHdl ); + } + + return pPropHdl; +} + +const XMLPropertyHandler* XMLPropertyHandlerFactory::CreatePropertyHandler( sal_Int32 nType ) +{ + XMLPropertyHandler* pPropHdl = NULL; + + switch( nType ) + { + case XML_TYPE_BOOL : + pPropHdl = new XMLBoolPropHdl; + break; + case XML_TYPE_MEASURE : + pPropHdl = new XMLMeasurePropHdl( 4 ); + break; + case XML_TYPE_MEASURE8 : + pPropHdl = new XMLMeasurePropHdl( 1 ); + break; + case XML_TYPE_MEASURE16: + pPropHdl = new XMLMeasurePropHdl( 2 ); + break; + case XML_TYPE_PERCENT : + pPropHdl = new XMLPercentPropHdl( 4 ); + break; + case XML_TYPE_PERCENT8 : + pPropHdl = new XMLPercentPropHdl( 1 ); + break; + case XML_TYPE_PERCENT16 : + pPropHdl = new XMLPercentPropHdl( 2 ); + break; + case XML_TYPE_DOUBLE_PERCENT : + pPropHdl = new XMLDoublePercentPropHdl(); + break; + case XML_TYPE_NEG_PERCENT : + pPropHdl = new XMLNegPercentPropHdl( 4 ); + break; + case XML_TYPE_NEG_PERCENT8 : + pPropHdl = new XMLNegPercentPropHdl( 1 ); + break; + case XML_TYPE_NEG_PERCENT16 : + pPropHdl = new XMLNegPercentPropHdl( 2 ); + break; + case XML_TYPE_MEASURE_PX : + pPropHdl = new XMLMeasurePxPropHdl( 4 ); + break; + case XML_TYPE_STRING : + pPropHdl = new XMLStringPropHdl; + break; + case XML_TYPE_COLOR : + pPropHdl = new XMLColorPropHdl; + break; + case XML_TYPE_NUMBER : + pPropHdl = new XMLNumberPropHdl( 4 ); + break; + case XML_TYPE_NUMBER8 : + pPropHdl = new XMLNumberPropHdl( 1 ); + break; + case XML_TYPE_NUMBER16: + pPropHdl = new XMLNumberPropHdl( 2 ); + break; + case XML_TYPE_NUMBER_NONE : + pPropHdl = new XMLNumberNonePropHdl; + break; + case XML_TYPE_NUMBER8_NONE : + pPropHdl = new XMLNumberNonePropHdl( 1 ); + break; + case XML_TYPE_NUMBER16_NONE : + pPropHdl = new XMLNumberNonePropHdl( 2 ); + break; + case XML_TYPE_DOUBLE : + pPropHdl = new XMLDoublePropHdl; + break; + case XML_TYPE_NBOOL : + pPropHdl = new XMLNBoolPropHdl; + break; + case XML_TYPE_COLORTRANSPARENT : + pPropHdl = new XMLColorTransparentPropHdl; + break; + case XML_TYPE_ISTRANSPARENT : + pPropHdl = new XMLIsTransparentPropHdl; + break; + case XML_TYPE_COLORAUTO : + pPropHdl = new XMLColorAutoPropHdl; + break; + case XML_TYPE_ISAUTOCOLOR : + pPropHdl = new XMLIsAutoColorPropHdl; + break; + case XML_TYPE_BUILDIN_CMP_ONLY : + pPropHdl = new XMLCompareOnlyPropHdl; + break; + + case XML_TYPE_RECTANGLE_LEFT : + case XML_TYPE_RECTANGLE_TOP : + case XML_TYPE_RECTANGLE_WIDTH : + case XML_TYPE_RECTANGLE_HEIGHT : + pPropHdl = new XMLRectangleMembersHdl( nType ); + break; + + case XML_TYPE_TEXT_CROSSEDOUT_TYPE: + pPropHdl = new XMLCrossedOutTypePropHdl ; + break; + case XML_TYPE_TEXT_CROSSEDOUT_STYLE: + pPropHdl = new XMLCrossedOutStylePropHdl ; + break; + case XML_TYPE_TEXT_CROSSEDOUT_WIDTH: + pPropHdl = new XMLCrossedOutWidthPropHdl ; + break; + case XML_TYPE_TEXT_CROSSEDOUT_TEXT: + pPropHdl = new XMLCrossedOutTextPropHdl ; + break; + case XML_TYPE_TEXT_BOOLCROSSEDOUT: + pPropHdl = new XMLNamedBoolPropertyHdl( + GetXMLToken(XML_SOLID), + GetXMLToken(XML_NONE) ); + break; + case XML_TYPE_TEXT_ESCAPEMENT: + pPropHdl = new XMLEscapementPropHdl; + break; + case XML_TYPE_TEXT_ESCAPEMENT_HEIGHT: + pPropHdl = new XMLEscapementHeightPropHdl; + break; + case XML_TYPE_TEXT_CASEMAP: + pPropHdl = new XMLCaseMapPropHdl; + break; + case XML_TYPE_TEXT_CASEMAP_VAR: + pPropHdl = new XMLCaseMapVariantHdl; + break; + case XML_TYPE_TEXT_FONTFAMILYNAME: + pPropHdl = new XMLFontFamilyNamePropHdl; + break; + case XML_TYPE_TEXT_FONTFAMILY: + pPropHdl = new XMLFontFamilyPropHdl; + break; + case XML_TYPE_TEXT_FONTENCODING: + pPropHdl = new XMLFontEncodingPropHdl; + break; + case XML_TYPE_TEXT_FONTPITCH: + pPropHdl = new XMLFontPitchPropHdl; + break; + case XML_TYPE_TEXT_KERNING: + pPropHdl = new XMLKerningPropHdl; + break; + case XML_TYPE_TEXT_POSTURE: + pPropHdl = new XMLPosturePropHdl; + break; + case XML_TYPE_TEXT_SHADOWED: + pPropHdl = new XMLShadowedPropHdl; + break; + case XML_TYPE_TEXT_UNDERLINE_TYPE: + pPropHdl = new XMLUnderlineTypePropHdl; + break; + case XML_TYPE_TEXT_UNDERLINE_STYLE: + pPropHdl = new XMLUnderlineStylePropHdl; + break; + case XML_TYPE_TEXT_UNDERLINE_WIDTH: + pPropHdl = new XMLUnderlineWidthPropHdl; + break; + case XML_TYPE_TEXT_UNDERLINE_COLOR: + pPropHdl = new XMLColorTransparentPropHdl( XML_FONT_COLOR ); + break; + case XML_TYPE_TEXT_UNDERLINE_HASCOLOR: + pPropHdl = new XMLIsTransparentPropHdl( XML_FONT_COLOR, + sal_False ); + break; + case XML_TYPE_TEXT_OVERLINE_TYPE: + pPropHdl = new XMLUnderlineTypePropHdl; + break; + case XML_TYPE_TEXT_OVERLINE_STYLE: + pPropHdl = new XMLUnderlineStylePropHdl; + break; + case XML_TYPE_TEXT_OVERLINE_WIDTH: + pPropHdl = new XMLUnderlineWidthPropHdl; + break; + case XML_TYPE_TEXT_OVERLINE_COLOR: + pPropHdl = new XMLColorTransparentPropHdl( XML_FONT_COLOR ); + break; + case XML_TYPE_TEXT_OVERLINE_HASCOLOR: + pPropHdl = new XMLIsTransparentPropHdl( XML_FONT_COLOR, + sal_False ); + break; + case XML_TYPE_TEXT_WEIGHT: + pPropHdl = new XMLFontWeightPropHdl; + break; + case XML_TYPE_TEXT_SPLIT: + pPropHdl = new XMLNamedBoolPropertyHdl( + GetXMLToken(XML_AUTO), + GetXMLToken(XML_ALWAYS) ); + break; + case XML_TYPE_TEXT_BREAKBEFORE: + pPropHdl = new XMLFmtBreakBeforePropHdl; + break; + case XML_TYPE_TEXT_BREAKAFTER: + pPropHdl = new XMLFmtBreakAfterPropHdl; + break; + case XML_TYPE_TEXT_SHADOW: + pPropHdl = new XMLShadowPropHdl; + break; + case XML_TYPE_TEXT_ADJUST: + pPropHdl = new XMLParaAdjustPropHdl; + break; + case XML_TYPE_TEXT_ADJUSTLAST: + pPropHdl = new XMLLastLineAdjustPropHdl; + break; + case XML_TYPE_CHAR_HEIGHT: + pPropHdl = new XMLCharHeightHdl; + break; + case XML_TYPE_CHAR_HEIGHT_PROP: + pPropHdl = new XMLCharHeightPropHdl; + break; + case XML_TYPE_CHAR_HEIGHT_DIFF: + pPropHdl = new XMLCharHeightDiffHdl; + break; + case XML_TYPE_CHAR_LANGUAGE: + pPropHdl = new XMLCharLanguageHdl; + break; + case XML_TYPE_CHAR_COUNTRY: + pPropHdl = new XMLCharCountryHdl; + break; + case XML_TYPE_LINE_SPACE_FIXED: + pPropHdl = new XMLLineHeightHdl; + break; + case XML_TYPE_LINE_SPACE_MINIMUM: + pPropHdl = new XMLLineHeightAtLeastHdl; + break; + case XML_TYPE_LINE_SPACE_DISTANCE: + pPropHdl = new XMLLineSpacingHdl; + break; + case XML_TYPE_BORDER_WIDTH: + pPropHdl = new XMLBorderWidthHdl; + break; + case XML_TYPE_BORDER: + pPropHdl = new XMLBorderHdl; + break; + case XML_TYPE_TEXT_TABSTOP: + pPropHdl = new XMLTabStopPropHdl; + break; + case XML_TYPE_ATTRIBUTE_CONTAINER: + pPropHdl = new XMLAttributeContainerHandler; + break; + case XML_TYPE_COLOR_MODE: + pPropHdl = new XMLEnumPropertyHdl( aXML_ColorMode_EnumMap, + ::getCppuType((const drawing::ColorMode*)0) ); + break; + case XML_TYPE_DURATION16_MS: + pPropHdl = new XMLDurationMS16PropHdl_Impl; + break; + case XML_TYPE_TEXT_HORIZONTAL_ADJUST: + pPropHdl = new XMLEnumPropertyHdl( + aXML_HorizontalAdjust_Enum, + ::getCppuType((const text::HorizontalAdjust*)0) ); + break; + case XML_TYPE_TEXT_DRAW_ASPECT: + pPropHdl = new DrawAspectHdl; + break; + case XML_TYPE_TEXT_WRITING_MODE: + pPropHdl = new XMLConstantsPropertyHandler( + &(aXML_WritingDirection_Enum[1]), + XML_LR_TB); + break; + case XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT: + pPropHdl = new XMLConstantsPropertyHandler( + aXML_WritingDirection_Enum, + XML_PAGE); + break; + case XML_TYPE_TEXT_HIDDEN_AS_DISPLAY: + pPropHdl = new XMLNamedBoolPropertyHdl( + GetXMLToken(XML_NONE), + GetXMLToken(XML_TRUE) ); + break; + case XML_TYPE_STYLENAME : + pPropHdl = new XMLStyleNamePropHdl; + break; + case XML_TYPE_NUMBER_NO_ZERO: + pPropHdl = new XMLNumberWithoutZeroPropHdl( 4 ); + break; + case XML_TYPE_NUMBER8_NO_ZERO: + pPropHdl = new XMLNumberWithoutZeroPropHdl( 1 ); + break; + case XML_TYPE_NUMBER16_NO_ZERO: + pPropHdl = new XMLNumberWithoutZeroPropHdl( 2 ); + break; + case XML_TYPE_NUMBER16_AUTO: + pPropHdl = new XMLNumberWithAutoInsteadZeroPropHdl(); + break; + } + + return pPropHdl; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/prstylei.cxx b/xmloff/source/style/prstylei.cxx new file mode 100644 index 000000000000..c0261eb0852c --- /dev/null +++ b/xmloff/source/style/prstylei.cxx @@ -0,0 +1,420 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include <tools/debug.hxx> +#include <set> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlprcon.hxx> +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/style/XAutoStyleFamily.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XPropertyState.hpp> +#include <com/sun/star/beans/XMultiPropertyStates.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <xmloff/xmlimp.hxx> + +#include <xmloff/prstylei.hxx> +#include <xmloff/attrlist.hxx> +#include "xmloff/xmlerror.hxx" + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::xml::sax; +using namespace ::com::sun::star::style; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::lang; +using namespace ::xmloff::token; + + +void XMLPropStyleContext::SetAttribute( sal_uInt16 nPrefixKey, + const OUString& rLocalName, + const OUString& rValue ) +{ + if( XML_NAMESPACE_STYLE == nPrefixKey && IsXMLToken( rLocalName, XML_FAMILY ) ) + { + DBG_ASSERT( GetFamily() == ((SvXMLStylesContext *)&mxStyles)->GetFamily( rValue ), "unexpected style family" ); + } + else + { + SvXMLStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue ); + } +} + +TYPEINIT1( XMLPropStyleContext, SvXMLStyleContext ); + +XMLPropStyleContext::XMLPropStyleContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, const OUString& rLName, + const Reference< XAttributeList > & xAttrList, + SvXMLStylesContext& rStyles, sal_uInt16 nFamily, + sal_Bool bDefault ) +: SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList, nFamily, bDefault ) +, msIsPhysical( RTL_CONSTASCII_USTRINGPARAM( "IsPhysical" ) ) +, msFollowStyle( RTL_CONSTASCII_USTRINGPARAM( "FollowStyle" ) ) +, mxStyles( &rStyles ) +{ +} + +XMLPropStyleContext::~XMLPropStyleContext() +{ +} + +SvXMLImportContext *XMLPropStyleContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference< XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + + sal_uInt32 nFamily = 0; + if( XML_NAMESPACE_STYLE == nPrefix ) + { + if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) ) + nFamily = XML_TYPE_PROP_GRAPHIC; + else if( IsXMLToken( rLocalName, XML_DRAWING_PAGE_PROPERTIES ) ) + nFamily = XML_TYPE_PROP_DRAWING_PAGE; + else if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) ) + nFamily = XML_TYPE_PROP_TEXT; + else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) ) + nFamily = XML_TYPE_PROP_PARAGRAPH; + else if( IsXMLToken( rLocalName, XML_RUBY_PROPERTIES ) ) + nFamily = XML_TYPE_PROP_RUBY; + else if( IsXMLToken( rLocalName, XML_SECTION_PROPERTIES ) ) + nFamily = XML_TYPE_PROP_SECTION; + else if( IsXMLToken( rLocalName, XML_TABLE_PROPERTIES ) ) + nFamily = XML_TYPE_PROP_TABLE; + else if( IsXMLToken( rLocalName, XML_TABLE_COLUMN_PROPERTIES ) ) + nFamily = XML_TYPE_PROP_TABLE_COLUMN; + else if( IsXMLToken( rLocalName, XML_TABLE_ROW_PROPERTIES ) ) + nFamily = XML_TYPE_PROP_TABLE_ROW; + else if( IsXMLToken( rLocalName, XML_TABLE_CELL_PROPERTIES ) ) + nFamily = XML_TYPE_PROP_TABLE_CELL; + else if( IsXMLToken( rLocalName, XML_CHART_PROPERTIES ) ) + nFamily = XML_TYPE_PROP_CHART; + } + if( nFamily ) + { + UniReference < SvXMLImportPropertyMapper > xImpPrMap = + ((SvXMLStylesContext *)&mxStyles)->GetImportPropertyMapper( + GetFamily() ); + if( xImpPrMap.is() ) + pContext = new SvXMLPropertySetContext( GetImport(), nPrefix, + rLocalName, xAttrList, + nFamily, + maProperties, + xImpPrMap ); + } + + if( !pContext ) + pContext = SvXMLStyleContext::CreateChildContext( nPrefix, rLocalName, + xAttrList ); + + return pContext; +} + +void XMLPropStyleContext::FillPropertySet( + const Reference< XPropertySet > & rPropSet ) +{ + UniReference < SvXMLImportPropertyMapper > xImpPrMap = + ((SvXMLStylesContext *)&mxStyles)->GetImportPropertyMapper( + GetFamily() ); + DBG_ASSERT( xImpPrMap.is(), "There is the import prop mapper" ); + if( xImpPrMap.is() ) + xImpPrMap->FillPropertySet( maProperties, rPropSet ); +} + +void XMLPropStyleContext::SetDefaults() +{ +} + +Reference < XStyle > XMLPropStyleContext::Create() +{ + Reference < XStyle > xNewStyle; + + OUString sServiceName( + ((SvXMLStylesContext *)&mxStyles)->GetServiceName( GetFamily() ) ); + if( sServiceName.getLength() ) + { + Reference< XMultiServiceFactory > xFactory( GetImport().GetModel(), + UNO_QUERY ); + if( xFactory.is() ) + { + Reference < XInterface > xIfc = + xFactory->createInstance( sServiceName ); + if( xIfc.is() ) + xNewStyle = Reference < XStyle >( xIfc, UNO_QUERY ); + } + } + + return xNewStyle; +} + +typedef ::std::set < OUString, ::comphelper::UStringLess > PropertyNameSet; + +void XMLPropStyleContext::CreateAndInsert( sal_Bool bOverwrite ) +{ + if( ((SvXMLStylesContext *)&mxStyles)->IsAutomaticStyle() + && ( GetFamily() == XML_STYLE_FAMILY_TEXT_TEXT || GetFamily() == XML_STYLE_FAMILY_TEXT_PARAGRAPH ) ) + { + Reference < XAutoStyleFamily > xAutoFamily = + ((SvXMLStylesContext *)&mxStyles)->GetAutoStyles( GetFamily() ); + if( !xAutoFamily.is() ) + return; + UniReference < SvXMLImportPropertyMapper > xImpPrMap = + ((SvXMLStylesContext *)&mxStyles)->GetImportPropertyMapper( GetFamily() ); + DBG_ASSERT( xImpPrMap.is(), "There is no import prop mapper" ); + if( xImpPrMap.is() ) + { + Sequence< PropertyValue > aValues; + xImpPrMap->FillPropertySequence( maProperties, aValues ); + + sal_Int32 nLen = aValues.getLength(); + if( nLen ) + { + if( GetFamily() == XML_STYLE_FAMILY_TEXT_PARAGRAPH ) + { + aValues.realloc( nLen + 2 ); + PropertyValue *pProps = aValues.getArray() + nLen; + pProps->Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaStyleName")); + OUString sParent( GetParentName() ); + if( sParent.getLength() ) + sParent = GetImport().GetStyleDisplayName( GetFamily(), sParent ); + else + sParent = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Standard")); + pProps->Value <<= sParent; + ++pProps; + pProps->Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaConditionalStyleName")); + pProps->Value <<= sParent; + } + + Reference < XAutoStyle > xAutoStyle = xAutoFamily->insertStyle( aValues ); + if( xAutoStyle.is() ) + { + Sequence< OUString > aPropNames(1); + aPropNames[0] = GetFamily() == XML_STYLE_FAMILY_TEXT_PARAGRAPH ? + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParaAutoStyleName")) : + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharAutoStyleName")); + Sequence< Any > aAny = xAutoStyle->getPropertyValues( aPropNames ); + if( aAny.hasElements() ) + { + OUString aName; + aAny[0] >>= aName; + SetAutoName( aName ); + } + } + } + } + } + else + { + const OUString& rName = GetDisplayName(); + if( 0 == rName.getLength() || IsDefaultStyle() ) + return; + + Reference < XNameContainer > xFamilies = + ((SvXMLStylesContext *)&mxStyles)->GetStylesContainer( GetFamily() ); + if( !xFamilies.is() ) + return; + + sal_Bool bNew = sal_False; + if( xFamilies->hasByName( rName ) ) + { + Any aAny = xFamilies->getByName( rName ); + aAny >>= mxStyle; + } + else + { + mxStyle = Create(); + if( !mxStyle.is() ) + return; + + Any aAny; + aAny <<= mxStyle; + xFamilies->insertByName( rName, aAny ); + bNew = sal_True; + } + + Reference < XPropertySet > xPropSet( mxStyle, UNO_QUERY ); + Reference< XPropertySetInfo > xPropSetInfo = + xPropSet->getPropertySetInfo(); + if( !bNew && xPropSetInfo->hasPropertyByName( msIsPhysical ) ) + { + Any aAny = xPropSet->getPropertyValue( msIsPhysical ); + bNew = !*(sal_Bool *)aAny.getValue(); + } + SetNew( bNew ); + if( rName != GetName() ) + GetImport().AddStyleDisplayName( GetFamily(), GetName(), rName ); + + if( bOverwrite || bNew ) + { + Reference< XPropertyState > xPropState( xPropSet, uno::UNO_QUERY ); + + UniReference < XMLPropertySetMapper > xPrMap; + UniReference < SvXMLImportPropertyMapper > xImpPrMap = + ((SvXMLStylesContext *)&mxStyles)->GetImportPropertyMapper( + GetFamily() ); + DBG_ASSERT( xImpPrMap.is(), "There is the import prop mapper" ); + if( xImpPrMap.is() ) + xPrMap = xImpPrMap->getPropertySetMapper(); + if( xPrMap.is() ) + { + Reference < XMultiPropertyStates > xMultiStates( xPropSet, + UNO_QUERY ); + if( xMultiStates.is() ) + { + xMultiStates->setAllPropertiesToDefault(); + } + else + { + PropertyNameSet aNameSet; + sal_Int32 nCount = xPrMap->GetEntryCount(); + sal_Int32 i; + for( i = 0; i < nCount; i++ ) + { + const OUString& rPrName = xPrMap->GetEntryAPIName( i ); + if( xPropSetInfo->hasPropertyByName( rPrName ) ) + aNameSet.insert( rPrName ); + } + + nCount = aNameSet.size(); + Sequence < OUString > aNames( nCount ); + OUString *pNames = aNames.getArray(); + PropertyNameSet::iterator aIter = aNameSet.begin(); + while( aIter != aNameSet.end() ) + *pNames++ = *aIter++; + + Sequence < PropertyState > aStates( + xPropState->getPropertyStates( aNames ) ); + const PropertyState *pStates = aStates.getConstArray(); + pNames = aNames.getArray(); + + for( i = 0; i < nCount; i++ ) + { + if( PropertyState_DIRECT_VALUE == *pStates++ ) + xPropState->setPropertyToDefault( pNames[i] ); + } + } + } + + if (mxStyle.is()) + mxStyle->setParentStyle(OUString()); + + FillPropertySet( xPropSet ); + } + else + { + SetValid( sal_False ); + } + } +} + +void XMLPropStyleContext::Finish( sal_Bool bOverwrite ) +{ + if( mxStyle.is() && (IsNew() || bOverwrite) ) + { + // The families cintaner must exist + Reference < XNameContainer > xFamilies = + ((SvXMLStylesContext *)&mxStyles)->GetStylesContainer( GetFamily() ); + DBG_ASSERT( xFamilies.is(), "Families lost" ); + if( !xFamilies.is() ) + return; + + // connect parent + OUString sParent( GetParentName() ); + if( sParent.getLength() ) + sParent = GetImport().GetStyleDisplayName( GetFamily(), sParent ); + if( sParent.getLength() && !xFamilies->hasByName( sParent ) ) + sParent = OUString(); + + if( sParent != mxStyle->getParentStyle() ) + { + // this may except if setting the parent style forms a + // circle in the style depencies; especially if the parent + // style is the same as the current style + try + { + mxStyle->setParentStyle( sParent ); + } + catch( uno::Exception e ) + { + // according to the API definition, I would expect a + // container::NoSuchElementException. But it throws an + // uno::RuntimeException instead. I catch + // uno::Exception in order to process both of them. + + // We can't set the parent style. For a proper + // Error-Message, we should pass in the name of the + // style, as well as the desired parent style. + Sequence<OUString> aSequence(2); + + // getName() throws no non-Runtime exception: + aSequence[0] = mxStyle->getName(); + aSequence[1] = sParent; + + GetImport().SetError( + XMLERROR_FLAG_ERROR | XMLERROR_PARENT_STYLE_NOT_ALLOWED, + aSequence, e.Message, NULL ); + } + } + + // connect follow + OUString sFollow( GetFollow() ); + if( sFollow.getLength() ) + sFollow = GetImport().GetStyleDisplayName( GetFamily(), sFollow ); + if( !sFollow.getLength() || !xFamilies->hasByName( sFollow ) ) + sFollow = mxStyle->getName(); + + Reference < XPropertySet > xPropSet( mxStyle, UNO_QUERY ); + Reference< XPropertySetInfo > xPropSetInfo = + xPropSet->getPropertySetInfo(); + if( xPropSetInfo->hasPropertyByName( msFollowStyle ) ) + { + Any aAny = xPropSet->getPropertyValue( msFollowStyle ); + OUString sCurrFollow; + aAny >>= sCurrFollow; + if( sCurrFollow != sFollow ) + { + aAny <<= sFollow; + xPropSet->setPropertyValue( msFollowStyle, aAny ); + } + } + } +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/shadwhdl.cxx b/xmloff/source/style/shadwhdl.cxx new file mode 100644 index 000000000000..03fcb8a4eaf9 --- /dev/null +++ b/xmloff/source/style/shadwhdl.cxx @@ -0,0 +1,178 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "shadwhdl.hxx" +#include <com/sun/star/uno/Any.hxx> +#include <rtl/ustrbuf.hxx> + +// -- +#include <com/sun/star/table/ShadowFormat.hpp> +#include <xmloff/xmluconv.hxx> +#include <xmloff/xmltoken.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::xmloff::token; + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLMeasurePropHdl +// + +XMLShadowPropHdl::~XMLShadowPropHdl() +{ + // nothing to do +} + +sal_Bool XMLShadowPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const +{ + sal_Bool bRet = sal_False; + table::ShadowFormat aShadow; + aShadow.Location = table::ShadowLocation_BOTTOM_RIGHT; + + sal_Bool bColorFound = sal_False; + sal_Bool bOffsetFound = sal_False; + SvXMLTokenEnumerator aTokenEnum( rStrImpValue ); + Color aColor( 128,128, 128 ); + OUString aToken; + + while( aTokenEnum.getNextToken( aToken ) ) + { + if( IsXMLToken( aToken, XML_NONE ) ) + { + aShadow.Location = table::ShadowLocation_NONE; + bRet = sal_True; + break; + } + else if( !bColorFound && aToken.compareToAscii( "#", 1 ) == 0 ) + { + bRet = rUnitConverter.convertColor( aColor, aToken ); + if( !bRet ) + return sal_False; + + bColorFound = sal_True; + } + else if( !bOffsetFound ) + { + sal_Int32 nX = 0, nY = 0; + + bRet = rUnitConverter.convertMeasure( nX, aToken ); + if( bRet && aTokenEnum.getNextToken( aToken ) ) + bRet = rUnitConverter.convertMeasure( nY, aToken ); + + if( bRet ) + { + if( nX < 0 ) + { + if( nY < 0 ) + aShadow.Location = table::ShadowLocation_TOP_LEFT; + else + aShadow.Location = table::ShadowLocation_BOTTOM_LEFT; + } + else + { + if( nY < 0 ) + aShadow.Location = table::ShadowLocation_TOP_RIGHT; + else + aShadow.Location = table::ShadowLocation_BOTTOM_RIGHT; + } + + if( nX < 0 ) nX *= -1; + if( nY < 0 ) nY *= -1; + + aShadow.ShadowWidth = sal::static_int_cast< sal_Int16 >( + (nX + nY) >> 1); + } + } + } + + if( bRet && ( bColorFound || bOffsetFound ) ) + { + aShadow.IsTransparent = aColor.GetTransparency() > 0; + aShadow.Color = aColor.GetColor(); + bRet = sal_True; + } + + rValue <<= aShadow; + + return bRet; +} + +sal_Bool XMLShadowPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const +{ + sal_Bool bRet = sal_False; + OUStringBuffer aOut; + table::ShadowFormat aShadow; + + if( rValue >>= aShadow ) + { + sal_Int32 nX = 1, nY = 1; + + switch( aShadow.Location ) + { + case table::ShadowLocation_TOP_LEFT: + nX = -1; + nY = -1; + break; + case table::ShadowLocation_TOP_RIGHT: + nY = -1; + break; + case table::ShadowLocation_BOTTOM_LEFT: + nX = -1; + break; + case table::ShadowLocation_BOTTOM_RIGHT: + break; + case table::ShadowLocation_NONE: + default: + rStrExpValue = GetXMLToken(XML_NONE); + return sal_True; + } + + nX *= aShadow.ShadowWidth; + nY *= aShadow.ShadowWidth; + + rUnitConverter.convertColor( aOut, aShadow.Color ); + + aOut.append( sal_Unicode(' ') ); + rUnitConverter.convertMeasure( aOut, nX ); + aOut.append( sal_Unicode(' ') ); + rUnitConverter.convertMeasure( aOut, nY ); + + rStrExpValue = aOut.makeStringAndClear(); + + bRet = sal_True; + } + + return bRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/shadwhdl.hxx b/xmloff/source/style/shadwhdl.hxx new file mode 100644 index 000000000000..6cb957778f01 --- /dev/null +++ b/xmloff/source/style/shadwhdl.hxx @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PROPERTYHANDLER_SHADOWTYPES_HXX +#define _XMLOFF_PROPERTYHANDLER_SHADOWTYPES_HXX + +#include <xmloff/xmlprhdl.hxx> + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLShadowPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLShadowPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +#endif // _XMLOFF_PROPERTYHANDLER_BASICTYPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/shdwdhdl.cxx b/xmloff/source/style/shdwdhdl.cxx new file mode 100644 index 000000000000..c6e2279239db --- /dev/null +++ b/xmloff/source/style/shdwdhdl.cxx @@ -0,0 +1,87 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include "shdwdhdl.hxx" +#include <com/sun/star/uno/Any.hxx> +#include <rtl/ustrbuf.hxx> + +// -- +#include <xmloff/xmltoken.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star::uno; +using namespace ::xmloff::token; + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLFmtSplitPropHdl +// + +XMLShadowedPropHdl::~XMLShadowedPropHdl() +{ + // nothing to do +} + +sal_Bool XMLShadowedPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + sal_Bool bValue = ! IsXMLToken( rStrImpValue, XML_NONE ); + rValue <<= sal_Bool(bValue); + bRet = sal_True; + + return bRet; +} + +sal_Bool XMLShadowedPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + sal_Bool bValue = sal_Bool(); + + if (rValue >>= bValue) + { + if( bValue ) + { + rStrExpValue = OUString( RTL_CONSTASCII_USTRINGPARAM( "1pt 1pt" ) ); + } + else + { + rStrExpValue = GetXMLToken( XML_NONE ); + } + + bRet = sal_True; + } + + return bRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/shdwdhdl.hxx b/xmloff/source/style/shdwdhdl.hxx new file mode 100644 index 000000000000..aba2f6c2c67a --- /dev/null +++ b/xmloff/source/style/shdwdhdl.hxx @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PROPERTYHANDLER_SHADOWEDTYPES_HXX +#define _XMLOFF_PROPERTYHANDLER_SHADOWEDTYPES_HXX + +#include <xmloff/xmlprhdl.hxx> + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLShadowedPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLShadowedPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +#endif // _XMLOFF_PROPERTYHANDLER_SHADOWEDTYPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/styleexp.cxx b/xmloff/source/style/styleexp.cxx new file mode 100644 index 000000000000..81b8dd3409e4 --- /dev/null +++ b/xmloff/source/style/styleexp.cxx @@ -0,0 +1,526 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#ifndef _SVSTDARR_STRINGSSORTDTOR_DECL +#define _SVSTDARR_STRINGSSORTDTOR +#include <svl/svstdarr.hxx> +#endif +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/attrlist.hxx> +#include <xmloff/xmlprmap.hxx> +#include <xmloff/xmlexppr.hxx> +#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XPropertyState.hpp> +#include <com/sun/star/document/XEventsSupplier.hpp> +#include <com/sun/star/text/XChapterNumberingSupplier.hpp> +#include <xmloff/xmlaustp.hxx> +#include <xmloff/styleexp.hxx> +#include <xmloff/xmlexp.hxx> +#include <xmloff/XMLEventExport.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::style; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::text; +using namespace ::xmloff::token; + +using ::com::sun::star::document::XEventsSupplier; + +XMLStyleExport::XMLStyleExport( + SvXMLExport& rExp, + const ::rtl::OUString& rPoolStyleName, + SvXMLAutoStylePoolP *pAutoStyleP ) : + rExport( rExp ), + sIsPhysical( RTL_CONSTASCII_USTRINGPARAM( "IsPhysical" ) ), + sIsAutoUpdate( RTL_CONSTASCII_USTRINGPARAM( "IsAutoUpdate" ) ), + sFollowStyle( RTL_CONSTASCII_USTRINGPARAM( "FollowStyle" ) ), + sNumberingStyleName( RTL_CONSTASCII_USTRINGPARAM( "NumberingStyleName" ) ), + sOutlineLevel( RTL_CONSTASCII_USTRINGPARAM( "OutlineLevel" ) ), + sPoolStyleName( rPoolStyleName ), + pAutoStylePool( pAutoStyleP ) +{ +} + +XMLStyleExport::~XMLStyleExport() +{ +} + +void XMLStyleExport::exportStyleAttributes( const Reference< XStyle >& ) +{ +} + +void XMLStyleExport::exportStyleContent( const Reference< XStyle >& ) +{ +} + +sal_Bool XMLStyleExport::exportStyle( + const Reference< XStyle >& rStyle, + const OUString& rXMLFamily, + const UniReference < SvXMLExportPropertyMapper >& rPropMapper, + const Reference< XNameAccess >& xStyles, + const OUString* pPrefix ) +{ + Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY ); + Reference< XPropertySetInfo > xPropSetInfo = + xPropSet->getPropertySetInfo(); + Any aAny; + + // Don't export styles that aren't existing really. This may be the + // case for StarOffice Writer's pool styles. + if( xPropSetInfo->hasPropertyByName( sIsPhysical ) ) + { + aAny = xPropSet->getPropertyValue( sIsPhysical ); + if( !*(sal_Bool *)aAny.getValue() ) + return sal_False; + } + + // <style:style ...> + GetExport().CheckAttrList(); + + // style:name="..." + OUString sName; + + if(pPrefix) + sName = *pPrefix; + sName += rStyle->getName(); + + sal_Bool bEncoded = sal_False; + const OUString sEncodedStyleName(GetExport().EncodeStyleName( sName, &bEncoded )); + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME, sEncodedStyleName ); + + if( bEncoded ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME, + sName); + + // style:family="..." + if( rXMLFamily.getLength() > 0 ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_FAMILY, rXMLFamily); + + // style:parent-style-name="..." + OUString sParentString(rStyle->getParentStyle()); + OUString sParent; + + if(sParentString.getLength()) + { + if(pPrefix) + sParent = *pPrefix; + sParent += sParentString; + } + else + sParent = sPoolStyleName; + + if( sParent.getLength() ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_PARENT_STYLE_NAME, + GetExport().EncodeStyleName( sParent ) ); + + // style:next-style-name="..." (paragraph styles only) + if( xPropSetInfo->hasPropertyByName( sFollowStyle ) ) + { + aAny = xPropSet->getPropertyValue( sFollowStyle ); + OUString sNextName; + aAny >>= sNextName; + if( sName != sNextName ) + { + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NEXT_STYLE_NAME, + GetExport().EncodeStyleName( sNextName ) ); + } + } + + // style:auto-update="..." (SW only) + if( xPropSetInfo->hasPropertyByName( sIsAutoUpdate ) ) + { + aAny = xPropSet->getPropertyValue( sIsAutoUpdate ); + if( *(sal_Bool *)aAny.getValue() ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_AUTO_UPDATE, + XML_TRUE ); + } + + // style:default-outline-level"..." + sal_Int32 nOutlineLevel = 0; + if( xPropSetInfo->hasPropertyByName( sOutlineLevel ) ) + { + Reference< XPropertyState > xPropState( xPropSet, uno::UNO_QUERY ); + if( PropertyState_DIRECT_VALUE == xPropState->getPropertyState( sOutlineLevel ) ) + { + aAny = xPropSet->getPropertyValue( sOutlineLevel ); + aAny >>= nOutlineLevel; + if( nOutlineLevel > 0 ) + { + OUStringBuffer sTmp; + sTmp.append( static_cast<sal_Int32>(nOutlineLevel)); + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_DEFAULT_OUTLINE_LEVEL, + sTmp.makeStringAndClear() ); + } + else + { + /* Empty value for style:default-outline-level does exist + since ODF 1.2. Thus, suppress its export for former versions. (#i104889#) + */ + if ( ( GetExport().getExportFlags() & EXPORT_OASIS ) != 0 && + GetExport().getDefaultVersion() >= SvtSaveOptions::ODFVER_012 ) + { + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_DEFAULT_OUTLINE_LEVEL, + OUString( RTL_CONSTASCII_USTRINGPARAM( "" ))); + } + } + } + } + + // style:list-style-name="..." (SW paragarph styles only) + if( xPropSetInfo->hasPropertyByName( sNumberingStyleName ) ) + { + Reference< XPropertyState > xPropState( xPropSet, uno::UNO_QUERY ); + if( PropertyState_DIRECT_VALUE == + xPropState->getPropertyState( sNumberingStyleName ) ) + { + aAny = xPropSet->getPropertyValue( sNumberingStyleName ); + if( aAny.hasValue() ) + { + OUString sListName; + aAny >>= sListName; + + /* An direct set empty list style has to be written. Otherwise, + this information is lost and causes an error, if the parent + style has a list style set. (#i69523#) + */ + if ( !sListName.getLength() ) + { + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_LIST_STYLE_NAME, + sListName /* empty string */); + } + else + { + // Written OpenDocument file format doesn't fit to the created text document (#i69627#) + bool bSuppressListStyle( false ); + { + if ( !GetExport().writeOutlineStyleAsNormalListStyle() ) + { + Reference< XChapterNumberingSupplier > xCNSupplier + (GetExport().GetModel(), UNO_QUERY); + + OUString sOutlineName; + if (xCNSupplier.is()) + { + Reference< XIndexReplace > xNumRule + ( xCNSupplier->getChapterNumberingRules() ); + DBG_ASSERT( xNumRule.is(), "no chapter numbering rules" ); + + if (xNumRule.is()) + { + Reference< XPropertySet > xNumRulePropSet + (xNumRule, UNO_QUERY); + xNumRulePropSet->getPropertyValue( + OUString(RTL_CONSTASCII_USTRINGPARAM("Name")) ) + >>= sOutlineName; + bSuppressListStyle = ( sListName == sOutlineName ); + } + } + } + } + + if ( sListName.getLength() && !bSuppressListStyle ) + { + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_LIST_STYLE_NAME, + GetExport().EncodeStyleName( sListName ) ); + } + } + } + } + else if( nOutlineLevel > 0 ) + { + + bool bNoInheritedListStyle( true ); + + ///////////////////////////////////////////////// + Reference<XStyle> xStyle( xPropState, UNO_QUERY ); + while ( xStyle.is() ) + { + OUString aParentStyle( xStyle->getParentStyle() ); + if ( aParentStyle.getLength() == 0 || + !xStyles->hasByName( aParentStyle ) ) + { + break; + } + else + { + xPropState = Reference< XPropertyState >( xStyles->getByName( aParentStyle ), UNO_QUERY ); + if ( !xPropState.is() ) + { + break; + } + if ( xPropState->getPropertyState( sNumberingStyleName ) == PropertyState_DIRECT_VALUE ) + { + bNoInheritedListStyle = false; + break; + } + else + { + xStyle = Reference<XStyle>( xPropState, UNO_QUERY ); + } + } + } + ///////////////////////////////////////////////// + if ( bNoInheritedListStyle ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_LIST_STYLE_NAME, + OUString( RTL_CONSTASCII_USTRINGPARAM( "" ))); + } + } + + // style:pool-id="..." is not required any longer since we use + // english style names only + exportStyleAttributes( rStyle ); + + // TODO: style:help-file-name="..." and style:help-id="..." can neither + // be modified by UI nor by API and that for, have not to be exported + // currently. + + { + // <style:style> + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, XML_STYLE, + sal_True, sal_True ); + + rPropMapper->SetStyleName( sName ); + + // <style:properties> + ::std::vector< XMLPropertyState > xPropStates = + rPropMapper->Filter( xPropSet ); + rPropMapper->exportXML( GetExport(), xPropStates, + XML_EXPORT_FLAG_IGN_WS ); + + rPropMapper->SetStyleName( OUString() ); + + exportStyleContent( rStyle ); + + // <script:events>, if they are supported by this style + Reference<XEventsSupplier> xEventsSupp(rStyle, UNO_QUERY); + GetExport().GetEventExport().Export(xEventsSupp); + } + return sal_True; +} + +sal_Bool XMLStyleExport::exportDefaultStyle( + const Reference< XPropertySet >& xPropSet, + const OUString& rXMLFamily, + const UniReference < SvXMLExportPropertyMapper >& rPropMapper ) +{ + Reference< XPropertySetInfo > xPropSetInfo = + xPropSet->getPropertySetInfo(); + + Any aAny; + + // <style:default-style ...> + GetExport().CheckAttrList(); + + { + // style:family="..." + if( rXMLFamily.getLength() > 0 ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_FAMILY, + rXMLFamily ); + // <style:style> + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, + XML_DEFAULT_STYLE, + sal_True, sal_True ); + // <style:properties> + ::std::vector< XMLPropertyState > xPropStates = + rPropMapper->FilterDefaults( xPropSet ); + rPropMapper->exportXML( GetExport(), xPropStates, + XML_EXPORT_FLAG_IGN_WS ); + } + return sal_True; +} + +void XMLStyleExport::exportStyleFamily( + const sal_Char *pFamily, + const OUString& rXMLFamily, + const UniReference < SvXMLExportPropertyMapper >& rPropMapper, + sal_Bool bUsed, sal_uInt16 nFamily, const OUString* pPrefix) +{ + const OUString sFamily(OUString::createFromAscii(pFamily )); + exportStyleFamily( sFamily, rXMLFamily, rPropMapper, bUsed, nFamily, + pPrefix); +} + +void XMLStyleExport::exportStyleFamily( + const OUString& rFamily, const OUString& rXMLFamily, + const UniReference < SvXMLExportPropertyMapper >& rPropMapper, + sal_Bool bUsed, sal_uInt16 nFamily, const OUString* pPrefix) +{ + DBG_ASSERT( GetExport().GetModel().is(), "There is the model?" ); + Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetExport().GetModel(), UNO_QUERY ); + if( !xFamiliesSupp.is() ) + return; // family not available in current model + + Reference< XNameAccess > xStyleCont; + + Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() ); + if( xFamilies->hasByName( rFamily ) ) + xFamilies->getByName( rFamily ) >>= xStyleCont; + + if( !xStyleCont.is() ) + return; + + Reference< XNameAccess > xStyles( xStyleCont, UNO_QUERY ); + // If next styles are supported and used styles should be exported only, + // the next style may be unused but has to be exported, too. In this case + // the names of all exported styles are remembered. + SvStringsSortDtor *pExportedStyles = 0; + sal_Bool bFirstStyle = sal_True; + + const uno::Sequence< ::rtl::OUString> aSeq = xStyles->getElementNames(); + const ::rtl::OUString* pIter = aSeq.getConstArray(); + const ::rtl::OUString* pEnd = pIter + aSeq.getLength(); + for(;pIter != pEnd;++pIter) + { + Reference< XStyle > xStyle; + try + { + xStyles->getByName( *pIter ) >>= xStyle; + } + catch( lang::IndexOutOfBoundsException ) + { + // due to bugs in prior versions it is possible that + // a binary file is missing some critical styles. + // The only possible way to deal with this is to + // not export them here and remain silent. + continue; + } + + DBG_ASSERT( xStyle.is(), "Style not found for export!" ); + if( xStyle.is() ) + { + if( !bUsed || xStyle->isInUse() ) + { + sal_Bool bExported = exportStyle( xStyle, rXMLFamily, rPropMapper, + xStyles,pPrefix ); + if( bUsed && bFirstStyle && bExported ) + { + // If this is the first style, find out wether next styles + // are supported. + Reference< XPropertySet > xPropSet( xStyle, UNO_QUERY ); + Reference< XPropertySetInfo > xPropSetInfo = + xPropSet->getPropertySetInfo(); + + if( xPropSetInfo->hasPropertyByName( sFollowStyle ) ) + pExportedStyles = new SvStringsSortDtor; + bFirstStyle = sal_False; + } + + if( pExportedStyles && bExported ) + { + // If next styles are supported, remember this style's name. + String *pTmp = new String( xStyle->getName() ); + if( !pExportedStyles->Insert( pTmp ) ) + delete pTmp; + } + } + + // if an auto style pool is given, remember this style's name as a + // style name that must not be used by automatic styles. + if( pAutoStylePool ) + pAutoStylePool->RegisterName( nFamily, xStyle->getName() ); + } + } + + if( pExportedStyles ) + { + // if next styles are supported, export all next styles that are + // unused and that for, haven't been exported in the first loop. + pIter = aSeq.getConstArray(); + for(;pIter != pEnd;++pIter) + { + Reference< XStyle > xStyle; + xStyles->getByName( *pIter ) >>= xStyle; + + DBG_ASSERT( xStyle.is(), "Style not found for export!" ); + if( xStyle.is() ) + { + Reference< XPropertySet > xPropSet( xStyle, UNO_QUERY ); + Reference< XPropertySetInfo > xPropSetInfo( xPropSet->getPropertySetInfo() ); + + // styles that aren't existing realy are ignored. + if( xPropSetInfo->hasPropertyByName( sIsPhysical ) ) + { + Any aAny( xPropSet->getPropertyValue( sIsPhysical ) ); + if( !*(sal_Bool *)aAny.getValue() ) + continue; + } + + if( !xStyle->isInUse() ) + continue; + + if( !xPropSetInfo->hasPropertyByName( sFollowStyle ) ) + { + DBG_ASSERT( 0==sFollowStyle.getLength(), + "no follow style???" ); + continue; + } + + OUString sNextName; + xPropSet->getPropertyValue( sFollowStyle ) >>= sNextName; + String sTmp( sNextName ); + // if the next style hasn't been exported by now, export it now + // and remember its name. + if( xStyle->getName() != sNextName && + !pExportedStyles->Seek_Entry( &sTmp ) ) + { + xStyleCont->getByName( sNextName ) >>= xStyle; + DBG_ASSERT( xStyle.is(), "Style not found for export!" ); + + if( xStyle.is() && exportStyle( xStyle, rXMLFamily, rPropMapper, xStyles,pPrefix ) ) + pExportedStyles->Insert( new String( sTmp ) ); + } + } + } + } + + delete pExportedStyles; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/tabsthdl.cxx b/xmloff/source/style/tabsthdl.cxx new file mode 100644 index 000000000000..c4e84b88858c --- /dev/null +++ b/xmloff/source/style/tabsthdl.cxx @@ -0,0 +1,94 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tabsthdl.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/style/TabStop.hpp> + +using namespace ::com::sun::star; + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLFontFamilyNamePropHdl +// + +XMLTabStopPropHdl::~XMLTabStopPropHdl() +{ + // Nothing to do +} + +bool XMLTabStopPropHdl::equals( const uno::Any& r1, const uno::Any& r2 ) const +{ + sal_Bool bEqual = sal_False; + + uno::Sequence< style::TabStop> aSeq1; + if( r1 >>= aSeq1 ) + { + uno::Sequence< style::TabStop> aSeq2; + if( r2 >>= aSeq2 ) + { + if( aSeq1.getLength() == aSeq2.getLength() ) + { + bEqual = sal_True; + if( aSeq1.getLength() > 0 ) + { + const style::TabStop* pTabs1 = aSeq1.getConstArray(); + const style::TabStop* pTabs2 = aSeq2.getConstArray(); + + int i=0; + + do + { + bEqual = ( pTabs1[i].Position == pTabs2[i].Position && + pTabs1[i].Alignment == pTabs2[i].Alignment && + pTabs1[i].DecimalChar == pTabs2[i].DecimalChar && + pTabs1[i].FillChar == pTabs2[i].FillChar ); + i++; + + } while( bEqual && i < aSeq1.getLength() ); + } + } + } + } + + return bEqual; +} + +sal_Bool XMLTabStopPropHdl::importXML( const ::rtl::OUString&, ::com::sun::star::uno::Any&, const SvXMLUnitConverter& ) const +{ + return sal_False; +} + +sal_Bool XMLTabStopPropHdl::exportXML( ::rtl::OUString&, const ::com::sun::star::uno::Any&, const SvXMLUnitConverter& ) const +{ + return sal_False; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/tabsthdl.hxx b/xmloff/source/style/tabsthdl.hxx new file mode 100644 index 000000000000..008cbcbf2291 --- /dev/null +++ b/xmloff/source/style/tabsthdl.hxx @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PROPERTYHANDLER_TABSTOPTYPES_HXX +#define _XMLOFF_PROPERTYHANDLER_TABSTOPTYPES_HXX + +#include <xmloff/xmlprhdl.hxx> + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLTabStopPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLTabStopPropHdl(); + + virtual bool equals( const ::com::sun::star::uno::Any& r1, const ::com::sun::star::uno::Any& r2 ) const; + + /// TabStops will be imported/exported as XML-Elements. So the Import/Export-work must be done at another place. + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +#endif // _XMLOFF_PROPERTYHANDLER_TABSTOPTYPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/undlihdl.cxx b/xmloff/source/style/undlihdl.cxx new file mode 100644 index 000000000000..85f72a06cdc8 --- /dev/null +++ b/xmloff/source/style/undlihdl.cxx @@ -0,0 +1,383 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <undlihdl.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <rtl/ustrbuf.hxx> + + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/awt/FontUnderline.hpp> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::awt; +using namespace ::xmloff::token; + +SvXMLEnumMapEntry const pXML_UnderlineType_Enum[] = +{ + { XML_NONE, FontUnderline::NONE }, + { XML_SINGLE, FontUnderline::SINGLE }, + { XML_DOUBLE, FontUnderline::DOUBLE }, + { XML_SINGLE, FontUnderline::DOTTED }, + { XML_SINGLE, FontUnderline::DASH }, + { XML_SINGLE, FontUnderline::LONGDASH }, + { XML_SINGLE, FontUnderline::DASHDOT }, + { XML_SINGLE, FontUnderline::DASHDOTDOT }, + { XML_SINGLE, FontUnderline::WAVE }, + { XML_SINGLE, FontUnderline::BOLD }, + { XML_SINGLE, FontUnderline::BOLDDOTTED }, + { XML_SINGLE, FontUnderline::BOLDDASH }, + { XML_SINGLE, FontUnderline::BOLDLONGDASH }, + { XML_SINGLE, FontUnderline::BOLDDASHDOT }, + { XML_SINGLE, FontUnderline::BOLDDASHDOTDOT }, + { XML_SINGLE, FontUnderline::BOLDWAVE }, + { XML_DOUBLE, FontUnderline::DOUBLEWAVE }, + { XML_SINGLE, FontUnderline::SMALLWAVE }, + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLEnumMapEntry const pXML_UnderlineStyle_Enum[] = +{ + { XML_NONE, FontUnderline::NONE }, + { XML_SOLID, FontUnderline::SINGLE }, + { XML_SOLID, FontUnderline::DOUBLE }, + { XML_DOTTED, FontUnderline::DOTTED }, + { XML_DASH, FontUnderline::DASH }, + { XML_LONG_DASH, FontUnderline::LONGDASH }, + { XML_DOT_DASH, FontUnderline::DASHDOT }, + { XML_DOT_DOT_DASH, FontUnderline::DASHDOTDOT }, + { XML_WAVE, FontUnderline::WAVE }, + { XML_SOLID, FontUnderline::BOLD }, + { XML_DOTTED, FontUnderline::BOLDDOTTED }, + { XML_DASH, FontUnderline::BOLDDASH }, + { XML_LONG_DASH, FontUnderline::BOLDLONGDASH }, + { XML_DOT_DASH, FontUnderline::BOLDDASHDOT }, + { XML_DOT_DOT_DASH, FontUnderline::BOLDDASHDOTDOT }, + { XML_WAVE, FontUnderline::BOLDWAVE }, + { XML_WAVE, FontUnderline::DOUBLEWAVE }, + { XML_SMALL_WAVE, FontUnderline::SMALLWAVE }, + { XML_TOKEN_INVALID, 0 } +}; + +SvXMLEnumMapEntry const pXML_UnderlineWidth_Enum[] = +{ + { XML_AUTO, FontUnderline::NONE }, + { XML_AUTO, FontUnderline::SINGLE }, + { XML_AUTO, FontUnderline::DOUBLE }, + { XML_AUTO, FontUnderline::DOTTED }, + { XML_AUTO, FontUnderline::DASH }, + { XML_AUTO, FontUnderline::LONGDASH }, + { XML_AUTO, FontUnderline::DASHDOT }, + { XML_AUTO, FontUnderline::DASHDOTDOT }, + { XML_AUTO, FontUnderline::WAVE }, + { XML_BOLD, FontUnderline::BOLD }, + { XML_BOLD, FontUnderline::BOLDDOTTED }, + { XML_BOLD, FontUnderline::BOLDDASH }, + { XML_BOLD, FontUnderline::BOLDLONGDASH }, + { XML_BOLD, FontUnderline::BOLDDASHDOT }, + { XML_BOLD, FontUnderline::BOLDDASHDOTDOT }, + { XML_BOLD, FontUnderline::BOLDWAVE }, + { XML_AUTO, FontUnderline::DOUBLEWAVE }, + { XML_THIN, FontUnderline::NONE }, + { XML_MEDIUM, FontUnderline::NONE }, + { XML_THICK, FontUnderline::BOLD}, + { XML_TOKEN_INVALID, 0 } +}; + + + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLUnderlineTypePropHdl +// + +XMLUnderlineTypePropHdl::~XMLUnderlineTypePropHdl() +{ + // nothing to do +} + +sal_Bool XMLUnderlineTypePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_uInt16 eNewUnderline; + sal_Bool bRet = SvXMLUnitConverter::convertEnum( + eNewUnderline, rStrImpValue, pXML_UnderlineType_Enum ); + if( bRet ) + { + // multi property: style and width might be set already. + // If the old value is NONE, the new is used unchanged. + sal_Int16 eUnderline = sal_Int16(); + if( (rValue >>= eUnderline) && FontUnderline::NONE!=eUnderline ) + { + switch( eNewUnderline ) + { + case FontUnderline::NONE: + case FontUnderline::SINGLE: + // keep existing line style + eNewUnderline = eUnderline; + break; + case FontUnderline::DOUBLE: + // A double line style has priority over a bold line style, + // but not over the line style itself. + switch( eUnderline ) + { + case FontUnderline::SINGLE: + case FontUnderline::BOLD: + break; + case FontUnderline::WAVE: + case FontUnderline::BOLDWAVE: + eNewUnderline = FontUnderline::DOUBLEWAVE; + break; + default: + // If a double line style is not supported for the existing + // value, keep the new one + eNewUnderline = eUnderline; + break; + } + break; + default: + OSL_ENSURE( bRet, "unexpected line type value" ); + break; + } + if( eNewUnderline != eUnderline ) + rValue <<= (sal_Int16)eNewUnderline; + } + else + { + rValue <<= (sal_Int16)eNewUnderline; + } + } + + return bRet; +} + +sal_Bool XMLUnderlineTypePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + sal_Int16 nValue = sal_Int16(); + OUStringBuffer aOut; + + if( (rValue >>= nValue) && + (FontUnderline::DOUBLE == nValue || + FontUnderline::DOUBLEWAVE == nValue) ) + { + bRet = SvXMLUnitConverter::convertEnum( + aOut, (sal_uInt16)nValue, pXML_UnderlineType_Enum ); + if( bRet ) + rStrExpValue = aOut.makeStringAndClear(); + } + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLUnderlineStylePropHdl +// + +XMLUnderlineStylePropHdl::~XMLUnderlineStylePropHdl() +{ + // nothing to do +} + +sal_Bool XMLUnderlineStylePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_uInt16 eNewUnderline; + sal_Bool bRet = SvXMLUnitConverter::convertEnum( + eNewUnderline, rStrImpValue, pXML_UnderlineStyle_Enum ); + if( bRet ) + { + // multi property: style and width might be set already. + // If the old value is NONE, the new is used unchanged. + sal_Int16 eUnderline = sal_Int16(); + if( (rValue >>= eUnderline) && FontUnderline::NONE!=eUnderline ) + { + switch( eNewUnderline ) + { + case FontUnderline::NONE: + case FontUnderline::SINGLE: + // keep double or bold line style + eNewUnderline = eUnderline; + case FontUnderline::DOTTED: + // The line style has priority over a double type. + if( FontUnderline::BOLD == eUnderline ) + eNewUnderline = FontUnderline::BOLDDOTTED; + break; + case FontUnderline::DASH: + if( FontUnderline::BOLD == eUnderline ) + eNewUnderline = FontUnderline::BOLDDASH; + break; + case FontUnderline::LONGDASH: + if( FontUnderline::BOLD == eUnderline ) + eNewUnderline = FontUnderline::BOLDLONGDASH; + break; + case FontUnderline::DASHDOT: + if( FontUnderline::BOLD == eUnderline ) + eNewUnderline = FontUnderline::BOLDDASHDOT; + break; + case FontUnderline::DASHDOTDOT: + if( FontUnderline::BOLD == eUnderline ) + eNewUnderline = FontUnderline::BOLDDASHDOTDOT; + break; + case FontUnderline::WAVE: + if( FontUnderline::BOLD == eUnderline ) + eNewUnderline = FontUnderline::BOLDWAVE; + break; + case FontUnderline::SMALLWAVE: + // SMALLWAVE is not used + default: + OSL_ENSURE( bRet, "unexpected line style value" ); + break; + } + if( eNewUnderline != eUnderline ) + rValue <<= (sal_Int16)eNewUnderline; + } + else + { + rValue <<= (sal_Int16)eNewUnderline; + } + } + + return bRet; +} + +sal_Bool XMLUnderlineStylePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + sal_Int16 nValue = sal_Int16(); + OUStringBuffer aOut; + + if( rValue >>= nValue ) + { + bRet = SvXMLUnitConverter::convertEnum( + aOut, (sal_uInt16)nValue, pXML_UnderlineStyle_Enum ); + if( bRet ) + rStrExpValue = aOut.makeStringAndClear(); + } + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLUnderlineWidthPropHdl +// + +XMLUnderlineWidthPropHdl::~XMLUnderlineWidthPropHdl() +{ + // nothing to do +} + +sal_Bool XMLUnderlineWidthPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_uInt16 eNewUnderline; + sal_Bool bRet = SvXMLUnitConverter::convertEnum( + eNewUnderline, rStrImpValue, pXML_UnderlineWidth_Enum ); + if( bRet ) + { + // multi property: style and width might be set already. + // If the old value is NONE, the new is used unchanged. + sal_Int16 eUnderline = sal_Int16(); + if( (rValue >>= eUnderline) && FontUnderline::NONE!=eUnderline ) + { + switch( eNewUnderline ) + { + case FontUnderline::NONE: + // keep existing line style + eNewUnderline = eUnderline; + break; + case FontUnderline::BOLD: + // A double line style has priority over a bold line style, + // but not over the line style itself. + switch( eUnderline ) + { + case FontUnderline::SINGLE: + break; + case FontUnderline::DOTTED: + eNewUnderline = FontUnderline::BOLDDOTTED; + break; + case FontUnderline::DASH: + eNewUnderline = FontUnderline::BOLDDASH; + break; + case FontUnderline::LONGDASH: + eNewUnderline = FontUnderline::BOLDLONGDASH; + break; + case FontUnderline::DASHDOT: + eNewUnderline = FontUnderline::BOLDDASHDOT; + break; + case FontUnderline::DASHDOTDOT: + eNewUnderline = FontUnderline::BOLDDASHDOTDOT; + break; + case FontUnderline::WAVE: + eNewUnderline = FontUnderline::BOLDWAVE; + break; + default: + // a doube line style overwrites a bold one + eNewUnderline = eUnderline; + break; + } + break; + default: + OSL_ENSURE( bRet, "unexpected line width value" ); + break; + } + if( eNewUnderline != eUnderline ) + rValue <<= (sal_Int16)eNewUnderline; + } + else + { + rValue <<= (sal_Int16)eNewUnderline; + } + } + + return bRet; +} + +sal_Bool XMLUnderlineWidthPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + sal_Int16 nValue = sal_Int16(); + OUStringBuffer aOut; + + if( (rValue >>= nValue) && (FontUnderline::NONE != nValue) ) + { + bRet = SvXMLUnitConverter::convertEnum( + aOut, (sal_uInt16)nValue, pXML_UnderlineWidth_Enum ); + if( bRet ) + rStrExpValue = aOut.makeStringAndClear(); + } + + return bRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/undlihdl.hxx b/xmloff/source/style/undlihdl.hxx new file mode 100644 index 000000000000..60818cc35657 --- /dev/null +++ b/xmloff/source/style/undlihdl.hxx @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PROPERTYHANDLER_UNDERLINETYPES_HXX +#define _XMLOFF_PROPERTYHANDLER_UNDERLINETYPES_HXX + +#include <xmloff/xmlprhdl.hxx> + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLUnderlineTypePropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLUnderlineTypePropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +class XMLUnderlineStylePropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLUnderlineStylePropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +class XMLUnderlineWidthPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLUnderlineWidthPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +#endif // _XMLOFF_PROPERTYHANDLER_UNDERLINETYPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/uniref.cxx b/xmloff/source/style/uniref.cxx new file mode 100644 index 000000000000..342df9fa1a51 --- /dev/null +++ b/xmloff/source/style/uniref.cxx @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <xmloff/uniref.hxx> + +UniRefBase::~UniRefBase() +{ +} + +void UniRefBase::release() +{ + if( !osl_decrementInterlockedCount( &m_refCount ) ) + delete this; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/weighhdl.cxx b/xmloff/source/style/weighhdl.cxx new file mode 100644 index 000000000000..9955d446e66f --- /dev/null +++ b/xmloff/source/style/weighhdl.cxx @@ -0,0 +1,177 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <weighhdl.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <tools/fontenum.hxx> +#include <tools/solar.h> + +#ifndef _INC_LIMITS +#include <limits.h> +#endif +#include <rtl/ustrbuf.hxx> +#include <rtl/ustring.hxx> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/awt/FontWeight.hpp> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star::uno; +using namespace ::xmloff::token; + +struct FontWeightMapper +{ + float fWeight; + sal_uInt16 nValue; +}; + +FontWeightMapper const aFontWeightMap[] = +{ + { ::com::sun::star::awt::FontWeight::DONTKNOW, 0 }, + { ::com::sun::star::awt::FontWeight::THIN, 100 }, + { ::com::sun::star::awt::FontWeight::ULTRALIGHT, 150 }, + { ::com::sun::star::awt::FontWeight::LIGHT, 250 }, + { ::com::sun::star::awt::FontWeight::SEMILIGHT, 350 }, + { ::com::sun::star::awt::FontWeight::NORMAL, 400 }, + { ::com::sun::star::awt::FontWeight::NORMAL, 450 }, + { ::com::sun::star::awt::FontWeight::SEMIBOLD, 600 }, + { ::com::sun::star::awt::FontWeight::BOLD, 700 }, + { ::com::sun::star::awt::FontWeight::ULTRABOLD, 800 }, + { ::com::sun::star::awt::FontWeight::BLACK, 900 }, + { ::com::sun::star::awt::FontWeight::DONTKNOW, 1000 } +}; + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLFmtBreakBeforePropHdl +// + +XMLFontWeightPropHdl::~XMLFontWeightPropHdl() +{ + // Nothing to do +} + +sal_Bool XMLFontWeightPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + sal_uInt16 nWeight = 0; + + if( IsXMLToken( rStrImpValue, XML_WEIGHT_NORMAL ) ) + { + nWeight = 400; + bRet = sal_True; + } + else if( IsXMLToken( rStrImpValue, XML_WEIGHT_BOLD ) ) + { + nWeight = 700; + bRet = sal_True; + } + else + { + sal_Int32 nTemp; + bRet = SvXMLUnitConverter::convertNumber( nTemp, rStrImpValue, 100, 900 ); + if( bRet ) + nWeight = sal::static_int_cast< sal_uInt16 >(nTemp); + } + + if( bRet ) + { + bRet = sal_False; + static int nCount = sizeof(aFontWeightMap)/sizeof(FontWeightMapper); + for( int i=0; i<nCount; i++ ) + { + if( (nWeight >= aFontWeightMap[i].nValue) && (nWeight <= aFontWeightMap[i+1].nValue) ) + { + sal_uInt16 nDiff1 = nWeight - aFontWeightMap[i].nValue; + sal_uInt16 nDiff2 = aFontWeightMap[i+1].nValue - nWeight; + + if( nDiff1 < nDiff2 ) + rValue <<= aFontWeightMap[i].fWeight; + else + rValue <<= aFontWeightMap[i+1].fWeight; + + bRet = sal_True; + break; + } + } + } + + return bRet; +} + +sal_Bool XMLFontWeightPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + float fValue = float(); + if( !( rValue >>= fValue ) ) + { + sal_Int32 nValue = 0; + if( rValue >>= nValue ) + { + fValue = (float)nValue; + bRet = sal_True; + } + } + else + bRet = sal_True; + + if( bRet ) + { + sal_uInt16 nWeight = 0; + static int nCount = sizeof(aFontWeightMap)/sizeof(FontWeightMapper); + for( int i=0; i<nCount; i++ ) + { + if( fValue <= aFontWeightMap[i].fWeight ) + { + nWeight = aFontWeightMap[i].nValue; + break; + } + } + + OUStringBuffer aOut; + + if( 400 == nWeight ) + aOut.append( GetXMLToken(XML_WEIGHT_NORMAL) ); + else if( 700 == nWeight ) + aOut.append( GetXMLToken(XML_WEIGHT_BOLD) ); + else + SvXMLUnitConverter::convertNumber( aOut, (sal_Int32)nWeight ); + + rStrExpValue = aOut.makeStringAndClear(); + } + + return bRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/weighhdl.hxx b/xmloff/source/style/weighhdl.hxx new file mode 100644 index 000000000000..5ac66dd18aff --- /dev/null +++ b/xmloff/source/style/weighhdl.hxx @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PROPERTYHANDLER_FONTWEIGHTTYPES_HXX +#define _XMLOFF_PROPERTYHANDLER_FONTWEIGHTTYPES_HXX + +#include <xmloff/xmlprhdl.hxx> + +/** + PropertyHandler for the XML-data-type: +*/ +class XMLFontWeightPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLFontWeightPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + + +#endif // _XMLOFF_PROPERTYHANDLER_FONTWEIGHTTYPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/xmlaustp.cxx b/xmloff/source/style/xmlaustp.cxx new file mode 100644 index 000000000000..669a4a169531 --- /dev/null +++ b/xmloff/source/style/xmlaustp.cxx @@ -0,0 +1,449 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + + +#include <com/sun/star/container/XIndexReplace.hpp> +#include <tools/debug.hxx> +#include "impastpl.hxx" +#include <xmloff/xmlaustp.hxx> +#include <xmloff/families.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlexp.hxx> +#include "xmloff/XMLTextListAutoStylePool.hxx" + +#include <xmloff/PageMasterStyleMap.hxx> +#include "PageMasterExportPropMapper.hxx" +#include "XMLBackgroundImageExport.hxx" + + +using namespace ::std; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::xmloff::token; + + +namespace +{ + static void lcl_exportDataStyle( SvXMLExport& _rExport, const UniReference< XMLPropertySetMapper >& _rxMapper, + const XMLPropertyState& _rProperty ) + { + DBG_ASSERT( _rxMapper.is(), "xmloff::lcl_exportDataStyle: invalid property mapper!" ); + // obtain the data style name + ::rtl::OUString sDataStyleName; + _rProperty.maValue >>= sDataStyleName; + DBG_ASSERT( sDataStyleName.getLength(), "xmloff::lcl_exportDataStyle: invalid property value for the data style name!" ); + + // add the attribute + _rExport.AddAttribute( + _rxMapper->GetEntryNameSpace( _rProperty.mnIndex ), + _rxMapper->GetEntryXMLName( _rProperty.mnIndex ), + sDataStyleName ); + } +} + +void SvXMLAutoStylePoolP::exportStyleAttributes( + SvXMLAttributeList&, + sal_Int32 nFamily, + const vector< XMLPropertyState >& rProperties, + const SvXMLExportPropertyMapper& rPropExp, + const SvXMLUnitConverter&, + const SvXMLNamespaceMap& + ) const +{ + if ( XML_STYLE_FAMILY_CONTROL_ID == nFamily ) + { // it's a control-related style + UniReference< XMLPropertySetMapper > aPropertyMapper = rPropExp.getPropertySetMapper(); + + for ( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin(); + pProp != rProperties.end(); + ++pProp + ) + { + if ( ( pProp->mnIndex > -1 ) + && ( CTF_FORMS_DATA_STYLE == aPropertyMapper->GetEntryContextId( pProp->mnIndex ) ) + ) + { // it's the data-style for a grid column + lcl_exportDataStyle( GetExport(), aPropertyMapper, *pProp ); + } + } + } + + if( (XML_STYLE_FAMILY_SD_GRAPHICS_ID == nFamily) || (XML_STYLE_FAMILY_SD_PRESENTATION_ID == nFamily) ) + { // it's a graphics style + UniReference< XMLPropertySetMapper > aPropertyMapper = rPropExp.getPropertySetMapper(); + DBG_ASSERT(aPropertyMapper.is(), "SvXMLAutoStylePoolP::exportStyleAttributes: invalid property set mapper!"); + + sal_Bool bFoundControlShapeDataStyle = sal_False; + sal_Bool bFoundNumberingRulesName = sal_False; + + for ( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin(); + pProp != rProperties.end(); + ++pProp + ) + { + if (pProp->mnIndex > -1) + { // it's a valid property + switch( aPropertyMapper->GetEntryContextId(pProp->mnIndex) ) + { + case CTF_SD_CONTROL_SHAPE_DATA_STYLE: + { // it's the control shape data style property + + if (bFoundControlShapeDataStyle) + { + OSL_FAIL("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the ControlShapeDataStyle context id!"); + // already added the attribute for the first occurrence + break; + } + + lcl_exportDataStyle( GetExport(), aPropertyMapper, *pProp ); + + // check if there is another property with the special context id we're handling here + bFoundControlShapeDataStyle = sal_True; + break; + } + case CTF_SD_NUMBERINGRULES_NAME: + { + if (bFoundNumberingRulesName) + { + OSL_FAIL("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the numbering rules name context id!"); + // already added the attribute for the first occurrence + break; + } + + uno::Reference< container::XIndexReplace > xNumRule; + pProp->maValue >>= xNumRule; + if( xNumRule.is() && (xNumRule->getCount() > 0 ) ) + { + const OUString sName(((XMLTextListAutoStylePool*)&GetExport().GetTextParagraphExport()->GetListAutoStylePool())->Add( xNumRule )); + + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_LIST_STYLE_NAME, GetExport().EncodeStyleName( sName ) ); + } + + bFoundNumberingRulesName = sal_True; + break; + } + } + } + } + } + + if( nFamily == XML_STYLE_FAMILY_PAGE_MASTER ) + { + for( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin(); pProp != rProperties.end(); ++pProp ) + { + if (pProp->mnIndex > -1) + { + UniReference< XMLPropertySetMapper > aPropMapper = rPropExp.getPropertySetMapper(); + sal_Int32 nIndex = pProp->mnIndex; + sal_Int16 nContextID = aPropMapper->GetEntryContextId( nIndex ); + switch( nContextID ) + { + case CTF_PM_PAGEUSAGE: + { + OUString sValue; + const XMLPropertyHandler* pPropHdl = aPropMapper->GetPropertyHandler( nIndex ); + if( pPropHdl && + pPropHdl->exportXML( sValue, pProp->maValue, + GetExport().GetMM100UnitConverter() ) && + ( ! IsXMLToken( sValue, XML_ALL ) ) ) + { + GetExport().AddAttribute( aPropMapper->GetEntryNameSpace( nIndex ), aPropMapper->GetEntryXMLName( nIndex ), sValue ); + } + } + break; + } + } + } + } +} + +void SvXMLAutoStylePoolP::exportStyleContent( + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > &, + sal_Int32 nFamily, + const vector< XMLPropertyState >& rProperties, + const SvXMLExportPropertyMapper& rPropExp, + const SvXMLUnitConverter&, + const SvXMLNamespaceMap& + ) const +{ + if( nFamily == XML_STYLE_FAMILY_PAGE_MASTER ) + { + OUString sWS( GetXMLToken(XML_WS) ); + + sal_Int32 nHeaderStartIndex(-1); + sal_Int32 nHeaderEndIndex(-1); + sal_Int32 nFooterStartIndex(-1); + sal_Int32 nFooterEndIndex(-1); + sal_Bool bHeaderStartIndex(sal_False); + sal_Bool bHeaderEndIndex(sal_False); + sal_Bool bFooterStartIndex(sal_False); + sal_Bool bFooterEndIndex(sal_False); + + UniReference< XMLPropertySetMapper > aPropMapper = rPropExp.getPropertySetMapper(); + + sal_Int32 nIndex(0); + while(nIndex < aPropMapper->GetEntryCount()) + { + switch( aPropMapper->GetEntryContextId( nIndex ) & CTF_PM_FLAGMASK ) + { + case CTF_PM_HEADERFLAG: + { + if (!bHeaderStartIndex) + { + nHeaderStartIndex = nIndex; + bHeaderStartIndex = sal_True; + } + if (bFooterStartIndex && !bFooterEndIndex) + { + nFooterEndIndex = nIndex; + bFooterEndIndex = sal_True; + } + } + break; + case CTF_PM_FOOTERFLAG: + { + if (!bFooterStartIndex) + { + nFooterStartIndex = nIndex; + bFooterStartIndex = sal_True; + } + if (bHeaderStartIndex && !bHeaderEndIndex) + { + nHeaderEndIndex = nIndex; + bHeaderEndIndex = sal_True; + } + } + break; + } + nIndex++; + } + if (!bHeaderEndIndex) + nHeaderEndIndex = nIndex; + if (!bFooterEndIndex) + nFooterEndIndex = nIndex; + + // export header style element + { + SvXMLElementExport aElem( + GetExport(), XML_NAMESPACE_STYLE, XML_HEADER_STYLE, + sal_True, sal_True ); + + rPropExp.exportXML( + GetExport(), rProperties, + nHeaderStartIndex, nHeaderEndIndex, XML_EXPORT_FLAG_IGN_WS); + } + + // export footer style + { + SvXMLElementExport aElem( + GetExport(), XML_NAMESPACE_STYLE, XML_FOOTER_STYLE, + sal_True, sal_True ); + + rPropExp.exportXML( + GetExport(), rProperties, + nFooterStartIndex, nFooterEndIndex, XML_EXPORT_FLAG_IGN_WS); + } + } +} + +SvXMLAutoStylePoolP::SvXMLAutoStylePoolP() +{ + OSL_FAIL("This constuctor is obsoleted and should not be used!"); + pImpl = NULL; +} + +SvXMLAutoStylePoolP::SvXMLAutoStylePoolP( SvXMLExport& rExport ) +{ + pImpl = new SvXMLAutoStylePoolP_Impl( rExport ); +} + +SvXMLAutoStylePoolP::~SvXMLAutoStylePoolP() +{ + delete pImpl; +} + +SvXMLExport& SvXMLAutoStylePoolP::GetExport() const +{ + return pImpl->GetExport(); +} + +// TODO: romove this +void SvXMLAutoStylePoolP::AddFamily( + sal_Int32 nFamily, + const OUString& rStrName, + SvXMLExportPropertyMapper* pMapper, + OUString aStrPrefix, + sal_Bool bAsFamily ) +{ + UniReference <SvXMLExportPropertyMapper> xTmp = pMapper; + AddFamily( nFamily, rStrName, xTmp, aStrPrefix, bAsFamily ); +} + +void SvXMLAutoStylePoolP::AddFamily( + sal_Int32 nFamily, + const OUString& rStrName, + const UniReference < SvXMLExportPropertyMapper > & rMapper, + const OUString& rStrPrefix, + sal_Bool bAsFamily ) +{ + pImpl->AddFamily( nFamily, rStrName, rMapper, rStrPrefix, bAsFamily ); +} + +void SvXMLAutoStylePoolP::RegisterName( sal_Int32 nFamily, + const OUString& rName ) +{ + pImpl->RegisterName( nFamily, rName ); +} + +void SvXMLAutoStylePoolP::GetRegisteredNames( + uno::Sequence<sal_Int32>& rFamilies, + uno::Sequence<OUString>& rNames ) +{ + pImpl->GetRegisteredNames( rFamilies, rNames ); +} + +void SvXMLAutoStylePoolP::RegisterNames( + uno::Sequence<sal_Int32>& aFamilies, + uno::Sequence<OUString>& aNames ) +{ + DBG_ASSERT( aFamilies.getLength() == aNames.getLength(), + "aFamilies != aNames" ); + + // iterate over sequence(s) and call RegisterName(..) for each pair + const sal_Int32* pFamilies = aFamilies.getConstArray(); + const OUString* pNames = aNames.getConstArray(); + sal_Int32 nCount = min( aFamilies.getLength(), aNames.getLength() ); + for( sal_Int32 n = 0; n < nCount; n++ ) + RegisterName( pFamilies[n], pNames[n] ); +} + +OUString SvXMLAutoStylePoolP::Add( sal_Int32 nFamily, + const vector< XMLPropertyState >& rProperties ) +{ + OUString sEmpty; + OUString sName; + pImpl->Add(sName, nFamily, sEmpty, rProperties ); + return sName; +} + +OUString SvXMLAutoStylePoolP::Add( sal_Int32 nFamily, + const OUString& rParent, + const vector< XMLPropertyState >& rProperties, bool bDontSeek ) +{ + OUString sName; + pImpl->Add(sName, nFamily, rParent, rProperties, sal_False, bDontSeek ); + return sName; +} + +sal_Bool SvXMLAutoStylePoolP::Add(OUString& rName, sal_Int32 nFamily, const ::std::vector< XMLPropertyState >& rProperties ) +{ + OUString sEmpty; + return pImpl->Add(rName, nFamily, sEmpty, rProperties); +} + +sal_Bool SvXMLAutoStylePoolP::Add(OUString& rName, sal_Int32 nFamily, const OUString& rParent, const ::std::vector< XMLPropertyState >& rProperties ) +{ + return pImpl->Add(rName, nFamily, rParent, rProperties); +} + +sal_Bool SvXMLAutoStylePoolP::AddNamed( const OUString& rName, sal_Int32 nFamily, const OUString& rParent, + const ::std::vector< XMLPropertyState >& rProperties ) + +{ + return pImpl->AddNamed(rName, nFamily, rParent, rProperties); +} + +OUString SvXMLAutoStylePoolP::AddAndCache( sal_Int32 nFamily, + const vector< XMLPropertyState >& rProperties ) +{ + OUString sEmpty; + OUString sName; + pImpl->Add(sName, nFamily, sEmpty, rProperties, sal_True ); + return sName; +} + +OUString SvXMLAutoStylePoolP::AddAndCache( sal_Int32 nFamily, + const OUString& rParent, + const vector< XMLPropertyState >& rProperties ) +{ + OUString sName; + pImpl->Add(sName, nFamily, rParent, rProperties, sal_True ); + return sName; +} + +OUString SvXMLAutoStylePoolP::AddAndCache( sal_Int32 nFamily, + const OUString& rParent ) +{ + return pImpl->AddToCache( nFamily, rParent ); +} + +OUString SvXMLAutoStylePoolP::Find( sal_Int32 nFamily, + const vector< XMLPropertyState >& rProperties ) const +{ + OUString sEmpty; + return pImpl->Find( nFamily, sEmpty, rProperties ); +} + +OUString SvXMLAutoStylePoolP::Find( sal_Int32 nFamily, + const OUString& rParent, + const vector< XMLPropertyState >& rProperties ) const +{ + return pImpl->Find( nFamily, rParent, rProperties ); +} + +OUString SvXMLAutoStylePoolP::FindAndRemoveCached( sal_Int32 nFamily ) const +{ + return pImpl->FindAndRemoveCached( nFamily ); +} + + +void SvXMLAutoStylePoolP::exportXML( sal_Int32 nFamily, + const uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > &, + const SvXMLUnitConverter&, + const SvXMLNamespaceMap& + ) const +{ + pImpl->exportXML( nFamily, + GetExport().GetDocHandler(), + GetExport().GetMM100UnitConverter(), + GetExport().GetNamespaceMap(), + this); +} + +void SvXMLAutoStylePoolP::ClearEntries() +{ + pImpl->ClearEntries(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/xmlbahdl.cxx b/xmloff/source/style/xmlbahdl.cxx new file mode 100644 index 000000000000..af4fcaba8f3c --- /dev/null +++ b/xmloff/source/style/xmlbahdl.cxx @@ -0,0 +1,946 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include <xmlbahdl.hxx> +#include <xmloff/xmluconv.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <xmloff/xmltoken.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star::uno; +using namespace ::xmloff::token; + +void lcl_xmloff_setAny( Any& rValue, sal_Int32 nValue, sal_Int8 nBytes ) +{ + switch( nBytes ) + { + case 1: + if( nValue < SCHAR_MIN ) + nValue = SCHAR_MIN; + else if( nValue > SCHAR_MAX ) + nValue = SCHAR_MAX; + rValue <<= (sal_Int8)nValue; + break; + case 2: + if( nValue < SHRT_MIN ) + nValue = SHRT_MIN; + else if( nValue > SHRT_MAX ) + nValue = SHRT_MAX; + rValue <<= (sal_Int16)nValue; + break; + case 4: + rValue <<= nValue; + break; + } +} + +sal_Bool lcl_xmloff_getAny( const Any& rValue, sal_Int32& nValue, + sal_Int8 nBytes ) +{ + sal_Bool bRet = sal_False; + + switch( nBytes ) + { + case 1: + { + sal_Int8 nValue8 = 0; + bRet = rValue >>= nValue8; + nValue = nValue8; + } + break; + case 2: + { + sal_Int16 nValue16 = 0; + bRet = rValue >>= nValue16; + nValue = nValue16; + } + break; + case 4: + bRet = rValue >>= nValue; + break; + } + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLNumberPropHdl +// + +XMLNumberPropHdl::~XMLNumberPropHdl() +{ + // nothing to do +} + +sal_Bool XMLNumberPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + sal_Int32 nValue = 0; + bRet = SvXMLUnitConverter::convertNumber( nValue, rStrImpValue ); + lcl_xmloff_setAny( rValue, nValue, nBytes ); + + return bRet; +} + +sal_Bool XMLNumberPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + sal_Int32 nValue; + OUStringBuffer aOut; + + if( lcl_xmloff_getAny( rValue, nValue, nBytes ) ) + { + SvXMLUnitConverter::convertNumber( aOut, nValue ); + rStrExpValue = aOut.makeStringAndClear(); + + bRet = sal_True; + } + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// class XMLNumberNonePropHdl +// + +XMLNumberNonePropHdl::XMLNumberNonePropHdl( sal_Int8 nB ) : + sZeroStr( GetXMLToken(XML_NO_LIMIT) ), + nBytes( nB ) +{ +} + +XMLNumberNonePropHdl::XMLNumberNonePropHdl( enum XMLTokenEnum eZeroString, sal_Int8 nB ) : + sZeroStr( GetXMLToken( eZeroString ) ), + nBytes( nB ) +{ +} + +XMLNumberNonePropHdl::~XMLNumberNonePropHdl() +{ + // nothing to do +} + +sal_Bool XMLNumberNonePropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + sal_Int32 nValue = 0; + if( rStrImpValue == sZeroStr ) + { + bRet = sal_True; + } + else + { + bRet = SvXMLUnitConverter::convertNumber( nValue, rStrImpValue ); + } + lcl_xmloff_setAny( rValue, nValue, nBytes ); + + return bRet; +} + +sal_Bool XMLNumberNonePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + sal_Int32 nValue; + + if( lcl_xmloff_getAny( rValue, nValue, nBytes ) ) + { + OUStringBuffer aOut; + + if( nValue == 0 ) + { + aOut.append( sZeroStr ); + } + else + { + SvXMLUnitConverter::convertNumber( aOut, nValue ); + } + + rStrExpValue = aOut.makeStringAndClear(); + + bRet = sal_True; + } + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLMeasurePropHdl +// + +XMLMeasurePropHdl::~XMLMeasurePropHdl() +{ + // nothing to do +} + +sal_Bool XMLMeasurePropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const +{ + sal_Bool bRet = sal_False; + + sal_Int32 nValue = 0; + bRet = rUnitConverter.convertMeasure( nValue, rStrImpValue ); + lcl_xmloff_setAny( rValue, nValue, nBytes ); + + return bRet; +} + +sal_Bool XMLMeasurePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const +{ + sal_Bool bRet = sal_False; + sal_Int32 nValue; + OUStringBuffer aOut; + + if( lcl_xmloff_getAny( rValue, nValue, nBytes ) ) + { + rUnitConverter.convertMeasure( aOut, nValue ); + rStrExpValue = aOut.makeStringAndClear(); + + bRet = sal_True; + } + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLBoolPropHdl +// + +XMLBoolPropHdl::~XMLBoolPropHdl() +{ + // nothing to do +} + +sal_Bool XMLBoolPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + bool bValue; + bRet = SvXMLUnitConverter::convertBool( bValue, rStrImpValue ); + rValue <<= sal_Bool(bValue); + + return bRet; +} + +sal_Bool XMLBoolPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + OUStringBuffer aOut; + sal_Bool bValue = sal_Bool(); + + if (rValue >>= bValue) + { + SvXMLUnitConverter::convertBool( aOut, bValue ); + rStrExpValue = aOut.makeStringAndClear(); + + bRet = sal_True; + } + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLNBoolPropHdl +// + +XMLNBoolPropHdl::~XMLNBoolPropHdl() +{ + // nothing to do +} + +sal_Bool XMLNBoolPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + bool bValue; + bRet = SvXMLUnitConverter::convertBool( bValue, rStrImpValue ); + rValue <<= sal_Bool(!bValue); + + return bRet; +} + +sal_Bool XMLNBoolPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + OUStringBuffer aOut; + sal_Bool bValue = sal_Bool(); + + if (rValue >>= bValue) + { + SvXMLUnitConverter::convertBool( aOut, !bValue ); + rStrExpValue = aOut.makeStringAndClear(); + + bRet = sal_True; + } + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLPercentPropHdl +// + +XMLPercentPropHdl::~XMLPercentPropHdl() +{ + // nothing to do +} + +sal_Bool XMLPercentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + sal_Int32 nValue = 0; + bRet = SvXMLUnitConverter::convertPercent( nValue, rStrImpValue ); + lcl_xmloff_setAny( rValue, nValue, nBytes ); + + return bRet; +} + +sal_Bool XMLPercentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + sal_Int32 nValue; + OUStringBuffer aOut; + + if( lcl_xmloff_getAny( rValue, nValue, nBytes ) ) + { + SvXMLUnitConverter::convertPercent( aOut, nValue ); + rStrExpValue = aOut.makeStringAndClear(); + + bRet = sal_True; + } + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLDoublePercentPropHdl +// + +sal_Bool XMLDoublePercentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + double fValue = 1.0; + + if( rStrImpValue.indexOf( (sal_Unicode)'%' ) == -1 ) + { + fValue = rStrImpValue.toDouble(); + } + else + { + sal_Int32 nValue = 0; + bRet = SvXMLUnitConverter::convertPercent( nValue, rStrImpValue ); + fValue = ((double)nValue) / 100.0; + } + rValue <<= fValue; + + return bRet; +} + +sal_Bool XMLDoublePercentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + double fValue = 0; + + if( rValue >>= fValue ) + { + fValue *= 100.0; + if( fValue > 0 ) fValue += 0.5; else fValue -= 0.5; + + sal_Int32 nValue = (sal_Int32)fValue; + + OUStringBuffer aOut; + SvXMLUnitConverter::convertPercent( aOut, nValue ); + rStrExpValue = aOut.makeStringAndClear(); + + bRet = sal_True; + } + + return bRet; +} + + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLNegPercentPropHdl +// + +XMLNegPercentPropHdl::~XMLNegPercentPropHdl() +{ + // nothing to do +} + +sal_Bool XMLNegPercentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + sal_Int32 nValue = 0; + bRet = SvXMLUnitConverter::convertPercent( nValue, rStrImpValue ); + lcl_xmloff_setAny( rValue, 100-nValue, nBytes ); + + return bRet; +} + +sal_Bool XMLNegPercentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + sal_Int32 nValue; + OUStringBuffer aOut; + + if( lcl_xmloff_getAny( rValue, nValue, nBytes ) ) + { + SvXMLUnitConverter::convertPercent( aOut, 100-nValue ); + rStrExpValue = aOut.makeStringAndClear(); + + bRet = sal_True; + } + + return bRet; +} + + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLMeasurePxPropHdl +// + +XMLMeasurePxPropHdl::~XMLMeasurePxPropHdl() +{ + // nothing to do +} + +sal_Bool XMLMeasurePxPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + sal_Int32 nValue = 0; + bRet = SvXMLUnitConverter::convertMeasurePx( nValue, rStrImpValue ); + lcl_xmloff_setAny( rValue, nValue, nBytes ); + + return bRet; +} + +sal_Bool XMLMeasurePxPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + sal_Int32 nValue; + OUStringBuffer aOut; + + if( lcl_xmloff_getAny( rValue, nValue, nBytes ) ) + { + SvXMLUnitConverter::convertMeasurePx( aOut, nValue ); + rStrExpValue = aOut.makeStringAndClear(); + + bRet = sal_True; + } + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLColorPropHdl +// + +XMLColorPropHdl::~XMLColorPropHdl() +{ + // Nothing to do +} + +sal_Bool XMLColorPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + Color aColor; + + const OUString astrHSL( RTL_CONSTASCII_USTRINGPARAM( "hsl" ) ); + if( rStrImpValue.matchIgnoreAsciiCase( astrHSL ) ) + { + sal_Int32 nOpen = rStrImpValue.indexOf( '(' ); + sal_Int32 nClose = rStrImpValue.lastIndexOf( ')' ); + + if( (nOpen != -1) && (nClose > nOpen) ) + { + const OUString aTmp( rStrImpValue.copy( nOpen+1, nClose - nOpen-1) ); + + sal_Int32 nIndex = 0; + + Sequence< double > aHSL(3); + aHSL[0] = aTmp.getToken( 0, ',', nIndex ).toDouble(); + aHSL[1] = aTmp.getToken( 0, ',', nIndex ).toDouble() / 100.0; + aHSL[2] = aTmp.getToken( 0, ',', nIndex ).toDouble() / 100.0; + rValue <<= aHSL; + bRet = true; + } + } + else + { + bRet = SvXMLUnitConverter::convertColor( aColor, rStrImpValue ); + rValue <<= (sal_Int32)( aColor.GetColor() ); + } + + return bRet; +} + +sal_Bool XMLColorPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + Color aColor; + sal_Int32 nColor = 0; + + OUStringBuffer aOut; + if( rValue >>= nColor ) + { + aColor.SetColor( nColor ); + + SvXMLUnitConverter::convertColor( aOut, aColor ); + rStrExpValue = aOut.makeStringAndClear(); + + bRet = sal_True; + } + else + { + Sequence< double > aHSL; + if( (rValue >>= aHSL) && (aHSL.getLength() == 3) ) + { + aOut.append( OUString(RTL_CONSTASCII_USTRINGPARAM("hsl(")) ); + aOut.append( aHSL[0] ); + aOut.append( OUString(RTL_CONSTASCII_USTRINGPARAM(",")) ); + aOut.append( aHSL[1] * 100.0 ); + aOut.append( OUString(RTL_CONSTASCII_USTRINGPARAM("%,")) ); + aOut.append( aHSL[2] * 100.0 ); + aOut.append( OUString(RTL_CONSTASCII_USTRINGPARAM("%)")) ); + rStrExpValue = aOut.makeStringAndClear(); + + bRet = sal_True; + } + } + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLStringPropHdl +// + +XMLStringPropHdl::~XMLStringPropHdl() +{ + // Nothing to do +} + +sal_Bool XMLStringPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + rValue <<= rStrImpValue; + bRet = sal_True; + + return bRet; +} + +sal_Bool XMLStringPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + if( rValue >>= rStrExpValue ) + bRet = sal_True; + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLStyleNamePropHdl +// + +XMLStyleNamePropHdl::~XMLStyleNamePropHdl() +{ + // Nothing to do +} + +sal_Bool XMLStyleNamePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const +{ + sal_Bool bRet = sal_False; + + if( rValue >>= rStrExpValue ) + { + rStrExpValue = rUnitConverter.encodeStyleName( rStrExpValue ); + bRet = sal_True; + } + + return bRet; +} + + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLDoublePropHdl +// + +XMLDoublePropHdl::~XMLDoublePropHdl() +{ + // Nothing to do +} + +sal_Bool XMLDoublePropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const +{ + double fDblValue; + sal_Bool bRet = SvXMLUnitConverter::convertDouble( fDblValue, rStrImpValue ); + rValue <<= fDblValue; + return bRet; +} + +sal_Bool XMLDoublePropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + double fValue = 0; + + if( rValue >>= fValue ) + { + OUStringBuffer aOut; + SvXMLUnitConverter::convertDouble( aOut, fValue ); + rStrExpValue = aOut.makeStringAndClear(); + bRet = sal_True; + } + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLColorTransparentPropHdl +// + +XMLColorTransparentPropHdl::XMLColorTransparentPropHdl( + enum XMLTokenEnum eTransparent ) : + sTransparent( GetXMLToken( + eTransparent != XML_TOKEN_INVALID ? eTransparent : XML_TRANSPARENT ) ) +{ + // Nothing to do +} + +XMLColorTransparentPropHdl::~XMLColorTransparentPropHdl() +{ + // Nothing to do +} + +sal_Bool XMLColorTransparentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + if( rStrImpValue != sTransparent ) + { + Color aColor; + bRet = SvXMLUnitConverter::convertColor( aColor, rStrImpValue ); + rValue <<= (sal_Int32)( aColor.GetColor() ); + } + + return bRet; +} + +sal_Bool XMLColorTransparentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + sal_Int32 nColor = 0; + + if( rStrExpValue == sTransparent ) + bRet = sal_False; + else if( rValue >>= nColor ) + { + Color aColor( nColor ); + OUStringBuffer aOut; + SvXMLUnitConverter::convertColor( aOut, aColor ); + rStrExpValue = aOut.makeStringAndClear(); + + bRet = sal_True; + } + + return bRet; +} + + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLIsTransparentPropHdl +// + +XMLIsTransparentPropHdl::XMLIsTransparentPropHdl( + enum XMLTokenEnum eTransparent, sal_Bool bTransPropVal ) : + sTransparent( GetXMLToken( + eTransparent != XML_TOKEN_INVALID ? eTransparent : XML_TRANSPARENT ) ), + bTransPropValue( bTransPropVal ) +{ +} + +XMLIsTransparentPropHdl::~XMLIsTransparentPropHdl() +{ + // Nothing to do +} + +sal_Bool XMLIsTransparentPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bValue = ( (rStrImpValue == sTransparent) == bTransPropValue); + rValue.setValue( &bValue, ::getBooleanCppuType() ); + + return sal_True; +} + +sal_Bool XMLIsTransparentPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + // MIB: This looks a bit strange, because bTransPropValue == bValue should + // do the same, but this only applies if 'true' is represented by the same + // 8 bit value in bValue and bTransPropValue. Who will ensure this? + sal_Bool bValue = *(sal_Bool *)rValue.getValue(); + sal_Bool bIsTrans = bTransPropValue ? bValue : !bValue; + + if( bIsTrans ) + { + rStrExpValue = sTransparent; + bRet = sal_True; + } + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLColorAutoPropHdl +// + +XMLColorAutoPropHdl::XMLColorAutoPropHdl() +{ + // Nothing to do +} + +XMLColorAutoPropHdl::~XMLColorAutoPropHdl() +{ + // Nothing to do +} + +sal_Bool XMLColorAutoPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + // This is a multi property: the value might be set to AUTO_COLOR + // already by the XMLIsAutoColorPropHdl! + sal_Int32 nColor = 0; + if( !(rValue >>= nColor) || -1 != nColor ) + { + Color aColor; + bRet = SvXMLUnitConverter::convertColor( aColor, rStrImpValue ); + if( bRet ) + rValue <<= (sal_Int32)( aColor.GetColor() ); + } + + return bRet; +} + +sal_Bool XMLColorAutoPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + + sal_Int32 nColor = 0; + if( (rValue >>= nColor) && -1 != nColor ) + { + Color aColor( nColor ); + OUStringBuffer aOut; + SvXMLUnitConverter::convertColor( aOut, aColor ); + rStrExpValue = aOut.makeStringAndClear(); + + bRet = sal_True; + } + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLIsAutoColorPropHdl +// + +XMLIsAutoColorPropHdl::XMLIsAutoColorPropHdl() +{ +} + +XMLIsAutoColorPropHdl::~XMLIsAutoColorPropHdl() +{ + // Nothing to do +} + +sal_Bool XMLIsAutoColorPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const +{ + bool bValue; + + // An auto color overrides any other color set! + sal_Bool bRet = SvXMLUnitConverter::convertBool( bValue, rStrImpValue ); + if( bRet && bValue ) + rValue <<= (sal_Int32)-1; + + return sal_True; +} + +sal_Bool XMLIsAutoColorPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + sal_Bool bRet = sal_False; + sal_Int32 nColor = 0; + + if( (rValue >>= nColor) && -1 == nColor ) + { + OUStringBuffer aOut; + SvXMLUnitConverter::convertBool( aOut, sal_True ); + rStrExpValue = aOut.makeStringAndClear(); + + bRet = sal_True; + } + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// +// class XMLCompareOnlyPropHdl +// + +XMLCompareOnlyPropHdl::~XMLCompareOnlyPropHdl() +{ + // Nothing to do +} + +sal_Bool XMLCompareOnlyPropHdl::importXML( const OUString&, Any&, const SvXMLUnitConverter& ) const +{ + DBG_ASSERT( !this, "importXML called for compare-only-property" ); + return sal_False; +} + +sal_Bool XMLCompareOnlyPropHdl::exportXML( OUString&, const Any&, const SvXMLUnitConverter& ) const +{ + DBG_ASSERT( !this, "exportXML called for compare-only-property" ); + return sal_False; +} + +/////////////////////////////////////////////////////////////////////////////// +// class XMLNumberWithoutZeroPropHdl +// + +XMLNumberWithoutZeroPropHdl::XMLNumberWithoutZeroPropHdl( sal_Int8 nB ) : + nBytes( nB ) +{ +} + +XMLNumberWithoutZeroPropHdl::~XMLNumberWithoutZeroPropHdl() +{ +} + +sal_Bool XMLNumberWithoutZeroPropHdl::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Int32 nValue = 0; + sal_Bool bRet = SvXMLUnitConverter::convertNumber( nValue, rStrImpValue ); + if( bRet ) + lcl_xmloff_setAny( rValue, nValue, nBytes ); + return bRet; +} + +sal_Bool XMLNumberWithoutZeroPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + + sal_Int32 nValue = 0; + sal_Bool bRet = lcl_xmloff_getAny( rValue, nValue, nBytes ); + bRet &= nValue != 0; + + if( bRet ) + { + OUStringBuffer aBuffer; + SvXMLUnitConverter::convertNumber( aBuffer, nValue ); + rStrExpValue = aBuffer.makeStringAndClear(); + } + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////////// +// class XMLNumberWithAutoInsteadZeroPropHdl +// + +XMLNumberWithAutoInsteadZeroPropHdl::~XMLNumberWithAutoInsteadZeroPropHdl() +{ +} + +sal_Bool XMLNumberWithAutoInsteadZeroPropHdl::importXML( + const OUString& rStrImpValue, + Any& rValue, + const SvXMLUnitConverter& ) const +{ + sal_Int32 nValue = 0; + sal_Bool bRet = SvXMLUnitConverter::convertNumber( nValue, rStrImpValue ); + if( bRet ) + lcl_xmloff_setAny( rValue, nValue, 2 ); + else if( rStrImpValue == GetXMLToken( XML_AUTO ) ) + { + rValue <<= (sal_Int16)nValue; + bRet = sal_True; + } + return bRet; +} + +sal_Bool XMLNumberWithAutoInsteadZeroPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const +{ + + sal_Int32 nValue = 0; + lcl_xmloff_getAny( rValue, nValue, 2 ); + + if( 0 == nValue ) + rStrExpValue = GetXMLToken( XML_AUTO ); + else + { + OUStringBuffer aBuffer; + SvXMLUnitConverter::convertNumber( aBuffer, nValue ); + rStrExpValue = aBuffer.makeStringAndClear(); + } + + return sal_True; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/xmlbahdl.hxx b/xmloff/source/style/xmlbahdl.hxx new file mode 100644 index 000000000000..80f75b0159c7 --- /dev/null +++ b/xmloff/source/style/xmlbahdl.hxx @@ -0,0 +1,310 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLOFF_PROPERTYHANDLER_BASICTYPES_HXX +#define _XMLOFF_PROPERTYHANDLER_BASICTYPES_HXX + +#include <xmloff/xmlprhdl.hxx> +#include <rtl/ustrbuf.hxx> +#include <xmloff/xmltoken.hxx> + + +/** + PropertyHandler for the XML-data-type: XML_TYPE_NUMBER +*/ +class XMLNumberPropHdl : public XMLPropertyHandler +{ + sal_Int8 nBytes; + +public: + XMLNumberPropHdl( sal_Int8 nB=4 ) : nBytes( nB ) {} + virtual ~XMLNumberPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +/** + PropertyHandler for the XML-data-type: XML_TYPE_NUMBER_NONE +*/ +class XMLNumberNonePropHdl : public XMLPropertyHandler +{ + ::rtl::OUString sZeroStr; + sal_Int8 nBytes; +public: + XMLNumberNonePropHdl( sal_Int8 nB = 4 ); + XMLNumberNonePropHdl( enum ::xmloff::token::XMLTokenEnum eZeroString, sal_Int8 nB = 4 ); + virtual ~XMLNumberNonePropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +/** + PropertyHandler for the XML-data-type: XML_TYPE_MEASURE +*/ +class XMLMeasurePropHdl : public XMLPropertyHandler +{ + sal_Int8 nBytes; +public: + XMLMeasurePropHdl( sal_Int8 nB=4 ) : nBytes( nB ) {} + virtual ~XMLMeasurePropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +/** + PropertyHandler for the XML-data-type: XML_TYPE_PERCENT +*/ +class XMLPercentPropHdl : public XMLPropertyHandler +{ + sal_Int8 nBytes; +public: + XMLPercentPropHdl( sal_Int8 nB=4 ) : nBytes( nB ) {} + virtual ~XMLPercentPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +/** + PropertyHandler for the XML-data-type: XML_TYPE_PERCENT + that is mapped on a double from 0.0 to 1.0 +*/ +class XMLDoublePercentPropHdl : public XMLPropertyHandler +{ + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +/** + PropertyHandler for the XML-data-type: XML_TYPE_NEG_PERCENT +*/ +class XMLNegPercentPropHdl : public XMLPropertyHandler +{ + sal_Int8 nBytes; +public: + XMLNegPercentPropHdl( sal_Int8 nB=4 ) : nBytes( nB ) {} + virtual ~XMLNegPercentPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +/** + PropertyHandler for the XML-data-type: XML_TYPE_PERCENT +*/ +class XMLMeasurePxPropHdl : public XMLPropertyHandler +{ + sal_Int8 nBytes; +public: + XMLMeasurePxPropHdl( sal_Int8 nB=4 ) : nBytes( nB ) {} + virtual ~XMLMeasurePxPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +/** + PropertyHandler for the XML-data-type: XML_TYPE_BOOL +*/ +class XMLBoolPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLBoolPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +/** + PropertyHandler for the XML-data-type: XML_TYPE_COLOR +*/ +class XMLColorPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLColorPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +/** + PropertyHandler for the XML-data-type: XML_TYPE_STRING +*/ +class XMLStringPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLStringPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +/** + PropertyHandler for the XML-data-type: XML_TYPE_STYLENAME +*/ +class XMLStyleNamePropHdl : public XMLStringPropHdl +{ +public: + virtual ~XMLStyleNamePropHdl(); + + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + + +/** + PropertyHandler for the XML-data-type: XML_TYPE_DOUBLE +*/ +class XMLDoublePropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLDoublePropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +/** + PropertyHandler for the XML-data-type: XML_TYPE_NBOOL +*/ +class XMLNBoolPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLNBoolPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +/** + PropertyHandler for the XML-data-type: XML_TYPE_COLORTRANSPARENT +*/ +class XMLColorTransparentPropHdl : public XMLPropertyHandler +{ + const ::rtl::OUString sTransparent; + +public: + XMLColorTransparentPropHdl( enum ::xmloff::token::XMLTokenEnum eTransparent = xmloff::token::XML_TOKEN_INVALID ); + virtual ~XMLColorTransparentPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +/** + PropertyHandler for the XML-data-type: XML_TYPE_ISTRANSPARENT +*/ +class XMLIsTransparentPropHdl : public XMLPropertyHandler +{ + const ::rtl::OUString sTransparent; + sal_Bool bTransPropValue; + +public: + XMLIsTransparentPropHdl( enum ::xmloff::token::XMLTokenEnum eTransparent = xmloff::token::XML_TOKEN_INVALID, + sal_Bool bTransPropValue = sal_True ); + virtual ~XMLIsTransparentPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +/** + PropertyHandler for the XML-data-type: XML_TYPE_COLORAUTO +*/ +class XMLColorAutoPropHdl : public XMLPropertyHandler +{ +public: + XMLColorAutoPropHdl(); + virtual ~XMLColorAutoPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +/** + PropertyHandler for the XML-data-type: XML_TYPE_COLORISAUTO +*/ +class XMLIsAutoColorPropHdl : public XMLPropertyHandler +{ +public: + XMLIsAutoColorPropHdl(); + virtual ~XMLIsAutoColorPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + + +/** + PropertyHandler for properties that cannot make use of importXML + and exportXML methods, but can make use of the default comparison +*/ +class XMLCompareOnlyPropHdl : public XMLPropertyHandler +{ +public: + virtual ~XMLCompareOnlyPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +/** + PropertyHandler for the XML-data-type: XML_TYPE_NUMBER_NO_ZERO + Reads/writes numeric properties, but fails for the value zero + (i.e., a value 0 property will not be written) +*/ +class XMLNumberWithoutZeroPropHdl : public XMLPropertyHandler +{ + sal_Int8 nBytes; +public: + XMLNumberWithoutZeroPropHdl( sal_Int8 nB = 4 ); + virtual ~XMLNumberWithoutZeroPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +/** + PropertyHandler for the XML-data-type: XML_TYPE_NUMBER16_AUTO + Reads/writes numeric properties with special handling for the value zero + (i.e., a value 0 property will be written as "auto") +*/ +class XMLNumberWithAutoInsteadZeroPropHdl : public XMLNumberWithoutZeroPropHdl +{ +public: + virtual ~XMLNumberWithAutoInsteadZeroPropHdl(); + + virtual sal_Bool importXML( const ::rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; + virtual sal_Bool exportXML( ::rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const; +}; + +#endif // _XMLOFF_PROPERTYHANDLER_BASICTYPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/xmlexppr.cxx b/xmloff/source/style/xmlexppr.cxx new file mode 100644 index 000000000000..48f383a9a376 --- /dev/null +++ b/xmloff/source/style/xmlexppr.cxx @@ -0,0 +1,1141 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/xml/AttributeData.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XPropertyState.hpp> +#include <com/sun/star/lang/XTypeProvider.hpp> +#include <com/sun/star/beans/XMultiPropertySet.hpp> +#include <com/sun/star/beans/XTolerantMultiPropertySet.hpp> +#include <com/sun/star/beans/TolerantPropertySetResultType.hpp> +#include <rtl/ustrbuf.hxx> +#include <list> +#include <boost/unordered_map.hpp> + +#include <xmloff/xmlexppr.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/attrlist.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmlexp.hxx> +#include <xmloff/xmlprmap.hxx> +#include <xmloff/PropertySetInfoHash.hxx> +#include <comphelper/stl_types.hxx> + +#ifndef _SVSTDARR_USHORTS +#define _SVSTDARR_USHORTS +#include <svl/svstdarr.hxx> +#endif + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::std; +using namespace ::com::sun::star; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::xmloff::token; + +#define GET_PROP_TYPE( f ) static_cast<sal_uInt16>((f & XML_TYPE_PROP_MASK) >> XML_TYPE_PROP_SHIFT) + +struct XMLPropTokens_Impl +{ + sal_uInt16 nType; + XMLTokenEnum eToken; +}; + +#define ENTRY(t) { GET_PROP_TYPE(XML_TYPE_PROP_##t), XML_##t##_PROPERTIES } +const sal_uInt16 MAX_PROP_TYPES = + (XML_TYPE_PROP_END >> XML_TYPE_PROP_SHIFT) - + (XML_TYPE_PROP_START >> XML_TYPE_PROP_SHIFT); + +static XMLPropTokens_Impl aPropTokens[MAX_PROP_TYPES] = +{ + ENTRY(CHART), + ENTRY(GRAPHIC), + ENTRY(TABLE), + ENTRY(TABLE_COLUMN), + ENTRY(TABLE_ROW), + ENTRY(TABLE_CELL), + ENTRY(LIST_LEVEL), + ENTRY(PARAGRAPH), + ENTRY(TEXT), + ENTRY(DRAWING_PAGE), + ENTRY(PAGE_LAYOUT), + ENTRY(HEADER_FOOTER), + ENTRY(RUBY), + ENTRY(SECTION) +}; + +/////////////////////////////////////////////////////////////////////////////// +// +// public methods +// + +/////////////////////////////////////////////////////////////////////////// +// +// Take all properties of the XPropertySet which are also found in the +// XMLPropertyMapEntry-array and which are not set to their default-value, +// if a state is available. +// +// After that I call the method 'ContextFilter'. +// + +typedef std::list<XMLPropertyState> XMLPropertyStateList_Impl; + +class XMLPropertyStates_Impl +{ + XMLPropertyStateList_Impl aPropStates; + XMLPropertyStateList_Impl::iterator aLastItr; + sal_uInt32 nCount; +public: + XMLPropertyStates_Impl(); + void AddPropertyState(const XMLPropertyState& rPropState); + void FillPropertyStateVector(std::vector<XMLPropertyState>& rVector); +}; + +XMLPropertyStates_Impl::XMLPropertyStates_Impl() : + aPropStates(), + nCount(0) +{ + aLastItr = aPropStates.begin(); +} + +void XMLPropertyStates_Impl::AddPropertyState( + const XMLPropertyState& rPropState) +{ + XMLPropertyStateList_Impl::iterator aItr = aPropStates.begin(); + sal_Bool bInserted(sal_False); + if (nCount) + { + if (aLastItr->mnIndex < rPropState.mnIndex) + aItr = ++aLastItr; + } + do + { + // TODO: one path required only + if (aItr == aPropStates.end()) + { + aLastItr = aPropStates.insert(aPropStates.end(), rPropState); + bInserted = sal_True; + nCount++; + } + else if (aItr->mnIndex > rPropState.mnIndex) + { + aLastItr = aPropStates.insert(aItr, rPropState); + bInserted = sal_True; + nCount++; + } + } + while(!bInserted && (aItr++ != aPropStates.end())); +} + +void XMLPropertyStates_Impl::FillPropertyStateVector( + std::vector<XMLPropertyState>& rVector) +{ + if (nCount) + { + rVector.resize(nCount, XMLPropertyState(-1)); + ::std::copy( aPropStates.begin(), aPropStates.end(), rVector.begin() ); + } +} + +class FilterPropertyInfo_Impl +{ + const rtl::OUString sApiName; + std::list<sal_uInt32> aIndexes; + sal_uInt32 nCount; + +public: + + FilterPropertyInfo_Impl( const rtl::OUString& rApiName, + const sal_uInt32 nIndex); + + const OUString& GetApiName() const { return sApiName; } + std::list<sal_uInt32>& GetIndexes() { return aIndexes; } + + void AddIndex( sal_uInt32 nIndex ) + { + aIndexes.push_back(nIndex); + nCount++; + } + + // for sort + sal_Bool operator< ( const FilterPropertyInfo_Impl& rArg ) const + { + return (GetApiName() < rArg.GetApiName()); + } +}; + +FilterPropertyInfo_Impl::FilterPropertyInfo_Impl( + const rtl::OUString& rApiName, + const sal_uInt32 nIndex ) : + sApiName( rApiName ), + aIndexes(), + nCount(1) +{ + aIndexes.push_back(nIndex); +} + +typedef std::list<FilterPropertyInfo_Impl> FilterPropertyInfoList_Impl; + +// ---------------------------------------------------------------------------- + +class FilterPropertiesInfo_Impl +{ + sal_uInt32 nCount; + FilterPropertyInfoList_Impl aPropInfos; + FilterPropertyInfoList_Impl::iterator aLastItr; + + Sequence <OUString> *pApiNames; + +public: + FilterPropertiesInfo_Impl(); + ~FilterPropertiesInfo_Impl(); + + void AddProperty(const rtl::OUString& rApiName, const sal_uInt32 nIndex); + const uno::Sequence<OUString>& GetApiNames(); + void FillPropertyStateArray( + vector< XMLPropertyState >& rPropStates, + const Reference< XPropertySet >& xPropSet, + const UniReference< XMLPropertySetMapper >& maPropMapper, + const sal_Bool bDefault = sal_False); + sal_uInt32 GetPropertyCount() const { return nCount; } +}; + +// ---------------------------------------------------------------------------- + +typedef boost::unordered_map +< + PropertySetInfoKey, + FilterPropertiesInfo_Impl *, + PropertySetInfoHash, + PropertySetInfoHash +> +FilterOropertiesHashMap_Impl; + +class FilterPropertiesInfos_Impl : public FilterOropertiesHashMap_Impl +{ +public: + ~FilterPropertiesInfos_Impl (); +}; + +FilterPropertiesInfos_Impl::~FilterPropertiesInfos_Impl () +{ + FilterOropertiesHashMap_Impl::iterator aIter = begin(); + FilterOropertiesHashMap_Impl::iterator aEnd = end(); + while( aIter != aEnd ) + { + delete (*aIter).second; + (*aIter).second = 0; + ++aIter; + } +} + +// ---------------------------------------------------------------------------- + +FilterPropertiesInfo_Impl::FilterPropertiesInfo_Impl() : + nCount(0), + aPropInfos(), + pApiNames( 0 ) +{ + aLastItr = aPropInfos.begin(); +} + +FilterPropertiesInfo_Impl::~FilterPropertiesInfo_Impl() +{ + delete pApiNames; +} + +void FilterPropertiesInfo_Impl::AddProperty( + const rtl::OUString& rApiName, const sal_uInt32 nIndex) +{ + aPropInfos.push_back(FilterPropertyInfo_Impl(rApiName, nIndex)); + nCount++; + + OSL_ENSURE( !pApiNames, "perfomance warning: API names already retrieved" ); + if( pApiNames ) + { + delete pApiNames; + pApiNames = NULL; + } +} +const uno::Sequence<OUString>& FilterPropertiesInfo_Impl::GetApiNames() +{ + OSL_ENSURE(nCount == aPropInfos.size(), "wrong property count"); + if( !pApiNames ) + { + // we have to do three things: + // 1) sort API names, + // 2) merge duplicates, + // 3) construct sequence + + // sort names + aPropInfos.sort(); + + // merge duplicates + if ( nCount > 1 ) + { + FilterPropertyInfoList_Impl::iterator aOld = aPropInfos.begin(); + FilterPropertyInfoList_Impl::iterator aEnd = aPropInfos.end(); + FilterPropertyInfoList_Impl::iterator aCurrent = aOld; + ++aCurrent; + + while ( aCurrent != aEnd ) + { + // equal to next element? + if ( aOld->GetApiName().equals( aCurrent->GetApiName() ) ) + { + // if equal: merge index lists + aOld->GetIndexes().merge( aCurrent->GetIndexes() ); + // erase element, and continue with next + aCurrent = aPropInfos.erase( aCurrent ); + nCount--; + } + else + { + // remember old element and continue with next + aOld = aCurrent; + ++aCurrent; + } + } + } + + // construct sequence + pApiNames = new Sequence < OUString >( nCount ); + OUString *pNames = pApiNames->getArray(); + FilterPropertyInfoList_Impl::iterator aItr = aPropInfos.begin(); + FilterPropertyInfoList_Impl::iterator aEnd = aPropInfos.end(); + for ( ; aItr != aEnd; ++aItr, ++pNames) + *pNames = aItr->GetApiName(); + } + + return *pApiNames; +} + +void FilterPropertiesInfo_Impl::FillPropertyStateArray( + vector< XMLPropertyState >& rPropStates, + const Reference< XPropertySet >& rPropSet, + const UniReference< XMLPropertySetMapper >& rPropMapper, + const sal_Bool bDefault ) +{ + XMLPropertyStates_Impl aPropStates; + + const uno::Sequence<OUString>& rApiNames = GetApiNames(); + + Reference < XTolerantMultiPropertySet > xTolPropSet( rPropSet, UNO_QUERY ); + if (xTolPropSet.is()) + { + if (!bDefault) + { + Sequence < beans::GetDirectPropertyTolerantResult > aResults(xTolPropSet->getDirectPropertyValuesTolerant(rApiNames)); + sal_Int32 nResultCount(aResults.getLength()); + if (nResultCount > 0) + { + const beans::GetDirectPropertyTolerantResult *pResults = aResults.getConstArray(); + FilterPropertyInfoList_Impl::iterator aPropIter(aPropInfos.begin()); + XMLPropertyState aNewProperty( -1 ); + sal_uInt32 i = 0; + while (nResultCount > 0 && i < nCount) + { + if (pResults->Name == aPropIter->GetApiName()) + { + aNewProperty.mnIndex = -1; + aNewProperty.maValue = pResults->Value; + + for( std::list<sal_uInt32>::iterator aIndexItr(aPropIter->GetIndexes().begin()); + aIndexItr != aPropIter->GetIndexes().end(); + ++aIndexItr ) + { + aNewProperty.mnIndex = *aIndexItr; + aPropStates.AddPropertyState( aNewProperty ); + } + ++pResults; + --nResultCount; + } + ++aPropIter; + ++i; + } + } + } + else + { + Sequence < beans::GetPropertyTolerantResult > aResults(xTolPropSet->getPropertyValuesTolerant(rApiNames)); + OSL_ENSURE( rApiNames.getLength() == aResults.getLength(), "wrong implemented XTolerantMultiPropertySet" ); + const beans::GetPropertyTolerantResult *pResults = aResults.getConstArray(); + FilterPropertyInfoList_Impl::iterator aPropIter(aPropInfos.begin()); + XMLPropertyState aNewProperty( -1 ); + sal_uInt32 nResultCount(aResults.getLength()); + OSL_ENSURE( nCount == nResultCount, "wrong implemented XTolerantMultiPropertySet??" ); + for( sal_uInt32 i = 0; i < nResultCount; ++i ) + { + if ((pResults->Result == beans::TolerantPropertySetResultType::SUCCESS) && + ((pResults->State == PropertyState_DIRECT_VALUE) || (pResults->State == PropertyState_DEFAULT_VALUE))) + { + aNewProperty.mnIndex = -1; + aNewProperty.maValue = pResults->Value; + + for( std::list<sal_uInt32>::iterator aIndexItr(aPropIter->GetIndexes().begin()); + aIndexItr != aPropIter->GetIndexes().end(); + ++aIndexItr ) + { + aNewProperty.mnIndex = *aIndexItr; + aPropStates.AddPropertyState( aNewProperty ); + } + } + ++pResults; + ++aPropIter; + } + } + } + else + { + Sequence < PropertyState > aStates; + const PropertyState *pStates = 0; + Reference< XPropertyState > xPropState( rPropSet, UNO_QUERY ); + if( xPropState.is() ) + { + aStates = xPropState->getPropertyStates( rApiNames ); + pStates = aStates.getConstArray(); + } + + Reference < XMultiPropertySet > xMultiPropSet( rPropSet, UNO_QUERY ); + if( xMultiPropSet.is() && !bDefault ) + { + Sequence < Any > aValues; + if( pStates ) + { + // step 1: get value count + sal_uInt32 nValueCount = 0; + sal_uInt32 i; + + for( i = 0; i < nCount; ++i, ++pStates ) + { + if( (*pStates == PropertyState_DIRECT_VALUE)/* || (bDefault && (*pStates == PropertyState_DEFAULT_VALUE))*/ ) + nValueCount++; + } + + if( nValueCount ) + { + // step 2: collect property names + Sequence < OUString > aAPINames( nValueCount ); + OUString *pAPINames = aAPINames.getArray(); + + ::std::vector< FilterPropertyInfoList_Impl::iterator > aPropIters; + aPropIters.reserve( nValueCount ); + + FilterPropertyInfoList_Impl::iterator aItr = aPropInfos.begin(); + OSL_ENSURE(aItr != aPropInfos.end(),"Invalid iterator!"); + + pStates = aStates.getConstArray(); + i = 0; + while( i < nValueCount ) + { + if( (*pStates == PropertyState_DIRECT_VALUE)/* || (bDefault && (*pStates == PropertyState_DEFAULT_VALUE))*/ ) + { + *pAPINames++ = aItr->GetApiName(); + aPropIters.push_back( aItr ); + ++i; + } + ++aItr; + ++pStates; + } + + aValues = xMultiPropSet->getPropertyValues( aAPINames ); + const Any *pValues = aValues.getConstArray(); + + ::std::vector< FilterPropertyInfoList_Impl::iterator >::const_iterator + pPropIter = aPropIters.begin(); + + XMLPropertyState aNewProperty( -1 ); + for( i = 0; i < nValueCount; ++i ) + { + aNewProperty.mnIndex = -1; + aNewProperty.maValue = *pValues; + + const ::std::list< sal_uInt32 >& rIndexes( (*pPropIter)->GetIndexes() ); + for ( std::list<sal_uInt32>::const_iterator aIndexItr = rIndexes.begin(); + aIndexItr != rIndexes.end(); + ++aIndexItr + ) + { + aNewProperty.mnIndex = *aIndexItr; + aPropStates.AddPropertyState( aNewProperty ); + } + + ++pPropIter; + ++pValues; + } + } + } + else + { + aValues = xMultiPropSet->getPropertyValues( rApiNames ); + const Any *pValues = aValues.getConstArray(); + + FilterPropertyInfoList_Impl::iterator aItr = aPropInfos.begin(); + for(sal_uInt32 i = 0; i < nCount; ++i) + { + // The value is stored in the PropertySet itself, add to list. + XMLPropertyState aNewProperty( -1 ); + aNewProperty.maValue = *pValues; + ++pValues; + for( std::list<sal_uInt32>::iterator aIndexItr = + aItr->GetIndexes().begin(); + aIndexItr != aItr->GetIndexes().end(); + ++aIndexItr ) + { + aNewProperty.mnIndex = *aIndexItr; + aPropStates.AddPropertyState( aNewProperty ); + } + ++aItr; + } + } + } + else + { + FilterPropertyInfoList_Impl::iterator aItr = aPropInfos.begin(); + for(sal_uInt32 i = 0; i < nCount; ++i) + { + sal_Bool bDirectValue = + !pStates || *pStates == PropertyState_DIRECT_VALUE; + if( bDirectValue || bDefault ) + { + // The value is stored in the PropertySet itself, add to list. + sal_Bool bGotValue = sal_False; + XMLPropertyState aNewProperty( -1 ); + for( std::list<sal_uInt32>::const_iterator aIndexItr = + aItr->GetIndexes().begin(); + aIndexItr != aItr->GetIndexes().end(); + ++aIndexItr ) + { + if( bDirectValue || + (rPropMapper->GetEntryFlags( *aIndexItr ) & + MID_FLAG_DEFAULT_ITEM_EXPORT) != 0 ) + { + try + { + if( !bGotValue ) + { + aNewProperty.maValue = + rPropSet->getPropertyValue( aItr->GetApiName() ); + bGotValue = sal_True; + } + aNewProperty.mnIndex = *aIndexItr; + aPropStates.AddPropertyState( aNewProperty ); + } + catch( UnknownPropertyException& ) + { + // might be a problem of getImplemenetationId + OSL_ENSURE( !this, "unknown property in getPropertyValue" ); + } + + } + } + } + + ++aItr; + if( pStates ) + ++pStates; + } + } + } + aPropStates.FillPropertyStateVector(rPropStates); +} + +/////////////////////////////////////////////////////////////////////////////// +// +// ctor/dtor , class SvXMLExportPropertyMapper +// + +SvXMLExportPropertyMapper::SvXMLExportPropertyMapper( + const UniReference< XMLPropertySetMapper >& rMapper ) : + pCache( 0 ), + maPropMapper( rMapper ) +{ +} + +SvXMLExportPropertyMapper::~SvXMLExportPropertyMapper() +{ + delete pCache; + mxNextMapper = 0; +} + +void SvXMLExportPropertyMapper::ChainExportMapper( + const UniReference< SvXMLExportPropertyMapper>& rMapper ) +{ + // add map entries from rMapper to current map + maPropMapper->AddMapperEntry( rMapper->getPropertySetMapper() ); + // rMapper uses the same map as 'this' + rMapper->maPropMapper = maPropMapper; + + // set rMapper as last mapper in current chain + UniReference< SvXMLExportPropertyMapper > xNext = mxNextMapper; + if( xNext.is()) + { + while( xNext->mxNextMapper.is()) + xNext = xNext->mxNextMapper; + xNext->mxNextMapper = rMapper; + } + else + mxNextMapper = rMapper; + + // if rMapper was already chained, correct + // map pointer of successors + xNext = rMapper; + + while( xNext->mxNextMapper.is()) + { + xNext = xNext->mxNextMapper; + xNext->maPropMapper = maPropMapper; + } +} + + +vector< XMLPropertyState > SvXMLExportPropertyMapper::_Filter( + const Reference< XPropertySet > xPropSet, + const sal_Bool bDefault ) const +{ + vector< XMLPropertyState > aPropStateArray; + + // Retrieve XPropertySetInfo and XPropertyState + Reference< XPropertySetInfo > xInfo( xPropSet->getPropertySetInfo() ); + if( !xInfo.is() ) + return aPropStateArray; + + sal_Int32 nProps = maPropMapper->GetEntryCount(); + + FilterPropertiesInfo_Impl *pFilterInfo = 0; + + Reference < XTypeProvider > xTypeProv( xPropSet, UNO_QUERY ); + Sequence< sal_Int8 > aImplId; + if( xTypeProv.is() ) + { + aImplId = xTypeProv->getImplementationId(); + if( aImplId.getLength() == 16 ) + { + if( pCache ) + { + // The key must not be created outside this block, because it + // keeps a reference to the property set info. + PropertySetInfoKey aKey( xInfo, aImplId ); + FilterPropertiesInfos_Impl::iterator aIter = + pCache->find( aKey ); + if( aIter != pCache->end() ) + pFilterInfo = (*aIter).second; + } + } + } + + sal_Bool bDelInfo = sal_False; + if( !pFilterInfo ) + { + pFilterInfo = new FilterPropertiesInfo_Impl; + for( sal_Int32 i=0; i < nProps; i++ ) + { + // Are we allowed to ask for the property? (MID_FLAG_NO_PROP..) + // Does the PropertySet contain name of mpEntries-array ? + const OUString& rAPIName = maPropMapper->GetEntryAPIName( i ); + const sal_Int32 nFlags = maPropMapper->GetEntryFlags( i ); + if( (0 == (nFlags & MID_FLAG_NO_PROPERTY_EXPORT)) && + ( (0 != (nFlags & MID_FLAG_MUST_EXIST)) || + xInfo->hasPropertyByName( rAPIName ) ) ) + { + const SvtSaveOptions::ODFDefaultVersion nCurrentVersion( SvtSaveOptions().GetODFDefaultVersion() ); + const SvtSaveOptions::ODFDefaultVersion nEarliestODFVersionForExport( + maPropMapper->GetEarliestODFVersionForExport( i ) ); + if( nCurrentVersion >= nEarliestODFVersionForExport + || nCurrentVersion == SvtSaveOptions::ODFVER_UNKNOWN + || nEarliestODFVersionForExport == SvtSaveOptions::ODFVER_UNKNOWN ) + pFilterInfo->AddProperty(rAPIName, i); + } + } + + if( xTypeProv.is() && aImplId.getLength() == 16 ) + { + // Check whether the property set info is destroyed if it is + // assigned to a weak reference only. If it is destroyed, then + // every instance of getPropertySetInfo returns a new object. + // Such property set infos must not be cached. + WeakReference < XPropertySetInfo > xWeakInfo( xInfo ); + xInfo = 0; + xInfo = xWeakInfo; + if( xInfo.is() ) + { + if( !pCache ) + ((SvXMLExportPropertyMapper *)this)->pCache = + new FilterPropertiesInfos_Impl; + PropertySetInfoKey aKey( xInfo, aImplId ); + (*pCache)[aKey] = pFilterInfo; + } + else + bDelInfo = sal_True; + } + else + { + OSL_FAIL("here is no TypeProvider or the ImplId is wrong"); + bDelInfo = sal_True; + } + } + + if( pFilterInfo->GetPropertyCount() ) + { + try + { + pFilterInfo->FillPropertyStateArray(aPropStateArray, + xPropSet, maPropMapper, + bDefault); + } + catch( UnknownPropertyException& ) + { + // might be a problem of getImplemenetationId + OSL_ENSURE( !this, "unknown property in getPropertyStates" ); + } + } + + // Call centext-filter + if( !aPropStateArray.empty() ) + ContextFilter( aPropStateArray, xPropSet ); + + // Have to do if we change from a vector to a list or something like that + + if( bDelInfo ) + delete pFilterInfo; + + return aPropStateArray; +} + +void SvXMLExportPropertyMapper::ContextFilter( + vector< XMLPropertyState >& rProperties, + Reference< XPropertySet > rPropSet ) const +{ + // Derived class could implement this. + if( mxNextMapper.is() ) + mxNextMapper->ContextFilter( rProperties, rPropSet ); +} + +/////////////////////////////////////////////////////////////////////////// +// +// Compares two Sequences of XMLPropertyState: +// 1.Number of elements equal ? +// 2.Index of each element equal ? (So I know whether the propertynames are the same) +// 3.Value of each element equal ? +// +sal_Bool SvXMLExportPropertyMapper::Equals( + const vector< XMLPropertyState >& aProperties1, + const vector< XMLPropertyState >& aProperties2 ) const +{ + sal_Bool bRet = sal_True; + sal_uInt32 nCount = aProperties1.size(); + + if( nCount == aProperties2.size() ) + { + sal_uInt32 nIndex = 0; + while( bRet && nIndex < nCount ) + { + const XMLPropertyState& rProp1 = aProperties1[ nIndex ]; + const XMLPropertyState& rProp2 = aProperties2[ nIndex ]; + + // Compare index. If equal, compare value + if( rProp1.mnIndex == rProp2.mnIndex ) + { + if( rProp1.mnIndex != -1 ) + { + // Now compare values + if( ( maPropMapper->GetEntryType( rProp1.mnIndex ) & + XML_TYPE_BUILDIN_CMP ) != 0 ) + // simple type ( binary compare ) + bRet = ( rProp1.maValue == rProp2.maValue ); + else + // complex type ( ask for compare-function ) + bRet = maPropMapper->GetPropertyHandler( + rProp1.mnIndex )->equals( rProp1.maValue, + rProp2.maValue ); + } + } + else + bRet = sal_False; + + nIndex++; + } + } + else + bRet = sal_False; + + return bRet; +} + + +/** fills the given attribute list with the items in the given set +void SvXMLExportPropertyMapper::exportXML( SvXMLAttributeList& rAttrList, + const ::std::vector< XMLPropertyState >& rProperties, + const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& rNamespaceMap, + sal_uInt16 nFlags ) const +{ + _exportXML( rAttrList, rProperties, rUnitConverter, rNamespaceMap, + nFlags, 0, -1, -1 ); +} + + +void SvXMLExportPropertyMapper::exportXML( SvXMLAttributeList& rAttrList, + const ::std::vector< XMLPropertyState >& rProperties, + const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& rNamespaceMap, + sal_Int32 nPropMapStartIdx, sal_Int32 nPropMapEndIdx, + sal_uInt16 nFlags ) const +{ + _exportXML( rAttrList, rProperties, rUnitConverter, rNamespaceMap, + nFlags, 0, nPropMapStartIdx, nPropMapEndIdx ); +} +*/ + + +void SvXMLExportPropertyMapper::exportXML( SvXMLAttributeList& rAttrList, + const XMLPropertyState& rProperty, + const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& rNamespaceMap, + sal_uInt16 nFlags ) const +{ + if( ( maPropMapper->GetEntryFlags( rProperty.mnIndex ) & + MID_FLAG_ELEMENT_ITEM_EXPORT ) == 0 ) + _exportXML( rAttrList, rProperty, rUnitConverter, rNamespaceMap, + nFlags ); +} + +void SvXMLExportPropertyMapper::exportXML( + SvXMLExport& rExport, + const ::std::vector< XMLPropertyState >& rProperties, + sal_uInt16 nFlags ) const +{ + exportXML( rExport, rProperties, -1, -1, nFlags ); +} + +void SvXMLExportPropertyMapper::exportXML( + SvXMLExport& rExport, + const ::std::vector< XMLPropertyState >& rProperties, + sal_Int32 nPropMapStartIdx, sal_Int32 nPropMapEndIdx, + sal_uInt16 nFlags ) const +{ + sal_uInt16 nPropTypeFlags = 0; + for( sal_uInt16 i=0; i<MAX_PROP_TYPES; ++i ) + { + sal_uInt16 nPropType = aPropTokens[i].nType; + if( 0==i || (nPropTypeFlags & (1 << nPropType)) != 0 ) + { + SvUShorts aIndexArray; + + _exportXML( nPropType, nPropTypeFlags, + rExport.GetAttrList(), rProperties, + rExport.GetMM100UnitConverter(), + rExport.GetNamespaceMap(), + nFlags, &aIndexArray, + nPropMapStartIdx, nPropMapEndIdx ); + + if( rExport.GetAttrList().getLength() > 0L || + (nFlags & XML_EXPORT_FLAG_EMPTY) != 0 || + aIndexArray.Count() != 0 ) + { + SvXMLElementExport aElem( rExport, XML_NAMESPACE_STYLE, + aPropTokens[i].eToken, + (nFlags & XML_EXPORT_FLAG_IGN_WS) != 0, + sal_False ); + + exportElementItems( rExport, rProperties, nFlags, aIndexArray ); + } + } + } +} + +/** this method is called for every item that has the + MID_FLAG_SPECIAL_ITEM_EXPORT flag set */ +void SvXMLExportPropertyMapper::handleSpecialItem( + SvXMLAttributeList& rAttrList, + const XMLPropertyState& rProperty, + const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& rNamespaceMap, + const ::std::vector< XMLPropertyState > *pProperties, + sal_uInt32 nIdx ) const +{ + OSL_ENSURE( mxNextMapper.is(), "special item not handled in xml export" ); + if( mxNextMapper.is() ) + mxNextMapper->handleSpecialItem( rAttrList, rProperty, rUnitConverter, + rNamespaceMap, pProperties, nIdx ); +} + +/** this method is called for every item that has the + MID_FLAG_ELEMENT_EXPORT flag set */ +void SvXMLExportPropertyMapper::handleElementItem( + SvXMLExport& rExport, + const XMLPropertyState& rProperty, + sal_uInt16 nFlags, + const ::std::vector< XMLPropertyState > *pProperties, + sal_uInt32 nIdx ) const +{ + OSL_ENSURE( mxNextMapper.is(), "element item not handled in xml export" ); + if( mxNextMapper.is() ) + mxNextMapper->handleElementItem( rExport, rProperty, nFlags, + pProperties, nIdx ); +} + +/////////////////////////////////////////////////////////////////////////////// +// +// protected methods +// + +/** fills the given attribute list with the items in the given set */ +void SvXMLExportPropertyMapper::_exportXML( + sal_uInt16 nPropType, sal_uInt16& rPropTypeFlags, + SvXMLAttributeList& rAttrList, + const ::std::vector< XMLPropertyState >& rProperties, + const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& rNamespaceMap, + sal_uInt16 nFlags, + SvUShorts* pIndexArray, + sal_Int32 nPropMapStartIdx, sal_Int32 nPropMapEndIdx ) const +{ + const sal_uInt32 nCount = rProperties.size(); + sal_uInt32 nIndex = 0; + + if( -1 == nPropMapStartIdx ) + nPropMapStartIdx = 0; + if( -1 == nPropMapEndIdx ) + nPropMapEndIdx = maPropMapper->GetEntryCount(); + + while( nIndex < nCount ) + { + sal_Int32 nPropMapIdx = rProperties[nIndex].mnIndex; + if( nPropMapIdx >= nPropMapStartIdx && + nPropMapIdx < nPropMapEndIdx )// valid entry? + { + sal_uInt32 nEFlags = maPropMapper->GetEntryFlags( nPropMapIdx ); + sal_uInt16 nEPType = GET_PROP_TYPE(nEFlags); + OSL_ENSURE( nEPType >= (XML_TYPE_PROP_START>>XML_TYPE_PROP_SHIFT), + "no prop type sepcified" ); + rPropTypeFlags |= (1 << nEPType); + if( nEPType == nPropType ) + { + // we have a valid map entry here, so lets use it... + if( ( nEFlags & MID_FLAG_ELEMENT_ITEM_EXPORT ) != 0 ) + { + // element items do not add any properties, + // we export it later + if( pIndexArray ) + pIndexArray->Insert( (sal_uInt16)nIndex, pIndexArray->Count() ); + } + else + { + _exportXML( rAttrList, rProperties[nIndex], rUnitConverter, + rNamespaceMap, nFlags, &rProperties, nIndex ); + } + } + } + + nIndex++; + } +} + +void SvXMLExportPropertyMapper::_exportXML( + SvXMLAttributeList& rAttrList, + const XMLPropertyState& rProperty, + const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& rNamespaceMap, + sal_uInt16 /*nFlags*/, + const ::std::vector< XMLPropertyState > *pProperties, + sal_uInt32 nIdx ) const +{ + OUString sCDATA( GetXMLToken(XML_CDATA) ); + + if ( ( maPropMapper->GetEntryFlags( rProperty.mnIndex ) & + MID_FLAG_SPECIAL_ITEM_EXPORT ) != 0 ) + { + uno::Reference< container::XNameContainer > xAttrContainer; + if( (rProperty.maValue >>= xAttrContainer) && xAttrContainer.is() ) + { + SvXMLNamespaceMap *pNewNamespaceMap = 0; + const SvXMLNamespaceMap *pNamespaceMap = &rNamespaceMap; + + uno::Sequence< OUString > aAttribNames( xAttrContainer->getElementNames() ); + const OUString* pAttribName = aAttribNames.getConstArray(); + + const sal_Int32 nCount = aAttribNames.getLength(); + + OUStringBuffer sNameBuffer; + xml::AttributeData aData; + for( sal_Int32 i=0; i < nCount; i++, pAttribName++ ) + { + xAttrContainer->getByName( *pAttribName ) >>= aData; + OUString sAttribName( *pAttribName ); + + // extract namespace prefix from attribute name if it exists + OUString sPrefix; + const sal_Int32 nColonPos = + pAttribName->indexOf( sal_Unicode(':') ); + if( nColonPos != -1 ) + sPrefix = pAttribName->copy( 0, nColonPos ); + + if( sPrefix.getLength() ) + { + OUString sNamespace( aData.Namespace ); + + // if the prefix isn't defined yet or has another meaning, + // we have to redefine it now. + sal_uInt16 nKey = pNamespaceMap->GetKeyByPrefix( sPrefix ); + if( USHRT_MAX == nKey || pNamespaceMap->GetNameByKey( nKey ) != sNamespace ) + { + sal_Bool bAddNamespace = sal_False; + if( USHRT_MAX == nKey ) + { + // The prefix is unused, so it is sufficient + // to add it to the namespace map. + bAddNamespace = sal_True; + } + else + { + // check if there is a prefix registered for the + // namepsace URI + nKey = pNamespaceMap->GetKeyByName( sNamespace ); + if( XML_NAMESPACE_UNKNOWN == nKey ) + { + // There is no prefix for the namespace, so + // we have to generate one and have to add it. + sal_Int32 n=0; + OUString sOrigPrefix( sPrefix ); + do + { + sNameBuffer.append( sOrigPrefix ); + sNameBuffer.append( ++n ); + sPrefix = sNameBuffer.makeStringAndClear(); + nKey = pNamespaceMap->GetKeyByPrefix( sPrefix ); + } + while( nKey != USHRT_MAX ); + + bAddNamespace = sal_True; + } + else + { + // If there is a prefix for the namespace, + // we reuse that. + sPrefix = pNamespaceMap->GetPrefixByKey( nKey ); + } + // In any case, the attribute name has to be adapted. + sNameBuffer.append( sPrefix ); + sNameBuffer.append( sal_Unicode(':') ); + sNameBuffer.append( pAttribName->copy( nColonPos+1 ) ); + sAttribName = sNameBuffer.makeStringAndClear(); + } + + if( bAddNamespace ) + { + if( !pNewNamespaceMap ) + { + pNewNamespaceMap = new SvXMLNamespaceMap( rNamespaceMap ); + pNamespaceMap = pNewNamespaceMap; + } + pNewNamespaceMap->Add( sPrefix, sNamespace ); + sNameBuffer.append( GetXMLToken(XML_XMLNS) ); + sNameBuffer.append( sal_Unicode(':') ); + sNameBuffer.append( sPrefix ); + rAttrList.AddAttribute( sNameBuffer.makeStringAndClear(), + sNamespace ); + } + } + } + OUString sOldValue( rAttrList.getValueByName( sAttribName ) ); + OSL_ENSURE( sOldValue.getLength() == 0, "alien attribute exists already" ); + OSL_ENSURE(aData.Type == GetXMLToken(XML_CDATA), "different type to our default type which should be written out"); + if( !sOldValue.getLength() ) + rAttrList.AddAttribute( sAttribName, aData.Value ); + } + + delete pNewNamespaceMap; + } + else + { + handleSpecialItem( rAttrList, rProperty, rUnitConverter, + rNamespaceMap, pProperties, nIdx ); + } + } + else if ( ( maPropMapper->GetEntryFlags( rProperty.mnIndex ) & + MID_FLAG_ELEMENT_ITEM_EXPORT ) == 0 ) + { + OUString aValue; + const OUString sName( rNamespaceMap.GetQNameByKey( + maPropMapper->GetEntryNameSpace( rProperty.mnIndex ), + maPropMapper->GetEntryXMLName( rProperty.mnIndex ) ) ); + + sal_Bool bRemove = sal_False; + if( ( maPropMapper->GetEntryFlags( rProperty.mnIndex ) & + MID_FLAG_MERGE_ATTRIBUTE ) != 0 ) + { + aValue = rAttrList.getValueByName( sName ); + bRemove = sal_True; + } + + if( maPropMapper->exportXML( aValue, rProperty, rUnitConverter ) ) + { + if( bRemove ) + rAttrList.RemoveAttribute( sName ); + rAttrList.AddAttribute( sName, aValue ); + } + } +} + +void SvXMLExportPropertyMapper::exportElementItems( + SvXMLExport& rExport, + const ::std::vector< XMLPropertyState >& rProperties, + sal_uInt16 nFlags, + const SvUShorts& rIndexArray ) const +{ + const sal_uInt16 nCount = rIndexArray.Count(); + + sal_Bool bItemsExported = sal_False; + OUString sWS( GetXMLToken(XML_WS) ); + for( sal_uInt16 nIndex = 0; nIndex < nCount; nIndex++ ) + { + const sal_uInt16 nElement = rIndexArray.GetObject( nIndex ); + + OSL_ENSURE( 0 != ( maPropMapper->GetEntryFlags( + rProperties[nElement].mnIndex ) & MID_FLAG_ELEMENT_ITEM_EXPORT), + "wrong mid flag!" ); + + rExport.IgnorableWhitespace(); + handleElementItem( rExport, rProperties[nElement], + nFlags, &rProperties, nElement ); + bItemsExported = sal_True; + } + + if( bItemsExported ) + rExport.IgnorableWhitespace(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/xmlimppr.cxx b/xmloff/source/style/xmlimppr.cxx new file mode 100644 index 000000000000..cf09b6cdc53c --- /dev/null +++ b/xmloff/source/style/xmlimppr.cxx @@ -0,0 +1,779 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <com/sun/star/xml/AttributeData.hpp> +#include <com/sun/star/beans/XMultiPropertySet.hpp> +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/lang/WrappedTargetException.hpp> +#include <com/sun/star/beans/UnknownPropertyException.hpp> +#include <com/sun/star/beans/PropertyVetoException.hpp> +#include <com/sun/star/beans/TolerantPropertySetResultType.hpp> +#include <rtl/ustrbuf.hxx> +#include <xmloff/xmlprmap.hxx> +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmlimppr.hxx> +#include <xmloff/xmlimp.hxx> + +#include "xmloff/unoatrcn.hxx" +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include "xmloff/xmlerror.hxx" +#include <tools/debug.hxx> + +#include "xmloff/contextid.hxx" + +// STL includes +#include <algorithm> +#include <functional> +#include <utility> +#include <vector> + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::xml; +using namespace ::com::sun::star::xml::sax; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::std; +using namespace ::xmloff::token; +using ::com::sun::star::lang::IllegalArgumentException; +using ::com::sun::star::lang::WrappedTargetException; +using ::com::sun::star::beans::UnknownPropertyException; +using ::com::sun::star::beans::PropertyVetoException; + +using rtl::OUString; +using rtl::OUStringBuffer; + +SvXMLImportPropertyMapper::SvXMLImportPropertyMapper( + const UniReference< XMLPropertySetMapper >& rMapper, + SvXMLImport& rImp ): + rImport(rImp), + maPropMapper ( rMapper ) +{ +} + +SvXMLImportPropertyMapper::~SvXMLImportPropertyMapper() +{ + mxNextMapper = 0; +} + +void SvXMLImportPropertyMapper::ChainImportMapper( + const UniReference< SvXMLImportPropertyMapper>& rMapper ) +{ + // add map entries from rMapper to current map + maPropMapper->AddMapperEntry( rMapper->getPropertySetMapper() ); + // rMapper uses the same map as 'this' + rMapper->maPropMapper = maPropMapper; + + // set rMapper as last mapper in current chain + UniReference< SvXMLImportPropertyMapper > xNext = mxNextMapper; + if( xNext.is()) + { + while( xNext->mxNextMapper.is()) + xNext = xNext->mxNextMapper; + xNext->mxNextMapper = rMapper; + } + else + mxNextMapper = rMapper; + + // if rMapper was already chained, correct + // map pointer of successors + xNext = rMapper; + + while( xNext->mxNextMapper.is()) + { + xNext = xNext->mxNextMapper; + xNext->maPropMapper = maPropMapper; + } +} + +void SvXMLImportPropertyMapper::importXML( + vector< XMLPropertyState >& rProperties, + Reference< XAttributeList > xAttrList, + const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& rNamespaceMap, + sal_uInt32 nPropType ) const +{ + importXML( rProperties, xAttrList, rUnitConverter, rNamespaceMap, + nPropType,-1, -1 ); +} + +/** fills the given itemset with the attributes in the given list */ +void SvXMLImportPropertyMapper::importXML( + vector< XMLPropertyState >& rProperties, + Reference< XAttributeList > xAttrList, + const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& rNamespaceMap, + sal_uInt32 nPropType, + sal_Int32 nStartIdx, + sal_Int32 nEndIdx ) const +{ + sal_Int16 nAttr = xAttrList->getLength(); + + Reference< XNameContainer > xAttrContainer; + + if( -1 == nStartIdx ) + nStartIdx = 0; + if( -1 == nEndIdx ) + nEndIdx = maPropMapper->GetEntryCount(); + for( sal_Int16 i=0; i < nAttr; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + OUString aLocalName, aPrefix, aNamespace; + sal_uInt16 nPrefix = rNamespaceMap.GetKeyByAttrName( rAttrName, &aPrefix, + &aLocalName, &aNamespace ); + + if( XML_NAMESPACE_XMLNS == nPrefix ) + continue; + + const OUString& rValue = xAttrList->getValueByIndex( i ); + + // index of actual property map entry + // This looks very strange, but it works well: + // If the start index is 0, the new value will become -1, and + // GetEntryIndex will start searching with position 0. + // Otherwise GetEntryIndex will start with the next position specified. + sal_Int32 nIndex = nStartIdx - 1; + sal_uInt32 nFlags = 0; // flags of actual property map entry + sal_Bool bFound = sal_False; + + // for better error reporting: this should be set true if no + // warning is needed + sal_Bool bNoWarning = sal_False; + bool bAlienImport = false; + + do + { + // find an entry for this attribute + nIndex = maPropMapper->GetEntryIndex( nPrefix, aLocalName, + nPropType, nIndex ); + + if( nIndex > -1 && nIndex < nEndIdx ) + { + // create a XMLPropertyState with an empty value + + nFlags = maPropMapper->GetEntryFlags( nIndex ); + if( (( nFlags & MID_FLAG_NO_PROPERTY ) == MID_FLAG_NO_PROPERTY) && (maPropMapper->GetEntryContextId( nIndex ) == CTF_ALIEN_ATTRIBUTE_IMPORT) ) + { + bAlienImport = true; + nIndex = -1; + } + else + { + if( ( nFlags & MID_FLAG_ELEMENT_ITEM_IMPORT ) == 0 ) + { + XMLPropertyState aNewProperty( nIndex ); + sal_Int32 nReference = -1; + + // if this is a multi attribute check if another attribute already set + // this any. If so use this as a initial value + if( ( nFlags & MID_FLAG_MERGE_PROPERTY ) != 0 ) + { + const OUString aAPIName( maPropMapper->GetEntryAPIName( nIndex ) ); + const sal_Int32 nSize = rProperties.size(); + for( nReference = 0; nReference < nSize; nReference++ ) + { + sal_Int32 nRefIdx = rProperties[nReference].mnIndex; + if( (nRefIdx != -1) && (nIndex != nRefIdx) && + (maPropMapper->GetEntryAPIName( nRefIdx ) == aAPIName )) + { + aNewProperty = rProperties[nReference]; + aNewProperty.mnIndex = nIndex; + break; + } + } + + if( nReference == nSize ) + nReference = -1; + } + + sal_Bool bSet = sal_False; + if( ( nFlags & MID_FLAG_SPECIAL_ITEM_IMPORT ) == 0 ) + { + // let the XMLPropertySetMapper decide how to import the value + bSet = maPropMapper->importXML( rValue, aNewProperty, + rUnitConverter ); + } + else + { + sal_uInt32 nOldSize = rProperties.size(); + + bSet = handleSpecialItem( aNewProperty, rProperties, + rValue, rUnitConverter, + rNamespaceMap ); + + // no warning if handleSpecialItem added properties + bNoWarning |= ( nOldSize != rProperties.size() ); + } + + // no warning if we found could set the item. This + // 'remembers' bSet across multi properties. + bNoWarning |= bSet; + + // store the property in the given vector + if( bSet ) + { + if( nReference == -1 ) + rProperties.push_back( aNewProperty ); + else + rProperties[nReference] = aNewProperty; + } + else + { + // warn about unknown value. Unless it's a + // multi property: Then we get another chance + // to set the value. + if( !bNoWarning && + ((nFlags & MID_FLAG_MULTI_PROPERTY) == 0) ) + { + Sequence<OUString> aSeq(2); + aSeq[0] = rAttrName; + aSeq[1] = rValue; + rImport.SetError( XMLERROR_FLAG_WARNING | + XMLERROR_STYLE_ATTR_VALUE, + aSeq ); + } + } + } + bFound = sal_True; + continue; + } + } + + if( !bFound ) + { + if( (XML_NAMESPACE_UNKNOWN_FLAG & nPrefix) || (XML_NAMESPACE_NONE == nPrefix) || bAlienImport ) + { + OSL_ENSURE( XML_NAMESPACE_NONE == nPrefix || + (XML_NAMESPACE_UNKNOWN_FLAG & nPrefix) || + bAlienImport, + "unknown attribute - might be a new feature?" ); + if( !xAttrContainer.is() ) + { + // add an unknown attribute container to the properties + Reference< XNameContainer > xNew( SvUnoAttributeContainer_CreateInstance(), UNO_QUERY ); + xAttrContainer = xNew; + + // find map entry and create new property state + if( -1 == nIndex ) + { + switch( nPropType ) + { + case XML_TYPE_PROP_CHART: + nIndex = maPropMapper->FindEntryIndex( "ChartUserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) ); + break; + case XML_TYPE_PROP_PARAGRAPH: + nIndex = maPropMapper->FindEntryIndex( "ParaUserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) ); + break; + case XML_TYPE_PROP_TEXT: + nIndex = maPropMapper->FindEntryIndex( "TextUserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) ); + break; + default: + break; + } + // other property type or property not found + if( -1 == nIndex ) + nIndex = maPropMapper->FindEntryIndex( "UserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) ); + } + + // #106963#; use userdefined attribute only if it is in the specified property range + if( nIndex != -1 && nIndex >= nStartIdx && nIndex < nEndIdx) + { + Any aAny; + aAny <<= xAttrContainer; + XMLPropertyState aNewProperty( nIndex, aAny ); + + // push it on our stack so we export it later + rProperties.push_back( aNewProperty ); + } + } + + if( xAttrContainer.is() ) + { + AttributeData aData; + aData.Type = GetXMLToken( XML_CDATA ); + aData.Value = rValue; + + OUStringBuffer sName; + if( XML_NAMESPACE_NONE != nPrefix ) + { + sName.append( aPrefix ); + sName.append( sal_Unicode(':') ); + aData.Namespace = aNamespace; + } + + sName.append( aLocalName ); + + Any aAny; + aAny <<= aData; + xAttrContainer->insertByName( sName.makeStringAndClear(), aAny ); + } + } + } + } + while( ( nIndex >= 0 ) && (( nFlags & MID_FLAG_MULTI_PROPERTY ) != 0 ) ); + } + + finished( rProperties, nStartIdx, nEndIdx ); +} + +/** this method is called for every item that has the MID_FLAG_SPECIAL_ITEM_IMPORT flag set */ +bool SvXMLImportPropertyMapper::handleSpecialItem( + XMLPropertyState& rProperty, + vector< XMLPropertyState >& rProperties, + const OUString& rValue, + const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& rNamespaceMap ) const +{ + OSL_ENSURE( mxNextMapper.is(), "unsuported special item in xml import" ); + if( mxNextMapper.is() ) + return mxNextMapper->handleSpecialItem( rProperty, rProperties, rValue, + rUnitConverter, rNamespaceMap ); + else + return sal_False; +} + +void SvXMLImportPropertyMapper::FillPropertySequence( + const ::std::vector< XMLPropertyState >& rProperties, + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rValues ) + const +{ + sal_Int32 nCount = rProperties.size(); + sal_Int32 nValueCount = 0; + rValues.realloc( nCount ); + PropertyValue *pProps = rValues.getArray(); + for( sal_Int32 i=0; i < nCount; i++ ) + { + const XMLPropertyState& rProp = rProperties[i]; + sal_Int32 nIdx = rProp.mnIndex; + if( nIdx == -1 ) + continue; + pProps->Name = maPropMapper->GetEntryAPIName( nIdx ); + if( pProps->Name.getLength() ) + { + pProps->Value <<= rProp.maValue; + ++pProps; + ++nValueCount; + } + } + if( nValueCount < nCount ) + rValues.realloc( nValueCount ); +} + +void SvXMLImportPropertyMapper::CheckSpecialContext( + const ::std::vector< XMLPropertyState >& aProperties, + const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet > rPropSet, + _ContextID_Index_Pair* pSpecialContextIds ) const +{ + OSL_ENSURE( rPropSet.is(), "need an XPropertySet" ); + sal_Int32 nCount = aProperties.size(); + + Reference< XPropertySetInfo > xInfo(rPropSet->getPropertySetInfo()); + + for( sal_Int32 i=0; i < nCount; i++ ) + { + const XMLPropertyState& rProp = aProperties[i]; + sal_Int32 nIdx = rProp.mnIndex; + + // disregard property state if it has an invalid index + if( -1 == nIdx ) + continue; + + const sal_Int32 nPropFlags = maPropMapper->GetEntryFlags( nIdx ); + + // handle no-property and special items + if( ( pSpecialContextIds != NULL ) && + ( ( 0 != ( nPropFlags & MID_FLAG_NO_PROPERTY_IMPORT ) ) || + ( 0 != ( nPropFlags & MID_FLAG_SPECIAL_ITEM_IMPORT ) ) ) ) + { + // maybe it's one of our special context ids? + sal_Int16 nContextId = maPropMapper->GetEntryContextId(nIdx); + + for ( sal_Int32 n = 0; + pSpecialContextIds[n].nContextID != -1; + n++ ) + { + // found: set index in pSpecialContextIds array + if ( pSpecialContextIds[n].nContextID == nContextId ) + { + pSpecialContextIds[n].nIndex = i; + break; // early out + } + } + } + } + +} + +sal_Bool SvXMLImportPropertyMapper::FillPropertySet( + const vector< XMLPropertyState >& aProperties, + const Reference< XPropertySet > rPropSet, + _ContextID_Index_Pair* pSpecialContextIds ) const +{ + sal_Bool bSet = sal_False; + + Reference< XTolerantMultiPropertySet > xTolPropSet( rPropSet, UNO_QUERY ); + if (xTolPropSet.is()) + bSet = _FillTolerantMultiPropertySet( aProperties, xTolPropSet, maPropMapper, rImport, + pSpecialContextIds ); + + if (!bSet) + { + // get property set info + Reference< XPropertySetInfo > xInfo(rPropSet->getPropertySetInfo()); + + // check for multi-property set + Reference<XMultiPropertySet> xMultiPropSet( rPropSet, UNO_QUERY ); + if ( xMultiPropSet.is() ) + { + // Try XMultiPropertySet. If that fails, try the regular route. + bSet = _FillMultiPropertySet( aProperties, xMultiPropSet, + xInfo, maPropMapper, + pSpecialContextIds ); + if ( !bSet ) + bSet = _FillPropertySet( aProperties, rPropSet, + xInfo, maPropMapper, rImport, + pSpecialContextIds); + } + else + bSet = _FillPropertySet( aProperties, rPropSet, xInfo, + maPropMapper, rImport, + pSpecialContextIds ); + } + + return bSet; +} + +sal_Bool SvXMLImportPropertyMapper::_FillPropertySet( + const vector<XMLPropertyState> & rProperties, + const Reference<XPropertySet> & rPropSet, + const Reference<XPropertySetInfo> & rPropSetInfo, + const UniReference<XMLPropertySetMapper> & rPropMapper, + SvXMLImport& rImport, + _ContextID_Index_Pair* pSpecialContextIds ) +{ + OSL_ENSURE( rPropSet.is(), "need an XPropertySet" ); + OSL_ENSURE( rPropSetInfo.is(), "need an XPropertySetInfo" ); + + // preliminaries + sal_Bool bSet = sal_False; + sal_Int32 nCount = rProperties.size(); + + // iterate over property states that we want to set + for( sal_Int32 i=0; i < nCount; i++ ) + { + const XMLPropertyState& rProp = rProperties[i]; + sal_Int32 nIdx = rProp.mnIndex; + + // disregard property state if it has an invalid index + if( -1 == nIdx ) + continue; + + const OUString& rPropName = rPropMapper->GetEntryAPIName( nIdx ); + const sal_Int32 nPropFlags = rPropMapper->GetEntryFlags( nIdx ); + + if ( ( 0 == ( nPropFlags & MID_FLAG_NO_PROPERTY ) ) && + ( ( 0 != ( nPropFlags & MID_FLAG_MUST_EXIST ) ) || + rPropSetInfo->hasPropertyByName( rPropName ) ) ) + { + // try setting the property + try + { + rPropSet->setPropertyValue( rPropName, rProp.maValue ); + bSet = sal_True; + } + catch ( IllegalArgumentException& e ) + { + // illegal value: check whether this property is + // allowed to throw this exception + if ( 0 == ( nPropFlags & MID_FLAG_PROPERTY_MAY_EXCEPT ) ) + { + Sequence<OUString> aSeq(1); + aSeq[0] = rPropName; + rImport.SetError( + XMLERROR_STYLE_PROP_VALUE | XMLERROR_FLAG_ERROR, + aSeq, e.Message, NULL ); + } + } + catch ( UnknownPropertyException& e ) + { + // unknown property: This is always an error! + Sequence<OUString> aSeq(1); + aSeq[0] = rPropName; + rImport.SetError( + XMLERROR_STYLE_PROP_UNKNOWN | XMLERROR_FLAG_ERROR, + aSeq, e.Message, NULL ); + } + catch ( PropertyVetoException& e ) + { + // property veto: this shouldn't happen + Sequence<OUString> aSeq(1); + aSeq[0] = rPropName; + rImport.SetError( + XMLERROR_STYLE_PROP_OTHER | XMLERROR_FLAG_ERROR, + aSeq, e.Message, NULL ); + } + catch ( WrappedTargetException& e ) + { + // wrapped target: this shouldn't happen either + Sequence<OUString> aSeq(1); + aSeq[0] = rPropName; + rImport.SetError( + XMLERROR_STYLE_PROP_OTHER | XMLERROR_FLAG_ERROR, + aSeq, e.Message, NULL ); + } + } + + // handle no-property and special items + if( ( pSpecialContextIds != NULL ) && + ( ( 0 != ( nPropFlags & MID_FLAG_NO_PROPERTY_IMPORT ) ) || + ( 0 != ( nPropFlags & MID_FLAG_SPECIAL_ITEM_IMPORT ) ) ) ) + { + // maybe it's one of our special context ids? + sal_Int16 nContextId = rPropMapper->GetEntryContextId(nIdx); + + for ( sal_Int32 n = 0; + pSpecialContextIds[n].nContextID != -1; + n++ ) + { + // found: set index in pSpecialContextIds array + if ( pSpecialContextIds[n].nContextID == nContextId ) + { + pSpecialContextIds[n].nIndex = i; + break; // early out + } + } + } + } + + return bSet; +} + + + +typedef pair<const OUString*, const Any* > PropertyPair; +typedef vector<PropertyPair> PropertyPairs; + +struct PropertyPairLessFunctor : + public std::binary_function<PropertyPair, PropertyPair, bool> +{ + bool operator()( const PropertyPair& a, const PropertyPair& b ) const + { + return (*a.first < *b.first ? true : false); + } +}; + +void SvXMLImportPropertyMapper::_PrepareForMultiPropertySet( + const vector<XMLPropertyState> & rProperties, + const Reference<XPropertySetInfo> & rPropSetInfo, + const UniReference<XMLPropertySetMapper> & rPropMapper, + _ContextID_Index_Pair* pSpecialContextIds, + Sequence<OUString>& rNames, + Sequence<Any>& rValues) +{ + sal_Int32 nCount = rProperties.size(); + + // property pairs structure stores names + values of properties to be set. + PropertyPairs aPropertyPairs; + aPropertyPairs.reserve( nCount ); + + // iterate over property states that we want to set + sal_Int32 i; + for( i = 0; i < nCount; i++ ) + { + const XMLPropertyState& rProp = rProperties[i]; + sal_Int32 nIdx = rProp.mnIndex; + + // disregard property state if it has an invalid index + if( -1 == nIdx ) + continue; + + const OUString& rPropName = rPropMapper->GetEntryAPIName( nIdx ); + const sal_Int32 nPropFlags = rPropMapper->GetEntryFlags( nIdx ); + + if ( ( 0 == ( nPropFlags & MID_FLAG_NO_PROPERTY ) ) && + ( ( 0 != ( nPropFlags & MID_FLAG_MUST_EXIST ) ) || + !rPropSetInfo.is() || + (rPropSetInfo.is() && rPropSetInfo->hasPropertyByName( rPropName )) ) ) + { + // save property into property pair structure + aPropertyPairs.push_back( PropertyPair( &rPropName, &rProp.maValue ) ); + } + + // handle no-property and special items + if( ( pSpecialContextIds != NULL ) && + ( ( 0 != ( nPropFlags & MID_FLAG_NO_PROPERTY_IMPORT ) ) || + ( 0 != ( nPropFlags & MID_FLAG_SPECIAL_ITEM_IMPORT ) ) ) ) + { + // maybe it's one of our special context ids? + sal_Int16 nContextId = rPropMapper->GetEntryContextId(nIdx); + for ( sal_Int32 n = 0; + pSpecialContextIds[n].nContextID != -1; + n++ ) + { + // found: set index in pSpecialContextIds array + if ( pSpecialContextIds[n].nContextID == nContextId ) + { + pSpecialContextIds[n].nIndex = i; + break; // early out + } + } + } + } + + // We now need to construct the sequences and actually the set + // values. + + // sort the property pairs + sort( aPropertyPairs.begin(), aPropertyPairs.end(), + PropertyPairLessFunctor()); + + // create sequences + rNames.realloc( aPropertyPairs.size() ); + OUString* pNamesArray = rNames.getArray(); + rValues.realloc( aPropertyPairs.size() ); + Any* pValuesArray = rValues.getArray(); + + // copy values into sequences + i = 0; + for( PropertyPairs::iterator aIter = aPropertyPairs.begin(); + aIter != aPropertyPairs.end(); + ++aIter ) + { + pNamesArray[i] = *(aIter->first); + pValuesArray[i++] = *(aIter->second); + } +} + +sal_Bool SvXMLImportPropertyMapper::_FillMultiPropertySet( + const vector<XMLPropertyState> & rProperties, + const Reference<XMultiPropertySet> & rMultiPropSet, + const Reference<XPropertySetInfo> & rPropSetInfo, + const UniReference<XMLPropertySetMapper> & rPropMapper, + _ContextID_Index_Pair* pSpecialContextIds ) +{ + OSL_ENSURE( rMultiPropSet.is(), "Need multi property set. "); + OSL_ENSURE( rPropSetInfo.is(), "Need property set info." ); + + sal_Bool bSuccessful = sal_False; + + Sequence<OUString> aNames; + Sequence<Any> aValues; + + _PrepareForMultiPropertySet(rProperties, rPropSetInfo, rPropMapper, pSpecialContextIds, + aNames, aValues); + + // and, finally, try to set the values + try + { + rMultiPropSet->setPropertyValues( aNames, aValues ); + bSuccessful = sal_True; + } + catch ( ... ) + { + OSL_ENSURE(bSuccessful, "Exception caught; style may not be imported correctly."); + } + + return bSuccessful; +} + +sal_Bool SvXMLImportPropertyMapper::_FillTolerantMultiPropertySet( + const vector<XMLPropertyState> & rProperties, + const Reference<XTolerantMultiPropertySet> & rTolMultiPropSet, + const UniReference<XMLPropertySetMapper> & rPropMapper, + SvXMLImport& rImport, + _ContextID_Index_Pair* pSpecialContextIds ) +{ + OSL_ENSURE( rTolMultiPropSet.is(), "Need tolerant multi property set. "); + + sal_Bool bSuccessful = sal_False; + + Sequence<OUString> aNames; + Sequence<Any> aValues; + + _PrepareForMultiPropertySet(rProperties, Reference<XPropertySetInfo>(NULL), rPropMapper, pSpecialContextIds, + aNames, aValues); + + // and, finally, try to set the values + try + { + Sequence< SetPropertyTolerantFailed > aResults(rTolMultiPropSet->setPropertyValuesTolerant( aNames, aValues )); + if (aResults.getLength() == 0) + bSuccessful = sal_True; + else + { + sal_Int32 nCount(aResults.getLength()); + for( sal_Int32 i = 0; i < nCount; ++i) + { + Sequence<OUString> aSeq(1); + aSeq[0] = aResults[i].Name; + rtl::OUString sMessage; + switch (aResults[i].Result) + { + case TolerantPropertySetResultType::UNKNOWN_PROPERTY : + sMessage = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UNKNOWN_PROPERTY")); + break; + case TolerantPropertySetResultType::ILLEGAL_ARGUMENT : + sMessage = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ILLEGAL_ARGUMENT")); + break; + case TolerantPropertySetResultType::PROPERTY_VETO : + sMessage = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PROPERTY_VETO")); + break; + case TolerantPropertySetResultType::WRAPPED_TARGET : + sMessage = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("WRAPPED_TARGET")); + break; + }; + rImport.SetError( + XMLERROR_STYLE_PROP_OTHER | XMLERROR_FLAG_ERROR, + aSeq, sMessage, NULL ); + } + } + } + catch ( ... ) + { + OSL_ENSURE(bSuccessful, "Exception caught; style may not be imported correctly."); + } + + return bSuccessful; +} + +void SvXMLImportPropertyMapper::finished( + vector< XMLPropertyState >& rProperties, + sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const +{ + // nothing to do here + if( mxNextMapper.is() ) + mxNextMapper->finished( rProperties, nStartIndex, nEndIndex ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/xmlnume.cxx b/xmloff/source/style/xmlnume.cxx new file mode 100644 index 000000000000..6ff60f002d39 --- /dev/null +++ b/xmloff/source/style/xmlnume.cxx @@ -0,0 +1,907 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/style/NumberingType.hpp> +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/container/XIndexReplace.hpp> +#include <com/sun/star/awt/XBitmap.hpp> +#include <com/sun/star/awt/FontDescriptor.hpp> +#include <com/sun/star/text/HoriOrientation.hpp> +#include <com/sun/star/text/VertOrientation.hpp> +#include <com/sun/star/text/XChapterNumberingSupplier.hpp> +#include <com/sun/star/text/PositionAndSpaceMode.hpp> +#include <com/sun/star/text/LabelFollow.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> + +#include <rtl/ustrbuf.hxx> + +#include <tools/debug.hxx> + +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include "fonthdl.hxx" +#include "xmloff/XMLTextListAutoStylePool.hxx" +#include <xmloff/xmlnume.hxx> +#include <xmloff/xmlexp.hxx> +#include <tools/fontenum.hxx> + + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::style; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::beans; +using namespace ::xmloff::token; + +static sal_Char const XML_UNO_NAME_NRULE_SYMBOL_TEXT_DISTANCE[] = "SymbolTextDistance"; +static sal_Char const XML_UNO_NAME_NRULE_PARENT_NUMBERING[] = "ParentNumbering"; +static sal_Char const XML_UNO_NAME_NRULE_CHAR_STYLE_NAME[] = "CharStyleName"; +static sal_Char const XML_UNO_NAME_NRULE_BULLET_CHAR[] = "BulletChar"; +static sal_Char const XML_UNO_NAME_NRULE_BULLET_RELSIZE[] = "BulletRelSize"; +static sal_Char const XML_UNO_NAME_NRULE_BULLET_COLOR[] = "BulletColor"; +static sal_Char const XML_UNO_NAME_NRULE_GRAPHIC_BITMAP[] = "GraphicBitmap"; +static sal_Char const XML_UNO_NAME_NRULE_GRAPHIC_SIZE[] = "GraphicSize"; +static sal_Char const XML_UNO_NAME_NRULE_VERT_ORIENT[] = "VertOrient"; +static sal_Char const XML_UNO_NAME_NRULE_NUMBERINGTYPE[] = "NumberingType"; +static sal_Char const XML_UNO_NAME_NRULE_HEADING_STYLE_NAME[] = "HeadingStyleName"; +static sal_Char const XML_UNO_NAME_NRULE_PREFIX[] = "Prefix"; +static sal_Char const XML_UNO_NAME_NRULE_SUFFIX[] = "Suffix"; +static sal_Char const XML_UNO_NAME_NRULE_ADJUST[] = "Adjust"; +static sal_Char const XML_UNO_NAME_NRULE_LEFT_MARGIN[] = "LeftMargin"; +static sal_Char const XML_UNO_NAME_NRULE_FIRST_LINE_OFFSET[] = "FirstLineOffset"; +static sal_Char const XML_UNO_NAME_NRULE_BULLET_FONT[] = "BulletFont"; +static sal_Char const XML_UNO_NAME_NRULE_GRAPHICURL[] = "GraphicURL"; +static sal_Char const XML_UNO_NAME_NRULE_START_WITH[] = "StartWith"; +static sal_Char const XML_UNO_NAME_NRULE_POSITION_AND_SPACE_MODE[] = "PositionAndSpaceMode"; +static sal_Char const XML_UNO_NAME_NRULE_LABEL_FOLLOWED_BY[] = "LabelFollowedBy"; +static sal_Char const XML_UNO_NAME_NRULE_LISTTAB_STOP_POSITION[] = "ListtabStopPosition"; +static sal_Char const XML_UNO_NAME_NRULE_FIRST_LINE_INDENT[] = "FirstLineIndent"; +static sal_Char const XML_UNO_NAME_NRULE_INDENT_AT[] = "IndentAt"; + +void SvxXMLNumRuleExport::exportLevelStyles( const uno::Reference< ::com::sun::star::container::XIndexReplace > & xNumRule, + sal_Bool bOutline ) +{ + sal_Int32 nCount = xNumRule ->getCount(); + for( sal_Int32 i=0; i<nCount; i++ ) + { + uno::Any aEntry( xNumRule->getByIndex( i ) ); + uno::Sequence<beans::PropertyValue> aSeq; + if( aEntry >>= aSeq ) + { + exportLevelStyle( i, aSeq, bOutline ); + } + } +} + +void SvxXMLNumRuleExport::exportLevelStyle( sal_Int32 nLevel, + const uno::Sequence<beans::PropertyValue>& rProps, + sal_Bool bOutline ) +{ + sal_Int16 eType = NumberingType::CHAR_SPECIAL; + + sal_Int16 eAdjust = HoriOrientation::LEFT; + OUString sPrefix, sSuffix; + OUString sTextStyleName; + sal_Bool bHasColor = sal_False; + sal_Int32 nColor = 0; + sal_Int32 nSpaceBefore = 0, nMinLabelWidth = 0, nMinLabelDist = 0; + + sal_Int16 nStartValue = 1, nDisplayLevels = 1, nBullRelSize = 0; + + sal_Unicode cBullet = 0xf095; + OUString sBulletFontName, sBulletFontStyleName ; + sal_Int16 eBulletFontFamily = FAMILY_DONTKNOW; + sal_Int16 eBulletFontPitch = PITCH_DONTKNOW; + rtl_TextEncoding eBulletFontEncoding = RTL_TEXTENCODING_DONTKNOW; + + OUString sImageURL; + uno::Reference< ::com::sun::star::awt::XBitmap > xBitmap; + sal_Int32 nImageWidth = 0, nImageHeight = 0; + sal_Int16 eImageVertOrient = VertOrientation::LINE_CENTER; + + sal_Int16 ePosAndSpaceMode = PositionAndSpaceMode::LABEL_WIDTH_AND_POSITION; + sal_Int16 eLabelFollowedBy = LabelFollow::LISTTAB; + sal_Int32 nListtabStopPosition( 0 ); + sal_Int32 nFirstLineIndent( 0 ); + sal_Int32 nIndentAt( 0 ); + + const sal_Int32 nCount = rProps.getLength(); + const beans::PropertyValue* pPropArray = rProps.getConstArray(); + for( sal_Int32 i=0; i<nCount; i++ ) + { + const beans::PropertyValue& rProp = pPropArray[i]; + + if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_NUMBERINGTYPE, sizeof(XML_UNO_NAME_NRULE_NUMBERINGTYPE)-1 ) ) + { + rProp.Value >>= eType; + } + else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_PREFIX, sizeof(XML_UNO_NAME_NRULE_PREFIX)-1 ) ) + { + rProp.Value >>= sPrefix; + } + else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_SUFFIX, sizeof(XML_UNO_NAME_NRULE_SUFFIX)-1 ) ) + { + rProp.Value >>= sSuffix; + } + else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_BULLET_CHAR, sizeof(XML_UNO_NAME_NRULE_BULLET_CHAR)-1 ) ) + { + OUString sValue; + rProp.Value >>= sValue; + if( sValue.getLength() > 0 ) + { + cBullet = (sal_Unicode)sValue[0]; + } + } + else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_BULLET_RELSIZE, sizeof(XML_UNO_NAME_NRULE_BULLET_RELSIZE)-1 ) ) + { + rProp.Value >>= nBullRelSize; + } + else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_ADJUST, sizeof(XML_UNO_NAME_NRULE_ADJUST)-1 ) ) + { + sal_Int16 nValue = 0; + rProp.Value >>= nValue; + eAdjust = nValue; + } + else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_BULLET_FONT, sizeof(XML_UNO_NAME_NRULE_BULLET_FONT)-1 ) ) + { + awt::FontDescriptor rFDesc; + if( rProp.Value >>= rFDesc ) + { + sBulletFontName = rFDesc.Name; + sBulletFontStyleName = rFDesc.StyleName; + eBulletFontFamily = (sal_Int16)rFDesc.Family; + eBulletFontPitch = (sal_Int16)rFDesc.Pitch; + eBulletFontEncoding = (rtl_TextEncoding)rFDesc.CharSet; + } + } + else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_GRAPHICURL, sizeof(XML_UNO_NAME_NRULE_GRAPHICURL)-1 ) ) + { + rProp.Value >>= sImageURL; + } + else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_GRAPHIC_BITMAP, sizeof(XML_UNO_NAME_NRULE_GRAPHIC_BITMAP)-1 ) ) + { + rProp.Value >>= xBitmap; + } + else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_BULLET_COLOR, sizeof(XML_UNO_NAME_NRULE_BULLET_COLOR)-1 ) ) + { + rProp.Value >>= nColor; + bHasColor = sal_True; + } + else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_START_WITH, sizeof(XML_UNO_NAME_NRULE_START_WITH)-1 ) ) + { + rProp.Value >>= nStartValue; + } + else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_LEFT_MARGIN, sizeof(XML_UNO_NAME_NRULE_LEFT_MARGIN)-1 ) ) + { + rProp.Value >>= nSpaceBefore; + } + else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_FIRST_LINE_OFFSET, sizeof(XML_UNO_NAME_NRULE_FIRST_LINE_OFFSET)-1 ) ) + { + rProp.Value >>= nMinLabelWidth; + } + else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_SYMBOL_TEXT_DISTANCE, sizeof(XML_UNO_NAME_NRULE_SYMBOL_TEXT_DISTANCE)-1 ) ) + { + rProp.Value >>= nMinLabelDist; + } + else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_PARENT_NUMBERING, sizeof(XML_UNO_NAME_NRULE_PARENT_NUMBERING)-1 ) ) + { + rProp.Value >>= nDisplayLevels; + if( nDisplayLevels > nLevel+1 ) + nDisplayLevels = static_cast<sal_Int16>( nLevel )+1; + } + else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_CHAR_STYLE_NAME, sizeof(XML_UNO_NAME_NRULE_CHAR_STYLE_NAME)-1 ) ) + { + rProp.Value >>= sTextStyleName; + } + else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_GRAPHIC_SIZE, sizeof(XML_UNO_NAME_NRULE_GRAPHIC_SIZE)-1 ) ) + { + awt::Size aSize; + if( rProp.Value >>= aSize ) + { + nImageWidth = aSize.Width; + nImageHeight = aSize.Height; + } + } + else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_VERT_ORIENT, sizeof(XML_UNO_NAME_NRULE_VERT_ORIENT)-1 ) ) + { + sal_Int16 nValue = 0; + rProp.Value >>= nValue; + eImageVertOrient = nValue; + } + else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_POSITION_AND_SPACE_MODE, + sizeof(XML_UNO_NAME_NRULE_POSITION_AND_SPACE_MODE)-1 ) ) + { + sal_Int16 nValue = 0; + rProp.Value >>= nValue; + ePosAndSpaceMode = nValue; + } + else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_LABEL_FOLLOWED_BY, + sizeof(XML_UNO_NAME_NRULE_LABEL_FOLLOWED_BY)-1 ) ) + { + sal_Int16 nValue = 0; + rProp.Value >>= nValue; + eLabelFollowedBy = nValue; + } + else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_LISTTAB_STOP_POSITION, + sizeof(XML_UNO_NAME_NRULE_LISTTAB_STOP_POSITION)-1 ) ) + { + rProp.Value >>= nListtabStopPosition; + } + else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_FIRST_LINE_INDENT, + sizeof(XML_UNO_NAME_NRULE_FIRST_LINE_INDENT)-1 ) ) + { + rProp.Value >>= nFirstLineIndent; + } + else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_INDENT_AT, + sizeof(XML_UNO_NAME_NRULE_INDENT_AT)-1 ) ) + { + rProp.Value >>= nIndentAt; + } + } + + if( bOutline && (NumberingType::CHAR_SPECIAL == eType || + NumberingType::BITMAP == eType) ) + { + DBG_ASSERT( !bOutline, + "SvxXMLNumRuleExport::exportLevelStyle: invalid style for outline" ); + return; + } + + GetExport().CheckAttrList(); + + // text:level + OUStringBuffer sTmp; + sTmp.append( nLevel + 1 ); + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_LEVEL, sTmp.makeStringAndClear() ); + // #i110694#: no style-name on list-level-style-image + // #i116149#: neither prefix/suffix + if (NumberingType::BITMAP != eType) + { + if (sTextStyleName.getLength() > 0) + { + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME, + GetExport().EncodeStyleName( sTextStyleName ) ); + } + if (sPrefix.getLength() > 0) + { + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NUM_PREFIX, + sPrefix ); + } + if (sSuffix.getLength() > 0) + { + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NUM_SUFFIX, + sSuffix ); + } + } + + enum XMLTokenEnum eElem = XML_LIST_LEVEL_STYLE_NUMBER; + if( NumberingType::CHAR_SPECIAL == eType ) + { + // <text:list-level-style-bullet> + eElem = XML_LIST_LEVEL_STYLE_BULLET; + + if( cBullet ) + { + if( cBullet < ' ' ) + { + cBullet = 0xF000 + 149; + } + // text:bullet-char="..." + sTmp.append( cBullet ); + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_BULLET_CHAR, + sTmp.makeStringAndClear() ); + } + + } + else if( NumberingType::BITMAP == eType ) + { + // <text:list-level-style-image> + + eElem = XML_LIST_LEVEL_STYLE_IMAGE; + + + if( sImageURL.getLength() ) + { + OUString sURL( GetExport().AddEmbeddedGraphicObject( sImageURL ) ); + if( sURL.getLength() ) + { + GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sURL ); + + GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE ); + GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED ); + GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD ); + } + } + else + { + DBG_ASSERT( !xBitmap.is(), + "embedded images are not supported by now" ); + } + } + else + { + // <text:list-level-style-number> or <text:outline-level-style> + if( bOutline ) + eElem = XML_OUTLINE_LEVEL_STYLE; + else + eElem = XML_LIST_LEVEL_STYLE_NUMBER; + + GetExport().GetMM100UnitConverter().convertNumFormat( sTmp, eType ); + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NUM_FORMAT, + sTmp.makeStringAndClear() ); + GetExport().GetMM100UnitConverter().convertNumLetterSync( sTmp, eType ); + if( sTmp.getLength() ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_NUM_LETTER_SYNC, + sTmp.makeStringAndClear() ); + + if( nStartValue != 1 ) + { + sTmp.append( (sal_Int32)nStartValue ); + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_START_VALUE, + sTmp.makeStringAndClear() ); + } + if( nDisplayLevels > 1 && NumberingType::NUMBER_NONE != eType ) + { + sTmp.append( (sal_Int32)nDisplayLevels ); + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_DISPLAY_LEVELS, + sTmp.makeStringAndClear() ); + } + } + + { + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, eElem, + sal_True, sal_True ); + + OUStringBuffer sBuffer; + if ( ePosAndSpaceMode == PositionAndSpaceMode::LABEL_WIDTH_AND_POSITION ) + { + nSpaceBefore += nMinLabelWidth; + nMinLabelWidth = -nMinLabelWidth; + if( nSpaceBefore != 0 ) + { + GetExport().GetMM100UnitConverter().convertMeasure( sBuffer, nSpaceBefore ); + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_SPACE_BEFORE, + sBuffer.makeStringAndClear() ); + } + if( nMinLabelWidth != 0 ) + { + GetExport().GetMM100UnitConverter().convertMeasure( sBuffer, nMinLabelWidth ); + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_MIN_LABEL_WIDTH, + sBuffer.makeStringAndClear() ); + } + if( nMinLabelDist > 0 ) + { + GetExport().GetMM100UnitConverter().convertMeasure( sBuffer, nMinLabelDist ); + GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_MIN_LABEL_DISTANCE, + sBuffer.makeStringAndClear() ); + } + } + /* Check, if properties for position-and-space-mode LABEL_ALIGNMENT + are allowed to be exported. (#i89178#) + */ + else if ( ePosAndSpaceMode == PositionAndSpaceMode::LABEL_ALIGNMENT && + mbExportPositionAndSpaceModeLabelAlignment ) + { + GetExport().AddAttribute( XML_NAMESPACE_TEXT, + XML_LIST_LEVEL_POSITION_AND_SPACE_MODE, + XML_LABEL_ALIGNMENT ); + } + if( HoriOrientation::LEFT != eAdjust ) + { + enum XMLTokenEnum eValue = XML_TOKEN_INVALID; + switch( eAdjust ) + { + case HoriOrientation::RIGHT: eValue = XML_END; break; + case HoriOrientation::CENTER: eValue = XML_CENTER; break; + } + if( eValue != XML_TOKEN_INVALID ) + GetExport().AddAttribute( XML_NAMESPACE_FO, XML_TEXT_ALIGN, eValue ); + } + + if( NumberingType::BITMAP == eType ) + { + enum XMLTokenEnum eValue = XML_TOKEN_INVALID; + switch( eImageVertOrient ) + { + case VertOrientation::BOTTOM: // yes, its OK: BOTTOM means that the baseline + // hits the frame at its topmost position + case VertOrientation::LINE_TOP: + case VertOrientation::CHAR_TOP: + eValue = XML_TOP; + break; + case VertOrientation::CENTER: + case VertOrientation::LINE_CENTER: + case VertOrientation::CHAR_CENTER: + eValue = XML_MIDDLE; + break; + case VertOrientation::TOP: // yes, its OK: TOP means that the baseline + // hits the frame at its bottommost position + case VertOrientation::LINE_BOTTOM: + case VertOrientation::CHAR_BOTTOM: + eValue = XML_BOTTOM; + break; + } + if( eValue != XML_TOKEN_INVALID ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_VERTICAL_POS, eValue ); + + eValue = XML_TOKEN_INVALID; + switch( eImageVertOrient ) + { + case VertOrientation::TOP: + case VertOrientation::CENTER: + case VertOrientation::BOTTOM: + eValue = XML_BASELINE; + break; + case VertOrientation::LINE_TOP: + case VertOrientation::LINE_CENTER: + case VertOrientation::LINE_BOTTOM: + eValue = XML_LINE; + break; + case VertOrientation::CHAR_TOP: + case VertOrientation::CHAR_CENTER: + case VertOrientation::CHAR_BOTTOM: + eValue = XML_CHAR; + break; + } + if( eValue != XML_TOKEN_INVALID ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_VERTICAL_REL, eValue ); + + if( nImageWidth > 0 ) + { + GetExport().GetMM100UnitConverter().convertMeasure( sBuffer, nImageWidth ); + GetExport().AddAttribute( XML_NAMESPACE_FO, XML_WIDTH, + sBuffer.makeStringAndClear() ); + } + + if( nImageHeight > 0 ) + { + GetExport().GetMM100UnitConverter().convertMeasure( sBuffer, nImageHeight ); + GetExport().AddAttribute( XML_NAMESPACE_FO, XML_HEIGHT, + sBuffer.makeStringAndClear() ); + } + } + + { + SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE, + XML_LIST_LEVEL_PROPERTIES, sal_True, sal_True ); + + /* Check, if properties for position-and-space-mode LABEL_ALIGNMENT + are allowed to be exported. (#i89178#) + */ + if ( ePosAndSpaceMode == PositionAndSpaceMode::LABEL_ALIGNMENT && + mbExportPositionAndSpaceModeLabelAlignment ) + { + enum XMLTokenEnum eValue = XML_LISTTAB; + if ( eLabelFollowedBy == LabelFollow::SPACE ) + { + eValue = XML_SPACE; + } + else if ( eLabelFollowedBy == LabelFollow::NOTHING ) + { + eValue = XML_NOTHING; + } + GetExport().AddAttribute( XML_NAMESPACE_TEXT, + XML_LABEL_FOLLOWED_BY, eValue ); + + if ( eLabelFollowedBy == LabelFollow::LISTTAB && + nListtabStopPosition > 0 ) + { + GetExport().GetMM100UnitConverter().convertMeasure( sBuffer, nListtabStopPosition ); + GetExport().AddAttribute( XML_NAMESPACE_TEXT, + XML_LIST_TAB_STOP_POSITION, + sBuffer.makeStringAndClear() ); + } + + if ( nFirstLineIndent != 0 ) + { + GetExport().GetMM100UnitConverter().convertMeasure( sBuffer, nFirstLineIndent ); + GetExport().AddAttribute( XML_NAMESPACE_FO, + XML_TEXT_INDENT, + sBuffer.makeStringAndClear() ); + } + + if ( nIndentAt != 0 ) + { + GetExport().GetMM100UnitConverter().convertMeasure( sBuffer, nIndentAt ); + GetExport().AddAttribute( XML_NAMESPACE_FO, + XML_MARGIN_LEFT, + sBuffer.makeStringAndClear() ); + } + + SvXMLElementExport aLabelAlignmentElement( GetExport(), XML_NAMESPACE_STYLE, + XML_LIST_LEVEL_LABEL_ALIGNMENT, + sal_True, sal_True ); + } + } + + if( NumberingType::CHAR_SPECIAL == eType ) + { + if( sBulletFontName.getLength() ) + { + OUString sStyleName = + GetExport().GetFontAutoStylePool()->Find( + sBulletFontName, sBulletFontStyleName, + eBulletFontFamily, eBulletFontPitch, + eBulletFontEncoding ); + + if( sStyleName.getLength() ) + { + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_FONT_NAME, + sStyleName ); + } + else + { + Any aAny; + OUString sTemp; + + const SvXMLUnitConverter& rUnitConv = + GetExport().GetMM100UnitConverter(); + XMLFontFamilyNamePropHdl aFamilyNameHdl; + aAny <<= sBulletFontName; + if( aFamilyNameHdl.exportXML( sTemp, aAny, rUnitConv ) ) + GetExport().AddAttribute( XML_NAMESPACE_FO, + XML_FONT_FAMILY, sTemp ); + + if( sBulletFontStyleName.getLength() ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_FONT_STYLE_NAME, + sBulletFontStyleName ); + + XMLFontFamilyPropHdl aFamilyHdl; + aAny <<= (sal_Int16)eBulletFontFamily; + if( aFamilyHdl.exportXML( sTemp, aAny, rUnitConv ) ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_FONT_FAMILY_GENERIC, + sTemp ); + + XMLFontPitchPropHdl aPitchHdl; + aAny <<= (sal_Int16)eBulletFontPitch; + if( aPitchHdl.exportXML( sTemp, aAny, rUnitConv ) ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_FONT_PITCH, sTemp ); + + XMLFontEncodingPropHdl aEncHdl; + aAny <<= (sal_Int16)eBulletFontEncoding; + if( aEncHdl.exportXML( sTemp, aAny, rUnitConv ) ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_FONT_CHARSET, sTemp ); + } + } + } + if( NumberingType::BITMAP != eType ) + { + // fo:color = "#..." + if( bHasColor ) + { + const Color aColor( nColor ); + if( aColor.GetColor() == 0xffffffff ) + { + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_USE_WINDOW_FONT_COLOR, XML_TRUE ); + } + else + { + SvXMLUnitConverter::convertColor( sBuffer, aColor ); + GetExport().AddAttribute( XML_NAMESPACE_FO, XML_COLOR, + sBuffer.makeStringAndClear() ); + } + } + // fo:height="...%" + if( nBullRelSize ) + { + GetExport().GetMM100UnitConverter().convertPercent( sTmp, nBullRelSize ); + GetExport().AddAttribute( XML_NAMESPACE_FO, XML_FONT_SIZE, + sTmp.makeStringAndClear() ); + } + } + if( GetExport().GetAttrList().getLength() > 0 ) + { + SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE, + XML_TEXT_PROPERTIES, sal_True, sal_True ); + } + if( NumberingType::BITMAP == eType && sImageURL.getLength() ) + { + // optional office:binary-data + GetExport().AddEmbeddedGraphicObjectAsBase64( sImageURL ); + } + } +} + + +uno::Reference< ::com::sun::star::container::XIndexReplace > SvxXMLNumRuleExport::GetUNONumRule() const +{ + return uno::Reference< ::com::sun::star::container::XIndexReplace > (); +} + +void SvxXMLNumRuleExport::AddListStyleAttributes() +{ +} + + +SvxXMLNumRuleExport::SvxXMLNumRuleExport( SvXMLExport& rExp ) : + rExport( rExp ), + sNumberingRules( RTL_CONSTASCII_USTRINGPARAM( "NumberingRules" ) ), + sIsPhysical( RTL_CONSTASCII_USTRINGPARAM( "IsPhysical" ) ), + sIsContinuousNumbering( RTL_CONSTASCII_USTRINGPARAM( "IsContinuousNumbering" ) ), + // Let list style creation depend on Load/Save option "ODF format version" (#i89178#) + mbExportPositionAndSpaceModeLabelAlignment( true ) +{ + switch ( GetExport().getDefaultVersion() ) + { + case SvtSaveOptions::ODFVER_010: + case SvtSaveOptions::ODFVER_011: + { + mbExportPositionAndSpaceModeLabelAlignment = false; + } + break; + default: // ODFVER_UNKNOWN or ODFVER_012 + { + mbExportPositionAndSpaceModeLabelAlignment = true; + } + } +} + +SvxXMLNumRuleExport::~SvxXMLNumRuleExport() +{ +} + +void SvxXMLNumRuleExport::exportNumberingRule( + const OUString& rName, + const Reference< XIndexReplace >& rNumRule ) +{ + Reference< XPropertySet > xPropSet( rNumRule, UNO_QUERY ); + Reference< XPropertySetInfo > xPropSetInfo; + if( xPropSet.is() ) + xPropSetInfo = xPropSet->getPropertySetInfo(); + + GetExport().CheckAttrList(); + + // style:name="..." + if( rName.getLength() ) + { + sal_Bool bEncoded = sal_False; + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME, + GetExport().EncodeStyleName( rName, &bEncoded ) ); + if( bEncoded ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME, + rName); + } + + // text:consecutive-numbering="..." + sal_Bool bContNumbering = sal_False; + if( xPropSetInfo.is() && + xPropSetInfo->hasPropertyByName( sIsContinuousNumbering ) ) + { + Any aAny( xPropSet->getPropertyValue( sIsContinuousNumbering ) ); + bContNumbering = *(sal_Bool *)aAny.getValue(); + } + if( bContNumbering ) + GetExport().AddAttribute( XML_NAMESPACE_TEXT, + XML_CONSECUTIVE_NUMBERING, XML_TRUE ); + + // other application specific attributes + AddListStyleAttributes(); + + { + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, XML_LIST_STYLE , + sal_True, sal_True ); + exportLevelStyles( rNumRule ); + } +} + +sal_Bool SvxXMLNumRuleExport::exportStyle( const Reference< XStyle >& rStyle ) +{ + Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY ); + Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo(); + + Any aAny; + + // Don't export styles that aren't existing really. This may be the + // case for StarOffice Writer's pool styles. + if( xPropSetInfo->hasPropertyByName( sIsPhysical ) ) + { + aAny = xPropSet->getPropertyValue( sIsPhysical ); + if( !*(sal_Bool *)aAny.getValue() ) + return sal_False; + } + + aAny = xPropSet->getPropertyValue( sNumberingRules ); + Reference<XIndexReplace> xNumRule; + aAny >>= xNumRule; + + OUString sName = rStyle->getName(); + + exportNumberingRule( sName, xNumRule ); + + return sal_True; +} + +void SvxXMLNumRuleExport::exportOutline() +{ + Reference< XChapterNumberingSupplier > xCNSupplier( GetExport().GetModel(), + UNO_QUERY ); + DBG_ASSERT( xCNSupplier.is(), "no chapter numbering supplier" ); + + if( xCNSupplier.is() ) + { + Reference< XIndexReplace > xNumRule( xCNSupplier->getChapterNumberingRules() ); + DBG_ASSERT( xNumRule.is(), "no chapter numbering rules" ); + + if( xNumRule.is() ) + { + /* Outline style has property style:name since ODF 1.2 + Thus, export this property and adjust fix for issue #i69627# (#i90780#) + */ + OUString sOutlineStyleName; + { + Reference<XPropertySet> xNumRulePropSet( + xCNSupplier->getChapterNumberingRules(), UNO_QUERY ); + if (xNumRulePropSet.is()) + { + const OUString sName( RTL_CONSTASCII_USTRINGPARAM("Name") ); + xNumRulePropSet->getPropertyValue( sName ) >>= sOutlineStyleName; + } + } + const SvtSaveOptions::ODFDefaultVersion nODFVersion = + GetExport().getDefaultVersion(); + if ( ( nODFVersion == SvtSaveOptions::ODFVER_010 || + nODFVersion == SvtSaveOptions::ODFVER_011 ) && + GetExport().writeOutlineStyleAsNormalListStyle() ) + { + exportNumberingRule( sOutlineStyleName, xNumRule ); + } + else + { + if ( nODFVersion != SvtSaveOptions::ODFVER_010 && + nODFVersion != SvtSaveOptions::ODFVER_011 ) + { + // style:name="..." + GetExport().CheckAttrList(); + if ( sOutlineStyleName.getLength() > 0 ) + { + sal_Bool bEncoded = sal_False; + GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME, + GetExport().EncodeStyleName( sOutlineStyleName, + &bEncoded ) ); + if( bEncoded ) + GetExport().AddAttribute( XML_NAMESPACE_STYLE, + XML_DISPLAY_NAME, + sOutlineStyleName ); + } + } + SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, + XML_OUTLINE_STYLE, sal_True, sal_True ); + exportLevelStyles( xNumRule, sal_True ); + } + } + } +} + +void SvxXMLNumRuleExport::exportStyles( sal_Bool bUsed, + XMLTextListAutoStylePool *pPool, + sal_Bool bExportChapterNumbering ) +{ + if( bExportChapterNumbering ) + exportOutline(); + + Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetExport().GetModel(), UNO_QUERY ); + DBG_ASSERT( xFamiliesSupp.is(), "No XStyleFamiliesSupplier from XModel for export!" ); + if( xFamiliesSupp.is() ) + { + Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() ); + DBG_ASSERT( xFamiliesSupp.is(), "getStyleFamilies() from XModel failed for export!" ); + + if( xFamilies.is() ) + { + const OUString aNumberStyleName( RTL_CONSTASCII_USTRINGPARAM( "NumberingStyles" )); + + Reference< XIndexAccess > xStyles; + if( xFamilies->hasByName( aNumberStyleName ) ) + { + xFamilies->getByName( aNumberStyleName ) >>= xStyles; + + DBG_ASSERT( xStyles.is(), "Style not found for export!" ); + + if( xStyles.is() ) + { + const sal_Int32 nStyles = xStyles->getCount(); + + for( sal_Int32 i=0; i < nStyles; i++ ) + { + Reference< XStyle > xStyle; + xStyles->getByIndex( i ) >>= xStyle; + + if( !bUsed || xStyle->isInUse() ) + { + exportStyle( xStyle ); + if( pPool ) + pPool->RegisterName( xStyle->getName() ); + } + } + } + } + } + } +} + +sal_Bool SvxXMLNumRuleExport::GetOutlineStyles( XMLStringVector& rStyleNames, + const ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XModel > & rModel ) +{ + Reference< XChapterNumberingSupplier > xCNSupplier( rModel, + UNO_QUERY ); + sal_Int32 nLevels = 0; + Reference< XIndexReplace > xNumRule; + if( xCNSupplier.is() ) + { + xNumRule = xCNSupplier->getChapterNumberingRules(); + if( xNumRule.is() ) + nLevels = xNumRule->getCount(); + } + + rStyleNames.resize( nLevels ); + for( sal_Int32 i=0; i<nLevels; i++ ) + { + uno::Any aEntry( xNumRule->getByIndex( i ) ); + uno::Sequence<beans::PropertyValue> aSeq; + if( aEntry >>= aSeq ) + { + const sal_Int32 nCount = aSeq.getLength(); + const beans::PropertyValue* pPropArray = aSeq.getConstArray(); + for( sal_Int32 j=0; j<nCount; j++ ) + { + const beans::PropertyValue& rProp = pPropArray[j]; + + if( rProp.Name.equalsAsciiL( + XML_UNO_NAME_NRULE_HEADING_STYLE_NAME, + sizeof(XML_UNO_NAME_NRULE_HEADING_STYLE_NAME)-1 ) ) + { + rProp.Value >>= rStyleNames[i]; + break; + } + } + } + } + + return nLevels != 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/xmlnumfe.cxx b/xmloff/source/style/xmlnumfe.cxx new file mode 100644 index 000000000000..6124414ffe5b --- /dev/null +++ b/xmloff/source/style/xmlnumfe.cxx @@ -0,0 +1,1809 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + +#define _SVSTDARR_ULONGS +#define _ZFORLIST_DECLARE_TABLE + +#include <svl/svstdarr.hxx> +#include <svl/zforlist.hxx> +#include <svl/zformat.hxx> +#include <svl/numuno.hxx> +#include <i18npool/mslangid.hxx> +#include <tools/debug.hxx> +#include <rtl/math.hxx> +#include <unotools/calendarwrapper.hxx> +#include <unotools/charclass.hxx> +#include <com/sun/star/lang/Locale.hpp> +#include <rtl/ustrbuf.hxx> + +#include <com/sun/star/i18n/NativeNumberXmlAttributes.hpp> + +#include <xmloff/xmlnumfe.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmluconv.hxx> +#include <xmloff/attrlist.hxx> +#include <xmloff/nmspmap.hxx> +#include <xmloff/families.hxx> +#include <xmloff/xmlnumfi.hxx> // SvXMLNumFmtDefaults + +#define _SVSTDARR_USHORTS +#include <svl/svstdarr.hxx> +#include <svl/nfsymbol.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlexp.hxx> + +#include <set> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::xmloff::token; +using namespace ::svt; + +//------------------------------------------------------------------------- + +#define XMLNUM_MAX_PARTS 3 + +//------------------------------------------------------------------------- + +struct LessuInt32 +{ + sal_Bool operator() (const sal_uInt32 rValue1, const sal_uInt32 rValue2) const + { + return rValue1 < rValue2; + } +}; + +typedef std::set< sal_uInt32, LessuInt32 > SvXMLuInt32Set; + +class SvXMLNumUsedList_Impl +{ + SvXMLuInt32Set aUsed; + SvXMLuInt32Set aWasUsed; + SvXMLuInt32Set::iterator aCurrentUsedPos; + sal_uInt32 nUsedCount; + sal_uInt32 nWasUsedCount; + +public: + SvXMLNumUsedList_Impl(); + ~SvXMLNumUsedList_Impl(); + + void SetUsed( sal_uInt32 nKey ); + sal_Bool IsUsed( sal_uInt32 nKey ) const; + sal_Bool IsWasUsed( sal_uInt32 nKey ) const; + void Export(); + + sal_Bool GetFirstUsed(sal_uInt32& nKey); + sal_Bool GetNextUsed(sal_uInt32& nKey); + + void GetWasUsed(uno::Sequence<sal_Int32>& rWasUsed); + void SetWasUsed(const uno::Sequence<sal_Int32>& rWasUsed); +}; + +//------------------------------------------------------------------------- + +struct SvXMLEmbeddedTextEntry +{ + sal_uInt16 nSourcePos; // position in NumberFormat (to skip later) + sal_Int32 nFormatPos; // resulting position in embedded-text element + rtl::OUString aText; + + SvXMLEmbeddedTextEntry( sal_uInt16 nSP, sal_Int32 nFP, const rtl::OUString& rT ) : + nSourcePos(nSP), nFormatPos(nFP), aText(rT) {} +}; + +typedef SvXMLEmbeddedTextEntry* SvXMLEmbeddedTextEntryPtr; +SV_DECL_PTRARR_DEL( SvXMLEmbeddedTextEntryArr, SvXMLEmbeddedTextEntryPtr, 4, 4 ) + +//------------------------------------------------------------------------- + +SV_IMPL_PTRARR( SvXMLEmbeddedTextEntryArr, SvXMLEmbeddedTextEntryPtr ); + +//------------------------------------------------------------------------- + +// +//! SvXMLNumUsedList_Impl should be optimized! +// + +SvXMLNumUsedList_Impl::SvXMLNumUsedList_Impl() : + nUsedCount(0), + nWasUsedCount(0) +{ +} + +SvXMLNumUsedList_Impl::~SvXMLNumUsedList_Impl() +{ +} + +void SvXMLNumUsedList_Impl::SetUsed( sal_uInt32 nKey ) +{ + if ( !IsWasUsed(nKey) ) + { + std::pair<SvXMLuInt32Set::iterator, bool> aPair = aUsed.insert( nKey ); + if (aPair.second) + nUsedCount++; + } +} + +sal_Bool SvXMLNumUsedList_Impl::IsUsed( sal_uInt32 nKey ) const +{ + SvXMLuInt32Set::const_iterator aItr = aUsed.find(nKey); + return (aItr != aUsed.end()); +} + +sal_Bool SvXMLNumUsedList_Impl::IsWasUsed( sal_uInt32 nKey ) const +{ + SvXMLuInt32Set::const_iterator aItr = aWasUsed.find(nKey); + return (aItr != aWasUsed.end()); +} + +void SvXMLNumUsedList_Impl::Export() +{ + SvXMLuInt32Set::const_iterator aItr = aUsed.begin(); + while (aItr != aUsed.end()) + { + std::pair<SvXMLuInt32Set::const_iterator, bool> aPair = aWasUsed.insert( *aItr ); + if (aPair.second) + nWasUsedCount++; + ++aItr; + } + aUsed.clear(); + nUsedCount = 0; +} + +sal_Bool SvXMLNumUsedList_Impl::GetFirstUsed(sal_uInt32& nKey) +{ + sal_Bool bRet(sal_False); + aCurrentUsedPos = aUsed.begin(); + if(nUsedCount) + { + DBG_ASSERT(aCurrentUsedPos != aUsed.end(), "something went wrong"); + nKey = *aCurrentUsedPos; + bRet = sal_True; + } + return bRet; +} + +sal_Bool SvXMLNumUsedList_Impl::GetNextUsed(sal_uInt32& nKey) +{ + sal_Bool bRet(sal_False); + if (aCurrentUsedPos != aUsed.end()) + { + ++aCurrentUsedPos; + if (aCurrentUsedPos != aUsed.end()) + { + nKey = *aCurrentUsedPos; + bRet = sal_True; + } + } + return bRet; +} + +void SvXMLNumUsedList_Impl::GetWasUsed(uno::Sequence<sal_Int32>& rWasUsed) +{ + rWasUsed.realloc(nWasUsedCount); + sal_Int32* pWasUsed = rWasUsed.getArray(); + if (pWasUsed) + { + SvXMLuInt32Set::const_iterator aItr = aWasUsed.begin(); + while (aItr != aWasUsed.end()) + { + *pWasUsed = *aItr; + ++aItr; + ++pWasUsed; + } + } +} + +void SvXMLNumUsedList_Impl::SetWasUsed(const uno::Sequence<sal_Int32>& rWasUsed) +{ + DBG_ASSERT(nWasUsedCount == 0, "WasUsed should be empty"); + sal_Int32 nCount(rWasUsed.getLength()); + const sal_Int32* pWasUsed = rWasUsed.getConstArray(); + for (sal_uInt16 i = 0; i < nCount; i++, pWasUsed++) + { + std::pair<SvXMLuInt32Set::const_iterator, bool> aPair = aWasUsed.insert( *pWasUsed ); + if (aPair.second) + nWasUsedCount++; + } +} + +//------------------------------------------------------------------------- + +SvXMLNumFmtExport::SvXMLNumFmtExport( + SvXMLExport& rExp, + const uno::Reference< util::XNumberFormatsSupplier >& rSupp ) : + rExport( rExp ), + sPrefix( OUString(RTL_CONSTASCII_USTRINGPARAM("N")) ), + pFormatter( NULL ), + pCharClass( NULL ), + pLocaleData( NULL ) +{ + // supplier must be SvNumberFormatsSupplierObj + SvNumberFormatsSupplierObj* pObj = + SvNumberFormatsSupplierObj::getImplementation( rSupp ); + if (pObj) + pFormatter = pObj->GetNumberFormatter(); + + if ( pFormatter ) + { + pCharClass = new CharClass( pFormatter->GetServiceManager(), + pFormatter->GetLocale() ); + pLocaleData = new LocaleDataWrapper( pFormatter->GetServiceManager(), + pFormatter->GetLocale() ); + } + else + { + lang::Locale aLocale( MsLangId::convertLanguageToLocale( MsLangId::getSystemLanguage() ) ); + + pCharClass = new CharClass( rExport.getServiceFactory(), aLocale ); + pLocaleData = new LocaleDataWrapper( rExport.getServiceFactory(), aLocale ); + } + + pUsedList = new SvXMLNumUsedList_Impl; +} + +SvXMLNumFmtExport::SvXMLNumFmtExport( + SvXMLExport& rExp, + const ::com::sun::star::uno::Reference< + ::com::sun::star::util::XNumberFormatsSupplier >& rSupp, + const rtl::OUString& rPrefix ) : + rExport( rExp ), + sPrefix( rPrefix ), + pFormatter( NULL ), + pCharClass( NULL ), + pLocaleData( NULL ) +{ + // supplier must be SvNumberFormatsSupplierObj + SvNumberFormatsSupplierObj* pObj = + SvNumberFormatsSupplierObj::getImplementation( rSupp ); + if (pObj) + pFormatter = pObj->GetNumberFormatter(); + + if ( pFormatter ) + { + pCharClass = new CharClass( pFormatter->GetServiceManager(), + pFormatter->GetLocale() ); + pLocaleData = new LocaleDataWrapper( pFormatter->GetServiceManager(), + pFormatter->GetLocale() ); + } + else + { + lang::Locale aLocale( MsLangId::convertLanguageToLocale( MsLangId::getSystemLanguage() ) ); + + pCharClass = new CharClass( rExport.getServiceFactory(), aLocale ); + pLocaleData = new LocaleDataWrapper( rExport.getServiceFactory(), aLocale ); + } + + pUsedList = new SvXMLNumUsedList_Impl; +} + +SvXMLNumFmtExport::~SvXMLNumFmtExport() +{ + delete pUsedList; + delete pLocaleData; + delete pCharClass; +} + +//------------------------------------------------------------------------- + +// +// helper methods +// + +OUString lcl_CreateStyleName( sal_Int32 nKey, sal_Int32 nPart, sal_Bool bDefPart, const rtl::OUString& rPrefix ) +{ + OUStringBuffer aFmtName( 10L ); + aFmtName.append( rPrefix ); + aFmtName.append( nKey ); + if (!bDefPart) + { + aFmtName.append( (sal_Unicode)'P' ); + aFmtName.append( nPart ); + } + return aFmtName.makeStringAndClear(); +} + +void SvXMLNumFmtExport::AddCalendarAttr_Impl( const OUString& rCalendar ) +{ + if ( rCalendar.getLength() ) + { + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_CALENDAR, rCalendar ); + } +} + +void SvXMLNumFmtExport::AddTextualAttr_Impl( sal_Bool bText ) +{ + if ( bText ) // non-textual + { + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_TEXTUAL, XML_TRUE ); + } +} + +void SvXMLNumFmtExport::AddStyleAttr_Impl( sal_Bool bLong ) +{ + if ( bLong ) // short is default + { + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_STYLE, XML_LONG ); + } +} + +void SvXMLNumFmtExport::AddLanguageAttr_Impl( sal_Int32 nLang ) +{ + if ( nLang != LANGUAGE_SYSTEM ) + { + OUString aLangStr, aCountryStr; + MsLangId::convertLanguageToIsoNames( (LanguageType)nLang, aLangStr, aCountryStr ); + + if (aLangStr.getLength()) + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_LANGUAGE, aLangStr ); + if (aCountryStr.getLength()) + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_COUNTRY, aCountryStr ); + } +} + +//------------------------------------------------------------------------- + +// +// methods to write individual elements within a format +// + +void SvXMLNumFmtExport::AddToTextElement_Impl( const OUString& rString ) +{ + // append to sTextContent, write element in FinishTextElement_Impl + // to avoid several text elements following each other + + sTextContent.append( rString ); +} + +void SvXMLNumFmtExport::FinishTextElement_Impl() +{ + if ( sTextContent.getLength() ) + { + SvXMLElementExport aElem( rExport, XML_NAMESPACE_NUMBER, XML_TEXT, + sal_True, sal_False ); + rExport.Characters( sTextContent.makeStringAndClear() ); + } +} + +void SvXMLNumFmtExport::WriteColorElement_Impl( const Color& rColor ) +{ + FinishTextElement_Impl(); + + OUStringBuffer aColStr( 7 ); + SvXMLUnitConverter::convertColor( aColStr, rColor ); + rExport.AddAttribute( XML_NAMESPACE_FO, XML_COLOR, + aColStr.makeStringAndClear() ); + + SvXMLElementExport aElem( rExport, XML_NAMESPACE_STYLE, XML_TEXT_PROPERTIES, + sal_True, sal_False ); +} + +void SvXMLNumFmtExport::WriteCurrencyElement_Impl( const OUString& rString, + const OUString& rExt ) +{ + FinishTextElement_Impl(); + + if ( rExt.getLength() ) + { + sal_Int32 nLang = rExt.toInt32(16); // hex + if ( nLang < 0 ) // extension string may contain "-" separator + nLang = -nLang; + AddLanguageAttr_Impl( nLang ); // adds to pAttrList + } + + SvXMLElementExport aElem( rExport, + XML_NAMESPACE_NUMBER, XML_CURRENCY_SYMBOL, + sal_True, sal_False ); + rExport.Characters( rString ); +} + +void SvXMLNumFmtExport::WriteBooleanElement_Impl() +{ + FinishTextElement_Impl(); + + SvXMLElementExport aElem( rExport, XML_NAMESPACE_NUMBER, XML_BOOLEAN, + sal_True, sal_False ); +} + +void SvXMLNumFmtExport::WriteTextContentElement_Impl() +{ + FinishTextElement_Impl(); + + SvXMLElementExport aElem( rExport, XML_NAMESPACE_NUMBER, XML_TEXT_CONTENT, + sal_True, sal_False ); +} + +// date elements + +void SvXMLNumFmtExport::WriteDayElement_Impl( const OUString& rCalendar, sal_Bool bLong ) +{ + FinishTextElement_Impl(); + + AddCalendarAttr_Impl( rCalendar ); // adds to pAttrList + AddStyleAttr_Impl( bLong ); // adds to pAttrList + + SvXMLElementExport aElem( rExport, XML_NAMESPACE_NUMBER, XML_DAY, + sal_True, sal_False ); +} + +void SvXMLNumFmtExport::WriteMonthElement_Impl( const OUString& rCalendar, sal_Bool bLong, sal_Bool bText ) +{ + FinishTextElement_Impl(); + + AddCalendarAttr_Impl( rCalendar ); // adds to pAttrList + AddStyleAttr_Impl( bLong ); // adds to pAttrList + AddTextualAttr_Impl( bText ); // adds to pAttrList + + SvXMLElementExport aElem( rExport, XML_NAMESPACE_NUMBER, XML_MONTH, + sal_True, sal_False ); +} + +void SvXMLNumFmtExport::WriteYearElement_Impl( const OUString& rCalendar, sal_Bool bLong ) +{ + FinishTextElement_Impl(); + + AddCalendarAttr_Impl( rCalendar ); // adds to pAttrList + AddStyleAttr_Impl( bLong ); // adds to pAttrList + + SvXMLElementExport aElem( rExport, XML_NAMESPACE_NUMBER, XML_YEAR, + sal_True, sal_False ); +} + +void SvXMLNumFmtExport::WriteEraElement_Impl( const OUString& rCalendar, sal_Bool bLong ) +{ + FinishTextElement_Impl(); + + AddCalendarAttr_Impl( rCalendar ); // adds to pAttrList + AddStyleAttr_Impl( bLong ); // adds to pAttrList + + SvXMLElementExport aElem( rExport, XML_NAMESPACE_NUMBER, XML_ERA, + sal_True, sal_False ); +} + +void SvXMLNumFmtExport::WriteDayOfWeekElement_Impl( const OUString& rCalendar, sal_Bool bLong ) +{ + FinishTextElement_Impl(); + + AddCalendarAttr_Impl( rCalendar ); // adds to pAttrList + AddStyleAttr_Impl( bLong ); // adds to pAttrList + + SvXMLElementExport aElem( rExport, XML_NAMESPACE_NUMBER, XML_DAY_OF_WEEK, + sal_True, sal_False ); +} + +void SvXMLNumFmtExport::WriteWeekElement_Impl( const OUString& rCalendar ) +{ + FinishTextElement_Impl(); + + AddCalendarAttr_Impl( rCalendar ); // adds to pAttrList + + SvXMLElementExport aElem( rExport, XML_NAMESPACE_NUMBER, XML_WEEK_OF_YEAR, + sal_True, sal_False ); +} + +void SvXMLNumFmtExport::WriteQuarterElement_Impl( const OUString& rCalendar, sal_Bool bLong ) +{ + FinishTextElement_Impl(); + + AddCalendarAttr_Impl( rCalendar ); // adds to pAttrList + AddStyleAttr_Impl( bLong ); // adds to pAttrList + + SvXMLElementExport aElem( rExport, XML_NAMESPACE_NUMBER, XML_QUARTER, + sal_True, sal_False ); +} + +// time elements + +void SvXMLNumFmtExport::WriteHoursElement_Impl( sal_Bool bLong ) +{ + FinishTextElement_Impl(); + + AddStyleAttr_Impl( bLong ); // adds to pAttrList + + SvXMLElementExport aElem( rExport, XML_NAMESPACE_NUMBER, XML_HOURS, + sal_True, sal_False ); +} + +void SvXMLNumFmtExport::WriteMinutesElement_Impl( sal_Bool bLong ) +{ + FinishTextElement_Impl(); + + AddStyleAttr_Impl( bLong ); // adds to pAttrList + + SvXMLElementExport aElem( rExport, XML_NAMESPACE_NUMBER, XML_MINUTES, + sal_True, sal_False ); +} + +void SvXMLNumFmtExport::WriteSecondsElement_Impl( sal_Bool bLong, sal_uInt16 nDecimals ) +{ + FinishTextElement_Impl(); + + AddStyleAttr_Impl( bLong ); // adds to pAttrList + if ( nDecimals > 0 ) + { + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_DECIMAL_PLACES, + OUString::valueOf( (sal_Int32) nDecimals ) ); + } + + SvXMLElementExport aElem( rExport, XML_NAMESPACE_NUMBER, XML_SECONDS, + sal_True, sal_False ); +} + +void SvXMLNumFmtExport::WriteAMPMElement_Impl() +{ + FinishTextElement_Impl(); + + SvXMLElementExport aElem( rExport, XML_NAMESPACE_NUMBER, XML_AM_PM, + sal_True, sal_False ); +} + +// numbers + +void SvXMLNumFmtExport::WriteNumberElement_Impl( + sal_Int32 nDecimals, sal_Int32 nInteger, + const OUString& rDashStr, sal_Bool bVarDecimals, + sal_Bool bGrouping, sal_Int32 nTrailingThousands, + const SvXMLEmbeddedTextEntryArr& rEmbeddedEntries ) +{ + FinishTextElement_Impl(); + + // decimals + if ( nDecimals >= 0 ) // negative = automatic + { + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_DECIMAL_PLACES, + OUString::valueOf( nDecimals ) ); + } + + // integer digits + if ( nInteger >= 0 ) // negative = automatic + { + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_MIN_INTEGER_DIGITS, + OUString::valueOf( nInteger ) ); + } + + // decimal replacement (dashes) or variable decimals (#) + if ( rDashStr.getLength() || bVarDecimals ) + { + // variable decimals means an empty replacement string + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_DECIMAL_REPLACEMENT, + rDashStr ); + } + + // (automatic) grouping separator + if ( bGrouping ) + { + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_GROUPING, XML_TRUE ); + } + + // display-factor if there are trailing thousands separators + if ( nTrailingThousands ) + { + // each separator character removes three digits + double fFactor = ::rtl::math::pow10Exp( 1.0, 3 * nTrailingThousands ); + + OUStringBuffer aFactStr; + SvXMLUnitConverter::convertDouble( aFactStr, fFactor ); + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_DISPLAY_FACTOR, aFactStr.makeStringAndClear() ); + } + + SvXMLElementExport aElem( rExport, XML_NAMESPACE_NUMBER, XML_NUMBER, + sal_True, sal_True ); + + // number:embedded-text as child elements + + sal_uInt16 nEntryCount = rEmbeddedEntries.Count(); + for (sal_uInt16 nEntry=0; nEntry<nEntryCount; nEntry++) + { + SvXMLEmbeddedTextEntry* pObj = rEmbeddedEntries[nEntry]; + + // position attribute + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_POSITION, + OUString::valueOf( pObj->nFormatPos ) ); + SvXMLElementExport aChildElem( rExport, XML_NAMESPACE_NUMBER, XML_EMBEDDED_TEXT, + sal_True, sal_False ); + + // text as element content + rtl::OUString aContent( pObj->aText ); + while ( nEntry+1 < nEntryCount && rEmbeddedEntries[nEntry+1]->nFormatPos == pObj->nFormatPos ) + { + // The array can contain several elements for the same position in the number + // (for example, literal text and space from underscores). They must be merged + // into a single embedded-text element. + aContent += rEmbeddedEntries[nEntry+1]->aText; + ++nEntry; + } + rExport.Characters( aContent ); + } +} + +void SvXMLNumFmtExport::WriteScientificElement_Impl( + sal_Int32 nDecimals, sal_Int32 nInteger, + sal_Bool bGrouping, sal_Int32 nExp ) +{ + FinishTextElement_Impl(); + + // decimals + if ( nDecimals >= 0 ) // negative = automatic + { + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_DECIMAL_PLACES, + OUString::valueOf( nDecimals ) ); + } + + // integer digits + if ( nInteger >= 0 ) // negative = automatic + { + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_MIN_INTEGER_DIGITS, + OUString::valueOf( nInteger ) ); + } + + // (automatic) grouping separator + if ( bGrouping ) + { + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_GROUPING, XML_TRUE ); + } + + // exponent digits + if ( nExp >= 0 ) + { + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_MIN_EXPONENT_DIGITS, + OUString::valueOf( nExp ) ); + } + + SvXMLElementExport aElem( rExport, + XML_NAMESPACE_NUMBER, XML_SCIENTIFIC_NUMBER, + sal_True, sal_False ); +} + +void SvXMLNumFmtExport::WriteFractionElement_Impl( + sal_Int32 nInteger, sal_Bool bGrouping, + sal_Int32 nNumerator, sal_Int32 nDenominator ) +{ + FinishTextElement_Impl(); + + // integer digits + if ( nInteger >= 0 ) // negative = default (no integer part) + { + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_MIN_INTEGER_DIGITS, + OUString::valueOf( nInteger ) ); + } + + // (automatic) grouping separator + if ( bGrouping ) + { + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_GROUPING, XML_TRUE ); + } + + // numerator digits + if ( nNumerator >= 0 ) + { + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_MIN_NUMERATOR_DIGITS, + OUString::valueOf( nNumerator ) ); + } + + // denominator digits + if ( nDenominator >= 0 ) + { + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_MIN_DENOMINATOR_DIGITS, + OUString::valueOf( nDenominator ) ); + } + + SvXMLElementExport aElem( rExport, XML_NAMESPACE_NUMBER, XML_FRACTION, + sal_True, sal_False ); +} + +// mapping (condition) + +void SvXMLNumFmtExport::WriteMapElement_Impl( sal_Int32 nOp, double fLimit, + sal_Int32 nKey, sal_Int32 nPart ) +{ + FinishTextElement_Impl(); + + if ( nOp != NUMBERFORMAT_OP_NO ) + { + // style namespace + + OUStringBuffer aCondStr( 20L ); + aCondStr.appendAscii( "value()" ); //! define constant + switch ( nOp ) + { + case NUMBERFORMAT_OP_EQ: aCondStr.append( (sal_Unicode) '=' ); break; + case NUMBERFORMAT_OP_NE: aCondStr.appendAscii( "<>" ); break; + case NUMBERFORMAT_OP_LT: aCondStr.append( (sal_Unicode) '<' ); break; + case NUMBERFORMAT_OP_LE: aCondStr.appendAscii( "<=" ); break; + case NUMBERFORMAT_OP_GT: aCondStr.append( (sal_Unicode) '>' ); break; + case NUMBERFORMAT_OP_GE: aCondStr.appendAscii( ">=" ); break; + default: + OSL_FAIL("unknown operator"); + } + ::rtl::math::doubleToUStringBuffer( aCondStr, fLimit, + rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, + '.', true ); + + rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_CONDITION, + aCondStr.makeStringAndClear() ); + + rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_APPLY_STYLE_NAME, + rExport.EncodeStyleName( lcl_CreateStyleName( nKey, nPart, sal_False, + sPrefix ) ) ); + + SvXMLElementExport aElem( rExport, XML_NAMESPACE_STYLE, XML_MAP, + sal_True, sal_False ); + } +} + +//------------------------------------------------------------------------- +// for old (automatic) currency formats: parse currency symbol from text + +xub_StrLen lcl_FindSymbol( const String& sUpperStr, const String& sCurString ) +{ + // search for currency symbol + // Quoting as in ImpSvNumberformatScan::Symbol_Division + + xub_StrLen nCPos = 0; + while (nCPos != STRING_NOTFOUND) + { + nCPos = sUpperStr.Search( sCurString, nCPos ); + if (nCPos != STRING_NOTFOUND) + { + // in Quotes? + xub_StrLen nQ = SvNumberformat::GetQuoteEnd( sUpperStr, nCPos ); + if ( nQ == STRING_NOTFOUND ) + { + // dm can be escaped as "dm or \d + sal_Unicode c; + if ( nCPos == 0 || + ((c = sUpperStr.GetChar(xub_StrLen(nCPos-1))) != '"' + && c != '\\') ) + { + return nCPos; // found + } + else + nCPos++; // continue + } + else + nCPos = nQ + 1; // continue after quote end + } + } + return STRING_NOTFOUND; // not found +} + +sal_Bool SvXMLNumFmtExport::WriteTextWithCurrency_Impl( const OUString& rString, + const ::com::sun::star::lang::Locale& rLocale ) +{ + // returns sal_True if currency element was written + + sal_Bool bRet = sal_False; + + LanguageType nLang = MsLangId::convertLocaleToLanguage( rLocale ); + pFormatter->ChangeIntl( nLang ); + String sCurString, sDummy; + pFormatter->GetCompatibilityCurrency( sCurString, sDummy ); + + pCharClass->setLocale( rLocale ); + String sUpperStr = pCharClass->upper(rString); + xub_StrLen nPos = lcl_FindSymbol( sUpperStr, sCurString ); + if ( nPos != STRING_NOTFOUND ) + { + sal_Int32 nLength = rString.getLength(); + sal_Int32 nCurLen = sCurString.Len(); + sal_Int32 nCont = nPos + nCurLen; + + // text before currency symbol + if ( nPos > 0 ) + AddToTextElement_Impl( rString.copy( 0, nPos ) ); + + // currency symbol (empty string -> default) + OUString sEmpty; + WriteCurrencyElement_Impl( sEmpty, sEmpty ); + bRet = sal_True; + + // text after currency symbol + if ( nCont < nLength ) + AddToTextElement_Impl( rString.copy( nCont, nLength-nCont ) ); + } + else + AddToTextElement_Impl( rString ); // simple text + + return bRet; // sal_True: currency element written +} + +//------------------------------------------------------------------------- + +OUString lcl_GetDefaultCalendar( SvNumberFormatter* pFormatter, LanguageType nLang ) +{ + // get name of first non-gregorian calendar for the language + + OUString aCalendar; + CalendarWrapper* pCalendar = pFormatter->GetCalendar(); + if (pCalendar) + { + lang::Locale aLocale( MsLangId::convertLanguageToLocale( nLang ) ); + + uno::Sequence<OUString> aCals = pCalendar->getAllCalendars( aLocale ); + sal_Int32 nCnt = aCals.getLength(); + sal_Bool bFound = sal_False; + for ( sal_Int32 j=0; j < nCnt && !bFound; j++ ) + { + if ( !aCals[j].equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("gregorian") ) ) + { + aCalendar = aCals[j]; + bFound = sal_True; + } + } + } + return aCalendar; +} + +//------------------------------------------------------------------------- + +sal_Bool lcl_IsInEmbedded( const SvXMLEmbeddedTextEntryArr& rEmbeddedEntries, sal_uInt16 nPos ) +{ + sal_uInt16 nCount = rEmbeddedEntries.Count(); + for (sal_uInt16 i=0; i<nCount; i++) + if ( rEmbeddedEntries[i]->nSourcePos == nPos ) + return sal_True; + + return sal_False; // not found +} + +sal_Bool lcl_IsDefaultDateFormat( const SvNumberformat& rFormat, sal_Bool bSystemDate, NfIndexTableOffset eBuiltIn ) +{ + // make an extra loop to collect date elements, to check if it is a default format + // before adding the automatic-order attribute + + SvXMLDateElementAttributes eDateDOW = XML_DEA_NONE; + SvXMLDateElementAttributes eDateDay = XML_DEA_NONE; + SvXMLDateElementAttributes eDateMonth = XML_DEA_NONE; + SvXMLDateElementAttributes eDateYear = XML_DEA_NONE; + SvXMLDateElementAttributes eDateHours = XML_DEA_NONE; + SvXMLDateElementAttributes eDateMins = XML_DEA_NONE; + SvXMLDateElementAttributes eDateSecs = XML_DEA_NONE; + sal_Bool bDateNoDefault = sal_False; + + sal_uInt16 nPos = 0; + sal_Bool bEnd = sal_False; + short nLastType = 0; + while (!bEnd) + { + short nElemType = rFormat.GetNumForType( 0, nPos, sal_False ); + switch ( nElemType ) + { + case 0: + if ( nLastType == NF_SYMBOLTYPE_STRING ) + bDateNoDefault = sal_True; // text at the end -> no default date format + bEnd = sal_True; // end of format reached + break; + case NF_SYMBOLTYPE_STRING: + case NF_SYMBOLTYPE_DATESEP: + case NF_SYMBOLTYPE_TIMESEP: + case NF_SYMBOLTYPE_TIME100SECSEP: + // text is ignored, except at the end + break; + // same mapping as in SvXMLNumFormatContext::AddNfKeyword: + case NF_KEY_NN: eDateDOW = XML_DEA_SHORT; break; + case NF_KEY_NNN: + case NF_KEY_NNNN: eDateDOW = XML_DEA_LONG; break; + case NF_KEY_D: eDateDay = XML_DEA_SHORT; break; + case NF_KEY_DD: eDateDay = XML_DEA_LONG; break; + case NF_KEY_M: eDateMonth = XML_DEA_SHORT; break; + case NF_KEY_MM: eDateMonth = XML_DEA_LONG; break; + case NF_KEY_MMM: eDateMonth = XML_DEA_TEXTSHORT; break; + case NF_KEY_MMMM: eDateMonth = XML_DEA_TEXTLONG; break; + case NF_KEY_YY: eDateYear = XML_DEA_SHORT; break; + case NF_KEY_YYYY: eDateYear = XML_DEA_LONG; break; + case NF_KEY_H: eDateHours = XML_DEA_SHORT; break; + case NF_KEY_HH: eDateHours = XML_DEA_LONG; break; + case NF_KEY_MI: eDateMins = XML_DEA_SHORT; break; + case NF_KEY_MMI: eDateMins = XML_DEA_LONG; break; + case NF_KEY_S: eDateSecs = XML_DEA_SHORT; break; + case NF_KEY_SS: eDateSecs = XML_DEA_LONG; break; + case NF_KEY_AP: + case NF_KEY_AMPM: break; // AM/PM may or may not be in date/time formats -> ignore by itself + default: + bDateNoDefault = sal_True; // any other element -> no default format + } + nLastType = nElemType; + ++nPos; + } + + if ( bDateNoDefault ) + return sal_False; // additional elements + else + { + NfIndexTableOffset eFound = (NfIndexTableOffset) SvXMLNumFmtDefaults::GetDefaultDateFormat( + eDateDOW, eDateDay, eDateMonth, eDateYear, eDateHours, eDateMins, eDateSecs, bSystemDate ); + + return ( eFound == eBuiltIn ); + } +} + +// +// export one part (condition) +// + +void SvXMLNumFmtExport::ExportPart_Impl( const SvNumberformat& rFormat, sal_uInt32 nKey, + sal_uInt16 nPart, sal_Bool bDefPart ) +{ + //! for the default part, pass the coditions from the other parts! + + // + // element name + // + + NfIndexTableOffset eBuiltIn = pFormatter->GetIndexTableOffset( nKey ); + + short nFmtType = 0; + sal_Bool bThousand = sal_False; + sal_uInt16 nPrecision = 0; + sal_uInt16 nLeading = 0; + rFormat.GetNumForInfo( nPart, nFmtType, bThousand, nPrecision, nLeading); + nFmtType &= ~NUMBERFORMAT_DEFINED; + + // special treatment of builtin formats that aren't detected by normal parsing + // (the same formats that get the type set in SvNumberFormatter::ImpGenerateFormats) + if ( eBuiltIn == NF_NUMBER_STANDARD ) + nFmtType = NUMBERFORMAT_NUMBER; + else if ( eBuiltIn == NF_BOOLEAN ) + nFmtType = NUMBERFORMAT_LOGICAL; + else if ( eBuiltIn == NF_TEXT ) + nFmtType = NUMBERFORMAT_TEXT; + + // #101606# An empty subformat is a valid number-style resulting in an + // empty display string for the condition of the subformat. + if ( nFmtType == NUMBERFORMAT_UNDEFINED && rFormat.GetNumForType( nPart, + 0, sal_False ) == 0 ) + nFmtType = 0; + + XMLTokenEnum eType = XML_TOKEN_INVALID; + switch ( nFmtType ) + { + // type is 0 if a format contains no recognized elements + // (like text only) - this is handled as a number-style. + case 0: + case NUMBERFORMAT_NUMBER: + case NUMBERFORMAT_SCIENTIFIC: + case NUMBERFORMAT_FRACTION: + eType = XML_NUMBER_STYLE; + break; + case NUMBERFORMAT_PERCENT: + eType = XML_PERCENTAGE_STYLE; + break; + case NUMBERFORMAT_CURRENCY: + eType = XML_CURRENCY_STYLE; + break; + case NUMBERFORMAT_DATE: + case NUMBERFORMAT_DATETIME: + eType = XML_DATE_STYLE; + break; + case NUMBERFORMAT_TIME: + eType = XML_TIME_STYLE; + break; + case NUMBERFORMAT_TEXT: + eType = XML_TEXT_STYLE; + break; + case NUMBERFORMAT_LOGICAL: + eType = XML_BOOLEAN_STYLE; + break; + } + DBG_ASSERT( eType != XML_TOKEN_INVALID, "unknown format type" ); + + OUString sAttrValue; + sal_Bool bUserDef = ( ( rFormat.GetType() & NUMBERFORMAT_DEFINED ) != 0 ); + + // + // common attributes for format + // + + // format name (generated from key) - style namespace + rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_NAME, + lcl_CreateStyleName( nKey, nPart, bDefPart, sPrefix ) ); + + // "volatile" attribute for styles used only in maps + if ( !bDefPart ) + rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_VOLATILE, XML_TRUE ); + + // language / country + LanguageType nLang = rFormat.GetLanguage(); + AddLanguageAttr_Impl( nLang ); // adds to pAttrList + + // title (comment) + // titles for builtin formats are not written + sAttrValue = rFormat.GetComment(); + if ( sAttrValue.getLength() && bUserDef && bDefPart ) + { + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_TITLE, sAttrValue ); + } + + // automatic ordering for currency and date formats + // only used for some built-in formats + sal_Bool bAutoOrder = ( eBuiltIn == NF_CURRENCY_1000INT || eBuiltIn == NF_CURRENCY_1000DEC2 || + eBuiltIn == NF_CURRENCY_1000INT_RED || eBuiltIn == NF_CURRENCY_1000DEC2_RED || + eBuiltIn == NF_CURRENCY_1000DEC2_DASHED || + eBuiltIn == NF_DATE_SYSTEM_SHORT || eBuiltIn == NF_DATE_SYSTEM_LONG || + eBuiltIn == NF_DATE_SYS_MMYY || eBuiltIn == NF_DATE_SYS_DDMMM || + eBuiltIn == NF_DATE_SYS_DDMMYYYY || eBuiltIn == NF_DATE_SYS_DDMMYY || + eBuiltIn == NF_DATE_SYS_DMMMYY || eBuiltIn == NF_DATE_SYS_DMMMYYYY || + eBuiltIn == NF_DATE_SYS_DMMMMYYYY || eBuiltIn == NF_DATE_SYS_NNDMMMYY || + eBuiltIn == NF_DATE_SYS_NNDMMMMYYYY || eBuiltIn == NF_DATE_SYS_NNNNDMMMMYYYY || + eBuiltIn == NF_DATETIME_SYSTEM_SHORT_HHMM || eBuiltIn == NF_DATETIME_SYS_DDMMYYYY_HHMMSS ); + + // format source (for date and time formats) + // only used for some built-in formats + sal_Bool bSystemDate = ( eBuiltIn == NF_DATE_SYSTEM_SHORT || + eBuiltIn == NF_DATE_SYSTEM_LONG || + eBuiltIn == NF_DATETIME_SYSTEM_SHORT_HHMM ); + sal_Bool bLongSysDate = ( eBuiltIn == NF_DATE_SYSTEM_LONG ); + + // check if the format definition matches the key + if ( bAutoOrder && ( nFmtType == NUMBERFORMAT_DATE || nFmtType == NUMBERFORMAT_DATETIME ) && + !lcl_IsDefaultDateFormat( rFormat, bSystemDate, eBuiltIn ) ) + { + bAutoOrder = bSystemDate = bLongSysDate = sal_False; // don't write automatic-order attribute then + } + + if ( bAutoOrder && + ( nFmtType == NUMBERFORMAT_CURRENCY || nFmtType == NUMBERFORMAT_DATE || nFmtType == NUMBERFORMAT_DATETIME ) ) + { + // #85109# format type must be checked to avoid dtd errors if + // locale data contains other format types at the built-in positions + + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_AUTOMATIC_ORDER, + XML_TRUE ); + } + + if ( bSystemDate && bAutoOrder && + ( nFmtType == NUMBERFORMAT_DATE || nFmtType == NUMBERFORMAT_DATETIME ) ) + { + // #85109# format type must be checked to avoid dtd errors if + // locale data contains other format types at the built-in positions + + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_FORMAT_SOURCE, + XML_LANGUAGE ); + } + + // overflow for time formats as in [hh]:mm + // controlled by bThousand from number format info + // default for truncate-on-overflow is true + if ( nFmtType == NUMBERFORMAT_TIME && bThousand ) + { + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_TRUNCATE_ON_OVERFLOW, + XML_FALSE ); + } + + // + // Native number transliteration + // + ::com::sun::star::i18n::NativeNumberXmlAttributes aAttr; + rFormat.GetNatNumXml( aAttr, nPart ); + if ( aAttr.Format.getLength() ) + { + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_FORMAT, + aAttr.Format ); + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_LANGUAGE, + aAttr.Locale.Language ); + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_COUNTRY, + aAttr.Locale.Country ); + rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_STYLE, + aAttr.Style ); + } + + // + // The element + // + SvXMLElementExport aElem( rExport, XML_NAMESPACE_NUMBER, eType, + sal_True, sal_True ); + + // + // color (properties element) + // + + const Color* pCol = rFormat.GetColor( nPart ); + if (pCol) + WriteColorElement_Impl(*pCol); + + + // detect if there is "real" content, excluding color and maps + //! move to implementation of Write... methods? + sal_Bool bAnyContent = sal_False; + + // + // format elements + // + + SvXMLEmbeddedTextEntryArr aEmbeddedEntries(0); + if ( eBuiltIn == NF_NUMBER_STANDARD ) + { + // default number format contains just one number element + WriteNumberElement_Impl( -1, 1, OUString(), sal_False, sal_False, 0, aEmbeddedEntries ); + bAnyContent = sal_True; + } + else if ( eBuiltIn == NF_BOOLEAN ) + { + // boolean format contains just one boolean element + WriteBooleanElement_Impl(); + bAnyContent = sal_True; + } + else + { + // first loop to collect attributes + + sal_Bool bDecDashes = sal_False; + sal_Bool bVarDecimals = sal_False; + sal_Bool bExpFound = sal_False; + sal_Bool bCurrFound = sal_False; + sal_Bool bInInteger = sal_True; + sal_Int32 nExpDigits = 0; + sal_Int32 nIntegerSymbols = 0; // for embedded-text, including "#" + sal_Int32 nTrailingThousands = 0; // thousands-separators after all digits + OUString sCurrExt; + OUString aCalendar; + sal_uInt16 nPos = 0; + sal_Bool bEnd = sal_False; + while (!bEnd) + { + short nElemType = rFormat.GetNumForType( nPart, nPos, sal_False ); + const XubString* pElemStr = rFormat.GetNumForString( nPart, nPos, sal_False ); + + switch ( nElemType ) + { + case 0: + bEnd = sal_True; // end of format reached + break; + case NF_SYMBOLTYPE_DIGIT: + if ( bExpFound && pElemStr ) + nExpDigits += pElemStr->Len(); + else if ( !bDecDashes && pElemStr && pElemStr->GetChar(0) == '-' ) + bDecDashes = sal_True; + else if ( !bVarDecimals && !bInInteger && pElemStr && pElemStr->GetChar(0) == '#' ) + { + // If the decimal digits string starts with a '#', variable + // decimals is assumed (for 0.###, but not 0.0##). + bVarDecimals = sal_True; + } + if ( bInInteger && pElemStr ) + nIntegerSymbols += pElemStr->Len(); + nTrailingThousands = 0; + break; + case NF_SYMBOLTYPE_DECSEP: + bInInteger = sal_False; + break; + case NF_SYMBOLTYPE_THSEP: + if (pElemStr) + nTrailingThousands += pElemStr->Len(); // is reset to 0 if digits follow + break; + case NF_SYMBOLTYPE_EXP: + bExpFound = sal_True; // following digits are exponent digits + bInInteger = sal_False; + break; + case NF_SYMBOLTYPE_CURRENCY: + bCurrFound = sal_True; + break; + case NF_SYMBOLTYPE_CURREXT: + if (pElemStr) + sCurrExt = *pElemStr; + break; + + // E, EE, R, RR: select non-gregorian calendar + // AAA, AAAA: calendar is switched at the position of the element + case NF_KEY_EC: + case NF_KEY_EEC: + case NF_KEY_R: + case NF_KEY_RR: + if (!aCalendar.getLength()) + aCalendar = lcl_GetDefaultCalendar( pFormatter, nLang ); + break; + } + ++nPos; + } + + // collect strings for embedded-text (must be known before number element is written) + + sal_Bool bAllowEmbedded = ( nFmtType == 0 || nFmtType == NUMBERFORMAT_NUMBER || + nFmtType == NUMBERFORMAT_CURRENCY || + nFmtType == NUMBERFORMAT_PERCENT ); + if ( bAllowEmbedded ) + { + sal_Int32 nDigitsPassed = 0; + nPos = 0; + bEnd = sal_False; + while (!bEnd) + { + short nElemType = rFormat.GetNumForType( nPart, nPos, sal_False ); + const XubString* pElemStr = rFormat.GetNumForString( nPart, nPos, sal_False ); + + switch ( nElemType ) + { + case 0: + bEnd = sal_True; // end of format reached + break; + case NF_SYMBOLTYPE_DIGIT: + if ( pElemStr ) + nDigitsPassed += pElemStr->Len(); + break; + case NF_SYMBOLTYPE_STRING: + case NF_SYMBOLTYPE_BLANK: + case NF_SYMBOLTYPE_PERCENT: + if ( nDigitsPassed > 0 && nDigitsPassed < nIntegerSymbols && pElemStr ) + { + // text (literal or underscore) within the integer part of a number:number element + + String aEmbeddedStr; + if ( nElemType == NF_SYMBOLTYPE_STRING || nElemType == NF_SYMBOLTYPE_PERCENT ) + aEmbeddedStr = *pElemStr; + else + SvNumberformat::InsertBlanks( aEmbeddedStr, 0, pElemStr->GetChar(1) ); + + sal_Int32 nEmbedPos = nIntegerSymbols - nDigitsPassed; + + SvXMLEmbeddedTextEntry* pObj = new SvXMLEmbeddedTextEntry( nPos, nEmbedPos, aEmbeddedStr ); + aEmbeddedEntries.Insert( pObj, aEmbeddedEntries.Count() ); + } + break; + } + ++nPos; + } + } + + // final loop to write elements + + sal_Bool bNumWritten = sal_False; + sal_Bool bCurrencyWritten = sal_False; + short nPrevType = 0; + nPos = 0; + bEnd = sal_False; + while (!bEnd) + { + short nElemType = rFormat.GetNumForType( nPart, nPos, sal_False ); + const XubString* pElemStr = rFormat.GetNumForString( nPart, nPos, sal_False ); + + switch ( nElemType ) + { + case 0: + bEnd = sal_True; // end of format reached + break; + case NF_SYMBOLTYPE_STRING: + case NF_SYMBOLTYPE_DATESEP: + case NF_SYMBOLTYPE_TIMESEP: + case NF_SYMBOLTYPE_TIME100SECSEP: + case NF_SYMBOLTYPE_PERCENT: + if (pElemStr) + { + if ( ( nPrevType == NF_KEY_S || nPrevType == NF_KEY_SS ) && + ( nElemType == NF_SYMBOLTYPE_TIME100SECSEP ) && + nPrecision > 0 ) + { + // decimal separator after seconds is implied by + // "decimal-places" attribute and must not be written + // as text element + //! difference between '.' and ',' is lost here + } + else if ( lcl_IsInEmbedded( aEmbeddedEntries, nPos ) ) + { + // text is written as embedded-text child of the number, + // don't create a text element + } + else if ( nFmtType == NUMBERFORMAT_CURRENCY && !bCurrFound && !bCurrencyWritten ) + { + // automatic currency symbol is implemented as part of + // normal text -> search for the symbol + bCurrencyWritten = WriteTextWithCurrency_Impl( *pElemStr, + MsLangId::convertLanguageToLocale( nLang ) ); + bAnyContent = sal_True; + } + else + AddToTextElement_Impl( *pElemStr ); + } + break; + case NF_SYMBOLTYPE_BLANK: + if ( pElemStr && !lcl_IsInEmbedded( aEmbeddedEntries, nPos ) ) + { + // turn "_x" into the number of spaces used for x in InsertBlanks in the NumberFormat + // (#i20396# the spaces may also be in embedded-text elements) + + String aBlanks; + SvNumberformat::InsertBlanks( aBlanks, 0, pElemStr->GetChar(1) ); + AddToTextElement_Impl( aBlanks ); + } + break; + case NF_KEY_GENERAL : + WriteNumberElement_Impl( -1, 1, OUString(), sal_False, sal_False, 0, aEmbeddedEntries ); + break; + case NF_KEY_CCC: + if (pElemStr) + { + if ( bCurrencyWritten ) + AddToTextElement_Impl( *pElemStr ); // never more than one currency element + else + { + //! must be different from short automatic format + //! but should still be empty (meaning automatic) + // pElemStr is "CCC" + + WriteCurrencyElement_Impl( *pElemStr, OUString() ); + bAnyContent = sal_True; + bCurrencyWritten = sal_True; + } + } + break; + case NF_SYMBOLTYPE_CURRENCY: + if (pElemStr) + { + if ( bCurrencyWritten ) + AddToTextElement_Impl( *pElemStr ); // never more than one currency element + else + { + WriteCurrencyElement_Impl( *pElemStr, sCurrExt ); + bAnyContent = sal_True; + bCurrencyWritten = sal_True; + } + } + break; + case NF_SYMBOLTYPE_DIGIT: + if (!bNumWritten) // write number part + { + switch ( nFmtType ) + { + // for type 0 (not recognized as a special type), + // write a "normal" number + case 0: + case NUMBERFORMAT_NUMBER: + case NUMBERFORMAT_CURRENCY: + case NUMBERFORMAT_PERCENT: + { + // decimals + // only some built-in formats have automatic decimals + sal_Int32 nDecimals = nPrecision; // from GetFormatSpecialInfo + if ( eBuiltIn == NF_NUMBER_STANDARD || + eBuiltIn == NF_CURRENCY_1000DEC2 || + eBuiltIn == NF_CURRENCY_1000DEC2_RED || + eBuiltIn == NF_CURRENCY_1000DEC2_CCC || + eBuiltIn == NF_CURRENCY_1000DEC2_DASHED ) + nDecimals = -1; + + // integer digits + // only one built-in format has automatic integer digits + sal_Int32 nInteger = nLeading; + if ( eBuiltIn == NF_NUMBER_SYSTEM ) + nInteger = -1; + + // string for decimal replacement + // has to be taken from nPrecision + // (positive number even for automatic decimals) + String sDashStr; + if ( bDecDashes && nPrecision > 0 ) + sDashStr.Fill( nPrecision, '-' ); + + WriteNumberElement_Impl( nDecimals, nInteger, sDashStr, bVarDecimals, + bThousand, nTrailingThousands, aEmbeddedEntries ); + bAnyContent = sal_True; + } + break; + case NUMBERFORMAT_SCIENTIFIC: + // #i43959# for scientific numbers, count all integer symbols ("0" and "#") + // as integer digits: use nIntegerSymbols instead of nLeading + // (use of '#' to select multiples in exponent might be added later) + WriteScientificElement_Impl( nPrecision, nIntegerSymbols, bThousand, nExpDigits ); + bAnyContent = sal_True; + break; + case NUMBERFORMAT_FRACTION: + { + sal_Int32 nInteger = nLeading; + if ( pElemStr && pElemStr->GetChar(0) == '?' ) + { + // If the first digit character is a question mark, + // the fraction doesn't have an integer part, and no + // min-integer-digits attribute must be written. + nInteger = -1; + } + WriteFractionElement_Impl( nInteger, bThousand, nPrecision, nPrecision ); + bAnyContent = sal_True; + } + break; + } + + bNumWritten = sal_True; + } + break; + case NF_SYMBOLTYPE_DECSEP: + if ( pElemStr && nPrecision == 0 ) + { + // A decimal separator after the number, without following decimal digits, + // isn't modelled as part of the number element, so it's written as text + // (the distinction between a quoted and non-quoted, locale-dependent + // character is lost here). + + AddToTextElement_Impl( *pElemStr ); + } + break; + case NF_SYMBOLTYPE_DEL: + if ( pElemStr && *pElemStr == XubString('@') ) + { + WriteTextContentElement_Impl(); + bAnyContent = sal_True; + } + break; + + case NF_SYMBOLTYPE_CALENDAR: + if ( pElemStr ) + aCalendar = *pElemStr; + break; + + // date elements: + + case NF_KEY_D: + case NF_KEY_DD: + { + sal_Bool bLong = ( nElemType == NF_KEY_DD ); + WriteDayElement_Impl( aCalendar, ( bSystemDate ? bLongSysDate : bLong ) ); + bAnyContent = sal_True; + } + break; + case NF_KEY_DDD: + case NF_KEY_DDDD: + case NF_KEY_NN: + case NF_KEY_NNN: + case NF_KEY_NNNN: + case NF_KEY_AAA: + case NF_KEY_AAAA: + { + OUString aCalAttr = aCalendar; + if ( nElemType == NF_KEY_AAA || nElemType == NF_KEY_AAAA ) + { + // calendar attribute for AAA and AAAA is switched only for this element + if (!aCalAttr.getLength()) + aCalAttr = lcl_GetDefaultCalendar( pFormatter, nLang ); + } + + sal_Bool bLong = ( nElemType == NF_KEY_NNN || nElemType == NF_KEY_NNNN || + nElemType == NF_KEY_DDDD || nElemType == NF_KEY_AAAA ); + WriteDayOfWeekElement_Impl( aCalAttr, ( bSystemDate ? bLongSysDate : bLong ) ); + bAnyContent = sal_True; + if ( nElemType == NF_KEY_NNNN ) + { + // write additional text element for separator + pLocaleData->setLocale( MsLangId::convertLanguageToLocale( nLang ) ); + AddToTextElement_Impl( pLocaleData->getLongDateDayOfWeekSep() ); + } + } + break; + case NF_KEY_M: + case NF_KEY_MM: + case NF_KEY_MMM: + case NF_KEY_MMMM: + case NF_KEY_MMMMM: //! first letter of month name, no attribute available + { + sal_Bool bLong = ( nElemType == NF_KEY_MM || nElemType == NF_KEY_MMMM ); + sal_Bool bText = ( nElemType == NF_KEY_MMM || nElemType == NF_KEY_MMMM || + nElemType == NF_KEY_MMMMM ); + WriteMonthElement_Impl( aCalendar, ( bSystemDate ? bLongSysDate : bLong ), bText ); + bAnyContent = sal_True; + } + break; + case NF_KEY_YY: + case NF_KEY_YYYY: + case NF_KEY_EC: + case NF_KEY_EEC: + case NF_KEY_R: //! R acts as EE, no attribute available + { + //! distinguish EE and R + // calendar attribute for E and EE and R is set in first loop + sal_Bool bLong = ( nElemType == NF_KEY_YYYY || nElemType == NF_KEY_EEC || + nElemType == NF_KEY_R ); + WriteYearElement_Impl( aCalendar, ( bSystemDate ? bLongSysDate : bLong ) ); + bAnyContent = sal_True; + } + break; + case NF_KEY_G: + case NF_KEY_GG: + case NF_KEY_GGG: + case NF_KEY_RR: //! RR acts as GGGEE, no attribute available + { + //! distinguish GG and GGG and RR + sal_Bool bLong = ( nElemType == NF_KEY_GGG || nElemType == NF_KEY_RR ); + WriteEraElement_Impl( aCalendar, ( bSystemDate ? bLongSysDate : bLong ) ); + bAnyContent = sal_True; + if ( nElemType == NF_KEY_RR ) + { + // calendar attribute for RR is set in first loop + WriteYearElement_Impl( aCalendar, ( bSystemDate ? bLongSysDate : sal_True ) ); + } + } + break; + case NF_KEY_Q: + case NF_KEY_QQ: + { + sal_Bool bLong = ( nElemType == NF_KEY_QQ ); + WriteQuarterElement_Impl( aCalendar, ( bSystemDate ? bLongSysDate : bLong ) ); + bAnyContent = sal_True; + } + break; + case NF_KEY_WW: + WriteWeekElement_Impl( aCalendar ); + bAnyContent = sal_True; + break; + + // time elements (bSystemDate is not used): + + case NF_KEY_H: + case NF_KEY_HH: + WriteHoursElement_Impl( nElemType == NF_KEY_HH ); + bAnyContent = sal_True; + break; + case NF_KEY_MI: + case NF_KEY_MMI: + WriteMinutesElement_Impl( nElemType == NF_KEY_MMI ); + bAnyContent = sal_True; + break; + case NF_KEY_S: + case NF_KEY_SS: + WriteSecondsElement_Impl( ( nElemType == NF_KEY_SS ), nPrecision ); + bAnyContent = sal_True; + break; + case NF_KEY_AMPM: + case NF_KEY_AP: + WriteAMPMElement_Impl(); // short/long? + bAnyContent = sal_True; + break; + } + nPrevType = nElemType; + ++nPos; + } + } + + if ( sTextContent.getLength() ) + bAnyContent = sal_True; // element written in FinishTextElement_Impl + + FinishTextElement_Impl(); // final text element - before maps + + if ( !bAnyContent ) + { + // for an empty format, write an empty text element + SvXMLElementExport aTElem( rExport, XML_NAMESPACE_NUMBER, XML_TEXT, + sal_True, sal_False ); + } + + // + // mapping (conditions) must be last elements + // + + if (bDefPart) + { + SvNumberformatLimitOps eOp1, eOp2; + double fLimit1, fLimit2; + rFormat.GetConditions( eOp1, fLimit1, eOp2, fLimit2 ); + + WriteMapElement_Impl( eOp1, fLimit1, nKey, 0 ); + WriteMapElement_Impl( eOp2, fLimit2, nKey, 1 ); + + if ( rFormat.HasTextFormat() ) + { + // 4th part is for text -> make an "all other numbers" condition for the 3rd part + // by reversing the 2nd condition + + SvNumberformatLimitOps eOp3 = NUMBERFORMAT_OP_NO; + double fLimit3 = fLimit2; + switch ( eOp2 ) + { + case NUMBERFORMAT_OP_EQ: eOp3 = NUMBERFORMAT_OP_NE; break; + case NUMBERFORMAT_OP_NE: eOp3 = NUMBERFORMAT_OP_EQ; break; + case NUMBERFORMAT_OP_LT: eOp3 = NUMBERFORMAT_OP_GE; break; + case NUMBERFORMAT_OP_LE: eOp3 = NUMBERFORMAT_OP_GT; break; + case NUMBERFORMAT_OP_GT: eOp3 = NUMBERFORMAT_OP_LE; break; + case NUMBERFORMAT_OP_GE: eOp3 = NUMBERFORMAT_OP_LT; break; + default: + break; + } + + if ( fLimit1 == fLimit2 && + ( ( eOp1 == NUMBERFORMAT_OP_LT && eOp2 == NUMBERFORMAT_OP_GT ) || + ( eOp1 == NUMBERFORMAT_OP_GT && eOp2 == NUMBERFORMAT_OP_LT ) ) ) + { + // For <x and >x, add =x as last condition + // (just for readability, <=x would be valid, too) + + eOp3 = NUMBERFORMAT_OP_EQ; + } + + WriteMapElement_Impl( eOp3, fLimit3, nKey, 2 ); + } + } +} + +//------------------------------------------------------------------------- + +// +// export one format +// + +void SvXMLNumFmtExport::ExportFormat_Impl( const SvNumberformat& rFormat, sal_uInt32 nKey ) +{ + sal_uInt16 nUsedParts = 0; + sal_uInt16 nPart; + for (nPart=0; nPart<XMLNUM_MAX_PARTS; nPart++) + if (rFormat.GetNumForType( nPart, 0, sal_False ) != 0) + nUsedParts = nPart+1; + + SvNumberformatLimitOps eOp1, eOp2; + double fLimit1, fLimit2; + rFormat.GetConditions( eOp1, fLimit1, eOp2, fLimit2 ); + + // if conditions are set, even empty formats must be written + + if ( eOp1 != NUMBERFORMAT_OP_NO && nUsedParts < 2 ) + nUsedParts = 2; + if ( eOp2 != NUMBERFORMAT_OP_NO && nUsedParts < 3 ) + nUsedParts = 3; + if ( rFormat.HasTextFormat() && nUsedParts < 4 ) + nUsedParts = 4; + + for (nPart=0; nPart<nUsedParts; nPart++) + { + sal_Bool bDefault = ( nPart+1 == nUsedParts ); // last = default + ExportPart_Impl( rFormat, nKey, nPart, bDefault ); + } +} + +//------------------------------------------------------------------------- + +// +// export method called by application +// + +void SvXMLNumFmtExport::Export( sal_Bool bIsAutoStyle ) +{ + if ( !pFormatter ) + return; // no formatter -> no entries + + sal_uInt32 nKey; + const SvNumberformat* pFormat = NULL; + sal_Bool bNext(pUsedList->GetFirstUsed(nKey)); + while(bNext) + { + pFormat = pFormatter->GetEntry(nKey); + if(pFormat) + ExportFormat_Impl( *pFormat, nKey ); + bNext = pUsedList->GetNextUsed(nKey); + } + if (!bIsAutoStyle) + { + SvUShorts aLanguages; + pFormatter->GetUsedLanguages( aLanguages ); + sal_uInt16 nLangCount = aLanguages.Count(); + for (sal_uInt16 nLangPos=0; nLangPos<nLangCount; nLangPos++) + { + LanguageType nLang = aLanguages[nLangPos]; + + sal_uInt32 nDefaultIndex = 0; + SvNumberFormatTable& rTable = pFormatter->GetEntryTable( + NUMBERFORMAT_DEFINED, nDefaultIndex, nLang ); + pFormat = rTable.First(); + while (pFormat) + { + nKey = rTable.GetCurKey(); + if (!pUsedList->IsUsed(nKey)) + { + DBG_ASSERT((pFormat->GetType() & NUMBERFORMAT_DEFINED) != 0, "a not user defined numberformat found"); + // user-defined and used formats are exported + ExportFormat_Impl( *pFormat, nKey ); + // if it is a user-defined Format it will be added else nothing will hapen + pUsedList->SetUsed(nKey); + } + + pFormat = rTable.Next(); + } + } + } + pUsedList->Export(); +} + +OUString SvXMLNumFmtExport::GetStyleName( sal_uInt32 nKey ) +{ + if(pUsedList->IsUsed(nKey) || pUsedList->IsWasUsed(nKey)) + return lcl_CreateStyleName( nKey, 0, sal_True, sPrefix ); + else + { + OSL_FAIL("There is no written Data-Style"); + return rtl::OUString(); + } +} + +void SvXMLNumFmtExport::SetUsed( sal_uInt32 nKey ) +{ + DBG_ASSERT( pFormatter != NULL, "missing formatter" ); + if( !pFormatter ) + return; + + if (pFormatter->GetEntry(nKey)) + pUsedList->SetUsed( nKey ); + else { + OSL_FAIL("no existing Numberformat found with this key"); + } +} + +void SvXMLNumFmtExport::GetWasUsed(uno::Sequence<sal_Int32>& rWasUsed) +{ + if (pUsedList) + pUsedList->GetWasUsed(rWasUsed); +} + +void SvXMLNumFmtExport::SetWasUsed(const uno::Sequence<sal_Int32>& rWasUsed) +{ + if (pUsedList) + pUsedList->SetWasUsed(rWasUsed); +} + + + +const SvNumberformat* lcl_GetFormat( SvNumberFormatter* pFormatter, + sal_uInt32 nKey ) +{ + return ( pFormatter != NULL ) ? pFormatter->GetEntry( nKey ) : NULL; +} + +sal_uInt32 SvXMLNumFmtExport::ForceSystemLanguage( sal_uInt32 nKey ) +{ + sal_uInt32 nRet = nKey; + + const SvNumberformat* pFormat = lcl_GetFormat( pFormatter, nKey ); + if( pFormat != NULL ) + { + DBG_ASSERT( pFormatter != NULL, "format without formatter?" ); + + xub_StrLen nErrorPos; + short nType = pFormat->GetType(); + + sal_uInt32 nNewKey = pFormatter->GetFormatForLanguageIfBuiltIn( + nKey, LANGUAGE_SYSTEM ); + + if( nNewKey != nKey ) + { + nRet = nNewKey; + } + else + { + String aFormatString( pFormat->GetFormatstring() ); + pFormatter->PutandConvertEntry( + aFormatString, + nErrorPos, nType, nNewKey, + pFormat->GetLanguage(), LANGUAGE_SYSTEM ); + + // success? Then use new key. + if( nErrorPos == 0 ) + nRet = nNewKey; + } + } + + return nRet; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/xmlnumfi.cxx b/xmloff/source/style/xmlnumfi.cxx new file mode 100644 index 000000000000..a09c88233066 --- /dev/null +++ b/xmloff/source/style/xmlnumfi.cxx @@ -0,0 +1,2233 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + +#include <unotools/syslocale.hxx> + +#define _ZFORLIST_DECLARE_TABLE +#include <svl/zforlist.hxx> + +#include <svl/zformat.hxx> +#include <svl/numuno.hxx> +#include <rtl/math.hxx> +#include <i18npool/mslangid.hxx> +#include <tools/debug.hxx> +#include <rtl/ustrbuf.hxx> + +#include <xmloff/xmlnumfi.hxx> +#include <xmloff/xmltkmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/nmspmap.hxx> +#include <xmloff/families.hxx> +#include <xmloff/xmltoken.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::xmloff::token; + +//------------------------------------------------------------------------- + +struct SvXMLNumFmtEntry +{ + rtl::OUString aName; + sal_uInt32 nKey; + sal_Bool bRemoveAfterUse; + + SvXMLNumFmtEntry( const rtl::OUString& rN, sal_uInt32 nK, sal_Bool bR ) : + aName(rN), nKey(nK), bRemoveAfterUse(bR) {} +}; + +typedef SvXMLNumFmtEntry* SvXMLNumFmtEntryPtr; +SV_DECL_PTRARR_DEL( SvXMLNumFmtEntryArr, SvXMLNumFmtEntryPtr, 4, 4 ) + +struct SvXMLEmbeddedElement +{ + sal_Int32 nFormatPos; + rtl::OUString aText; + + SvXMLEmbeddedElement( sal_Int32 nFP, const rtl::OUString& rT ) : + nFormatPos(nFP), aText(rT) {} + + // comparison operators for PTRARR sorting - sorted by position + sal_Bool operator ==( const SvXMLEmbeddedElement& r ) const { return nFormatPos == r.nFormatPos; } + sal_Bool operator < ( const SvXMLEmbeddedElement& r ) const { return nFormatPos < r.nFormatPos; } +}; + +typedef SvXMLEmbeddedElement* SvXMLEmbeddedElementPtr; +SV_DECL_PTRARR_SORT_DEL( SvXMLEmbeddedElementArr, SvXMLEmbeddedElementPtr, 0, 4 ) + +//------------------------------------------------------------------------- + +class SvXMLNumImpData +{ + SvNumberFormatter* pFormatter; + SvXMLTokenMap* pStylesElemTokenMap; + SvXMLTokenMap* pStyleElemTokenMap; + SvXMLTokenMap* pStyleAttrTokenMap; + SvXMLTokenMap* pStyleElemAttrTokenMap; + LocaleDataWrapper* pLocaleData; + SvXMLNumFmtEntryArr aNameEntries; + + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxServiceFactory; + +public: + SvXMLNumImpData( + SvNumberFormatter* pFmt, + const uno::Reference<lang::XMultiServiceFactory>& xServiceFactory ); + ~SvXMLNumImpData(); + + SvNumberFormatter* GetNumberFormatter() const { return pFormatter; } + const SvXMLTokenMap& GetStylesElemTokenMap(); + const SvXMLTokenMap& GetStyleElemTokenMap(); + const SvXMLTokenMap& GetStyleAttrTokenMap(); + const SvXMLTokenMap& GetStyleElemAttrTokenMap(); + const LocaleDataWrapper& GetLocaleData( LanguageType nLang ); + sal_uInt32 GetKeyForName( const rtl::OUString& rName ); + void AddKey( sal_uInt32 nKey, const rtl::OUString& rName, sal_Bool bRemoveAfterUse ); + void SetUsed( sal_uInt32 nKey ); + void RemoveVolatileFormats(); +}; + + +struct SvXMLNumberInfo +{ + sal_Int32 nDecimals; + sal_Int32 nInteger; + sal_Int32 nExpDigits; + sal_Int32 nNumerDigits; + sal_Int32 nDenomDigits; + sal_Bool bGrouping; + sal_Bool bDecReplace; + sal_Bool bVarDecimals; + double fDisplayFactor; + SvXMLEmbeddedElementArr aEmbeddedElements; + + SvXMLNumberInfo() + { + nDecimals = nInteger = nExpDigits = nNumerDigits = nDenomDigits = -1; + bGrouping = bDecReplace = bVarDecimals = sal_False; + fDisplayFactor = 1.0; + } +}; + +class SvXMLNumFmtElementContext : public SvXMLImportContext +{ + SvXMLNumFormatContext& rParent; + sal_uInt16 nType; + rtl::OUStringBuffer aContent; + SvXMLNumberInfo aNumInfo; + LanguageType nElementLang; + sal_Bool bLong; + sal_Bool bTextual; + rtl::OUString sCalendar; + +public: + SvXMLNumFmtElementContext( SvXMLImport& rImport, sal_uInt16 nPrfx, + const rtl::OUString& rLName, + SvXMLNumFormatContext& rParentContext, sal_uInt16 nNewType, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList>& xAttrList ); + virtual ~SvXMLNumFmtElementContext(); + + virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList>& xAttrList ); + virtual void Characters( const rtl::OUString& rChars ); + virtual void EndElement(); + + void AddEmbeddedElement( sal_Int32 nFormatPos, const rtl::OUString& rContent ); +}; + + +class SvXMLNumFmtEmbeddedTextContext : public SvXMLImportContext +{ + SvXMLNumFmtElementContext& rParent; + rtl::OUStringBuffer aContent; + sal_Int32 nTextPosition; + +public: + SvXMLNumFmtEmbeddedTextContext( SvXMLImport& rImport, sal_uInt16 nPrfx, + const rtl::OUString& rLName, + SvXMLNumFmtElementContext& rParentContext, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList>& xAttrList ); + virtual ~SvXMLNumFmtEmbeddedTextContext(); + + virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList>& xAttrList ); + virtual void Characters( const rtl::OUString& rChars ); + virtual void EndElement(); +}; + + +class SvXMLNumFmtMapContext : public SvXMLImportContext +{ + SvXMLNumFormatContext& rParent; + rtl::OUString sCondition; + rtl::OUString sName; + +public: + SvXMLNumFmtMapContext( SvXMLImport& rImport, sal_uInt16 nPrfx, + const rtl::OUString& rLName, + SvXMLNumFormatContext& rParentContext, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList>& xAttrList ); + virtual ~SvXMLNumFmtMapContext(); + + virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList>& xAttrList ); + virtual void Characters( const rtl::OUString& rChars ); + virtual void EndElement(); +}; + + +class SvXMLNumFmtPropContext : public SvXMLImportContext +{ + SvXMLNumFormatContext& rParent; + Color aColor; + sal_Bool bColSet; + +public: + SvXMLNumFmtPropContext( SvXMLImport& rImport, sal_uInt16 nPrfx, + const rtl::OUString& rLName, + SvXMLNumFormatContext& rParentContext, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList>& xAttrList ); + virtual ~SvXMLNumFmtPropContext(); + + virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList>& xAttrList ); + virtual void Characters( const rtl::OUString& rChars ); + virtual void EndElement(); +}; + + +//------------------------------------------------------------------------- + +enum SvXMLStyleTokens +{ + XML_TOK_STYLE_TEXT, + XML_TOK_STYLE_NUMBER, + XML_TOK_STYLE_SCIENTIFIC_NUMBER, + XML_TOK_STYLE_FRACTION, + XML_TOK_STYLE_CURRENCY_SYMBOL, + XML_TOK_STYLE_DAY, + XML_TOK_STYLE_MONTH, + XML_TOK_STYLE_YEAR, + XML_TOK_STYLE_ERA, + XML_TOK_STYLE_DAY_OF_WEEK, + XML_TOK_STYLE_WEEK_OF_YEAR, + XML_TOK_STYLE_QUARTER, + XML_TOK_STYLE_HOURS, + XML_TOK_STYLE_AM_PM, + XML_TOK_STYLE_MINUTES, + XML_TOK_STYLE_SECONDS, + XML_TOK_STYLE_BOOLEAN, + XML_TOK_STYLE_TEXT_CONTENT, + XML_TOK_STYLE_PROPERTIES, + XML_TOK_STYLE_MAP +}; + +enum SvXMLStyleAttrTokens +{ + XML_TOK_STYLE_ATTR_NAME, + XML_TOK_STYLE_ATTR_LANGUAGE, + XML_TOK_STYLE_ATTR_COUNTRY, + XML_TOK_STYLE_ATTR_TITLE, + XML_TOK_STYLE_ATTR_AUTOMATIC_ORDER, + XML_TOK_STYLE_ATTR_FORMAT_SOURCE, + XML_TOK_STYLE_ATTR_TRUNCATE_ON_OVERFLOW, + XML_TOK_STYLE_ATTR_VOLATILE, + XML_TOK_STYLE_ATTR_TRANSL_FORMAT, + XML_TOK_STYLE_ATTR_TRANSL_LANGUAGE, + XML_TOK_STYLE_ATTR_TRANSL_COUNTRY, + XML_TOK_STYLE_ATTR_TRANSL_STYLE +}; + +enum SvXMLStyleElemAttrTokens +{ + XML_TOK_ELEM_ATTR_DECIMAL_PLACES, + XML_TOK_ELEM_ATTR_MIN_INTEGER_DIGITS, + XML_TOK_ELEM_ATTR_GROUPING, + XML_TOK_ELEM_ATTR_DISPLAY_FACTOR, + XML_TOK_ELEM_ATTR_DECIMAL_REPLACEMENT, + XML_TOK_ELEM_ATTR_MIN_EXPONENT_DIGITS, + XML_TOK_ELEM_ATTR_MIN_NUMERATOR_DIGITS, + XML_TOK_ELEM_ATTR_MIN_DENOMINATOR_DIGITS, + XML_TOK_ELEM_ATTR_LANGUAGE, + XML_TOK_ELEM_ATTR_COUNTRY, + XML_TOK_ELEM_ATTR_STYLE, + XML_TOK_ELEM_ATTR_TEXTUAL, + XML_TOK_ELEM_ATTR_CALENDAR +}; + +//------------------------------------------------------------------------- + +// +// standard colors +// + +#define XML_NUMF_COLORCOUNT 10 + +static ColorData aNumFmtStdColors[XML_NUMF_COLORCOUNT] = +{ + COL_BLACK, + COL_LIGHTBLUE, + COL_LIGHTGREEN, + COL_LIGHTCYAN, + COL_LIGHTRED, + COL_LIGHTMAGENTA, + COL_BROWN, + COL_GRAY, + COL_YELLOW, + COL_WHITE +}; + +// +// token maps +// + +// maps for SvXMLUnitConverter::convertEnum + +static SvXMLEnumMapEntry aStyleValueMap[] = +{ + { XML_SHORT, sal_False }, + { XML_LONG, sal_True }, + { XML_TOKEN_INVALID, 0 } +}; + +static SvXMLEnumMapEntry aFormatSourceMap[] = +{ + { XML_FIXED, sal_False }, + { XML_LANGUAGE, sal_True }, + { XML_TOKEN_INVALID, 0 } +}; + +//------------------------------------------------------------------------- + +struct SvXMLDefaultDateFormat +{ + NfIndexTableOffset eFormat; + SvXMLDateElementAttributes eDOW; + SvXMLDateElementAttributes eDay; + SvXMLDateElementAttributes eMonth; + SvXMLDateElementAttributes eYear; + SvXMLDateElementAttributes eHours; + SvXMLDateElementAttributes eMins; + SvXMLDateElementAttributes eSecs; + sal_Bool bSystem; +}; + +static SvXMLDefaultDateFormat aDefaultDateFormats[] = +{ + // format day-of-week day month year hours minutes seconds format-source + + { NF_DATE_SYSTEM_SHORT, XML_DEA_NONE, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_True }, + { NF_DATE_SYSTEM_LONG, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_True }, + { NF_DATE_SYS_MMYY, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_LONG, XML_DEA_SHORT, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_False }, + { NF_DATE_SYS_DDMMM, XML_DEA_NONE, XML_DEA_LONG, XML_DEA_TEXTSHORT, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_False }, + { NF_DATE_SYS_DDMMYYYY, XML_DEA_NONE, XML_DEA_LONG, XML_DEA_LONG, XML_DEA_LONG, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_False }, + { NF_DATE_SYS_DDMMYY, XML_DEA_NONE, XML_DEA_LONG, XML_DEA_LONG, XML_DEA_SHORT, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_False }, + { NF_DATE_SYS_DMMMYY, XML_DEA_NONE, XML_DEA_SHORT, XML_DEA_TEXTSHORT, XML_DEA_SHORT, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_False }, + { NF_DATE_SYS_DMMMYYYY, XML_DEA_NONE, XML_DEA_SHORT, XML_DEA_TEXTSHORT, XML_DEA_LONG, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_False }, + { NF_DATE_SYS_DMMMMYYYY, XML_DEA_NONE, XML_DEA_SHORT, XML_DEA_TEXTLONG, XML_DEA_LONG, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_False }, + { NF_DATE_SYS_NNDMMMYY, XML_DEA_SHORT, XML_DEA_SHORT, XML_DEA_TEXTSHORT, XML_DEA_SHORT, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_False }, + { NF_DATE_SYS_NNDMMMMYYYY, XML_DEA_SHORT, XML_DEA_SHORT, XML_DEA_TEXTLONG, XML_DEA_LONG, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_False }, + { NF_DATE_SYS_NNNNDMMMMYYYY, XML_DEA_LONG, XML_DEA_SHORT, XML_DEA_TEXTLONG, XML_DEA_LONG, XML_DEA_NONE, XML_DEA_NONE, XML_DEA_NONE, sal_False }, + { NF_DATETIME_SYSTEM_SHORT_HHMM, XML_DEA_NONE, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_NONE, sal_True }, + { NF_DATETIME_SYS_DDMMYYYY_HHMMSS, XML_DEA_NONE, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_ANY, XML_DEA_ANY, sal_False } +}; + +//------------------------------------------------------------------------- + +SV_IMPL_PTRARR( SvXMLNumFmtEntryArr, SvXMLNumFmtEntryPtr ); +SV_IMPL_OP_PTRARR_SORT( SvXMLEmbeddedElementArr, SvXMLEmbeddedElementPtr ); + +//------------------------------------------------------------------------- + +// +// SvXMLNumImpData +// + +SvXMLNumImpData::SvXMLNumImpData( + SvNumberFormatter* pFmt, + const uno::Reference<lang::XMultiServiceFactory>& xServiceFactory ) +: pFormatter(pFmt), + pStylesElemTokenMap(NULL), + pStyleElemTokenMap(NULL), + pStyleAttrTokenMap(NULL), + pStyleElemAttrTokenMap(NULL), + pLocaleData(NULL), + + mxServiceFactory(xServiceFactory) +{ + DBG_ASSERT( mxServiceFactory.is(), "got no service manager" ); +} + +SvXMLNumImpData::~SvXMLNumImpData() +{ + delete pStylesElemTokenMap; + delete pStyleElemTokenMap; + delete pStyleAttrTokenMap; + delete pStyleElemAttrTokenMap; + delete pLocaleData; +} + +sal_uInt32 SvXMLNumImpData::GetKeyForName( const rtl::OUString& rName ) +{ + sal_uInt16 nCount = aNameEntries.Count(); + for (sal_uInt16 i=0; i<nCount; i++) + { + const SvXMLNumFmtEntry* pObj = aNameEntries[i]; + if ( pObj->aName == rName ) + return pObj->nKey; // found + } + return NUMBERFORMAT_ENTRY_NOT_FOUND; +} + +void SvXMLNumImpData::AddKey( sal_uInt32 nKey, const rtl::OUString& rName, sal_Bool bRemoveAfterUse ) +{ + if ( bRemoveAfterUse ) + { + // if there is already an entry for this key without the bRemoveAfterUse flag, + // clear the flag for this entry, too + + sal_uInt16 nCount = aNameEntries.Count(); + for (sal_uInt16 i=0; i<nCount; i++) + { + SvXMLNumFmtEntry* pObj = aNameEntries[i]; + if ( pObj->nKey == nKey && !pObj->bRemoveAfterUse ) + { + bRemoveAfterUse = sal_False; // clear flag for new entry + break; + } + } + } + else + { + // call SetUsed to clear the bRemoveAfterUse flag for other entries for this key + SetUsed( nKey ); + } + + SvXMLNumFmtEntry* pObj = new SvXMLNumFmtEntry( rName, nKey, bRemoveAfterUse ); + aNameEntries.Insert( pObj, aNameEntries.Count() ); +} + +void SvXMLNumImpData::SetUsed( sal_uInt32 nKey ) +{ + sal_uInt16 nCount = aNameEntries.Count(); + for (sal_uInt16 i=0; i<nCount; i++) + { + SvXMLNumFmtEntry* pObj = aNameEntries[i]; + if ( pObj->nKey == nKey ) + { + pObj->bRemoveAfterUse = sal_False; // used -> don't remove + + // continue searching - there may be several entries for the same key + // (with different names), the format must not be deleted if any one of + // them is used + } + } +} + +void SvXMLNumImpData::RemoveVolatileFormats() +{ + // remove temporary (volatile) formats from NumberFormatter + // called at the end of each import (styles and content), so volatile formats + // from styles can't be used in content + + if ( !pFormatter ) + return; + + sal_uInt16 nCount = aNameEntries.Count(); + for (sal_uInt16 i=0; i<nCount; i++) + { + const SvXMLNumFmtEntry* pObj = aNameEntries[i]; + if ( pObj->bRemoveAfterUse ) + { + const SvNumberformat* pFormat = pFormatter->GetEntry(pObj->nKey); + if (pFormat && (pFormat->GetType() & NUMBERFORMAT_DEFINED)) + pFormatter->DeleteEntry( pObj->nKey ); + } + } +} + +const SvXMLTokenMap& SvXMLNumImpData::GetStylesElemTokenMap() +{ + if( !pStylesElemTokenMap ) + { + static SvXMLTokenMapEntry aStylesElemMap[] = + { + // style elements + { XML_NAMESPACE_NUMBER, XML_NUMBER_STYLE, XML_TOK_STYLES_NUMBER_STYLE }, + { XML_NAMESPACE_NUMBER, XML_CURRENCY_STYLE, XML_TOK_STYLES_CURRENCY_STYLE }, + { XML_NAMESPACE_NUMBER, XML_PERCENTAGE_STYLE, XML_TOK_STYLES_PERCENTAGE_STYLE }, + { XML_NAMESPACE_NUMBER, XML_DATE_STYLE, XML_TOK_STYLES_DATE_STYLE }, + { XML_NAMESPACE_NUMBER, XML_TIME_STYLE, XML_TOK_STYLES_TIME_STYLE }, + { XML_NAMESPACE_NUMBER, XML_BOOLEAN_STYLE, XML_TOK_STYLES_BOOLEAN_STYLE }, + { XML_NAMESPACE_NUMBER, XML_TEXT_STYLE, XML_TOK_STYLES_TEXT_STYLE }, + XML_TOKEN_MAP_END + }; + + pStylesElemTokenMap = new SvXMLTokenMap( aStylesElemMap ); + } + return *pStylesElemTokenMap; +} + +const SvXMLTokenMap& SvXMLNumImpData::GetStyleElemTokenMap() +{ + if( !pStyleElemTokenMap ) + { + static SvXMLTokenMapEntry aStyleElemMap[] = + { + // elements in a style + { XML_NAMESPACE_NUMBER, XML_TEXT, XML_TOK_STYLE_TEXT }, + { XML_NAMESPACE_NUMBER, XML_NUMBER, XML_TOK_STYLE_NUMBER }, + { XML_NAMESPACE_NUMBER, XML_SCIENTIFIC_NUMBER, XML_TOK_STYLE_SCIENTIFIC_NUMBER }, + { XML_NAMESPACE_NUMBER, XML_FRACTION, XML_TOK_STYLE_FRACTION }, + { XML_NAMESPACE_NUMBER, XML_CURRENCY_SYMBOL, XML_TOK_STYLE_CURRENCY_SYMBOL }, + { XML_NAMESPACE_NUMBER, XML_DAY, XML_TOK_STYLE_DAY }, + { XML_NAMESPACE_NUMBER, XML_MONTH, XML_TOK_STYLE_MONTH }, + { XML_NAMESPACE_NUMBER, XML_YEAR, XML_TOK_STYLE_YEAR }, + { XML_NAMESPACE_NUMBER, XML_ERA, XML_TOK_STYLE_ERA }, + { XML_NAMESPACE_NUMBER, XML_DAY_OF_WEEK, XML_TOK_STYLE_DAY_OF_WEEK }, + { XML_NAMESPACE_NUMBER, XML_WEEK_OF_YEAR, XML_TOK_STYLE_WEEK_OF_YEAR }, + { XML_NAMESPACE_NUMBER, XML_QUARTER, XML_TOK_STYLE_QUARTER }, + { XML_NAMESPACE_NUMBER, XML_HOURS, XML_TOK_STYLE_HOURS }, + { XML_NAMESPACE_NUMBER, XML_AM_PM, XML_TOK_STYLE_AM_PM }, + { XML_NAMESPACE_NUMBER, XML_MINUTES, XML_TOK_STYLE_MINUTES }, + { XML_NAMESPACE_NUMBER, XML_SECONDS, XML_TOK_STYLE_SECONDS }, + { XML_NAMESPACE_NUMBER, XML_BOOLEAN, XML_TOK_STYLE_BOOLEAN }, + { XML_NAMESPACE_NUMBER, XML_TEXT_CONTENT, XML_TOK_STYLE_TEXT_CONTENT }, + { XML_NAMESPACE_STYLE, XML_TEXT_PROPERTIES, XML_TOK_STYLE_PROPERTIES }, + { XML_NAMESPACE_STYLE, XML_MAP, XML_TOK_STYLE_MAP }, + XML_TOKEN_MAP_END + }; + + pStyleElemTokenMap = new SvXMLTokenMap( aStyleElemMap ); + } + return *pStyleElemTokenMap; +} + +const SvXMLTokenMap& SvXMLNumImpData::GetStyleAttrTokenMap() +{ + if( !pStyleAttrTokenMap ) + { + static SvXMLTokenMapEntry aStyleAttrMap[] = + { + // attributes for a style + { XML_NAMESPACE_STYLE, XML_NAME, XML_TOK_STYLE_ATTR_NAME }, + { XML_NAMESPACE_NUMBER, XML_LANGUAGE, XML_TOK_STYLE_ATTR_LANGUAGE }, + { XML_NAMESPACE_NUMBER, XML_COUNTRY, XML_TOK_STYLE_ATTR_COUNTRY }, + { XML_NAMESPACE_NUMBER, XML_TITLE, XML_TOK_STYLE_ATTR_TITLE }, + { XML_NAMESPACE_NUMBER, XML_AUTOMATIC_ORDER, XML_TOK_STYLE_ATTR_AUTOMATIC_ORDER }, + { XML_NAMESPACE_NUMBER, XML_FORMAT_SOURCE, XML_TOK_STYLE_ATTR_FORMAT_SOURCE }, + { XML_NAMESPACE_NUMBER, XML_TRUNCATE_ON_OVERFLOW, XML_TOK_STYLE_ATTR_TRUNCATE_ON_OVERFLOW }, + { XML_NAMESPACE_STYLE, XML_VOLATILE, XML_TOK_STYLE_ATTR_VOLATILE }, + { XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_FORMAT, XML_TOK_STYLE_ATTR_TRANSL_FORMAT }, + { XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_LANGUAGE, XML_TOK_STYLE_ATTR_TRANSL_LANGUAGE }, + { XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_COUNTRY, XML_TOK_STYLE_ATTR_TRANSL_COUNTRY }, + { XML_NAMESPACE_NUMBER, XML_TRANSLITERATION_STYLE, XML_TOK_STYLE_ATTR_TRANSL_STYLE }, + XML_TOKEN_MAP_END + }; + + pStyleAttrTokenMap = new SvXMLTokenMap( aStyleAttrMap ); + } + return *pStyleAttrTokenMap; +} + +const SvXMLTokenMap& SvXMLNumImpData::GetStyleElemAttrTokenMap() +{ + if( !pStyleElemAttrTokenMap ) + { + static SvXMLTokenMapEntry aStyleElemAttrMap[] = + { + // attributes for an element within a style + { XML_NAMESPACE_NUMBER, XML_DECIMAL_PLACES, XML_TOK_ELEM_ATTR_DECIMAL_PLACES }, + { XML_NAMESPACE_NUMBER, XML_MIN_INTEGER_DIGITS, XML_TOK_ELEM_ATTR_MIN_INTEGER_DIGITS }, + { XML_NAMESPACE_NUMBER, XML_GROUPING, XML_TOK_ELEM_ATTR_GROUPING }, + { XML_NAMESPACE_NUMBER, XML_DISPLAY_FACTOR, XML_TOK_ELEM_ATTR_DISPLAY_FACTOR }, + { XML_NAMESPACE_NUMBER, XML_DECIMAL_REPLACEMENT, XML_TOK_ELEM_ATTR_DECIMAL_REPLACEMENT }, + { XML_NAMESPACE_NUMBER, XML_MIN_EXPONENT_DIGITS, XML_TOK_ELEM_ATTR_MIN_EXPONENT_DIGITS }, + { XML_NAMESPACE_NUMBER, XML_MIN_NUMERATOR_DIGITS, XML_TOK_ELEM_ATTR_MIN_NUMERATOR_DIGITS }, + { XML_NAMESPACE_NUMBER, XML_MIN_DENOMINATOR_DIGITS, XML_TOK_ELEM_ATTR_MIN_DENOMINATOR_DIGITS }, + { XML_NAMESPACE_NUMBER, XML_LANGUAGE, XML_TOK_ELEM_ATTR_LANGUAGE }, + { XML_NAMESPACE_NUMBER, XML_COUNTRY, XML_TOK_ELEM_ATTR_COUNTRY }, + { XML_NAMESPACE_NUMBER, XML_STYLE, XML_TOK_ELEM_ATTR_STYLE }, + { XML_NAMESPACE_NUMBER, XML_TEXTUAL, XML_TOK_ELEM_ATTR_TEXTUAL }, + { XML_NAMESPACE_NUMBER, XML_CALENDAR, XML_TOK_ELEM_ATTR_CALENDAR }, + XML_TOKEN_MAP_END + }; + + pStyleElemAttrTokenMap = new SvXMLTokenMap( aStyleElemAttrMap ); + } + return *pStyleElemAttrTokenMap; +} + +const LocaleDataWrapper& SvXMLNumImpData::GetLocaleData( LanguageType nLang ) +{ + if ( !pLocaleData ) + pLocaleData = new LocaleDataWrapper( + (pFormatter ? pFormatter->GetServiceManager() : + mxServiceFactory), + MsLangId::convertLanguageToLocale( nLang ) ); + else + pLocaleData->setLocale( MsLangId::convertLanguageToLocale( nLang ) ); + return *pLocaleData; +} + +//------------------------------------------------------------------------- + +// +// SvXMLNumFmtMapContext +// + +SvXMLNumFmtMapContext::SvXMLNumFmtMapContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, const rtl::OUString& rLName, + SvXMLNumFormatContext& rParentContext, + const uno::Reference<xml::sax::XAttributeList>& xAttrList ) : + SvXMLImportContext( rImport, nPrfx, rLName ), + rParent( rParentContext ) +{ + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + OUString sAttrName = xAttrList->getNameByIndex( i ); + OUString sValue = xAttrList->getValueByIndex( i ); + OUString aLocalName; + sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); + if ( nPrefix == XML_NAMESPACE_STYLE ) + { + if ( IsXMLToken( aLocalName, XML_CONDITION) ) + sCondition = sValue; + else if ( IsXMLToken( aLocalName, XML_APPLY_STYLE_NAME) ) + sName = sValue; + } + } +} + +SvXMLNumFmtMapContext::~SvXMLNumFmtMapContext() +{ +} + +SvXMLImportContext* SvXMLNumFmtMapContext::CreateChildContext( + sal_uInt16 nPrfx, const rtl::OUString& rLName, + const uno::Reference<xml::sax::XAttributeList>& ) +{ + // no elements supported - use default context + return new SvXMLImportContext( GetImport(), nPrfx, rLName ); +} + +void SvXMLNumFmtMapContext::Characters( const rtl::OUString& ) +{ +} + +void SvXMLNumFmtMapContext::EndElement() +{ + rParent.AddCondition( sCondition, sName ); +} + +//------------------------------------------------------------------------- + +// +// SvXMLNumFmtPropContext +// + +SvXMLNumFmtPropContext::SvXMLNumFmtPropContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, const rtl::OUString& rLName, + SvXMLNumFormatContext& rParentContext, + const uno::Reference<xml::sax::XAttributeList>& xAttrList ) : + SvXMLImportContext( rImport, nPrfx, rLName ), + rParent( rParentContext ), + bColSet( sal_False ) +{ + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + OUString sAttrName = xAttrList->getNameByIndex( i ); + OUString sValue = xAttrList->getValueByIndex( i ); + OUString aLocalName; + sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); + if ( nPrefix == XML_NAMESPACE_FO && IsXMLToken( aLocalName, XML_COLOR ) ) + bColSet = SvXMLUnitConverter::convertColor( aColor, sValue ); + } +} + +SvXMLNumFmtPropContext::~SvXMLNumFmtPropContext() +{ +} + +SvXMLImportContext* SvXMLNumFmtPropContext::CreateChildContext( + sal_uInt16 nPrfx, const rtl::OUString& rLName, + const uno::Reference<xml::sax::XAttributeList>& ) +{ + // no elements supported - use default context + return new SvXMLImportContext( GetImport(), nPrfx, rLName ); +} + +void SvXMLNumFmtPropContext::Characters( const rtl::OUString& ) +{ +} + +void SvXMLNumFmtPropContext::EndElement() +{ + if (bColSet) + rParent.AddColor( aColor ); +} + +//------------------------------------------------------------------------- + +// +// SvXMLNumFmtEmbeddedTextContext +// + +SvXMLNumFmtEmbeddedTextContext::SvXMLNumFmtEmbeddedTextContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, const rtl::OUString& rLName, + SvXMLNumFmtElementContext& rParentContext, + const uno::Reference<xml::sax::XAttributeList>& xAttrList ) : + SvXMLImportContext( rImport, nPrfx, rLName ), + rParent( rParentContext ), + nTextPosition( 0 ) +{ + sal_Int32 nAttrVal; + + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + OUString sAttrName = xAttrList->getNameByIndex( i ); + OUString sValue = xAttrList->getValueByIndex( i ); + OUString aLocalName; + sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); + if ( nPrefix == XML_NAMESPACE_NUMBER && IsXMLToken( aLocalName, XML_POSITION ) ) + { + if ( SvXMLUnitConverter::convertNumber( nAttrVal, sValue, 0 ) ) + nTextPosition = nAttrVal; + } + } +} + +SvXMLNumFmtEmbeddedTextContext::~SvXMLNumFmtEmbeddedTextContext() +{ +} + +SvXMLImportContext* SvXMLNumFmtEmbeddedTextContext::CreateChildContext( + sal_uInt16 nPrfx, const rtl::OUString& rLName, + const uno::Reference<xml::sax::XAttributeList>& ) +{ + // no elements supported - use default context + return new SvXMLImportContext( GetImport(), nPrfx, rLName ); +} + +void SvXMLNumFmtEmbeddedTextContext::Characters( const rtl::OUString& rChars ) +{ + aContent.append( rChars ); +} + +void SvXMLNumFmtEmbeddedTextContext::EndElement() +{ + rParent.AddEmbeddedElement( nTextPosition, aContent.makeStringAndClear() ); +} + +//------------------------------------------------------------------------- + +sal_Bool lcl_ValidChar( sal_Unicode cChar, const SvXMLNumFormatContext& rParent ) +{ + sal_uInt16 nFormatType = rParent.GetType(); + + // Treat space equal to non-breaking space separator. + const sal_Unicode cNBSP = 0x00A0; + sal_Unicode cTS; + if ( ( nFormatType == XML_TOK_STYLES_NUMBER_STYLE || + nFormatType == XML_TOK_STYLES_CURRENCY_STYLE || + nFormatType == XML_TOK_STYLES_PERCENTAGE_STYLE ) && + (cChar == (cTS = rParent.GetLocaleData().getNumThousandSep().GetChar(0)) || + (cChar == ' ' && cTS == cNBSP)) ) + { + // #i22394# Extra occurrences of thousands separator must be quoted, so they + // aren't mis-interpreted as display-factor. + // This must be limited to the format types that can contain a number element, + // because the same character can be a date separator that should not be quoted + // in date formats. + + return sal_False; // force quotes + } + + // see ImpSvNumberformatScan::Next_Symbol + if ( cChar == ' ' || + cChar == '-' || + cChar == '/' || + cChar == '.' || + cChar == ',' || + cChar == ':' || + cChar == '\'' ) + return sal_True; // for all format types + + // percent sign must be used without quotes for percentage styles only + if ( nFormatType == XML_TOK_STYLES_PERCENTAGE_STYLE && cChar == '%' ) + return sal_True; + + // don't put quotes around single parentheses (often used for negative numbers) + if ( ( nFormatType == XML_TOK_STYLES_NUMBER_STYLE || + nFormatType == XML_TOK_STYLES_CURRENCY_STYLE || + nFormatType == XML_TOK_STYLES_PERCENTAGE_STYLE ) && + ( cChar == '(' || cChar == ')' ) ) + return sal_True; + + return sal_False; +} + +void lcl_EnquoteIfNecessary( rtl::OUStringBuffer& rContent, const SvXMLNumFormatContext& rParent ) +{ + sal_Bool bQuote = sal_True; + sal_Int32 nLength = rContent.getLength(); + + if ( ( nLength == 1 && + lcl_ValidChar( rContent.charAt(0), rParent ) ) || + ( nLength == 2 && + lcl_ValidChar( rContent.charAt(0), rParent ) && + rContent.charAt(1) == ' ' ) ) + { + // don't quote single separator characters like space or percent, + // or separator characters followed by space (used in date formats) + bQuote = sal_False; + } + else if ( rParent.GetType() == XML_TOK_STYLES_PERCENTAGE_STYLE && nLength > 1 ) + { + // the percent character in percentage styles must be left out of quoting + // (one occurrence is enough even if there are several percent characters in the string) + + rtl::OUString aString( rContent.getStr() ); + sal_Int32 nPos = aString.indexOf( (sal_Unicode) '%' ); + if ( nPos >= 0 ) + { + if ( nPos + 1 < nLength ) + { + if ( nPos + 2 == nLength && lcl_ValidChar( rContent.charAt(nPos + 1), rParent ) ) + { + // single character that doesn't need quoting + } + else + { + // quote text behind percent character + rContent.insert( nPos + 1, (sal_Unicode) '"' ); + rContent.append( (sal_Unicode) '"' ); + } + } + if ( nPos > 0 ) + { + if ( nPos == 1 && lcl_ValidChar( rContent.charAt(0), rParent ) ) + { + // single character that doesn't need quoting + } + else + { + // quote text before percent character + rContent.insert( nPos, (sal_Unicode) '"' ); + rContent.insert( 0, (sal_Unicode) '"' ); + } + } + bQuote = sal_False; + } + // else: normal quoting (below) + } + + if ( bQuote ) + { + // #i55469# quotes in the string itself have to be escaped + rtl::OUString aString( rContent.getStr() ); + bool bEscape = ( aString.indexOf( (sal_Unicode) '"' ) >= 0 ); + if ( bEscape ) + { + // A quote is turned into "\"" - a quote to end quoted text, an escaped quote, + // and a quote to resume quoting. + rtl::OUString aInsert( RTL_CONSTASCII_USTRINGPARAM( "\"\\\"" ) ); + + sal_Int32 nPos = 0; + while ( nPos < rContent.getLength() ) + { + if ( rContent.charAt( nPos ) == (sal_Unicode) '"' ) + { + rContent.insert( nPos, aInsert ); + nPos += aInsert.getLength(); + } + ++nPos; + } + } + + // quote string literals + rContent.insert( 0, (sal_Unicode) '"' ); + rContent.append( (sal_Unicode) '"' ); + + // remove redundant double quotes at start or end + if ( bEscape ) + { + if ( rContent.getLength() > 2 && + rContent.charAt(0) == (sal_Unicode) '"' && + rContent.charAt(1) == (sal_Unicode) '"' ) + { + String aTrimmed( rContent.makeStringAndClear().copy(2) ); + rContent = rtl::OUStringBuffer( aTrimmed ); + } + + sal_Int32 nLen = rContent.getLength(); + if ( nLen > 2 && + rContent.charAt(nLen-1) == (sal_Unicode) '"' && + rContent.charAt(nLen-2) == (sal_Unicode) '"' ) + { + String aTrimmed( rContent.makeStringAndClear().copy( 0, nLen - 2 ) ); + rContent = rtl::OUStringBuffer( aTrimmed ); + } + } + } +} + +// +// SvXMLNumFmtElementContext +// + +SvXMLNumFmtElementContext::SvXMLNumFmtElementContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, const rtl::OUString& rLName, + SvXMLNumFormatContext& rParentContext, sal_uInt16 nNewType, + const uno::Reference<xml::sax::XAttributeList>& xAttrList ) : + SvXMLImportContext( rImport, nPrfx, rLName ), + rParent( rParentContext ), + nType( nNewType ), + nElementLang( LANGUAGE_SYSTEM ), + bLong( sal_False ), + bTextual( sal_False ) +{ + OUString sLanguage, sCountry; + sal_Int32 nAttrVal; + bool bAttrBool; + sal_uInt16 nAttrEnum; + double fAttrDouble; + + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + OUString sAttrName = xAttrList->getNameByIndex( i ); + OUString sValue = xAttrList->getValueByIndex( i ); + OUString aLocalName; + sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); + + const SvXMLTokenMap& rTokenMap = rParent.GetData()->GetStyleElemAttrTokenMap(); + sal_uInt16 nToken = rTokenMap.Get( nPrefix, aLocalName ); + + switch (nToken) + { + case XML_TOK_ELEM_ATTR_DECIMAL_PLACES: + if ( SvXMLUnitConverter::convertNumber( nAttrVal, sValue, 0 ) ) + aNumInfo.nDecimals = nAttrVal; + break; + case XML_TOK_ELEM_ATTR_MIN_INTEGER_DIGITS: + if ( SvXMLUnitConverter::convertNumber( nAttrVal, sValue, 0 ) ) + aNumInfo.nInteger = nAttrVal; + break; + case XML_TOK_ELEM_ATTR_GROUPING: + if ( SvXMLUnitConverter::convertBool( bAttrBool, sValue ) ) + aNumInfo.bGrouping = bAttrBool; + break; + case XML_TOK_ELEM_ATTR_DISPLAY_FACTOR: + if ( SvXMLUnitConverter::convertDouble( fAttrDouble, sValue ) ) + aNumInfo.fDisplayFactor = fAttrDouble; + break; + case XML_TOK_ELEM_ATTR_DECIMAL_REPLACEMENT: + if ( sValue.getLength() > 0 ) + aNumInfo.bDecReplace = sal_True; // only a default string is supported + else + aNumInfo.bVarDecimals = sal_True; // empty replacement string: variable decimals + break; + case XML_TOK_ELEM_ATTR_MIN_EXPONENT_DIGITS: + if ( SvXMLUnitConverter::convertNumber( nAttrVal, sValue, 0 ) ) + aNumInfo.nExpDigits = nAttrVal; + break; + case XML_TOK_ELEM_ATTR_MIN_NUMERATOR_DIGITS: + if ( SvXMLUnitConverter::convertNumber( nAttrVal, sValue, 0 ) ) + aNumInfo.nNumerDigits = nAttrVal; + break; + case XML_TOK_ELEM_ATTR_MIN_DENOMINATOR_DIGITS: + if ( SvXMLUnitConverter::convertNumber( nAttrVal, sValue, 0 ) ) + aNumInfo.nDenomDigits = nAttrVal; + break; + case XML_TOK_ELEM_ATTR_LANGUAGE: + sLanguage = sValue; + break; + case XML_TOK_ELEM_ATTR_COUNTRY: + sCountry = sValue; + break; + case XML_TOK_ELEM_ATTR_STYLE: + if ( SvXMLUnitConverter::convertEnum( nAttrEnum, sValue, aStyleValueMap ) ) + bLong = (sal_Bool) nAttrEnum; + break; + case XML_TOK_ELEM_ATTR_TEXTUAL: + if ( SvXMLUnitConverter::convertBool( bAttrBool, sValue ) ) + bTextual = bAttrBool; + break; + case XML_TOK_ELEM_ATTR_CALENDAR: + sCalendar = sValue; + break; + } + } + + if ( sLanguage.getLength() || sCountry.getLength() ) + { + nElementLang = MsLangId::convertIsoNamesToLanguage( sLanguage, sCountry ); + if ( nElementLang == LANGUAGE_DONTKNOW ) + nElementLang = LANGUAGE_SYSTEM; //! error handling for invalid locales? + } +} + +SvXMLNumFmtElementContext::~SvXMLNumFmtElementContext() +{ +} + +SvXMLImportContext* SvXMLNumFmtElementContext::CreateChildContext( + sal_uInt16 nPrfx, const rtl::OUString& rLName, + const uno::Reference<xml::sax::XAttributeList>& xAttrList ) +{ + // only number:number supports number:embedded-text child element + + if ( nType == XML_TOK_STYLE_NUMBER && + nPrfx == XML_NAMESPACE_NUMBER && IsXMLToken( rLName, XML_EMBEDDED_TEXT ) ) + { + return new SvXMLNumFmtEmbeddedTextContext( GetImport(), nPrfx, rLName, *this, xAttrList ); + } + else + return new SvXMLImportContext( GetImport(), nPrfx, rLName ); +} + +void SvXMLNumFmtElementContext::Characters( const rtl::OUString& rChars ) +{ + aContent.append( rChars ); +} + +void SvXMLNumFmtElementContext::AddEmbeddedElement( sal_Int32 nFormatPos, const rtl::OUString& rContent ) +{ + if ( rContent.getLength() ) + { + SvXMLEmbeddedElement* pObj = new SvXMLEmbeddedElement( nFormatPos, rContent ); + if ( !aNumInfo.aEmbeddedElements.Insert( pObj ) ) + { + // there's already an element at this position - append text to existing element + + delete pObj; + sal_uInt16 nElementCount = aNumInfo.aEmbeddedElements.Count(); + for (sal_uInt16 i=0; i<nElementCount; i++) + { + pObj = aNumInfo.aEmbeddedElements[i]; + if ( pObj->nFormatPos == nFormatPos ) + { + pObj->aText += rContent; + break; + } + } + } + } +} + +void SvXMLNumFmtElementContext::EndElement() +{ + sal_Bool bEffLong = bLong; + switch (nType) + { + case XML_TOK_STYLE_TEXT: + if ( rParent.HasLongDoW() && + rParent.GetLocaleData().getLongDateDayOfWeekSep() == + String( aContent.getStr() ) ) + { + // skip separator constant after long day of week + // (NF_KEY_NNNN contains the separator) + + if ( rParent.ReplaceNfKeyword( NF_KEY_NNN, NF_KEY_NNNN ) ) + { + aContent = OUStringBuffer(); + } + + rParent.SetHasLongDoW( sal_False ); // only once + } + if ( aContent.getLength() ) + { + lcl_EnquoteIfNecessary( aContent, rParent ); + rParent.AddToCode( aContent.makeStringAndClear() ); + } + break; + + case XML_TOK_STYLE_NUMBER: + rParent.AddNumber( aNumInfo ); + break; + + case XML_TOK_STYLE_CURRENCY_SYMBOL: + rParent.AddCurrency( aContent.makeStringAndClear(), nElementLang ); + break; + + case XML_TOK_STYLE_TEXT_CONTENT: + rParent.AddToCode( OUString::valueOf((sal_Unicode)'@') ); + break; + case XML_TOK_STYLE_BOOLEAN: + // ignored - only default boolean format is supported + break; + + case XML_TOK_STYLE_DAY: + rParent.UpdateCalendar( sCalendar ); +//! I18N doesn't provide SYSTEM or extended date information yet + + rParent.AddNfKeyword( + sal::static_int_cast< sal_uInt16 >( + bEffLong ? NF_KEY_DD : NF_KEY_D ) ); + break; + case XML_TOK_STYLE_MONTH: + rParent.UpdateCalendar( sCalendar ); +//! I18N doesn't provide SYSTEM or extended date information yet + + rParent.AddNfKeyword( + sal::static_int_cast< sal_uInt16 >( + bTextual + ? ( bEffLong ? NF_KEY_MMMM : NF_KEY_MMM ) + : ( bEffLong ? NF_KEY_MM : NF_KEY_M ) ) ); + break; + case XML_TOK_STYLE_YEAR: + rParent.UpdateCalendar( sCalendar ); +//! I18N doesn't provide SYSTEM or extended date information yet + // Y after G (era) is replaced by E + if ( rParent.HasEra() ) + rParent.AddNfKeyword( + sal::static_int_cast< sal_uInt16 >( + bEffLong ? NF_KEY_EEC : NF_KEY_EC ) ); + else + rParent.AddNfKeyword( + sal::static_int_cast< sal_uInt16 >( + bEffLong ? NF_KEY_YYYY : NF_KEY_YY ) ); + break; + case XML_TOK_STYLE_ERA: + rParent.UpdateCalendar( sCalendar ); +//! I18N doesn't provide SYSTEM or extended date information yet + rParent.AddNfKeyword( + sal::static_int_cast< sal_uInt16 >( + bEffLong ? NF_KEY_GGG : NF_KEY_G ) ); + // HasEra flag is set + break; + case XML_TOK_STYLE_DAY_OF_WEEK: + rParent.UpdateCalendar( sCalendar ); +//! I18N doesn't provide SYSTEM or extended date information yet + rParent.AddNfKeyword( + sal::static_int_cast< sal_uInt16 >( + bEffLong ? NF_KEY_NNNN : NF_KEY_NN ) ); + break; + case XML_TOK_STYLE_WEEK_OF_YEAR: + rParent.UpdateCalendar( sCalendar ); + rParent.AddNfKeyword( NF_KEY_WW ); + break; + case XML_TOK_STYLE_QUARTER: + rParent.UpdateCalendar( sCalendar ); + rParent.AddNfKeyword( + sal::static_int_cast< sal_uInt16 >( + bEffLong ? NF_KEY_QQ : NF_KEY_Q ) ); + break; + case XML_TOK_STYLE_HOURS: + rParent.AddNfKeyword( + sal::static_int_cast< sal_uInt16 >( + bEffLong ? NF_KEY_HH : NF_KEY_H ) ); + break; + case XML_TOK_STYLE_AM_PM: + //! short/long? + rParent.AddNfKeyword( NF_KEY_AMPM ); + break; + case XML_TOK_STYLE_MINUTES: + rParent.AddNfKeyword( + sal::static_int_cast< sal_uInt16 >( + bEffLong ? NF_KEY_MMI : NF_KEY_MI ) ); + break; + case XML_TOK_STYLE_SECONDS: + rParent.AddNfKeyword( + sal::static_int_cast< sal_uInt16 >( + bEffLong ? NF_KEY_SS : NF_KEY_S ) ); + if ( aNumInfo.nDecimals > 0 ) + { + // manually add the decimal places + const String& rSep = rParent.GetLocaleData().getNumDecimalSep(); + for ( xub_StrLen j=0; j<rSep.Len(); j++ ) + { + rParent.AddToCode( OUString::valueOf( rSep.GetChar(j) ) ); + } + for (sal_Int32 i=0; i<aNumInfo.nDecimals; i++) + rParent.AddToCode( OUString::valueOf((sal_Unicode)'0') ); + } + break; + + case XML_TOK_STYLE_FRACTION: + { + if ( aNumInfo.nInteger >= 0 ) + { + // add integer part only if min-integer-digits attribute is there + aNumInfo.nDecimals = 0; + rParent.AddNumber( aNumInfo ); // number without decimals + rParent.AddToCode( OUString::valueOf((sal_Unicode)' ') ); + } + + //! build string and add at once + + sal_Int32 i; + for (i=0; i<aNumInfo.nNumerDigits; i++) + rParent.AddToCode( OUString::valueOf((sal_Unicode)'?') ); + rParent.AddToCode( OUString::valueOf((sal_Unicode)'/') ); + for (i=0; i<aNumInfo.nDenomDigits; i++) + rParent.AddToCode( OUString::valueOf((sal_Unicode)'?') ); + } + break; + + case XML_TOK_STYLE_SCIENTIFIC_NUMBER: + { + rParent.AddNumber( aNumInfo ); // simple number + + rParent.AddToCode( OUString(RTL_CONSTASCII_USTRINGPARAM("E+")) ); + for (sal_Int32 i=0; i<aNumInfo.nExpDigits; i++) + rParent.AddToCode( OUString::valueOf((sal_Unicode)'0') ); + } + break; + + default: + OSL_FAIL("invalid element ID"); + } +} + +//------------------------------------------------------------------------- + +sal_uInt16 SvXMLNumFmtDefaults::GetDefaultDateFormat( SvXMLDateElementAttributes eDOW, + SvXMLDateElementAttributes eDay, SvXMLDateElementAttributes eMonth, + SvXMLDateElementAttributes eYear, SvXMLDateElementAttributes eHours, + SvXMLDateElementAttributes eMins, SvXMLDateElementAttributes eSecs, + sal_Bool bSystem ) +{ + const sal_uInt16 nCount = sizeof(aDefaultDateFormats) / sizeof(SvXMLDefaultDateFormat); + for (sal_uInt16 nPos=0; nPos<nCount; nPos++) + { + const SvXMLDefaultDateFormat& rEntry = aDefaultDateFormats[nPos]; + if ( bSystem == rEntry.bSystem && + ( eDOW == rEntry.eDOW || ( rEntry.eDOW == XML_DEA_ANY && eDOW != XML_DEA_NONE ) ) && + ( eDay == rEntry.eDay || ( rEntry.eDay == XML_DEA_ANY && eDay != XML_DEA_NONE ) ) && + ( eMonth == rEntry.eMonth || ( rEntry.eMonth == XML_DEA_ANY && eMonth != XML_DEA_NONE ) ) && + ( eYear == rEntry.eYear || ( rEntry.eYear == XML_DEA_ANY && eYear != XML_DEA_NONE ) ) && + ( eHours == rEntry.eHours || ( rEntry.eHours == XML_DEA_ANY && eHours != XML_DEA_NONE ) ) && + ( eMins == rEntry.eMins || ( rEntry.eMins == XML_DEA_ANY && eMins != XML_DEA_NONE ) ) && + ( eSecs == rEntry.eSecs || ( rEntry.eSecs == XML_DEA_ANY && eSecs != XML_DEA_NONE ) ) ) + { + return sal::static_int_cast< sal_uInt16 >(rEntry.eFormat); + } + } + + return NF_INDEX_TABLE_ENTRIES; // invalid +} + +//------------------------------------------------------------------------- + +// +// SvXMLNumFormatContext +// + +SvXMLNumFormatContext::SvXMLNumFormatContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, const rtl::OUString& rLName, + SvXMLNumImpData* pNewData, sal_uInt16 nNewType, + const uno::Reference<xml::sax::XAttributeList>& xAttrList, + SvXMLStylesContext& rStyles ) : + SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList ), + pData( pNewData ), + pStyles( &rStyles ), + aMyConditions(), + nType( nNewType ), + nKey(-1), + nFormatLang( LANGUAGE_SYSTEM ), + bAutoOrder( sal_False ), + bFromSystem( sal_False ), + bTruncate( sal_True ), + bAutoDec( sal_False ), + bAutoInt( sal_False ), + bHasExtraText( sal_False ), + bHasLongDoW( sal_False ), + bHasEra( sal_False ), + bHasDateTime( sal_False ), + bRemoveAfterUse( sal_False ), + eDateDOW( XML_DEA_NONE ), + eDateDay( XML_DEA_NONE ), + eDateMonth( XML_DEA_NONE ), + eDateYear( XML_DEA_NONE ), + eDateHours( XML_DEA_NONE ), + eDateMins( XML_DEA_NONE ), + eDateSecs( XML_DEA_NONE ), + bDateNoDefault( sal_False ) +{ + OUString sLanguage, sCountry; + ::com::sun::star::i18n::NativeNumberXmlAttributes aNatNumAttr; + bool bAttrBool; + sal_uInt16 nAttrEnum; + + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + OUString sAttrName = xAttrList->getNameByIndex( i ); + OUString sValue = xAttrList->getValueByIndex( i ); + OUString aLocalName; + sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); + + const SvXMLTokenMap& rTokenMap = pData->GetStyleAttrTokenMap(); + sal_uInt16 nToken = rTokenMap.Get( nPrefix, aLocalName ); + switch (nToken) + { + case XML_TOK_STYLE_ATTR_NAME: + break; + case XML_TOK_STYLE_ATTR_LANGUAGE: + sLanguage = sValue; + break; + case XML_TOK_STYLE_ATTR_COUNTRY: + sCountry = sValue; + break; + case XML_TOK_STYLE_ATTR_TITLE: + sFormatTitle = sValue; + break; + case XML_TOK_STYLE_ATTR_AUTOMATIC_ORDER: + if ( SvXMLUnitConverter::convertBool( bAttrBool, sValue ) ) + bAutoOrder = bAttrBool; + break; + case XML_TOK_STYLE_ATTR_FORMAT_SOURCE: + if ( SvXMLUnitConverter::convertEnum( nAttrEnum, sValue, aFormatSourceMap ) ) + bFromSystem = (sal_Bool) nAttrEnum; + break; + case XML_TOK_STYLE_ATTR_TRUNCATE_ON_OVERFLOW: + if ( SvXMLUnitConverter::convertBool( bAttrBool, sValue ) ) + bTruncate = bAttrBool; + break; + case XML_TOK_STYLE_ATTR_VOLATILE: + // volatile formats can be removed after importing + // if not used in other styles + if ( SvXMLUnitConverter::convertBool( bAttrBool, sValue ) ) + bRemoveAfterUse = bAttrBool; + break; + case XML_TOK_STYLE_ATTR_TRANSL_FORMAT: + aNatNumAttr.Format = sValue; + break; + case XML_TOK_STYLE_ATTR_TRANSL_LANGUAGE: + aNatNumAttr.Locale.Language = sValue; + break; + case XML_TOK_STYLE_ATTR_TRANSL_COUNTRY: + aNatNumAttr.Locale.Country = sValue; + break; + case XML_TOK_STYLE_ATTR_TRANSL_STYLE: + aNatNumAttr.Style = sValue; + break; + } + } + + if ( sLanguage.getLength() || sCountry.getLength() ) + { + nFormatLang = MsLangId::convertIsoNamesToLanguage( sLanguage, sCountry ); + if ( nFormatLang == LANGUAGE_DONTKNOW ) + nFormatLang = LANGUAGE_SYSTEM; //! error handling for invalid locales? + } + + if ( aNatNumAttr.Format.getLength() ) + { + SvNumberFormatter* pFormatter = pData->GetNumberFormatter(); + if ( pFormatter ) + { + sal_Int32 nNatNum = pFormatter->GetNatNum()->convertFromXmlAttributes( aNatNumAttr ); + aFormatCode.appendAscii( RTL_CONSTASCII_STRINGPARAM( "[NatNum" ) ); + aFormatCode.append( nNatNum, 10 ); + + LanguageType eLang = MsLangId::convertLocaleToLanguage( aNatNumAttr.Locale ); + if ( eLang == LANGUAGE_DONTKNOW ) + eLang = LANGUAGE_SYSTEM; //! error handling for invalid locales? + if ( eLang != nFormatLang && eLang != LANGUAGE_SYSTEM ) + { + aFormatCode.appendAscii( RTL_CONSTASCII_STRINGPARAM( "][$-" ) ); + // language code in upper hex: + aFormatCode.append( String::CreateFromInt32( sal_Int32( eLang ), 16 ).ToUpperAscii() ); + } + aFormatCode.append( sal_Unicode(']') ); + } + } +} + +SvXMLNumFormatContext::SvXMLNumFormatContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, const rtl::OUString& rLName, + const uno::Reference<xml::sax::XAttributeList>& xAttrList, + const sal_Int32 nTempKey, + SvXMLStylesContext& rStyles ) : + SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList, XML_STYLE_FAMILY_DATA_STYLE ), + pData( NULL ), + pStyles( &rStyles ), + aMyConditions(), + nType( 0 ), + nKey(nTempKey), + nFormatLang( LANGUAGE_SYSTEM ), + bAutoOrder( sal_False ), + bFromSystem( sal_False ), + bTruncate( sal_True ), + bAutoDec( sal_False ), + bAutoInt( sal_False ), + bHasExtraText( sal_False ), + bHasLongDoW( sal_False ), + bHasEra( sal_False ), + bHasDateTime( sal_False ), + bRemoveAfterUse( sal_False ), + eDateDOW( XML_DEA_NONE ), + eDateDay( XML_DEA_NONE ), + eDateMonth( XML_DEA_NONE ), + eDateYear( XML_DEA_NONE ), + eDateHours( XML_DEA_NONE ), + eDateMins( XML_DEA_NONE ), + eDateSecs( XML_DEA_NONE ), + bDateNoDefault( sal_False ) +{ + SetAttribute(XML_NAMESPACE_STYLE, GetXMLToken(XML_NAME), rLName); +} + +SvXMLNumFormatContext::~SvXMLNumFormatContext() +{ +} + +SvXMLImportContext* SvXMLNumFormatContext::CreateChildContext( + sal_uInt16 nPrfx, const rtl::OUString& rLName, + const uno::Reference<xml::sax::XAttributeList>& xAttrList ) +{ + SvXMLImportContext* pContext = NULL; + + const SvXMLTokenMap& rTokenMap = pData->GetStyleElemTokenMap(); + sal_uInt16 nToken = rTokenMap.Get( nPrfx, rLName ); + switch (nToken) + { + case XML_TOK_STYLE_TEXT: + case XML_TOK_STYLE_NUMBER: + case XML_TOK_STYLE_SCIENTIFIC_NUMBER: + case XML_TOK_STYLE_FRACTION: + case XML_TOK_STYLE_CURRENCY_SYMBOL: + case XML_TOK_STYLE_DAY: + case XML_TOK_STYLE_MONTH: + case XML_TOK_STYLE_YEAR: + case XML_TOK_STYLE_ERA: + case XML_TOK_STYLE_DAY_OF_WEEK: + case XML_TOK_STYLE_WEEK_OF_YEAR: + case XML_TOK_STYLE_QUARTER: + case XML_TOK_STYLE_HOURS: + case XML_TOK_STYLE_AM_PM: + case XML_TOK_STYLE_MINUTES: + case XML_TOK_STYLE_SECONDS: + case XML_TOK_STYLE_BOOLEAN: + case XML_TOK_STYLE_TEXT_CONTENT: + pContext = new SvXMLNumFmtElementContext( GetImport(), nPrfx, rLName, + *this, nToken, xAttrList ); + break; + + case XML_TOK_STYLE_PROPERTIES: + pContext = new SvXMLNumFmtPropContext( GetImport(), nPrfx, rLName, + *this, xAttrList ); + break; + case XML_TOK_STYLE_MAP: + { + // SvXMLNumFmtMapContext::EndElement adds to aMyConditions, + // so there's no need for an extra flag + pContext = new SvXMLNumFmtMapContext( GetImport(), nPrfx, rLName, + *this, xAttrList ); + } + break; + } + + if( !pContext ) + pContext = new SvXMLImportContext( GetImport(), nPrfx, rLName ); + return pContext; +} + +sal_Int32 SvXMLNumFormatContext::GetKey() +{ + if (nKey > -1) + { + if (bRemoveAfterUse) + { + // format is used -> don't remove + bRemoveAfterUse = sal_False; + if (pData) + pData->SetUsed(nKey); + + // Add to import's list of keys now - CreateAndInsert didn't add + // the style if bRemoveAfterUse was set. + GetImport().AddNumberStyle( nKey, GetName() ); + } + return nKey; + } + else + { + // reset bRemoveAfterUse before CreateAndInsert, so AddKey is called without bRemoveAfterUse set + bRemoveAfterUse = sal_False; + CreateAndInsert(sal_True); + return nKey; + } +} + +sal_Int32 SvXMLNumFormatContext::PrivateGetKey() +{ + // used for map elements in CreateAndInsert - don't reset bRemoveAfterUse flag + + if (nKey > -1) + return nKey; + else + { + CreateAndInsert(sal_True); + return nKey; + } +} + +sal_Int32 SvXMLNumFormatContext::CreateAndInsert( com::sun::star::uno::Reference< com::sun::star::util::XNumberFormatsSupplier >& xFormatsSupplier ) +{ + if (nKey <= -1) + { + SvNumberFormatter* pFormatter = NULL; + SvNumberFormatsSupplierObj* pObj = + SvNumberFormatsSupplierObj::getImplementation( xFormatsSupplier ); + if (pObj) + pFormatter = pObj->GetNumberFormatter(); + + if ( pFormatter ) + return CreateAndInsert( pFormatter ); + else + return -1; + } + else + return nKey; +} + +void SvXMLNumFormatContext::CreateAndInsert(sal_Bool /*bOverwrite*/) +{ + if (!(nKey > -1)) + CreateAndInsert(pData->GetNumberFormatter()); +} + +sal_Int32 SvXMLNumFormatContext::CreateAndInsert(SvNumberFormatter* pFormatter) +{ + if (!pFormatter) + { + OSL_FAIL("no number formatter"); + return -1; + } + + sal_uInt32 nIndex = NUMBERFORMAT_ENTRY_NOT_FOUND; + + for (sal_uInt32 i = 0; i < aMyConditions.size(); i++) + { + SvXMLNumFormatContext* pStyle = (SvXMLNumFormatContext *)pStyles->FindStyleChildContext( + XML_STYLE_FAMILY_DATA_STYLE, aMyConditions[i].sMapName, sal_False); + if (pStyle) + { + if ((pStyle->PrivateGetKey() > -1)) // don't reset pStyle's bRemoveAfterUse flag + AddCondition(i); + } + } + + if ( !aFormatCode.getLength() ) + { + // insert empty format as empty string (with quotes) + // #93901# this check has to be done before inserting the conditions + aFormatCode.appendAscii("\"\""); // "" + } + + aFormatCode.insert( 0, aConditions.makeStringAndClear() ); + OUString sFormat = aFormatCode.makeStringAndClear(); + + // test special cases + + if ( bAutoDec ) // automatic decimal places + { + // #99391# adjust only if the format contains no text elements, no conditions + // and no color definition (detected by the '[' at the start) + + if ( nType == XML_TOK_STYLES_NUMBER_STYLE && !bHasExtraText && + aMyConditions.size() == 0 && sFormat.toChar() != (sal_Unicode)'[' ) + nIndex = pFormatter->GetStandardIndex( nFormatLang ); + } + if ( bAutoInt ) // automatic integer digits + { + //! only if two decimal places was set? + + if ( nType == XML_TOK_STYLES_NUMBER_STYLE && !bHasExtraText && + aMyConditions.size() == 0 && sFormat.toChar() != (sal_Unicode)'[' ) + nIndex = pFormatter->GetFormatIndex( NF_NUMBER_SYSTEM, nFormatLang ); + } + + // boolean is always the builtin boolean format + // (no other boolean formats are implemented) + if ( nType == XML_TOK_STYLES_BOOLEAN_STYLE ) + nIndex = pFormatter->GetFormatIndex( NF_BOOLEAN, nFormatLang ); + + // check for default date formats + if ( nType == XML_TOK_STYLES_DATE_STYLE && bAutoOrder && !bDateNoDefault ) + { + NfIndexTableOffset eFormat = (NfIndexTableOffset) SvXMLNumFmtDefaults::GetDefaultDateFormat( + eDateDOW, eDateDay, eDateMonth, eDateYear, + eDateHours, eDateMins, eDateSecs, bFromSystem ); + if ( eFormat < NF_INDEX_TABLE_ENTRIES ) + { + // #109651# if a date format has the automatic-order attribute and + // contains exactly the elements of one of the default date formats, + // use that default format, with the element order and separators + // from the current locale settings + + nIndex = pFormatter->GetFormatIndex( eFormat, nFormatLang ); + } + } + + if ( nIndex == NUMBERFORMAT_ENTRY_NOT_FOUND && sFormat.getLength() ) + { + // insert by format string + + String aFormatStr( sFormat ); + nIndex = pFormatter->GetEntryKey( aFormatStr, nFormatLang ); + if ( nIndex == NUMBERFORMAT_ENTRY_NOT_FOUND ) + { + xub_StrLen nErrPos = 0; + short l_nType = 0; + sal_Bool bOk = pFormatter->PutEntry( aFormatStr, nErrPos, l_nType, nIndex, nFormatLang ); + if ( !bOk && nErrPos == 0 && aFormatStr != String(sFormat) ) + { + // if the string was modified by PutEntry, look for an existing format + // with the modified string + nIndex = pFormatter->GetEntryKey( aFormatStr, nFormatLang ); + if ( nIndex != NUMBERFORMAT_ENTRY_NOT_FOUND ) + bOk = sal_True; + } + if (!bOk) + nIndex = NUMBERFORMAT_ENTRY_NOT_FOUND; + } + } + +//! I18N doesn't provide SYSTEM or extended date information yet + if ( nIndex != NUMBERFORMAT_ENTRY_NOT_FOUND && !bAutoOrder ) + { + // use fixed-order formats instead of SYS... if bAutoOrder is false + // (only if the format strings are equal for the locale) + + NfIndexTableOffset eOffset = pFormatter->GetIndexTableOffset( nIndex ); + if ( eOffset == NF_DATE_SYS_DMMMYYYY ) + { + sal_uInt32 nNewIndex = pFormatter->GetFormatIndex( NF_DATE_DIN_DMMMYYYY, nFormatLang ); + const SvNumberformat* pOldEntry = pFormatter->GetEntry( nIndex ); + const SvNumberformat* pNewEntry = pFormatter->GetEntry( nNewIndex ); + if ( pOldEntry && pNewEntry && pOldEntry->GetFormatstring() == pNewEntry->GetFormatstring() ) + nIndex = nNewIndex; + } + else if ( eOffset == NF_DATE_SYS_DMMMMYYYY ) + { + sal_uInt32 nNewIndex = pFormatter->GetFormatIndex( NF_DATE_DIN_DMMMMYYYY, nFormatLang ); + const SvNumberformat* pOldEntry = pFormatter->GetEntry( nIndex ); + const SvNumberformat* pNewEntry = pFormatter->GetEntry( nNewIndex ); + if ( pOldEntry && pNewEntry && pOldEntry->GetFormatstring() == pNewEntry->GetFormatstring() ) + nIndex = nNewIndex; + } + } + + if ((nIndex != NUMBERFORMAT_ENTRY_NOT_FOUND) && sFormatTitle.getLength()) + { + SvNumberformat* pFormat = const_cast<SvNumberformat*>(pFormatter->GetEntry( nIndex )); + if (pFormat) + { + String sTitle (sFormatTitle); + pFormat->SetComment(sTitle); + } + } + + if ( nIndex == NUMBERFORMAT_ENTRY_NOT_FOUND ) + { + OSL_FAIL("invalid number format"); + nIndex = pFormatter->GetStandardIndex( nFormatLang ); + } + + pData->AddKey( nIndex, GetName(), bRemoveAfterUse ); + nKey = nIndex; + + // Add to import's list of keys (shared between styles and content import) + // only if not volatile - formats are removed from NumberFormatter at the + // end of each import (in SvXMLNumFmtHelper dtor). + // If bRemoveAfterUse is reset later in GetKey, AddNumberStyle is called there. + + if (!bRemoveAfterUse) + GetImport().AddNumberStyle( nKey, GetName() ); + + return nKey; +} + +void SvXMLNumFormatContext::Finish( sal_Bool bOverwrite ) +{ + SvXMLStyleContext::Finish( bOverwrite ); +} + +const LocaleDataWrapper& SvXMLNumFormatContext::GetLocaleData() const +{ + return pData->GetLocaleData( nFormatLang ); +} + +void SvXMLNumFormatContext::AddToCode( const rtl::OUString& rString ) +{ + aFormatCode.append( rString ); + bHasExtraText = sal_True; +} + +void SvXMLNumFormatContext::AddNumber( const SvXMLNumberInfo& rInfo ) +{ + SvNumberFormatter* pFormatter = pData->GetNumberFormatter(); + if (!pFormatter) + return; + + // store special conditions + bAutoDec = ( rInfo.nDecimals < 0 ); + bAutoInt = ( rInfo.nInteger < 0 ); + + sal_uInt16 nPrec = 0; + sal_uInt16 nLeading = 0; + if ( rInfo.nDecimals >= 0 ) // < 0 : Default + nPrec = (sal_uInt16) rInfo.nDecimals; + if ( rInfo.nInteger >= 0 ) // < 0 : Default + nLeading = (sal_uInt16) rInfo.nInteger; + + if ( bAutoDec ) + { + if ( nType == XML_TOK_STYLES_CURRENCY_STYLE ) + { + // for currency formats, "automatic decimals" is used for the automatic + // currency format with (fixed) decimals from the locale settings + + const LocaleDataWrapper& rLoc = pData->GetLocaleData( nFormatLang ); + nPrec = rLoc.getCurrDigits(); + } + else + { + // for other types, "automatic decimals" means dynamic determination of + // decimals, as achieved with the "general" keyword + + aFormatCode.append( pFormatter->GetStandardName( nFormatLang ) ); + return; + } + } + if ( bAutoInt ) + { + //!... + } + + sal_uInt16 nGenPrec = nPrec; + if ( rInfo.bDecReplace || rInfo.bVarDecimals ) + nGenPrec = 0; // generate format without decimals... + + sal_Bool bGrouping = rInfo.bGrouping; + sal_uInt16 nEmbeddedCount = rInfo.aEmbeddedElements.Count(); + if ( nEmbeddedCount ) + bGrouping = sal_False; // grouping and embedded characters can't be used together + + String aNumStr; + sal_uInt32 nStdIndex = pFormatter->GetStandardIndex( nFormatLang ); + pFormatter->GenerateFormat( aNumStr, nStdIndex, nFormatLang, + bGrouping, sal_False, nGenPrec, nLeading ); + + if ( rInfo.nExpDigits >= 0 && nLeading == 0 && !bGrouping && nEmbeddedCount == 0 ) + { + // #i43959# For scientific numbers, "#" in the integer part forces a digit, + // so it has to be removed if nLeading is 0 (".00E+0", not "#.00E+0"). + + aNumStr.EraseLeadingChars( (sal_Unicode)'#' ); + } + + if ( nEmbeddedCount ) + { + // insert embedded strings into number string + // only the integer part is supported + // nZeroPos is the string position where format position 0 is inserted + + xub_StrLen nZeroPos = aNumStr.Search( pData->GetLocaleData( nFormatLang ).getNumDecimalSep() ); + if ( nZeroPos == STRING_NOTFOUND ) + nZeroPos = aNumStr.Len(); + + // aEmbeddedElements is sorted - last entry has the largest position (leftmost) + const SvXMLEmbeddedElement* pLastObj = rInfo.aEmbeddedElements[nEmbeddedCount - 1]; + sal_Int32 nLastFormatPos = pLastObj->nFormatPos; + if ( nLastFormatPos >= nZeroPos ) + { + // add '#' characters so all embedded texts are really embedded in digits + // (there always has to be a digit before the leftmost embedded text) + + xub_StrLen nAddCount = (xub_StrLen)nLastFormatPos + 1 - nZeroPos; + String aDigitStr; + aDigitStr.Fill( nAddCount, (sal_Unicode)'#' ); + aNumStr.Insert( aDigitStr, 0 ); + nZeroPos = nZeroPos + nAddCount; + } + + // aEmbeddedElements is sorted with ascending positions - loop is from right to left + for (sal_uInt16 nElement = 0; nElement < nEmbeddedCount; nElement++) + { + const SvXMLEmbeddedElement* pObj = rInfo.aEmbeddedElements[nElement]; + sal_Int32 nFormatPos = pObj->nFormatPos; + sal_Int32 nInsertPos = nZeroPos - nFormatPos; + if ( nFormatPos >= 0 && nInsertPos >= 0 ) + { + rtl::OUStringBuffer aContent( pObj->aText ); + // #107805# always quote embedded strings - even space would otherwise + // be recognized as thousands separator in French. + aContent.insert( 0, (sal_Unicode) '"' ); + aContent.append( (sal_Unicode) '"' ); + + aNumStr.Insert( String( aContent.makeStringAndClear() ), (xub_StrLen)nInsertPos ); + } + } + } + + aFormatCode.append( aNumStr ); + + if ( ( rInfo.bDecReplace || rInfo.bVarDecimals ) && nPrec ) // add decimal replacement (dashes) + { + // add dashes for explicit decimal replacement, # for variable decimals + sal_Unicode cAdd = rInfo.bDecReplace ? '-' : '#'; + + aFormatCode.append( pData->GetLocaleData( nFormatLang ).getNumDecimalSep() ); + for ( sal_uInt16 i=0; i<nPrec; i++) + aFormatCode.append( cAdd ); + } + + // add extra thousands separators for display factor + + if ( rInfo.fDisplayFactor != 1.0 && rInfo.fDisplayFactor > 0.0 ) + { + // test for 1.0 is just for optimization - nSepCount would be 0 + + // one separator for each factor of 1000 + sal_Int32 nSepCount = (sal_Int32) ::rtl::math::round( log10(rInfo.fDisplayFactor) / 3.0 ); + if ( nSepCount > 0 ) + { + OUString aSep = pData->GetLocaleData( nFormatLang ).getNumThousandSep(); + for ( sal_Int32 i=0; i<nSepCount; i++ ) + aFormatCode.append( aSep ); + } + } +} + +void SvXMLNumFormatContext::AddCurrency( const rtl::OUString& rContent, LanguageType nLang ) +{ + sal_Bool bAutomatic = sal_False; + OUString aSymbol = rContent; + if ( aSymbol.getLength() == 0 ) + { + SvNumberFormatter* pFormatter = pData->GetNumberFormatter(); + if ( pFormatter ) + { + pFormatter->ChangeIntl( nFormatLang ); + String sCurString, sDummy; + pFormatter->GetCompatibilityCurrency( sCurString, sDummy ); + aSymbol = sCurString; + + bAutomatic = sal_True; + } + } + else if ( nLang == LANGUAGE_SYSTEM && aSymbol.compareToAscii("CCC") == 0 ) + { + // "CCC" is used for automatic long symbol + bAutomatic = sal_True; + } + + if ( bAutomatic ) + { + // remove unnecessary quotes before automatic symbol (formats like "-(0DM)") + // otherwise the currency symbol isn't recognized (#94048#) + + sal_Int32 nLength = aFormatCode.getLength(); + if ( nLength > 1 && aFormatCode.charAt( nLength-1 ) == '"' ) + { + // find start of quoted string + // When SvXMLNumFmtElementContext::EndElement creates escaped quotes, + // they must be handled here, too. + + sal_Int32 nFirst = nLength - 2; + while ( nFirst >= 0 && aFormatCode.charAt( nFirst ) != '"' ) + --nFirst; + if ( nFirst >= 0 ) + { + // remove both quotes from aFormatCode + rtl::OUString aOld = aFormatCode.makeStringAndClear(); + if ( nFirst > 0 ) + aFormatCode.append( aOld.copy( 0, nFirst ) ); + if ( nLength > nFirst + 2 ) + aFormatCode.append( aOld.copy( nFirst + 1, nLength - nFirst - 2 ) ); + } + } + } + + if (!bAutomatic) + aFormatCode.appendAscii( "[$" ); // intro for "new" currency symbols + + aFormatCode.append( aSymbol ); + + if (!bAutomatic) + { + if ( nLang != LANGUAGE_SYSTEM ) + { + // '-' sign and language code in hex: + aFormatCode.append( (sal_Unicode) '-' ); + aFormatCode.append( String::CreateFromInt32( sal_Int32( nLang ), 16 ).ToUpperAscii() ); + } + + aFormatCode.append( (sal_Unicode) ']' ); // end of "new" currency symbol + } +} + +void SvXMLNumFormatContext::AddNfKeyword( sal_uInt16 nIndex ) +{ + SvNumberFormatter* pFormatter = pData->GetNumberFormatter(); + if (!pFormatter) + return; + + if ( nIndex == NF_KEY_G || nIndex == NF_KEY_GG || nIndex == NF_KEY_GGG ) + bHasEra = sal_True; + + if ( nIndex == NF_KEY_NNNN ) + { + nIndex = NF_KEY_NNN; + bHasLongDoW = sal_True; // to remove string constant with separator + } + + String sKeyword = pFormatter->GetKeyword( nFormatLang, nIndex ); + + if ( nIndex == NF_KEY_H || nIndex == NF_KEY_HH || + nIndex == NF_KEY_MI || nIndex == NF_KEY_MMI || + nIndex == NF_KEY_S || nIndex == NF_KEY_SS ) + { + if ( !bTruncate && !bHasDateTime ) + { + // with truncate-on-overflow = false, add "[]" to first time part + + sKeyword.Insert( (sal_Unicode) '[', 0 ); + sKeyword.Append( (sal_Unicode) ']' ); + } + bHasDateTime = sal_True; + } + + aFormatCode.append( sKeyword ); + + // collect the date elements that the format contains, to recognize default date formats + switch ( nIndex ) + { + case NF_KEY_NN: eDateDOW = XML_DEA_SHORT; break; + case NF_KEY_NNN: + case NF_KEY_NNNN: eDateDOW = XML_DEA_LONG; break; + case NF_KEY_D: eDateDay = XML_DEA_SHORT; break; + case NF_KEY_DD: eDateDay = XML_DEA_LONG; break; + case NF_KEY_M: eDateMonth = XML_DEA_SHORT; break; + case NF_KEY_MM: eDateMonth = XML_DEA_LONG; break; + case NF_KEY_MMM: eDateMonth = XML_DEA_TEXTSHORT; break; + case NF_KEY_MMMM: eDateMonth = XML_DEA_TEXTLONG; break; + case NF_KEY_YY: eDateYear = XML_DEA_SHORT; break; + case NF_KEY_YYYY: eDateYear = XML_DEA_LONG; break; + case NF_KEY_H: eDateHours = XML_DEA_SHORT; break; + case NF_KEY_HH: eDateHours = XML_DEA_LONG; break; + case NF_KEY_MI: eDateMins = XML_DEA_SHORT; break; + case NF_KEY_MMI: eDateMins = XML_DEA_LONG; break; + case NF_KEY_S: eDateSecs = XML_DEA_SHORT; break; + case NF_KEY_SS: eDateSecs = XML_DEA_LONG; break; + case NF_KEY_AP: + case NF_KEY_AMPM: break; // AM/PM may or may not be in date/time formats -> ignore by itself + default: + bDateNoDefault = sal_True; // any other element -> no default format + } +} + +sal_Bool lcl_IsAtEnd( rtl::OUStringBuffer& rBuffer, const String& rToken ) +{ + sal_Int32 nBufLen = rBuffer.getLength(); + xub_StrLen nTokLen = rToken.Len(); + + if ( nTokLen > nBufLen ) + return sal_False; + + sal_Int32 nStartPos = nBufLen - nTokLen; + for ( xub_StrLen nTokPos = 0; nTokPos < nTokLen; nTokPos++ ) + if ( rToken.GetChar( nTokPos ) != rBuffer.charAt( nStartPos + nTokPos ) ) + return sal_False; + + return sal_True; +} + +sal_Bool SvXMLNumFormatContext::ReplaceNfKeyword( sal_uInt16 nOld, sal_uInt16 nNew ) +{ + // replaces one keyword with another if it is found at the end of the code + + SvNumberFormatter* pFormatter = pData->GetNumberFormatter(); + if (!pFormatter) + return sal_False; + + String sOldStr = pFormatter->GetKeyword( nFormatLang, nOld ); + if ( lcl_IsAtEnd( aFormatCode, sOldStr ) ) + { + // remove old keyword + aFormatCode.setLength( aFormatCode.getLength() - sOldStr.Len() ); + + // add new keyword + String sNewStr = pFormatter->GetKeyword( nFormatLang, nNew ); + aFormatCode.append( sNewStr ); + + return sal_True; // changed + } + return sal_False; // not found +} + +void SvXMLNumFormatContext::AddCondition( const sal_Int32 nIndex ) +{ + rtl::OUString rApplyName = aMyConditions[nIndex].sMapName; + rtl::OUString rCondition = aMyConditions[nIndex].sCondition; + SvNumberFormatter* pFormatter = pData->GetNumberFormatter(); + sal_uInt32 l_nKey = pData->GetKeyForName( rApplyName ); + OUString sValue(RTL_CONSTASCII_USTRINGPARAM("value()")); //! define constant + sal_Int32 nValLen = sValue.getLength(); + + if ( pFormatter && l_nKey != NUMBERFORMAT_ENTRY_NOT_FOUND && + rCondition.copy( 0, nValLen ) == sValue ) + { + //! test for valid conditions + //! test for default conditions + + OUString sRealCond = rCondition.copy( nValLen, rCondition.getLength() - nValLen ); + sal_Bool bDefaultCond = sal_False; + + //! collect all conditions first and adjust default to >=0, >0 or <0 depending on count + //! allow blanks in conditions + sal_Bool bFirstCond = ( aConditions.getLength() == 0 ); + if ( bFirstCond && aMyConditions.size() == 1 && sRealCond.compareToAscii( ">=0" ) == 0 ) + bDefaultCond = sal_True; + + if ( nType == XML_TOK_STYLES_TEXT_STYLE && nIndex == 2 ) + { + // The third condition in a number format with a text part can only be + // "all other numbers", the condition string must be empty. + bDefaultCond = sal_True; + } + + if (!bDefaultCond) + { + sal_Int32 nPos = sRealCond.indexOf( '.' ); + if ( nPos >= 0 ) + { // #i8026# #103991# localize decimal separator + const String& rDecSep = GetLocaleData().getNumDecimalSep(); + if ( rDecSep.Len() > 1 || rDecSep.GetChar(0) != '.' ) + sRealCond = sRealCond.replaceAt( nPos, 1, rDecSep ); + } + aConditions.append( (sal_Unicode) '[' ); + aConditions.append( sRealCond ); + aConditions.append( (sal_Unicode) ']' ); + } + + const SvNumberformat* pFormat = pFormatter->GetEntry(l_nKey); + if ( pFormat ) + aConditions.append( OUString( pFormat->GetFormatstring() ) ); + + aConditions.append( (sal_Unicode) ';' ); + } +} + +void SvXMLNumFormatContext::AddCondition( const sal_Int32 nIndex, const rtl::OUString& rFormat, const LocaleDataWrapper& rData ) +{ + rtl::OUString rCondition = aMyConditions[nIndex].sCondition; + OUString sValue(RTL_CONSTASCII_USTRINGPARAM("value()")); //! define constant + sal_Int32 nValLen = sValue.getLength(); + + if ( rCondition.copy( 0, nValLen ) == sValue ) + { + //! test for valid conditions + //! test for default conditions + + OUString sRealCond = rCondition.copy( nValLen, rCondition.getLength() - nValLen ); + sal_Bool bDefaultCond = sal_False; + + //! collect all conditions first and adjust default to >=0, >0 or <0 depending on count + //! allow blanks in conditions + sal_Bool bFirstCond = ( aConditions.getLength() == 0 ); + if ( bFirstCond && aMyConditions.size() == 1 && sRealCond.compareToAscii( ">=0" ) == 0 ) + bDefaultCond = sal_True; + + if ( nType == XML_TOK_STYLES_TEXT_STYLE && nIndex == 2 ) + { + // The third condition in a number format with a text part can only be + // "all other numbers", the condition string must be empty. + bDefaultCond = sal_True; + } + + if (!bDefaultCond) + { + sal_Int32 nPos = sRealCond.indexOf( '.' ); + if ( nPos >= 0 ) + { // #i8026# #103991# localize decimal separator + const String& rDecSep = rData.getNumDecimalSep(); + if ( rDecSep.Len() > 1 || rDecSep.GetChar(0) != '.' ) + sRealCond = sRealCond.replaceAt( nPos, 1, rDecSep ); + } + aConditions.append( (sal_Unicode) '[' ); + aConditions.append( sRealCond ); + aConditions.append( (sal_Unicode) ']' ); + } + + aConditions.append( rFormat ); + + aConditions.append( (sal_Unicode) ';' ); + } +} + +void SvXMLNumFormatContext::AddCondition( const rtl::OUString& rCondition, const rtl::OUString& rApplyName ) +{ + MyCondition aCondition; + aCondition.sCondition = rCondition; + aCondition.sMapName = rApplyName; + aMyConditions.push_back(aCondition); +} + +void SvXMLNumFormatContext::AddColor( const Color& rColor ) +{ + SvNumberFormatter* pFormatter = pData->GetNumberFormatter(); + if (!pFormatter) + return; + + OUStringBuffer aColName; + for ( sal_uInt16 i=0; i<XML_NUMF_COLORCOUNT; i++ ) + if ( rColor == aNumFmtStdColors[i] ) + { + aColName = OUString( pFormatter->GetKeyword( nFormatLang, sal::static_int_cast< sal_uInt16 >(NF_KEY_FIRSTCOLOR + i) ) ); + break; + } + + if ( aColName.getLength() ) + { + aColName.insert( 0, (sal_Unicode) '[' ); + aColName.append( (sal_Unicode) ']' ); + aFormatCode.insert( 0, aColName.makeStringAndClear() ); + } +} + +void SvXMLNumFormatContext::UpdateCalendar( const rtl::OUString& rNewCalendar ) +{ + if ( rNewCalendar != sCalendar ) + { + sCalendar = rNewCalendar; + if ( sCalendar.getLength() ) + { + aFormatCode.appendAscii( "[~" ); // intro for calendar code + aFormatCode.append( sCalendar ); + aFormatCode.append( (sal_Unicode) ']' ); // end of "new" currency symbolcalendar code + } + } +} + +sal_Bool SvXMLNumFormatContext::IsSystemLanguage() +{ + return nFormatLang == LANGUAGE_SYSTEM; +} + +//------------------------------------------------------------------------- + +// +// SvXMLNumFmtHelper +// + +SvXMLNumFmtHelper::SvXMLNumFmtHelper( + const uno::Reference<util::XNumberFormatsSupplier>& rSupp, + const uno::Reference<lang::XMultiServiceFactory>& xServiceFactory ) +: mxServiceFactory(xServiceFactory) +{ + DBG_ASSERT( mxServiceFactory.is(), "got no service manager" ); + + SvNumberFormatter* pFormatter = NULL; + SvNumberFormatsSupplierObj* pObj = + SvNumberFormatsSupplierObj::getImplementation( rSupp ); + if (pObj) + pFormatter = pObj->GetNumberFormatter(); + + pData = new SvXMLNumImpData( pFormatter, mxServiceFactory ); +} + +SvXMLNumFmtHelper::SvXMLNumFmtHelper( + SvNumberFormatter* pNumberFormatter, + const uno::Reference<lang::XMultiServiceFactory>& xServiceFactory ) +: mxServiceFactory(xServiceFactory) +{ + DBG_ASSERT( mxServiceFactory.is(), "got no service manager" ); + + pData = new SvXMLNumImpData( pNumberFormatter, mxServiceFactory ); +} + +SvXMLNumFmtHelper::~SvXMLNumFmtHelper() +{ + // remove temporary (volatile) formats from NumberFormatter + pData->RemoveVolatileFormats(); + + delete pData; +} + +SvXMLStyleContext* SvXMLNumFmtHelper::CreateChildContext( SvXMLImport& rImport, + sal_uInt16 nPrefix, const OUString& rLocalName, + const uno::Reference<xml::sax::XAttributeList>& xAttrList, + SvXMLStylesContext& rStyles ) +{ + SvXMLStyleContext* pContext = NULL; + + const SvXMLTokenMap& rTokenMap = pData->GetStylesElemTokenMap(); + sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName ); + switch (nToken) + { + case XML_TOK_STYLES_NUMBER_STYLE: + case XML_TOK_STYLES_CURRENCY_STYLE: + case XML_TOK_STYLES_PERCENTAGE_STYLE: + case XML_TOK_STYLES_DATE_STYLE: + case XML_TOK_STYLES_TIME_STYLE: + case XML_TOK_STYLES_BOOLEAN_STYLE: + case XML_TOK_STYLES_TEXT_STYLE: + pContext = new SvXMLNumFormatContext( rImport, nPrefix, rLocalName, + pData, nToken, xAttrList, rStyles ); + break; + } + + // return NULL if not a data style, caller must handle other elements + return pContext; +} + +const SvXMLTokenMap& SvXMLNumFmtHelper::GetStylesElemTokenMap() +{ + return pData->GetStylesElemTokenMap(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/xmlnumi.cxx b/xmloff/source/style/xmlnumi.cxx new file mode 100644 index 000000000000..1d6d5a518249 --- /dev/null +++ b/xmloff/source/style/xmlnumi.cxx @@ -0,0 +1,1397 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/awt/Size.hpp> +#include <com/sun/star/awt/FontDescriptor.hpp> +#include <com/sun/star/text/HoriOrientation.hpp> +#include <com/sun/star/text/VertOrientation.hpp> +#include <com/sun/star/text/PositionAndSpaceMode.hpp> +#include <com/sun/star/text/LabelFollow.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/io/XOutputStream.hpp> + +#include <rtl/ustrbuf.hxx> + +#include <tools/urlobj.hxx> +#include <tools/debug.hxx> +#include <tools/fontenum.hxx> + +#include <xmloff/xmltkmap.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmlimp.hxx> +#include <xmloff/XMLBase64ImportContext.hxx> +#include <xmloff/xmltoken.hxx> + +#include <xmloff/i18nmap.hxx> +#include <xmloff/xmluconv.hxx> +#include "fonthdl.hxx" +#include <xmloff/XMLFontStylesContext.hxx> +#include <xmloff/families.hxx> +#include <xmloff/maptype.hxx> + +#include <xmloff/xmlnumi.hxx> + +#define _SVSTDARR_USHORTS +#include <svl/svstdarr.hxx> + + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::style; +using namespace ::com::sun::star::text; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::frame; +using namespace ::xmloff::token; +using namespace ::com::sun::star::io; + +using rtl::OUString; +using rtl::OUStringBuffer; + +static sal_Char const XML_UNO_NAME_NRULE_SYMBOL_TEXT_DISTANCE[] = + "SymbolTextDistance"; +static sal_Char const XML_UNO_NAME_NRULE_PARENT_NUMBERING[] = + "ParentNumbering"; +static sal_Char const XML_UNO_NAME_NRULE_CHAR_STYLE_NAME[] = + "CharStyleName"; +static sal_Char const XML_UNO_NAME_NRULE_BULLET_CHAR[] ="BulletChar"; +static sal_Char const XML_UNO_NAME_NRULE_BULLET_RELSIZE[] = "BulletRelSize"; +static sal_Char const XML_UNO_NAME_NRULE_GRAPHIC_SIZE[] = + "GraphicSize"; +static sal_Char const XML_UNO_NAME_NRULE_VERT_ORIENT[] ="VertOrient"; + +static sal_Char const XML_UNO_NAME_NRULE_NUMBERINGTYPE[] = "NumberingType"; +static sal_Char const XML_UNO_NAME_NRULE_PREFIX[] = "Prefix"; +static sal_Char const XML_UNO_NAME_NRULE_SUFFIX[] = "Suffix"; +static sal_Char const XML_UNO_NAME_NRULE_ADJUST[] = "Adjust"; +static sal_Char const XML_UNO_NAME_NRULE_LEFT_MARGIN[] = "LeftMargin"; +static sal_Char const XML_UNO_NAME_NRULE_FIRST_LINE_OFFSET[] = + "FirstLineOffset"; +static sal_Char const XML_UNO_NAME_NRULE_BULLET_FONT[] = "BulletFont"; +static sal_Char const XML_UNO_NAME_NRULE_GRAPHICURL[] = "GraphicURL"; +static sal_Char const XML_UNO_NAME_NRULE_START_WITH[] = "StartWith"; +static sal_Char const XML_UNO_NAME_NRULE_BULLET_COLOR[] = "BulletColor"; +static sal_Char const XML_UNO_NAME_NRULE_POSITION_AND_SPACE_MODE[] = "PositionAndSpaceMode"; +static sal_Char const XML_UNO_NAME_NRULE_LABEL_FOLLOWED_BY[] = "LabelFollowedBy"; +static sal_Char const XML_UNO_NAME_NRULE_LISTTAB_STOP_POSITION[] = "ListtabStopPosition"; +static sal_Char const XML_UNO_NAME_NRULE_FIRST_LINE_INDENT[] = "FirstLineIndent"; +static sal_Char const XML_UNO_NAME_NRULE_INDENT_AT[] = "IndentAt"; + +// --------------------------------------------------------------------- + +class SvxXMLListLevelStyleContext_Impl; + +class SvxXMLListLevelStyleAttrContext_Impl : public SvXMLImportContext +{ + SvxXMLListLevelStyleContext_Impl& rListLevel; + +public: + + SvxXMLListLevelStyleAttrContext_Impl( + SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList >& xAttrList, + SvxXMLListLevelStyleContext_Impl& rLLevel ); + virtual ~SvxXMLListLevelStyleAttrContext_Impl(); + + virtual SvXMLImportContext *CreateChildContext( + sal_uInt16 nPrefix, const OUString& rLocalName, + const Reference< xml::sax::XAttributeList > & xAttrList ); +}; + +// --------------------------------------------------------------------- + +class SvxXMLListLevelStyleLabelAlignmentAttrContext_Impl : public SvXMLImportContext +{ + SvxXMLListLevelStyleContext_Impl& rListLevel; + +public: + + SvxXMLListLevelStyleLabelAlignmentAttrContext_Impl( + SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList >& xAttrList, + SvxXMLListLevelStyleContext_Impl& rLLevel ); + virtual ~SvxXMLListLevelStyleLabelAlignmentAttrContext_Impl(); +}; + +// --------------------------------------------------------------------- + +enum SvxXMLTextListLevelStyleAttrTokens +{ + XML_TOK_TEXT_LEVEL_ATTR_LEVEL, + XML_TOK_TEXT_LEVEL_ATTR_STYLE_NAME, + XML_TOK_TEXT_LEVEL_ATTR_BULLET_CHAR, + XML_TOK_TEXT_LEVEL_ATTR_HREF, + XML_TOK_TEXT_LEVEL_ATTR_TYPE, + XML_TOK_TEXT_LEVEL_ATTR_SHOW, + XML_TOK_TEXT_LEVEL_ATTR_ACTUATE, + XML_TOK_TEXT_LEVEL_ATTR_NUM_FORMAT, + XML_TOK_TEXT_LEVEL_ATTR_NUM_PREFIX, + XML_TOK_TEXT_LEVEL_ATTR_NUM_SUFFIX, + XML_TOK_TEXT_LEVEL_ATTR_NUM_LETTER_SYNC, + XML_TOK_TEXT_LEVEL_ATTR_START_VALUE, + XML_TOK_TEXT_LEVEL_ATTR_DISPLAY_LEVELS, + + XML_TOK_TEXT_LEVEL_ATTR_END=XML_TOK_UNKNOWN +}; + +const SvXMLTokenMapEntry* lcl_getLevelAttrTokenMap() +{ + static SvXMLTokenMapEntry aLevelAttrTokenMap[] = + { + { XML_NAMESPACE_TEXT, XML_LEVEL, XML_TOK_TEXT_LEVEL_ATTR_LEVEL }, + { XML_NAMESPACE_TEXT, XML_STYLE_NAME, XML_TOK_TEXT_LEVEL_ATTR_STYLE_NAME }, + { XML_NAMESPACE_TEXT, XML_BULLET_CHAR, XML_TOK_TEXT_LEVEL_ATTR_BULLET_CHAR }, + { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_TEXT_LEVEL_ATTR_HREF }, + { XML_NAMESPACE_XLINK, XML_TYPE, XML_TOK_TEXT_LEVEL_ATTR_TYPE }, + { XML_NAMESPACE_XLINK, XML_SHOW, XML_TOK_TEXT_LEVEL_ATTR_SHOW }, + { XML_NAMESPACE_XLINK, XML_ACTUATE, XML_TOK_TEXT_LEVEL_ATTR_ACTUATE }, + + { XML_NAMESPACE_STYLE, XML_NUM_FORMAT, XML_TOK_TEXT_LEVEL_ATTR_NUM_FORMAT }, + { XML_NAMESPACE_STYLE, XML_NUM_PREFIX, XML_TOK_TEXT_LEVEL_ATTR_NUM_PREFIX }, + { XML_NAMESPACE_STYLE, XML_NUM_SUFFIX, XML_TOK_TEXT_LEVEL_ATTR_NUM_SUFFIX }, + { XML_NAMESPACE_STYLE, XML_NUM_LETTER_SYNC, XML_TOK_TEXT_LEVEL_ATTR_NUM_LETTER_SYNC }, + { XML_NAMESPACE_TEXT, XML_START_VALUE, XML_TOK_TEXT_LEVEL_ATTR_START_VALUE }, + { XML_NAMESPACE_TEXT, XML_DISPLAY_LEVELS, XML_TOK_TEXT_LEVEL_ATTR_DISPLAY_LEVELS }, + + XML_TOKEN_MAP_END + }; + return aLevelAttrTokenMap; +} + +class SvxXMLListLevelStyleContext_Impl : public SvXMLImportContext +{ + friend class SvxXMLListLevelStyleAttrContext_Impl; + const OUString sStarBats; + const OUString sStarMath; + + OUString sPrefix; + OUString sSuffix; + OUString sTextStyleName; + OUString sNumFormat; + OUString sNumLetterSync; + OUString sBulletFontName; + OUString sBulletFontStyleName; + OUString sImageURL; + + Reference < XOutputStream > xBase64Stream; + + sal_Int32 nLevel; + sal_Int32 nSpaceBefore; + sal_Int32 nMinLabelWidth; + sal_Int32 nMinLabelDist; + sal_Int32 nImageWidth; + sal_Int32 nImageHeight; + sal_Int16 nNumStartValue; + sal_Int16 nNumDisplayLevels; + + sal_Int16 eAdjust; + sal_Int16 eBulletFontFamily; + sal_Int16 eBulletFontPitch; + rtl_TextEncoding eBulletFontEncoding; + sal_Int16 eImageVertOrient; + + sal_Unicode cBullet; + + sal_Int16 nRelSize; + Color aColor; + + sal_Int16 ePosAndSpaceMode; + sal_Int16 eLabelFollowedBy; + sal_Int32 nListtabStopPosition; + sal_Int32 nFirstLineIndent; + sal_Int32 nIndentAt; + + sal_Bool bBullet : 1; + sal_Bool bImage : 1; + sal_Bool bNum : 1; + sal_Bool bHasColor : 1; + + void SetRelSize( sal_Int16 nRel ) { nRelSize = nRel; } + void SetColor( sal_Int32 _aColor ) { aColor = _aColor; bHasColor = sal_True; } + void SetSpaceBefore( sal_Int32 nSet ) { nSpaceBefore = nSet; } + void SetMinLabelWidth( sal_Int32 nSet ) { nMinLabelWidth = nSet; } + void SetMinLabelDist( sal_Int32 nSet ) { nMinLabelDist = nSet; } + void SetAdjust( sal_Int16 eSet ) { eAdjust = eSet; } + + void SetBulletFontName( const OUString& rSet ) { sBulletFontName = rSet; } + void SetBulletFontStyleName( const OUString& rSet ) + { sBulletFontStyleName = rSet; } + void SetBulletFontFamily( sal_Int16 eSet ) { eBulletFontFamily = eSet; } + void SetBulletFontPitch( sal_Int16 eSet ) { eBulletFontPitch = eSet; } + void SetBulletFontEncoding( rtl_TextEncoding eSet ) + { eBulletFontEncoding = eSet; } + + void SetImageWidth( sal_Int32 nSet ) { nImageWidth = nSet; } + void SetImageHeight( sal_Int32 nSet ) { nImageHeight = nSet; } + void SetImageVertOrient( sal_Int16 eSet ) + { eImageVertOrient = eSet; } + +public: + + SvxXMLListLevelStyleContext_Impl( + SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > & xAttrList ); + virtual ~SvxXMLListLevelStyleContext_Impl(); + + virtual SvXMLImportContext *CreateChildContext( + sal_uInt16 nPrefix, const OUString& rLocalName, + const Reference< xml::sax::XAttributeList > & xAttrList ); + + sal_Int32 GetLevel() const { return nLevel; } + Sequence<beans::PropertyValue> GetProperties( + const SvI18NMap *pI18NMap=0 ); + + inline void SetPosAndSpaceMode( sal_Int16 eValue ) + { + ePosAndSpaceMode = eValue; + } + inline void SetLabelFollowedBy( sal_Int16 eValue ) + { + eLabelFollowedBy = eValue; + } + inline void SetListtabStopPosition( sal_Int32 nValue ) + { + nListtabStopPosition = nValue; + } + inline void SetFirstLineIndent( sal_Int32 nValue ) + { + nFirstLineIndent = nValue; + } + inline void SetIndentAt( sal_Int32 nValue ) + { + nIndentAt = nValue; + } +}; + +SvxXMLListLevelStyleContext_Impl::SvxXMLListLevelStyleContext_Impl( + SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > & xAttrList ) + +: SvXMLImportContext( rImport, nPrfx, rLName ) +, sStarBats( RTL_CONSTASCII_USTRINGPARAM( "StarBats" ) ) +, sStarMath( RTL_CONSTASCII_USTRINGPARAM( "StarMath" ) ) +, sNumFormat( OUString(RTL_CONSTASCII_USTRINGPARAM("1")) ) +, nLevel( -1L ) +, nSpaceBefore( 0L ) +, nMinLabelWidth( 0L ) +, nMinLabelDist( 0L ) +, nImageWidth( 0L ) +, nImageHeight( 0L ) +, nNumStartValue( 1 ) +, nNumDisplayLevels( 1 ) +, eAdjust( HoriOrientation::LEFT ) +, eBulletFontFamily( FAMILY_DONTKNOW ) +, eBulletFontPitch( PITCH_DONTKNOW ) +, eBulletFontEncoding( RTL_TEXTENCODING_DONTKNOW ) +, eImageVertOrient(0) +, cBullet( 0 ) +, nRelSize(0) +, aColor( 0 ) +, ePosAndSpaceMode( PositionAndSpaceMode::LABEL_WIDTH_AND_POSITION ) +, eLabelFollowedBy( LabelFollow::LISTTAB ) +, nListtabStopPosition( 0 ) +, nFirstLineIndent( 0 ) +, nIndentAt( 0 ) +, bBullet( sal_False ) +, bImage( sal_False ) +, bNum( sal_False ) +, bHasColor( sal_False ) +{ + if( IsXMLToken( rLName, XML_LIST_LEVEL_STYLE_NUMBER ) || + IsXMLToken( rLName, XML_OUTLINE_LEVEL_STYLE ) ) + bNum = sal_True; + else if( IsXMLToken( rLName, XML_LIST_LEVEL_STYLE_BULLET ) ) + bBullet = sal_True; + else if( IsXMLToken( rLName, XML_LIST_LEVEL_STYLE_IMAGE ) ) + bImage = sal_True; + + SvXMLTokenMap aTokenMap( lcl_getLevelAttrTokenMap() ); + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + OUString aLocalName; + sal_uInt16 nPrefix = + GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, + &aLocalName ); + const OUString& rValue = xAttrList->getValueByIndex( i ); + + switch( aTokenMap.Get( nPrefix, aLocalName ) ) + { + case XML_TOK_TEXT_LEVEL_ATTR_LEVEL: + nLevel = rValue.toInt32(); + if( nLevel >= 1L ) + nLevel--; + else + nLevel = 0; + break; + case XML_TOK_TEXT_LEVEL_ATTR_STYLE_NAME: + sTextStyleName = rValue; + break; + case XML_TOK_TEXT_LEVEL_ATTR_BULLET_CHAR: + cBullet = rValue[0]; + break; + case XML_TOK_TEXT_LEVEL_ATTR_HREF: + if( bImage ) + sImageURL = rValue; + break; + case XML_TOK_TEXT_LEVEL_ATTR_TYPE: + case XML_TOK_TEXT_LEVEL_ATTR_SHOW: + case XML_TOK_TEXT_LEVEL_ATTR_ACTUATE: + // This properties will be ignored + break; + case XML_TOK_TEXT_LEVEL_ATTR_NUM_FORMAT: + if( bNum ) + sNumFormat = rValue; + break; + case XML_TOK_TEXT_LEVEL_ATTR_NUM_PREFIX: + sPrefix = rValue; + break; + case XML_TOK_TEXT_LEVEL_ATTR_NUM_SUFFIX: + sSuffix = rValue; + break; + case XML_TOK_TEXT_LEVEL_ATTR_NUM_LETTER_SYNC: + if( bNum ) + sNumLetterSync = rValue; + break; + case XML_TOK_TEXT_LEVEL_ATTR_START_VALUE: + if( bNum ) + { + sal_Int32 nTmp = rValue.toInt32(); + nNumStartValue = + (nTmp < 0L) ? 1 : ( (nTmp>SHRT_MAX) ? SHRT_MAX + : (sal_Int16)nTmp ); + } + break; + case XML_TOK_TEXT_LEVEL_ATTR_DISPLAY_LEVELS: + if( bNum ) + { + sal_Int32 nTmp = rValue.toInt32(); + nNumDisplayLevels = + (nTmp < 1L) ? 1 : ( (nTmp>SHRT_MAX) ? SHRT_MAX + : (sal_Int16)nTmp ); + } + break; + } + } +} + +SvxXMLListLevelStyleContext_Impl::~SvxXMLListLevelStyleContext_Impl() +{ +} + +SvXMLImportContext *SvxXMLListLevelStyleContext_Impl::CreateChildContext( + sal_uInt16 nPrefix, const OUString& rLocalName, + const Reference< xml::sax::XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + if( XML_NAMESPACE_STYLE == nPrefix && + ( IsXMLToken( rLocalName, XML_LIST_LEVEL_PROPERTIES ) || + IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) ) ) + { + pContext = new SvxXMLListLevelStyleAttrContext_Impl( GetImport(), + nPrefix, + rLocalName, + xAttrList, + *this ); + } + else if( (XML_NAMESPACE_OFFICE == nPrefix) && xmloff::token::IsXMLToken( rLocalName, + xmloff::token::XML_BINARY_DATA ) ) + { + if( bImage && !sImageURL.getLength() && !xBase64Stream.is() ) + { + xBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64(); + if( xBase64Stream.is() ) + pContext = new XMLBase64ImportContext( GetImport(), nPrefix, + rLocalName, xAttrList, + xBase64Stream ); + } + } + if( !pContext ) + { + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + } + + return pContext; +} + +Sequence<beans::PropertyValue> SvxXMLListLevelStyleContext_Impl::GetProperties( + const SvI18NMap *pI18NMap ) +{ + sal_Int16 eType; + + sal_Int32 nCount = 0; + if( bBullet ) + { + eType = NumberingType::CHAR_SPECIAL; + nCount = cBullet ? 15 : 14; + } + if( bImage ) + { + eType = NumberingType::BITMAP; + nCount = 15; + + if( (sImageURL.getLength() > 0L) || xBase64Stream.is() ) + nCount++; + } + if( bNum ) + { + eType = NumberingType::ARABIC; + GetImport().GetMM100UnitConverter().convertNumFormat( + eType, sNumFormat, sNumLetterSync, sal_True ); + nCount = 15; + } + + if( ( bBullet || bNum ) && nRelSize ) + nCount++; + + if( !bImage && bHasColor ) + { + nCount++; + } + + if (bBullet && sSuffix.getLength()) + { + sal_uInt16 const nVersion(GetImport().getGeneratorVersion()); + sal_Int32 nUPD; + sal_Int32 nBuildId; + if (GetImport().getBuildIds(nUPD, nBuildId) + && ( (SvXMLImport::OOo_1x == nVersion) + || (SvXMLImport::OOo_2x == nVersion) + || (310 == nUPD) || (320 == nUPD) || (330 == nUPD) + || ((300 == nUPD) && (nBuildId <= 9573)))) + { + // #i93908# OOo < 3.4 wrote a bogus suffix for bullet chars + sSuffix = ::rtl::OUString(); // clear it + } + } + + Sequence<beans::PropertyValue> aPropSeq( nCount ); + if( nCount > 0 ) + { + beans::PropertyValue *pProps = aPropSeq.getArray(); + sal_Int32 nPos = 0; + pProps[nPos].Name = + OUString(RTL_CONSTASCII_USTRINGPARAM( XML_UNO_NAME_NRULE_NUMBERINGTYPE )); + pProps[nPos++].Value <<= (sal_Int16)eType ; + + pProps[nPos].Name = OUString(RTL_CONSTASCII_USTRINGPARAM( XML_UNO_NAME_NRULE_PREFIX )); + pProps[nPos++].Value <<= sPrefix; + + pProps[nPos].Name = OUString(RTL_CONSTASCII_USTRINGPARAM( XML_UNO_NAME_NRULE_SUFFIX )); + pProps[nPos++].Value <<= sSuffix; + + pProps[nPos].Name = OUString(RTL_CONSTASCII_USTRINGPARAM( XML_UNO_NAME_NRULE_ADJUST )); + pProps[nPos++].Value <<= eAdjust; + + sal_Int32 nLeftMargin = nSpaceBefore + nMinLabelWidth; + pProps[nPos].Name = + OUString(RTL_CONSTASCII_USTRINGPARAM( XML_UNO_NAME_NRULE_LEFT_MARGIN )); + pProps[nPos++].Value <<= (sal_Int32)nLeftMargin; + + sal_Int32 nFirstLineOffset = -nMinLabelWidth; + + pProps[nPos].Name = + OUString(RTL_CONSTASCII_USTRINGPARAM( XML_UNO_NAME_NRULE_FIRST_LINE_OFFSET )); + pProps[nPos++].Value <<= (sal_Int32)nFirstLineOffset; + + pProps[nPos].Name = + OUString(RTL_CONSTASCII_USTRINGPARAM(XML_UNO_NAME_NRULE_SYMBOL_TEXT_DISTANCE)); + pProps[nPos++].Value <<= (sal_Int16)nMinLabelDist; + + pProps[nPos].Name = + OUString(RTL_CONSTASCII_USTRINGPARAM(XML_UNO_NAME_NRULE_POSITION_AND_SPACE_MODE)); + pProps[nPos++].Value <<= (sal_Int16)ePosAndSpaceMode; + pProps[nPos].Name = + OUString(RTL_CONSTASCII_USTRINGPARAM(XML_UNO_NAME_NRULE_LABEL_FOLLOWED_BY)); + pProps[nPos++].Value <<= (sal_Int16)eLabelFollowedBy; + pProps[nPos].Name = + OUString(RTL_CONSTASCII_USTRINGPARAM(XML_UNO_NAME_NRULE_LISTTAB_STOP_POSITION)); + pProps[nPos++].Value <<= (sal_Int32)nListtabStopPosition; + pProps[nPos].Name = + OUString(RTL_CONSTASCII_USTRINGPARAM(XML_UNO_NAME_NRULE_FIRST_LINE_INDENT)); + pProps[nPos++].Value <<= (sal_Int32)nFirstLineIndent; + pProps[nPos].Name = + OUString(RTL_CONSTASCII_USTRINGPARAM(XML_UNO_NAME_NRULE_INDENT_AT)); + pProps[nPos++].Value <<= (sal_Int32)nIndentAt; + + OUString sDisplayTextStyleName = GetImport().GetStyleDisplayName( + XML_STYLE_FAMILY_TEXT_TEXT, sTextStyleName ); + OUString sStyleName = sDisplayTextStyleName; + if( sStyleName.getLength() && pI18NMap ) + sStyleName = pI18NMap->Get( SFX_STYLE_FAMILY_CHAR, sStyleName ); + pProps[nPos].Name = + OUString(RTL_CONSTASCII_USTRINGPARAM( XML_UNO_NAME_NRULE_CHAR_STYLE_NAME )); + pProps[nPos++].Value <<= sDisplayTextStyleName; + + if( bBullet ) + { + awt::FontDescriptor aFDesc; + aFDesc.Name = sBulletFontName; + if( sBulletFontName.getLength() ) + { + aFDesc.StyleName = sBulletFontStyleName; + aFDesc.Family = eBulletFontFamily; + aFDesc.Pitch = eBulletFontPitch; + aFDesc.CharSet = eBulletFontEncoding; + aFDesc.Weight = WEIGHT_DONTKNOW; + sal_Bool bStarSymbol = sal_False; + if( aFDesc.Name.equalsIgnoreAsciiCase( sStarBats ) ) + { + cBullet = GetImport().ConvStarBatsCharToStarSymbol( cBullet ); + bStarSymbol = sal_True; + } + else if( aFDesc.Name.equalsIgnoreAsciiCase( sStarMath ) ) + { + cBullet = GetImport().ConvStarMathCharToStarSymbol( cBullet ); + bStarSymbol = sal_True; + } + if( bStarSymbol ) + aFDesc.Name = + OUString( RTL_CONSTASCII_USTRINGPARAM("StarSymbol" ) ); + } + + if( cBullet ) + { + OUStringBuffer sTmp(1); + sTmp.append( cBullet ); + pProps[nPos].Name = + OUString(RTL_CONSTASCII_USTRINGPARAM( XML_UNO_NAME_NRULE_BULLET_CHAR )); + pProps[nPos++].Value <<= sTmp.makeStringAndClear(); + } + + pProps[nPos].Name = + OUString(RTL_CONSTASCII_USTRINGPARAM( XML_UNO_NAME_NRULE_BULLET_FONT )); + pProps[nPos++].Value <<= aFDesc; + + } + + if( bImage ) + { + OUString sStr( sImageURL ); + if( sImageURL.getLength() ) + { + sStr = GetImport().ResolveGraphicObjectURL( sImageURL, + sal_False ); + } + else if( xBase64Stream.is() ) + { + sStr = GetImport().ResolveGraphicObjectURLFromBase64( xBase64Stream ); + } + + if( sStr.getLength() ) + { + pProps[nPos].Name = + OUString(RTL_CONSTASCII_USTRINGPARAM( XML_UNO_NAME_NRULE_GRAPHICURL )); + pProps[nPos++].Value <<= sStr; + } + + awt::Size aSize( nImageWidth, nImageHeight ); + pProps[nPos].Name = + OUString(RTL_CONSTASCII_USTRINGPARAM( XML_UNO_NAME_NRULE_GRAPHIC_SIZE )); + pProps[nPos++].Value <<= aSize; + + pProps[nPos].Name = + OUString(RTL_CONSTASCII_USTRINGPARAM( XML_UNO_NAME_NRULE_VERT_ORIENT )); + pProps[nPos++].Value <<= (sal_Int16)eImageVertOrient; + } + + if( bNum ) + { + pProps[nPos].Name = + OUString(RTL_CONSTASCII_USTRINGPARAM( XML_UNO_NAME_NRULE_START_WITH )); + pProps[nPos++].Value <<= (sal_Int16)nNumStartValue; + + pProps[nPos].Name = + OUString(RTL_CONSTASCII_USTRINGPARAM(XML_UNO_NAME_NRULE_PARENT_NUMBERING)); + pProps[nPos++].Value <<= (sal_Int16)nNumDisplayLevels; + } + + if( ( bNum || bBullet ) && nRelSize ) + { + pProps[nPos].Name = + OUString(RTL_CONSTASCII_USTRINGPARAM( XML_UNO_NAME_NRULE_BULLET_RELSIZE )); + pProps[nPos++].Value <<= nRelSize; + } + + if( !bImage && bHasColor ) + { + pProps[nPos].Name = OUString(RTL_CONSTASCII_USTRINGPARAM( XML_UNO_NAME_NRULE_BULLET_COLOR )); + pProps[nPos++].Value <<= (sal_Int32)aColor.GetColor(); + } + + DBG_ASSERT( nPos == nCount, "array under/overflow" ); + } + + return aPropSeq; +} + +// --------------------------------------------------------------------- + +enum SvxXMLStyleAttributesAttrTokens +{ + XML_TOK_STYLE_ATTRIBUTES_ATTR_SPACE_BEFORE, + XML_TOK_STYLE_ATTRIBUTES_ATTR_MIN_LABEL_WIDTH, + XML_TOK_STYLE_ATTRIBUTES_ATTR_MIN_LABEL_DIST, + XML_TOK_STYLE_ATTRIBUTES_ATTR_TEXT_ALIGN, + XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_NAME, + XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_FAMILY, + XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_FAMILY_GENERIC, + XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_STYLENAME, + XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_PITCH, + XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_CHARSET, + XML_TOK_STYLE_ATTRIBUTES_ATTR_VERTICAL_POS, + XML_TOK_STYLE_ATTRIBUTES_ATTR_VERTICAL_REL, + XML_TOK_STYLE_ATTRIBUTES_ATTR_WIDTH, + XML_TOK_STYLE_ATTRIBUTES_ATTR_HEIGHT, + XML_TOK_STYLE_ATTRIBUTES_ATTR_COLOR, + XML_TOK_STYLE_ATTRIBUTES_ATTR_WINDOW_FONT_COLOR, + XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_SIZE, + XML_TOK_STYLE_ATTRIBUTES_ATTR_POSITION_AND_SPACE_MODE, + XML_TOK_STYLE_ATTRIBUTES_ATTR_END=XML_TOK_UNKNOWN +}; +const SvXMLTokenMapEntry* lcl_getStyleAttributesAttrTokenMap() +{ + static SvXMLTokenMapEntry aStyleAttributesAttrTokenMap[] = + { + { XML_NAMESPACE_TEXT, XML_SPACE_BEFORE, + XML_TOK_STYLE_ATTRIBUTES_ATTR_SPACE_BEFORE }, + { XML_NAMESPACE_TEXT, XML_MIN_LABEL_WIDTH, + XML_TOK_STYLE_ATTRIBUTES_ATTR_MIN_LABEL_WIDTH }, + { XML_NAMESPACE_TEXT, XML_MIN_LABEL_DISTANCE, + XML_TOK_STYLE_ATTRIBUTES_ATTR_MIN_LABEL_DIST }, + { XML_NAMESPACE_FO, XML_TEXT_ALIGN, + XML_TOK_STYLE_ATTRIBUTES_ATTR_TEXT_ALIGN }, + { XML_NAMESPACE_STYLE, XML_FONT_NAME, + XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_NAME }, + { XML_NAMESPACE_FO, XML_FONT_FAMILY, + XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_FAMILY }, + { XML_NAMESPACE_STYLE, XML_FONT_FAMILY_GENERIC, + XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_FAMILY_GENERIC }, + { XML_NAMESPACE_STYLE, XML_FONT_STYLE_NAME, + XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_STYLENAME }, + { XML_NAMESPACE_STYLE, XML_FONT_PITCH, + XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_PITCH }, + { XML_NAMESPACE_STYLE, XML_FONT_CHARSET, + XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_CHARSET }, + { XML_NAMESPACE_STYLE, XML_VERTICAL_POS, + XML_TOK_STYLE_ATTRIBUTES_ATTR_VERTICAL_POS }, + { XML_NAMESPACE_STYLE, XML_VERTICAL_REL, + XML_TOK_STYLE_ATTRIBUTES_ATTR_VERTICAL_REL }, + { XML_NAMESPACE_FO, XML_WIDTH, + XML_TOK_STYLE_ATTRIBUTES_ATTR_WIDTH }, + { XML_NAMESPACE_FO, XML_HEIGHT, + XML_TOK_STYLE_ATTRIBUTES_ATTR_HEIGHT }, + { XML_NAMESPACE_FO, XML_COLOR, + XML_TOK_STYLE_ATTRIBUTES_ATTR_COLOR }, + { XML_NAMESPACE_STYLE, XML_USE_WINDOW_FONT_COLOR, + XML_TOK_STYLE_ATTRIBUTES_ATTR_WINDOW_FONT_COLOR }, + { XML_NAMESPACE_FO, XML_FONT_SIZE, + XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_SIZE }, + { XML_NAMESPACE_TEXT, XML_LIST_LEVEL_POSITION_AND_SPACE_MODE, + XML_TOK_STYLE_ATTRIBUTES_ATTR_POSITION_AND_SPACE_MODE }, + XML_TOKEN_MAP_END + }; + return aStyleAttributesAttrTokenMap; +} +SvxXMLListLevelStyleAttrContext_Impl::SvxXMLListLevelStyleAttrContext_Impl( + SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > & xAttrList, + SvxXMLListLevelStyleContext_Impl& rLLevel ) : + SvXMLImportContext( rImport, nPrfx, rLName ), + rListLevel( rLLevel ) +{ + SvXMLTokenMap aTokenMap( lcl_getStyleAttributesAttrTokenMap() ); + SvXMLUnitConverter& rUnitConv = GetImport().GetMM100UnitConverter(); + + OUString sFontName, sFontFamily, sFontStyleName, sFontFamilyGeneric, + sFontPitch, sFontCharset; + OUString sVerticalPos, sVerticalRel; + + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + OUString aLocalName; + sal_uInt16 nPrefix = + GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, + &aLocalName ); + const OUString& rValue = xAttrList->getValueByIndex( i ); + + sal_Int32 nVal; + switch( aTokenMap.Get( nPrefix, aLocalName ) ) + { + case XML_TOK_STYLE_ATTRIBUTES_ATTR_SPACE_BEFORE: + if( rUnitConv.convertMeasure( nVal, rValue, SHRT_MIN, SHRT_MAX ) ) + rListLevel.SetSpaceBefore( nVal ); + break; + case XML_TOK_STYLE_ATTRIBUTES_ATTR_MIN_LABEL_WIDTH: + if( rUnitConv.convertMeasure( nVal, rValue, 0, SHRT_MAX ) ) + rListLevel.SetMinLabelWidth( nVal ); + break; + case XML_TOK_STYLE_ATTRIBUTES_ATTR_MIN_LABEL_DIST: + if( rUnitConv.convertMeasure( nVal, rValue, 0, USHRT_MAX ) ) + rListLevel.SetMinLabelDist( nVal ); + break; + case XML_TOK_STYLE_ATTRIBUTES_ATTR_TEXT_ALIGN: + if( rValue.getLength() ) + { + sal_Int16 eAdjust = HoriOrientation::LEFT; + if( IsXMLToken( rValue, XML_CENTER ) ) + eAdjust = HoriOrientation::CENTER; + else if( IsXMLToken( rValue, XML_END ) ) + eAdjust = HoriOrientation::RIGHT; + rListLevel.SetAdjust( eAdjust ); + } + break; + case XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_NAME: + sFontName = rValue; + break; + case XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_FAMILY: + sFontFamily = rValue; + break; + case XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_FAMILY_GENERIC: + sFontFamilyGeneric = rValue; + break; + case XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_STYLENAME: + sFontStyleName = rValue; + break; + case XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_PITCH: + sFontPitch = rValue; + break; + case XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_CHARSET: + sFontCharset = rValue; + break; + case XML_TOK_STYLE_ATTRIBUTES_ATTR_VERTICAL_POS: + sVerticalPos = rValue; + break; + case XML_TOK_STYLE_ATTRIBUTES_ATTR_VERTICAL_REL: + sVerticalRel = rValue; + break; + case XML_TOK_STYLE_ATTRIBUTES_ATTR_WIDTH: + if( rUnitConv.convertMeasure( nVal, rValue, 0, SAL_MAX_INT32) ) + rListLevel.SetImageWidth( nVal ); + break; + case XML_TOK_STYLE_ATTRIBUTES_ATTR_HEIGHT: + if( rUnitConv.convertMeasure( nVal, rValue, 0, SAL_MAX_INT32) ) + rListLevel.SetImageHeight( nVal ); + break; + case XML_TOK_STYLE_ATTRIBUTES_ATTR_COLOR: + { + Color aColor; + if( SvXMLUnitConverter::convertColor( aColor, rValue ) ) + rListLevel.SetColor( (sal_Int32)aColor.GetColor() ); + } + break; + case XML_TOK_STYLE_ATTRIBUTES_ATTR_WINDOW_FONT_COLOR: + { + if( IsXMLToken( rValue, XML_TRUE ) ) + rListLevel.SetColor( (sal_Int32)0xffffffff ); + } + break; + case XML_TOK_STYLE_ATTRIBUTES_ATTR_FONT_SIZE: + if(SvXMLUnitConverter::convertPercent( nVal, rValue ) ) + rListLevel.SetRelSize( (sal_Int16)nVal ); + break; + case XML_TOK_STYLE_ATTRIBUTES_ATTR_POSITION_AND_SPACE_MODE: + { + sal_Int16 ePosAndSpaceMode = PositionAndSpaceMode::LABEL_WIDTH_AND_POSITION; + if( IsXMLToken( rValue, XML_LABEL_ALIGNMENT ) ) + ePosAndSpaceMode = PositionAndSpaceMode::LABEL_ALIGNMENT; + rListLevel.SetPosAndSpaceMode( ePosAndSpaceMode ); + } + break; + } + } + + if( sFontName.getLength() ) + { + const XMLFontStylesContext *pFontDecls = + GetImport().GetTextImport()->GetFontDecls(); + if( pFontDecls ) + { + ::std::vector < XMLPropertyState > aProps; + if( pFontDecls->FillProperties( sFontName, aProps, 0, 1, 2, 3, 4 ) ) + { + OUString sTmp; + sal_Int16 nTmp = 0; + ::std::vector< XMLPropertyState >::iterator i; + for( i = aProps.begin(); i != aProps.end(); i++ ) + { + switch( i->mnIndex ) + { + case 0: + i->maValue >>= sTmp; + rListLevel.SetBulletFontName( sTmp); + break; + case 1: + i->maValue >>= sTmp; + rListLevel.SetBulletFontStyleName( sTmp ); + break; + case 2: + i->maValue >>= nTmp; + rListLevel.SetBulletFontFamily( nTmp ); + break; + case 3: + i->maValue >>= nTmp; + rListLevel.SetBulletFontPitch( nTmp ); + break; + case 4: + i->maValue >>= nTmp; + rListLevel.SetBulletFontEncoding( nTmp ); + break; + } + } + } + } + } + if( sFontFamily.getLength() ) + { + String sEmpty; + Any aAny; + + XMLFontFamilyNamePropHdl aFamilyNameHdl; + if( aFamilyNameHdl.importXML( sFontFamily, aAny, rUnitConv ) ) + { + OUString sTmp; + aAny >>= sTmp; + rListLevel.SetBulletFontName( sTmp); + } + + XMLFontFamilyPropHdl aFamilyHdl; + if( sFontFamilyGeneric.getLength() && + aFamilyHdl.importXML( sFontFamilyGeneric, aAny, rUnitConv ) ) + { + sal_Int16 nTmp = 0; + aAny >>= nTmp; + rListLevel.SetBulletFontFamily( nTmp ); + } + + if( sFontStyleName.getLength() ) + rListLevel.SetBulletFontStyleName( sFontStyleName ); + + XMLFontPitchPropHdl aPitchHdl; + if( sFontPitch.getLength() && + aPitchHdl.importXML( sFontPitch, aAny, rUnitConv ) ) + { + sal_Int16 nTmp = 0; + aAny >>= nTmp; + rListLevel.SetBulletFontPitch( nTmp ); + } + + XMLFontEncodingPropHdl aEncHdl; + if( sFontCharset.getLength() && + aEncHdl.importXML( sFontCharset, aAny, rUnitConv ) ) + { + sal_Int16 nTmp = 0; + aAny >>= nTmp; + rListLevel.SetBulletFontEncoding( nTmp ); + } + } + + sal_Int16 eVertOrient = VertOrientation::LINE_CENTER; + if( sVerticalPos.getLength() ) + { + if( IsXMLToken( sVerticalPos, XML_TOP ) ) + eVertOrient = VertOrientation::LINE_TOP; + else if( IsXMLToken( sVerticalPos, XML_BOTTOM ) ) + eVertOrient = VertOrientation::LINE_BOTTOM; + } + if( sVerticalRel.getLength() ) + { + if( IsXMLToken( sVerticalRel, XML_BASELINE ) ) + { + // TOP and BOTTOM are exchanged for a baseline relation + switch( eVertOrient ) + { + case VertOrientation::LINE_TOP: + eVertOrient = VertOrientation::BOTTOM; + break; + case VertOrientation::LINE_CENTER: + eVertOrient = VertOrientation::CENTER; + break; + case VertOrientation::LINE_BOTTOM: + eVertOrient = VertOrientation::TOP; + break; + } + } + else if( IsXMLToken( sVerticalRel, XML_CHAR ) ) + { + switch( eVertOrient ) + { + case VertOrientation::LINE_TOP: + eVertOrient = VertOrientation::CHAR_TOP; + break; + case VertOrientation::LINE_CENTER: + eVertOrient = VertOrientation::CHAR_CENTER; + break; + case VertOrientation::LINE_BOTTOM: + eVertOrient = VertOrientation::CHAR_BOTTOM; + break; + } + } + } + rListLevel.SetImageVertOrient( eVertOrient ); +} + +SvxXMLListLevelStyleAttrContext_Impl::~SvxXMLListLevelStyleAttrContext_Impl() +{ +} + +SvXMLImportContext* SvxXMLListLevelStyleAttrContext_Impl::CreateChildContext( + sal_uInt16 nPrefix, const OUString& rLocalName, + const Reference< xml::sax::XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + if ( XML_NAMESPACE_STYLE == nPrefix && + IsXMLToken( rLocalName, XML_LIST_LEVEL_LABEL_ALIGNMENT ) ) + { + pContext = new SvxXMLListLevelStyleLabelAlignmentAttrContext_Impl( GetImport(), + nPrefix, + rLocalName, + xAttrList, + rListLevel ); + } + if( !pContext ) + { + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + } + + return pContext; +} + +// --------------------------------------------------------------------- + +enum SvxXMLStyleAttributesLabelAlignmentAttrTokens +{ + XML_TOK_STYLE_ATTRIBUTES_ATTR_LABEL_FOLLOWED_BY, + XML_TOK_STYLE_ATTRIBUTES_ATTR_LISTTAB_STOP_POSITION, + XML_TOK_STYLE_ATTRIBUTES_ATTR_FIRST_LINE_INDENT, + XML_TOK_STYLE_ATTRIBUTES_ATTR_INDENT_AT, + + XML_TOK_STYLE_ATTRIBUTES_LABEL_ALIGNMENT_ATTR_END=XML_TOK_UNKNOWN +}; +const SvXMLTokenMapEntry* lcl_getStyleAlignmentAttributesAttrTokenMap() +{ + static SvXMLTokenMapEntry aStyleAlignmentAttributesAttrTokenMap[] = + { + { XML_NAMESPACE_TEXT, XML_LABEL_FOLLOWED_BY, + XML_TOK_STYLE_ATTRIBUTES_ATTR_LABEL_FOLLOWED_BY }, + { XML_NAMESPACE_TEXT, XML_LIST_TAB_STOP_POSITION, + XML_TOK_STYLE_ATTRIBUTES_ATTR_LISTTAB_STOP_POSITION }, + { XML_NAMESPACE_FO, XML_TEXT_INDENT, + XML_TOK_STYLE_ATTRIBUTES_ATTR_FIRST_LINE_INDENT }, + { XML_NAMESPACE_FO, XML_MARGIN_LEFT, + XML_TOK_STYLE_ATTRIBUTES_ATTR_INDENT_AT }, + + XML_TOKEN_MAP_END + }; + return aStyleAlignmentAttributesAttrTokenMap; +} +SvxXMLListLevelStyleLabelAlignmentAttrContext_Impl::SvxXMLListLevelStyleLabelAlignmentAttrContext_Impl( + SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > & xAttrList, + SvxXMLListLevelStyleContext_Impl& rLLevel ) : + SvXMLImportContext( rImport, nPrfx, rLName ), + rListLevel( rLLevel ) +{ + SvXMLTokenMap aTokenMap( lcl_getStyleAlignmentAttributesAttrTokenMap() ); + SvXMLUnitConverter& rUnitConv = GetImport().GetMM100UnitConverter(); + + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + OUString aLocalName; + sal_uInt16 nPrefix = + GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, + &aLocalName ); + const OUString& rValue = xAttrList->getValueByIndex( i ); + + sal_Int32 nVal; + switch( aTokenMap.Get( nPrefix, aLocalName ) ) + { + case XML_TOK_STYLE_ATTRIBUTES_ATTR_LABEL_FOLLOWED_BY: + { + sal_Int16 eLabelFollowedBy = LabelFollow::LISTTAB; + if( IsXMLToken( rValue, XML_SPACE ) ) + eLabelFollowedBy = LabelFollow::SPACE; + else if( IsXMLToken( rValue, XML_NOTHING ) ) + eLabelFollowedBy = LabelFollow::NOTHING; + rListLevel.SetLabelFollowedBy( eLabelFollowedBy ); + } + break; + case XML_TOK_STYLE_ATTRIBUTES_ATTR_LISTTAB_STOP_POSITION: + if( rUnitConv.convertMeasure( nVal, rValue, 0, SHRT_MAX ) ) + rListLevel.SetListtabStopPosition( nVal ); + break; + case XML_TOK_STYLE_ATTRIBUTES_ATTR_FIRST_LINE_INDENT: + if( rUnitConv.convertMeasure( nVal, rValue, SHRT_MIN, SHRT_MAX ) ) + rListLevel.SetFirstLineIndent( nVal ); + break; + case XML_TOK_STYLE_ATTRIBUTES_ATTR_INDENT_AT: + if( rUnitConv.convertMeasure( nVal, rValue, SHRT_MIN, SHRT_MAX ) ) + rListLevel.SetIndentAt( nVal ); + break; + } + } +} + +SvxXMLListLevelStyleLabelAlignmentAttrContext_Impl::~SvxXMLListLevelStyleLabelAlignmentAttrContext_Impl() +{ +} + +// --------------------------------------------------------------------- + +typedef SvxXMLListLevelStyleContext_Impl *SvxXMLListLevelStyleContext_ImplPtr; +SV_DECL_PTRARR( SvxXMLListStyle_Impl, SvxXMLListLevelStyleContext_ImplPtr, + 10, 5 ) + +void SvxXMLListStyleContext::SetAttribute( sal_uInt16 nPrefixKey, + const OUString& rLocalName, + const OUString& rValue ) +{ + if( XML_NAMESPACE_TEXT == nPrefixKey && + IsXMLToken( rLocalName, XML_CONSECUTIVE_NUMBERING ) ) + { + bConsecutive = IsXMLToken( rValue, XML_TRUE ); + } + else + { + SvXMLStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue ); + } +} + + +SvxXMLListStyleContext::SvxXMLListStyleContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLName, + const Reference< xml::sax::XAttributeList > & xAttrList, + sal_Bool bOutl ) +: SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList, bOutl ? XML_STYLE_FAMILY_TEXT_OUTLINE : XML_STYLE_FAMILY_TEXT_LIST ) +, sIsPhysical( RTL_CONSTASCII_USTRINGPARAM( "IsPhysical" ) ) +, sNumberingRules( RTL_CONSTASCII_USTRINGPARAM( "NumberingRules" ) ) +, sName( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ) +, sIsContinuousNumbering( RTL_CONSTASCII_USTRINGPARAM( "IsContinuousNumbering" ) ) +, pLevelStyles( 0 ) +, nLevels( 0 ) +, bConsecutive( sal_False ) +, bOutline( bOutl ) +{ +} + +SvxXMLListStyleContext::~SvxXMLListStyleContext() +{ + if( pLevelStyles ) + { + while( pLevelStyles->Count() ) + { + sal_uInt16 n = pLevelStyles->Count() - 1; + SvxXMLListLevelStyleContext_Impl *pStyle = (*pLevelStyles)[n]; + pLevelStyles->Remove( n, 1 ); + pStyle->ReleaseRef(); + } + } + + delete pLevelStyles; +} + +TYPEINIT1( SvxXMLListStyleContext, SvXMLStyleContext ); + +SvXMLImportContext *SvxXMLListStyleContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference< xml::sax::XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + + if( XML_NAMESPACE_TEXT == nPrefix && + ( bOutline + ? IsXMLToken( rLocalName, XML_OUTLINE_LEVEL_STYLE ) + : ( IsXMLToken( rLocalName, XML_LIST_LEVEL_STYLE_NUMBER ) || + IsXMLToken( rLocalName, XML_LIST_LEVEL_STYLE_BULLET ) || + IsXMLToken( rLocalName, XML_LIST_LEVEL_STYLE_IMAGE ) ) ) ) + { + SvxXMLListLevelStyleContext_Impl *pLevelStyle = + new SvxXMLListLevelStyleContext_Impl( GetImport(), nPrefix, + rLocalName, xAttrList ); + if( !pLevelStyles ) + pLevelStyles = new SvxXMLListStyle_Impl; + pLevelStyles->Insert( pLevelStyle, pLevelStyles->Count() ); + pLevelStyle->AddRef(); + + pContext = pLevelStyle; + } + else + { + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + } + + return pContext; +} + +void SvxXMLListStyleContext::FillUnoNumRule( + const Reference< container::XIndexReplace > & rNumRule, + const SvI18NMap *pI18NMap ) const +{ + try + { + if( pLevelStyles && rNumRule.is() ) + { + sal_uInt16 nCount = pLevelStyles->Count(); + sal_Int32 l_nLevels = rNumRule->getCount(); + for( sal_uInt16 i=0; i < nCount; i++ ) + { + SvxXMLListLevelStyleContext_Impl *pLevelStyle = + (*pLevelStyles)[i]; + sal_Int32 nLevel = pLevelStyle->GetLevel(); + if( nLevel >= 0 && nLevel < l_nLevels ) + { + Sequence<beans::PropertyValue> aProps = + pLevelStyle->GetProperties( pI18NMap ); + Any aAny; + aAny <<= aProps; + rNumRule->replaceByIndex( nLevel, aAny ); + } + } + } + + Reference < XPropertySet > xPropSet( rNumRule, UNO_QUERY ); + Reference< XPropertySetInfo > xPropSetInfo; + if (xPropSet.is()) + xPropSetInfo = xPropSet->getPropertySetInfo(); + if( xPropSetInfo.is() && + xPropSetInfo->hasPropertyByName( sIsContinuousNumbering ) ) + { + Any aAny; + sal_Bool bTmp = bConsecutive; + aAny.setValue( &bTmp, ::getBooleanCppuType() ); + xPropSet->setPropertyValue( sIsContinuousNumbering, aAny ); + } + } + catch( Exception& ) + { + OSL_FAIL( "SvxXMLListStyleContext::FillUnoNumRule - Exception catched" ); + } +} + +void SvxXMLListStyleContext::CreateAndInsertLate( sal_Bool bOverwrite ) +{ + if( bOutline ) + { + if( bOverwrite ) + { + const Reference< XIndexReplace >& rNumRule = + GetImport().GetTextImport()->GetChapterNumbering(); + // We don't set xNumberingRules here, to avoid using them + // as numbering rules. + if( rNumRule.is() ) + FillUnoNumRule( rNumRule, 0 ); + } + } + else + { + Reference < XStyle > xStyle; + const OUString& rName = GetDisplayName(); + if( 0 == rName.getLength() ) + { + SetValid( sal_False ); + return; + } + + const Reference < XNameContainer >& rNumStyles = + GetImport().GetTextImport()->GetNumberingStyles(); + if( !rNumStyles.is() ) + { + SetValid( sal_False ); + return; + } + + sal_Bool bNew = sal_False; + if( rNumStyles->hasByName( rName ) ) + { + Any aAny = rNumStyles->getByName( rName ); + aAny >>= xStyle; + } + else + { + Reference< XMultiServiceFactory > xFactory( GetImport().GetModel(), + UNO_QUERY ); + DBG_ASSERT( xFactory.is(), "no factory" ); + if( !xFactory.is() ) + return; + + Reference < XInterface > xIfc = xFactory->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.NumberingStyle")) ); + if( !xIfc.is() ) + return; + Reference < XStyle > xTmp( xIfc, UNO_QUERY ); + xStyle = xTmp; + if( !xStyle.is() ) + return; + + Any aAny; + aAny <<= xStyle; + rNumStyles->insertByName( rName, aAny ); + bNew = sal_True; + } + + Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY ); + Reference< XPropertySetInfo > xPropSetInfo = + xPropSet->getPropertySetInfo(); + if( !bNew && xPropSetInfo->hasPropertyByName( sIsPhysical ) ) + { + Any aAny = xPropSet->getPropertyValue( sIsPhysical ); + bNew = !*(sal_Bool *)aAny.getValue(); + } + if( rName != GetName() ) + GetImport().AddStyleDisplayName( XML_STYLE_FAMILY_TEXT_LIST, + GetName(), rName ); + + Any aAny = xPropSet->getPropertyValue( sNumberingRules ); + aAny >>= xNumRules; + nLevels = xNumRules->getCount(); + if( bOverwrite || bNew ) + { + FillUnoNumRule( xNumRules, 0 ); + aAny <<= xNumRules; + xPropSet->setPropertyValue( sNumberingRules, aAny ); + } + else + { + SetValid( sal_False ); + } + + SetNew( bNew ); + } +} + +void SvxXMLListStyleContext::CreateAndInsertAuto() const +{ + DBG_ASSERT( !bOutline, "Outlines cannot be inserted here" ); + DBG_ASSERT( !xNumRules.is(), "Numbering Rule is existing already" ); + + const OUString& rName = GetName(); + if( bOutline || xNumRules.is() || 0 == rName.getLength() ) + { + ((SvxXMLListStyleContext *)this)->SetValid( sal_False ); + return; + } + + ((SvxXMLListStyleContext *)this)->xNumRules = CreateNumRule( + GetImport().GetModel() ); + ((SvxXMLListStyleContext *)this)->nLevels = xNumRules->getCount(); + + FillUnoNumRule( xNumRules, 0 ); +} + +Reference < XIndexReplace > SvxXMLListStyleContext::CreateNumRule( + const Reference < XModel > & rModel ) +{ + Reference<XIndexReplace> xNumRule; + + Reference< XMultiServiceFactory > xFactory( rModel, UNO_QUERY ); + DBG_ASSERT( xFactory.is(), "no factory" ); + if( !xFactory.is() ) + return xNumRule; + + Reference < XInterface > xIfc = xFactory->createInstance(OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.NumberingRules")) ); + if( !xIfc.is() ) + return xNumRule; + + xNumRule = Reference<XIndexReplace>( xIfc, UNO_QUERY ); + DBG_ASSERT( xNumRule.is(), "go no numbering rule" ); + + return xNumRule; +} + +void SvxXMLListStyleContext::SetDefaultStyle( + const Reference < XIndexReplace > & rNumRule, + sal_Int16 nLevel, + sal_Bool bOrdered ) +{ + Sequence<beans::PropertyValue> aPropSeq( bOrdered ? 1 : 4 ); + beans::PropertyValue *pProps = aPropSeq.getArray(); + + pProps->Name = + OUString(RTL_CONSTASCII_USTRINGPARAM( XML_UNO_NAME_NRULE_NUMBERINGTYPE )); + (pProps++)->Value <<= (sal_Int16)(bOrdered ? NumberingType::ARABIC + : NumberingType::CHAR_SPECIAL ); + if( !bOrdered ) + { + // TODO: Bullet-Font + awt::FontDescriptor aFDesc; + aFDesc.Name = OUString( +#if defined UNX + RTL_CONSTASCII_USTRINGPARAM( "starbats" ) +#else + RTL_CONSTASCII_USTRINGPARAM( "StarBats" ) +#endif + ); + aFDesc.Family = FAMILY_DONTKNOW ; + aFDesc.Pitch = PITCH_DONTKNOW ; + aFDesc.CharSet = RTL_TEXTENCODING_SYMBOL ; + aFDesc.Weight = WEIGHT_DONTKNOW; + pProps->Name = + OUString(RTL_CONSTASCII_USTRINGPARAM( XML_UNO_NAME_NRULE_BULLET_FONT )); + (pProps++)->Value <<= aFDesc; + + OUStringBuffer sTmp(1); + sTmp.append( (sal_Unicode)(0xF000 + 149) ); + pProps->Name = + OUString(RTL_CONSTASCII_USTRINGPARAM( XML_UNO_NAME_NRULE_BULLET_CHAR )); + (pProps++)->Value <<= sTmp.makeStringAndClear(); + pProps->Name = + OUString(RTL_CONSTASCII_USTRINGPARAM( XML_UNO_NAME_NRULE_CHAR_STYLE_NAME )); + (pProps++)->Value <<= + OUString( RTL_CONSTASCII_USTRINGPARAM( "Numbering Symbols" ) ); + } + + Any aAny; + aAny <<= aPropSeq; + rNumRule->replaceByIndex( nLevel, aAny ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/xmlprcon.cxx b/xmloff/source/style/xmlprcon.cxx new file mode 100644 index 000000000000..84c0cee372e3 --- /dev/null +++ b/xmloff/source/style/xmlprcon.cxx @@ -0,0 +1,106 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <xmloff/xmlimp.hxx> + + +#include <xmloff/xmlprcon.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::std; + +SvXMLPropertySetContext::SvXMLPropertySetContext( + SvXMLImport& rImp, sal_uInt16 nPrfx, + const OUString& rLName, + const uno::Reference< xml::sax::XAttributeList >& xAttrList, + sal_uInt32 nFam, + vector< XMLPropertyState > &rProps, + const UniReference < SvXMLImportPropertyMapper > &rMap, + sal_Int32 nSIdx, sal_Int32 nEIdx ) +: SvXMLImportContext( rImp, nPrfx, rLName ) +, mnStartIdx( nSIdx ) +, mnEndIdx( nEIdx ) +, mnFamily( nFam ) +, mrProperties( rProps ) +, mxMapper( rMap ) +{ + mxMapper->importXML( mrProperties, xAttrList, + GetImport().GetMM100UnitConverter(), + GetImport().GetNamespaceMap(), mnFamily, + mnStartIdx, mnEndIdx ); +} + +SvXMLPropertySetContext::~SvXMLPropertySetContext() +{ +} + +SvXMLImportContext *SvXMLPropertySetContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const uno::Reference< xml::sax::XAttributeList >& xAttrList ) +{ + UniReference< XMLPropertySetMapper > aSetMapper( + mxMapper->getPropertySetMapper() ); + sal_Int32 nEntryIndex = aSetMapper->GetEntryIndex( nPrefix, rLocalName, + mnFamily, mnStartIdx ); + + if( ( nEntryIndex != -1 ) && (-1 == mnEndIdx || nEntryIndex < mnEndIdx ) && + ( 0 != ( aSetMapper->GetEntryFlags( nEntryIndex ) + & MID_FLAG_ELEMENT_ITEM_IMPORT ) ) ) + { + XMLPropertyState aProp( nEntryIndex ); + return CreateChildContext( nPrefix, rLocalName, xAttrList, + mrProperties, aProp ); + } + else + { + return new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + } +} + +/** This method is called from this instance implementation of + CreateChildContext if the element matches an entry in the + SvXMLImportItemMapper with the mid flag MID_FLAG_ELEMENT +*/ +SvXMLImportContext *SvXMLPropertySetContext::CreateChildContext( + sal_uInt16 nPrefix, + const rtl::OUString& rLocalName, + const uno::Reference< xml::sax::XAttributeList >&, + ::std::vector< XMLPropertyState > &, + const XMLPropertyState& ) +{ + return new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/xmlprhdl.cxx b/xmloff/source/style/xmlprhdl.cxx new file mode 100644 index 000000000000..b43377c8f70d --- /dev/null +++ b/xmloff/source/style/xmlprhdl.cxx @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <xmloff/xmlprhdl.hxx> +#include <com/sun/star/uno/Any.hxx> + +XMLPropertyHandler::~XMLPropertyHandler() +{ + // does nothing +} + +bool XMLPropertyHandler::equals( const ::com::sun::star::uno::Any& r1, const ::com::sun::star::uno::Any& r2 ) const +{ + return (r1 == r2); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/xmlprmap.cxx b/xmloff/source/style/xmlprmap.cxx new file mode 100644 index 000000000000..766f25bfa426 --- /dev/null +++ b/xmloff/source/style/xmlprmap.cxx @@ -0,0 +1,255 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <tools/debug.hxx> +#include <xmloff/xmlprhdl.hxx> +#include "xmlbahdl.hxx" +#include <xmloff/xmlprmap.hxx> +#include <xmloff/xmltypes.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XPropertyState.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <xmloff/xmltoken.hxx> + + +using namespace ::std; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using ::xmloff::token::GetXMLToken; + +XMLPropertySetMapperEntry_Impl::XMLPropertySetMapperEntry_Impl( + const XMLPropertyMapEntry& rMapEntry, + const UniReference< XMLPropertyHandlerFactory >& rFactory ) : + sXMLAttributeName( GetXMLToken(rMapEntry.meXMLName) ), + sAPIPropertyName( OUString(rMapEntry.msApiName, rMapEntry.nApiNameLength, + RTL_TEXTENCODING_ASCII_US ) ), + nXMLNameSpace( rMapEntry.mnNameSpace ), + nType( rMapEntry.mnType ), + nContextId( rMapEntry.mnContextId ), + nEarliestODFVersionForExport( rMapEntry.mnEarliestODFVersionForExport ), + pHdl( rFactory->GetPropertyHandler( rMapEntry.mnType & MID_FLAG_MASK ) ) +{ +} + +XMLPropertySetMapperEntry_Impl::XMLPropertySetMapperEntry_Impl( + const XMLPropertySetMapperEntry_Impl& rEntry ) : + sXMLAttributeName( rEntry.sXMLAttributeName), + sAPIPropertyName( rEntry.sAPIPropertyName), + nXMLNameSpace( rEntry.nXMLNameSpace), + nType( rEntry.nType), + nContextId( rEntry.nContextId), + nEarliestODFVersionForExport( rEntry.nEarliestODFVersionForExport ), + pHdl( rEntry.pHdl) +{ + DBG_ASSERT( pHdl, "Unknown XML property type handler!" ); +} + +/////////////////////////////////////////////////////////////////////////// +// +// Ctor +// +XMLPropertySetMapper::XMLPropertySetMapper( + const XMLPropertyMapEntry* pEntries, + const UniReference< XMLPropertyHandlerFactory >& rFactory ) +{ + aHdlFactories.push_back( rFactory ); + if( pEntries ) + { + const XMLPropertyMapEntry* pIter = pEntries; + + // count entries + while( pIter->msApiName ) + { + XMLPropertySetMapperEntry_Impl aEntry( *pIter, rFactory ); + aMapEntries.push_back( aEntry ); + pIter++; + } + } +} + +XMLPropertySetMapper::~XMLPropertySetMapper() +{ +} + +void XMLPropertySetMapper::AddMapperEntry( + const UniReference < XMLPropertySetMapper >& rMapper ) +{ + for( vector < UniReference < XMLPropertyHandlerFactory > >::iterator + aFIter = rMapper->aHdlFactories.begin(); + aFIter != rMapper->aHdlFactories.end(); + ++aFIter ) + { + aHdlFactories.push_back( *aFIter ); + } + + for( vector < XMLPropertySetMapperEntry_Impl >::iterator + aEIter = rMapper->aMapEntries.begin(); + aEIter != rMapper->aMapEntries.end(); + ++aEIter ) + { + aMapEntries.push_back( *aEIter ); + } +} + +/////////////////////////////////////////////////////////////////////////// +// +// Export a Property +// +sal_Bool XMLPropertySetMapper::exportXML( + OUString& rStrExpValue, + const XMLPropertyState& rProperty, + const SvXMLUnitConverter& rUnitConverter ) const +{ + sal_Bool bRet = sal_False; + + const XMLPropertyHandler* pHdl = GetPropertyHandler( rProperty.mnIndex ); + + DBG_ASSERT( pHdl, "Unknown XML Type!" ); + if( pHdl ) + bRet = pHdl->exportXML( rStrExpValue, rProperty.maValue, + rUnitConverter ); + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////// +// +// Import a Property +// +sal_Bool XMLPropertySetMapper::importXML( + const OUString& rStrImpValue, + XMLPropertyState& rProperty, + const SvXMLUnitConverter& rUnitConverter ) const +{ + sal_Bool bRet = sal_False; + + const XMLPropertyHandler* pHdl = GetPropertyHandler( rProperty.mnIndex ); + + if( pHdl ) + bRet = pHdl->importXML( rStrImpValue, rProperty.maValue, + rUnitConverter ); + + return bRet; +} + +/////////////////////////////////////////////////////////////////////////// +// +// Search for the given name and the namespace in the list and return +// the index of the entry +// If there is no matching entry the method returns -1 +// +sal_Int32 XMLPropertySetMapper::GetEntryIndex( + sal_uInt16 nNamespace, + const OUString& rStrName, + sal_uInt32 nPropType, + sal_Int32 nStartAt /* = -1 */ ) const +{ + sal_Int32 nEntries = GetEntryCount(); + sal_Int32 nIndex= nStartAt == - 1? 0 : nStartAt+1; + + if ( nEntries ) + { + do + { + const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex]; + if( (!nPropType || nPropType == rEntry.GetPropType()) && + rEntry.nXMLNameSpace == nNamespace && + rStrName == rEntry.sXMLAttributeName ) + return nIndex; + else + nIndex++; + + } while( nIndex<nEntries ); + } + + return -1; +} + + +/** searches for an entry that matches the given api name, namespace and local name or -1 if nothing found */ +sal_Int32 XMLPropertySetMapper::FindEntryIndex( + const sal_Char* sApiName, + sal_uInt16 nNameSpace, + const OUString& sXMLName ) const +{ + sal_Int32 nIndex = 0; + sal_Int32 nEntries = GetEntryCount(); + + do + { + const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex]; + if( rEntry.nXMLNameSpace == nNameSpace && + rEntry.sXMLAttributeName.equals( sXMLName ) && + 0 == rEntry.sAPIPropertyName.compareToAscii( sApiName ) ) + return nIndex; + else + nIndex++; + + } while( nIndex < nEntries ); + + return -1; +} + +sal_Int32 XMLPropertySetMapper::FindEntryIndex( const sal_Int16 nContextId ) const +{ + sal_Int32 nIndex = 0; + const sal_Int32 nEntries = GetEntryCount(); + + if ( nEntries ) + { + do + { + const XMLPropertySetMapperEntry_Impl& rEntry = aMapEntries[nIndex]; + if( rEntry.nContextId == nContextId ) + return nIndex; + else + nIndex++; + + } while( nIndex < nEntries ); + } + + return -1; +} + +void XMLPropertySetMapper::RemoveEntry( sal_Int32 nIndex ) +{ + const sal_Int32 nEntries = GetEntryCount(); + if( nIndex>=nEntries || nIndex<0 ) + return; + vector < XMLPropertySetMapperEntry_Impl >::iterator aEIter = aMapEntries.begin(); + for( sal_Int32 nN=0; nN<nIndex; nN++ ) + ++aEIter; + aMapEntries.erase( aEIter ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/xmlstyle.cxx b/xmloff/source/style/xmlstyle.cxx new file mode 100644 index 000000000000..b3343c307193 --- /dev/null +++ b/xmloff/source/style/xmlstyle.cxx @@ -0,0 +1,954 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <com/sun/star/xml/sax/SAXParseException.hpp> +#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> +#include <com/sun/star/xml/sax/SAXException.hpp> +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +#include <com/sun/star/xml/sax/XAttributeList.hpp> +#include <com/sun/star/xml/sax/XLocator.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/style/XAutoStylesSupplier.hpp> +#include <com/sun/star/style/XAutoStyleFamily.hpp> +#include "PageMasterPropMapper.hxx" +#include <tools/debug.hxx> +#include <svl/cntnrsrt.hxx> +#include <svl/itemset.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> + +#include <xmloff/families.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/xmlnumi.hxx> +#include <xmloff/xmlimppr.hxx> +#include <xmloff/xmlstyle.hxx> +#include <xmloff/txtstyli.hxx> +#include <xmloff/txtprmap.hxx> +#include <xmloff/xmlnumfi.hxx> +#include "XMLChartStyleContext.hxx" +#include "XMLChartPropertySetMapper.hxx" +#include <xmloff/XMLShapeStyleContext.hxx> +#include "FillStyleContext.hxx" +#include "XMLFootnoteConfigurationImportContext.hxx" +#include "XMLIndexBibliographyConfigurationContext.hxx" +#include "XMLLineNumberingImportContext.hxx" +#include "PageMasterImportContext.hxx" +#include "PageMasterImportPropMapper.hxx" + +#include <vector> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; +using ::std::vector; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::style; +using namespace ::xmloff::token; + +// --------------------------------------------------------------------- + +static SvXMLTokenMapEntry aStyleStylesElemTokenMap[] = +{ + { XML_NAMESPACE_STYLE, XML_STYLE, XML_TOK_STYLE_STYLE }, + { XML_NAMESPACE_STYLE, XML_PAGE_LAYOUT, XML_TOK_STYLE_PAGE_MASTER }, + { XML_NAMESPACE_TEXT, XML_LIST_STYLE, XML_TOK_TEXT_LIST_STYLE }, + { XML_NAMESPACE_TEXT, XML_OUTLINE_STYLE, XML_TOK_TEXT_OUTLINE }, + { XML_NAMESPACE_STYLE, XML_DEFAULT_STYLE, XML_TOK_STYLE_DEFAULT_STYLE }, + { XML_NAMESPACE_DRAW, XML_GRADIENT, XML_TOK_STYLES_GRADIENTSTYLES }, + { XML_NAMESPACE_DRAW, XML_HATCH, XML_TOK_STYLES_HATCHSTYLES }, + { XML_NAMESPACE_DRAW, XML_FILL_IMAGE, XML_TOK_STYLES_BITMAPSTYLES }, + { XML_NAMESPACE_DRAW, XML_OPACITY, XML_TOK_STYLES_TRANSGRADIENTSTYLES }, + { XML_NAMESPACE_DRAW, XML_MARKER, XML_TOK_STYLES_MARKERSTYLES }, + { XML_NAMESPACE_DRAW, XML_STROKE_DASH, XML_TOK_STYLES_DASHSTYLES }, + { XML_NAMESPACE_TEXT, XML_NOTES_CONFIGURATION, XML_TOK_TEXT_NOTE_CONFIG }, + { XML_NAMESPACE_TEXT, XML_BIBLIOGRAPHY_CONFIGURATION, XML_TOK_TEXT_BIBLIOGRAPHY_CONFIG }, + { XML_NAMESPACE_TEXT, XML_LINENUMBERING_CONFIGURATION,XML_TOK_TEXT_LINENUMBERING_CONFIG }, + { XML_NAMESPACE_STYLE, XML_DEFAULT_PAGE_LAYOUT, XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT }, + XML_TOKEN_MAP_END +}; + +const SvXMLTokenMap& SvXMLStylesContext::GetStyleStylesElemTokenMap() +{ + if( !mpStyleStylesElemTokenMap ) + mpStyleStylesElemTokenMap = + new SvXMLTokenMap( aStyleStylesElemTokenMap ); + + return *mpStyleStylesElemTokenMap; +} + +// --------------------------------------------------------------------- + +void SvXMLStyleContext::SetAttribute( sal_uInt16 nPrefixKey, + const OUString& rLocalName, + const OUString& rValue ) +{ + // TODO: use a map here + if( XML_NAMESPACE_STYLE == nPrefixKey ) + { + if( IsXMLToken( rLocalName, XML_FAMILY ) ) + { + if( IsXMLToken( rValue, XML_PARAGRAPH ) ) + mnFamily = (sal_uInt16)SFX_STYLE_FAMILY_PARA; + else if( IsXMLToken( rValue, XML_TEXT ) ) + mnFamily = (sal_uInt16)SFX_STYLE_FAMILY_CHAR; + } + else if( IsXMLToken( rLocalName, XML_NAME ) ) + { + maName = rValue; + } + else if( IsXMLToken( rLocalName, XML_DISPLAY_NAME ) ) + { + maDisplayName = rValue; + } + else if( IsXMLToken( rLocalName, XML_PARENT_STYLE_NAME ) ) + { + maParentName = rValue; + } + else if( IsXMLToken( rLocalName, XML_NEXT_STYLE_NAME ) ) + { + maFollow = rValue; + } + else if( IsXMLToken( rLocalName, XML_HELP_FILE_NAME ) ) + { + maHelpFile = rValue; + } + else if( IsXMLToken( rLocalName, XML_HELP_ID ) ) + { + sal_Int32 nTmp = rValue.toInt32(); + mnHelpId = + (nTmp < 0L) ? 0U : ( (nTmp > USHRT_MAX) ? USHRT_MAX + : (sal_uInt16)nTmp ); + } + } +} + +TYPEINIT1( SvXMLStyleContext, SvXMLImportContext ); + +SvXMLStyleContext::SvXMLStyleContext( + SvXMLImport& rImp, sal_uInt16 nPrfx, + const OUString& rLName, + const uno::Reference< xml::sax::XAttributeList >&, + sal_uInt16 nFam, sal_Bool bDefault ) : + SvXMLImportContext( rImp, nPrfx, rLName ), + mnHelpId( UCHAR_MAX ), + mnFamily( nFam ), + mbValid( sal_True ), + mbNew( sal_True ), + mbDefaultStyle( bDefault ) +{ +} + +SvXMLStyleContext::~SvXMLStyleContext() +{ +} + +SvXMLImportContext *SvXMLStyleContext::CreateChildContext( sal_uInt16 nPrefix, + const OUString& rLocalName, + const uno::Reference< xml::sax::XAttributeList > & ) +{ + return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );; +} + +void SvXMLStyleContext::StartElement( const uno::Reference< xml::sax::XAttributeList > & xAttrList ) +{ + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + OUString aLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName ); + const OUString& rValue = xAttrList->getValueByIndex( i ); + + SetAttribute( nPrefix, aLocalName, rValue ); + } +} + +void SvXMLStyleContext::SetDefaults() +{ +} + +void SvXMLStyleContext::CreateAndInsert( sal_Bool /*bOverwrite*/ ) +{ +} + +void SvXMLStyleContext::CreateAndInsertLate( sal_Bool /*bOverwrite*/ ) +{ +} + +void SvXMLStyleContext::Finish( sal_Bool /*bOverwrite*/ ) +{ +} + +sal_Bool SvXMLStyleContext::IsTransient() const +{ + return sal_False; +} + +// --------------------------------------------------------------------- + +class SvXMLStyleIndex_Impl +{ + OUString sName; + sal_uInt16 nFamily; + const SvXMLStyleContext *pStyle; + +public: + + SvXMLStyleIndex_Impl( sal_uInt16 nFam, const OUString& rName ) : + sName( rName ), + nFamily( nFam ), + pStyle ( 0 ) + { + } + + SvXMLStyleIndex_Impl( const SvXMLStyleContext *pStl ) : + sName( pStl->GetName() ), + nFamily( pStl->GetFamily() ), + pStyle ( pStl ) + { + } + + const OUString& GetName() const { return sName; } + sal_uInt16 GetFamily() const { return nFamily; } + const SvXMLStyleContext *GetStyle() const { return pStyle; } +}; + +int SvXMLStyleIndexCmp_Impl( const SvXMLStyleIndex_Impl& r1, + const SvXMLStyleIndex_Impl& r2 ) +{ + int nRet; + if( (sal_uInt16)r1.GetFamily() < (sal_uInt16)r2.GetFamily() ) + nRet = -1; + else if( (sal_uInt16)r1.GetFamily() > (sal_uInt16)r2.GetFamily() ) + nRet = 1; + else + nRet = (int)r1.GetName().compareTo( r2.GetName() ); + + return nRet; +} + +// --------------------------------------------------------------------- + +typedef SvXMLStyleContext *SvXMLStyleContextPtr; +typedef vector< SvXMLStyleContextPtr > SvXMLStyleContexts_Impl; + +DECLARE_CONTAINER_SORT_DEL( SvXMLStyleIndices_Impl, SvXMLStyleIndex_Impl ) +IMPL_CONTAINER_SORT( SvXMLStyleIndices_Impl, SvXMLStyleIndex_Impl, + SvXMLStyleIndexCmp_Impl ) + + +class SvXMLStylesContext_Impl +{ + SvXMLStyleContexts_Impl aStyles; + SvXMLStyleIndices_Impl *pIndices; + sal_Bool bAutomaticStyle; + +#ifdef DBG_UTIL + sal_uInt32 nIndexCreated; +#endif + + void FlushIndex() { delete pIndices; pIndices = 0; } + +public: + SvXMLStylesContext_Impl( sal_Bool bAuto ); + ~SvXMLStylesContext_Impl(); + + size_t GetStyleCount() const { return aStyles.size(); } + + const SvXMLStyleContext *GetStyle( size_t i ) const + { + return i < aStyles.size() ? aStyles[ i ] : 0; + } + + SvXMLStyleContext *GetStyle( size_t i ) + { + return i < aStyles.size() ? aStyles[ i ] : 0; + } + + inline void AddStyle( SvXMLStyleContext *pStyle ); + void Clear(); + + const SvXMLStyleContext *FindStyleChildContext( sal_uInt16 nFamily, + const OUString& rName, sal_Bool bCreateIndex ) const; + sal_Bool IsAutomaticStyle() const { return bAutomaticStyle; } +}; + +SvXMLStylesContext_Impl::SvXMLStylesContext_Impl( sal_Bool bAuto ) : + pIndices( 0 ), + bAutomaticStyle( bAuto ) +#ifdef DBG_UTIL +, nIndexCreated( 0 ) +#endif +{} + +SvXMLStylesContext_Impl::~SvXMLStylesContext_Impl() +{ + delete pIndices; + + for ( size_t i = 0, n = aStyles.size(); i < n; ++i ) + { + SvXMLStyleContext *pStyle = aStyles[ i ]; + pStyle->ReleaseRef(); + } + aStyles.clear(); +} + +inline void SvXMLStylesContext_Impl::AddStyle( SvXMLStyleContext *pStyle ) +{ + aStyles.push_back( pStyle ); + pStyle->AddRef(); + + FlushIndex(); +} + +void SvXMLStylesContext_Impl::Clear() +{ + FlushIndex(); + + for ( size_t i = 0, n = aStyles.size(); i < n; ++i ) + { + SvXMLStyleContext *pStyle = aStyles[ i ]; + pStyle->ReleaseRef(); + } + aStyles.clear(); +} + +const SvXMLStyleContext *SvXMLStylesContext_Impl::FindStyleChildContext( + sal_uInt16 nFamily, + const OUString& rName, + sal_Bool bCreateIndex ) const +{ + const SvXMLStyleContext *pStyle = 0; + + if( !pIndices && bCreateIndex && !aStyles.empty() ) + { +#ifdef DBG_UTIL + DBG_ASSERT( 0==nIndexCreated, + "Performance warning: sdbcx::Index created multiple times" ); +#endif + ((SvXMLStylesContext_Impl *)this)->pIndices = + new SvXMLStyleIndices_Impl( + sal::static_int_cast< sal_uInt16 >( aStyles.size() ), 5 ); + for( size_t i = 0; i < aStyles.size(); i++ ) + { + SvXMLStyleIndex_Impl* pStyleIndex = new SvXMLStyleIndex_Impl( aStyles[ i ] ); + if (!pIndices->Insert( pStyleIndex )) + { + OSL_FAIL("Here is a double Style"); + delete pStyleIndex; + } + } +#ifdef DBG_UTIL + ((SvXMLStylesContext_Impl *)this)->nIndexCreated++; +#endif + } + + if( pIndices ) + { + SvXMLStyleIndex_Impl aIndex( nFamily, rName ); + sal_uLong nPos = 0; + if( pIndices->Seek_Entry( &aIndex, &nPos ) ) + pStyle = pIndices->GetObject( nPos )->GetStyle(); + } + else + { + for( size_t i = 0; !pStyle && i < aStyles.size(); i++ ) + { + const SvXMLStyleContext *pS = aStyles[ i ]; + if( pS->GetFamily() == nFamily && + pS->GetName() == rName ) + pStyle = pS; + } + } + return pStyle; +} + +// --------------------------------------------------------------------- + +TYPEINIT1( SvXMLStylesContext, SvXMLImportContext ); + +sal_uInt32 SvXMLStylesContext::GetStyleCount() const +{ + return mpImpl->GetStyleCount(); +} + +SvXMLStyleContext *SvXMLStylesContext::GetStyle( sal_uInt32 i ) +{ + return mpImpl->GetStyle( i ); +} + +const SvXMLStyleContext *SvXMLStylesContext::GetStyle( sal_uInt32 i ) const +{ + return mpImpl->GetStyle( i ); +} + +sal_Bool SvXMLStylesContext::IsAutomaticStyle() const +{ + return mpImpl->IsAutomaticStyle(); +} + +SvXMLStyleContext *SvXMLStylesContext::CreateStyleChildContext( + sal_uInt16 p_nPrefix, + const OUString& rLocalName, + const uno::Reference< xml::sax::XAttributeList > & xAttrList ) +{ + SvXMLStyleContext *pStyle = NULL; + + if(GetImport().GetDataStylesImport()) + { + pStyle = GetImport().GetDataStylesImport()->CreateChildContext(GetImport(), p_nPrefix, + rLocalName, xAttrList, *this); + } + + if (!pStyle) + { + const SvXMLTokenMap& rTokenMap = GetStyleStylesElemTokenMap(); + sal_uInt16 nToken = rTokenMap.Get( p_nPrefix, rLocalName ); + switch( nToken ) + { + case XML_TOK_STYLE_STYLE: + case XML_TOK_STYLE_DEFAULT_STYLE: + { + sal_uInt16 nFamily = 0; + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + OUString aLocalName; + sal_uInt16 nPrefix = + GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, + &aLocalName ); + if( XML_NAMESPACE_STYLE == nPrefix && + IsXMLToken( aLocalName, XML_FAMILY ) ) + { + const OUString& rValue = xAttrList->getValueByIndex( i ); + nFamily = GetFamily( rValue ); + break; + } + } + pStyle = XML_TOK_STYLE_STYLE==nToken + ? CreateStyleStyleChildContext( nFamily, p_nPrefix, + rLocalName, xAttrList ) + : CreateDefaultStyleStyleChildContext( nFamily, p_nPrefix, + rLocalName, xAttrList ); + } + break; + case XML_TOK_STYLE_PAGE_MASTER: + case XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT: + { + //there is not page family in odf now, so I specify one for it + sal_Bool bDefaultStyle = XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT == nToken + ? sal_True: sal_False; + pStyle = new PageStyleContext( GetImport(), p_nPrefix, + rLocalName, xAttrList, *this, bDefaultStyle ); + } + break; + case XML_TOK_TEXT_LIST_STYLE: + pStyle = new SvxXMLListStyleContext( GetImport(), p_nPrefix, + rLocalName, xAttrList ); + break; + case XML_TOK_TEXT_OUTLINE: + pStyle = new SvxXMLListStyleContext( GetImport(), p_nPrefix, + rLocalName, xAttrList, sal_True ); + break; + case XML_TOK_TEXT_NOTE_CONFIG: + pStyle = new XMLFootnoteConfigurationImportContext(GetImport(), + p_nPrefix, + rLocalName, + xAttrList); + break; + + case XML_TOK_TEXT_BIBLIOGRAPHY_CONFIG: + pStyle = new XMLIndexBibliographyConfigurationContext( + GetImport(), p_nPrefix, rLocalName, xAttrList); + break; + + case XML_TOK_TEXT_LINENUMBERING_CONFIG: + pStyle = new XMLLineNumberingImportContext( + GetImport(), p_nPrefix, rLocalName, xAttrList); + break; + + // + // FillStyles + // + case XML_TOK_STYLES_GRADIENTSTYLES: + { + pStyle = new XMLGradientStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList ); + break; + } + case XML_TOK_STYLES_HATCHSTYLES: + { + pStyle = new XMLHatchStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList ); + break; + } + case XML_TOK_STYLES_BITMAPSTYLES: + { + pStyle = new XMLBitmapStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList ); + break; + } + case XML_TOK_STYLES_TRANSGRADIENTSTYLES: + { + pStyle = new XMLTransGradientStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList ); + break; + } + case XML_TOK_STYLES_MARKERSTYLES: + { + pStyle = new XMLMarkerStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList ); + break; + } + case XML_TOK_STYLES_DASHSTYLES: + { + pStyle = new XMLDashStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList ); + break; + } + } + } + + return pStyle; +} + +SvXMLStyleContext *SvXMLStylesContext::CreateStyleStyleChildContext( + sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName, + const uno::Reference< xml::sax::XAttributeList > & xAttrList ) +{ + SvXMLStyleContext *pStyle = 0; + + switch( nFamily ) + { + case XML_STYLE_FAMILY_TEXT_PARAGRAPH: + case XML_STYLE_FAMILY_TEXT_TEXT: + case XML_STYLE_FAMILY_TEXT_SECTION: + pStyle = new XMLTextStyleContext( GetImport(), nPrefix, rLocalName, + xAttrList, *this, nFamily ); + break; + + case XML_STYLE_FAMILY_TEXT_RUBY: + pStyle = new XMLPropStyleContext( GetImport(), nPrefix, rLocalName, + xAttrList, *this, nFamily ); + break; + case XML_STYLE_FAMILY_SCH_CHART_ID: + pStyle = new XMLChartStyleContext( GetImport(), nPrefix, rLocalName, + xAttrList, *this, nFamily ); + break; + + case XML_STYLE_FAMILY_SD_GRAPHICS_ID: + case XML_STYLE_FAMILY_SD_PRESENTATION_ID: + case XML_STYLE_FAMILY_SD_POOL_ID: + pStyle = new XMLShapeStyleContext( GetImport(), nPrefix, rLocalName, + xAttrList, *this, nFamily ); + } + + return pStyle; +} + +SvXMLStyleContext *SvXMLStylesContext::CreateDefaultStyleStyleChildContext( + sal_uInt16 /*nFamily*/, sal_uInt16 /*nPrefix*/, const OUString& /*rLocalName*/, + const uno::Reference< xml::sax::XAttributeList > & ) +{ + return 0; +} + + +sal_Bool SvXMLStylesContext::InsertStyleFamily( sal_uInt16 ) const +{ + return sal_True; +} + +sal_uInt16 SvXMLStylesContext::GetFamily( + const ::rtl::OUString& rValue ) const +{ + sal_uInt16 nFamily = 0U; + if( IsXMLToken( rValue, XML_PARAGRAPH ) ) + { + nFamily = XML_STYLE_FAMILY_TEXT_PARAGRAPH; + } + else if( IsXMLToken( rValue, XML_TEXT ) ) + { + nFamily = XML_STYLE_FAMILY_TEXT_TEXT; + } + else if( IsXMLToken( rValue, XML_DATA_STYLE ) ) + { + nFamily = XML_STYLE_FAMILY_DATA_STYLE; + } + else if ( IsXMLToken( rValue, XML_SECTION ) ) + { + nFamily = XML_STYLE_FAMILY_TEXT_SECTION; + } + else if( IsXMLToken( rValue, XML_TABLE ) ) + { + nFamily = XML_STYLE_FAMILY_TABLE_TABLE; + } + else if( IsXMLToken( rValue, XML_TABLE_COLUMN ) ) + nFamily = XML_STYLE_FAMILY_TABLE_COLUMN; + else if( IsXMLToken( rValue, XML_TABLE_ROW ) ) + nFamily = XML_STYLE_FAMILY_TABLE_ROW; + else if( IsXMLToken( rValue, XML_TABLE_CELL ) ) + nFamily = XML_STYLE_FAMILY_TABLE_CELL; + else if( rValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(XML_STYLE_FAMILY_SD_GRAPHICS_NAME))) + { + nFamily = XML_STYLE_FAMILY_SD_GRAPHICS_ID; + } + else if( rValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(XML_STYLE_FAMILY_SD_PRESENTATION_NAME))) + { + nFamily = XML_STYLE_FAMILY_SD_PRESENTATION_ID; + } + else if( rValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(XML_STYLE_FAMILY_SD_POOL_NAME))) + { + nFamily = XML_STYLE_FAMILY_SD_POOL_ID; + } + else if( rValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(XML_STYLE_FAMILY_SD_DRAWINGPAGE_NAME))) + { + nFamily = XML_STYLE_FAMILY_SD_DRAWINGPAGE_ID; + } + else if( rValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( XML_STYLE_FAMILY_SCH_CHART_NAME ))) + { + nFamily = XML_STYLE_FAMILY_SCH_CHART_ID; + } + else if ( IsXMLToken( rValue, XML_RUBY ) ) + { + nFamily = XML_STYLE_FAMILY_TEXT_RUBY; + } + + return nFamily; +} + +UniReference < SvXMLImportPropertyMapper > SvXMLStylesContext::GetImportPropertyMapper( + sal_uInt16 nFamily ) const +{ + UniReference < SvXMLImportPropertyMapper > xMapper; + + switch( nFamily ) + { + case XML_STYLE_FAMILY_TEXT_PARAGRAPH: + if( !mxParaImpPropMapper.is() ) + { + SvXMLStylesContext * pThis = (SvXMLStylesContext *)this; + pThis->mxParaImpPropMapper = + pThis->GetImport().GetTextImport() + ->GetParaImportPropertySetMapper(); + } + xMapper = mxParaImpPropMapper; + break; + case XML_STYLE_FAMILY_TEXT_TEXT: + if( !mxTextImpPropMapper.is() ) + { + SvXMLStylesContext * pThis = (SvXMLStylesContext *)this; + pThis->mxTextImpPropMapper = + pThis->GetImport().GetTextImport() + ->GetTextImportPropertySetMapper(); + } + xMapper = mxTextImpPropMapper; + break; + + case XML_STYLE_FAMILY_TEXT_SECTION: + // don't cache section mapper, as it's rarely used + // *sigh*, cast to non-const, because this is a const method, + // but SvXMLImport::GetTextImport() isn't. + xMapper = ((SvXMLStylesContext*)this)->GetImport().GetTextImport()-> + GetSectionImportPropertySetMapper(); + break; + + case XML_STYLE_FAMILY_TEXT_RUBY: + // don't cache section mapper, as it's rarely used + // *sigh*, cast to non-const, because this is a const method, + // but SvXMLImport::GetTextImport() isn't. + xMapper = ((SvXMLStylesContext*)this)->GetImport().GetTextImport()-> + GetRubyImportPropertySetMapper(); + break; + + case XML_STYLE_FAMILY_SD_GRAPHICS_ID: + case XML_STYLE_FAMILY_SD_PRESENTATION_ID: + case XML_STYLE_FAMILY_SD_POOL_ID: + if(!mxShapeImpPropMapper.is()) + { + UniReference< XMLShapeImportHelper > aImpHelper = ((SvXMLImport&)GetImport()).GetShapeImport(); + ((SvXMLStylesContext*)this)->mxShapeImpPropMapper = + aImpHelper->GetPropertySetMapper(); + } + xMapper = mxShapeImpPropMapper; + break; + case XML_STYLE_FAMILY_SCH_CHART_ID: + if( ! mxChartImpPropMapper.is() ) + { + XMLPropertySetMapper *pPropMapper = new XMLChartPropertySetMapper(); + mxChartImpPropMapper = new XMLChartImportPropertyMapper( pPropMapper, GetImport() ); + } + xMapper = mxChartImpPropMapper; + break; + case XML_STYLE_FAMILY_PAGE_MASTER: + if( ! mxPageImpPropMapper.is() ) + { + XMLPropertySetMapper *pPropMapper = + new XMLPageMasterPropSetMapper(); + mxPageImpPropMapper = + new PageMasterImportPropertyMapper( pPropMapper, + ((SvXMLStylesContext*)this)->GetImport() ); + } + xMapper = mxPageImpPropMapper; + break; + } + + return xMapper; +} + +Reference < XAutoStyleFamily > SvXMLStylesContext::GetAutoStyles( sal_uInt16 nFamily ) const +{ + Reference < XAutoStyleFamily > xAutoStyles; + if( XML_STYLE_FAMILY_TEXT_TEXT == nFamily || XML_STYLE_FAMILY_TEXT_PARAGRAPH == nFamily) + { + bool bPara = XML_STYLE_FAMILY_TEXT_PARAGRAPH == nFamily; + OUString sName; + if( !bPara && mxTextAutoStyles.is() ) + xAutoStyles = mxTextAutoStyles; + else if( bPara && mxParaAutoStyles.is() ) + xAutoStyles = mxParaAutoStyles; + else + { + sName = bPara ? + OUString( RTL_CONSTASCII_USTRINGPARAM( "ParagraphStyles" ) ): + OUString( RTL_CONSTASCII_USTRINGPARAM( "CharacterStyles" ) ); + Reference< XAutoStylesSupplier > xAutoStylesSupp( GetImport().GetModel(), UNO_QUERY ); + Reference< XAutoStyles > xAutoStyleFamilies = xAutoStylesSupp->getAutoStyles(); + if (xAutoStyleFamilies->hasByName(sName)) + { + Any aAny = xAutoStyleFamilies->getByName( sName ); + xAutoStyles = *(Reference<XAutoStyleFamily>*)aAny.getValue(); + if( bPara ) + ((SvXMLStylesContext *)this)->mxParaAutoStyles = xAutoStyles; + else + ((SvXMLStylesContext *)this)->mxTextAutoStyles = xAutoStyles; + } + } + } + return xAutoStyles; +} + +Reference < XNameContainer > SvXMLStylesContext::GetStylesContainer( + sal_uInt16 nFamily ) const +{ + Reference < XNameContainer > xStyles; + OUString sName; + switch( nFamily ) + { + case XML_STYLE_FAMILY_TEXT_PARAGRAPH: + if( mxParaStyles.is() ) + xStyles = mxParaStyles; + else + sName = + OUString( RTL_CONSTASCII_USTRINGPARAM( "ParagraphStyles" ) ); + break; + + case XML_STYLE_FAMILY_TEXT_TEXT: + if( mxTextStyles.is() ) + xStyles = mxTextStyles; + else + sName = + OUString( RTL_CONSTASCII_USTRINGPARAM( "CharacterStyles" ) ); + break; + } + if( !xStyles.is() && sName.getLength() ) + { + Reference< XStyleFamiliesSupplier > xFamiliesSupp( + GetImport().GetModel(), UNO_QUERY ); + if ( xFamiliesSupp.is() ) + { + Reference< XNameAccess > xFamilies = xFamiliesSupp->getStyleFamilies(); + if (xFamilies->hasByName(sName)) + { + xStyles.set(xFamilies->getByName( sName ),uno::UNO_QUERY); + + switch( nFamily ) + { + case XML_STYLE_FAMILY_TEXT_PARAGRAPH: + ((SvXMLStylesContext *)this)->mxParaStyles = xStyles; + break; + + case XML_STYLE_FAMILY_TEXT_TEXT: + ((SvXMLStylesContext *)this)->mxTextStyles = xStyles; + break; + } + } + } + } + + return xStyles; +} + +OUString SvXMLStylesContext::GetServiceName( sal_uInt16 nFamily ) const +{ + String sServiceName; + switch( nFamily ) + { + case XML_STYLE_FAMILY_TEXT_PARAGRAPH: + sServiceName = msParaStyleServiceName; + break; + case XML_STYLE_FAMILY_TEXT_TEXT: + sServiceName = msTextStyleServiceName; + break; + } + + return sServiceName; +} + + +SvXMLStylesContext::SvXMLStylesContext( SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const uno::Reference< xml::sax::XAttributeList > &, sal_Bool bAuto ) : + SvXMLImportContext( rImport, nPrfx, rLName ), + msParaStyleServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.ParagraphStyle" ) ), + msTextStyleServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.CharacterStyle" ) ), + mpImpl( new SvXMLStylesContext_Impl( bAuto ) ), + mpStyleStylesElemTokenMap( 0 ) +{ +} + + +SvXMLStylesContext::~SvXMLStylesContext() +{ + delete mpStyleStylesElemTokenMap; + delete mpImpl; +} + +SvXMLImportContext *SvXMLStylesContext::CreateChildContext( sal_uInt16 nPrefix, + const OUString& rLocalName, + const uno::Reference< xml::sax::XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + + SvXMLStyleContext *pStyle = + CreateStyleChildContext( nPrefix, rLocalName, xAttrList ); + if( pStyle ) + { + if( !pStyle->IsTransient() ) + mpImpl->AddStyle( pStyle ); + pContext = pStyle; + } + else + { + pContext = new SvXMLImportContext( GetImport(), nPrefix, + rLocalName ); + } + + return pContext; +} + +void SvXMLStylesContext::EndElement() +{ +} + +void SvXMLStylesContext::AddStyle(SvXMLStyleContext& rNew) +{ + mpImpl->AddStyle( &rNew ); +} + +void SvXMLStylesContext::Clear() +{ + mpImpl->Clear(); +} + +void SvXMLStylesContext::CopyAutoStylesToDoc() +{ + sal_uInt32 nCount = GetStyleCount(); + sal_uInt32 i; + for( i = 0; i < nCount; i++ ) + { + SvXMLStyleContext *pStyle = GetStyle( i ); + if( !pStyle || ( pStyle->GetFamily() != XML_STYLE_FAMILY_TEXT_TEXT && + pStyle->GetFamily() != XML_STYLE_FAMILY_TEXT_PARAGRAPH && + pStyle->GetFamily() != XML_STYLE_FAMILY_TABLE_CELL ) ) + continue; + pStyle->CreateAndInsert( sal_False ); + } +} + +void SvXMLStylesContext::CopyStylesToDoc( sal_Bool bOverwrite, + sal_Bool bFinish ) +{ + // pass 1: create text, paragraph and frame styles + sal_uInt32 nCount = GetStyleCount(); + sal_uInt32 i; + + for( i = 0; i < nCount; i++ ) + { + SvXMLStyleContext *pStyle = GetStyle( i ); + if( !pStyle ) + continue; + + if (pStyle->IsDefaultStyle()) + pStyle->SetDefaults(); + else if( InsertStyleFamily( pStyle->GetFamily() ) ) + pStyle->CreateAndInsert( bOverwrite ); + } + + // pass 2: create list styles (they require char styles) + for( i=0; i<nCount; i++ ) + { + SvXMLStyleContext *pStyle = GetStyle( i ); + if( !pStyle || pStyle->IsDefaultStyle()) + continue; + + if( InsertStyleFamily( pStyle->GetFamily() ) ) + pStyle->CreateAndInsertLate( bOverwrite ); + } + + // pass3: finish creation of styles + if( bFinish ) + FinishStyles( bOverwrite ); +} + +void SvXMLStylesContext::FinishStyles( sal_Bool bOverwrite ) +{ + sal_uInt32 nCount = GetStyleCount(); + for( sal_uInt32 i=0; i<nCount; i++ ) + { + SvXMLStyleContext *pStyle = GetStyle( i ); + if( !pStyle || !pStyle->IsValid() || pStyle->IsDefaultStyle() ) + continue; + + if( InsertStyleFamily( pStyle->GetFamily() ) ) + pStyle->Finish( bOverwrite ); + } +} + + +const SvXMLStyleContext *SvXMLStylesContext::FindStyleChildContext( + sal_uInt16 nFamily, + const OUString& rName, + sal_Bool bCreateIndex ) const +{ + return mpImpl->FindStyleChildContext( nFamily, rName, bCreateIndex ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/xmltabe.cxx b/xmloff/source/style/xmltabe.cxx new file mode 100644 index 000000000000..d967e3d30618 --- /dev/null +++ b/xmloff/source/style/xmltabe.cxx @@ -0,0 +1,140 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + +#include <tools/debug.hxx> +#include <com/sun/star/style/TabStop.hpp> +#include <com/sun/star/style/TabAlign.hpp> +#include <rtl/ustrbuf.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmluconv.hxx> +#include <xmloff/xmlexp.hxx> +#include "xmloff/xmltabe.hxx" + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::xmloff::token; + +SvXMLEnumMapEntry pXML_tabstop_style[] = +{ + { XML_LEFT, style::TabAlign_LEFT }, + { XML_CENTER, style::TabAlign_CENTER }, + { XML_RIGHT, style::TabAlign_RIGHT }, + { XML_CHAR, style::TabAlign_DECIMAL }, + { XML_DEFAULT, style::TabAlign_DEFAULT }, // ????????????????????????????????????? + { XML_TOKEN_INVALID, 0 } +}; + +void SvxXMLTabStopExport::exportTabStop( const ::com::sun::star::style::TabStop* pTabStop ) +{ + SvXMLUnitConverter& rUnitConv = rExport.GetMM100UnitConverter(); + + // text:level + OUStringBuffer sBuffer; + + // position attribute + rUnitConv.convertMeasure( sBuffer, pTabStop->Position ); + rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_POSITION, + sBuffer.makeStringAndClear() ); + + // type attribute + if( style::TabAlign_LEFT != pTabStop->Alignment ) + { + rUnitConv.convertEnum( sBuffer, pTabStop->Alignment, + pXML_tabstop_style ); + rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_TYPE, + sBuffer.makeStringAndClear() ); + } + + // char + if( style::TabAlign_DECIMAL == pTabStop->Alignment && + pTabStop->DecimalChar != 0 ) + { + sBuffer.append( pTabStop->DecimalChar ); + rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_CHAR, + sBuffer.makeStringAndClear() ); + } + + // leader-char + if( ' ' != pTabStop->FillChar && 0 != pTabStop->FillChar ) + { + rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_LEADER_STYLE, + GetXMLToken('.' == pTabStop->FillChar ? XML_DOTTED + : XML_SOLID) ); + + sBuffer.append( pTabStop->FillChar ); + rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_LEADER_TEXT, + sBuffer.makeStringAndClear() ); + } + + SvXMLElementExport rElem( rExport, XML_NAMESPACE_STYLE, XML_TAB_STOP, + sal_True, sal_True ); +} + + +SvxXMLTabStopExport::SvxXMLTabStopExport( + SvXMLExport& rExp) + : rExport( rExp ) +{ +} + +SvxXMLTabStopExport::~SvxXMLTabStopExport() +{ +} + +void SvxXMLTabStopExport::Export( const uno::Any& rAny ) +{ + uno::Sequence< ::com::sun::star::style::TabStop> aSeq; + if(!(rAny >>= aSeq)) + { + OSL_FAIL( "SvxXMLTabStopExport needs a Sequence ::com::sun::star::style::TabStop>" ); + } + else + { + const ::com::sun::star::style::TabStop* pTabs = aSeq.getConstArray(); + const sal_Int32 nTabs = aSeq.getLength(); + + SvXMLElementExport rElem( rExport, XML_NAMESPACE_STYLE, XML_TAB_STOPS, + sal_True, sal_True ); + + for( sal_Int32 nIndex = 0; nIndex < nTabs; nIndex++ ) + { + if( style::TabAlign_DEFAULT != pTabs[nIndex].Alignment ) + exportTabStop( &(pTabs[nIndex]) ); + } + } +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/xmltabi.cxx b/xmloff/source/style/xmltabi.cxx new file mode 100644 index 000000000000..a5c92fb5469d --- /dev/null +++ b/xmloff/source/style/xmltabi.cxx @@ -0,0 +1,295 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" +#include <com/sun/star/style/TabAlign.hpp> +#include <rtl/ustrbuf.hxx> +#include <xmloff/xmltkmap.hxx> +#include <xmloff/nmspmap.hxx> +#include "xmloff/xmlnmspe.hxx" +#include <xmloff/xmlimp.hxx> +#include <com/sun/star/style/TabStop.hpp> +#include <xmloff/xmltoken.hxx> +#include "xmloff/i18nmap.hxx" +#include <xmloff/xmluconv.hxx> + +#include "xmltabi.hxx" + +#define _SVSTDARR_USHORTS +#include <svl/svstdarr.hxx> + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +using namespace ::com::sun::star; +using namespace ::xmloff::token; + +// --- + +enum SvXMLTokenMapAttrs +{ + XML_TOK_TABSTOP_POSITION, + XML_TOK_TABSTOP_TYPE, + XML_TOK_TABSTOP_CHAR, + XML_TOK_TABSTOP_LEADER_STYLE, + XML_TOK_TABSTOP_LEADER_TEXT, + XML_TOK_TABSTOP_END=XML_TOK_UNKNOWN +}; + +static SvXMLTokenMapEntry aTabsAttributesAttrTokenMap[] = +{ + { XML_NAMESPACE_STYLE, XML_POSITION, XML_TOK_TABSTOP_POSITION }, + { XML_NAMESPACE_STYLE, XML_TYPE, XML_TOK_TABSTOP_TYPE }, + { XML_NAMESPACE_STYLE, XML_CHAR, XML_TOK_TABSTOP_CHAR }, + { XML_NAMESPACE_STYLE, XML_LEADER_TEXT, XML_TOK_TABSTOP_LEADER_TEXT }, + { XML_NAMESPACE_STYLE, XML_LEADER_STYLE, XML_TOK_TABSTOP_LEADER_STYLE }, + XML_TOKEN_MAP_END +}; + +// --- + +class SvxXMLTabStopContext_Impl : public SvXMLImportContext +{ +private: + style::TabStop aTabStop; + +public: + TYPEINFO(); + + SvxXMLTabStopContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const uno::Reference< xml::sax::XAttributeList > & xAttrList ); + + virtual ~SvxXMLTabStopContext_Impl(); + + virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const OUString& rLocalName, + const uno::Reference< xml::sax::XAttributeList > & xAttrList ); + + const style::TabStop& getTabStop() const { return aTabStop; } +}; + +TYPEINIT1( SvxXMLTabStopContext_Impl, SvXMLImportContext ); + +SvxXMLTabStopContext_Impl::SvxXMLTabStopContext_Impl( + SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const uno::Reference< xml::sax::XAttributeList > & xAttrList ) +: SvXMLImportContext( rImport, nPrfx, rLName ) +{ + aTabStop.Position = 0; + aTabStop.Alignment = style::TabAlign_LEFT; + aTabStop.DecimalChar = sal_Unicode( ',' ); + aTabStop.FillChar = sal_Unicode( ' ' ); + sal_Unicode cTextFillChar = 0; + + SvXMLTokenMap aTokenMap( aTabsAttributesAttrTokenMap ); + + sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; + for( sal_Int16 i=0; i < nAttrCount; i++ ) + { + const OUString& rAttrName = xAttrList->getNameByIndex( i ); + OUString aLocalName; + sal_uInt16 nPrefix = + GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, + &aLocalName ); + const OUString& rValue = xAttrList->getValueByIndex( i ); + + sal_Int32 nVal; + switch( aTokenMap.Get( nPrefix, aLocalName ) ) + { + case XML_TOK_TABSTOP_POSITION: + if( GetImport().GetMM100UnitConverter().convertMeasure( nVal, + rValue ) ) + aTabStop.Position = nVal; + break; + case XML_TOK_TABSTOP_TYPE: + if( IsXMLToken( rValue, XML_LEFT ) ) + { + aTabStop.Alignment = style::TabAlign_LEFT; + } + else if( IsXMLToken( rValue, XML_RIGHT ) ) + { + aTabStop.Alignment = style::TabAlign_RIGHT; + } + else if( IsXMLToken( rValue, XML_CENTER ) ) + { + aTabStop.Alignment = style::TabAlign_CENTER; + } + else if( IsXMLToken( rValue, XML_CHAR ) ) + { + aTabStop.Alignment = style::TabAlign_DECIMAL; + } + else if( IsXMLToken( rValue, XML_DEFAULT ) ) + { + aTabStop.Alignment = style::TabAlign_DEFAULT; + } + break; + case XML_TOK_TABSTOP_CHAR: + if( 0 != rValue.getLength() ) + aTabStop.DecimalChar = rValue[0]; + break; + case XML_TOK_TABSTOP_LEADER_STYLE: + if( IsXMLToken( rValue, XML_NONE ) ) + aTabStop.FillChar = ' '; + else if( IsXMLToken( rValue, XML_DOTTED ) ) + aTabStop.FillChar = '.'; + else + aTabStop.FillChar = '_'; + break; + case XML_TOK_TABSTOP_LEADER_TEXT: + if( 0 != rValue.getLength() ) + cTextFillChar = rValue[0]; + break; + } + } + + if( cTextFillChar != 0 && aTabStop.FillChar != ' ' ) + aTabStop.FillChar = cTextFillChar; +} + +SvxXMLTabStopContext_Impl::~SvxXMLTabStopContext_Impl() +{ +} + +SvXMLImportContext *SvxXMLTabStopContext_Impl::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const uno::Reference< xml::sax::XAttributeList > & ) +{ + return new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); +} + + + + +typedef SvxXMLTabStopContext_Impl *SvxXMLTabStopContext_Impl_ImplPtr; +SV_DECL_PTRARR( SvxXMLTabStopArray_Impl, SvxXMLTabStopContext_Impl_ImplPtr, 20, 5 ) + + +// --- + +TYPEINIT1( SvxXMLTabStopImportContext, XMLElementPropertyContext ); + +SvxXMLTabStopImportContext::SvxXMLTabStopImportContext( + SvXMLImport& rImport, sal_uInt16 nPrfx, + const OUString& rLName, + const XMLPropertyState& rProp, + ::std::vector< XMLPropertyState > &rProps ) +: XMLElementPropertyContext( rImport, nPrfx, rLName, rProp, rProps ), + mpTabStops( NULL ) +{ +} + +SvxXMLTabStopImportContext::~SvxXMLTabStopImportContext() +{ + if( mpTabStops ) + { + sal_uInt16 nCount = mpTabStops->Count(); + while( nCount ) + { + nCount--; + SvxXMLTabStopContext_Impl *pTabStop = (*mpTabStops)[nCount]; + mpTabStops->Remove( nCount, 1 ); + pTabStop->ReleaseRef(); + } + } + + delete mpTabStops; +} + +SvXMLImportContext *SvxXMLTabStopImportContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const uno::Reference< xml::sax::XAttributeList > & xAttrList ) +{ + SvXMLImportContext *pContext = 0; + + if( XML_NAMESPACE_STYLE == nPrefix && IsXMLToken( rLocalName, XML_TAB_STOP ) ) + { + // create new tabstop import context + SvxXMLTabStopContext_Impl *pTabStopContext = + new SvxXMLTabStopContext_Impl( GetImport(), nPrefix, rLocalName, + xAttrList ); + + // add new tabstop to array of tabstops + if( !mpTabStops ) + mpTabStops = new SvxXMLTabStopArray_Impl; + + mpTabStops->Insert( pTabStopContext, mpTabStops->Count() ); + pTabStopContext->AddRef(); + + pContext = pTabStopContext; + } + else + { + pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); + } + + return pContext; +} + +void SvxXMLTabStopImportContext::EndElement( ) +{ + sal_uInt16 nCount = mpTabStops ? mpTabStops->Count() : 0; + uno::Sequence< style::TabStop> aSeq( nCount ); + + if( mpTabStops ) + { + sal_uInt16 nNewCount = 0; + + style::TabStop* pTabStops = aSeq.getArray(); + for( sal_uInt16 i=0; i < nCount; i++ ) + { + SvxXMLTabStopContext_Impl *pTabStopContext = (*mpTabStops)[i]; + const style::TabStop& rTabStop = pTabStopContext->getTabStop(); + sal_Bool bDflt = style::TabAlign_DEFAULT == rTabStop.Alignment; + if( !bDflt || 0==i ) + { + *pTabStops++ = pTabStopContext->getTabStop(); + nNewCount++; + } + if( bDflt && 0==i ) + break; + } + + if( nCount != nNewCount ) + aSeq.realloc( nNewCount ); + } + aProp.maValue <<= aSeq; + + SetInsert( sal_True ); + XMLElementPropertyContext::EndElement(); + +} + + + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |