20#include "basicelement.h"
21#include "styleelement.h"
23KFORMULA_NAMESPACE_BEGIN
26 m_scriptMinSizeType( NoSize ),
27 m_veryVeryThinMathSpaceType( NoSize ),
28 m_veryThinMathSpaceType( NoSize ),
29 m_thinMathSpaceType( NoSize ),
30 m_mediumMathSpaceType( NoSize ),
31 m_thickMathSpaceType( NoSize ),
32 m_veryThickMathSpaceType( NoSize ),
33 m_veryVeryThickMathSpaceType( NoSize ),
34 m_customScriptLevel( false ),
35 m_relativeScriptLevel( false ),
36 m_customDisplayStyle( false ),
37 m_customScriptSizeMultiplier( false ),
38 m_customBackground( false )
42bool StyleElement::readAttributesFromMathMLDom(
const TQDomElement& element )
48 TQString scriptlevelStr = element.attribute(
"scriptlevel" );
49 if ( ! scriptlevelStr.isNull() ) {
50 if ( scriptlevelStr[0] ==
'+' || scriptlevelStr[0] ==
'-' ) {
51 m_relativeScriptLevel =
true;
54 m_scriptLevel = scriptlevelStr.toInt( &ok );
56 kdWarning( DEBUGID ) <<
"Invalid scriptlevel attribute value: "
57 << scriptlevelStr << endl;
60 m_customScriptLevel =
true;
63 TQString displaystyleStr = element.attribute(
"displaystyle" );
64 if ( ! displaystyleStr.isNull() ) {
65 if ( displaystyleStr.lower() ==
"true" ) {
66 m_displayStyle =
true;
69 m_displayStyle =
false;
71 m_customDisplayStyle =
true;
73 TQString scriptsizemultiplierStr = element.attribute(
"scriptsizemultiplier" );
74 if ( ! scriptsizemultiplierStr.isNull() ) {
76 m_scriptSizeMultiplier = scriptsizemultiplierStr.toDouble( &ok );
78 kdWarning( DEBUGID ) <<
"Invalid scriptsizemultiplier attribute value: "
79 << scriptsizemultiplierStr << endl;
82 m_customScriptSizeMultiplier =
true;
85 TQString scriptminsizeStr = element.attribute(
"scriptminsize" );
86 if ( ! scriptminsizeStr.isNull() ) {
87 readSizeAttribute( scriptminsizeStr, &m_scriptMinSizeType, &m_scriptMinSize );
89 TQString backgroundStr = element.attribute(
"background" );
90 if ( ! backgroundStr.isNull() ) {
92 m_customBackground =
true;
93 if ( backgroundStr[0] !=
'#' ) {
97 m_background = TQColor( backgroundStr );
100 TQString veryverythinmathspaceStr = element.attribute(
"veryverythinmathspace" );
101 if ( ! veryverythinmathspaceStr.isNull() ) {
102 readSizeAttribute( veryverythinmathspaceStr, &m_veryVeryThinMathSpaceType, &m_veryVeryThinMathSpace );
104 TQString verythinmathspaceStr = element.attribute(
"verythinmathspace" );
105 if ( ! verythinmathspaceStr.isNull() ) {
106 readSizeAttribute( verythinmathspaceStr, &m_veryThinMathSpaceType, &m_veryThinMathSpace );
108 TQString thinmathspaceStr = element.attribute(
"thinmathspace" );
109 if ( ! thinmathspaceStr.isNull() ) {
110 readSizeAttribute( thinmathspaceStr, &m_thinMathSpaceType, &m_thinMathSpace );
112 TQString mediummathspaceStr = element.attribute(
"mediummathspace" );
113 if ( ! mediummathspaceStr.isNull() ) {
114 readSizeAttribute( mediummathspaceStr, &m_mediumMathSpaceType, &m_mediumMathSpace );
116 TQString thickmathspaceStr = element.attribute(
"thickmathspace" );
117 if ( ! thickmathspaceStr.isNull() ) {
118 readSizeAttribute( thickmathspaceStr, &m_thickMathSpaceType, &m_thickMathSpace );
120 TQString verythickmathspaceStr = element.attribute(
"verythickmathspace" );
121 if ( ! verythickmathspaceStr.isNull() ) {
122 readSizeAttribute( verythickmathspaceStr, &m_veryThickMathSpaceType, &m_veryThickMathSpace );
124 TQString veryverythickmathspaceStr = element.attribute(
"veryverythickmathspace" );
125 if ( ! veryverythickmathspaceStr.isNull() ) {
126 readSizeAttribute( veryverythickmathspaceStr, &m_veryVeryThickMathSpaceType, &m_veryVeryThickMathSpace );
131void StyleElement::writeMathMLAttributes( TQDomElement& element )
const
133 if ( m_customScriptLevel ) {
135 if ( m_relativeScriptLevel && m_scriptLevel >= 0 ) {
138 element.setAttribute(
"scriptlevel", prefix + TQString(
"%1" ).arg( m_scriptLevel ) );
140 if ( m_customDisplayStyle ) {
141 element.setAttribute(
"displaystyle", m_displayStyle ?
"true" :
"false" );
143 if ( m_customScriptSizeMultiplier ) {
144 element.setAttribute(
"scriptsizemultiplier", TQString(
"%1" ).arg( m_scriptSizeMultiplier ) );
146 writeSizeAttribute( element,
"scriptminsize", m_scriptMinSizeType, m_scriptMinSize );
147 if ( m_customBackground ) {
148 element.setAttribute(
"background", m_background.name() );
150 writeSizeAttribute( element,
"veryverythinmathspace", m_veryVeryThinMathSpaceType, m_veryVeryThinMathSpace );
151 writeSizeAttribute( element,
"verythinmathspace", m_veryThinMathSpaceType, m_veryThinMathSpace );
152 writeSizeAttribute( element,
"thinmathspace", m_thinMathSpaceType, m_thinMathSpace );
153 writeSizeAttribute( element,
"mediummathspace", m_mediumMathSpaceType, m_mediumMathSpace );
154 writeSizeAttribute( element,
"thickmathspace", m_thickMathSpaceType, m_thickMathSpace );
155 writeSizeAttribute( element,
"verythickmathspace", m_veryThickMathSpaceType, m_veryThickMathSpace );
156 writeSizeAttribute( element,
"veryverythickmathspace", m_veryVeryThickMathSpaceType, m_veryVeryThickMathSpace );
158 inherited::writeMathMLAttributes( element );
162void StyleElement::setStyleSize(
const ContextStyle& context, StyleAttributes& style )
164 if ( m_customScriptLevel ) {
165 if ( m_relativeScriptLevel ) {
166 style.setScriptLevel( style.scriptLevel() + m_scriptLevel );
169 style.setScriptLevel( m_scriptLevel );
173 style.setScriptLevel( style.scriptLevel() );
175 if ( m_customDisplayStyle || style.customDisplayStyle() ) {
176 style.setCustomDisplayStyle(
true );
177 if ( m_customDisplayStyle ) {
178 style.setDisplayStyle( m_displayStyle );
181 style.setDisplayStyle( style.displayStyle() );
185 style.setCustomDisplayStyle(
false );
187 if ( m_customScriptSizeMultiplier ) {
188 style.setScriptSizeMultiplier( m_scriptSizeMultiplier );
191 style.setScriptSizeMultiplier( style.scriptSizeMultiplier() );
196 double basesize = context.layoutUnitPtToPt( context.getBaseSize() );
197 double size = style.scriptMinSize();
198 switch ( m_scriptMinSizeType ) {
200 size = m_scriptMinSize;
202 size = m_scriptMinSize * basesize;
204 size = context.pixelXToPt( m_scriptMinSize );
208 style.setScriptMinSize( size );
210 style.setVeryVeryThinMathSpace( sizeFactor( context,
211 m_veryVeryThinMathSpaceType,
212 m_veryVeryThinMathSpace,
213 style.veryVeryThinMathSpace() ));
214 style.setVeryThinMathSpace( sizeFactor( context, m_veryThinMathSpaceType,
216 style.veryThinMathSpace() ));
217 style.setThinMathSpace( sizeFactor( context, m_thinMathSpaceType,
219 style.thinMathSpace() ));
220 style.setMediumMathSpace( sizeFactor( context, m_mediumMathSpaceType,
222 style.mediumMathSpace() ));
223 style.setThickMathSpace( sizeFactor( context, m_thickMathSpaceType,
225 style.thickMathSpace() ));
226 style.setVeryThickMathSpace( sizeFactor( context, m_veryThickMathSpaceType,
227 m_veryThickMathSpace,
228 style.veryThickMathSpace() ));
229 style.setVeryVeryThickMathSpace( sizeFactor( context,
230 m_veryVeryThickMathSpaceType,
231 m_veryVeryThickMathSpace,
232 style.veryVeryThickMathSpace() ));
233 inherited::setStyleSize( context, style );
236double StyleElement::sizeFactor(
const ContextStyle& context, SizeType st,
237 double length,
double defvalue )
239 double basesize = context.layoutUnitPtToPt( context.getBaseSize() );
242 return length / basesize;
246 return context.pixelXToPt( length ) / basesize;
253void StyleElement::setStyleVariant( StyleAttributes& style )
255 if ( customMathVariant() ) {
256 style.setCustomMathVariant (
true );
257 style.setCustomFontWeight(
false );
258 style.setCustomFontStyle(
false );
259 style.setCustomFont(
false );
260 if ( customMathVariant() ) {
261 style.setCharFamily ( charFamily() );
262 style.setCharStyle( charStyle() );
265 style.setCharFamily( style.charFamily() );
266 style.setCharStyle( style.charStyle() );
270 style.setCustomMathVariant(
false );
271 if ( customFontFamily() ) {
272 style.setCustomFont(
true );
273 style.setFont( TQFont(fontFamily()) );
276 bool fontweight =
false;
277 if ( customFontWeight() || style.customFontWeight() ) {
278 style.setCustomFontWeight(
true );
279 if ( customFontWeight() ) {
280 fontweight = fontWeight();
283 fontweight = style.fontWeight();
285 style.setFontWeight( fontweight );
288 style.setCustomFontWeight(
false );
291 bool fontstyle =
false;
292 if ( customFontStyle() || style.customFontStyle() ) {
293 style.setCustomFontStyle(
true );
294 if ( customFontStyle() ) {
295 fontstyle = fontStyle();
298 fontstyle = style.fontStyle();
300 style.setFontStyle( fontstyle );
303 style.setCustomFontStyle(
false );
306 if ( fontweight && fontstyle ) {
307 style.setCharStyle( boldItalicChar );
309 else if ( fontweight && ! fontstyle ) {
310 style.setCharStyle( boldChar );
312 else if ( ! fontweight && fontstyle ) {
313 style.setCharStyle( italicChar );
316 style.setCharStyle( normalChar );
321void StyleElement::setStyleBackground( StyleAttributes& style )
323 if ( customMathBackground() ) {
324 style.setBackground( mathBackground() );
326 else if ( m_customBackground ) {
327 style.setBackground( m_background );
330 style.setBackground( style.background() );
334void StyleElement::resetStyle( StyleAttributes& style )
336 inherited::resetStyle( style );
337 style.resetScriptLevel();
338 style.resetScriptSizeMultiplier();
339 style.resetScriptMinSize();
340 style.resetVeryVeryThinMathSpace();
341 style.resetVeryThinMathSpace();
342 style.resetThinMathSpace();
343 style.resetMediumMathSpace();
344 style.resetThickMathSpace();
345 style.resetVeryThickMathSpace();
346 style.resetVeryVeryThickMathSpace();
347 style.resetDisplayStyle();
350void StyleElement::readSizeAttribute(
const TQString& str, SizeType* st,
double* s )
352 if ( st == 0 || s == 0 ){
355 if ( str ==
"small" ) {
359 else if ( str ==
"normal" ) {
363 else if ( str ==
"big" ) {
372void StyleElement::writeSizeAttribute( TQDomElement element,
const TQString& str, SizeType st,
double s )
const
376 element.setAttribute( str, TQString(
"%1pt" ).arg( s ) );
379 element.setAttribute( str, TQString(
"%1%" ).arg( s * 100.0 ) );
382 element.setAttribute( str, TQString(
"%1px" ).arg( s ) );
390KFORMULA_NAMESPACE_END
Basis of every formula element.
virtual bool readAttributesFromMathMLDom(const TQDomElement &element)
Reads our attributes from the MathML element.
double getSize(const TQString &str, SizeType *st)
Utility function that sets the size type and returns the size value from a MathML attribute string wi...
Contains all the style information for the formela.
This class handles mathematical style attributes common to token elements, as explained in MathML Spe...
TQString getHtmlColor(const TQString &colorStr)
Return RGB string from HTML Colors.
virtual bool readAttributesFromMathMLDom(const TQDomElement &element)
Reads our attributes from the MathML element.