summaryrefslogtreecommitdiffstats
path: root/src/kernel
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2025-01-29 18:05:37 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2025-01-30 19:06:32 +0900
commitb64537250370dd61e3d8ba037679bddbc0f79d61 (patch)
tree9531e2d2fb79945ae821a2805079b93697e54734 /src/kernel
parentc919740e87c71232b3d2d1335efb2c4c293ff80c (diff)
downloadtqt-b64537250370dd61e3d8ba037679bddbc0f79d61.tar.gz
tqt-b64537250370dd61e3d8ba037679bddbc0f79d61.zip
Add support for surrogate pairs to TQChar API.
This relates to issue #162. The new code is partially taken from Qt4 but with some local rework. Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it> (cherry picked from commit c5cda03125a6d34c179d968011083bceb87976bd)
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/qfontengine_x11.cpp17
-rw-r--r--src/kernel/qtextengine.cpp3
2 files changed, 9 insertions, 11 deletions
diff --git a/src/kernel/qfontengine_x11.cpp b/src/kernel/qfontengine_x11.cpp
index 539b14aed..084b830ba 100644
--- a/src/kernel/qfontengine_x11.cpp
+++ b/src/kernel/qfontengine_x11.cpp
@@ -1531,16 +1531,15 @@ static glyph_t getAdobeCharIndex(XftFont *font, int cmap, uint ucs4)
return g;
}
-static uint getChar(const TQChar *str, int &i, const int len)
+static uint getUnicode(const TQChar *str, int &i, const int len)
{
- uint uc = str[i].unicode();
- if (uc >= 0xd800 && uc < 0xdc00 && i < len-1) {
- uint low = str[++i].unicode();
- if (low >= 0xdc00 && low < 0xe000) {
- uc = (uc - 0xd800)*0x400 + (low - 0xdc00) + 0x10000;
- }
+ if (str[i].isHighSurrogate() && i < (len - 1) && str[i + 1].isLowSurrogate())
+ {
+ ++i; // Don't delete this: it is required for correct
+ // advancement when handling surrogate pairs
+ return TQChar::surrogateToUcs4(str[i - 1], str[i]);
}
- return uc;
+ return str[i].unicode();
}
TQFontEngine::Error TQFontEngineXft::stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const
@@ -1552,7 +1551,7 @@ TQFontEngine::Error TQFontEngineXft::stringToCMap( const TQChar *str, int len, g
int glyph_pos = 0;
for ( int i = 0; i < len; ++i ) {
- uint uc = getChar(str, i, len);
+ uint uc = getUnicode(str, i, len);
if ( uc == 0xa0 )
uc = 0x20;
if ( mirrored )
diff --git a/src/kernel/qtextengine.cpp b/src/kernel/qtextengine.cpp
index f527cd86a..7ada261e9 100644
--- a/src/kernel/qtextengine.cpp
+++ b/src/kernel/qtextengine.cpp
@@ -819,8 +819,7 @@ static void calcLineBreaks(const TQString &str, TQCharAttributes *charAttributes
if (category == TQChar::Other_Surrogate) {
// char stop only on first pair
- if (uc[i].unicode() >= 0xd800 && uc[i].unicode() < 0xdc00 && i < len-1
- && uc[i+1].unicode() >= 0xdc00 && uc[i+1].unicode() < 0xe000)
+ if (uc[i].isHighSurrogate() && i < (len - 1) && uc[i + 1].isLowSurrogate())
goto nsm;
// ### correctly handle second surrogate
}