Note: This is taken from the Chicken Wiki, where a more recent version could be available.
freetype bindings for Chicken.
(use freetype) (define lib (ft-init-freetype)) (define face (ft-new-face lib "/usr/share/fonts/truetype/msttcorefonts/arial.ttf")) (ft-set-char-size face 0 (* 16 64) 300 300) (ft-set-pixel-sizes face 0 16) (define AV (make-ft-vector)) (ft-get-kerning face (ft-get-char-index face (char->integer #\A)) (ft-get-char-index face (char->integer #\V)) FT_KERNING_DEFAULT AV) (print "AV kerning: " (ft-vector-x AV) " " (ft-vector-y AV))
AV kerning: -64 0
procedure: (ft-init-freetype) => <error-code>
Create a new freetype library object.
procedure: (ft-new-face <lib> <path>) => <face>
Load a font face from a file. Returns #f if the file can't be loaded.
procedure: (ft-set-char-size <face> <char-width> <char-height> <hres> <vres>) => <error-code>
procedure: (ft-set-pixel-size <face> <pixel-width> <pixel-height>) => <error-code>
procedure: (ft-get-char-index <face> <char-code>) => <glyph-index>
procedure: (ft-load-glyph <face> <glyph-index> <load-flags>) => <error-code>
procedure: (ft-load-char <face> <char-code> <load-flags>) => <error-code>
procedure: (ft-render-glyph <glyph> <render-flags>) => <error-code>
procedure: (ft-get-kerning <face> <left> <right> <kerning-mode> <vector>) => <error-code>
procedure: (ft-select-charmap <face> <charmap-index>) => <error-code>
procedure: (ft-set-transform <face> <matrix> <delta>)
;; Render an anti-aliased "A" to text using the chars 0-9 for grayscale. (use freetype lolevel) (define lib (ft-init-freetype)) (define face (ft-new-face lib "/usr/share/fonts/truetype/msttcorefonts/arial.ttf")) (ft-set-char-size face 0 (* 16 64) 300 300) (ft-set-pixel-sizes face 0 16) (ft-load-char face (char->integer #\A) FT_LOAD_DEFAULT) (ft-render-glyph (ft-face-glyph face) FT_RENDER_MODE_NORMAL) (let* ((glyph (ft-face-glyph face)) (bitmap (ft-glyph-slot-bitmap glyph)) (width (ft-bitmap-width bitmap)) (rows (ft-bitmap-rows bitmap)) (buf (ft-bitmap-buffer bitmap))) (do ((i 0 (+ i 1))) ((= i rows)) (do ((j 0 (+ j 1))) ((= j width)) (let ((d (pointer-u8-ref (pointer-offset buf (+ j (* i width)))))) (write-char (if (zero? d) #\space (integer->char (+ (inexact->exact (truncate (/ d 25.6))) (char->integer #\0))))))) (newline)))
393 666 09190 37 73 63 36 090 090 27 72 6999996 090 090 26 72 63 36 080 080
BSD