{ ====================================================================
A simple example of printing text.
==================================================================== }

ONLY FORTH ALSO DEFINITIONS DECIMAL

[UNDEFINED] CURRENT-DC [IF]
\ User Vars
 #USER
   CELL +USER CURRENT-DC  \ Device Context
 TO #USER

: MY-DC  ( -- hDC )     CURRENT-DC @ ;
: IS-MY-DC  ( hDC -- )  CURRENT-DC ! ;  \ Set at BeginPaint etc
: GET-MY-DC  ( -- )     HWND GetDC IS-MY-DC ;
: RELEASE-MY-DC ( -- )  HWND MY-DC ReleaseDC DROP ;
[THEN]


PRINTING +ORDER  \ Need stuff from Preview.F

DOCINFO BUILDS MY-DI

: START-OF-DOC   MY-DC  MY-DI ADDR StartDoc 0> NOT IOR_PRT_BADSTARTDOC ?THROW ;
: START-OF-PAGE  MY-DC  StartPage 0> NOT IOR_PRT_BADSTARTPAGE ?THROW ;
: END-OF-PAGE    MY-DC  EndPage 0> NOT IOR_PRT_BADENDPAGE ?THROW  ;
: END-OF-DOC     MY-DC  EndDoc 0> NOT IOR_PRT_BADENDDOC ?THROW ;

: MY-DEFAULT-PRINTER  DEFAULT-PRINTER  pd DC @ IS-MY-DC ;

: SET-DOC-NAME  ( zName -- )  \ Name Print Job
   DOCINFO SIZEOF MY-DI Size !
   ( doc name )  MY-DI DocName !
   0 MY-DI Output !  0 MY-DI Datatype !  0 MY-DI Type ! ;

: YADA  ( -- )
   MY-DC 100 200 ( x y )
   Z" SwiftForth is FORTH, Inc.’s integrated development system." ZCOUNT
   TextOut DROP ( Output Text ) ;

: PRINT-TEST  ( -- )
   MY-DEFAULT-PRINTER
   Z" Test Document" SET-DOC-NAME
   START-OF-DOC
   START-OF-PAGE ( We must manage our paging )
   ( Now we render our output )
   YADA ( something to output )
   END-OF-PAGE
   END-OF-DOC
   MY-DC DeleteDC DROP ( Delete Printer DC ) ;


PRINTING -ORDER

CR
CR .( Type PRINT-TEST to run the demo.)
CR

\ The following Examples Require FontTools.F and FormatText.F

FORMATTER BUILDS TEST-FORMAT  \ Our Test Instance

: (SF)  ( -- addr cnt )
   S" SwiftForth is FORTH, Inc.’s integrated development system for Windows 95, 98, and NT." ;

: PRINT-SIMPLE
   MY-DEFAULT-PRINTER
   Z" Test Format Document" SET-DOC-NAME
   START-OF-DOC
   START-OF-PAGE ( We must manage our paging )
   ( Now we render our output )
   (SF) ( addr cnt ) TEST-FORMAT SET-TEXT
   10 50 300 400 ( x1 y1 x2 y2 ) TEST-FORMAT OUTPUT-TEXT-IN-RECT
   END-OF-PAGE
   END-OF-DOC
   MY-DC DeleteDC DROP ( Delete Printer DC ) ;

CR
CR .( Type PRINT-SIMPLE to run the format print demo.)
CR