mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-11-15 18:15:52 +08:00
JKQTMathText: improved startup-speed by doing font searches only once per program start (via static variables)
This commit is contained in:
parent
01b6d7cee6
commit
bbfcec74ab
@ -3270,32 +3270,37 @@ JKQTMathText::JKQTMathText(QObject* parent):
|
|||||||
blackboardSimulated=true;
|
blackboardSimulated=true;
|
||||||
|
|
||||||
|
|
||||||
QString serifFont="serif";
|
static QString serifFont="serif";
|
||||||
QString sansFont="sans";
|
static QString sansFont="sans";
|
||||||
QString symbolFont="symbol";
|
static QString symbolFont="symbol";
|
||||||
QString scriptFont="script";
|
static QString scriptFont="script";
|
||||||
QString typewriterFont="typewriter";
|
static QString typewriterFont="typewriter";
|
||||||
QString decorativeFont="decorative";
|
static QString decorativeFont="decorative";
|
||||||
QString blackboardFont="blackboard";
|
static QString blackboardFont="blackboard";
|
||||||
QString fracturFont="fraktur";
|
static QString fracturFont="fraktur";
|
||||||
|
static bool firstStart=true;
|
||||||
|
|
||||||
|
if (firstStart) {
|
||||||
|
firstStart=false;
|
||||||
QStringList fonts=fontdb.families();
|
QStringList fonts=fontdb.families();
|
||||||
//qDebug()<<"fonts:\n"<<fonts;
|
//qDebug()<<"fonts:\n"<<fonts;
|
||||||
|
|
||||||
for (const QString& f: fonts) {
|
for (const QString& f: fonts) {
|
||||||
if (typewriterFont=="typewriter" && QFontInfo(QFont(f)).styleHint()==QFont::TypeWriter) {
|
QFont fnt(f);
|
||||||
|
QFontInfo fi(fnt);
|
||||||
|
if (typewriterFont=="typewriter" && fi.styleHint()==QFont::TypeWriter) {
|
||||||
typewriterFont=f;
|
typewriterFont=f;
|
||||||
}
|
}
|
||||||
if (decorativeFont=="decorative" && QFontInfo(QFont(f)).styleHint()==QFont::Decorative) {
|
if (decorativeFont=="decorative" && fi.styleHint()==QFont::Decorative) {
|
||||||
decorativeFont=f;
|
decorativeFont=f;
|
||||||
}
|
}
|
||||||
if (serifFont=="serif" && QFontInfo(QFont(f)).styleHint()==QFont::Serif) {
|
if (serifFont=="serif" && fi.styleHint()==QFont::Serif) {
|
||||||
serifFont=f;
|
serifFont=f;
|
||||||
}
|
}
|
||||||
if (sansFont=="sans" && QFontInfo(QFont(f)).styleHint()==QFont::SansSerif) {
|
if (sansFont=="sans" && fi.styleHint()==QFont::SansSerif) {
|
||||||
sansFont=f;
|
sansFont=f;
|
||||||
}
|
}
|
||||||
if (scriptFont=="script" && QFontInfo(QFont(f)).styleHint()==QFont::Cursive) {
|
if (scriptFont=="script" && fi.styleHint()==QFont::Cursive) {
|
||||||
scriptFont=f;
|
scriptFont=f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3317,7 +3322,7 @@ JKQTMathText::JKQTMathText(QObject* parent):
|
|||||||
checkForFonts(decorativeFont, QStringList {"Lucida Calligraphy", "Cookie", "Segoe Print", "Comic Sans", "Comic Sans MS", "Gabriola", "Gabriola Standard", "Lucida Handwriting Kursiv", "Lucida Handwriting", "Pristina", "Pristina Standard", "MathJax_Caligraphics"});
|
checkForFonts(decorativeFont, QStringList {"Lucida Calligraphy", "Cookie", "Segoe Print", "Comic Sans", "Comic Sans MS", "Gabriola", "Gabriola Standard", "Lucida Handwriting Kursiv", "Lucida Handwriting", "Pristina", "Pristina Standard", "MathJax_Caligraphics"});
|
||||||
checkForFonts(scriptFont, QStringList {"Lucida Handwriting", "Dancing Script", "Amazone BT", "ScriptS", "ScriptC", "ScriptC Standard", "Script", "Brush Script MT", "Brush Script MT Kursiv", "MathJax_Script"});
|
checkForFonts(scriptFont, QStringList {"Lucida Handwriting", "Dancing Script", "Amazone BT", "ScriptS", "ScriptC", "ScriptC Standard", "Script", "Brush Script MT", "Brush Script MT Kursiv", "MathJax_Script"});
|
||||||
checkForFonts(fracturFont, QStringList {"Old English Text MT", "Old English Text MT Standard", "UnifrakturMaguntia Standard", "UnifrakturMaguntia", "MathJax_Fraktur", "UnifrakturCook Fett"});
|
checkForFonts(fracturFont, QStringList {"Old English Text MT", "Old English Text MT Standard", "UnifrakturMaguntia Standard", "UnifrakturMaguntia", "MathJax_Fraktur", "UnifrakturCook Fett"});
|
||||||
|
}
|
||||||
|
|
||||||
if (serifFont!="serif") addReplacementFont("serif", serifFont);
|
if (serifFont!="serif") addReplacementFont("serif", serifFont);
|
||||||
if (sansFont!="sans") addReplacementFont("sans", sansFont);
|
if (sansFont!="sans") addReplacementFont("sans", sansFont);
|
||||||
@ -3406,13 +3411,14 @@ void JKQTMathText::saveSettings(QSettings& settings, const QString& group) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool JKQTMathText::useSTIX(bool mathModeOnly) {
|
bool JKQTMathText::useSTIX(bool mathModeOnly) {
|
||||||
QFontDatabase fdb;
|
|
||||||
|
|
||||||
static QStringList mathNames{"STIX Two Math", "STIX Math", "STIX Two Math Standard", "STIX Math Standard"};
|
static QStringList mathNames{"STIX Two Math", "STIX Math", "STIX Two Math Standard", "STIX Math Standard"};
|
||||||
static QStringList textNames{"STIX", "STIXGeneral", "STIX General"};
|
static QStringList textNames{"STIX", "STIXGeneral", "STIX General"};
|
||||||
|
|
||||||
QString textFamily;
|
static QString textFamily;
|
||||||
QString mathFamily;
|
static QString mathFamily;
|
||||||
|
if (textFamily.isEmpty() && mathFamily.isEmpty()) {
|
||||||
|
QFontDatabase fdb;
|
||||||
for (const QString& name:mathNames) {
|
for (const QString& name:mathNames) {
|
||||||
for (int i=0; i<fdb.families().size(); i++) {
|
for (int i=0; i<fdb.families().size(); i++) {
|
||||||
if (fdb.families().at(i).contains(name) ) {
|
if (fdb.families().at(i).contains(name) ) {
|
||||||
@ -3444,6 +3450,7 @@ bool JKQTMathText::useSTIX(bool mathModeOnly) {
|
|||||||
} else if (!mathFamily.isEmpty() && textFamily.isEmpty()) {
|
} else if (!mathFamily.isEmpty() && textFamily.isEmpty()) {
|
||||||
textFamily=mathFamily;
|
textFamily=mathFamily;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool res=false;
|
bool res=false;
|
||||||
|
|
||||||
@ -3473,8 +3480,9 @@ bool JKQTMathText::useXITS(bool mathModeOnly)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString textFamily;
|
static QString textFamily;
|
||||||
QString mathFamily;
|
static QString mathFamily;
|
||||||
|
if (textFamily.isEmpty() && mathFamily.isEmpty()) {
|
||||||
for (int i=0; i<fdb.families().size(); i++) {
|
for (int i=0; i<fdb.families().size(); i++) {
|
||||||
if (fdb.families().at(i).contains("XITS Math")) {
|
if (fdb.families().at(i).contains("XITS Math")) {
|
||||||
mathFamily=fdb.families().at(i);
|
mathFamily=fdb.families().at(i);
|
||||||
@ -3490,6 +3498,7 @@ bool JKQTMathText::useXITS(bool mathModeOnly)
|
|||||||
} else if (!mathFamily.isEmpty() && textFamily.isEmpty()) {
|
} else if (!mathFamily.isEmpty() && textFamily.isEmpty()) {
|
||||||
textFamily=mathFamily;
|
textFamily=mathFamily;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool res=false;
|
bool res=false;
|
||||||
|
|
||||||
@ -3510,14 +3519,14 @@ bool JKQTMathText::useXITS(bool mathModeOnly)
|
|||||||
bool JKQTMathText::useASANA(bool mathModeOnly)
|
bool JKQTMathText::useASANA(bool mathModeOnly)
|
||||||
{
|
{
|
||||||
QFontDatabase fdb;
|
QFontDatabase fdb;
|
||||||
|
|
||||||
if (!fdb.families().contains("Asana") && !fdb.families().contains("Asana Math")) {
|
if (!fdb.families().contains("Asana") && !fdb.families().contains("Asana Math")) {
|
||||||
if (QFile::exists(":/JKQTMathText/fonts/asana-math.otf")) { /*i=*/QFontDatabase::addApplicationFont(":/JKQTMathText/fonts/asana-math.otf"); }
|
if (QFile::exists(":/JKQTMathText/fonts/asana-math.otf")) { /*i=*/QFontDatabase::addApplicationFont(":/JKQTMathText/fonts/asana-math.otf"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString textFamily;
|
static QString textFamily;
|
||||||
QString mathFamily;
|
static QString mathFamily;
|
||||||
|
if (textFamily.isEmpty() && mathFamily.isEmpty()) {
|
||||||
for (int i=0; i<fdb.families().size(); i++) {
|
for (int i=0; i<fdb.families().size(); i++) {
|
||||||
if (fdb.families().at(i).contains("Asana Math")) {
|
if (fdb.families().at(i).contains("Asana Math")) {
|
||||||
mathFamily=fdb.families().at(i);
|
mathFamily=fdb.families().at(i);
|
||||||
@ -3533,6 +3542,7 @@ bool JKQTMathText::useASANA(bool mathModeOnly)
|
|||||||
} else if (!mathFamily.isEmpty() && textFamily.isEmpty()) {
|
} else if (!mathFamily.isEmpty() && textFamily.isEmpty()) {
|
||||||
textFamily=mathFamily;
|
textFamily=mathFamily;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool res=false;
|
bool res=false;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user