2019-01-26 19:28:44 +08:00
/*
2022-06-08 21:38:26 +08:00
Copyright ( c ) 2008 - 2022 Jan W . Krieger ( < jan @ jkrieger . de > )
2019-01-26 19:28:44 +08:00
This software is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License ( LGPL ) as published by
2019-02-08 00:24:46 +08:00
the Free Software Foundation , either version 2.1 of the License , or
2019-01-26 19:28:44 +08:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License ( LGPL ) for more details .
You should have received a copy of the GNU Lesser General Public License ( LGPL )
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# include "jkqtmathtext/jkqtmathtext.h"
2022-06-08 21:38:26 +08:00
# include "jkqtmathtext/nodes/jkqtmathtextnode.h"
2019-05-30 04:40:02 +08:00
# include "jkqtcommon/jkqtpcodestructuring.h"
# include "jkqtcommon/jkqtpstringtools.h"
2022-08-19 18:16:00 +08:00
# include "jkqtmathtext/nodes/jkqtmathtextnodetools.h"
2022-06-08 21:38:26 +08:00
# include "jkqtmathtext/nodes/jkqtmathtexttextnode.h"
# include "jkqtmathtext/nodes/jkqtmathtextbracenode.h"
# include "jkqtmathtext/nodes/jkqtmathtextdecoratednode.h"
# include "jkqtmathtext/nodes/jkqtmathtextfracnode.h"
# include "jkqtmathtext/nodes/jkqtmathtextinstructionnode.h"
# include "jkqtmathtext/nodes/jkqtmathtextlistnode.h"
# include "jkqtmathtext/nodes/jkqtmathtextmatrixnode.h"
# include "jkqtmathtext/nodes/jkqtmathtextsqrtnode.h"
# include "jkqtmathtext/nodes/jkqtmathtextsubsupernode.h"
# include "jkqtmathtext/nodes/jkqtmathtextsymbolnode.h"
2022-07-04 02:30:12 +08:00
# include "jkqtmathtext/nodes/jkqtmathtextwhitespacenode.h"
2022-08-19 18:16:00 +08:00
# include "jkqtmathtext/nodes/jkqtmathtextboxinstructionnode.h"
# include "jkqtmathtext/nodes/jkqtmathtexthorizontallistnode.h"
# include "jkqtmathtext/nodes/jkqtmathtextmodifyenvironmentnode.h"
# include "jkqtmathtext/nodes/jkqtmathtextnoopnode.h"
# include "jkqtmathtext/nodes/jkqtmathtextverbatimnode.h"
# include "jkqtmathtext/nodes/jkqtmathtextverticallistnode.h"
2022-08-20 22:19:40 +08:00
# include "jkqtmathtext/parsers/jkqtmathtextlatexparser.h"
2019-05-30 04:40:02 +08:00
# include <cmath>
2019-01-26 19:28:44 +08:00
# include <QFontMetricsF>
# include <QDebug>
# include <QFontDatabase>
# include <typeinfo>
2020-08-14 20:12:59 +08:00
# include <QPainterPath>
2019-01-26 19:28:44 +08:00
2022-04-21 16:57:24 +08:00
2022-09-01 20:36:34 +08:00
// --------------------------------------------------------------------------------------------------
// -- instanciation of the static JKQTMathText members
// --------------------------------------------------------------------------------------------------
2019-02-08 00:24:46 +08:00
const double JKQTMathText : : ABS_MIN_LINEWIDTH = 0.02 ;
2022-09-01 20:36:34 +08:00
QString JKQTMathText : : init_serifFont = " serif " ;
QString JKQTMathText : : init_sansFont = " sans " ;
QString JKQTMathText : : init_symbolFont = " symbol " ;
QString JKQTMathText : : init_scriptFont = " script " ;
QString JKQTMathText : : init_typewriterFont = " typewriter " ;
QString JKQTMathText : : init_caligraphicFont = " decorative " ;
QString JKQTMathText : : init_blackboardFont = " blackboard " ;
QString JKQTMathText : : init_fracturFont = " fraktur " ;
bool JKQTMathText : : s_firstStart = true ;
2019-01-26 19:28:44 +08:00
2022-06-03 19:33:18 +08:00
2019-06-30 23:34:41 +08:00
// --------------------------------------------------------------------------------------------------
// -- implementation of the JKQTMathText methods
// --------------------------------------------------------------------------------------------------
2022-09-01 20:36:34 +08:00
JKQTMathText : : JKQTMathText ( QObject * parent , bool useFontsForGUI ) :
2019-06-30 23:34:41 +08:00
QObject ( parent )
{
2019-11-24 19:48:20 +08:00
//std::chrono::high_resolution_clock::time_point t0=std::chrono::high_resolution_clock::now();
2020-06-28 15:49:20 +08:00
initJKQTMathTextResources ( ) ;
2019-11-24 19:48:20 +08:00
//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();
2019-06-30 23:34:41 +08:00
fontSize = 10 ;
2022-07-05 03:02:43 +08:00
fontSizeUnits = JKQTMathTextEnvironment : : POINTS ;
2022-06-27 05:42:06 +08:00
fontColor = QColor ( " black " ) ;
2019-06-30 23:34:41 +08:00
brace_factor = 1.04 ;
2022-06-27 05:42:06 +08:00
brace_y_shift_factor = 0.7 ; //-1;
2022-08-12 22:50:26 +08:00
subsuper_size_factor = 0.65 ;
2022-06-26 06:28:49 +08:00
subsuper_mode_selection_by_size_factor = 1.01 ;
2019-06-30 23:34:41 +08:00
sub_shift_factor = 0.4 ;
2022-06-26 06:28:49 +08:00
super_shift_factor = 0.7 ;
special_sub_shift_factor = 0.4 ;
special_super_shift_factor = 0.4 ;
2019-06-30 23:34:41 +08:00
2022-06-09 05:52:22 +08:00
frac_factor = 1.0 ;
frac_nested_factor = 0.7 ;
2019-06-30 23:34:41 +08:00
frac_shift_factor = 0.4 ;
2022-06-27 05:42:06 +08:00
2019-06-30 23:34:41 +08:00
underbrace_factor = 0.75 ;
2022-06-28 03:09:22 +08:00
underbrace_separation_xfactor = 0.25 ;
underbrace_bracesize_xfactor = 0.5 ;
2022-06-20 18:17:32 +08:00
underset_factor = 0.7 ;
2022-06-29 05:14:31 +08:00
decoration_height_factor = 0.3 ;
2022-06-07 05:24:05 +08:00
decoration_width_reduction_Xfactor = 0.2 ;
2022-06-29 05:14:31 +08:00
decoration_separation_factor = 0.1 ;
2022-06-27 05:42:06 +08:00
2019-06-30 23:34:41 +08:00
operatorsubsuper_size_factor = 0.65 ;
2022-08-18 04:56:57 +08:00
operatorsubsuper_distance_factor = 0.35 ;
2022-06-26 06:28:49 +08:00
operatorsubsuper_extraspace_factor = 0.5 ;
2022-06-28 04:57:49 +08:00
intsubsuper_xcorrection_factor = 0.25 ;
intsubbesides_xcorrection_xfactor = 0.33 ;
2022-08-02 18:10:59 +08:00
mathoperator_width_factor = 1.5 ;
2022-06-26 06:28:49 +08:00
bigmathoperator_font_factor = 1.8 ;
2019-06-30 23:34:41 +08:00
2022-06-28 18:00:20 +08:00
sqrt_width_Xfactor = 0.8 ;
sqrt_height_factor = 1.2 ;
sqrt_smallfont_factor = 0.57 ;
2022-08-12 18:54:10 +08:00
matrix_linewidth_thin_factor = 0.4 ;
matrix_linewidth_heavy_factor = 1.5 ;
matrix_line_separation_factor = 2.0 ;
2022-08-19 18:16:00 +08:00
matrix_xSeparation_factor = 0.75 ;
matrix_ySeparation_factor = 0.6 ;
matrix_xPadding_factor = 0.75 ;
matrix_yPadding_factor = 0.75 ;
2022-08-12 18:54:10 +08:00
2022-08-10 18:12:30 +08:00
blackboradFontMode = MTBBDMdefault ;
2019-06-30 23:34:41 +08:00
2019-06-30 23:59:04 +08:00
2022-09-01 20:36:34 +08:00
if ( s_firstStart ) {
2019-11-24 19:48:20 +08:00
//t0=std::chrono::high_resolution_clock::now();
2022-09-01 20:36:34 +08:00
s_firstStart = false ;
2022-06-03 04:31:39 +08:00
# if (QT_VERSION<QT_VERSION_CHECK(6, 0, 0))
QFontDatabase fdb ;
const auto fonts = fdb . families ( ) ;
# else
const auto fonts = QFontDatabase : : families ( ) ;
# endif
2019-11-24 19:48:20 +08:00
2019-06-30 23:34:41 +08:00
2019-06-30 23:59:04 +08:00
auto checkForFonts = [ & fonts ] ( QString & targetfont , const QStringList & fontoptions ) {
for ( auto & f : fontoptions ) {
if ( fonts . contains ( f ) ) {
targetfont = f ;
break ;
}
}
} ;
2019-06-30 23:34:41 +08:00
2022-09-01 20:36:34 +08:00
checkForFonts ( init_serifFont , QStringList { " Times New Roman " , " Times " , " FreeSerif " , " DejaVu Serif " } ) ;
2019-11-24 19:48:20 +08:00
//qDebug()<<"check 1st font: "<<std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now()-t0).count()/1000.0<<"ms";
2022-09-01 20:36:34 +08:00
checkForFonts ( init_sansFont , QStringList { " Segoe UI " , " Arial Unicode MS " , " Arial Unicode " , " Lucida Sans Unicode " , " Arial " , " Helvetica " , " FreeSans " , " DejaVu Sans " , " Lucida Sans " } ) ;
checkForFonts ( init_symbolFont , QStringList { " Segoe UI Symbol " , " XITS Math " , " Cambria Math " , " Fira Math " , " Lucida Bright Math " , " SymbolStandard " , " Symbol " } ) ;
checkForFonts ( init_typewriterFont , QStringList { " Courier New " , " Courier " , " Courier Std " , " FreeMono " , " CMU Typewriter Text " , " UM Typewriter " } ) ;
checkForFonts ( init_blackboardFont , QStringList { " Double Stroke " , " CloisterOpenFace BT " , " GoudyHandtooled BT " , " Castellar " , " MathJax_AMS " , " Castellar Standard " , " MathJax_AMS Standard " , " Colonna MT " } ) ;
checkForFonts ( init_caligraphicFont , 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 ( init_scriptFont , QStringList { " Lucida Handwriting " , " Dancing Script " , " Amazone BT " , " ScriptS " , " ScriptC " , " ScriptC Standard " , " Script " , " Brush Script MT " , " Brush Script MT Kursiv " , " MathJax_Script " } ) ;
checkForFonts ( init_fracturFont , QStringList { " Old English Text MT " , " Old English Text MT Standard " , " UnifrakturMaguntia Standard " , " UnifrakturMaguntia " , " MathJax_Fraktur " , " UnifrakturCook Fett " } ) ;
2019-11-24 19:48:20 +08:00
//qDebug()<<"check all font: "<<std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now()-t0).count()/1000.0<<"ms";
2019-06-30 23:59:04 +08:00
}
2019-06-30 23:34:41 +08:00
2019-11-24 19:48:20 +08:00
//t0=std::chrono::high_resolution_clock::now();
2022-09-01 20:36:34 +08:00
if ( init_serifFont ! = " serif " ) addReplacementFont ( " serif " , init_serifFont ) ;
if ( init_sansFont ! = " sans " ) addReplacementFont ( " sans " , init_sansFont ) ;
if ( init_symbolFont ! = " symbol " ) addReplacementFont ( " symbol " , init_symbolFont ) ;
if ( init_scriptFont ! = " script " ) addReplacementFont ( " script " , init_scriptFont ) ;
if ( init_typewriterFont ! = " typewriter " ) addReplacementFont ( " typewriter " , init_typewriterFont ) ;
if ( init_caligraphicFont ! = " decorative " ) addReplacementFont ( " decorative " , init_caligraphicFont ) ;
if ( init_fracturFont ! = " fraktur " ) addReplacementFont ( " fraktur " , init_fracturFont ) ;
if ( init_blackboardFont ! = " blackboard " ) {
addReplacementFont ( " blackboard " , init_blackboardFont ) ;
2019-06-30 23:34:41 +08:00
}
2019-11-24 19:48:20 +08:00
//qDebug()<<"add replacement 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();
2022-09-01 20:36:34 +08:00
setFontSans ( init_sansFont , estimateJKQTMathTextFontEncoding ( init_sansFont ) ) ;
setFontMathSans ( init_sansFont , estimateJKQTMathTextFontEncoding ( init_sansFont ) ) ;
setFontTypewriter ( init_typewriterFont , estimateJKQTMathTextFontEncoding ( init_typewriterFont ) ) ;
setFontRoman ( init_serifFont , estimateJKQTMathTextFontEncoding ( init_serifFont ) ) ;
setFontMathRoman ( init_serifFont , estimateJKQTMathTextFontEncoding ( init_serifFont ) ) ;
setFontCaligraphic ( init_caligraphicFont , estimateJKQTMathTextFontEncoding ( init_caligraphicFont ) ) ;
if ( init_blackboardFont ! = " blackboard " ) {
setFontBlackboard ( init_blackboardFont , estimateJKQTMathTextFontEncoding ( init_blackboardFont ) ) ;
2022-08-10 18:12:30 +08:00
setFontBlackboradMode ( MTBBDMunicodeCharactersOrFontDirectly ) ;
2022-07-04 02:30:12 +08:00
} else {
2022-09-01 20:36:34 +08:00
setFontBlackboard ( init_sansFont , estimateJKQTMathTextFontEncoding ( init_sansFont ) ) ;
2022-08-10 18:12:30 +08:00
setFontBlackboradMode ( MTBBDMunicodeCharactersOrSimulate ) ;
2022-07-04 02:30:12 +08:00
}
2022-09-01 20:36:34 +08:00
setFontScript ( init_scriptFont , estimateJKQTMathTextFontEncoding ( init_scriptFont ) ) ;
setFontFraktur ( init_fracturFont , estimateJKQTMathTextFontEncoding ( init_fracturFont ) ) ;
setFallbackFontSymbols ( init_symbolFont , estimateJKQTMathTextFontEncoding ( init_symbolFont ) ) ;
2019-11-24 19:48:20 +08:00
//qDebug()<<"set 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();
2019-06-30 23:34:41 +08:00
useXITS ( ) ;
2019-11-24 19:48:20 +08:00
//qDebug()<<"useXITS: "<<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();
2022-09-01 20:36:34 +08:00
if ( useFontsForGUI ) useGuiFonts ( ) ;
2019-06-30 23:34:41 +08:00
parsedNode = nullptr ;
}
JKQTMathText : : ~ JKQTMathText ( ) {
if ( parsedNode ! = nullptr ) delete parsedNode ;
parsedNode = nullptr ;
}
void JKQTMathText : : loadSettings ( const QSettings & settings , const QString & group ) {
fontSize = settings . value ( group + " font_size " , fontSize ) . toDouble ( ) ;
2022-07-05 03:02:43 +08:00
fontSizeUnits = JKQTMathTextEnvironment : : String2FontSizeUnit ( settings . value ( group + " font_size_units " , JKQTMathTextEnvironment : : FontSizeUnit2String ( fontSizeUnits ) ) . toString ( ) ) ;
2019-06-30 23:34:41 +08:00
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 ( ) ;
2022-06-26 06:28:49 +08:00
subsuper_mode_selection_by_size_factor = settings . value ( group + " subsuper_mode_selection_by_size_factor " , subsuper_mode_selection_by_size_factor ) . toDouble ( ) ;
2019-06-30 23:34:41 +08:00
super_shift_factor = settings . value ( group + " super_shift_factor " , super_shift_factor ) . toDouble ( ) ;
sub_shift_factor = settings . value ( group + " sub_shift_factor " , sub_shift_factor ) . toDouble ( ) ;
2022-06-26 06:28:49 +08:00
special_super_shift_factor = settings . value ( group + " special_super_shift_factor " , special_super_shift_factor ) . toDouble ( ) ;
special_sub_shift_factor = settings . value ( group + " special_sub_shift_factor " , special_sub_shift_factor ) . toDouble ( ) ;
2019-06-30 23:34:41 +08:00
frac_factor = settings . value ( group + " frac_factor " , frac_factor ) . toDouble ( ) ;
frac_shift_factor = settings . value ( group + " frac_shift_factor " , frac_shift_factor ) . toDouble ( ) ;
underbrace_factor = settings . value ( group + " underbrace_factor " , underbrace_factor ) . toDouble ( ) ;
2022-06-28 03:09:22 +08:00
underbrace_bracesize_xfactor = settings . value ( group + " underbrace_bracesize_xfactor " , underbrace_bracesize_xfactor ) . toDouble ( ) ;
underbrace_separation_xfactor = settings . value ( group + " underbrace_separation_xfactor " , underbrace_separation_xfactor ) . toDouble ( ) ;
2022-07-04 02:30:12 +08:00
underset_factor = settings . value ( group + " underset_factor " , underset_factor ) . toDouble ( ) ;
2019-06-30 23:34:41 +08:00
brace_y_shift_factor = settings . value ( group + " brace_y_shift_factor " , brace_y_shift_factor ) . toDouble ( ) ;
decoration_height_factor = settings . value ( group + " decoration_height_factor " , decoration_height_factor ) . toDouble ( ) ;
2022-06-29 05:14:31 +08:00
decoration_separation_factor = settings . value ( group + " decoration_separation_factor " , decoration_separation_factor ) . toDouble ( ) ;
2022-06-07 05:24:05 +08:00
decoration_width_reduction_Xfactor = settings . value ( group + " decoration_width_reduction_xfactor " , decoration_width_reduction_Xfactor ) . toDouble ( ) ;
2019-06-30 23:34:41 +08:00
operatorsubsuper_size_factor = settings . value ( group + " operatorsubsuper_size_factor " , operatorsubsuper_size_factor ) . toDouble ( ) ;
2022-06-26 06:28:49 +08:00
operatorsubsuper_distance_factor = settings . value ( group + " operatorsubsuper_distance_factor " , operatorsubsuper_distance_factor ) . toDouble ( ) ;
operatorsubsuper_extraspace_factor = settings . value ( group + " operatorsubsuper_extraspace_factor " , operatorsubsuper_extraspace_factor ) . toDouble ( ) ;
2019-06-30 23:34:41 +08:00
mathoperator_width_factor = settings . value ( group + " mathoperator_width_factor " , mathoperator_width_factor ) . toDouble ( ) ;
2022-06-28 04:57:49 +08:00
intsubsuper_xcorrection_factor = settings . value ( group + " intsubsuper_xcorrection_factor " , intsubsuper_xcorrection_factor ) . toDouble ( ) ;
intsubbesides_xcorrection_xfactor = settings . value ( group + " intsubbesides_xcorrection_xfactor " , intsubbesides_xcorrection_xfactor ) . toDouble ( ) ;
2022-06-28 18:00:20 +08:00
sqrt_width_Xfactor = settings . value ( group + " sqrt_width_Xfactor " , sqrt_width_Xfactor ) . toDouble ( ) ;
sqrt_height_factor = settings . value ( group + " sqrt_height_factor " , sqrt_height_factor ) . toDouble ( ) ;
sqrt_smallfont_factor = settings . value ( group + " sqrt_smallfont_factor " , sqrt_smallfont_factor ) . toDouble ( ) ;
2022-07-04 02:30:12 +08:00
bigmathoperator_font_factor = settings . value ( group + " bigmathoperator_font_factor " , bigmathoperator_font_factor ) . toDouble ( ) ;
frac_nested_factor = settings . value ( group + " frac_nested_factor " , frac_nested_factor ) . toDouble ( ) ;
2019-06-30 23:34:41 +08:00
2022-08-12 18:54:10 +08:00
matrix_linewidth_thin_factor = settings . value ( group + " matrix_linewidth_thin_factor " , matrix_linewidth_thin_factor ) . toDouble ( ) ;
matrix_linewidth_heavy_factor = settings . value ( group + " matrix_linewidth_heavy_factor " , matrix_linewidth_heavy_factor ) . toDouble ( ) ;
matrix_line_separation_factor = settings . value ( group + " matrix_line_separation_factor " , matrix_line_separation_factor ) . toDouble ( ) ;
matrix_xSeparation_factor = settings . value ( group + " matrix_xSeparation_factor " , matrix_xSeparation_factor ) . toDouble ( ) ;
matrix_ySeparation_factor = settings . value ( group + " matrix_ySeparation_factor " , matrix_ySeparation_factor ) . toDouble ( ) ;
matrix_xPadding_factor = settings . value ( group + " matrix_xPadding_factor " , matrix_xPadding_factor ) . toDouble ( ) ;
matrix_yPadding_factor = settings . value ( group + " matrix_yPadding_factor " , matrix_yPadding_factor ) . toDouble ( ) ;
2019-06-30 23:34:41 +08:00
if ( settings . value ( group + " use_stix_fonts " , false ) . toBool ( ) ) useSTIX ( ) ;
if ( settings . value ( group + " use_xits_fonts " , false ) . toBool ( ) ) useXITS ( ) ;
if ( settings . value ( group + " use_asana_fonts " , false ) . toBool ( ) ) useASANA ( ) ;
}
void JKQTMathText : : saveSettings ( QSettings & settings , const QString & group ) const {
settings . setValue ( group + " font_size " , fontSize ) ;
2022-07-05 03:02:43 +08:00
settings . setValue ( group + " font_size_units " , JKQTMathTextEnvironment : : FontSizeUnit2String ( fontSizeUnits ) ) ;
2019-06-30 23:34:41 +08:00
settings . setValue ( group + " font_color " , jkqtp_QColor2String ( fontColor ) ) ;
settings . setValue ( group + " brace_factor " , brace_factor ) ;
settings . setValue ( group + " subsuper_size_factor " , subsuper_size_factor ) ;
2022-06-26 06:28:49 +08:00
settings . setValue ( group + " subsuper_mode_selection_by_size_factor " , subsuper_mode_selection_by_size_factor ) ;
2019-06-30 23:34:41 +08:00
settings . setValue ( group + " sub_shift_factor " , sub_shift_factor ) ;
settings . setValue ( group + " super_shift_factor " , super_shift_factor ) ;
2022-06-26 06:28:49 +08:00
settings . setValue ( group + " special_sub_shift_factor " , special_sub_shift_factor ) ;
settings . setValue ( group + " special_super_shift_factor " , special_super_shift_factor ) ;
2019-06-30 23:34:41 +08:00
settings . setValue ( group + " frac_factor " , frac_factor ) ;
settings . setValue ( group + " frac_shift_factor " , frac_shift_factor ) ;
settings . setValue ( group + " underbrace_factor " , underbrace_factor ) ;
2022-06-28 03:09:22 +08:00
settings . setValue ( group + " underbrace_bracesize_xfactor " , underbrace_bracesize_xfactor ) ;
settings . setValue ( group + " underbrace_separation_xfactor " , underbrace_separation_xfactor ) ;
2022-07-04 02:30:12 +08:00
settings . setValue ( group + " underset_factor " , underset_factor ) ;
2019-06-30 23:34:41 +08:00
settings . setValue ( group + " operatorsubsuper_size_factor " , operatorsubsuper_size_factor ) ;
2022-06-26 06:28:49 +08:00
settings . setValue ( group + " operatorsubsuper_distance_factor " , operatorsubsuper_distance_factor ) ;
settings . setValue ( group + " operatorsubsuper_extraspace_factor " , operatorsubsuper_extraspace_factor ) ;
2019-06-30 23:34:41 +08:00
settings . setValue ( group + " mathoperator_width_factor " , mathoperator_width_factor ) ;
2022-06-28 04:57:49 +08:00
settings . setValue ( group + " intsubsuper_xcorrection_factor " , intsubsuper_xcorrection_factor ) ;
settings . setValue ( group + " intsubbesides_xcorrection_xfactor " , intsubbesides_xcorrection_xfactor ) ;
2019-06-30 23:34:41 +08:00
settings . setValue ( group + " brace_y_shift_factor " , brace_y_shift_factor ) ;
settings . setValue ( group + " decoration_height_factor " , decoration_height_factor ) ;
2022-06-29 05:14:31 +08:00
settings . setValue ( group + " decoration_separation_factor " , decoration_separation_factor ) ;
2022-06-07 05:24:05 +08:00
settings . setValue ( group + " decoration_width_reduction_xfactor " , decoration_width_reduction_Xfactor ) ;
2022-06-28 18:00:20 +08:00
settings . setValue ( group + " sqrt_width_Xfactor " , sqrt_width_Xfactor ) ;
settings . setValue ( group + " sqrt_height_factor " , sqrt_height_factor ) ;
settings . setValue ( group + " sqrt_smallfont_factor " , sqrt_smallfont_factor ) ;
2022-07-04 02:30:12 +08:00
settings . setValue ( group + " bigmathoperator_font_factor " , bigmathoperator_font_factor ) ;
settings . setValue ( group + " frac_nested_factor " , frac_nested_factor ) ;
2022-08-12 18:54:10 +08:00
settings . setValue ( group + " matrix_linewidth_thin_factor " , matrix_linewidth_thin_factor ) ;
settings . setValue ( group + " matrix_linewidth_heavy_factor " , matrix_linewidth_heavy_factor ) ;
settings . setValue ( group + " matrix_line_separation_factor " , matrix_line_separation_factor ) ;
settings . setValue ( group + " matrix_xSeparation_factor " , matrix_xSeparation_factor ) ;
settings . setValue ( group + " matrix_ySeparation_factor " , matrix_ySeparation_factor ) ;
settings . setValue ( group + " matrix_xPadding_factor " , matrix_xPadding_factor ) ;
settings . setValue ( group + " matrix_yPadding_factor " , matrix_yPadding_factor ) ;
2019-06-30 23:34:41 +08:00
}
2022-09-20 03:53:53 +08:00
bool JKQTMathText : : parse ( const QString & markup , DefaultParserTypes markupType , ParseOptions options )
2022-08-20 22:19:40 +08:00
{
2022-09-20 03:53:53 +08:00
if ( markupType = = LatexParser ) return parse < JKQTMathTextLatexParser > ( markup , options ) ;
2022-08-20 22:19:40 +08:00
return false ;
}
2022-08-21 20:49:48 +08:00
bool JKQTMathText : : useSTIX ( bool mathModeOnly , bool useAsFallbackSymbol ) {
2019-06-30 23:34:41 +08:00
2022-07-04 02:30:12 +08:00
const JKQTMathTextFontSpecifier stixs = JKQTMathTextFontSpecifier : : getSTIXFamilies ( ) ;
2019-06-30 23:34:41 +08:00
bool res = false ;
2022-07-04 02:30:12 +08:00
if ( ! mathModeOnly & & ! stixs . fontName ( ) . isEmpty ( ) ) {
setFontRoman ( stixs . fontName ( ) , MTFEUnicode ) ;
2019-06-30 23:34:41 +08:00
res = true ;
}
2022-07-04 02:30:12 +08:00
if ( ! stixs . mathFontName ( ) . isEmpty ( ) ) {
setFontMathRoman ( stixs . mathFontName ( ) , MTFEUnicode ) ;
2022-08-21 20:49:48 +08:00
if ( useAsFallbackSymbol ) setFallbackFontSymbols ( stixs . fallbackSymbolsFontName ( ) , MTFEUnicode ) ;
2022-06-03 03:02:23 +08:00
res = true ;
2022-07-04 02:30:12 +08:00
} else if ( ! stixs . fontName ( ) . isEmpty ( ) ) {
setFontMathRoman ( stixs . fontName ( ) , MTFEUnicode ) ;
2022-08-21 20:49:48 +08:00
if ( useAsFallbackSymbol ) setFallbackFontSymbols ( stixs . fallbackSymbolsFontName ( ) , MTFEUnicode ) ;
2019-06-30 23:34:41 +08:00
res = true ;
}
return res ;
}
2022-08-21 20:49:48 +08:00
bool JKQTMathText : : useXITS ( bool mathModeOnly , bool useAsFallbackSymbol )
2019-06-30 23:34:41 +08:00
{
2022-06-03 03:02:23 +08:00
const JKQTMathTextFontSpecifier xits = JKQTMathTextFontSpecifier : : getXITSFamilies ( ) ;
2019-06-30 23:34:41 +08:00
bool res = false ;
2022-06-03 03:02:23 +08:00
if ( ! mathModeOnly & & ! xits . fontName ( ) . isEmpty ( ) ) {
2022-07-04 02:30:12 +08:00
setFontRoman ( xits . fontName ( ) , MTFEUnicode ) ;
2022-08-21 20:49:48 +08:00
if ( useAsFallbackSymbol ) setFallbackFontSymbols ( xits . fallbackSymbolsFontName ( ) , MTFEUnicode ) ;
2019-06-30 23:34:41 +08:00
res = true ;
}
2022-06-03 03:02:23 +08:00
if ( ! xits . mathFontName ( ) . isEmpty ( ) ) {
2022-07-04 02:30:12 +08:00
setFontMathRoman ( xits . mathFontName ( ) , MTFEUnicode ) ;
2022-08-21 20:49:48 +08:00
if ( useAsFallbackSymbol ) setFallbackFontSymbols ( xits . fallbackSymbolsFontName ( ) , MTFEUnicode ) ;
2019-06-30 23:34:41 +08:00
res = true ;
}
return res ;
}
2022-09-01 20:36:34 +08:00
bool JKQTMathText : : useFiraMath ( bool mathModeOnly , bool useAsFallbackSymbol )
{
const JKQTMathTextFontSpecifier fira = JKQTMathTextFontSpecifier : : getFIRAFamilies ( ) ;
bool res = false ;
qDebug ( ) < < " useFiraMath( " < < mathModeOnly < < " , " < < useAsFallbackSymbol < < " ) " ;
if ( ! mathModeOnly & & ! fira . fontName ( ) . isEmpty ( ) ) {
setFontRoman ( fira . fontName ( ) , MTFEUnicode ) ;
if ( useAsFallbackSymbol ) setFallbackFontSymbols ( fira . fallbackSymbolsFontName ( ) , MTFEUnicode ) ;
res = true ;
}
if ( ! fira . mathFontName ( ) . isEmpty ( ) ) {
setFontMathRoman ( fira . mathFontName ( ) , MTFEUnicode ) ;
if ( useAsFallbackSymbol ) setFallbackFontSymbols ( fira . fallbackSymbolsFontName ( ) , MTFEUnicode ) ;
res = true ;
}
//std::cout<<"useFiraMath("<<mathModeOnly<<", "<<useAsFallbackSymbol<<") roman="<<getFontRoman().toStdString()<<", mathRoman="<<getFontMathRoman().toStdString()<<", symbol="<<getFallbackFontSymbols().toStdString();
return res ;
}
2022-08-21 20:49:48 +08:00
bool JKQTMathText : : useASANA ( bool mathModeOnly , bool useAsFallbackSymbol )
2019-06-30 23:34:41 +08:00
{
2022-08-21 20:49:48 +08:00
const JKQTMathTextFontSpecifier asana = JKQTMathTextFontSpecifier : : getASANAFamilies ( ) ;
2019-06-30 23:34:41 +08:00
bool res = false ;
2022-06-03 03:02:23 +08:00
if ( ! mathModeOnly & & ! asana . fontName ( ) . isEmpty ( ) ) {
2022-07-04 02:30:12 +08:00
setFontRoman ( asana . fontName ( ) , MTFEUnicode ) ;
2022-08-21 20:49:48 +08:00
if ( useAsFallbackSymbol ) setFallbackFontSymbols ( asana . fallbackSymbolsFontName ( ) , MTFEUnicode ) ;
2019-06-30 23:34:41 +08:00
res = true ;
}
2022-06-03 03:02:23 +08:00
if ( ! asana . mathFontName ( ) . isEmpty ( ) ) {
2022-07-04 02:30:12 +08:00
setFontMathRoman ( asana . mathFontName ( ) , MTFEUnicode ) ;
2022-08-21 20:49:48 +08:00
if ( useAsFallbackSymbol ) setFallbackFontSymbols ( asana . fallbackSymbolsFontName ( ) , MTFEUnicode ) ;
2019-06-30 23:34:41 +08:00
res = true ;
}
return res ;
}
2022-09-01 20:36:34 +08:00
bool JKQTMathText : : useGuiFonts ( )
{
const JKQTMathTextFontSpecifier rm = JKQTMathTextFontSpecifier : : getAppFontFamilies ( ) ;
const JKQTMathTextFontSpecifier sf = JKQTMathTextFontSpecifier : : getAppFontSFFamilies ( ) ;
if ( rm . hasFontName ( ) ) setFontRoman ( rm . fontName ( ) , MTFEUnicode ) ;
if ( rm . hasMathFontName ( ) ) setFontMathRoman ( rm . mathFontName ( ) , MTFEUnicode ) ;
if ( rm . hasFallbackSymbolFontName ( ) ) setFallbackFontSymbols ( rm . fallbackSymbolsFontName ( ) , MTFEUnicode ) ;
if ( sf . hasFontName ( ) ) setFontSans ( sf . fontName ( ) , MTFEUnicode ) ;
if ( sf . hasMathFontName ( ) ) setFontMathSans ( sf . mathFontName ( ) , MTFEUnicode ) ;
return true ;
}
2022-06-08 21:38:26 +08:00
void JKQTMathText : : useAnyUnicode ( QString timesFont , const QString & sansFont , JKQTMathTextFontEncoding encodingTimes , JKQTMathTextFontEncoding encodingSans )
2022-07-05 03:02:43 +08:00
{
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 )
2019-06-30 23:34:41 +08:00
{
if ( ! timesFont . isEmpty ( ) ) { setFontRoman ( timesFont , encodingTimes ) ; }
if ( ! sansFont . isEmpty ( ) ) { setFontSans ( sansFont , encodingSans ) ; }
}
QString JKQTMathText : : toHtml ( bool * ok , double fontPointSize ) {
QString s ;
bool okk = false ;
2022-06-20 18:17:32 +08:00
if ( getNodeTree ( ) ! = nullptr ) {
2022-06-08 21:38:26 +08:00
JKQTMathTextEnvironment ev ;
2019-06-30 23:34:41 +08:00
ev . color = fontColor ;
ev . fontSize = fontPointSize ;
2022-07-05 03:02:43 +08:00
ev . fontSizeUnit = JKQTMathTextEnvironment : : POINTS ;
2019-06-30 23:34:41 +08:00
2022-06-08 21:38:26 +08:00
JKQTMathTextEnvironment defaultev ;
2019-06-30 23:34:41 +08:00
defaultev . fontSize = fontPointSize ;
2022-07-05 03:02:43 +08:00
defaultev . fontSizeUnit = JKQTMathTextEnvironment : : POINTS ;
2019-06-30 23:34:41 +08:00
2022-06-20 18:17:32 +08:00
okk = getNodeTree ( ) - > toHtml ( s , ev , defaultev ) ;
2019-06-30 23:34:41 +08:00
}
if ( ok ) * ok = okk ;
return s ;
}
void JKQTMathText : : setFontColor ( const QColor & __value )
{
this - > fontColor = __value ;
}
QColor JKQTMathText : : getFontColor ( ) const
{
return this - > fontColor ;
}
void JKQTMathText : : setFontSize ( double __value )
{
2022-07-05 03:02:43 +08:00
setFontPointSize ( __value ) ;
}
void JKQTMathText : : setFontPointSize ( double __value )
{
fontSize = __value ;
fontSizeUnits = JKQTMathTextEnvironment : : POINTS ;
}
void JKQTMathText : : setFontSizePixels ( double __value )
{
fontSize = __value ;
fontSizeUnits = JKQTMathTextEnvironment : : PIXELS ;
2019-06-30 23:34:41 +08:00
}
double JKQTMathText : : getFontSize ( ) const
{
2022-07-05 03:02:43 +08:00
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 ;
2019-06-30 23:34:41 +08:00
}
2022-06-08 21:38:26 +08:00
void JKQTMathText : : addReplacementFont ( const QString & nonUseFont , const QString & useFont , JKQTMathTextFontEncoding useFontEncoding ) {
2019-06-30 23:34:41 +08:00
fontReplacements . insert ( nonUseFont , useFont ) ;
fontEncodingReplacements . insert ( nonUseFont , useFontEncoding ) ;
}
void JKQTMathText : : addReplacementFont ( const QString & nonUseFont , const QString & useFont ) {
fontReplacements . insert ( nonUseFont , useFont ) ;
auto it = fontEncodingReplacements . find ( nonUseFont ) ;
if ( it ! = fontEncodingReplacements . end ( ) ) fontEncodingReplacements . erase ( it ) ;
}
2022-06-08 21:38:26 +08:00
QPair < QString , JKQTMathTextFontEncoding > JKQTMathText : : getReplacementFont ( const QString & nonUseFont , const QString & defaultFont , JKQTMathTextFontEncoding defaultFontEncoding ) const {
QPair < QString , JKQTMathTextFontEncoding > res ( defaultFont , defaultFontEncoding ) ;
2019-06-30 23:34:41 +08:00
for ( auto it = fontReplacements . begin ( ) ; it ! = fontReplacements . end ( ) ; + + it ) {
if ( it . key ( ) . toLower ( ) = = nonUseFont . toLower ( ) ) {
res . first = it . value ( ) ;
res . second = fontEncodingReplacements . value ( res . first , res . second ) ;
return res ;
}
}
return res ;
}
2022-07-04 02:30:12 +08:00
QPair < QString , JKQTMathTextFontEncoding > JKQTMathText : : getFontData ( JKQTMathTextEnvironmentFont font , bool in_math_environment ) const
2019-06-30 23:34:41 +08:00
{
2022-06-03 19:33:18 +08:00
if ( in_math_environment ) {
if ( font = = MTEroman ) font = MTEmathRoman ;
if ( font = = MTEsans ) font = MTEmathSans ;
}
2022-06-03 03:02:23 +08:00
const auto fd = fontDefinitions . value ( font ) ;
2022-06-08 21:38:26 +08:00
return QPair < QString , JKQTMathTextFontEncoding > ( fd . fontName , fd . fontEncoding ) ;
2019-06-30 23:34:41 +08:00
}
2022-06-08 21:38:26 +08:00
void JKQTMathText : : setFontRomanOrSpecial ( const QString & __value , JKQTMathTextFontEncoding encoding )
2019-06-30 23:34:41 +08:00
{
2022-06-03 03:02:23 +08:00
setFontRomanOrSpecial ( JKQTMathTextFontSpecifier : : fromFontSpec ( __value ) , encoding ) ;
}
2022-06-08 21:38:26 +08:00
void JKQTMathText : : setFontRomanOrSpecial ( const JKQTMathTextFontSpecifier & fontName , JKQTMathTextFontEncoding encoding )
2022-06-03 03:02:23 +08:00
{
if ( ! fontName . hasMathFontName ( ) ) {
2022-08-21 20:49:48 +08:00
setFontRoman ( fontName . fontName ( ) , encoding ) ;
setFontMathRoman ( fontName . fontName ( ) , encoding ) ;
2022-06-03 03:02:23 +08:00
} else {
setFontRoman ( fontName . fontName ( ) , encoding ) ;
2022-08-21 20:49:48 +08:00
setFontMathRoman ( fontName . mathFontName ( ) , encoding ) ;
2019-06-30 23:34:41 +08:00
}
2022-09-01 20:36:34 +08:00
if ( fontName . hasFallbackSymbolFontName ( ) ) setFallbackFontSymbols ( fontName . fallbackSymbolsFontName ( ) , encoding ) ;
}
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 ) ;
}
if ( beforePlus . toUpper ( ) = = " GUI " ) useGuiFonts ( ) ;
else {
const QStringList splitSlash = beforePlus . split ( ' / ' ) ;
if ( splitSlash . size ( ) = = 1 ) {
setFontRoman ( JKQTMathTextFontSpecifier : : transformFontNameAndDecodeSpecialFonts ( splitSlash [ 0 ] ) , MTFEUnicode ) ;
setFontMathRoman ( JKQTMathTextFontSpecifier : : transformFontNameAndDecodeSpecialFonts ( splitSlash [ 0 ] ) , MTFEUnicode ) ;
setFontSans ( init_sansFont , estimateJKQTMathTextFontEncoding ( init_sansFont ) ) ;
setFontMathSans ( init_sansFont , estimateJKQTMathTextFontEncoding ( init_sansFont ) ) ;
} else if ( splitSlash . size ( ) = = 2 ) {
setFontRoman ( JKQTMathTextFontSpecifier : : transformFontNameAndDecodeSpecialFonts ( splitSlash [ 0 ] ) , MTFEUnicode ) ;
setFontMathRoman ( JKQTMathTextFontSpecifier : : transformFontNameAndDecodeSpecialFonts ( splitSlash [ 0 ] ) , MTFEUnicode ) ;
setFontSans ( JKQTMathTextFontSpecifier : : transformFontNameAndDecodeSpecialFonts ( splitSlash [ 1 ] ) , MTFEUnicode ) ;
setFontMathSans ( JKQTMathTextFontSpecifier : : transformFontNameAndDecodeSpecialFonts ( splitSlash [ 1 ] ) , MTFEUnicode ) ;
} else if ( splitSlash . size ( ) = = 4 ) {
setFontRoman ( JKQTMathTextFontSpecifier : : transformFontNameAndDecodeSpecialFonts ( splitSlash [ 0 ] ) , MTFEUnicode ) ;
setFontMathRoman ( JKQTMathTextFontSpecifier : : transformFontNameAndDecodeSpecialFonts ( splitSlash [ 2 ] ) , MTFEUnicode ) ;
setFontSans ( JKQTMathTextFontSpecifier : : transformFontNameAndDecodeSpecialFonts ( splitSlash [ 1 ] ) , MTFEUnicode ) ;
setFontMathSans ( JKQTMathTextFontSpecifier : : transformFontNameAndDecodeSpecialFonts ( splitSlash [ 3 ] ) , MTFEUnicode ) ;
} else {
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 ( ) ;
2019-06-30 23:34:41 +08:00
}
2022-06-08 21:38:26 +08:00
void JKQTMathText : : setFontRoman ( const QString & __value , JKQTMathTextFontEncoding encoding )
2019-06-30 23:34:41 +08:00
{
auto f = getReplacementFont ( __value , __value , encoding ) ;
2019-11-16 22:02:48 +08:00
fontDefinitions [ MTEroman ] . fontName = f . first ;
fontDefinitions [ MTEroman ] . fontEncoding = f . second ;
2019-06-30 23:34:41 +08:00
}
2022-08-21 20:49:48 +08:00
void JKQTMathText : : setFontRomanAndMath ( const QString & fontName , JKQTMathTextFontEncoding encoding )
{
setFontRoman ( fontName , encoding ) ;
setFontMathRoman ( fontName , encoding ) ;
}
2019-06-30 23:34:41 +08:00
QString JKQTMathText : : getFontRoman ( ) const
{
return fontDefinitions [ MTEroman ] . fontName ;
}
2022-06-08 21:38:26 +08:00
JKQTMathTextFontEncoding JKQTMathText : : getFontEncodingRoman ( ) const
2019-06-30 23:34:41 +08:00
{
return fontDefinitions [ MTEroman ] . fontEncoding ;
}
2022-06-08 21:38:26 +08:00
void JKQTMathText : : setFontSans ( const QString & __value , JKQTMathTextFontEncoding encoding )
2019-06-30 23:34:41 +08:00
{
auto f = getReplacementFont ( __value , __value , encoding ) ;
2019-11-16 22:02:48 +08:00
fontDefinitions [ MTEsans ] . fontName = f . first ;
fontDefinitions [ MTEsans ] . fontEncoding = f . second ;
2019-06-30 23:34:41 +08:00
}
QString JKQTMathText : : getFontSans ( ) const
{
return fontDefinitions [ MTEsans ] . fontName ;
}
2022-06-08 21:38:26 +08:00
JKQTMathTextFontEncoding JKQTMathText : : getFontEncodingSans ( ) const
2019-06-30 23:34:41 +08:00
{
return fontDefinitions [ MTEsans ] . fontEncoding ;
}
2022-06-08 21:38:26 +08:00
void JKQTMathText : : setFontTypewriter ( const QString & __value , JKQTMathTextFontEncoding encoding )
2019-06-30 23:34:41 +08:00
{
auto f = getReplacementFont ( __value , __value , encoding ) ;
2019-11-16 22:02:48 +08:00
fontDefinitions [ MTEtypewriter ] . fontName = f . first ;
fontDefinitions [ MTEtypewriter ] . fontEncoding = f . second ;
2019-06-30 23:34:41 +08:00
}
QString JKQTMathText : : getFontTypewriter ( ) const
{
return fontDefinitions [ MTEtypewriter ] . fontName ;
}
2022-06-08 21:38:26 +08:00
JKQTMathTextFontEncoding JKQTMathText : : getFontEncodingTypewriter ( ) const
2019-06-30 23:34:41 +08:00
{
return fontDefinitions [ MTEtypewriter ] . fontEncoding ;
}
2022-06-08 21:38:26 +08:00
void JKQTMathText : : setFontScript ( const QString & __value , JKQTMathTextFontEncoding encoding )
2019-06-30 23:34:41 +08:00
{
auto f = getReplacementFont ( __value , __value , encoding ) ;
2019-11-16 22:02:48 +08:00
fontDefinitions [ MTEscript ] . fontName = f . first ;
fontDefinitions [ MTEscript ] . fontEncoding = f . second ;
2019-06-30 23:34:41 +08:00
}
QString JKQTMathText : : getFontScript ( ) const
{
return fontDefinitions [ MTEscript ] . fontName ;
}
2022-06-08 21:38:26 +08:00
JKQTMathTextFontEncoding JKQTMathText : : getFontEncodingScript ( ) const
2019-06-30 23:34:41 +08:00
{
return fontDefinitions [ MTEscript ] . fontEncoding ;
}
2022-06-08 21:38:26 +08:00
void JKQTMathText : : setFontFraktur ( const QString & __value , JKQTMathTextFontEncoding encoding )
2019-06-30 23:34:41 +08:00
{
auto f = getReplacementFont ( __value , __value , encoding ) ;
2019-11-16 22:02:48 +08:00
fontDefinitions [ MTEfraktur ] . fontName = f . first ;
fontDefinitions [ MTEfraktur ] . fontEncoding = f . second ;
2019-06-30 23:34:41 +08:00
}
QString JKQTMathText : : getFontFraktur ( ) const
{
return fontDefinitions [ MTEfraktur ] . fontName ;
}
2022-06-08 21:38:26 +08:00
JKQTMathTextFontEncoding JKQTMathText : : getFontEncodingFraktur ( ) const
2019-06-30 23:34:41 +08:00
{
return fontDefinitions [ MTEfraktur ] . fontEncoding ;
}
2022-07-04 02:30:12 +08:00
void JKQTMathText : : setFallbackFontSymbols ( const QString & fontName , JKQTMathTextFontEncoding encoding )
2019-06-30 23:34:41 +08:00
{
2022-07-04 02:30:12 +08:00
auto f = getReplacementFont ( fontName , fontName , encoding ) ;
fontDefinitions [ MTEFallbackSymbols ] . fontName = f . first ;
fontDefinitions [ MTEFallbackSymbols ] . fontEncoding = f . second ;
2019-06-30 23:34:41 +08:00
}
2022-07-04 02:30:12 +08:00
QString JKQTMathText : : getFallbackFontSymbols ( ) const
2019-06-30 23:34:41 +08:00
{
2022-07-04 02:30:12 +08:00
return fontDefinitions [ MTEFallbackSymbols ] . fontName ;
2019-06-30 23:34:41 +08:00
}
2022-07-04 02:30:12 +08:00
JKQTMathTextFontEncoding JKQTMathText : : getFontEncodingFallbackFontSymbols ( ) const
2019-06-30 23:34:41 +08:00
{
2022-07-04 02:30:12 +08:00
return fontDefinitions [ MTEFallbackSymbols ] . fontEncoding ;
2019-06-30 23:34:41 +08:00
}
2022-06-08 21:38:26 +08:00
void JKQTMathText : : setFontCaligraphic ( const QString & __value , JKQTMathTextFontEncoding encoding )
2019-06-30 23:34:41 +08:00
{
auto f = getReplacementFont ( __value , __value , encoding ) ;
2019-11-16 22:02:48 +08:00
fontDefinitions [ MTEcaligraphic ] . fontName = f . first ;
fontDefinitions [ MTEcaligraphic ] . fontEncoding = f . second ;
2019-06-30 23:34:41 +08:00
}
QString JKQTMathText : : getFontCaligraphic ( ) const
{
return fontDefinitions [ MTEcaligraphic ] . fontName ;
}
2022-06-08 21:38:26 +08:00
JKQTMathTextFontEncoding JKQTMathText : : getFontEncodingCaligraphic ( ) const
2019-06-30 23:34:41 +08:00
{
return fontDefinitions [ MTEcaligraphic ] . fontEncoding ;
}
2022-06-08 21:38:26 +08:00
void JKQTMathText : : setFontMathRoman ( const QString & fontName , JKQTMathTextFontEncoding encoding )
2019-06-30 23:34:41 +08:00
{
auto f = getReplacementFont ( fontName , fontName , encoding ) ;
fontDefinitions [ MTEmathRoman ] . fontName = f . first ;
fontDefinitions [ MTEmathRoman ] . fontEncoding = f . second ;
}
QString JKQTMathText : : getFontMathRoman ( ) const
{
return fontDefinitions [ MTEmathRoman ] . fontName ;
}
2022-06-08 21:38:26 +08:00
void JKQTMathText : : setFontMathSans ( const QString & fontName , JKQTMathTextFontEncoding encoding )
2019-06-30 23:34:41 +08:00
{
auto f = getReplacementFont ( fontName , fontName , encoding ) ;
fontDefinitions [ MTEmathSans ] . fontName = f . first ;
fontDefinitions [ MTEmathSans ] . fontEncoding = f . second ;
}
QString JKQTMathText : : getFontMathSans ( ) const
{
return fontDefinitions [ MTEmathSans ] . fontName ;
}
2022-06-08 21:38:26 +08:00
JKQTMathTextFontEncoding JKQTMathText : : getFontEncodingMathSans ( ) const
2019-06-30 23:34:41 +08:00
{
return fontDefinitions [ MTEmathSans ] . fontEncoding ;
}
2019-01-26 19:28:44 +08:00
2022-06-08 21:38:26 +08:00
JKQTMathTextFontEncoding JKQTMathText : : getFontEncodingMathRoman ( ) const
2019-06-30 23:34:41 +08:00
{
return fontDefinitions [ MTEmathRoman ] . fontEncoding ;
}
2019-01-26 19:28:44 +08:00
2022-06-08 21:38:26 +08:00
void JKQTMathText : : setFontBlackboard ( const QString & __value , JKQTMathTextFontEncoding encoding )
2019-06-30 23:34:41 +08:00
{
auto f = getReplacementFont ( __value , __value , encoding ) ;
2019-11-16 22:02:48 +08:00
fontDefinitions [ MTEblackboard ] . fontName = f . first ;
fontDefinitions [ MTEblackboard ] . fontEncoding = f . second ;
2019-06-30 23:34:41 +08:00
}
2019-01-26 19:28:44 +08:00
2022-08-10 18:12:30 +08:00
JKQTMathTextBlackboradDrawingMode JKQTMathText : : getFontBlackboradMode ( ) const
2019-06-30 23:34:41 +08:00
{
2022-08-10 18:12:30 +08:00
return blackboradFontMode ;
2019-06-30 23:34:41 +08:00
}
2019-01-26 19:28:44 +08:00
2022-08-10 18:12:30 +08:00
void JKQTMathText : : setFontBlackboradMode ( JKQTMathTextBlackboradDrawingMode mode )
2019-06-30 23:34:41 +08:00
{
2022-08-10 18:12:30 +08:00
blackboradFontMode = mode ;
2019-06-30 23:34:41 +08:00
}
2019-01-26 19:28:44 +08:00
2019-06-30 23:34:41 +08:00
QString JKQTMathText : : getFontBlackboard ( ) const
{
return fontDefinitions [ MTEblackboard ] . fontName ;
2019-01-26 19:28:44 +08:00
}
2022-06-08 21:38:26 +08:00
JKQTMathTextFontEncoding JKQTMathText : : getFontEncodingBlackboard ( ) const
2019-06-30 23:34:41 +08:00
{
return fontDefinitions [ MTEblackboard ] . fontEncoding ;
2019-06-21 04:24:47 +08:00
}
2019-06-30 23:34:41 +08:00
void JKQTMathText : : setBraceFactor ( double __value )
{
this - > brace_factor = __value ;
2019-03-07 06:18:29 +08:00
}
2019-06-30 23:34:41 +08:00
double JKQTMathText : : getBraceFactor ( ) const
{
return this - > brace_factor ;
}
2019-01-26 19:28:44 +08:00
2019-06-30 23:34:41 +08:00
void JKQTMathText : : setSubsuperSizeFactor ( double __value )
2019-01-26 19:28:44 +08:00
{
2019-06-30 23:34:41 +08:00
this - > subsuper_size_factor = __value ;
}
2019-01-26 19:28:44 +08:00
2019-06-30 23:34:41 +08:00
double JKQTMathText : : getSubsuperSizeFactor ( ) const
{
return this - > subsuper_size_factor ;
}
2019-01-26 19:28:44 +08:00
2022-06-26 06:28:49 +08:00
void JKQTMathText : : setSubsuperModeSelectionBySizeFactor ( double __value )
{
subsuper_mode_selection_by_size_factor = __value ;
}
double JKQTMathText : : getSubsuperModeSelectionBySizeFactor ( ) const
{
return subsuper_mode_selection_by_size_factor ;
}
2019-06-30 23:34:41 +08:00
void JKQTMathText : : setOperatorsubsuperSizeFactor ( double __value )
{
this - > operatorsubsuper_size_factor = __value ;
}
2019-01-26 19:28:44 +08:00
2019-06-30 23:34:41 +08:00
double JKQTMathText : : getOperatorsubsuperSizeFactor ( ) const
{
return this - > operatorsubsuper_size_factor ;
}
2019-01-26 19:28:44 +08:00
2022-06-26 06:28:49 +08:00
void JKQTMathText : : setOperatorsubsuperDistanceFactor ( double __value )
{
this - > operatorsubsuper_distance_factor = __value ;
}
double JKQTMathText : : getOperatorsubsuperDistanceFactor ( ) const
{
return this - > operatorsubsuper_distance_factor ;
}
void JKQTMathText : : setOperatorsubsuperExtraSpaceFactor ( double __value )
{
operatorsubsuper_extraspace_factor = __value ;
}
double JKQTMathText : : getOperatorsubsuperExtraSpaceFactor ( ) const
{
return operatorsubsuper_extraspace_factor ;
}
2019-06-30 23:34:41 +08:00
void JKQTMathText : : setMathoperatorWidthFactor ( double __value )
{
this - > mathoperator_width_factor = __value ;
}
2019-01-26 19:28:44 +08:00
2019-06-30 23:34:41 +08:00
double JKQTMathText : : getMathoperatorWidthFactor ( ) const
{
return this - > mathoperator_width_factor ;
}
2019-01-26 19:28:44 +08:00
2022-06-28 04:57:49 +08:00
void JKQTMathText : : setIntSubSuperXCorrectionFactor ( double __value )
{
intsubsuper_xcorrection_factor = __value ;
}
double JKQTMathText : : getIntSubSuperXCorrectionFactor ( ) const
{
return intsubsuper_xcorrection_factor ;
}
void JKQTMathText : : setIntSubBesidesXCorrectionXFactor ( double __value )
{
intsubbesides_xcorrection_xfactor = __value ;
}
double JKQTMathText : : getIntSubBesidesXCorrectionXFactor ( ) const
{
return intsubbesides_xcorrection_xfactor ;
}
2022-06-26 06:28:49 +08:00
void JKQTMathText : : setBigMathoperatorFontFactor ( double __value )
{
bigmathoperator_font_factor = __value ;
}
double JKQTMathText : : getBigMathoperatorFontFactor ( ) const
{
return bigmathoperator_font_factor ;
}
2019-06-30 23:34:41 +08:00
void JKQTMathText : : setSuperShiftFactor ( double __value )
{
this - > super_shift_factor = __value ;
2019-01-26 19:28:44 +08:00
}
2019-06-30 23:34:41 +08:00
double JKQTMathText : : getSuperShiftFactor ( ) const
{
return this - > super_shift_factor ;
2019-01-26 19:28:44 +08:00
}
2019-06-30 23:34:41 +08:00
void JKQTMathText : : setSubShiftFactor ( double __value )
{
this - > sub_shift_factor = __value ;
}
2019-01-26 19:28:44 +08:00
2019-06-30 23:34:41 +08:00
double JKQTMathText : : getSubShiftFactor ( ) const
{
return this - > sub_shift_factor ;
}
2019-01-26 19:28:44 +08:00
2022-06-26 06:28:49 +08:00
double JKQTMathText : : getSpecialSuperShiftFactor ( ) const
{
return special_super_shift_factor ;
}
void JKQTMathText : : setSpecialSuperShiftFactor ( double __value )
{
special_super_shift_factor = __value ;
}
void JKQTMathText : : setSpecialSubShiftFactor ( double __value )
{
special_sub_shift_factor = __value ;
}
double JKQTMathText : : getSpecialSubShiftFactor ( ) const
{
return special_sub_shift_factor ;
}
2019-06-30 23:34:41 +08:00
void JKQTMathText : : setUnderbraceFactor ( double __value )
{
this - > underbrace_factor = __value ;
2019-01-26 19:28:44 +08:00
}
2019-06-30 23:34:41 +08:00
double JKQTMathText : : getUnderbraceFactor ( ) const
{
return this - > underbrace_factor ;
}
2019-01-26 19:28:44 +08:00
2022-06-28 03:09:22 +08:00
void JKQTMathText : : setUnderbraceSeparationXFactor ( double __value )
{
underbrace_separation_xfactor = __value ;
}
double JKQTMathText : : getUnderbraceSeparationXFactor ( ) const
{
return underbrace_separation_xfactor ;
}
void JKQTMathText : : setUnderbraceBraceSizeXFactor ( double __value )
{
underbrace_bracesize_xfactor = __value ;
}
double JKQTMathText : : getUnderbraceBraceSizeXFactor ( ) const
{
return underbrace_bracesize_xfactor ;
}
2019-06-30 23:34:41 +08:00
void JKQTMathText : : setUndersetFactor ( double __value )
{
2022-06-20 18:17:32 +08:00
this - > underset_factor = __value ;
2019-06-30 23:34:41 +08:00
}
2019-01-26 19:28:44 +08:00
2019-06-30 23:34:41 +08:00
double JKQTMathText : : getUndersetFactor ( ) const
{
2022-06-20 18:17:32 +08:00
return this - > underset_factor ;
2019-01-26 19:28:44 +08:00
}
2019-06-30 23:34:41 +08:00
void JKQTMathText : : setFracFactor ( double __value )
2019-01-26 19:28:44 +08:00
{
2019-06-30 23:34:41 +08:00
this - > frac_factor = __value ;
2019-01-26 19:28:44 +08:00
}
2019-06-30 23:34:41 +08:00
double JKQTMathText : : getFracFactor ( ) const
2019-01-26 19:28:44 +08:00
{
2019-06-30 23:34:41 +08:00
return this - > frac_factor ;
2019-01-26 19:28:44 +08:00
}
2022-06-09 05:52:22 +08:00
void JKQTMathText : : setFracNestedFactor ( double __value )
{
frac_nested_factor = __value ;
}
double JKQTMathText : : getFracNestedFactor ( ) const
{
return frac_nested_factor ;
}
2019-06-30 23:34:41 +08:00
void JKQTMathText : : setFracShiftFactor ( double __value )
{
this - > frac_shift_factor = __value ;
2019-01-26 19:28:44 +08:00
}
2019-06-30 23:34:41 +08:00
double JKQTMathText : : getFracShiftFactor ( ) const
{
return this - > frac_shift_factor ;
}
2019-01-26 19:28:44 +08:00
2019-06-30 23:34:41 +08:00
void JKQTMathText : : setBraceYShiftFactor ( double __value )
{
this - > brace_y_shift_factor = __value ;
}
2019-01-26 19:28:44 +08:00
2019-06-30 23:34:41 +08:00
double JKQTMathText : : getBraceYShiftFactor ( ) const
{
return this - > brace_y_shift_factor ;
2019-01-26 19:28:44 +08:00
}
2019-06-30 23:34:41 +08:00
void JKQTMathText : : setDecorationHeightFactor ( double __value )
{
this - > decoration_height_factor = __value ;
2019-05-06 01:31:20 +08:00
}
2019-06-30 23:34:41 +08:00
double JKQTMathText : : getDecorationHeightFactor ( ) const
2019-02-08 00:24:46 +08:00
{
2019-06-30 23:34:41 +08:00
return this - > decoration_height_factor ;
2019-02-08 00:24:46 +08:00
}
2022-06-29 05:14:31 +08:00
void JKQTMathText : : setDecorationSeparationXFactor ( double __value )
{
decoration_separation_factor = __value ;
}
double JKQTMathText : : getDecorationSeparationFactor ( ) const
{
return decoration_separation_factor ;
}
void JKQTMathText : : setDecorationWidthReductionFactor ( double __value )
2022-06-07 05:24:05 +08:00
{
decoration_width_reduction_Xfactor = __value ;
}
double JKQTMathText : : getDecorationWidthReductionXFactor ( ) const
{
return decoration_width_reduction_Xfactor ;
}
2022-06-28 18:00:20 +08:00
void JKQTMathText : : setSqrtWidthXFactor ( double __value )
{
sqrt_width_Xfactor = __value ;
}
double JKQTMathText : : getSqrtWidthXFactor ( ) const
{
return sqrt_width_Xfactor ;
}
void JKQTMathText : : setSqrtHeightFactor ( double __value )
{
sqrt_height_factor = __value ;
}
double JKQTMathText : : getSqrtHeightFactor ( ) const
{
return sqrt_height_factor ;
}
void JKQTMathText : : setSqrtSmallFontFactor ( double __value )
{
sqrt_smallfont_factor = __value ;
}
double JKQTMathText : : getSqrtSmallFontFactor ( ) const
{
return sqrt_smallfont_factor ;
}
2022-08-12 18:54:10 +08:00
double JKQTMathText : : getMatrixLinewidthThinFactor ( )
{
return matrix_linewidth_thin_factor ;
}
void JKQTMathText : : setMatrixLinewidthThinFactor ( double factor )
{
matrix_linewidth_thin_factor = factor ;
}
double JKQTMathText : : getMatrixLinewidthHeavyFactor ( )
{
return matrix_linewidth_heavy_factor ;
}
void JKQTMathText : : setMatrixLinewidthHeavyFactor ( double factor )
{
matrix_linewidth_heavy_factor = factor ;
}
double JKQTMathText : : getMatrixLineSeparationFactor ( )
{
return matrix_line_separation_factor ;
}
void JKQTMathText : : setMatrixLineSeparationFactor ( double factor )
{
matrix_line_separation_factor = factor ;
}
double JKQTMathText : : getMatrixXSeparationFactor ( )
{
return matrix_xSeparation_factor ;
}
void JKQTMathText : : setMatrixXSeparationFactor ( double factor )
{
matrix_xSeparation_factor = factor ;
}
double JKQTMathText : : getMatrixYSeparationFactor ( )
{
return matrix_ySeparation_factor ;
}
void JKQTMathText : : setMatrixYSeparationFactor ( double factor )
{
matrix_ySeparation_factor = factor ;
}
double JKQTMathText : : getMatrixXPaddingFactor ( )
{
return matrix_xPadding_factor ;
}
void JKQTMathText : : setMatrixXPaddingFactor ( double factor )
{
matrix_xPadding_factor = factor ;
}
double JKQTMathText : : getMatrixYPaddingFactor ( )
{
return matrix_yPadding_factor ;
}
void JKQTMathText : : setMatrixYPaddingFactor ( double factor )
{
matrix_yPadding_factor = factor ;
}
2019-06-30 23:34:41 +08:00
QStringList JKQTMathText : : getErrorList ( ) const {
return this - > error_list ;
2019-01-26 19:28:44 +08:00
}
2022-08-07 23:57:52 +08:00
bool JKQTMathText : : hadErrors ( ) const
{
return error_list . size ( ) > 0 ;
}
2022-06-08 21:38:26 +08:00
void JKQTMathText : : addToErrorList ( const QString & error )
{
error_list . append ( error ) ;
}
2019-01-26 19:28:44 +08:00
2022-08-20 22:19:40 +08:00
void JKQTMathText : : clearErrorList ( )
2022-08-03 15:55:45 +08:00
{
2022-08-20 22:19:40 +08:00
error_list . clear ( ) ;
2022-08-03 21:23:14 +08:00
}
2022-08-20 22:19:40 +08:00
const JKQTMathTextNode * JKQTMathText : : getNodeTree ( ) const {
2019-06-30 23:34:41 +08:00
return this - > parsedNode ;
}
2019-01-26 19:28:44 +08:00
QSizeF JKQTMathText : : getSize ( QPainter & painter ) {
2022-06-20 18:17:32 +08:00
if ( getNodeTree ( ) ! = nullptr ) {
2022-08-13 21:32:31 +08:00
const JKQTMathTextNodeSize s = getSizeDetail ( painter ) ;
return s . getSize ( ) ;
2019-01-26 19:28:44 +08:00
}
return QSizeF ( 0 , 0 ) ;
}
2022-08-13 21:32:31 +08:00
QSize JKQTMathText : : getIntSize ( QPainter & painter )
{
if ( getNodeTree ( ) ! = nullptr ) {
const JKQTMathTextNodeSize s = getSizeDetail ( painter ) ;
return s . getIntSize ( ) ;
}
return QSize ( 0 , 0 ) ;
}
2019-01-26 19:28:44 +08:00
double JKQTMathText : : getDescent ( QPainter & painter ) {
2022-08-13 21:32:31 +08:00
const JKQTMathTextNodeSize s = getSizeDetail ( painter ) ;
return s . getDescent ( ) ;
2019-01-26 19:28:44 +08:00
}
double JKQTMathText : : getAscent ( QPainter & painter ) {
2022-08-13 21:32:31 +08:00
const JKQTMathTextNodeSize s = getSizeDetail ( painter ) ;
return s . baselineHeight ;
2019-01-26 19:28:44 +08:00
}
void JKQTMathText : : getSizeDetail ( QPainter & painter , double & width , double & ascent , double & descent , double & strikeoutPos ) {
2022-08-07 23:57:52 +08:00
JKQTMathTextNodeSize s = getSizeDetail ( painter ) ;
width = s . width ;
ascent = s . baselineHeight ;
descent = s . getDescent ( ) ;
strikeoutPos = s . strikeoutPos ;
}
JKQTMathTextNodeSize JKQTMathText : : getSizeDetail ( QPainter & painter )
{
JKQTMathTextNodeSize s ;
2022-06-20 18:17:32 +08:00
if ( getNodeTree ( ) ! = nullptr ) {
2022-06-08 21:38:26 +08:00
JKQTMathTextEnvironment ev ;
2019-01-26 19:28:44 +08:00
ev . color = fontColor ;
ev . fontSize = fontSize ;
2022-07-05 03:02:43 +08:00
ev . fontSizeUnit = fontSizeUnits ;
2019-01-26 19:28:44 +08:00
2022-08-07 23:57:52 +08:00
s = getNodeTree ( ) - > getSize ( painter , ev ) ;
2019-01-26 19:28:44 +08:00
}
2022-08-07 23:57:52 +08:00
return s ;
2019-01-26 19:28:44 +08:00
}
2022-07-04 03:30:12 +08:00
void JKQTMathText : : draw ( QPainter & painter , QPointF x , bool drawBoxes )
{
draw ( painter , x . x ( ) , x . y ( ) , drawBoxes ) ;
}
2022-08-08 16:12:59 +08:00
double JKQTMathText : : draw ( QPainter & painter , double x , double y , bool drawBoxes ) {
2022-06-20 18:17:32 +08:00
if ( getNodeTree ( ) ! = nullptr ) {
2022-08-08 16:12:59 +08:00
painter . save ( ) ; auto __finalpaint = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
2022-09-02 04:22:17 +08:00
painter . setPen ( fontColor ) ;
painter . setBrush ( Qt : : NoBrush ) ;
2022-06-08 21:38:26 +08:00
JKQTMathTextEnvironment ev ;
2019-01-26 19:28:44 +08:00
ev . color = fontColor ;
ev . fontSize = fontSize ;
2022-07-05 03:02:43 +08:00
ev . fontSizeUnit = fontSizeUnits ;
2022-06-20 18:17:32 +08:00
getNodeTree ( ) - > setDrawBoxes ( drawBoxes ) ;
2022-08-08 16:12:59 +08:00
const double xend = getNodeTree ( ) - > draw ( painter , x , y , ev ) ;
return xend ;
2019-01-26 19:28:44 +08:00
}
2022-08-08 16:12:59 +08:00
return x ;
2019-01-26 19:28:44 +08:00
}
2019-05-01 20:58:19 +08:00
void JKQTMathText : : draw ( QPainter & painter , unsigned int flags , QRectF rect , bool drawBoxes ) {
2022-06-20 18:17:32 +08:00
if ( getNodeTree ( ) ! = nullptr ) {
2022-08-08 16:12:59 +08:00
painter . save ( ) ; auto __finalpaint = JKQTPFinally ( [ & painter ] ( ) { painter . restore ( ) ; } ) ;
2022-09-02 04:22:17 +08:00
painter . setPen ( fontColor ) ;
painter . setBrush ( Qt : : NoBrush ) ;
2022-08-08 16:12:59 +08:00
2022-06-08 21:38:26 +08:00
JKQTMathTextEnvironment ev ;
2019-01-26 19:28:44 +08:00
ev . color = fontColor ;
ev . fontSize = fontSize ;
2022-07-05 03:02:43 +08:00
ev . fontSizeUnit = fontSizeUnits ;
2022-06-20 18:17:32 +08:00
getNodeTree ( ) - > setDrawBoxes ( drawBoxes ) ;
2019-01-26 19:28:44 +08:00
2022-08-08 16:12:59 +08:00
const JKQTMathTextNodeSize size = getSizeDetail ( painter ) ;
2019-01-26 19:28:44 +08:00
// align left top
double x = rect . left ( ) ;
2022-08-08 16:12:59 +08:00
double y = rect . top ( ) + size . baselineHeight ;
2019-01-26 19:28:44 +08:00
// care for horizontal align
2022-08-08 16:12:59 +08:00
if ( ( flags & Qt : : AlignRight ) ! = 0 ) x = x + rect . width ( ) - size . width ;
else if ( ( flags & Qt : : AlignHCenter ) ! = 0 ) x = x + ( rect . width ( ) - size . width ) / 2.0 ;
2019-01-26 19:28:44 +08:00
// care for vertical align
2022-08-08 16:12:59 +08:00
if ( ( flags & Qt : : AlignBottom ) ! = 0 ) y = y + rect . height ( ) - size . overallHeight ;
else if ( ( flags & Qt : : AlignVCenter ) ! = 0 ) y = y + ( rect . height ( ) - size . overallHeight ) / 2.0 ;
2019-01-26 19:28:44 +08:00
// finally draw
2022-08-08 16:12:59 +08:00
const double xend = getNodeTree ( ) - > draw ( painter , x , y , ev ) ;
2019-01-26 19:28:44 +08:00
}
}
2022-08-07 23:57:52 +08:00
QPixmap JKQTMathText : : drawIntoPixmap ( bool drawBoxes , QColor backgroundColor , int sizeincrease , qreal devicePixelRatio )
{
// 1. generate dummy QPixmap that is needed to use a QPainter
// we need the dummy, because we first need to determine the size of the render output
// for which we need a QPainter.
QPixmap pix ( 1 , 1 ) ;
pix . setDevicePixelRatio ( devicePixelRatio ) ;
{
QPainter painter ;
// 2. now we determine the size and additional parameters,
// such as the ascent(or "baseline height")
painter . begin ( & pix ) ;
painter . setRenderHint ( QPainter : : Antialiasing ) ;
painter . setRenderHint ( QPainter : : TextAntialiasing ) ;
painter . setRenderHint ( QPainter : : SmoothPixmapTransform ) ;
const JKQTMathTextNodeSize size = getSizeDetail ( painter ) ;
const QSize pixsize = size . getIntSize ( ) + QSize ( 2 * sizeincrease , 2 * sizeincrease ) ;
painter . end ( ) ;
// 3. finally we can generate a QPixmap with the appropriate
// size to contain the full rendering. We fill it with the
// color white and finally paint the math markup/LaTeX string
pix = QPixmap ( pixsize ) ;
pix . setDevicePixelRatio ( devicePixelRatio ) ;
pix . fill ( backgroundColor ) ;
painter . begin ( & pix ) ;
painter . setRenderHint ( QPainter : : Antialiasing ) ;
painter . setRenderHint ( QPainter : : TextAntialiasing ) ;
painter . setRenderHint ( QPainter : : SmoothPixmapTransform ) ;
draw ( painter , Qt : : AlignVCenter | Qt : : AlignHCenter , QRect ( QPoint ( 0 , 0 ) , pixsize ) , drawBoxes ) ;
painter . end ( ) ;
}
return pix ;
}
QImage JKQTMathText : : drawIntoImage ( bool drawBoxes , QColor backgroundColor , int sizeincrease , qreal devicePixelRatio , unsigned int resolution_dpi )
{
// 1. generate dummy QPixmap that is needed to use a QPainter
// we need the dummy, because we first need to determine the size of the render output
// for which we need a QPainter.
QImage img ( 1 , 1 , QImage : : Format_ARGB32 ) ;
img . setDevicePixelRatio ( devicePixelRatio ) ;
img . setDotsPerMeterX ( resolution_dpi * ( 10000 / 254 ) ) ;
img . setDotsPerMeterY ( resolution_dpi * ( 10000 / 254 ) ) ;
{
QPainter painter ;
// 2. now we determine the size and additional parameters,
// such as the ascent(or "baseline height")
painter . begin ( & img ) ;
painter . setRenderHint ( QPainter : : Antialiasing ) ;
painter . setRenderHint ( QPainter : : TextAntialiasing ) ;
painter . setRenderHint ( QPainter : : SmoothPixmapTransform ) ;
const JKQTMathTextNodeSize size = getSizeDetail ( painter ) ;
const QSize pixsize = size . getIntSize ( ) + QSize ( 2 * sizeincrease , 2 * sizeincrease ) ;
painter . end ( ) ;
// 3. finally we can generate a QPixmap with the appropriate
// size to contain the full rendering. We fill it with the
// color white and finally paint the math markup/LaTeX string
2022-08-08 16:12:59 +08:00
img = QImage ( pixsize * devicePixelRatio , QImage : : Format_ARGB32 ) ;
2022-08-07 23:57:52 +08:00
img . setDevicePixelRatio ( devicePixelRatio ) ;
2022-08-08 16:12:59 +08:00
img . setDotsPerMeterX ( resolution_dpi * ( 10000 / 254 ) ) ;
img . setDotsPerMeterY ( resolution_dpi * ( 10000 / 254 ) ) ;
2022-08-07 23:57:52 +08:00
img . fill ( backgroundColor ) ;
painter . begin ( & img ) ;
painter . setRenderHint ( QPainter : : Antialiasing ) ;
painter . setRenderHint ( QPainter : : TextAntialiasing ) ;
painter . setRenderHint ( QPainter : : SmoothPixmapTransform ) ;
draw ( painter , Qt : : AlignVCenter | Qt : : AlignHCenter , QRect ( QPoint ( 0 , 0 ) , pixsize ) , drawBoxes ) ;
painter . end ( ) ;
}
return img ;
}
2022-08-08 16:12:59 +08:00
2022-08-07 23:57:52 +08:00
QPicture JKQTMathText : : drawIntoPicture ( bool drawBoxes )
{
// 1. generate dummy QPixmap that is needed to use a QPainter
// we need the dummy, because we first need to determine the size of the render output
// for which we need a QPainter.
QPicture pic ;
{
QPainter painter ;
// 2. now we determine the size and additional parameters,
// such as the ascent(or "baseline height")
painter . begin ( & pic ) ;
painter . setRenderHint ( QPainter : : Antialiasing ) ;
painter . setRenderHint ( QPainter : : TextAntialiasing ) ;
painter . setRenderHint ( QPainter : : SmoothPixmapTransform ) ;
const JKQTMathTextNodeSize size = getSizeDetail ( painter ) ;
painter . end ( ) ;
// 3. finally we can generate a QPixmap with the appropriate
// size to contain the full rendering. We fill it with the
// color white and finally paint the math markup/LaTeX string
painter . begin ( & pic ) ;
painter . setRenderHint ( QPainter : : Antialiasing ) ;
painter . setRenderHint ( QPainter : : TextAntialiasing ) ;
painter . setRenderHint ( QPainter : : SmoothPixmapTransform ) ;
draw ( painter , 0 , size . baselineHeight , drawBoxes ) ;
painter . end ( ) ;
}
return pic ;
}
2019-01-26 19:28:44 +08:00
2022-08-20 22:19:40 +08:00
JKQTMathTextNode * JKQTMathText : : getNodeTree ( ) {
2019-06-30 23:34:41 +08:00
return parsedNode ;
}