Function: bdf-read-font-info
bdf-read-font-info is a byte-compiled function defined in
ps-bdf.el.gz.
Signature
(bdf-read-font-info BDFNAME)
Documentation
Read BDF font file BDFNAME and return information (FONT-INFO) of the file.
BDFNAME must be an absolute file name.
FONT-INFO is a list of the following format:
(BDFFILE MOD-TIME FONT-BOUNDING-BOX
RELATIVE-COMPOSE BASELINE-OFFSET CODE-RANGE MAXLEN OFFSET-VECTOR)
MOD-TIME is last modification time in the same format as current-time.
SIZE is a size of the font on 72 dpi device. This value is got from SIZE record of the font.
FONT-BOUNDING-BOX is the font bounding box as a list of four integers, BBX-WIDTH, BBX-HEIGHT, BBX-XOFF, and BBX-YOFF.
RELATIVE-COMPOSE is an integer value of the font's property
_MULE_RELATIVE_COMPOSE. If the font doesn't have this property, the
value is 0.
BASELINE-OFFSET is an integer value of the font's property
_MULE_BASELINE_OFFSET. If the font doesn't have this property, the
value is 0.
CODE-RANGE is a vector of minimum 1st byte, maximum 1st byte, minimum
2nd byte, maximum 2nd byte, minimum code, maximum code, and default
code. For 1-byte fonts, the first two elements are 0.
MAXLEN is a maximum bytes of one glyph information in the font file.
OFFSET-VECTOR is a vector of a file position which starts bitmap data of the glyph in the font file.
Nth element of OFFSET-VECTOR is a file position for the glyph of code
CODE, where N and CODE are in the following relation:
(bdf-compact-code CODE) => N, (bdf-expand-code N) => CODE
Source Code
;; Defined in /usr/src/emacs/lisp/ps-bdf.el.gz
(defun bdf-read-font-info (bdfname)
"Read `BDF' font file BDFNAME and return information (FONT-INFO) of the file.
BDFNAME must be an absolute file name.
FONT-INFO is a list of the following format:
(BDFFILE MOD-TIME FONT-BOUNDING-BOX
RELATIVE-COMPOSE BASELINE-OFFSET CODE-RANGE MAXLEN OFFSET-VECTOR)
MOD-TIME is last modification time in the same format as `current-time'.
SIZE is a size of the font on 72 dpi device. This value is got
from SIZE record of the font.
FONT-BOUNDING-BOX is the font bounding box as a list of four integers,
BBX-WIDTH, BBX-HEIGHT, BBX-XOFF, and BBX-YOFF.
RELATIVE-COMPOSE is an integer value of the font's property
`_MULE_RELATIVE_COMPOSE'. If the font doesn't have this property, the
value is 0.
BASELINE-OFFSET is an integer value of the font's property
`_MULE_BASELINE_OFFSET'. If the font doesn't have this property, the
value is 0.
CODE-RANGE is a vector of minimum 1st byte, maximum 1st byte, minimum
2nd byte, maximum 2nd byte, minimum code, maximum code, and default
code. For 1-byte fonts, the first two elements are 0.
MAXLEN is a maximum bytes of one glyph information in the font file.
OFFSET-VECTOR is a vector of a file position which starts bitmap data
of the glyph in the font file.
Nth element of OFFSET-VECTOR is a file position for the glyph of code
CODE, where N and CODE are in the following relation:
(bdf-compact-code CODE) => N, (bdf-expand-code N) => CODE"
(let* ((buf (bdf-find-file bdfname))
(maxlen 0)
(relative-compose 'false)
(baseline-offset 0)
size
dpi
font-bounding-box
default-char
code-range
offset-vector)
(if buf
(message "Reading %s..." bdfname)
(error "BDF file %s doesn't exist" bdfname))
(unwind-protect
(with-current-buffer buf
(goto-char (point-min))
(search-forward "\nFONTBOUNDINGBOX")
(setq font-bounding-box
(vector (read (current-buffer)) (read (current-buffer))
(read (current-buffer)) (read (current-buffer))))
;; The following kludgy code is to avoid bugs of fonts
;; jiskan16.bdf and jiskan24.bdf distributed with X.
;; They contain wrong FONTBOUNDINGBOX.
(and (> (aref font-bounding-box 3) 0)
(string-match "jiskan\\(16\\|24\\)" bdfname)
(aset font-bounding-box 3
(- (aref font-bounding-box 3))))
(goto-char (point-min))
(search-forward "\nFONT ")
(if (looking-at "-[^-]*-[^-]*-[^-]*-[^-]*-[^-]*-[^-]*-\\([0-9]+\\)")
(setq size (string-to-number (match-string 1)))
(search-forward "\nSIZE ")
(setq size (read (current-buffer)))
;; The following kludgy code is to avoid bugs of several
;; fonts which have wrong SIZE record.
(and (string-match "jiskan" bdfname)
(<= size (/ (aref font-bounding-box 1) 3))
(setq size (aref font-bounding-box 1)))
(setq dpi (read (current-buffer)))
(if (and (> dpi 0) (/= dpi 72))
(setq size (/ (* size dpi) 72))))
(setq default-char (bdf-search-and-read "\nDEFAULT_CHAR" nil))
(search-forward "\nSTARTCHAR")
(forward-line -1)
(let ((limit (point)))
(setq relative-compose
(or (bdf-search-and-read "\n_MULE_RELATIVE_COMPOSE" limit)
'false)
baseline-offset
(or (bdf-search-and-read "\n_MULE_BASELINE_OFFSET" limit)
0)))
(let ((min-code0 256) (min-code1 256) (min-code 65536)
(max-code0 0) (max-code1 0) (max-code 0)
glyph glyph-list code0 code1 code offset)
(while (search-forward "\nSTARTCHAR" nil t)
(setq offset (line-beginning-position))
(search-forward "\nENCODING")
(setq code (read (current-buffer)))
(if (< code 0)
(search-forward "ENDCHAR")
(setq code0 (ash code -8)
code1 (logand code 255)
min-code (min min-code code)
max-code (max max-code code)
min-code0 (min min-code0 code0)
max-code0 (max max-code0 code0)
min-code1 (min min-code1 code1)
max-code1 (max max-code1 code1))
(search-forward "ENDCHAR")
(setq maxlen (max maxlen (- (point) offset))
glyph-list (cons (cons code offset) glyph-list))))
(setq code-range
(vector min-code0 max-code0 min-code1 max-code1
min-code max-code (or default-char min-code))
offset-vector
(make-vector (1+ (bdf-compact-code max-code code-range))
nil))
(while glyph-list
(setq glyph (car glyph-list)
glyph-list (cdr glyph-list))
(aset offset-vector
(bdf-compact-code (car glyph) code-range)
(cdr glyph)))))
(kill-buffer buf))
(message "Reading %s...done" bdfname)
(list bdfname (bdf-file-mod-time bdfname)
size font-bounding-box relative-compose baseline-offset
code-range maxlen offset-vector)))