CLX-TRUETYPE


Next: , Up: (dir)

Introduction

clx-truetype renders TrueType fonts over X11 drawable (window or pixmap) using CLX, XRender, ZPB-TTF, CL-VECTORS.

clx-truetype was originally written for mcclim font rendering by Gilbert Baumann and Andy Hefner.

clx-truetype is maintained in Git:

     git clone git://github.com/filonenko-mikhail/clx-truetype

will get you a local copy.

     http://github.com/filonenko-mikhail/clx-truetype/

is the GitHub project page, where the issue tracker is located.

Table of Contents


Next: , Previous: Top, Up: Top

1 Overview

clx-truetype is library for text rendering over X11 drawable using CLX, XRender, ZPB-TTF, CL-VECTORS.

TrueType font metrics

ttf-metrics.png


Next: , Previous: Overview, Up: Top

2 Examples

Drawing text is quite simple.

First and only one time step is loading font cache using cache-fonts. If you add font to your system, you should call it again.

     (cache-fonts)

Make instance of font:

     (font (make-instance 'font :family "Times New Roman" :subfamily "Bold Italic"
                                   :size 12 :antialiased t))

Draw it using draw-text or draw-text-line functions:

     (draw-text window grackon font "The quick brown fox jumps over the lazy dog." 100 100)

Move <<cursor>> using baseline-to-baseline distance.

