www.delorie.com/gnu/docs/plotutils/plotutils_53.html   search  
 
Buy GNU books!


The Plotutils Package

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.2.6 Drawing on a physical page

GNU libplot can draw graphics over an entire page of paper, not merely within the graphics display or `viewport' that it normally uses.

The default viewport used by an Illustrator, Postscript, Fig, or PCL Plotter is a square region centered on the page. The size of the default viewport depends on the PAGESIZE parameter, which may be "letter", "a4", etc. See C. Page Sizes and Viewport Sizes. For example, the default viewport on a letter-sized page, which has width 8.5in and height 11in, is a square of side 8in.

However, you may specify different dimensions for the viewport, and a different position as well. In particular, you may specify a viewport that covers the entire page. This would be accomplished by setting PAGESIZE to, for example, "letter,xsize=8.5in,ysize=11in,xorigin=0in,yorigin=0in". "xorigin" and "yorigin" specify the location of the lower left corner of the viewport, relative to the lower left corner of the page.

With this choice for the viewport, the entire page is in principle imageable. For full-page drawing, it is convenient to define a user coordinate system in terms of which the lower left corner of the page is (0,0), and in which the units are physical inches or centimeters. To do so, you would use appropriate arguments when invoking the space operation on the Plotter. The following program shows how the space operation would be invoked.

 
#include <stdio.h> 
#include <plot.h>
     
int main()
{
  plPlotter *plotter;
  plPlotterParams *plotter_params;
     
  /* set page size parameter, including viewport size and location */
  plotter_params = pl_newplparams ();
  pl_setplparam (plotter_params, "PAGESIZE", 
                 "letter,xsize=8.5in,ysize=11in,xorigin=0in,yorigin=0in");
     
  /* create a Postscript Plotter with the specified parameter */
  plotter = pl_newpl_r ("ps", stdin, stdout, stderr, plotter_params);
     
  pl_openpl_r (plotter);                /* begin page of graphics */
  pl_fspace_r (plotter,
               0.0, 0.0, 8.5, 11.0);   /* set user coor system */
     
  pl_fontname_r (plotter, "Times-Bold");
  pl_ffontsize_r (plotter, 0.5);        /* font size = 0.5in = 36pt */

  pl_fmove_r (plotter, 1.0, 10.0);
  pl_alabel_r (plotter, 'l', 'x', "One inch below the top");
  pl_fline_r (plotter, 1.0, 10.0, 7.5, 10.0);

  pl_fmove_r (plotter, 7.5, 1.0);
  pl_alabel_r (plotter, 'r', 'x', "One inch above the bottom");
  pl_fline_r (plotter, 1.0, 1.0, 7.5, 1.0);

  pl_closepl_r (plotter);               /* end page of graphics */
  pl_deletepl_r (plotter);              /* delete Plotter */
  return 0;
}

The program will print two strings and draw the baseline for each. The first string will be left-justified at position (1.0,11.0), which is one inch below the top of the page. The second string will be right-justified at position (7.5,1.0), which is one inch above the bottom of the page. For both strings, the 'x' argument of pl_alabel_r specifies the vertical positioning: it requests that the baseline of the string, rather than (say) its top or bottom, be positioned at the current vertical position.

The preceding discussion and sample program dealt with the portrait orientation of the printed page, which is the default. Drawing in landscape orientation is only slightly more complicated. For this, the viewport would be rotated on the page by setting the Plotter parameter ROTATION. Its default value is "0" (or "no"), and other allowed values are "90" (or "yes"), "180", and "270". On a letter-sized page in landscape orientation, a rotated viewport has lower left corner (0.0,0.0) and upper right corner (11.0,8.5), provided that inches are used. The following program is a modified version of the preceding, showing how a landscape orientation would be produced.

 
#include <stdio.h> 
#include <plot.h>
     
int main()
{
  plPlotter *plotter;
  plPlotterParams *plotter_params;
     
  /* set Plotter parameters */
  plotter_params = pl_newplparams ();
  pl_setplparam (plotter_params, "PAGESIZE", 
                 "letter,xsize=8.5in,ysize=11in,xorigin=0in,yorigin=0in");
  pl_setplparam (plotter_params, "ROTATION", "90");
     
  /* create a Postscript Plotter with the specified parameters */
  plotter = pl_newpl_r ("ps", stdin, stdout, stderr, plotter_params);
     
  pl_openpl_r (plotter);                /* begin page of graphics */
  pl_fspace_r (plotter,
               0.0, 0.0, 11.0, 8.5);   /* set user coor system */
     
  pl_fontname_r (plotter, "Times-Bold");
  pl_ffontsize_r (plotter, 0.5);        /* font size = 0.5in = 36pt */

  pl_fmove_r (plotter, 1.0, 7.5);
  pl_alabel_r (plotter, 'l', 'x', "One inch below the top");
  pl_fline_r (plotter, 1.0, 7.5, 10.0, 7.5);

  pl_fmove_r (plotter, 10.0, 1.0);
  pl_alabel_r (plotter, 'r', 'x', "One inch above the bottom");
  pl_fline_r (plotter, 1.0, 1.0, 10.0, 1.0);

  pl_closepl_r (plotter);               /* end page of graphics */
  pl_deletepl_r (plotter);              /* delete Plotter */
  return 0;
}

It is worth nothing that rotating a viewport, by specifying a nonzero value for ROTATION, does not change the position of its four corners. Rather, any graphics that are drawn are rotated within it. If the viewport is rectangular rather than square, this `rotation' necessarily includes a rescaling.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright © 2003   by The Free Software Foundation     Updated Jun 2003