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:16 +0900
commitc5cda03125a6d34c179d968011083bceb87976bd (patch)
tree33c2ba873b23cf503ed3c3aa1c52d3fac1006245 /src/kernel
parentd517cda6bdb0160be39a96712d4cf6036b920be3 (diff)
downloadtqt-c5cda03125a6d34c179d968011083bceb87976bd.tar.gz
tqt-c5cda03125a6d34c179d968011083bceb87976bd.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>
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/tqfontengine_x11.cpp17
-rw-r--r--src/kernel/tqtextengine.cpp3
2 files changed, 9 insertions, 11 deletions
diff --git a/src/kernel/tqfontengine_x11.cpp b/src/kernel/tqfontengine_x11.cpp
index b3461a6ff..47078dea9 100644
--- a/src/kernel/tqfontengine_x11.cpp
+++ b/src/kernel/tqfontengine_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/tqtextengine.cpp b/src/kernel/tqtextengine.cpp
index f50d849cc..05cdbcc13 100644
--- a/src/kernel/tqtextengine.cpp
+++ b/src/kernel/tqtextengine.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
}