diff options
-rw-r--r-- | chickadee/render/font.scm | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/chickadee/render/font.scm b/chickadee/render/font.scm index 1a01ad4..f63450b 100644 --- a/chickadee/render/font.scm +++ b/chickadee/render/font.scm @@ -42,6 +42,7 @@ font? font-face font-line-height + font-line-width font-bold? font-italic? draw-text* @@ -75,6 +76,17 @@ (set-record-type-printer! <font> display-font) +(define (font-line-width font text) + "Return the width of TEXT when rendered with FONT." + (let loop ((width 0.0) + (i 0)) + (if (< i (string-length text)) + (let ((char (or (font-ref font (string-ref text i)) + (font-ref font #\?)))) + (loop (+ width (font-char-advance char)) + (+ i 1))) + width))) + (define* (load-tile-font file tile-width tile-height characters #:key (face "untitled") (margin 0) (spacing 0)) "Load the font named FACE from FILE, a bitmap image containing the |