- NUMCOLORS = 4096
- BITSPERCOMPONENT = 12
- POINTS
- INCHES
- MM
- PORTRAIT = 1
- LANDSCAPE = 2
- EPS = 0x4,EPS_PORTRAIT=0x5,
- NOIMGOPTS = 0
- USERPAGE = -1,
- USERPAGE is used internally. It is not a valid media type.
- LETTER = 0
- The following lists the known media types (paper sizes). The following lists the known media types (paper sizes).
- NA_LETTER = LETTER,LEGAL,NA_LEGAL=LEGAL,NA_10X13_ENVELOPE
- NA_9X12_ENVELOPE
- NA_NUMBER_10_ENVELOPE
- NA_7X9_ENVELOPE
- NA_9X11_ENVELOPE
- NA_10X14_ENVELOPE
- NA_6X9_ENVELOPE
- NA_10X15_ENVELOPE
- A
- B
- C
- D
- E
- ISO_A0
- ISO_A1
- ISO_A2
- ISO_A3
- ISO_A4
- A4 = ISO_A4,ISO_A5,ISO_A6,ISO_A7
- ISO_A8
- ISO_A9
- ISO_A10
- ISO_B0
- ISO_B1
- ISO_B2
- ISO_B3
- ISO_B4
- ISO_B5
- ISO_B6
- ISO_B7
- ISO_B8
- ISO_B9
- ISO_B10
- ISO_C0
- ISO_C1
- ISO_C2
- ISO_C3
- ISO_C4
- ISO_C5
- ISO_C6
- ISO_C7
- ISO_C8
- ISO_DESIGNATED
- JIS_B0
- JIS_B1
- JIS_B2
- JIS_B3
- JIS_B4
- JIS_B5
- JIS_B6
- JIS_B7
- JIS_B8
- JIS_B9
- JIS_B10
- AlignCenter = Display::AlignCenter,AlignLeft=Display::AlignLeft,AlignTop=Display::AlignTop,AlignRight=Display::AlignRight,AlignBottom=Display::AlignBottom,AlignTopLeft=Display::AlignTopLeft,AlignTopRight=Display::AlignTopRight,AlignBottomLeft=Display::AlignBottomLeft,AlignBottomRight=Display::AlignBottomRight
- STATESTACKLENGTH = 16
While there are many constructors, PSDrivers will probably most frequently be created using something like:
If it were desired to use RGB colormode rather than INDEXED,
the following could be added.
PSDriver is logically split into two sections. The 'upper' level
contains public functions, such as drawLine(). These do various
amounts of bookkeeping, such as bounding box calculations, then call
the 'lower' level routines, typically with names starting with emit.
(eg. emitLine() in this example).
There are many public routines that will rarely be called from outside
of PSDriver. Typical of these are the various xxxToAscii85 routines
that are used internally to generate image data.
Notes:
INDEXED, PORTRAIT to a default file.
Set/get desired color space. (Default is INDEXED).
Set current color used for text and vectors. Only the first
argument is used for indexed & gray.
For Indexed mode, color should be in the range (0..ncolors-1)
where ncolors is the number of colors in the table. color
is truncated to an integer.
For the others, color should be in the range (0..1).
Change color space then set color.
Load color tables with contents of a, b & c. Typically, a holds
red, b holds green & c holds blue. Values should be in the
range (0..1).
May be called anytime, but values are only used in INDEXED mode.
Start is starting index in the color table. Len is the
number of entries to set.
Change origin to x/y.
Change scale by x/y.
Rotate by # degrees.
Set the length of dashes.
Save/restore graphics state.
Display a line of text. Tabs, newlines, etc. are not handled.
Set/Get font scaling used with setFont.
Return page size (drawable area - margins).
If userCoords is True, values are in current user coordinates.
Otherwise, they are in transformed coordinates ( points).
Return bounding box.
Return is True if a bounding box was declared initially. Otherwise,
False and the current value of the bounding box will be returned.
If userCoords is True, values are in current user coordinates.
Otherwise, transformed coords.
Returns True if bounding box size was given to the constructor.
Put a comment in the output file.
The comment may include newlines.
Routines to encode non negative binary numbers in ASCII85 format.
There will be upto 5/4 as many output characters as input bytes.
Returns the number of bytes written to out.
Converts in to ASCII85 bytes using only lower 12 bits of each
integer. Out must be at least 1.75*inlength rounded up to
a multiple of 5 bytes long.
( <1.5bytes/entry>*
Encode data as ASCII85 chars. Function return is an array of
chars. (use delete [] to free). outlen is set to the number of
bytes in the array.
On input, if bpc is 8, data is treated as containing 1 byte per
element. If bpc is 12, data is assumed to contain 12 bits/element.
If bpc is 0, the array is scanned.
On return, bpc is set the the value actually used.
Miscellaneous functions to convert between typical scalings.
Return a string representation of a dimension.
Is the output EPS? Portrait?
Draw a width x height PS image.
matrix Matrix to convert between user & image space.
width, height size of input image in pixels.
bpc bits per color component. ( 8 or 12)
smooth 0 - no smoothing, 1 - smooth pixels.
ghostscript may core dump if not 0.
ascii85 data encoded as ASCII85 chars.
len length of data array.
Load one value into color table.
Thrown Exceptions
PSDriver does not currently explicitly throw any exceptions.
To Do
Member Description
enum ColorSpace
The various color spaces PSDriver knows about.
enum LineStyle
Different line types that can be drawn.
enum
Constants describing the the length of the indexed color table and the number of bits per color component.
enum Dimension
enum Layout
enum ImageOptions
Options for drawImage.
SMOOTH Pixels are interpolated. Not supported by all
interpreters. Old versions of ghostscript may core
dump if this is selected.
enum MediaSize
enum TextAlign
PSDriver()
Arguments to the various constructors:
PSDriver(ostream &out)
PSDriver(const char *filename)
PSDriver(ostream &out, const MediaSize, const MediaSize=PORTRAIT, PSInfo *info=NULL)
PSDriver(const String &fname, const MediaSize, const Layout=PORTRAIT, PSInfo *info=NULL)
PSDriver(const char *fname, const MediaSize, const Layout=PORTRAIT, PSInfo *info=NULL)
PSDriver(ostream &out, const Dimension dim, const float x0, const float y0, const float x1, const float y1, const Dimension=PORTRAIT, PSInfo *info=NULL)
PSDriver(const String &outname, const Dimension dim, const float x0, const float y0, const float x1, const float y1, const Layout=PORTRAIT, PSInfo *info=NULL)
PSDriver(const String &outname, const MediaSize, const Dimension dim, const float x0, const float y0, const float x1, const float y1, const Layout=PORTRAIT, PSInfo *info=NULL)
PSDriver(const char *outname, const Dimension dim, const float x0, const float y0, const float x1, const float y1, const Layout=PORTRAIT, PSInfo *info=NULL)
~PSDriver()
void setColorSpace(const ColorSpace)
inline ColorSpace colorSpace()const
void setColor(const float rh, const float gs, const float bv)
void setColor(const float color)
Set color value for indexed and gray scale modes.
If called when not in indexed or gray modes, the same value
is used for all three components.
void setBackgroundColor(const float rh, const float gs, const float bv, const ColorSpace=RGB)
Color to be used for dashes.
void setBackgroundColor(const float color, const ColorSpace=INDEXED)
Set color value for indexed and gray scale modes.
void setIndexColor(const float indx)
void setRGBColor(const float r, const float g, const float b)
void setHSVColor(const float h, const float s, const float v)
void setHSBColor(const float h, const float s, const float b)
void storeColors(const int start, const int len, const float *r, const float *g, const float *b)
void storeColorValues(const int len, const int *indexes, const float *a, const float *b, const float *c)
Scatter load the colortable. Much more effecient if indexes are
consecutive.
void storeColor(const int index, const float r, const float g, const float b)
Store 1 color.
void setLinearRamps(const int ncolors)
Load linear ramps (0..1.0) into the first ncolors entries.
void translate(const float x, const float y)
Current transform matrix is changed by the given values, not
replaced.
void scale(const float x, const float y)
Current transform matrix is changed by the given values, not
replaced.
void rotate(const float degrees)
Current transform matrix is changed by the given values, not
replaced.
void setDashLength(const float length)
void drawImage( const float x0, const float y0, const int width, const int height, const float xsize, const float ysize, const uShort *data, const int bpc=0, const ColorSpace=INDEXED, const int imageopts=0)
Draw an Image
x0,y0 Image is drawn with lower left corner at x0, y0.
(In current user coordinates).
width,height Size of source image in elements.
xsize,ysize Size of output image. (Eg. If current user
coordinates were in inches, a size of 2 would create
a two inch output square regardless of the size of the
input image).
data Data for an image that is width pixels wide by
height pixels high. The actual length of the array
depends on the ColorSpace argument:
INDEXED: The array contains width*height
indexes in the range 0.. 2^bpc -1.
(0..255 or 0..4095).
RGB or HSV: The array contains width*height
RGB (HSV) triples in the range
0..255 for bpc=8 or 0..1023 otherwise.
The length of the array is
width*height*3.
bpc Used to determing how data is encoded.
If (0 < bpc <= 8) 8 bit encoding is used.
If bpc > 8, 12 bit encoding is used.
If bpc <= 0, the array is scanned to determine the
encoding method.
ColorSpace Whether image is INDEXED, RGB or HSV.
imageopts Bitwise OR of IMAGEOPTS.
Currently only whether to smooth image.
void gsave()
void grestore()
void setLineStyle(const LineStyle)
Graphics
void lineWidth(const float w)
w = 1.0 means 0.005".
void moveTo(const float x, const float y)
void lineTo(const float x, const float y, const int stroke=1)
void drawPolygon(const int len, const float *x, const float *y, const int fill=0)
void drawPolyline(const int len, const float *x, const float *y, const int close=0, const int fill=0)
void drawLine( const float x0, const float y0, const float x1, const float y1)
void drawLines(const int len, const float *x1, const float *y1, const float *x2, const float *y2)
void drawRectangle(const float x0, const float y0, const float x1, const float y1, const int fill=0)
void drawFilledRectangle(const float x0, const float y0, const float x1, const float y1)
void drawPoint( const float x, const float y, const float radius=1.0)
void drawPoints(const int len, const float *x, const float *y, const float radius=1.0)
void drawColoredPoints( const int len, const float *x, const float *y, const float *colors, const float radius=1.0)
void drawText(const float x, const float y, const char *str, const TextAlign algn=AlignBottomLeft, const float angle = 0)
Text
void setFont(const char *fn)
PSDriver just passes the name to the output file.
It can't know whether the font really exists on the output device.
Set font using current font scaling.
void findFont(const char *fn, const float scale)
Use font with supplied scaling.
void setDefaultFontScale(const float scl)
float getDefaultFontScale()const
void pageSize(float &width, float &height, const Bool userCoords=True)
Misc.
Bool getBoundingBox( float &x0, float &y0, float &x1, float &y1, const Bool userCoords=True)const
inline Bool haveBoundingBox()const
void comment(const char *)
void comment(const String &)
void pushMatrix()
Push/pop transform matrix.
void popMatrix()
void newPage()
void flush()
Flush the output.
void finish()
Done. Called by the destructor.
void clipRect( const float x0, const float y0, const float width, const float height)
Set clipping rectangle.
Subsequent calls can only make the clipping rectangle smaller.
static int bytesToAscii85(const char *in, const int inlength, char *out)
The following, while public, will almost will almost
never be called from outside of PSDriver.
static int uShorts8ToAscii85(const uShort *in, const int inlength, char *out)
static int uShorts12ToAscii85(const uShort *in, const int width, const int height, char *out)
static char *encodeUShorts(const int width, const int height, int &bpc, const uShort *data, int &outlen)
static inline float pointsToInches(const float in)
static inline float pointsToMM(const float in)
static inline float inchesToPoints(const float in)
static inline float mmToPoints(const float in)
static float toPoints(const float in, const Dimension indem)
static float fromPoints(const float in, const Dimension indem)
void toPoints(const float xin, const float yin, float &xout, float &yout, const Bool absolute=True)const
Do forward or reverse transformation on a point.
If absolute is False, the translations aren't done.
void fromPoints(const float xin, const float yin, float &xout, float &yout, const Bool absolute=True)const
static const char *dimensionToString(const PSDriver::Dimension dim)
const char *dimensionToString()const
Dimension dimension()const
Bool isEPS()const
Bool isPortrait()const
static const PSDriver::PageInfo *pageInfo(const PSDriver::MediaSize)
Given a paper type, return a pointer to its description.
static const PSDriver::PageInfo *getPageInfo(const int indx)
Return page description for index indx.
static const PSDriver::PageInfo *lookupPageInfo(const char *name)
Lookup for a page description using the name field.
static int numPageTypes()
void drawImage(const float imagematrix[6], const int width, const int height, const uShort *data, const int bpc=-1, const ColorSpace cs=INDEXED, const int smooth=0)
Similar to the public drawImage but uses a transform matrix instead of
position and scaling.
imagematrix 6 element array that defines transformation
from user space to image space:
m = [ a b c d tx ty ]
x' = ax + cy + tx
y' = bx + dy + ty
The transformation is such that [ width 0 0 height 0 0] will
map the image into a unit square which would then be scaled
by the current scale() values.
To invert the image, use: [ width 0 0 -height 0 height].
If imagematrix is NULL, the image will be mapped into the
unit square.
bpc is as above.
If smooth is 0, no smoothing is done. Otherwise, pixels are
interpolated.
Caution: This routine bypasses boundary box checks! If
BB checks are not important, then this routine could be public.
void newPath()
void stroke()
These are used internally.
void closePath()
void init(ostream &output, const ColorSpace cs, const PageInfo *, const Layout, PSInfo *)
void initname(const String &name, const ColorSpace cs, const PageInfo *, const Layout, PSInfo *)
void bbCheck(const float x, const float y, const Bool userCoords=True)
Compare x/y to current bounding box. x and y are in current
user coordinates unless userCoords is False in which case they
have already been transformed.
void bbCheck()
void setCurrXY( const float x, const float y, const Bool userCoords = True)
Do bbCheck on current position.
void getCurrXY( float &x, float &y, const Bool userCoords=True)
void startDocument()
void emitHeader()
Code writers.
void emitProlog()
void emitTrailer()
void emitShowPage(const int force=0)
void emitPageNum()
void emitSetup()
void emitColorSpace(const ColorSpace)
void emitLineStyle(const LineStyle)
void emitDashLength(const float length)
void emitLineWidth(const float w)
void emitMoveTo(const float x, const float y)
void emitLineTo(const float x, const float y, const int stroke=1)
void emitPolyline(const int len, const float *x, const float *y, const int close, const int fill)
void emitPolygon(const int len, const float *x, const float *y, const int fill)
void emitLine(const float x0, const float y0, const float x1, const float y1)
void emitLines(const int len, const float *x1, const float *y1, const float *x2, const float *y2)
void emitRectangle(const float x, const float y, const float width, const float height, const int fill)
void emitPoint(const float x, const float y, const float radius=1.0)
void emitPoints(const int len, const float *x, const float *y, const float radius=1.0)
void emitRotate(const float degrees)
Rotate by degrees.
void emitScale(const float x, const float y)
Scale. (new scale = void emitTranslate(const float x, const float y)
Change origin.
void emitFindFont(const char *fn, const float scale)
void emitText(const float x, const float y, const char *str, const TextAlign=AlignBottomLeft, const float angle = 0)
Load font.
Draw text starting at point x, y.
Newlines, tabs, etc. are not handled.
void emitString(const char *str)
Just throw a string on the stack and leave it there.
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)
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 & c. Typically, a holds
red, b holds green & c holds blue. Values should be in the
range (0..1).
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. Much more effecient if indexes are consecutive.
void emitStoreColors(const int color, const int start, const int len, const float *ary)
Internal helper function.
void emitStoreColor(const int index, const float r, const float g, const float b)
void emitSetColor(const ColorSpace cs, const int index)
Set curren`t color.
void emitSetColor(const ColorSpace cs, const float a, const float b, const float c)
void emitSetLinearRamps(const int ncolors)
Load color first ncolors entries in the tables with linear
ramps scaled 0..1.
void emitGSave()
void emitGRestore()
void emitPushMatrix()
void emitPopMatrix()
void emitClipRect(const float x0, const float y0, const float width, const float height)
void emitBackgroundColor(const float a, const float b, const float c, const ColorSpace cs)
void emitBoundingBox()
Write value of bounding box to output.
void pushState()
void popState()
enum
Length of internal state(transform) stack.