[cl-pdf-devel] Font loading on demand

Dmitri Ivanov divanov at aha.ru
Sat Mar 13 08:10:48 UTC 2004


Hello,

I suggest protocol as follows.

;;; Autoloading fonts on demand
(defgeneric require-font (name type &key encoding verbose errorp
&allow-other-keys))

(defmethod require-font (name (type (eql :type1)) &key (encoding
*default-encoding*)
                                                       (afm name) (pfb afm)
                                                       verbose (errorp t))
  (setf name (string-downcase name))
  (or (gethash (list name (get-encoding encoding)) *font-cache*)
      (loop for font-dir in *afm-files-directories*
            for afm-truename = (probe-file (make-pathname :name afm :type
"afm"
                                                          :defaults
font-dir))
            when afm-truename
              do (when verbose (format t "~&; Loading font ~s on demand..."
name))
                 (load-t1-font afm-truename
                               (probe-file (make-pathname :name pfb :type
"pfb"
                                                          :defaults
font-dir)))
                 (return (make-instance 'font :name name :encoding
encoding)))
      (if errorp
          (error "Font ~s not found." name)
          nil)))

To really benefit, this fragment should be accompanied by removing the
following from font.lisp:

;(eval-when (:load-toplevel :execute)
;  (load-fonts))

and dropping (pdf:get-font) from the following in
cl-typesetting/specials.lisp:

;(defvar *default-font* (pdf:get-font)) ; DI: Unavailable while loading
module on demand
(defvar *default-font* nil)

--
Sincerely,
Dmitri Ivanov
lisp.ystok.ru





More information about the cl-pdf-devel mailing list