PHP. Postscript

Summary
Sets the percentage of line height that belongs to the font.
This table defines the filenames that are associated with the font descriptions.
Begin new page
End current page
Show some centeredtext at specific coordinates
Show some centered text at specific coordinates with font settings
Close the postscript file
Determine “x” value by the absolute position from the upper left hand corner horizontally.
Determine “y” value by the absolute position from the upper left hand corner vertically.
Draw a line
Move to coordinates
Move to coordinates and change the font
Insert a PS file/image (remember to delete the information in the top of the file (source))
Draw a rectangle
Draw and shade a rectangle
Set rotation, use 0 or 360 to end rotation
Set the font to show
Show some text at the current coordinates (use ‘moveto’ to set coordinates)
Evaluate the text and show it at the current coordinates
Show some text at specific coordinates
Show some text at specific coordinates with font settings
Creates a text virtual bounding box, to determine whether text will fit in a certain area
Returns the last bottom Y coordinate of a virtual text bounding box.
Convert X coordinate to horizontal measurement
Convert Y coordinate to vertical measurement
Internal function to determine the split of a string while still fitting within a virtual boundary
Internal method to determine maximum height of a string in the designated font and size.
Internal method to determine length of a string in the designated font and size.

Variables

Postscript->spacing_multiplier

Sets the percentage of line height that belongs to the font.  (example: if this is set to 0.8, 80% of the space is taken up by the font, and the remaining 20% is space)

Postscript->font_table

This table defines the filenames that are associated with the font descriptions.  They are used so that PHP can correctly load the fonts to determine what text line widths are.  These come in the Debian ‘gsfonts’ package.

Functions

Postscript constructor

Parameters

$fnameFile name for output
$_options(optional) Associative array of optional parameters.
  • title - Title of generated page.  Defaults to ‘Generated with PSLib’.
  • orientation - Orientation of generated page.  Defaults to ‘Portrait’.
  • paper - Paper size.  Defaults to ‘letter’.
  • author - Author name.  Defaults to ‘phpwebtools/PSLib’.

begin_page

function begin_page($page)

Begin new page

Parameters

$pagePage number

end_page

function end_page()

End current page

center_xy

function center_xy($text,
$xcoord,
$ycoord)

Show some centeredtext at specific coordinates

Parameters

$textText to display
$xcoordX coordinate
$ycoordY coordinate

center_xy_font

function center_xy_font($text,
$xcoord,
$ycoord,
$font_name,
$font_size)

Show some centered text at specific coordinates with font settings

Parameters

$textText to display
$xcoordX coordinate
$ycoordY coordinate
$font_nameName of the font to be used
$font_sizeSize of the font to be used

close

function close()

Close the postscript file

inches_to_x

function inches_to_x($i)

Determine “x” value by the absolute position from the upper left hand corner horizontally.  Returns a point value.

Parameters

$iHorizontal position from left side of the paper in inches.

Returns

X point value

inches_to_y

function inches_to_y($i)

Determine “y” value by the absolute position from the upper left hand corner vertically.  Returns a point value.

Parameters

$iVertical position from top of the paper in inches.

Returns

Y point value

line

function line($xcoord_from = 0,
$ycoord_from = 0,
$xcoord_to = 0,
$ycoord_to = 0,
$linewidth = 0)

Draw a line

Parameters

$xcoord_fromOrigin X position of the line
$ycoord_fromOrigin Y position of the line
$xcoord_toDestination X position of the line
$ycoord_toDestination Y position of the line
$linewidthWidth of the line in points

moveto

function moveto($xcoord,
$ycoord)

Move to coordinates

Parameters

$xcoordDestination X coordinate
$ycoordDestination Y coordinate

moveto_font

function moveto_font($xcoord,
$ycoord,
$font_name,
$font_size)

Move to coordinates and change the font

Parameters

$xcoordDestination X coordinate
$ycoordDestination Y coordinate
$font_nameName of the font
$font_sizePoint size of the font

open_ps

function open_ps($ps_file = "")

Insert a PS file/image (remember to delete the information in the top of the file (source))

Parameters

$ps_fileName of the file to join into the current rendering

rect

function rect($xcoord_from,
$ycoord_from,
$xcoord_to,
$ycoord_to,
$linewidth)

Draw a rectangle

Parameters

$xcoord_fromOrigin X position of the upper left corner
$ycoord_fromOrigin Y position of the upper left corner
$xcoord_toDestination X position of the lower right corner
$ycoord_toDestination Y position of the lower right corner
$linewidthWidth of the lines in points

rect_fill

function rect_fill($xcoord_from,
$ycoord_from,
$xcoord_to,
$ycoord_to,
$linewidth,
$darkness)

Draw and shade a rectangle

Parameters

$xcoord_fromOrigin X position of the upper left corner
$ycoord_fromOrigin Y position of the upper left corner
$xcoord_toDestination X position of the lower right corner
$ycoord_toDestination Y position of the lower right corner
$linewidthWidth of the lines in points
$darknessDarkness, in 0 ..  1 value.

rotate

function rotate($degrees)

Set rotation, use 0 or 360 to end rotation

Parameters

$degreesDegrees to rotate the current drawing aspect

set_font

function set_font($font_name,
$font_size)

Set the font to show

Parameters

$font_nameName of the font
$font_sizePoint size of the font

show

function show($text)

