-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMmlTextNode.cpp
53 lines (40 loc) · 1.55 KB
/
MmlTextNode.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
#include "MmlTextNode.h"
#include "MmlDocument.h"
MmlTextNode::MmlTextNode( const QString &text, MmlDocument *document ) : MmlNode( TextNode, document, MmlAttributeMap() )
{
m_text = text;
// Trim whitespace from ends, but keep nbsp and thinsp
m_text.remove( QRegularExpression( "^[^\\S\\x00a0\\x2009]+" ) );
m_text.remove( QRegularExpression( "[^\\S\\x00a0\\x2009]+$" ) );
}
QString MmlTextNode::toStr() const
{
return MmlNode::toStr() + " text=\"" + m_text + "\"";
}
bool MmlTextNode::isInvisibleOperator() const
{
return m_text == QString( QChar( 0x61, 0x20 ) ) // ⁡
|| m_text == QString( QChar( 0x62, 0x20 ) ) // ⁢
|| m_text == QString( QChar( 0x63, 0x20 ) ) // ⁣
|| m_text == QString( QChar( 0x64, 0x20 ) ); // Invisible addition
}
void MmlTextNode::paintSymbol(QPainter *painter, double x_scaling, double y_scaling ) const
{
MmlNode::paintSymbol( painter, x_scaling, y_scaling );
if ( isInvisibleOperator() )
return;
painter->save();
QPointF d_pos = devicePoint( QPointF() );
QPointF s_pos = symbolRect().topLeft();
painter->translate( d_pos + s_pos );
painter->scale( x_scaling, y_scaling );
painter->setFont( font() );
painter->drawText( QPointF( 0.0, basePos() ) - s_pos, m_text );
painter->restore();
}
QRectF MmlTextNode::symbolRect() const
{
QRectF br = isInvisibleOperator() ? QRectF() : QFontMetricsF( font() ).tightBoundingRect( m_text );
br.translate( 0.0, basePos() );
return br;
}