mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2025-02-03 11:09:20 +08:00
jkqtmathtext_render: added option to generate listing of all symbols + fixed some bugs
This commit is contained in:
parent
baeb7f9e38
commit
d3b0e88bb8
@ -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;
|
||||
}
|
||||
|
@ -175,6 +175,9 @@ class JKQTMathTextNode; // forward
|
||||
<br>using "Courier New": \image html jkqtmathtext/jkqtmathtext_couriernew.png
|
||||
<br>using "Comic Sans MS": \image html jkqtmathtext/jkqtmathtext_comicsans.png
|
||||
<br>using "Old English Text": \image html jkqtmathtext/jkqtmathtext_OldEnglish.png
|
||||
<br>using "Computer Modern": \image html jkqtmathtext/jkqtmathtext_computermodern.png
|
||||
<br>using "Fira": \image html jkqtmathtext/jkqtmathtext_fira.png
|
||||
<br>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<JKQTMathTextEnvironmentFont, JKQTMathTextFontDefinition> 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;
|
||||
|
||||
|
||||
|
@ -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));
|
||||
|
@ -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:
|
||||
|
@ -21,6 +21,7 @@
|
||||
#endif
|
||||
#include "jkqtmathtext/jkqtmathtextlabel.h"
|
||||
#include "jkqtcommon/jkqtpstringtools.h"
|
||||
#include "jkqtmathtext/nodes/jkqtmathtextsymbolnode.h"
|
||||
#include <iostream>
|
||||
|
||||
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<QMap<QString,QString>> cmdoptions;
|
||||
if (inputfile.size()<=0) {
|
||||
latex.append(latex_cmdline);
|
||||
outputFilename.append(outputFilename_cmdline);
|
||||
cmdoptions.append(QMap<QString,QString>());
|
||||
} else {
|
||||
if (listsymbols.size()>0) {
|
||||
//std::cout<<"LISTSYMBOLS: "<<outputDir.absoluteFilePath(listsymbols).toStdString()<<"\n";
|
||||
QFile fileListF(outputDir.absoluteFilePath(listsymbols));
|
||||
if (fileListF.open(QFile::WriteOnly|QFile::Text)) {
|
||||
QTextStream fileList(&fileListF);
|
||||
int i=1;
|
||||
fileList<<"/*!\n"
|
||||
" \\defgroup jkqtmathtext_supportedlatexsymbols Supported LaTeX-Symbols\n"
|
||||
" \\ingroup jkqtmathtext_general\n\n";
|
||||
fileList<<" <table>\n";
|
||||
fileList<<" <tr>\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<QString,QString>());
|
||||
//std::cout<<" - "<<latex.last().toStdString()<<": "<<outputFilename.last().toStdString()<<"\n";
|
||||
fileList<<" <td><code>\\\\"<<symbol<<"</code>:\n <td> \\image html jkqtmathtext/symbols/"<<outputFilename.last()<<"\n";
|
||||
if (i%3==0) {
|
||||
fileList<<" </tr>\n <tr>\n";
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
fileList<<" </tr>";
|
||||
fileList<<" </table>\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<QString,QString>());
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
std::cout
|
||||
<<"===========================================================\n"
|
||||
<<"= jkqtmathtext_render: ";
|
||||
if (inputfile.size()>0) std::cout<<"FILE-MODE ("<<inputfile.toStdString()<<")\n";
|
||||
if (inputfile.size()>0) std::cout<<"FILE-MODE (read from "<<inputfile.toStdString()<<")\n";
|
||||
else if (listsymbols.size()>0) std::cout<<"LIST-SYMBOLS-MODE (store to "<<listsymbols.toStdString()<<")\n";
|
||||
else std::cout<<"COMMAND-LINE-MODE\n";
|
||||
std::cout<<"\n"
|
||||
<<"===========================================================\n";
|
||||
|
Loading…
Reference in New Issue
Block a user