fplotlib_render module#

renderer_t is the format-independent drawing contract. Drawing does not require a file, an encoded format, or a bytes method. encoded_renderer_t extends it with bytes for PDF/SVG/PNG/EPS output; recording and interactive targets can implement drawing alone.

The built-in text family has size, weight and slant styles. There is no serif/monospace family selector that silently substitutes the sans font. Finished glyph runs identify the actual built-in glyphs they use.

No renderer call returns an error. A call that breaks the contract, such as drawing before open_canvas, a coordinate that is not finite or lies beyond MAX_COORD (1e15 points), an end_group without a begin_group or asking for bytes before close_canvas, stops the program with a message naming the rule (see fplotlib_status).

renderer_t makes these checks itself, the same way for every backend. Its public methods are non_overridable: each checks the call and keeps the canvas state, then calls the backend’s deferred *_impl method (open_canvas_impl, draw_path_impl, …, bytes_impl). A new backend implements only those, and may assume every call it receives is valid. The *_impl bindings are public only so that a backend in another module can implement them; code that draws calls the methods without the suffix, since calling an *_impl directly skips the checks.

A filled paint fills with its fill_rule, FILL_NONZERO by default or FILL_EVENODD, the same in every backend: SVG and PDF name the rule, EPS uses eofill, and PNG takes the parity of the winding number its rasterizer sums, where nonzero clamps it. At a pixel that edges cross, PNG takes the sum of their signed areas for the area they cover, for either rule, which can overstate it where contours overlap there. Under a frame’s clip, or a paint clip in a transformed frame, an even-odd fill is filled whole and its coverage multiplied by the clip’s: exact inside the clip, and off by up to a quarter of a pixel either way where the shape’s edge and the clip’s cross the same pixel, a quarter too little for two halves that coincide and a quarter too much for a shape that ends just where the clip begins. Strokes and glyphs always fill nonzero.

begin_frame(matrix, clip) and end_frame() scope an affine transform and a rectangular clip: matrix is [a,b,c,d,e,f], mapping a point of the frame to (a*x+c*y+e, b*x+d*y+f) in its parent, and clip, when on, is in the frame’s coordinates. Like the other methods they are checked once, in renderer_t: the canvas must be open, the matrix finite and within MAX_COORD, and the clip a box of nonnegative size. Frames and groups nest: each must end inside whatever began after it, and none may be open at close_canvas. Every built-in backend implements begin_frame_impl and end_frame_impl. A custom target that does not accepts only the identity transform without a clip, and stops on any other rather than ignoring it.

SVG, PDF and EPS write a frame’s matrix with fifteen significant digits of each factor, and the numbers inside it with one more decimal than six for each power of ten the frames open magnify by (bounded by sqrt(|A|_1 |A|_inf) of each matrix, so a frame that only moves adds none), up to forty and to seventeen significant digits: a frame that scales by 4e-7 keeps its scale, and one that magnifies a million times still writes what it holds to a millionth of a point on the page, as far as the viewer computes that finely; many PDF and PostScript readers work in single precision. frame_decimals(r) gives that count for the frames open now, and frame_decimals(r, outer=.true.) for those around the innermost, for a custom encoder to use the same; the cap at seventeen significant digits is fmt_num’s, which a custom formatter applies itself.

The PNG backend draws a frame’s content transformed and clipped; a paint clip inside a clipped frame is cut as geometry, or for an even-odd fill applied as the mask above, so its edges are antialiased rather than whole pixels. Contours that overlap where a clip cuts them can saturate a pixel there that they cover only in part, as overlapping contours can anywhere. A dashed stroke is built in the frame’s coordinates, but what the rasterizer may skip of it is decided by the canvas: a segment is walked only where the matrix maps it into the canvas, widened on each side by the pen as the matrix stretches that axis, and only over the dashes whose place along the line falls within the canvas’s span along it, and a cap’s length beyond. A segment whose dashes cross the canvas as stripes less than half a pixel apart is drawn solid at the pattern’s cover, the approximation fplotlib_status describes; that bounds every walk by the canvas, however the frame shrinks, shears or stretches. Everywhere else the dashes are what walking every one of them draws.

Pages are not part of renderer_t: pdf_renderer_t%new_page starts the next page of a PDF, and the other formats write one page each.

fplotlib_render (module)#

Variables

