JKQTMathText code/documentation cleanup

This commit is contained in:
jkriege2 2022-06-20 12:17:32 +02:00
parent d8a3539844
commit 48a9a45af9
6 changed files with 61 additions and 74 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -72,19 +72,15 @@ JKQTMathText::JKQTMathText(QObject* parent):
frac_nested_factor=0.7;
frac_shift_factor=0.4;
underbrace_factor=0.75;
undersetFactor=0.7;
underset_factor=0.7;
decoration_height_factor=0.2;
decoration_width_reduction_Xfactor=0.2;
brace_y_shift_factor=0.7;//-1;
operatorsubsuper_size_factor=0.65;
mathoperator_width_factor=1.5;
expensiveRendering=true;
blackboardSimulated=true;
showLeftBrace=true;
showRightBrace=true;
static QString serifFont="serif";
static QString sansFont="sans";
@ -210,7 +206,7 @@ void JKQTMathText::loadSettings(const QSettings& settings, const QString& group)
frac_factor=settings.value(group+"frac_factor", frac_factor).toDouble();
frac_shift_factor=settings.value(group+"frac_shift_factor", frac_shift_factor).toDouble();
underbrace_factor=settings.value(group+"underbrace_factor", underbrace_factor).toDouble();
undersetFactor=settings.value(group+"undersetFactor", undersetFactor).toDouble();
underset_factor=settings.value(group+"undersetFactor", underset_factor).toDouble();
brace_y_shift_factor=settings.value(group+"brace_y_shift_factor", brace_y_shift_factor).toDouble();
decoration_height_factor=settings.value(group+"decoration_height_factor", decoration_height_factor).toDouble();
decoration_width_reduction_Xfactor=settings.value(group+"decoration_width_reduction_xfactor", decoration_width_reduction_Xfactor).toDouble();
@ -236,7 +232,7 @@ void JKQTMathText::saveSettings(QSettings& settings, const QString& group) const
settings.setValue(group+ "frac_factor", frac_factor);
settings.setValue(group+ "frac_shift_factor", frac_shift_factor);
settings.setValue(group+ "underbrace_factor", underbrace_factor);
settings.setValue(group+ "undersetFactor", undersetFactor);
settings.setValue(group+ "undersetFactor", underset_factor);
settings.setValue(group+ "operatorsubsuper_size_factor", operatorsubsuper_size_factor);
settings.setValue(group+ "mathoperator_width_factor", mathoperator_width_factor);
settings.setValue(group+ "brace_y_shift_factor", brace_y_shift_factor);
@ -261,7 +257,6 @@ bool JKQTMathText::useSTIX(bool mathModeOnly) {
res=true;
}
brace_shrink_factor=0.6;
return res;
}
@ -275,14 +270,12 @@ bool JKQTMathText::useXITS(bool mathModeOnly)
setFontRoman(xits.fontName(), MTFEunicode);
setSymbolfontSymbol(xits.fontName(), MTFEunicode);
setSymbolfontGreek(xits.fontName(), MTFEunicode);
brace_shrink_factor=0.6;
res=true;
}
if (!xits.mathFontName().isEmpty()) {
setFontMathRoman(xits.mathFontName(), MTFEunicode);
setSymbolfontSymbol(xits.fontName(), MTFEunicode);
setSymbolfontGreek(xits.fontName(), MTFEunicode);
brace_shrink_factor=0.6;
res=true;
}
@ -304,7 +297,6 @@ bool JKQTMathText::useASANA(bool mathModeOnly)
res=true;
}
brace_shrink_factor=0.6;
return res;
}
@ -312,14 +304,13 @@ void JKQTMathText::useAnyUnicode(QString timesFont, const QString &sansFont, JKQ
{
if (!timesFont.isEmpty()) { setFontRoman(timesFont, encodingTimes); }
if (!sansFont.isEmpty()) { setFontSans(sansFont, encodingSans); }
brace_shrink_factor=0.6;
}
QString JKQTMathText::toHtml(bool *ok, double fontPointSize) {
QString s;
bool okk=false;
if (getTree()!=nullptr) {
if (getNodeTree()!=nullptr) {
JKQTMathTextEnvironment ev;
ev.color=fontColor;
ev.fontSize=fontPointSize;
@ -327,7 +318,7 @@ QString JKQTMathText::toHtml(bool *ok, double fontPointSize) {
JKQTMathTextEnvironment defaultev;
defaultev.fontSize=fontPointSize;
okk=getTree()->toHtml(s, ev, defaultev);
okk=getNodeTree()->toHtml(s, ev, defaultev);
}
if (ok) *ok=okk;
return s;
@ -720,12 +711,12 @@ double JKQTMathText::getUnderbraceFactor() const
void JKQTMathText::setUndersetFactor(double __value)
{
this->undersetFactor = __value;
this->underset_factor = __value;
}
double JKQTMathText::getUndersetFactor() const
{
return this->undersetFactor;
return this->underset_factor;
}
void JKQTMathText::setFracFactor(double __value)
@ -788,16 +779,6 @@ double JKQTMathText::getDecorationWidthReductionXFactor() const
return decoration_width_reduction_Xfactor;
}
void JKQTMathText::setExpensiveRendering(bool __value)
{
this->expensiveRendering = __value;
}
bool JKQTMathText::getExpensiveRendering() const
{
return this->expensiveRendering;
}
void JKQTMathText::setUseUnparsed(bool __value)
{
this->useUnparsed = __value;
@ -1227,10 +1208,6 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, JKQTMathTextBraceType
bool tokenWasNoBrace=false;
const QString firstTokenChar(currentTokenName[0]);
if (TokenNameMatchesJKQTMathTextBraceType(firstTokenChar, quitOnClosingBrace, true, &tokenWasNoBrace)) {
//std::cout<<"found \\right '"<<currentTokenName.toStdString()<<"'\n";
showLeftBrace=(quitOnClosingBrace==MTBTAny || quitOnClosingBrace!=MTBTNone);
showRightBrace=!tokenWasNoBrace;
//if (!showRightBrace) std::cout<<"don't show right brace '"<<quitOnClosingBrace.toStdString()<<"' !!!\n";
if (quitOnClosingBrace!=MTBTAny) currentTokenName=currentTokenName.right(currentTokenName.size()-1);
break;
} else {
@ -1430,7 +1407,7 @@ bool JKQTMathText::parse(const QString& text, bool addSpaceBeforeAndAfter){
QSizeF JKQTMathText::getSize(QPainter& painter){
if (getTree()!=nullptr) {
if (getNodeTree()!=nullptr) {
double w=0, a=0, d=0, s=0;
getSizeDetail(painter, w, a, d, s);
return QSizeF(w, a+d);
@ -1455,13 +1432,13 @@ void JKQTMathText::getSizeDetail(QPainter& painter, double& width, double& ascen
ascent=0;
descent=0;
strikeoutPos=0;
if (getTree()!=nullptr) {
if (getNodeTree()!=nullptr) {
JKQTMathTextEnvironment ev;
ev.color=fontColor;
ev.fontSize=fontSize;
double overallHeight=0;
getTree()->getSize(painter, ev, width, ascent, overallHeight, strikeoutPos);
getNodeTree()->getSize(painter, ev, width, ascent, overallHeight, strikeoutPos);
descent=overallHeight-ascent;
ascent=ascent*1.1;
descent=qMax(ascent*0.1, descent*1.1);
@ -1470,7 +1447,7 @@ void JKQTMathText::getSizeDetail(QPainter& painter, double& width, double& ascen
}
void JKQTMathText::draw(QPainter& painter, double x, double y, bool drawBoxes){
if (getTree()!=nullptr) {
if (getNodeTree()!=nullptr) {
JKQTMathTextEnvironment ev;
ev.color=fontColor;
ev.fontSize=fontSize;
@ -1478,15 +1455,15 @@ void JKQTMathText::draw(QPainter& painter, double x, double y, bool drawBoxes){
QPen p=pp;
p.setStyle(Qt::SolidLine);
painter.setPen(p);
getTree()->setDrawBoxes(drawBoxes);
getNodeTree()->setDrawBoxes(drawBoxes);
painter.setPen(p);
getTree()->draw(painter, x, y, ev);
getNodeTree()->draw(painter, x, y, ev);
painter.setPen(pp);
}
}
void JKQTMathText::draw(QPainter& painter, unsigned int flags, QRectF rect, bool drawBoxes) {
if (getTree()!=nullptr) {
if (getNodeTree()!=nullptr) {
QPen pp=painter.pen();
QPen p=pp;
p.setStyle(Qt::SolidLine);
@ -1494,13 +1471,13 @@ void JKQTMathText::draw(QPainter& painter, unsigned int flags, QRectF rect, bool
JKQTMathTextEnvironment ev;
ev.color=fontColor;
ev.fontSize=fontSize;
getTree()->setDrawBoxes(drawBoxes);
getNodeTree()->setDrawBoxes(drawBoxes);
painter.setPen(p);
double width=0;
double baselineHeight=0;
double overallHeight=0, strikeoutPos=0;
getTree()->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos);
getNodeTree()->getSize(painter, ev, width, baselineHeight, overallHeight, strikeoutPos);
// align left top
double x=rect.left();
@ -1515,13 +1492,13 @@ void JKQTMathText::draw(QPainter& painter, unsigned int flags, QRectF rect, bool
else if ((flags & Qt::AlignVCenter) != 0) y=y+(rect.height()-overallHeight)/2.0;
// finally draw
getTree()->draw(painter, x, y, ev);
getNodeTree()->draw(painter, x, y, ev);
painter.setPen(pp);
}
}
JKQTMathTextNode *JKQTMathText::getTree() const {
JKQTMathTextNode *JKQTMathText::getNodeTree() const {
if (useUnparsed) return unparsedNode;
return parsedNode;
}

View File

@ -493,10 +493,6 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
void setDecorationWidthReductionXFactor(double __value);
/** \copydoc decoration_width_reduction_Xfactor */
double getDecorationWidthReductionXFactor() const;
/** \copydoc expensiveRendering */
void setExpensiveRendering(bool __value);
/** \copydoc expensiveRendering */
bool getExpensiveRendering() const;
/** \copydoc useUnparsed */
void setUseUnparsed(bool __value);
/** \copydoc useUnparsed */
@ -535,28 +531,49 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
double subsuper_size_factor;
/** \brief fraction of a whitespace by which to shift a sub-/superscript left/right when the previous text is italic */
double italic_correction_factor;
/** \brief like subsuper_size_factor, but for operators (\\sum, \\int) where the text is placed above/below the symbol */
/** \brief like subsuper_size_factor, but for operators (\C \\sum , \c \\int , ...) where the text is placed above/below the symbol */
double operatorsubsuper_size_factor;
/** \brief factor, used to extend the size of an operator in math mode */
/** \brief factor, used to extend the size of an operator in math mode
*
* The next image demonstrates the effect of this property, which adds extra space
* around certain math operators in math mode:
*
* \image html jkqtmathparser_mathoperator_width_factor.png
*/
double mathoperator_width_factor;
/** \brief relative shift of text in superscript to normal text:
* 0= baseline kept, 1: baseline shifted to top of normal text */
* 0= baseline kept, 1: baseline shifted to top of normal text
*
* \image html jkqtmathtext_superscriptnode_getSizeInternal.png
*/
double super_shift_factor;
/** \brief relative shift of text in subscript to normal text:
* 0= baseline kept, 1: baseline shifted to bottom of normal text */
* 0= baseline kept, 1: baseline shifted to bottom of normal text
*
* \image html jkqtmathtext_subscriptnode_getSizeInternal.png
*/
double sub_shift_factor;
/** \brief scaling factor for font size of nominator and denominator of a fraction */
/** \brief scaling factor for font size of nominator and denominator of a fraction
*
* \image html jkqtmathtext_frac_factor.png
*/
double frac_factor;
/** \brief scaling factor for font size of nominator and denominator of a nested fraction */
/** \brief scaling factor for font size of nominator and denominator of a nested fraction
*
* \image html jkqtmathtext_frac_factor.png
*/
double frac_nested_factor;
/** \brief shift of denominator/nummerator away from central line of a frac */
/** \brief shift of denominator/nummerator away from central line of a frac
*
* \image html jkqtmathtext_fracnode_geo.png
*/
double frac_shift_factor;
/** \brief scaling factor for font of underbrace/overbrace text */
double underbrace_factor;
/** \brief scaling factor for font of underset/overset text */
double undersetFactor;
double underset_factor;
/** \brief fraction of the brace ascent that the brace is shifted downwards, when scaled */
double brace_y_shift_factor;
/** \brief size of the decorations (dot, tilde, ...), as fraction of the baselineheight
@ -569,14 +586,8 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
* \image html jkqtmathtext/decoration_sizing.png
*/
double decoration_width_reduction_Xfactor;
/** \brief switches on some options that will grant better rendering at the expense of higher time consumption */
bool expensiveRendering;
/** \brief a list that will be filled with error messages while parsing, if any error occur */
QStringList error_list;
/** \brief used by the parser. This is used to implement brace pairs with \\right. */
bool showRightBrace;
/** \brief used by the parser. This is used to implement brace pairs with \\left. */
bool showLeftBrace;
/** \brief the result of parsing the last string supplied to the object via parse() */
JKQTMathTextNode* parsedNode;
@ -585,22 +596,23 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
/** \brief if true, the unparsedNode is drawn */
bool useUnparsed;
JKQTMathTextNode* getTree() const;
/** \brief returns the syntax tree of JKQTMathTextNode's that was created by the last parse call */
JKQTMathTextNode* getNodeTree() const;
/** \brief the token types that may arrise in the string */
enum tokenType {
MTTnone, /*!< \brief no token */
MTTtext, /*!< \brief a piece of general text */
MTTinstruction, /*!< \brief an instruction, started by "\", e.g. "\textbf", ... */
MTTunderscore, /*!< \brief the character "_" */
MTThat, /*!< \brief the character "^" */
MTTdollar, /*!< \brief the character "$" */
MTTopenbrace, /*!< \brief the character "{" */
MTTclosebrace, /*!< \brief the character "}" */
MTTopenbracket, /*!< \brief the character "[" */
MTTclosebracket, /*!< \brief the character "]" */
MTTinstruction, /*!< \brief an instruction, started by \c "\\", e.g. \c "\textbf", ... */
MTTunderscore, /*!< \brief the character \c "_" */
MTThat, /*!< \brief the character \c "^" */
MTTdollar, /*!< \brief the character \c "$" */
MTTopenbrace, /*!< \brief the character \c "{" */
MTTclosebrace, /*!< \brief the character \c "}" */
MTTopenbracket, /*!< \brief the character \c "[" */
MTTclosebracket, /*!< \brief the character \c "]" */
MTTwhitespace, /*!< \brief some whitespace */
MTTampersand /*!< \brief the character "&" */
MTTampersand /*!< \brief the character \c "&" */
};
/** \brief tokenizer for the LaTeX parser */

View File

@ -25,7 +25,7 @@
/*! \def JKQTMATHTEXT_LIB_EXPORT
\ingroup jkqtmathtext
\ingroup jkqtmathtext_tools
This define allows to export functions and classes from the jkqtcommon-library when building a dynamic/shared library.
Usage is as follows:
@ -58,7 +58,7 @@
*/
/*! \def JKQTMATHTEXT_LIB_IN_DLL
\ingroup jkqtmathtext
\ingroup jkqtmathtext_tools
\brief declares that the application should link against a shared version of
JKQTMathText, i.e. \c JKQTMathTextSharedLib_XYZ .
This needs to be defined while compiling the library and while compiling
@ -66,7 +66,7 @@
*/
/*! \def JKQTMATHTEXT_LIB_EXPORT_LIBRARY
\ingroup jkqtmathtext
\ingroup jkqtmathtext_tools
\brief is only defined while compiling JKQTMathText into \c JKQTMathTextSharedLib_XYZ
and ensures thet the symbols are exported. If it is not defined (e.g. while
compiling an application), the symbols are imported

View File

@ -45,7 +45,6 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextFracNode: public JKQTMathTextDualChild
public:
/** \brief type of ffractions represented by JKQTMathTextFracNode
* \ingroup jkqtmathtext
* \see JKQTMathTextFracNode, JKQTMathTextFracNode::FracType2String()
*/
enum FracType {
@ -62,7 +61,6 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextFracNode: public JKQTMathTextDualChild
};
/** \brief convert a JKQTMathTextFracNode::FracType into a QString
* \ingroup jkqtmathtext
* \see JKQTMathTextFracNode::FracType
*/
static QString FracType2String(FracType mode);