1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: style.hxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #ifndef INCLUDED_PDFI_STYLE_HXX
33 #define INCLUDED_PDFI_STYLE_HXX
35 #include "pdfihelper.hxx"
38 #include <rtl/ustring.hxx>
39 #include <rtl/string.hxx>
40 #include "treevisiting.hxx"
46 struct ElementTreeVisitable
;
54 PropertyMap Properties
;
55 rtl::OUString Contents
;
56 Element
* ContainedElement
;
57 std::vector
< Style
* > SubStyles
;
59 Style() : ContainedElement( NULL
) {}
60 Style( const rtl::OString
& rName
, const PropertyMap
& rProps
) :
63 ContainedElement( NULL
)
71 PropertyMap Properties
;
72 rtl::OUString Contents
;
73 Element
* ContainedElement
;
74 std::vector
<sal_Int32
> SubStyles
;
79 HashedStyle() : ContainedElement( NULL
), IsSubStyle( true ), RefCount( 0 ) {}
81 HashedStyle( const HashedStyle
& rRight
) :
83 Properties( rRight
.Properties
),
84 Contents( rRight
.Contents
),
85 ContainedElement( rRight
.ContainedElement
),
86 SubStyles( rRight
.SubStyles
),
87 IsSubStyle( rRight
.IsSubStyle
),
91 size_t hashCode() const
93 size_t nRet
= size_t(Name
.hashCode());
94 for( PropertyMap::const_iterator it
= Properties
.begin();
95 it
!= Properties
.end(); ++it
)
97 nRet
^= size_t(it
->first
.hashCode());
98 nRet
^= size_t(it
->second
.hashCode());
100 nRet
= size_t(Contents
.hashCode());
101 nRet
^= size_t(ContainedElement
);
102 for( unsigned int n
= 0; n
< SubStyles
.size(); ++n
)
103 nRet
^= size_t(SubStyles
[n
]);
107 bool operator==(const HashedStyle
& rRight
) const
109 if( Name
!= rRight
.Name
||
110 Properties
!= rRight
.Properties
||
111 Contents
!= rRight
.Contents
||
112 ContainedElement
!= rRight
.ContainedElement
||
113 SubStyles
.size() != rRight
.SubStyles
.size()
116 for( unsigned int n
= 0; n
< SubStyles
.size(); ++n
)
118 if( SubStyles
[n
] != rRight
.SubStyles
[n
] )
126 friend struct StyleHash
;
129 size_t operator()( const StyleContainer::HashedStyle
& rStyle
) const
131 return rStyle
.hashCode();
135 struct StyleIdNameSort
;
136 friend struct StyleIdNameSort
;
137 struct StyleIdNameSort
139 const std::hash_map
< sal_Int32
, HashedStyle
>* m_pMap
;
141 StyleIdNameSort( const std::hash_map
< sal_Int32
, HashedStyle
>* pMap
) :
144 bool operator()( sal_Int32 nLeft
, sal_Int32 nRight
)
146 const std::hash_map
< sal_Int32
, HashedStyle
>::const_iterator left_it
=
147 m_pMap
->find( nLeft
);
148 const std::hash_map
< sal_Int32
, HashedStyle
>::const_iterator right_it
=
149 m_pMap
->find( nRight
);
150 if( left_it
== m_pMap
->end() )
152 else if( right_it
== m_pMap
->end() )
155 return left_it
->second
.Name
< right_it
->second
.Name
;
160 std::hash_map
< sal_Int32
, HashedStyle
> m_aIdToStyle
;
161 std::hash_map
< HashedStyle
, sal_Int32
, StyleHash
> m_aStyleToId
;
163 void impl_emitStyle( sal_Int32 nStyleId
,
164 EmitContext
& rContext
,
165 ElementTreeVisitor
& rContainedElemVisitor
);
170 void emit( EmitContext
& rContext
,
171 ElementTreeVisitor
& rContainedElemVisitor
);
173 sal_Int32
impl_getStyleId( const Style
& rStyle
, bool bSubStyle
);
174 sal_Int32
getStyleId( const Style
& rStyle
)
175 { return impl_getStyleId( rStyle
, false ); }
176 sal_Int32
getStandardStyleId( const rtl::OString
& rFamily
);
178 // returns NULL for an invalid style id
179 const PropertyMap
* getProperties( sal_Int32 nStyleId
) const;
180 sal_Int32
setProperties( sal_Int32 nStyleId
, const PropertyMap
&rNewProps
);
181 rtl::OUString
getStyleName( sal_Int32 nStyle
) const;