home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Magazine / UsingPDF / GhostScript / source / gs5.10 / gdevpdfp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-02  |  5.5 KB  |  190 lines

  1. /* Copyright (C) 1996, 1997 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* gdevpdfp.c */
  20. /* Get/put parameters for PDF-writing driver */
  21. #include "gx.h"
  22. #include "gserrors.h"
  23. #include "gdevpdfx.h"
  24.  
  25. /*
  26.  * The pdfwrite device supports the following "real" parameters:
  27.  *    OutputFile <string>
  28.  *    (all the Distiller parameters except *ImageDict)
  29.  * Currently, very few Distiller parameters actually have any effect.
  30.  *
  31.  * The device also supports the following write-only pseudo-parameters that
  32.  * serve only to communicate other information from the PostScript file.
  33.  * Their "value" is an array of strings, some of which may be the result
  34.  * of converting arbitrary PostScript objects to string form.
  35.  *    pdfmark - see gdevpdfm.c
  36.  *    show - see gdevpdft.c
  37.  */
  38.  
  39. private const int CoreDistVersion = 3000;    /* Distiller 3.0 */
  40.  
  41. /* ---------------- Get parameters ---------------- */
  42.  
  43. /* Get parameters. */
  44. int
  45. gdev_pdf_get_params(gx_device *dev, gs_param_list *plist)
  46. {    gx_device_pdf *pdev = (gx_device_pdf *)dev;
  47.     int code = gdev_psdf_get_params(dev, plist);
  48.  
  49.     if ( code < 0 ||
  50.          (code = param_write_float(plist, "CompatibilityLevel",
  51.                        &pdev->CompatibilityLevel)) < 0 ||
  52.          (code = param_write_int(plist, "CoreDistVersion",
  53.                      (int *)&CoreDistVersion)) < 0 ||
  54.             /* ****** DoThumbnails is OBSOLETE ****** */
  55.          (code = param_write_bool(plist, "DoThumbnails",
  56.                       &pdev->DoThumbnails)) < 0 ||
  57.          (code = param_write_bool(plist, "ReAssignCharacters",
  58.                       &pdev->ReAssignCharacters)) < 0 ||
  59.          (code = param_write_bool(plist, "ReEncodeCharacters",
  60.                       &pdev->ReEncodeCharacters)) < 0 ||
  61.          (code = param_write_long(plist, "FirstObjectNumber",
  62.                       &pdev->FirstObjectNumber)) < 0
  63.        )
  64.       ;
  65.     return code;
  66. }
  67.  
  68. /* ---------------- Put parameters ---------------- */
  69.  
  70. /* Put parameters. */
  71. int
  72. gdev_pdf_put_params(gx_device *dev, gs_param_list *plist)
  73. {    gx_device_pdf *pdev = (gx_device_pdf *)dev;
  74.     int ecode = 0;
  75.     int code;
  76.     float cl = pdev->CompatibilityLevel;
  77.     bool dt = pdev->DoThumbnails;
  78.     bool rac = pdev->ReAssignCharacters;
  79.     bool rec = pdev->ReEncodeCharacters;
  80.     long fon = pdev->FirstObjectNumber;
  81.     gs_param_name param_name;
  82.  
  83.         /* General parameters. */
  84.  
  85.     switch ( code = param_read_float(plist, (param_name = "CompatibilityLevel"), &cl) )
  86.     {
  87.     default:
  88.         ecode = code;
  89.         param_signal_error(plist, param_name, ecode);
  90.     case 0:
  91.     case 1:
  92.         break;
  93.     }
  94.  
  95.     { int cdv = CoreDistVersion;
  96.       ecode = psdf_put_int_param(plist, (param_name = "CoreDistVersion"), &cdv, ecode);
  97.       if ( cdv != CoreDistVersion )
  98.         param_signal_error(plist, param_name, ecode = gs_error_rangecheck);
  99.     }
  100.             /* ****** DoThumbnails is OBSOLETE ****** */
  101.     ecode = psdf_put_bool_param(plist, "DoThumbnails", &dt, ecode);
  102.  
  103.     ecode = psdf_put_bool_param(plist, "ReAssignCharacters", &rac, ecode);
  104.     ecode = psdf_put_bool_param(plist, "ReEncodeCharacters", &rec, ecode);
  105.     switch ( code = param_read_long(plist, (param_name = "FirstObjectNumber"), &fon) )
  106.     {
  107.     case 0:
  108.         /*
  109.          * Setting this parameter is only legal if the file
  110.          * has just been opened and nothing has been written,
  111.          * or if we are setting it to the same value.
  112.          */
  113.         if ( fon == pdev->FirstObjectNumber )
  114.           break;
  115.         if ( fon <= 0 || fon > 0x7fff0000 ||
  116.              (pdev->next_id != 0 &&
  117.               pdev->next_id !=
  118.                 pdev->FirstObjectNumber + pdf_num_initial_ids)
  119.            )
  120.           ecode = gs_error_rangecheck;
  121.         else
  122.           break;
  123.     default:
  124.         ecode = code;
  125.         param_signal_error(plist, param_name, ecode);
  126.     case 1:
  127.         break;
  128.     }
  129.  
  130.     /* Handle pseudo-parameters. */
  131.  
  132.     { gs_param_string_array ppa;
  133.       switch ( code = param_read_string_array(plist,
  134.                           (param_name = "pdfmark"),
  135.                           &ppa) )
  136.       {
  137.       case 0:
  138.         pdf_open_document(pdev);
  139.         code = pdfmark_process(pdev, &ppa);
  140.         if ( code >= 0 )
  141.           break;
  142.         /* falls through for errors */
  143.       default:
  144.         ecode = code;
  145.         param_signal_error(plist, param_name, ecode);
  146.       case 1:
  147.         break;
  148.       }
  149.     }
  150.  
  151.     { gs_param_dict ppd;
  152.       switch ( code = param_begin_read_dict(plist,
  153.                         (param_name = "show"),
  154.                         &ppd, false) )
  155.       {
  156.       case 0:
  157.         pdf_open_document(pdev);
  158.         code = pdfshow_process(pdev, &ppd);
  159.         param_end_read_dict(plist, param_name, &ppd);
  160.         if ( code >= 0 )
  161.           break;
  162.         /* falls through for errors */
  163.       default:
  164.         ecode = code;
  165.         param_signal_error(plist, param_name, ecode);
  166.       case 1:
  167.         break;
  168.       }
  169.     }
  170.  
  171.     if ( ecode < 0 )
  172.       return ecode;
  173.     code = gdev_psdf_put_params(dev, plist);
  174.     if ( code < 0 )
  175.       return code;
  176.  
  177.     pdev->CompatibilityLevel = cl;
  178.     pdev->DoThumbnails = dt;
  179.     pdev->ReAssignCharacters = rac;
  180.     pdev->ReEncodeCharacters = rec;
  181.     if ( fon != pdev->FirstObjectNumber )
  182.       { pdev->FirstObjectNumber = fon;
  183.         if ( pdev->tfile != 0 )
  184.           { fseek(pdev->tfile, 0L, SEEK_SET);
  185.         pdf_initialize_ids(pdev);
  186.           }
  187.       }
  188.     return 0;
  189. }
  190.