src/font.c

changeset 65
9c44c55d327a
parent 48
6e5b5ba2752c
child 66
8297afa1c29c
     1.1 --- a/src/font.c	Thu Apr 18 21:53:53 2024 +0200
     1.2 +++ b/src/font.c	Thu Apr 18 22:53:55 2024 +0200
     1.3 @@ -43,17 +43,19 @@
     1.4      }
     1.5  }
     1.6  
     1.7 -AscFont const *asc_font(enum AscFontStyle style, int size) {
     1.8 +void asc_font(enum AscFontStyle style, int size) {
     1.9      for (unsigned int i = 0 ; i < asc_context.fonts_loaded ; i++) {
    1.10          AscFont *font = &asc_context.fonts[i];
    1.11          if (font->size == size && font->style == style) {
    1.12 -            return font;
    1.13 +            asc_context.active_font = i;
    1.14 +            return;
    1.15          }
    1.16      }
    1.17  
    1.18      if (asc_context.fonts_loaded == ASC_MAX_FONTS) {
    1.19 -        asc_dprintf("WARNING: Maximum number of fonts reached, wiping cache!");
    1.20 -        asc_font_cache_clear();
    1.21 +        asc_error("Too many fonts. Cannot load more until cache is repaired.");
    1.22 +        asc_context.active_font = ASC_MAX_FONTS;
    1.23 +        return;
    1.24      }
    1.25  
    1.26      unsigned int slot = asc_context.fonts_loaded++;
    1.27 @@ -64,27 +66,8 @@
    1.28      if (font->ptr == NULL) {
    1.29          asc_context.fonts_loaded--;
    1.30          asc_error(TTF_GetError());
    1.31 -        return NULL;
    1.32 -    }
    1.33 -    asc_dprintf("Loaded font size %u, style %u in slot %u", size, style, slot);
    1.34 -    return font;
    1.35 -}
    1.36 -
    1.37 -void asc_font_cache_clear(void) {
    1.38 -    asc_dprintf("Fonts in cache that are being unloaded: %u", asc_context.fonts_loaded);
    1.39 -    while (asc_context.fonts_loaded > 0) {
    1.40 -        unsigned int i = --asc_context.fonts_loaded;
    1.41 -        AscFont *font = &asc_context.fonts[i];
    1.42 -        TTF_CloseFont(font->ptr);
    1.43 -        font->ptr = NULL;
    1.44 +    } else {
    1.45 +        asc_dprintf("Loaded font size %u, style %u in slot %u", size, style, slot);
    1.46 +        asc_context.active_font = slot;
    1.47      }
    1.48  }
    1.49 -
    1.50 -AscFont const *asc_font_cache_validate(AscFont const *font) {
    1.51 -    if (font->ptr) {
    1.52 -        return font;
    1.53 -    } else {
    1.54 -        asc_dprintf("Cache miss for font size %u, style %u", font->size, font->style);
    1.55 -        return asc_font(font->style, font->size);
    1.56 -    }
    1.57 -}

mercurial