@@ -19,6 +19,7 @@ module font_mod |
| 19 | 19 | integer :: cell_height = 0 |
| 20 | 20 | integer :: ascender = 0 |
| 21 | 21 | integer :: descender = 0 |
| 22 | + integer :: fallback_ascender = 0 ! For baseline alignment with fallback font |
| 22 | 23 | logical :: loaded = .false. |
| 23 | 24 | logical :: has_fallback = .false. |
| 24 | 25 | end type font_t |
@@ -194,6 +195,7 @@ contains |
| 194 | 195 | character(len=*), intent(in) :: path |
| 195 | 196 | character(len=256) :: c_path |
| 196 | 197 | integer(c_int) :: err |
| 198 | + integer(c_int) :: fb_cell_w, fb_cell_h, fb_asc, fb_desc |
| 197 | 199 | |
| 198 | 200 | if (.not. font%loaded) return |
| 199 | 201 | if (len_trim(path) == 0) return |
@@ -209,6 +211,10 @@ contains |
| 209 | 211 | end if |
| 210 | 212 | |
| 211 | 213 | font%has_fallback = .true. |
| 214 | + |
| 215 | + ! Get fallback font metrics for baseline alignment |
| 216 | + call fortty_ft_get_metrics(font%ft_face_fallback, fb_cell_w, fb_cell_h, fb_asc, fb_desc) |
| 217 | + font%fallback_ascender = fb_asc |
| 212 | 218 | end subroutine font_load_fallback |
| 213 | 219 | |
| 214 | 220 | ! Check if a glyph exists in the primary font |
@@ -278,6 +284,11 @@ contains |
| 278 | 284 | glyph%advance = adv |
| 279 | 285 | glyph%valid = .true. |
| 280 | 286 | |
| 287 | + ! Normalize baseline: adjust bearing_y for ascender difference between fonts |
| 288 | + if (used_fallback) then |
| 289 | + glyph%bearing_y = glyph%bearing_y - (font%fallback_ascender - font%ascender) |
| 290 | + end if |
| 291 | + |
| 281 | 292 | end function font_render_glyph_with_fallback |
| 282 | 293 | |
| 283 | 294 | ! Find a font that supports a specific codepoint using fontconfig |