Here it is complete example. Just insert it into repl, and evaluate (show-window).

     (defpackage #:clx-truetype-test
       (:nicknames :xft-test)
       (:use #:cl #:xft)
       (:export show-window))
     
     (in-package :clx-truetype-test)
     
     (defvar *display* (xlib:open-default-display))
     
     (defvar *screen* (xlib:display-default-screen *display*))
     (defvar *root* (xlib:screen-root *screen*))
     
     (defun show-window ()
       (let* ((black (xlib:screen-black-pixel *screen*))
              (white (xlib:screen-white-pixel *screen*))
              (window
                (xlib:create-window :parent *root* :x 0 :y 0 :width 640 :height 480
                               :class :input-output
                               :background white
                               :event-mask '(:key-press :key-release :exposure :button-press
                                             :structure-notify)))
              (grackon (xlib:create-gcontext
                        :drawable window
     		   :foreground black
     		   :background white))
              (font (make-instance 'font :family "Times New Roman" :subfamily "Bold Italic"
                                   :size 12 :antialiased t)))
         (unwind-protect
              (progn
                (xlib:map-window window)
                (setf (xlib:gcontext-foreground grackon) black)
                (xlib:event-case (*display* :force-output-p t
                                       :discard-p t)
                  (:exposure ()
                             (draw-text window grackon font "The quick brown fox jumps over the lazy dog." 100 100)
                             (when (= 0 (random 2))
                               (rotatef (xlib:gcontext-foreground grackon) (xlib:gcontext-background grackon)))
                             (draw-text window grackon font "Съешь же ещё этих мягких французских булок, да выпей чаю." 100 (+ 100 (baseline-to-baseline window font)))
                             (setf (font-antialiased font) (= 0 (random 2)))
                             (if (= 0 (random 2))
                                 (setf (font-subfamily font) "Regular")
                                 (setf (font-subfamily font) "Italic"))
                             (draw-text window grackon font "Жебракують філософи при ґанку церкви в Гадячі, ще й шатро їхнє п’яне знаємо." 100 (+ 100 (* 2 (baseline-to-baseline window font))))
                             (draw-text window grackon font "Press space to exit. Нажмите пробел для выхода." 100 (+ 100 (* 3 (baseline-to-baseline window font)))))
                  (:button-press () t)
                  (:key-press (code state) (char= #\Space (xlib:keycode->character *display* code state)))))
           (progn
             (xlib:free-gcontext grackon)
             (xlib:destroy-window window)
             (xlib:display-force-output *display*)))))

Result is

example.png


Next: , Previous: Examples, Up: Top

3 Dictionary

— Package: xft

Package contains api for TrueType text rendering using clx, XRender. Glyphs information is obtained by zpb-ttf. Font rasterization is made by cl-vectors.

— Variable: *font-dirs*

List of directories, which contain TrueType fonts.

— Function: cache-fonts

Caches fonts from *font-dirs* directories.

— Function: cache-font-file pathname

Caches font file.

— Function: get-font-families

Returns cached font families.

— Function: get-font-subfamilies font-family

Returns font subfamilies for current font-family. For e.g. regular, italic, bold, etc.

— Class: font

Class precedence list: font, standard-object, t

Slots:

Class for representing font information.

— Generic Function: font-equal font1 font2

Returns t if two font objects are equal, else returns nil.

— Function: screen-default-dpi screen

Returns default dpi for screen. pixel width * 25.4/millimeters width

— Function: screen-dpi screen

Returns current dpi for screen.

— Function: (setf screen-dpi) value screen

Sets current dpi for screen.

— Function: font-ascent drawable font

Returns ascent of font. drawable must be window, pixmap or screen.

— Function: font-descent drawable font

Returns descent of font. drawable must be window, pixmap or screen.

— Function: font-line-gap drawable font

Returns line gap of font. drawable must be window, pixmap or screen.

— Function: baseline-to-baseline drawable font

Returns distance between baselines of font. drawable must be window, pixmap or screen. ascent - descent + line gap

— Function: text-bounding-box drawable font string &key start end

Returns text bounding box. drawable must be window, pixmap or screen. Text bounding box is only for contours. Bounding box for space (#x20) is zero.

— Function: text-width drawable font string &key start end

Returns width of text bounding box. drawable must be window, pixmap or screen.

— Function: text-height drawable font string &key start end

Returns height of text bounding box. drawable must be window, pixmap or screen.

— Function: text-line-bounding-box drawable font string &key start end

Returns text line bounding box. drawable must be window, pixmap or screen. Text line bounding box is bigger than text bounding box. It's height is ascent + descent, width is sum of advance widths minus sum of kernings.

— Function: text-line-width drawable font string &key start end

Returns width of text line bounding box. drawable must be window, pixmap or screen. It is sum of advance widths minus sum of kernings.

— Function: text-line-height drawable font string &key start end

Returns height of text line bounding box. drawable must be window, pixmap or screen.

— Function: xmin bounding-box

Returns left side x of bounding-box

— Function: ymin bounding-box

Returns bottom side y of bounding-box

— Function: xmax bounding-box

Returns right side x of bounding-box

— Function: ymax bounding-box

Returns top side y of bounding-box

— Function: draw-text drawable gcontext font string x y &key start end draw-background-p

Draws text string using font on drawable with graphic context gcontext. x, y are the left point of base line. start and end are used for substring rendering. If gcontext has background color, text bounding box will be filled with it. Text line bounding box is bigger than text bounding box. drawable must be window or pixmap.

— Function: draw-text-line drawable gcontext font string x y &key start end draw-background-p

Draws text string using font on drawable with graphic context gcontext. x, y are the left point of base line. start and end are used for substring rendering. If gcontext has background color, text line bounding box will be filled with it. Text line bounding box is bigger than text bounding box. drawable must be window or pixmap.

— Function: font-lines-height drawable font lines-count

Returns text lines height in pixels. For one line height is ascender+descender. For more than one line height is ascender+descender+linegap.


Next: , Previous: Dictionary, Up: Top

Appendix A Concept Index


Next: , Previous: Concept Index, Up: Top

Appendix B Function Index


Next: , Previous: Function Index, Up: Top

Appendix C Variable Index


Next: , Previous: Variable Index, Up: Top

Appendix D Type Index


Previous: Type Index, Up: Top

Colophon

This manual is maintained in Texinfo, and automatically translated into other forms (e.g. HTML or pdf). If you're reading this manual in one of these non-Texinfo translated forms, that's fine, but if you want to modify this manual, you are strongly advised to seek out a Texinfo version and modify that instead of modifying a translated version.