4.2 Using fonts

4.2.2 Printing text output

The functionscharblt andstringblt print onto a bitmap a single character and a string respectively. You can specify the font that is used for the character or string.

Print text in some alternate fonts. You might have to load these fonts first for this example to work.

(clear-bitmap *window*)
;; Use the default font first.
(stringblt *window*
  (make-position 20 20) *default-font* "Default Font")

;; Use a roman font. (stringblt *window* (make-position 20 40) (find-font "BOLD-ROMAN") "Bold Roman")

;; Use an italic font. (stringblt *window* (make-position 20 60) (find-font "ITALIC") "ITALIC")

Define a function that prints the contents of a font on a window by using the functioncharblt.

(defun show-font (window font)
  (let ((font (find-font font)))
      font                  ; Check to see that the font exists.
      (let ((window-width (region-width 
                            (window-inside-region window)))
            (window-height (region-height 
                            (window-inside-region window)))
            (font-width (font-fixed-width font))
            (font-height (font-height font)))
        (clear-bitmap window)
        ;; iterate over the characters in this font.
        (loop for char-number from 0 to (font-code-limit font)
              with window-x = 0
              with window-y = font-height
              do (charblt             ; Print the character.
                   (make-position window-x window-y)
                   (character char-number))
              if (>= (+ window-x (* font-width 2)) window-width)
              do (progn (setq window-x 0)
                        (setq window-y (+ window-y font-height)))
              do (setq window-x (+ window-x font-width))))
      (format t "Sorry, this font is not loaded.~%"))))

;; Invoke the function with the default font. (show-font *window* *default-font*)

;; Now try another font. (show-font *window* "BOLD-ROMAN")

Some fonts contain nonprinting characters that have special bit settings and that do not look like normal characters. Nonprinting character sometimes appear as blocks and lines when you display a font.

The Window Tool Kit - 9 SEP 1996

Generated with Harlequin WebMaker