SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SDL::FontRef Struct Reference

Handle to a non owned font. More...

Inheritance diagram for SDL::FontRef:
Inheritance graph
[legend]

Public Member Functions

constexpr FontRef (const FontRef &other)
 Copy constructor.
 
constexpr FontRef (FontRef &&other)
 Move constructor.
 
constexpr ~FontRef ()=default
 Default constructor.
 
FontRefoperator= (FontRef other)
 Assignment operator.
 
void reset (TTF_Font *newResource={})
 Dispose of a previously-created font.
 
 FontBase (StringParam file, float ptsize)
 Create a font from a file, using a specified point size.
 
 FontBase (IOStreamBase &src, float ptsize)
 Create a font from an IOStreamBase, using a specified point size.
 
 FontBase (PropertiesBase &props)
 Create a font with the specified properties.
 
- Public Member Functions inherited from SDL::FontBase
 FontBase (StringParam file, float ptsize)
 Create a font from a file, using a specified point size.
 
 FontBase (IOStreamBase &src, float ptsize)
 Create a font from an IOStreamBase, using a specified point size.
 
 FontBase (PropertiesBase &props)
 Create a font with the specified properties.
 
Font Copy () const
 Create a copy of an existing font.
 
PropertiesRef GetProperties ()
 Get the properties associated with a font.
 
Uint32 GetGeneration () const
 Get the font generation.
 
void AddFallback (FontBase &fallback)
 Add a fallback font.
 
void RemoveFallback (FontBase &fallback)
 Remove a fallback font.
 
void ClearFallbacks ()
 Remove all fallback fonts.
 
void SetSize (float ptsize)
 Set a font's size dynamically.
 
void SetSizeDPI (float ptsize, int hdpi, int vdpi)
 Set font size dynamically with target resolutions, in dots per inch.
 
float GetSize () const
 Get the size of a font.
 
void GetDPI (int *hdpi, int *vdpi) const
 Get font target resolutions, in dots per inch.
 
void SetStyle (FontStyleFlags style)
 Set a font's current style.
 
FontStyleFlags GetStyle () const
 Query a font's current style.
 
void SetOutline (int outline)
 Set a font's current outline.
 
int GetOutline () const
 Query a font's current outline.
 
void SetHinting (HintingFlags hinting)
 Set a font's current hinter setting.
 
int GetNumFaces () const
 Query the number of faces of a font.
 
HintingFlags GetHinting () const
 Query a font's current FreeType hinter setting.
 
void SetSDF (bool enabled)
 Enable Signed Distance Field rendering for a font.
 
bool GetSDF () const
 Query whether Signed Distance Field rendering is enabled for a font.
 
int GetWeight () const
 Query a font's weight, in terms of the lightness/heaviness of the strokes.
 
void SetWrapAlignment (HorizontalAlignment align)
 Set a font's current wrap alignment option.
 
HorizontalAlignment GetWrapAlignment () const
 Query a font's current wrap alignment option.
 
int GetHeight () const
 Query the total height of a font.
 
int GetAscent () const
 Query the offset from the baseline to the top of a font.
 
int GetDescent () const
 Query the offset from the baseline to the bottom of a font.
 
void SetLineSkip (int lineskip)
 Set the spacing between lines of text for a font.
 
int GetLineSkip () const
 Query the spacing between lines of text for a font.
 
void SetKerning (bool enabled)
 Set if kerning is enabled for a font.
 
bool GetKerning () const
 Query whether or not kerning is enabled for a font.
 
bool IsFixedWidth () const
 Query whether a font is fixed-width.
 
bool IsScalable () const
 Query whether a font is scalable or not.
 
const char * GetFamilyName () const
 Query a font's family name.
 
const char * GetStyleName () const
 Query a font's style name.
 
void SetDirection (Direction direction)
 Set the direction to be used for text shaping by a font.
 
Direction GetDirection () const
 Get the direction to be used for text shaping by a font.
 
void SetScript (Uint32 script)
 Set the script to be used for text shaping by a font.
 
Uint32 GetScript () const
 Get the script used for text shaping a font.
 
void SetLanguage (StringParam language_bcp47)
 Set language to be used for text shaping by a font.
 
bool HasGlyph (Uint32 ch) const
 Check whether a glyph is provided by the font for a UNICODE codepoint.
 
SurfaceRef GetGlyphImage (Uint32 ch, ImageType *image_type=nullptr) const
 Get the pixel image for a UNICODE codepoint.
 
SurfaceRef GetGlyphImageForIndex (Uint32 glyph_index, ImageType *image_type=nullptr) const
 Get the pixel image for a character index.
 
void GetGlyphMetrics (Uint32 ch, int *minx, int *maxx, int *miny, int *maxy, int *advance) const
 Query the metrics (dimensions) of a font's glyph for a UNICODE codepoint.
 
int GetGlyphKerning (Uint32 previous_ch, Uint32 ch) const
 Query the kerning size between the glyphs of two UNICODE codepoints.
 
Point GetStringSize (std::string_view text) const
 Calculate the dimensions of a rendered string of UTF-8 text.
 
void GetStringSize (std::string_view text, int *w, int *h) const
 Calculate the dimensions of a rendered string of UTF-8 text.
 
Point GetStringSizeWrapped (std::string_view text, int wrap_width) const
 Calculate the dimensions of a rendered string of UTF-8 text.
 
void GetStringSizeWrapped (std::string_view text, int wrap_width, int *w, int *h) const
 Calculate the dimensions of a rendered string of UTF-8 text.
 
void MeasureString (std::string_view text, int max_width, int *measured_width, size_t *measured_length) const
 Calculate how much of a UTF-8 string will fit in a given width.
 
Surface RenderText_Solid (std::string_view text, Color fg) const
 Render UTF-8 text at fast quality to a new 8-bit surface.
 
Surface RenderText_Solid_Wrapped (std::string_view text, Color fg, int wrapLength) const
 Render word-wrapped UTF-8 text at fast quality to a new 8-bit surface.
 
Surface RenderGlyph_Solid (Uint32 ch, Color fg) const
 Render a single 32-bit glyph at fast quality to a new 8-bit surface.
 
Surface RenderText_Shaded (std::string_view text, Color fg, Color bg) const
 Render UTF-8 text at high quality to a new 8-bit surface.
 
Surface RenderText_Shaded_Wrapped (std::string_view text, Color fg, Color bg, int wrap_width) const
 Render word-wrapped UTF-8 text at high quality to a new 8-bit surface.
 
Surface RenderGlyph_Shaded (Uint32 ch, Color fg, Color bg) const
 Render a single UNICODE codepoint at high quality to a new 8-bit surface.
 
Surface RenderText_Blended (std::string_view text, Color fg) const
 Render UTF-8 text at high quality to a new ARGB surface.
 
Surface RenderText_Blended_Wrapped (std::string_view text, Color fg, int wrap_width) const
 Render word-wrapped UTF-8 text at high quality to a new ARGB surface.
 
Surface RenderGlyph_Blended (Uint32 ch, Color fg) const
 Render a single UNICODE codepoint at high quality to a new ARGB surface.
 
Surface RenderText_LCD (std::string_view text, Color fg, Color bg) const
 Render UTF-8 text at LCD subpixel quality to a new ARGB surface.
 
Surface RenderText_LCD_Wrapped (std::string_view text, Color fg, Color bg, int wrap_width) const
 Render word-wrapped UTF-8 text at LCD subpixel quality to a new ARGB surface.
 
Surface RenderGlyph_LCD (Uint32 ch, Color fg, Color bg) const
 Render a single UNICODE codepoint at LCD subpixel quality to a new ARGB surface.
 
constexpr Resource (T resource={})
 Constructs the underlying resource.
 
constexpr Resource (std::nullptr_t)
 Equivalent to default ctor.
 
constexpr Resource (std::nullopt_t)
 Equivalent to default ctor.
 
 Resource (const Resource &other)=delete
 
 Resource (Resource &&other)=delete
 
- Public Member Functions inherited from SDL::Resource< TTF_Font * >
constexpr Resource (TTF_Font * resource={})
 Constructs the underlying resource.
 
constexpr Resource (std::nullptr_t)
 Equivalent to default ctor.
 
constexpr Resource (std::nullopt_t)
 Equivalent to default ctor.
 
 Resource (const Resource &other)=delete
 
 Resource (Resource &&other)=delete
 
Resourceoperator= (const Resource &other)=delete
 
Resourceoperator= (Resource &&other)=delete
 
constexpr operator bool () const
 True if contains a valid resource.
 
constexpr bool operator== (const Resource &other) const=default
 Comparison.
 
