mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-25 10:01:38 +08:00
NEW: JKQTMathText: added functions to set the font-size in pixels (as alternative to the existing functions that set them in points), implements request #76
This commit is contained in:
parent
9a13e5127a
commit
2ef181301b
@ -54,6 +54,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
|
|||||||
<li>NEW: \limits and \nolimits works as in LaTeX now (before it was simply removed and the functionality implemented for a fixed list of symbols)</li>
|
<li>NEW: \limits and \nolimits works as in LaTeX now (before it was simply removed and the functionality implemented for a fixed list of symbols)</li>
|
||||||
<li>NEW: added top-corner (\ulcorner/\urcorner) and bottom-corner brackets (\llcorner/\lrcorner)</li>
|
<li>NEW: added top-corner (\ulcorner/\urcorner) and bottom-corner brackets (\llcorner/\lrcorner)</li>
|
||||||
<li>NEW: added \overbracket and \underbracket</li>
|
<li>NEW: added \overbracket and \underbracket</li>
|
||||||
|
<li>NEW: added functions to set the font-size in pixels (as alternative to the existing functions that set them in points), implements request <a href="https://github.com/jkriege2/JKQtPlotter/issues/76">#76</a> from <a href="https://github.com/igormironchik">user:igormironchik</a> </li>
|
||||||
</ul>
|
</ul>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
@ -258,6 +258,7 @@ TestForm::TestForm(QWidget *parent) :
|
|||||||
connect(ui->cmbLastAlign, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
|
connect(ui->cmbLastAlign, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
|
||||||
connect(ui->cmbFont, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
|
connect(ui->cmbFont, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
|
||||||
connect(ui->cmbScript, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
|
connect(ui->cmbScript, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
|
||||||
|
connect(ui->cmbSizeUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
|
||||||
connect(ui->cmbTestset, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
|
connect(ui->cmbTestset, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
|
||||||
connect(ui->cmbCaligraphic, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
|
connect(ui->cmbCaligraphic, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
|
||||||
connect(ui->cmbUnicodeSans, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
|
connect(ui->cmbUnicodeSans, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMath()));
|
||||||
@ -573,9 +574,11 @@ void TestForm::updateMath()
|
|||||||
bool ok=true;
|
bool ok=true;
|
||||||
int size=sl[i].trimmed().toUInt(&ok);
|
int size=sl[i].trimmed().toUInt(&ok);
|
||||||
if (!ok) size=10+i*5;
|
if (!ok) size=10+i*5;
|
||||||
mt.setFontSize(size);
|
QString unit="";
|
||||||
|
if (ui->cmbSizeUnit->currentIndex()==0) { unit="pt"; mt.setFontSize(size); }
|
||||||
|
else {unit="px"; mt.setFontSizePixels(size); }
|
||||||
double durationSizingMS=0, durationTimingMS=0;
|
double durationSizingMS=0, durationTimingMS=0;
|
||||||
Y+=draw(painter, X1, Y, mt, QString("%1, %2, %3pt").arg(ui->cmbTestset->currentText()).arg(ui->cmbFont->currentText()).arg(size), durationSizingMS, durationTimingMS);
|
Y+=draw(painter, X1, Y, mt, QString("%1, %2, %3"+unit).arg(ui->cmbTestset->currentText()).arg(ui->cmbFont->currentText()).arg(size), durationSizingMS, durationTimingMS);
|
||||||
|
|
||||||
if (i==0) {
|
if (i==0) {
|
||||||
ui->labError->clear();
|
ui->labError->clear();
|
||||||
@ -600,8 +603,10 @@ void TestForm::updateMath()
|
|||||||
bool ok=true;
|
bool ok=true;
|
||||||
int size=sl.last().trimmed().toUInt(&ok);
|
int size=sl.last().trimmed().toUInt(&ok);
|
||||||
if (!ok) size=font().pointSizeF();
|
if (!ok) size=font().pointSizeF();
|
||||||
mt.setFontSize(size);
|
QString unit;
|
||||||
Y+=drawAligned(painter, X1, Y, mt, QString("%1, %2pt, align: %3").arg(ui->cmbTestset->currentText()).arg(size).arg(ui->cmbLastAlign->currentText()));
|
if (ui->cmbSizeUnit->currentIndex()==0) { unit="pt"; mt.setFontSize(size); }
|
||||||
|
else { unit="px"; mt.setFontSizePixels(size); }
|
||||||
|
Y+=drawAligned(painter, X1, Y, mt, QString("%1, %2"+unit+", align: %3").arg(ui->cmbTestset->currentText()).arg(size).arg(ui->cmbLastAlign->currentText()));
|
||||||
}
|
}
|
||||||
|
|
||||||
painter.end();
|
painter.end();
|
||||||
|
@ -588,7 +588,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0" colspan="2">
|
<item row="0" column="0" colspan="2">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,2,0,2,0,0,1,0,0,0,0,0,0">
|
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,2,0,2,0,0,0,1,0,0,0,0,0,0">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_3">
|
<widget class="QLabel" name="label_3">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -675,6 +675,26 @@
|
|||||||
</item>
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="cmbSizeUnit">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>pt</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>px</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_2">
|
<widget class="QLabel" name="label_2">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -61,6 +61,7 @@ JKQTMathText::JKQTMathText(QObject* parent):
|
|||||||
//qDebug()<<"init_resoucre: "<<std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now()-t0).count()/1000.0<<"ms"; t0=std::chrono::high_resolution_clock::now();
|
//qDebug()<<"init_resoucre: "<<std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now()-t0).count()/1000.0<<"ms"; t0=std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
fontSize=10;
|
fontSize=10;
|
||||||
|
fontSizeUnits=JKQTMathTextEnvironment::POINTS;
|
||||||
fontColor=QColor("black");
|
fontColor=QColor("black");
|
||||||
italic_correction_factor=0.4;
|
italic_correction_factor=0.4;
|
||||||
brace_factor=1.04;
|
brace_factor=1.04;
|
||||||
@ -121,30 +122,6 @@ JKQTMathText::JKQTMathText(QObject* parent):
|
|||||||
#else
|
#else
|
||||||
const auto fonts=QFontDatabase::families();
|
const auto fonts=QFontDatabase::families();
|
||||||
#endif
|
#endif
|
||||||
//qDebug()<<"fonts:\n"<<fonts;
|
|
||||||
|
|
||||||
/*if (SCAN_FONTS_ON_STARTUP) {
|
|
||||||
for (const QString& f: fonts) {
|
|
||||||
QFont fnt(f);
|
|
||||||
QFontInfo fi(fnt);
|
|
||||||
if (typewriterFont=="typewriter" && fi.styleHint()==QFont::TypeWriter) {
|
|
||||||
typewriterFont=f;
|
|
||||||
}
|
|
||||||
if (decorativeFont=="decorative" && fi.styleHint()==QFont::Decorative) {
|
|
||||||
decorativeFont=f;
|
|
||||||
}
|
|
||||||
if (serifFont=="serif" && fi.styleHint()==QFont::Serif) {
|
|
||||||
serifFont=f;
|
|
||||||
}
|
|
||||||
if (sansFont=="sans" && fi.styleHint()==QFont::SansSerif) {
|
|
||||||
sansFont=f;
|
|
||||||
}
|
|
||||||
if (scriptFont=="script" && fi.styleHint()==QFont::Cursive) {
|
|
||||||
scriptFont=f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
//qDebug()<<"iterate "<<fonts.size()<<" fonts: "<<std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now()-t0).count()/1000.0<<"ms"; t0=std::chrono::high_resolution_clock::now();
|
|
||||||
|
|
||||||
|
|
||||||
auto checkForFonts=[&fonts](QString& targetfont, const QStringList& fontoptions) {
|
auto checkForFonts=[&fonts](QString& targetfont, const QStringList& fontoptions) {
|
||||||
@ -220,6 +197,7 @@ JKQTMathText::~JKQTMathText() {
|
|||||||
|
|
||||||
void JKQTMathText::loadSettings(const QSettings& settings, const QString& group){
|
void JKQTMathText::loadSettings(const QSettings& settings, const QString& group){
|
||||||
fontSize=settings.value(group+"font_size", fontSize).toDouble();
|
fontSize=settings.value(group+"font_size", fontSize).toDouble();
|
||||||
|
fontSizeUnits=JKQTMathTextEnvironment::String2FontSizeUnit(settings.value(group+"font_size_units", JKQTMathTextEnvironment::FontSizeUnit2String(fontSizeUnits)).toString());
|
||||||
fontColor=jkqtp_String2QColor(settings.value(group+"font_color", jkqtp_QColor2String(fontColor)).toString());
|
fontColor=jkqtp_String2QColor(settings.value(group+"font_color", jkqtp_QColor2String(fontColor)).toString());
|
||||||
brace_factor=settings.value(group+"brace_factor", brace_factor).toDouble();
|
brace_factor=settings.value(group+"brace_factor", brace_factor).toDouble();
|
||||||
brace_shrink_factor=settings.value(group+"brace_shrink_factor", brace_shrink_factor).toDouble();
|
brace_shrink_factor=settings.value(group+"brace_shrink_factor", brace_shrink_factor).toDouble();
|
||||||
@ -261,6 +239,7 @@ void JKQTMathText::loadSettings(const QSettings& settings, const QString& group)
|
|||||||
|
|
||||||
void JKQTMathText::saveSettings(QSettings& settings, const QString& group) const{
|
void JKQTMathText::saveSettings(QSettings& settings, const QString& group) const{
|
||||||
settings.setValue(group+"font_size", fontSize);
|
settings.setValue(group+"font_size", fontSize);
|
||||||
|
settings.setValue(group+"font_size_units", JKQTMathTextEnvironment::FontSizeUnit2String(fontSizeUnits));
|
||||||
settings.setValue(group+"font_color", jkqtp_QColor2String(fontColor));
|
settings.setValue(group+"font_color", jkqtp_QColor2String(fontColor));
|
||||||
settings.setValue(group+ "brace_factor", brace_factor);
|
settings.setValue(group+ "brace_factor", brace_factor);
|
||||||
settings.setValue(group+ "brace_shrink_factor", brace_shrink_factor);
|
settings.setValue(group+ "brace_shrink_factor", brace_shrink_factor);
|
||||||
@ -363,6 +342,24 @@ bool JKQTMathText::useASANA(bool mathModeOnly)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void JKQTMathText::useAnyUnicode(QString timesFont, const QString &sansFont, JKQTMathTextFontEncoding encodingTimes, JKQTMathTextFontEncoding encodingSans)
|
void JKQTMathText::useAnyUnicode(QString timesFont, const QString &sansFont, JKQTMathTextFontEncoding encodingTimes, JKQTMathTextFontEncoding encodingSans)
|
||||||
|
{
|
||||||
|
if (!timesFont.isEmpty()) {
|
||||||
|
setFontRoman(timesFont, encodingTimes);
|
||||||
|
setFontMathRoman(timesFont, encodingTimes);
|
||||||
|
}
|
||||||
|
if (!sansFont.isEmpty()) {
|
||||||
|
setFontSans(sansFont, encodingSans);
|
||||||
|
setFontMathSans(sansFont, encodingSans);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void JKQTMathText::useAnyUnicodeForMathOnly(QString timesFont, const QString &sansFont, JKQTMathTextFontEncoding encodingTimes, JKQTMathTextFontEncoding encodingSans)
|
||||||
|
{
|
||||||
|
if (!timesFont.isEmpty()) { setFontMathRoman(timesFont, encodingTimes); }
|
||||||
|
if (!sansFont.isEmpty()) { setFontMathSans(sansFont, encodingSans); }
|
||||||
|
}
|
||||||
|
|
||||||
|
void JKQTMathText::useAnyUnicodeForTextOnly(QString timesFont, const QString &sansFont, JKQTMathTextFontEncoding encodingTimes, JKQTMathTextFontEncoding encodingSans)
|
||||||
{
|
{
|
||||||
if (!timesFont.isEmpty()) { setFontRoman(timesFont, encodingTimes); }
|
if (!timesFont.isEmpty()) { setFontRoman(timesFont, encodingTimes); }
|
||||||
if (!sansFont.isEmpty()) { setFontSans(sansFont, encodingSans); }
|
if (!sansFont.isEmpty()) { setFontSans(sansFont, encodingSans); }
|
||||||
@ -376,9 +373,11 @@ QString JKQTMathText::toHtml(bool *ok, double fontPointSize) {
|
|||||||
JKQTMathTextEnvironment ev;
|
JKQTMathTextEnvironment ev;
|
||||||
ev.color=fontColor;
|
ev.color=fontColor;
|
||||||
ev.fontSize=fontPointSize;
|
ev.fontSize=fontPointSize;
|
||||||
|
ev.fontSizeUnit=JKQTMathTextEnvironment::POINTS;
|
||||||
|
|
||||||
JKQTMathTextEnvironment defaultev;
|
JKQTMathTextEnvironment defaultev;
|
||||||
defaultev.fontSize=fontPointSize;
|
defaultev.fontSize=fontPointSize;
|
||||||
|
defaultev.fontSizeUnit=JKQTMathTextEnvironment::POINTS;
|
||||||
|
|
||||||
okk=getNodeTree()->toHtml(s, ev, defaultev);
|
okk=getNodeTree()->toHtml(s, ev, defaultev);
|
||||||
}
|
}
|
||||||
@ -399,12 +398,36 @@ QColor JKQTMathText::getFontColor() const
|
|||||||
|
|
||||||
void JKQTMathText::setFontSize(double __value)
|
void JKQTMathText::setFontSize(double __value)
|
||||||
{
|
{
|
||||||
this->fontSize = __value;
|
setFontPointSize(__value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void JKQTMathText::setFontPointSize(double __value)
|
||||||
|
{
|
||||||
|
fontSize = __value;
|
||||||
|
fontSizeUnits=JKQTMathTextEnvironment::POINTS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JKQTMathText::setFontSizePixels(double __value)
|
||||||
|
{
|
||||||
|
fontSize = __value;
|
||||||
|
fontSizeUnits=JKQTMathTextEnvironment::PIXELS;
|
||||||
}
|
}
|
||||||
|
|
||||||
double JKQTMathText::getFontSize() const
|
double JKQTMathText::getFontSize() const
|
||||||
{
|
{
|
||||||
return this->fontSize;
|
return getFontPointSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
double JKQTMathText::getFontPointSize() const
|
||||||
|
{
|
||||||
|
if (fontSizeUnits==JKQTMathTextEnvironment::POINTS) return fontSize;
|
||||||
|
else return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
double JKQTMathText::getFontSizePixels() const
|
||||||
|
{
|
||||||
|
if (fontSizeUnits==JKQTMathTextEnvironment::PIXELS) return fontSize;
|
||||||
|
else return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JKQTMathText::addReplacementFont(const QString &nonUseFont, const QString &useFont, JKQTMathTextFontEncoding useFontEncoding) {
|
void JKQTMathText::addReplacementFont(const QString &nonUseFont, const QString &useFont, JKQTMathTextFontEncoding useFontEncoding) {
|
||||||
@ -1638,6 +1661,7 @@ void JKQTMathText::getSizeDetail(QPainter& painter, double& width, double& ascen
|
|||||||
JKQTMathTextEnvironment ev;
|
JKQTMathTextEnvironment ev;
|
||||||
ev.color=fontColor;
|
ev.color=fontColor;
|
||||||
ev.fontSize=fontSize;
|
ev.fontSize=fontSize;
|
||||||
|
ev.fontSizeUnit=fontSizeUnits;
|
||||||
|
|
||||||
double overallHeight=0;
|
double overallHeight=0;
|
||||||
getNodeTree()->getSize(painter, ev, width, ascent, overallHeight, strikeoutPos);
|
getNodeTree()->getSize(painter, ev, width, ascent, overallHeight, strikeoutPos);
|
||||||
@ -1658,6 +1682,7 @@ void JKQTMathText::draw(QPainter& painter, double x, double y, bool drawBoxes){
|
|||||||
JKQTMathTextEnvironment ev;
|
JKQTMathTextEnvironment ev;
|
||||||
ev.color=fontColor;
|
ev.color=fontColor;
|
||||||
ev.fontSize=fontSize;
|
ev.fontSize=fontSize;
|
||||||
|
ev.fontSizeUnit=fontSizeUnits;
|
||||||
QPen pp=painter.pen();
|
QPen pp=painter.pen();
|
||||||
QPen p=pp;
|
QPen p=pp;
|
||||||
p.setStyle(Qt::SolidLine);
|
p.setStyle(Qt::SolidLine);
|
||||||
@ -1678,6 +1703,7 @@ void JKQTMathText::draw(QPainter& painter, unsigned int flags, QRectF rect, bool
|
|||||||
JKQTMathTextEnvironment ev;
|
JKQTMathTextEnvironment ev;
|
||||||
ev.color=fontColor;
|
ev.color=fontColor;
|
||||||
ev.fontSize=fontSize;
|
ev.fontSize=fontSize;
|
||||||
|
ev.fontSizeUnit=fontSizeUnits;
|
||||||
getNodeTree()->setDrawBoxes(drawBoxes);
|
getNodeTree()->setDrawBoxes(drawBoxes);
|
||||||
painter.setPen(p);
|
painter.setPen(p);
|
||||||
|
|
||||||
|
@ -294,10 +294,22 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
|||||||
void setFontColor(const QColor & __value);
|
void setFontColor(const QColor & __value);
|
||||||
/** \copydoc fontColor */
|
/** \copydoc fontColor */
|
||||||
QColor getFontColor() const;
|
QColor getFontColor() const;
|
||||||
/** \copydoc fontSize */
|
/** \copydoc setFontPointSize() */
|
||||||
void setFontSize(double __value);
|
void setFontSize(double __value);
|
||||||
/** \copydoc fontSize */
|
/** \brief set the default font size in points
|
||||||
|
* \see getFontSize(), fontSize, fontSizeUnits */
|
||||||
|
void setFontPointSize(double __value);
|
||||||
|
/** \brief set the default font soze in pixels
|
||||||
|
* \see getFontSizePixels(), fontSize, fontSizeUnits */
|
||||||
|
void setFontSizePixels(double __value);
|
||||||
|
/** \brief returns the currently set default font size in points, if it was defined in points using setFontSize(), or -1 if it was set in pixels with setFontSizePixels()
|
||||||
|
* \see setFontSize(), fontSize, fontSizeUnits */
|
||||||
|
double getFontPointSize() const;
|
||||||
|
/** \copydoc getFontPointSize() */
|
||||||
double getFontSize() const;
|
double getFontSize() const;
|
||||||
|
/** \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 add a font pair to the table with font replacements
|
/** \brief add a font pair to the table with font replacements
|
||||||
*
|
*
|
||||||
* e.g. if it is known that a certain font is not good for rendering, you can add an alternative with this function.
|
* e.g. if it is known that a certain font is not good for rendering, you can add an alternative with this function.
|
||||||
@ -440,8 +452,9 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
|||||||
|
|
||||||
/** \brief sets \a timesFont (with its encoding \a encodingTimes ) for serif-text and \a sansFont (with its encoding \a encodingSans ) for both mathmode and textmode fonts
|
/** \brief sets \a timesFont (with its encoding \a encodingTimes ) for serif-text and \a sansFont (with its encoding \a encodingSans ) for both mathmode and textmode fonts
|
||||||
*
|
*
|
||||||
* use generic Unicode fonts, e.g. "Arial" and "Times New Roman" in math-mode.
|
* \note use generic Unicode fonts, e.g. "Arial" and "Times New Roman" in math-mode.
|
||||||
* You should use fonts that contain as many of the mathematical symbols as possible to ensure good rendering results.
|
* You should use fonts that contain as many of the mathematical symbols as possible
|
||||||
|
* to ensure good rendering results.
|
||||||
*
|
*
|
||||||
* <code>useAnyUnicode("Times New Roman", "Times New Roman")</code>:<br>\image html jkqtmathtext/jkqtmathparser_timesnewroman.png <br><br>
|
* <code>useAnyUnicode("Times New Roman", "Times New Roman")</code>:<br>\image html jkqtmathtext/jkqtmathparser_timesnewroman.png <br><br>
|
||||||
* <code>useAnyUnicode("Arial", "Arial")</code>:<br>\image html jkqtmathtext/jkqtmathparser_arial.png <br><br>
|
* <code>useAnyUnicode("Arial", "Arial")</code>:<br>\image html jkqtmathtext/jkqtmathparser_arial.png <br><br>
|
||||||
@ -449,7 +462,20 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
|||||||
* <code>useAnyUnicode("Comic Sans MS", "Comic Sans MS")</code>:<br>\image html jkqtmathtext/jkqtmathparser_comicsans.png <br><br>
|
* <code>useAnyUnicode("Comic Sans MS", "Comic Sans MS")</code>:<br>\image html jkqtmathtext/jkqtmathparser_comicsans.png <br><br>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void useAnyUnicode(QString timesFont=QString(""), const QString& sansFont=QString(""), JKQTMathTextFontEncoding encodingTimes=JKQTMathTextFontEncoding::MTFEUnicode, JKQTMathTextFontEncoding encodingSans=JKQTMathTextFontEncoding::MTFEUnicode);
|
void useAnyUnicode(QString timesFont, const QString& sansFont, JKQTMathTextFontEncoding encodingTimes=JKQTMathTextFontEncoding::MTFEUnicode, JKQTMathTextFontEncoding encodingSans=JKQTMathTextFontEncoding::MTFEUnicode);
|
||||||
|
/** \brief sets \a timesFont (with its encoding \a encodingTimes ) for serif-text and \a sansFont (with its encoding \a encodingSans ) for mathmode fonts only
|
||||||
|
*
|
||||||
|
* \note use generic Unicode fonts, e.g. "Arial" and "Times New Roman" in math-mode.
|
||||||
|
* You should use fonts that contain as many of the mathematical symbols as possible to ensure good rendering results.
|
||||||
|
*
|
||||||
|
* \see useAnyUnicodeForTextOnly(), useAnyUnicode()
|
||||||
|
*/
|
||||||
|
void useAnyUnicodeForMathOnly(QString timesFont, const QString& sansFont, JKQTMathTextFontEncoding encodingTimes=JKQTMathTextFontEncoding::MTFEUnicode, JKQTMathTextFontEncoding encodingSans=JKQTMathTextFontEncoding::MTFEUnicode);
|
||||||
|
/** \brief sets \a timesFont (with its encoding \a encodingTimes ) for serif-text and \a sansFont (with its encoding \a encodingSans ) for both mathmode fonts only
|
||||||
|
*
|
||||||
|
* \see useAnyUnicodeForMathOnly(), useAnyUnicode()
|
||||||
|
*/
|
||||||
|
void useAnyUnicodeForTextOnly(QString timesFont, const QString& sansFont, JKQTMathTextFontEncoding encodingTimes=JKQTMathTextFontEncoding::MTFEUnicode, JKQTMathTextFontEncoding encodingSans=JKQTMathTextFontEncoding::MTFEUnicode);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -601,8 +627,10 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
|
|||||||
|
|
||||||
/** \brief font color */
|
/** \brief font color */
|
||||||
QColor fontColor;
|
QColor fontColor;
|
||||||
/** \brief base font size in points */
|
/** \brief base font size in the units defined in fontSizeUnits \see fontSizeUnits */
|
||||||
double fontSize;
|
double fontSize;
|
||||||
|
/** \brief unit of fontSize */
|
||||||
|
JKQTMathTextEnvironment::FontSizeUnit fontSizeUnits;
|
||||||
|
|
||||||
|
|
||||||
/** \brief stores information about the different fonts used by LaTeX markup */
|
/** \brief stores information about the different fonts used by LaTeX markup */
|
||||||
|
@ -415,10 +415,28 @@ bool InstructionNameMatchesJKQTMathTextBraceType(const QString &token, JKQTMathT
|
|||||||
return (bt==type);
|
return (bt==type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString JKQTMathTextEnvironment::FontSizeUnit2String(FontSizeUnit unit)
|
||||||
|
{
|
||||||
|
switch(unit) {
|
||||||
|
case PIXELS: return "pix";
|
||||||
|
default:
|
||||||
|
case POINTS: return "pt";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JKQTMathTextEnvironment::FontSizeUnit JKQTMathTextEnvironment::String2FontSizeUnit(QString unit)
|
||||||
|
{
|
||||||
|
unit=unit.toLower().trimmed();
|
||||||
|
if (unit=="pt" || unit=="points" || unit=="point") return POINTS;
|
||||||
|
if (unit=="pix" || unit=="pixel" || unit=="pixels" || unit=="px") return PIXELS;
|
||||||
|
return POINTS;
|
||||||
|
}
|
||||||
|
|
||||||
JKQTMathTextEnvironment::JKQTMathTextEnvironment() {
|
JKQTMathTextEnvironment::JKQTMathTextEnvironment() {
|
||||||
color=QColor("black");
|
color=QColor("black");
|
||||||
font=MTEroman;
|
font=MTEroman;
|
||||||
fontSize=10;
|
fontSize=10;
|
||||||
|
fontSizeUnit=POINTS;
|
||||||
bold=false;
|
bold=false;
|
||||||
italic=false;
|
italic=false;
|
||||||
smallCaps=false;
|
smallCaps=false;
|
||||||
@ -489,14 +507,17 @@ QFont JKQTMathTextEnvironment::getFont(JKQTMathText* parent) const {
|
|||||||
f.setStrikeOut(strike);
|
f.setStrikeOut(strike);
|
||||||
f.setCapitalization(QFont::MixedCase);
|
f.setCapitalization(QFont::MixedCase);
|
||||||
if (smallCaps) f.setCapitalization(QFont::SmallCaps);
|
if (smallCaps) f.setCapitalization(QFont::SmallCaps);
|
||||||
f.setPointSizeF(fontSize);
|
if (fontSizeUnit==POINTS) f.setPointSizeF(fontSize);
|
||||||
|
else if (fontSizeUnit==PIXELS) f.setPixelSize(static_cast<int>(fontSize));
|
||||||
f.setStyleStrategy(QFont::NoFontMerging);
|
f.setStyleStrategy(QFont::NoFontMerging);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString JKQTMathTextEnvironment::toHtmlStart(JKQTMathTextEnvironment defaultEv) const {
|
QString JKQTMathTextEnvironment::toHtmlStart(JKQTMathTextEnvironment defaultEv) const {
|
||||||
QString s;
|
QString s;
|
||||||
s=s+"font-size: "+QLocale::c().toString(fontSize)+"pt; ";
|
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; ";
|
||||||
|
|
||||||
if (insideMath) {
|
if (insideMath) {
|
||||||
if (defaultEv.italic) {
|
if (defaultEv.italic) {
|
||||||
if (!italic) s=s+"font-style: italic; ";
|
if (!italic) s=s+"font-style: italic; ";
|
||||||
|
@ -232,6 +232,16 @@ enum JKQTMathTextEnvironmentFont {
|
|||||||
* \ingroup jkqtmathtext_tools
|
* \ingroup jkqtmathtext_tools
|
||||||
*/
|
*/
|
||||||
struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextEnvironment {
|
struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextEnvironment {
|
||||||
|
/** \brief units for the property JKQTMathTextEnvironment::fontSize (Points/PT or Pixels) */
|
||||||
|
enum FontSizeUnit {
|
||||||
|
POINTS,
|
||||||
|
PIXELS
|
||||||
|
};
|
||||||
|
/** \brief convert a FontSizeUnit to a string \see FontSizeUnit,String2FontSizeUnit() */
|
||||||
|
static QString FontSizeUnit2String(FontSizeUnit unit);
|
||||||
|
/** \brief convert a string into a FontSizeUnit \see FontSizeUnit,FontSizeUnit2String() */
|
||||||
|
static FontSizeUnit String2FontSizeUnit(QString unit);
|
||||||
|
|
||||||
JKQTMathTextEnvironment();
|
JKQTMathTextEnvironment();
|
||||||
/** \brief current font color */
|
/** \brief current font color */
|
||||||
QColor color;
|
QColor color;
|
||||||
@ -239,8 +249,11 @@ struct JKQTMATHTEXT_LIB_EXPORT JKQTMathTextEnvironment {
|
|||||||
JKQTMathTextEnvironmentFont font;
|
JKQTMathTextEnvironmentFont font;
|
||||||
/** \brief custom font, when font==MTECustomFont */
|
/** \brief custom font, when font==MTECustomFont */
|
||||||
QString customFontName;
|
QString customFontName;
|
||||||
/** \brief current font size [pt] */
|
/** \brief current font size the unit is determined by fontSizeUnit */
|
||||||
double fontSize;
|
double fontSize;
|
||||||
|
/** \brief the unit of the font size fontSize */
|
||||||
|
FontSizeUnit fontSizeUnit;
|
||||||
|
|
||||||
/** \brief is the text currently bold? */
|
/** \brief is the text currently bold? */
|
||||||
bool bold;
|
bool bold;
|
||||||
/** \brief is the text currently italic? */
|
/** \brief is the text currently italic? */
|
||||||
|
@ -93,9 +93,9 @@ double JKQTMathTextBraceNode::draw(QPainter& painter, double x, double y, JKQTMa
|
|||||||
double nodeOverallHeight=0, nodeStrikeoutPos=0;
|
double nodeOverallHeight=0, nodeStrikeoutPos=0;
|
||||||
double bracewidth=0, braceheight=0;
|
double bracewidth=0, braceheight=0;
|
||||||
getSizeInternalAndBrace(painter, currentEv, nodeWidth, nodeBaselineHeight, nodeOverallHeight, nodeStrikeoutPos, bracewidth, braceheight);
|
getSizeInternalAndBrace(painter, currentEv, nodeWidth, nodeBaselineHeight, nodeOverallHeight, nodeStrikeoutPos, bracewidth, braceheight);
|
||||||
|
const QFontMetricsF fm(currentEv.getFont(parentMathText));
|
||||||
|
|
||||||
|
const double lw=qMax(0.25,fm.lineWidth());
|
||||||
const double lw=qMax(0.25,ceil(currentEv.fontSize/16.0));//fm.lineWidth();
|
|
||||||
|
|
||||||
double xnew=x;
|
double xnew=x;
|
||||||
|
|
||||||
@ -425,7 +425,8 @@ JKQTMathTextBraceType JKQTMathTextBraceNode::getClosebrace() const {
|
|||||||
|
|
||||||
void JKQTMathTextBraceNode::getBraceSize(QPainter &/*painter*/, JKQTMathTextEnvironment ev, double /*baselineHeight*/, double overallHeight, double &bracewidth, double &braceheight) const
|
void JKQTMathTextBraceNode::getBraceSize(QPainter &/*painter*/, JKQTMathTextEnvironment ev, double /*baselineHeight*/, double overallHeight, double &bracewidth, double &braceheight) const
|
||||||
{
|
{
|
||||||
const double lw=qMax(0.25,ceil(ev.fontSize/12.0));
|
const QFontMetricsF fm(ev.getFont(parentMathText));
|
||||||
|
const double lw=qMax(0.25,fm.lineWidth());
|
||||||
braceheight=overallHeight*parentMathText->getBraceFactor();
|
braceheight=overallHeight*parentMathText->getBraceFactor();
|
||||||
bracewidth=0.6*pow(braceheight, 0.6);
|
bracewidth=0.6*pow(braceheight, 0.6);
|
||||||
if (openbrace==MTBTCurlyBracket || closebrace==MTBTCurlyBracket) bracewidth=qMax(bracewidth, lw*3.5);
|
if (openbrace==MTBTCurlyBracket || closebrace==MTBTCurlyBracket) bracewidth=qMax(bracewidth, lw*3.5);
|
||||||
|
@ -111,8 +111,7 @@ double JKQTMathTextWhitespaceNode::draw(QPainter &painter, double x, double y, J
|
|||||||
|
|
||||||
void JKQTMathTextWhitespaceNode::getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv, double &width, double &baselineHeight, double &overallHeight, double &strikeoutPos, const JKQTMathTextNodeSize *prevNodeSize)
|
void JKQTMathTextWhitespaceNode::getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv, double &width, double &baselineHeight, double &overallHeight, double &strikeoutPos, const JKQTMathTextNodeSize *prevNodeSize)
|
||||||
{
|
{
|
||||||
const double singelWidthPT=Type2PointWidth(whitespace.type, currentEv);
|
const double singelWidthPIX=Type2PixelWidth(whitespace.type, currentEv, painter.device());
|
||||||
const double singelWidthPIX=singelWidthPT/72.0*painter.device()->logicalDpiX();
|
|
||||||
const QFontMetricsF fm(currentEv.getFont(parentMathText));
|
const QFontMetricsF fm(currentEv.getFont(parentMathText));
|
||||||
width=singelWidthPIX*static_cast<double>(whitespace.count);
|
width=singelWidthPIX*static_cast<double>(whitespace.count);
|
||||||
baselineHeight=0;
|
baselineHeight=0;
|
||||||
@ -127,7 +126,7 @@ void JKQTMathTextWhitespaceNode::fillSupportedInstructions()
|
|||||||
if (supportedInstructions.size()==0) {
|
if (supportedInstructions.size()==0) {
|
||||||
supportedInstructions[" "]=WhitespaceProps(WSTthicker, 1);
|
supportedInstructions[" "]=WhitespaceProps(WSTthicker, 1);
|
||||||
supportedInstructions["nbsp"]=WhitespaceProps(WSTNonbreaking, 1);
|
supportedInstructions["nbsp"]=WhitespaceProps(WSTNonbreaking, 1);
|
||||||
supportedInstructions["enspace"]=WhitespaceProps(WST1en, 1);
|
supportedInstructions["enspace"]=supportedInstructions["enskip"]=WhitespaceProps(WST1en, 1);
|
||||||
supportedInstructions["quad"]=supportedInstructions["emspace"]=WhitespaceProps(WSTQuad, 1);
|
supportedInstructions["quad"]=supportedInstructions["emspace"]=WhitespaceProps(WSTQuad, 1);
|
||||||
supportedInstructions["qquad"]=WhitespaceProps(WSTQuad, 2);
|
supportedInstructions["qquad"]=WhitespaceProps(WSTQuad, 2);
|
||||||
supportedInstructions[","]=supportedInstructions["thinspace"]=WhitespaceProps(WSTthin, 1);
|
supportedInstructions[","]=supportedInstructions["thinspace"]=WhitespaceProps(WSTthin, 1);
|
||||||
@ -159,13 +158,18 @@ QString JKQTMathTextWhitespaceNode::Type2String(Types type)
|
|||||||
return "???";
|
return "???";
|
||||||
}
|
}
|
||||||
|
|
||||||
double JKQTMathTextWhitespaceNode::Type2PointWidth(Types type, JKQTMathTextEnvironment currentEv) const
|
double JKQTMathTextWhitespaceNode::Type2PixelWidth(Types type, JKQTMathTextEnvironment currentEv, QPaintDevice* pd) const
|
||||||
{
|
{
|
||||||
const double em=currentEv.fontSize;
|
const QFontMetricsF fm(currentEv.getFont(parentMathText), pd);
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(5,11,0)
|
||||||
|
const double em=fm.horizontalAdvance(QChar(0x2003));//currentEv.fontSize;
|
||||||
|
#else
|
||||||
|
const double em=fm.width(QChar(0x2003));//currentEv.fontSize;
|
||||||
|
#endif
|
||||||
const double en=em/2.0;
|
const double en=em/2.0;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case WSTNormal: return QFontMetricsF(currentEv.getFont(parentMathText)).width(' ');
|
case WSTNormal: return fm.width(' ');
|
||||||
case WSTNonbreaking: return QFontMetricsF(currentEv.getFont(parentMathText)).width(' ');
|
case WSTNonbreaking: return fm.width(' ');
|
||||||
case WST1en: return en;
|
case WST1en: return en;
|
||||||
case WST1em: return em;
|
case WST1em: return em;
|
||||||
case WSThair: return em/12.0;
|
case WSThair: return em/12.0;
|
||||||
|
@ -57,8 +57,8 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathTextWhitespaceNode: public JKQTMathTextNod
|
|||||||
};
|
};
|
||||||
/** \brief converts Types \a type into a string */
|
/** \brief converts Types \a type into a string */
|
||||||
static QString Type2String(Types type);
|
static QString Type2String(Types type);
|
||||||
/** \brief converts Types \a type into its width in points (pt), based on \a currentEv */
|
/** \brief converts Types \a type into its width in pixels, based on \a currentEv and \a pd */
|
||||||
double Type2PointWidth(Types type, JKQTMathTextEnvironment currentEv) const;
|
double Type2PixelWidth(Types type, JKQTMathTextEnvironment currentEv, QPaintDevice *pd) const;
|
||||||
/** \brief checks whether a given LaTeX instruction name is supported by this node class type */
|
/** \brief checks whether a given LaTeX instruction name is supported by this node class type */
|
||||||
static bool supportsInstructionName(const QString& instruction);
|
static bool supportsInstructionName(const QString& instruction);
|
||||||
/** \brief constructs a node with count=1 and type=WSTNormal */
|
/** \brief constructs a node with count=1 and type=WSTNormal */
|
||||||
|
Loading…
Reference in New Issue
Block a user