Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes gcc wnarrowing spam (issue #38) #39

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 43 additions & 14 deletions SDL_FontCache.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ See SDL_FontCache.h for license info.

#include "SDL_FontCache.h"


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -231,7 +232,7 @@ char* FC_GetStringASCII_Latin1(void)

FC_Rect FC_MakeRect(float x, float y, float w, float h)
{
FC_Rect r = {x, y, w, h};
FC_Rect r = {(FC_COORD)x, (FC_COORD)y, (FC_COORD)w, (FC_COORD)h};
return r;
}

Expand Down Expand Up @@ -446,6 +447,8 @@ struct FC_Font
FC_Image** glyph_cache;

char* loading_string;
// Fallback font - if a codepoint is not found in this font, then search this font
FC_Font * fallback;

};

Expand Down Expand Up @@ -617,7 +620,7 @@ static_inline FC_Rect FC_RectUnion(FC_Rect A, FC_Rect B)
x2 = FC_MAX(A.x+A.w, B.x+B.w);
y2 = FC_MAX(A.y+A.h, B.y+B.h);
{
FC_Rect result = {x, y, FC_MAX(0, x2 - x), FC_MAX(0, y2 - y)};
FC_Rect result = {(FC_COORD)x, (FC_COORD)y, FC_MAX(0, (FC_COORD)(x2 - x)), FC_MAX(0, (FC_COORD)(y2 - y))};
return result;
}
}
Expand Down Expand Up @@ -686,16 +689,16 @@ FC_Rect FC_DefaultRenderCallback(FC_Image* src, FC_Rect* srcrect, FC_Target* des
if(xscale < 0)
{
xscale = -xscale;
flip = (SDL_RendererFlip) ((int)flip | (int)SDL_FLIP_HORIZONTAL);
flip = (SDL_RendererFlip) ((FC_COORD)flip | (FC_COORD)SDL_FLIP_HORIZONTAL);
}
if(yscale < 0)
{
yscale = -yscale;
flip = (SDL_RendererFlip) ((int)flip | (int)SDL_FLIP_VERTICAL);
flip = (SDL_RendererFlip) ((FC_COORD)flip | (FC_COORD)SDL_FLIP_VERTICAL);
}

SDL_Rect r = *srcrect;
SDL_Rect dr = {(int)x, (int)y, (int)(xscale*r.w), (int)(yscale*r.h)};
SDL_Rect dr = {(FC_COORD)x, (FC_COORD)y, (FC_COORD)(xscale*r.w), (FC_COORD)(yscale*r.h)};
SDL_RenderCopyEx(dest, src, &r, &dr, 0, NULL, flip);
}
#endif
Expand Down Expand Up @@ -897,6 +900,8 @@ static void FC_Init(FC_Font* font)

if(fc_buffer == NULL)
fc_buffer = (char*)malloc(fc_buffer_size);

font->fallback = NULL;
}

static Uint8 FC_GrowGlyphCache(FC_Font* font)
Expand Down Expand Up @@ -1607,7 +1612,20 @@ Uint8 FC_GetGlyphData(FC_Font* font, FC_GlyphData* result, Uint32 codepoint)
SDL_QueryTexture(cache_image, NULL, NULL, &w, &h);
#endif

surf = TTF_RenderUTF8_Blended(font->ttf_source, buff, white);
// Find the font in the linked list that has this character
FC_Font * working = font;
// std::cout << "FC_Font: " << font << "glyphProvided " << TTF_GlyphIsProvided32(working->ttf_source, codepoint) << ", glypth: [" << buff << "]" << ", codepoint: [" << (codepoint) << "]"<< std::endl;
// while (working)
// {
// if (!TTF_GlyphIsProvided32(working->ttf_source, codepoint)) // Requires SDL_TTF 2.0.16
// working = working->fallback;
// else
// break;
// }
// if (!working)
// working = font;

