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

155 lines
4.4 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
#include "weighhdl.hxx"
#include <sax/tools/converter.hxx>
#include <xmloff/xmltoken.hxx>
#include <tools/fontenum.hxx>
2000-09-18 16:07:07 +00:00
#include <limits.h>
#include <rtl/ustrbuf.hxx>
#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;
using namespace ::xmloff::token;
2000-09-18 16:07:07 +00:00
struct FontWeightMapper
{
2009-10-19 17:30:34 +02:00
float fWeight;
sal_uInt16 nValue;
2000-09-18 16:07:07 +00:00
};
FontWeightMapper const aFontWeightMap[] =
{
{ 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
}
bool XMLFontWeightPropHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
2000-09-18 16:07:07 +00:00
{
bool bRet = false;
2000-09-18 16:07:07 +00:00
sal_uInt16 nWeight = 0;
if( IsXMLToken( rStrImpValue, XML_WEIGHT_NORMAL ) )
2000-09-18 16:07:07 +00:00
{
nWeight = 400;
bRet = true;
2000-09-18 16:07:07 +00:00
}
else if( IsXMLToken( rStrImpValue, XML_WEIGHT_BOLD ) )
2000-09-18 16:07:07 +00:00
{
nWeight = 700;
bRet = true;
2000-09-18 16:07:07 +00:00
}
else
{
sal_Int32 nTemp;
bRet = ::sax::Converter::convertNumber(nTemp, rStrImpValue, 100, 900);
if( bRet )
nWeight = sal::static_int_cast< sal_uInt16 >(nTemp);
2000-09-18 16:07:07 +00:00
}
if( bRet )
{
bRet = false;
int const nCount = SAL_N_ELEMENTS(aFontWeightMap);
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
bRet = true;
2000-09-18 16:07:07 +00:00
break;
}
}
}
return bRet;
}
bool XMLFontWeightPropHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
2000-09-18 16:07:07 +00:00
{
bool bRet = false;
2000-09-18 16:07:07 +00:00
float fValue = float();
2000-09-18 16:07:07 +00:00
if( !( rValue >>= fValue ) )
{
sal_Int32 nValue = 0;
2000-09-18 16:07:07 +00:00
if( rValue >>= nValue )
{
fValue = static_cast<float>(nValue);
bRet = true;
2000-09-18 16:07:07 +00:00
}
}
else
bRet = true;
2000-09-18 16:07:07 +00:00
if( bRet )
{
sal_uInt16 nWeight = 0;
for( auto const & pair : aFontWeightMap )
2000-09-18 16:07:07 +00:00
{
if( fValue <= pair.fWeight )
2000-09-18 16:07:07 +00:00
{
nWeight = pair.nValue;
2000-09-18 16:07:07 +00:00
break;
}
}
if( 400 == nWeight )
rStrExpValue = GetXMLToken(XML_WEIGHT_NORMAL);
2000-09-18 16:07:07 +00:00
else if( 700 == nWeight )
rStrExpValue = GetXMLToken(XML_WEIGHT_BOLD);
2000-09-18 16:07:07 +00:00
else
rStrExpValue = OUString::number( nWeight );
2000-09-18 16:07:07 +00:00
}
return bRet;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */