fortrangoingonforty/fortty / 15b48a8

Browse files

Fix text and cursor alignment using font ascender

Use ascender (not cell_height) for baseline positioning. Text baseline
is now at y + ascender, leaving room below for descenders. Cursor
rendering updated to align properly with text glyphs.
Authored by espadonne
SHA
15b48a87b47fbe0249622dfab93012f86aee454f
Parents
a7f901b
Tree
08d7108

1 changed file

StatusFile+-
M src/fortty.f90 12 10
src/fortty.f90modified
@@ -33,7 +33,7 @@ program fortty
3333
   integer :: response_len
3434
   real :: x, y, r, g, b, bg_r, bg_g, bg_b
3535
   type(cell_t), allocatable :: sb_line(:)
36
-  integer :: cell_width, cell_height  ! From font metrics
36
+  integer :: cell_width, cell_height, ascender  ! From font metrics
3737
   real(8) :: current_time, last_time, blink_timer
3838
   logical :: cursor_blink_visible
3939
   type(selection_t) :: sel
@@ -173,9 +173,11 @@ program fortty
173173
   ! Get cell dimensions from font metrics
174174
   cell_width = ren%font%cell_width
175175
   cell_height = ren%font%cell_height
176
+  ascender = ren%font%ascender
176177
   if (cell_width < 1) cell_width = 10  ! Fallback
177178
   if (cell_height < 1) cell_height = 18  ! Fallback
178
-  print *, "Font cell size:", cell_width, "x", cell_height
179
+  if (ascender < 1) ascender = cell_height - 4  ! Fallback estimate
180
+  print *, "Font cell size:", cell_width, "x", cell_height, " ascender:", ascender
179181
 
180182
   ! Share cell dimensions with window module for mouse selection
181183
   call window_set_cell_size(cell_width, cell_height)
@@ -317,8 +319,8 @@ program fortty
317319
             r = real(cell%fg%r) / 255.0
318320
             g = real(cell%fg%g) / 255.0
319321
             b = real(cell%fg%b) / 255.0
320
-            ! Text baseline is at cell bottom; add cell_height to position correctly
321
-            call renderer_draw_char(ren, x, y + real(cell_height), cell%codepoint, r, g, b, 1.0)
322
+            ! Baseline is at y + ascender (not cell bottom - descenders need room below)
323
+            call renderer_draw_char(ren, x, y + real(ascender), cell%codepoint, r, g, b, 1.0)
322324
           end if
323325
         end do
324326
       else
@@ -344,8 +346,8 @@ program fortty
344346
               r = real(cell%fg%r) / 255.0
345347
               g = real(cell%fg%g) / 255.0
346348
               b = real(cell%fg%b) / 255.0
347
-              ! Text baseline is at cell bottom; add cell_height to position correctly
348
-              call renderer_draw_char(ren, x, y + real(cell_height), cell%codepoint, r, g, b, 1.0)
349
+              ! Baseline is at y + ascender (consistent with scrollback rendering)
350
+              call renderer_draw_char(ren, x, y + real(ascender), cell%codepoint, r, g, b, 1.0)
349351
             end if
350352
           end do
351353
         end if
@@ -361,15 +363,15 @@ program fortty
361363
 
362364
         select case (term%cursor%style)
363365
           case (CURSOR_BLOCK)
364
-            ! Filled block cursor
366
+            ! Filled block cursor - cover the full cell
365367
             call renderer_draw_rect(ren, x, y, real(cell_width), real(cell_height), &
366368
                                     0.7, 0.7, 0.7, 0.8)
367369
           case (CURSOR_UNDERLINE)
368
-            ! Underline at bottom of cell
369
-            call renderer_draw_rect(ren, x, y + real(cell_height) - 2.0, &
370
+            ! Underline at the baseline position (y + ascender)
371
+            call renderer_draw_rect(ren, x, y + real(ascender), &
370372
                                     real(cell_width), 2.0, 0.7, 0.7, 0.7, 1.0)
371373
           case (CURSOR_BAR)
372
-            ! Vertical bar at left of cell
374
+            ! Vertical bar at left of cell - full cell height
373375
             call renderer_draw_rect(ren, x, y, 2.0, real(cell_height), 0.7, 0.7, 0.7, 1.0)
374376
           case default
375377
             ! Fallback to block