fortplot_stb_truetype Module

Backend-agnostic text rendering using STB TrueType Provides iso_c_binding interface to stb_truetype.h functions



Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: STB_SUCCESS = 1
integer, public, parameter :: STB_ERROR = 0

Derived Types

type, public, bind(C) ::  stb_fontinfo_t

Components

Type Visibility Attributes Name Initial
type(c_ptr), public :: data_ptr = c_null_ptr
integer(kind=c_int), public :: fontstart = 0
integer(kind=c_int), public :: numGlyphs = 0
type(c_ptr), public :: private_data = c_null_ptr

Functions

public function stb_init_font(font_info, font_file_path) result(success)

Initialize font from file path

Arguments

Type IntentOptional Attributes Name
type(stb_fontinfo_t), intent(inout) :: font_info
character(len=*), intent(in) :: font_file_path

Return Value logical

public function stb_scale_for_pixel_height(font_info, pixel_height) result(scale)

Calculate scale factor for desired pixel height

Arguments

Type IntentOptional Attributes Name
type(stb_fontinfo_t), intent(in) :: font_info
real(kind=wp), intent(in) :: pixel_height

Return Value real(kind=wp)

public function stb_find_glyph_index(font_info, codepoint) result(glyph_index)

Find glyph index for Unicode codepoint

Arguments

Type IntentOptional Attributes Name
type(stb_fontinfo_t), intent(in) :: font_info
integer, intent(in) :: codepoint

Return Value integer

public function stb_get_codepoint_bitmap(font_info, scale_x, scale_y, codepoint, width, height, xoff, yoff) result(bitmap_ptr)

Allocate and render character bitmap

Arguments

Type IntentOptional Attributes Name
type(stb_fontinfo_t), intent(in) :: font_info
real(kind=wp), intent(in) :: scale_x
real(kind=wp), intent(in) :: scale_y
integer, intent(in) :: codepoint
integer, intent(out) :: width
integer, intent(out) :: height
integer, intent(out) :: xoff
integer, intent(out) :: yoff

Return Value type(c_ptr)


Subroutines

public subroutine stb_cleanup_font(font_info)

Clean up font resources

Arguments

Type IntentOptional Attributes Name
type(stb_fontinfo_t), intent(inout) :: font_info

public subroutine stb_get_font_vmetrics(font_info, ascent, descent, line_gap)

Get vertical font metrics in unscaled coordinates

Arguments

Type IntentOptional Attributes Name
type(stb_fontinfo_t), intent(in) :: font_info
integer, intent(out) :: ascent
integer, intent(out) :: descent
integer, intent(out) :: line_gap

public subroutine stb_get_codepoint_hmetrics(font_info, codepoint, advance_width, left_side_bearing)

Get horizontal character metrics in unscaled coordinates

Arguments

Type IntentOptional Attributes Name
type(stb_fontinfo_t), intent(in) :: font_info
integer, intent(in) :: codepoint
integer, intent(out) :: advance_width
integer, intent(out) :: left_side_bearing

public subroutine stb_get_codepoint_bitmap_box(font_info, codepoint, scale_x, scale_y, ix0, iy0, ix1, iy1)

Get bounding box for character bitmap

Arguments

Type IntentOptional Attributes Name
type(stb_fontinfo_t), intent(in) :: font_info
integer, intent(in) :: codepoint
real(kind=wp), intent(in) :: scale_x
real(kind=wp), intent(in) :: scale_y
integer, intent(out) :: ix0
integer, intent(out) :: iy0
integer, intent(out) :: ix1
integer, intent(out) :: iy1

public subroutine stb_make_codepoint_bitmap(font_info, output_buffer, out_w, out_h, out_stride, scale_x, scale_y, codepoint)

Render character into provided buffer

Arguments

Type IntentOptional Attributes Name
type(stb_fontinfo_t), intent(in) :: font_info
integer(kind=c_int8_t), intent(inout), target :: output_buffer(*)
integer, intent(in) :: out_w
integer, intent(in) :: out_h
integer, intent(in) :: out_stride
real(kind=wp), intent(in) :: scale_x
real(kind=wp), intent(in) :: scale_y
integer, intent(in) :: codepoint

public subroutine stb_free_bitmap(bitmap_ptr)

Free bitmap allocated by stb_get_codepoint_bitmap

Arguments

Type IntentOptional Attributes Name
type(c_ptr), intent(in) :: bitmap_ptr