truetype_font_t Derived Type

type, public :: truetype_font_t


Components

Type Visibility Attributes Name Initial
integer(kind=int8), public, allocatable :: data(:)
integer, public :: fontstart = 0
integer, public :: num_glyphs = 0
integer, public :: loca = 0
integer, public :: head = 0
integer, public :: glyf = 0
integer, public :: hhea = 0
integer, public :: hmtx = 0
integer, public :: kern = 0
integer, public :: gpos = 0
integer, public :: index_map = 0
integer, public :: index_to_loc_format = 0
logical, public :: initialized = .false.

Type-Bound Procedures

procedure, public :: init => font_init

  • private function font_init(self, filepath) result(success)

    Load a TrueType font from file.

    Arguments

    Type IntentOptional Attributes Name
    class(truetype_font_t), intent(inout) :: self
    character(len=*), intent(in) :: filepath

    Return Value logical

procedure, public :: cleanup => font_cleanup

  • private subroutine font_cleanup(self)

    Release all font resources.

    Arguments

    Type IntentOptional Attributes Name
    class(truetype_font_t), intent(inout) :: self

procedure, public :: scale_for_pixel_height => font_scale

  • private function font_scale(self, pixel_height) result(scale)

    Get scale factor for desired pixel height.

    Arguments

    Type IntentOptional Attributes Name
    class(truetype_font_t), intent(in) :: self
    real(kind=dp), intent(in) :: pixel_height

    Return Value real(kind=dp)

procedure, public :: get_vmetrics => font_vmetrics

  • private subroutine font_vmetrics(self, ascent, descent, line_gap)

    Get vertical font metrics (unscaled).

    Arguments

    Type IntentOptional Attributes Name
    class(truetype_font_t), intent(in) :: self
    integer, intent(out) :: ascent
    integer, intent(out) :: descent
    integer, intent(out) :: line_gap

procedure, public :: get_hmetrics => font_hmetrics

  • private subroutine font_hmetrics(self, codepoint, advance_width, left_side_bearing)

    Get horizontal metrics for a codepoint (unscaled).

    Arguments

    Type IntentOptional Attributes Name
    class(truetype_font_t), intent(in) :: self
    integer, intent(in) :: codepoint
    integer, intent(out) :: advance_width
    integer, intent(out) :: left_side_bearing

procedure, public :: find_glyph_index => font_find_glyph

  • private function font_find_glyph(self, codepoint) result(glyph_index)

    Map a Unicode codepoint to a glyph index.

    Arguments

    Type IntentOptional Attributes Name
    class(truetype_font_t), intent(in) :: self
    integer, intent(in) :: codepoint

    Return Value integer

procedure, public :: get_bitmap_box => font_bitmap_box

  • private subroutine font_bitmap_box(self, codepoint, scale_x, scale_y, ix0, iy0, ix1, iy1)

    Get bitmap bounding box for a codepoint.

    Arguments

    Type IntentOptional Attributes Name
    class(truetype_font_t), intent(in) :: self
    integer, intent(in) :: codepoint
    real(kind=dp), intent(in) :: scale_x
    real(kind=dp), intent(in) :: scale_y
    integer, intent(out) :: ix0
    integer, intent(out) :: iy0
    integer, intent(out) :: ix1
    integer, intent(out) :: iy1

procedure, public :: get_codepoint_bitmap => font_get_bitmap

  • private subroutine font_get_bitmap(self, scale_x, scale_y, codepoint, bitmap, width, height, xoff, yoff)

    Render a codepoint to an 8-bit grayscale bitmap. The bitmap is returned as an allocatable int8 array.

    Arguments

    Type IntentOptional Attributes Name
    class(truetype_font_t), intent(in) :: self
    real(kind=dp), intent(in) :: scale_x
    real(kind=dp), intent(in) :: scale_y
    integer, intent(in) :: codepoint
    integer(kind=int8), intent(out), allocatable :: bitmap(:)
    integer, intent(out) :: width
    integer, intent(out) :: height
    integer, intent(out) :: xoff
    integer, intent(out) :: yoff

procedure, public :: make_codepoint_bitmap => font_make_bitmap

  • private subroutine font_make_bitmap(self, output, out_w, out_h, out_stride, scale_x, scale_y, codepoint)

    Render a codepoint into a user-provided buffer.

    Arguments

    Type IntentOptional Attributes Name
    class(truetype_font_t), intent(in) :: self
    integer(kind=int8), intent(inout) :: output(:)
    integer, intent(in) :: out_w
    integer, intent(in) :: out_h
    integer, intent(in) :: out_stride
    real(kind=dp), intent(in) :: scale_x
    real(kind=dp), intent(in) :: scale_y
    integer, intent(in) :: codepoint