Changeset 44 in Sophya
- Timestamp:
- Apr 9, 1997, 5:45:23 PM (28 years ago)
- Location:
- trunk/SophyaPI/PI
- Files:
-
- 1 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PI/Makefile
r43 r44 2 2 3 3 all: $(LIB)libPI.a 4 $(LIB)libPI.a : $(OBJ)piapplgen.o $(OBJ)piapplx.o $(OBJ)pibwdggen.o $(OBJ)pibwdgx.o $(OBJ)picmap.o $(OBJ)picmapgen.o $(OBJ)picmapx.o $(OBJ)picontainergen.o $(OBJ)picontainerx.o $(OBJ)pidrawwin.o $(OBJ)pifilechogen.o $(OBJ)pifilechox.o $(OBJ)pihisto.o $(OBJ)piimage.o $(OBJ)pilistgen.o $(OBJ)pilistx.o $(OBJ)pimenubargen.o $(OBJ)pimenubarx.o $(OBJ)pimenugen.o $(OBJ)pimenux.o $(OBJ)pimsghandler.o $(OBJ)pioptmenugen.o $(OBJ)pioptmenux.o $(OBJ)piperiodx.o $(OBJ)pipixmapgen.o $(OBJ)pipixmapx.o $(OBJ)piscdrawwdg.o $(OBJ)pistdwdggen.o $(OBJ)pistdwdgx.o $(OBJ)pistlist.o $(OBJ)piup.o $(OBJ)piwdggen.o $(OBJ)piwdgx.o $(OBJ)piwindowgen.o $(OBJ)piwindowx.o $(OBJ)pixtbase.o $(OBJ)ps dict.o $(OBJ)psfile.o4 $(LIB)libPI.a : $(OBJ)piapplgen.o $(OBJ)piapplx.o $(OBJ)pibwdggen.o $(OBJ)pibwdgx.o $(OBJ)picmap.o $(OBJ)picmapgen.o $(OBJ)picmapx.o $(OBJ)picontainergen.o $(OBJ)picontainerx.o $(OBJ)pidrawwin.o $(OBJ)pifilechogen.o $(OBJ)pifilechox.o $(OBJ)pihisto.o $(OBJ)piimage.o $(OBJ)pilistgen.o $(OBJ)pilistx.o $(OBJ)pimenubargen.o $(OBJ)pimenubarx.o $(OBJ)pimenugen.o $(OBJ)pimenux.o $(OBJ)pimsghandler.o $(OBJ)pioptmenugen.o $(OBJ)pioptmenux.o $(OBJ)piperiodx.o $(OBJ)pipixmapgen.o $(OBJ)pipixmapx.o $(OBJ)piscdrawwdg.o $(OBJ)pistdwdggen.o $(OBJ)pistdwdgx.o $(OBJ)pistlist.o $(OBJ)piup.o $(OBJ)piwdggen.o $(OBJ)piwdgx.o $(OBJ)piwindowgen.o $(OBJ)piwindowx.o $(OBJ)pixtbase.o $(OBJ)psfile.o 5 5 $(AR) $(ARFLAGS) $@ $? 6 6 … … 207 207 $(OBJ)pixtbase.o: pixtbase.cc pixtbaseP.h pibwdgx.h pisysdep.h pibwdggen.h \ 208 208 piwdgx.h piwdggen.h pimsghandler.h pixtbase.h 209 $(OBJ)psdict.o: psdict.cc psfile.h $(INC)defs.h \210 pisysdep.h pibwdgx.h pibwdggen.h piwdgx.h piwdggen.h pimsghandler.h \211 picmap.h picmapx.h picmapgen.h212 209 $(OBJ)psfile.o: psfile.cc psfile.h $(INC)defs.h \ 213 210 pisysdep.h pibwdgx.h pibwdggen.h piwdgx.h piwdggen.h pimsghandler.h \ -
trunk/SophyaPI/PI/pibwdggen.h
r37 r44 20 20 enum PIFontAtt { PI_NotDefFontAtt = -1, 21 21 PI_RomanFont = 1, PI_BoldFont = 2, PI_ItalicFont = 4 }; 22 23 enum PIPaperSize { PI_A4 = 1, PI_A3 = 2, PI_A5 = 3, PI_NotDefPaperSize = 0}; 24 25 enum PIOrientation { PI_Landscape = 0, PI_Portrait = 1, PI_Auto = 2 } ; 26 22 27 23 28 enum PILineAtt { PI_NotDefLineAtt = -1, -
trunk/SophyaPI/PI/pibwdgx.cc
r32 r44 293 293 PILineAtt clatt; 294 294 if(mPSOut) 295 mPSOut->DrawMarker((float)x0,(float)y0,mMrk,mFCol );295 mPSOut->DrawMarker((float)x0,(float)y0,mMrk,mFCol,mMrkSz); 296 296 else 297 297 { … … 360 360 ytmp[i] = (float)y[i]; 361 361 } 362 mPSOut->DrawMarkers(xtmp,ytmp,n,mMrk,mFCol );362 mPSOut->DrawMarkers(xtmp,ytmp,n,mMrk,mFCol, mMrkSz); 363 363 free(xtmp); 364 364 free(ytmp); -
trunk/SophyaPI/PI/piwdggen.cc
r37 r44 56 56 psf->DrawBox(0., 0., (float)XSize(), (float)YSize()); 57 57 sprintf(str,"PIWdgGen::PSPrint() Kind=%ld Name= %s", kind(), Nom().c_str()); 58 psf->DrawString( 5., 5., str);58 psf->DrawString(12., 12., str, PI_Black, PI_RomanFont, 10); 59 59 psf->EndBloc(); 60 60 -
trunk/SophyaPI/PI/piwindowgen.cc
r32 r44 20 20 { 21 21 if (!psf) return; 22 int ori;23 ori = (XSize() > YSize()) ? LANDSCAPE : PORTRAIT ;24 psf->NewPage((float)XSize(), (float)YSize(), ori);22 //int ori; 23 //ori = (XSize() > YSize()) ? LANDSCAPE : PORTRAIT ; 24 psf->NewPage((float)XSize(), (float)YSize(),PI_Auto); 25 25 PIContainerGen::PSPrint(psf, ofx, ofy); 26 26 } -
trunk/SophyaPI/PI/psfile.cc
r41 r44 4 4 * 19/06/96 5 5 * 6 * Modification le 01/03/96 7 * - fusion psfile.cc - psdict.cc 6 8 * 7 9 */ … … 13 15 #include "psfile.h" 14 16 15 16 17 18 19 extern float cm2pt(float x); 20 17 /* En cm */ 18 #define MIN_SIZE_IN_PAGE 2. 21 19 22 20 /* 23 * Premier constructeur : 24 * Creation d'un fichier .ps ou .eps 21 * Dictionnaire PIDict 22 * 23 * Contient les fonctions suivantes : 24 * 25 25 * 26 26 */ 27 PSFile::PSFile (char *FileName = NULL, float Tx, float Ty, 28 float Dx, float Dy) { 29 30 // extern int FileEmpty; 31 // extern int BlocActive; 32 // extern int PageActive; 33 34 /* Si une bounding box est precisee, on produit du .eps */ 35 if ( (Tx != 0) && (Ty != 0) ) isEPS = 1; 36 else isEPS = 0; 37 38 39 /* Nom du fichier */ 40 if ( FileName != NULL ) { 41 mPSFileName = new ( char[strlen(FileName)+1] ); 42 strcpy(mPSFileName, FileName); 43 } 44 else { 45 mPSFileName = new ( char[11] ); 46 strncpy(mPSFileName, "unnamed.ps", 11); 47 } 27 #define PIDICT_PAR \ 28 \ 29 PI_Landscape, PI_Portrait,\ 30 \ 31 PI_Black, PI_White, PI_Grey, PI_Red, PI_Blue,\ 32 PI_Green, PI_Yellow, PI_Magenta, PI_NotDefColor,\ 33 \ 34 PI_RomanFont, PI_BoldFont, PI_ItalicFont, PI_NotDefFontAtt,\ 35 PI_SmallSizeFont, PI_NormalSizeFont, PI_BigSizeFont, PI_NotDefFontSize, \ 36 \ 37 PI_NormalLine, PI_ThinLine, PI_ThickLine, PI_NotDefLineAtt 38 39 #define PIDICT "\ 40 /$PIDict 50 dict def\n\ 41 $PIDict begin $PIDict /mtrx matrix put /Landscape %d def /Portrait %d def\n\ 42 %% Couleurs et fontes courantes\n\ 43 /C%-2d {0.0 0.0 0.0 setrgbcolor} bind def %% PI_Black\n\ 44 /C%-2d {0.996 0.996 0.996 setrgbcolor} bind def %% PI_White\n\ 45 /C%-2d {0.824 0.824 0.824 setrgbcolor} bind def %% PI_Grey\n\ 46 /C%-2d {0.996 0.0 0.0 setrgbcolor} bind def %% PI_Red\n\ 47 /C%-2d {0.0 0.0 0.996 setrgbcolor} bind def %% PI_Blue\n\ 48 /C%-2d {0.0 0.996 0.0 setrgbcolor} bind def %% PI_Green\n\ 49 /C%-2d {0.996 0.996 0.0 setrgbcolor} bind def %% PI_Yellow\n\ 50 /C%-2d {0.996 0.0 0.996 setrgbcolor} bind def %% PI_Magenta\n\ 51 /C%-2d {} bind def %% PI_NotDefColor\n\ 52 /F%-2d {/Times-Roman findfont} bind def %% PI_RomanFont\n\ 53 /F%-2d {/Times-Bold findfont} bind def %% PI_BoldFont\n\ 54 /F%-2d {/Times-Italic findfont} bind def %% PI_ItalicFont\n\ 55 /F%-2d {}\ 56 bind def %% PI_NotDefFontAtt\n\ 57 /FS {scalefont setfont} bind def\n\ 58 %%/FS%-2d {8 scalefont setfont} bind def %% PI_SmallSizeFont\n\ 59 %%/FS%-2d {12 scalefont setfont} bind def %% PI_NormalSizeFont\n\ 60 %%/FS%-2d {16 scalefont setfont} bind def %% PI_BigSizeFont\n\ 61 /FS%-2d {} bind def %% PI_NotDefFontSize\n\ 62 /L%-2d {1 slw} bind def %% PI_NormalLine\n\ 63 /L%-2d {0.5 slw} bind def %% PI_ThinLine\n\ 64 /L%-2d {3 slw} bind def %% PI_ThickLine\n\ 65 /L%-2d {} bind def %% PI_NotDefLineAtt\n\ 66 \ 67 %% Conversion\n\ 68 /cm {28.3 mul} bind def %% cm --> points\n\ 69 /Ux {$Cvrtx mul} bind def %% Unites utilisateur /x --> points\n\ 70 /Uy {$Cvrty mul} bind def %% Unites utilisateur /y --> points\n\ 71 \ 72 %% Pages et Blocs\n\ 73 /newref {%% Dx Dy Tx Ty X0 Y0 newref\n\ 74 translate 3 -1 roll cm div 28.3 mul /$Cvrty exch def\n\ 75 exch cm div 28.3 mul /$Cvrtx exch def} bind def\n\ 76 /NewPage {%% Dx Dy orientation NewPage\n\ 77 /$PageEnteredState save def 1 -1 scale Portrait eq {w cm h cm 0 h cm neg\n\ 78 newref} { -90 rotate h cm w cm 0 0 newref} ifelse} bind def\n\ 79 /EndPage { %% EndPage\n\ 80 $PageEnteredState restore} bind def\n\ 81 /NewBloc { %% Dx Dy Tx Ty X0 Y0 NewBloc\n\ 82 /$BlocEnteredState save def newref} bind def\n\ 83 /EndBloc { %% EndBloc\n\ 84 $BlocEnteredState restore} bind def\n\ 85 \ 86 %% Trace\n\ 87 /n {newpath} bind def /c {closepath} bind def\n\ 88 /gs {gsave} bind def /gr {grestore} bind def\n\ 89 /m {moveto} bind def /l {lineto} bind def\n\ 90 /s {stroke} bind def /f {fill} bind def\n\ 91 /sc {scale} bind def /S {gs 1 -1 sc show gr} bind def \n\ 92 /slw {setlinewidth} bind def\n\ 93 /ff {findfont} bind def /sf {setfont} bind def /scf {scalefont} bind def\n\ 94 /rl {rlineto} bind def /tr {translate} bind def\n\ 95 %% Tx Ty X0 Y0 box\n\ 96 /box {tr 0 3 1 roll neg exch 0 0 3 index neg 0 0 m rl rl rl c} bind def\n\ 97 %% R X0 Y0 circle\n\ 98 /circle {tr dup 0 m 0 0 3 -1 roll 0 380 arc} bind def\n\ 99 %% DrawEllipse pompee sur transfig\n\ 100 /ellipse {/endangle exch def /startangle exch def /yrad exch def\n\ 101 /xrad exch def /y exch def /x exch def /savematrix mtrx currentmatrix def\n\ 102 x y tr xrad yrad sc 0 0 1 startangle endangle arc\n\ 103 closepath savematrix setmatrix } def\n\ 104 \ 105 %% Gestion des images\n\ 106 %% ColorImage, pompee sur xv (qui les avait pompees sur xgrab)\n\ 107 /colorimage where %% do we know about 'colorimage'?\n\ 108 { pop } %% yes: pop off the 'dict' returned\n\ 109 { %% no: define one\n\ 110 /colortogray { %% define an RGB->I function\n\ 111 /rgbdata exch store %% call input 'rgbdata'\n\ 112 rgbdata length 3 idiv\n\ 113 /npixls exch store\n\ 114 /rgbindx 0 store\n\ 115 0 1 npixls 1 sub {\n\ 116 grays exch\n\ 117 rgbdata rgbindx get 20 mul %% Red\n\ 118 rgbdata rgbindx 1 add get 32 mul %% Green\n\ 119 rgbdata rgbindx 2 add get 12 mul %% Blue\n\ 120 add add 64 idiv %% I = .5G + .31R + .18B\n\ 121 put\n\ 122 /rgbindx rgbindx 3 add store\n\ 123 } for\n\ 124 grays 0 npixls getinterval\n\ 125 } bind def\n\ 126 /mergeprocs { %% def\n\ 127 dup length 3 -1 roll dup length dup 5 1 roll 3 -1 roll add\n\ 128 array cvx dup 3 -1 roll 0 exch putinterval dup 4 2 roll\n\ 129 putinterval } bind def\n\ 130 /colorimage {\n\ 131 pop pop %% remove 'false 3' operands\n\ 132 {colortogray} mergeprocs image} bind def\n\ 133 } ifelse %% end of 'false' case\n\ 134 \ 135 %% GetRGB\n\ 136 /GetRGB { %% ImageStr --> RGBStr\n\ 137 /ImageData exch store\n\ 138 %% Pour chaque element de ImageData,\n\ 139 %% On va chercher les valeurs RGB correspondantes\n\ 140 0 1 Taille 1 sub {\n\ 141 /i exch store %% On met a jour l'indice de parcours\n\ 142 ImageData i get %% Recupere la Indice e val dans la chaine ImData\n\ 143 ColorMap exch get %% On recupere la valeur RGB Correspondante\n\ 144 aload pop %% On met tout ca dans la pile\n\ 145 %% Maintenant, on va mettre tout ca dans la chaine RGBStr\n\ 146 RGBStr i 3 mul 2 add 3 -1 roll put\n\ 147 RGBStr i 3 mul 1 add 3 -1 roll put\n\ 148 RGBStr i 3 mul 3 -1 roll put\n\ 149 } for\n\ 150 RGBStr 0 Taille 3 mul getinterval %% On renvoie la chaine RGB\n\ 151 } bind def\n\ 152 end\n\ 153 " 154 155 156 157 /* 158 * Les PIMarkers sont definis et geres commes des fontes 159 * 160 * 161 */ 162 #define PIMARKERS_PAR PI_DotMarker, PI_PlusMarker, PI_CrossMarker,\ 163 PI_CircleMarker, PI_FCircleMarker, PI_BoxMarker, PI_FBoxMarker,\ 164 PI_TriangleMarker, PI_FTriangleMarker, PI_StarMarker, PI_FStarMarker 165 166 #define PIMARKERS "\ 167 %% Definition de la fonte $PIMarkers\n\ 168 /$PIMarkers 26 dict def\n\ 169 $PIMarkers begin\n\ 170 /FontType 3 def\n\ 171 /FontMatrix [0.001 0 0 0.001 -0.375 -0.375] def\n\ 172 /FontBBox [0 0 1000 1000] def\n\ 173 /Encoding 256 array def\n\ 174 0 1 255 {Encoding exch /.notdef put} for\n\ 175 Encoding %d /PIDot put %% PI_DotMarker\n\ 176 Encoding %d /PIPlus put %% PI_PlusMarker\n\ 177 Encoding %d /PICross put %% PI_CrossMarker\n\ 178 Encoding %d /PICircle put %% PI_CircleMarker\n\ 179 Encoding %d /PIFCircle put %% PI_FCircleMarker\n\ 180 Encoding %d /PIBox put %% PI_BoxMarker\n\ 181 Encoding %d /PIFBox put %% PI_FBoxMarker\n\ 182 Encoding %d /PITriangle put %% PI_TriangleMarker\n\ 183 Encoding %d /PIFTriangle put %% PI_FTriangleMarker\n\ 184 Encoding %d /PIStar put %% PI_StarMarker\n\ 185 Encoding %d /PIFStar put %% PI_FStarMarker\n\ 186 /CharProcs 26 dict def\n\ 187 $PIDict begin\n\ 188 CharProcs begin\n\ 189 /.notdef {} def\n\ 190 /PIDot {100 375 375 circle f} bind def\n\ 191 /PIPlus {0 375 m 750 375 l 375 0 m 375 750 l s} bind def\n\ 192 /PICross {0 0 m 750 750 l 750 0 m 0 750 l s} bind def\n\ 193 /PICircle {375 375 375 circle s} bind def\n\ 194 /PIFCircle {375 375 375 circle f} bind def\n\ 195 /PIBox {0 0 m 750 0 l 750 750 l 0 750 l c s} bind def\n\ 196 /PIFBox {0 0 m 750 0 l 750 750 l 0 750 l c f} bind def\n\ 197 /PITriangle {0 750 m 375 0 l 750 750 l c s} bind def\n\ 198 /PIFTriangle {0 750 m 375 0 l 750 750 l c f} bind def\n\ 199 /PIStar {} def\n\ 200 /PIFStar {} def\n\ 201 end %%$PIDict\n\ 202 end %%$CharProcs\n\ 203 /BuildChar {\n\ 204 1000 0 %% Largeur \n\ 205 0 0 750 750 %% Bounding Box\n\ 206 setcachedevice \n\ 207 exch begin\n\ 208 Encoding exch get\n\ 209 CharProcs exch get\n\ 210 end exec} def\n\ 211 end\n\ 212 /PIMarkers $PIMarkers definefont pop\n\ 213 save\n\ 214 " 215 216 /* Dimensions des divers formats */ 217 struct PaperSize { 218 float width ; 219 float height ; 220 }; 221 struct PaperSize PaperSizeTable[] = { 222 { 0.0, 0.0}, /* PI_NotDefFormat */ 223 {21.0, 29.7}, /* PI_A4 */ 224 {29.7, 42.0}, /* PI_A3 */ 225 {14.8, 21.0} /* PI_A5 ? */ 226 } ; 227 228 229 float cm2pt(float x); 230 231 232 /* Fonction WriteHeader */ 233 #define END_PROLOG_PAR PAGE_WIDTH, PAGE_HEIGHT 234 #define END_PROLOG "/NewFile { %%%% w h NewFile (--> h et w en cm <--)\n\ 235 $PIDict begin /PIMarkers ff 14 scf sf /h exch def /w exch def \n\ 236 /$PIEnteredState save def} bind def\n\ 237 /EndFile {$PIEnteredState restore end} bind def\n\ 238 %%%%EndProlog\n\n\ 239 " 240 241 #define HEADER "\ 242 %%%%Title: %s\n\ 243 %%%%Creator: PSFile\n\ 244 %%%%CreationDate: %s\ 245 %%%%Pages: (atend)\n\ 246 %%%%EndComments\n\n\ 247 " 248 249 250 /* 251 * PostScript encapsule... 252 * 253 * Attention la bounding Box ne sera specifiee 254 * qu'au premier NewPage() --> definie dans 255 * le champ "Trailer" 256 * 257 */ 258 PSFile::PSFile(char * FileName, float sc) 259 : mPSFileName(FileName==NULL? "unnamed.eps" : FileName), 260 Tw (-1.), Th(-1.), /* Non specifies pour du eps */ 261 WMargin (-1), HMargin(-1), /* Non specifiees en eps */ 262 isEPS(1), 263 scale(sc), /* Defaut : 1. */ 264 mPaperSize(PI_NotDefPaperSize), /* Non specifiee en eps */ 265 PageCounter(0), /* Fichier vide */ 266 FileEmpty(1), /* Fichier vide */ 267 currentPage(NULL), 268 currentBloc(NULL), 269 mDrawColor(PI_Black), 270 mFillColor(PI_Black), 271 mFontAtt(PI_RomanFont), 272 mFontSize(PI_NormalSizeFont), 273 mLineAtt(PI_NormalLine), 274 mMarker(PI_DotMarker) 275 { 276 char* date = new (char[64] ) ; 277 time_t timer ; 278 279 /* Ouverture du fichier en mode w+ */ 280 if ( (mPSFile = fopen(FileName, "w+")) == NULL){ 281 perror (FileName); 282 return; 283 } 284 285 /* Ecriture du Header */ 286 fprintf(mPSFile, "%%!PS-Adobe-2.0 EPSF-2.0\n"); 287 fprintf(mPSFile, "%%%%BoundingBox: "); 288 /* 289 * Les dimensions de la BB seront notees ici lors du 290 * premier appel a NewPage 291 * 292 * C'est laid... si qqn a une meilleure idee... 293 */ 294 boundingBox = ftell(mPSFile) ; 295 fprintf(mPSFile, " \n"); 296 297 time(&timer) ; 298 date = ctime(&timer) ; 299 fprintf(mPSFile, HEADER, mPSFileName, date) ; /* titre, date etc... */ 300 fprintf(mPSFile, PIDICT, PIDICT_PAR) ; /* Dictionnaire */ 301 fprintf(mPSFile, PIMARKERS, PIMARKERS_PAR) ; /* Fonte "PIMARKERS" */ 302 // fprintf(mPSFile, END_PROLOG) ; 303 /* Aucun format n'est specifie ici ... */ 304 fprintf(mPSFile, "$PIDict begin /PIMarkers ff 14 scf sf\n") ; 305 fprintf(mPSFile, "/FState save def\n%%%%EndProlog\n\n") ; 306 } 307 308 309 310 /* 311 * PostScript simple... 312 * 313 * 314 */ 315 PSFile::PSFile(char *FileName, 316 PIOrientation orientation, 317 PIPaperSize paperSize, 318 float marginX, float marginY) 319 : mPSFileName (FileName == NULL ? "unnamed.ps" : FileName), 320 Tw(PaperSizeTable[paperSize].width), /* Format papier utilise */ 321 Th(PaperSizeTable[paperSize].height), /* */ 322 WMargin(marginX), 323 HMargin(marginY), 324 isEPS(0), 325 scale(0.), 326 PageCounter(0), /* Fichier vide */ 327 FileEmpty(1), /* */ 328 currentPage(NULL), 329 currentBloc(NULL), 330 mDrawColor(PI_Black), 331 mFillColor(PI_Black), 332 mFontAtt(PI_RomanFont), 333 mFontSize(PI_NormalSizeFont), 334 mLineAtt(PI_NormalLine), 335 mMarker(PI_DotMarker) 336 { 337 char * date = new(char[64]) ; 338 time_t timer ; 48 339 49 340 /* Ouverture du fichier, en mode w+ (tout est ecrase) */ … … 53 344 } 54 345 55 /* Initialisations... */ 56 mFormat.X0 = 0; /* Pr le moment ... */ 57 mFormat.Y0 = 0; 58 mFormat.orientation = LANDSCAPE; 59 if ( (Tx == 0) || (Ty == 0) ) { 60 mFormat.Tx = PAGE_WIDTH; 61 mFormat.Ty = PAGE_HEIGHT; 62 } 63 else { 64 mFormat.Tx = Tx; 65 mFormat.Ty = Ty; 66 } 67 if ( (Dx == 0) || (Dy == 0) ) { 68 mFormat.Dx = mFormat.Tx; 69 mFormat.Dy = mFormat.Ty; 70 } 71 else { 72 mFormat.Dx = Dx; 73 mFormat.Dy = Dy; 74 } 75 PageCounter = 0; 76 mDrawColor = PI_Black; 77 mFillColor = PI_Black; 78 mFontAtt = PI_RomanFont; 79 mFontSize = PI_NormalSizeFont; 80 mLineAtt = PI_NormalLine; 81 mMarker = PI_DotMarker; 82 83 /* Ecriture de l'en tete */ 84 WriteHeader(); 85 } 86 87 /* 88 * Second constructeur 89 * 90 * Extraction d'un bloc ou d'une page 91 * d'un fichier deja existant 92 * 93 */ 94 //PSFile::PSFile(char * FileName, PSFile *File = NULL , int PageNum = 0, 95 // int BlocNum = 0) { 96 // 97 // PageList::iterator PIt; 98 // char *buffer; 99 // 100 // if ( (File == NULL) || (PageNum == 0) ) { 101 // fprintf(stderr, "PSFile::PSFile : args incorrects\n"); 102 // return; 103 // } 104 // 105 // 106 // if ( FileName != NULL ) { 107 // mPSFileName = new ( char[strlen(FileName)+1] ); 108 // strcpy(mPSFileName, FileName); 109 // } 110 // else { 111 // mPSFileName = new ( char[11] ); 112 // strncpy(mPSFileName, "unnamed.ps", 11); 113 // } 114 // 115 // 116 // if ( PageCounter >= PageNum ) { 117 // for(PIt = (File)->mPageList.begin(); PIt < (File)->mPageList.end(); 118 // PIt++); 119 // PIt--; 120 // } 121 // else { 122 // fprintf(stderr, "Page %d inexistante\n", PageNum); 123 // return; 124 // } 125 // 126 // if (BlocNum != 0) { 127 // if ( (*PIt).BlocCounter >= BlocNum ) { 128 // for(BIt=(*PIt).mBlocList.begin();PIt<(*PIt).mBlocList.end();BIt++); 129 // BIt--; 130 // } 131 // else { 132 // fprintf(stderr,"Bloc %d, (Page %d) inexistant\n",BlocNum,PageNum); 133 // return; 134 // } 135 // } 136 // 137 // if ( (mPSFile = fopen(FileName, "w+")) == NULL){ 138 // perror (FileName); 139 // return; 140 // } 141 // 142 // mFormat.X0 = 0; 143 // mFormat.Y0 = 0; 144 // mFormat.orientation = PORTRAIT; 145 // if ( (Tx == 0) || (Ty == 0) ) { 146 // mFormat.Tx = PAGE_WIDTH; 147 // mFormat.Ty = PAGE_HEIGHT; 148 // } 149 // if ( (Dx == 0) || (Dy == 0) ) { 150 // mFormat.Dx = mFormat.Tx; 151 // mFormat.Dy = mFormat.Ty; 152 // } 153 // PageCounter = 0; 154 // mDrawColor = PI_Black; 155 // mFillColor = PI_Black; 156 // mFontAtt = PI_RomanFont; 157 // mFontSize = PI_NormalSizeFont; 158 // mLineAtt = PI_NormalLine; 159 // mMarker = PI_DotMarker; 160 // 161 // WriteHeader(); 162 // WriteNewPage(&(*PIt)); 163 // if(BlocNum != 0) 164 // WriteNewBloc(&(*BIt)); 165 // 166 // PSScan(PageNum, BlocNum, off_t limites[2]); 167 // 168 // 169 // 170 // buffer = (char*)malloc(BUFSZ*sizeof(char)); 171 // 172 // return; 173 //} 174 175 346 /* Format et orientation */ 347 348 /* Ecriture du Header */ 349 fprintf(mPSFile, "%%!PS-Adobe-2.0\n") ; 350 time(&timer) ; 351 date = ctime(&timer) ; 352 fprintf(mPSFile, HEADER, mPSFileName, date) ; /* titre, date etc... */ 353 fprintf(mPSFile, PIDICT, PIDICT_PAR) ; /* Dictionnaire */ 354 fprintf(mPSFile, PIMARKERS, PIMARKERS_PAR) ; /* Fonte "PIMARKERS" */ 355 fprintf(mPSFile, "$PIDict begin /PIMarkers ff 14 scf sf\n") ; 356 fprintf(mPSFile, "/FState save def\n%%%%EndProlog\n\n") ; 357 } 176 358 177 359 … … 181 363 */ 182 364 PSFile::~PSFile () { 183 extern int FileEmpty;184 extern int BlocActive;185 extern int PageActive;186 365 187 366 /* On ferme tout ce qui ne l'est pas */ 188 if ( BlocActive) PSFile::EndBloc();189 if ( PageActive) PSFile::EndPage();367 if (currentBloc) PSFile::EndBloc(); 368 if (currentPage) PSFile::EndPage(); 190 369 191 370 /* Si le fichier est vide, on le detruit */ 192 371 if (FileEmpty) remove(mPSFileName); 193 372 194 /* Sinon, on ecrit le "Trailer" et on ferme */373 /* On ecrit le "Trailer" et on ferme */ 195 374 else { 196 WriteTrailer(); 375 /* On restore l'etat initial */ 376 fprintf(mPSFile,"FState restore\n") ; 377 fprintf(mPSFile, "%%%%Trailer\n%%%%Pages: %d\n%%%%EOF\n", 378 PageCounter) ; 197 379 fclose (mPSFile); 198 380 } … … 205 387 } 206 388 207 Format *PSFile::GetFormat() {208 209 Format *form = (Format*)malloc(sizeof(Format));210 211 form->X0 = mFormat.X0;212 form->Y0 = mFormat.Y0;213 form->Tx = mFormat.Tx;214 form->Ty = mFormat.Ty;215 form->Dx = mFormat.Dx;216 form->Dy = mFormat.Dy;217 form->orientation = mFormat.orientation;218 return(form);219 }220 389 221 390 char* PSFile::GetFileName() { … … 254 423 } 255 424 256 void PSFile::NewPage(float Dx, float Dy, int orient) { 257 258 extern int PageActive; 259 extern int PageEmpty; 260 Page mNewPage; 425 void PSFile::NewPage(float Dx, float Dy, PIOrientation orientation) { 426 427 float tw, th; /* largeur & hauteur corrigees des marges */ 261 428 262 429 /* On ferme ce qui doit l'etre ... */ 263 if (PageActive) PSFile::EndPage(); 264 265 mNewPage.num = ++PageCounter; 266 mNewPage.BlocCounter = 0; 267 mNewPage.format.X0 = 0; 268 mNewPage.format.Y0 = 0; 269 mNewPage.format.Tx = mFormat.Tx; 270 mNewPage.format.Ty = mFormat.Ty; 271 mNewPage.format.Dx = Dx; 272 mNewPage.format.Dy = Dy; 273 mNewPage.format.orientation = orient; 274 275 /* On enregistre la position du debut --> AVANT D'ECRIRE */ 276 mNewPage.offset.begin = ftell(mPSFile); 277 278 /* On met a jour le fichier */ 279 WriteNewPage(&mNewPage); 280 281 /* On ajoute cette nouvelle page a la liste des pages du fichier */ 282 mPageList.push_back(mNewPage); 283 284 PageActive = 1; 285 PageEmpty = 1; 430 if (currentPage) PSFile::EndPage(); 431 432 currentPage = new (Page) ; 433 434 /* Initialisations */ 435 currentPage->num = ++PageCounter; 436 currentPage->BlocCounter = 0; 437 currentPage->Dx = Dx; 438 currentPage->Dy = Dy; 439 currentPage->orientation = orientation ; 440 441 /* Position du debut AVANT D'ECRIRE! */ 442 currentPage->begin = ftell(mPSFile); 443 444 /* On ecrit dans le fichier */ 445 fprintf(mPSFile, "%%%%Page: %d %d\n", PageCounter, PageCounter) ; 446 fprintf(mPSFile, "/PState save def 1 -1 scale\n"); 447 448 /* 449 * Si eps : Portrait || Auto == on laisse tel que 450 * Landscape == on tourne de -90 degres 451 */ 452 if(isEPS) { 453 if( (orientation == PI_Portrait) || (orientation == PI_Auto) ) 454 fprintf(mPSFile, 455 "%.2f %.2f %.2f %.2f %.2f %.2f newref\n", 456 Dx, Dy, Dx*scale, Dy*scale, 0., -Dy*scale); 457 else 458 if(orientation==PI_Landscape) 459 fprintf(mPSFile, 460 "-90 rotate %.2f %.2f %.2f %.2f %.2f %.2f newref\n", 461 Dx, Dy, Dx*scale, Dy*scale, 0., 0.); 462 else 463 fprintf(stderr, "Orientation Error ; Page : %d\n", 464 currentPage->num) ; 465 /* 466 * On specifie la bb 467 * (Si non encore fait par un appel precedent a NewPage() ) 468 */ 469 if(boundingBox) { 470 currentPage->tmp = ftell(mPSFile) ; 471 fseek(mPSFile,boundingBox,SEEK_SET) ; 472 if( (orientation == PI_Portrait) || (orientation == PI_Auto) ) 473 fprintf(mPSFile, "%d %d %d %d", 0, 0, 474 (int)(Dx*scale), (int)(Dy*scale) ) ; 475 else 476 fprintf(mPSFile, "%d %d %d %d", 0, 0, 477 (int)(Dy*scale), (int)(Dx*scale) ) ; 478 fseek(mPSFile,currentPage->tmp,SEEK_SET) ; 479 boundingBox = 0 ; 480 } /* BB */ 481 } /* EPS */ 482 /* 483 * Si ps : 484 * - soustraction marges --> rectangle utile. 485 * - Si PI_Auto : On fait au mieux pour minimiser le 486 * redimensionnement... 487 * - Si PI_Portrait, on ne fait rien, sauf 488 * peut-etre un redimensionnement pour rentrer dans les marges 489 * - Si PI_Landscape, on tourne de -90 degres. 490 */ 491 else { 492 /* Eviter image reduite a un point...ou moins... */ 493 if((tw = Tw - 2*WMargin) < (Tw/10)) { 494 WMargin = (0.45)*Tw ; 495 tw = Tw/10; 496 } 497 if((th = Th - 2*HMargin)< (Th/10)) { 498 HMargin = (0.45)*Th ; 499 th = Th/10; 500 } 501 /* Portrait ou Landscape ? */ 502 if(orientation == PI_Auto) 503 if( ((tw < th) && (Dx < Dy)) || 504 ((tw > th) && (Dx > Dy) )) 505 currentPage->orientation = PI_Portrait ; 506 else 507 currentPage->orientation = PI_Landscape ; 508 509 if(currentPage->orientation == PI_Portrait) { 510 if( (tw/Dx) < (th/Dy) ) 511 scale = tw/Dx ; 512 else 513 scale = th/Dy; 514 fprintf(mPSFile, 515 "%.2f %.2f %.2f cm %.2f cm %.2f cm %.2f cm newref\n", 516 Dx, Dy, 517 Dx*scale, Dy*scale, 518 0.5*(Tw-tw), -0.5*(Th+th)) ; 519 } 520 if(currentPage->orientation == PI_Landscape) { 521 /* Idem avec X<->Y */ 522 if( (th/Dx) < (th/Dy) ) 523 scale = th/Dx; 524 else 525 scale = tw/Dy ; 526 fprintf(mPSFile, 527 "-90 rotate %.2f %.2f %.2f cm %.2f cm %.2f cm %.2f cm newref\n", 528 Dx, Dy, 529 Dx*scale, Dy*scale, 530 0.5*(Th-th), 0.5*(Tw-tw)); 531 } 532 } /* End if .ps */ 533 currentPage->tmp = ftell(mPSFile); 286 534 } 287 535 … … 290 538 void PSFile::EndPage() { 291 539 292 extern int PageActive;293 extern int BlocActive;294 extern int PageEmpty;295 extern int FileEmpty;296 PageList::iterator it;297 298 540 /* Si rien a fermer, on s'en va */ 299 if ( ! PageActive ) return;541 if ( ! currentPage ) return; 300 542 301 543 /* Si un bloc non ferme, on appelle EndBloc */ 302 if ( BlocActive) PSFile::EndBloc();544 if ( currentBloc ) PSFile::EndBloc(); 303 545 304 546 /* Si la page est vide, on la detruit */ 305 if (PageEmpty) { 306 it = mPageList.end(); it--; 307 /* Si 1 seule page ds fichier, retour au debut */ 308 if ( it == mPageList.begin() ) 309 fseek(mPSFile, (*it).offset.begin, SEEK_SET); 310 /* Sinon, on retourne a la fin de la page precedente */ 311 else { 312 it--; 313 fseek(mPSFile, (*it).offset.end, SEEK_SET); 314 it++; 315 } 316 mPageList.erase(it); 547 if (currentPage->tmp == ftell(mPSFile)) { 548 fseek(mPSFile, currentPage->begin, SEEK_SET); 549 delete(currentPage) ; 317 550 PageCounter--; 318 551 } 319 /* Sinon, Ok, on met a jour le fichier*/552 /* Sinon, fin page + empilage */ 320 553 else { 321 it = mPageList.end(); it--; 322 (*it).offset.end = ftell(mPSFile); 323 WriteEndPage(&(*it)); 554 // it = mPageList.end(); it--; 555 fprintf(mPSFile,"PState restore showpage\n"); 556 fprintf(mPSFile,"%%>EndPage %d\n\n\n", currentPage->num); 557 currentPage->end = ftell(mPSFile); 558 mPageList.push_back(*currentPage); /* Pourquoi PageList ? */ 324 559 FileEmpty = 0; 325 560 } 326 PageActive = 0;561 currentPage = NULL; 327 562 } 328 563 … … 330 565 void PSFile::NewBloc(float x0, float y0, float Tx, float Ty, 331 566 float Dx, float Dy){ 332 extern int BlocActive;333 extern int PageActive;334 extern int BlocEmpty;335 Bloc mNewBloc;336 PageList::iterator it;337 567 338 568 /* Si pas de page, on s'en va */ 339 if ( !PageActive) return;569 if ( ! currentPage ) return; 340 570 341 571 /* On ferme le bloc precedent (Pas de Bloc-gigognes ! ) */ 342 if (BlocActive) PSFile::EndBloc(); 343 344 it = mPageList.end(); it --; 345 /* On remplit mNewBloc */ 346 mNewBloc.num = ++(*it).BlocCounter; 347 mNewBloc.format.X0 = x0; 348 mNewBloc.format.Y0 = y0; 349 mNewBloc.format.Tx = Tx; 350 mNewBloc.format.Ty = Ty; 351 mNewBloc.format.Dx = Dx; 352 mNewBloc.format.Dy = Dy; 353 mNewBloc.format.orientation = 0; /* Pr l'inst, blk non orient */ 354 mNewBloc.offset.begin = ftell(mPSFile); 572 if (currentBloc) PSFile::EndBloc(); 573 574 currentBloc = new (Bloc) ; 575 /* On remplit currentBloc */ 576 currentBloc->num = ++(currentPage->BlocCounter); 577 currentBloc->X0 = x0; 578 currentBloc->Y0 = y0; 579 currentBloc->Tx = Tx; 580 currentBloc->Ty = Ty; 581 currentBloc->Dx = Dx; 582 currentBloc->Dy = Dy; 583 currentBloc->begin = ftell(mPSFile); 355 584 356 585 /* On met a jour le fichier */ 357 WriteNewBloc(&mNewBloc); 358 359 /* On met a jour la liste des blocs */ 360 (*it).mBlocList.push_back(mNewBloc); 361 362 BlocActive = 1; 363 BlocEmpty = 1; 586 fprintf(mPSFile, "%%>BeginBloc %d\n", currentBloc->num); 587 fprintf(mPSFile, "%.2f %.2f %.2f Ux %.2f Uy %.2f Ux %.2f Uy NewBloc\n", 588 currentBloc->Dx, currentBloc->Dy, 589 currentBloc->Tx, currentBloc->Ty, 590 currentBloc->X0, currentBloc->Y0); 591 currentBloc->tmp = ftell(mPSFile) ; 364 592 } 365 593 366 594 367 595 void PSFile::EndBloc() { 368 extern int BlocActive;369 extern int BlocEmpty;370 extern int PageEmpty;371 PageList::iterator PIt;372 BlocList::iterator BIt;373 596 374 597 /* On verifie qu'un bloc ouvert existe bien */ 375 if ( ! BlocActive) return;598 if ( ! currentBloc ) return; 376 599 377 600 /* Si le bloc est vide, on le detruit */ 378 if (BlocEmpty) { 379 PIt = mPageList.end(); PIt--; 380 BIt = (*PIt).mBlocList.end(); BIt--; 381 /* Si 1 seul bloc --> debut */ 382 if ( BIt == (*PIt).mBlocList.begin()) { 383 fseek(mPSFile,(*BIt).offset.begin, SEEK_SET); 384 } 385 /* Sinon, --> fin du bloc precedent */ 386 else { 387 BIt--; 388 fseek(mPSFile, (*BIt).offset.end, SEEK_SET); 389 BIt++; 390 } 391 (*PIt).mBlocList.erase(BIt); 392 (*PIt).BlocCounter--; 601 if (currentBloc->tmp == ftell(mPSFile)) { 602 fseek(mPSFile, currentBloc->begin, SEEK_SET) ; 603 currentPage->BlocCounter-- ; 393 604 } 394 605 /* Sinon, Ok met a jour le fichier */ 395 else { 396 PIt = mPageList.end(); PIt--;397 BIt = (*PIt).mBlocList.end(); BIt--;398 (*BIt).offset.end = ftell(mPSFile);399 WriteEndBloc(&(*BIt));400 PageEmpty = 0;401 } 402 403 BlocActive = 0;606 else { 607 fprintf(mPSFile, "EndBloc\n"); 608 fprintf(mPSFile, "%%>EndBloc %d\n", currentBloc->num); 609 currentBloc->end = ftell(mPSFile) ; 610 currentPage->mBlocList.push_back(*currentBloc) ; 611 // PageEmpty = 0; 612 } 613 /* Flags */ 614 currentBloc = NULL ; 404 615 } 405 616 406 617 407 618 void PSFile::DrawString (float x, float y, char *s, 408 PIColors DrawColor, 409 PIFontAtt FontAtt, 410 int FontSize) { 411 extern int BlocEmpty; 412 extern int PageEmpty; 619 PIColors DrawColor, 620 PIFontAtt FontAtt, 621 int FontSize) { 413 622 int change = 0; 414 623 … … 416 625 if ( (DrawColor != PI_NotDefColor) || (DrawColor != mDrawColor) ) { 417 626 mDrawColor = DrawColor; 418 WriteSetColor(mDrawColor); 419 } 420 627 fprintf(mPSFile, "C%d ", mDrawColor) ; 628 } 421 629 /* Choix des fontes */ 422 630 if ( (FontAtt != PI_NotDefFontAtt) || (FontAtt != mFontAtt) ) { … … 427 635 change = 1;} 428 636 if (change) 429 WriteSetFont(mFontAtt, mFontSize); 430 431 WriteDrawString(x, y, s); 432 433 BlocEmpty = 0; 434 PageEmpty = 0; 637 fprintf(mPSFile, "F%d %d FS ", mFontAtt, FontSize) ; 638 639 fprintf(mPSFile, "gs %.2f Ux %.2f Uy m (%s) S gr\n", x, y, s) ; 435 640 } 436 641 … … 439 644 PIColors DrawColor, 440 645 PILineAtt LineAtt) { 441 extern int BlocEmpty;442 extern int PageEmpty;443 646 444 647 /* Line Att */ 445 648 if ( (LineAtt != PI_NotDefLineAtt) || (LineAtt != mLineAtt) ) { 446 649 mLineAtt = LineAtt; 447 WriteSetLineWidth(mLineAtt);650 fprintf(mPSFile, "%d slw ", mLineAtt) ; 448 651 } 449 652 … … 451 654 if ( (DrawColor != PI_NotDefColor) || (DrawColor != mDrawColor) ) { 452 655 mDrawColor = DrawColor; 453 WriteSetColor(mDrawColor);656 fprintf(mPSFile, "C%d ", mDrawColor); 454 657 } 455 658 456 659 /* Dessin */ 457 WriteDrawLine(x1, y1, x2, y2); 458 459 BlocEmpty = 0; 460 PageEmpty = 0; 461 } 462 463 464 465 void PSFile::DrawBox (float x0, float y0, float Tx, float Ty, 466 PIColors DrawColor, 467 PILineAtt LineAtt) { 468 extern int BlocEmpty; 469 extern int PageEmpty; 660 fprintf(mPSFile, "n %.2f Ux %.2f Uy m %.2f Ux %.2f Uy l s\n", 661 x1, y1, x2, y2) ; 662 } 663 664 665 666 void PSFile::DrawBox(float x0, float y0, float Tx, float Ty, 667 PIColors DrawColor, 668 PILineAtt LineAtt) { 470 669 471 670 /* Changement couleurs ? */ 472 671 if ( (DrawColor != PI_NotDefColor) || (DrawColor != mDrawColor) ) { 473 672 mDrawColor = DrawColor; 474 WriteSetColor(mDrawColor);673 fprintf(mPSFile, "C%d ", mDrawColor) ; 475 674 } 476 675 … … 478 677 if ( (LineAtt != PI_NotDefLineAtt) || (LineAtt != mLineAtt) ) { 479 678 mLineAtt = LineAtt; 480 WriteSetLineWidth(mLineAtt);679 fprintf(mPSFile, "%d slw ", mLineAtt) ; 481 680 } 482 681 483 682 /* On dessine */ 484 WriteDrawBox(x0, y0, Tx, Ty); 485 486 /* Le fichier n'est plus vide */ 487 BlocEmpty = 0; 488 PageEmpty = 0; 489 } 490 491 492 void PSFile::DrawFBox (float x0, float y0, float Tx, float Ty, 683 fprintf(mPSFile, "gs n %.2f Ux %.2f Uy %.2f Ux %.2f Uy box s gr\n", 684 Tx, Ty, x0, y0) ; 685 } 686 687 688 void PSFile::DrawFBox(float x0, float y0, float Tx, float Ty, 493 689 PIColors DrawColor, 494 690 PIColors FillColor, 495 691 PILineAtt LineAtt) { 496 extern int BlocEmpty;497 extern int PageEmpty;498 499 692 500 693 /* Line Att */ 501 694 if ( (LineAtt != PI_NotDefLineAtt) || (LineAtt != mLineAtt) ) { 502 695 mLineAtt = LineAtt; 503 WriteSetLineWidth(mLineAtt);696 fprintf(mPSFile, "%d slw ", mLineAtt) ; 504 697 } 505 698 … … 507 700 if ( (FillColor != PI_NotDefColor) || (FillColor != mFillColor) ) 508 701 mFillColor = FillColor; 509 WriteSetColor(mFillColor);510 WriteDrawFBox(x0, y0, Tx, Ty);511 WriteSetColor(mDrawColor); 512 702 fprintf(mPSFile, "C%d ", mFillColor) ; 703 fprintf(mPSFile, "gs n %.2f Ux %.2f Uy %.2f Ux %.2f Uy box f gr\n", 704 Tx, Ty, x0, y0) ; 705 513 706 /* Dessin du contour (s'il y a lieu) */ 514 if ( (DrawColor != PI_NotDefColor) && (FillColor != DrawColor) ) {707 if ( (DrawColor != PI_NotDefColor) && (FillColor != DrawColor) ) 515 708 mDrawColor = DrawColor; 516 WriteSetColor(DrawColor); 517 WriteDrawBox(x0, y0, Tx, Ty); 518 } 519 /* Le fichier n'est plus vide */ 520 BlocEmpty = 0; 521 PageEmpty = 0; 709 fprintf(mPSFile, "C%d ", mDrawColor) ; 710 fprintf(mPSFile, "gs n %.2f Ux %.2f Uy %.2f Ux %.2f Uy box s gr\n", 711 Tx, Ty, x0, y0) ; 522 712 } 523 713 524 714 525 715 void PSFile::DrawCircle (float x0, float y0, float r, 526 PIColors DrawColor, 527 PILineAtt LineAtt) { 528 extern int BlocEmpty; 529 extern int PageEmpty; 716 PIColors DrawColor, 717 PILineAtt LineAtt) { 530 718 531 719 /* Couleurs */ 532 720 if ( (DrawColor != PI_NotDefColor) || (DrawColor != mDrawColor) ) { 533 721 mDrawColor = DrawColor; 534 WriteSetColor(DrawColor);722 fprintf(mPSFile, "C%d ", mDrawColor); 535 723 } 536 724 … … 538 726 if ( (LineAtt != PI_NotDefLineAtt) || (LineAtt != mLineAtt) ) { 539 727 mLineAtt = LineAtt; 540 WriteSetLineWidth(mLineAtt);728 fprintf(mPSFile, "%d slw ", mLineAtt); 541 729 } 542 730 543 731 /* Dessin */ 544 WriteDrawCircle(x0, y0, r); 545 546 BlocEmpty = 0; 547 PageEmpty = 0; 732 fprintf(mPSFile, "gs n %.2f Ux %.2f Uy %.2f Ux %.2f Uy 0 360 ellipse s gr\n", 733 x0, y0, r, r) ; 548 734 } 549 735 … … 553 739 PIColors FillColor, 554 740 PILineAtt LineAtt) { 555 extern int BlocEmpty;556 extern int PageEmpty;557 741 558 742 /* Line Att */ 559 743 if ( (LineAtt != PI_NotDefLineAtt) || (LineAtt != mLineAtt) ) { 560 744 mLineAtt = LineAtt; 561 WriteSetLineWidth(mLineAtt);745 fprintf(mPSFile, "%d slw ", mLineAtt) ; 562 746 } 563 747 … … 565 749 if ( (FillColor != PI_NotDefColor) || (FillColor != mFillColor) ){ 566 750 mFillColor = FillColor; 567 WriteSetColor(FillColor); 568 } 569 WriteDrawFCircle(x0, y0, r); 751 fprintf(mPSFile, "C%d ", mFillColor) ; 752 } 753 fprintf(mPSFile, "gs n %.2f Ux %.2f Uy %.2f Ux %.2f Uy \ 754 0 360 ellipse f gr\n", 755 x0, y0, r, r); 756 fprintf(mPSFile, "C%d ", mDrawColor) ; 570 757 571 758 /* Dessin du contour (s'il y a lieu) */ 572 759 if ( (DrawColor != PI_NotDefColor) && (FillColor != DrawColor) ) { 573 760 mDrawColor = DrawColor; 574 WriteSetColor(DrawColor); 575 WriteDrawCircle(x0, y0, r); 576 } 577 BlocEmpty = 0; 578 PageEmpty = 0; 761 fprintf(mPSFile, "C%d ", mDrawColor); 762 fprintf(mPSFile, "gs n %.2f Ux %.2f Uy %.2f Ux %.2f Uy 0 360 ellipse s gr\n", 763 x0, y0, r, r) ; 764 } 579 765 } 580 766 … … 583 769 PIColors DrawColor, 584 770 PILineAtt LineAtt) { 585 extern int BlocEmpty;586 extern int PageEmpty;587 // int change = 0;588 771 589 772 /* Line Att */ 590 773 if ( (LineAtt != PI_NotDefLineAtt) || (LineAtt != mLineAtt) ) { 591 774 mLineAtt = LineAtt; 592 WriteSetLineWidth(mLineAtt);775 fprintf(mPSFile, "%d slw ", mLineAtt) ; 593 776 } 594 777 … … 596 779 if ( (DrawColor != PI_NotDefColor) || (DrawColor != mDrawColor) ) { 597 780 mDrawColor = DrawColor; 598 WriteSetColor(DrawColor);781 fprintf(mPSFile, "C%d ", mDrawColor) ; 599 782 } 600 783 601 784 /* On dessine ; ici*/ 602 WriteDrawPolygon (x, y, n); 603 604 BlocEmpty = 0; 605 PageEmpty = 0; 785 fprintf(mPSFile, "%.2f Ux %.2f Uy m\n", x[0], y[0]); 786 for(int i = 0; i<n; i++) 787 fprintf(mPSFile, "%.2f Ux %.2f Uy %.2f Ux %.2f Uy l\n", 788 x[i+1], y[i+1], x[i], y[i]); 789 fprintf(mPSFile, "c s\n"); 606 790 } 607 791 … … 612 796 PILineAtt LineAtt) { 613 797 614 extern int BlocEmpty;615 extern int PageEmpty;616 617 798 /* Line Att */ 618 799 if ( (LineAtt != PI_NotDefLineAtt) || (LineAtt != mLineAtt) ) { 619 800 mLineAtt = LineAtt; 620 WriteSetLineWidth(mLineAtt);801 fprintf(mPSFile, "%d slw ", mLineAtt) ; 621 802 } 622 803 623 804 /* Dessin du fond... */ 624 if ( (FillColor != PI_NotDefColor) || (FillColor != mFillColor) ) {805 if ( (FillColor != PI_NotDefColor) || (FillColor != mFillColor) ) 625 806 mFillColor = FillColor; 626 WriteSetColor(FillColor); 627 } 628 WriteDrawFPolygon(x, y, n); 807 fprintf(mPSFile, "C%d ", mFillColor) ; 808 fprintf(mPSFile, "%.2f Ux %.2f Uy m\n", x[0], y[0]); 809 int i; 810 for(i = 0; i<n; i++) 811 fprintf(mPSFile, "%.2f Ux %.2f Uy %.2f Ux %.2f Uy l\n", 812 x[i+1], y[i+1], x[i], y[i]); 813 fprintf(mPSFile, "c f\n"); 629 814 630 815 /* ...puis du contour (s'il y a lieu) */ 631 if ( (DrawColor != PI_NotDefColor) && (DrawColor != FillColor) ) {816 if ( (DrawColor != PI_NotDefColor) && (DrawColor != FillColor) ) 632 817 mDrawColor = DrawColor; 633 WriteSetColor(DrawColor);634 WriteDrawPolygon(x, y, n);635 }636 637 BlocEmpty = 0;638 PageEmpty = 0;818 fprintf(mPSFile, "C%d ", mDrawColor) ; 819 fprintf(mPSFile, "%.2f Ux %.2f Uy m\n", x[0], y[0]); 820 for(i = 0; i<n; i++) 821 fprintf(mPSFile, "%.2f Ux %.2f Uy %.2f Ux %.2f Uy l\n", 822 x[i+1], y[i+1], x[i], y[i]); 823 fprintf(mPSFile, "c s\n"); 639 824 } 640 825 … … 642 827 643 828 void PSFile::DrawMarker (float x0, float y0, 644 PIMarker MrkType, 645 PIColors DrawColor) { 646 extern int BlocEmpty; 647 extern int PageEmpty; 648 649 829 PIMarker MrkType, 830 PIColors DrawColor, 831 int MarkerSize) { 650 832 /* Couleurs */ 651 833 if ( (DrawColor != PI_NotDefColor) || (DrawColor != mDrawColor) ) { 652 834 mDrawColor = DrawColor; 653 WriteSetColor(mDrawColor);835 fprintf(mPSFile, "C%d ", mDrawColor) ; 654 836 } 655 837 … … 658 840 mMarker = MrkType; 659 841 842 if(MarkerSize != mMarkerSize) { 843 mMarkerSize = MarkerSize ; 844 fprintf(mPSFile, "/PIMarkers ff %d scf sf\n", mMarkerSize) ; 845 } 660 846 /* Dessin */ 661 WriteDrawMarker(x0, y0); 662 663 BlocEmpty = 0; 664 PageEmpty = 0; 665 } 666 667 847 fprintf(mPSFile, "%.2f Ux %.2f Uy m (\\%#o) show\n", x0, y0, mMarker) ; 848 849 } 850 851 /* 852 * Pas d'options pour specifier la taille des Markers ? 853 * 854 */ 668 855 void PSFile::DrawMarkers (float *x0, float *y0, int n, 669 PIMarker MrkType, 670 PIColors DrawColor) { 671 extern int BlocEmpty; 672 extern int PageEmpty; 673 856 PIMarker MrkType, 857 PIColors DrawColor, 858 int MarkerSize) { 674 859 /* Couleurs */ 675 860 if ( (DrawColor != PI_NotDefColor) || (DrawColor != mDrawColor) ) { 676 861 mDrawColor = DrawColor; 677 WriteSetColor(mDrawColor);862 fprintf(mPSFile, "C%d ", mDrawColor) ; 678 863 } 679 864 … … 682 867 mMarker = MrkType; 683 868 869 if(MarkerSize != mMarkerSize) { 870 mMarkerSize = MarkerSize ; 871 fprintf(mPSFile, "/PIMarkers ff %d scf sf\n", mMarkerSize) ; 872 } 684 873 /* Dessin */ 685 WriteDrawMarkers(x0, y0, n); 686 687 BlocEmpty = 0; 688 PageEmpty = 0; 874 for(int i = 0; i<n; i++) 875 fprintf(mPSFile, "%.2f Ux %.2f Uy m (\\%#o) show\n", x0[i], y0[i], mMarker) ; 689 876 } 690 877 … … 694 881 PIColorMap *mMap) { 695 882 696 extern int BlocEmpty; 697 extern int PageEmpty; 698 699 WriteImage(x0, y0, Tx, Ty, Nx, Ny, Pict,mMap); 700 701 BlocEmpty = 0; 702 PageEmpty = 0; 883 int i, j; 884 885 /* Buffers PostScript */ 886 fprintf(mPSFile, "/Taille %d def\n", Nx); 887 fprintf(mPSFile, "/ImStr Taille string def\n"); 888 fprintf(mPSFile, "/RGBStr Taille 3 mul string def\n"); 889 890 /* Ecriture ColorMap */ 891 fprintf(mPSFile, "/ColorMap %02d array def\n", mMap->NCol() ); 892 for(i = 0; i < mMap->NCol(); i++) { 893 fprintf(mPSFile, "ColorMap %d [16#%02X 16#%02X 16#%02X] put\n", 894 i, 895 (int)(mMap->GetColor(i).red/256), 896 (int)(mMap->GetColor(i).green/256), 897 (int)(mMap->GetColor(i).blue/256)); 898 } 899 /* Emplacement de l'image */ 900 fprintf(mPSFile, "gs %.2f %.2f tr %.2f Ux %.2f Uy sc\n", x0, y0, Tx, Ty); 901 /* Nbr pix-X, Nbr pix-Y bits/pixels */ 902 fprintf(mPSFile, "%d %d 8\n", Nx, Ny); 903 /* Matrice de passage */ 904 fprintf(mPSFile, "[%d 0 0 %d 0 0]", Nx, Ny); 905 /* Fonction colorimage */ 906 fprintf(mPSFile, "{currentfile ImStr readhexstring pop GetRGB}\ 907 false 3 colorimage\n\n"); 908 /* Data */ 909 for(i = 0; i < Ny; i++) { 910 for(j = 0; j<Nx-1; j++ ) 911 fprintf(mPSFile, "%02X", Pict[i*Nx+j]); 912 fprintf(mPSFile, "%02X\n", Pict[i*Nx+j]); 913 } 914 /* Un petit grestore ...*/ 915 fprintf(mPSFile, "gr\n"); 703 916 } 704 917 705 918 /* 706 * Une fonction de conversion qui sert une fois919 * Conversion 707 920 * 708 921 */ … … 712 925 } 713 926 714 715 /* Logique de controle */716 /* static */ int FileEmpty = 1;717 /* static */ int PageEmpty;718 /* static */ int BlocEmpty;719 /* static */ int BlocActive;720 /* static */ int PageActive; -
trunk/SophyaPI/PI/psfile.h
r40 r44 12 12 * Au depart, 1UC == 1cm 13 13 * - Les reperes sont orientes a la maniere XWindow 14 * 15 * 17/02/97 : modification des constructeurs(1-->eps,2-->ps) 16 * ajout du type enum orientation 14 17 * 15 18 */ … … 22 25 #endif 23 26 #include "pisysdep.h" 27 //#include "piinclude.h" 24 28 25 29 #include PIBWDG_H // Types enumeres repris de Peida:PIFontSize... … … 29 33 30 34 31 /* 32 * Unique format actuellement gere : A4 33 * 34 */ 35 enum PIPaperSizes { PI_A3 = 0, PI_A4 = 1, PI_A5 = 2, PI_NotDef = -1}; 36 37 #define PAGE_WIDTH 21.0 /* == 595 points */ 38 #define PAGE_HEIGHT 29.7 /* == 842 points */ 39 40 #define PORTRAIT 1 41 #define LANDSCAPE 0 35 36 /* 37 *#define PAGE_WIDTH 21.0 == 595 points 38 *#define PAGE_HEIGHT 29.7 == 842 points 39 *#define PORTRAIT 1 40 *#define LANDSCAPE 0 41 */ 42 42 43 43 44 44 45 45 /* Valable pour une page, ou un bloc */ 46 typedef struct { 47 float X0; /* Coordonnes sommet NO */ 48 float Y0; /* en unites courantes */ 49 float Tx; /* Format */ 50 float Ty; /* en unites courantes */ 51 float Dx; /* Coord sommet SE */ 52 float Dy; /* en unites courantes */ 53 int orientation; /* LANDSCAPE OU PORTRAIT */ 54 } Format; 55 56 57 typedef struct{ 58 char *Name; 59 int Tx; /* En 1/72e de pouce !! */ 60 int Ty; /* unite naturelle de ps */ 61 } PIMedia; 62 46 /*typedef struct { 47 * float X0; Coordonnes sommet NO 48 * float Y0; en unites courantes 49 * float Tx; Format 50 * float Ty; en unites courantes 51 * float Dx; Coord sommet SE 52 * float Dy; en unites courantes 53 * int orientation; LANDSCAPE OU PORTRAIT 54 *} Format; 55 */ 56 57 /* 58 *typedef struct{ 59 * char *Name; 60 * int Tx; En 1/72e de pouce !! 61 * int Ty; unite naturelle de ps 62 *} PIMedia; 63 */ 63 64 64 65 … … 67 68 68 69 public: 69 70 PSFile (char * FileName, float Tx = 0, float Ty = 0, 71 float Dx = 0, float Dy = 0); 72 /* PSFile (PSFile *File, int PageNum, int BlocNum);*/ 73 /* PSFile (char * FileName, int PageNum, int BlocNum);*/ 70 /* Production fichier eps */ 71 PSFile (char * FileName, float sc = 1.0); 72 /* Production fichier ps */ 73 PSFile (char * FileName, PIOrientation orientation, 74 PIPaperSize paperSize= PI_A4, 75 float marginX = 1.0, float marginY = 1.0 ) ; 74 76 75 77 virtual ~PSFile(); … … 79 81 80 82 81 /* A changer ? 82 * Pourrait introduire des incompatibilites 83 * en cas de chgt sur la struct format ? 84 */ 85 virtual Format* GetFormat(); 86 87 /*Attributs graphiques */ 83 /* virtual Format* GetFormat(); */ 84 /* Attributs graphiques */ 88 85 virtual PIColors GetDrawColor(); 89 86 virtual PIColors GetFillColor(); … … 93 90 virtual PIMarker GetMarker(); 94 91 95 virtual void NewPage(float Dx, float Dy, intorientation);92 virtual void NewPage(float Dx, float Dy, PIOrientation orientation); 96 93 virtual void EndPage(); 97 94 virtual void NewBloc(float x0, float y0, float Tx, float Ty, … … 130 127 virtual void DrawMarker (float x0, float y0, 131 128 PIMarker MrkType = PI_NotDefMarker, 132 PIColors DrawColor = PI_NotDefColor); 129 PIColors DrawColor = PI_NotDefColor, 130 int MarkerSize=14); 133 131 virtual void DrawMarkers (float *x0, float *y0, int n, 134 132 PIMarker MrkType = PI_NotDefMarker, 135 PIColors DrawColor = PI_NotDefColor); 133 PIColors DrawColor = PI_NotDefColor, 134 int MarkerSize=14); 136 135 137 136 virtual void Image(float x0, float y0, float Tx, float Ty, … … 140 139 PIColorMap *mColorMap); 141 140 142 143 144 145 146 147 148 typedef struct { 149 off_t begin; 150 off_t end; 151 } Offset; 152 141 #ifndef __DECCXX 142 private: 143 #endif 144 145 153 146 /* Blocs */ 154 147 typedef struct { 155 148 int num; 156 149 char* label; 157 Format format; 158 Offset offset; 159 } Bloc; 150 float X0, Y0; /* coordonnees sommet NO */ 151 float Tx, Ty; /* Format */ 152 float Dx, Dy; /* Repere utilisateur */ 153 long begin,end,tmp; /* offsets dans le fichier */ 154 } Bloc ; 160 155 typedef list<Bloc> BlocList; /* STL */ 156 161 157 162 158 /* Pages */ … … 164 160 int num; 165 161 int BlocCounter; 166 Format format; 167 Offset offset; 168 BlocList mBlocList; /* Page == Liste de blocs */ 169 } Page; 162 float Dx,Dy; /* Sommet SE (unites utilisateur) */ 163 PIOrientation orientation; 164 long begin, end, tmp; /* Offsets dans le fichier */ 165 BlocList mBlocList; /* Page == Liste de blocs */ 166 } Page ; 170 167 typedef list<Page> PageList; /* STL */ 171 168 169 #ifdef __DECCXX 172 170 private: 173 174 /* --> Toute la classe */ 175 static PSFile** PSFiles; /* Tableau des PSFiles existants */ 176 177 /* --> le fichier */ 171 #endif 172 173 /* Fichier ps/eps */ 178 174 FILE * mPSFile; 179 175 char * mPSFileName; 176 float Tw,Th ; /* Format, en cm */ 177 float WMargin,HMargin ; /* Marges minimales */ 180 178 int isEPS; /* Vrai si PostScript Encapsule */ 181 Format mFormat; /* Format par defaut */ 182 int PageCounter; /* Nbre de pages */ 183 PageList mPageList; /* Fichier == Liste de pages */ 184 185 /* Attributs graphiques */ 179 long boundingBox; /* Endroit ou est specifiee la bb */ 180 float scale; /* boundingbox = Dx*scale ; Dy*scale */ 181 PIPaperSize mPaperSize ; 182 int PageCounter; /* nbr pages */ 183 int FileEmpty; 184 Page* currentPage; /* Avant empilage */ 185 Bloc* currentBloc; /* Avant empilage */ 186 PageList mPageList; /* Fichier == Liste de pages */ 187 188 189 /* Attributs graphiques, initialises par constructeur */ 186 190 enum PIColors mDrawColor; /* Couleur de trace courante */ 187 191 enum PIColors mFillColor; /* Couleur de remplissage courante */ 188 enum PIFontAtt mFontAtt; 189 enum PIFontSize mFontSize; 192 enum PIFontAtt mFontAtt; 193 enum PIFontSize mFontSize; 190 194 enum PILineAtt mLineAtt; /* Epaisseur d une ligne */ 191 195 enum PIMarker mMarker; /* Marker courant */ 192 193 194 /* Ecriture du PostScript dans le fichier Physique */ 195 /* Le code se trouve ds PSDict.cc */ 196 virtual void WriteHeader(); 197 virtual void WriteTrailer(); 198 virtual void WriteNewPage(Page *mPage); 199 virtual void WriteEndPage(Page *mPage); 200 virtual void WriteNewBloc(Bloc *mBloc); 201 virtual void WriteEndBloc(Bloc *mBloc); 202 virtual void WriteDrawString(float x, float y, char* s); 203 virtual void WriteDrawLine(float x1, float y1, float x2, float y2); 204 virtual void WriteDrawBox(float x0, float y0, float Tx, float Ty); 205 virtual void WriteDrawFBox(float x0, float y0, float Tx, float Ty); 206 virtual void WriteDrawCircle(float x0, float y0, float r); 207 virtual void WriteDrawFCircle(float x0, float y0, float r); 208 virtual void WriteDrawPolygon(float *x, float *y, int n); 209 virtual void WriteDrawFPolygon(float *x, float *y, int n); 210 virtual void WriteDrawMarker(float x0, float y0); 211 virtual void WriteDrawMarkers(float *x0, float *y0, int n); 212 virtual void WriteImage(float x0, float y0, float Tx, float Ty, 213 int Nx, int Ny, unsigned char *pict, PIColorMap *mColorMap); 214 virtual void WriteSetColor(PIColors mDrawColor); 215 virtual void WriteSetFont(PIFontAtt mFontAtt, int mFontSize); 216 virtual void WriteSetLineWidth(PILineAtt mLineAtt); 217 }; /* End class PSFile */ 196 int mMarkerSize; /* Taille (en points) du marker courant */ 197 } ; 198 218 199 219 200 #endif/* PSFILE_H_SEEN */
Note:
See TracChangeset
for help on using the changeset viewer.