casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PSDriver.h
Go to the documentation of this file.
1 //# PSDriver.h: Defines PSDriver, a low-level PostScript interface for the DL.
2 //# Copyright (C) 1999,2000,2001,2002,2003
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef TRIALDISPLAY_PSDRIVER_H
29 #define TRIALDISPLAY_PSDRIVER_H
30 
31 #include <casa/aips.h>
33 #include <casa/BasicSL/String.h>
34 
35 //# Forward declarations
36 #include <casa/iosfwd.h>
37 
38 namespace casa { //# NAMESPACE CASA - BEGIN
39 
40 // <summary>
41 // Low level interface between PSPixelCanvas{ColorTable} and PostScript.
42 // </summary>
43 
44 // <use visibility=local>
45 
46 //<a name="Synopsis"></a>
47 // <synopsis>
48 // PSDriver takes graphics requests from
49 // <linkto class="PSPixelCanvas"> PSPixelCanvas </linkto> and
50 // <linkto class="PSPixelCanvasColorTable"> PSPixelCanvasColorTable </linkto>
51 // and generates PostScript code. It might be thought of as playing an
52 // analogous role to what Xlib does for the X11PixelCanvas{ColorTable}.
53 // It could be used separately, but mostly programers will just
54 // create a PSDriver object to pass to PSPixelCanvas{ColorTable}.
55 //
56 // While there are many constructors, PSDrivers will probably most frequently
57 // be created using something like:
58 //
59 // <srcblock>
60 // PSdriver *ps = new PSDriver("filename", PSDriver::LETTER,
61 // PSDriver::PORTRAIT);
62 // </srcblock>
63 //
64 // If it were desired to use RGB colormode rather than INDEXED,
65 // the following could be added.
66 //
67 //<srcblock>
68 // ps->setColorSpace(PSDriver::RGB);
69 //</srcblock>
70 //
71 // PSDriver is logically split into two sections. The 'upper' level
72 // contains public functions, such as drawLine(). These do various
73 // amounts of bookkeeping, such as bounding box calculations, then call
74 // the 'lower' level routines, typically with names starting with emit.
75 // (eg. emitLine() in this example).
76 //
77 // There are many public routines that will rarely be called from outside
78 // of PSDriver. Typical of these are the various xxxToAscii85 routines
79 // that are used internally to generate image data.
80 
81 // </synopsis>
82 //
83 // <thrown>
84 // PSDriver does not currently explicitly throw any exceptions.
85 // </thrown>
86 //
87 //<a name="ToDo"></a>
88 // <todo>
89 // <ol>
90 // <li> EPS support is preliminary.
91 // <li> Vertical text justification doesn't look correct, presumably because
92 // the character's bounding box includes interline space.
93 // <li> No display list support.
94 // <li> Clipping support is disabled since it is currently possible to
95 // only reduce the size of the clipping path, not replace it.
96 // <li> Points are drawn as filled circles of fixed size.
97 // </ol>
98 // </todo>
99 //
100 // Notes:
101 // <ol>
102 // <li> It is possible to switch between Index, RGB and HSV modes at will.
103 // <li> The length of the color table is 4096 entries.
104 // <li> PostScript doesn't deal with pixels.
105 // <li> The transform matrix affects virtually everything.
106 // <li> Font names must be known by the PostScript interpreter.
107 // </ol>
108 
109  class PSDriver {
110  public:
111  // The various color spaces PSDriver knows about.
113  // Different line types that can be drawn.
115  // Constants describing the the length of the indexed color table and the number of bits per color component.
116  enum {NUMCOLORS = 4096, BITSPERCOMPONENT=12};
118  enum Layout { PORTRAIT=1, LANDSCAPE=2, EPS=0x4, EPS_PORTRAIT=0x5,
120  };
121 
122 //<srcblock>
123  // Options for drawImage.
124  // SMOOTH Pixels are interpolated. Not supported by all
125  // interpreters. Old versions of ghostscript may core
126  // dump if this is selected.
127 //</srcblock>
128  enum ImageOptions { NOIMGOPTS=0, SMOOTH=0x1};
129 
130  enum MediaSize {
131  // USERPAGE is used internally. It is not a valid media type.
133  // The following lists the known media types (paper sizes).
138  A, B, C, D, E,
146  };
147 //
148  enum TextAlign {
158  };
159 
160 // PSInfo is used to supply comment fields for the PostScript header
161 // and other information that needs to be available when the PSDriver
162 // object is created. Its use is optional.
163  class PSInfo {
164  public:
165  PSInfo();
166  ~PSInfo();
167  void Creator(const char *);
168  void Creator(const casacore::String &);
169  const casacore::String &Creator()const {
170  return creator_;
171  }
172  void For(const char *);
173  void For(const casacore::String &);
174  const casacore::String &For()const {
175  return for_;
176  }
177  void Title(const char *);
178  void Title(const casacore::String &);
179  const casacore::String &Title()const {
180  return title_;
181  }
182  void Comment(const casacore::String &);
183  void Comment(const char *);
184  const casacore::String &Comment()const {
185  return comment_;
186  }
187 
188  void setMargins(const float lm, const float rm,
189  const float tm, const float bm,
190  const Dimension dim= PSDriver::INCHES);
191  // If setMargins has been called, returns true and the
192  // margin values. Otherwise, returns false and does not
193  // change the arguments.
194  casacore::Bool getMargins(float &lm, float &rm,
195  float &tm, float &bm);
196  private:
201  float lm_, rm_, tm_, bm_; // Margins.
202  casacore::Bool haveMargins_; // setMargins has been called.
203  };
204  // Generic PostScript
205 
206  public:
207 // Arguments to the various constructors:
208 // <ul>
209 // <li> out is an ostream that the PostScript code is written to.
210 // <li> fname it the name of the output file to be written to.
211 // <li> MediaSize is the paper size. Each paper size has default margins.
212 // <li> Dimension is POINTS, INCHES or MM. Describes values of x0,y0,x1,y1.
213 // <li> x0,y0,x1,y1 are used instead of MediaSize to explicitly give
214 // the lower left and upper right corners of the
215 // drawing surface.
216 // <li> Layout is PORTRAIT or LANDSCAPE.
217 // <li> PSInfo supplies optional header comments or margins.
218 // Optional argument.
219 // </ul>
220 //
221  // INDEXED, PORTRAIT to a default file.
222  PSDriver();
223  PSDriver(std::ostream &out);
224  PSDriver(const char *filename);
225  PSDriver(std::ostream &out, const MediaSize, const Layout=PORTRAIT,
226  PSInfo *info=NULL);
227  PSDriver(const casacore::String &fname, const MediaSize, const Layout=PORTRAIT,
228  PSInfo *info=NULL);
229  PSDriver(const char *fname, const MediaSize, const Layout=PORTRAIT,
230  PSInfo *info=NULL);
231 
232  PSDriver(std::ostream &out, const Dimension dim,
233  const float x0, const float y0,
234  const float x1, const float y1,
235  const Layout=PORTRAIT, PSInfo *info=NULL);
236  PSDriver(const casacore::String &outname, const Dimension dim,
237  const float x0, const float y0,
238  const float x1, const float y1,
239  const Layout=PORTRAIT, PSInfo *info=NULL);
240  PSDriver(const casacore::String &outname, const MediaSize,
241  const Dimension dim,
242  const float x0, const float y0,
243  const float x1, const float y1,
244  const Layout=PORTRAIT, PSInfo *info=NULL);
245  PSDriver(const char *outname, const Dimension dim,
246  const float x0, const float y0,
247  const float x1, const float y1,
248  const Layout=PORTRAIT, PSInfo *info=NULL);
249  ~PSDriver();
250 
251 //# ////////////////////////////////////////////////////////////////
252 //
253  // Set/get desired color space. (Default is INDEXED).
254 //<group>
255  void setColorSpace(const ColorSpace);
256  inline ColorSpace colorSpace()const {
257  return colorSpace_;
258  }
259 //</group>
260  // Set current color used for text and vectors. Only the first
261  // argument is used for indexed & gray.
262  // For Indexed mode, color should be in the range (0..ncolors-1)
263  // where ncolors is the number of colors in the table. color
264  // is truncated to an integer.
265  // For the others, color should be in the range (0..1).
266  void setColor(const float rh, const float gs, const float bv);
267  // Set color value for indexed and gray scale modes.
268  // If called when not in indexed or gray modes, the same value
269  // is used for all three components.
270  void setColor(const float color);
271  // Color to be used for dashes.
272  void setBackgroundColor(const float rh, const float gs,
273  const float bv, const ColorSpace=RGB);
274  // Set color value for indexed and gray scale modes.
275  void setBackgroundColor(const float color, const ColorSpace=INDEXED);
276 
277  // Change color space then set color.
278  void setIndexColor(const float indx);
279  void setRGBColor(const float r, const float g, const float b);
280  void setHSVColor(const float h, const float s, const float v) {
281  setHSBColor(h, s, v);
282  }
283  void setHSBColor(const float h, const float s, const float b);
284 
285  // Load color tables with contents of a, b & c. Typically, a holds
286  // red, b holds green & c holds blue. Values should be in the
287  // range (0..1).
288  // May be called anytime, but values are only used in INDEXED mode.
289  // Start is starting index in the color table. Len is the
290  // number of entries to set.
291  void storeColors(const int start, const int len,
292  const float *r, const float *g, const float *b);
293  // Scatter load the colortable. Much more effecient if indexes are
294  // consecutive.
295  void storeColorValues(const int len, const int *indexes,
296  const float *a, const float *b, const float *c);
297  // Store 1 color.
298  void storeColor(const int index,
299  const float r, const float g, const float b);
300  // Load linear ramps (0..1.0) into the first ncolors entries.
301  void setLinearRamps(const int ncolors);
302 //# ////////////////////////////////////////////////////////////////
303 //# // casacore::Coordinate commands.
304  // Current transform matrix is changed by the given values, not
305  // replaced.
306 // <group>
307  // Change origin to x/y.
308  void translate(const float x, const float y);
309  // Change scale by x/y.
310  void scale(const float x, const float y);
311  // Rotate by # degrees.
312  void rotate(const float degrees);
313 // </group>
314 
315  // Set the length of dashes.
316  void setDashLength(const float length);
317  public:
318 //# ////////////////////////////////////////////////////////////////
319 //<srcblock>
320  // Draw an Image
321  // x0,y0 Image is drawn with lower left corner at x0, y0.
322  // (In current user coordinates).
323  // width,height Size of source image in elements.
324  // xsize,ysize Size of output image. (Eg. If current user
325  // coordinates were in inches, a size of 2 would create
326  // a two inch output square regardless of the size of the
327  // input image).
328  // data casacore::Data for an image that is width pixels wide by
329  // height pixels high. The actual length of the array
330  // depends on the ColorSpace argument:
331  // INDEXED: The array contains width*height
332  // indexes in the range 0.. 2^bpc -1.
333  // (0..255 or 0..4095).
334  // RGB or HSV: The array contains width*height
335  // RGB (HSV) triples in the range
336  // 0..255 for bpc=8 or 0..1023 otherwise.
337  // The length of the array is
338  // width*height*3.
339  // bpc Used to determing how data is encoded.
340  // If (0 < bpc <= 8) 8 bit encoding is used.
341  // If bpc > 8, 12 bit encoding is used.
342  // If bpc <= 0, the array is scanned to determine the
343  // encoding method.
344  // ColorSpace Whether image is INDEXED, RGB or HSV.
345  // imageopts Bitwise OR of IMAGEOPTS.
346  // Currently only whether to smooth image.
347 //</srcblock>
348 
349  void drawImage( const float x0, const float y0,
350  const int width, const int height,
351  const float xsize, const float ysize,
352  const casacore::uShort *data,
353  const int bpc=0, const ColorSpace=INDEXED,
354  const int imageopts=0);
355 
356  // Save/restore graphics state.
357 //<group>
358  void gsave();
359  void grestore();
360 //</group>
361 //
362 //<srcblock>
363  // Graphics
364 //</srcblock>
365 //
366 
367  void setLineStyle(const LineStyle);
368  // w = 1.0 means 0.005".
369  void lineWidth(const float w);
370 
371  void moveTo(const float x, const float y);
372  void lineTo(const float x, const float y, const int stroke=1);
373 
374  void drawPolygon(const int len, const float *x, const float *y,
375  const int fill=0);
376  void drawPolyline(const int len, const float *x, const float *y,
377  const int close=0, const int fill=0);
378  void drawLine( const float x0, const float y0,
379  const float x1, const float y1);
380  void drawLines(const int len, const float *x1, const float *y1,
381  const float *x2, const float *y2);
382  void drawRectangle(const float x0, const float y0,
383  const float x1, const float y1, const int fill=0);
384  void drawFilledRectangle(const float x0, const float y0,
385  const float x1, const float y1);
386  void drawPoint( const float x, const float y, const float radius=1.0);
387  void drawPoints(const int len, const float *x, const float *y,
388  const float radius=1.0);
389  void drawColoredPoints( const int len, const float *x, const float *y,
390  const float *colors, const float radius=1.0);
391 
392 
393 //# ////////////////////////////////////////////////////////////////
394 //
395 //<srcblock>
396  // Text
397 //</srcblock>
398 //#
399 
400 // Display a line of text. Tabs, newlines, etc. are not handled.
401  void drawText(const float x, const float y, const char *str,
402  const TextAlign algn=AlignBottomLeft,
403  const float angle = 0);
404 //<note role=caution> PSDriver just passes the name to the output file.
405 // It can't know whether the font really exists on the output device.
406 //</note>
407  // Set font using current font scaling.
408  void setFont(const char *fn);
409  // Use font with supplied scaling.
410  void findFont(const char *fn, const float scale);
411 
412  // Set/Get font scaling used with setFont.
413  void setDefaultFontScale(const float scl);
414  float getDefaultFontScale()const {
415  return defaultFontSize_;
416  }
417 //
418 //# ////////////////////////////////////////////////////////////////
419 //<srcblock>
420  // Misc.
421 //</srcblock>
422 //
423  // Return page size (drawable area - margins).
424  // If userCoords is true, values are in current user coordinates.
425  // Otherwise, they are in transformed coordinates ( points).
426  void pageSize(float &width, float &height,
427  const casacore::Bool userCoords=true);
428 
429  // Return bounding box.
430  // Return is true if a bounding box was declared initially. Otherwise,
431  // false and the current value of the bounding box will be returned.
432  // If userCoords is true, values are in current user coordinates.
433  // Otherwise, transformed coords.
434  casacore::Bool getBoundingBox( float &x0, float &y0, float &x1, float &y1,
435  const casacore::Bool userCoords=true)const;
436 
437  // Returns true if bounding box size was given to the constructor.
439  return haveBoundingBox_;
440  }
441 
442  // Put a comment in the output file.
443  // The comment may include newlines.
444 //<group>
445  void comment(const char *);
446  void comment(const casacore::String &);
447 //</group>
448  // Push/pop transform matrix.
449 //<group>
450  void pushMatrix();
451  void popMatrix();
452 //</group>
453  void newPage();
454  // Flush the output.
455  void flush();
456  // Done. Called by the destructor.
457  void finish();
458  // Set clipping rectangle.
459  // Subsequent calls can only make the clipping rectangle smaller.
460  void clipRect( const float x0, const float y0,
461  const float width, const float height);
462  public:
463 //
464 //<srcblock>
465 // The following, while public, will almost will almost
466 // never be called from outside of PSDriver.
467 //</srcblock>
468 
469  // Routines to encode non negative binary numbers in ASCII85 format.
470  // There will be upto 5/4 as many output characters as input bytes.
471  // Returns the number of bytes written to out.
472 
473  static int bytesToAscii85(const char *in, const int inlength,
474  char *out);
475  static int uShorts8ToAscii85(const casacore::uShort *in,
476  const int inlength, char *out);
477 
478 
479  // Converts in to ASCII85 bytes using only lower 12 bits of each
480  // integer. Out must be at least 1.75*inlength rounded up to
481  // a multiple of 5 bytes long.
482  // ( <1.5bytes/entry>*<inlength entries>*<1.25 expansion>).
483  // If inlength is odd, a 0 valued entry will be implicitly added.
484  static int uShorts12ToAscii85(const casacore::uShort *in,
485  const int width,
486  const int height, char *out);
487 
488  // Encode data as ASCII85 chars. casacore::Function return is an array of
489  // chars. (use delete [] to free). outlen is set to the number of
490  // bytes in the array.
491  // On input, if bpc is 8, data is treated as containing 1 byte per
492  // element. If bpc is 12, data is assumed to contain 12 bits/element.
493  // If bpc is 0, the array is scanned.
494  // On return, bpc is set the the value actually used.
495  static char *encodeUShorts(const int width, const int height,
496  int &bpc, const casacore::uShort *data,
497  int &outlen);
498 
499 //# ////////////////////////////////////////////////////////////////
500  // Miscellaneous functions to convert between typical scalings.
501  static inline float pointsToInches(const float in) {
502  return in/72.0;
503  }
504  static inline float pointsToMM(const float in) {
505  return in*(25.4/72.0);
506  }
507  static inline float inchesToPoints(const float in) {
508  return in*72.0;
509  }
510  static inline float mmToPoints(const float in) {
511  return in*(72./25.4);
512  }
513 
514  static float toPoints(const float in, const Dimension indem);
515  static float fromPoints(const float in, const Dimension indem);
516 //# ////////////////////////////////////////////////////////////////
517 
518  // Do forward or reverse transformation on a point.
519  // If absolute is false, the translations aren't done.
520  void toPoints(const float xin, const float yin,
521  float &xout, float &yout,
522  const casacore::Bool absolute=true)const {
523  state_.toPoints(xin, yin, xout, yout, absolute);
524  }
525 
526  void fromPoints(const float xin, const float yin,
527  float &xout, float &yout,
528  const casacore::Bool absolute=true)const {
529  state_.fromPoints(xin, yin, xout, yout, absolute);
530  }
531 
532 
533  // Return a string representation of a dimension.
534  static const char *dimensionToString(const PSDriver::Dimension dim);
535  const char *dimensionToString()const {
537  }
539  return dimension_;
540  }
541 
542  // Is the output EPS? Portrait?
543 //<group>
545  return eps_;
546  }
548  return portrait_;
549  }
550 //</group>
551 
552  // The PageInfo struct is used internally to supply descriptions
553  // of the various page types.
554  typedef struct PageInfo {
555  PSDriver::MediaSize media; // A4, LETTER, etc.
556  float width;
557  float height;
558  float lrmargin;
559  float tbmargin;
560  PSDriver::Dimension dimension; // MM or INCHES.
561  const char *name; //"North American letter", etc.
562  const char *alias1; // "NA_LETTER", etc.
563  const char *alias2; // "LETTER", etc.
564  } pageinfo_;
565  // Given a paper type, return a pointer to its description.
566  static const PSDriver::PageInfo *pageInfo(const PSDriver::MediaSize);
567  // Return page description for index indx.
568  static const PSDriver::PageInfo *getPageInfo(const int indx);
569  // Lookup for a page description using the name field.
570  static const PSDriver::PageInfo *lookupPageInfo(const char *name);
571  static int numPageTypes(); // # of page types.
572  private:
573 //<srcblock>
574  // Similar to the public drawImage but uses a transform matrix instead of
575  // position and scaling.
576  // imagematrix 6 element array that defines transformation
577  // from user space to image space:
578  // m = [ a b c d tx ty ]
579  // x' = ax + cy + tx
580  // y' = bx + dy + ty
581  // The transformation is such that [ width 0 0 height 0 0] will
582  // map the image into a unit square which would then be scaled
583  // by the current scale() values.
584  // To invert the image, use: [ width 0 0 -height 0 height].
585  // If imagematrix is NULL, the image will be mapped into the
586  // unit square.
587  // bpc is as above.
588  // If smooth is 0, no smoothing is done. Otherwise, pixels are
589  // interpolated.
590  // Caution: This routine bypasses boundary box checks! If
591  // BB checks are not important, then this routine could be public.
592 //</srcblock>
593 #if 0
594  void drawImage(const float imagematrix[6],
595  const int width, const int height,
596  const casacore::uShort *data,
597  const int bpc=-1, const ColorSpace cs=INDEXED,
598  const int smooth=0);
599 #endif
600 //# ////////////////////////////////////////////////////////////////
601  void newPath(); // These are used internally.
602  void stroke();
603  void closePath();
604 //# ////////////////////////////////////////////////////////////////
605  void init(std::ostream &output, const ColorSpace cs,
606  const PageInfo *, const Layout, PSInfo *);
607  void initname(const casacore::String &name, const ColorSpace cs,
608  const PageInfo *, const Layout, PSInfo *);
609  // Compare x/y to current bounding box. x and y are in current
610  // user coordinates unless userCoords is false in which case they
611  // have already been transformed.
612  void bbCheck(const float x, const float y, const casacore::Bool userCoords=true);
613  void bbCheck(); // Do bbCheck on current position.
614 
615  void setCurrXY( const float x, const float y,
616  const casacore::Bool userCoords = true) {
617  state_.setXY(x, y, userCoords);
618  }
619  void getCurrXY( float &x, float &y, const casacore::Bool userCoords=true) {
620  state_.getXY(x, y, userCoords);
621  }
622  private:
623  void startDocument();
624  // Code writers.
625  void emitHeader();
626  void emitProlog();
627  void emitTrailer();
628  void emitShowPage(const int force=0);
629  void emitPageNum();
630  void emitSetup();
631 
632  void emitColorSpace(const ColorSpace);
633  void emitLineStyle(const LineStyle);
634  void emitDashLength(const float length);
635  void emitLineWidth(const float w);
636  void emitMoveTo(const float x, const float y);
637  void emitLineTo(const float x, const float y, const int stroke=1);
638  void emitPolyline(const int len, const float *x, const float *y,
639  const int close, const int fill);
640  void emitPolygon(const int len, const float *x, const float *y,
641  const int fill);
642  void emitLine(const float x0, const float y0,
643  const float x1, const float y1);
644  void emitLines(const int len, const float *x1, const float *y1,
645  const float *x2, const float *y2);
646  void emitRectangle(const float x, const float y,
647  const float width, const float height,
648  const int fill);
649  void emitPoint(const float x, const float y, const float radius=1.0);
650  void emitPoints(const int len, const float *x, const float *y,
651  const float radius=1.0);
652  // Rotate by degrees.
653  void emitRotate(const float degrees);
654  // Scale. (new scale = <old scale>*<new scale>.
655  void emitScale(const float x, const float y);
656  // Change origin.
657  void emitTranslate(const float x, const float y);
658 
659  void emitFindFont(const char *fn, const float scale); // Load font.
660  // Draw text starting at point x, y.
661  // Newlines, tabs, etc. are not handled.
662  void emitText(const float x, const float y, const char *str,
664  const float angle = 0);
665  // Just throw a string on the stack and leave it there.
666  void emitString(const char *str);
667 
668  // Draw a width x height PS image.
669  // matrix casacore::Matrix to convert between user & image space.
670  // width, height size of input image in pixels.
671  // bpc bits per color component. ( 8 or 12)
672  // smooth 0 - no smoothing, 1 - smooth pixels.
673  // ghostscript may core dump if not 0.
674  // ascii85 data encoded as ASCII85 chars.
675  // len length of data array.
676  void emitImage( const float matrix[6],
677  const int width, const int height, const int bpc,
678  const int smooth, const char *ascii85, const int len,
679  const ColorSpace=INDEXED);
680  // Load color tables with contents of a, b & c. Typically, a holds
681  // red, b holds green & c holds blue. Values should be in the
682  // range (0..1).
683  void emitStoreColors(const int start, const int len,
684  const float *a, const float *b, const float *c);
685  // Load color tables given an array of colors and their corresponding
686  // indexes. Much more effecient if indexes are consecutive.
687  void emitStoreColorValues(const int len, const int *indexes,
688  const float *a, const float *b, const float *c);
689  // Internal helper function.
690  void emitStoreColors(const int color, const int start, const int len,
691  const float *ary);
692 
693  // Load one value into color table.
694  void emitStoreColor(const int index,
695  const float r, const float g, const float b);
696  // Set curren`t color.
697  void emitSetColor(const ColorSpace cs, const int index);
698  void emitSetColor(const ColorSpace cs,
699  const float a, const float b, const float c);
700  // Load color first ncolors entries in the tables with linear
701  // ramps scaled 0..1.
702  void emitSetLinearRamps(const int ncolors);
703  void emitGSave();
704  void emitGRestore();
705  void emitPushMatrix();
706  void emitPopMatrix();
707  void emitClipRect(const float x0, const float y0,
708  const float width, const float height);
709  void emitBackgroundColor(const float a, const float b, const float c,
710  const ColorSpace cs);
711  // Write value of bounding box to output.
712  void emitBoundingBox();
713  private:
714  // Holds our copy of the current transformation matrix. Used for
715  // bounding box computations.
716  class PSState {
717  public:
718  PSState();
719  ~PSState();
720  void scale( const float x, const float y);
721  void translate( const float x, const float y);
722  void rotate(const float degrees);
723  // [ x' y' 1 ] = [ x y 1] * CTM
724  inline void toPoints(const float xin, const float yin,
725  float &xout, float &yout,
726  const casacore::Bool absolute=true)const {
727  xout = (float)(a_*xin + c_*yin);
728  yout = (float)(b_*xin + d_*yin);
729  if(absolute) {
730  xout += (float)tx_;
731  yout += (float)ty_;
732  }
733  }
734 
735  // [ x y 1 ] = [ x' y' 1] * inverse(CTM);
736  inline void fromPoints(const float xin, const float yin,
737  float &xout, float &yout,
738  const casacore::Bool absolute=true)const {
739  xout = (float)(ai_*xin + ci_*yin);
740  yout = (float)(bi_*xin + di_*yin);
741  if(absolute) {
742  xout += (float)txi_;
743  yout += (float)tyi_;
744  }
745  }
746 
747  void setIdentity();
748  void operator=(const PSState &);
749  // Set/Get the current position.
750  void setXY(const float x, const float y,
751  const casacore::Bool userCoords=true);
752  void getXY(float &x, float &y, const casacore::Bool userCoords=true);
753  private:
754  void invert();
755 
756  double a_, b_, c_, d_, tx_, ty_; // Forward
757  double ai_, bi_, ci_, di_, txi_, tyi_; // Inverse
758  float currX_, currY_; // Current x/y in pnts
759 
760  };
761  void pushState();
762  void popState();
763  // Length of internal state(transform) stack.
764  enum {STATESTACKLENGTH=16};
768  std::ostream *out;
769  std::fstream *mystream_;
776  float xscale_, yscale_; // Paper size scale.
777  // Bounding box in points.
778  float bbx0_, bby0_;
779  float bbx1_, bby1_;
780  casacore::Bool boxCheck0_; // Has anything been checked?
783  // user coords.
784  // Page boundaries in points;
785  float xll_, yll_;
786  float xur_, yur_;
787 
788  // Clipping rectangle in points.
791 
792  unsigned int pageNum_; // Current page number.
793  int finished_; // Set when finished called.
795  };
796 
797 
798 } //# NAMESPACE CASA - END
799 
800 #endif
PSDriver::Dimension dimension
Definition: PSDriver.h:560
void rotate(const float degrees)
Rotate by # degrees.
void setRGBColor(const float r, const float g, const float b)
void setHSBColor(const float h, const float s, const float b)
void emitShowPage(const int force=0)
static float fromPoints(const float in, const Dimension indem)
void emitScale(const float x, const float y)
Scale.
void setHSVColor(const float h, const float s, const float v)
Definition: PSDriver.h:280
void drawPoints(const int len, const float *x, const float *y, const float radius=1.0)
void drawLine(const float x0, const float y0, const float x1, const float y1)
void setLinearRamps(const int ncolors)
Load linear ramps (0..1.0) into the first ncolors entries.
static int numPageTypes()
void lineTo(const float x, const float y, const int stroke=1)
ColorSpace colorSpace() const
Definition: PSDriver.h:256
casacore::String comment_
Definition: PSDriver.h:200
struct casa::PSDriver::PageInfo pageinfo_
The PageInfo struct is used internally to supply descriptions of the various page types...
Low level interface between PSPixelCanvas{ColorTable} and PostScript.
Definition: PSDriver.h:109
const char * alias2
Definition: PSDriver.h:563
void setFont(const char *fn)
Holds our copy of the current transformation matrix.
Definition: PSDriver.h:716
void emitPolygon(const int len, const float *x, const float *y, const int fill)
void storeColorValues(const int len, const int *indexes, const float *a, const float *b, const float *c)
Scatter load the colortable.
void storeColors(const int start, const int len, const float *r, const float *g, const float *b)
Load color tables with contents of a, b &amp; c.
void init(std::ostream &output, const ColorSpace cs, const PageInfo *, const Layout, PSInfo *)
void drawText(const float x, const float y, const char *str, const TextAlign algn=AlignBottomLeft, const float angle=0)
br&gt;&lt;strong&gt;Caution:&lt;/strong&gt;&lt;em&gt; PSDriver just passes the name to the output file; It can&#39;t know w...
PSInfo * info_
Definition: PSDriver.h:794
void toPoints(const float xin, const float yin, float &xout, float &yout, const casacore::Bool absolute=true) const
Do forward or reverse transformation on a point.
Definition: PSDriver.h:520
void emitStoreColor(const int index, const float r, const float g, const float b)
Load one value into color table.
void setXY(const float x, const float y, const casacore::Bool userCoords=true)
Set/Get the current position.
void setDashLength(const float length)
Set the length of dashes.
PSState statestack_[STATESTACKLENGTH]
Definition: PSDriver.h:767
void emitRectangle(const float x, const float y, const float width, const float height, const int fill)
void fromPoints(const float xin, const float yin, float &xout, float &yout, const casacore::Bool absolute=true) const
[ x y 1 ] = [ x&#39; y&#39; 1] * inverse(CTM);
Definition: PSDriver.h:736
const casacore::String & Creator() const
Definition: PSDriver.h:169
const char * dimensionToString() const
Definition: PSDriver.h:535
void drawColoredPoints(const int len, const float *x, const float *y, const float *colors, const float radius=1.0)
void finish()
Done.
void emitPoint(const float x, const float y, const float radius=1.0)
std::fstream * mystream_
Definition: PSDriver.h:769
static float toPoints(const float in, const Dimension indem)
void setCurrXY(const float x, const float y, const casacore::Bool userCoords=true)
Definition: PSDriver.h:615
void emitColorSpace(const ColorSpace)
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
casacore::Bool portrait_
Definition: PSDriver.h:772
void emitBackgroundColor(const float a, const float b, const float c, const ColorSpace cs)
void emitLines(const int len, const float *x1, const float *y1, const float *x2, const float *y2)
casacore::Bool haveBoundingBox() const
Returns true if bounding box size was given to the constructor.
Definition: PSDriver.h:438
void drawPoint(const float x, const float y, const float radius=1.0)
static int uShorts12ToAscii85(const casacore::uShort *in, const int width, const int height, char *out)
Converts in to ASCII85 bytes using only lower 12 bits of each integer.
casacore::Bool haveBoundingBox_
Definition: PSDriver.h:781
static const PSDriver::PageInfo * getPageInfo(const int indx)
Return page description for index indx.
void toPoints(const float xin, const float yin, float &xout, float &yout, const casacore::Bool absolute=true) const
[ x&#39; y&#39; 1 ] = [ x y 1] * CTM
Definition: PSDriver.h:724
The PageInfo struct is used internally to supply descriptions of the various page types...
Definition: PSDriver.h:554
static const PSDriver::PageInfo * lookupPageInfo(const char *name)
Lookup for a page description using the name field.
void translate(const float x, const float y)
void drawImage(const float x0, const float y0, const int width, const int height, const float xsize, const float ysize, const casacore::uShort *data, const int bpc=0, const ColorSpace=INDEXED, const int imageopts=0)
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
Definition: PlotData.h:48
void emitStoreColorValues(const int len, const int *indexes, const float *a, const float *b, const float *c)
Load color tables given an array of colors and their corresponding indexes.
reference point aligned to center of text
Definition: DisplayEnums.h:183
casacore::String creator_
Definition: PSDriver.h:199
void emitLine(const float x0, const float y0, const float x1, const float y1)
void emitHeader()
Code writers.
void initname(const casacore::String &name, const ColorSpace cs, const PageInfo *, const Layout, PSInfo *)
reference point aligned to bottom right corner of text
Definition: DisplayEnums.h:199
const casacore::String & Comment() const
Definition: PSDriver.h:184
void lineWidth(const float w)
w = 1.0 means 0.005".
void emitClipRect(const float x0, const float y0, const float width, const float height)
void emitText(const float x, const float y, const char *str, const TextAlign=AlignBottomLeft, const float angle=0)
Draw text starting at point x, y.
casacore::Bool eps_
Definition: PSDriver.h:773
void gsave()
Save/restore graphics state.
void findFont(const char *fn, const float scale)
Use font with supplied scaling.
void storeColor(const int index, const float r, const float g, const float b)
Store 1 color.
void scale(const float x, const float y)
void moveTo(const float x, const float y)
LineStyle
Different line types that can be drawn.
Definition: PSDriver.h:114
void emitLineWidth(const float w)
float clipYll_
Definition: PSDriver.h:790
LineStyle lineStyle_
Definition: PSDriver.h:774
static const PSDriver::PageInfo * pageInfo(const PSDriver::MediaSize)
Given a paper type, return a pointer to its description.
void emitMoveTo(const float x, const float y)
const casacore::String & Title() const
Definition: PSDriver.h:179
reference point aligned to top right corner of text
Definition: DisplayEnums.h:195
LatticeExprNode length(const LatticeExprNode &expr, const LatticeExprNode &axis)
2-argument function to get the length of an axis.
void fromPoints(const float xin, const float yin, float &xout, float &yout, const casacore::Bool absolute=true) const
Definition: PSDriver.h:526
void emitPushMatrix()
void smooth(CalSet< casacore::Complex > &cs, const casacore::String &smtype, const casacore::Double &smtime, casacore::Vector< casacore::Int > selfields)
Globals.
const char * alias1
Definition: PSDriver.h:562
static float pointsToInches(const float in)
Miscellaneous functions to convert between typical scalings.
Definition: PSDriver.h:501
PSDriver()
Generic PostScript.
void rotate(const float degrees)
reference point aligned to center ot top edge of text
Definition: DisplayEnums.h:187
The following lists the known media types (paper sizes).
Definition: PSDriver.h:134
void getCurrXY(float &x, float &y, const casacore::Bool userCoords=true)
Definition: PSDriver.h:619
reference point aligned to center of right edge of text
Definition: DisplayEnums.h:189
float clipXur_
Definition: PSDriver.h:789
void emitSetColor(const ColorSpace cs, const int index)
Set curren`t color.
static float inchesToPoints(const float in)
Definition: PSDriver.h:507
casacore::Bool checkBoundingBox_
Definition: PSDriver.h:782
void drawPolygon(const int len, const float *x, const float *y, const int fill=0)
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
PSDriver::MediaSize media
Definition: PSDriver.h:555
float getDefaultFontScale() const
Definition: PSDriver.h:414
static int bytesToAscii85(const char *in, const int inlength, char *out)
casacore::Bool isEPS() const
Is the output EPS? Portrait?
Definition: PSDriver.h:544
void drawPolyline(const int len, const float *x, const float *y, const int close=0, const int fill=0)
void emitTranslate(const float x, const float y)
Change origin.
void emitImage(const float matrix[6], const int width, const int height, const int bpc, const int smooth, const char *ascii85, const int len, const ColorSpace=INDEXED)
Draw a width x height PS image.
void emitPageNum()
static float pointsToMM(const float in)
Definition: PSDriver.h:504
void emitLineStyle(const LineStyle)
void emitSetLinearRamps(const int ncolors)
Load color first ncolors entries in the tables with linear ramps scaled 0..1.
static int uShorts8ToAscii85(const casacore::uShort *in, const int inlength, char *out)
void emitBoundingBox()
Write value of bounding box to output.
unsigned int pageNum_
Definition: PSDriver.h:792
void clipRect(const float x0, const float y0, const float width, const float height)
Set clipping rectangle.
void emitRotate(const float degrees)
Rotate by degrees.
void getXY(float &x, float &y, const casacore::Bool userCoords=true)
ColorSpace colorSpace_
Definition: PSDriver.h:770
void setIndexColor(const float indx)
Change color space then set color.
void emitGRestore()
std::ostream * out
Definition: PSDriver.h:768
int statestackindex_
Definition: PSDriver.h:765
ColorSpace
The various color spaces PSDriver knows about.
Definition: PSDriver.h:112
casacore::Bool getBoundingBox(float &x0, float &y0, float &x1, float &y1, const casacore::Bool userCoords=true) const
Return bounding box.
static float mmToPoints(const float in)
Definition: PSDriver.h:510
void setMargins(const float lm, const float rm, const float tm, const float bm, const Dimension dim=PSDriver::INCHES)
void emitTrailer()
float xll_
user coords.
Definition: PSDriver.h:785
void emitLineTo(const float x, const float y, const int stroke=1)
void emitDashLength(const float length)
void startDocument()
reference point aligned to center of bottom edge of text
Definition: DisplayEnums.h:191
void pushMatrix()
Push/pop transform matrix.
void emitPopMatrix()
void drawLines(const int len, const float *x1, const float *y1, const float *x2, const float *y2)
float xscale_
Definition: PSDriver.h:776
void emitStoreColors(const int start, const int len, const float *a, const float *b, const float *c)
Load color tables with contents of a, b &amp; c.
void flush()
Flush the output.
void emitFindFont(const char *fn, const float scale)
const Double c
Fundamental physical constants (SI units):
PSState state_
Definition: PSDriver.h:766
casacore::Bool getMargins(float &lm, float &rm, float &tm, float &bm)
If setMargins has been called, returns true and the margin values.
casacore::Bool haveMargins_
Definition: PSDriver.h:202
void emitPolyline(const int len, const float *x, const float *y, const int close, const int fill)
String: the storage and methods of handling collections of characters.
Definition: String.h:223
casacore::String title_
Definition: PSDriver.h:198
float clipXll_
Clipping rectangle in points.
Definition: PSDriver.h:789
static char * encodeUShorts(const int width, const int height, int &bpc, const casacore::uShort *data, int &outlen)
Encode data as ASCII85 chars.
void translate(const float x, const float y)
Current transform matrix is changed by the given values, not replaced.
void setColorSpace(const ColorSpace)
Set/get desired color space.
float bbx0_
Bounding box in points.
Definition: PSDriver.h:778
void scale(const float x, const float y)
Change scale by x/y.
void drawFilledRectangle(const float x0, const float y0, const float x1, const float y1)
void setBackgroundColor(const float rh, const float gs, const float bv, const ColorSpace=RGB)
Color to be used for dashes.
casacore::Bool boxCheck0_
Definition: PSDriver.h:780
casacore::Bool isPortrait() const
Definition: PSDriver.h:547
void operator=(const PSState &)
void emitString(const char *str)
Just throw a string on the stack and leave it there.
void setLineStyle(const LineStyle)
const casacore::String & For() const
Definition: PSDriver.h:174
casacore::String for_
Definition: PSDriver.h:197
void emitPoints(const int len, const float *x, const float *y, const float radius=1.0)
Dimension dimension_
Definition: PSDriver.h:771
reference point aligned to center of left edge of text
Definition: DisplayEnums.h:185
PSInfo is used to supply comment fields for the PostScript header and other information that needs to...
Definition: PSDriver.h:163
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the color(i.e.,"000000"for black) and
void pageSize(float &width, float &height, const casacore::Bool userCoords=true)
float defaultFontSize_
Definition: PSDriver.h:775
USERPAGE is used internally.
Definition: PSDriver.h:132
reference point aligned to top left corner of text
Definition: DisplayEnums.h:193
float yscale_
Definition: PSDriver.h:776
void comment(const char *)
Put a comment in the output file.
float clipYur_
Definition: PSDriver.h:790
Dimension dimension() const
Definition: PSDriver.h:538
void setColor(const float rh, const float gs, const float bv)
Set current color used for text and vectors.
void drawRectangle(const float x0, const float y0, const float x1, const float y1, const int fill=0)
void setDefaultFontScale(const float scl)
Set/Get font scaling used with setFont.
reference point aligned to bottom left corner of text
Definition: DisplayEnums.h:197
unsigned short uShort
Definition: aipstype.h:49