Download Manual

Transcript
Chapter 6: Fonts and Colors
34
6 Fonts and Colors
6.1 Fonts
SENSAWAVE provides a font system designed to generate identical output on all supported
raster and vector rendering backends, including PDF, EPS, PNG, PPM and OpenGL.
The supported font faces are FONT_MONOSPACE, FONT_SANSSERIF, FONT_SERIF and FONT_
SYMBOL. Each font except the latter is available in four different styles: FONT_NORMAL, FONT_
BOLD, FONT_ITALIC, FONT_BOLDITALIC. The supported font sizes are FONT_8PT, FONT_10PT,
FONT_12PT, FONT_14PT, FONT_18PT and FONT_24PT.
A font-new call is used to create a font object, and font?, font-name and font-size can
be used to query a font object:
> (define f (font-new FONT_14PT))
> (font? f)
#t
> (font-name f)
"Helvetica"
> (font-size f)
14
The name returned by font-name is the one used for rendering on PDF and EPS backends.
The font-stringascent font-stringdescent and font-stringwidth can be used to calculate string dimensions for a given font:
> (font-stringascent f "a")
8
> (font-stringdescent f "p")
-3
> (font-stringwidth f "Hello World")
75
Unlike normal scheme objects, a font object must be explicitly deleted to free its storage:
> (font-delete f)
The following example renders some of the supported fonts in a framebuffer:
;; examples/fonts.scm
;; displays loadable fonts in a framebuffer window
;; routine to render a font
(define (show-font fbuf face points y)
(let* ((label "ABCDEFGabcdefg12345!#$")
(fnt (font-new points face))
(dy (- (font-stringascent fnt label)
(font-stringdescent fnt label))))
(framebuffer-text fbuf 20 y Black fnt label HORIZONTAL)
(font-delete fnt)
(+ y dy)))