Files
libreoffice/sw/source/ui/vba/vbafont.cxx
Michael Meeks caaeb0a046 re-base on ALv2 code. Includes:
Patches contributed by Oliver-Rainer Wittmann
    sw34bf06: #i117783# - Writer's implementation of XPagePrintable -
    apply print settings to new printing routines
    http://svn.apache.org/viewvc?view=revision&revision=1172115
    sw34bf06: #o12311627# use <rtl_random> methods to
    create unique ids for list styles and list ids
    http://svn.apache.org/viewvc?view=revision&revision=1172112
    sw34bf06 #i114725#,#i115828# - method <SwDoc::ClearDoc()> -
    clear list structures completely
    http://svn.apache.org/viewvc?view=revision&revision=1172122
    i#118572 - remove ui string and help content regarding usage of
    Java Mail in Writer's Mail Merge as Java Mail is not used.
    http://svn.apache.org/viewvc?view=revision&revision=1197035

    Patches contributed by Mathias Bauer
    cws mba34issues01: #i117718#: provide filter name in
    case storage of medium does not allow to detect one
    http://svn.apache.org/viewvc?view=revision&revision=1172350
    cws mba34issues01: #i117721#: directly provide
    parameters retrieved from SfxMedium
    http://svn.apache.org/viewvc?view=revision&revision=1172353
    gnumake4 work variously
    http://svn.apache.org/viewvc?view=revision&revision=1394707
    http://svn.apache.org/viewvc?view=revision&revision=1394326
    http://svn.apache.org/viewvc?view=revision&revision=1396797
    http://svn.apache.org/viewvc?view=revision&revision=1397315
    cws mba34issues01: #i117723#: convert assertion into trace
    http://svn.apache.org/viewvc?view=revision&revision=1172355
    cws mba34issues01: #i117699#: keep layout alive until swdoc dies
    http://svn.apache.org/viewvc?view=revision&revision=1172362
    cws mba34issues01: #i117943#: missing color attributes in RTF clipboard
    http://svn.apache.org/viewvc?view=revision&revision=1172363

    Patch contributed by Henning Brinkmann
    imported patch i#103878
    http://svn.apache.org/viewvc?view=revision&revision=1172109

    Patches contributed by Michael Stahl
    sw34bf06: #i117955#: WW8 export: disable storing of section breaks in endnotes
    http://svn.apache.org/viewvc?view=revision&revision=1172119

    Patch contributed by imacat
    Fixed the Asian language work count.
    http://svn.apache.org/viewvc?view=revision&revision=1241345

    Patch contributed by Pedro Giffuni
    i#20878 - Add comment with BZ issue for reference.
    http://svn.apache.org/viewvc?view=revision&revision=1244517

    Patch contributed by Andre Fischer
    Do not add targets for junit tests when junit is disabled.
    http://svn.apache.org/viewvc?view=revision&revision=1241508

add writerperfect dependency.
2012-11-30 10:10:38 +00:00

