Skip to content

File include/brisk/graphics/Fonts.hpp


EFreeType class

EFreeType

OpenTypeFeatureFlag class

OpenTypeFeatureFlag

FontManager class

FontManager

ShapedText class

ShapedText

Immutable, width-independent representation of shaped text.

ShapedText stores the source-to-grapheme mappings and paragraph information needed for text editing, cursor movement, selection, and layout creation. It has value semantics: copies share the immutable shaped data through a std::shared_ptr-backed store, while each value can be used independently. Use layout() to produce a width-dependent TextLayout for measurement or drawing.


TextLayout class

TextLayout

Immutable width-dependent layout with measurement and interaction operations.

TextLayout contains the lines, metrics, bounds, and source mappings resulting from laying out a ShapedText with specific width and alignment options. It supports caret positioning, hit-testing, vertical caret movement, and selection-rectangle generation in layout coordinates. It has value semantics: copies share the immutable layout data through a std::shared_ptr-backed store and remain safe to retain independently.


TextSelectionRect class

TextSelectionRect

One rectangle segment belonging to a text selection.


TextEngineState class (Internal::TextEngineState)

TextEngineState

FontMetrics class

FontMetrics

FontMetricsRepresents metrics for a font, providing details about its dimensions and spacing.

size variable (FontMetrics::size)

float size

The size of the font in points.

ascender variable (FontMetrics::ascender)

float ascender

The ascender height, always positive and points upwards.

descender variable (FontMetrics::descender)

float descender

The descender height, always negative and points downwards.

height variable (FontMetrics::height)

float height

The total height of the font, including ascender, descender, and line gap.

spaceAdvanceX variable (FontMetrics::spaceAdvanceX)

float spaceAdvanceX

The horizontal advance width for a space character.

lineThickness variable (FontMetrics::lineThickness)

float lineThickness

The thickness of lines, such as for underline or strikethrough.

xHeight variable (FontMetrics::xHeight)

float xHeight

The height of the lowercase 'x' character.

capitalHeight variable (FontMetrics::capitalHeight)

float capitalHeight

The height of uppercase characters.

linegap function (FontMetrics::linegap)

float linegap() const noexcept

Computes the line gap, the vertical space between lines of text.
Returns The line gap value.

vertBounds function (FontMetrics::vertBounds)

float vertBounds() const noexcept

Computes the vertical bounds of the font.
Returns The total vertical bounds (ascender - descender).

underlineOffset function (FontMetrics::underlineOffset)

float underlineOffset() const noexcept

Computes the offset for an underline relative to the baseline.
Returns The underline offset.

overlineOffset function (FontMetrics::overlineOffset)

float overlineOffset() const noexcept

Computes the offset for an overline relative to the baseline.
Returns The overline offset.

lineThroughOffset function (FontMetrics::lineThroughOffset)

float lineThroughOffset() const noexcept

Computes the offset for a line through the text.
Returns The line-through offset.

operator== function (FontMetrics::operator==)

bool operator==(const FontMetrics &b) const noexcept =
    default

Compares two FontMetrics objects for equality.
Param b The FontMetrics object to compare against.
Returns True if the objects are equal, false otherwise.


TextLayoutAlignment enum

enum class TextLayoutAlignment : uint8_t

Horizontal alignment used when producing a TextLayout.

Start enumerator (TextLayoutAlignment::Start)

Align to the start edge of each paragraph, respecting its direction.

End enumerator (TextLayoutAlignment::End)

Align to the end edge of each paragraph, respecting its direction.

Left enumerator (TextLayoutAlignment::Left)

Align to the physical left edge.

Right enumerator (TextLayoutAlignment::Right)

Align to the physical right edge.

Center enumerator (TextLayoutAlignment::Center)

Center each line in the available layout width.


TextLayoutOptions class

TextLayoutOptions

Options controlling conversion of shaped text into a TextLayout.

maxLineWidth variable (TextLayoutOptions::maxLineWidth)

float maxLineWidth = HUGE_VALF

Maximum line width in pixels. Finite positive values enable wrapping; zero does not impose a width limit. The resulting coordinates are intrinsic and can be translated by the caller.

firstLineIndent variable (TextLayoutOptions::firstLineIndent)

float firstLineIndent = 0.f

Additional indentation applied to the first line of each paragraph, in pixels.

tabWidth variable (TextLayoutOptions::tabWidth)

float tabWidth = 0.f

Absolute tab-stop interval in pixels. Zero uses the interval configured by the shaped text.

alignment variable (TextLayoutOptions::alignment)

