diff --git a/libs/qsynedit/qsynedit/document.cpp b/libs/qsynedit/qsynedit/document.cpp index d6e399ab..a9443d05 100644 --- a/libs/qsynedit/qsynedit/document.cpp +++ b/libs/qsynedit/qsynedit/document.cpp @@ -836,6 +836,8 @@ QString Document::glyph(int line, int glyphIdx) QString Document::glyphAt(int line, int charPos) { QMutexLocker locker(&mMutex); + if (line<0 || line>=count()) + return QString(); QList glyphStartCharList = mLines[line]->glyphStartCharList(); int glyphIdx = charToGlyphIndex(mLines[line]->lineText(), glyphStartCharList, charPos); return mLines[line]->glyph(glyphIdx); @@ -844,6 +846,8 @@ QString Document::glyphAt(int line, int charPos) int Document::charToGlyphStartChar(int line, int charPos) { QMutexLocker locker(&mMutex); + if (line<0 || line>=count()) + return 0; QList glyphStartCharList = mLines[line]->glyphStartCharList(); int glyphIdx = charToGlyphIndex(mLines[line]->lineText(), glyphStartCharList, charPos); return mLines[line]->glyphStartChar(glyphIdx); @@ -1029,6 +1033,8 @@ int Document::xposToGlyphIndex(int strWidth, QList glyphPositionList, int x int Document::charToGlyphStartPosition(int line, int charPos) { QMutexLocker locker(&mMutex); + if (line<0 || line>=count()) + return 0; QList glyphStartCharList = mLines[line]->glyphStartCharList(); int glyphIdx = charToGlyphIndex(mLines[line]->lineText(), glyphStartCharList, charPos); return mLines[line]->glyphStartPosition(glyphIdx); @@ -1047,7 +1053,7 @@ int Document::xposToGlyphStartChar(int line, int xpos) int Document::charToGlyphStartPosition(int line, const QString newStr, int charPos) { QMutexLocker locker(&mMutex); - if (mLines[line]->lineText() == newStr) { + if (line>=0 && linelineText() == newStr) { return charToGlyphStartPosition(line,charPos); } else { QList glyphStartCharList = calcGlyphStartCharList(newStr); diff --git a/libs/qsynedit/qsynedit/painter.cpp b/libs/qsynedit/qsynedit/painter.cpp index 66f0f23b..a0ab4cf0 100644 --- a/libs/qsynedit/qsynedit/painter.cpp +++ b/libs/qsynedit/qsynedit/painter.cpp @@ -379,13 +379,13 @@ void QSynEditPainter::paintToken( bool tryLigature = false; if (glyph.length()==0) { } else if (glyph.length()==1 && glyph.front().unicode()<=32){ + } else if (mEdit->mOptions.testFlag(eoForceMonospace) + && glyphWidth != mPainter->fontMetrics().horizontalAdvance(glyph)) { } else { tryLigature = true; } if (tryLigature) { QString textToPaint = glyph; - int oldGlyphWidth = glyphWidth; - int oldI = i; while(i+1mOptions.testFlag(eoForceMonospace)) { + if (glyphWidth+glyph2Width != mPainter->fontMetrics().horizontalAdvance(textToPaint+glyph2)) { + break; + } + } + i++; + glyphWidth += glyph2Width; + textToPaint += glyph2; if (tokenWidth + glyphWidth > last ) break; } - 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; + if (!fontInited) { + mPainter->setFont(font); + fontInited = true; } + //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 dfb00208..311e460d 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -864,14 +864,12 @@ QString QSynEdit::GetLeftSpacing(int charCount, bool wantTabs) const int QSynEdit::charToGlyphLeft(int line, int charPos) const { - Q_ASSERT(line>=1 && line <= mDocument->count()); QString s = getDisplayStringAtLine(line); return mDocument->charToGlyphStartPosition(line-1, s, charPos-1); } int QSynEdit::charToGlyphLeft(int line, const QString &s, int charPos) const { - Q_ASSERT(line>=1 && line <= mDocument->count()); return mDocument->charToGlyphStartPosition(line-1, s, charPos-1); }