fortplot_text_layout Module

Shared text layout utilities (width/height calculations, mathtext helpers)



Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: DEFAULT_FONT_SIZE = 16
integer, public, parameter :: TITLE_FONT_SIZE = 20
integer, public, parameter :: LABEL_FONT_SIZE = 16
integer, public, parameter :: TICK_FONT_SIZE = 13

Functions

public pure function has_mathtext(text) result(is_mathtext)

Check if text contains math segments delimited by '$...$'

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: text

Return Value logical

public function calculate_text_width(text) result(width)

Calculate the pixel width of text using STB TrueType with UTF-8 support Supports mathematical notation with superscripts and subscripts

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: text

Return Value integer

public function calculate_text_width_with_size(text, pixel_height) result(width)

Calculate text width using a specific font size Supports mathematical notation with superscripts and subscripts

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: text
real(kind=wp), intent(in) :: pixel_height

Return Value integer

public function calculate_text_height(text) result(height)

Calculate the pixel height of text using STB TrueType Supports mathematical notation with superscripts and subscripts

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: text

Return Value integer

public function calculate_text_descent(text) result(descent_pixels)

Calculate the descent (below baseline) portion of text in pixels

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: text

Return Value integer

public recursive function calculate_mathtext_width_internal(elements, base_font_size) result(total_width)

Calculate total width of mathematical text elements

Arguments

Type IntentOptional Attributes Name
type(mathtext_element_t), intent(in) :: elements(:)
real(kind=wp), intent(in) :: base_font_size

Return Value integer

public function calculate_text_width_with_size_internal(text, pixel_height) result(width)

Internal text width calculation to avoid circular dependencies

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: text
real(kind=wp), intent(in) :: pixel_height

Return Value integer

public function calculate_text_height_with_size_internal(pixel_height) result(height)

Internal text height calculation based on font metrics

Arguments

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

Return Value integer

public function calculate_mathtext_height_internal(elements, base_font_size) result(total_height)

Calculate total height of mathematical text elements

Arguments

Type IntentOptional Attributes Name
type(mathtext_element_t), intent(in) :: elements(:)
real(kind=wp), intent(in) :: base_font_size

Return Value integer


Subroutines

public subroutine preprocess_math_text(input_text, result_text, result_len)

Remove '$' delimiters and escape '^'/'_' outside math so they render literally

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: input_text
character(len=*), intent(out) :: result_text
integer, intent(out) :: result_len