source: project/wiki/freetype @ 4569

Last change on this file since 4569 was 4569, checked in by Alex Shinn, 13 years ago

Changes applied for ashinn (220.97.133.113) through svnwiki:

File size: 6.4 KB
Line 
1[[tags: egg]]
2
3freetype bindings for Chicken.
4
5[[toc:]]
6
7=== Usage
8
9<enscript highlight=scheme>
10(use freetype)
11(define lib (ft-init-freetype))
12(define face
13  (ft-new-face lib "/usr/share/fonts/truetype/msttcorefonts/arial.ttf"))
14(ft-set-char-size face 0 (* 16 64) 300 300)
15(ft-set-pixel-sizes face 0 16)
16(define AV (make-ft-vector))
17(ft-get-kerning face
18                (ft-get-char-index face (char->integer #\A))
19                (ft-get-char-index face (char->integer #\V))
20                FT_KERNING_DEFAULT
21                AV)
22(print "AV kerning: " (ft-vector-x AV) " " (ft-vector-y AV))
23</enscript>
24
25  AV kerning: -64 0
26
27=== Procedures
28
29 '''procedure:''' (ft-init-freetype) => <error-code>
30
31Create a new freetype library object.
32
33 '''procedure:''' (ft-new-face <lib> <path>) => <face>
34
35Load a font face from a file.  Returns #f if the file can't be loaded.
36
37 '''procedure:''' (ft-set-char-size <face> <char-width> <char-height> <hres> <vres>) => <error-code>
38
39 '''procedure:''' (ft-set-pixel-size <face> <pixel-width> <pixel-height>) => <error-code>
40
41 '''procedure:''' (ft-get-char-index <face> <char-code>) => <glyph-index>
42
43 '''procedure:''' (ft-load-glyph <face> <glyph-index> <load-flags>) => <error-code>
44
45 '''procedure:''' (ft-load-char <face> <char-code> <load-flags>) => <error-code>
46
47 '''procedure:''' (ft-render-glyph <glyph> <render-flags>) => <error-code>
48
49 '''procedure:''' (ft-get-kerning <face> <left> <right> <kerning-mode> <vector>) => <error-code>
50
51 '''procedure:''' (ft-select-charmap <face> <charmap-index>) => <error-code>
52
53 '''procedure:''' (ft-set-transform <face> <matrix> <delta>)
54
55=== Records
56
57==== ft-vector
58
59* make-ft-vector
60* free-ft-vector
61* ft-vector-x
62* ft-vector-y
63* ft-vector-x-set!
64* ft-vector-y-set!
65
66==== ft-matrix
67
68* make-ft-matrix
69* free-ft-matrix
70* ft-matrix-xx
71* ft-matrix-xy
72* ft-matrix-yx
73* ft-matrix-yy
74* ft-matrix-xx-set!
75* ft-matrix-xy-set!
76* ft-matrix-yx-set!
77* ft-matrix-yy-set!
78
79==== ft-face
80
81* free-ft-face
82* ft-face-num-faces
83* ft-face-face-index
84* ft-face-face-flags
85* ft-face-style-flags
86* ft-face-num-glyphs
87* ft-face-family-name
88* ft-face-style-name
89* ft-face-num-fixed-sizes
90* ft-face-available-sizes
91* ft-face-num-charmaps
92* ft-face-charmaps
93* ft-face-generic-data
94* ft-face-generic-finalizer
95* ft-face-bbox-xmin
96* ft-face-bbox-xmax
97* ft-face-bbox-ymin
98* ft-face-bbox-ymax
99* ft-face-units-per-EM
100* ft-face-ascender
101* ft-face-descender
102* ft-face-height
103* ft-face-max-advance-width
104* ft-face-max-advance-height
105* ft-face-underline-position
106* ft-face-underline-thickness
107* ft-face-glyph
108* ft-face-size
109* ft-face-charmap
110
111==== ft-glyph-slot
112
113* free-ft-glyph-slot
114* ft-glyph-slot-library
115* ft-glyph-slot-face
116* ft-glyph-slot-next
117* ft-glyph-slot-reserved
118* ft-glyph-slot-generic-data
119* ft-glyph-slot-generic-finalizer
120* ft-glyph-slot-metrics
121* ft-glyph-slot-linear-hori-advance
122* ft-glyph-slot-linear-vert-advance
123* ft-glyph-slot-advance-x
124* ft-glyph-slot-advance-y
125* ft-glyph-slot-format
126* ft-glyph-slot-bitmap
127* ft-glyph-slot-outline
128* ft-glyph-slot-num_subglyphs
129* ft-glyph-slot-subglyphs
130* ft-glyph-slot-control-data
131* ft-glyph-slot-control-len
132* ft-glyph-slot-lsb-delta
133* ft-glyph-slot-rsb-delta
134
135==== ft-bitmap
136
137* free-ft-bitmap
138* ft-bitmap-rows
139* ft-bitmap-width
140* ft-bitmap-pitch
141* ft-bitmap-buffer
142* ft-bitmap-num-grays
143* ft-bitmap-pixel-mode
144* ft-bitmap-palette-mode
145* ft-bitmap-palette
146
147==== ft-glyph-metrics
148
149* free-ft-glyph-metrics
150* ft-glyph-metrics-width
151* ft-glyph-metrics-height
152* ft-glyph-metrics-hori-bearing-x
153* ft-glyph-metrics-hori-bearing-y
154* ft-glyph-metrics-hori-advance
155* ft-glyph-metrics-vert-bearing-x
156* ft-glyph-metrics-vert-bearing-y
157* ft-glyph-metrics-vert-advance
158
159
160=== Enums
161
162==== Encodings
163
164*  FT_ENCODING_NONE
165*  FT_ENCODING_MS_SYMBOL
166*  FT_ENCODING_UNICODE
167*  FT_ENCODING_SJIS
168*  FT_ENCODING_GB2312
169*  FT_ENCODING_BIG5
170*  FT_ENCODING_WANSUNG
171*  FT_ENCODING_JOHAB
172*  FT_ENCODING_ADOBE_STANDARD
173*  FT_ENCODING_ADOBE_EXPERT
174*  FT_ENCODING_ADOBE_CUSTOM
175*  FT_ENCODING_ADOBE_LATIN_1
176*  FT_ENCODING_OLD_LATIN_2
177*  FT_ENCODING_APPLE_ROMAN
178
179==== Face Flags
180
181*  FT_FACE_FLAG_SCALABLE
182*  FT_FACE_FLAG_FIXED_SIZES
183*  FT_FACE_FLAG_FIXED_WIDTH
184*  FT_FACE_FLAG_SFNT
185*  FT_FACE_FLAG_HORIZONTAL
186*  FT_FACE_FLAG_VERTICAL
187*  FT_FACE_FLAG_KERNING
188*  FT_FACE_FLAG_FAST_GLYPHS
189*  FT_FACE_FLAG_MULTIPLE_MASTERS
190*  FT_FACE_FLAG_GLYPH_NAMES
191*  FT_FACE_FLAG_EXTERNAL_STREAM
192
193==== Style Flags
194
195*  FT_STYLE_FLAG_ITALIC
196*  FT_STYLE_FLAG_BOLD
197
198==== Open Flags
199
200*  FT_OPEN_MEMORY
201*  FT_OPEN_STREAM
202*  FT_OPEN_PATHNAME
203*  FT_OPEN_DRIVER
204*  FT_OPEN_PARAMS
205
206==== Load Options
207
208*  FT_LOAD_DEFAULT
209*  FT_LOAD_NO_SCALE
210*  FT_LOAD_NO_HINTING
211*  FT_LOAD_RENDER
212*  FT_LOAD_NO_BITMAP
213*  FT_LOAD_VERTICAL_LAYOUT
214*  FT_LOAD_FORCE_AUTOHINT
215*  FT_LOAD_CROP_BITMAP
216*  FT_LOAD_PEDANTIC
217*  FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
218*  FT_LOAD_NO_RECURSE
219*  FT_LOAD_IGNORE_TRANSFORM
220*  FT_LOAD_MONOCHROME
221*  FT_LOAD_LINEAR_DESIGN
222*  FT_LOAD_TARGET_NORMAL
223*  FT_LOAD_TARGET_LIGHT
224*  FT_LOAD_TARGET_MONO
225*  FT_LOAD_TARGET_LCD
226*  FT_LOAD_TARGET_LCD_V
227
228==== Render Mode
229
230*  FT_RENDER_MODE_NORMAL
231*  FT_RENDER_MODE_LIGHT
232*  FT_RENDER_MODE_MONO
233*  FT_RENDER_MODE_LCD
234*  FT_RENDER_MODE_LCD_V
235*  FT_RENDER_MODE_MAX
236
237==== Kerning Mode
238
239*  FT_KERNING_DEFAULT
240*  FT_KERNING_UNFITTED
241*  FT_KERNING_UNSCALED
242
243=== Example
244
245<enscript highlight=scheme>
246;; Render an anti-aliased "A" to text using the chars 0-9 for grayscale.
247
248(use freetype lolevel)
249
250(define lib (ft-init-freetype))
251(define face
252  (ft-new-face lib "/usr/share/fonts/truetype/msttcorefonts/arial.ttf"))
253(ft-set-char-size face 0 (* 16 64) 300 300)
254(ft-set-pixel-sizes face 0 16)
255
256(ft-load-char face (char->integer #\A) FT_LOAD_DEFAULT)
257(ft-render-glyph (ft-face-glyph face) FT_RENDER_MODE_NORMAL)
258
259(let* ((glyph (ft-face-glyph face))
260       (bitmap (ft-glyph-slot-bitmap glyph))
261       (width (ft-bitmap-width bitmap))
262       (rows (ft-bitmap-rows bitmap))
263       (buf (ft-bitmap-buffer bitmap)))
264  (do ((i 0 (+ i 1)))
265      ((= i rows))
266    (do ((j 0 (+ j 1)))
267        ((= j width))
268      (let ((d (pointer-u8-ref
269                   (pointer-offset buf (+ j (* i width))))))
270        (write-char (if (zero? d)
271                        #\space
272                        (integer->char
273                         (+ (inexact->exact (truncate (/ d 25.6)))
274                            (char->integer #\0)))))))
275    (newline)))
276</enscript>
277
278      393   
279      666   
280     09190   
281     37 73   
282     63 36   
283    090 090 
284    27   72 
285    6999996 
286   090   090
287   26     72
288   63     36
289  080     080
290
291=== Author
292
293[[Alex Shinn]]
294
295=== License
296
297BSD
298
299=== History
300
301; 0.1 : initial release
Note: See TracBrowser for help on using the repository browser.