Text annotation system for fortplot (Issue #55)
Provides comprehensive text annotation functionality with support for: - Multiple coordinate systems (data, figure, axis) - Typography control (font size, alignment, rotation) - Background boxes and arrow annotations - Backend-independent rendering
Follows SOLID principles with clean separation of concerns
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | public, | parameter | :: | COORD_DATA | = | 1 | |
integer, | public, | parameter | :: | COORD_FIGURE | = | 2 | |
integer, | public, | parameter | :: | COORD_AXIS | = | 3 |
4-argument coordinate transformation (figure or axis coordinates)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(text_annotation_t), | intent(in) | :: | annotation | |||
real(kind=wp), | intent(in) | :: | area_or_size(:) | |||
real(kind=wp), | intent(out) | :: | pixel_x | |||
real(kind=wp), | intent(out) | :: | pixel_y |
5-argument coordinate transformation (data coordinates)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(text_annotation_t), | intent(in) | :: | annotation | |||
real(kind=wp), | intent(in) | :: | plot_area(:) | |||
real(kind=wp), | intent(in) | :: | data_bounds(:) | |||
real(kind=wp), | intent(out) | :: | pixel_x | |||
real(kind=wp), | intent(out) | :: | pixel_y |
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
character(len=256), | public | :: | text | = | "" | ||
real(kind=wp), | public | :: | x | = | 0.0_wp | ||
real(kind=wp), | public | :: | y | = | 0.0_wp | ||
integer, | public | :: | coord_type | = | COORD_DATA | ||
real(kind=wp), | public | :: | font_size | = | 12.0_wp | ||
real(kind=wp), | public | :: | rotation | = | 0.0_wp | ||
character(len=16), | public | :: | alignment | = | 'left' | ||
character(len=16), | public | :: | ha | = | 'left' | ||
character(len=16), | public | :: | va | = | 'bottom' | ||
character(len=64), | public | :: | font_family | = | 'DejaVu Sans' | ||
character(len=16), | public | :: | weight | = | 'normal' | ||
character(len=16), | public | :: | style | = | 'normal' | ||
real(kind=wp), | public | :: | color(3) | = | [0.0_wp, 0.0_wp, 0.0_wp] | ||
real(kind=wp), | public | :: | alpha | = | 1.0_wp | ||
logical, | public | :: | has_bbox | = | .false. | ||
logical, | public | :: | bbox | = | .false. | ||
type(annotation_color_t), | public | :: | bbox_color | = | annotation_color_t(1.0_wp, 1.0_wp, 1.0_wp, 1.0_wp) | ||
logical, | public | :: | has_arrow | = | .false. | ||
real(kind=wp), | public | :: | arrow_x | = | 0.0_wp | ||
real(kind=wp), | public | :: | arrow_y | = | 0.0_wp | ||
integer, | public | :: | arrow_coord_type | = | COORD_DATA | ||
real(kind=wp), | public | :: | xytext_x | = | 0.0_wp | ||
real(kind=wp), | public | :: | xytext_y | = | 0.0_wp | ||
integer, | public | :: | xytext_coord_type | = | COORD_DATA | ||
character(len=64), | public | :: | arrowstyle | = | '' |
Create a text annotation with specified properties
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | text | |||
real(kind=wp), | intent(in) | :: | x | |||
real(kind=wp), | intent(in) | :: | y | |||
integer, | intent(in), | optional | :: | coord_type |
Check if annotation is visible within plot area
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(text_annotation_t), | intent(in) | :: | annotation | |||
real(kind=wp), | intent(in) | :: | plot_area(4) |
Clean up text annotation resources
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(text_annotation_t), | intent(inout) | :: | annotation |
Transform annotation coordinates with logarithmic scaling support
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(text_annotation_t), | intent(in) | :: | annotation | |||
real(kind=wp), | intent(in) | :: | plot_area(4) | |||
real(kind=wp), | intent(in) | :: | data_bounds(4) | |||
logical, | intent(in) | :: | log_scale_x | |||
logical, | intent(in) | :: | log_scale_y | |||
real(kind=wp), | intent(out) | :: | pixel_x | |||
real(kind=wp), | intent(out) | :: | pixel_y |
Calculate aligned text position based on alignment settings
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(text_annotation_t), | intent(in) | :: | annotation | |||
real(kind=wp), | intent(in) | :: | text_width | |||
real(kind=wp), | intent(in) | :: | text_height | |||
real(kind=wp), | intent(out) | :: | adjusted_x | |||
real(kind=wp), | intent(out) | :: | adjusted_y |
Calculate bounding box for rotated text
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(text_annotation_t), | intent(in) | :: | annotation | |||
real(kind=wp), | intent(out) | :: | bounds(4) |
Validate annotation coordinate values
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(text_annotation_t), | intent(in) | :: | annotation | |||
logical, | intent(out) | :: | valid | |||
character(len=256), | intent(out) | :: | error_message |
Validate annotation parameter values
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(text_annotation_t), | intent(in) | :: | annotation | |||
logical, | intent(out) | :: | valid | |||
character(len=256), | intent(out) | :: | error_message |
Comprehensive annotation validation combining coordinate and parameter checks
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(text_annotation_t), | intent(in) | :: | annotation | |||
logical, | intent(out) | :: | valid | |||
character(len=*), | intent(out) | :: | error_message |
Safe text metrics calculation with error handling
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(text_annotation_t), | intent(in) | :: | annotation | |||
real(kind=wp), | intent(out) | :: | width | |||
real(kind=wp), | intent(out) | :: | height | |||
logical, | intent(out) | :: | valid | |||
character(len=*), | intent(out) | :: | error_message |
Load font system from specified path
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | font_path | |||
logical, | intent(out) | :: | loaded | |||
character(len=*), | intent(out) | :: | error_message |
Alias for validate_annotation_parameters for API compatibility
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(text_annotation_t), | intent(in) | :: | annotation | |||
logical, | intent(out) | :: | valid | |||
character(len=*), | intent(out) | :: | error_message |
Calculate text dimensions for given annotation
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(text_annotation_t), | intent(in) | :: | annotation | |||
real(kind=wp), | intent(out) | :: | width | |||
real(kind=wp), | intent(out) | :: | height |
Calculate anchor position based on alignment settings
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(text_annotation_t), | intent(in) | :: | annotation | |||
real(kind=wp), | intent(in) | :: | text_width | |||
real(kind=wp), | intent(in) | :: | text_height | |||
real(kind=wp), | intent(out) | :: | anchor_x | |||
real(kind=wp), | intent(out) | :: | anchor_y |
Calculate bounding box for rotated text
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(text_annotation_t), | intent(in) | :: | annotation | |||
real(kind=wp), | intent(out) | :: | bounds(4) |
Select font family with fallback mechanism
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(text_annotation_t), | intent(in) | :: | annotation | |||
character(len=*), | intent(out) | :: | selected_font | |||
logical, | intent(out) | :: | font_found |
Validate typography-specific parameters with normalization support
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(text_annotation_t), | intent(in) | :: | annotation | |||
logical, | intent(out) | :: | valid | |||
character(len=*), | intent(out) | :: | error_message |