[cl-pdf-devel] Font loading on demand

Marc Battyani marc.battyani at fractalconcept.com
Sat Mar 13 23:32:15 UTC 2004


From: "Dmitri Ivanov" <divanov at aha.ru> writes:


> 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))

Well, in fact load-fonts does not load the fonts. ;-) I shoud rename it to
load-std-pdf-fonts-afm as it only loads the AFM files for the 14 predefined
pdf fonts.

But I will insert this into load-t1-font and change a few names...

> 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)

You need a default font otherwise you will be forced to specify the font by
a style construct

Marc





More information about the cl-pdf-devel mailing list