|
| 1 | +program test_title_centering_raster |
| 2 | + !! Verifies raster title centering over plot area |
| 3 | + use fortplot_layout, only: plot_margins_t, plot_area_t, calculate_plot_area |
| 4 | + use fortplot_constants, only: TITLE_VERTICAL_OFFSET |
| 5 | + use fortplot_text, only: calculate_text_width |
| 6 | + use fortplot_raster_axes, only: compute_title_position |
| 7 | + use, intrinsic :: iso_fortran_env, only: wp => real64 |
| 8 | + implicit none |
| 9 | + |
| 10 | + type(plot_margins_t) :: margins |
| 11 | + type(plot_area_t) :: plot_area |
| 12 | + integer, parameter :: CANVAS_WIDTH = 640 |
| 13 | + integer, parameter :: CANVAS_HEIGHT = 480 |
| 14 | + |
| 15 | + character(len=*), parameter :: title_text = 'Simple Sine Wave' |
| 16 | + character(len=500) :: processed_text, escaped_text |
| 17 | + integer :: processed_len |
| 18 | + real(wp) :: title_px_r, title_py_r |
| 19 | + integer :: expected_px, expected_py, measured_width |
| 20 | + |
| 21 | + margins = plot_margins_t() |
| 22 | + call calculate_plot_area(CANVAS_WIDTH, CANVAS_HEIGHT, margins, plot_area) |
| 23 | + |
| 24 | + call compute_title_position(plot_area, title_text, processed_text, processed_len, & |
| 25 | + escaped_text, title_px_r, title_py_r) |
| 26 | + |
| 27 | + measured_width = calculate_text_width(trim(escaped_text)) |
| 28 | + expected_px = plot_area%left + plot_area%width/2 - measured_width/2 |
| 29 | + expected_py = plot_area%bottom - TITLE_VERTICAL_OFFSET |
| 30 | + |
| 31 | + if (int(title_px_r) /= expected_px) then |
| 32 | + print *, 'FAIL: Title X not centered; got ', int(title_px_r), ' expected ', expected_px |
| 33 | + stop 1 |
| 34 | + end if |
| 35 | + |
| 36 | + if (int(title_py_r) /= expected_py) then |
| 37 | + print *, 'FAIL: Title Y offset incorrect; got ', int(title_py_r), ' expected ', expected_py |
| 38 | + stop 1 |
| 39 | + end if |
| 40 | + |
| 41 | + print *, 'PASS: Title centering matches expected pixel position' |
| 42 | +end program test_title_centering_raster |
| 43 | + |
0 commit comments