work save

This commit is contained in:
Roy Qu 2024-02-22 19:00:47 +08:00
parent cb1d2594da
commit 2489148da6
3 changed files with 29 additions and 15 deletions

View File

@ -842,17 +842,26 @@ QList<int> calcGlyphPositions(const QString &text)
QList<int> glyphPositions;
//parse mGlyphs
int i=0;
bool consecutive = false;
while (i<text.length()) {
QChar ch = text[i];
if (ch.isHighSurrogate() && i+1<text.length() && QChar::isLowSurrogate(text[i+1].unicode())) {
//character that larger than 0xffff
glyphPositions.append(i);
int ucs4 = QChar::surrogateToUcs4(ch, text[i+1]);
if (QChar::combiningClass(ucs4)==0 || glyphPositions.isEmpty()) {
if (!consecutive)
glyphPositions.append(i);
}
i+=2;
continue;
} else if (ch.unicode() == 0x200D) {
consecutive = true;
} else if (ch.combiningClass()!=0 && !glyphPositions.isEmpty()) {
//a Combining character
} else {
glyphPositions.append(i);
if (!consecutive)
glyphPositions.append(i);
consecutive = false;
}
i++;
}

View File

@ -88,7 +88,9 @@ private:
* @return char index in the line text (start from 0)
*/
int glyphStart(int i) const {
Q_ASSERT(i>=0 && i<mGlyphPositions.length());
Q_ASSERT(i>=0);
if (i>=mGlyphPositions.length())
return mLineText.length();
return mGlyphPositions[i];
}
@ -115,7 +117,9 @@ private:
*/
int glyphStartColumn(int i) const {
Q_ASSERT(mColumns>=0);
Q_ASSERT(i>=0 && i<mGlyphColumns.length());
Q_ASSERT(i>=0);
if (i>mGlyphColumns.length())
return mColumns+1;
return mGlyphColumns[i];
}

View File

@ -401,9 +401,10 @@ void QSynEditPainter::paintToken(const QString &token, int tokenCols, int column
QList<int> glyphPositions = calcGlyphPositions(token);
for (int i=0; i< glyphPositions.length();i++) {
int glyphStart = glyphPositions[i];
int glyphLen =(i+1<glyphPositions.length())?glyphPositions[i+1]:token.length();
QString glyph = token.mid(glyphStart,glyphLen);
int glyphEnd =(i+1<glyphPositions.length())?glyphPositions[i+1]:token.length();
QString glyph = token.mid(glyphStart,glyphEnd-glyphStart);
int charCols = edit->document()->glyphColumns(glyph, columnsBefore+tokenColLen);
//qDebug()<<glyph<<charCols;
if (tokenColLen+charCols>=first) {
if (!startPaint && (tokenColLen+1!=first)) {
nX-= (first - tokenColLen - 1) * edit->mCharWidth;
@ -414,15 +415,15 @@ void QSynEditPainter::paintToken(const QString &token, int tokenCols, int column
break;
//painter->drawText(nX,rcToken.bottom()-painter->fontMetrics().descent()*edit->dpiFactor() , Token[i]);
if (startPaint) {
bool drawed = false;
bool drawed = false;
if (painter->fontInfo().fixedPitch()
&& edit->mOptions.testFlag(eoLigatureSupport)
&& operatorGlyphs.contains(glyph)) {
QString textToPaint = glyph;
while(i+1<token.length()) {
int glyphStart = glyphPositions[i+1];
int glyphLen =(i+2<glyphPositions.length())?glyphPositions[i+2]:token.length();
QString glyph2 = token.mid(glyphStart,glyphLen);
int glyphEnd =(i+2<glyphPositions.length())?glyphPositions[i+2]:token.length();
QString glyph2 = token.mid(glyphStart,glyphEnd-glyphStart);
if (!operatorGlyphs.contains(glyph))
break;
i+=1;
@ -433,11 +434,11 @@ void QSynEditPainter::paintToken(const QString &token, int tokenCols, int column
drawed = true;
}
if (!drawed) {
if (token[i].unicode()<=0xFF) {
QChar ch;
if (glyph.length()==1 && glyph.front().unicode()<=0xFF) {
QString ch;
int padding=0;
if (showGlyphs) {
switch(token[i].unicode()) {
switch(glyph.front().unicode()) {
case '\t':
ch=TabGlyph;
padding=(charCols-1)/2*edit->mCharWidth;
@ -446,15 +447,15 @@ void QSynEditPainter::paintToken(const QString &token, int tokenCols, int column
ch=SpaceGlyph;
break;
default:
ch=token[i];
ch=glyph;
}
} else {
ch=token[i];
ch=glyph;
}
painter->drawText(nX+padding,rcToken.bottom()-painter->fontMetrics().descent() , ch);
} else {
painter->setFont(fontForNonAscii);
painter->drawText(nX,rcToken.bottom()-painter->fontMetrics().descent() , token[i]);
painter->drawText(nX,rcToken.bottom()-painter->fontMetrics().descent() , glyph);
painter->setFont(font);
}
drawed = true;