2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
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
|
|
|
|
|
|
|
#include <fonthdl.hxx>
|
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
|
|
|
|
|
|
|
#include <sax/tools/converter.hxx>
|
|
|
|
|
2007-06-27 14:39:25 +00:00
|
|
|
#include <xmloff/xmltoken.hxx>
|
|
|
|
#include <xmloff/xmluconv.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
#include <rtl/ustrbuf.hxx>
|
|
|
|
#include <com/sun/star/uno/Any.hxx>
|
2009-10-18 15:05:21 +02:00
|
|
|
#include <tools/fontenum.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
2001-06-15 09:37:08 +00:00
|
|
|
using namespace ::xmloff::token;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2012-10-11 17:52:52 +02:00
|
|
|
static const SvXMLEnumMapEntry* lcl_getFontFamilyGenericMapping()
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2010-12-12 09:24:14 +01:00
|
|
|
static SvXMLEnumMapEntry const aFontFamilyGenericMapping[] =
|
2009-04-23 10:42:05 +00:00
|
|
|
{
|
|
|
|
{ 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;
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2010-12-12 09:24:14 +01:00
|
|
|
static SvXMLEnumMapEntry const aFontPitchMapping[] =
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2001-06-15 09:37:08 +00:00
|
|
|
{ XML_FIXED, PITCH_FIXED },
|
|
|
|
{ XML_VARIABLE, PITCH_VARIABLE },
|
|
|
|
{ XML_TOKEN_INVALID, 0 }
|
2000-09-18 16:07:07 +00:00
|
|
|
};
|
2013-08-09 20:04:34 +02:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
// class XMLFontFamilyNamePropHdl
|
|
|
|
|
|
|
|
XMLFontFamilyNamePropHdl::~XMLFontFamilyNamePropHdl()
|
|
|
|
{
|
|
|
|
// Nothing to do
|
|
|
|
}
|
|
|
|
|
2013-09-16 15:06:48 +02:00
|
|
|
bool XMLFontFamilyNamePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2013-09-16 15:06:48 +02:00
|
|
|
bool bRet = false;
|
2012-01-29 21:05:26 +00:00
|
|
|
OUStringBuffer sValue;
|
2000-09-18 16:07:07 +00:00
|
|
|
sal_Int32 nPos = 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
sal_Int32 nFirst = nPos;
|
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
|
|
|
nPos = ::sax::Converter::indexOfComma( rStrImpValue, nPos );
|
2012-07-13 15:15:57 +02:00
|
|
|
sal_Int32 nLast = (-1 == nPos ? rStrImpValue.getLength() - 1 : nPos - 1);
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// skip trailing blanks
|
2013-11-13 12:10:31 +02:00
|
|
|
while( nLast > nFirst && ' ' == rStrImpValue[nLast] )
|
2000-09-18 16:07:07 +00:00
|
|
|
nLast--;
|
|
|
|
|
|
|
|
// skip leading blanks
|
2013-11-13 12:10:31 +02:00
|
|
|
while(nFirst <= nLast && ' ' == rStrImpValue[nFirst])
|
2000-09-18 16:07:07 +00:00
|
|
|
nFirst++;
|
|
|
|
|
|
|
|
// remove quotes
|
2013-10-21 09:53:57 +02:00
|
|
|
sal_Unicode c = nFirst > nLast ? 0 : rStrImpValue[nFirst];
|
2013-11-13 12:10:31 +02:00
|
|
|
if( nFirst < nLast && ('\'' == c || '\"' == c) && rStrImpValue[nLast] == c )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
nFirst++;
|
|
|
|
nLast--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( nFirst <= nLast )
|
|
|
|
{
|
2013-03-09 17:44:52 +01:00
|
|
|
if( !sValue.isEmpty() )
|
2012-01-29 21:05:26 +00:00
|
|
|
sValue.append(';');
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2012-01-29 21:05:26 +00:00
|
|
|
sValue.append(rStrImpValue.copy( nFirst, nLast-nFirst+1));
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( -1 != nPos )
|
|
|
|
nPos++;
|
|
|
|
}
|
|
|
|
while( -1 != nPos );
|
|
|
|
|
2013-03-09 17:44:52 +01:00
|
|
|
if (!sValue.isEmpty())
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2012-01-29 21:05:26 +00:00
|
|
|
rValue <<= sValue.makeStringAndClear();
|
2013-09-16 15:06:48 +02:00
|
|
|
bRet = true;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2013-09-16 15:06:48 +02:00
|
|
|
bool XMLFontFamilyNamePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2013-09-16 15:06:48 +02:00
|
|
|
bool bRet = false;
|
2000-09-18 16:07:07 +00:00
|
|
|
OUString aStrFamilyName;
|
|
|
|
|
|
|
|
if( rValue >>= aStrFamilyName )
|
|
|
|
{
|
2015-01-23 15:40:46 +01:00
|
|
|
OUStringBuffer sValue( aStrFamilyName.getLength() + 2 );
|
2010-07-20 18:01:48 +02:00
|
|
|
sal_Int32 nPos = 0;
|
2000-09-18 16:07:07 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
sal_Int32 nFirst = nPos;
|
2013-11-13 12:10:31 +02:00
|
|
|
nPos = aStrFamilyName.indexOf( ';', nPos );
|
2010-07-20 18:01:48 +02:00
|
|
|
sal_Int32 nLast = (-1 == nPos ? aStrFamilyName.getLength() : nPos);
|
2000-10-12 10:20:43 +00:00
|
|
|
|
|
|
|
// 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--;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// skip trailing blanks
|
2013-11-13 12:10:31 +02:00
|
|
|
while( nLast > nFirst && ' ' == aStrFamilyName[nLast] )
|
2000-09-18 16:07:07 +00:00
|
|
|
nLast--;
|
|
|
|
|
|
|
|
// skip leading blanks
|
2013-11-13 12:10:31 +02:00
|
|
|
while( nFirst <= nLast && ' ' == aStrFamilyName[nFirst] )
|
2000-09-18 16:07:07 +00:00
|
|
|
nFirst++;
|
|
|
|
|
|
|
|
if( nFirst <= nLast )
|
|
|
|
{
|
2013-06-18 19:53:19 +02:00
|
|
|
if( !sValue.isEmpty() )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2013-11-13 12:10:31 +02:00
|
|
|
sValue.append( ',' );
|
|
|
|
sValue.append( ' ' );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2010-07-20 18:01:48 +02:00
|
|
|
sal_Int32 nLen = nLast-nFirst+1;
|
2000-09-18 16:07:07 +00:00
|
|
|
OUString sFamily( aStrFamilyName.copy( nFirst, nLen ) );
|
2013-09-16 15:06:48 +02:00
|
|
|
bool bQuote = false;
|
2000-09-18 16:07:07 +00:00
|
|
|
for( sal_Int32 i=0; i < nLen; i++ )
|
|
|
|
{
|
|
|
|
sal_Unicode c = sFamily[i];
|
2013-11-13 12:10:31 +02:00
|
|
|
if( ' ' == c || ',' == c )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2013-09-16 15:06:48 +02:00
|
|
|
bQuote = true;
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( bQuote )
|
2013-11-13 12:10:31 +02:00
|
|
|
sValue.append( '\'' );
|
2000-09-18 16:07:07 +00:00
|
|
|
sValue.append( sFamily );
|
|
|
|
if( bQuote )
|
2013-11-13 12:10:31 +02:00
|
|
|
sValue.append( '\'' );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
while( -1L != nPos );
|
|
|
|
|
|
|
|
rStrExpValue = sValue.makeStringAndClear();
|
|
|
|
|
2013-09-16 15:06:48 +02:00
|
|
|
bRet = true;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
// class XMLFontFamilyPropHdl
|
|
|
|
|
|
|
|
XMLFontFamilyPropHdl::~XMLFontFamilyPropHdl()
|
|
|
|
{
|
|
|
|
// Nothing to do
|
|
|
|
}
|
|
|
|
|
2013-09-16 15:06:48 +02:00
|
|
|
bool XMLFontFamilyPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
sal_uInt16 eNewFamily;
|
2013-09-16 15:06:48 +02:00
|
|
|
bool bRet = SvXMLUnitConverter::convertEnum( eNewFamily, rStrImpValue, lcl_getFontFamilyGenericMapping() );
|
2006-10-12 13:49:30 +00:00
|
|
|
if( bRet )
|
2000-11-13 07:44:24 +00:00
|
|
|
rValue <<= (sal_Int16)eNewFamily;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2013-09-16 15:06:48 +02:00
|
|
|
bool XMLFontFamilyPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2013-09-16 15:06:48 +02:00
|
|
|
bool bRet = false;
|
2000-09-18 16:07:07 +00:00
|
|
|
OUStringBuffer aOut;
|
|
|
|
|
2006-08-29 10:01:36 +00:00
|
|
|
sal_Int16 nFamily = sal_Int16();
|
2000-09-18 16:07:07 +00:00
|
|
|
if( rValue >>= nFamily )
|
|
|
|
{
|
|
|
|
FontFamily eFamily = (FontFamily)nFamily;
|
|
|
|
if( eFamily != FAMILY_DONTKNOW )
|
2009-04-23 10:42:05 +00:00
|
|
|
bRet = SvXMLUnitConverter::convertEnum( aOut, eFamily, lcl_getFontFamilyGenericMapping() );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rStrExpValue = aOut.makeStringAndClear();
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
// class XMLFontEncodingPropHdl
|
|
|
|
|
|
|
|
XMLFontEncodingPropHdl::~XMLFontEncodingPropHdl()
|
|
|
|
{
|
|
|
|
// Nothing to do
|
|
|
|
}
|
|
|
|
|
2013-09-16 15:06:48 +02:00
|
|
|
bool XMLFontEncodingPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2013-09-16 15:06:48 +02:00
|
|
|
bool bRet = true;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2001-06-29 20:07:26 +00:00
|
|
|
if( IsXMLToken( rStrImpValue, XML_X_SYMBOL ) )
|
2000-09-18 16:07:07 +00:00
|
|
|
rValue <<= (sal_Int16) RTL_TEXTENCODING_SYMBOL;
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2013-09-16 15:06:48 +02:00
|
|
|
bool XMLFontEncodingPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2013-09-16 15:06:48 +02:00
|
|
|
bool bRet = false;
|
2000-09-18 16:07:07 +00:00
|
|
|
OUStringBuffer aOut;
|
2006-08-29 10:01:36 +00:00
|
|
|
sal_Int16 nSet = sal_Int16();
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
if( rValue >>= nSet )
|
|
|
|
{
|
|
|
|
if( (rtl_TextEncoding)nSet == RTL_TEXTENCODING_SYMBOL )
|
|
|
|
{
|
2001-06-29 20:07:26 +00:00
|
|
|
aOut.append( GetXMLToken(XML_X_SYMBOL) );
|
2000-09-18 16:07:07 +00:00
|
|
|
rStrExpValue = aOut.makeStringAndClear();
|
2013-09-16 15:06:48 +02:00
|
|
|
bRet = true;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
// class XMLFontPitchPropHdl
|
|
|
|
|
|
|
|
XMLFontPitchPropHdl::~XMLFontPitchPropHdl()
|
|
|
|
{
|
|
|
|
// Nothing to do
|
|
|
|
}
|
|
|
|
|
2013-09-16 15:06:48 +02:00
|
|
|
bool XMLFontPitchPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2010-11-10 13:50:33 +08:00
|
|
|
sal_uInt16 eNewPitch;
|
2013-09-16 15:06:48 +02:00
|
|
|
bool bRet = SvXMLUnitConverter::convertEnum( eNewPitch, rStrImpValue, aFontPitchMapping );
|
2006-10-12 13:49:30 +00:00
|
|
|
if( bRet )
|
2000-09-18 16:07:07 +00:00
|
|
|
rValue <<= (sal_Int16)eNewPitch;
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2013-09-16 15:06:48 +02:00
|
|
|
bool XMLFontPitchPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2013-09-16 15:06:48 +02:00
|
|
|
bool bRet = false;
|
2006-08-29 10:01:36 +00:00
|
|
|
sal_Int16 nPitch = sal_Int16();
|
2000-09-18 16:07:07 +00:00
|
|
|
OUStringBuffer aOut;
|
|
|
|
|
2004-09-08 14:00:02 +00:00
|
|
|
FontPitch ePitch = PITCH_DONTKNOW;
|
2000-09-18 16:07:07 +00:00
|
|
|
if( rValue >>= nPitch )
|
|
|
|
ePitch = (FontPitch)nPitch;
|
|
|
|
|
|
|
|
if( PITCH_DONTKNOW != ePitch )
|
|
|
|
{
|
2006-10-12 13:49:30 +00:00
|
|
|
bRet = SvXMLUnitConverter::convertEnum( aOut, ePitch, aFontPitchMapping, XML_FIXED );
|
2000-09-18 16:07:07 +00:00
|
|
|
rStrExpValue = aOut.makeStringAndClear();
|
|
|
|
}
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
2010-10-12 15:53:47 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|