) (08/01/89)
discovered something interesting just recently. SHEET-STRING-OUT-EXPLICIT-1, which is called by the method :SHEET-STRING-OUT-EXPLICIT, has a behavioral feature/bug. it does precisely what the manual says it should--I believe that what it says is actually wrong. in particular, it has to do with the third returned value: FINAL-INDEX. It actually returns the position of the end of the string, which isn't what you want (that's readily available via LENGTH). You actually want the index (in the string) of the next character to be printed. the patch below does just this. -- clint ;;; -*- Mode:Common-Lisp; Package:TV; Fonts:(medfnt MEDFNtB hl12b hl12bi cptfontb); -*- ;;;a patch which corrects indexing of the string upon reaching end-of-window/line. ;;; the third returned value is now the position of the next character to be used. (DEFUN sheet-string-out-explicit-1 (sheet string start-x ypos xlim ylim font aluf &optional (start 0) (end nil) multi-line-line-height (align-for-lozenge nil) color) "Output STRING on SHEET without using SHEET's cursor, font, etc. Output starts at cursor position START-X, Y but SHEET's cursor is not moved. Output stops if x-position XLIM or y-position YLIM is reached. Font FONT is used, and alu-function ALU. START and END specify a portion of STRING to be used. MULTI-LINE-LINE-HEIGHT is how far to move down for Return characters; Return also moves back to x-position START-X. NIL means output <Return> with a lozenge. All position arguments are relative to SHEET's outside edges." (DECLARE (VALUES final-x final-y final-index)) (coerce-font font sheet) (prepare-color (sheet color) (prepare-sheet (sheet) (OR xlim (SETQ xlim (sheet-width sheet))) (LET* ((index (OR start 0)) (end (OR end (ARRAY-ACTIVE-LENGTH string))) (xpos start-x) ch) (WHEN (PLUSP (sheet-right-margin-character-flag sheet)) ;; Ensure enough room for ! at right of screen. (DECF xlim (font-char-width font))) (LOOP while (< index end) doing (MULTIPLE-VALUE-SETQ (xpos index) (draw-string-internal sheet string index end xpos ypos xlim font aluf)) (UNLESS index ;Done? (RETURN xpos ypos index)) ;patch changed END to INDEX (SETQ ch (AREF string index)) (COND ((AND multi-line-line-height (= ch #\Newline)) (SETQ xpos start-x ypos (+ ypos multi-line-line-height)) (INCF index) (IF (AND ylim (> (+ ypos multi-line-line-height) ylim)) (RETURN xpos ypos index))) ((NOT (GRAPHIC-CHAR-P ch)) ;Special character? (LET ((STRING (lozenged-special-char-name ch)) nx) (MULTIPLE-VALUE-BIND (lozenge-width corner-width corner-height) (lozenged-string-geometry string) (IF (> (SETQ nx (+ xpos lozenge-width)) xlim) (RETURN xlim ylim index)) (sheet-display-lozenged-string-internal sheet string xpos (OR align-for-lozenge ypos) xlim aluf lozenge-width corner-width corner-height) (SETQ xpos nx))) (INCF index)) (t ; Else end of line (RETURN xpos ypos index))) ;patch changed END to INDEX )))))