Пример #1
0
<?php

$ps = ps_new();
if (!ps_open_file($ps, "-")) {
    print "Cannot open PostScript file\n";
    exit;
}
ps_set_info($ps, "Creator", "draw.php");
ps_set_info($ps, "Author", "Uwe Steinmann");
ps_set_info($ps, "Title", "Creating document in memory");
ps_begin_page($ps, 596, 842);
ps_end_page($ps);
ps_close($ps);
echo ps_get_buffer($ps);
ps_delete($ps);
Пример #2
0
    ps_lineto($psdoc, 150, 850);
    ps_arc($psdoc, 150, 750, 100, 90, 180);
    ps_lineto($psdoc, 50, 150);
    ps_arc($psdoc, 150, 150, 100, 180, 270);
    ps_stroke($psdoc);
}
$psdoc = ps_new();
if (!ps_open_file($psdoc, "fontcreate.ps")) {
    print "Cannot open PostScript file\n";
    exit;
}
ps_set_info($psdoc, "Creator", __FILE__);
ps_set_info($psdoc, "Author", "Uwe Steinmann");
ps_set_info($psdoc, "Title", "Boxed Text");
ps_set_info($psdoc, "Keywords", "Boxes, Text Rendering");
ps_set_info($psdoc, "BoundingBox", "0 0 596 842");
$myfont = ps_begin_font($psdoc, "test", 0.001, 0.0, 0.0, 0.001, 0.0, 0.0);
ps_begin_glyph($psdoc, "a", 800.0, 0.0, 0.0, 800.0, 800.0);
ps_rect($psdoc, 10, 10, 300, 300);
ps_stroke($psdoc);
ps_end_glyph($psdoc);
ps_begin_glyph($psdoc, "b", 800.0, 0.0, 0.0, 800.0, 800.0);
ps_rect($psdoc, 10, 10, 300, 300);
ps_fill($psdoc);
ps_end_glyph($psdoc);
ps_begin_glyph($psdoc, "zero", 900.0, 0.0, 0.0, 900.0, 900.0);
frame($psdoc);
ps_end_glyph($psdoc);
ps_begin_glyph($psdoc, "one", 900.0, 0.0, 0.0, 900.0, 900.0);
frame($psdoc);
ps_circle($psdoc, 450, 450, 80);
Пример #3
0
<?php

define("LEFT_BORDER", 50);
function footer($ps, $text)
{
    $psfont = ps_findfont($ps, "Helvetica", "", 0);
    ps_setfont($ps, $psfont, 8.0);
    $buffer = "This file has been created with pslib " . ps_get_parameter($ps, "dottedversion", 0.0);
    ps_show_xy($ps, $buffer, LEFT_BORDER, 25);
}
$ps = ps_new();
if (!ps_open_file($ps, "overprint.ps")) {
    print "Cannot open PostScript file\n";
    exit;
}
ps_set_info($ps, "Creator", "draw.php");
ps_set_info($ps, "Author", "Uwe Steinmann");
ps_set_info($ps, "Title", "Overprint");
ps_begin_page($ps, 596, 842);
footer($ps, "");
ps_setcolor($ps, "fill", "cmyk", 1.0, 0.0, 0.0, 0.0);
ps_rect($ps, 100, 100, 200, 200);
ps_fill($ps);
ps_setoverprintmode($ps, 1);
ps_rect($ps, 120, 120, 100, 100);
ps_fill($ps);
ps_end_page($ps);
ps_close($ps);
ps_delete($ps);
Пример #4
0
     ps_lineto($p, EXAMPLE_BOX_WIDTH, EXAMPLE_BOX_HEIGHT - EXAMPLE_BOX_TITLE_HEIGHT);
     ps_stroke($p);
 }
 function end_example_box($p)
 {
     ps_restore($p);
 }
 $ps = ps_new();
 if (!ps_open_file($ps, $newpsdoc)) {
     print "Cannot open PostScript file\n";
     exit;
 }
 ps_set_parameter($ps, "warning", "true");
 ps_set_info($ps, "Creator", "draw.php");
 ps_set_info($ps, "Author", "Uwe Steinmann");
 ps_set_info($ps, "Title", "Many examples");
 $pstemplate = ps_begin_template($ps, 30.0, 30.0);
 ps_moveto($ps, 0, 0);
 ps_lineto($ps, 30, 30);
 ps_moveto($ps, 0, 30);
 ps_lineto($ps, 30, 0);
 ps_stroke($ps);
 ps_end_template($ps);
 $pspattern1 = ps_begin_pattern($ps, 10.0, 10.0, 10.0, 10.0, 1);
 ps_setlinewidth($ps, 0.2);
 ps_setcolor($ps, "stroke", "rgb", 0.0, 0.0, 1.0, 0.0);
 ps_moveto($ps, 0, 0);
 ps_lineto($ps, 7, 7);
 ps_stroke($ps);
 ps_moveto($ps, 0, 7);
 ps_lineto($ps, 7, 0);
