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
|
|
|
|
2017-10-23 22:27:32 +02:00
|
|
|
#include "weighhdl.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:45:49 +00:00
|
|
|
#include <xmloff/xmltoken.hxx>
|
2009-10-18 15:05:21 +02:00
|
|
|
#include <tools/fontenum.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
#include <rtl/ustrbuf.hxx>
|
2006-06-19 17:35:18 +00:00
|
|
|
#include <rtl/ustring.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
#include <com/sun/star/uno/Any.hxx>
|
2009-10-19 17:30:34 +02:00
|
|
|
#include <com/sun/star/awt/FontWeight.hpp>
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
using namespace ::com::sun::star::uno;
|
2001-06-29 20:07:26 +00:00
|
|
|
using namespace ::xmloff::token;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
struct FontWeightMapper
|
|
|
|
{
|
2009-10-19 17:30:34 +02:00
|
|
|
float fWeight;
|
2010-11-10 13:50:33 +08:00
|
|
|
sal_uInt16 nValue;
|
2000-09-18 16:07:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
FontWeightMapper const aFontWeightMap[] =
|
|
|
|
{
|
2015-11-26 08:43:00 +02:00
|
|
|
{ css::awt::FontWeight::DONTKNOW, 0 },
|
|
|
|
{ css::awt::FontWeight::THIN, 100 },
|
|
|
|
{ css::awt::FontWeight::ULTRALIGHT, 150 },
|
|
|
|
{ css::awt::FontWeight::LIGHT, 250 },
|
|
|
|
{ css::awt::FontWeight::SEMILIGHT, 350 },
|
|
|
|
{ css::awt::FontWeight::NORMAL, 400 },
|
|
|
|
{ css::awt::FontWeight::NORMAL, 450 },
|
|
|
|
{ css::awt::FontWeight::SEMIBOLD, 600 },
|
|
|
|
{ css::awt::FontWeight::BOLD, 700 },
|
|
|
|
{ css::awt::FontWeight::ULTRABOLD, 800 },
|
|
|
|
{ css::awt::FontWeight::BLACK, 900 },
|
|
|
|
{ css::awt::FontWeight::DONTKNOW, 1000 }
|
2000-09-18 16:07:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// class XMLFmtBreakBeforePropHdl
|
|
|
|
|
|
|
|
XMLFontWeightPropHdl::~XMLFontWeightPropHdl()
|
|
|
|
{
|
|
|
|
// Nothing to do
|
|
|
|
}
|
|
|
|
|
2013-09-16 15:06:48 +02:00
|
|
|
bool XMLFontWeightPropHdl::importXML( const OUString& rStrImpValue, 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
|
|
|
sal_uInt16 nWeight = 0;
|
|
|
|
|
2001-06-29 20:07:26 +00:00
|
|
|
if( IsXMLToken( rStrImpValue, XML_WEIGHT_NORMAL ) )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
nWeight = 400;
|
2013-09-16 15:06:48 +02:00
|
|
|
bRet = true;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2001-06-29 20:07:26 +00:00
|
|
|
else if( IsXMLToken( rStrImpValue, XML_WEIGHT_BOLD ) )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
nWeight = 700;
|
2013-09-16 15:06:48 +02:00
|
|
|
bRet = true;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sal_Int32 nTemp;
|
#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
|
|
|
bRet = ::sax::Converter::convertNumber(nTemp, rStrImpValue, 100, 900);
|
2006-10-12 13:51:57 +00:00
|
|
|
if( bRet )
|
|
|
|
nWeight = sal::static_int_cast< sal_uInt16 >(nTemp);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( bRet )
|
|
|
|
{
|
2013-09-16 15:06:48 +02:00
|
|
|
bRet = false;
|
2017-06-14 09:35:16 +02:00
|
|
|
int const nCount = SAL_N_ELEMENTS(aFontWeightMap);
|
2012-07-27 17:31:03 +02:00
|
|
|
for (int i = 0; i < (nCount-1); ++i)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
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 )
|
2009-10-19 17:30:34 +02:00
|
|
|
rValue <<= aFontWeightMap[i].fWeight;
|
2000-09-18 16:07:07 +00:00
|
|
|
else
|
2009-10-19 17:30:34 +02:00
|
|
|
rValue <<= aFontWeightMap[i+1].fWeight;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2013-09-16 15:06:48 +02:00
|
|
|
bRet = true;
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2013-09-16 15:06:48 +02:00
|
|
|
bool XMLFontWeightPropHdl::exportXML( OUString& rStrExpValue, const 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
|
|
|
|
2006-11-01 15:09:25 +00:00
|
|
|
float fValue = float();
|
2000-09-18 16:07:07 +00:00
|
|
|
if( !( rValue >>= fValue ) )
|
|
|
|
{
|
2006-11-21 16:37:46 +00:00
|
|
|
sal_Int32 nValue = 0;
|
2000-09-18 16:07:07 +00:00
|
|
|
if( rValue >>= nValue )
|
|
|
|
{
|
2018-01-12 20:09:29 +01:00
|
|
|
fValue = static_cast<float>(nValue);
|
2013-09-16 15:06:48 +02:00
|
|
|
bRet = true;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2013-09-16 15:06:48 +02:00
|
|
|
bRet = true;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
if( bRet )
|
|
|
|
{
|
|
|
|
sal_uInt16 nWeight = 0;
|
2017-06-14 09:35:16 +02:00
|
|
|
for( auto const & pair : aFontWeightMap )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2017-06-14 09:35:16 +02:00
|
|
|
if( fValue <= pair.fWeight )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2017-06-14 09:35:16 +02:00
|
|
|
nWeight = pair.nValue;
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( 400 == nWeight )
|
2017-02-01 09:26:27 +02:00
|
|
|
rStrExpValue = GetXMLToken(XML_WEIGHT_NORMAL);
|
2000-09-18 16:07:07 +00:00
|
|
|
else if( 700 == nWeight )
|
2017-02-01 09:26:27 +02:00
|
|
|
rStrExpValue = GetXMLToken(XML_WEIGHT_BOLD);
|
2000-09-18 16:07:07 +00:00
|
|
|
else
|
2017-02-01 09:26:27 +02:00
|
|
|
rStrExpValue = OUString::number( nWeight );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|