NEW: LaTeX-Parser simplifies parse-tree to increase speed of execution

This commit is contained in:
jkriege2 2022-06-19 22:36:38 +02:00
parent d885f7f00a
commit 03c59d3507
20 changed files with 468 additions and 190 deletions

View File

@ -12,8 +12,21 @@
- \ref JKQTMathTextSimpleExample
.
\defgroup jkqtmathtext_items JKQTMathText Render-Tree Items
\ingroup jkqtmathtext
\defgroup jkqtmathtext_render JKQTMathText Main (Render) Class
\ingroup jkqtmathtext
\defgroup jkqtmathtext_items JKQTMathText Render-Tree Items
\ingroup jkqtmathtext_render
\defgroup jkqtmathtext_widgets JKQTMathText widgets
\ingroup jkqtmathtext
\defgroup jkqtmathtext_tools JKQTMathText Tool Functions and Types
\ingroup jkqtmathtext
\defgroup jkqtmathtext_tools JKQTMathText Tool Functions and Types
\ingroup jkqtmathtext
*/

View File

@ -40,6 +40,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
<li>NEW: improved frac-rendering: font-scaling takes nesting-level into account, overall-rendering, sizes, if a brace surrounds a frac, the heights are equal above and below to center the brace , ...</li>
<li>NEW: shows strikeoutPos when drawing Debug-Boxes</li>
<li>NEW: LaTeX-Parser understands optional instruction parameters in [...] now</li>
<li>NEW: LaTeX-Parser simplifies parrse-tree to increase speed of execution</li>
</ul>
</ul>

View File

