20#include "elementtype.h"
21#include "paddedelement.h"
23KFORMULA_NAMESPACE_BEGIN
26 m_widthType( NoSize ),
27 m_lspaceType( NoSize ),
28 m_heightType( NoSize ),
29 m_depthType( NoSize ),
30 m_widthRelative( false ),
31 m_lspaceRelative( false ),
32 m_heightRelative( false ),
33 m_depthRelative( false )
41void PaddedElement::calcSizes(
const ContextStyle& context,
43 ContextStyle::IndexStyle istyle,
44 StyleAttributes& style )
46 double factor = style.sizeFactor();
54 for ( iterator it = begin(); it != end(); ++it ) {
55 luPixel spaceBefore = 0;
56 if ( it == begin() ) {
57 spaceBefore = context.
ptToPixelX( getSpaceBefore( context, tstyle, factor ) );
59 it->calcSizes( context, tstyle, istyle, style );
60 width += it->getWidth() + spaceBefore;
61 luPixel baseline = it->getBaseline();
62 if ( baseline > -1 ) {
63 height = TQMAX( height, baseline );
64 depth = TQMAX( depth, it->getHeight() - baseline );
67 luPixel bl = it->getHeight()/2 + context.axisHeight( tstyle, factor );
68 height = TQMAX( height, bl );
69 depth = TQMAX( depth, it->getHeight() - bl );
74 width = context.getEmptyRectWidth( factor );
75 height = context.getEmptyRectHeight( factor );
79 luPixel left = calcSize( context, m_lspaceType, m_lspaceRelative, m_lspace, width, height, 0 );
80 luPixel right = calcSize( context, m_widthType, m_widthRelative, m_width, width, height, width ) + left;
81 luPixel down = calcSize( context, m_depthType, m_depthRelative, m_depth, width, height, depth );
82 luPixel
up = calcSize( context, m_heightType, m_heightRelative, m_height, width, height, height );
85 if ( right < 0 ) right = 0;
86 if ( up + down < 0 )
up = down = 0;
91 for ( iterator it = begin(); it != end(); ++it ) {
92 luPixel spaceBefore = 0;
93 if ( it == begin() ) {
94 spaceBefore = context.
ptToPixelX( getSpaceBefore( context, tstyle, factor ) );
96 it->calcSizes( context, tstyle, istyle, style );
97 it->setX( width + spaceBefore );
98 width += it->getWidth() + spaceBefore;
102 setHeight( up + down );
104 setChildrenPositions();
108 setHeight( up + down );
113bool PaddedElement::readAttributesFromMathMLDom(
const TQDomElement& element)
119 TQString widthStr = element.attribute(
"width" ).stripWhiteSpace().lower();
120 if ( ! widthStr.isNull() ) {
121 m_width = readSizeAttribute( widthStr, &m_widthType, &m_widthRelative );
123 TQString lspaceStr = element.attribute(
"lspace" ).stripWhiteSpace().lower();
124 if ( ! lspaceStr.isNull() ) {
125 m_lspace = readSizeAttribute( lspaceStr, &m_lspaceType, &m_lspaceRelative );
127 TQString heightStr = element.attribute(
"height" ).stripWhiteSpace().lower();
128 if ( ! heightStr.isNull() ) {
129 m_height = readSizeAttribute( heightStr, &m_heightType, &m_heightRelative );
131 TQString depthStr = element.attribute(
"depth" ).stripWhiteSpace().lower();
132 if ( ! depthStr.isNull() ) {
133 m_depth = readSizeAttribute( depthStr, &m_depthType, &m_depthRelative );
139void PaddedElement::writeMathMLAttributes( TQDomElement& element )
const
141 writeSizeAttribute( element,
"width", m_widthType, m_width, m_widthRelative );
142 writeSizeAttribute( element,
"lspace", m_lspaceType, m_lspace, m_lspaceRelative );
143 writeSizeAttribute( element,
"height", m_heightType, m_height, m_heightRelative );
144 writeSizeAttribute( element,
"depth", m_depthType, m_depth, m_depthRelative );
147double PaddedElement::readSizeAttribute(
const TQString& str, SizeType* st,
bool* relative )
152 if ( str[0] ==
'+' || str[0] ==
'-' ) {
155 int index = str.find(
"width" );
157 int index2 = str.find(
"%" );
158 if ( index2 != -1 ) {
159 return str2size( str.left( index2 ).stripWhiteSpace(), st, WidthRelativeSize ) / 100.0;
161 return str2size( str.left( index ).stripWhiteSpace(), st, WidthRelativeSize );
163 index = str.find(
"height" );
165 int index2 = str.find(
"%" );
166 if ( index2 != -1 ) {
167 return str2size( str.left( index2 ).stripWhiteSpace(), st, HeightRelativeSize ) / 100.0;
169 return str2size( str.left( index ).stripWhiteSpace(), st, HeightRelativeSize );
171 index = str.find(
"%" );
173 return str2size( str.left( index ).stripWhiteSpace(), st, RelativeSize ) / 100.0;
175 index = str.find(
"pt", 0,
false );
177 return str2size( str.left( index ).stripWhiteSpace(), st, AbsoluteSize );
179 index = str.find(
"mm", 0,
false );
181 return str2size( str.left( index ).stripWhiteSpace(), st, AbsoluteSize ) * 72.0 / 20.54;
183 index = str.find(
"cm", 0,
false );
185 return str2size( str.left( index ).stripWhiteSpace(), st, AbsoluteSize ) * 72.0 / 2.54;
187 index = str.find(
"in", 0,
false );
189 return str2size( str.left( index ).stripWhiteSpace(), st, AbsoluteSize ) * 72.0;
191 index = str.find(
"em", 0,
false );
193 return str2size( str.left( index ).stripWhiteSpace(), st, RelativeSize );
195 index = str.find(
"ex", 0,
false );
197 return str2size( str.left( index ).stripWhiteSpace(), st, RelativeSize );
199 index = str.find(
"pc", 0,
false );
201 return str2size( str.left( index ).stripWhiteSpace(), st, AbsoluteSize ) * 12.0;
203 index = str.find(
"px", 0,
false );
205 return str2size( str.left( index ).stripWhiteSpace(), st, PixelSize );
208 return str2size( str, st, AbsoluteSize );
211double PaddedElement::str2size(
const TQString& str, SizeType *st, SizeType type )
214 double size = str.toDouble( &ok );
227void PaddedElement::writeSizeAttribute( TQDomElement element,
const TQString& str,
228 SizeType st,
bool relative,
double s )
const
232 s < 0 ? prefix =
"-" : prefix =
"+" ;
235 case WidthRelativeSize:
236 element.setAttribute( str, prefix + TQString(
"%1 width" ).arg( s ) );
238 case HeightRelativeSize:
239 element.setAttribute( str, prefix + TQString(
"%1 height" ).arg( s ) );
241 element.setAttribute( str, prefix + TQString(
"%1pt" ).arg( s ) );
244 element.setAttribute( str, prefix + TQString(
"%1%" ).arg( s * 100.0 ) );
247 element.setAttribute( str, prefix + TQString(
"%1px" ).arg( s ) );
254luPixel PaddedElement::calcSize(
const ContextStyle& context, SizeType type,
255 bool relative,
double length, luPixel width,
256 luPixel height, luPixel defvalue )
258 luPixel value = defvalue;
268 value += length * value;
272 case WidthRelativeSize:
274 value += length * width;
276 value = length * width;
278 case HeightRelativeSize:
280 value += length * height;
282 value = length * height;
296KFORMULA_NAMESPACE_END
Basis of every formula element.
virtual bool readAttributesFromMathMLDom(const TQDomElement &element)
Reads our attributes from the MathML element.
Contains all the style information for the formela.
TextStyle
Textstyles like in TeX.
int ptToPixelX(double pt) const
Basic pt to pixel and pixel to pt conversions, valid at any zoom level, as well as at the Layout Unit...
static double ptToLayoutUnitPt(double pt)
Not zoom dependent.
int pixelToLayoutUnitX(int x) const
The "[zoomed] view pixel" -> "layout unit pixel" conversions.
The element that contains a number of children.
TDEAction * up(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)