MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
pslib.class
Ir para a documentação deste ficheiro.
1<?php
2// +-----------------------------------------------------------------+
3// | PSLib - PHP class for generating PostScript files. |
4// +-----------------------------------------------------------------+
5// | CopyLeft (L) 1999-2002 Vilson Cristiano Gartner |
6// | UNIVATES - Centro Universitario |
7// +-----------------------------------------------------------------+
8// | Licensed under LGPL: see COPYING or FSF at www.fsf.org for |
9// | further details |
10// | |
11// | Site: http://pslib.codigolivre.org.br |
12// | E-mail: vgartner@univates.br |
13// | |
14// +-----------------------------------------------------------------+
15// | Abstract: PSLib main class file. |
16// | |
17// | Created: 2002/07/24 - Vilson Cristiano Gartner |
18// | |
19// | PSLib Version: 0.4 |
20// +-----------------------------------------------------------------+
21
23{
24 var $fp;
26 var $string = "";
27 var $page = 1;
28 var $ISOLatin1 = true; //ISOLatin Encoding
30 var $fonts;
31 var $red = -1;
32 var $green = -1;
33 var $blue = -1;
34
35 // startup the whole thing = Aqui tudo inicia
36 function postscript($fname = "", $author = "", $title = "Generated with PSLib 0.4", $orientation = "Portrait",
37 $fonts = "")
38 {
39 // A text string was requested: file name to create
40 if ($fname)
41 {
42 if (!$this->fp = fopen($fname, "w"))
43 return (0);
44 }
45
46 if ($fonts)
47 {
48 foreach ($fonts as $f)
49 {
50 $this->fonts[] = $f;
51 }
52 }
53
54 $this->string .= "%!PS-Adobe-3.0 \n";
55 $this->string .= '%%Creator: ' . $author . " using PSLib (http://pslib.codigolivre.org.br)\n";
56 $this->string .= '%%CreationDate: ' . date("d/m/Y, H:i") . "\n";
57 $this->string .= '%%LanguageLevel: 2';
58 $this->string .= '%%Title: ' . $title . "\n";
59 $this->string .= "%%PageOrder: Ascend \n";
60 $this->string .= '%%Orientation: ' . $orientation . "\n";
61 $this->string .= "%%DocumentMedia: A4 595 842 0 () ()\n";
62 $this->string .= "%%EndComments \n";
63 $this->string .= "%%BeginProlog \n";
64 $this->string .= "%%BeginResource: definicoes \n";
65
66 // Include resources
67 if (!empty($this->resources))
68 {
69 foreach ($this->resources as $r)
70 {
71 $this->string .= $r . " \n";
72 }
73 }
74
75 $this->string .= "%%EndResource \n";
76 $this->string .= "%%EndProlog \n\n";
77
78 $this->string .= "/d {bind def} bind def \n";
79 $this->string .= "/D {def} d \n";
80 $this->string .= "/t true D \n";
81 $this->string
82 .= "/np {newpath} D /cp {closepath} D /gs {gsave} D /gr {grestore} D /sk {stroke} D /fl {fill} D /rt {rotate} D /s {show} D /ff {findfont} D /cf {scalefont setfont} d /mv {moveto} D /lw {setlinewidth} D /lt {lineto} D /sc {setrgbcolor} D /sp {showpage} D /rc {-1 -1 -1 sc} D \n";
83
84 if ($this->ISOLatin1 == true)
85 {
86 // Fonts for encoding
87 $this->string .= '/FL [';
88 $this->string .= '/Arial /Arial-Bold /Arial-Italic /Arial-BoldItalic ';
89 $this->string .= '/Times /Times-Roman /Times-Bold /Times-BoldItalic ';
90 $this->string .= '/Courier /Courier-Oblique /Courier-Bold /Courier-BoldOblique';
91 $this->string .= '/Helvetica /Helvetica-Oblique /Helvetica-Bold /Helvetica-BoldOblique';
92
93 // Any aditional font
94 if (!empty($this->fonts))
95 {
96 foreach ($this->fonts as $f)
97 {
98 $this->string .= "/$f ";
99 }
100 }
101
102 $this->string .= "] D \n";
103
104 $this->string
105 .= "/ReencodeISO {
106 dup dup findfont dup length dict
107 begin{1 index /FID ne{D}{pop pop}
108 ifelse }forall \n";
109
110 $this->string
111 .= "/Encoding ISOLatin1Encoding D currentdict end definefont} D
112 /ISOLatin1Encoding [
113 /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
114 /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
115 /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
116 /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
117 /space/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright
118 /parenleft/parenright/asterisk/plus/comma/hyphen/period/slash
119 /zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon
120 /less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N
121 /O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright
122 /asciicircum/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m
123 /n/o/p/q/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/asciitilde
124 /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
125 /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
126 /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
127 /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
128 /.notdef/space/exclamdown/cent/sterling/currency/yen/brokenbar
129 /section/dieresis/copyright/ordfeminine/guillemotleft/logicalnot
130 /hyphen/registered/macron/degree/plusminus/twosuperior/threesuperior
131 /acute/mu/paragraph/periodcentered/cedilla/onesuperior/ordmasculine
132 /guillemotright/onequarter/onehalf/threequarters/questiondown
133 /Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla
134 /Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex
135 /Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis
136 /multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute
137 /Thorn/germandbls/agrave/aacute/acircumflex/atilde/adieresis
138 /aring/ae/ccedilla/egrave/eacute/ecircumflex/edieresis/igrave
139 /iacute/icircumflex/idieresis/eth/ntilde/ograve/oacute/ocircumflex
140 /otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex/udieresis
141 /yacute/thorn/ydieresis
142 ] D \n";
143
144 $this->string
145 .= "[128/backslash 129/parenleft 130/parenright 141/circumflex 142/tilde
146 143/perthousand 144/dagger 145/daggerdbl 146/Ydieresis 147/scaron 148/Scaron
147 149/oe 150/OE 151/guilsinglleft 152/guilsinglright 153/quotesinglbase
148 154/quotedblbase 155/quotedblleft 156/quotedblright 157/endash 158/emdash
149 159/trademark] \n";
150
151 $this->string
152 .= "aload length 2 idiv 1 1 3 -1 roll{pop ISOLatin1Encoding 3 1 roll put}for
153 t{FL{ReencodeISO D}forall}{4 1 FL length 1 sub{FL E get ReencodeISO D}for}ifelse \n";
154 }
155
156 return (1);
157 }
158
159 // Internal use. Adds fonts for ISOLatin1 Encoding
160 function _add_font($font)
161 {
162 if (!$font)
163 {
164 return (0);
165 }
166
167 if ($this->ISOLatin1 == true)
168 {
169 $ffound = false;
170
171 if (!empty($this->fonts))
172 {
173 foreach ($this->fonts as $f)
174 {
175 if ($font == $f)
176 {
177 $ffound = true;
178 break;
179 }
180 }
181 }
182
183 if (!$ffound)
184 {
185 $this->fonts[] = $font;
186 }
187 }
188
189 return (1);
190 }
191
192 // Insert a line in the file
193 function insert_line($line)
194 {
195 $this->string .= $line . " \n";
196
197 return (1);
198 }
199
200 // Include resource in the file's Resources Section
201 function include_resource($res)
202 {
203 $this->resources[] = $res;
204
205 return (1);
206 }
207
208 // Use ISOLatin1 Encoding = Acentuação, caracteres gráficos
209 function encode_ISOLatin1($var = true)
210 {
211 $this->ISOLatin1 = $var;
212
213 return (1);
214 }
215
216 // Begin new page = Inicia uma nova pagina
218 {
219 $this->string .= "%%Page: " . $page . ' ' . $page . "\n";
220
221 return (1);
222 }
223
224 // End page = Finaliza pagina
225 function end_page()
226 {
227 $this->string .= "sp \n";
228
229 return (1);
230 }
231
232 // Close the postscript file = Fecha o arquivo postscript
233 function close()
234 {
235 $this->string .= "sp \n";
236
237 if ($this->fp)
238 {
239 fwrite($this->fp, $this->string);
240 fclose ($this->fp);
241 }
242
243 return ($this->string);
244 }
245
246 // Draw a line = Desenha uma linha
247 function line($xcoord_from = 0, $ycoord_from = 0, $xcoord_to = 0, $ycoord_to = 0, $linewidth = 0)
248 {
249 if ((!$xcoord_from) || (!$ycoord_to) || (!$xcoord_to) || (!$ycoord_to) || (!$linewidth))
250 return (0);
251
252 $this->string .= $linewidth . " lw ";
253 $this->string .= $xcoord_from . ' ' . $ycoord_from . " mv \n";
254 $this->string .= $xcoord_to . ' ' . $ycoord_to . " lt \n";
255 $this->string .= "sk \n";
256
257 return (1);
258 }
259
260 // Move to coordinates = Move para as coordenadas
261 function moveto($xcoord, $ycoord)
262 {
263 if ((empty($xcoord)) || (empty($ycoord)))
264 return (0);
265
266 $this->string .= $xcoord . ' ' . $ycoord . " mv \n";
267
268 return (1);
269 }
270
271 // Move to coordinates and change the font = Move para as coordenadas e muda a fonte
272 function moveto_font($xcoord, $ycoord, $font_name, $font_size)
273 {
274 if ((!$xcoord) || (!$ycoord) || (!$font_name) || (!$font_size))
275 return (0);
276
277 $this->string .= $xcoord . ' ' . $ycoord . " mv \n";
278 $this->string .= '/' . $font_name . ' ff ' . $font_size . " cf \n";
279
280 $this->_add_font($font_name);
281
282 return (1);
283 }
284
285 // Insert a PS file/image (remember to delete the information in the top of the file (source))
286 // Insere um arquivo/imagem PS (lembre-se de remover a informaçao no inicio daquele arquivo)
287 function open_ps($ps_file = "")
288 {
289 if (!$ps_file)
290 return (0);
291
292 if ($f = join('', file($ps_file)))
293 $this->string .= $f;
294 else
295 return (0);
296
297 return (1);
298 }
299
300 // Draw a circle = Desenha um circulo
301 function circle($xcoord, $ycoord, $ray, $linewidth)
302 {
303 if ((!$xcoord) || (!$ycoord) || (!$ray) || (!$linewidth))
304 return (0);
305
306 $this->arc($xcoord, $ycoord, $ray, $linewidth, 1, 360);
307
308 return (1);
309 }
310
311 // Draw and shade circle = Desenha um circulo
312 function circle_fill($xcoord, $ycoord, $ray, $linewidth, $red, $green, $blue, $border = false)
313 {
314 if ((!$xcoord) || (!$ycoord) || (!$ray) || (!$linewidth) || (!$red) || (!$green) || (!$blue))
315 return (0);
316
317 $this->arc_fill($xcoord, $ycoord, $ray, $linewidth, 1, 360, $red, $green, $blue, $border);
318
319 return (1);
320 }
321
322 // Draw a arc = Desenha um arco
323 function arc($xcoord, $ycoord, $ray, $linewidth, $angle_start, $angle_end)
324 {
325 if ((!$xcoord) || (!$ycoord) || (!$ray) || (!$angle_start) || (!$angle_end) || (!$linewidth))
326 return (0);
327
328 $this->string .= "np \n";
329 $this->string .= $linewidth . " lw \n";
330 $this->string .= $xcoord . ' ' . $ycoord . ' ' . $ray . ' ' . $angle_start . ' ' . $angle_end . " arc \n";
331 $this->string .= "cp \n";
332 $this->string .= "sk \n";
333
334 return (1);
335 }
336
337 // Draw and shade a arc = Desenha e preenche um arco
338 function arc_fill($xcoord, $ycoord, $ray, $linewidth, $angle_start, $angle_end, $red, $green, $blue,
339 $border = false)
340 {
341 if ((!$xcoord) || (!$ycoord) || (!$ray) || (!$angle_start) || (!$angle_end) || (!$linewidth))
342 return (0);
343
344 $this->string .= "np \n";
345 $this->string .= $linewidth . " lw \n";
346 $this->string .= $xcoord . ' ' . $ycoord . ' ' . $ray . ' ' . $angle_start . ' ' . $angle_end . " arc \n";
347 $this->string .= "cp \n";
348
349 if ($border)
350 $this->string .= "gs \n";
351
352 $this->string .= "$red $green $blue sc fl\n";
353
354 if ($border)
355 $this->string .= "gr \n";
356
357 $this->string .= "sk \n";
358
359 return (1);
360 }
361
362 // Draw a rectangle = Desenha um retangulo
363 function rect($xcoord_from, $ycoord_from, $xcoord_to, $ycoord_to, $linewidth)
364 {
365 if ((!$xcoord_from) || (!$ycoord_from) || (!$xcoord_to) || (!$ycoord_to) || (!$linewidth))
366 return (0);
367
368 $this->string .= $linewidth . " lw \n";
369 $this->string .= "np \n";
370 $this->string .= $xcoord_from . ' ' . $ycoord_from . " mv \n";
371 $this->string .= $xcoord_to . ' ' . $ycoord_from . " lt \n";
372 $this->string .= $xcoord_to . ' ' . $ycoord_to . " lt \n";
373 $this->string .= $xcoord_from . " " . $ycoord_to . " lt \n";
374 $this->string .= "cp \n";
375 $this->string .= "sk \n";
376
377 return (1);
378 }
379
380 // Draw and shade a rectangle = Desenha um retangulo e preenche
381 function rect_fill($xcoord_from, $ycoord_from, $xcoord_to, $ycoord_to, $linewidth, $red, $green, $blue,
382 $border = false)
383 {
384 if ((!$xcoord_from) || (!$ycoord_from) || (!$xcoord_to) || (!$ycoord_to) || (!$linewidth) || (!$red)
385 || (!$green) || (!$blue))
386 return (0);
387
388 $this->string .= "np \n";
389 $this->string .= $linewidth . " lw \n";
390 $this->string .= $xcoord_from . ' ' . $ycoord_from . " mv \n";
391 $this->string .= $xcoord_to . ' ' . $ycoord_from . " lt \n";
392 $this->string .= $xcoord_to . ' ' . $ycoord_to . " lt \n";
393 $this->string .= $xcoord_from . ' ' . $ycoord_to . " lt \n";
394 $this->string .= "cp \n";
395
396 if ($border)
397 $this->string .= "gs \n";
398
399 $this->string .= "$red $green $blue sc fl \n";
400
401 if ($border)
402 $this->string .= "gr \n";
403
404 $this->string .= "sk \n";
405
406 return (1);
407 }
408
409 // Set rotation, use 0 or 360 to end rotation
410 // Muda a rotacao do texto, passe 0 ou 360 para finalizar a rotacao
411 function rotate($degrees)
412 {
413 if (!$degrees)
414 return (0);
415
416 if (($degrees == '0') or ($degrees == '360'))
417 {
418 $this->string .= "gr \n";
419 }
420 else
421 {
422 $this->string .= "gs \n";
423 $this->string .= $degrees . " rt \n";
424 }
425
426 return (1);
427 }
428
429 // Set the font to show = Muda a fonte
430 function set_font($font_name, $font_size)
431 {
432 if ((!$font_name) || (!$font_size))
433 return (0);
434
435 $this->string .= '/' . $font_name . ' ff ' . $font_size . " cf \n";
436
437 $this->_add_font($font_name);
438
439 return (1);
440 }
441
442 // Show some text at the current coordinates (use 'moveto' to set coordinates)
443 // if red, green, blue left blank, defaults to black or last set_color
444 // color is determined by standard red, green, blue coding from 0-1, decimals are usable
445 // examples; light red = 1 0 0, light green = 0 1 0, light blue 0 0 1,
446 // darker blue = 0 0 .5, light purple = 1 0 1, see palette.ps for all values
447 // justification: l (default) left justified
448 // c = centered (centers around current coordinates, therefore to center
449 // on a line, moveto the center of the page)
450 // r = right justified (right justifies at the current location, use moveto
451 // to set coordinates)
452 function show($text, $red = '', $green = '', $blue = '', $justify = 'l')
453 {
454 if (!$text)
455 return (0);
456
457 if (($red) || ($green) || ($blue) && ($red != $red1) || ($green != $green1) || ($blue != $blue1))
458 {
459 $red1 = $this->red;
460 $green1 = $this->green;
461 $blue1 = $this->blue;
462
463 $restart_color = true;
464 $this->set_color($red, $green, $blue);
465 }
466
467 switch ($justify)
468 {
469 case 'c':
470 $this->string .= "( $text ) dup stringwidth pop 2 div neg 0 rmoveto s \n";
471
472 break;
473
474 case 'r':
475 $this->string .= "( $text ) dup stringwidth pop neg 0 rmoveto s \n";
476
477 break;
478
479 default:
480 $this->string .= "( $text ) s \n";
481
482 break;
483 }
484
485 $this->_add_font($font_name);
486
487 if ($restart_color)
488 {
489 $this->set_color($red1, $green1, $blue1);
490 }
491
492 return (1);
493 }
494
495 // Evaluate the text and show it at the current coordinates
496 // Processa o texto e o escreve na posicao atual
497 function show_eval($text)
498 {
499 if (!$text)
500 return (0);
501
502 eval ("\$text = \"$text\";");
503 $this->string .= '(' . $text . ") s \n";
504
505 return (1);
506 }
507
508 // Show some text at specific coordinates and resets color back to black
509 // Escreve o texto na coordenada informada e reseta a cor para preto
510 function show_xy($text, $xcoord, $ycoord, $red = '', $green = '', $blue = '', $justify = 'l')
511 {
512 if ((!$text) || (!$xcoord) || (!$ycoord))
513 return (0);
514
515 $this->moveto($xcoord, $ycoord);
516 $this->show($text, $red, $green, $blue, $justify);
517
518 return (1);
519 }
520
521 // Show some text at specific coordinates with font settings
522 // Mostra o texto na coordenada informa com a fonte especifica
523 function show_xy_font($text, $xcoord, $ycoord, $font_name, $font_size, $red = '', $green = '', $blue = '',
524 $justify = 'l')
525 {
526 if ((!$text) || (!$xcoord) || (!$ycoord) || (!$font_name) || (!$font_size))
527 return (0);
528
529 $this->set_font($font_name, $font_size);
530 $this->show_xy($text, $xcoord, $ycoord, $red, $green, $blue, $justify);
531
532 return (1);
533 }
534
535 // Set the color to show text as. = setar a cor padrao
536 function set_color($red = -1, $green = -1, $blue = -1)
537 {
538 $this->red = $red;
539 $this->green = $green;
540 $this->blue = $blue;
541
542 if (($red == -1) && ($green == -1) && ($blue == -1))
543 {
544 $this->string .= "rc \n";
545 }
546 else
547 {
548 $this->string .= "$red $green $blue sc \n";
549 }
550
551 return (1);
552 }
553}
554?>
include_resource($res)
Definição pslib.class:201
rect_fill($xcoord_from, $ycoord_from, $xcoord_to, $ycoord_to, $linewidth, $red, $green, $blue, $border=false)
Definição pslib.class:381
arc($xcoord, $ycoord, $ray, $linewidth, $angle_start, $angle_end)
Definição pslib.class:323
show($text, $red='', $green='', $blue='', $justify='l')
Definição pslib.class:452
show_xy_font($text, $xcoord, $ycoord, $font_name, $font_size, $red='', $green='', $blue='', $justify='l')
Definição pslib.class:523
line($xcoord_from=0, $ycoord_from=0, $xcoord_to=0, $ycoord_to=0, $linewidth=0)
Definição pslib.class:247
rotate($degrees)
Definição pslib.class:411
show_xy($text, $xcoord, $ycoord, $red='', $green='', $blue='', $justify='l')
Definição pslib.class:510
circle($xcoord, $ycoord, $ray, $linewidth)
Definição pslib.class:301
show_eval($text)
Definição pslib.class:497
arc_fill($xcoord, $ycoord, $ray, $linewidth, $angle_start, $angle_end, $red, $green, $blue, $border=false)
Definição pslib.class:338
encode_ISOLatin1($var=true)
Definição pslib.class:209
moveto($xcoord, $ycoord)
Definição pslib.class:261
circle_fill($xcoord, $ycoord, $ray, $linewidth, $red, $green, $blue, $border=false)
Definição pslib.class:312
rect($xcoord_from, $ycoord_from, $xcoord_to, $ycoord_to, $linewidth)
Definição pslib.class:363
postscript($fname="", $author="", $title="Generated with PSLib 0.4", $orientation="Portrait", $fonts="")
Definição pslib.class:36
moveto_font($xcoord, $ycoord, $font_name, $font_size)
Definição pslib.class:272
insert_line($line)
Definição pslib.class:193
_add_font($font)
Definição pslib.class:160
open_ps($ps_file="")
Definição pslib.class:287
begin_page($page)
Definição pslib.class:217
set_font($font_name, $font_size)
Definição pslib.class:430
set_color($red=-1, $green=-1, $blue=-1)
Definição pslib.class:536
$title
Definição base.php:3