/* Copyright (c) 2008-2022 Jan W. Krieger () 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 . */ #include "jkqtmathtext/nodes/jkqtmathtextlistnode.h" #include "jkqtmathtext/nodes/jkqtmathtextsymbolnode.h" #include "jkqtmathtext/nodes/jkqtmathtextbracenode.h" #include "jkqtmathtext/nodes/jkqtmathtextsubsupernode.h" #include "jkqtmathtext/jkqtmathtexttools.h" #include "jkqtmathtext/jkqtmathtext.h" #include "jkqtcommon/jkqtpcodestructuring.h" #include "jkqtcommon/jkqtpstringtools.h" #include #include #include #include #include #include #include JKQTMathTextListNode::JKQTMathTextListNode(JKQTMathText* _parent): JKQTMathTextNode(_parent) { nodes.clear(); // these operations cause sub/sup script to be typeset over/under the operator, not right besides! subsupOperations<<"sum"<<"prod"<<"coprod" <<"bigcap"<<"bigcup"<<"bigvee"<<"bighat" <<"int"<<"iint"<<"iiint"<<"oint"<<"oiint"<<"oiiint" <<"mod"<<"median"<<"max"<<"min"<<"argmax"<<"argmin"<<"sup"<<"inf" <<"liminf"<<"limsup"<<"lim"<<"max"<<"min"; } JKQTMathTextListNode::~JKQTMathTextListNode() { for (int i=0; igetTightBoundingRect(currentEv.getFont(parent), "M", painter.device()); double xnew=0; bool wasBrace=false; for (int i=0; i0 && wasBrace) { nodes[i-1]->getSize(painter, currentEv, prevNodeSize.width, prevNodeSize.baselineHeight, prevNodeSize.overallHeight, prevNodeSize.strikeoutPos); prevNodeSizePtr=&prevNodeSize; } bool doDraw=true; JKQTMathTextSymbolNode* smb=dynamic_cast(nodes[i]); // if we find a subscript/superscript node we check whether the next node is super/subscript // if so, we typeset them at the same x-psotion, so sub/superscripts appear correctly if (dynamic_cast(nodes[i])) { if (i+1(nodes[i+1])) { // is this subscript? double w1, w2, oh, bh, sp; nodes[i]->getSize(painter, currentEv, w1, bh, oh, sp, prevNodeSizePtr); if (bh>baselineHeight) { overallHeight=overallHeight+bh-baselineHeight; baselineHeight=bh; strikeoutPos=sp; } if (baselineHeight+oh-bh>overallHeight) { overallHeight=baselineHeight+oh-bh; strikeoutPos=sp; } i++; nodes[i]->getSize(painter, currentEv, w2, bh, oh, sp, prevNodeSizePtr); //qDebug()<<"super_sub: sub: "<getTypeName()<<" w2="<getOperatorsubsuperSizeFactor(); double w1=0, w2=0, w3=0; double oh1=0, oh2=0, oh3=0; double bh1=0, bh2=0, bh3=0; double sp1=0, sp2=0, sp3=0; nodes[i]->getSize(painter, currentEv, w1, bh1, oh1, sp1); //qDebug()<<"sub_super: node: "<getTypeName()<<" w1="<getTypeName()<<" w2="<getTypeName()<<" w3="<getOperatorsubsuperSizeFactor(); double w1=0, w2=0; double oh1=0, oh2=0; double bh1=0, bh2=0; double sp1=0, sp2=0;//, sp3=0; nodes[i]->getSize(painter, currentEv, w1, bh1, oh1, sp1); subn->getChild()->getSize(painter, ev, w2, bh2, oh2, sp2); //double d1=oh1-bh1; //double d2=oh2-bh2; double oh=oh1+oh2; double sh=oh1-bh1+oh2*1.1; if (oh>overallHeight) overallHeight=oh; if (bh1>baselineHeight) baselineHeight=bh1; if (sh>overallHeight-baselineHeight) { overallHeight=baselineHeight+sh; } double w=qMax(w1, w2)+fm.boundingRect(' ').width(); i++; doDraw=false; xnew+=w; //qDebug()<<"### subsupop: sub overallHeight="<0 && wasBrace) { nodes[i-1]->getSize(painter, currentEv, prevNodeSize.width, prevNodeSize.baselineHeight, prevNodeSize.overallHeight, prevNodeSize.strikeoutPos); prevNodeSizePtr=&prevNodeSize; } JKQTMathTextSymbolNode* smb=dynamic_cast(nodes[i]); // if we find a subscript/superscript node we check whether the next node is super/subscript // if so, we typeset them at the same x-psotion, so sub/superscripts appear correctly if (dynamic_cast(nodes[i])) { if (i+1(nodes[i+1])) { // is this subscript? //painter.setPen(QPen("red")); //painter.drawEllipse(xnew-4,ynew+shift-(ccOverallHeight-ccBaselineHeight)-4,8,8); double xnew1=nodes[i]->draw(painter, xnew, ynew, currentEv, prevNodeSizePtr); i++; //painter.setPen(QPen("magenta")); //painter.drawEllipse(xnew-4,ynew-4,8,8); double xnew2=nodes[i]->draw(painter, xnew, ynew, currentEv, prevNodeSizePtr); //i++; xnew=qMax(xnew1, xnew2); doDraw=false; } } } else if (dynamic_cast(nodes[i])) { if (i+1(nodes[i+1])) { // is this subscript? //painter.setPen(QPen("red")); //painter.drawEllipse(xnew-4,ynew+shift-(ccOverallHeight-ccBaselineHeight)-4,8,8); double xnew1=nodes[i]->draw(painter, xnew, ynew, currentEv, prevNodeSizePtr); i++; //painter.setPen(QPen("magenta")); //painter.drawEllipse(xnew-4,ynew-4,8,8); double xnew2=nodes[i]->draw(painter, xnew, ynew, currentEv, prevNodeSizePtr); //i++; xnew=qMax(xnew1, xnew2); doDraw=false; } } } else { if (smb) { QString s=smb->getSymbolName(); if (subsupOperations.contains(s)) { JKQTMathTextSubscriptNode* subn=nullptr; if (i+1(nodes[i+1]); JKQTMathTextSuperscriptNode* supn=nullptr; if (i+2(nodes[i+2]); //std::cout<<"symbol ='"<getOperatorsubsuperSizeFactor(); double w1=0, w2=0, w3=0; double oh1=0, oh2=0, oh3=0; double bh1=0, bh2=0, bh3=0, sp; nodes[i]->getSize(painter, currentEv, w1, bh1, oh1, sp); subn->getChild()->getSize(painter, ev, w2, bh2, oh2, sp); supn->getChild()->getSize(painter, ev, w3, bh3, oh3, sp); double d1=oh1-bh1; //double d2=oh2-bh2; double d3=oh3-bh3; double w=qMax(qMax(w1, w2), w3); //double xnew1= double xn1=nodes[i]->draw(painter, xnew+(w-w1)/2.0, ynew, currentEv); i++; //double xnew2= double xn2=subn->getChild()->draw(painter, xnew+(w-w2)/2.0, ynew+bh2+d1, ev); i++; //double xnew3= double xn3=supn->getChild()->draw(painter, xnew+(w-w3)/2.0, ynew-bh1-d3-fm.xHeight()/4.0, ev); doDraw=false; xnew=qMax(qMax(xn1, xn2), xn3)+fm.boundingRect(' ').width(); } else if (subn) { // is this subscript and not superscript? JKQTMathTextEnvironment ev=currentEv; ev.fontSize=ev.fontSize*parent->getOperatorsubsuperSizeFactor(); double w1=0, w2=0; double oh1=0, oh2=0; double bh1=0, bh2=0, sp=0; nodes[i]->getSize(painter, currentEv, w1, bh1, oh1, sp); subn->getChild()->getSize(painter, ev, w2, bh2, oh2, sp); double d1=oh1-bh1; //double d2=oh2-bh2; double w=qMax(w1, w2); //double xnew1= double xn2=nodes[i]->draw(painter, xnew+(w-w1)/2.0, ynew, currentEv); i++; //double xnew2= double xn1=subn->getChild()->draw(painter, xnew+(w-w2)/2.0, ynew+bh2+d1, ev)+fm.boundingRect(' ').width(); doDraw=false; //xnew+=w; xnew=qMax(xn1, xn2); } else if (supn) { // is this subscript and superscript? JKQTMathTextEnvironment ev=currentEv; ev.fontSize=ev.fontSize*parent->getOperatorsubsuperSizeFactor(); double w1=0, w3=0; double oh1=0, oh3=0; double bh1=0, bh3=0, sp; nodes[i]->getSize(painter, currentEv, w1, bh1, oh1, sp); supn->getChild()->getSize(painter, ev, w3, bh3, oh3, sp); //double d1=oh1-bh1; //double d2=oh2-bh2; double d3=oh3-bh3; double w=qMax(w1, w3); //double xnew1= double xn1=nodes[i]->draw(painter, xnew+(w-w1)/2.0, ynew, currentEv); i++; //double xnew3= double xn3=supn->getChild()->draw(painter, xnew+(w-w3)/2.0, ynew-bh1-d3-fm.xHeight()/4.0, ev); doDraw=false; xnew=qMax(xn1, xn3)+fm.boundingRect(' ').width(); } } } } if (idraw(painter, xnew, ynew, currentEv, prevNodeSizePtr); } wasBrace=dynamic_cast(nodes[i]); } return xnew; } bool JKQTMathTextListNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) { bool ok=true; for (int i=0; itoHtml(h, currentEv, defaultEv); html=html+h; } return ok; } void JKQTMathTextListNode::setDrawBoxes(bool draw) { this->drawBoxes=draw; for (int i=0; isetDrawBoxes(draw); } } QList JKQTMathTextListNode::getNodes() const { return this->nodes; }