diff --git a/default.fnt b/default.fnt new file mode 100644 index 0000000..daea21e --- /dev/null +++ b/default.fnt @@ -0,0 +1,130 @@ +bitmap=font.gif +32: 0 0 3 5 0 # +33: 4 0 3 5 0 # ! +34: 8 0 3 5 0 # " +35: 12 0 3 5 0 # # +36: 16 0 3 5 0 # $ +37: 20 0 3 5 0 # % +38: 24 0 3 5 0 # & +39: 28 0 3 5 0 # ' +40: 32 0 3 5 0 # ( +41: 36 0 3 5 0 # ) +42: 40 0 3 5 0 # * +43: 44 0 3 5 0 # + +44: 48 0 3 5 0 # , +45: 52 0 3 5 0 # - +46: 56 0 3 5 0 # . +47: 60 0 3 5 0 # / + +48: 0 6 3 5 0 # 0 +49: 4 6 3 5 0 # 1 +50: 8 6 3 5 0 # 2 +51: 12 6 3 5 0 # 3 +52: 16 6 3 5 0 # 4 +53: 20 6 3 5 0 # 5 +54: 24 6 3 5 0 # 6 +55: 28 6 3 5 0 # 7 +56: 32 6 3 5 0 # 8 +57: 36 6 3 5 0 # 9 +58: 40 6 3 5 0 # : +59: 44 6 3 5 0 # ; +60: 48 6 3 5 0 # < +61: 52 6 3 5 0 # = +62: 56 6 3 5 0 # > +63: 60 6 3 5 0 # ? + +64: 0 12 3 5 0 # @ +65: 4 12 3 5 0 # A +66: 8 12 3 5 0 # B +67: 12 12 3 5 0 # C +68: 16 12 3 5 0 # D +69: 20 12 3 5 0 # E +70: 24 12 3 5 0 # F +71: 28 12 3 5 0 # G +72: 32 12 3 5 0 # H +73: 36 12 3 5 0 # I +74: 40 12 3 5 0 # J +75: 44 12 3 5 0 # K +76: 48 12 3 5 0 # L +77: 52 12 3 5 0 # M +78: 56 12 3 5 0 # N +79: 60 12 3 5 0 # O + +80: 0 18 3 5 0 # P +81: 4 18 3 5 0 # Q +82: 8 18 3 5 0 # R +83: 12 18 3 5 0 # S +84: 16 18 3 5 0 # T +85: 20 18 3 5 0 # U +86: 24 18 3 5 0 # V +87: 28 18 3 5 0 # W +88: 32 18 3 5 0 # X +89: 36 18 3 5 0 # Y +90: 40 18 3 5 0 # Z +91: 44 18 3 5 0 # [ +92: 48 18 3 5 0 # \ +93: 52 18 3 5 0 # ] +94: 56 18 3 5 0 # ^ +95: 60 18 3 5 0 # _ + +96: 0 24 3 5 0 # ` +97: 4 24 3 5 0 # a +98: 8 24 3 5 0 # b +99: 12 24 3 5 0 # c +100: 16 24 3 5 0 # d +101: 20 24 3 5 0 # e +102: 24 24 3 5 0 # f +103: 28 24 3 5 0 # g +104: 32 24 3 5 0 # h +105: 36 24 3 5 0 # i +106: 40 24 3 5 0 # j +107: 44 24 3 5 0 # k +108: 48 24 3 5 0 # l +109: 52 24 3 5 0 # m +110: 56 24 3 5 0 # n +111: 60 24 3 5 0 # o + +112: 0 30 3 5 0 # p +113: 4 30 3 5 0 # q +114: 8 30 3 5 0 # r +115: 12 30 3 5 0 # s +116: 16 30 3 5 0 # t +117: 20 30 3 5 0 # u +118: 24 30 3 5 0 # v +119: 28 30 3 5 0 # w +120: 32 30 3 5 0 # x +121: 36 30 3 5 0 # y +122: 40 30 3 5 0 # z +123: 44 30 3 5 0 # { +124: 48 30 3 5 0 # | +125: 52 30 3 5 0 # } +126: 56 30 3 5 0 # ~ +127: 60 30 3 5 0 # ⌂ (DEL placeholder) + +# Extended characters +161: 0 36 3 5 0 # ¡ +191: 4 36 3 5 0 # ¿ +192: 8 36 3 8 3 # À +193: 12 36 3 8 3 # Á +200: 16 36 3 8 3 # È +201: 20 36 3 8 3 # É +204: 24 36 3 8 3 # Ì +205: 28 36 3 8 3 # Í +210: 32 36 3 8 3 # Ò +211: 36 36 3 8 3 # Ó +217: 40 36 3 8 3 # Ù +218: 44 36 3 8 3 # Ú +209: 48 36 3 7 2 # Ñ +241: 52 36 3 6 1 # ñ +199: 56 36 3 5 0 # Ç +231: 60 36 3 5 0 # ç +224: 0 45 3 7 2 # à +225: 4 45 3 7 2 # á +232: 8 45 3 7 2 # è +233: 12 45 3 7 2 # é +236: 16 45 3 7 2 # ì +237: 20 45 3 7 2 # í +242: 24 45 3 7 2 # ò +243: 28 45 3 7 2 # ó +249: 32 45 3 7 2 # ù +250: 36 45 3 7 2 # ú diff --git a/font.gif b/font.gif new file mode 100644 index 0000000..1f1766f Binary files /dev/null and b/font.gif differ diff --git a/mini.cpp b/mini.cpp index cd7b3ae..f68d722 100644 --- a/mini.cpp +++ b/mini.cpp @@ -10,6 +10,7 @@ #include "log.h" #define MAX_SURFACES 100 +#define MAX_FONTS 5 #ifdef MACOS_BUNDLE #include @@ -26,11 +27,14 @@ struct surface_t { uint32_t size; }; +struct char_t { + uint8_t x,y,w,h,base; +}; + struct font_t { - struct special_char_t { uint8_t character; SDL_Rect glyph; SDL_Point displacement; }; - int8_t spacing; - SDL_Rect characters[96]; - special_char_t specials[64]; + char *name {nullptr}; + uint8_t surface {0}; + char_t chars[256]; }; int fps=0; @@ -53,6 +57,7 @@ surface_t *dest_surface = screen_surface; surface_t *source_surface = NULL; surface_t *map_surface = NULL; +font_t fonts[MAX_FONTS]; FILE *file = NULL; //uint8_t file_mode = 0; bool file_ignore_comma=true; @@ -274,6 +279,20 @@ uint8_t newsurf(int w, int h) { return i; } +uint8_t loadsurf(uint8_t* buffer, const char* name) { + // Agafar la pròxima textura lliure + unsigned int i = 0; + while (i= 0 && code < 256) { + font.chars[code] = { (uint8_t)x, (uint8_t)y, (uint8_t)w, (uint8_t)h, (uint8_t)base }; + } + } + } + return true; +} + +static inline uint32_t utf8_decode(const char* s, int& advance) { + const unsigned char* p = (const unsigned char*)s; + uint32_t cp; + + if (p[0] < 0x80) { + cp = p[0]; + advance = 1; + } + else if ((p[0] & 0xE0) == 0xC0) { + cp = ((p[0] & 0x1F) << 6) | + (p[1] & 0x3F); + advance = 2; + } + else if ((p[0] & 0xF0) == 0xE0) { + cp = ((p[0] & 0x0F) << 12) | + ((p[1] & 0x3F) << 6) | + (p[2] & 0x3F); + advance = 3; + } + else if ((p[0] & 0xF8) == 0xF0) { + cp = ((p[0] & 0x07) << 18) | + ((p[1] & 0x3F) << 12) | + ((p[2] & 0x3F) << 6) | + (p[3] & 0x3F); + advance = 4; + } + else { + cp = 0xFFFD; // carácter inválido + advance = 1; + } + + return cp; +} + void simple_pset(int x, int y, uint8_t color) { x += ds::origin[0]; y += ds::origin[1]; if (x < ds::clip[0] || x > ds::clip[2] || y < ds::clip[1] || y > ds::clip[3]) return;