function drawRectangle($left, $top, $right, $bottom, $style) { $this->_convertPosition($left, $top); $this->_convertPosition($right, $bottom); ps_setcolor($this->ps, 'stroke', $style['line'][0], $style['line'][1], $style['line'][2], $style['line'][3], $style['line'][4]); if (isset($style['fill'])) { ps_setcolor($this->ps, 'fill', $style['fill'][0], $style['fill'][1], $style['fill'][2], $style['fill'][3], $style['fill'][4]); } ps_setlinewidth($this->ps, $style['line-width']); ps_rect($this->ps, $left, $top, $right - $left, $bottom - $top); if (isset($style['fill'])) { ps_fill_stroke($this->ps); } else { ps_stroke($this->ps); } }
function begin_example_box($p, $llx, $lly, $title, $font) { ps_save($p); ps_translate($p, $llx, $lly); ps_setcolor($p, "fill", "gray", 0.5, 0.0, 0.0, 0.0); ps_rect($p, 0, EXAMPLE_BOX_HEIGHT - EXAMPLE_BOX_TITLE_HEIGHT, EXAMPLE_BOX_WIDTH, EXAMPLE_BOX_TITLE_HEIGHT); ps_fill($p); ps_setcolor($p, "stroke", "gray", 1.0, 0.0, 0.0, 0.0); ps_setfont($p, $font, 12.0); ps_show_xy($p, $title, 10, EXAMPLE_BOX_HEIGHT - EXAMPLE_BOX_TITLE_HEIGHT + 5); ps_setlinewidth($p, 1.0); ps_setcolor($p, "stroke", "gray", 0.0, 0.0, 0.0, 0.0); ps_rect($p, 0, 0, EXAMPLE_BOX_WIDTH, EXAMPLE_BOX_HEIGHT); ps_stroke($p); ps_moveto($p, 0, EXAMPLE_BOX_HEIGHT - EXAMPLE_BOX_TITLE_HEIGHT); ps_lineto($p, EXAMPLE_BOX_WIDTH, EXAMPLE_BOX_HEIGHT - EXAMPLE_BOX_TITLE_HEIGHT); ps_stroke($p); }
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); ps_fill($psdoc); ps_end_glyph($psdoc); ps_begin_glyph($psdoc, "two", 900.0, 0.0, 0.0, 900.0, 900.0); frame($psdoc); ps_circle($psdoc, 250, 250, 80); ps_fill($psdoc); ps_circle($psdoc, 650, 650, 80);
<?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);
/** * Draw a rectangle * * Parameter array: * 'x0': int X start point * 'y0': int Y start point * 'x1': int X end point * 'y1': int Y end point * 'fill': mixed [optional] The fill color * 'line': mixed [optional] The line color * @param array $params Parameter array */ function rectangle($params) { $x0 = $this->_getX($params['x0']); $y0 = $this->_getY($params['y0']); $x1 = $this->_getX($params['x1']); $y1 = $this->_getY($params['y1']); $fillColor = isset($params['fill']) ? $params['fill'] : false; $lineColor = isset($params['line']) ? $params['line'] : false; $line = $this->_setLineStyle($lineColor); $fill = $this->_setFillStyle($fillColor); if ($line || $fill) { ps_rect($this->_ps, min($x0, $x1), min($y0, $y1), abs($x1 - $x0), abs($y1 - $y0)); if ($line && $fill) { ps_fill_stroke($this->_ps); } elseif ($line) { ps_stroke($this->_ps); } elseif ($fill) { ps_fill($this->_ps); } } parent::rectangle($params); }