- prnt() now handles accents and spanish characters correctly

This commit is contained in:
2022-10-26 16:28:52 +02:00
parent 5ebd02ae66
commit a029771b07
2 changed files with 49 additions and 1 deletions

View File

@@ -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<size_in_bytes;++i) if (str[i] != 194 && str[i] != 195) size_in_utfchars++;
return size_in_utfchars;
}
int rnd(int x) {
return rand()%x;
}

2
mini.h
View File

@@ -222,6 +222,8 @@ float max(float x, float y);
float mid(float x, float y, float z);
float min(float x, float y);
int utfstrlen(const char *str);
int rnd(int x);
//void srand(int x);