freetype bindings for Chicken.

  1. Usage
  2. Procedures
  3. Records
    1. ft-vector
    2. ft-matrix
    3. ft-face
    4. ft-glyph-slot
    5. ft-bitmap
    6. ft-glyph-metrics
  4. Enums
    1. Encodings
    2. Face Flags
    3. Style Flags
    4. Open Flags
    5. Load Options
    6. Render Mode
    7. Kerning Mode
  5. Example
  6. Author
  7. Repository
  8. License
  9. History

Usage

(import 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

[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>)

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.

(import (chicken memory) 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)

(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

Repository

This egg is hosted on the CHICKEN Subversion repository:

https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/freetype

If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.

License

BSD

History

0.2
Port to CHICKEN 5
0.1
initial release