mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-24 09:31:40 +08:00
JKQTMathText: improved HTML export (now color and font-family are supported)
This commit is contained in:
parent
b38ccc5fbc
commit
200c538a49
@ -446,6 +446,29 @@ JKQTMathTextEnvironment::JKQTMathTextEnvironment() {
|
||||
overline=false;
|
||||
strike=false;
|
||||
insideMath=false;
|
||||
insideMathForceDigitsUpright=true;
|
||||
}
|
||||
|
||||
void JKQTMathTextEnvironment::beginMathMode()
|
||||
{
|
||||
insideMath=true;
|
||||
insideMathForceDigitsUpright=true;
|
||||
italic=true;
|
||||
smallCaps=false;
|
||||
underlined=false;
|
||||
overline=false;
|
||||
strike=false;
|
||||
}
|
||||
|
||||
void JKQTMathTextEnvironment::endMathMode()
|
||||
{
|
||||
insideMath=false;
|
||||
insideMathForceDigitsUpright=true;
|
||||
italic=false;
|
||||
smallCaps=false;
|
||||
underlined=false;
|
||||
overline=false;
|
||||
strike=false;
|
||||
}
|
||||
|
||||
JKQTMathTextFontEncoding JKQTMathTextEnvironment::getFontEncoding(JKQTMathText* parent) const {
|
||||
@ -514,7 +537,7 @@ QFont JKQTMathTextEnvironment::getFont(JKQTMathText* parent) const {
|
||||
return f;
|
||||
}
|
||||
|
||||
QString JKQTMathTextEnvironment::toHtmlStart(JKQTMathTextEnvironment defaultEv) const {
|
||||
QString JKQTMathTextEnvironment::toHtmlStart(JKQTMathTextEnvironment defaultEv, JKQTMathText* parentMathText) const {
|
||||
QString s;
|
||||
if (fontSizeUnit==POINTS) s=s+"font-size: "+QLocale::c().toString(fontSize)+"pt; ";
|
||||
else if (fontSizeUnit==PIXELS) s=s+"font-size: "+QLocale::c().toString(fontSize)+"px; ";
|
||||
@ -530,6 +553,8 @@ QString JKQTMathTextEnvironment::toHtmlStart(JKQTMathTextEnvironment defaultEv)
|
||||
if (!defaultEv.italic && italic) s=s+"font-style: italic; ";
|
||||
}
|
||||
if (bold && !defaultEv.bold) s=s+"font-weight: bold";
|
||||
if (color!=defaultEv.color) s=s+"color: "+color.name();
|
||||
if (font!=defaultEv.font) s=s+"font-family: "+getFont(parentMathText).family();
|
||||
|
||||
QStringList td;
|
||||
if (underlined && !defaultEv.underlined) td<<"underline";
|
||||
@ -539,7 +564,7 @@ QString JKQTMathTextEnvironment::toHtmlStart(JKQTMathTextEnvironment defaultEv)
|
||||
return "<span style=\""+s+"\">";
|
||||
}
|
||||
|
||||
QString JKQTMathTextEnvironment::toHtmlAfter(JKQTMathTextEnvironment /*defaultEv*/) const {
|
||||
QString JKQTMathTextEnvironment::toHtmlAfter(JKQTMathTextEnvironment /*defaultEv*/, JKQTMathText */*parentMathText*/) const {
|
||||
return "</span>";
|
||||
}
|
||||
|
||||
|
@ -266,6 +266,12 @@ struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextEnvironment {
|
||||
bool strike;
|
||||
/** \brief is the text currently are we inside a math environment? */
|
||||
bool insideMath;
|
||||
/** \brief if \a insideMath \c ==true and this is \c true (the default), then digits are forced to be typeset in upright, otherwise they are typeset as defined by the other properties */
|
||||
bool insideMathForceDigitsUpright;
|
||||
/** \brief sets insideMath \c =true and insideMathForceDigitsUpright \c =true */
|
||||
void beginMathMode();
|
||||
/** \brief sets insideMath \c =false and insideMathForceDigitsUpright \c =true */
|
||||
void endMathMode();
|
||||
|
||||
|
||||
/** \brief build a QFont object from the settings in this object */
|
||||
@ -277,13 +283,13 @@ struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextEnvironment {
|
||||
* \param defaultEv environment before applying the current object (to detect changes)
|
||||
* \see toHtmlAfter()
|
||||
*/
|
||||
QString toHtmlStart(JKQTMathTextEnvironment defaultEv) const;
|
||||
QString toHtmlStart(JKQTMathTextEnvironment defaultEv, JKQTMathText *parentMathText) const;
|
||||
/** \brief generate a HTML postfix that formats the text in front of it according to the settings in this object
|
||||
*
|
||||
* \param defaultEv environment before applying the current object (to detect changes)
|
||||
* \see toHtmlAfter()
|
||||
*/
|
||||
QString toHtmlAfter(JKQTMathTextEnvironment defaultEv) const;
|
||||
QString toHtmlAfter(JKQTMathTextEnvironment defaultEv, JKQTMathText *parentMathText) const;
|
||||
};
|
||||
|
||||
/** \brief beschreibt die Größe eines Knotens
|
||||
|
@ -279,7 +279,7 @@ bool JKQTMathTextSymbolNode::toHtml(QString &html, JKQTMathTextEnvironment curre
|
||||
ev.fontSize=ev.fontSize*props.html.fontScalingFactor;
|
||||
if (has(props.globalFlags, ExtendWidthInMathmode)) s=" "+s+" ";
|
||||
if (has(props.globalFlags, MakeWhitespaceHalf)) s.replace(" ", " ");
|
||||
if (ok) html=html+ev.toHtmlStart(defaultEv)+s+ev.toHtmlAfter(defaultEv);
|
||||
if (ok) html=html+ev.toHtmlStart(defaultEv, parentMathText)+s+ev.toHtmlAfter(defaultEv, parentMathText);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@ -361,6 +361,16 @@ JKQTMathTextSymbolNode::SymbolFullProps JKQTMathTextSymbolNode::NarrowMathOperat
|
||||
return SymbolFullProps(MTFEUnicode, SymbolProps(unicode, ItalicOff|BoldOff, 1.0, 0.0)).addGlobalFlags(SmallExtendWidthInMathmode|MakeWhitespaceHalf);
|
||||
}
|
||||
|
||||
JKQTMathTextSymbolNode::SymbolFullProps JKQTMathTextSymbolNode::NarrowMathOperatorSymbolStd(const QString &symbol)
|
||||
{
|
||||
return NarrowMathOperatorSymbolStd(symbol,symbol);
|
||||
}
|
||||
|
||||
JKQTMathTextSymbolNode::SymbolFullProps JKQTMathTextSymbolNode::NarrowMathOperatorSymbolStd(const QString &symbol, const QString &symbolHTML)
|
||||
{
|
||||
return SymbolFullProps(MTFEStandard, SymbolProps(symbol, ItalicOff|BoldOff, 1.0, 0.0)).addHtml(symbol, ItalicOff|BoldOff, 1.0, 0.0).addGlobalFlags(SmallExtendWidthInMathmode|MakeWhitespaceHalf);
|
||||
}
|
||||
|
||||
JKQTMathTextSymbolNode::SymbolFullProps JKQTMathTextSymbolNode::GreekLetter_WinSymbol_Unicode_Html(const QString &letterWinSymbol, const QString &letterUnicode, const QString &html)
|
||||
{
|
||||
return SymbolFullProps(MTFEUnicode, SymbolProps(letterUnicode), MTFEWinSymbol, SymbolProps(letterWinSymbol), html);
|
||||
@ -640,6 +650,7 @@ void JKQTMathTextSymbolNode::fillSymbolTables()
|
||||
**************************************************************************************/
|
||||
{ auto s=MathOperatorSymbolUnicode(QChar(0x2217)).addMathOperatorStd("*").addMathOperatorHtml("*");
|
||||
symbols["*"]=s; symbols["ast"]=s; symbols["asterisk"]=s; }
|
||||
symbols["/"]=NarrowMathOperatorSymbolStd("/");
|
||||
symbols["+"]=MathOperatorSymbolUnicode(QChar(0x2B)).addMathOperatorHtml("+").addMathOperatorStd("+");
|
||||
symbols["-"]=MathOperatorSymbolUnicode(QChar(0x2212)).addMathOperatorHtml("-").addMathOperatorStd("-");
|
||||
symbols["<"]=MathOperatorSymbol("<", "<");
|
||||
|
@ -275,8 +275,12 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextSymbolNode: public JKQTMathTextNode {
|
||||
static SymbolFullProps UprightSymbolUnicode(const QString& symbol, const QString& html=QString());
|
||||
/** \brief constructs a SymbolProps for a math-operator symbol like \c \\pm ... in unicode-full-encoding, i.e. ItalicOff, BoldOff, ExtendWidthInMathmode */
|
||||
static SymbolFullProps MathOperatorSymbolUnicode(const QString& unicode);
|
||||
/** \brief constructs a SymbolProps for a math-operator symbol like \c \\pm ... in unicode-full-encoding, i.e. ItalicOff, BoldOff, SmallExtendWidthInMathmode */
|
||||
/** \brief constructs a SymbolProps for a narrow math-operator symbol like \c \\pm ... in unicode-full-encoding, i.e. ItalicOff, BoldOff, SmallExtendWidthInMathmode */
|
||||
static SymbolFullProps NarrowMathOperatorSymbolUnicode(const QString& unicode);
|
||||
/** \brief constructs a SymbolProps for a narrow math-operator symbol like \c \\pm ... in unicode-full-encoding, i.e. ItalicOff, BoldOff, SmallExtendWidthInMathmode */
|
||||
static SymbolFullProps NarrowMathOperatorSymbolStd(const QString& symbol);
|
||||
/** \brief constructs a SymbolProps for a narrow math-operator symbol like \c \\pm ... in unicode-full-encoding, i.e. ItalicOff, BoldOff, SmallExtendWidthInMathmode */
|
||||
static SymbolFullProps NarrowMathOperatorSymbolStd(const QString& symbol, const QString& symbolHTML);
|
||||
|
||||
|
||||
/** \brief symbols that can be generated in any standard-font */
|
||||
|
@ -182,7 +182,7 @@ double JKQTMathTextTextNode::draw(QPainter& painter, double x, double y, JKQTMat
|
||||
}
|
||||
|
||||
bool JKQTMathTextTextNode::toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) {
|
||||
html=html+currentEv.toHtmlStart(defaultEv)+text+currentEv.toHtmlAfter(defaultEv);
|
||||
html=html+currentEv.toHtmlStart(defaultEv, parentMathText)+text+currentEv.toHtmlAfter(defaultEv, parentMathText);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user