TextLayoutAlignment alignment = TextLayoutAlignment::Start

Horizontal alignment of each laid-out line.

allowBreakAnywhere variable (TextLayoutOptions::allowBreakAnywhere)

bool allowBreakAnywhere = false

If true, permits line breaks at grapheme boundaries where ordinary word wrapping would not.


CaretAffinity enum

enum class CaretAffinity : uint8_t

Selects which visual side owns a caret at an ambiguous boundary.

Upstream enumerator (CaretAffinity::Upstream)

Associate the caret with the preceding visual position.

Downstream enumerator (CaretAffinity::Downstream)

Associate the caret with the following visual position.


CaretIndex class

CaretIndex

A caret location expressed as a grapheme boundary and visual affinity.

grapheme variable (CaretIndex::grapheme)

uint32_t grapheme = 0

Grapheme boundary index.

affinity variable (CaretIndex::affinity)

CaretAffinity affinity = CaretAffinity::Downstream

Visual side at the boundary.


CaretPosition class

CaretPosition

A caret location expressed in layout coordinates.

x variable (CaretPosition::x)

float x = 0.f

Horizontal caret position in layout coordinates.

line variable (CaretPosition::line)

uint32_t line = 0

Zero-based line index.

bidiLevel variable (CaretPosition::bidiLevel)

uint8_t bidiLevel = 0

Bidirectional embedding level at the caret.


TextSelectionRect class

TextSelectionRect

One rectangle segment belonging to a text selection.

line variable (TextSelectionRect::line)

uint32_t line = 0

Zero-based line index.

x0 variable (TextSelectionRect::x0)

float x0 = 0.f

Start of the selected segment in layout coordinates.

x1 variable (TextSelectionRect::x1)

float x1 = 0.f

End of the selected segment in layout coordinates.


ShapedParagraph class

ShapedParagraph

Character and grapheme range for one paragraph in ShapedText.

characterRange variable (ShapedParagraph::characterRange)

Range<uint32_t> characterRange

Half-open character/codepoint range.

graphemeRange variable (ShapedParagraph::graphemeRange)

Range<uint32_t> graphemeRange

Half-open grapheme range.

direction variable (ShapedParagraph::direction)

TextDirection direction = TextDirection::LTR

Base direction of the paragraph.


TextLayoutLineEnd enum

enum class TextLayoutLineEnd : uint8_t

Describes why a line ends.

SoftWrap enumerator (TextLayoutLineEnd::SoftWrap)

The line ended because of the available width.

MandatoryBreak enumerator (TextLayoutLineEnd::MandatoryBreak)

The line ended at an explicit line-break character.

ParagraphEnd enumerator (TextLayoutLineEnd::ParagraphEnd)

The line ended at the end of a paragraph.


TextLine class

TextLine

Metrics and source ranges for one line in a TextLayout.

characterRange variable (TextLine::characterRange)

Range<uint32_t> characterRange

Half-open character/codepoint range.

graphemeRange variable (TextLine::graphemeRange)

Range<uint32_t> graphemeRange

Half-open grapheme range.

direction variable (TextLine::direction)

TextDirection direction = TextDirection::LTR

Base direction of the line.

end variable (TextLine::end)

TextLayoutLineEnd end = TextLayoutLineEnd::ParagraphEnd

Reason the line ends.

baseline variable (TextLine::baseline)

float baseline = 0.f

Baseline y-coordinate.

ascender variable (TextLine::ascender)

float ascender = 0.f

Distance above the baseline.

descender variable (TextLine::descender)

float descender = 0.f

Distance below the baseline; normally negative.

leading variable (TextLine::leading)

float leading = 0.f

Extra line spacing distributed around the line.

width variable (TextLine::width)

float width = 0.f

Width including trailing whitespace.

trimmedWidth variable (TextLine::trimmedWidth)

float trimmedWidth = 0.f

Width excluding trailing whitespace.


TextLayout class

TextLayout

Immutable width-dependent layout with measurement and interaction operations.

TextLayout contains the lines, metrics, bounds, and source mappings resulting from laying out a ShapedText with specific width and alignment options. It supports caret positioning, hit-testing, vertical caret movement, and selection-rectangle generation in layout coordinates. It has value semantics: copies share the immutable layout data through a std::shared_ptr-backed store and remain safe to retain independently.


PimplAccessor class

PimplAccessor

ShapedText class

ShapedText

Immutable, width-independent representation of shaped text.