constexpr bool operator== (std::nullopt_t) const
 Comparison.
 
constexpr bool operator== (std::nullptr_t) const
 Comparison.
 
constexpr TTF_Font * get () const
 Return contained resource;.
 
constexpr TTF_Font * release (TTF_Font * newResource={})
 Return contained resource and empties or replace value.
 
constexpr const TTF_Font * operator-> () const
 Access to fields.
 
constexpr TTF_Font * operator-> ()
 Access to fields.
 

Additional Inherited Members

- Static Public Member Functions inherited from SDL::FontBase
static Uint32 GetGlyphScript (Uint32 ch)
 Get the script used by a 32-bit codepoint.
 

Detailed Description

Category:
Resource
See also
FontBase
Font

Member Function Documentation

◆ FontBase() [1/3]

SDL::FontBase::FontBase ( IOStreamBase src,
float  ptsize 
)
inline

Some .fon fonts will have several sizes embedded in the file, so the point size becomes the index of choosing which size. If the value is too high, the last indexed size will be the default.

Parameters
srcan IOStreamBase to provide a font file's data.
ptsizepoint size to use for the newly-opened font.
Postcondition
a valid FontBase on success.
Exceptions
Erroron failure.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL_ttf 3.0.0.

◆ FontBase() [2/3]

SDL::FontBase::FontBase ( PropertiesBase props)
inline

These are the supported properties:

  • prop::Font.CREATE_FILENAME_STRING: the font file to open, if an IOStreamBase isn't being used. This is required if prop::Font.CREATE_IOSTREAM_POINTER and prop::Font.CREATE_EXISTING_FONT aren't set.
  • prop::Font.CREATE_IOSTREAM_POINTER: an IOStreamBase containing the font to be opened. This should not be closed until the font is closed. This is required if prop::Font.CREATE_FILENAME_STRING and prop::Font.CREATE_EXISTING_FONT aren't set.
  • prop::Font.CREATE_IOSTREAM_OFFSET_NUMBER: the offset in the iostream for the beginning of the font, defaults to 0.
  • prop::Font.CREATE_IOSTREAM_AUTOCLOSE_BOOLEAN: true if closing the font should also close the associated IOStreamBase.
  • prop::Font.CREATE_SIZE_FLOAT: the point size of the font. Some .fon fonts will have several sizes embedded in the file, so the point size becomes the index of choosing which size. If the value is too high, the last indexed size will be the default.
  • prop::Font.CREATE_FACE_NUMBER: the face index of the font, if the font contains multiple font faces.
  • prop::Font.CREATE_HORIZONTAL_DPI_NUMBER: the horizontal DPI to use for font rendering, defaults to prop::Font.CREATE_VERTICAL_DPI_NUMBER if set, or 72 otherwise.
  • prop::Font.CREATE_VERTICAL_DPI_NUMBER: the vertical DPI to use for font rendering, defaults to prop::Font.CREATE_HORIZONTAL_DPI_NUMBER if set, or 72 otherwise.
  • prop::Font.CREATE_EXISTING_FONT: an optional FontBase that, if set, will be used as the font data source and the initial size and style of the new font.
Parameters
propsthe properties to use.
Postcondition
a valid FontBase on success.
Exceptions
Erroron failure.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL_ttf 3.0.0.

◆ FontBase() [3/3]

SDL::FontBase::FontBase ( StringParam  file,
float  ptsize 
)
inline

Some .fon fonts will have several sizes embedded in the file, so the point size becomes the index of choosing which size. If the value is too high, the last indexed size will be the default.

Parameters
filepath to font file.
ptsizepoint size to use for the newly-opened font.
Postcondition
a valid FontBase on success.
Exceptions
Erroron failure.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL_ttf 3.0.0.

◆ reset()

void SDL::FontRef::reset ( TTF_Font *  newResource = {})
inline

Call this when done with a font. This function will free any resources associated with it. It is safe to call this function on nullptr, for example on the result of a failed call to FontBase.FontBase().

The font is not valid after being passed to this function. String pointers from functions that return information on this font, such as FontBase.GetFamilyName() and FontBase.GetStyleName(), are no longer valid after this call, as well.

Thread safety:
This function should not be called while any other thread is using the font.
Since
This function is available since SDL_ttf 3.0.0.
See also
FontBase.FontBase

The documentation for this struct was generated from the following file: