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

Handle to an owned font. More...

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

Public Member Functions

void Close ()
 Dispose of a previously-created font.
 
FontShared share ()
 Move this font into a FontShared.
 
constexpr ResourceUnique (std::nullptr_t=nullptr)
 Default constructor.
 
constexpr ResourceUnique (base::value_type value, DELETER deleter={})
 Constructs from raw type.
 
constexpr ResourceUnique (ResourceUnique &&other)
 Move constructor.
 
 ResourceUnique (const ResourceUnique &other)=delete
 
- Public Member Functions inherited from SDL::ResourceUnique< FontRef >
constexpr ResourceUnique (std::nullptr_t=nullptr)
 Default constructor.
 
constexpr ResourceUnique (base::value_type value, DefaultDeleter< FontRef > deleter={})
 Constructs from raw type.
 
constexpr ResourceUnique (ResourceUnique &&other)
 Move constructor.
 
 ResourceUnique (const ResourceUnique &other)=delete
 
 ~ResourceUnique ()
 Destructor.
 
constexpr ResourceUniqueoperator= (ResourceUnique other)
 Assignment operator.
 
void reset ()
 Resets the value, destroying the resource if not nullptr.
 
- Public Member Functions inherited from SDL::ResourceOwnerBase< RESOURCE, DELETER >
RESOURCE release ()
 Returns reference and reset this.
 
- Public Member Functions inherited from SDL::ResourcePtrBase< RESOURCE >
constexpr operator bool () const
 Check if not null.
 
constexpr bool operator== (const ResourcePtrBase &other) const
 Comparison.
 
constexpr bool operator== (std::nullptr_t) const
 Comparison.
 
constexpr bool operator== (std::nullopt_t) const
 Comparison.
 
constexpr reference operator* () const
 Gets reference.
 
constexpr const referenceoperator-> () const
 Gets addressable reference.
 
constexpr referenceoperator-> ()
 Gets addressable reference.
 
reference get () const
 Get reference.
 

Static Public Member Functions

static Font Open (StringParam file, float ptsize)
 Create a font from a file, using a specified point size.
 
static Font Open (IOStreamRef src, float ptsize)
 Create a font from an IOStreamRef, using a specified point size.
 
static Font OpenWithProperties (PropertiesRef props)
 Create a font with the specified properties.
 

Additional Inherited Members

- Public Types inherited from SDL::ResourceOwnerBase< RESOURCE, DELETER >
using deleter = DELETER
 The deleter type.
 
- Public Types inherited from SDL::ResourcePtrBase< RESOURCE >
using reference = RESOURCE
 The reference resource type.
 
using value_type = typename reference::value_type
 The raw resource type.
 
- Protected Member Functions inherited from SDL::ResourceOwnerBase< RESOURCE, DELETER >
constexpr ResourceOwnerBase (base::value_type value={}, DELETER deleter={})
 Constructs from raw type.
 
void free ()
 Frees resource.
 
- Protected Member Functions inherited from SDL::ResourcePtrBase< RESOURCE >
constexpr ResourcePtrBase (value_type value={})
 Constructs from raw type.
 
referenceget ()
 Get reference.
 

Detailed Description

Category:
Resource
See also
FontRef

Member Function Documentation

◆ Close()

void SDL::Font::Close ( )
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 Font.Open().

The font is not valid after being passed to this function. String pointers from functions that return information on this font, such as FontRef.GetFamilyName() and FontRef.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
Font.Open

◆ Open() [1/2]

static Font SDL::Font::Open ( IOStreamRef  src,
float  ptsize 
)
inlinestatic

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 IOStreamRef to provide a font file's data.
ptsizepoint size to use for the newly-opened font.
Returns
a valid FontRef 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.
See also
Font.Close

◆ Open() [2/2]

static Font SDL::Font::Open ( StringParam  file,
float  ptsize 
)
inlinestatic

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.
Returns
a valid FontRef 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.
See also
Font.Close

◆ OpenWithProperties()

static Font SDL::Font::OpenWithProperties ( PropertiesRef  props)
inlinestatic

These are the supported properties:

  • prop::Font.CREATE_FILENAME_STRING: the font file to open, if an IOStreamRef isn't being used. This is required if prop::Font.CREATE_IOSTREAM_POINTER and prop::Font.CREATE_EXISTING_FONT_POINTER aren't set.
  • prop::Font.CREATE_IOSTREAM_POINTER: an IOStreamRef 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_POINTER 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 IOStreamRef.
  • 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_POINTER: an optional FontRef 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.
Returns
a valid FontRef 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.
See also
Font.Close

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