surf = TTF_RenderUTF8_Blended(working->ttf_source, buff, white);
if(surf == NULL)
{
return 0;
Expand Down Expand Up @@ -2184,7 +2202,7 @@ FC_Rect FC_DrawBoxEffect(FC_Font* font, FC_Target* dest, FC_Rect box, FC_Effect

FC_Rect FC_DrawColumn(FC_Font* font, FC_Target* dest, float x, float y, Uint16 width, const char* formatted_text, ...)
{
FC_Rect box = {x, y, width, 0};
FC_Rect box = {(FC_COORD)x, (FC_COORD)y, (FC_COORD)width, 0};
int total_height;

if(formatted_text == NULL || font == NULL)
Expand All @@ -2201,7 +2219,7 @@ FC_Rect FC_DrawColumn(FC_Font* font, FC_Target* dest, float x, float y, Uint16 w

FC_Rect FC_DrawColumnAlign(FC_Font* font, FC_Target* dest, float x, float y, Uint16 width, FC_AlignEnum align, const char* formatted_text, ...)
{
FC_Rect box = {x, y, width, 0};
FC_Rect box = {(FC_COORD)x, (FC_COORD)y, (FC_COORD)width, 0};
int total_height;

if(formatted_text == NULL || font == NULL)
Expand Down Expand Up @@ -2230,7 +2248,7 @@ FC_Rect FC_DrawColumnAlign(FC_Font* font, FC_Target* dest, float x, float y, Uin

FC_Rect FC_DrawColumnScale(FC_Font* font, FC_Target* dest, float x, float y, Uint16 width, FC_Scale scale, const char* formatted_text, ...)
{
FC_Rect box = {x, y, width, 0};
FC_Rect box = {(FC_COORD)x, (FC_COORD)y, (FC_COORD)width, 0};
int total_height;

if(formatted_text == NULL || font == NULL)
Expand All @@ -2247,7 +2265,7 @@ FC_Rect FC_DrawColumnScale(FC_Font* font, FC_Target* dest, float x, float y, Uin

FC_Rect FC_DrawColumnColor(FC_Font* font, FC_Target* dest, float x, float y, Uint16 width, SDL_Color color, const char* formatted_text, ...)
{
FC_Rect box = {x, y, width, 0};
FC_Rect box = {(FC_COORD)x, (FC_COORD)y, (FC_COORD)width, 0};
int total_height;

if(formatted_text == NULL || font == NULL)
Expand All @@ -2264,7 +2282,7 @@ FC_Rect FC_DrawColumnColor(FC_Font* font, FC_Target* dest, float x, float y, Uin

FC_Rect FC_DrawColumnEffect(FC_Font* font, FC_Target* dest, float x, float y, Uint16 width, FC_Effect effect, const char* formatted_text, ...)
{
FC_Rect box = {x, y, width, 0};
FC_Rect box = {(FC_COORD)x, (FC_COORD)y, (FC_COORD)width, 0};
int total_height;

if(formatted_text == NULL || font == NULL)
Expand Down Expand Up @@ -2293,7 +2311,7 @@ FC_Rect FC_DrawColumnEffect(FC_Font* font, FC_Target* dest, float x, float y, Ui

static FC_Rect FC_RenderCenter(FC_Font* font, FC_Target* dest, float x, float y, FC_Scale scale, const char* text)
{
FC_Rect result = {x, y, 0, 0};
FC_Rect result = {(FC_COORD)x, (FC_COORD)y, 0, 0};
if(text == NULL || font == NULL)
return result;

Expand Down Expand Up @@ -2326,7 +2344,7 @@ static FC_Rect FC_RenderCenter(FC_Font* font, FC_Target* dest, float x, float y,

static FC_Rect FC_RenderRight(FC_Font* font, FC_Target* dest, float x, float y, FC_Scale scale, const char* text)
{
FC_Rect result = {x, y, 0, 0};
FC_Rect result = {(FC_COORD)x, (FC_COORD)y, 0, 0};
if(text == NULL || font == NULL)
return result;

Expand Down Expand Up @@ -2721,7 +2739,7 @@ SDL_Color FC_GetDefaultColor(FC_Font* font)

FC_Rect FC_GetBounds(FC_Font* font, float x, float y, FC_AlignEnum align, FC_Scale scale, const char* formatted_text, ...)
{
FC_Rect result = {x, y, 0, 0};
FC_Rect result = {(FC_COORD)x, (FC_COORD)y, 0, 0};

if(formatted_text == NULL)
return result;
Expand Down Expand Up @@ -2898,3 +2916,14 @@ void FC_SetDefaultColor(FC_Font* font, SDL_Color color)

font->default_color = color;
}


void FC_AddFallbackFont(FC_Font* base, FC_Font* fallback)
{
FC_Font * working = base;
if (!working) return;
while (working->fallback)
working = working->fallback;
working->fallback = fallback;
}

5 changes: 4 additions & 1 deletion SDL_FontCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ THE SOFTWARE.

#ifdef FC_USE_SDL_GPU
#include "SDL_gpu.h"
#define FC_COORD float
#else
#define FC_COORD int
#endif


Expand Down Expand Up @@ -316,7 +319,7 @@ void FC_SetFilterMode(FC_Font* font, FC_FilterEnum filter);
void FC_SetSpacing(FC_Font* font, int LetterSpacing);
void FC_SetLineSpacing(FC_Font* font, int LineSpacing);
void FC_SetDefaultColor(FC_Font* font, SDL_Color color);

void FC_AddFallbackFont(FC_Font* base, FC_Font* fallback);

#ifdef __cplusplus
}
Expand Down