FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

PRINTING

Print a styled text resource


Here is a subroutine that paginates edit field text by using the "line starts" table in every TE record and blockmoving 49 line sections out of the record and into the print record. It then slaps a Styl format onto the end of the record and prints it. This was necessary because printing ZText handles does not recognise the "Window" text settings, thus the formatting of the printed text is otherwise unpredictable.
FBII only, for now, pending the "route" statement fix. The Styl format was created by making a TEXT resource with resEdit, typing some text, selecting all the text, and formatting it as desired. The Styl resource is created automatically, and the TEXT resource can then be deleted.
The width of text on the page is determined by the edit field width on the screen, so set this appropriately first and do a TEUpdate.
LOCAL FN printRept
  DIM wndPtr&, wTitle$, inHndl&, myHnd&, done%, pg%
  DIM nLine%, nLines%, err%, start%, theEnd%, size%
  DIM rHnd&, pgStr$
    DEF LPRINT                                    'print... dialog box
    LONG IF PRCANCEL = _false                     'cancel button pressed?
      wndPtr& = FN FRONTWINDOW
      CALL GETWTITLE(wndPtr&,wTitle$)
      inHndl& = TEHANDLE(1)
      myHnd& = FN NEWHANDLE(_maxInt)
      done% = 0
      pg% = 0
      nLine% = 0
      nLines% = inHndl&..teNLines%
      DO
        INC(pg%)
        err% = FN SETHANDLESIZE(myHnd&, _maxInt)
        LONG IF nLine% + 49 >= nLines%
          theEnd% = {[inHndl&] + _teLines + 2 * nLines%}
          done% = _zTrue
        XELSE
          theEnd% = {[inHndl&] + _teLines + 2 * nLine% + 98}
        END IF
        start% = {[inHndl&] + _teLines + 2 * nLine%}
        size% = theEnd% - start%
        nLine% = nLine% + 49
        BLOCKMOVE [[[inHndl&] + 62]] + start%, [myHnd&] + 2, size%
        err% = FN SETHANDLESIZE(myHnd&, size% + 2)
        %[myHnd&], size%
        rHnd& = FN GETRESOURCE(_"styl", 128)
        err% = FN HANDANDHAND(rHnd&, myHnd&)
        LONG IF pg% > 1 OR NOT done%
          pgStr$ = "Page " + STR$(pg%)
        XELSE
          pgStr$ = ""
        END IF
        ROUTE 128
        TEXT _monaco, 10
        EDIT FIELD #1,wTitle$,(36,54)-(WINDOW(_width),69),_noFramed
        EDIT FIELD #2, pgStr$, (WINDOW(_width)-126,36)-(WINDOW(_width)-54,69),_noFramed,_rightJust
        EDIT FIELD #-3,&myHnd&,(36,74)-(WINDOW(_width),WINDOW(_height)), _noFramed
        ROUTE 0
        LONG IF NOT done%
          CLEAR LPRINT
        END IF
      UNTIL done%
      CLOSE LPRINT
      err% = FN DISPOSHANDLE(myHnd&)
    END IF
END FN
Charles P.