Skip to content

[Feature request] More glyph data querying functions. #613

@TriangulumDesire

Description

@TriangulumDesire

I am proposing to add some more functions to get information about glyphs (mainly to assist with text segmentation and transformation). I suggest the following API additions:

// Enumeration containing all of the Unicode general category values (https://www.unicode.org/reports/tr44/#General_Category_Values).
// Based on HarfBuzz's hb_unicode_general_category_t (https://harfbuzz.github.io/harfbuzz-hb-unicode.html#hb-unicode-general-category-t).
typedef enum TTF_GeneralCategory
{
    // ...
} TTF_GeneralCategory;

// Returns the general category of a character, or TTF_GENERAL_CATEGORY_INVALID on error or if built without HarfBuzz.
// This is useful for segmenting text, or determining which fonts to use in some cases.
// (For example, one might wish to use different fonts for letters and numbers within the same string, or wish to enable certain features for uppercase letters.)
// Will make use of hb_unicode_general_category (https://harfbuzz.github.io/harfbuzz-hb-unicode.html#hb-unicode-general-category).
TTF_GeneralCategory TTF_GetGlyphGeneralCategory(Uint32 ch);

// Returns the canonical combining class (https://www.unicode.org/reports/tr44/#Canonical_Combining_Class_Values) of a character, or -1 on error or if built without HarfBuzz.
// This is useful for segmentation and some text transformations, such as the special cases at the bottom of https://www.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt.
// Will make use of hb_unicode_combining_class (https://harfbuzz.github.io/harfbuzz-hb-unicode.html#hb-unicode-combining-class).
int TTF_GetGlyphCombiningClass(Uint32 ch);

// Returns the horizontal direction of a script (left-to-right or right-to-left) or TTF_DIRECTION_INVALID if script supports both directions or built without HarfBuzz.
// This is useful for segmenting and correctly rendering bidirectional text.
// Will make use of hb_script_get_horizontal_direction (https://harfbuzz.github.io/harfbuzz-hb-common.html#hb-script-get-horizontal-direction).
TTF_Direction TTF_GetScriptHorizontalDirection(Uint32 script);

// Returns the bidirectional-mirroring glyph of the given glyph. For example '(' would return ')'. Full list available here: https://www.unicode.org/Public/17.0.0/ucd/BidiMirroring.txt
// If a glyph has no mirror (or if built without HarfBuzz), the glyph itself will be returned.
// This is useful for proper bidirectional text transformation.
// Will make use of hb_unicode_mirroring (https://harfbuzz.github.io/harfbuzz-hb-unicode.html#hb-unicode-mirroring).
Uint32 TTF_GetGlyphMirror(Uint32 ch);

All of these functions will be small and simple to implement, as HarfBuzz already has the functionality. If SDL_ttf is built without HarfBuzz, then these functions will just return a default, invalid value.

I am happy to create a pull request for all of this; I'm just asking beforehand if this is something you think should be added to the library. (I can understand if you feel if some of these don't belong within the scope of SDL_ttf.) The main reason I am asking for these is because I am planning to create a simplified version of my FreeType/HarfBuzz text renderer using SDL_ttf, and these are the only functionalities of HarfBuzz I need that SDL_ttf doesn't currently offer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions