Function: ps-plot-region

ps-plot-region is a byte-compiled function defined in ps-print.el.gz.

Signature

(ps-plot-region FROM TO FONT &optional FG-COLOR BG-COLOR EFFECTS)

Source Code

;; Defined in /usr/src/emacs/lisp/ps-print.el.gz
(defun ps-plot-region (from to font &optional fg-color bg-color effects)
  (or (equal font ps-current-font)
      (ps-set-font font))

  ;; Specify a foreground color only if:
  ;;    one's specified,
  ;;    it's different from the background (if `ps-fg-validate-p' is non-nil)
  ;;    and it's different from the current.
  (let ((fg (or fg-color ps-default-foreground)))
    (if ps-fg-validate-p
	(let ((bg (or bg-color ps-default-background))
	      (el ps-foreground-list))
	  (while (and el (equal fg bg))
	    (setq fg (car el)
		  el (cdr el)))))
    (or (equal fg ps-current-color)
	(ps-set-color fg)))

  (or (equal bg-color ps-current-bg)
      (ps-set-bg bg-color))

  ;; Specify effects (underline, overline, box, etc.)
  (cond
   ((not (integerp effects))
    (ps-output "0 EF\n")
    (setq ps-current-effect 0))
   ((/= effects ps-current-effect)
    (ps-output (number-to-string effects) " EF\n")
    (setq ps-current-effect effects)))

  ;; Starting at the beginning of the specified region...
  (save-excursion
    (goto-char from)

    ;; ...break the region up into chunks separated by tabs, linefeeds,
    ;; formfeeds, control characters, and plot each chunk.
    (while (< from to)
      ;; skip lines between cut markers
      (and ps-begin-cut-regexp ps-end-cut-regexp
	   (looking-at ps-begin-cut-regexp)
	   (progn
	     (goto-char (match-end 0))
	     (and (re-search-forward ps-end-cut-regexp to 'noerror)
		  (= (following-char) ?\n)
		  (forward-char 1))
	     (setq from (point))))
      (if (re-search-forward ps-control-or-escape-regexp to t)
	  ;; region with some control characters or some multi-byte characters
	  (let* ((match-point (match-beginning 0))
		 (match       (char-after match-point)))
	    (when (< from match-point)
	      (ps-plot ps-basic-plot-string-function
		       from match-point bg-color))
	    (cond
	     ((= match ?\t)		; tab
	      (let ((linestart (line-beginning-position)))
		(forward-char -1)
		(setq from (+ linestart (current-column)))
		(when (re-search-forward "[ \t]+" to t)
		  (ps-plot 'ps-basic-plot-whitespace
			   from (+ linestart (current-column))
			   bg-color))))

	     ((= match ?\n)		; newline
	      (if (looking-at "\f[^\n]")
		  ;; \n\ftext\n ==>> next page, but keep line counting!!
		  (progn
		    (ps-skip-newline to)
		    (ps-next-page))
		;; \n\f\n     ==>> it'll be handled by form feed
		;; \ntext\n   ==>> next line
		(ps-next-line)))

	     ((= match ?\f)		; form feed
	      ;; do not skip page if previous character is NEWLINE and
	      ;; it is a beginning of page.
	      (unless (and (equal (char-after (1- match-point)) ?\n)
			   (= ps-height-remaining ps-print-height))
		;; \f\n ==>> skip \n, but keep line counting!!
		(and (equal (following-char) ?\n)
		     (ps-skip-newline to))
		(ps-next-page)))

	     (t				; characters from 127 to 255
	      (ps-control-character match)))
	    (setq from (point)))
	;; region without control characters
	(ps-plot ps-basic-plot-string-function from to bg-color)
	(setq from to)))))