PHP: PDF_lineto - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

PDF_load_font PDF_initgraphics

Last updated: Fri, 26 Jan 2007

view this page in

# PDF_lineto

(PHP 3 >= 3.0.6, PHP 4, PECL)

PDF_lineto -- Draw a line

## Описание

bool PDF_lineto ( resource p, float x, float y )

Draws a line from the current point to another point. Возвращает `TRUE` в случае успешного завершения или `FALSE` в случае возникновения ошибки.

add a note User Contributed Notes
PDF_lineto
rod-php at thecomplex dot com
01-Oct-2002 10:32
`function pdf_arrow ($pdfobj, $x1, $y1, $x2, $y2, $dashed) {
// This function will draw, stroke, and fill a line
// from (x1,y1) to (x2,y2) with an arrowhead defined
// by $headangle (in degrees) and $arrowlength.
// If $dashed is nonzero, a dashed line is drawn.
// REQUIRES: find_angle
$headangle = 20;
$arrowlength = 20;
list ($angle, $slope) = find_angle($x1, $y1, $x2, $y2);
pdf_moveto($pdfobj, $x2, $y2);
// Find the two other points of the arrowhead
// using $headangle and $arrowlength.
$xarrow1 = $x2+cos(deg2rad(180+$angle+$headangle/2))*$arrowlength;
$yarrow1 = $y2+sin(deg2rad(180+$angle+$headangle/2))*$arrowlength;
$xarrow2 = $x2+cos(deg2rad(180+$angle-$headangle/2))*$arrowlength;
$yarrow2 = $y2+sin(deg2rad(180+$angle-$headangle/2))*$arrowlength;
// Draw two legs of the arrowhead, close and fill
pdf_lineto($pdfobj, $xarrow1, $yarrow1);
pdf_lineto($pdfobj, $xarrow2, $yarrow2);
pdf_closepath($pdfobj);
pdf_fill($pdfobj);
// Find the point bisecting the short side
// of the arrowhead. This is necessary so
// the end of the line doesn't poke out the
// beyond the arrow point.
$x2line = ($xarrow1+$xarrow2)/2;
$y2line = ($yarrow1+$yarrow2)/2;
// Now draw the "body" line of the arrow
if ($dashed != 0) {
pdf_setdash($pdfobj,5,5);
}
pdf_moveto($pdfobj, $x1, $y1);
pdf_lineto($pdfobj, $x2line, $y2line);
pdf_stroke($pdfobj);
}`
rod-php at thecomplex dot com
01-Oct-2002 10:20
`function find_angle ($x1, $y1, $x2, $y2) {
// This function takes two points (x1,y1) and (x2,y2)
// as inputs and finds the slope and angle of a line
// between those two points. It returns the angle
// and slope in an array. I can't figure out how to
// return a NULL value, so if the two input points
// are in a vertical line, the function returns
// $angle = 90 and $slope = 0. I know this is wrong.
if (($x2-$x1) != 0) {
$slope = ($y2-$y1)/($x2-$x1);
// Get rotation angle by finding the arctangent of the slope
$angle = rad2deg(atan($slope));
if ($x1 > $x2) {
$angle = 180+$angle;
} elseif ($y1 > $y2) {
$angle = 360+$angle;
}
} else {
// Vertical line has no slope, 90deg angle
$angle = 90;
# unset ($slope);
$slope = 0;
}
return array ($angle, $slope);
}`
rod-php at thecomplex dot com
01-Oct-2002 10:18
`function find_length ($x1, $y1, $x2, $y2) {
// Find distance between two points (x1,y1) and (x2,y2)
// Also useful to find length of a line.
return sqrt( pow($x2-$x1,2) + pow($y2-$y1,2) );
}`
add a note
PDF_load_font PDF_initgraphics

Last updated: Fri, 26 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 10:36:09 2007 PST