21#include "KoStyleStack.h"
37 : m_propertiesTagName( "properties" ), m_styleNSURI( styleNSURI ), m_foNSURI( foNSURI )
42KoStyleStack::~KoStyleStack()
49#ifdef DEBUG_STYLESTACK
50 kdDebug(30003) << "clear!" << endl;
56 m_marks.push( m_stack.count() );
57#ifdef DEBUG_STYLESTACK
58 kdDebug(30003) << "save (level " << m_marks.count() << ") -> index " << m_stack.count() << endl;
64 Q_ASSERT( !m_marks.isEmpty() );
65 int toIndex = m_marks.pop();
66#ifdef DEBUG_STYLESTACK
67 kdDebug(30003) << "restore (level " << m_marks.count()+1 << ") -> to index " << toIndex << endl;
69 Q_ASSERT( toIndex > -1 );
70 Q_ASSERT( toIndex <= ( int)m_stack.count() );
71 for ( int index = ( int)m_stack.count() - 1; index >= toIndex; --index )
77 Q_ASSERT( !m_stack.isEmpty() );
79#ifdef DEBUG_STYLESTACK
80 kdDebug(30003) << "pop -> count=" << m_stack.count() << endl;
86 m_stack.append( style );
87#ifdef DEBUG_STYLESTACK
88 kdDebug(30003) << "pushed " << style.attributeNS( m_styleNSURI, "name", TQString() ) << " -> count=" << m_stack.count() << endl;
94 TQString fullName( name );
95 if ( !detail.isEmpty() )
100 TQValueList<TQDomElement>::ConstIterator it = m_stack.end();
101 while ( it != m_stack.begin() )
104 TQDomElement properties = (*it).namedItem( "style:"+m_propertiesTagName ).toElement();
105 if ( properties.hasAttribute( name ) ||
106 ( !detail.isEmpty() && properties.hasAttribute( fullName ) ) )
114 TQString fullName( name );
115 if ( !detail.isEmpty() )
120 TQValueList<TQDomElement>::ConstIterator it = m_stack.end();
121 while ( it != m_stack.begin() )
124 TQDomElement properties = (*it).namedItem( "style:"+m_propertiesTagName ).toElement();
125 if ( properties.hasAttribute( name ) )
126 return properties.attribute( name );
127 if ( !detail.isEmpty() && properties.hasAttribute( fullName ) )
128 return properties.attribute( fullName );
135 TQString fullName( name );
141 TQValueList<TQDomElement>::ConstIterator it = m_stack.end();
142 while ( it != m_stack.begin() )
145 TQDomElement properties = KoDom::namedItemNS( *it, m_styleNSURI, m_propertiesTagName );
146 if ( properties.hasAttributeNS( nsURI, name ) )
147 return properties.attributeNS( nsURI, name, TQString() );
148 if ( detail && properties.hasAttributeNS( nsURI, fullName ) )
149 return properties.attributeNS( nsURI, fullName, TQString() );
156 TQString fullName( name );
162 TQValueList<TQDomElement>::ConstIterator it = m_stack.end();
163 while ( it != m_stack.begin() )
166 TQDomElement properties = KoDom::namedItemNS( *it, m_styleNSURI, m_propertiesTagName );
167 if ( properties.hasAttributeNS( nsURI, name ) ||
168 ( detail && properties.hasAttributeNS( nsURI, fullName ) ) )
179 const TQString name = "font-size";
181 TQValueList<TQDomElement>::ConstIterator it = m_stack.end();
183 while ( it != m_stack.begin() )
186 TQDomElement properties = KoDom::namedItemNS( *it, m_styleNSURI, m_propertiesTagName ).toElement();
187 if ( properties.hasAttributeNS( m_foNSURI, name ) ) {
188 const TQString value = properties.attributeNS( m_foNSURI, name, TQString() );
189 if ( value.endsWith( "%" ) )
190 percent *= value.left( value.length() - 1 ).toDouble() / 100.0;
200 TQValueList<TQDomElement>::ConstIterator it = m_stack.end();
201 while ( it != m_stack.begin() )
204 TQDomElement properties = (*it).namedItem( "style:"+m_propertiesTagName ).toElement();
205 if ( !properties.namedItem( name ).isNull() )
214 TQValueList<TQDomElement>::ConstIterator it = m_stack.end();
216 while ( it != m_stack.begin() )
219 TQDomElement properties = (*it).namedItem( "style:"+m_propertiesTagName ).toElement();
220 if ( !properties.namedItem( name ).isNull() )
221 return properties.namedItem( name ).toElement();
224 return TQDomElement();
229 TQValueList<TQDomElement>::ConstIterator it = m_stack.end();
230 while ( it != m_stack.begin() )
233 TQDomElement properties = KoDom::namedItemNS( *it, m_styleNSURI, m_propertiesTagName );
243 TQValueList<TQDomElement>::ConstIterator it = m_stack.end();
245 while ( it != m_stack.begin() )
248 TQDomElement properties = KoDom::namedItemNS( *it, m_styleNSURI, m_propertiesTagName );
254 return TQDomElement();
257bool KoStyleStack::isUserStyle( const TQDomElement& e, const TQString& family ) const
259 if ( e.attributeNS( m_styleNSURI, "family", TQString() ) != family )
261 const TQDomElement parent = e.parentNode().toElement();
263 return parent.localName() == "styles" ;
268 TQValueList<TQDomElement>::ConstIterator it = m_stack.end();
269 while ( it != m_stack.begin() )
273 if ( isUserStyle( *it, family ) )
274 return (*it).attributeNS( m_styleNSURI, "name", TQString() );
282 TQValueList<TQDomElement>::ConstIterator it = m_stack.end();
283 while ( it != m_stack.begin() )
287 if ( isUserStyle( *it, family ) )
288 return (*it).attributeNS( m_styleNSURI, "display-name", TQString() );
295 m_propertiesTagName = typeProperties == 0 ? TQCString( "properties" ) : ( TQCString( typeProperties ) + "-properties" );
KoStyleStack() Create a OASIS style stack.
bool hasAttributeNS(const char *nsURI, const char *localName, const char *detail=0) const Check if any of the styles on the stack has an attribute called 'name'-'detail' where detail is e....
TQDomElement childNode(const TQString &name) const TDE_DEPRECATED Search for a child node called 'name', starting on top of the stack, and return it.
void save() Save the current state of the stack.
void clear() Clears the complete stack.
TQDomElement childNodeNS(const char *nsURI, const char *localName) const Search for a child element which has a child element called 'localName' in the namespace 'nsURI' star...
void setTypeProperties(const char *typeProperties) Set the type of properties that will be looked for.
bool hasChildNode(const TQString &name) const TDE_DEPRECATED Check if any of the styles on the stack has a child node called 'name'.
double fontSize() const Special case for the current font size, due to special handling of fo:font-size="115%".
void push(const TQDomElement &style) Pushes the new style onto the stack.
bool hasAttribute(const TQString &name, const TQString &detail=TQString()) const TDE_DEPRECATED Check if any of the styles on the stack has an attribute called 'name'-'detail' where detail is e....
TQString attribute(const TQString &name, const TQString &detail=TQString()) const TDE_DEPRECATED Search for the attribute called 'name', starting on top of the stack, and return it.
TQString attributeNS(const char *nsURI, const char *localName, const char *detail=0) const Search for the attribute called 'name', starting on top of the stack, and return it.
bool hasChildNodeNS(const char *nsURI, const char *localName) const Check if any of the styles on the stack has a child element called 'localName' in the namespace 'nsUR...
void pop() Removes the style on top of the stack.
void restore() Restore the stack to the state it was at the corresponding save() call.
TQString userStyleDisplayName(const TQString &family) const Return the display name of the style specified by the user, i.e.
TQString userStyleName(const TQString &family) const Return the name of the style specified by the user, i.e.
static double parseValue(TQString value, double defaultVal=0.0) parse common KOffice and OO values, like "10cm", "5mm" to pt
Repository of XML namespaces used for OASIS documents.
KOFFICECORE_EXPORT TQDomElement namedItemNS(const TQDomNode &node, const char *nsURI, const char *localName) A namespace-aware version of TQDomNode::namedItem(), which also takes care of casting to a TQDomEleme...
|