home *** CD-ROM | disk | FTP | other *** search
/ swCHIP 1991 January / swCHIP_95-1.bin / utility / gs333ini / gs3.33 / devarch.doc < prev    next >
Text File  |  1995-12-09  |  14KB  |  352 lines

  1.    Copyright (C) 1993, 1994 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.  
  20. This file, devarch.doc, contains notes about the architecture of
  21. device handling in Ghostscript.  It is intended only for developers
  22. with a fairly deep understanding of Level 2 PostScript.
  23.  
  24. For an overview of Ghostscript and a list of the documentation files, see
  25. README.
  26.  
  27. ----------------------------------------------------------------
  28.  
  29. ****** MUCH OF THE MATERIAL IN THIS DOCUMENT IS UNRELIABLE.  DON'T
  30. TRUST IT. ******
  31.  
  32. Background
  33. ==========
  34.  
  35. PostScript language
  36. -------------------
  37.  
  38. Adobe's Level 1 PostScript specification ignored, except for a few
  39. now-obsolete operators, the possibility of a single PostScript system that
  40. had multiple hardware devices attached to it; Level 1 also did not deal, in
  41. a systematic way, with control of printing features such as page size and
  42. output finishing.  In contrast, the available Level 2 specifications (the
  43. PostScript Language Reference Manual, Second Edition, and subsequent
  44. documentation obtained from the Adobe file server describing Adobe
  45. PostScript products through PostScript version 2013) include extensive
  46. facilities in this area.
  47.  
  48. Adobe's documentation refers explicitly to three concepts of "device":
  49.  
  50.     - A physical device such as a file system, a communication port, or
  51. a printing engine.  The IODevice resource enumerates these devices without
  52. providing any other information about them.  Each IODevice may have a set
  53. of state variables specific to it; the setdevparams and currentdevparams
  54. operators control the state of individual IODevices.  (In the rest of this
  55. document, we are not concerned with IODevices.)
  56.  
  57.     - A class of destination for rendering.  The OutputDevice resource
  58. enumerates these, and gives some further information (available page sizes
  59. and resolutions).  OutputDevices do not have state per se, although in
  60. Adobe's model, they typically correspond 1-for-1 with those IODevices that
  61. can serve as destinations for rendering.
  62.  
  63.     - An actual destination for rendering.  This may be a special
  64. destination like the null device or a cache device, a display (for which
  65. the documentation specifies no further details), or an instance of an
  66. OutputDevice.  OutputDevice instances are called "page devices".  The only
  67. directly visible, program-controlled state of a page device is the
  68. contents of the current page.  However, page devices also have a very
  69. large set of optional parameters that may be set when setpagedevice
  70. creates the instance, and read by currentpagedevice; some of these
  71. parameters may change from time to time as a result of external events or
  72. conditions.  The parameters control both external hardware (e.g., duplex
  73. or collation) and internally implemented facilities such as portrait vs.
  74. landscape orientation.
  75.  
  76. Ghostscript
  77. -----------
  78.  
  79. Ghostscript generalizes the Adobe model in several areas at the level of
  80. the PostScript program.
  81.  
  82.     - In addition to hard copy devices, Ghostscript can produce output
  83. on physical displays, window systems, raster files, or RAM; a typical
  84. Ghostscript configuration supports more than one of these.  Ghostscript
  85. models this by providing new OutputDevices, and a new concept called an
  86. OutputDevice family for grouping them.
  87.  
  88.     - Ghostscript normally includes multiple drivers that can write to
  89. the same physical device (for example, multiple raster file format
  90. generators, or multiple printer drivers).  Ghostscript models this by
  91. making each driver a different OutputDevice.
  92.  
  93.     - Ghostscript explicitly makes visible the objects that represent
  94. OutputDevice instances (page devices and their display, file, and RAM
  95. analogues) as new PostScript objects of type /devicetype.
  96.  
  97. In the remainder of this document, we describe Ghostscript's handling of
  98. devices from four viewpoints: that of an ordinary PostScript program, that
  99. of the Ghostscript implementation at the PostScript level, that of the
  100. Ghostscript implementation at the C level, and that of the Ghostscript
  101. device driver.
  102.  
  103. PostScript programs
  104. ===================
  105.  
  106. OutputDevice resource
  107. ---------------------
  108.  
  109. The OutputDevice resource is described in Adobe documentation as having
  110. been added in Adobe interpreter version 2011.  Briefly, the resource names
  111. are the same as the allowed values of the /OutputDevice page device
  112. parameter, and the resource values are dictionaries giving properties of
  113. the output device.  The defined properties as of version 2012 are
  114. HWResolution, ManualSize, and PageSize.
  115.  
  116. Ghostscript provides one OutputDevice for each available driver.  This
  117. includes file formats (e.g., /gifmono) and display or window systems
  118. (e.g., /x11) as well as printer types (e.g., /ljet3).  It provides a
  119. special OutputDevice called /RAM whose instances simply accumulate a
  120. bitmap in RAM for later readout.  In addition, if the available drivers
  121. include any printer, fax, or display driver, Ghostscript provides
  122. OutputDevice entries called /Printer, /Fax, /RasterFile, and /Display
  123. respectively that are aliases for the default driver in the respective
  124. family.  (There is nothing special about these three names.  Any driver
  125. can declare that it belongs to a particular family, and the driver of any
  126. given family that appears earliest in the build list becomes the default
  127. driver with that family name.)  Finally, Ghostscript always provides an
  128. OutputDevice called /Default that is an alias for the default OutputDevice
  129. (the one used if setpagedevice is invoked with no current page device and
  130. no OutputDevice key in the parameter dictionary).
  131.  
  132. Operators
  133. ---------
  134.  
  135. Ghostscript provides the setpagedevice and currentpagedevice operators, as
  136. required by the Level 2 PostScript specifications.  Ghostscript also
  137. provides a few other operators that implement increased functionality.
  138.  
  139. <int> .indexdevicename <outdevname>
  140.  
  141.     Returns the name of the int'th driver in the build list.  The first
  142. driver is numbered 0.
  143.  
  144. <outdevname> .selectdevice
  145.  
  146.     Creates and makes current a default instance of a given
  147. OutputDevice.
  148.  
  149. - .currentdevice <device>
  150.  
  151.     Returns the current device, which may be a page device or a special
  152. device.
  153.  
  154. <outdevname> .getoutputparams <mark> <name1> <value1> ... <nameN> <valueN>
  155.  
  156.     Returns the parameters of a default instance of the given
  157. OutputDevice.  Also returns the information for the OutputDevice resource
  158. dictionary.
  159.  
  160. <device> .getoutputparams <mark> <name1> <value1> ... <nameN> <valueN>
  161.  
  162.     Returns the parameters of a given device.
  163.  
  164. Page device parameters
  165. ----------------------
  166.  
  167. Most of the page device parameters documented by Adobe (either in the New
  168. Red Book or in the post-Book notes) are specific to particular devices.
  169. Ghostscript leaves these up to the device driver to process, and only
  170. provides the Policies and PolicyReport mechanism to handle those that are
  171. unknown or out of range.  Here are the parameters documented by Adobe that
  172. Ghostscript knows about specifically:
  173.  
  174.     BeginPage, EndPage, Install - per Red Book documentation.
  175.  
  176.     Policies - per Red Book documentation.  The PageSize policy value
  177.     of 7 (in later Adobe documentation) is not supported.
  178.  
  179.     ImagingBBox, HWResolution, Margins, PageSize - per Red Book
  180.     documentation.  Margins are given in device-specific units, per
  181.     later Adobe documentation.
  182.  
  183.     OutputDevice - per later Adobe documentation.
  184.  
  185.     InputAttributes, OutputAttributes - per Red Book documentation.
  186.     The feature whereby if InputAttributes is null, the interpreter
  187.     consults the driver directly for media selection (per later
  188.     documentation) is not implemented.
  189.  
  190.     Orientation - per Red Book documentation, also supported for RAM
  191.     and display devices.  We aren't sure yet how Orientation will
  192.     affect raster file output devices.
  193.  
  194.     ProcessColorModel - per later Adobe documentation, but read-only
  195.     for all but RAM devices.  For RAM devices, only DeviceGray,
  196.     DeviceRGB, and DeviceCMYK are supported.
  197.  
  198.     InsertSheet, OutputPage, SeparationColorNames, SeparationOrder -
  199.     not currently supported.
  200.  
  201.     Collate and the concept of a "set" - not currently supported.
  202.  
  203. Ghostscript also implements the following parameters that are not
  204. documented by Adobe:
  205.  
  206.     BitsPerPixel - the number of bits per pixel, an integer between 1
  207.     and 32.  This is read-only for all but RAM devices and a few file
  208.     formats.
  209.  
  210.     GrayValues, RedValues, GreenValues, BlueValues, ColorValues -
  211.     as defined by Adobe for the deviceinfo operator.  These are
  212.     read-only for all but RAM devices and a few file formats.
  213.  
  214.     .HWGrayMap, .HWRedMap, .HWGreenMap, .HWBlueMap, .HWColorMap -
  215.     the maps of the realizable device colors.  Each map is a string of
  216.     M x xxxValues bytes; each entry is M bytes, where M = 1 for the
  217.     first 4 maps and 1, 3, or 4 bytes according to the
  218.     ProcessColorModel for HWColorMap.  (I.e., the maps are like the
  219.     lookup table for an Indexed color space.)  If a map is missing, the
  220.     realizable colors are 0, 1/N, ..., 1, where N is xxxValues-1.
  221.     The Map parameters are read-only for all but RAM devices and a few
  222.     file formats.  Also, the strings returned are themselves always
  223.     read-only; the only way to change a Map is to set the parameter.
  224.  
  225.     MaxRasterMemory - the maximum amount of RAM that can be allocated
  226.     for raster memory.  This is a constraint in addition to that
  227.     imposed by the MaxRasterMemory system parameter.
  228.  
  229.     .PageCount - the number of times that the EndPage routine of this
  230.     page device returned true.  Normally, this is the same as the
  231.     number of executions of showpage or copypage.
  232.  
  233.     .ShowpageCount - the number of times that showpage was executed
  234.     with this page device; this is the value supplied to the BeginPage
  235.     and EndPage procedures.
  236.  
  237.     .HWMargins - the widths of the unprintable areas at the left,
  238.     bottom, right, and top edges of the page, expressed in 1/72"
  239.     units.  If ImagingBBox has not been specified, the default
  240.     ImagingBBox is the PageSize inset by the .HWMargins.
  241.  
  242. All other documented page device parameters, including Details
  243. dictionaries, are simply passed to the driver.
  244.  
  245. Implementation - PostScript level
  246. =================================
  247.  
  248. Operators
  249. ---------
  250.  
  251. <device> .setdevice -
  252.  
  253.     Sets the current device without doing any of the things required
  254. by setpagedevice.
  255.  
  256. Implementation - C level
  257. ========================
  258.  
  259. Driver interface
  260. ================
  261.  
  262. Appendix: Relationship to older Ghostscript versions
  263. ====================================================
  264.  
  265. Operators
  266. ---------
  267.  
  268. Previous Ghostscript versions provided a set of device handling operators
  269. that were designed before the newer Adobe specifications were available.
  270. We now indicate how these map to newer facilities.
  271.  
  272. .getdevice
  273.     This low-level operator, renamed .indexdevice, still exists to
  274. allow enumerating the output devices.  The standard way to enumerate
  275. OutputDevices is now (*) {...} /OutputDevice resourceforall.
  276.  
  277. selectdevice
  278.     This has been renamed .selectdevice, in keeping with Ghostscript
  279. practice of preceding all Ghostscript-specific operators with a dot.
  280. /outdevname selectdevice is essentially the same as << /OutputDevice
  281. /outdevname >> setpagedevice.
  282.  
  283. currentdevice
  284.     This has been renamed .currentdevice.
  285.  
  286. setdevice
  287.     We aren't sure what will happen to this.
  288.  
  289. copydevice
  290.     This is essentially equivalent to
  291.         gsave .setdevice << >> setpagedevice
  292.           .currentdevice grestore
  293. since setpagedevice always creates a new device.
  294.  
  295. getdeviceprops
  296.     Renamed .getoutputparams.
  297.  
  298. devicename
  299.     This can be implemented using .getoutputparams.
  300.  
  301. deviceinitialmatrix
  302.     This can be determined by selecting the device and then reading out
  303. the defaultmatrix.
  304.  
  305. putdeviceprops
  306.     This has been renamed .putoutputparams.  Its status in the new
  307. scheme of things, like the status of setdevice, is unclear.
  308.  
  309. makeimagedevice
  310.     Replaced by setpagedevice with << /OutputDevice /RAM >>.  The
  311. matrix, width, height, and palette arguments are replaced by parameters in
  312. the device dictionary.  The default matrix is the identity matrix, the
  313. default width and height are 0, the default depth is 1, and the default
  314. palette is <ff 00>.
  315.  
  316. copyscanlines
  317.     We aren't sure whether to retain this or to replace it with an
  318. .imagefilter operator that provides a stream to read out the bits of a
  319. memory device.
  320.  
  321. Page device parameters
  322. ----------------------
  323.  
  324. Previous Ghostscript versions had a concept of "device properties", which
  325. correspond to page device parameters in the current architecture.  Here we
  326. list the correspondence between former Ghostscript device properties and
  327. current Ghostscript parameters.
  328.  
  329.     Prior Ghostscript        Current Ghostscript
  330.     -----------------        -------------------
  331.  
  332. Size and shape:
  333.  
  334.     InitialMatrix            Margins, Orientation, Install
  335.  
  336. Color:
  337.  
  338.     Colors                [color]Values
  339.  
  340.     HWColorMap            HW[color]Map
  341.  
  342. Other:
  343.  
  344.     Name                OutputDevice
  345.  
  346.     BufferSpace, MaxBitmap        MaxRasterMemory
  347.  
  348. Orientation, HWResolution, and Margins, together with the ability of the
  349. Install procedure to set the default CTM, are sufficient to specify all
  350. possible legal values of the initial transformation matrix.  ****** Not
  351. sufficient to handle an inverted Y axis.
  352.