Пример #5
0
 /**
  * Create the PostScript canvas.
  *
  * Parameters available:
  *
  * 'page' Specify the page/paper format for the graph's page, available
  * formats are: A0, A1, A2, A3, A4, A5, A6, B5, letter, legal, ledger,
  * 11x17, cd_front, inlay, inlay_nosides
  *
  * 'align' Alignment of the graph on the page, available options are:
  * topleft, topcenter, topright, leftcenter, center, rightcenter,
  * leftbottom, centerbottom, rightbottom
  *
  * 'orientation' Specifies the paper orientation, default is 'portrait' and
  * 'landscape' is also supported.
  *
  * 'creator' The creator tag of the PostScript/graph
  *
  * 'author' The author tag of the PostScript/graph
  *
  * 'title' The title tag of the PostScript/graph
  *
  * 'width' The width of the graph on the page
  *
  * 'height' The height of the graph on the page
  *
  * 'left' The left offset of the graph on the page
  *
  * 'top' The top offset of the graph on the page
  *
  * 'filename' The PostScript file to open/add page to, using 'filename' requires
  * 'ps' An existing pslib PostScript document to add the page to
  *
  * 'add_page' (true/false) Used together with 'ps', to specify whether the
  * canvas should add a new graph page (true) or create the graph on the
  * current page (false), default is 'true'
  *
  * The 'page' and 'width' & 'height' can be mutually omitted, if 'page' is
  * omitted the page is created using dimensions of width x height, and if
  * width and height are omitted the page dimensions are used for the graph.
  *
  * If 'ps' is specified, 'filename', 'creator', 'author' and 'title' has no
  * effect.
  *
  * 'left' and 'top' are overridden by 'align'
  *
  * It is required either to specify 'width' & 'height' or 'page'.
  *
  * The PostScript format/pslib has some limitations on the capabilities,
  * which means some functionality available using other canvass (fx. alpha
  * blending and gradient fills) are not supported with PostScript
  * (see Canvas.txt in the docs/ folder for further details)
  *
  * @param array $param Parameter array
  */
 function Image_Canvas_PS($param)
 {
     if (isset($param['page'])) {
         switch (strtoupper($param['page'])) {
             case 'A0':
                 $this->_pageWidth = 2380;
                 $this->_pageHeight = 3368;
                 break;
             case 'A1':
                 $this->_pageWidth = 1684;
                 $this->_pageHeight = 2380;
                 break;
             case 'A2':
                 $this->_pageWidth = 1190;
                 $this->_pageHeight = 1684;
                 break;
             case 'A3':
                 $this->_pageWidth = 842;
                 $this->_pageHeight = 1190;
                 break;
             case 'A4':
                 $this->_pageWidth = 595;
                 $this->_pageHeight = 842;
                 break;
             case 'A5':
                 $this->_pageWidth = 421;
                 $this->_pageHeight = 595;
                 break;
             case 'A6':
                 $this->_pageWidth = 297;
                 $this->_pageHeight = 421;
                 break;
             case 'B5':
                 $this->_pageWidth = 501;
                 $this->_pageHeight = 709;
                 break;
             case 'LETTER':
                 $this->_pageWidth = 612;
                 $this->_pageHeight = 792;
                 break;
             case 'LEGAL':
                 $this->_pageWidth = 612;
                 $this->_pageHeight = 1008;
                 break;
             case 'LEDGER':
                 $this->_pageWidth = 1224;
                 $this->_pageHeight = 792;
                 break;
             case '11X17':
                 $this->_pageWidth = 792;
                 $this->_pageHeight = 1224;
                 break;
             case 'CD_FRONT':
                 $this->_pageWidth = 337;
                 $this->_pageHeight = 337;
                 break;
             case 'INLAY':
                 $this->_pageWidth = 425;
                 $this->_pageHeight = 332;
                 break;
             case 'INLAY_NOSIDES':
                 $this->_pageWidth = 390;
                 $this->_pageHeight = 332;
                 break;
         }
     }
     $this->setDefaultFont(array('name' => 'Helvetica', 'color' => 'black', 'size' => 9));
     if (isset($param['orientation']) && strtoupper($param['orientation']) == 'LANDSCAPE') {
         $w = $this->_pageWidth;
         $this->_pageWidth = $this->_pageHeight;
         $this->_pageHeight = $w;
     }
     parent::Image_Canvas($param);
     if (!$this->_pageWidth) {
         $this->_pageWidth = $this->_width;
     } elseif (!$this->_width) {
         $this->_width = $this->_pageWidth;
     }
     if (!$this->_pageHeight) {
         $this->_pageHeight = $this->_height;
     } elseif (!$this->_height) {
         $this->_height = $this->_pageHeight;
     }
     $this->_width = min($this->_width, $this->_pageWidth);
     $this->_height = min($this->_height, $this->_pageHeight);
     if (isset($param['align']) && ($this->_width != $this->_pageWidth || $this->_height != $this->_pageHeight)) {
         switch (strtoupper($param['align'])) {
             case 'TOPLEFT':
                 $this->_top = 0;
                 $this->_left = 0;
                 break;
             case 'TOPCENTER':
                 $this->_top = 0;
                 $this->_left = ($this->_pageWidth - $this->_width) / 2;
                 break;
             case 'TOPRIGHT':
                 $this->_top = 0;
                 $this->_left = $this->_pageWidth - $this->_width;
                 break;
             case 'LEFTCENTER':
                 $this->_top = ($this->_pageHeight - $this->_height) / 2;
                 $this->_left = 0;
                 break;
             case 'CENTER':
                 $this->_top = ($this->_pageHeight - $this->_height) / 2;
                 $this->_left = ($this->_pageWidth - $this->_width) / 2;
                 break;
             case 'RIGHTCENTER':
                 $this->_top = ($this->_pageHeight - $this->_height) / 2;
                 $this->_left = $this->_pageWidth - $this->_width;
                 break;
             case 'LEFTBOTTOM':
                 $this->_top = $this->_pageHeight - $this->_height;
                 $this->_left = 0;
                 break;
             case 'CENTERBOTTOM':
                 $this->_top = $this->_pageHeight - $this->_height;
                 $this->_left = ($this->_pageWidth - $this->_width) / 2;
                 break;
             case 'RIGHTBOTTOM':
                 $this->_top = $this->_pageHeight - $this->_height;
                 $this->_left = $this->_pageWidth - $this->_width;
                 break;
         }
     }
     $addPage = true;
     if (isset($param['ps']) && is_resource($param['ps'])) {
         $this->_ps =& $param['ps'];
         if (isset($param['add_page']) && $param['add_page'] === false) {
             $addPage = false;
         }
     } else {
         $this->_ps = ps_new();
         if (isset($param['filename'])) {
             ps_open_file($this->_ps, $param['filename']);
         } else {
             ps_open_file($this->_ps);
         }
         ps_set_parameter($this->_ps, 'warning', 'true');
         ps_set_info($this->_ps, 'Creator', isset($param['creator']) ? $param['creator'] : 'PEAR::Image_Canvas');
         ps_set_info($this->_ps, 'Author', isset($param['author']) ? $param['author'] : 'Jesper Veggerby');
         ps_set_info($this->_ps, 'Title', isset($param['title']) ? $param['title'] : 'Image_Canvas');
     }
     if ($addPage) {
         ps_begin_page($this->_ps, $this->_pageWidth, $this->_pageHeight);
     }
     $this->_reset();
     $this->_pslib = $this->_version();
 }
