A simple implementation of wcwidth(3) in C as a port of wcwidth.py.
Used in Termux as part of the libandroid-support.so
shared library.
A Unicode 15-conformant implementation of wcwidth() in C.
License: Other
A simple implementation of wcwidth(3) in C as a port of wcwidth.py.
Used in Termux as part of the libandroid-support.so
shared library.
It would be my first contribution to a project which is not my own. So, no clue how to do.
I've forked the project: https://github.com/PitWD/termux_wcwidth
The changes are made inside the wcwidth() function. And I added two functions to test_wcwidth.c for a simple time measurement.
Please check the changes and if you are fine with them, I would love to get a little introduction how to prepare them for a regular commit.
1st edit:
~10% faster. Binary size is a little smaller, RAM usage the same.
2nd edit:
Even RAM usage is a little smaller...
I am looking into rxvt-unicode's handling of wide characters once again, and
found the following:
The NerdFileTypes font for example seems to use private use codepoints:
E.g. 0xe612 (๎) is defined as:
StartChar: uniE612
Encoding: 58898 58898 924
Width: 2592
GlyphClass: 2
Flags: MW
According to https://codepoints.net/U+e612 this is "U+E612 PRIVATE USE CODEPOINT", with Ambiguous East Asian Width, where http://unicode.org/reports/tr11/#Ambiguous says
Private-use character codes and the replacement character have
ambiguous width, because they may stand in for characters of any width.
This could be interpreted as "let the font decide", and therefore I've looked
into using the following method in rxvt-unicode to ask the font for the actual
width:
int rxvt_font_xft::get_wcwidth (unicode_t unicode)
{
FcChar32 ch = unicode;
XGlyphInfo g;
XftTextExtents32 (term->dpy, f, &ch, 1, &g);
int w = g.width - g.x;
// int wcw = max (WCWIDTH (unicode), 1);
int r = (w + term->fwidth - 1) / term->fwidth;
printf("get_wcwidth: fwidth=%d, g.width=%d-g.x=%d => w=%d, xOff=%d => %d\n", term->fwidth, g.width, g.x, w, g.xOff, r);
r = (g.xOff + term->fwidth - 1 - term->fwidth/2) / term->fwidth;
return r;
}
Using this in rxvt_term::scr_add_lines then:
int width = WCWIDTH (c);
rxvt_fontset *fs = FONTSET (rstyle);
rxvt_font *f = (*fs)[fs->find_font_idx (c)];
int wcwidth = f->get_wcwidth(c);
printf("c: %c, f: %d, width=%d, wcwidth=%d\n", c, f, width, wcwidth);
width = wcwidth;
While this method works well for rxvt-unicode (but is slow, of course), it does not play well with the shell/programs being used therein (just like some custom wcwidth implementation).
Therefore this would need to be provided through wcwidth
itself.
Do you think it would be feasible to add support for something like this to this library/project?
I could imagine this being opt-in, e.g. through defining some environment variable (containing a list of fonts, since for rxvt-unicode only a defined list would be used).
Also this would need to have some caching in place then probably.
The obvious workaround is to patch (this) wcwidth
to just return what you expect, which works well already.
Hello, I'd like to use this project in QTerminal, the terminal emulator for LXQT. (lxqt/qtermwidget#94) What's the license of wcwidth.c
? Is it also MIT, like wcwidth.py?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.