- fix: (wrongly) use the default font to calculate non-ascii characters' width
This commit is contained in:
parent
66746e8c3d
commit
40dec1b9ff
1
NEWS.md
1
NEWS.md
|
@ -9,6 +9,7 @@ Red Panda C++ Version 1.1.6
|
|||
- enhancement: disable column mode in readonly editors
|
||||
- fix: inefficient loop when render long lines
|
||||
- fix: indents for "default" are not the same with "case"
|
||||
- fix: (wrongly) use the default font to calculate non-ascii characters' width
|
||||
|
||||
Red Panda C++ Version 1.1.5
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent),
|
|||
#error "Not supported!"
|
||||
#endif
|
||||
mFontDummy.setStyleStrategy(QFont::PreferAntialias);
|
||||
mDocument = std::make_shared<SynDocument>(mFontDummy, this);
|
||||
mDocument = std::make_shared<SynDocument>(mFontDummy, mFontDummy, this);
|
||||
//fPlugins := TList.Create;
|
||||
mMouseMoved = false;
|
||||
mUndoing = false;
|
||||
|
@ -4068,6 +4068,8 @@ void SynEdit::setFontForNonAscii(const QFont &newFontForNonAscii)
|
|||
{
|
||||
mFontForNonAscii = newFontForNonAscii;
|
||||
mFontForNonAscii.setStyleStrategy(QFont::PreferAntialias);
|
||||
if (mDocument)
|
||||
mDocument->setFontMetrics(font(),mFontForNonAscii);
|
||||
}
|
||||
|
||||
const QColor &SynEdit::backgroundColor() const
|
||||
|
@ -6197,7 +6199,7 @@ bool SynEdit::event(QEvent *event)
|
|||
case QEvent::FontChange:
|
||||
synFontChanged();
|
||||
if (mDocument)
|
||||
mDocument->setFontMetrics(font());
|
||||
mDocument->setFontMetrics(font(),mFontForNonAscii);
|
||||
break;
|
||||
case QEvent::MouseMove: {
|
||||
updateMouseCursor();
|
||||
|
|
|
@ -27,9 +27,10 @@
|
|||
#include <QMessageBox>
|
||||
#include <cmath>
|
||||
|
||||
SynDocument::SynDocument(const QFont& font, QObject *parent):
|
||||
SynDocument::SynDocument(const QFont& font, const QFont& nonAsciiFont, QObject *parent):
|
||||
QObject(parent),
|
||||
mFontMetrics(font),
|
||||
mNonAsciiFontMetrics(nonAsciiFont),
|
||||
mTabWidth(4),
|
||||
mMutex(QMutex::Recursive)
|
||||
{
|
||||
|
@ -515,10 +516,11 @@ const QFontMetrics &SynDocument::fontMetrics() const
|
|||
return mFontMetrics;
|
||||
}
|
||||
|
||||
void SynDocument::setFontMetrics(const QFont &newFont)
|
||||
void SynDocument::setFontMetrics(const QFont &newFont, const QFont& newNonAsciiFont)
|
||||
{
|
||||
mFontMetrics = QFontMetrics(newFont);
|
||||
mCharWidth = mFontMetrics.horizontalAdvance("M");
|
||||
mNonAsciiFontMetrics = QFontMetrics(newNonAsciiFont);
|
||||
}
|
||||
|
||||
void SynDocument::setTabWidth(int newTabWidth)
|
||||
|
@ -723,8 +725,13 @@ int SynDocument::charColumns(QChar ch) const
|
|||
{
|
||||
if (ch.unicode()<=32)
|
||||
return 1;
|
||||
int width;
|
||||
if (ch.unicode()<0xFF)
|
||||
width = mFontMetrics.horizontalAdvance(ch);
|
||||
else
|
||||
width = mNonAsciiFontMetrics.horizontalAdvance(ch);
|
||||
//return std::ceil((int)(fontMetrics().horizontalAdvance(ch) * dpiFactor()) / (double)mCharWidth);
|
||||
return std::ceil((int)(fontMetrics().horizontalAdvance(ch)) / (double)mCharWidth);
|
||||
return std::ceil(width / (double)mCharWidth);
|
||||
}
|
||||
|
||||
void SynDocument::putTextStr(const QString &text)
|
||||
|
|
|
@ -60,7 +60,7 @@ class SynDocument : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SynDocument(const QFont& font, QObject* parent=nullptr);
|
||||
explicit SynDocument(const QFont& font, const QFont& nonAsciiFont, QObject* parent=nullptr);
|
||||
|
||||
int parenthesisLevels(int Index);
|
||||
int bracketLevels(int Index);
|
||||
|
@ -116,7 +116,7 @@ public:
|
|||
void setTabWidth(int newTabWidth);
|
||||
|
||||
const QFontMetrics &fontMetrics() const;
|
||||
void setFontMetrics(const QFont &newFont);
|
||||
void setFontMetrics(const QFont &newFont, const QFont& newNonAsciiFont);
|
||||
|
||||
public slots:
|
||||
void invalidAllLineColumns();
|
||||
|
@ -144,6 +144,7 @@ private:
|
|||
//SynEdit* mEdit;
|
||||
|
||||
QFontMetrics mFontMetrics;
|
||||
QFontMetrics mNonAsciiFontMetrics;
|
||||
int mTabWidth;
|
||||
int mCharWidth;
|
||||
//int mCount;
|
||||
|
|
Loading…
Reference in New Issue