Files
libreoffice/xmloff/source/style/xmlnume.cxx

827 lines
30 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patches contributed by: Armin Le Grand. #118558# Correcting OLE attributes of LO3.4 at load time by loading as OOo3.3, details see task. http://svn.apache.org/viewvc?view=revision&revision=1195906 #118485# - Styles for OLEs are not saved. http://svn.apache.org/viewvc?view=revision&revision=1182166 #118898# Adapted ImpGraphic::ImplGetBitmap to correctly convert metafiles http://svn.apache.org/viewvc?view=revision&revision=1293316 #119337# Solves the wrong get/setPropertyValue calls in SvxShapeText (and thus in SvxOle2Shape) http://svn.apache.org/viewvc?view=revision&revision=1344156 Patches contributed by Mathias Bauer (and others) gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 cws mba34issues01: #i117717#: remove wrong assertion http://svn.apache.org/viewvc?view=revision&revision=1172349 Patch contributed by Herbert Duerr goodbye Registration and License dialogs, don't let the door hit you http://svn.apache.org/viewvc?view=revision&revision=1172613 help gcc 4.6.0 on 32bit ubuntu 11.10" http://svn.apache.org/viewvc?view=revision&revision=1245357 Do not add targets for junit tests when junit is disabled. Patch contributed by Andre Fischer http://svn.apache.org/viewvc?view=revision&revision=1241508 Revert "sb140: #i117082# avoid unncessary static class data members commit 21d97438e2944861e26e4984195f959a0cce1e41. remove obsolete FreeBSD visibility special case. retain consolidated BSD bridge code, remove OS/2 pieces.
2012-11-12 17:21:24 +00:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2000-09-18 16:07:07 +00:00
2000-09-18 16:07:07 +00:00
#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>
2000-09-18 16:07:07 +00:00
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
New o3tl::try/doGet to obtain value from Any ...in an attempt to reduce usage of type-unsafe void const * css::uno::Any::getValue() These new functions are often more convenient to use than the existing ">>=" and Any::get<T>. Note how they are careful to provide a pointer directly into the given Any, instead of creating temporaries. As an example, replaced most calls of getValue across xmloff: * Cases that first check for a specific type (via getValueType etc.) and then call getValue can instead call tryGet. (But beware that tryGet supports some conversions, which a check for a specific type may have missed---either intentionally or by accident. Also beware the somewhat common idiom of checking for TypeClass_ENUM and then using getValue to obtain a sal_Int32; this cannot be replaced with a call to tryGet.) * Cases that seem confident that the Any is of the correct type when calling getValue (but apparently are confident due to some higher-layer protocol, as the surrounding code does not do any checking via getValueType or similar) can instead call doGet. It throws an exception if it turns out the confidence wasn't warranted. (Many of the existing calls that directly dereferenced the return value of getValue as sal_Bool look suspicious, in that the author might have thought the given code would also cover a VOID Any---which technically it even would have happened to do. If any RuntimeExceptions thrown from these doGet calls start to crop up, these changes need to be revisited. Some may even be rewritten as uses of ">>=". But at least "make check" did not show any such problems. Also note that casting the value obtained from getValue to any css::uno::Reference<X> with X being anything but the base css::uno::XInterface was always prone to producing a bad pointer, in case the interface actually stored in the Any derived from X via multiple inheritance.) * Should there ever be cases where an Any is known to be of the requested type, some additional forceGet could be introduced (which would assert instead of throwing an exception). Change-Id: I2d8739e86314eff73abfcafe01d806f5bc5c34db
2016-06-02 15:06:06 +02:00
#include <o3tl/any.hxx>
#include <rtl/ustrbuf.hxx>
#include <sax/tools/converter.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>
2000-09-18 16:07:07 +00:00
2000-09-18 16:07:07 +00:00
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;
2000-09-18 16:07:07 +00:00
void SvxXMLNumRuleExport::exportLevelStyles( const uno::Reference< css::container::XIndexReplace > & xNumRule,
bool bOutline )
2000-09-18 16:07:07 +00:00
{
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,
2000-09-18 16:07:07 +00:00
const uno::Sequence<beans::PropertyValue>& rProps,
bool bOutline )
2000-09-18 16:07:07 +00:00
{
sal_Int16 eType = NumberingType::CHAR_SPECIAL;
sal_Int16 eAdjust = HoriOrientation::LEFT;
OUString sPrefix, sSuffix;
OUString sTextStyleName;
bool bHasColor = false;
sal_Int32 nColor = 0;
2000-09-18 16:07:07 +00:00
sal_Int32 nSpaceBefore = 0, nMinLabelWidth = 0, nMinLabelDist = 0;
2000-12-01 17:59:51 +00:00
sal_Int16 nStartValue = 1, nDisplayLevels = 1, nBullRelSize = 0;
2000-09-18 16:07:07 +00:00
sal_Unicode cBullet = 0xf095;
OUString sBulletFontName, sBulletFontStyleName ;
FontFamily eBulletFontFamily = FAMILY_DONTKNOW;
FontPitch eBulletFontPitch = PITCH_DONTKNOW;
2000-09-18 16:07:07 +00:00
rtl_TextEncoding eBulletFontEncoding = RTL_TEXTENCODING_DONTKNOW;
OUString sImageURL;
uno::Reference< css::awt::XBitmap > xBitmap;
2000-09-18 16:07:07 +00:00
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();
2000-09-18 16:07:07 +00:00
const beans::PropertyValue* pPropArray = rProps.getConstArray();
for( sal_Int32 i=0; i<nCount; i++ )
{
const beans::PropertyValue& rProp = pPropArray[i];
if( rProp.Name == "NumberingType" )
2000-09-18 16:07:07 +00:00
{
2001-03-19 08:41:43 +00:00
rProp.Value >>= eType;
2000-09-18 16:07:07 +00:00
}
else if( rProp.Name == "Prefix" )
2000-09-18 16:07:07 +00:00
{
rProp.Value >>= sPrefix;
}
else if( rProp.Name == "Suffix" )
2000-09-18 16:07:07 +00:00
{
rProp.Value >>= sSuffix;
}
else if( rProp.Name == "BulletChar" )
2000-09-18 16:07:07 +00:00
{
OUString sValue;
rProp.Value >>= sValue;
if( !sValue.isEmpty() )
2000-12-06 09:06:42 +00:00
{
cBullet = sValue[0];
2000-12-06 09:06:42 +00:00
}
2000-09-18 16:07:07 +00:00
}
else if( rProp.Name == "BulletRelSize" )
2000-12-01 17:59:51 +00:00
{
rProp.Value >>= nBullRelSize;
}
else if( rProp.Name == "Adjust" )
2000-09-18 16:07:07 +00:00
{
sal_Int16 nValue = 0;
2000-09-18 16:07:07 +00:00
rProp.Value >>= nValue;
eAdjust = nValue;
}
else if( rProp.Name == "BulletFont" )
2000-09-18 16:07:07 +00:00
{
awt::FontDescriptor rFDesc;
if( rProp.Value >>= rFDesc )
{
sBulletFontName = rFDesc.Name;
sBulletFontStyleName = rFDesc.StyleName;
eBulletFontFamily = static_cast< FontFamily >( rFDesc.Family );
eBulletFontPitch = static_cast< FontPitch >( rFDesc.Pitch );
2000-09-18 16:07:07 +00:00
eBulletFontEncoding = (rtl_TextEncoding)rFDesc.CharSet;
}
}
else if( rProp.Name == "GraphicURL" )
2000-09-18 16:07:07 +00:00
{
rProp.Value >>= sImageURL;
}
else if( rProp.Name == "GraphicBitmap" )
2000-09-18 16:07:07 +00:00
{
rProp.Value >>= xBitmap;
}
else if( rProp.Name == "BulletColor" )
{
rProp.Value >>= nColor;
bHasColor = true;
}
else if( rProp.Name == "StartWith" )
2000-09-18 16:07:07 +00:00
{
rProp.Value >>= nStartValue;
}
else if( rProp.Name == "LeftMargin" )
2000-09-18 16:07:07 +00:00
{
rProp.Value >>= nSpaceBefore;
}
else if( rProp.Name == "FirstLineOffset" )
2000-09-18 16:07:07 +00:00
{
rProp.Value >>= nMinLabelWidth;
}
else if( rProp.Name == "SymbolTextDistance" )
2000-09-18 16:07:07 +00:00
{
rProp.Value >>= nMinLabelDist;
}
else if( rProp.Name == "ParentNumbering" )
2000-09-18 16:07:07 +00:00
{
rProp.Value >>= nDisplayLevels;
if( nDisplayLevels > nLevel+1 )
nDisplayLevels = static_cast<sal_Int16>( nLevel )+1;
2000-09-18 16:07:07 +00:00
}
else if( rProp.Name == "CharStyleName" )
2000-09-18 16:07:07 +00:00
{
rProp.Value >>= sTextStyleName;
}
else if( rProp.Name == "GraphicSize" )
2000-09-18 16:07:07 +00:00
{
awt::Size aSize;
if( rProp.Value >>= aSize )
{
nImageWidth = aSize.Width;
nImageHeight = aSize.Height;
}
}
else if( rProp.Name == "VertOrient" )
2000-09-18 16:07:07 +00:00
{
sal_Int16 nValue = 0;
2000-09-18 16:07:07 +00:00
rProp.Value >>= nValue;
eImageVertOrient = nValue;
}
else if( rProp.Name == "PositionAndSpaceMode" )
{
sal_Int16 nValue = 0;
rProp.Value >>= nValue;
ePosAndSpaceMode = nValue;
}
else if( rProp.Name == "LabelFollowedBy" )
{
sal_Int16 nValue = 0;
rProp.Value >>= nValue;
eLabelFollowedBy = nValue;
}
else if( rProp.Name == "ListtabStopPosition" )
{
rProp.Value >>= nListtabStopPosition;
}
else if( rProp.Name == "FirstLineIndent" )
{
rProp.Value >>= nFirstLineIndent;
}
else if( rProp.Name == "IndentAt" )
{
rProp.Value >>= nIndentAt;
}
2000-09-18 16:07:07 +00:00
}
if( bOutline && (NumberingType::CHAR_SPECIAL == eType ||
NumberingType::BITMAP == eType) )
{
SAL_WARN_IF( bOutline, "xmloff",
2000-09-18 16:07:07 +00:00
"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.isEmpty())
{
GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
GetExport().EncodeStyleName( sTextStyleName ) );
}
if (!sPrefix.isEmpty())
{
GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NUM_PREFIX,
sPrefix );
}
if (!sSuffix.isEmpty())
{
GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NUM_SUFFIX,
sSuffix );
}
}
2000-09-18 16:07:07 +00:00
enum XMLTokenEnum eElem = XML_LIST_LEVEL_STYLE_NUMBER;
2000-09-18 16:07:07 +00:00
if( NumberingType::CHAR_SPECIAL == eType )
{
// <text:list-level-style-bullet>
eElem = XML_LIST_LEVEL_STYLE_BULLET;
2000-09-18 16:07:07 +00:00
2001-06-29 11:34:19 +00:00
if( cBullet )
{
2001-10-17 12:26:13 +00:00
if( cBullet < ' ' )
{
cBullet = 0xF000 + 149;
}
2001-06-29 11:34:19 +00:00
// text:bullet-char="..."
sTmp.append( cBullet );
GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_BULLET_CHAR,
2001-06-29 11:34:19 +00:00
sTmp.makeStringAndClear() );
}
else
{
// If 'cBullet' is zero, XML_BULLET_CHAR must exist with blank.
GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_BULLET_CHAR, "");
}
2000-09-18 16:07:07 +00:00
}
else if( NumberingType::BITMAP == eType )
{
// <text:list-level-style-image>
eElem = XML_LIST_LEVEL_STYLE_IMAGE;
2000-09-18 16:07:07 +00:00
if( !sImageURL.isEmpty() )
2000-09-18 16:07:07 +00:00
{
2001-06-19 14:08:23 +00:00
OUString sURL( GetExport().AddEmbeddedGraphicObject( sImageURL ) );
if( !sURL.isEmpty() )
2001-06-19 14:08:23 +00:00
{
GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sURL );
2000-09-18 16:07:07 +00:00
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 );
2001-06-19 14:08:23 +00:00
}
2000-09-18 16:07:07 +00:00
}
else
{
SAL_WARN_IF( xBitmap.is(), "xmloff",
2000-09-18 16:07:07 +00:00
"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;
2000-09-18 16:07:07 +00:00
else
eElem = XML_LIST_LEVEL_STYLE_NUMBER;
2000-09-18 16:07:07 +00:00
2001-03-19 08:41:43 +00:00
GetExport().GetMM100UnitConverter().convertNumFormat( sTmp, eType );
GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
2001-03-19 08:41:43 +00:00
sTmp.makeStringAndClear() );
SvXMLUnitConverter::convertNumLetterSync( sTmp, eType );
if( !sTmp.isEmpty() )
2001-03-19 08:41:43 +00:00
GetExport().AddAttribute( XML_NAMESPACE_STYLE,
XML_NUM_LETTER_SYNC,
2001-03-19 08:41:43 +00:00
sTmp.makeStringAndClear() );
2000-09-18 16:07:07 +00:00
2001-08-21 15:33:20 +00:00
if( nStartValue != 1 )
2000-09-18 16:07:07 +00:00
{
sTmp.append( (sal_Int32)nStartValue );
GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_START_VALUE,
2000-09-18 16:07:07 +00:00
sTmp.makeStringAndClear() );
}
if( nDisplayLevels > 1 && NumberingType::NUMBER_NONE != eType )
{
sTmp.append( (sal_Int32)nDisplayLevels );
GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_DISPLAY_LEVELS,
2000-09-18 16:07:07 +00:00
sTmp.makeStringAndClear() );
}
}
{
SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, eElem,
true, true );
2000-09-18 16:07:07 +00:00
OUStringBuffer sBuffer;
if ( ePosAndSpaceMode == PositionAndSpaceMode::LABEL_WIDTH_AND_POSITION )
2000-09-18 16:07:07 +00:00
{
nSpaceBefore += nMinLabelWidth;
nMinLabelWidth = -nMinLabelWidth;
if( nSpaceBefore != 0 )
{
GetExport().GetMM100UnitConverter().convertMeasureToXML(
sBuffer, nSpaceBefore );
GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_SPACE_BEFORE,
sBuffer.makeStringAndClear() );
}
if( nMinLabelWidth != 0 )
{
GetExport().GetMM100UnitConverter().convertMeasureToXML(
sBuffer, nMinLabelWidth );
GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_MIN_LABEL_WIDTH,
sBuffer.makeStringAndClear() );
}
if( nMinLabelDist > 0 )
{
GetExport().GetMM100UnitConverter().convertMeasureToXML(
sBuffer, nMinLabelDist );
GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_MIN_LABEL_DISTANCE,
sBuffer.makeStringAndClear() );
}
2000-09-18 16:07:07 +00:00
}
/* Check, if properties for position-and-space-mode LABEL_ALIGNMENT
are allowed to be exported. (#i89178#)
*/
else if ( ePosAndSpaceMode == PositionAndSpaceMode::LABEL_ALIGNMENT &&
mbExportPositionAndSpaceModeLabelAlignment )
2000-09-18 16:07:07 +00:00
{
GetExport().AddAttribute( XML_NAMESPACE_TEXT,
XML_LIST_LEVEL_POSITION_AND_SPACE_MODE,
XML_LABEL_ALIGNMENT );
2000-09-18 16:07:07 +00:00
}
if( HoriOrientation::LEFT != eAdjust )
{
enum XMLTokenEnum eValue = XML_TOKEN_INVALID;
2000-09-18 16:07:07 +00:00
switch( eAdjust )
{
case HoriOrientation::RIGHT: eValue = XML_END; break;
case HoriOrientation::CENTER: eValue = XML_CENTER; break;
2000-09-18 16:07:07 +00:00
}
if( eValue != XML_TOKEN_INVALID )
GetExport().AddAttribute( XML_NAMESPACE_FO, XML_TEXT_ALIGN, eValue );
2000-09-18 16:07:07 +00:00
}
if( NumberingType::BITMAP == eType )
2000-09-18 16:07:07 +00:00
{
enum XMLTokenEnum eValue = XML_TOKEN_INVALID;
2000-09-18 16:07:07 +00:00
switch( eImageVertOrient )
{
case VertOrientation::BOTTOM: // yes, it's OK: BOTTOM means that the baseline
2000-09-18 16:07:07 +00:00
// hits the frame at its topmost position
case VertOrientation::LINE_TOP:
case VertOrientation::CHAR_TOP:
eValue = XML_TOP;
2000-09-18 16:07:07 +00:00
break;
case VertOrientation::CENTER:
case VertOrientation::LINE_CENTER:
case VertOrientation::CHAR_CENTER:
eValue = XML_MIDDLE;
2000-09-18 16:07:07 +00:00
break;
case VertOrientation::TOP: // yes, it's OK: TOP means that the baseline
2000-09-18 16:07:07 +00:00
// hits the frame at its bottommost position
case VertOrientation::LINE_BOTTOM:
case VertOrientation::CHAR_BOTTOM:
eValue = XML_BOTTOM;
2000-09-18 16:07:07 +00:00
break;
}
if( eValue != XML_TOKEN_INVALID )
GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_VERTICAL_POS, eValue );
2000-09-18 16:07:07 +00:00
eValue = XML_TOKEN_INVALID;
2000-09-18 16:07:07 +00:00
switch( eImageVertOrient )
{
case VertOrientation::TOP:
case VertOrientation::CENTER:
case VertOrientation::BOTTOM:
eValue = XML_BASELINE;
2000-09-18 16:07:07 +00:00
break;
case VertOrientation::LINE_TOP:
case VertOrientation::LINE_CENTER:
case VertOrientation::LINE_BOTTOM:
eValue = XML_LINE;
2000-09-18 16:07:07 +00:00
break;
case VertOrientation::CHAR_TOP:
case VertOrientation::CHAR_CENTER:
case VertOrientation::CHAR_BOTTOM:
eValue = XML_CHAR;
2000-09-18 16:07:07 +00:00
break;
}
if( eValue != XML_TOKEN_INVALID )
GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_VERTICAL_REL, eValue );
2000-09-18 16:07:07 +00:00
if( nImageWidth > 0 )
{
GetExport().GetMM100UnitConverter().convertMeasureToXML(
sBuffer, nImageWidth );
GetExport().AddAttribute( XML_NAMESPACE_FO, XML_WIDTH,
2000-09-18 16:07:07 +00:00
sBuffer.makeStringAndClear() );
}
if( nImageHeight > 0 )
{
GetExport().GetMM100UnitConverter().convertMeasureToXML(
sBuffer, nImageHeight );
GetExport().AddAttribute( XML_NAMESPACE_FO, XML_HEIGHT,
2000-09-18 16:07:07 +00:00
sBuffer.makeStringAndClear() );
}
}
{
SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE,
XML_LIST_LEVEL_PROPERTIES, true, 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().convertMeasureToXML(
sBuffer, nListtabStopPosition );
GetExport().AddAttribute( XML_NAMESPACE_TEXT,
XML_LIST_TAB_STOP_POSITION,
sBuffer.makeStringAndClear() );
}
if ( nFirstLineIndent != 0 )
{
GetExport().GetMM100UnitConverter().convertMeasureToXML(
sBuffer, nFirstLineIndent );
GetExport().AddAttribute( XML_NAMESPACE_FO,
XML_TEXT_INDENT,
sBuffer.makeStringAndClear() );
}
if ( nIndentAt != 0 )
{
GetExport().GetMM100UnitConverter().convertMeasureToXML(
sBuffer, nIndentAt );
GetExport().AddAttribute( XML_NAMESPACE_FO,
XML_MARGIN_LEFT,
sBuffer.makeStringAndClear() );
}
SvXMLElementExport aLabelAlignmentElement( GetExport(), XML_NAMESPACE_STYLE,
XML_LIST_LEVEL_LABEL_ALIGNMENT,
true, true );
}
}
if( NumberingType::CHAR_SPECIAL == eType )
{
if( !sBulletFontName.isEmpty() )
{
OUString sStyleName =
GetExport().GetFontAutoStylePool()->Find(
sBulletFontName, sBulletFontStyleName,
eBulletFontFamily, eBulletFontPitch,
eBulletFontEncoding );
if( !sStyleName.isEmpty() )
{
GetExport().AddAttribute( XML_NAMESPACE_STYLE,
XML_FONT_NAME,
sStyleName );
}
else
{
OUString sTemp;
const SvXMLUnitConverter& rUnitConv =
GetExport().GetMM100UnitConverter();
XMLFontFamilyNamePropHdl aFamilyNameHdl;
if( aFamilyNameHdl.exportXML( sTemp, Any(sBulletFontName), rUnitConv ) )
GetExport().AddAttribute( XML_NAMESPACE_FO,
XML_FONT_FAMILY, sTemp );
if( !sBulletFontStyleName.isEmpty() )
GetExport().AddAttribute( XML_NAMESPACE_STYLE,
XML_FONT_STYLE_NAME,
sBulletFontStyleName );
XMLFontFamilyPropHdl aFamilyHdl;
if( aFamilyHdl.exportXML( sTemp, Any((sal_Int16)eBulletFontFamily), rUnitConv ) )
GetExport().AddAttribute( XML_NAMESPACE_STYLE,
XML_FONT_FAMILY_GENERIC,
sTemp );
XMLFontPitchPropHdl aPitchHdl;
if( aPitchHdl.exportXML( sTemp, Any((sal_Int16)eBulletFontPitch), rUnitConv ) )
GetExport().AddAttribute( XML_NAMESPACE_STYLE,
XML_FONT_PITCH, sTemp );
XMLFontEncodingPropHdl aEncHdl;
if( aEncHdl.exportXML( sTemp, Any((sal_Int16)eBulletFontEncoding), rUnitConv ) )
GetExport().AddAttribute( XML_NAMESPACE_STYLE,
XML_FONT_CHARSET, sTemp );
}
}
}
if( NumberingType::BITMAP != eType )
{
// fo:color = "#..."
if( bHasColor )
{
if (0xffffffff == static_cast<sal_uInt32>(nColor))
{
GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_USE_WINDOW_FONT_COLOR, XML_TRUE );
}
else
{
::sax::Converter::convertColor( sBuffer, nColor );
GetExport().AddAttribute( XML_NAMESPACE_FO, XML_COLOR,
sBuffer.makeStringAndClear() );
}
}
// fo:height="...%"
if( nBullRelSize )
{
::sax::Converter::convertPercent( sTmp, nBullRelSize );
GetExport().AddAttribute( XML_NAMESPACE_FO, XML_FONT_SIZE,
sTmp.makeStringAndClear() );
}
}
2000-09-18 16:07:07 +00:00
if( GetExport().GetAttrList().getLength() > 0 )
{
SvXMLElementExport aElement( GetExport(), XML_NAMESPACE_STYLE,
XML_TEXT_PROPERTIES, true, true );
2000-09-18 16:07:07 +00:00
}
if( NumberingType::BITMAP == eType && !sImageURL.isEmpty() )
2001-06-19 14:08:23 +00:00
{
// optional office:binary-data
GetExport().AddEmbeddedGraphicObjectAsBase64( sImageURL );
}
2000-09-18 16:07:07 +00:00
}
}
SvxXMLNumRuleExport::SvxXMLNumRuleExport( SvXMLExport& rExp ) :
rExport( rExp ),
sNumberingRules( "NumberingRules" ),
sIsPhysical( "IsPhysical" ),
sIsContinuousNumbering( "IsContinuousNumbering" ),
// Let list style creation depend on Load/Save option "ODF format version" (#i89178#)
mbExportPositionAndSpaceModeLabelAlignment( true )
2000-09-18 16:07:07 +00:00
{
switch ( GetExport().getDefaultVersion() )
{
case SvtSaveOptions::ODFVER_010:
case SvtSaveOptions::ODFVER_011:
{
mbExportPositionAndSpaceModeLabelAlignment = false;
}
break;
default: // ODFVER_UNKNOWN or ODFVER_012
{
mbExportPositionAndSpaceModeLabelAlignment = true;
}
}
2000-09-18 16:07:07 +00:00
}
SvxXMLNumRuleExport::~SvxXMLNumRuleExport()
2000-09-18 16:07:07 +00:00
{
}
void SvxXMLNumRuleExport::exportNumberingRule(
const OUString& rName, bool bIsHidden,
2000-09-18 16:07:07 +00:00
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.isEmpty() )
{
bool bEncoded = false;
GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME,
GetExport().EncodeStyleName( rName, &bEncoded ) );
if( bEncoded )
GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME,
rName);
}
2000-09-18 16:07:07 +00:00
// style:hidden="..."
if ( bIsHidden && GetExport( ).getDefaultVersion( ) == SvtSaveOptions::ODFVER_LATEST )
GetExport( ).AddAttribute( XML_NAMESPACE_STYLE, XML_HIDDEN, "true" );
2000-09-18 16:07:07 +00:00
// text:consecutive-numbering="..."
bool bContNumbering = false;
2000-09-18 16:07:07 +00:00
if( xPropSetInfo.is() &&
xPropSetInfo->hasPropertyByName( sIsContinuousNumbering ) )
{
Any aAny( xPropSet->getPropertyValue( sIsContinuousNumbering ) );
bContNumbering = *o3tl::doAccess<bool>(aAny);
2000-09-18 16:07:07 +00:00
}
if( bContNumbering )
GetExport().AddAttribute( XML_NAMESPACE_TEXT,
XML_CONSECUTIVE_NUMBERING, XML_TRUE );
2000-09-18 16:07:07 +00:00
{
SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, XML_LIST_STYLE ,
true, true );
2000-09-18 16:07:07 +00:00
exportLevelStyles( rNumRule );
}
}
void SvxXMLNumRuleExport::exportStyle( const Reference< XStyle >& rStyle )
2000-09-18 16:07:07 +00:00
{
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( !*o3tl::doAccess<bool>(aAny) )
return;
2000-09-18 16:07:07 +00:00
}
aAny = xPropSet->getPropertyValue( sNumberingRules );
Reference<XIndexReplace> xNumRule;
aAny >>= xNumRule;
OUString sName = rStyle->getName();
bool bHidden = false;
if ( xPropSetInfo->hasPropertyByName( "Hidden" ) )
{
aAny = xPropSet->getPropertyValue( "Hidden" );
aAny >>= bHidden;
}
exportNumberingRule( sName, bHidden, xNumRule );
2000-09-18 16:07:07 +00:00
}
void SvxXMLNumRuleExport::exportOutline()
{
Reference< XChapterNumberingSupplier > xCNSupplier( GetExport().GetModel(),
UNO_QUERY );
SAL_WARN_IF( !xCNSupplier.is(), "xmloff", "no chapter numbering supplier" );
2000-09-18 16:07:07 +00:00
if( xCNSupplier.is() )
{
Reference< XIndexReplace > xNumRule( xCNSupplier->getChapterNumberingRules() );
SAL_WARN_IF( !xNumRule.is(), "xmloff", "no chapter numbering rules" );
2000-09-18 16:07:07 +00:00
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( "Name" );
xNumRulePropSet->getPropertyValue( sName ) >>= sOutlineStyleName;
}
}
const SvtSaveOptions::ODFDefaultVersion nODFVersion =
GetExport().getDefaultVersion();
if ( ( nODFVersion == SvtSaveOptions::ODFVER_010 ||
nODFVersion == SvtSaveOptions::ODFVER_011 ) &&
GetExport().writeOutlineStyleAsNormalListStyle() )
{
exportNumberingRule( sOutlineStyleName, false, xNumRule );
}
else
{
if ( nODFVersion != SvtSaveOptions::ODFVER_010 &&
nODFVersion != SvtSaveOptions::ODFVER_011 )
{
// style:name="..."
GetExport().CheckAttrList();
if ( !sOutlineStyleName.isEmpty() )
{
bool bEncoded = 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, true, true );
exportLevelStyles( xNumRule, true );
}
2000-09-18 16:07:07 +00:00
}
}
}
void SvxXMLNumRuleExport::exportStyles( bool bUsed,
XMLTextListAutoStylePool *pPool,
bool bExportChapterNumbering )
2000-09-18 16:07:07 +00:00
{
2001-01-18 10:59:42 +00:00
if( bExportChapterNumbering )
exportOutline();
2000-09-18 16:07:07 +00:00
Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetExport().GetModel(), UNO_QUERY );
SAL_WARN_IF( !xFamiliesSupp.is(), "xmloff", "No XStyleFamiliesSupplier from XModel for export!" );
2000-09-18 16:07:07 +00:00
if( xFamiliesSupp.is() )
{
Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
SAL_WARN_IF( !xFamiliesSupp.is(), "xmloff", "getStyleFamilies() from XModel failed for export!" );
2000-09-18 16:07:07 +00:00
if( xFamilies.is() )
{
const OUString aNumberStyleName( "NumberingStyles" );
2000-09-18 16:07:07 +00:00
Reference< XIndexAccess > xStyles;
if( xFamilies->hasByName( aNumberStyleName ) )
{
xFamilies->getByName( aNumberStyleName ) >>= xStyles;
SAL_WARN_IF( !xStyles.is(), "xmloff", "Style not found for export!" );
2000-09-18 16:07:07 +00:00
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() );
}
}
}
}
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */