22#include <tqfontmetrics.h>
28#include "contextstyle.h"
29#include "elementvisitor.h"
30#include "spaceelement.h"
33KFORMULA_NAMESPACE_BEGIN
36SpaceElement::SpaceElement( SpaceWidth space,
bool tab,
BasicElement* parent )
39 m_widthType( NoSize ),
40 m_heightType( NoSize ),
41 m_depthType( NoSize ),
42 m_lineBreak( NoBreakType )
47 m_widthType = NegativeThinMathSpace;
50 m_widthType = ThinMathSpace;
53 m_widthType = MediumMathSpace;
56 m_widthType = ThickMathSpace;
59 m_widthType = VeryVeryThickMathSpace;
67 m_widthType( other.m_widthType ),
68 m_width( other.m_width ),
69 m_heightType( other.m_heightType ),
70 m_height( other.m_height ),
71 m_depthType( other.m_depthType ),
72 m_depth( other.m_depth ),
73 m_lineBreak( other.m_lineBreak )
80 return visitor->visit(
this );
86 ContextStyle::IndexStyle ,
87 StyleAttributes& style )
89 double factor = style.sizeFactor();
90 luPt mySize = context.getAdjustedSize( tstyle, factor );
91 TQFont font = context.getDefaultFont();
92 font.setPointSize( mySize );
94 TQFontMetrics fm( font );
96 LuPixelRect hbound = fm.boundingRect( w );
98 LuPixelRect vbound = fm.boundingRect( h );
100 double width = style.getSpace( m_widthType, m_width );
101 if ( m_widthType == AbsoluteSize ) {
102 width = m_width / context.layoutUnitPtToPt( context.getBaseSize() );
104 else if ( m_widthType == PixelSize ) {
105 width = context.pixelYToPt( m_width ) / context.layoutUnitPtToPt( context.getBaseSize() );
107 double height = style.getSpace( m_heightType, m_height );
108 if ( m_heightType == AbsoluteSize ) {
109 height = m_height / context.layoutUnitPtToPt( context.getBaseSize() );
111 else if ( m_heightType == PixelSize ) {
112 height = context.pixelYToPt( m_height ) / context.layoutUnitPtToPt( context.getBaseSize() );
114 double depth = style.getSpace( m_depthType, m_depth );
115 if ( m_depthType == AbsoluteSize ) {
116 depth = m_depth / context.layoutUnitPtToPt( context.getBaseSize() );
118 else if ( m_depthType == PixelSize ) {
119 depth = context.pixelYToPt( m_depth ) / context.layoutUnitPtToPt( context.getBaseSize() );
122 setWidth( hbound.width() * width );
123 setHeight( vbound.height() * height + vbound.height() * depth );
124 setBaseline( vbound.height() * height );
127 getParent()->registerTab(
this );
131void SpaceElement::draw( TQPainter& painter,
const LuPixelRect& ,
134 ContextStyle::IndexStyle ,
136 const LuPixelPoint& parentOrigin )
138 LuPixelPoint myPos(parentOrigin.x()+getX(), parentOrigin.y()+getY());
143 if ( context.edit() ) {
144 painter.setPen( context.getEmptyColor() );
145 painter.drawLine( context.layoutUnitToPixelX( myPos.x() ),
146 context.layoutUnitToPixelY( myPos.y()+getHeight() ),
147 context.layoutUnitToPixelX( myPos.x()+getWidth()-1 ),
148 context.layoutUnitToPixelY( myPos.y()+getHeight() ) );
149 painter.drawLine( context.layoutUnitToPixelX( myPos.x() ),
150 context.layoutUnitToPixelY( myPos.y()+getHeight() ),
151 context.layoutUnitToPixelX( myPos.x() ),
152 context.layoutUnitToPixelY( myPos.y()+getHeight()-getHeight()/5 ) );
153 painter.drawLine( context.layoutUnitToPixelX( myPos.x()+getWidth()-1 ),
154 context.layoutUnitToPixelY( myPos.y()+getHeight() ),
155 context.layoutUnitToPixelX( myPos.x()+getWidth()-1 ),
156 context.layoutUnitToPixelY( myPos.y()+getHeight()-getHeight()/5 ) );
164 switch ( m_widthType ) {
165 case NegativeVeryVeryThinMathSpace:
166 case NegativeVeryThinMathSpace:
167 case NegativeThinMathSpace:
168 case NegativeMediumMathSpace:
169 case NegativeThickMathSpace:
170 case NegativeVeryThickMathSpace:
171 case NegativeVeryVeryThickMathSpace:
172 element.setAttribute(
"WIDTH",
"negthin" );
174 case VeryVeryThinMathSpace:
175 case VeryThinMathSpace:
177 element.setAttribute(
"WIDTH",
"thin" );
179 case MediumMathSpace:
180 element.setAttribute(
"WIDTH",
"medium" );
183 element.setAttribute(
"WIDTH",
"thick" );
185 case VeryThickMathSpace:
186 case VeryVeryThickMathSpace:
187 element.setAttribute(
"WIDTH",
"quad" );
193 element.setAttribute(
"WIDTH",
"negthin" );
196 element.setAttribute(
"WIDTH",
"thin" );
202 element.setAttribute(
"TAB",
"true" );
211 TQString widthStr = element.attribute(
"WIDTH" );
212 if( !widthStr.isNull() ) {
213 if ( widthStr.lower() ==
"quad" ) {
214 m_widthType = VeryVeryThickMathSpace;
216 else if ( widthStr.lower() ==
"thick" ) {
217 m_widthType = ThickMathSpace;
219 else if ( widthStr.lower() ==
"medium" ) {
220 m_widthType = MediumMathSpace;
222 else if ( widthStr.lower() ==
"negthin" ) {
223 m_widthType = NegativeThinMathSpace;
226 m_widthType = ThinMathSpace;
232 TQString tabStr = element.attribute(
"TAB" );
233 m_tab = !tabStr.isNull();
248 TQString widthStr = element.attribute(
"width" ).stripWhiteSpace().lower();
249 if ( ! widthStr.isNull() ) {
250 m_width =
getSize( widthStr, &m_widthType );
251 if ( m_widthType == NoSize ) {
252 m_widthType = getSpace( widthStr );
255 TQString heightStr = element.attribute(
"height" ).stripWhiteSpace().lower();
256 if ( ! heightStr.isNull() ) {
257 m_height =
getSize( heightStr, &m_heightType );
259 TQString depthStr = element.attribute(
"depth" ).stripWhiteSpace().lower();
260 if ( ! depthStr.isNull() ) {
261 m_depth =
getSize( depthStr, &m_depthType );
263 TQString linebreakStr = element.attribute(
"linebreak" ).stripWhiteSpace().lower();
264 if ( ! linebreakStr.isNull() ) {
265 if ( linebreakStr ==
"auto" ) {
266 m_lineBreak = AutoBreak;
268 else if ( linebreakStr ==
"newline" ) {
269 m_lineBreak = NewLineBreak;
271 else if ( linebreakStr ==
"indentingnewline" ) {
272 m_lineBreak = IndentingNewLineBreak;
274 else if ( linebreakStr ==
"nobreak" ) {
275 m_lineBreak = NoBreak;
277 else if ( linebreakStr ==
"goodbreak" ) {
278 m_lineBreak = GoodBreak;
280 else if ( linebreakStr ==
"badbreak" ) {
281 m_lineBreak = BadBreak;
287void SpaceElement::writeMathMLAttributes( TQDomElement& element )
const
289 switch ( m_widthType ) {
291 element.setAttribute(
"width", TQString(
"%1pt" ).arg( m_width ) );
294 element.setAttribute(
"width", TQString(
"%1%" ).arg( m_width * 100.0 ) );
297 element.setAttribute(
"width", TQString(
"%1px" ).arg( m_width ) );
299 case NegativeVeryVeryThinMathSpace:
300 element.setAttribute(
"width",
"negativeveryverythinmathspace" );
302 case NegativeVeryThinMathSpace:
303 element.setAttribute(
"width",
"negativeverythinmathspace" );
305 case NegativeThinMathSpace:
306 element.setAttribute(
"width",
"negativethinmathspace" );
308 case NegativeMediumMathSpace:
309 element.setAttribute(
"width",
"negativemediummathspace" );
311 case NegativeThickMathSpace:
312 element.setAttribute(
"width",
"negativethickmathspace" );
314 case NegativeVeryThickMathSpace:
315 element.setAttribute(
"width",
"negativeverythickmathspace" );
317 case NegativeVeryVeryThickMathSpace:
318 element.setAttribute(
"width",
"negativeveryverythickmathspace" );
320 case VeryVeryThinMathSpace:
321 element.setAttribute(
"width",
"veryverythinmathspace" );
323 case VeryThinMathSpace:
324 element.setAttribute(
"width",
"verythinmathspace" );
327 element.setAttribute(
"width",
"thinmathspace" );
329 case MediumMathSpace:
330 element.setAttribute(
"width",
"mediummathspace" );
333 element.setAttribute(
"width",
"thickmathspace" );
335 case VeryThickMathSpace:
336 element.setAttribute(
"width",
"verythickmathspace" );
338 case VeryVeryThickMathSpace:
339 element.setAttribute(
"width",
"veryverythickmathspace" );
344 switch ( m_heightType ) {
346 element.setAttribute(
"height", TQString(
"%1pt" ).arg( m_height ) );
349 element.setAttribute(
"height", TQString(
"%1%" ).arg( m_height * 100.0 ) );
352 element.setAttribute(
"height", TQString(
"%1px" ).arg( m_height ) );
357 switch ( m_depthType ) {
359 element.setAttribute(
"depth", TQString(
"%1pt" ).arg( m_depth ) );
362 element.setAttribute(
"depth", TQString(
"%1%" ).arg( m_depth * 100.0 ) );
365 element.setAttribute(
"depth", TQString(
"%1px" ).arg( m_depth ) );
370 switch ( m_lineBreak ) {
372 element.setAttribute(
"linebreak",
"auto" );
375 element.setAttribute(
"linebreak",
"newline" );
377 case IndentingNewLineBreak:
378 element.setAttribute(
"linebreak",
"indentingnewline" );
381 element.setAttribute(
"linebreak",
"nobreak" );
384 element.setAttribute(
"linebreak",
"goodbreak" );
387 element.setAttribute(
"linebreak",
"badbreak" );
396 switch ( m_widthType ) {
397 case NegativeVeryVeryThinMathSpace:
398 case NegativeVeryThinMathSpace:
399 case NegativeThinMathSpace:
400 case NegativeMediumMathSpace:
401 case NegativeThickMathSpace:
402 case NegativeVeryThickMathSpace:
403 case NegativeVeryVeryThickMathSpace:
405 case VeryVeryThinMathSpace:
406 case VeryThinMathSpace:
409 case MediumMathSpace:
413 case VeryThickMathSpace:
414 case VeryVeryThickMathSpace:
431KFORMULA_NAMESPACE_END
Basis of every formula element.
virtual bool readAttributesFromMathMLDom(const TQDomElement &element)
Reads our attributes from the MathML element.
virtual bool readContentFromDom(TQDomNode &node)
Reads our content from the node.
virtual bool readAttributesFromDom(TQDomElement element)
Reads our attributes from the 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...
virtual void writeDom(TQDomElement element)
Appends our attributes to the dom element.
Contains all the style information for the formela.
TextStyle
Textstyles like in TeX.
A element that represents a space.
virtual void writeDom(TQDomElement element)
Appends our attributes to the dom element.
virtual TQString toLatex()
Draws the whole element including its children.
virtual bool readAttributesFromDom(TQDomElement element)
Reads our attributes from the element.
virtual void calcSizes(const ContextStyle &cstyle, ContextStyle::TextStyle tstyle, ContextStyle::IndexStyle istyle, StyleAttributes &style)
Calculates our width and height and our children's parentPosition.
virtual bool accept(ElementVisitor *visitor)
Visit this element.
virtual bool readContentFromDom(TQDomNode &node)
Reads our content from the node.
virtual bool readAttributesFromMathMLDom(const TQDomElement &element)
Reads our attributes from the MathML element.