Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
Merge pull request #120 from fsomers/fontconfig-set-name
Browse files Browse the repository at this point in the history
Add support for setting a FontConfig name
  • Loading branch information
dertseha authored Aug 30, 2020
2 parents f78f02f + 5f1384d commit 76d6467
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions FontConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ func (config FontConfig) SetMergeMode(value bool) {
}
}

// SetName sets a short display name for a font, for diagnostic purposes.
// If the FontConfig does not provide a name, one will be synthesized for
// fonts which are added from files. When adding fonts from memory, this
// method can be used to provide a name.
// The name will be truncated if it is longer than the limit supported by imgui.
func (config FontConfig) SetName(name string) {
if config != DefaultFontConfig {
nameArg, nameFin := wrapString(name)
defer nameFin()
C.iggFontConfigSetName(config.handle(), nameArg)
}
}

// getFontDataOwnedByAtlas gets the current ownership status of the font data.
func (config FontConfig) getFontDataOwnedByAtlas() bool {
if config != DefaultFontConfig {
Expand Down
8 changes: 8 additions & 0 deletions wrapper/FontConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ void iggFontConfigSetMergeMode(IggFontConfig handle, IggBool value)
fontConfig->MergeMode = value;
}

void iggFontConfigSetName(IggFontConfig handle, char const *value)
{
ImFontConfig *fontConfig = reinterpret_cast<ImFontConfig *>(handle);
const size_t bufSize = sizeof(fontConfig->Name);
strncpy(fontConfig->Name, value, bufSize - 1);
fontConfig->Name[bufSize - 1] = '\0';
}

int iggFontConfigGetFontDataOwnedByAtlas(IggFontConfig handle)
{
ImFontConfig *fontConfig = reinterpret_cast<ImFontConfig *>(handle);
Expand Down
1 change: 1 addition & 0 deletions wrapper/FontConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extern void iggFontConfigSetPixelSnapH(IggFontConfig handle, IggBool value);
extern void iggFontConfigSetGlyphMinAdvanceX(IggFontConfig handle, float value);
extern void iggFontConfigSetGlyphMaxAdvanceX(IggFontConfig handle, float value);
extern void iggFontConfigSetMergeMode(IggFontConfig handle, IggBool value);
extern void iggFontConfigSetName(IggFontConfig handle, char const *value);
extern int iggFontConfigGetFontDataOwnedByAtlas(IggFontConfig handle);

#ifdef __cplusplus
Expand Down

0 comments on commit 76d6467

Please sign in to comment.