kopia lustrzana https://github.com/jamescoxon/dl-fldigi
UTF-8 wide characters
* Fix put_echo_char() to handle UTF-8 characters wider than two bytes * Reimplement Fl_Text_Buffer_mod::get_char_at() to handle UTF-8 chars wider than two bytespull/1/head
rodzic
1b8cccdbbd
commit
1abb9b9b69
|
@ -6364,9 +6364,14 @@ void put_echo_char(unsigned int data, int style)
|
||||||
if (asc != NULL) { // MAIL / ARQ / RTTY / CW
|
if (asc != NULL) { // MAIL / ARQ / RTTY / CW
|
||||||
sch.assign(asc[data & 0xFF]);
|
sch.assign(asc[data & 0xFF]);
|
||||||
} else if (data & 0x8000) { //UTF-8 extended character
|
} else if (data & 0x8000) { //UTF-8 extended character
|
||||||
sch.assign(" ");
|
unsigned int shiftdata = data;
|
||||||
sch[0] = (data >> 8) & 0xFF;
|
while (!(shiftdata & 0xff000000))
|
||||||
sch[1] = (data & 0xFF);
|
shiftdata <<= 8;
|
||||||
|
unsigned char c;
|
||||||
|
while ((c = (shiftdata >> 24) & 0xff)) {
|
||||||
|
sch += c;
|
||||||
|
shiftdata <<= 8;
|
||||||
|
}
|
||||||
} else { // keyboard character including MSB set chars
|
} else { // keyboard character including MSB set chars
|
||||||
sch.assign(" ");
|
sch.assign(" ");
|
||||||
sch[0] = data;
|
sch[0] = data;
|
||||||
|
|
|
@ -258,28 +258,29 @@ unsigned int Fl_Text_Buffer_mod::char_at(int pos) const {
|
||||||
Return a UTF-8 character at the given index.
|
Return a UTF-8 character at the given index.
|
||||||
Pos must be at a character boundary.
|
Pos must be at a character boundary.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned int Fl_Text_Buffer_mod::get_char_at(int pos, int &len) const {
|
unsigned int Fl_Text_Buffer_mod::get_char_at(int pos, int &len) const {
|
||||||
if (pos < 0 || pos >= mLength) {
|
if (pos < 0 || pos >= mLength)
|
||||||
len = 1;
|
return '\0';
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
IS_UTF8_ALIGNED2(this, (pos))
|
IS_UTF8_ALIGNED2(this, (pos))
|
||||||
|
|
||||||
const char *src = address(pos);
|
const char *src = address(pos);
|
||||||
unsigned int code;
|
unsigned int code = 0;
|
||||||
int codelen;
|
|
||||||
if (*src & 0x80) { // what should be a multibyte encoding
|
if (*src & 0x80) {
|
||||||
fl_utf8decode(src, src+2, &codelen);
|
fl_utf8decode(src, 0, &len);
|
||||||
if (codelen == 2)
|
|
||||||
code = (*src << 8) | (*(src+1) & 0xFF);
|
for (int i = 0; i < len && i < 4; i++) {
|
||||||
else
|
code <<= 8;
|
||||||
code = *src & 0xFF;
|
code |= (unsigned char)*(src + i) & 0xFF;
|
||||||
} else { // handle the 1-byte utf8 encoding:
|
|
||||||
code = (*src & 0xFF);
|
|
||||||
codelen = 1;
|
|
||||||
}
|
}
|
||||||
len = codelen;
|
}
|
||||||
|
else {
|
||||||
|
code = *src;
|
||||||
|
len = 1;
|
||||||
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue