diff --git a/basegraph.cpp b/basegraph.cpp index 54bbe7d1..41e1003f 100644 --- a/basegraph.cpp +++ b/basegraph.cpp @@ -132,25 +132,17 @@ bool eqs(const char* x, const char* y) { return *y? *x==*y?eqs(x+1,y+1):false:true; } -EX int getnext(const char* s, int& i) { +EX int getnext(const string& s, int& i) { int siz = utfsize(s[i]); // if(fontdeb) printf("s=%s i=%d siz=%d\n", s, i, siz); if(siz == 1) return s[i++]; for(int k=0; k chars; + vector reps; }; #endif @@ -582,6 +575,7 @@ EX void init_glfont(int size) { glfont_t& f(*(cfont->glfont[size])); f.chars.resize(CHARS); + f.reps.resize(CHARS, nullptr); //f.list_base = glGenLists(128); glGenTextures(1, &f.texture ); @@ -630,6 +624,22 @@ EX void init_glfont(int size) { sdltogl(txt, f, ch); SDL_DestroySurface(txt); #endif + + if(ch >= 128 && !TTF_GlyphIsProvided(cfont->font[siz], unicode_value(natchars[ch-128], 0).first)) { + string s = natchars[ch - 128]; + if(s == "Ⓐ") f.reps[ch] = "(A)"; + if(s == "Ⓑ") f.reps[ch] = "(B)"; + if(s == "Ⓧ") f.reps[ch] = "(X)"; + if(s == "Ⓨ") f.reps[ch] = "(Y)"; + if(s == "Ⓛ") f.reps[ch] = "(L)"; + if(s == "Ⓡ") f.reps[ch] = "(R)"; + if(s == "Ⓡ") f.reps[ch] = "(R)"; + + for(int j=0; j vid.fsize || size > max_glfont_size) gsiz = max_glfont_size; @@ -702,8 +712,14 @@ bool gl_print(int x, int y, int shift, int size, const char *s, color_t color, i int tsize = 0; + const char *replacement = ""; int replacement_i = 0; + for(int i=0; s[i];) { - tsize += f.chars[getnext(s,i)].w * size/gsiz; + + int tabid = replacement[replacement_i] ? getnext(replacement, replacement_i) : getnext(s,i); + if(f.reps[tabid]) { replacement = f.reps[tabid]; replacement_i = 0; continue; } + + tsize += f.chars[tabid].w * size/gsiz; } x -= tsize * align / 16; y += f.chars[32].h * size / (gsiz*2); @@ -727,7 +743,8 @@ bool gl_print(int x, int y, int shift, int size, const char *s, color_t color, i for(int i=0; s[i];) { - int tabid = getnext(s,i); + int tabid = replacement[replacement_i] ? getnext(replacement, replacement_i) : getnext(s,i); + if(f.reps[tabid]) { replacement = f.reps[tabid]; replacement_i = 0; continue; } auto& c = f.chars[tabid]; int wi = c.w * size/gsiz; int hi = c.h * size/gsiz; @@ -798,6 +815,25 @@ EX void resetGL() { #endif +EX pair unicode_value(const string& s, int i) { + unsigned char uch = (unsigned char) s[i]; + if(uch >= 192 && uch < 224) { + int u = ((s[i] - 192)&31) << 6; + i++; + u += (s[i] - 128) & 63; + return {u, i}; + } + else if(uch >= 224 && uch < 240) { + int u = ((s[i] - 224)&15) << 12; + i++; + u += (s[i] & 63) << 6; + i++; + u += (s[i] & 63) << 0; + return {u, i}; + } + return {uch, i+1}; + } + #if CAP_XGD vector graphdata; @@ -816,27 +852,9 @@ EX bool displaychr(int x, int y, int shift, int size, char chr, color_t col) { void gdpush_utf8(const string& s) { int g = (int) graphdata.size(), q = 0; gdpush((int) s.size()); for(int i=0; i= 192 && uch < 224) { - int u = ((s[i] - 192)&31) << 6; - i++; - u += (s[i] - 128) & 63; - gdpush(u); q++; - } - else if(uch >= 224 && uch < 240) { - int u = ((s[i] - 224)&15) << 12; - i++; - u += (s[i] & 63) << 6; - i++; - u += (s[i] & 63) << 0; - gdpush(u); q++; - } - else -#endif - { - gdpush(s[i]); q++; - } + int u; + tie(u, i) = unicode_value(s, i); + gdpush(u); q++; } graphdata[g] = q; } diff --git a/dialogs.cpp b/dialogs.cpp index 33254a1f..6f0295a2 100644 --- a/dialogs.cpp +++ b/dialogs.cpp @@ -1925,8 +1925,8 @@ EX namespace dialog { EX string infix; - string foreign_letters = "ÁÄÇÈÉÍÎÖÚÜßàáâãäçèéêìíîïòóôõöøùúüýąćČčĎďĘęĚěğİıŁłńňŘřŚśŞşŠšŤťůŹźŻżŽž"; - string latin_letters = "AACEEIIOUUsAAAAACEEEIIIIOOOOOOUUUYACCCDDEEEEGIILLNNRRSSSSSSTTUZZZZZZ"; + EX string foreign_letters = "ÁÄÇÈÉÍÎÖÚÜßàáâãäçèéêìíîïòóôõöøùúüýąćČčĎďĘęĚěğİıŁłńňŘřŚśŞşŠšŤťůŹźŻżŽž"; + EX string latin_letters = "AACEEIIOUUsAAAAACEEEIIIIOOOOOOUUUYACCCDDEEEEGIILLNNRRSSSSSSTTUZZZZZZ"; EX string human_simplify(const string &s, bool include_symbols) { string t = ""; diff --git a/drawing.cpp b/drawing.cpp index f39e42b4..60ad8b74 100644 --- a/drawing.cpp +++ b/drawing.cpp @@ -2911,7 +2911,7 @@ EX void write_in_space(const shiftmatrix& V, int fsize, double size, const strin vector chars; int i = 0; - while(i < isize(s)) { chars.push_back(getnext(s.c_str(), i)); } + while(i < isize(s)) { chars.push_back(getnext(s, i)); } ld tw = 0; for(int c: chars) tw += f.chars[c].w; diff --git a/scores.cpp b/scores.cpp index 5a4a1efe..74be673a 100644 --- a/scores.cpp +++ b/scores.cpp @@ -20,7 +20,7 @@ int which_mode; string csub(const string& str, int q) { int i = 0; - for(int j=0; j