chickadee » freetype

Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

freetype bindings for Chicken.

Usage

(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

Procedures

ft-init-freetypeprocedure

Create a new freetype library object.

ft-new-face <lib> <path>procedure

Load a font face from a file. Returns #f if the file can't be loaded.

ft-set-char-size <face> <char-width> <char-height> <hres> <vres>procedure
ft-set-pixel-size <face> <pixel-width> <pixel-height>procedure
ft-get-char-index <face> <char-code>procedure
ft-load-glyph <face> <glyph-index> <load-flags>procedure
ft-load-char <face> <char-code> <load-flags>procedure
ft-render-glyph <glyph> <render-flags>procedure
ft-get-kerning <face> <left> <right> <kerning-mode> <vector>procedure
ft-select-charmap <face> <charmap-index>procedure
ft-set-transform <face> <matrix> <delta>procedure

Records

ft-vector

ft-matrix

ft-face

ft-glyph-slot

ft-bitmap

ft-glyph-metrics

Enums

Encodings

Face Flags

Style Flags

Open Flags

Load Options

Render Mode

Kerning Mode

Example

;; 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+ 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

Author

Alex Shinn

License

BSD

History

0.1
initial release

Contents »