void Graphics::textnpos(char *s, int n, int w, int *cx, int *cy) { int x = 0; int y = 0; int wordlen, charspace; while (*s&&n) { wordlen = strcspn(s," .,!?\n"); charspace = textwidthx(s, w-x); if (charspace<wordlen && wordlen && w-x<w/3) { x = 0; y += FONT_H+2; } for (; *s && --wordlen>=-1; s++) { if (!n) { break; } x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; if (x>=w) { x = 0; y += FONT_H+2; } n--; } } *cx = x-1; *cy = y; }
int Graphics::textposxy(char *s, int width, int w, int h) { int x=0,y=0,n=0,cw, wordlen, charspace; while (*s) { wordlen = strcspn(s," .,!?\n"); charspace = textwidthx(s, width-x); if (charspace<wordlen && wordlen && width-x<width/3) { x = 0; y += FONT_H+2; } for (; *s && --wordlen>=-1; s++) { cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; if ((x+(cw/2) >= w && y+6 >= h)||(y+6 >= h+FONT_H+2)) return n++; x += cw; if (x>=width) { x = 0; y += FONT_H+2; } n++; } } return n; }
void clean_text(char *text, int vwidth) { int i = 0; if(textwidth(text) > vwidth) { text[textwidthx(text, vwidth)] = 0; } for(i = 0; i < strlen(text); i++) { if(! (text[i]>=' ' && text[i]<127)) { text[i] = ' '; } } }
int Graphics::textwrapheight(char *s, int width) { int x=0, height=FONT_H+2, cw; int wordlen; int charspace; while (*s) { wordlen = strcspn(s," .,!?\n"); charspace = textwidthx(s, width-x); if (charspace<wordlen && wordlen && width-x<width/3) { x = 0; height += FONT_H+2; } for (; *s && --wordlen>=-1; s++) { if (*s == '\n') { x = 0; height += FONT_H+2; } else if (*s == '\b') { if(!s[1]) break; s++; } else if (*s == '\x0F') { if(!s[1] || !s[2] || !s[3]) break; s+=3; } else { cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]]; if (x+cw>=width) { x = 0; height += FONT_H+2; } x += cw; } } } return height; }