Skip to content

Commit cd66d08

Browse files
committed
Fix mathtext spacing - preserve trailing spaces in width calculation
- Fixed render_mathtext_element_pdf to include trailing spaces in width - Added text_len calculation that scans beyond len_trim for spaces - Fixes title spacing: 'x² and e⁻ˣ/³' now displays correctly - Completes mathtext spacing fix for issue #1413 Before: 'x² ande⁻ˣ/³' (missing space) After: 'x² and e⁻ˣ/³' (correct spacing)
1 parent 0ec6583 commit cd66d08

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/backends/vector/fortplot_pdf_mathtext_render.f90

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ subroutine render_mathtext_element_pdf(this, element, x_pos, baseline_y, &
5050

5151
real(wp) :: elem_font_size, elem_y
5252
real(wp) :: char_width
53-
integer :: i, codepoint, char_len
53+
integer :: i, codepoint, char_len, text_len
5454
real(wp) :: sym_w, rad_width, top_y
5555

5656
elem_font_size = base_font_size * element%font_size_ratio
@@ -100,7 +100,17 @@ subroutine render_mathtext_element_pdf(this, element, x_pos, baseline_y, &
100100

101101
char_width = 0.0_wp
102102
i = 1
103-
do while (i <= len_trim(element%text))
103+
! Calculate width including trailing spaces by scanning beyond len_trim
104+
text_len = len_trim(element%text)
105+
do while (text_len < len(element%text))
106+
if (element%text(text_len+1:text_len+1) == ' ') then
107+
text_len = text_len + 1
108+
else
109+
exit
110+
end if
111+
end do
112+
113+
do while (i <= text_len)
104114
char_len = utf8_char_length(element%text(i:i))
105115
if (char_len == 0) then
106116
codepoint = iachar(element%text(i:i))

0 commit comments

Comments
 (0)