ShapedText stores the source-to-grapheme mappings and paragraph information needed for text editing, cursor movement, selection, and layout creation. It has value semantics: copies share the immutable shaped data through a std::shared_ptr-backed store, while each value can be used independently. Use layout() to produce a width-dependent TextLayout for measurement or drawing.

Impl class (ShapedText::Impl)

Impl

ShapedText function (ShapedText::ShapedText)

ShapedText()

Constructs an empty shaped-text value.

ShapedText(const ShapedText &)

Copies a shaped-text value and its source mappings.

ShapedText(ShapedText &&) noexcept

Transfers a shaped-text value into a new object.

empty function (ShapedText::empty)

bool empty() const noexcept


Returns true if no text was shaped, otherwise false.

characterCount function (ShapedText::characterCount)

uint32_t characterCount() const noexcept


Returns Number of source Unicode codepoints represented by the text.

graphemeCount function (ShapedText::graphemeCount)

uint32_t graphemeCount() const noexcept


Returns Number of graphemes represented by the source text.

graphemeBoundaries function (ShapedText::graphemeBoundaries)

std::span<const uint32_t>
graphemeBoundaries() const noexcept


Returns Source character boundaries for graphemes, including the initial and final boundary.

paragraphCount function (ShapedText::paragraphCount)

size_t paragraphCount() const noexcept


Returns Number of paragraphs in the shaped text.

paragraph function (ShapedText::paragraph)

ShapedParagraph paragraph(size_t index) const noexcept


Param index Zero-based paragraph index.
Returns Paragraph ranges, or an empty value if index is out of range.

characterToGrapheme function (ShapedText::characterToGrapheme)

uint32_t
characterToGrapheme(uint32_t character) const noexcept


Param character Source character/codepoint boundary, clamped to characterCount().
Returns Grapheme boundary containing the specified character boundary.

graphemeToCharacter function (ShapedText::graphemeToCharacter)

uint32_t
graphemeToCharacter(uint32_t grapheme) const noexcept


Param grapheme Grapheme boundary, clamped to graphemeCount().
Returns Source character/codepoint boundary corresponding to the grapheme boundary.

graphemeToCharacters function (ShapedText::graphemeToCharacters)

Range<uint32_t>
graphemeToCharacters(uint32_t grapheme) const noexcept


Param grapheme Grapheme index, clamped to the last grapheme.
Returns Half-open source character range covered by the grapheme.

isParagraphSeparator function (ShapedText::isParagraphSeparator)

bool isParagraphSeparator(uint32_t grapheme) const noexcept


Param grapheme Grapheme index to inspect.
Returns true if the grapheme is a paragraph separator rather than paragraph content.

caretFromCharacter function (ShapedText::caretFromCharacter)

CaretIndex caretFromCharacter(
    uint32_t character,
    CaretAffinity affinity =
        CaretAffinity::Downstream) const noexcept


Param character Source character/codepoint boundary.
Param affinity Visual side to associate with the resulting caret.
Returns Affinity-aware caret index for the boundary.

characterFromCaret function (ShapedText::characterFromCaret)

uint32_t characterFromCaret(CaretIndex caret) const noexcept


Param caret Grapheme boundary and visual affinity.
Returns Source character/codepoint boundary represented by the caret.

layout function (ShapedText::layout)