Пример #6
0
    ps_lineto($p, EXAMPLE_BOX_WIDTH, EXAMPLE_BOX_HEIGHT - EXAMPLE_BOX_TITLE_HEIGHT);
    ps_stroke($p);
}
function end_example_box($p)
{
    ps_restore($p);
}
$ps = ps_new();
if (!ps_open_file($ps, "D:/xampp/htdocs/xampp/external/ps/image.ps")) {
    print "Cannot open PostScript file\n";
    exit;
}
ps_set_parameter($ps, "warning", "true");
ps_set_info($ps, "Creator", "image.php");
ps_set_info($ps, "Author", "Uwe Steinmann");
ps_set_info($ps, "Title", "Image examples");
ps_begin_page($ps, 596, 842);
$psfont = ps_findfont($ps, "D:/xampp/htdocs/xampp/external/ps/Helvetica", "", 0);
ps_setfont($ps, $psfont, 12.0);
$x = 0;
$y = 625;
begin_example_box($ps, LEFT_BORDER + (EXAMPLE_BOX_WIDTH + 30) * $x++, $y, "Indexed image without alpha channel", $psfont);
$psimage = ps_open_image_file($ps, "png", "indexed.png", NULL, 0);
ps_place_image($ps, $psimage, 10, 30, 1.0);
$buffer = sprintf("%.0f x %.0f pixel", ps_get_value($ps, "imagewidth", $psimage), ps_get_value($ps, "imageheight", $psimage));
ps_setfont($ps, $psfont, 10.0);
ps_show_xy($ps, $buffer, EXAMPLE_BOX_WIDTH - 10 - ps_stringwidth($ps, $buffer, $psfont, 10), 10);
end_example_box($ps);
begin_example_box($ps, LEFT_BORDER + (EXAMPLE_BOX_WIDTH + 30) * $x++, $y, "RGB image without alpha channel", $psfont);
$psimage = ps_open_image_file($ps, "png", "rgb.png", NULL, 0);
ps_place_image($ps, $psimage, 10, 30, 1.0);
Пример #7
0
<?php

