Picture

Martin Wierich martinw@cs.kun.nl
Mon, 10 Jul 2000 17:25:07 +0200


Hoi Erik,

> The only way to get hold of a Picture is through:
> 
> DrawInWindow :: !WindowId ![DrawFunction] !(IOState s) -> IOState s
> :: DrawFunction :== Picture -> Picture
> 
> for Window pictures, or through:
> 
> print   ::      !Bool !Bool
>                         .(PrintInfo !*Picture -> ([DrawFunction],!*Picture))
>                         !PrintSetup !*printEnv
>                 ->      (!PrintSetup,!*printEnv)
>                 |       PrintEnvironments printEnv
> 
> There seems to be no way to involve a picture in a calculation to produce
> something other than a picture, such as the file in my case.
> 
> Have I overlooked a function in the IOInterface 0.8.1?

You can use the printPagePerPage function for that purpose:

  import StdEnv, deltaPrint, deltaPicture

  write_stringwidth_into_file :: !Bool !String !*File !*World -> (!.File,
!.World)
  write_stringwidth_into_file emulate_screen string file w
      # (default_ps, w)
              = defaultPrintSetup w
        (StartedPrinting file, w)
              = printPagePerPage False emulate_screen file prepare undef 
                                 default_ps w
      = (file, w)

    where

      prepare :: !*File !PrintInfo !*Picture ->
((!Bool,Point),(!.File,!*Picture))
      prepare file _ picture
        # (stringwidth,picture)
               = PictureStringWidth string picture
          file = fwritei stringwidth file
        = ((True, undef), (file, picture))

The "write_stringwidth_into_file" function writes the width of the string
argument into the file.
Note that it does _not_ need a picture argument.
The "prepare" argument of the "printPagePerPage" function works on a picture and
on a polymorphic state. So
you can choose a file to be this state.
This does not only work for printer pictures: Setting the "emulate_screen"
Boolean to True will have the
effect that the picture emulates the screen resolution.

The Tutorial to the Object I/O library contains a chapter about it's printing
functions. It's also worth
to read in a 0.8 I/O context.

> Has this been cured in the Object IO system?

The upper function is a little bit overdone for just accessing a screen picture.
Therefore the Object I/O
library includes a class "accScreenPicture" (in module StdPSt).

bye
  Martin Wierich
  University of Nijmegen