summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sdl2/bindings/ttf.scm3
-rw-r--r--sdl2/ttf.scm14
2 files changed, 17 insertions, 0 deletions
diff --git a/sdl2/bindings/ttf.scm b/sdl2/bindings/ttf.scm
index 9808fd4..fb3b717 100644
--- a/sdl2/bindings/ttf.scm
+++ b/sdl2/bindings/ttf.scm
@@ -57,6 +57,9 @@ RETURN-TYPE and accept arguments of ARG-TYPES."
(define-foreign ttf-font-height
int "TTF_FontHeight" '(*))
+(define-foreign ttf-glyph-metrics
+ int "TTF_GlyphMetrics" (list '* uint16 '* '* '* '* '*))
+
(define-foreign ttf-render-text-solid
'* "TTF_RenderText_Solid" (list '* '* sdl-color))
diff --git a/sdl2/ttf.scm b/sdl2/ttf.scm
index 4c4d3be..0a73b8a 100644
--- a/sdl2/ttf.scm
+++ b/sdl2/ttf.scm
@@ -71,6 +71,20 @@ size is POINT-SIZE."
"Return the maximum height of FONT."
(ffi:ttf-font-height (unwrap-font font)))
+(define (font-glyph-metrics font char)
+ "Return a 5-element list containing the metrics of CHAR in FONT in
+the following format: (minx maxx miny maxy advance)"
+ (let ((bv (make-s32vector 5)))
+ (if (zero? (ffi:ttf-glyph-metrics (unwrap-font font)
+ (char->integer char)
+ (bytevector->pointer bv)
+ (bytevector->pointer bv 4)
+ (bytevector->pointer bv 8)
+ (bytevector->pointer bv 16)
+ (bytevector->pointer bv 32)))
+ (s32vector->list bv)
+ (sdl-error "font-glyph-metrics" "failed to get glyph metrics"))))
+
(define (render-font-solid font text color)
"Render TEXT, a UTF-8 encoded string, using FONT and COLOR, the
foreground color, and return a surface containing the results."