summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2018-04-21 20:07:38 -0400
committerDavid Thompson <dthompson2@worcester.edu>2018-04-21 20:07:38 -0400
commit649fe208ca96891faf249b7fb0a884a5d9d40b58 (patch)
tree23cc230db5edd4a83cb57cebe5d5c1a44d543e33
parentacab405e3c67e508aba618b68a3cf59d7a5d367f (diff)
render: font: Add font-line-width procedure.
* chickadee/render/font.scm (font-line-width): New procedure.
-rw-r--r--chickadee/render/font.scm12
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