$ps = ps_new();
if (!ps_open_file($ps, "D:/xampp/htdocs/xampp/external/ps/text.ps")) {
    print "Cannot open PostScript file\n";
    exit;
}
ps_set_parameter($ps, "warning", "false");
ps_set_info($ps, "Creator", "text.php");
ps_set_info($ps, "Author", "Uwe Steinmann");
ps_set_info($ps, "Title", "Text output");
ps_set_info($ps, "BoundingBox", "0 0 596 842");
ps_set_info($ps, "Orientation", "Portrait");
if (!($font = ps_findfont($ps, "Dustismo", "builtin", 1))) {
    echo "Could not find font.\n";
    exit;
}
ps_begin_page($ps, 596, 842);
ps_setfont($ps, $font, 14.0);
ps_show_xy($ps, "Text starting at position (100, 700) with kerning", 100, 700);
ps_set_parameter($ps, "kerning", "false");
ps_show_xy($ps, "Text starting at position (100, 670) without kerning", 100, 670);
ps_set_parameter($ps, "kerning", "true");
ps_set_parameter($ps, "underline", "true");
ps_show_xy($ps, "Text starting at position (100, 640) with underlining", 100, 640);
ps_set_parameter($ps, "underline", "false");
ps_set_parameter($ps, "overline", "true");
ps_show_xy($ps, "Text starting at position (100, 610) with overlining", 100, 610);
ps_set_parameter($ps, "overline", "false");
ps_set_parameter($ps, "strikeout", "true");
ps_show_xy($ps, "Text starting at position (100, 580) striked out", 100, 580);
Пример #8
0
<?php

