fortplot_braille Module

Braille subpixel canvas for the text backend.

A braille canvas maps each terminal character cell to a 2-by-4 grid of dots and encodes the set dots as a Unicode braille codepoint (U+2800 + bitmask). This gives line and scatter data glyphs four times the vertical and twice the horizontal resolution of plain ASCII cells, while axes, ticks, and labels stay ordinary text.

Dot-bit layout matches Drawille's pixel map: column 0 (left): dot1=0x01 dot2=0x02 dot3=0x04 dot7=0x40 column 1 (right): dot4=0x08 dot5=0x10 dot6=0x20 dot8=0x80


Derived Types

type, public ::  braille_canvas_t

Components

Type Visibility Attributes Name Initial
integer, public :: n_cols = 0
integer, public :: n_rows = 0
integer, public :: sub_w = 0
integer, public :: sub_h = 0
integer, public, allocatable :: mask(:,:)

Functions

public function create_braille_canvas(n_cols, n_rows) result(canvas)

Build a blank braille canvas sized to a text grid of n_cols by n_rows character cells. Subpixel resolution is 2n_cols by 4n_rows dots.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: n_cols
integer, intent(in) :: n_rows

Return Value type(braille_canvas_t)

public pure function braille_dot_bit(local_x, local_y) result(bit)

Bit value for one dot within a cell. local_x in {0,1} (left/right), local_y in {0,1,2,3} (top to bottom). Out-of-range positions have no dot and return 0 so an invalid position never sets a spurious bit.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: local_x
integer, intent(in) :: local_y

Return Value integer

public pure function braille_mask_valid(mask) result(valid)

A mask is a valid braille bitmask only within [0, 255]; any other value carries dot bits that do not exist in the U+2800 block.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: mask

Return Value logical

public pure function braille_codepoint(mask) result(cp)

Codepoint for a braille mask, clamped into the valid block so an invalid mask can never encode outside U+2800..U+28FF.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: mask

Return Value integer

public pure function braille_char(mask) result(utf8)

UTF-8 encoding of the braille codepoint for a mask. Invalid masks are clamped before encoding (braille_mask_valid reports the raw value).

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: mask

Return Value character(len=3)


Subroutines

public subroutine set_braille_pixel(canvas, x_sub, y_sub)

Turn on the subpixel dot at absolute subpixel coordinates (x_sub in [0, sub_w), y_sub in [0, sub_h)). Coordinates outside the canvas are ignored, so callers never corrupt an out-of-range cell.

Arguments

Type IntentOptional Attributes Name
type(braille_canvas_t), intent(inout) :: canvas
integer, intent(in) :: x_sub
integer, intent(in) :: y_sub

public subroutine braille_draw_line(canvas, x0, y0, x1, y1)

Rasterize a line between two subpixel coordinates with Bresenham's algorithm, setting every visited dot.

Arguments

Type IntentOptional Attributes Name
type(braille_canvas_t), intent(inout) :: canvas
integer, intent(in) :: x0
integer, intent(in) :: y0
integer, intent(in) :: x1
integer, intent(in) :: y1