home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 4 / AUCD4.iso / acorn / riscos / releases / oslib / examples / Examples / p3-659 < prev    next >
Text File  |  1994-03-24  |  3KB  |  99 lines

  1. #include "os.h"
  2. #include "osfind.h"
  3. #include "pdriver.h"
  4.  
  5. extern os_error *Get_Document_Size (os_box *);
  6. extern os_error *Fit_Two_Pages (int x0, int y0, int x1, int y1,
  7.       os_box *, os_hom_trfm *, os_coord *, os_coord *);
  8. extern os_error *Draw_Page (int page, os_box *);
  9.  
  10. os_error *print_out (int first_page, int last_page, char *title,
  11.       char *file_name, font_f *font_ptr)
  12.  
  13. {  os_error *error;
  14.    os_f job, old_job;
  15.    bool done_openout = FALSE, done_select_job = FALSE, more;
  16.    bits features;
  17.    os_box box, printable, box2;
  18.    os_hom_trfm trfm;
  19.    os_coord o1, o2;
  20.    int page, page_to_print;
  21.  
  22.    if ((error = xosfind_openout (osfind_NO_PATH | osfind_ERROR_IF_DIR |
  23.          osfind_ERROR_IF_ABSENT, "printer:", NULL, &job)) != NULL)
  24.       goto finish;
  25.    done_openout = TRUE;
  26.  
  27.    if ((error = xpdriver_select_job (job, title, &old_job)) != NULL)
  28.       goto finish;
  29.    done_select_job = TRUE;
  30.  
  31.    /*This code is not explicitly in the BASIC, but PROCdeclarefonts must do
  32.       something like this:*/
  33.    if ((error = xpdriver_info (NULL, NULL, NULL, &features, NULL, NULL,
  34.          NULL, NULL)) != NULL)
  35.       goto finish;
  36.  
  37.    if ((features & pdriver_FEATURE_DECLARE_FONT) != 0)
  38.       do
  39.          if ((error = xpdriver_declare_font (*font_ptr, NULL, 0)) != NULL)
  40.             goto finish;
  41.       while (*font_ptr++ != 0);
  42.  
  43.    if ((error = Get_Document_Size (&box)) != NULL)
  44.       goto finish;
  45.  
  46.    if ((error = xpdriver_page_size (NULL, NULL, &printable.x0,
  47.          &printable.y0, &printable.x1, &printable.y1)) != NULL)
  48.       goto finish;
  49.  
  50.    if ((error = Fit_Two_Pages (printable.x0, printable.y0, printable.x1,
  51.          printable.y1, &box, &trfm, &o1, &o2)) != NULL)
  52.       goto finish;
  53.  
  54.    for (page = first_page; page <= last_page; page += 2)
  55.    {  if ((error = xpdriver_give_rectangle (page, &box, &trfm, &o1,
  56.             os_COLOUR_WHITE)) != NULL)
  57.          goto finish;
  58.  
  59.       if (page < last_page)
  60.          if ((error = xpdriver_give_rectangle (page + 1, &box, &trfm, &o2,
  61.                os_COLOUR_WHITE)) != NULL)
  62.             goto finish;
  63.  
  64.       if ((error = xpdriver_draw_page (1, &box2, 0, NULL, &more,
  65.             &page_to_print)) != NULL)
  66.          goto finish;
  67.  
  68.       while (more)
  69.       {  if ((error = Draw_Page (page_to_print, &box2)) != NULL)
  70.             goto finish;
  71.  
  72.          if ((error = xpdriver_get_rectangle (&box2, &more, &page_to_print))
  73.                != NULL)
  74.             goto finish;
  75.       }
  76.    }
  77.  
  78. finish:
  79.    if (done_select_job)
  80.    {  os_error *error1;
  81.  
  82.       error1 = error == NULL? xpdriver_end_job (job):
  83.             xpdriver_abort_job (job);
  84.       if (error == NULL) error = error1;
  85.  
  86.       error1 = xpdriver_select_job (old_job, NULL, NULL);
  87.       if (error == NULL) error = error1;
  88.    }
  89.  
  90.    if (done_openout)
  91.    {  os_error *error1;
  92.  
  93.       error1 = xosfind_close (job);
  94.       if (error == NULL) error = error1;
  95.    }
  96.  
  97.    return error;
  98. }
  99.