From a029771b07c488ee16cb1bf591656f3241564ee1 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Wed, 26 Oct 2022 16:28:52 +0200 Subject: [PATCH] - prnt() now handles accents and spanish characters correctly --- mini.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++++- mini.h | 2 ++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/mini.cpp b/mini.cpp index 0960c24..d12c20d 100644 --- a/mini.cpp +++ b/mini.cpp @@ -499,6 +499,18 @@ void fillp(uint16_t pat, bool transparent) { ds::fill_pattern = pat; } +void print_symbol(char sym, int x, int y) { + switch(sym) { + case 1: pset(x, y-3); pset(x+1, y-2); break; + case 2: pset(x+1, y-2); pset(x+2, y-3); break; + case 3: pset(x+1, y+5); break; + case 4: pset(x, y-2); pset(x+1, y-2); pset(x+2, y-2); break; + case 5: pset(x, y-2); pset(x+1, y-1); break; + case 6: pset(x+1, y-1); pset(x+2, y-2); break; + case 7: pset(x, y-1); pset(x+1, y-1); pset(x+2, y-1); break; + } +} + void print_char(char chr, int x, int y) { int xi = 0, yi = 0; uint16_t val = 1; @@ -509,8 +521,35 @@ void print_char(char chr, int x, int y) { } } +void print_char_hv(char chr, int x, int y) { + int xi = 0, yi = 0; + uint16_t val = 1; + while(1) { + if (font[chr-32] & val) pset(x+(2-xi), y+(4-yi)); + if (xi<2) xi++; else { if (yi==4) return; else { xi=0; yi++; } } + val <<= 1; + } +} + +const char t195_char[]={65,65,0,0,0,0,0,67,69,69,0,0,73,73,0,0,0,78,79,79,0,0,0,0,0,85,85,0,0,0,0,0,97,97,0,0,0,0,0,99,101,101,0,0,105,105,0,0,0,110,111,111,0,0,0,0,0,117,117,0,0,0,0,0}; +const char t195_symbol[]={1,2,0,0,0,0,0,3,1,2,0,0,1,2,0,0,0,4,1,2,0,0,0,0,0,1,2,0,0,0,0,0,5,6,0,0,0,0,0,3,5,6,0,0,5,6,0,0,0,7,5,6,0,0,0,0,0,5,6,0,0,0,0,0}; + void print(const char *str, int x, int y) { - for (int i=0; i < SDL_strlen(str); ++i) print_char(str[i], x+i*4, y); + int pos=0; + for (int i=0; i < SDL_strlen(str); ++i) { + if ((unsigned char)str[i]==194) { + i++; + if ((unsigned char)str[i]==161) print_char_hv('!', x+pos*4, y); + else if ((unsigned char)str[i]==191) print_char_hv('?', x+pos*4, y); + } else if ((unsigned char)str[i]==195) { + i++; + print_char(t195_char[(unsigned char)str[i]-128], x+pos*4, y); + print_symbol(t195_symbol[(unsigned char)str[i]-128], x+pos*4, y); + } else { + print_char(str[i], x+pos*4, y); + } + pos++; + } } void print(const char *str, int x, int y, uint8_t color) { ds::pen_color=color; @@ -867,6 +906,13 @@ float min(float x, float y) { return SDL_min(x, y); } +int utfstrlen(const char *str) { + const int size_in_bytes = SDL_strlen(str); + int size_in_utfchars = 0; + for (int i=0;i