diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index ac2c7bdd..fac20c5c 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -5258,8 +5258,6 @@ void Editor::applySettings() options.setFlag(QSynedit::eoAutoIndent,pSettings->editor().autoIndent()); options.setFlag(QSynedit::eoTabsToSpaces,pSettings->editor().tabToSpaces()); - options.setFlag(QSynedit::eoLigatureSupport, pSettings->editor().enableLigaturesSupport()); - options.setFlag(QSynedit::eoKeepCaretX,pSettings->editor().keepCaretX()); options.setFlag(QSynedit::eoEnhanceHomeKey,pSettings->editor().enhanceHomeKey()); options.setFlag(QSynedit::eoEnhanceEndKey,pSettings->editor().enhanceEndKey()); @@ -5273,6 +5271,10 @@ void Editor::applySettings() options.setFlag(QSynedit::eoShowRainbowColor, pSettings->editor().rainbowParenthesis() && syntaxer() && syntaxer()->supportBraceLevel()); + options.setFlag(QSynedit::eoForceMonospace, + pSettings->editor().forceFixedFontWidth()); + options.setFlag(QSynedit::eoLigatureSupport, + pSettings->editor().enableLigaturesSupport()); setOptions(options); setTabSize(pSettings->editor().tabWidth()); diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index cc4d7360..b48fdb94 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -857,6 +857,16 @@ void Settings::Editor::setTipsDelay(int newTipsDelay) mTipsDelay = newTipsDelay; } +bool Settings::Editor::forceFixedFontWidth() const +{ + return mForceFixedFontWidth; +} + +void Settings::Editor::setForceFixedFontWidth(bool newForceFixedWidth) +{ + mForceFixedFontWidth = newForceFixedWidth; +} + bool Settings::Editor::showTrailingSpaces() const { return mShowTrailingSpaces; @@ -1408,6 +1418,7 @@ void Settings::Editor::doSave() saveValue("font_only_monospaced", mFontOnlyMonospaced); saveValue("line_spacing",mLineSpacing); saveValue("enable_ligatures_support", mEnableLigaturesSupport); + saveValue("force_fixed_font_width", mForceFixedFontWidth); saveValue("show_leading_spaces", mShowLeadingSpaces); saveValue("show_trailing_spaces", mShowTrailingSpaces); @@ -1538,6 +1549,12 @@ void Settings::Editor::doLoad() mFontName = stringValue("font_name",DEFAULT_MONO_FONT); QString defaultCjkFontName = DEFAULT_MONO_FONT; QString defaultLocaleName = QLocale::system().name(); + bool isZhJa = + defaultLocaleName.startsWith("zh_") + || defaultLocaleName.startsWith("ja_") + || defaultLocaleName==("zh") + || defaultLocaleName == ("ja"); + if (defaultLocaleName == "zh_TW") defaultCjkFontName = CJK_MONO_FONT_TC; else if (defaultLocaleName == "ja_JP") @@ -1554,7 +1571,13 @@ void Settings::Editor::doLoad() mFontSize = intValue("font_size",12); mFontOnlyMonospaced = boolValue("font_only_monospaced",true); mLineSpacing = doubleValue("line_spacing",1.1); - mEnableLigaturesSupport = boolValue("enable_ligatures_support", true); + mForceFixedFontWidth = boolValue("force_fixed_font_width", isZhJa); + // if (mForceFixedFontWidth) + // mEnableLigaturesSupport = false; + // else + // mEnableLigaturesSupport = boolValue("enable_ligatures_support", !isZhJa); + mEnableLigaturesSupport = boolValue("enable_ligatures_support", !isZhJa); + mShowLeadingSpaces = boolValue("show_leading_spaces", false); mShowTrailingSpaces = boolValue("show_trailing_spaces", false); diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h index ed225df1..f931a27b 100644 --- a/RedPandaIDE/settings.h +++ b/RedPandaIDE/settings.h @@ -420,6 +420,9 @@ public: int tipsDelay() const; void setTipsDelay(int newTipsDelay); + bool forceFixedFontWidth() const; + void setForceFixedFontWidth(bool newForceFixedWidth); + private: //General // indents @@ -456,7 +459,6 @@ public: bool mShowRightEdgeLine; int mRightEdgeWidth; QColor mRightEdgeLineColor; - bool mEnableLigaturesSupport; //Font //font @@ -469,6 +471,8 @@ public: int mFontSize; bool mFontOnlyMonospaced; double mLineSpacing; + bool mEnableLigaturesSupport; + bool mForceFixedFontWidth; bool mShowLeadingSpaces; bool mShowTrailingSpaces; diff --git a/RedPandaIDE/settingsdialog/editorfontwidget.cpp b/RedPandaIDE/settingsdialog/editorfontwidget.cpp index 69608373..889ae7ae 100644 --- a/RedPandaIDE/settingsdialog/editorfontwidget.cpp +++ b/RedPandaIDE/settingsdialog/editorfontwidget.cpp @@ -71,6 +71,7 @@ void EditorFontWidget::doLoad() ui->spinFontSize->setValue(pSettings->editor().fontSize()); ui->spinLineSpacing->setValue(pSettings->editor().lineSpacing()); ui->chkLigature->setChecked(pSettings->editor().enableLigaturesSupport()); + ui->chkForceFixedFontWidth->setChecked(pSettings->editor().forceFixedFontWidth()); ui->chkLeadingSpaces->setChecked(pSettings->editor().showLeadingSpaces()); ui->chkInnerSpaces->setChecked(pSettings->editor().showInnerSpaces()); ui->chkTrailingSpaces->setChecked(pSettings->editor().showTrailingSpaces()); @@ -104,6 +105,7 @@ void EditorFontWidget::doSave() pSettings->editor().setLineSpacing(ui->spinLineSpacing->value()); pSettings->editor().setEnableLigaturesSupport(ui->chkLigature->isChecked()); + pSettings->editor().setForceFixedFontWidth(ui->chkForceFixedFontWidth->isChecked()); pSettings->editor().setShowLeadingSpaces(ui->chkLeadingSpaces->isChecked()); pSettings->editor().setShowInnerSpaces(ui->chkInnerSpaces->isChecked()); pSettings->editor().setShowTrailingSpaces(ui->chkTrailingSpaces->isChecked()); @@ -132,3 +134,17 @@ void EditorFontWidget::onFallbackFontsCheckStateChanged() ui->cbFallbackFont3->setEnabled(ui->chkFallbackFont3->isChecked()); } + +// void EditorFontWidget::on_chkLigature_toggled(bool checked) +// { +// if (ui->chkLigature->isChecked()) +// ui->chkForceFixedFontWidth->setChecked(false); +// } + + +// void EditorFontWidget::on_chkForceFixedFontWidth_toggled(bool checked) +// { +// if (ui->chkForceFixedFontWidth->isChecked()) +// ui->chkLigature->setChecked(false); +// } + diff --git a/RedPandaIDE/settingsdialog/editorfontwidget.h b/RedPandaIDE/settingsdialog/editorfontwidget.h index 8b9cf5a2..a2545e9b 100644 --- a/RedPandaIDE/settingsdialog/editorfontwidget.h +++ b/RedPandaIDE/settingsdialog/editorfontwidget.h @@ -37,6 +37,10 @@ private slots: void on_chkOnlyMonospacedFonts_stateChanged(int arg1); void on_chkGutterOnlyMonospacedFonts_stateChanged(int arg1); + // void on_chkLigature_toggled(bool checked); + + // void on_chkForceFixedFontWidth_toggled(bool checked); + private: Ui::EditorFontWidget *ui; diff --git a/RedPandaIDE/settingsdialog/editorfontwidget.ui b/RedPandaIDE/settingsdialog/editorfontwidget.ui index 79f4b7f2..27c3685d 100644 --- a/RedPandaIDE/settingsdialog/editorfontwidget.ui +++ b/RedPandaIDE/settingsdialog/editorfontwidget.ui @@ -23,125 +23,6 @@ 11 - - - - Font: - - - - - - - Enable ligatures support - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - false - - - QComboBox::AdjustToContents - - - QFontComboBox::AllFonts - - - - - - - Show only monospaced fonts - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - Size: - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 1 - - - 1.000000000000000 - - - 3.000000000000000 - - - 0.100000000000000 - - - - - - - Qt::Horizontal - - - - 563 - 20 - - - - - - - @@ -149,16 +30,9 @@ - - - - Fallback Font: - - - - - - + + + 0 @@ -172,24 +46,21 @@ 0 - + false - - QComboBox::AdjustToContents - - + *Needs restart - + Qt::Horizontal @@ -287,9 +158,44 @@ - - - + + + + Fallback Font 3: + + + + + + + Fallback Font: + + + + + + + Fallback Font 2: + + + + + + + Size: + + + + + + + Font: + + + + + + 0 @@ -303,21 +209,27 @@ 0 - + false - - - - - - *Needs restart + + QComboBox::AdjustToContents + + + QFontComboBox::AllFonts - + + + Show only monospaced fonts + + + + + Qt::Horizontal @@ -332,18 +244,144 @@ - - - - Fallback Font 2: - + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + false + + + QComboBox::AdjustToContents + + + + + + + *Needs restart + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + - - - - Fallback Font 3: - + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 1 + + + 1.000000000000000 + + + 3.000000000000000 + + + 0.100000000000000 + + + + + + + Qt::Horizontal + + + + 563 + 20 + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Enable ligatures support + + + + + + + Force fixed width + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + diff --git a/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts b/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts index 6caa1fd2..759431f6 100644 --- a/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts +++ b/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts @@ -1569,6 +1569,10 @@ Fallback Font 3: + + Force fixed width + + EditorGeneralWidget diff --git a/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts b/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts index d2dc4173..2ab064dc 100644 --- a/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts +++ b/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts @@ -1653,7 +1653,7 @@ p, li { white-space: pre-wrap; } 输入当前断点的生效条件: - + Readonly 只读 @@ -2059,27 +2059,27 @@ p, li { white-space: pre-wrap; } 表单 - - - + + + *Needs restart *需要重启之后生效 - - + + Size: 大小: - - + + Font: 字体: - - + + Show only monospaced fonts 只显示等宽字体 @@ -2096,102 +2096,107 @@ p, li { white-space: pre-wrap; } 显示特殊字符 - + Enable ligatures support 启用连字(ligratures)功能 - + Line Spacing: 行高: - + Fallback Font: 备选字体: - + Fallback Font 2: 备选字体2: - + Fallback Font 3: 备选字体3: - + + Force fixed width + 强制等宽显示 + + + Show whitespaces 显示空白字符 - + Leading 行首 - + Inner 中间 - + Trailing 行尾 - + Line break 换行符 - + Gutter 装订线 - + Gutter is visible 显示装订线区域 - + Left Offset 左侧留白 - + Right Offset 右侧留白 - + Show Line Numbers 显示行号 - + Add leading zeros to line numbers 在行号前补齐前导0 - + Line numbers starts at zero 第一行从0开始编号 - + Auto calculate the digit count of line number 自动计算行号位数 - + Digit count 行号位数 - + Use Custom Font 使用自定义字体 @@ -8855,7 +8860,7 @@ p, li { white-space: pre-wrap; } QApplication - + Error 错误 @@ -8947,23 +8952,23 @@ p, li { white-space: pre-wrap; } - - + + Error 错误 - + Can't create configuration folder %1 无法创建配置文件夹"%1" - + Can't write to configuration file %1 无法写入配置文件夹"%1" - + Can't load autolink settings 无法载入自动链接设置 @@ -9071,7 +9076,7 @@ p, li { white-space: pre-wrap; } 生成调试信息(-g3) - + Would you like Red Panda C++ to search for compilers in PATH? 您同意小熊猫C++在PATH路径中寻找gcc编译器吗? @@ -9282,7 +9287,7 @@ p, li { white-space: pre-wrap; } 只生成汇编代码(-S) - + Confirm 确认 @@ -9303,13 +9308,13 @@ p, li { white-space: pre-wrap; } 如果仍然保留这些设置,可能会导致编译错误。<br /><br />请选择“是”,除非您清楚的知道选择“否”的后果, - - + + Compiler set not configuared. 未配置编译器设置。 - + Would you like Red Panda C++ to search for compilers in the following locations: <BR />'%1'<BR />'%2'? 您需要小熊猫C++在下列位置搜索编译器吗:<br />%1<br />%2 @@ -9665,12 +9670,12 @@ p, li { white-space: pre-wrap; } 无标题 - + constructor 构造函数 - + destructor 析构函数 @@ -9678,7 +9683,7 @@ p, li { white-space: pre-wrap; } - + Can't open file '%1' for read. @@ -9733,7 +9738,7 @@ p, li { white-space: pre-wrap; } 无法检测适用于 “%1” 的终端参数模式。 - + Error executing platform compiler hint add-on 执行平台编译器提示附加组件错误 @@ -10697,12 +10702,12 @@ p, li { white-space: pre-wrap; } Settings - + Error 错误 - + Can't find terminal program! 找不到合适的终端程序! diff --git a/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts b/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts index fe485d38..a55b93a1 100644 --- a/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts +++ b/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts @@ -1402,6 +1402,10 @@ Fallback Font 3: + + Force fixed width + + EditorGeneralWidget diff --git a/RedPandaIDE/widgets/cpudialog.cpp b/RedPandaIDE/widgets/cpudialog.cpp index f366bcc0..a48aefed 100644 --- a/RedPandaIDE/widgets/cpudialog.cpp +++ b/RedPandaIDE/widgets/cpudialog.cpp @@ -142,7 +142,11 @@ void CPUDialog::setDisassembly(const QString& file, const QString& funcName,cons void CPUDialog::resetEditorFont(float dpi) { - + QSynedit::EditorOptions options=ui->txtCode->getOptions(); + options.setFlag(QSynedit::eoLigatureSupport, pSettings->editor().enableLigaturesSupport()); + options.setFlag(QSynedit::eoForceMonospace, + pSettings->editor().forceFixedFontWidth()); + ui->txtCode->setOptions(options); QFont f=QFont(); f.setFamilies(pSettings->editor().fontFamilies()); f.setPixelSize(pointToPixel(pSettings->editor().fontSize(),dpi)); diff --git a/libs/qsynedit/qsynedit/document.cpp b/libs/qsynedit/qsynedit/document.cpp index 8dc06e09..d6e399ab 100644 --- a/libs/qsynedit/qsynedit/document.cpp +++ b/libs/qsynedit/qsynedit/document.cpp @@ -31,13 +31,14 @@ namespace QSynedit { Document::Document(const QFont& font, QObject *parent): - QObject(parent), - mFontMetrics(font), - mTabSize(4), + QObject{parent}, + mFontMetrics{font}, + mTabSize{4}, + mForceMonospace{false}, #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) - mMutex() + mMutex{} #else - mMutex(QMutex::Recursive) + mMutex{QMutex::Recursive} #endif { mAppendNewLineAtEOF = true; @@ -585,6 +586,19 @@ void Document::saveUTF32File(QFile &file, QTextCodec* codec) file.write(codec->fromUnicode(text)); } +bool Document::forceMonospace() const +{ + return mForceMonospace; +} + +void Document::setForceMonospace(bool newForceMonospace) +{ + int oldValue = mForceMonospace; + mForceMonospace = newForceMonospace; + if (oldValue != mForceMonospace) + invalidateAllLineWidth(); +} + const QFontMetrics &Document::fontMetrics() const { return mFontMetrics; @@ -936,7 +950,7 @@ int Document::glyphWidth(int line, int glyphIdx) int Document::glyphWidth(const QString &glyph, int left) const { - return glyphWidth(glyph,left,mFontMetrics); + return glyphWidth(glyph,left,mFontMetrics,mForceMonospace); } int Document::charToGlyphIndex(int line, int charIdx) @@ -982,7 +996,7 @@ QList Document::calcGlyphPositionList(const QString &lineText, const QList< end = lineText.length(); } QString glyph = lineText.mid(start,end-start); - int gWidth = glyphWidth(glyph, right, fontMetrics); + int gWidth = glyphWidth(glyph, right, fontMetrics, mForceMonospace); glyphPostionList.append(right); right += gWidth; } @@ -1732,7 +1746,7 @@ int Document::updateGlyphStartPositionList( end = lineText.length(); } QString glyph = lineText.mid(start,end-start); - int gWidth = glyphWidth(glyph, right, fontMetrics); + int gWidth = glyphWidth(glyph, right, fontMetrics, mForceMonospace); glyphStartPositionList[i] = right; right += gWidth; } @@ -1741,18 +1755,22 @@ int Document::updateGlyphStartPositionList( return right-left; } -int Document::glyphWidth(const QString &glyph, int left, const QFontMetrics &fontMetrics) const +int Document::glyphWidth(const QString &glyph, int left, const QFontMetrics &fontMetrics, bool forceMonospace) const { int glyphWidth; if (glyph.length()==0) return 0; QChar ch = glyph[0]; - if (ch == '\t') { + if (ch == '\t') { glyphWidth = tabWidth() - left % tabWidth(); } else { glyphWidth = fontMetrics.horizontalAdvance(glyph); //qDebug()< glyphStartPositionList); int glyphWidth(const QString& glyph, int left, - const QFontMetrics &fontMetrics) const; + const QFontMetrics &fontMetrics, + bool forceMonospace) const; int xposToGlyphIndex(int strWidth, QList glyphPositionList, int xpos) const; int charToGlyphIndex(const QString& str, QList glyphStartCharList, int charPos) const; @@ -604,6 +608,7 @@ private: bool mAppendNewLineAtEOF; int mIndexOfLongestLine; int mUpdateCount; + bool mForceMonospace; #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) QRecursiveMutex mMutex; #else diff --git a/libs/qsynedit/qsynedit/painter.cpp b/libs/qsynedit/qsynedit/painter.cpp index cd1f17b4..66f0f23b 100644 --- a/libs/qsynedit/qsynedit/painter.cpp +++ b/libs/qsynedit/qsynedit/painter.cpp @@ -384,6 +384,8 @@ void QSynEditPainter::paintToken( } if (tryLigature) { QString textToPaint = glyph; + int oldGlyphWidth = glyphWidth; + int oldI = i; while(i+1 last ) break; } - if (!fontInited) { - mPainter->setFont(font); - fontInited = true; + if (glyphWidth + == mPainter->fontMetrics().horizontalAdvance(textToPaint)) { + if (!fontInited) { + mPainter->setFont(font); + fontInited = true; + } + //qDebug()<<"paint 1:"<drawText(nX,rcToken.bottom()-mPainter->fontMetrics().descent() , textToPaint); + drawed = true; + } else { + glyphWidth = oldGlyphWidth; + i=oldI; } - //qDebug()<<"paint 1:"<drawText(nX,rcToken.bottom()-mPainter->fontMetrics().descent() , textToPaint); - drawed = true; } } if (!drawed) { diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index 71e50cca..dfb00208 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -4077,15 +4077,19 @@ void QSynEdit::setOptions(const EditorOptions &Value) setTopLine(mTopLine); bool bUpdateAll = - !sameEditorOption(Value,mOptions,eoShowLeadingSpaces) - || !sameEditorOption(Value,mOptions,eoShowInnerSpaces) - || !sameEditorOption(Value,mOptions,eoShowTrailingSpaces) - || !sameEditorOption(Value,mOptions,eoShowLineBreaks) - || !sameEditorOption(Value,mOptions,eoShowRainbowColor); + !sameEditorOption(Value,mOptions, eoShowLeadingSpaces) + || !sameEditorOption(Value,mOptions, eoLigatureSupport) + || !sameEditorOption(Value,mOptions, eoForceMonospace) + || !sameEditorOption(Value,mOptions, eoShowInnerSpaces) + || !sameEditorOption(Value,mOptions, eoShowTrailingSpaces) + || !sameEditorOption(Value,mOptions, eoShowLineBreaks) + || !sameEditorOption(Value,mOptions, eoShowRainbowColor); //bool bUpdateScroll = (Options * ScrollOptions)<>(Value * ScrollOptions); bool bUpdateScroll = true; mOptions = Value; + mDocument->setForceMonospace(mOptions.testFlag(eoForceMonospace) ); + // constrain caret position to MaxScrollWidth if eoScrollPastEol is enabled internalSetCaretXY(caretXY()); if (mOptions.testFlag(eoScrollPastEol)) { diff --git a/libs/qsynedit/qsynedit_zh_CN.ts b/libs/qsynedit/qsynedit_zh_CN.ts index 2161a981..ebfcf659 100644 --- a/libs/qsynedit/qsynedit_zh_CN.ts +++ b/libs/qsynedit/qsynedit_zh_CN.ts @@ -4288,29 +4288,29 @@ QSynedit::Document - + Can't open file '%1' for read! 无法读取文件"%1". - - + + Can't load codec '%1'! 无法加载字符编码"%1"! - + '%1' is a binaray File! This is a binaray File! '%1'是二进制文件! - + Can't open file '%1' for save! 无法保存文件"%1"! - + Data not correctly writed to file '%1'. 数据未能正确写入文件"%1"。