VERB_MOVEinteger, parameter, Default = 1
VERB_LINEinteger, parameter, Default = 2
VERB_CUBICinteger, parameter, Default = 3
VERB_CLOSEinteger, parameter, Default = 4
CAP_BUTTinteger, parameter, Default = 0
CAP_ROUNDinteger, parameter, Default = 1
CAP_SQUAREinteger, parameter, Default = 2
JOIN_MITERinteger, parameter, Default = 0
JOIN_ROUNDinteger, parameter, Default = 1
JOIN_BEVELinteger, parameter, Default = 2
FILL_NONZEROinteger, parameter, Default = 0
FILL_EVENODDinteger, parameter, Default = 1
ANCHOR_STARTinteger, parameter, Default = 0
ANCHOR_MIDDLEinteger, parameter, Default = 1
ANCHOR_ENDinteger, parameter, Default = 2
BASE_ALPHABETICinteger, parameter, Default = 0
BASE_MIDDLEinteger, parameter, Default = 1
BASE_TOPinteger, parameter, Default = 2
BASE_BOTTOMinteger, parameter, Default = 3
WEIGHT_NORMALinteger, parameter, Default = 0
WEIGHT_BOLDinteger, parameter, Default = 1
SLANT_ROMANinteger, parameter, Default = 0
SLANT_ITALICinteger, parameter, Default = 1
MAX_DASHinteger, parameter, Default = 8
MAX_COORDreal(kind=dp), parameter, Default = 1.0e15_dp
MAX_PEN_PER_DASHreal(kind=dp), parameter, Default = 100.0_dp

Types

clip_t (type)#

clip_t (type)
Attributes:
onlogical, Default = .false.
xreal(kind=dp), Default = 0.0_dp
yreal(kind=dp), Default = 0.0_dp
wreal(kind=dp), Default = 0.0_dp
hreal(kind=dp), Default = 0.0_dp

paint_t (type)#

paint_t (type)
Attributes:
filledlogical, Default = .false.
fill_rgbinteger, dimension(3), Default = [0, 0, 0]
fill_alphareal(kind=dp), Default = 1.0_dp
fill_ruleinteger, Default = FILL_NONZERO
strokedlogical, Default = .false.
stroke_rgbinteger, dimension(3), Default = [0, 0, 0]
stroke_alphareal(kind=dp), Default = 1.0_dp
line_widthreal(kind=dp), Default = 1.0_dp
capinteger, Default = CAP_BUTT
joininteger, Default = JOIN_MITER
miter_limitreal(kind=dp), Default = 10.0_dp
n_dashinteger, Default = 0
dashreal(kind=dp), dimension(MAX_DASH), Default = 0.0_dp
dash_offsetreal(kind=dp), Default = 0.0_dp
cliptype(clip_t)

font_t (type)#

font_t (type)
Attributes:
sizereal(kind=dp), Default = 10.0_dp
weightinteger, Default = WEIGHT_NORMAL
slantinteger, Default = SLANT_ROMAN

glyphrun_t (type)#

glyphrun_t (type)
Attributes:
ninteger, Default = 0
gidinteger, allocatable, dimension(:)
fontinteger, allocatable, dimension(:)
firstinteger, allocatable, dimension(:)
lastinteger, allocatable, dimension(:)
xreal(kind=dp), allocatable, dimension(:)
yreal(kind=dp), allocatable, dimension(:)
sizereal(kind=dp), allocatable, dimension(:)
textcharacter(len=:), allocatable
source_mathlogical, Default = .false.

renderer_t (type)#

renderer_t (type)
Attributes:
widthreal(kind=dp), Default = 0.0_dp
heightreal(kind=dp), Default = 0.0_dp
is_openlogical, Default = .false.
is_finishedlogical, Default = .false.
n_groupinteger, Default = 0
n_frameinteger, Default = 0
scopescharacter(len=:), allocatable
Procedures:

encoded_renderer_t (type)#

encoded_renderer_t (type)
Procedures:

Procedures

frame_decimals (function)#

function frame_decimals(r, outer) -> d
Arguments:
rclass(renderer_t), intent(in)
outerlogical, intent(in), optional
Returns:
dinteger

bytes (function)#

function bytes(self) -> b
Arguments:
selfclass(encoded_renderer_t), intent(in)
Returns:
bcharacter(len=:), allocatable

begin_frame_impl (subroutine)#

