Skip to content

Commit

Permalink
Added properties to customize the font outline
Browse files Browse the repository at this point in the history
Fixes #422
  • Loading branch information
slouken committed Dec 7, 2024
1 parent fc3e109 commit c182fd1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions include/SDL3_ttf/SDL_ttf.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_OpenFontWithProperties(SDL_Properties
/**
* Get the properties associated with a font.
*
* The following read-write properties are provided by SDL:
*
* - `TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER`: The FT_Stroker_LineCap value used when setting the font outline, defaults to `FT_STROKER_LINECAP_ROUND`.
* - `TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER`: The FT_Stroker_LineJoin value used when setting the font outline, defaults to `FT_STROKER_LINEJOIN_ROUND`.
* - `TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER`: The FT_Fixed miter limit used when setting the font outline, defaults to 0.
*
* \param font the font to query.
* \returns a valid property ID on success or 0 on failure; call
* SDL_GetError() for more information.
Expand All @@ -239,6 +245,10 @@ extern SDL_DECLSPEC TTF_Font * SDLCALL TTF_OpenFontWithProperties(SDL_Properties
*/
extern SDL_DECLSPEC SDL_PropertiesID SDLCALL TTF_GetFontProperties(TTF_Font *font);

#define TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER "SDL_ttf.font.outline.line_cap"
#define TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER "SDL_ttf.font.outline.line_join"
#define TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER "SDL_ttf.font.outline.miter_limit"

/**
* Get the font generation.
*
Expand Down Expand Up @@ -394,6 +404,8 @@ extern SDL_DECLSPEC int SDLCALL TTF_GetFontStyle(const TTF_Font *font);
/**
* Set a font's current outline.
*
* This uses the font properties `TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER`, `TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER`, and `TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER` when setting the font outline.
*
* This updates any TTF_Text objects using this font, and clears
* already-generated glyphs, if any, from the cache.
*
Expand Down
6 changes: 5 additions & 1 deletion src/SDL_ttf.c
Original file line number Diff line number Diff line change
Expand Up @@ -5057,7 +5057,11 @@ bool TTF_SetFontOutline(TTF_Font *font, int outline)
}
}

FT_Stroker_Set(font->stroker, outline * 64, FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0);
SDL_PropertiesID props = TTF_GetFontProperties(font);
FT_Stroker_LineCap line_cap = (FT_Stroker_LineCap)SDL_GetNumberProperty(props, TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER, FT_STROKER_LINECAP_ROUND);
FT_Stroker_LineJoin line_join = (FT_Stroker_LineJoin)SDL_GetNumberProperty(props, TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER, FT_STROKER_LINEJOIN_ROUND);
FT_Fixed miter_limit = (FT_Fixed)SDL_GetNumberProperty(props, TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER, 0);
FT_Stroker_Set(font->stroker, outline * 64, line_cap, line_join, miter_limit);
} else {
if (font->stroker) {
FT_Stroker_Done(font->stroker);
Expand Down

0 comments on commit c182fd1

Please sign in to comment.