-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
45 lines (29 loc) · 1.09 KB
/
main.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
#include <QApplication>
#include <QLabel>
#include <QVBoxLayout>
#include "MmlDocument.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget MainWindow;
QLabel labelformula(&MainWindow);
QVBoxLayout layout(&MainWindow);
layout.addWidget(&labelformula);
QPainter painter;
QPixmap pixmap(300, 150);
painter.begin(&pixmap);
painter.fillRect( QRect(0,0, 300, 150), Qt::white );
QString formula = "<math><mfrac><mrow><mn>1</mn></mrow><mrow><mn>2</mn></mrow></mfrac><mo>×</mo><mi>ln</mi><mrow><mo>(</mo><mo>∣</mo><mi>tan</mi><mrow><mo>(</mo><mfrac><mrow><mi>x</mi></mrow><mrow><mn>2</mn></mrow></mfrac><mo>)</mo></mrow><mo>∣</mo><mo>)</mo></mrow></math>";
MmlDocument doc;
doc.clear();
doc.setContent( formula );
doc.setBaseFontPointSize( 32 );
doc.layout();
doc.paint( &painter, QPointF(50,50) );
painter.end();
//optionally pixmap can be saved to a PNG file
pixmap.save("./mathml_formula.png");
labelformula.setPixmap(pixmap);
MainWindow.show();
return a.exec();
}