From d3b0e88bb88ceef98d4b3b0553288453d381aca4 Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Sun, 7 Aug 2022 22:13:31 +0200 Subject: [PATCH] jkqtmathtext_render: added option to generate listing of all symbols + fixed some bugs --- lib/jkqtmathtext/jkqtmathtext.cpp | 6 +-- lib/jkqtmathtext/jkqtmathtext.h | 25 ++++++++--- .../nodes/jkqtmathtextsymbolnode.cpp | 7 +++ .../nodes/jkqtmathtextsymbolnode.h | 2 + .../jkqtmathtext_render.cpp | 45 ++++++++++++++++--- 5 files changed, 71 insertions(+), 14 deletions(-) diff --git a/lib/jkqtmathtext/jkqtmathtext.cpp b/lib/jkqtmathtext/jkqtmathtext.cpp index 6f5489a766..965031de58 100644 --- a/lib/jkqtmathtext/jkqtmathtext.cpp +++ b/lib/jkqtmathtext/jkqtmathtext.cpp @@ -1398,7 +1398,7 @@ JKQTMathText::tokenType JKQTMathText::getToken() { const QString verbEndChar=parseString.mid(currentTokenID, 1); currentTokenName=readUntil(true, verbEndChar); return currentToken=MTTinstructionVerbatim; - } else if (currentTokenName.startsWith("begin")) { + } else if (currentTokenName=="begin") { currentTokenID++; if (parseString[currentTokenID]!='{') error_list.append(tr("error @ ch. %1: didn't find '{' after '\\begin'").arg(currentTokenID)); // find closing brace '}' after '\\begin{name'); currentTokenName=readUntil(true, "}"); @@ -1413,9 +1413,9 @@ JKQTMathText::tokenType JKQTMathText::getToken() { return currentToken=MTTinstructionVerbatim; } return currentToken=MTTinstructionBegin; - } else if (currentTokenName.startsWith("end")) { + } else if (currentTokenName=="end") { currentTokenID++; - if (parseString[currentTokenID]!='{') error_list.append(tr("error @ ch. %1: didn't find '{' after '\\end'").arg(currentTokenID)); // find closing brace '}' after '\\begin{name'); + if (currentTokenID>=parseString.size() || parseString[currentTokenID]!='{') error_list.append(tr("error @ ch. %1: didn't find '{' after '\\end'").arg(currentTokenID)); // find closing brace '}' after '\\begin{name'); currentTokenName=readUntil(true, "}"); return currentToken=MTTinstructionEnd; } diff --git a/lib/jkqtmathtext/jkqtmathtext.h b/lib/jkqtmathtext/jkqtmathtext.h index caa32e2f26..549b718dad 100644 --- a/lib/jkqtmathtext/jkqtmathtext.h +++ b/lib/jkqtmathtext/jkqtmathtext.h @@ -175,6 +175,9 @@ class JKQTMathTextNode; // forward
using "Courier New": \image html jkqtmathtext/jkqtmathtext_couriernew.png
using "Comic Sans MS": \image html jkqtmathtext/jkqtmathtext_comicsans.png
using "Old English Text": \image html jkqtmathtext/jkqtmathtext_OldEnglish.png +
using "Computer Modern": \image html jkqtmathtext/jkqtmathtext_computermodern.png +
using "Fira": \image html jkqtmathtext/jkqtmathtext_fira.png +
using "MS Segoe UI": \image html jkqtmathtext/jkqtmathtext_mssegoeui.png . Math-mode is activated by enclosing your equation in \c $...$ or \c \\[...\\] . This mode is optimized for mathematical equations. Here is an example of the difference: @@ -362,13 +365,16 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject { void setFontCaligraphic(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard); /** \brief retrieves the font to be used for text in the logical font MTEcaligraphic */ QString getFontCaligraphic() const; - /** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEblackboard */ + /** \brief set the font \a fontName and it's encoding \a encoding to be used for text in the logical font MTEblackboard \see setFontBlackboardSimulated() + * + * + */ void setFontBlackboard(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard); - /** \brief blackboard font is simulated by using roman with outlines only */ + /** \copydoc blackboardSimulated */ void setFontBlackboardSimulated(bool doSimulate); - /** \brief is blackboard font simulated by using roman with outlines only */ + /** \copydoc blackboardSimulated \see setFontBlackboardSimulated() */ bool isFontBlackboardSimulated() const; - /** \brief retrieves the font to be used for text in the logical font MTEblackboard */ + /** \brief retrieves the font to be used for text in the logical font MTEblackboard \see setFontBlackboardSimulated() */ QString getFontBlackboard() const; /** \brief set the font \a fontName and it's encoding \a encoding to be used for symbols in the logical font \a font */ void setFallbackFontSymbols(const QString & fontName, JKQTMathTextFontEncoding encoding=JKQTMathTextFontEncoding::MTFEStandard); @@ -626,7 +632,16 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject { /** \brief stores information about the different fonts used by LaTeX markup */ QHash fontDefinitions; - /** \brief if enabled, the blackboard-characters are simulated by using font outlines only */ + /** \brief if enabled, the blackboard-characters are simulated by using font outlines only + * + * A possible choice for a blackboard font (Castellar) looks like this: + * \image html jkqtmathtext/jkqtmathtext_bb.png + * If such a font is not available, you can set this property blackboardSimulated + * to \c true and chose a font, like e.g. Arial to output blackboard-letters as: + * \image html jkqtmathtext/jkqtmathtext_bb_sim.png + * + * \see setFontBlackboard() setFontBlackboardSimulated() + */ bool blackboardSimulated; diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.cpp index 31d172658a..b3c0b29962 100644 --- a/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.cpp +++ b/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.cpp @@ -306,6 +306,12 @@ bool JKQTMathTextSymbolNode::hasSymbol(const QString &symbolName) return symbols.contains(symbolName); } +QStringList JKQTMathTextSymbolNode::getSymbols() +{ + fillSymbolTables(); + return symbols.keys(); +} + bool JKQTMathTextSymbolNode::isSubSuperscriptBelowAboveSymbol(const QString &symbolName) { fillSymbolTables(); @@ -462,6 +468,7 @@ void JKQTMathTextSymbolNode::fillSymbolTables() symbols["|"]=SimpleUprightTextSymbol("||", "‖").addUprightUnicode(QChar(0x2016)); symbols["}"]=SimpleUprightTextSymbol("}"); symbols["AC"]=UprightSymbolUnicode(QChar(0x223F)).addUprightHtml("∿").addUprightStd("~"); + symbols["circonflex"]=SimpleTextSymbol("^"); symbols["aa"]=SimpleTextSymbol(QChar(0xE5)); symbols["ae"]=SimpleTextSymbol(QChar(0xE6)); symbols["AE"]=SimpleTextSymbol(QChar(0xC6)); diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.h b/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.h index 68ee594797..95e1ac0e75 100644 --- a/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.h +++ b/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.h @@ -83,6 +83,8 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextSymbolNode: public JKQTMathTextNode { void getSymbolSize(QPainter& painter, JKQTMathTextEnvironment currentEv, double& width, double& baselineHeight, double& overallHeight, double& strikeoutPos, double& subSuperXCorrection, double& subBesidesXCorrection, const JKQTMathTextNodeSize* prevNodeSize=nullptr); /** \brief checks whether the given symbol name can be prepresented by this type of node */ static bool hasSymbol(const QString& symbolName); + /** \brief return a list of all defined symbols */ + static QStringList getSymbols(); /** \brief checks whether the given symbol name can be prepresented by this type of node */ static bool isSubSuperscriptBelowAboveSymbol(const QString& symbolName); protected: diff --git a/tools/jkqtmathtext_render/jkqtmathtext_render.cpp b/tools/jkqtmathtext_render/jkqtmathtext_render.cpp index 3cc477ced5..b1e3a86ea2 100644 --- a/tools/jkqtmathtext_render/jkqtmathtext_render.cpp +++ b/tools/jkqtmathtext_render/jkqtmathtext_render.cpp @@ -21,6 +21,7 @@ #endif #include "jkqtmathtext/jkqtmathtextlabel.h" #include "jkqtcommon/jkqtpstringtools.h" +#include "jkqtmathtext/nodes/jkqtmathtextsymbolnode.h" #include void processFont(const QString font, QStringList& fonts, QString& mathFont) @@ -64,6 +65,8 @@ int main(int argc, char* argv[]) parser.addOption(inputfileOption); QCommandLineOption outputDirectoryOption("outputdir", "write results into this directory.", "outputdir", app.applicationDirPath()); parser.addOption(outputDirectoryOption); + QCommandLineOption listsymbolsOption("listsymbols", "list all symbols in the given output file and generate images.", "listsymbols", ""); + parser.addOption(listsymbolsOption); QCommandLineOption drawBoxesOption("drawboxes", "draw boxes."); parser.addOption(drawBoxesOption); QCommandLineOption verboseOption("verbose", "verbose output."); @@ -111,15 +114,40 @@ int main(int argc, char* argv[]) const QDir outputDir(parser.value(outputDirectoryOption)); const QString outputFilename_cmdline=outputDir.absoluteFilePath(args.value(1, "output.png")); const QString inputfile=parser.value(inputfileOption); + const QString listsymbols=parser.value(listsymbolsOption); const bool verbose = parser.isSet(verboseOption); QStringList latex, outputFilename; QList> cmdoptions; - if (inputfile.size()<=0) { - latex.append(latex_cmdline); - outputFilename.append(outputFilename_cmdline); - cmdoptions.append(QMap()); - } else { + if (listsymbols.size()>0) { + //std::cout<<"LISTSYMBOLS: "<\n"; + fileList<<" \n"; + for (const QString& symbol: JKQTMathTextSymbolNode::getSymbols()) { + if (symbol.size()>0 && symbol[0].isLetter()) { + latex.append("\\"+symbol); + outputFilename.append("jkqtmathtext_symbols_"+symbol+".png"); + cmdoptions.append(QMap()); + //std::cout<<" - "<\\\\"<:\n \\image html jkqtmathtext/symbols/"<\n \n"; + } + i++; + } + } + fileList<<" "; + fileList<<" \n"; + fileList<<"*/\n"; + } + } else if (inputfile.size()>0){ QFile f(inputfile); if (f.open(QFile::ReadOnly|QFile::Text)) { QString currentOutFile=""; @@ -182,13 +210,18 @@ int main(int argc, char* argv[]) } } + } else { + latex.append(latex_cmdline); + outputFilename.append(outputFilename_cmdline); + cmdoptions.append(QMap()); } if (verbose) { std::cout <<"===========================================================\n" <<"= jkqtmathtext_render: "; - if (inputfile.size()>0) std::cout<<"FILE-MODE ("<0) std::cout<<"FILE-MODE (read from "<0) std::cout<<"LIST-SYMBOLS-MODE (store to "<