[BRLTTY] brltty 6.0 testing report

Nicolas Pitre nico at fluxnic.net
Fri Feb 8 20:23:46 EST 2019


On Fri, 8 Feb 2019, Dave Mielke wrote:

> [quoted lines by 高生旺 on 2019/02/05 at 12:06 +0800]
> 
> >There will be a blank space after each Chinese character.
> >And after copying and pasting, each character will have another space.
> 
> Could you please send me a file containing these characters? Also, is there a
> contraction subtable that I can include to define them?

Chinese characters are considered to be double width by the Linux vt 
code. Since the text console is assumed to be a fixed width display, the 
vt code inserts a space after the glyph representing a double-width 
character to span two columns.  The Unicode screen representation 
duplicated that behavior to preserve the 1:1 correspondance.

So Samuel's suggestion is probably right i.e. if wcwidth() > 1 and the 
following character is a space then drop that space.

Better yet, copy the code from the Linux vt code into BRLTTY's Linux 
screen driver so the behavior will match. That code is:

/* is_double_width() is based on the wcwidth() implementation by
 * Markus Kuhn -- 2007-05-26 (Unicode 5.0)
 * Latest version: http://www.cl.cam.ac.uk/‾mgk25/ucs/wcwidth.c
 */
struct interval {
	uint32_t first;
	uint32_t last;
};

static int ucs_cmp(const void *key, const void *elt)
{
	uint32_t ucs = *(uint32_t *)key;
	struct interval e = *(struct interval *) elt;

	if (ucs > e.last)
		return 1;
	else if (ucs < e.first)
		return -1;
	return 0;
}

static int is_double_width(uint32_t ucs)
{
	static const struct interval double_width[] = {
		{ 0x1100, 0x115F }, { 0x2329, 0x232A }, { 0x2E80, 0x303E },
		{ 0x3040, 0xA4CF }, { 0xAC00, 0xD7A3 }, { 0xF900, 0xFAFF },
		{ 0xFE10, 0xFE19 }, { 0xFE30, 0xFE6F }, { 0xFF00, 0xFF60 },
		{ 0xFFE0, 0xFFE6 }, { 0x20000, 0x2FFFD }, { 0x30000, 0x3FFFD }
	};
	if (ucs < double_width[0].first ||
	    ucs > double_width[ARRAY_SIZE(double_width) - 1].last)
		return 0;

	return bsearch(&ucs, double_width, ARRAY_SIZE(double_width),
			sizeof(struct interval), ucs_cmp) != NULL;
}


Nicolas


More information about the BRLTTY mailing list