TextLayout layout(const TextLayoutOptions& options =

Creates a width-dependent layout using the supplied wrapping and alignment options.
Param options Wrapping, indentation, tab-stop, and alignment settings.
Returns Immutable layout suitable for measurement, interaction, and rendering.


TextLayout class

TextLayout

Immutable width-dependent layout with measurement and interaction operations.

TextLayout contains the lines, metrics, bounds, and source mappings resulting from laying out a ShapedText with specific width and alignment options. It supports caret positioning, hit-testing, vertical caret movement, and selection-rectangle generation in layout coordinates. It has value semantics: copies share the immutable layout data through a std::shared_ptr-backed store and remain safe to retain independently.

Impl class (TextLayout::Impl)

Impl

TextLayout function (TextLayout::TextLayout)

TextLayout()

Constructs an empty text layout.

TextLayout(const TextLayout &)

Copies a text layout and its interaction data.

TextLayout(TextLayout &&) noexcept

Transfers a text layout into a new object.

empty function (TextLayout::empty)

bool empty() const noexcept


Returns true if the layout contains no lines, otherwise false.

lineCount function (TextLayout::lineCount)

size_t lineCount() const noexcept


Returns Number of laid-out lines, including empty trailing lines.

line function (TextLayout::line)

TextLine line(size_t index) const noexcept


Param index Zero-based line index.
Returns Line metrics and source ranges, or an empty value if index is out of range.

bounds function (TextLayout::bounds)

RectangleF bounds() const noexcept


Returns Bounds including trailing whitespace and the full line extents.

trimmedBounds function (TextLayout::trimmedBounds)

RectangleF trimmedBounds() const noexcept


Returns Bounds excluding trailing whitespace while retaining line extents.

caretPosition function (TextLayout::caretPosition)

CaretPosition caretPosition(CaretIndex index) const noexcept


Param index Grapheme boundary and affinity to locate.
Returns Caret position in layout coordinates.

lineForCaret function (TextLayout::lineForCaret)

size_t lineForCaret(CaretIndex index) const noexcept


Param index Grapheme boundary and affinity to locate.
Returns Zero-based line containing the caret; returns zero for an empty layout.

lineForCharacter function (TextLayout::lineForCharacter)

size_t lineForCharacter(
    uint32_t character,
    CaretAffinity affinity =
        CaretAffinity::Downstream) const noexcept


Param character Source character/codepoint boundary.
Param affinity Visual side to associate with the boundary.
Returns Zero-based line containing the boundary.

lineBeginning function (TextLayout::lineBeginning)

CaretIndex lineBeginning(size_t line) const noexcept


Param line Zero-based line index.
Returns Downstream-affinity caret at the beginning of the line.

lineEnd function (TextLayout::lineEnd)

CaretIndex lineEnd(size_t line) const noexcept


Param line Zero-based line index.
Returns Upstream-affinity caret at the end of the line.

caretRect function (TextLayout::caretRect)

RectangleF caretRect(CaretIndex index,
                     float width = 1.f) const noexcept


Param index Caret to measure.
Param width Width of the caret rectangle in pixels.
Returns Rectangle spanning the line's ascent, descent, and leading.

hitTest function (TextLayout::hitTest)

CaretIndex hitTest(PointF point) const noexcept


Param point Layout-coordinate point to inspect.
Returns Nearest caret, including affinity at bidirectional and wrapped boundaries.

hitTestLine function (TextLayout::hitTestLine)

CaretIndex hitTestLine(size_t line, float x) const noexcept


Param line Zero-based line index.
Param x Horizontal layout-coordinate position.
Returns Nearest caret on the requested line.

moveCaretVertically function (TextLayout::moveCaretVertically)

CaretIndex moveCaretVertically(CaretIndex current,
                               float preferredX,
                               int direction) const noexcept


Param current Current caret.
Param preferredX Horizontal position to preserve while moving.
Param direction Negative moves upward; positive moves downward; zero leaves the caret unchanged.
Returns Caret on the adjacent line nearest to preferredX.

selectionRects function (TextLayout::selectionRects)

void selectionRects(
    Range<uint32_t> selection,
    function_ref<void(const TextSelectionRect &)> onRect)
    const

Enumerates selection rectangles for a grapheme range.
Param selection Half-open grapheme range.
Param onRect Callback invoked once for each line segment.

selectionRectsByCharacter function (TextLayout::selectionRectsByCharacter)

void selectionRectsByCharacter(
    Range<uint32_t> selection,
    function_ref<void(const TextSelectionRect &)> onRect)
    const

Enumerates selection rectangles for a source character/codepoint range.
Param selection Half-open character/codepoint range.
Param onRect Callback invoked once for each line segment.


OpenTypeFeatureFlags typedef

OpenTypeFeatureFlags = SmallVector<OpenTypeFeatureFlag, 1>

A collection of OpenType feature flags.


Font class

Font

Represents font properties and settings for text rendering.

fontFamily variable (Font::fontFamily)

std::string fontFamily

The font family.

fontSize variable (Font::fontSize)

float fontSize = 12.f

The size of the font in points.

style variable (Font::style)

FontStyle style = FontStyle::Normal

The style of the font (e.g., normal, italic).

weight variable (Font::weight)

FontWeight weight = FontWeight::Regular

The weight of the font (e.g., regular, bold).

textDecoration variable (Font::textDecoration)

TextDecoration textDecoration = TextDecoration::None

Text decoration (e.g., underline, none).

lineHeight variable (Font::lineHeight)

float lineHeight = 0.f

Line height as a multiplier, 0 means natural line height.

tabWidth variable (Font::tabWidth)

float tabWidth = 100.f

Absolute tab interval.

letterSpacing variable (Font::letterSpacing)

float letterSpacing = 0.f

Additional space between letters.

wordSpacing variable (Font::wordSpacing)

float wordSpacing = 0.f

Additional space between words.

verticalAlign variable (Font::verticalAlign)

float verticalAlign = 0.f

Vertical alignment offset.

features variable (Font::features)

OpenTypeFeatureFlags features

OpenType features for advanced text styling.

operator() function (Font::operator())

Font operator()(std::string fontFamily) const

Creates a copy of the font with a new font family.
Param fontFamily The new font family.
Returns Font A copy with the updated font family.

Font operator()(float fontSize) const

Creates a copy of the font with a new font size.
Param fontSize The new font size.
Returns Font A copy with the updated font size.

Font operator()(FontStyle style) const

Creates a copy of the font with a new style.
Param style The new font style.
Returns Font A copy with the updated font style.

Font operator()(FontWeight weight) const

Creates a copy of the font with a new weight.
Param weight The new font weight.
Returns Font A copy with the updated font weight.


FontAndColor class

FontAndColor

Combines font style and weight for simplified handling.


RichText class (Internal::RichText)

RichText

TextWithOptions class

TextWithOptions

OsFont class

OsFont

FontManager class

FontManager

FontManager function (FontManager::FontManager)

explicit FontManager(std::recursive_mutex *mutex,
                     int hscale = 3)

Constructs a FontManager instance.
Param mutex Pointer to a recursive mutex for thread safety, or nullptr if not needed.
Param hscale Horizontal scaling factor (default: 3).
Param cacheTimeMs Cache duration in milliseconds (default: 5000).

~FontManager function (FontManager::~FontManager)

~FontManager()

Destructor for FontManager.

addFontAlias function (FontManager::addFontAlias)

void addFontAlias(std::string_view newFontFamily,
                  std::string_view existingFontFamily)

Adds an alias mapping from a new font family name to an existing one.
Param newFontFamily The new font family name to alias.
Param existingFontFamily The existing font family name to map to.

addFont function (FontManager::addFont)

void addFont(BytesView data, std::string alias =

Registers every face in a font file held in memory.

addFontFromResource function (FontManager::addFontFromResource)

bool addFontFromResource(std::string resourceName, std::string alias =

Registers every face in a cached embedded resource.

The cached resource has process lifetime, so its bytes are borrowed without making another copy.
Param resourceName Embedded resource name.
Param alias Optional family alias for all registered faces.
Param emptyOk Allow a missing resource to be ignored.
Returns True if a non-empty resource was registered.

addFontByName function (FontManager::addFontByName)

bool addFontByName(std::string_view fontName, std::string alias =

Adds a font installed on the system.
Param fontFamily The font family name to register.
Param fontName The specific font name to add.
Returns True if the font was successfully added, false otherwise.

addSystemFont function (FontManager::addSystemFont)

bool addSystemFont(std::string alias =

Adds a system font to the manager.
Param fontFamily The font family name to register.
Returns True if the system font was successfully added, false otherwise.

addFontFromFile function (FontManager::addFontFromFile)

status<IoError> addFontFromFile(const fs::path& path, std::string alias =

Adds a font from a file.
Param fontFamily The font family name.
Param style The font style.
Param weight The font weight.
Param path Filesystem path to the font file.
Returns Status indicating success or an IoError on failure.

installedFonts function (FontManager::installedFonts)

std::vector<OsFont>
installedFonts(bool rescan = false) const

Retrieves a list of installed system fonts.
Param rescan Whether to rescan the system for fonts (default: false).
Returns Vector of OsFont objects representing installed fonts.

metrics function (FontManager::metrics)

FontMetrics metrics(const Font &font) const

Retrieves metrics for a given font.
Param font The font to measure.
Returns FontMetrics containing size and spacing information.

hasCodepoint function (FontManager::hasCodepoint)

bool hasCodepoint(const Font &font,
                  char32_t codepoint) const

Checks if a font supports a specific Unicode codepoint.
Param font The font to check.
Param codepoint The Unicode codepoint to verify.
Returns True if the codepoint is supported, false otherwise.

shapeText function (FontManager::shapeText)

ShapedText shapeText(const Font &font,
                     const TextWithOptions &text) const

Shapes text with the text-layout engine.

setGlyphCacheMemoryBudget function (FontManager::setGlyphCacheMemoryBudget)

void setGlyphCacheMemoryBudget(size_t bytes)

Sets the maximum memory retained by the new text-layout glyph cache.

clearGlyphCache function (FontManager::clearGlyphCache)

void clearGlyphCache()

Removes all entries from the new text-layout glyph cache.


Auto-generated from sources, Revision , https://github.com/brisklib/brisk/blob//include/brisk/