From 649fe208ca96891faf249b7fb0a884a5d9d40b58 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 21 Apr 2018 20:07:38 -0400 Subject: render: font: Add font-line-width procedure. * chickadee/render/font.scm (font-line-width): New procedure. --- chickadee/render/font.scm | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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! 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 -- cgit v1.2.3