mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-24 17:41:39 +08:00
NEW: Added JKQTMathText::setFontOptions(), which allows to make fonts initially e.g. bold, italic, ... and extended JKQTMathText::setFontSpecial() accordingly
This commit is contained in:
parent
a4b4e484bc
commit
122371e743
@ -90,7 +90,8 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
|
||||
<li>NEW: add color palettes from Green's HELIX method, see <a href="https://arxiv.org/abs/1108.5083">https://arxiv.org/abs/1108.5083</a>, also see <a href="https://jiffyclub.github.io/palettable/cubehelix/">https://jiffyclub.github.io/palettable/cubehelix/</a>, see JKQTPCreateGreensCubeHelixLUT() and e.g. JKQTPMathImageCubeHelixClassic, JKQTPMathImageCubeHelix1, ...</li>
|
||||
<li>NEW: Using Q_SIGNALS/Q_SLOTS instead of signals/slots MOC-keywords ... this allows for interoperability with other signals/slots frameworks, thanks to <a href="https://github.com/nickmontini">user:nickmontini</a> for the proposal</li>
|
||||
<li>NEW: you can use any (preferably stepped/categorial) JKQTPMathImageColorPalette as default graph colors list in a style.ini file, by setting <tt>auto_styles/use_color_from_palette=PALETTE_NAME</tt></li>
|
||||
<li>NEW added entry for plotLabelColor to JKQTBasePlotterStyle</li>
|
||||
<li>NEW: added entry for JKQTBasePlotterStyle::plotLabelColor to set the plot label color</li>
|
||||
<li>NEW: Due to addition of JKQTMathText::setFontOptions() and the matchign extension of JKQTMathText::setFontSpecial() (see below) you can now add modifiers like <tt>+BOLD+ITALIC</tt> to any font-name provided to JKQTPlotter and in style INI-files</li>
|
||||
</ul></li>
|
||||
|
||||
<li>JKQTMathText:<ul>
|
||||
@ -161,6 +162,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
|
||||
<li>NEW: added environment-modifying commands for text formatting: \c {\\bfseries...}, \c {\\itshape...}, \c {\\bf...}, \c {\\it...}, \c {\\sffamily...}, \c {\\ttfamily...}, ... </li>
|
||||
<li>NEW: Added the Fira Math fonts as sans-serif symbol font to the library (as a ressource) and added JKQTMathText::useFiraMath()</li>
|
||||
<li>NEW: Added JKQTMathText::useGuiFonts()</li>
|
||||
<li>NEW: Added JKQTMathText::setFontOptions(), which allows to make fonts initially e.g. bold, italic, ... and extended JKQTMathText::setFontSpecial() accordingly</li>
|
||||
</ul></li>
|
||||
</ul>
|
||||
|
||||
|
@ -81,6 +81,7 @@ JKQTMathText::JKQTMathText(QObject* parent, bool useFontsForGUI):
|
||||
|
||||
fontSize=10;
|
||||
fontSizeUnits=JKQTMathTextEnvironment::POINTS;
|
||||
fontOptions=BaseFontDefault;
|
||||
fontColor=QColor("black");
|
||||
brace_factor=1.04;
|
||||
brace_y_shift_factor=0.7;//-1;
|
||||
@ -207,6 +208,7 @@ JKQTMathText::~JKQTMathText() {
|
||||
void JKQTMathText::loadSettings(const QSettings& settings, const QString& group){
|
||||
fontSize=settings.value(group+"font_size", fontSize).toDouble();
|
||||
fontSizeUnits=JKQTMathTextEnvironment::String2FontSizeUnit(settings.value(group+"font_size_units", JKQTMathTextEnvironment::FontSizeUnit2String(fontSizeUnits)).toString());
|
||||
fontOptions=String2BaseFontOptions(settings.value(group+"font_options", BaseFontOptions2String(fontOptions)).toString());
|
||||
fontColor=jkqtp_String2QColor(settings.value(group+"font_color", jkqtp_QColor2String(fontColor)).toString());
|
||||
brace_factor=settings.value(group+"brace_factor", brace_factor).toDouble();
|
||||
subsuper_size_factor=settings.value(group+"subsuper_size_factor", subsuper_size_factor).toDouble();
|
||||
@ -254,6 +256,7 @@ void JKQTMathText::loadSettings(const QSettings& settings, const QString& group)
|
||||
void JKQTMathText::saveSettings(QSettings& settings, const QString& group) const{
|
||||
settings.setValue(group+"font_size", fontSize);
|
||||
settings.setValue(group+"font_size_units", JKQTMathTextEnvironment::FontSizeUnit2String(fontSizeUnits));
|
||||
settings.setValue(group+"font_options", BaseFontOptions2String(fontOptions));
|
||||
settings.setValue(group+"font_color", jkqtp_QColor2String(fontColor));
|
||||
settings.setValue(group+ "brace_factor", brace_factor);
|
||||
settings.setValue(group+ "subsuper_size_factor", subsuper_size_factor);
|
||||
@ -423,13 +426,16 @@ QString JKQTMathText::toHtml(bool *ok, double fontPointSize) {
|
||||
bool okk=false;
|
||||
if (getNodeTree()!=nullptr) {
|
||||
JKQTMathTextEnvironment ev;
|
||||
ev.color=fontColor;
|
||||
modifyEnvironmentFromFontSettings(ev);
|
||||
ev.fontSize=fontPointSize;
|
||||
ev.fontSizeUnit=JKQTMathTextEnvironment::POINTS;
|
||||
ev.fontSizeUnit=JKQTMathTextEnvironment::PIXELS;
|
||||
|
||||
JKQTMathTextEnvironment defaultev;
|
||||
defaultev.fontSize=fontPointSize;
|
||||
defaultev.fontSizeUnit=JKQTMathTextEnvironment::POINTS;
|
||||
const auto defColor=defaultev.color;
|
||||
modifyEnvironmentFromFontSettings(defaultev);
|
||||
defaultev.color=defColor;
|
||||
ev.fontSize=fontPointSize;
|
||||
ev.fontSizeUnit=JKQTMathTextEnvironment::PIXELS;
|
||||
|
||||
okk=getNodeTree()->toHtml(s, ev, defaultev);
|
||||
}
|
||||
@ -437,6 +443,30 @@ QString JKQTMathText::toHtml(bool *ok, double fontPointSize) {
|
||||
return s;
|
||||
}
|
||||
|
||||
QString JKQTMathText::BaseFontOptions2String(JKQTMathText::BaseFontOptions opt)
|
||||
{
|
||||
QStringList res;
|
||||
if (opt.testFlag(BaseFontBold)) res<<"BOLD";
|
||||
if (opt.testFlag(BaseFontItalic)) res<<"ITALIC";
|
||||
if (opt.testFlag(BaseFontUnderlined)) res<<"UNDERLINED";
|
||||
if (opt.testFlag(BaseFontSmallCaps)) res<<"SMALLCAPS";
|
||||
|
||||
return res.join('+');
|
||||
}
|
||||
|
||||
JKQTMathText::BaseFontOptions JKQTMathText::String2BaseFontOptions(const QString &s)
|
||||
{
|
||||
BaseFontOptions res=BaseFontDefault;
|
||||
const auto opts=s.toUpper().trimmed().simplified().split('+');
|
||||
for (const auto& o: opts) {
|
||||
if (o=="BOLD" || o=="BF" || o=="B") res.setFlag(BaseFontBold);
|
||||
else if (o=="ITALIC" || o=="IT" || o=="I") res.setFlag(BaseFontItalic);
|
||||
else if (o=="UNDERLINED" || o=="UL" || o=="U") res.setFlag(BaseFontUnderlined);
|
||||
else if (o=="SMALLCAPS" || o=="SC" || o=="S") res.setFlag(BaseFontSmallCaps);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
void JKQTMathText::setFontColor(const QColor &__value)
|
||||
{
|
||||
@ -482,6 +512,21 @@ double JKQTMathText::getFontSizePixels() const
|
||||
else return -1;
|
||||
}
|
||||
|
||||
void JKQTMathText::setFontOptions(JKQTMathText::BaseFontOptions opts)
|
||||
{
|
||||
fontOptions=opts;
|
||||
}
|
||||
|
||||
void JKQTMathText::setFontOption(JKQTMathText::BaseFontOption opt, bool enabled)
|
||||
{
|
||||
fontOptions.setFlag(opt, enabled);
|
||||
}
|
||||
|
||||
JKQTMathText::BaseFontOptions JKQTMathText::getFontOptions() const
|
||||
{
|
||||
return fontOptions;
|
||||
}
|
||||
|
||||
void JKQTMathText::addReplacementFont(const QString &nonUseFont, const QString &useFont, JKQTMathTextFontEncoding useFontEncoding) {
|
||||
fontReplacements.insert(nonUseFont, useFont);
|
||||
fontEncodingReplacements.insert(nonUseFont, useFontEncoding);
|
||||
@ -537,12 +582,16 @@ void JKQTMathText::setFontSpecial(const QString &fontSpec)
|
||||
{
|
||||
if (fontSpec.trimmed().size()==0) return;
|
||||
QString beforePlus=fontSpec;
|
||||
QString afterPlus="";
|
||||
const int Iplus=fontSpec.lastIndexOf('+');
|
||||
if (Iplus>=0 && Iplus<fontSpec.size()) {
|
||||
beforePlus=fontSpec.left(Iplus);
|
||||
afterPlus=fontSpec.mid(Iplus+1);
|
||||
QStringList afterPlus;
|
||||
afterPlus=fontSpec.split('+');
|
||||
if (afterPlus.size()>1) {
|
||||
beforePlus=afterPlus.first();
|
||||
afterPlus.removeFirst();
|
||||
} else {
|
||||
afterPlus.clear();
|
||||
}
|
||||
|
||||
|
||||
if (beforePlus.toUpper()=="GUI") useGuiFonts();
|
||||
else {
|
||||
const QStringList splitSlash=beforePlus.split('/');
|
||||
@ -565,10 +614,22 @@ void JKQTMathText::setFontSpecial(const QString &fontSpec)
|
||||
qDebug()<<"JKQTMathText::setFontSpecial(): undecodable fontSpec '"<<fontSpec<<"'";
|
||||
}
|
||||
}
|
||||
if (afterPlus.toUpper()=="XITS") useXITS();
|
||||
if (afterPlus.toUpper()=="STIX") useSTIX();
|
||||
if (afterPlus.toUpper()=="ASANA") useASANA();
|
||||
if (afterPlus.toUpper()=="FIRA") useFiraMath();
|
||||
BaseFontOptions opt=BaseFontDefault;
|
||||
for (const auto& afterIn: afterPlus) {
|
||||
const auto after=afterIn.toUpper();
|
||||
if (after=="XITS") useXITS();
|
||||
else if (after=="STIX") useSTIX();
|
||||
else if (after=="ASANA") useASANA();
|
||||
else if (after=="FIRA") useFiraMath();
|
||||
else if (after=="BOLD" || after=="BF" || after=="B") opt.setFlag(BaseFontBold);
|
||||
else if (after=="ITALIC" || after=="IT" || after=="I") opt.setFlag(BaseFontItalic);
|
||||
else if (after=="UNDERLINED" || after=="UL" || after=="U") opt.setFlag(BaseFontUnderlined);
|
||||
else if (after=="SMALLCAPS" || after=="SC" || after=="S") opt.setFlag(BaseFontSmallCaps);
|
||||
else {
|
||||
qDebug()<<"JKQTMathText::setFontSpecial() didn't recognize font name component '"<<after<<"'";
|
||||
}
|
||||
}
|
||||
setFontOptions(opt);
|
||||
}
|
||||
|
||||
void JKQTMathText::setFontRoman(const QString &__value, JKQTMathTextFontEncoding encoding)
|
||||
@ -1130,6 +1191,7 @@ void JKQTMathText::clearErrorList()
|
||||
error_list.clear();
|
||||
}
|
||||
|
||||
|
||||
const JKQTMathTextNode *JKQTMathText::getNodeTree() const {
|
||||
return this->parsedNode;
|
||||
}
|
||||
@ -1174,15 +1236,24 @@ void JKQTMathText::getSizeDetail(QPainter& painter, double& width, double& ascen
|
||||
strikeoutPos=s.strikeoutPos;
|
||||
}
|
||||
|
||||
|
||||
void JKQTMathText::modifyEnvironmentFromFontSettings(JKQTMathTextEnvironment &ev) const
|
||||
{
|
||||
ev.color=fontColor;
|
||||
ev.fontSize=fontSize;
|
||||
ev.fontSizeUnit=fontSizeUnits;
|
||||
ev.bold=fontOptions.testFlag(BaseFontBold);
|
||||
ev.italic=fontOptions.testFlag(BaseFontItalic);
|
||||
ev.underlined=fontOptions.testFlag(BaseFontUnderlined);
|
||||
if (fontOptions.testFlag(BaseFontSmallCaps)) ev.capitalization=QFont::SmallCaps;
|
||||
}
|
||||
|
||||
JKQTMathTextNodeSize JKQTMathText::getSizeDetail(QPainter &painter)
|
||||
{
|
||||
JKQTMathTextNodeSize s;
|
||||
if (getNodeTree()!=nullptr) {
|
||||
JKQTMathTextEnvironment ev;
|
||||
ev.color=fontColor;
|
||||
ev.fontSize=fontSize;
|
||||
ev.fontSizeUnit=fontSizeUnits;
|
||||
|
||||
modifyEnvironmentFromFontSettings(ev);
|
||||
s=getNodeTree()->getSize(painter, ev);
|
||||
}
|
||||
return s;
|
||||
@ -1199,9 +1270,7 @@ double JKQTMathText::draw(QPainter& painter, double x, double y, bool drawBoxes)
|
||||
painter.setPen(fontColor);
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
JKQTMathTextEnvironment ev;
|
||||
ev.color=fontColor;
|
||||
ev.fontSize=fontSize;
|
||||
ev.fontSizeUnit=fontSizeUnits;
|
||||
modifyEnvironmentFromFontSettings(ev);
|
||||
getNodeTree()->setDrawBoxes(drawBoxes);
|
||||
const double xend=getNodeTree()->draw(painter, x, y, ev);
|
||||
return xend;
|
||||
@ -1216,9 +1285,7 @@ void JKQTMathText::draw(QPainter& painter, unsigned int flags, QRectF rect, bool
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
|
||||
JKQTMathTextEnvironment ev;
|
||||
ev.color=fontColor;
|
||||
ev.fontSize=fontSize;
|
||||
ev.fontSizeUnit=fontSizeUnits;
|
||||
modifyEnvironmentFromFontSettings(ev);
|
||||
getNodeTree()->setDrawBoxes(drawBoxes);
|
||||
|
||||
const JKQTMathTextNodeSize size= getSizeDetail(painter);
|
||||
|
@ -333,6 +333,20 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
|
||||
/** @name Font Handling */
|
||||
/**@{*/
|
||||
/** \brief options for the base font */
|
||||
enum BaseFontOption {
|
||||
BaseFontBold = 0x01, /*!< \brief output is bold (equivalent to placinf text in <code>\textbf{...}</code>) */
|
||||
BaseFontItalic = 0x02, /*!< \brief output is italic (equivalent to placinf text in <code>\textit{...}</code>) */
|
||||
BaseFontUnderlined = 0x04, /*!< \brief output is underlined (equivalent to placinf text in <code>\underlined{...}</code>) */
|
||||
BaseFontSmallCaps = 0x08, /*!< \brief output is underlined (equivalent to placinf text in <code>\underlined{...}</code>) */
|
||||
BaseFontDefault=0x00, /*!< \brief base font is used as is, without modifications */
|
||||
};
|
||||
Q_DECLARE_FLAGS(BaseFontOptions, BaseFontOption)
|
||||
Q_FLAG(BaseFontOptions)
|
||||
/** \brief convert BaseFontOptions to a string (e.g. <code>BOLD+ITALIC</code> */
|
||||
static QString BaseFontOptions2String(BaseFontOptions opt);
|
||||
/** \brief convert a string (generated by BaseFontOptions2String() to BaseFontOptions */
|
||||
static BaseFontOptions String2BaseFontOptions(const QString& s);
|
||||
/** \copydoc fontColor */
|
||||
void setFontColor(const QColor & __value);
|
||||
/** \copydoc fontColor */
|
||||
@ -353,6 +367,21 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
/** \brief returns the currently set default font size in pixels, if it was defined in points using setFontSizePixels(), or -1 if it was set in points with setFontSize()
|
||||
* \see setFontSizePixels(), fontSize, fontSizeUnits */
|
||||
double getFontSizePixels() const;
|
||||
/** \brief set (overwrite) the options applied to the base font
|
||||
*
|
||||
* \see BaseFontOptions
|
||||
*/
|
||||
void setFontOptions(BaseFontOptions opts);
|
||||
/** \brief en/disable the given base font option
|
||||
*
|
||||
* \see BaseFontOptions
|
||||
*/
|
||||
void setFontOption(BaseFontOption opt,bool enabled=true);
|
||||
/** \brief returns the options applied to the base font
|
||||
*
|
||||
* \see BaseFontOptions
|
||||
*/
|
||||
BaseFontOptions getFontOptions() const;
|
||||
|
||||
|
||||
/** \brief add a font pair to the table with font replacements
|
||||
@ -412,6 +441,10 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
* - \c +ASANA use ASANA for math/symbols, calls useASANA()
|
||||
* - \c +STIX use STIX for math/symbols, calls useSTIX()
|
||||
* - \c +FIRA use Fira Math for math/symbols, calls useFiraMath()
|
||||
* - \c +BOLD make font initially bold
|
||||
* - \c +ITALIC make font initially italic
|
||||
* - \c +UNDERLINED make font initially underlines
|
||||
* - \c +SMALLCAPS make font initially smallcaps
|
||||
* .
|
||||
* - \c GUI use GUI-fonts, calls useGuiFonts()
|
||||
* .
|
||||
@ -849,6 +882,10 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
||||
double fontSize;
|
||||
/** \brief unit of fontSize */
|
||||
JKQTMathTextEnvironment::FontSizeUnit fontSizeUnits;
|
||||
/** \brief additional options for the base fonts */
|
||||
BaseFontOptions fontOptions;
|
||||
/** \brief sets all properties of JKQTMathTextEnvironment \a ev from the fon settings stored in this class (e.g. fontSize, fontOptions, ...) */
|
||||
void modifyEnvironmentFromFontSettings(JKQTMathTextEnvironment& ev) const;
|
||||
|
||||
|
||||
/** \brief stores information about the different fonts used by LaTeX markup */
|
||||
|
Loading…
Reference in New Issue
Block a user