mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-10 01:29:05 -04:00
[EGCcore] property variation is 0 columns, as is ZWJ #2315
This commit is contained in:
parent
8872cf73ab
commit
8d08e14912
@ -9,8 +9,9 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unigbrk.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <unigbrk.h>
|
||||||
|
#include <unictype.h>
|
||||||
#include "notcurses/notcurses.h"
|
#include "notcurses/notcurses.h"
|
||||||
#include "compat/compat.h"
|
#include "compat/compat.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
@ -109,23 +110,34 @@ utf8_egc_len(const char* gcluster, int* colcount){
|
|||||||
if(prevw && !injoin && uc_is_grapheme_break(prevw, wc)){
|
if(prevw && !injoin && uc_is_grapheme_break(prevw, wc)){
|
||||||
break; // starts a new EGC, exit and do not claim
|
break; // starts a new EGC, exit and do not claim
|
||||||
}
|
}
|
||||||
|
if(uc_is_property_variation_selector(wc)){ // ends EGC
|
||||||
|
ret += r;
|
||||||
|
break;
|
||||||
|
}
|
||||||
int cols = wcwidth(wc);
|
int cols = wcwidth(wc);
|
||||||
if(cols < 0){
|
if(cols < 0){
|
||||||
|
injoin = false;
|
||||||
if(iswspace(wc)){ // newline or tab
|
if(iswspace(wc)){ // newline or tab
|
||||||
return ret + 1;
|
return ret + 1;
|
||||||
}
|
}
|
||||||
if(iswcntrl(wc)){
|
cols = 1;
|
||||||
|
if(wc == L'\u200d'){ // ZWJ is iswcntrl, so check it first
|
||||||
|
injoin = true;
|
||||||
|
cols = 0;
|
||||||
|
}else if(iswcntrl(wc)){
|
||||||
logerror("prohibited or invalid Unicode: 0x%x\n", wc);
|
logerror("prohibited or invalid Unicode: 0x%x\n", wc);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
cols = 1;
|
}else if(injoin){
|
||||||
|
cols = 0;
|
||||||
|
injoin = false;
|
||||||
}
|
}
|
||||||
injoin = (wc == L'\u200d');
|
|
||||||
*colcount += cols;
|
*colcount += cols;
|
||||||
ret += r;
|
ret += r;
|
||||||
gcluster += r;
|
gcluster += r;
|
||||||
prevw = wc;
|
prevw = wc;
|
||||||
}while(r);
|
}while(r);
|
||||||
|
// FIXME what if injoin is set? incomplete EGC!
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user