@ -368,16 +368,16 @@ QTreeWidgetItem *TestForm::createTree(JKQTMathTextNode *node, QTreeWidgetItem* p
if (inst1N->getChild()) ti->addChild(createTree(inst1N->getChild(), ti));
} else if (lstN) {
name=QString("MTlistNode");
QList<JKQTMathTextNode*> list=lstN->getNodes();
QList<JKQTMathTextNode*> list=lstN->getChildren();
for (int i=0; i<list.size(); i++) {
ti->addChild(createTree(list[i], ti));
}
} else if (symN) {
name=QString("JKQTMathTextSymbolNode: \'%1\' (addWhite: %2)").arg(symN->getSymbolName()).arg(symN->getAddWhitespace());
name=QString("MTSymbolNode: \'%1\' (addWhite: %2)").arg(symN->getSymbolName()).arg(symN->getAddWhitespace());
} else if (spN) {
name=QString("JKQTMathTextWhitespaceNode :\'%1\'").arg(txtN->getText());
name=QString("MTWhitespaceNode :\'%1\'").arg(txtN->getText());
} else if (txtN) {
name=QString("JKQTMathTextTextNode: \'%1\'").arg(txtN->getText());
name=QString("MTTextNode: \'%1\'").arg(txtN->getText());
} else {
name=QString("unknown");

View File

@ -35,6 +35,7 @@ set(SOURCES
${CMAKE_CURRENT_LIST_DIR}/nodes/jkqtmathtextsqrtnode.cpp
${CMAKE_CURRENT_LIST_DIR}/nodes/jkqtmathtextsubsupernode.cpp
${CMAKE_CURRENT_LIST_DIR}/nodes/jkqtmathtextsymbolnode.cpp
${CMAKE_CURRENT_LIST_DIR}/nodes/jkqtmathtextnodetools.cpp
)
set(HEADERS
@ -66,6 +67,8 @@ set(HEADERS
$<INSTALL_INTERFACE:nodes/jkqtmathtextsubsupernode.h>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/nodes/jkqtmathtextsymbolnode.h>
$<INSTALL_INTERFACE:nodes/jkqtmathtextsymbolnode.h>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/nodes/jkqtmathtextnodetools.h>
$<INSTALL_INTERFACE:nodes/jkqtmathtextnodetools.h>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/jkqtmathtext_imexport.h>
$<INSTALL_INTERFACE:jkqtmathtext_imexport.h>
)

View File

@ -33,6 +33,7 @@
#include "jkqtmathtext/nodes/jkqtmathtextsqrtnode.h"
#include "jkqtmathtext/nodes/jkqtmathtextsubsupernode.h"
#include "jkqtmathtext/nodes/jkqtmathtextsymbolnode.h"
#include "jkqtmathtext/nodes/jkqtmathtextnodetools.h"
#include <cmath>
#include <QFontMetricsF>
#include <QDebug>
@ -979,12 +980,12 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, JKQTMathTextBraceType
getNew=addWhite;
if (parsingMathEnvironment) {
if (mathEnvironmentSpecialText.contains(text.trimmed())) {
nl->addNode(new JKQTMathTextSymbolNode(this, text, addWhite));
nl->addChild(new JKQTMathTextSymbolNode(this, text, addWhite));
} else {
nl->addNode(new JKQTMathTextTextNode(this, text, addWhite, parsingMathEnvironment));
nl->addChild(new JKQTMathTextTextNode(this, text, addWhite, parsingMathEnvironment));
}
} else {
nl->addNode(new JKQTMathTextTextNode(this, text, addWhite, parsingMathEnvironment));
nl->addChild(new JKQTMathTextTextNode(this, text, addWhite, parsingMathEnvironment));
}
} else if (currentToken==MTTinstruction) {
const QString currentInstructionName=currentTokenName;
@ -993,9 +994,9 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, JKQTMathTextBraceType
if (currentToken==MTTopenbrace) {
//std::cout<<"found '{' after '"<<name.toStdString()<<"'\n";
if (currentInstructionName=="sqrt") {
nl->addNode(new JKQTMathTextSqrtNode(this, parseLatexString(true)));
nl->addChild(new JKQTMathTextSqrtNode(this, parseLatexString(true)));
} else if (currentInstructionName=="cbrt") {
nl->addNode(new JKQTMathTextSqrtNode(this, parseLatexString(true), 3));
nl->addChild(new JKQTMathTextSqrtNode(this, parseLatexString(true), 3));
} else if (currentInstructionName=="verb") {
QString text="";
currentTokenID++;
@ -1007,73 +1008,73 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, JKQTMathTextBraceType
if (currentTokenID<parseString.size()) c=parseString[currentTokenID];
}
if (c!='}') error_list.append(tr("error @ ch. %1: \verb{...} not closed by '}'").arg(currentTokenID).arg(currentInstructionName));
nl->addNode(new JKQTMathTextTextNode(this, text, false));
nl->addChild(new JKQTMathTextTextNode(this, text, false));
}
} else if (currentInstructionName=="frac") {
JKQTMathTextNode* n1=parseLatexString(true);
JKQTMathTextNode* n2=nullptr;
if (getToken()==MTTopenbrace) n2=parseLatexString(true);
if (n1 && n2) nl->addNode(new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMfrac));
if (n1 && n2) nl->addChild(new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMfrac));
else error_list.append(tr("error @ ch. %1: expected two arguments in '{' braces after '%2' command").arg(currentTokenID).arg(currentInstructionName));
} else if (currentInstructionName=="dfrac" || currentInstructionName=="cfrac") {
JKQTMathTextNode* n1=parseLatexString(true);
JKQTMathTextNode* n2=nullptr;
if (getToken()==MTTopenbrace) n2=parseLatexString(true);
if (n1 && n2) nl->addNode(new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMdfrac));
if (n1 && n2) nl->addChild(new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMdfrac));
else error_list.append(tr("error @ ch. %1: expected two arguments in '{' braces after '%2' command").arg(currentTokenID).arg(currentInstructionName));
} else if (currentInstructionName=="sfrac" || currentInstructionName=="slantfrac" || currentInstructionName=="xfrac") {
JKQTMathTextNode* n1=parseLatexString(true);
JKQTMathTextNode* n2=nullptr;
if (getToken()==MTTopenbrace) n2=parseLatexString(true);
if (n1 && n2) nl->addNode(new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMsfrac));
if (n1 && n2) nl->addChild(new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMsfrac));
else error_list.append(tr("error @ ch. %1: expected two arguments in '{' braces after '%2' command").arg(currentTokenID).arg(currentInstructionName));
} else if (currentInstructionName=="stfrac" || currentInstructionName=="nicefrac" || currentInstructionName=="slanttextfrac" || currentInstructionName=="xtfrac") {
JKQTMathTextNode* n1=parseLatexString(true);
JKQTMathTextNode* n2=nullptr;
if (getToken()==MTTopenbrace) n2=parseLatexString(true);
if (n1 && n2) nl->addNode(new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMstfrac));
if (n1 && n2) nl->addChild(new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMstfrac));
else error_list.append(tr("error @ ch. %1: expected two arguments in '{' braces after '%2' command").arg(currentTokenID).arg(currentInstructionName));
} else if (currentInstructionName=="tfrac") {
JKQTMathTextNode* n1=parseLatexString(true);
JKQTMathTextNode* n2=nullptr;
if (getToken()==MTTopenbrace) n2=parseLatexString(true);
if (n1 && n2) nl->addNode(new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMtfrac));
if (n1 && n2) nl->addChild(new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMtfrac));
else error_list.append(tr("error @ ch. %1: expected two arguments in '{' braces after '%2' command").arg(currentTokenID).arg(currentInstructionName));
} else if (currentInstructionName=="stackrel") {
JKQTMathTextNode* n1=parseLatexString(true);
JKQTMathTextNode* n2=nullptr;
if (getToken()==MTTopenbrace) n2=parseLatexString(true);
if (n1 && n2) nl->addNode(new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMstackrel));
if (n1 && n2) nl->addChild(new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMstackrel));
else error_list.append(tr("error @ ch. %1: expected two arguments in '{' braces after '%2' command").arg(currentTokenID).arg(currentInstructionName));
} else if (currentInstructionName=="binom") {
JKQTMathTextNode* n1=parseLatexString(true);
JKQTMathTextNode* n2=nullptr;
if (getToken()==MTTopenbrace) n2=parseLatexString(true);
if (n1 && n2) nl->addNode(new JKQTMathTextBraceNode(this, MTBTParenthesis, MTBTParenthesis, new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMstackrel)));
if (n1 && n2) nl->addChild(new JKQTMathTextBraceNode(this, MTBTParenthesis, MTBTParenthesis, new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMstackrel)));
else error_list.append(tr("error @ ch. %1: expected two arguments in '{' braces after '%2' command").arg(currentTokenID).arg(currentInstructionName));
} else if (currentInstructionName=="underbrace") {
JKQTMathTextNode* n1=parseLatexString(true);
JKQTMathTextNode* n2=nullptr;
if (getToken()==MTTopenbrace) n2=parseLatexString(true);
if (n1 && n2) nl->addNode(new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMunderbrace));
if (n1 && n2) nl->addChild(new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMunderbrace));
else error_list.append(tr("error @ ch. %1: expected two arguments in '{' braces after '%2' command").arg(currentTokenID).arg(currentInstructionName));
} else if (currentInstructionName=="underset") {
JKQTMathTextNode* n1=parseLatexString(true);
JKQTMathTextNode* n2=nullptr;
if (getToken()==MTTopenbrace) n2=parseLatexString(true);
if (n1 && n2) nl->addNode(new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMunderset));
if (n1 && n2) nl->addChild(new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMunderset));
else error_list.append(tr("error @ ch. %1: expected two arguments in '{' braces after '%2' command").arg(currentTokenID).arg(currentInstructionName));
} else if (currentInstructionName=="overbrace") {
JKQTMathTextNode* n1=parseLatexString(true);
JKQTMathTextNode* n2=nullptr;
if (getToken()==MTTopenbrace) n2=parseLatexString(true);
if (n1 && n2) nl->addNode(new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMoverbrace));
if (n1 && n2) nl->addChild(new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMoverbrace));
else error_list.append(tr("error @ ch. %1: expected two arguments in '{' braces after '%2' command").arg(currentTokenID).arg(currentInstructionName));
} else if (currentInstructionName=="overset") {
JKQTMathTextNode* n1=parseLatexString(true);
JKQTMathTextNode* n2=nullptr;
if (getToken()==MTTopenbrace) n2=parseLatexString(true);
if (n1 && n2) nl->addNode(new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMoverset));
if (n1 && n2) nl->addChild(new JKQTMathTextFracNode(this, n1, n2, JKQTMathTextFracNode::MTFMoverset));
else error_list.append(tr("error @ ch. %1: expected two arguments in '{' braces after '%2' command").arg(currentTokenID).arg(currentInstructionName));
} else if (currentInstructionName=="begin") {
if (getToken()==MTTtext) {
@ -1100,13 +1101,13 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, JKQTMathTextBraceType
first=false;
}
//std::cout<<" creating matrix-node with "<<items.size()<<" items.\n";
if (envname=="pmatrix") nl->addNode(new JKQTMathTextBraceNode(this, MTBTParenthesis, MTBTParenthesis, new JKQTMathTextMatrixNode(this, items)));
else if (envname=="cases") nl->addNode(new JKQTMathTextBraceNode(this, MTBTCurlyBracket, MTBTNone, new JKQTMathTextMatrixNode(this, items)));
else if (envname=="bmatrix") nl->addNode(new JKQTMathTextBraceNode(this, MTBTSquareBracket, MTBTSquareBracket, new JKQTMathTextMatrixNode(this, items)));
else if (envname=="Bmatrix") nl->addNode(new JKQTMathTextBraceNode(this, MTBTCurlyBracket, MTBTCurlyBracket, new JKQTMathTextMatrixNode(this, items)));
else if (envname=="vmatrix") nl->addNode(new JKQTMathTextBraceNode(this, MTBTSingleLine, MTBTSingleLine, new JKQTMathTextMatrixNode(this, items)));
else if (envname=="Vmatrix") nl->addNode(new JKQTMathTextBraceNode(this, MTBTDoubleLine, MTBTDoubleLine, new JKQTMathTextMatrixNode(this, items)));
else nl->addNode(new JKQTMathTextMatrixNode(this, items));
if (envname=="pmatrix") nl->addChild(new JKQTMathTextBraceNode(this, MTBTParenthesis, MTBTParenthesis, new JKQTMathTextMatrixNode(this, items)));
else if (envname=="cases") nl->addChild(new JKQTMathTextBraceNode(this, MTBTCurlyBracket, MTBTNone, new JKQTMathTextMatrixNode(this, items)));
else if (envname=="bmatrix") nl->addChild(new JKQTMathTextBraceNode(this, MTBTSquareBracket, MTBTSquareBracket, new JKQTMathTextMatrixNode(this, items)));
else if (envname=="Bmatrix") nl->addChild(new JKQTMathTextBraceNode(this, MTBTCurlyBracket, MTBTCurlyBracket, new JKQTMathTextMatrixNode(this, items)));
else if (envname=="vmatrix") nl->addChild(new JKQTMathTextBraceNode(this, MTBTSingleLine, MTBTSingleLine, new JKQTMathTextMatrixNode(this, items)));
else if (envname=="Vmatrix") nl->addChild(new JKQTMathTextBraceNode(this, MTBTDoubleLine, MTBTDoubleLine, new JKQTMathTextMatrixNode(this, items)));
else nl->addChild(new JKQTMathTextMatrixNode(this, items));
//std::cout<<" creating matrix-node ... done!\n";
} else {
error_list.append(tr("error @ ch. %1: unknown environment '%2'").arg(currentTokenID).arg(envname));
@ -1131,47 +1132,47 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, JKQTMathTextBraceType
getNew=true;
}
} else if (currentInstructionName=="vec") {
nl->addNode(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDvec, parseLatexString(true)));
nl->addChild(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDvec, parseLatexString(true)));
} else if (currentInstructionName=="overline"||currentInstructionName=="oline"||currentInstructionName=="ol") {
nl->addNode(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDoverline, parseLatexString(true)));
nl->addChild(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDoverline, parseLatexString(true)));
} else if (currentInstructionName=="underline"||currentInstructionName=="uline"||currentInstructionName=="ul") {
nl->addNode(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDunderline, parseLatexString(true)));
nl->addChild(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDunderline, parseLatexString(true)));
} else if (currentInstructionName=="uuline"||currentInstructionName=="uul") {
nl->addNode(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDdoubleunderline, parseLatexString(true)));
nl->addChild(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDdoubleunderline, parseLatexString(true)));
} else if (currentInstructionName=="ooline"||currentInstructionName=="ool") {
nl->addNode(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDdoubleoverline, parseLatexString(true)));
nl->addChild(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDdoubleoverline, parseLatexString(true)));
} else if (currentInstructionName=="arrow"||currentInstructionName=="overrightarrow"||currentInstructionName=="overarrow") {
nl->addNode(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDarrow, parseLatexString(true)));
nl->addChild(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDarrow, parseLatexString(true)));
} else if (currentInstructionName=="hat" || currentInstructionName=="^") {
nl->addNode(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDhat, parseLatexString(true)));
nl->addChild(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDhat, parseLatexString(true)));
} else if (currentInstructionName=="widehat") {
nl->addNode(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDwidehat, parseLatexString(true)));
nl->addChild(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDwidehat, parseLatexString(true)));
} else if (currentInstructionName=="check" || currentInstructionName=="v") {
nl->addNode(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDcheck, parseLatexString(true)));
nl->addChild(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDcheck, parseLatexString(true)));
} else if (currentInstructionName=="widecheck") {
nl->addNode(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDwidecheck, parseLatexString(true)));
nl->addChild(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDwidecheck, parseLatexString(true)));
} else if (currentInstructionName=="bar") {
nl->addNode(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDbar, parseLatexString(true)));
nl->addChild(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDbar, parseLatexString(true)));
} else if (currentInstructionName=="dot" || currentInstructionName==".") {
nl->addNode(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDdot, parseLatexString(true)));
nl->addChild(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDdot, parseLatexString(true)));
} else if (currentInstructionName=="ocirc") {
nl->addNode(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDocirc, parseLatexString(true)));
nl->addChild(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDocirc, parseLatexString(true)));
} else if (currentInstructionName=="tilde" || currentInstructionName=="~") {
nl->addNode(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDtilde, parseLatexString(true)));
nl->addChild(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDtilde, parseLatexString(true)));
} else if (currentInstructionName=="breve" || currentInstructionName=="u") {
nl->addNode(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDbreve, parseLatexString(true)));
nl->addChild(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDbreve, parseLatexString(true)));
} else if (currentInstructionName=="widetilde") {
nl->addNode(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDwidetilde, parseLatexString(true)));
nl->addChild(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDwidetilde, parseLatexString(true)));
} else if (currentInstructionName=="ddot") {
nl->addNode(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDddot, parseLatexString(true)));
nl->addChild(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDddot, parseLatexString(true)));
} else if (currentInstructionName=="cancel") {
nl->addNode(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDcancel, parseLatexString(true)));
nl->addChild(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDcancel, parseLatexString(true)));
} else if (currentInstructionName=="xcancel") {
nl->addNode(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDxcancel, parseLatexString(true)));
nl->addChild(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDxcancel, parseLatexString(true)));
} else if (currentInstructionName=="bcancel") {
nl->addNode(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDbcancel, parseLatexString(true)));
nl->addChild(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDbcancel, parseLatexString(true)));
} else if (currentInstructionName=="strike" || currentInstructionName=="st" || currentInstructionName=="sout") {
nl->addNode(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDstrike, parseLatexString(true)));
nl->addChild(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDstrike, parseLatexString(true)));
} else {
if (currentInstructionName=="textcolor" || currentInstructionName=="mathcolor" || currentInstructionName=="color" || currentInstructionName=="colorbox") {
bool foundError=true;
@ -1185,11 +1186,11 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, JKQTMathTextBraceType
}
}
if (foundError) error_list.append(tr("error @ ch. %1: expected two arguments in '{' braces after '%2' command").arg(currentTokenID).arg(currentInstructionName));
else nl->addNode(new JKQTMathTextInstruction1Node(this, currentInstructionName, parseLatexString(true), QStringList(col)));
else nl->addChild(new JKQTMathTextInstruction1Node(this, currentInstructionName, parseLatexString(true), QStringList(col)));
} else {
nl->addNode(new JKQTMathTextInstruction1Node(this, currentInstructionName, parseLatexString(true)));
nl->addChild(new JKQTMathTextInstruction1Node(this, currentInstructionName, parseLatexString(true)));
}
}
} else if (currentToken==MTTopenbracket && currentInstructionName!="left") {
@ -1198,8 +1199,8 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, JKQTMathTextBraceType
JKQTMathTextNode* n1=parseLatexString(true, MTBTAny, "", true);
JKQTMathTextListNode* n1lst=dynamic_cast<JKQTMathTextListNode*>(n1);
JKQTMathTextTextNode* n1txt=dynamic_cast<JKQTMathTextTextNode*>(n1);
if (n1lst && n1lst->count()==1) {
n1txt=dynamic_cast<JKQTMathTextTextNode*>(n1lst->child(0));
if (n1lst && n1lst->childCount()==1) {
n1txt=dynamic_cast<JKQTMathTextTextNode*>(n1lst->getChild(0));
}
int degree=2;
bool ok=false;
@ -1213,10 +1214,10 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, JKQTMathTextBraceType
if (getToken()==MTTopenbrace) n2=parseLatexString(true);
else error_list.append(tr("error @ ch. %1: expected one argument in '{' braces after '%2' command with an optional argument in []").arg(currentTokenID).arg(currentInstructionName));
if (n1 && n2) nl->addNode(new JKQTMathTextSqrtNode(this, n2, degree));
if (n1 && n2) nl->addChild(new JKQTMathTextSqrtNode(this, n2, degree));
else error_list.append(tr("error @ ch. %1: expected two arguments in '{' braces after '%2' command").arg(currentTokenID).arg(currentInstructionName));
} else {
nl->addNode(new JKQTMathTextTextNode(this, "[", false));
nl->addChild(new JKQTMathTextTextNode(this, "[", false));
}
} else {
//std::cout<<"did not find '{' after '"<<name.toStdString()<<"'\n";
@ -1255,10 +1256,10 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, JKQTMathTextBraceType
if (bracetype==MTBTNone) {
currentTokenName=currentTokenName.right(currentTokenName.size()-1);
JKQTMathTextNode* cn=parseLatexString(currentTokenName.size()<=0, MTBTAny);
nl->addNode(new JKQTMathTextBraceNode(this, MTBTNone, bracetype, cn));
nl->addChild(new JKQTMathTextBraceNode(this, MTBTNone, bracetype, cn));
} else if (isPrintableJKQTMathTextBraceType(bracetype)) {
currentTokenName=currentTokenName.right(currentTokenName.size()-1); // we already used the first character from the text token!
nl->addNode(new JKQTMathTextBraceNode(this, bracetype, bracetype, parseLatexString(currentTokenName.size()<=0, bracetype)));
nl->addChild(new JKQTMathTextBraceNode(this, bracetype, bracetype, parseLatexString(currentTokenName.size()<=0, bracetype)));
} else {
getNew=false;
}
@ -1266,12 +1267,12 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, JKQTMathTextBraceType
} else if (currentToken==MTTinstruction) {
const JKQTMathTextBraceType bracetypeopening=InstructionName2OpeningJKQTMathTextBraceType(currentTokenName);
if (bracetypeopening!=MTBTUnknown) {
nl->addNode(new JKQTMathTextBraceNode(this, bracetypeopening, bracetypeopening, parseLatexString(true, bracetypeopening)));
nl->addChild(new JKQTMathTextBraceNode(this, bracetypeopening, bracetypeopening, parseLatexString(true, bracetypeopening)));
} else if (currentToken==MTTinstruction && TokenNameMatchesJKQTMathTextBraceType(currentTokenName, quitOnClosingBrace, true)) {
break;
}
} else if (currentToken==MTTopenbracket) {
nl->addNode(new JKQTMathTextBraceNode(this, MTBTSquareBracket, MTBTSquareBracket, parseLatexString(true, MTBTSquareBracket)));
nl->addChild(new JKQTMathTextBraceNode(this, MTBTSquareBracket, MTBTSquareBracket, parseLatexString(true, MTBTSquareBracket)));
} else {
error_list.append(tr("error @ ch. %1: unexpected token after \\left").arg(currentTokenID));
}
@ -1287,11 +1288,11 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, JKQTMathTextBraceType
if (n0=='v' && n1.isLetter()) {
done=true;
//std::cout<<"found \\v... command\n";
nl->addNode(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDvec, new JKQTMathTextTextNode(this, QString(n1), false, parsingMathEnvironment)));
nl->addChild(new JKQTMathTextDecoratedNode(this, JKQTMathTextDecoratedNode::MTDvec, new JKQTMathTextTextNode(this, QString(n1), false, parsingMathEnvironment)));
} else if (n0=='c' && n1.isLetter()) {
done=true;
//std::cout<<"found \\v... command\n";
nl->addNode(new JKQTMathTextInstruction1Node(this, "mathcal", new JKQTMathTextTextNode(this, QString(n1), false, parsingMathEnvironment)));
nl->addChild(new JKQTMathTextInstruction1Node(this, "mathcal", new JKQTMathTextTextNode(this, QString(n1), false, parsingMathEnvironment)));
}
} else if (currentInstructionName.size()==3) {
QString n0=currentInstructionName.left(2);
@ -1299,15 +1300,15 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, JKQTMathTextBraceType
if (n0=="bb" && n1.isLetter()) {
done=true;
//std::cout<<"found \\v... command\n";
nl->addNode(new JKQTMathTextInstruction1Node(this, "mathbb", new JKQTMathTextTextNode(this, QString(n1), false, parsingMathEnvironment)));
nl->addChild(new JKQTMathTextInstruction1Node(this, "mathbb", new JKQTMathTextTextNode(this, QString(n1), false, parsingMathEnvironment)));
}
}
if (!done) nl->addNode(new JKQTMathTextSymbolNode(this, currentInstructionName, false));//, addWhite));
if (!done) nl->addChild(new JKQTMathTextSymbolNode(this, currentInstructionName, false));//, addWhite));
}
}
} else if (currentToken==MTTwhitespace) {
if (!parsingMathEnvironment) nl->addNode(new JKQTMathTextWhitespaceNode(this));
if (!parsingMathEnvironment) nl->addChild(new JKQTMathTextWhitespaceNode(this));
} else if (currentToken==MTTunderscore) {
getToken();
JKQTMathTextNode* child=nullptr;
@ -1336,8 +1337,8 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, JKQTMathTextBraceType
} else {
getNew=false;
}
if (child!=nullptr) nl->addNode(new JKQTMathTextSubscriptNode(this, child));
if (child2!=nullptr) nl->addNode(child2);
if (child!=nullptr) nl->addChild(new JKQTMathTextSubscriptNode(this, child));
if (child2!=nullptr) nl->addChild(child2);
} else if (currentToken==MTThat) {
getToken();
JKQTMathTextNode* child=nullptr;
@ -1366,17 +1367,17 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, JKQTMathTextBraceType
} else {
getNew=false;
}
if (child!=nullptr) nl->addNode(new JKQTMathTextSuperscriptNode(this, child));
if (child2!=nullptr) nl->addNode(child2);
if (child!=nullptr) nl->addChild(new JKQTMathTextSuperscriptNode(this, child));
if (child2!=nullptr) nl->addChild(child2);
} else if (currentToken==MTTopenbrace) {
nl->addNode(parseLatexString(true));
nl->addChild(parseLatexString(true));
} else if (currentToken==MTTclosebrace) {
break;
} else if (currentToken==MTTopenbracket) {
nl->addNode(new JKQTMathTextTextNode(this, "[", false));
nl->addChild(new JKQTMathTextTextNode(this, "[", false));
} else if (currentToken==MTTclosebracket) {
if (quitOnClosingBracket) break;
else nl->addNode(new JKQTMathTextTextNode(this, "]", false));
else nl->addChild(new JKQTMathTextTextNode(this, "]", false));
} else if (currentToken==MTTampersand) {
break;
} else if (currentToken==MTTdollar) {
@ -1385,13 +1386,13 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, JKQTMathTextBraceType
break;
} else { // starting math environment
parsingMathEnvironment=true;
nl->addNode(new JKQTMathTextInstruction1Node(this, "equation", parseLatexString(true)));
nl->addChild(new JKQTMathTextInstruction1Node(this, "equation", parseLatexString(true)));
}
}
if (getNew) getToken();
}
//std::cout<<" leaving parseLatexString()\n";
return JKQTMathTextListNode::simplyfyListNode(nl);
return simplifyJKQTMathTextNode(nl);
}

