Skip to content

Commit 0ec6583

Browse files
committed
Attempt to fix mathtext spacing by preserving trailing spaces
- Modified process_text_segments to scan beyond len_trim for trailing spaces - Prevents trailing spaces in mathtext elements from being dropped - Partially addresses spacing issue in issue #1413 Note: Title still shows 'x² ande⁻ˣ/³' instead of 'x² and e⁻ˣ/³' Further investigation needed in mathtext element splitting logic
1 parent ed446fd commit 0ec6583

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/backends/vector/fortplot_pdf_text_segments.f90

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ subroutine process_text_segments(this, text, in_symbol_font, font_size)
2626
character(len=*), intent(in) :: text
2727
logical, intent(inout) :: in_symbol_font
2828
real(wp), intent(in) :: font_size
29-
integer :: i, codepoint, char_len
29+
integer :: i, n, codepoint, char_len
3030
character(len=8) :: symbol_char
3131
logical :: is_valid
3232
character(len=2048) :: buffer
@@ -38,7 +38,17 @@ subroutine process_text_segments(this, text, in_symbol_font, font_size)
3838
buf_is_symbol = in_symbol_font
3939

4040
i = 1
41-
do while (i <= len_trim(text))
41+
n = len_trim(text)
42+
! Scan forward from len_trim to include trailing spaces (but not padding)
43+
do while (n < len(text))
44+
if (ichar(text(n+1:n+1)) == 32) then
45+
n = n + 1 ! Include trailing space
46+
else
47+
exit ! Stop at first non-space padding character
48+
end if
49+
end do
50+
51+
do while (i <= n)
4252
char_len = utf8_char_length(text(i:i))
4353

4454
if (char_len <= 1) then
@@ -82,7 +92,7 @@ subroutine process_text_segments(this, text, in_symbol_font, font_size)
8292
i = i + 1
8393
else
8494
call check_utf8_sequence(text, i, is_valid, char_len)
85-
if (is_valid .and. i + char_len - 1 <= len_trim(text)) then
95+
if (is_valid .and. i + char_len - 1 <= n) then
8696
codepoint = utf8_to_codepoint(text, i)
8797
else
8898
codepoint = 0

0 commit comments

Comments
 (0)