subroutine begin_frame_impl(self, matrix, clip)
Arguments:
selfclass(renderer_t), intent(inout)
matrixreal(kind=dp), intent(in), dimension(6)
cliptype(clip_t), intent(in)

end_frame_impl (subroutine)#

subroutine end_frame_impl(self)
Arguments:
selfclass(renderer_t), intent(inout)

begin_group_impl (subroutine)#

subroutine begin_group_impl(self, name)
Arguments:
selfclass(renderer_t), intent(inout)
namecharacter(len=*), intent(in)

end_group_impl (subroutine)#

subroutine end_group_impl(self)
Arguments:
selfclass(renderer_t), intent(inout)

open_canvas (subroutine)#

subroutine open_canvas(self, width, height, bg_rgb, bg_alpha, x0, y0)
Arguments:
selfclass(renderer_t), intent(inout)
widthreal(kind=dp), intent(in)
heightreal(kind=dp), intent(in)
bg_rgbinteger, intent(in), optional, dimension(3)
bg_alphareal(kind=dp), intent(in), optional
x0real(kind=dp), intent(in), optional
y0real(kind=dp), intent(in), optional

close_canvas (subroutine)#

subroutine close_canvas(self)
Arguments:
selfclass(renderer_t), intent(inout)

draw_path (subroutine)#

subroutine draw_path(self, x, y, verbs, n_verb, paint)
Arguments:
selfclass(renderer_t), intent(inout)
xreal(kind=dp), intent(in), dimension(:)
yreal(kind=dp), intent(in), dimension(:)
verbsinteger, intent(in), dimension(:)
n_verbinteger, intent(in)
painttype(paint_t), intent(in)

draw_rect (subroutine)#

subroutine draw_rect(self, x, y, w, h, paint, radius)
Arguments:
selfclass(renderer_t), intent(inout)
xreal(kind=dp), intent(in)
yreal(kind=dp), intent(in)
wreal(kind=dp), intent(in)
hreal(kind=dp), intent(in)
painttype(paint_t), intent(in)
radiusreal(kind=dp), intent(in), optional

draw_circle (subroutine)#

subroutine draw_circle(self, cx, cy, r, paint)
Arguments:
selfclass(renderer_t), intent(inout)
cxreal(kind=dp), intent(in)
cyreal(kind=dp), intent(in)
rreal(kind=dp), intent(in)
painttype(paint_t), intent(in)

draw_markers (subroutine)#

subroutine draw_markers(self, x, y, mx, my, mverbs, n_mverb, paint)
Arguments:
selfclass(renderer_t), intent(inout)
xreal(kind=dp), intent(in), dimension(:)
yreal(kind=dp), intent(in), dimension(:)
mxreal(kind=dp), intent(in), dimension(:)
myreal(kind=dp), intent(in), dimension(:)
mverbsinteger, intent(in), dimension(:)
n_mverbinteger, intent(in)
painttype(paint_t), intent(in)

draw_glyphs (subroutine)#

subroutine draw_glyphs(self, x, y, run, paint, angle)
Arguments:
selfclass(renderer_t), intent(inout)
xreal(kind=dp), intent(in)
yreal(kind=dp), intent(in)
runtype(glyphrun_t), intent(in)
painttype(paint_t), intent(in)
anglereal(kind=dp), intent(in)

draw_image (subroutine)#

subroutine draw_image(self, x, y, w, h, rgba, nx, ny, paint)
Arguments:
selfclass(renderer_t), intent(inout)
xreal(kind=dp), intent(in)
yreal(kind=dp), intent(in)
wreal(kind=dp), intent(in)
hreal(kind=dp), intent(in)
rgbainteger, (:, :, :), intent(in), dimension(:,:,:)
nxinteger, intent(in)
nyinteger, intent(in)
painttype(paint_t), intent(in)

begin_group (subroutine)#

subroutine begin_group(self, name)
Arguments:
selfclass(renderer_t), intent(inout)
namecharacter(len=*), intent(in)

end_group (subroutine)#

subroutine end_group(self)
Arguments:
selfclass(renderer_t), intent(inout)

begin_frame (subroutine)#

subroutine begin_frame(self, matrix, clip)
Arguments:
selfclass(renderer_t), intent(inout)
matrixreal(kind=dp), intent(in), dimension(6)
cliptype(clip_t), intent(in)

end_frame (subroutine)#

subroutine end_frame(self)
Arguments:
selfclass(renderer_t), intent(inout)