Function: strokes-xpm-to-compressed-string

strokes-xpm-to-compressed-string is a byte-compiled function defined in strokes.el.gz.

Signature

(strokes-xpm-to-compressed-string &optional XPM-BUFFER)

Documentation

Convert XPM in XPM-BUFFER to compressed string representing the stroke.

XPM-BUFFER defaults to " *strokes-xpm*".

Source Code

;; Defined in /usr/src/emacs/lisp/strokes.el.gz
(defun strokes-xpm-to-compressed-string (&optional xpm-buffer)
  "Convert XPM in XPM-BUFFER to compressed string representing the stroke.
XPM-BUFFER defaults to \" *strokes-xpm*\"."
  (with-current-buffer (setq xpm-buffer (or xpm-buffer " *strokes-xpm*"))
    (goto-char (point-min))
    (search-forward "/* pixels */")	; skip past header junk
    (forward-char 2)
    ;; a note for below:
    ;; the `current-char' is the char being counted -- NOT the char at (point)
    ;; which happens to be called `char-at-point'
    (let ((compressed-string "+/")	; initialize the output
	  (count 0)			; keep a current count of
					; `current-char'
	  (last-char-was-on-p t)        ; last entered stream
					; represented `on' bits
	  (current-char-is-on-p nil)	; current stream represents `on' bits
	  (char-at-point (char-after)))	; read the first char
      (while (not (eq char-at-point ?})) ; a `}' denotes the
					; end of the pixmap
	(cond ((zerop count)		; must restart counting
	       ;; check to see if the `char-at-point' is an actual pixmap bit
	       (when (strokes-xpm-char-bit-p char-at-point)
		 (setq count 1
		       current-char-is-on-p (strokes-xpm-char-on-p char-at-point)))
	       (forward-char 1))
	      ((= count 61)		; maximum single char's
					; encoding length
	       (setq compressed-string
		     (concat compressed-string
			     ;; add a zero-length encoding when
			     ;; necessary
			     (when (eq last-char-was-on-p
				       current-char-is-on-p)
			       ;; "0"
			       (strokes-xpm-encode-length-as-string 0))
			     (strokes-xpm-encode-length-as-string 61))
		     last-char-was-on-p current-char-is-on-p
		     count 0))		; note that we just set
					; count=0 and *don't* advance
					; (point)
	      ((strokes-xpm-char-bit-p char-at-point) ; an actual xpm bit
	       (if (eq current-char-is-on-p
		       (strokes-xpm-char-on-p char-at-point))
		   ;; yet another of the same bit-type, so we continue
		   ;; counting...
		   (progn
                     (incf count)
		     (forward-char 1))
		 ;; otherwise, it's the opposite bit-type, so we do a
		 ;; write and then restart count ### NOTE (for myself
		 ;; to be aware of) ### I really should advance
		 ;; (point) in this case instead of letting another
		 ;; iteration go through and letting the case: count=0
		 ;; take care of this stuff for me.  That's why
		 ;; there's no (forward-char 1) below.
		 (setq compressed-string
		       (concat compressed-string
			       ;; add a zero-length encoding when
			       ;; necessary
			       (when (eq last-char-was-on-p
					 current-char-is-on-p)
				 ;; "0"
				 (strokes-xpm-encode-length-as-string 0))
			       (strokes-xpm-encode-length-as-string count))
		       count 0
		       last-char-was-on-p current-char-is-on-p)))
	      (t			; ELSE it's some other useless
					; char, like `"' or `,'
	       (forward-char 1)))
	(setq char-at-point (char-after)))
      (concat compressed-string
	      (when (> count 0)
		(concat (when (eq last-char-was-on-p
				  current-char-is-on-p)
			  ;; "0"
			  (strokes-xpm-encode-length-as-string 0))
			(strokes-xpm-encode-length-as-string count)))
	      "/"))))