GhostScript.h
Go to the documentation of this file.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
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00048
#ifndef GHOSTSCRIPT_INC
00049
#define GHOSTSCRIPT_INC
00050
00051
00052
00053
00054
00055
#include <plearn/math/Mat.h>
00056
00057
namespace PLearn {
00058
using namespace std;
00059
00064
real rgb2real(
real r,
real g,
real b);
00065
void real2rgb(
real colorval,
real& r,
real& g,
real& b);
00066
00067 class GhostScript
00068 {
00069
protected:
00070 FILE*
gs_cstream;
00071 PStream togs;
00072 char command_string[1000];
00073 bool isfile;
00074
static void writeBitmapHexString1Bit(
const Mat& bm,
PStream& out,
bool lastrowfirst=
false);
00075
static void writeBitmapHexString8Bits(
const Mat& bm,
PStream& out,
bool lastrowfirst=
false);
00076
static void writeBitmapHexString24Bits(
const Mat& bm,
PStream& out,
bool lastrowfirst=
false);
00077
00078
00079
#if __GNUC__ > 2 && !defined(WIN32)
00080
typedef ios::char_type
char_type;
00081
#else
00082 typedef ios::char_type
char_type;
00083
#endif
00084
00085
00086
00087
00088
00089
00090
00091
public:
00092
00094
GhostScript(
int width=200,
int height=200);
00095
00097
GhostScript(
const string& filename,
real x1,
real y1,
real x2,
real y2);
00098
00099
~GhostScript();
00100
00101
void flush();
00102
00103 PStream&
operator<<(
char* str)
00104 {
return togs<<str; }
00105
00106 void run(
const char* filename)
00107 {
togs <<
"\n(" << filename <<
") run " <<
endl; }
00108
00109 void copypage()
00110 {
togs <<
"\ncopypage" <<
endl; }
00111
00112 void showpage()
00113 {
togs <<
"\nshowpage" <<
endl; }
00114
00115 void gsave()
00116 {
togs <<
"\ngsave\n"; }
00117
00118 void grestore()
00119 {
togs <<
"\ngrestore\n"; }
00120
00121 void translate(
real x,
real y)
00122 {
togs <<
"\n" <<
x <<
" " << y <<
" translate\n"; }
00123
00124 void scale(
real x,
real y)
00125 {
togs <<
"\n" <<
x <<
" " << y <<
" scale\n"; }
00126
00127 void moveto(
real x,
real y)
00128 {
togs <<
"\n" <<
x <<
" " << y <<
" moveto\n"; }
00129
00130 void rotate(
real angle)
00131 {
togs <<
"\n" << angle <<
" rotate\n"; }
00132
00137 void mapping(
real sourcex,
real sourcey,
real sourcewidth,
real sourceheight,
00138
real destx,
real desty,
real destwidth,
real destheight)
00139 {
00140 scale(destwidth/sourcewidth, destheight/sourceheight);
00141 translate(-sourcex+destx*sourcewidth/destwidth,-sourcey+desty*sourceheight/destheight);
00142 }
00143
00144 void show(
const char* str)
00145 {
togs <<
"(" << str <<
") show" <<
endl; }
00146
00149
void show(
real x,
real y,
const char* str,
char halign=
'l',
char valign=
'b');
00150
00151 void centerShow(
real x,
real y,
const char* str)
00152 { show(
x,y,str,
'c',
'm'); }
00153
00155
void multilineShow(
real x,
real y,
const string& text,
real newlinesize,
char halign=
'l',
char valign=
'b');
00156
00157 void show(
real x,
real y,
Vec v)
00158 {
togs <<
"\n" <<
x <<
" " << y <<
" moveto (" << v <<
") show" <<
endl; }
00159
00160 void centerShow(
real x,
real y,
Vec v)
00161 {
togs <<
"\n" <<
x <<
" " << y <<
" moveto (" << v <<
") dup stringwidth exch -2 div exch -2 div rmoveto show" <<
endl; }
00162
00163 void erasepage()
00164 {
togs <<
"\nerasepage" <<
endl; }
00165
00166 void setcolor(
real r,
real g,
real b)
00167 {
togs <<
"\n/DeviceRGB setcolorspace " << r <<
" " << g <<
" " << b <<
" setcolor\n"; }
00168
00170 void setcolor(
real rgb)
00171 {
00172
real r,g,b;
00173
real2rgb(rgb,r,g,b);
00174 setcolor(r,g,b);
00175 }
00176
00177
void setcolor(
char* colorname);
00178
00179 void setgray(
real g)
00180 {
togs <<
"\n" << g <<
" setgray\n"; }
00181
00182 void setlinewidth(
real w)
00183 {
togs <<
"\n" << w <<
" setlinewidth\n"; }
00184
00186 void setdash(
Vec ary,
real x=0)
00187 {
00188
if(ary.
isEmpty())
00189
togs <<
"[ 3 3 ] " <<
x <<
" setdash\n";
00190
else
00191
togs <<
"[ " << ary <<
" ] " <<
x <<
" setdash\n";
00192 }
00193
00194 void drawLine(
real x1,
real y1,
real x2,
real y2)
00195 {
togs <<
"\n" << x1 <<
" " << y1 <<
" moveto " << x2 <<
" " << y2 <<
" lineto stroke" <<
endl; }
00196
00197 void drawArrow(
real x1,
real y1,
real x2,
real y2)
00198 {
00199 drawLine(x1,y1,x2,y2);
00200
drawCircle(x2,y2,2);
00201 }
00202
00203
void drawBox(
real x,
real y,
real width,
real height);
00204
void fillBox(
real x,
real y,
real width,
real height);
00205
00206
void drawCross(
real x,
real y,
real r,
bool vertical=
false,
real ry=-1);
00207
00208
void drawCircle(
real x,
real y,
real r);
00209
void fillCircle(
real x,
real y,
real r);
00210
00215
void displayBlack(
const Mat& bm,
real x,
real y,
real w,
real h,
bool painton1=
true);
00216
00218
void displayGray(
const Mat& bm,
real x,
real y,
real w,
real h);
00219
00221
void displayRGB(
const Mat& bm,
real x,
real y,
real w,
real h);
00222
00223 void usefont(
const char* fontname=
"Times-Roman",
real pointsize=12.0)
00224 {
togs <<
"\n/" << fontname <<
" findfont " << pointsize <<
" scalefont setfont" <<
endl; }
00225 };
00226
00227 }
00228
00229
#endif
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
Generated on Tue Aug 17 15:54:29 2004 for PLearn by
1.3.7