summaryrefslogtreecommitdiffstats
path: root/src/kernel/tqfont_x11.cpp
diff options
context:
space:
mode:
authorMichele Calgaro <[email protected]>2025-02-04 17:59:57 +0900
committerMichele Calgaro <[email protected]>2025-02-09 19:21:03 +0900
commit486aa07930e7b6e900f77e64726c8cc4110511d8 (patch)
tree8b8d515be0f9d860bd46d778977b6beab732120d /src/kernel/tqfont_x11.cpp
parent46f42bcd5a6e2ad99fe842432279e529adce890a (diff)
downloadtqt3-486aa07930e7b6e900f77e64726c8cc4110511d8.tar.gz
tqt3-486aa07930e7b6e900f77e64726c8cc4110511d8.zip
Extend work on supporting surrogate characters done in commit e0a38072
Signed-off-by: Michele Calgaro <[email protected]>
Diffstat (limited to 'src/kernel/tqfont_x11.cpp')
-rw-r--r--src/kernel/tqfont_x11.cpp32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/kernel/tqfont_x11.cpp b/src/kernel/tqfont_x11.cpp
index 6f4097029..92cd8b113 100644
--- a/src/kernel/tqfont_x11.cpp
+++ b/src/kernel/tqfont_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;
}