From ebba71064efa3f12d6b735725639797ab9396af7 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 15 Apr 2021 22:48:09 -0400 Subject: graphics: font: Add ascender/descender fields to . --- chickadee/graphics/font.scm | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/chickadee/graphics/font.scm b/chickadee/graphics/font.scm index 3635676..416680d 100644 --- a/chickadee/graphics/font.scm +++ b/chickadee/graphics/font.scm @@ -50,6 +50,8 @@ load-font font? font-face + font-ascender + font-descender font-line-height font-line-width font-bold? @@ -68,11 +70,14 @@ (advance font-char-advance)) (define-record-type - (make-font face bold? italic? line-height chars kernings sprite-batches) + (make-font face bold? italic? ascender descender line-height chars kernings + sprite-batches) font? (face font-face) (bold? font-bold?) (italic? font-italic?) + (ascender font-ascender) + (descender font-descender) (line-height font-line-height) (chars font-chars) (kernings font-kernings) @@ -197,10 +202,12 @@ display it at POINT-SIZE. By default, the ASCII character is used." (hashq-set! batches texture (make-sprite-batch texture)))) (let ((style (face-style-name face))) (match (size-metrics (face-size face)) - ((_ _ _ _ _ _ height _) + ((_ _ _ _ ascender descender height _) (make-font (face-family-name face) (and (string-match ".*[B,b]old.*" style) #t) (and (string-match ".*[I,i]talic.*" style) #t) + (/ ascender 64.0) + (/ descender 64.0) (/ height 64.0) chars kernings @@ -236,7 +243,8 @@ image may have MARGIN pixels of empty space around its border." (kernings (make-hash-table)) (batches (make-hash-table))) (hashq-set! batches texture (make-sprite-batch texture)) - (make-font face #f #f tile-height chars kernings batches))) + (make-font face #f #f (exact->inexact tile-height) 0.0 + (exact->inexact tile-height) chars kernings batches))) (define (load-bitmap-font file) "Load the AngelCode formatted bitmap font within FILE. The file @@ -412,7 +420,7 @@ extension must be either .xml or .fnt." (face (attr info 'face)) (bold? (attr info 'bold (const #t))) (italic? (attr info 'italic (const #t))) - (line-height (attr common 'lineHeight string->number)) + (line-height (exact->inexact (attr common 'lineHeight string->number))) (image-width (attr common 'scaleW string->number)) (image-height (attr common 'scaleH string->number)) (pages (parse-pages ((sxpath '(font pages page)) tree))) @@ -426,7 +434,7 @@ extension must be either .xml or .fnt." (hash-for-each (lambda (id texture) (hashq-set! batches texture (make-sprite-batch texture))) pages) - (make-font face bold? italic? line-height chars kernings batches))) + (make-font face bold? italic? line-height 0.0 line-height chars kernings batches))) (define (font-ref font char) (hashv-ref (font-chars font) char)) -- cgit v1.2.3