add more fall back fonts

This commit is contained in:
Roy Qu 2024-02-26 18:22:02 +08:00
parent 174808d416
commit dfd7075dfb
9 changed files with 349 additions and 184 deletions

View File

@ -677,6 +677,28 @@ void Settings::Editor::setFallbackFontName(const QString &newFontName)
mFallbackFontName = newFontName;
}
const QString &Settings::Editor::fallbackFontName2() const
{
return mFallbackFontName2;
}
void Settings::Editor::setFallbackFontName2(const QString &newFontName)
{
mFallbackFontName2 = newFontName;
}
const QString &Settings::Editor::fallbackFontName3() const
{
return mFallbackFontName3;
}
void Settings::Editor::setFallbackFontName3(const QString &newFontName)
{
mFallbackFontName3 = newFontName;
}
int Settings::Editor::mouseSelectionScrollSpeed() const
{
return mMouseSelectionScrollSpeed;
@ -1349,6 +1371,8 @@ void Settings::Editor::doSave()
//font
saveValue("font_name", mFontName);
saveValue("fallback_font_name", mFallbackFontName);
saveValue("fallback_font_name2", mFallbackFontName2);
saveValue("fallback_font_name3", mFallbackFontName3);
saveValue("font_size", mFontSize);
saveValue("font_only_monospaced", mFontOnlyMonospaced);
saveValue("line_spacing",mLineSpacing);
@ -1492,6 +1516,8 @@ void Settings::Editor::doLoad()
else if (defaultLocaleName == "zh_CN")
defaultCjkFontName = CJK_MONO_FONT_SC;
mFallbackFontName = stringValue("fallback_font_name",defaultCjkFontName);
mFallbackFontName2 = stringValue("fallback_font_name2",DEFAULT_MONO_FONT);
mFallbackFontName3 = stringValue("fallback_font_name3",DEFAULT_MONO_FONT);
mFontSize = intValue("font_size",12);
mFontOnlyMonospaced = boolValue("font_only_monospaced",true);
mLineSpacing = doubleValue("line_spacing",1.1);

View File

@ -356,7 +356,13 @@ public:
void setEnableLigaturesSupport(bool newEnableLigaturesSupport);
const QString &fallbackFontName() const;
void setFallbackFontName(const QString &newNonAsciiFontName);
void setFallbackFontName(const QString &newFontName);
const QString &fallbackFontName2() const;
void setFallbackFontName2(const QString &newFontName);
const QString &fallbackFontName3() const;
void setFallbackFontName3(const QString &newFontName);
int mouseSelectionScrollSpeed() const;
void setMouseSelectionScrollSpeed(int newMouseSelectionScrollSpeed);
@ -448,6 +454,8 @@ public:
//font
QString mFontName;
QString mFallbackFontName;
QString mFallbackFontName2;
QString mFallbackFontName3;
int mFontSize;
bool mFontOnlyMonospaced;
double mLineSpacing;

View File

@ -57,6 +57,8 @@ void EditorFontWidget::doLoad()
ui->chkOnlyMonospacedFonts->setChecked(pSettings->editor().fontOnlyMonospaced());
ui->cbFont->setCurrentFont(QFont(pSettings->editor().fontName()));
ui->cbFallbackFont->setCurrentFont(QFont(pSettings->editor().fallbackFontName()));
ui->cbFallbackFont2->setCurrentFont(QFont(pSettings->editor().fallbackFontName2()));
ui->cbFallbackFont3->setCurrentFont(QFont(pSettings->editor().fallbackFontName3()));
ui->spinFontSize->setValue(pSettings->editor().fontSize());
ui->spinLineSpacing->setValue(pSettings->editor().lineSpacing());
ui->chkLigature->setChecked(pSettings->editor().enableLigaturesSupport());
@ -85,6 +87,8 @@ void EditorFontWidget::doSave()
pSettings->editor().setFontOnlyMonospaced(ui->chkOnlyMonospacedFonts->isChecked());
pSettings->editor().setFontName(ui->cbFont->currentFont().family());
pSettings->editor().setFallbackFontName(ui->cbFallbackFont->currentFont().family());
pSettings->editor().setFallbackFontName2(ui->cbFallbackFont2->currentFont().family());
pSettings->editor().setFallbackFontName3(ui->cbFallbackFont3->currentFont().family());
pSettings->editor().setFontSize(ui->spinFontSize->value());
pSettings->editor().setLineSpacing(ui->spinLineSpacing->value());

View File

@ -23,160 +23,20 @@
<property name="rightMargin">
<number>11</number>
</property>
<item row="1" column="1">
<widget class="QWidget" name="widget_9" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFontComboBox" name="cbFallbackFont">
<property name="editable">
<bool>false</bool>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_10">
<property name="text">
<string>*Needs restart</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="3" column="1">
<widget class="QWidget" name="widget_10" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_8">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QDoubleSpinBox" name="spinLineSpacing">
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>1.000000000000000</double>
</property>
<property name="maximum">
<double>3.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>563</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Size:</string>
<string>Font:</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="chkLigature">
<property name="text">
<string>Enable ligatures support</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Line Spacing:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QWidget" name="widget_3" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QSpinBox" name="spinFontSize">
<property name="minimum">
<number>2</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="0" column="1">
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
@ -228,6 +88,67 @@
</layout>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Size:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QWidget" name="widget_10" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_8">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QDoubleSpinBox" name="spinLineSpacing">
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>1.000000000000000</double>
</property>
<property name="maximum">
<double>3.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>563</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Line Spacing:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
@ -235,13 +156,188 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<item row="2" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Font:</string>
<string>Fallback Font 2:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QWidget" name="widget_9" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFontComboBox" name="cbFallbackFont">
<property name="editable">
<bool>false</bool>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_10">
<property name="text">
<string>*Needs restart</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="4" column="1">
<widget class="QWidget" name="widget_3" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QSpinBox" name="spinFontSize">
<property name="minimum">
<number>2</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Fallback Font 3:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QWidget" name="widget_11" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_9">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFontComboBox" name="cbFallbackFont2"/>
</item>
<item>
<widget class="QLabel" name="label_13">
<property name="text">
<string>*Needs restart</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="3" column="1">
<widget class="QWidget" name="widget_12" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFontComboBox" name="cbFallbackFont3"/>
</item>
<item>
<widget class="QLabel" name="label_14">
<property name="text">
<string>*Needs restart</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_10">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -1561,6 +1561,14 @@
<source>*Needs restart</source>
<translation type="unfinished">*Necessário reiniciar</translation>
</message>
<message>
<source>Fallback Font 2:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Fallback Font 3:</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>EditorGeneralWidget</name>

View File

@ -2059,25 +2059,27 @@ p, li { white-space: pre-wrap; }
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="54"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="194"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="280"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="321"/>
<source>*Needs restart</source>
<translation>*</translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="124"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="508"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="94"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="604"/>
<source>Size:</source>
<translation>:</translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="241"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="501"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="29"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="597"/>
<source>Font:</source>
<translation>:</translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="211"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="596"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="71"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="692"/>
<source>Show only monospaced fonts</source>
<translation></translation>
</message>
@ -2094,92 +2096,102 @@ p, li { white-space: pre-wrap; }
<translation type="vanished"></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="131"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="36"/>
<source>Enable ligatures support</source>
<translation>(ligratures)</translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="138"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="148"/>
<source>Line Spacing:</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="234"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="155"/>
<source>Fallback Font:</source>
<translation>:</translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="251"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="162"/>
<source>Fallback Font 2:</source>
<translation>2:</translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="255"/>
<source>Fallback Font 3:</source>
<translation>3:</translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="347"/>
<source>Show whitespaces</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="257"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="353"/>
<source>Leading</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="264"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="360"/>
<source>Inner</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="271"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="367"/>
<source>Trailing</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="278"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="374"/>
<source>Line break</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="288"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="384"/>
<source>Gutter</source>
<translation>线</translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="309"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="405"/>
<source>Gutter is visible</source>
<translation>线</translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="331"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="427"/>
<source>Left Offset</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="348"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="444"/>
<source>Right Offset</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="381"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="477"/>
<source>Show Line Numbers</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="405"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="501"/>
<source>Add leading zeros to line numbers</source>
<translation>0</translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="412"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="508"/>
<source>Line numbers starts at zero</source>
<translation>0</translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="419"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="515"/>
<source>Auto calculate the digit count of line number</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="441"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="537"/>
<source>Digit count</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="477"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="573"/>
<source>Use Custom Font</source>
<translation>使</translation>
</message>
@ -9059,7 +9071,7 @@ p, li { white-space: pre-wrap; }
<translation>(-g3)</translation>
</message>
<message>
<location filename="../settings.cpp" line="3440"/>
<location filename="../settings.cpp" line="3466"/>
<source>Would you like Red Panda C++ to search for compilers in PATH?</source>
<translation>C++PATH路径中寻找gcc编译器吗</translation>
</message>
@ -9270,7 +9282,7 @@ p, li { white-space: pre-wrap; }
<translation type="vanished">(-S)</translation>
</message>
<message>
<location filename="../settings.cpp" line="3442"/>
<location filename="../settings.cpp" line="3468"/>
<source>Confirm</source>
<translation></translation>
</message>
@ -9291,13 +9303,13 @@ p, li { white-space: pre-wrap; }
<translation type="vanished">&lt;br /&gt;&lt;br /&gt;</translation>
</message>
<message>
<location filename="../settings.cpp" line="3432"/>
<location filename="../settings.cpp" line="3438"/>
<location filename="../settings.cpp" line="3458"/>
<location filename="../settings.cpp" line="3464"/>
<source>Compiler set not configuared.</source>
<translation></translation>
</message>
<message>
<location filename="../settings.cpp" line="3434"/>
<location filename="../settings.cpp" line="3460"/>
<source>Would you like Red Panda C++ to search for compilers in the following locations: &lt;BR /&gt;&apos;%1&apos;&lt;BR /&gt;&apos;%2&apos;? </source>
<translation>C++&lt;br /&gt;%1&lt;br /&gt;%2</translation>
</message>
@ -9666,7 +9678,7 @@ p, li { white-space: pre-wrap; }
<location filename="../autolinkmanager.cpp" line="54"/>
<location filename="../autolinkmanager.cpp" line="70"/>
<location filename="../autolinkmanager.cpp" line="89"/>
<location filename="../settings.cpp" line="4055"/>
<location filename="../settings.cpp" line="4081"/>
<location filename="../widgets/ojproblemsetmodel.cpp" line="168"/>
<location filename="../widgets/ojproblemsetmodel.cpp" line="229"/>
<source>Can&apos;t open file &apos;%1&apos; for read.</source>
@ -9721,7 +9733,7 @@ p, li { white-space: pre-wrap; }
<translation> %1 </translation>
</message>
<message>
<location filename="../settings.cpp" line="3300"/>
<location filename="../settings.cpp" line="3326"/>
<source>Error executing platform compiler hint add-on</source>
<translation></translation>
</message>
@ -10685,12 +10697,12 @@ p, li { white-space: pre-wrap; }
<context>
<name>Settings</name>
<message>
<location filename="../settings.cpp" line="4042"/>
<location filename="../settings.cpp" line="4068"/>
<source>Error</source>
<translation></translation>
</message>
<message>
<location filename="../settings.cpp" line="4043"/>
<location filename="../settings.cpp" line="4069"/>
<source>Can&apos;t find terminal program!</source>
<translation></translation>
</message>

View File

@ -1394,6 +1394,14 @@
<source>*Needs restart</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Fallback Font 2:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Fallback Font 3:</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>EditorGeneralWidget</name>

View File

@ -147,7 +147,10 @@ void CPUDialog::resetEditorFont(float dpi)
f.setFamilies(
QStringList{
pSettings->editor().fontName(),
pSettings->editor().fallbackFontName()});
pSettings->editor().fallbackFontName(),
pSettings->editor().fallbackFontName2(),
pSettings->editor().fallbackFontName3(),
});
f.setPixelSize(pointToPixel(pSettings->editor().fontSize(),dpi));
f.setStyleStrategy(QFont::PreferAntialias);
ui->txtCode->setFont(f);

View File

@ -1750,7 +1750,7 @@ int Document::glyphWidth(const QString &glyph, int left, const QFontMetrics &fon
if (ch == '\t') {
glyphWidth = tabWidth() - left % tabWidth();
} else {
glyphWidth = fontMetrics.horizontalAdvance(ch);
glyphWidth = fontMetrics.horizontalAdvance(glyph);
//qDebug()<<glyph<<glyphCols<<width<<mCharWidth;
}
return glyphWidth;