grimfang4 / SDL_FontCache

A generic font caching C library with loading and rendering support for SDL.
MIT License
305 stars 66 forks source link

Fixes gcc wnarrowing spam (issue #38) #39

Open SnapperTT opened 5 years ago

SnapperTT commented 5 years ago

Adds a number of int casts to take out gcc -wnarrowing spam

grimfang4 commented 5 years ago

Sorry I didn't think about this earlier, but this library compiles slightly differently for SDL and SDL_gpu. SDL uses a rect structure that stores integers, while SDL_gpu uses one that stores floats. SDL_FontCache uses a #define to make FC_Rect match the rect used by the appropriate rendering system. The solution here should depend on which system is being used so the floating point precision is preserved for SDL_gpu instead of always truncating to int.

SnapperTT commented 5 years ago

This could be fixed by having:

#ifdef SDL_gpu (or other)
   #define FC_COORD float
#else
   #define FC_COORD int
#endif

And replacing all (int) casts with (FC_COORD) casts. Sound good for me to do this?

grimfang4 commented 5 years ago

Yep, I'm good with that.

SnapperTT commented 5 years ago

Updated. Also changed #include "SDL.h" to #include . If you like I can change it back (and the turn around for said change should be faster. Sorry to keep you waiting mate!)

grimfang4 commented 5 years ago

Hey, no problem. I've got plenty to occupy me. :)

I'd prefer it as "SDL.h" because it should be checking project-defined search directories before checking standard install locations.

SnapperTT commented 5 years ago

I've reverted the <> to "", and took a crack at #29 .

I've added a "fallback" member to FC_Font, added "void FC_AddFallback(base_font, fallback_font)" which adds the fallback font to the end of the fallback font linked list, and added the font switching to SDL_FontCache.c:1617.

The font switching does "work" - it does successfully load glyphs from other fonts, however the is-glyph-missing detection does not work, so its commented out, so that when a suitable fix is found it can be easily applied