2010-10-12 15:53:47 +02:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2000-11-14 09:19:45 +00:00
/*************************************************************************
*
2008-04-10 21:29:15 +00:00
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER .
2000-11-14 09:19:45 +00:00
*
2010-02-12 15:01:35 +01:00
* Copyright 2000 , 2010 Oracle and / or its affiliates .
2000-11-14 09:19:45 +00:00
*
2008-04-10 21:29:15 +00:00
* OpenOffice . org - a multi - platform office productivity suite
2000-11-14 09:19:45 +00:00
*
2008-04-10 21:29:15 +00:00
* This file is part of OpenOffice . org .
2000-11-14 09:19:45 +00:00
*
2008-04-10 21:29:15 +00:00
* OpenOffice . org is free software : you can redistribute it and / or modify
* it under the terms of the GNU Lesser General Public License version 3
* only , as published by the Free Software Foundation .
2000-11-14 09:19:45 +00:00
*
2008-04-10 21:29:15 +00:00
* OpenOffice . org is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Lesser General Public License version 3 for more details
* ( a copy is included in the LICENSE file that accompanied this code ) .
2000-11-14 09:19:45 +00:00
*
2008-04-10 21:29:15 +00:00
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice . org . If not , see
* < http : //www.openoffice.org/license.html>
* for a copy of the LGPLv3 License .
2000-11-14 09:19:45 +00:00
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-09-17 09:50:01 +00:00
2000-11-14 09:19:45 +00:00
# include <com/sun/star/awt/FontFamily.hpp>
# include <com/sun/star/awt/FontPitch.hpp>
2010-04-19 17:29:55 +02:00
# include <rtl/logfile.hxx>
2007-06-27 14:33:03 +00:00
# include <xmloff/nmspmap.hxx>
2010-04-16 23:04:00 +02:00
# include "xmloff/xmlnmspe.hxx"
2007-06-27 14:33:03 +00:00
# include <xmloff/xmltoken.hxx>
2000-11-14 09:19:45 +00:00
# include "fonthdl.hxx"
2007-06-27 14:33:03 +00:00
# include <xmloff/xmlimp.hxx>
# include <xmloff/maptype.hxx>
# include <xmloff/XMLFontStylesContext.hxx>
2010-04-19 17:29:55 +02:00
2008-03-12 09:47:19 +00:00
using : : rtl : : OUString ;
using : : rtl : : OUStringBuffer ;
2000-11-14 09:19:45 +00:00
using namespace : : com : : sun : : star ;
using namespace : : com : : sun : : star : : uno ;
using namespace : : com : : sun : : star : : xml : : sax ;
using namespace : : com : : sun : : star : : container ;
using namespace : : com : : sun : : star : : beans ;
using namespace : : com : : sun : : star : : lang ;
using namespace : : com : : sun : : star : : awt ;
2001-06-15 16:16:59 +00:00
using namespace : : xmloff : : token ;
2000-11-14 09:19:45 +00:00
2001-06-29 20:07:26 +00:00
2000-11-14 09:19:45 +00:00
# define XML_STYLE_FAMILY_FONT 1
enum XMLFontStyleAttrTokens
{
XML_TOK_FONT_STYLE_ATTR_FAMILY ,
XML_TOK_FONT_STYLE_ATTR_FAMILY_GENERIC ,
XML_TOK_FONT_STYLE_ATTR_STYLENAME ,
XML_TOK_FONT_STYLE_ATTR_PITCH ,
XML_TOK_FONT_STYLE_ATTR_CHARSET ,
XML_TOK_FONT_STYLE_ATTR_END = XML_TOK_UNKNOWN
} ;
2009-04-23 10:42:05 +00:00
const SvXMLTokenMapEntry * lcl_getFontStyleAttrTokenMap ( )
2000-11-14 09:19:45 +00:00
{
2010-12-06 10:36:18 +00:00
static SvXMLTokenMapEntry aFontStyleAttrTokenMap [ ] =
2009-04-23 10:42:05 +00:00
{
{ XML_NAMESPACE_SVG , XML_FONT_FAMILY ,
XML_TOK_FONT_STYLE_ATTR_FAMILY } ,
{ XML_NAMESPACE_STYLE , XML_FONT_FAMILY_GENERIC ,
XML_TOK_FONT_STYLE_ATTR_FAMILY_GENERIC } ,
{ XML_NAMESPACE_STYLE , XML_FONT_ADORNMENTS ,
XML_TOK_FONT_STYLE_ATTR_STYLENAME } ,
{ XML_NAMESPACE_STYLE , XML_FONT_PITCH ,
XML_TOK_FONT_STYLE_ATTR_PITCH } ,
{ XML_NAMESPACE_STYLE , XML_FONT_CHARSET ,
XML_TOK_FONT_STYLE_ATTR_CHARSET } ,
2000-11-14 09:19:45 +00:00
2009-04-23 10:42:05 +00:00
XML_TOKEN_MAP_END
} ;
return aFontStyleAttrTokenMap ;
}
2000-11-14 09:19:45 +00:00
class XMLFontStyleContext_Impl : public SvXMLStyleContext
{
Any aFamilyName ;
Any aStyleName ;
Any aFamily ;
Any aPitch ;
Any aEnc ;
SvXMLImportContextRef xStyles ;
XMLFontStylesContext * GetStyles ( )
{
return ( ( XMLFontStylesContext * ) & xStyles ) ;
}
public :
TYPEINFO ( ) ;
XMLFontStyleContext_Impl ( SvXMLImport & rImport , sal_uInt16 nPrfx ,
const : : rtl : : OUString & rLName ,
const : : com : : sun : : star : : uno : : Reference <
: : com : : sun : : star : : xml : : sax : : XAttributeList > & xAttrList ,
XMLFontStylesContext & rStyles ) ;
virtual ~ XMLFontStyleContext_Impl ( ) ;
void SetAttribute ( sal_uInt16 nPrefixKey , const OUString & rLocalName ,
const OUString & rValue ) ;
void FillProperties ( : : std : : vector < XMLPropertyState > & rProps ,
sal_Int32 nFamilyNameIdx ,
sal_Int32 nStyleNameIdx ,
sal_Int32 nFamilyIdx ,
sal_Int32 nPitchIdx ,
sal_Int32 nCharsetIdx ) const ;
} ;
TYPEINIT1 ( XMLFontStyleContext_Impl , SvXMLStyleContext ) ;
XMLFontStyleContext_Impl : : XMLFontStyleContext_Impl ( SvXMLImport & rImport ,
sal_uInt16 nPrfx , const OUString & rLName ,
const Reference < XAttributeList > & xAttrList ,
XMLFontStylesContext & rStyles ) :
2001-01-16 15:36:55 +00:00
SvXMLStyleContext ( rImport , nPrfx , rLName , xAttrList , XML_STYLE_FAMILY_FONT ) ,
2000-11-14 09:19:45 +00:00
xStyles ( & rStyles )
{
OUString sEmpty ;
aFamilyName < < = sEmpty ;
aStyleName < < = sEmpty ;
aFamily < < = ( sal_Int16 ) FontFamily : : DONTKNOW ;
aPitch < < = ( sal_Int16 ) FontPitch : : DONTKNOW ;
aEnc < < = ( sal_Int16 ) rStyles . GetDfltCharset ( ) ;
}
void XMLFontStyleContext_Impl : : SetAttribute ( sal_uInt16 nPrefixKey ,
const OUString & rLocalName ,
const OUString & rValue )
{
SvXMLUnitConverter & rUnitConv = GetImport ( ) . GetMM100UnitConverter ( ) ;
const SvXMLTokenMap & rTokenMap = GetStyles ( ) - > GetFontStyleAttrTokenMap ( ) ;
Any aAny ;
switch ( rTokenMap . Get ( nPrefixKey , rLocalName ) )
{
case XML_TOK_FONT_STYLE_ATTR_FAMILY :
if ( GetStyles ( ) - > GetFamilyNameHdl ( ) . importXML ( rValue , aAny ,
rUnitConv ) )
aFamilyName = aAny ;
break ;
case XML_TOK_FONT_STYLE_ATTR_STYLENAME :
aStyleName < < = rValue ;
break ;
case XML_TOK_FONT_STYLE_ATTR_FAMILY_GENERIC :
if ( GetStyles ( ) - > GetFamilyHdl ( ) . importXML ( rValue , aAny ,
rUnitConv ) )
aFamily = aAny ;
break ;
case XML_TOK_FONT_STYLE_ATTR_PITCH :
if ( GetStyles ( ) - > GetPitchHdl ( ) . importXML ( rValue , aAny ,
rUnitConv ) )
aPitch = aAny ;
break ;
case XML_TOK_FONT_STYLE_ATTR_CHARSET :
if ( GetStyles ( ) - > GetEncodingHdl ( ) . importXML ( rValue , aAny ,
rUnitConv ) )
aEnc = aAny ;
break ;
default :
SvXMLStyleContext : : SetAttribute ( nPrefixKey , rLocalName , rValue ) ;
break ;
}
}
XMLFontStyleContext_Impl : : ~ XMLFontStyleContext_Impl ( )
{
}
void XMLFontStyleContext_Impl : : FillProperties (
: : std : : vector < XMLPropertyState > & rProps ,
sal_Int32 nFamilyNameIdx ,
sal_Int32 nStyleNameIdx ,
sal_Int32 nFamilyIdx ,
sal_Int32 nPitchIdx ,
sal_Int32 nCharsetIdx ) const
{
if ( nFamilyNameIdx ! = - 1 )
{
XMLPropertyState aPropState ( nFamilyNameIdx , aFamilyName ) ;
rProps . push_back ( aPropState ) ;
}
if ( nStyleNameIdx ! = - 1 )
{
XMLPropertyState aPropState ( nStyleNameIdx , aStyleName ) ;
rProps . push_back ( aPropState ) ;
}
if ( nFamilyIdx ! = - 1 )
{
XMLPropertyState aPropState ( nFamilyIdx , aFamily ) ;
rProps . push_back ( aPropState ) ;
}
if ( nPitchIdx ! = - 1 )
{
XMLPropertyState aPropState ( nPitchIdx , aPitch ) ;
rProps . push_back ( aPropState ) ;
}
if ( nCharsetIdx ! = - 1 )
{
XMLPropertyState aPropState ( nCharsetIdx , aEnc ) ;
rProps . push_back ( aPropState ) ;
}
}
SvXMLStyleContext * XMLFontStylesContext : : CreateStyleChildContext (
sal_uInt16 nPrefix ,
const : : rtl : : OUString & rLocalName ,
const : : com : : sun : : star : : uno : : Reference <
: : com : : sun : : star : : xml : : sax : : XAttributeList > & xAttrList )
{
SvXMLStyleContext * pStyle ;
if ( XML_NAMESPACE_STYLE = = nPrefix & &
2004-07-13 07:22:51 +00:00
IsXMLToken ( rLocalName , XML_FONT_FACE ) )
2000-11-14 09:19:45 +00:00
{
pStyle = new XMLFontStyleContext_Impl ( GetImport ( ) , nPrefix ,
rLocalName , xAttrList , * this ) ;
}
else
{
pStyle = SvXMLStylesContext : : CreateStyleChildContext ( nPrefix ,
rLocalName , xAttrList ) ;
}
return pStyle ;
}
TYPEINIT1 ( XMLFontStylesContext , SvXMLStylesContext ) ;
XMLFontStylesContext : : XMLFontStylesContext ( SvXMLImport & rImport ,
sal_uInt16 nPrfx , const OUString & rLName ,
const Reference < XAttributeList > & xAttrList ,
rtl_TextEncoding eDfltEnc ) :
SvXMLStylesContext ( rImport , nPrfx , rLName , xAttrList ) ,
pFamilyNameHdl ( new XMLFontFamilyNamePropHdl ) ,
pFamilyHdl ( new XMLFontFamilyPropHdl ) ,
pPitchHdl ( new XMLFontPitchPropHdl ) ,
pEncHdl ( new XMLFontEncodingPropHdl ) ,
2009-04-23 10:42:05 +00:00
pFontStyleAttrTokenMap ( new SvXMLTokenMap ( lcl_getFontStyleAttrTokenMap ( ) ) ) ,
2006-06-19 17:29:23 +00:00
eDfltEncoding ( eDfltEnc )
2000-11-14 09:19:45 +00:00
{
}
XMLFontStylesContext : : ~ XMLFontStylesContext ( )
{
delete pFamilyNameHdl ;
delete pFamilyHdl ;
delete pPitchHdl ;
delete pEncHdl ;
delete pFontStyleAttrTokenMap ;
}
sal_Bool XMLFontStylesContext : : FillProperties ( const OUString & rName ,
: : std : : vector < XMLPropertyState > & rProps ,
sal_Int32 nFamilyNameIdx ,
sal_Int32 nStyleNameIdx ,
sal_Int32 nFamilyIdx ,
sal_Int32 nPitchIdx ,
sal_Int32 nCharsetIdx ) const
{
2008-03-05 15:47:02 +00:00
const SvXMLStyleContext * pStyle = FindStyleChildContext ( XML_STYLE_FAMILY_FONT , rName , sal_True ) ;
const XMLFontStyleContext_Impl * pFontStyle = PTR_CAST ( XMLFontStyleContext_Impl , pStyle ) ; // use temp var, PTR_CAST is a bad macro, FindStyleChildContext will be called twice
2000-11-14 09:19:45 +00:00
if ( pFontStyle )
pFontStyle - > FillProperties ( rProps , nFamilyNameIdx , nStyleNameIdx ,
nFamilyIdx , nPitchIdx , nCharsetIdx ) ;
return 0 ! = pFontStyle ;
}
2010-10-12 15:53:47 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */