-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMmlMoNode.cpp
162 lines (139 loc) · 4.91 KB
/
MmlMoNode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#ifndef MMLMONODE_CPP
#define MMLMONODE_CPP
#include "MmlMoNode.h"
MmlMoNode::MmlMoNode( MmlDocument *document, const MmlAttributeMap &attribute_map ) : MmlTokenNode( MoNode, document, attribute_map )
{
m_oper_spec = 0;
}
QString MmlMoNode::toStr() const
{
return MmlNode::toStr() + QString( " form=%1" ).arg( ( int )form() );
}
void MmlMoNode::layoutSymbol()
{
if ( firstChild() == 0 )
return;
firstChild()->setRelOrigin( QPointF( 0.0, 0.0 ) );
if ( m_oper_spec == 0 )
m_oper_spec = OperSpecSearchResult::mmlFindOperSpec( !text().compare( "−" )?"-":text(), form() );
}
QString MmlMoNode::dictionaryAttribute( const QString &name ) const
{
const MmlNode *p = this;
for ( ; p != 0; p = p->parent() )
{
if ( p == this || p->nodeType() == MstyleNode )
{
QString expl_attr = p->explicitAttribute( name );
if ( !expl_attr.isNull() )
return expl_attr;
}
}
return Helpers::mmlDictAttribute( name, m_oper_spec );
}
bool MmlMoNode::unaryMinus() const
{
return !text().compare( "−" )
&& previousSibling() != 0
&& previousSibling()->nodeType() == MoNode
&& ( !( ( MmlMoNode* ) previousSibling() )->text().compare( "=" )
|| !( ( MmlMoNode* ) previousSibling() )->text().compare( "(" )
|| !( ( MmlMoNode* ) previousSibling() )->text().compare( "|" )
|| !( ( MmlMoNode* ) previousSibling() )->text().compare( "⌊" )
|| !( ( MmlMoNode* ) previousSibling() )->text().compare( "⌈" )
|| !( ( MmlMoNode* ) previousSibling() )->text().compare( "," ) );
}
Mml::FormType MmlMoNode::form() const
{
QString value_str = inheritAttributeFromMrow( "form" );
if ( !value_str.isNull() )
{
bool ok;
FormType value = Helpers::mmlInterpretForm( value_str, &ok );
if ( ok )
return value;
else
qWarning() << "Could not convert " << value_str << " to form";
}
// Default heuristic.
if ( firstSibling() == ( MmlNode* )this && lastSibling() != ( MmlNode* )this )
return PrefixForm;
else if ( lastSibling() == ( MmlNode* )this && firstSibling() != ( MmlNode* )this )
return PostfixForm;
else if ( unaryMinus() )
return PrefixForm;
else
return InfixForm;
}
void MmlMoNode::stretch()
{
if ( parent() == 0 )
return;
if ( m_oper_spec == 0 )
return;
if ( m_oper_spec->stretch_dir == MmlOperSpec::HStretch
&& parent()->nodeType() == MrowNode
&& ( previousSibling() != 0 || nextSibling() != 0) )
return;
QRectF pmr = parent()->myRect();
QRectF pr = parentRect();
switch ( m_oper_spec->stretch_dir )
{
case MmlOperSpec::VStretch:
stretchTo( QRectF( pr.left(), pmr.top(), pr.width(), pmr.height() ) );
break;
case MmlOperSpec::HStretch:
stretchTo( QRectF( pmr.left(), pr.top(), pmr.width(), pr.height() ) );
break;
case MmlOperSpec::HVStretch:
stretchTo( pmr );
break;
case MmlOperSpec::NoStretch:
break;
}
}
qreal MmlMoNode::lspace() const
{
Q_ASSERT( m_oper_spec != 0 );
if ( parent() == 0
|| ( parent()->nodeType() != MrowNode
&& parent()->nodeType() != MfencedNode
&& parent()->nodeType() != UnknownNode )
|| previousSibling() == 0
|| ( previousSibling() == 0 && nextSibling() == 0 )
|| ( previousSibling() != 0
&& previousSibling()->nodeType() == MoNode
&& !( ( MmlMoNode* ) previousSibling() )->text().compare( text() ) )
|| unaryMinus()
|| ( !text().compare( "|" )
&& previousSibling() != 0
&& previousSibling()->nodeType() == MoNode
&& ( !( ( MmlMoNode* ) previousSibling() )->text().compare( "=" )
|| !( ( MmlMoNode* ) previousSibling() )->text().compare( "−" )
|| !( ( MmlMoNode* ) previousSibling() )->text().compare( "," ) ) ) )
return 0.0;
else
return interpretSpacing( dictionaryAttribute( "lspace" ), 0 );
}
qreal MmlMoNode::rspace() const
{
Q_ASSERT( m_oper_spec != 0 );
if ( parent() == 0
|| ( parent()->nodeType() != MrowNode
&& parent()->nodeType() != MfencedNode
&& parent()->nodeType() != UnknownNode )
|| nextSibling() == 0
|| ( previousSibling() == 0 && nextSibling() == 0 ) )
return 0.0;
else
return interpretSpacing( dictionaryAttribute( "rspace" ), 0 );
}
QRectF MmlMoNode::symbolRect() const
{
if ( firstChild() == 0 )
return QRectF( 0.0, 0.0, 0.0, 0.0 );
QRectF cmr = firstChild()->myRect();
return QRectF( -lspace(), cmr.top(),
cmr.width() + lspace() + rspace(), cmr.height() );
}
#endif//MMLMONODE_CPP