View File

@ -42,7 +42,7 @@
class JKQTMathTextNode; // forward
/*! \brief this class parses a LaTeX string and can then draw the contained text/equation onto a <a href="http://doc.qt.io/qt-5/qpainter.html">QPainter</a>
\ingroup jkqtmathtext
\ingroup jkqtmathtext_render
JKQTMathText is a self-contained LaTeX-renderer for Qt. It is used to renderer

View File

@ -31,7 +31,7 @@
/*! \brief A QLabel-derived class that draws an equation with LaTeX markup using JKQTMathText
\ingroup jkqtmathtext
\ingroup jkqtmathtext_widgets
\see JKQTMathText
*/

View File

@ -47,13 +47,13 @@ class JKQTMathText; // forward
/** \brief initialized Qt-ressources necessary for JKQTMathText
* \ingroup jkqtmathtext
* \ingroup jkqtmathtext_tools
*/
JKQTMATHTEXT_LIB_EXPORT void initJKQTMathTextResources();
/*! \brief represents a font specifier for JKQTMathText. The font consists of two parts: the actual font and the font used for math output (which may be empty)
\ingroup jkqtmathtext
\ingroup jkqtmathtext_tools
\section JKQTMathTextFontSpecifier_specialNames Special FOnt Names
This object also implements replacing special font names with actual fonts. Supported special font names are:
@ -123,7 +123,7 @@ private:
/** \brief used to specify the font encoding used for drawing
* \ingroup jkqtmathtext
* \ingroup jkqtmathtext_tools
*/
enum JKQTMathTextFontEncoding {
MTFEwinSymbol, /*!< \brief This assumes that symbols shall be taken from a MS Windows style Symbol font */
@ -133,12 +133,12 @@ enum JKQTMathTextFontEncoding {
};
/** \brief convert MTfontEncoding to a string
* \ingroup jkqtmathtext
* \ingroup jkqtmathtext_tools
*/
JKQTMATHTEXT_LIB_EXPORT QString JKQTMathTextFontEncoding2String(JKQTMathTextFontEncoding e);
/** \brief types of available braces
* \ingroup jkqtmathtext
* \ingroup jkqtmathtext_tools
*/
enum JKQTMathTextBraceType {
MTBTParenthesis=0, /*!< \brief parantheses () \image html jkqtmathtext/jkqtmathtext_brace_round.png */
@ -154,22 +154,22 @@ enum JKQTMathTextBraceType {
MTBTUnknown /*!< \brief an unknown tokenName presented to TokenName2JKQTMathTextBraceType() */
};
/** \brief convert a JKQTMathTextBraceType into a string
* \ingroup jkqtmathtext
* \ingroup jkqtmathtext_tools
*/
JKQTMATHTEXT_LIB_EXPORT QString JKQTMathTextBraceType2String(JKQTMathTextBraceType type);
/** \brief convert a string \a tokenName describing a LaTeX Token or Instruction into an opening or closing JKQTMathTextBraceType
* \ingroup jkqtmathtext
* \ingroup jkqtmathtext_tools
*/
JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBraceType TokenName2JKQTMathTextBraceType(const QString& tokenName);
/** \brief convert a string \a tokenName describing a LaTeX Instruction into an opening JKQTMathTextBraceType
* \ingroup jkqtmathtext
* \ingroup jkqtmathtext_tools
*
* This returns a JKQTMathTextBraceType for which isPrintableJKQTMathTextBraceType() is \c true, or MTBTUnknown,
* never MTBTNone or MTBTAny.
*/
JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBraceType InstructionName2OpeningJKQTMathTextBraceType(const QString& tokenName);
/** \brief convert a string \a tokenName describing a LaTeX Instruction into an opening or closing JKQTMathTextBraceType
* \ingroup jkqtmathtext
* \ingroup jkqtmathtext_tools
*
* This returns a JKQTMathTextBraceType for which isPrintableJKQTMathTextBraceType() is \c true, or MTBTUnknown,
* never MTBTNone or MTBTAny.
@ -177,11 +177,11 @@ JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBraceType InstructionName2OpeningJKQTMathTex
JKQTMATHTEXT_LIB_EXPORT JKQTMathTextBraceType InstructionName2JKQTMathTextBraceType(const QString& tokenName);
/** \brief return \c true if \a type represents a printable type of brace (including MTBTNone), basically \c true
* for any JKQTMathTextBraceType that can be used as parameter to JKQTMathTextBraceNode
* \ingroup jkqtmathtext
* \ingroup jkqtmathtext_tools
*/
JKQTMATHTEXT_LIB_EXPORT bool isPrintableJKQTMathTextBraceType(JKQTMathTextBraceType type);
/** \brief returns true, if the given token/instruction-Name \a token ("{", "(", ..., "lceil", ".", ...) matches the given \a type (returns true, when \a type == MTBTAny )
* \ingroup jkqtmathtext
* \ingroup jkqtmathtext_tools
*
* This accepts TokenName2JKQTMathTextBraceType(toke)==MTBTNone for any \a type, iff \a acceptMTBTNone \a ==true.
*
@ -189,7 +189,7 @@ JKQTMATHTEXT_LIB_EXPORT bool isPrintableJKQTMathTextBraceType(JKQTMathTextBraceT
*/
JKQTMATHTEXT_LIB_EXPORT bool TokenNameMatchesJKQTMathTextBraceType(const QString &token, JKQTMathTextBraceType type, bool acceptMTBTNone, bool *tokenEqualsNone=nullptr);
/** \brief returns true, if the given instruction-Name \a token ("|", "{", ..., "lceil", ".", ...) matches the given \a type (returns true, when \a type == MTBTAny )
* \ingroup jkqtmathtext
* \ingroup jkqtmathtext_tools
*
* This accepts TokenName2JKQTMathTextBraceType(toke)==MTBTNone for any \a type, iff \a acceptMTBTNone \a ==true.
*
@ -198,7 +198,7 @@ JKQTMATHTEXT_LIB_EXPORT bool TokenNameMatchesJKQTMathTextBraceType(const QString
JKQTMATHTEXT_LIB_EXPORT bool InstructionNameMatchesJKQTMathTextBraceType(const QString &token, JKQTMathTextBraceType type, bool acceptMTBTNone, bool *tokenEqualsNone=nullptr);
/** \brief the available logical fonts (default is MTEroman)
* \ingroup jkqtmathtext
* \ingroup jkqtmathtext_tools
*/
enum JKQTMathTextEnvironmentFont {
MTEroman, /*!< \brief roman font, e.g. <code>\\rm{}</code> */
@ -215,9 +215,8 @@ enum JKQTMathTextEnvironmentFont {
};
/** \brief describes the current drawing environment (base fontname ...)
* \ingroup jkqtmathtext
* \ingroup jkqtmathtext_tools
*/
struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextEnvironment {
JKQTMathTextEnvironment();
@ -260,7 +259,7 @@ struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextEnvironment {
};
/** \brief beschreibt die Größe eines Knotens
* \ingroup jkqtmathtext
* \ingroup jkqtmathtext_tools
*/
struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextNodeSize {
JKQTMathTextNodeSize();
@ -271,7 +270,7 @@ struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextNodeSize {
};
/** \brief summarizes all information available on a font for a specific MTenvironmentFont
* \ingroup jkqtmathtext
* \ingroup jkqtmathtext_tools
* \see fontDefinitions
*/
struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextFontDefinition {
@ -293,7 +292,7 @@ struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextFontDefinition {
/** \brief create a QPainterPath for drawing horizontal braces
* \ingroup jkqtmathtext
* \ingroup jkqtmathtext_tools
*
* \image html jkqtmathtext/JKQTMathTextMakeHBracePath.png
*/
@ -301,7 +300,7 @@ JKQTMATHTEXT_LIB_EXPORT QPainterPath JKQTMathTextMakeHBracePath(double x, double
/** \brief create a QPainterPath for drawing horizontal arrows
* \ingroup jkqtmathtext
* \ingroup jkqtmathtext_tools
*
* \image html jkqtmathtext/JKQTMathTextMakeArrow.png
*/
@ -309,7 +308,7 @@ JKQTMATHTEXT_LIB_EXPORT QPainterPath JKQTMathTextMakeArrow(double x, double y, d
/** \brief create a QPainterPath for drawing horizontal double arrows
* \ingroup jkqtmathtext
* \ingroup jkqtmathtext_tools
*
* \image html jkqtmathtext/JKQTMathTextMakeDArrow.png
*/
@ -348,11 +347,11 @@ inline uint qHash(const JKQTMathTextTBRDataH& data) {
/** \brief calculates the tight bounding rectangle around \a text, uses internal hashing to not redo a calculation that has already been performed
* \ingroup jkqtmathtext
* \ingroup jkqtmathtext_tools
*/
JKQTMATHTEXT_LIB_EXPORT QRectF JKQTMathTextGetTightBoundingRect(const QFont &fm, const QString& text, QPaintDevice *pd);
/** \brief returns a copy of \a f, but with the italic-property set to \c false
* \ingroup jkqtmathtext
* \ingroup jkqtmathtext_tools
*/
JKQTMATHTEXT_LIB_EXPORT QFont JKQTMathTextGetNonItalic(const QFont& f);

View File

@ -56,7 +56,7 @@ void JKQTMathTextBraceNode::getSizeInternalAndBrace(QPainter &painter, JKQTMathT
{
const JKQTMathTextEnvironment ev=currentEv;
child->getSize(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos);
getChild()->getSize(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos);
const double cAscentAboveStrike=baselineHeight-strikeoutPos;
const double cDescentBelowStrike=overallHeight-baselineHeight+strikeoutPos;
@ -180,7 +180,7 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
painter.setPen(pold);
xnew= child->draw(painter, xnew, y, currentEv);
xnew= getChild()->draw(painter, xnew, y, currentEv);
{
bool showClosingBrace=true;
@ -283,7 +283,7 @@ bool JKQTMathTextBraceNode::toHtml(QString &html, JKQTMathTextEnvironment curren
html=html+ob;
bool ok=child->toHtml(html, currentEv, defaultEv);
bool ok=getChild()->toHtml(html, currentEv, defaultEv);
html=html+cb;

View File

@ -100,9 +100,9 @@ JKQTMathTextDecoratedNode::~JKQTMathTextDecoratedNode() {
void JKQTMathTextDecoratedNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* /*prevNodeSize*/) {
const QFontMetricsF fm(currentEv.getFont(parentMathText), painter.device());
child->getSize(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos);
getChild()->getSize(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos);
const double italic_xcorrection=getNonItalicXCorretion(painter, width, currentEv, child);
const double italic_xcorrection=getNonItalicXCorretion(painter, width, currentEv, getChild());
const double decoheightfactor=parentMathText->getDecorationHeightFactor();
const double deco_miniwidth=((decoration==MTDtilde||decoration==MTDbreve)?fm.boundingRect("~").width():fm.boundingRect("^").width())-italic_xcorrection;
@ -123,7 +123,7 @@ double JKQTMathTextDecoratedNode::draw(QPainter& painter, double x, double y, JK
doDrawBoxes(painter, x, y, currentEv);
JKQTMathTextEnvironment ev=currentEv;
double width=0, baselineHeight=0, overallHeight=0, strikeoutPos=0;
child->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos);
getChild()->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos);
const QFont font=ev.getFont(parentMathText);
const QFontMetricsF fm(font, painter.device());
const double width_X=fm.boundingRect("X").width();
@ -135,7 +135,7 @@ double JKQTMathTextDecoratedNode::draw(QPainter& painter, double x, double y, JK
const double strike_ypos=y-baselineHeight/2.0;
const double decobelow_ypos=y+qMax((overallHeight-baselineHeight)*(1.0+decoheightfactor), fm.xHeight()*decoheightfactor);
const double deco_height=decoheightfactor*baselineHeight;
const double italic_xcorrection=getNonItalicXCorretion(painter, width, ev, child);
const double italic_xcorrection=getNonItalicXCorretion(painter, width, ev, getChild());
const double deco_xoffset=parentMathText->getDecorationWidthReductionXFactor()*width_X/2.0;
const double deco_width=std::max<double>(width_x*0.5,width-2.0*deco_xoffset-italic_xcorrection);
const double deco_vecwidth=width_x*0.33;
@ -154,7 +154,7 @@ double JKQTMathTextDecoratedNode::draw(QPainter& painter, double x, double y, JK
p.setColor(ev.color);
p.setWidthF(qMax(parentMathText->ABS_MIN_LINEWIDTH, fm.lineWidth()));//ceil(currentEv.fontSize/16.0));
double xnew=child->draw(painter, x, y, ev);
double xnew=getChild()->draw(painter, x, y, ev);
if (decoration==MTDvec) {
painter.setPen(p);

View File

@ -61,7 +61,7 @@ void JKQTMathTextInstruction1Node::getSizeInternal(QPainter& painter, JKQTMathTe
setupMTenvironment(ev);
child->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos);
getChild()->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos);
if (name=="colorbox" || name=="fbox" || name=="boxed") {
QFontMetricsF fm(ev.getFont(parentMathText));
double xw=fm.boundingRect("x").width();
@ -84,7 +84,7 @@ double JKQTMathTextInstruction1Node::draw(QPainter& painter, double x, double y,
if (name=="colorbox") fcol=QColor(parameters.value(0, ev.color.name()));
//qDebug()<<"COLOR="<<fcol;
double width, baselineHeight, overallHeight, strikeoutPos;
child->getSize(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos);
getChild()->getSize(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos);
QPen p=painter.pen();
QFontMetricsF fm(currentEv.getFont(parentMathText));
double xw=fm.boundingRect("x").width();
@ -94,7 +94,7 @@ double JKQTMathTextInstruction1Node::draw(QPainter& painter, double x, double y,
shiftX=xw/2.0;
}
double xnew= child->draw(painter, x+shiftX, y, ev);
double xnew= getChild()->draw(painter, x+shiftX, y, ev);
painter.setPen(oldPen);
return xnew;
}
@ -104,7 +104,7 @@ bool JKQTMathTextInstruction1Node::toHtml(QString &html, JKQTMathTextEnvironment
setupMTenvironment(ev);
return child->toHtml(html, ev, defaultEv);
return getChild()->toHtml(html, ev, defaultEv);
}
QString JKQTMathTextInstruction1Node::getName() const {

View File

@ -43,7 +43,7 @@ QSet<QString> JKQTMathTextListNode::subsupOperations= (QSet<QString>()<<"sum"<<"
<<"liminf"<<"limsup"<<"lim"<<"max"<<"min");
JKQTMathTextListNode::JKQTMathTextListNode(JKQTMathText* _parent):
JKQTMathTextNode(_parent)
JKQTMathTextMultiChildNode(_parent)
{
nodes.clear();
// these operations cause sub/sup script to be typeset over/under the operator, not right besides!
@ -411,7 +411,7 @@ double JKQTMathTextListNode::draw(QPainter& painter, double x, double y, JKQTMat
return xnew;
}
void JKQTMathTextListNode::addNode(JKQTMathTextNode *n) {
void JKQTMathTextListNode::addChild(JKQTMathTextNode *n) {
n->setParentNode(this);
nodes.append(n);
}
@ -426,27 +426,16 @@ bool JKQTMathTextListNode::toHtml(QString &html, JKQTMathTextEnvironment current
return ok;
}
void JKQTMathTextListNode::setDrawBoxes(bool draw)
{
this->drawBoxes=draw;
for (int i=0; i<nodes.size(); i++) {
nodes[i]->setDrawBoxes(draw);
}
}
QList<JKQTMathTextNode *> JKQTMathTextListNode::getNodes() const {
QList<JKQTMathTextNode *> JKQTMathTextListNode::getChildren() {
return this->nodes;
}
int JKQTMathTextListNode::count() const
int JKQTMathTextListNode::childCount() const
{
return nodes.size();
}
int JKQTMathTextListNode::size() const
{
return nodes.size();
}
void JKQTMathTextListNode::clearChildren(bool deleteChildren)
{
@ -458,27 +447,21 @@ void JKQTMathTextListNode::clearChildren(bool deleteChildren)
nodes.clear();
}
JKQTMathTextNode *JKQTMathTextListNode::child(int i)
JKQTMathTextNode *JKQTMathTextListNode::getChild(int i)
{
return nodes[i];
}
const JKQTMathTextNode *JKQTMathTextListNode::child(int i) const
const JKQTMathTextNode *JKQTMathTextListNode::getChild(int i) const
{
return nodes[i];
}
JKQTMathTextNode *JKQTMathTextListNode::simplyfyListNode(JKQTMathTextListNode *nl) {
return nl;
if (nl==nullptr) return nl;
if (nl->count()==1) {
// if there was only a single node: simplify the syntax tree, by removing the outer list node
JKQTMathTextNode* ret= nl->child(0);
nl->clearChildren(false);
delete nl;
return ret;
}
return nl;
JKQTMathTextNode *JKQTMathTextListNode::replaceChild(int i, JKQTMathTextNode *newChild)
{
JKQTMathTextNode* c=nodes[i];
nodes[i]=newChild;
newChild->setParentNode(this);
return c;
}

View File

@ -35,7 +35,7 @@ class JKQTMathText; // forward
/** \brief subclass representing a list of nodes in the syntax tree
* \ingroup jkqtmathtext_items
*/
class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextListNode: public JKQTMathTextNode {
class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextListNode: public JKQTMathTextMultiChildNode {
public:
explicit JKQTMathTextListNode(JKQTMathText* parent);
virtual ~JKQTMathTextListNode() override;
@ -43,26 +43,22 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextListNode: public JKQTMathTextNode {
virtual QString getTypeName() const override;
/** \copydoc JKQTMathTextNode::draw() */
virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override;
/** \brief add a child node */
void addNode(JKQTMathTextNode* n);
/** \copydoc JKQTMathTextNode::toHtml() */
virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) override;
/** \copydoc JKQTMathTextNode::setDrawBoxes() */
virtual void setDrawBoxes(bool draw) override;
/** \copydoc nodes */
QList<JKQTMathTextNode*> getNodes() const;
/** \brief return number of children */
int count() const;
/** \brief return number of children */
int size() const;
/** \brief clear all children, deleting them if \a deleteChildren==true */
void clearChildren(bool deleteChildren=true);
/** \brief return i-th child node */
JKQTMathTextNode* child(int i);
/** \brief return i-th child node */
const JKQTMathTextNode* child(int i) const;
/** \brief simplifies the given list-node, i.e. if it contains one child only, the child is returned and the list node destroyed, otherwise the list node \a nl is returned */
static JKQTMathTextNode* simplyfyListNode(JKQTMathTextListNode* nl);
/** \brief add a child node */
void addChild(JKQTMathTextNode* n);
/** \copydoc JKQTMathTextMultiChildNode::getChildren() */
virtual QList<JKQTMathTextNode*> getChildren() override;
/** \copydoc JKQTMathTextMultiChildNode::childCount() */
virtual int childCount() const override;
/** \copydoc JKQTMathTextMultiChildNode::clearChildren() */
virtual void clearChildren(bool deleteChildren=true) override;
/** \copydoc JKQTMathTextMultiChildNode::getChild() */
virtual JKQTMathTextNode* getChild(int i) override;
/** \copydoc JKQTMathTextMultiChildNode::getChild() */
virtual const JKQTMathTextNode* getChild(int i) const override;
/** \copydoc JKQTMathTextMultiChildNode::getChild() */
virtual JKQTMathTextNode* replaceChild(int i, JKQTMathTextNode* newChild) override;
protected:
/** \copydoc JKQTMathTextNode::getSizeInternal() */
virtual void getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* prevNodeSize=nullptr) override;

View File

@ -149,7 +149,8 @@ JKQTMathTextSingleChildNode::JKQTMathTextSingleChildNode(JKQTMathTextNode *_chil
JKQTMathTextSingleChildNode::~JKQTMathTextSingleChildNode()
{
if (child) delete child;
JKQTMathTextNode* c=child; child=nullptr;
if (c) delete c;
}
JKQTMathTextNode *JKQTMathTextSingleChildNode::getChild()
@ -162,6 +163,28 @@ const JKQTMathTextNode *JKQTMathTextSingleChildNode::getChild() const
return child;
}
JKQTMathTextNode *JKQTMathTextSingleChildNode::replaceChild(JKQTMathTextNode *newChild)
{
JKQTMathTextNode* c=child;
child=newChild;
child->setParentNode(this);
return c;
}
void JKQTMathTextSingleChildNode::replaceAndDeleteChild(JKQTMathTextNode *newChild)
{
JKQTMathTextNode* oldC=replaceChild(newChild);
if (newChild!=oldC) {
oldC->setParentNode(nullptr);
delete oldC;
}
}
bool JKQTMathTextSingleChildNode::hasChild() const
{
return child!=nullptr;
}
void JKQTMathTextSingleChildNode::setDrawBoxes(bool draw)
{
JKQTMathTextNode::setDrawBoxes(draw);
@ -170,7 +193,7 @@ void JKQTMathTextSingleChildNode::setDrawBoxes(bool draw)
JKQTMathTextDualChildNode::JKQTMathTextDualChildNode(JKQTMathTextNode *_child1, JKQTMathTextNode *_child2, JKQTMathText *parentMathText):
JKQTMathTextNode(parentMathText),
JKQTMathTextMultiChildNode(parentMathText),
child1(_child1),
child2(_child2)
{
@ -180,8 +203,10 @@ JKQTMathTextDualChildNode::JKQTMathTextDualChildNode(JKQTMathTextNode *_child1,
JKQTMathTextDualChildNode::~JKQTMathTextDualChildNode()
{
if (child1) delete child1;
if (child2) delete child2;
JKQTMathTextNode* c1=child1; child1=nullptr;
JKQTMathTextNode* c2=child2; child2=nullptr;
if (c1) delete c1;
if (c2) delete c2;
}
JKQTMathTextNode *JKQTMathTextDualChildNode::getChild1()
@ -204,9 +229,94 @@ const JKQTMathTextNode *JKQTMathTextDualChildNode::getChild2() const
return child2;
}
void JKQTMathTextDualChildNode::setDrawBoxes(bool draw)
JKQTMathTextNode *JKQTMathTextDualChildNode::getChild(int i)
{
if (i==0) return child1;
if (i==1) return child2;
return nullptr;
}
const JKQTMathTextNode *JKQTMathTextDualChildNode::getChild(int i) const
{
if (i==0) return child1;
if (i==1) return child2;
return nullptr;
}
JKQTMathTextNode *JKQTMathTextDualChildNode::replaceChild(int i, JKQTMathTextNode *newChild)
{
if (i==0) {
JKQTMathTextNode* c=child1;
child1=newChild;
child1->setParentNode(this);
return c;
}
if (i==1) {
JKQTMathTextNode* c=child2;
child2=newChild;
child2->setParentNode(this);
return c;
}
return nullptr;
}
int JKQTMathTextDualChildNode::childCount() const
{
return 2;
}
void JKQTMathTextDualChildNode::clearChildren(bool deleteChildren)
{
JKQTMathTextNode* c1=child1; child1=nullptr;
if (c1) delete c1;
JKQTMathTextNode* c2=child2; child2=nullptr;
if (c2) delete c2;
}
JKQTMathTextMultiChildNode::JKQTMathTextMultiChildNode(JKQTMathText *parentMathText):
JKQTMathTextNode(parentMathText)
{
}
JKQTMathTextMultiChildNode::~JKQTMathTextMultiChildNode()
{
}
QList<JKQTMathTextNode *> JKQTMathTextMultiChildNode::getChildren()
{
QList<JKQTMathTextNode *> l;
for (int i=0; i<childCount(); i++) {
l.append(getChild(i));
}
return l;
}
QList<const JKQTMathTextNode *> JKQTMathTextMultiChildNode::getChildren() const
{
QList<const JKQTMathTextNode *> l;
for (int i=0; i<childCount(); i++) {
l.append(getChild(i));
}
return l;
}
void JKQTMathTextMultiChildNode::replaceAndDeleteChild(int i, JKQTMathTextNode *newChild)
{
JKQTMathTextNode* oldC=replaceChild(i, newChild);
if (newChild!=oldC) {
oldC->setParentNode(nullptr);
delete oldC;
}
}
void JKQTMathTextMultiChildNode::setDrawBoxes(bool draw)
{
JKQTMathTextNode::setDrawBoxes(draw);
if (child1) child1->setDrawBoxes(draw);
if (child2) child2->setDrawBoxes(draw);
for (int i=0; i<childCount(); i++) {
JKQTMathTextNode* c=getChild(i);
if (c) c->setDrawBoxes(draw);
}
}

View File

@ -156,6 +156,15 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextSingleChildNode: public JKQTMathTextNo
JKQTMathTextNode* getChild();
/** \copydoc child */
const JKQTMathTextNode* getChild() const;
/** \brief replaces the child node with the node \a newChild , returns the replaced old node */
JKQTMathTextNode* replaceChild(JKQTMathTextNode* newChild);
/** \brief replaces the child node with the node \a newChild , deletes the replaced old node */
void replaceAndDeleteChild(JKQTMathTextNode* newChild);
/** \brief returns \c true if the child is valie (\c !=nullptr ) */
bool hasChild() const;
/** \copydoc JKQTMathTextNode::setDrawBoxes() */
virtual void setDrawBoxes(bool draw) override;
protected:
@ -166,7 +175,41 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextSingleChildNode: public JKQTMathTextNo
/** \brief subclass representing a node in the syntax tree, that has two children
* \ingroup jkqtmathtext_items
*/
class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextDualChildNode: public JKQTMathTextNode {
class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextMultiChildNode: public JKQTMathTextNode {
public:
explicit JKQTMathTextMultiChildNode(JKQTMathText* parentMathText);
virtual ~JKQTMathTextMultiChildNode() override;
/** \brief returns a list of all child node */
virtual QList<JKQTMathTextNode*> getChildren();
/** \brief returns a list of all child node */
virtual QList<const JKQTMathTextNode*> getChildren() const;
/** \brief returns the i-th child node */
virtual JKQTMathTextNode* getChild(int i)=0;
/** \brief returns the i-th child node */
virtual const JKQTMathTextNode* getChild(int i) const=0;
/** \brief replaces the i-th child node with the node \a newChild , returns the replaced old node */
virtual JKQTMathTextNode* replaceChild(int i, JKQTMathTextNode* newChild) =0;
/** \brief replaces the i-th child node with the node \a newChild , deletes the replaced old node */
virtual void replaceAndDeleteChild(int i, JKQTMathTextNode* newChild);
/** \brief returns the number of child nodes */
virtual int childCount() const =0;
/** \brief clear all children, deleting them if \a deleteChildren==true */
virtual void clearChildren(bool deleteChildren=true) =0;
/** \copydoc JKQTMathTextNode::setDrawBoxes() */
virtual void setDrawBoxes(bool draw) override;
protected:
};
/** \brief subclass representing a node in the syntax tree, that has two children
* \ingroup jkqtmathtext_items
*/
class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextDualChildNode: public JKQTMathTextMultiChildNode {
public:
explicit JKQTMathTextDualChildNode(JKQTMathTextNode* _child1, JKQTMathTextNode* _child2, JKQTMathText* parentMathText);
virtual ~JKQTMathTextDualChildNode() override;
@ -179,8 +222,19 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextDualChildNode: public JKQTMathTextNode
JKQTMathTextNode* getChild2();
/** \copydoc child2 */
const JKQTMathTextNode* getChild2() const;
/** \copydoc JKQTMathTextNode::setDrawBoxes() */
virtual void setDrawBoxes(bool draw) override;
/** \copydoc JKQTMathTextMultiChildNode::getChild() */
virtual JKQTMathTextNode* getChild(int i) override;
/** \copydoc JKQTMathTextMultiChildNode::getChild() */
virtual const JKQTMathTextNode* getChild(int i) const override;
/** \copydoc JKQTMathTextMultiChildNode::getChild() */
virtual JKQTMathTextNode* replaceChild(int i, JKQTMathTextNode* newChild) override;
/** \copydoc JKQTMathTextMultiChildNode::getChild() */
virtual int childCount() const override;
/** \copydoc JKQTMathTextMultiChildNode::getChild() */
virtual void clearChildren(bool deleteChildren=true) override;
protected:
/** \brief first child node of this node */
JKQTMathTextNode* child1;

View File

@ -0,0 +1,67 @@
/*
Copyright (c) 2008-2022 Jan W. Krieger (<jan@jkrieger.de>)
This software is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License (LGPL) as published by
the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License (LGPL) for more details.
You should have received a copy of the GNU Lesser General Public License (LGPL)
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "jkqtmathtext/nodes/jkqtmathtextnodetools.h"
#include "jkqtmathtext/nodes/jkqtmathtextlistnode.h"
#include "jkqtmathtext/jkqtmathtexttools.h"
#include "jkqtmathtext/jkqtmathtext.h"
#include <QDebug>
JKQTMathTextNode *simplifyJKQTMathTextNode(JKQTMathTextNode *node)
{
JKQTMathTextListNode* nl=dynamic_cast<JKQTMathTextListNode*>(node);
JKQTMathTextMultiChildNode* nmc=dynamic_cast<JKQTMathTextMultiChildNode*>(node);
JKQTMathTextSingleChildNode* nsc=dynamic_cast<JKQTMathTextSingleChildNode*>(node);
if (nl) {
if (nl->childCount()==1) {
// if there was only a single node: simplify the syntax tree, by removing the outer list node
JKQTMathTextNode* ret= simplifyJKQTMathTextNode(nl->getChild(0));
nl->clearChildren(false);
ret->setParentNode(nullptr);
delete nl;
return ret;
} else if (nl->childCount()>1) {
// if there are several child nodes, apply this method recursively
for (int i=0; i<nl->childCount(); i++) {
JKQTMathTextNode* c=nl->getChild(i);
JKQTMathTextNode* newc= simplifyJKQTMathTextNode(c);
if (c!=newc) nl->replaceAndDeleteChild(i, newc);
}
return nl;
}
return nl;
} else if (nmc) {
// apply this method recursively to any children
for (int i=0; i<nmc->childCount(); i++) {
JKQTMathTextNode* c=nmc->getChild(i);
JKQTMathTextNode* newc= simplifyJKQTMathTextNode(c);
if (c!=newc) nmc->replaceAndDeleteChild(i, newc);
}
return nmc;
} else if (nsc) {
// apply this method recursively to the child
JKQTMathTextNode* c=nsc->getChild();
JKQTMathTextNode* newc= simplifyJKQTMathTextNode(c);
if (c!=newc) nsc->replaceAndDeleteChild(newc);
return nsc;
}
return node;
}

View File

@ -0,0 +1,49 @@
/*
Copyright (c) 2008-2022 Jan W. Krieger (<jan@jkrieger.de>)
with contributions from: Razi Alavizadeh
This software is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License (LGPL) as published by
the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License (LGPL) for more details.
You should have received a copy of the GNU Lesser General Public License (LGPL)
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef JKQTMATHTEXTNODETOOLS_H
#define JKQTMATHTEXTNODETOOLS_H
#include "jkqtmathtext/jkqtmathtext_imexport.h"
class JKQTMathTextNode; // forward
/** \brief simplifies the node \a node and the tree below it. You can put the return value in place of \a node after the call
* \ingroup jkqtmathtext_items
*
* Basically this takes does the following steps (recursively):
* - remove any JKQTMathTextListNode that has only one child
* .
*/
JKQTMATHTEXT_LIB_EXPORT JKQTMathTextNode* simplifyJKQTMathTextNode(JKQTMathTextNode* node);
#endif // JKQTMATHTEXTNODETOOLS_H

View File

@ -47,7 +47,7 @@ JKQTMathTextSqrtNode::~JKQTMathTextSqrtNode() {
void JKQTMathTextSqrtNode::getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, const JKQTMathTextNodeSize* /*prevNodeSize*/) {
QFontMetricsF fm(currentEv.getFont(parentMathText), painter.device());
child->getSize(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos);
getChild()->getSize(painter, currentEv, width, baselineHeight, overallHeight, strikeoutPos);
overallHeight=overallHeight*1.2;//+fm.ascent()*0.1;
baselineHeight=baselineHeight*1.2;//+fm.ascent()*0.1;
@ -57,7 +57,7 @@ void JKQTMathTextSqrtNode::getSizeInternal(QPainter& painter, JKQTMathTextEnviro
double JKQTMathTextSqrtNode::draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv, const JKQTMathTextNodeSize* /*prevNodeSize*/) {
doDrawBoxes(painter, x, y, currentEv);
double width=0, baselineHeight=0, overallHeight=0, sp=0;
child->getSize(painter, currentEv, width, baselineHeight, overallHeight, sp);
getChild()->getSize(painter, currentEv, width, baselineHeight, overallHeight, sp);
QFont f=currentEv.getFont(parentMathText);
QFont fsmall=f;
QFontMetricsF fm(f, painter.device());
@ -83,7 +83,7 @@ double JKQTMathTextSqrtNode::draw(QPainter& painter, double x, double y, JKQTMat
painter.drawText(QPointF(x+0.33*w, y-0.55*a), QLocale::c().toString(degree));
}
//painter.restore();
double xnew=child->draw(painter, x+1.2*w, y, currentEv);
double xnew=getChild()->draw(painter, x+1.2*w, y, currentEv);
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
painter.setPen(p);
if (w>0) {
@ -97,7 +97,7 @@ double JKQTMathTextSqrtNode::draw(QPainter& painter, double x, double y, JKQTMat
bool JKQTMathTextSqrtNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) {
html=html+"&radic;<span style=\"text-decoration:overline\">";
bool ok=child->toHtml(html, currentEv, defaultEv);
bool ok=getChild()->toHtml(html, currentEv, defaultEv);
html=html+"&nbsp;</span>";
return ok;
}

View File

@ -51,7 +51,7 @@ void JKQTMathTextSuperscriptNode::getSizeInternal(QPainter& painter, JKQTMathTex
const QFontMetricsF fm(currentEv.getFont(parentMathText), painter.device());
const QRectF tbr=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parentMathText), "M", painter.device());
double cstrikeoutPos=0;
child->getSize(painter, ev, width, baselineHeight, overallHeight, cstrikeoutPos);
getChild()->getSize(painter, ev, width, baselineHeight, overallHeight, cstrikeoutPos);
double shift=parentMathText->getSuperShiftFactor()*tbr.height();
if (prevNodeSize!=nullptr && prevNodeSize->baselineHeight>tbr.height()) {
@ -70,7 +70,7 @@ double JKQTMathTextSuperscriptNode::draw(QPainter& painter, double x, double y,
ev.fontSize=ev.fontSize*parentMathText->getSubsuperSizeFactor();
double cWidth, cBaselineHeight, cOverallHeight, cStrikeoutPos;
child->getSize(painter, ev, cWidth, cBaselineHeight, cOverallHeight, cStrikeoutPos);
getChild()->getSize(painter, ev, cWidth, cBaselineHeight, cOverallHeight, cStrikeoutPos);
QFontMetricsF fm(currentEv.getFont(parentMathText), painter.device());
QRectF tbr=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parentMathText), "M", painter.device());
@ -84,7 +84,7 @@ double JKQTMathTextSuperscriptNode::draw(QPainter& painter, double x, double y,
double xx=x;
if (currentEv.italic && prevNodeSize==nullptr) xx=xx+double(fm.boundingRect(' ').width())*parentMathText->getItalicCorrectionFactor();
return child->draw(painter, xx, y-yshift, ev);//+0.5*fm.boundingRect("A").width();
return getChild()->draw(painter, xx, y-yshift, ev);//+0.5*fm.boundingRect("A").width();
}
@ -97,7 +97,7 @@ QString JKQTMathTextSuperscriptNode::getTypeName() const
bool JKQTMathTextSuperscriptNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv)
{
html=html+"<sup>";
bool ok=child->toHtml(html, currentEv, defaultEv);
bool ok=getChild()->toHtml(html, currentEv, defaultEv);
html=html+"</sup>";
return ok;
}
@ -121,7 +121,7 @@ void JKQTMathTextSubscriptNode::getSizeInternal(QPainter& painter, JKQTMathTextE
JKQTMathTextEnvironment ev=currentEv;
ev.fontSize=ev.fontSize*parentMathText->getSubsuperSizeFactor();
child->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos);
getChild()->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos);
QFontMetricsF fm(ev.getFont(parentMathText), painter.device());
QRectF tbr=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parentMathText), "M", painter.device());
@ -145,7 +145,7 @@ double JKQTMathTextSubscriptNode::draw(QPainter& painter, double x, double y, JK
QRectF tbr=JKQTMathTextGetTightBoundingRect(currentEv.getFont(parentMathText), "M", painter.device());
double width=0, baselineHeight=0, overallHeight=0, strikeoutPos=0;
child->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos);
getChild()->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos);
double shift=parentMathText->getSubShiftFactor()*tbr.height();
if (prevNodeSize!=nullptr && prevNodeSize->overallHeight-prevNodeSize->baselineHeight>shift) {
@ -159,7 +159,7 @@ double JKQTMathTextSubscriptNode::draw(QPainter& painter, double x, double y, JK
//qDebug()<<"shift="<<shift<<", yshift="<<yshift;
double xx=x;
if (currentEv.italic && prevNodeSize==nullptr) xx=xx-double(fm.boundingRect(' ').width())*parentMathText->getItalicCorrectionFactor();
return child->draw(painter, xx, y+yshift, ev);//+0.5*fm.boundingRect("A").width();
return getChild()->draw(painter, xx, y+yshift, ev);//+0.5*fm.boundingRect("A").width();
}
QString JKQTMathTextSubscriptNode::getTypeName() const
@ -169,7 +169,7 @@ QString JKQTMathTextSubscriptNode::getTypeName() const
bool JKQTMathTextSubscriptNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) {
html=html+"<sub>";
bool ok=child->toHtml(html, currentEv, defaultEv);
bool ok=getChild()->toHtml(html, currentEv, defaultEv);
html=html+"</sub>";
return ok;
}

View File

@ -947,13 +947,13 @@ double JKQTMathTextSymbolNode::draw(QPainter& painter, double x, double y, JKQTM
if (props.italic>0) f.setItalic(true);
if (props.bold<0) f.setBold(false);
if (props.bold>0) f.setBold(true);
QFontMetricsF fm(f, painter.device());
QFontMetricsF fm1(f1, painter.device());
const QFontMetricsF fm(f, painter.device());
const QFontMetricsF fm1(f1, painter.device());
painter.setFont(f);
double shift=0;
if (props.extendWidthInMathmode && currentEv.insideMath) {
double origwidth=width/parentMathText->getMathoperatorWidthFactor();
const double origwidth=width/parentMathText->getMathoperatorWidthFactor();
shift=0.5*(width-origwidth);
//width=width*parent->getMathoperatorWidthFactor();
}
@ -965,15 +965,17 @@ double JKQTMathTextSymbolNode::draw(QPainter& painter, double x, double y, JKQTM
p.setWidthF(fm.lineWidth());
p.setStyle(Qt::SolidLine);
painter.setPen(p);
double xwi=fm.boundingRect("x").width();
const double xwi=fm.boundingRect("x").width();
if (!props.symbol.isEmpty()) {
// if the symbol has been recognized in the constructor: draw the symbol
painter.drawText(QPointF(x+shift, y+props.yfactor*overallHeight), props.symbol);
double xx=x+shift;
double yy=y-fm.xHeight()-(JKQTMathTextGetTightBoundingRect(f, "M", painter.device()).height()-fm.xHeight())/3.0;
QLineF l(xx, yy, xx+xwi/3.0+((currentEv.italic)?(xwi/3.0):0), yy);
if (props.drawBar&&l.length()>0) painter.drawLine(l);
if (props.drawBar) {
const double xx=x+shift;
const double yy=y-fm.xHeight()-(JKQTMathTextGetTightBoundingRect(f, "M", painter.device()).height()-fm.xHeight())/3.0;
const QLineF l(xx, yy, xx+xwi/3.0+((currentEv.italic)?(xwi/3.0):0), yy);
if (l.length()>0) painter.drawLine(l);
}
// try to draw some often used special symbols, by synthesizing them from
// standard characters in the current drawing font
} else if (symbolName=="infty") {