00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef TRIALDISPLAY_PSDRIVER_H
00029 #define TRIALDISPLAY_PSDRIVER_H
00030
00031 #include <casa/aips.h>
00032 #include <display/Display/DisplayEnums.h>
00033 #include <casa/BasicSL/String.h>
00034
00035
00036 #include <casa/iosfwd.h>
00037
00038 namespace casa {
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 class PSDriver {
00110 public:
00111
00112 enum ColorSpace { UNKNOWNSPACE=-1, INDEXED, GRAY, RGB, HSV, HSB=HSV};
00113
00114 enum LineStyle { UNKNOWNSTYPE=-1, SOLID, DASHED, DASHDASH};
00115
00116 enum {NUMCOLORS = 4096, BITSPERCOMPONENT=12};
00117 enum Dimension { POINTS, INCHES, MM};
00118 enum Layout { PORTRAIT=1, LANDSCAPE=2, EPS=0x4, EPS_PORTRAIT=0x5,
00119 EPS_LANDSCAPE=0x6
00120 };
00121
00122
00123
00124
00125
00126
00127
00128 enum ImageOptions { NOIMGOPTS=0, SMOOTH=0x1};
00129
00130 enum MediaSize {
00131
00132 USERPAGE=-1,
00133
00134 LETTER=0, NA_LETTER=LETTER, LEGAL, NA_LEGAL=LEGAL,
00135 NA_10X13_ENVELOPE, NA_9X12_ENVELOPE,
00136 NA_NUMBER_10_ENVELOPE, NA_7X9_ENVELOPE, NA_9X11_ENVELOPE,
00137 NA_10X14_ENVELOPE, NA_6X9_ENVELOPE, NA_10X15_ENVELOPE,
00138 A, B, C, D, E,
00139 ISO_A0, ISO_A1, ISO_A2, ISO_A3, ISO_A4, A4=ISO_A4, ISO_A5, ISO_A6,
00140 ISO_A7, ISO_A8, ISO_A9, ISO_A10, ISO_B0, ISO_B1, ISO_B2, ISO_B3,
00141 ISO_B4, ISO_B5, ISO_B6, ISO_B7, ISO_B8, ISO_B9, ISO_B10, ISO_C0,
00142 ISO_C1, ISO_C2, ISO_C3, ISO_C4, ISO_C5, ISO_C6, ISO_C7, ISO_C8,
00143 ISO_DESIGNATED,
00144 JIS_B0, JIS_B1, JIS_B2, JIS_B3, JIS_B4, JIS_B5, JIS_B6, JIS_B7,
00145 JIS_B8, JIS_B9, JIS_B10
00146 };
00147
00148 enum TextAlign {
00149 AlignCenter = Display::AlignCenter,
00150 AlignLeft = Display::AlignLeft,
00151 AlignTop = Display::AlignTop,
00152 AlignRight = Display::AlignRight,
00153 AlignBottom = Display::AlignBottom,
00154 AlignTopLeft = Display::AlignTopLeft,
00155 AlignTopRight = Display::AlignTopRight,
00156 AlignBottomLeft = Display::AlignBottomLeft,
00157 AlignBottomRight = Display::AlignBottomRight
00158 };
00159
00160
00161
00162
00163 class PSInfo {
00164 public:
00165 PSInfo();
00166 ~PSInfo();
00167 void Creator(const char *);
00168 void Creator(const String &);
00169 const String &Creator()const {
00170 return creator_;
00171 }
00172 void For(const char *);
00173 void For(const String &);
00174 const String &For()const {
00175 return for_;
00176 }
00177 void Title(const char *);
00178 void Title(const String &);
00179 const String &Title()const {
00180 return title_;
00181 }
00182 void Comment(const String &);
00183 void Comment(const char *);
00184 const String &Comment()const {
00185 return comment_;
00186 }
00187
00188 void setMargins(const float lm, const float rm,
00189 const float tm, const float bm,
00190 const Dimension dim= PSDriver::INCHES);
00191
00192
00193
00194 Bool getMargins(float &lm, float &rm,
00195 float &tm, float &bm);
00196 private:
00197 String for_;
00198 String title_;
00199 String creator_;
00200 String comment_;
00201 float lm_, rm_, tm_, bm_;
00202 Bool haveMargins_;
00203 };
00204
00205
00206 public:
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 PSDriver();
00223 PSDriver(ostream &out);
00224 PSDriver(const char *filename);
00225 PSDriver(ostream &out, const MediaSize, const Layout=PORTRAIT,
00226 PSInfo *info=NULL);
00227 PSDriver(const String &fname, const MediaSize, const Layout=PORTRAIT,
00228 PSInfo *info=NULL);
00229 PSDriver(const char *fname, const MediaSize, const Layout=PORTRAIT,
00230 PSInfo *info=NULL);
00231
00232 PSDriver(ostream &out, const Dimension dim,
00233 const float x0, const float y0,
00234 const float x1, const float y1,
00235 const Layout=PORTRAIT, PSInfo *info=NULL);
00236 PSDriver(const String &outname, const Dimension dim,
00237 const float x0, const float y0,
00238 const float x1, const float y1,
00239 const Layout=PORTRAIT, PSInfo *info=NULL);
00240 PSDriver(const String &outname, const MediaSize,
00241 const Dimension dim,
00242 const float x0, const float y0,
00243 const float x1, const float y1,
00244 const Layout=PORTRAIT, PSInfo *info=NULL);
00245 PSDriver(const char *outname, const Dimension dim,
00246 const float x0, const float y0,
00247 const float x1, const float y1,
00248 const Layout=PORTRAIT, PSInfo *info=NULL);
00249 ~PSDriver();
00250
00251
00252
00253
00254
00255 void setColorSpace(const ColorSpace);
00256 inline ColorSpace colorSpace()const {
00257 return colorSpace_;
00258 }
00259
00260
00261
00262
00263
00264
00265
00266 void setColor(const float rh, const float gs, const float bv);
00267
00268
00269
00270 void setColor(const float color);
00271
00272 void setBackgroundColor(const float rh, const float gs,
00273 const float bv, const ColorSpace=RGB);
00274
00275 void setBackgroundColor(const float color, const ColorSpace=INDEXED);
00276
00277
00278 void setIndexColor(const float indx);
00279 void setRGBColor(const float r, const float g, const float b);
00280 void setHSVColor(const float h, const float s, const float v) {
00281 setHSBColor(h, s, v);
00282 }
00283 void setHSBColor(const float h, const float s, const float b);
00284
00285
00286
00287
00288
00289
00290
00291 void storeColors(const int start, const int len,
00292 const float *r, const float *g, const float *b);
00293
00294
00295 void storeColorValues(const int len, const int *indexes,
00296 const float *a, const float *b, const float *c);
00297
00298 void storeColor(const int index,
00299 const float r, const float g, const float b);
00300
00301 void setLinearRamps(const int ncolors);
00302
00303
00304
00305
00306
00307
00308 void translate(const float x, const float y);
00309
00310 void scale(const float x, const float y);
00311
00312 void rotate(const float degrees);
00313
00314
00315
00316 void setDashLength(const float length);
00317 public:
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349 void drawImage( const float x0, const float y0,
00350 const int width, const int height,
00351 const float xsize, const float ysize,
00352 const uShort *data,
00353 const int bpc=0, const ColorSpace=INDEXED,
00354 const int imageopts=0);
00355
00356
00357
00358 void gsave();
00359 void grestore();
00360
00361
00362
00363
00364
00365
00366
00367 void setLineStyle(const LineStyle);
00368
00369 void lineWidth(const float w);
00370
00371 void moveTo(const float x, const float y);
00372 void lineTo(const float x, const float y, const int stroke=1);
00373
00374 void drawPolygon(const int len, const float *x, const float *y,
00375 const int fill=0);
00376 void drawPolyline(const int len, const float *x, const float *y,
00377 const int close=0, const int fill=0);
00378 void drawLine( const float x0, const float y0,
00379 const float x1, const float y1);
00380 void drawLines(const int len, const float *x1, const float *y1,
00381 const float *x2, const float *y2);
00382 void drawRectangle(const float x0, const float y0,
00383 const float x1, const float y1, const int fill=0);
00384 void drawFilledRectangle(const float x0, const float y0,
00385 const float x1, const float y1);
00386 void drawPoint( const float x, const float y, const float radius=1.0);
00387 void drawPoints(const int len, const float *x, const float *y,
00388 const float radius=1.0);
00389 void drawColoredPoints( const int len, const float *x, const float *y,
00390 const float *colors, const float radius=1.0);
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401 void drawText(const float x, const float y, const char *str,
00402 const TextAlign algn=AlignBottomLeft,
00403 const float angle = 0);
00404
00405
00406
00407
00408 void setFont(const char *fn);
00409
00410 void findFont(const char *fn, const float scale);
00411
00412
00413 void setDefaultFontScale(const float scl);
00414 float getDefaultFontScale()const {
00415 return defaultFontSize_;
00416 }
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426 void pageSize(float &width, float &height,
00427 const Bool userCoords=True);
00428
00429
00430
00431
00432
00433
00434 Bool getBoundingBox( float &x0, float &y0, float &x1, float &y1,
00435 const Bool userCoords=True)const;
00436
00437
00438 inline Bool haveBoundingBox()const {
00439 return haveBoundingBox_;
00440 }
00441
00442
00443
00444
00445 void comment(const char *);
00446 void comment(const String &);
00447
00448
00449
00450 void pushMatrix();
00451 void popMatrix();
00452
00453 void newPage();
00454
00455 void flush();
00456
00457 void finish();
00458
00459
00460 void clipRect( const float x0, const float y0,
00461 const float width, const float height);
00462 public:
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473 static int bytesToAscii85(const char *in, const int inlength,
00474 char *out);
00475 static int uShorts8ToAscii85(const uShort *in,
00476 const int inlength, char *out);
00477
00478
00479
00480
00481
00482
00483
00484 static int uShorts12ToAscii85(const uShort *in,
00485 const int width,
00486 const int height, char *out);
00487
00488
00489
00490
00491
00492
00493
00494
00495 static char *encodeUShorts(const int width, const int height,
00496 int &bpc, const uShort *data,
00497 int &outlen);
00498
00499
00500
00501 static inline float pointsToInches(const float in) {
00502 return in/72.0;
00503 }
00504 static inline float pointsToMM(const float in) {
00505 return in*(25.4/72.0);
00506 }
00507 static inline float inchesToPoints(const float in) {
00508 return in*72.0;
00509 }
00510 static inline float mmToPoints(const float in) {
00511 return in*(72./25.4);
00512 }
00513
00514 static float toPoints(const float in, const Dimension indem);
00515 static float fromPoints(const float in, const Dimension indem);
00516
00517
00518
00519
00520 void toPoints(const float xin, const float yin,
00521 float &xout, float &yout,
00522 const Bool absolute=True)const {
00523 state_.toPoints(xin, yin, xout, yout, absolute);
00524 }
00525
00526 void fromPoints(const float xin, const float yin,
00527 float &xout, float &yout,
00528 const Bool absolute=True)const {
00529 state_.fromPoints(xin, yin, xout, yout, absolute);
00530 }
00531
00532
00533
00534 static const char *dimensionToString(const PSDriver::Dimension dim);
00535 const char *dimensionToString()const {
00536 return dimensionToString(dimension_);
00537 }
00538 Dimension dimension()const {
00539 return dimension_;
00540 }
00541
00542
00543
00544 Bool isEPS()const {
00545 return eps_;
00546 }
00547 Bool isPortrait()const {
00548 return portrait_;
00549 }
00550
00551
00552
00553
00554 typedef struct PageInfo {
00555 PSDriver::MediaSize media;
00556 float width;
00557 float height;
00558 float lrmargin;
00559 float tbmargin;
00560 PSDriver::Dimension dimension;
00561 const char *name;
00562 const char *alias1;
00563 const char *alias2;
00564 } pageinfo_;
00565
00566 static const PSDriver::PageInfo *pageInfo(const PSDriver::MediaSize);
00567
00568 static const PSDriver::PageInfo *getPageInfo(const int indx);
00569
00570 static const PSDriver::PageInfo *lookupPageInfo(const char *name);
00571 static int numPageTypes();
00572 private:
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593 #if 0
00594 void drawImage(const float imagematrix[6],
00595 const int width, const int height,
00596 const uShort *data,
00597 const int bpc=-1, const ColorSpace cs=INDEXED,
00598 const int smooth=0);
00599 #endif
00600
00601 void newPath();
00602 void stroke();
00603 void closePath();
00604
00605 void init(ostream &output, const ColorSpace cs,
00606 const PageInfo *, const Layout, PSInfo *);
00607 void initname(const String &name, const ColorSpace cs,
00608 const PageInfo *, const Layout, PSInfo *);
00609
00610
00611
00612 void bbCheck(const float x, const float y, const Bool userCoords=True);
00613 void bbCheck();
00614
00615 void setCurrXY( const float x, const float y,
00616 const Bool userCoords = True) {
00617 state_.setXY(x, y, userCoords);
00618 }
00619 void getCurrXY( float &x, float &y, const Bool userCoords=True) {
00620 state_.getXY(x, y, userCoords);
00621 }
00622 private:
00623 void startDocument();
00624
00625 void emitHeader();
00626 void emitProlog();
00627 void emitTrailer();
00628 void emitShowPage(const int force=0);
00629 void emitPageNum();
00630 void emitSetup();
00631
00632 void emitColorSpace(const ColorSpace);
00633 void emitLineStyle(const LineStyle);
00634 void emitDashLength(const float length);
00635 void emitLineWidth(const float w);
00636 void emitMoveTo(const float x, const float y);
00637 void emitLineTo(const float x, const float y, const int stroke=1);
00638 void emitPolyline(const int len, const float *x, const float *y,
00639 const int close, const int fill);
00640 void emitPolygon(const int len, const float *x, const float *y,
00641 const int fill);
00642 void emitLine(const float x0, const float y0,
00643 const float x1, const float y1);
00644 void emitLines(const int len, const float *x1, const float *y1,
00645 const float *x2, const float *y2);
00646 void emitRectangle(const float x, const float y,
00647 const float width, const float height,
00648 const int fill);
00649 void emitPoint(const float x, const float y, const float radius=1.0);
00650 void emitPoints(const int len, const float *x, const float *y,
00651 const float radius=1.0);
00652
00653 void emitRotate(const float degrees);
00654
00655 void emitScale(const float x, const float y);
00656
00657 void emitTranslate(const float x, const float y);
00658
00659 void emitFindFont(const char *fn, const float scale);
00660
00661
00662 void emitText(const float x, const float y, const char *str,
00663 const TextAlign=AlignBottomLeft,
00664 const float angle = 0);
00665
00666 void emitString(const char *str);
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676 void emitImage( const float matrix[6],
00677 const int width, const int height, const int bpc,
00678 const int smooth, const char *ascii85, const int len,
00679 const ColorSpace=INDEXED);
00680
00681
00682
00683 void emitStoreColors(const int start, const int len,
00684 const float *a, const float *b, const float *c);
00685
00686
00687 void emitStoreColorValues(const int len, const int *indexes,
00688 const float *a, const float *b, const float *c);
00689
00690 void emitStoreColors(const int color, const int start, const int len,
00691 const float *ary);
00692
00693
00694 void emitStoreColor(const int index,
00695 const float r, const float g, const float b);
00696
00697 void emitSetColor(const ColorSpace cs, const int index);
00698 void emitSetColor(const ColorSpace cs,
00699 const float a, const float b, const float c);
00700
00701
00702 void emitSetLinearRamps(const int ncolors);
00703 void emitGSave();
00704 void emitGRestore();
00705 void emitPushMatrix();
00706 void emitPopMatrix();
00707 void emitClipRect(const float x0, const float y0,
00708 const float width, const float height);
00709 void emitBackgroundColor(const float a, const float b, const float c,
00710 const ColorSpace cs);
00711
00712 void emitBoundingBox();
00713 private:
00714
00715
00716 class PSState {
00717 public:
00718 PSState();
00719 ~PSState();
00720 void scale( const float x, const float y);
00721 void translate( const float x, const float y);
00722 void rotate(const float degrees);
00723
00724 inline void toPoints(const float xin, const float yin,
00725 float &xout, float &yout,
00726 const Bool absolute=True)const {
00727 xout = (float)(a_*xin + c_*yin);
00728 yout = (float)(b_*xin + d_*yin);
00729 if(absolute) {
00730 xout += (float)tx_;
00731 yout += (float)ty_;
00732 }
00733 }
00734
00735
00736 inline void fromPoints(const float xin, const float yin,
00737 float &xout, float &yout,
00738 const Bool absolute=True)const {
00739 xout = (float)(ai_*xin + ci_*yin);
00740 yout = (float)(bi_*xin + di_*yin);
00741 if(absolute) {
00742 xout += (float)txi_;
00743 yout += (float)tyi_;
00744 }
00745 }
00746
00747 void setIdentity();
00748 void operator=(const PSState &);
00749
00750 void setXY(const float x, const float y,
00751 const Bool userCoords=True);
00752 void getXY(float &x, float &y, const Bool userCoords=True);
00753 private:
00754 void invert();
00755
00756 double a_, b_, c_, d_, tx_, ty_;
00757 double ai_, bi_, ci_, di_, txi_, tyi_;
00758 float currX_, currY_;
00759
00760 };
00761 void pushState();
00762 void popState();
00763
00764 enum {STATESTACKLENGTH=16};
00765 int statestackindex_;
00766 PSState state_;
00767 PSState statestack_[STATESTACKLENGTH];
00768 ostream *out;
00769 std::fstream *mystream_;
00770 ColorSpace colorSpace_;
00771 Dimension dimension_;
00772 Bool portrait_;
00773 Bool eps_;
00774 LineStyle lineStyle_;
00775 float defaultFontSize_;
00776 float xscale_, yscale_;
00777
00778 float bbx0_, bby0_;
00779 float bbx1_, bby1_;
00780 Bool boxCheck0_;
00781 Bool haveBoundingBox_;
00782 Bool checkBoundingBox_;
00783
00784
00785 float xll_, yll_;
00786 float xur_, yur_;
00787
00788
00789 float clipXll_, clipXur_;
00790 float clipYll_, clipYur_;
00791
00792 unsigned int pageNum_;
00793 int finished_;
00794 PSInfo *info_;
00795 };
00796
00797
00798 }
00799
00800 #endif