[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fred Styles



>Is there someone out there that understands the format of the style vector
>that Fred uses to keep style infos? (i.e. the format of the vector
>(BUFFER-GET-STYLE (FRED-BUFFER a-fred-window) 0 NIL)
>
>I managed to uncover some of it, but any tips would be greatly appreciated.
>Thanks.

Firstly, I must warn you that this format is subject to change (though
it's no likely to change until at least MCL 2.0b1).

Here's some code that will hopefully clarify mattters a little:

--------------------------------------------------------------

; describe-style-vector.lisp
;
; Show how to interpret the style vectors returned by
; buffer-get-style

(in-package :ccl)

;Format of style vectors:
;one word has the number of different fonts used
;each font is four bytes 2 bytes font id, one byte size, one byte style
;each font change has four bytes, 1 byte font index, 3 bytes offset
(defun describe-style-vector (v &optional (stream t))
  (let* ((font-count (aref v 0))
         font-list
         (index 1)
         (next-offset 0))
    ; Parse the font descriptions
    (dotimes (i font-count)
      (let* ((font-code (aref v index))
             (size/style (aref v (1+ index)))
             (size (ash size/style -8))
             (style (logand #xff size/style)))
        (push (font-spec (+ (ash font-code 16) (ash style 8)) size)
              font-list))
      (incf index 2))
    (setq font-list (nreverse font-list))
    ; Describe the font runs
    (loop
      (let* ((font-index (ash (aref v index) -8))
             (offset next-offset))
        (when (eql 0 font-index) (return))
        (setq next-offset 
              (+ (ash (logand (aref v (incf index 2)) #xff) 16)
                 (aref v (1+ index))))
        (format stream "~&~d to ~d are ~s~%"
                offset (1- next-offset) (nth (1- font-index) font-list))))))