summaryrefslogtreecommitdiffstats
path: root/src/kernel/qfont_x11.cpp
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2025-02-04 17:59:57 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2025-02-09 19:21:23 +0900
commitfd79f0c8b020ff0c60b62c83745beb030ef38997 (patch)
tree9c9b0f1801b49d6d674685e257247db95df12a9f /src/kernel/qfont_x11.cpp
parent7f62b55432d2a5712694dec689f1ce4f07bc70a4 (diff)
downloadtqt-fd79f0c8.tar.gz
tqt-fd79f0c8.zip
Extend work on supporting surrogate characters done in commit e0a38072
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it> (cherry picked from commit 486aa07930e7b6e900f77e64726c8cc4110511d8)
Diffstat (limited to 'src/kernel/qfont_x11.cpp')
-rw-r--r--src/kernel/qfont_x11.cpp32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/kernel/qfont_x11.cpp b/src/kernel/qfont_x11.cpp
index c58f8aa6c..baeb0a939 100644
--- a/src/kernel/qfont_x11.cpp
+++ b/src/kernel/qfont_x11.cpp
@@ -675,22 +675,32 @@ int TQFontMetrics::width( TQChar ch ) const
return advances[0];
}
-
int TQFontMetrics::charWidth( const TQString &str, int pos ) const
{
- if ( pos < 0 || pos > (int)str.length() )
+ if ( pos < 0 || pos >= (int)str.length() )
return 0;
- const TQChar &ch = str.unicode()[ pos ];
- if ( ch.unicode() < TQFontEngineData::widthCacheSize &&
- d->engineData && d->engineData->widthCache[ ch.unicode() ] )
- return d->engineData->widthCache[ ch.unicode() ];
+ uint uc;
+ bool isSurrogate;
+ if (str[pos].isHighSurrogate() && pos < (str.length() - 1) && str[pos + 1].isLowSurrogate())
+ {
+ isSurrogate = true;
+ uc = TQChar::surrogateToUcs4(str[pos], str[pos + 1]);
+ }
+ else
+ {
+ isSurrogate = false;
+ uc = str[pos].unicode();
+ }
+ if ( uc < TQFontEngineData::widthCacheSize &&
+ d->engineData && d->engineData->widthCache[ uc ] )
+ return d->engineData->widthCache[ uc ];
+ const TQChar &ch = str.unicode()[ pos ];
TQFont::Script script;
SCRIPT_FOR_CHAR( script, ch );
int width;
-
if ( script >= TQFont::Arabic && script <= TQFont::Khmer ) {
// complex script shaping. Have to do some hard work
int from = TQMAX( 0, pos - 8 );
@@ -700,7 +710,7 @@ int TQFontMetrics::charWidth( const TQString &str, int pos ) const
layout.itemize( TQTextEngine::WidthOnly );
width = layout.width( pos-from, 1 );
} else if ( ::category( ch ) == TQChar::Mark_NonSpacing || qIsZeroWidthChar(ch.unicode())) {
- width = 0;
+ width = 0;
} else {
TQFontEngine *engine = d->engineForScript( script );
#ifdef QT_CHECK_STATE
@@ -710,10 +720,10 @@ int TQFontMetrics::charWidth( const TQString &str, int pos ) const
glyph_t glyphs[8];
advance_t advances[8];
int nglyphs = 7;
- engine->stringToCMap( &ch, 1, glyphs, advances, &nglyphs, FALSE );
+ engine->stringToCMap( &ch, isSurrogate ? 2 : 1, glyphs, advances, &nglyphs, FALSE );
width = advances[0];
}
- if ( ch.unicode() < TQFontEngineData::widthCacheSize && width > 0 && width < 0x100 )
- d->engineData->widthCache[ ch.unicode() ] = width;
+ if ( uc < TQFontEngineData::widthCacheSize && width > 0 && width < 0x100 )
+ d->engineData->widthCache[ uc ] = width;
return width;
}