Show some text at the current coordinates (use ‘moveto’ to set coordinates)

See Also

moveto

show_eval

function show_eval($_text)

Evaluate the text and show it at the current coordinates

Parameters

$textText with php variable expressions

show_xy

function show_xy($text,
$xcoord,
$ycoord)

Show some text at specific coordinates

Parameters

$textText to display
$xcoordX coordinate of origin point
$ycoordY coordinate of origin point

show_xy_font

function show_xy_font($text,
$xcoord,
$ycoord,
$font_name,
$font_size)

Show some text at specific coordinates with font settings

Parameters

$textText to display
$xcoordX coordinate of origin point
$ycoordY coordinate of origin point
$font_nameName of the font
$font_sizeSize of the font

text_vbbox

function text_vbbox ($string,  
$font,  
$size,  
$tx,  
$ty,  
$bx,  
$by = -1)

Creates a text virtual bounding box, to determine whether text will fit in a certain area

Parameters

$stringText string to be displayed.  Line breaks with line break characters are honored, otherwise text is wrapped at the edge of the box.
$fontName of the font to be used
$sizeSize of the font to be used
$txTop left X coordinate for the bounding box
$tyTop left Y coordinate for the bounding box
$bxBottom right X coordinate for the bounding box
$by(optional) Bottom right Y coordinate for the bounding box.  If this is not set, this is not considered to be a fixed size bounding box, and the Y parameter will expand until either the page ends or the text is exhausted.

text_vbbox_bottom

function text_vbbox_bottom()

Returns the last bottom Y coordinate of a virtual text bounding box.

Returns

Y coordinate, or false if there was no Y coordinate computed.

See Also

text_vbbox

x_to_inches

function x_to_inches($p)

Convert X coordinate to horizontal measurement

Parameters

$pPosition as X coordinate in points

Returns

Horizontal inches measurement from the top left of the page.

y_to_inches

function y_to_inches($p)

Convert Y coordinate to vertical measurement

Parameters

$pPosition as Y coordinate in points

Returns

Vertical inches measurement from the top left of the page.

_get_string_split

function _get_string_split ($font,
$size,
$_string,
$width)

Internal function to determine the split of a string while still fitting within a virtual boundary

Parameters

$fontFont to use
$sizeSize of the font to use
$_stringText string to split
$widthWidth of virtual bounding box in points

Returns

Position to split the string at.

_get_text_height

function _get_text_height ($font,
$size,
$string)

Internal method to determine maximum height of a string in the designated font and size.

Parameters

$fontFont to be used
$sizeSize of the font to be used
$stringText string

Returns

Height in points.

_get_text_length

function _get_text_length ($font,
$size,
$string)

Internal method to determine length of a string in the designated font and size.

Parameters

$fontFont to be used
$sizeSize of the font to be used
$stringText string

Returns

Length in points

function begin_page($page)
Begin new page
function end_page()
End current page
function center_xy($text,
$xcoord,
$ycoord)
Show some centeredtext at specific coordinates
function center_xy_font($text,
$xcoord,
$ycoord,
$font_name,
$font_size)
Show some centered text at specific coordinates with font settings
function close()
Close the postscript file
function inches_to_x($i)
Determine “x” value by the absolute position from the upper left hand corner horizontally.
function inches_to_y($i)
Determine “y” value by the absolute position from the upper left hand corner vertically.
function line($xcoord_from = 0,
$ycoord_from = 0,
$xcoord_to = 0,
$ycoord_to = 0,
$linewidth = 0)
Draw a line
function moveto($xcoord,
$ycoord)
Move to coordinates
function moveto_font($xcoord,
$ycoord,
$font_name,
$font_size)
Move to coordinates and change the font
function open_ps($ps_file = "")
Insert a PS file/image (remember to delete the information in the top of the file (source))
function rect($xcoord_from,
$ycoord_from,
$xcoord_to,
$ycoord_to,
$linewidth)
Draw a rectangle
function rect_fill($xcoord_from,
$ycoord_from,
$xcoord_to,
$ycoord_to,
$linewidth,
$darkness)
Draw and shade a rectangle
function rotate($degrees)
Set rotation, use 0 or 360 to end rotation
function set_font($font_name,
$font_size)
Set the font to show
function show($text)
Show some text at the current coordinates (use ‘moveto’ to set coordinates)
function show_eval($_text)
Evaluate the text and show it at the current coordinates
function show_xy($text,
$xcoord,
$ycoord)
Show some text at specific coordinates
function show_xy_font($text,
$xcoord,
$ycoord,
$font_name,
$font_size)
Show some text at specific coordinates with font settings
function text_vbbox ($string,  
$font,  
$size,  
$tx,  
$ty,  
$bx,  
$by = -1)
Creates a text virtual bounding box, to determine whether text will fit in a certain area
function text_vbbox_bottom()
Returns the last bottom Y coordinate of a virtual text bounding box.
function x_to_inches($p)
Convert X coordinate to horizontal measurement
function y_to_inches($p)
Convert Y coordinate to vertical measurement
function _get_string_split ($font,
$size,
$_string,
$width)
Internal function to determine the split of a string while still fitting within a virtual boundary
function _get_text_height ($font,
$size,
$string)
Internal method to determine maximum height of a string in the designated font and size.
function _get_text_length ($font,
$size,
$string)
Internal method to determine length of a string in the designated font and size.