From 568e83e4f6f56f51c0105d1bd62659e2de2d52f0 Mon Sep 17 00:00:00 2001 From: nick black Date: Sat, 6 Feb 2021 21:36:41 -0500 Subject: [PATCH] blitting: place utf8 in tcache #1334 --- src/lib/blit.c | 6 +++--- src/lib/blitset.h | 16 +++++++--------- src/lib/direct.cpp | 6 +++--- src/lib/internal.h | 3 +-- src/lib/notcurses.c | 10 ++++++---- src/lib/plot.h | 4 ++-- src/lib/visual.cpp | 3 +-- 7 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/lib/blit.c b/src/lib/blit.c index 8cca19617..d99494315 100644 --- a/src/lib/blit.c +++ b/src/lib/blit.c @@ -902,8 +902,8 @@ int ncblit_rgba(const void* data, int linesize, const struct ncvisual_options* v blitter = vopts->blitter; } const bool degrade = !(vopts->flags & NCVISUAL_OPTION_NODEGRADE); - const struct blitset* bset = lookup_blitset(notcurses_canutf8(ncplane_notcurses(nc)), - blitter, degrade); + const notcurses* notc = ncplane_notcurses(nc); + const struct blitset* bset = lookup_blitset(¬c->tcache, blitter, degrade); if(bset == NULL){ return -1; } @@ -913,5 +913,5 @@ int ncblit_rgba(const void* data, int linesize, const struct ncvisual_options* v } ncblitter_e ncvisual_media_defblitter(const notcurses* nc, ncscale_e scale){ - return rgba_blitter_default(nc->utf8, scale, nc->tcache.sextants); + return rgba_blitter_default(nc->tcache.utf8, scale, nc->tcache.sextants); } diff --git a/src/lib/blitset.h b/src/lib/blitset.h index a2bd0ce07..fc64344b9 100644 --- a/src/lib/blitset.h +++ b/src/lib/blitset.h @@ -4,12 +4,12 @@ #include "notcurses/notcurses.h" static inline const struct blitset* -lookup_blitset(unsigned utf8, ncblitter_e setid, bool may_degrade) { +lookup_blitset(const tinfo* tcache, ncblitter_e setid, bool may_degrade) { if(setid == NCBLIT_DEFAULT){ // ought have resolved NCBLIT_DEFAULT before now return NULL; } // the only viable blitter in ASCII is NCBLIT_1x1 - if(!utf8 && setid != NCBLIT_1x1){ + if(!tcache->utf8 && setid != NCBLIT_1x1){ if(may_degrade){ setid = NCBLIT_1x1; }else{ @@ -54,14 +54,12 @@ rgba_blitter_default(bool utf8, ncscale_e scale, bool sextants){ } static inline const struct blitset* -rgba_blitter_low(bool utf8, bool sextants, ncscale_e scale, bool maydegrade, +rgba_blitter_low(const tinfo* tcache, bool sextants, ncscale_e scale, bool maydegrade, ncblitter_e blitrec) { - const struct blitset* bset; - if(blitrec != NCBLIT_DEFAULT){ - bset = lookup_blitset(utf8, blitrec, maydegrade); - }else{ - bset = lookup_blitset(utf8, rgba_blitter_default(utf8, scale, sextants), maydegrade); + if(blitrec == NCBLIT_DEFAULT){ + blitrec = rgba_blitter_default(tcache->utf8, scale, sextants); } + const struct blitset* bset = lookup_blitset(tcache, blitrec, maydegrade); if(bset && !bset->blit){ // FIXME remove this once all blitters are enabled bset = NULL; } @@ -74,7 +72,7 @@ static inline const struct blitset* rgba_blitter(const struct notcurses* nc, const struct ncvisual_options* opts) { const bool maydegrade = !(opts && (opts->flags & NCVISUAL_OPTION_NODEGRADE)); const ncscale_e scale = opts ? opts->scaling : NCSCALE_NONE; - return rgba_blitter_low(notcurses_canutf8(nc), notcurses_cansextant(nc), + return rgba_blitter_low(&nc->tcache, notcurses_cansextant(nc), scale, maydegrade, opts ? opts->blitter : NCBLIT_DEFAULT); } diff --git a/src/lib/direct.cpp b/src/lib/direct.cpp index 8c18ff2bd..3c89608d2 100644 --- a/src/lib/direct.cpp +++ b/src/lib/direct.cpp @@ -485,7 +485,7 @@ ncdirectv* ncdirect_render_frame(ncdirect* n, const char* file, return nullptr; } //fprintf(stderr, "render %d/%d to %d+%d scaling: %d\n", ncv->rows, ncv->cols, leny, lenx, scale); - auto bset = rgba_blitter_low(n->utf8, n->tcache.sextants, scale, true, blitter); + auto bset = rgba_blitter_low(&n->tcache, n->tcache.sextants, scale, true, blitter); if(!bset){ ncvisual_destroy(ncv); return nullptr; @@ -638,7 +638,7 @@ ncdirect* ncdirect_core_init(const char* termtype, FILE* outfp, uint64_t flags){ } const char* encoding = nl_langinfo(CODESET); if(encoding && strcmp(encoding, "UTF-8") == 0){ - ret->utf8 = true; + ret->tcache.utf8 = true; } if(setup_signals(ret, (flags & NCDIRECT_OPTION_NO_QUIT_SIGHANDLERS), true, ncdirect_stop_minimal)){ @@ -1066,7 +1066,7 @@ bool ncdirect_canopen_images(const ncdirect* n __attribute__ ((unused))){ // Is our encoding UTF-8? Requires LANG being set to a UTF8 locale. bool ncdirect_canutf8(const ncdirect* n){ - return n->utf8; + return n->tcache.utf8; } int ncdirect_flush(const ncdirect* nc){ diff --git a/src/lib/internal.h b/src/lib/internal.h index 3f2fd5950..52157b276 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -268,6 +268,7 @@ typedef struct tinfo { bool CCCflag; // "CCC" flag for palette set capability bool BCEflag; // "BCE" flag for erases with background color bool AMflag; // "AM" flag for automatic movement to next line + bool utf8; // are we using utf-8 encoding, as hoped? char* smcup; // enter alternate mode char* rmcup; // restore primary mode @@ -304,7 +305,6 @@ typedef struct ncdirect { uint64_t channels; // current channels uint16_t stylemask; // current styles ncinputlayer input; // input layer; we're in cbreak mode - bool utf8; // are we using utf-8 encoding, as hoped? struct termios tpreserved; // terminal state upon entry // some terminals (e.g. kmscon) return cursor coordinates inverted from the // typical order. we detect it the first time ncdirect_cursor_yx() is called. @@ -360,7 +360,6 @@ typedef struct notcurses { int loglevel; palette256 palette; // 256-indexed palette can be used instead of/with RGB bool palette_damage[NCPALETTESIZE]; - bool utf8; // are we using utf-8 encoding, as hoped? bool libsixel; // do we have Sixel support? } notcurses; diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 9f65fd4fd..49152e73e 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -945,10 +945,11 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){ init_lang(ret); } const char* encoding = nl_langinfo(CODESET); + bool utf8; if(encoding && !strcmp(encoding, "UTF-8")){ - ret->utf8 = true; + utf8 = true; }else if(encoding && (!strcmp(encoding, "ANSI_X3.4-1968") || !strcmp(encoding, "US-ASCII"))){ - ret->utf8 = false; + utf8 = false; }else{ fprintf(stderr, "Encoding (\"%s\") was neither ANSI_X3.4-1968 nor UTF-8, refusing to start\n Did you call setlocale()?\n", encoding ? encoding : "none found"); @@ -1028,6 +1029,7 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){ if(interrogate_terminfo(&ret->tcache, shortname_term)){ goto err; } + ret->tcache.utf8 = utf8; warn_terminfo(ret, &ret->tcache); reset_term_attributes(ret); if(ncinputlayer_init(&ret->input, stdin)){ @@ -2044,11 +2046,11 @@ int notcurses_mouse_disable(notcurses* n){ } bool notcurses_canutf8(const notcurses* nc){ - return nc->utf8; + return nc->tcache.utf8; } bool notcurses_cansextant(const notcurses* nc){ - return nc->tcache.sextants && nc->utf8; + return nc->tcache.sextants && nc->tcache.utf8; } bool notcurses_canfade(const notcurses* nc){ diff --git a/src/lib/plot.h b/src/lib/plot.h index 57f97a057..2f7f0ef00 100644 --- a/src/lib/plot.h +++ b/src/lib/plot.h @@ -42,6 +42,7 @@ class ncppplot { ncplane_destroy(n); return false; } + const notcurses* notc = ncplane_notcurses(n); ncblitter_e blitter = opts ? opts->gridtype : NCBLIT_DEFAULT; if(blitter == NCBLIT_DEFAULT){ if(notcurses_canutf8(ncplane_notcurses(n))){ @@ -51,8 +52,7 @@ class ncppplot { } } bool degrade_blitter = !(opts && (opts->flags & NCPLOT_OPTION_NODEGRADE)); - auto bset = lookup_blitset(notcurses_canutf8(ncplane_notcurses(n)), - blitter, degrade_blitter); + auto bset = lookup_blitset(¬c->tcache, blitter, degrade_blitter); if(bset == nullptr){ ncplane_destroy(n); return false; diff --git a/src/lib/visual.cpp b/src/lib/visual.cpp index 1815d746e..a93286e40 100644 --- a/src/lib/visual.cpp +++ b/src/lib/visual.cpp @@ -79,8 +79,7 @@ auto ncvisual_geom(const notcurses* nc, const ncvisual* n, blitter = vopts->blitter; } const bool maydegrade = !(vopts && (vopts->flags & NCVISUAL_OPTION_NODEGRADE)); - const struct blitset* bset = lookup_blitset(notcurses_canutf8(nc), - blitter, maydegrade); + const struct blitset* bset = lookup_blitset(&nc->tcache, blitter, maydegrade); if(!bset){ return -1; }