home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / DRIVERS.DOC < prev    next >
Text File  |  1994-07-27  |  30KB  |  694 lines

  1.    Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994 Aladdin Enterprises.
  2.      All rights reserved.
  3.   
  4.   This file is part of Aladdin Ghostscript.
  5.   
  6.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  7.   or distributor accepts any responsibility for the consequences of using it,
  8.   or for whether it serves any particular purpose or works at all, unless he
  9.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  10.   License (the "License") for full details.
  11.   
  12.   Every copy of Aladdin Ghostscript must include a copy of the License,
  13.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  14.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  15.   under certain conditions described in the License.  Among other things, the
  16.   License requires that the copyright notice and this notice be preserved on
  17.   all copies.
  18.  
  19. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  20.  
  21. This file, drivers.doc, describes the interface between Ghostscript and
  22. device drivers.
  23.  
  24. For an overview of Ghostscript and a list of the documentation files, see
  25. README.
  26.  
  27. ********
  28. ******** Adding a driver ********
  29. ********
  30.  
  31. To add a driver to Ghostscript, all you need to do is edit devs.mak in
  32. two places.  The first is the list of devices, in the section headed
  33.  
  34. # -------------------------------- Catalog ------------------------------- #
  35.  
  36. Pick a name for your device, say smurf, and add smurf to the list.
  37. (Device names must be 1 to 8 characters, consisting of only letters,
  38. digits, and underscores, of which the first character must be a letter.
  39. Case is significant: all current device names are lower case.)
  40. The second is the section headed
  41.  
  42. # ---------------------------- Device drivers ---------------------------- #
  43.  
  44. Suppose the files containing the smurf driver are called joe and fred.
  45. Then you should add the following lines:
  46.  
  47. # ------ The SMURF device ------ #
  48.  
  49. smurf_=joe.$(OBJ) fred.$(OBJ)
  50. smurf.dev: $(smurf_)
  51.     $(SHP)gssetdev smurf $(smurf_)
  52.  
  53. joe.$(OBJ): joe.c ...and whatever it depends on
  54.  
  55. fred.$(OBJ): fred.c ...and whatever it depends on
  56.  
  57. If the smurf driver also needs special libraries, e.g., a library named
  58. gorf, then the gssetdev line should look like
  59.     $(SHP)gssetdev smurf $(smurf_)
  60.     $(SHP)gsaddmod smurf -lib gorf
  61.  
  62. ********
  63. ******** Keeping things simple
  64. ********
  65.  
  66. If you want to add a simple device (specifically, a black-and-white
  67. printer), you probably don't need to read the rest of this document; just
  68. use the code in an existing driver as a guide.  The Epson and BubbleJet
  69. drivers (gdevepsn.c and gdevbj10.c) are good models for dot-matrix
  70. printers, which require presenting the data for many scan lines at once;
  71. the DeskJet/LaserJet drivers (gdevdjet.c) are good models for laser
  72. printers, which take a single scan line at a time but support data
  73. compression.  For color printers, the DeskJet 500C driver (gdevcdj.c) is a
  74. good place to start.  gdevcdj.c is also a good example of a device that
  75. has additional settable attributes (in this case, different output quality
  76. modes that aren't just a matter of resolution).
  77.  
  78. On the other hand, if you're writing a driver for some more esoteric
  79. device, you probably do need at least some of the information in the rest
  80. of this document.  It might be a good idea for you to read it in
  81. conjunction with one of the existing drivers.
  82.  
  83. ********
  84. ******** Driver structure ********
  85. ********
  86.  
  87. A device is represented by a structure divided into three parts:
  88.  
  89.     - procedures that are shared by all instances of each device;
  90.  
  91.     - parameters that are present in all devices but may be different
  92.       for each device or instance; and
  93.  
  94.     - device-specific parameters that may be different for each instance.
  95.  
  96. Normally, the procedure structure is defined and initialized at compile
  97. time.  A prototype of the parameter structure (including both generic and
  98. device-specific parameters) is defined and initialized at compile time,
  99. but is copied and filled in when an instance of the device is created.
  100.  
  101. The gx_device_common macro defines the common structure elements, with the
  102. intent that devices define and export a structure along the following
  103. lines:
  104.  
  105.     typedef struct smurf_device_s {
  106.         gx_device_common;
  107.         ... device-specific parameters ...
  108.     } smurf_device;
  109.     smurf_device gs_smurf_device = {
  110.         sizeof(smurf_device),        * params_size
  111.         { ... procedures ... },        * procs
  112.         ... generic parameter values ...
  113.         ... device-specific parameter values ...
  114.     };
  115.  
  116. The device structure instance *must* have the name gs_smurf_device, where
  117. smurf is the device name used in devs.mak.
  118.  
  119. All the device procedures are called with the device as the first
  120. argument.  Since each device type is actually a different structure type,
  121. the device procedures must be declared as taking a gx_device * as their
  122. first argument, and must cast it to smurf_device * internally.  For
  123. example, in the code for the "memory" device, the first argument to all
  124. routines is called dev, but the routines actually use md to reference
  125. elements of the full structure, by virtue of the definition
  126.  
  127.     #define md ((gx_device_memory *)dev)
  128.  
  129. (This is a cheap version of "object-oriented" programming: in C++, for
  130. example, the cast would be unnecessary, and in fact the procedure table
  131. would be constructed by the compiler.)
  132.  
  133. Structure definition
  134. --------------------
  135.  
  136. This essentially duplicates the structure definition in gxdevice.h.
  137.  
  138. typedef struct gx_device_s {
  139.     int params_size;        /* size of this structure */
  140.     gx_device_procs *procs;        /* pointer to procedure structure */
  141.     char *name;            /* the device name */
  142.     int width;            /* width in pixels */
  143.     int height;            /* height in pixels */
  144.     float x_pixels_per_inch;    /* x density */
  145.     float y_pixels_per_inch;    /* y density */
  146.     gs_rect margin_inches;        /* margins around imageable area, */
  147.                     /* in inches */
  148.     gx_device_color_info color_info;    /* color information */
  149.     int is_open;            /* true if device has been opened */
  150. } gx_device;
  151.  
  152. The name in the structure should be the same as the name in devs.mak.
  153.  
  154. gx_device_common is a macro consisting of just the element definitions.
  155.  
  156. For sophisticated developers only
  157. ---------------------------------
  158.  
  159. If for any reason you need to change the definition of the basic device
  160. structure, or add procedures, you must change the following places:
  161.  
  162.     - This document and NEWS (if you want to keep the
  163.         documentation up to date).
  164.     - The definition of gx_device_common and/or the procedures
  165.         in gxdevice.h.
  166.     - Possibly, the default forwarding procedures in gxdevice.h
  167.         and gsdevice.c.
  168.     - The following devices that must have complete (non-defaulted)
  169.         procedure vectors:
  170.         - The null device in gsdevice.c.
  171.         - The command list "device" in gxclist.c.
  172.         - The "memory" devices in gdevmem.h and gdevmem*.c.
  173.     - The procedure record completion routine in gsdevice.c.
  174.     - The clip list accumulation "device" in gxacpath.c.
  175.     - The clipping "devices" in gxcpath.c and gxclip2.c.
  176.     - The hit detection "device" in zupath.c.
  177.     - The generic printer device macros in gdevprn.h.
  178.     - The generic printer device code in gdevprn.c.
  179.     - All the real devices in the standard Ghostscript distribution,
  180.         as listed in devs.mak.  (Most of the printer devices are
  181.         created with the macros in gdevprn.h, so you may not have to
  182.         edit the source code for them.)
  183.     - Any other drivers you have that aren't part of the standard
  184.         Ghostscript distribution.
  185.  
  186. You may also have to change the code for gx_default_get_params and/or
  187. gx_default_put_params (in gsdparam.c).
  188.  
  189. Note that if all you are doing is adding optional procedures, you do NOT
  190. have to modify any of the real device drivers listed in devs.mak;
  191. Ghostscript will substitute the default procedures properly.
  192.  
  193. ********
  194. ******** Coding conventions ********
  195. ********
  196.  
  197. While most drivers (especially printer drivers) follow a very similar
  198. template, there is one important coding convention that is not obvious
  199. from reading the code for existing drivers: Driver procedures must not use
  200. malloc to allocate any storage that stays around after the procedure
  201. returns.  Instead, they must use gs_malloc and gs_free, which have
  202. slightly different calling conventions.  (The prototypes for these are in
  203. gs.h, which is included in gx.h, which is included in gdevprn.h.)  This is
  204. necessary so that Ghostscript can clean up all allocated memory before
  205. exiting, which is essential in environments that provide only
  206. single-address-space multi-tasking (specifically, Microsoft Windows).
  207.  
  208. char *gs_malloc(uint num_elements, uint element_size,
  209.   const char *client_name);
  210.  
  211.     Like calloc, but unlike malloc, gs_malloc takes an element count
  212. and an element size.  For structures, num_elements is 1 and element_size
  213. is sizeof the structure; for byte arrays, num_elements is the number of
  214. bytes and element_size is 1.
  215.  
  216.     The client_name is used for tracing and debugging.  It must be a
  217. real string, not NULL.  Normally it is the name of the procedure in which
  218. the call occurs.
  219.  
  220. void gs_free(char *data, uint num_elements, uint element_size,
  221.   const char *client_name);
  222.  
  223.     Unlike free, gs_free demands that num_elements and element_size be
  224. supplied.  It also requires a client name, like gs_malloc.
  225.  
  226. ********
  227. ******** Types and coordinates ********
  228. ********
  229.  
  230. Coordinate system
  231. -----------------
  232.  
  233. Since each driver specifies the initial transformation from user to device
  234. coordinates, the driver can use any coordinate system it wants, as long as
  235. a device coordinate will fit in an int.  (This is only an issue on MS-DOS
  236. systems, where ints are only 16 bits.  User coordinates are represented as
  237. floats.)  Typically the coordinate system will have (0,0) in the upper
  238. left corner, with X increasing to the right and Y increasing toward the
  239. bottom.  This happens to be the coordinate system that all the currently
  240. supported devices use.  However, there is supposed to be nothing in the
  241. rest of Ghostscript that assumes this.
  242.  
  243. Drivers must check (and, if necessary, clip) the coordinate parameters
  244. given to them: they should not assume the coordinates will be in bounds.
  245. The fit_fill and fit_copy macros in gxdevice.h are very helpful in doing
  246. this.
  247.  
  248. Color definition
  249. ----------------
  250.  
  251. Ghostscript represents colors internally as RGB or CMYK values.  In
  252. communicating with devices, however, it assumes that each device has a
  253. palette of colors identified by integers (to be precise, elements of type
  254. gx_color_index).  Drivers may provide a uniformly spaced gray ramp or
  255. color cube for halftoning, or they may do their own color approximation,
  256. or both.
  257.  
  258. The color_info member of the device structure defines the color and
  259. gray-scale capabilities of the device.  Its type is defined as follows:
  260.  
  261. typedef struct gx_device_color_info_s {
  262.     int num_components;        /* 1 = gray only, 3 = RGB, */
  263.                     /* 4 = CMYK */
  264.     int depth;            /* # of bits per pixel */
  265.     gx_color_value max_gray;    /* # of distinct gray levels -1 */
  266.     gx_color_value max_rgb;        /* # of distinct color levels -1 */
  267.                     /* (only relevant if num_comp. > 1) */
  268.     gx_color_value dither_gray;    /* size of gray ramp for halftoning */
  269.     gx_color_value dither_rgb;    /* size of color cube ditto */
  270.                     /* (only relevant if num_comp. > 1) */
  271. } gx_device_color_info;
  272.  
  273. The following macros (in gxdevice.h) provide convenient shorthands for
  274. initializing this structure for ordinary black-and-white or color devices:
  275.  
  276. #define dci_black_and_white { 1, 1, 1, 0, 2, 0 }
  277. #define dci_color(depth,maxv,dither) { 3, depth, maxv, maxv, dither, dither }
  278.  
  279. The idea is that a device has a certain number of gray levels (max_gray
  280. +1) and a certain number of colors (max_rgb +1) that it can produce
  281. directly.  When Ghostscript wants to render a given RGB color as a device
  282. color, it first tests whether the color is a gray level.  (If
  283. num_components is 1, it converts all colors to gray levels.)  If so:
  284.  
  285.     - If max_gray is large (>= 31), Ghostscript asks the device to
  286. approximate the gray level directly.  If the device returns a
  287. gx_color_value, Ghostscript uses it.  Otherwise, Ghostscript assumes that
  288. the device can represent dither_gray distinct gray levels, equally spaced
  289. along the diagonal of the color cube, and uses the two nearest ones to the
  290. desired color for halftoning.
  291.  
  292. If the color is not a gray level:
  293.  
  294.     - If max_rgb is large (>= 31), Ghostscript asks the device to
  295. approximate the color directly.  If the device returns a
  296. gx_color_value, Ghostscript uses it.  Otherwise, Ghostscript assumes
  297. that the device can represent dither_rgb * dither_rgb * dither_rgb
  298. distinct colors, equally spaced throughout the color cube, and uses
  299. two of the nearest ones to the desired color for halftoning.
  300.  
  301. Types
  302. -----
  303.  
  304. Here is a brief explanation of the various types that appear as parameters
  305. or results of the drivers.
  306.  
  307. gx_color_value (defined in gxdevice.h)
  308.  
  309.     This is the type used to represent RGB color values.  It is
  310. currently equivalent to unsigned short.  However, Ghostscript may use less
  311. than the full range of the type to represent color values:
  312. gx_color_value_bits is the number of bits actually used, and
  313. gx_max_color_value is the maximum value (equal to
  314. 2^gx_max_color_value_bits - 1).
  315.  
  316. gx_device (defined in gxdevice.h)
  317.  
  318.     This is the device structure, as explained above.
  319.  
  320. gs_matrix (defined in gsmatrix.h)
  321.  
  322.     This is a 2-D homogenous coordinate transformation matrix, used by
  323. many Ghostscript operators.
  324.  
  325. gx_color_index (defined in gxdevice.h)
  326.  
  327.     This is meant to be whatever the driver uses to represent a device
  328. color.  For example, it might be an index in a color map.  Ghostscript
  329. doesn't ever do any computations with these values: it gets them from
  330. map_rgb_color or map_cmyk_color and hands them back as arguments to
  331. several other procedures.  The special value gx_no_color_index (defined as
  332. (gx_color_index)(-1)) means "transparent" for some of the procedures.  The
  333. type definition is simply:
  334.  
  335.     typedef unsigned long gx_color_index;
  336.  
  337. gs_param_list (defined in gsparam.h)
  338.  
  339.     This is a parameter list, which is used to read and set attributes
  340. in a device.  See the comments in gsparam.h, and the description of the
  341. get_params and put_params procedures below, for more detail.
  342.  
  343. gx_bitmap (defined in gxbitmap.h)
  344.  
  345.     This structure type represents a bitmap to be used as a tile for
  346. filling a region (rectangle).  Here is a copy of the relevant part of the
  347. file:
  348.  
  349. /*
  350.  * Structure for describing stored bitmaps.
  351.  * Bitmaps are stored bit-big-endian (i.e., the 2^7 bit of the first
  352.  * byte corresponds to x=0), as a sequence of bytes (i.e., you can't
  353.  * do word-oriented operations on them if you're on a little-endian
  354.  * platform like the Intel 80x86 or VAX).  Each scan line must start on
  355.  * a (32-bit) word boundary, and hence is padded to a word boundary,
  356.  * although this should rarely be of concern, since the raster and width
  357.  * are specified individually.  The first scan line corresponds to y=0
  358.  * in whatever coordinate system is relevant.
  359.  *
  360.  * For bitmaps used as halftone tiles, we may replicate the tile in
  361.  * X and/or Y, but it is still valuable to know the true tile dimensions.
  362.  */
  363. typedef struct gx_bitmap_s {
  364.     byte *data;
  365.     int raster;            /* bytes per scan line */
  366.     gs_int_point size;        /* width, height */
  367.     gx_bitmap_id id;
  368.     ushort rep_width, rep_height;    /* true size of tile */
  369. } gx_bitmap;
  370.  
  371. ********
  372. ******** Driver procedures ********
  373. ********
  374.  
  375. All the procedures that return int results return 0 on success, or an
  376. appropriate negative error code in the case of error conditions.  The
  377. error codes are defined in gserrors.h.  The relevant ones for drivers
  378. are as follows:
  379.  
  380.     gs_error_invalidfileaccess
  381.         An attempt to open a file failed.
  382.  
  383.     gs_error_limitcheck
  384.         An otherwise valid parameter value was too large for
  385.         the implementation.
  386.  
  387.     gs_error_rangecheck
  388.         A parameter was outside the valid range.
  389.  
  390.     gs_error_VMerror
  391.         An attempt to allocate memory failed.  (If this
  392.         happens, the procedure should release all memory it
  393.         allocated before it returns.)
  394.  
  395. If a driver does return an error, it should use the return_error
  396. macro rather than a simple return statement, e.g.,
  397.  
  398.     return_error(gs_error_VMerror);
  399.  
  400. This macro is defined in gx.h, which is automatically included by
  401. gdevprn.h but not by gserrors.h.
  402.  
  403. Most of the procedures that a driver may implement are optional.  If a
  404. device doesn't supply an optional procedure <proc>, the entry in the
  405. procedure structure may be either gx_default_<proc>, e.g.
  406. gx_default_tile_rectangle, or NULL or 0.  (The device procedure must also
  407. call the gx_default_ procedure if it doesn't implement the function for
  408. particular values of the arguments.)  Since C compilers supply 0 as the
  409. value for omitted structure elements, this convention means that
  410. statically initialized procedure structures will continue to work even if
  411. new (optional) members are added.
  412.  
  413. Life cycle
  414. ----------
  415.  
  416. Ghostscript "opens" and "closes" drivers explicitly; a driver can assume
  417. that no output operations will be done through it while it is closed.
  418. Ghostscript keeps track of whether a given driver is open, so a driver
  419. will never be opened when it is already open, or closed when it is already
  420. closed.
  421.  
  422. The following are the only driver procedures that may be called when the
  423. driver is closed:
  424.     open_device
  425.     get_initial_matrix
  426.     get_params
  427.     put_params
  428.  
  429. Open/close/sync
  430. ---------------
  431.  
  432. int (*open_device)(P1(gx_device *)) [OPTIONAL]
  433.  
  434.     Open the device: do any initialization associated with making the
  435. device instance valid.  This must be done before any output to the device.
  436. The default implementation does nothing.
  437.  
  438. void (*get_initial_matrix)(P2(gx_device *, gs_matrix *)) [OPTIONAL]
  439.  
  440.     Construct the initial transformation matrix mapping user
  441. coordinates (nominally 1/72" per unit) to device coordinates.  The default
  442. procedure computes this from width, height, and x/y_pixels_per_inch on the
  443. assumption that the origin is in the upper left corner, i.e.
  444.         xx = x_pixels_per_inch/72, xy = 0,
  445.         yx = 0, yy = -y_pixels_per_inch/72,
  446.         tx = 0, ty = height.
  447.  
  448. int (*sync_output)(P1(gx_device *)) [OPTIONAL]
  449.  
  450.     Synchronize the device.  If any output to the device has been
  451. buffered, send / write it now.  Note that this may be called several times
  452. in the process of constructing a page, so printer drivers should NOT
  453. implement this by printing the page.  The default implementation does
  454. nothing.
  455.  
  456. int (*output_page)(P3(gx_device *, int num_copies, int flush)) [OPTIONAL]
  457.  
  458.     Output a fully composed page to the device.  The num_copies
  459. argument is the number of copies that should be produced for a hardcopy
  460. device.  (This may be ignored if the driver has some other way to specify
  461. the number of copies.)  The flush argument is true for showpage, false for
  462. copypage.  The default definition just calls sync_output.  Printer drivers
  463. should implement this by printing and ejecting the page.
  464.  
  465. int (*close_device)(P1(gx_device *)) [OPTIONAL]
  466.  
  467.     Close the device: release any associated resources.  After this,
  468. output to the device is no longer allowed.  The default implementation
  469. does nothing.
  470.  
  471. Color mapping
  472. -------------
  473.  
  474. A given driver normally will implement either map_rgb_color or
  475. map_cmyk_color, but not both.  Black-and-white drivers do not need to
  476. implement either one.
  477.  
  478. gx_color_index (*map_rgb_color)(P4(gx_device *, gx_color_value red,
  479.   gx_color_value green, gx_color_value blue)) [OPTIONAL]
  480.  
  481.     Map a RGB color to a device color.  The range of legal values of
  482. the RGB arguments is 0 to gx_max_color_value.  The default algorithm uses
  483. the map_cmyk_color procedure if the driver supplies one, otherwise returns
  484. 1 if any of the values exceeds gx_max_color_value/2, 0 otherwise.
  485.  
  486.     Ghostscript assumes that for devices that have color capability
  487. (i.e., color_info.num_components > 1), map_rgb_color returns a color index
  488. for a gray level (as opposed to a non-gray color) iff red = green = blue.
  489.  
  490. gx_color_index (*map_cmyk_color)(P5(gx_device *, gx_color_value cyan,
  491.   gx_color_value magenta, gx_color_value yellow, gx_color_value black))
  492.   [OPTIONAL]
  493.  
  494.     Map a CMYK color to a device color.  The range of legal values of
  495. the CMYK arguments is 0 to gx_max_color_value.  The default algorithm
  496. calls the map_rgb_color procedure, with suitably transformed arguments.
  497.  
  498.     Ghostscript assumes that for devices that have color capability
  499. (i.e., color_info.num_components > 1), map_cmyk_color returns a color
  500. index for a gray level (as opposed to a non-gray color) iff cyan = magenta
  501. = yellow.
  502.  
  503. int (*map_color_rgb)(P3(gx_device *, gx_color_index color,
  504.   gx_color_value rgb[3])) [OPTIONAL]
  505.  
  506.     Map a device color code to RGB values.  The default algorithm
  507. returns (0 if color==0 else gx_max_color_value) for all three components.
  508.  
  509. gx_color_index (*map_rgb_alpha_color)(P5(gx_device *, gx_color_value red,
  510.   gx_color_value green, gx_color_value blue, gx_color_value alpha)) [OPTIONAL]
  511.  
  512.     Map a RGB color and an opacity value to a device color.  The range
  513. of legal values of the RGB and alpha arguments is 0 to gx_max_color_value;
  514. alpha = 0 means transparent, alpha = gx_max_color_value means fully
  515. opaque.  The default is to use the map_rgb_color procedure and ignore
  516. alpha.
  517.  
  518.     Note that if a driver implements map_rgb_alpha_color, it must also
  519. implement map_rgb_color, and must implement them in such a way that
  520. map_rgb_alpha_color(dev, r, g, b, gx_max_color_value) returns the same
  521. value as map_rgb_color(dev, r, g, b).
  522.  
  523.     Note that there is no map_cmyk_alpha_color procedure.  CMYK
  524. devices currently do not support variable opacity; alpha is ignored on
  525. such devices.
  526.  
  527. Drawing
  528. -------
  529.  
  530. All drawing operations use device coordinates and device color values.
  531.  
  532. int (*fill_rectangle)(P6(gx_device *, int x, int y,
  533.   int width, int height, gx_color_index color))
  534.  
  535.     Fill a rectangle with a color.  The set of pixels filled is
  536. {(px,py) | x <= px < x + width and y <= py < y + height}.  In other words,
  537. the point (x,y) is included in the rectangle, as are (x+w-1,y), (x,y+h-1),
  538. and (x+w-1,y+h-1), but *not* (x+w,y), (x,y+h), or (x+w,y+h).  If width <=
  539. 0 or height <= 0, fill_rectangle should return 0 without drawing anything.
  540.  
  541. int (*draw_line)(P6(gx_device *, int x0, int y0, int x1, int y1,
  542.   gx_color_index color)) [OPTIONAL]
  543.  
  544.     Draw a minimum-thickness line from (x0,y0) to (x1,y1).  The
  545. precise set of points to be filled is defined as follows.  First, if y1 <
  546. y0, swap (x0,y0) and (x1,y1).  Then the line includes the point (x0,y0)
  547. but not the point (x1,y1).  If x0=x1 and y0=y1, draw_line should return 0
  548. without drawing anything.
  549.  
  550. Bitmap imaging
  551. --------------
  552.  
  553. Bitmap (or pixmap) images are stored in memory in a nearly standard way.
  554. The first byte corresponds to (0,0) in the image coordinate system: bits
  555. (or polybit color values) are packed into it left-to-right.  There may be
  556. padding at the end of each scan line: the distance from one scan line to
  557. the next is always passed as an explicit argument.
  558.  
  559. int (*copy_mono)(P11(gx_device *, const unsigned char *data, int data_x,
  560.   int raster, gx_bitmap_id id, int x, int y, int width, int height,
  561.   gx_color_index color0, gx_color_index color1))
  562.  
  563.     Copy a monochrome image (similar to the PostScript image
  564. operator).  Each scan line is raster bytes wide.  Copying begins at
  565. (data_x,0) and transfers a rectangle of the given width at height to the
  566. device at device coordinate (x,y).  (If the transfer should start at some
  567. non-zero y value in the data, the caller can adjust the data address by
  568. the appropriate multiple of the raster.)  The copying operation writes
  569. device color color0 at each 0-bit, and color1 at each 1-bit: if color0 or
  570. color1 is gx_no_color_index, the device pixel is unaffected if the image
  571. bit is 0 or 1 respectively.  If id is different from gx_no_bitmap_id, it
  572. identifies the bitmap contents unambiguously; a call with the same id will
  573. always have the same data, raster, and data contents.
  574.  
  575.     This operation is the workhorse for text display in Ghostscript,
  576. so implementing it efficiently is very important.
  577.  
  578. int (*tile_rectangle)(P10(gx_device *, const gx_bitmap *tile,
  579.   int x, int y, int width, int height,
  580.   gx_color_index color0, gx_color_index color1,
  581.   int phase_x, int phase_y)) [OPTIONAL]
  582.  
  583.     Tile a rectangle.  Tiling consists of doing multiple copy_mono
  584. operations to fill the rectangle with copies of the tile.  The tiles are
  585. aligned with the device coordinate system, to avoid "seams".
  586. Specifically, the (phase_x, phase_y) point of the tile is aligned with the
  587. origin of the device coordinate system.  (Note that this is backwards from
  588. the PostScript definition of halftone phase.)  phase_x and phase_y are
  589. guaranteed to be in the range [0..tile->width) and [0..tile->height)
  590. respectively.
  591.  
  592.     If color0 and color1 are both gx_no_color_index, then the tile is
  593. a color pixmap, not a bitmap: see the next section.
  594.  
  595. Pixmap imaging
  596. --------------
  597.  
  598. Pixmaps are just like bitmaps, except that each pixel occupies more than
  599. one bit.  All the bits for each pixel are grouped together (this is
  600. sometimes called "chunky" or "Z" format).  The number of bits per pixel is
  601. given by the color_info.depth parameter in the device structure: the legal
  602. values are 1, 2, 4, 8, 16, 24, or 32.  The pixel values are device color
  603. codes (i.e., whatever it is that map_rgb_color returns).
  604.  
  605. int (*copy_color)(P9(gx_device *, const unsigned char *data, int data_x,
  606.   int raster, gx_bitmap_id id, int x, int y, int width, int height))
  607.  
  608.     Copy a color image with multiple bits per pixel.  The raster is in
  609. bytes, but x and width are in pixels, not bits.  If the device doesn't
  610. actually support color, this is OPTIONAL; the default is equivalent to
  611. copy_mono with color0 = 0 and color1 = 1.  If id is different from
  612. gx_no_bitmap_id, it identifies the bitmap contents unambiguously; a call
  613. with the same id will always have the same data, raster, and data
  614. contents.
  615.  
  616. tile_rectangle can also take colored tiles.  This is indicated by the
  617. color0 and color1 arguments both being gx_no_color_index.  In this case,
  618. as for copy_color, the raster and height in the "bitmap" are interpreted
  619. as for real bitmaps, but the x and width are in pixels, not bits.
  620.  
  621. Reading bits back
  622. -----------------
  623.  
  624. int (*get_bits)(P4(gx_device *, int y, byte *str, byte **actual_data))
  625.   [OPTIONAL]
  626.  
  627.     Read one scan line of bits back from the device into the area
  628. starting at str, namely, scan line y.  If the bits cannot be read back
  629. (e.g., from a printer), return -1; otherwise return 0.  The contents of
  630. the bits beyond the last valid bit in the scan line (as defined by the
  631. device width) are unpredictable.
  632.  
  633.     If actual_data is NULL, the bits are always returned at str.  If
  634. actual_data is not NULL, get_bits may either copy the bits to str and set
  635. *actual_data = str, or it may leave the bits where they are and return a
  636. pointer to them in *actual_data.  In the latter case, the bits are
  637. guaranteed to start on a 32-bit boundary and to be padded to a multiple of
  638. 32 bits; also in this case, the bits are not guaranteed to still be there
  639. after the next call on get_bits.
  640.  
  641. Parameters
  642. ----------
  643.  
  644. Devices may have an open-ended set of parameters, which are simply pairs
  645. consisting of a name and a value.  The value may be of various types:
  646. integer (int or long), boolean, float, string, name, null, array of
  647. integer, or array of float.
  648.  
  649. Parameter handling is somewhat complex.  If your device has parameters
  650. beyond those of a straightforward display or printer, we strongly advise
  651. using the code for the default implementation of get_params and put_params
  652. in gsdparam.c as a model for your own code.
  653.  
  654. int (*get_params)(P2(gx_device *dev, gs_param_list *plist)) [OPTIONAL]
  655.  
  656.     Read the parameters of the device into the parameter list at plist.
  657. See gsparam.h for more details, gx_default_get_params in gsdparam.c for an
  658. example.
  659.     
  660. int (*put_params)(P2(gx_device *dev, gs_param_list *plist)) [OPTIONAL]
  661.  
  662.     Set the parameters of the device from the parameter list at plist.
  663. Return 1 if the device needs to be closed and reopened.  Again, see
  664. gsparam.h for more details, gx_default_put_params in gsdparam.c for an
  665. example.
  666.  
  667.     Changing the value of device parameters may require closing the
  668. device and reopening it.  If this is the case, the put_params procedure
  669. should return 1; a higher-level routine (gs_putdeviceparams) will close and
  670. reopen it.
  671.  
  672. External fonts
  673. --------------
  674.  
  675. Drivers may include the ability to display text.  More precisely, they may
  676. supply a set of procedures that in turn implement some font and text
  677. handling capabilities.  These procedures are documented in another file,
  678. xfonts.doc.  The link between the two is the driver procedure that
  679. supplies the font/text procedures:
  680.  
  681. xfont_procs *(*get_xfont_procs)(P1(gx_device *dev)) [OPTIONAL]
  682.  
  683.     Return a structure of procedures for handling external fonts and
  684. text display.  A NULL value means that this driver doesn't provide this
  685. capability.
  686.  
  687. For technical reasons, a second procedure is also needed:
  688.  
  689. gx_device *(*get_xfont_device)(P1(gx_device *dev)) [OPTIONAL]
  690.  
  691.     Return the device that implements get_xfont_procs in a non-default
  692. way for this device, if any.  Except for certain special internal devices,
  693. this is always the device argument.
  694.