$ps = ps_new();
if (!ps_open_file($ps, "hyperlinks.ps")) {
    print "Cannot open PostScript file\n";
    exit;
}
ps_set_parameter($ps, "warning", "true");
ps_set_info($ps, "Creator", "hyperlinks.php");
ps_set_info($ps, "Author", "Uwe Steinmann");
ps_set_info($ps, "Title", "Creating Hyperlinks with pdfmarks");
$fontsize = 20.0;
ps_begin_page($ps, 596, 842);
$b1 = ps_add_bookmark($ps, "Content", 0, 0);
ps_add_bookmark($ps, "First Page", $b1, 0);
$psfont = ps_findfont($ps, "Helvetica", "", 0);
ps_setfont($ps, $psfont, $fontsize);
ps_set_value($ps, "leading", 14.0);
ps_show_xy($ps, "This is a web link", 100, 100);
$len = ps_stringwidth($ps, "This is a web link", $psfont, $fontsize);
ps_add_weblink($ps, 100, 100, 100 + $len, 130, "http://www.mmk-hagen.de");
ps_show_xy($ps, "This is a pdf link to an external document", 100, 150);
$len = ps_stringwidth($ps, "This is a pdf link to an external document", $psfont, $fontsize);
ps_add_pdflink($ps, 100, 150, 100 + $len, 180, "test.pdf", 1, "fitpage");
ps_show_xy($ps, "This is a launch link", 100, 200);
$len = ps_stringwidth($ps, "This is a launch link", $psfont, $fontsize);
ps_add_launchlink($ps, 100, 200, 100 + $len, 230, "/usr/bin/gedit");
ps_show_xy($ps, "This is a pdf link within the document", 100, 250);
$len = ps_stringwidth($ps, "This is a pdf link within the document", $psfont, $fontsize);
ps_add_locallink($ps, 100, 250, 100 + $len, 280, 2, "fitpage");
ps_end_page($ps);
Пример #9
0
<?php

$radius = 200;
$margin = 20;
$pagecount = 300;
$ps = ps_new();
if (!ps_open_file($ps, "psclock.ps")) {
    print "Cannot open PostScript file\n";
    exit;
}
ps_set_parameter($ps, "warning", "true");
ps_set_info($ps, "Creator", "psclock.php");
ps_set_info($ps, "Author", "Uwe Steinmann");
ps_set_info($ps, "Title", "Analog Clock");
while ($pagecount-- > 0) {
    ps_begin_page($ps, 2 * ($radius + $margin), 2 * ($radius + $margin));
    ps_set_parameter($ps, "transition", "wipe");
    ps_set_value($ps, "duration", 0.5);
    ps_translate($ps, $radius + $margin, $radius + $margin);
    ps_save($ps);
    ps_setcolor($ps, "both", "rgb", 0.0, 0.0, 1.0, 0.0);
    /* minute strokes */
    ps_setlinewidth($ps, 2.0);
    for ($alpha = 0; $alpha < 360; $alpha += 6) {
        ps_rotate($ps, 6.0);
        ps_moveto($ps, $radius, 0.0);
        ps_lineto($ps, $radius - $margin / 3, 0.0);
        ps_stroke($ps);
    }
    ps_restore($ps);
    ps_save($ps);