237 lines
7.9 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* 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 .
*/
#include "vbafont.hxx"
#include <com/sun/star/awt/FontUnderline.hpp>
#include <ooo/vba/word/WdUnderline.hpp>
#include <boost/unordered_map.hpp>
#include <sal/macros.h>
#include <ooo/vba/word/WdColorIndex.hpp>
using namespace ::ooo::vba;
using namespace ::com::sun::star;
const uno::Any aLongAnyTrue( sal_Int16(-1) );
const uno::Any aLongAnyFalse( sal_Int16( 0 ) );
struct MapPair
{
sal_Int32 nMSOConst;
sal_Int32 nOOOConst;
};
static MapPair UnderLineTable[] = {
{ word::WdUnderline::wdUnderlineNone, com::sun::star::awt::FontUnderline::NONE },
{ word::WdUnderline::wdUnderlineSingle, com::sun::star::awt::FontUnderline::SINGLE },
{ word::WdUnderline::wdUnderlineWords, com::sun::star::awt::FontUnderline::SINGLE },
{ word::WdUnderline::wdUnderlineDouble, com::sun::star::awt::FontUnderline::DOUBLE },
{ word::WdUnderline::wdUnderlineDotted, com::sun::star::awt::FontUnderline::DOTTED },
{ word::WdUnderline::wdUnderlineThick, com::sun::star::awt::FontUnderline::BOLDDASH },
{ word::WdUnderline::wdUnderlineDash, com::sun::star::awt::FontUnderline::DASH },
{ word::WdUnderline::wdUnderlineDotDash, com::sun::star::awt::FontUnderline::DASHDOT },
{ word::WdUnderline::wdUnderlineDotDotDash, com::sun::star::awt::FontUnderline::DASHDOTDOT },
{ word::WdUnderline::wdUnderlineWavy, com::sun::star::awt::FontUnderline::WAVE },
{ word::WdUnderline::wdUnderlineDottedHeavy, com::sun::star::awt::FontUnderline::BOLDDOTTED },
{ word::WdUnderline::wdUnderlineDashHeavy, com::sun::star::awt::FontUnderline::BOLDDASH },
{ word::WdUnderline::wdUnderlineDotDashHeavy, com::sun::star::awt::FontUnderline::BOLDDASHDOT },
{ word::WdUnderline::wdUnderlineDotDotDashHeavy, com::sun::star::awt::FontUnderline::BOLDDASHDOTDOT },
{ word::WdUnderline::wdUnderlineWavyHeavy, com::sun::star::awt::FontUnderline::BOLDWAVE },
{ word::WdUnderline::wdUnderlineDashLong, com::sun::star::awt::FontUnderline::LONGDASH },
{ word::WdUnderline::wdUnderlineWavyDouble, com::sun::star::awt::FontUnderline::DOUBLEWAVE },
{ word::WdUnderline::wdUnderlineDashLongHeavy, com::sun::star::awt::FontUnderline::BOLDLONGDASH },
};
typedef boost::unordered_map< sal_Int32, sal_Int32 > ConstToConst;
class UnderLineMapper
{
ConstToConst MSO2OOO;
ConstToConst OOO2MSO;
private:
UnderLineMapper()
{
sal_Int32 nLen = SAL_N_ELEMENTS( UnderLineTable );
for ( sal_Int32 index=0; index<nLen; ++index )
{
MSO2OOO[ UnderLineTable[ index ].nMSOConst ] = UnderLineTable[ index ].nOOOConst;
OOO2MSO[ UnderLineTable[ index ].nOOOConst ] = UnderLineTable[ index ].nMSOConst;
}
}
public:
static rtl::OUString propName()
{
static rtl::OUString sPropName( RTL_CONSTASCII_USTRINGPARAM("CharUnderline") );
return sPropName;
}
static UnderLineMapper& instance()
{
static UnderLineMapper theMapper;
return theMapper;
}
sal_Int32 getOOOFromMSO( sal_Int32 nMSOConst ) throw( lang::IllegalArgumentException )
{
ConstToConst::iterator it = MSO2OOO.find( nMSOConst );
if ( it == MSO2OOO.end() )
throw lang::IllegalArgumentException();
return it->second;
}
sal_Int32 getMSOFromOOO( sal_Int32 nOOOConst ) throw( lang::IllegalArgumentException )
{
ConstToConst::iterator it = OOO2MSO.find( nOOOConst );
if ( it == OOO2MSO.end() )
throw lang::IllegalArgumentException();
return it->second;
}
};
SwVbaFont::SwVbaFont( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess >& xPalette, uno::Reference< css::beans::XPropertySet > xPropertySet ) throw ( css::uno::RuntimeException ) : SwVbaFont_BASE( xParent, xContext, xPalette, xPropertySet )
{
}
uno::Any SAL_CALL
SwVbaFont::getUnderline() throw (uno::RuntimeException)
{
sal_Int32 nOOVal = 0;
mxFont->getPropertyValue( UnderLineMapper::propName() ) >>= nOOVal;
return uno::makeAny( UnderLineMapper::instance().getMSOFromOOO( nOOVal ) );
}
void SAL_CALL
SwVbaFont::setUnderline( const uno::Any& _underline ) throw (uno::RuntimeException)
{
sal_Int32 nMSOVal = 0;
if ( _underline >>= nMSOVal )
{
sal_Int32 nOOVal = UnderLineMapper::instance().getOOOFromMSO( nMSOVal );
mxFont->setPropertyValue( UnderLineMapper::propName(), uno::makeAny( nOOVal ) );
}
}
rtl::OUString
SwVbaFont::getServiceImplName()
{
return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaFont"));
}
void SAL_CALL
SwVbaFont::setColorIndex( const uno::Any& _colorindex ) throw( uno::RuntimeException )
{
sal_Int32 nIndex = 0;
_colorindex >>= nIndex;
return setColor( OORGBToXLRGB(mxPalette->getByIndex( nIndex )) );
}
uno::Any SAL_CALL
SwVbaFont::getColorIndex() throw ( uno::RuntimeException )
{
sal_Int32 nColor = 0;
XLRGBToOORGB( getColor() ) >>= nColor;
sal_Int32 nElems = mxPalette->getCount();
sal_Int32 nIndex = 0;
for ( sal_Int32 count=0; count<nElems; ++count )
{
sal_Int32 nPaletteColor = 0;
mxPalette->getByIndex( count ) >>= nPaletteColor;
if ( nPaletteColor == nColor )
{
nIndex = count;
break;
}
}
return uno::makeAny( nIndex );
}
uno::Any SAL_CALL
SwVbaFont::getSubscript() throw ( uno::RuntimeException )
{
sal_Bool bRes = sal_False;
SwVbaFont_BASE::getSubscript() >>= bRes;
if ( bRes )
return aLongAnyTrue;
return aLongAnyFalse;
}
uno::Any SAL_CALL
SwVbaFont::getSuperscript() throw ( uno::RuntimeException )
{
sal_Bool bRes = sal_False;
SwVbaFont_BASE::getSuperscript() >>= bRes;
if ( bRes )
return aLongAnyTrue;
return aLongAnyFalse;
}
uno::Any SAL_CALL
SwVbaFont::getBold() throw (uno::RuntimeException)
{
sal_Bool bRes = sal_False;
SwVbaFont_BASE::getBold() >>= bRes;
if ( bRes )
return aLongAnyTrue;
return aLongAnyFalse;
}
uno::Any SAL_CALL
SwVbaFont::getItalic() throw (uno::RuntimeException)
{
sal_Bool bRes = sal_False;
SwVbaFont_BASE::getItalic() >>= bRes;
if ( bRes )
return aLongAnyTrue;
return aLongAnyFalse;
}
uno::Any SAL_CALL
SwVbaFont::getStrikethrough() throw (css::uno::RuntimeException)
{
sal_Bool bRes = sal_False;
SwVbaFont_BASE::getStrikethrough() >>= bRes;
if ( bRes )
return aLongAnyTrue;
return aLongAnyFalse;
}
uno::Any SAL_CALL
SwVbaFont::getShadow() throw (uno::RuntimeException)
{
sal_Bool bRes = sal_False;
SwVbaFont_BASE::getShadow() >>= bRes;
if ( bRes )
return aLongAnyTrue;
return aLongAnyFalse;
}
uno::Sequence< rtl::OUString >
SwVbaFont::getServiceNames()
{
static uno::Sequence< rtl::OUString > aServiceNames;
if ( aServiceNames.getLength() == 0 )
{
aServiceNames.realloc( 1 );
aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Font" ) );
}
return aServiceNames;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */