| Current Path : /var/www/html/mmishra/mm/ada/examples/ |
| Current File : /var/www/html/mmishra/mm/ada/examples/Graphics.php |
<?php
//***************************************************************************
//
// SYBREX SYSTEMS INCORPORATED
// Copyright (C) 2005 Sybrex Systems Incorporated
// All rights reserved.
//
// NOTICE: Sybrex permits you to use, modify, and distribute this file
// in accordance with the terms of the Sybrex license agreement
// accompanying it. If you have received this file from a source other
// than Sybrex, then your use, modification, or distribution of it
// requires the prior written permission of Sybrex.
//
//----------------------------------------------------------------------
// Graphics.php
//***************************************************************************
define( 'PAGEW', 595 ); // Page width constant definition
define( 'PAGEH', 842 ); // Page height constant definition
define( 'FIGCOUNT', 200 ); # Count of figures per one example
$LineDash = array( "[2 2] 0", "[4 4] 0", "[8 8] 0", "[8 8] 4", "[8 8] 8", "[12 4] 0", "[16 3 4 3] 0", "[13 3 2 3 2 3] 0", "[ ] 0" );
// Determination of graphics objects coordinates, normalized to 100
function cx( $x ) {
return PAGEW * $x / 100 ;
};
function cy( $y ) {
return PAGEH * $y / 100 ;
};
# Random number from 0 to 1
function rnd( ) {
return rand() / getrandmax() ;
};
# Check Windows operating system
function is_windows() {
return ( substr_count( php_uname( 's' ), 'Windows' ) ? true : false );
};
if (!extension_loaded('VersyPDF')) {
if ( is_windows() ) {
dl('php_versypdf.dll');
} else {
dl('versypdf.so');
}
}
// Initialize PDF Library with empty license name and key ( demo version )
$Lib = pdf_library_init( "", "" );
$a = 0;
$b = 0;
$c = 0;
$d = 0;
$i = 0;
// Create new empty PDF Document
$Doc = pdfdoc_create( $Lib );
// Set AutoLaunch property of Docyment if Windows family system is loaded
if ( is_windows() ) pdfdoc_set_auto_launch( $Doc, true );
//************************************************************************
//* Text Fonts Example *
//************************************************************************
// Create new page in PDF document
$PageId = pdfdoc_append_page( $Doc, PAGEW, PAGEH );
// Create Page Content $Box with default resolution ( 72 dpi )
$Box = pdfpage_create_paint_box( $Doc, $PageId, 72 );
// Save the current graphics state on the graphics state stack.
pbx_state_store( $Box );
// Set active font as Helvetica, size is 4% of page height
$FontId = pdffont_standard_append( $Doc, STDF_HELVETICA, ET_STANDARD_ENCODING ) ;
pbx_set_active_font( $Box, $FontId, cy( 4 ), false, false );
// Font color is black
pbx_set_fill_color ( $Box, ul_color_from_rgb ( 0, 0, 0 ) );
// Draw title of current page
pbx_text_out( $Box, ( cx( 50 ) - pbx_get_text_width( $Box, "Lines" ) / 2 ), cy( 4 ), 0, "Lines" );
// Set active font as Helvetica, size is 1.2% of page height
$FontId = pdffont_standard_append( $Doc, STDF_HELVETICA, ET_STANDARD_ENCODING ) ;
pbx_set_active_font( $Box, $FontId, cy( 1.2 ), false, false );
// Draw title o current example near right border of page
pbx_text_out ( $Box, cx( 80 ), cy( 9 ), 0, "Dash Types" );
// Set stroke color as black
pbx_set_stroke_color ( $Box, ul_color_from_rgb ( 0, 0, 0 ) );
// Draw 9 types of dashed lines from dash type array - LineDashTypes
foreach ( $LineDash as $i ) {
// Set dash type from string's array
pbx_set_dash( $Box, $i );
// Move current position on $Box in start of line
pbx_moveto( $Box, cx( 10 ), cy( 10 + 3 * $a ) );
// Draw line from left side to right
pbx_lineto( $Box, cx( 60 ), cy( 10 + 3 * $a ) );
// ... and colorize it
pbx_stroke( $Box );
// Draw dash type as text near example line
pbx_text_out( $Box, cx( 62 ), cy( 9.5 + 3 * $a ), 0, $i );
$a++;
}
// Draw title of current example near right border of page,
// and in 39% of page height from top
pbx_text_out( $Box, cx( 80 ), cy( 39 ), 0, "Width Values" );
foreach ( range( 1, 19 ) as $i ) {
// Increase line width from 0 to 4.5 by 0.25 points
pbx_set_line_width( $Box, 0.25 * $i );
// Set line color as dark blue
pbx_set_stroke_color( $Box, ul_color_from_rgb( 0.0, 0.0, 0.5 ) );
// Move current position on $Box in start of line
pbx_moveto( $Box, cx( 10 ), cy( 40 + 3 * $i ) );
// Draw line from left side to right
pbx_lineto( $Box, cx( 60 ), cy( 40 + 3 * $i ) );
// ... and colorize it
pbx_stroke( $Box );
// Create line width value
$Width = 0.25 * $i;
# ... and draw text label near example line
pbx_text_out( $Box, cx( 62 ), cy( 39.5 + 3 * $i ), 0, "Line width = $Width" );
}
// Restore the graphics state by removing the most recently saved state
// from the stack and making it the current state.
pbx_state_restore ( $Box );
// Save non-packed Page Content and Free $Box
pbx_close( $Box, false );
//******************************************************************************
// Draw graphic primitives as rectangles, rotated rectangles, ellipses, circles
//******************************************************************************
// Create new page in PDF document
$PageId = pdfdoc_append_page( $Doc, PAGEW, PAGEH );
// Create Page Content $Box with default resolution ( 72 dpi )
$Box = pdfpage_create_paint_box( $Doc, $PageId, 72 );
// Save the current graphics state on the graphics state stack.
pbx_state_store( $Box );
// Set active font as Helvetica, size is 3% of page height
$FontId = pdffont_standard_append( $Doc, STDF_HELVETICA, ET_STANDARD_ENCODING );
pbx_set_active_font( $Box, $FontId , cy(3), false, false );
// Text Color set a black
pbx_set_fill_color( $Box, ul_color_from_rgb( 0, 0, 0 ) );
// Draw title 'Rectangles'
pbx_text_out( $Box, cx(28) - pbx_get_text_width( $Box, "Rectangles" )/2, cy(4), 0, "Rectangles" );
// End the path object without filling or stroking it.
pbx_new_path( $Box );
// Set big rectangle for inserting other rectangles
pbx_rectangle( $Box, cx(10), cy(10), cx(45), cy(45) );
// Check path for clipping
pbx_clip( $Box );
// Start new path for drawing
pbx_new_path( $Box );
// Set line width as 0.5 points
pbx_set_line_width( $Box, 0.5 );
// Draw rectangles in clipping path area
foreach( range( 1, FIGCOUNT ) as $i ) {
// Set randomize stroke color
pbx_set_stroke_color( $Box, ul_color_from_rgb( rnd(), rnd(), rnd() ) );
// Set randomize fill color
pbx_set_fill_color( $Box, ul_color_from_rgb( rnd(), rnd(), rnd() ) );
// Random X-coordinate of left border
$a = cx( 5 ) + cx( 35 * rnd() );
// Random Y-coordinate of top border
$b = cy( 5 ) + cy( 35 * rnd() );
// Random width of rectangle
$c = cx( 10 * rnd() );
// Random height of rectangle
$d = cy( 10 * rnd() );
// Draw this rectangle
pbx_rectangle( $Box, $a, $b, $a + $c, $b + $d );
// ... and colorize it
pbx_fill_and_stroke( $Box );
}
// Restore the graphics state by removing the most recently saved state
// from the stack and making it the current state.
pbx_state_restore( $Box );
// Start new path for drawing without old clipping path
pbx_new_path( $Box );
// Set line width as 3 points
pbx_set_line_width( $Box, 3 );
// Set line color of rectangle as black
pbx_set_stroke_color( $Box, ul_color_from_rgb( 0, 0, 0 ) );
// Draw dribble rectangle
pbx_rectangle( $Box, cx(10), cy(10), cx(45), cy(45) );
// ... and colorize it
pbx_stroke( $Box );
// Save the current graphics state on the graphics state stack.
pbx_state_store( $Box );
// Set the text font as Helvetica, size is 3% of page height
$FontId = pdffont_standard_append( $Doc, STDF_HELVETICA, ET_STANDARD_ENCODING );
pbx_set_active_font( $Box, $FontId , cy(3), false, false );
// Text Color set a black
pbx_set_fill_color( $Box, ul_color_from_rgb( 0, 0, 0 ) );
// Draw title 'Rotated rectangles'
pbx_text_out( $Box, cx(74) - pbx_get_text_width( $Box, "Rotated rectangles" )/2, cy(4), 0, "Rotated rectangles" );
// End the path object without filling or stroking it.
pbx_new_path( $Box );
// Set big rectangle for inserting other rectangles
pbx_rectangle( $Box, cx(55), cy(10), cx(90), cy(45) );
// Check path for clipping
pbx_clip( $Box );
// Start new path for drawing
pbx_new_path( $Box );
// Set line width as 0.5 points
pbx_set_line_width( $Box, 0.5 );
// Draw rotated rectangles in clipping path area
foreach ( range( 1, FIGCOUNT ) as $i ) {
// Set randomize stroke color
pbx_set_stroke_color( $Box, ul_color_from_rgb( rnd(), rnd(), rnd() ) );
// Set randomize fill color
pbx_set_fill_color( $Box, ul_color_from_rgb( rnd(), rnd(), rnd() ) );
// Random X-coordinate of left border
$a = cx( 50 ) + cx( 35 * rnd() );
// Random Y-coordinate of top border
$b = cy( 90 ) - cy( 35 * rnd() );
// Random width of rectangle
$c = cx( 10 * rnd() );
// Random height of rectangle
$d = cy( 10 * rnd() );
// Draw this rectangle which rotated on randomize angle form -45 to 45 degrees
pbx_rect_rotated( $Box, $a, $b, $c, $d, 90 * rnd() - 45 );
// ... and colorize it
pbx_fill_and_stroke( $Box );
}
// Restore the graphics state by removing the most recently saved state
// from the stack and making it the current state.
pbx_state_restore( $Box );
// Start new path for drawing without old clipping path
pbx_new_path( $Box );
// Set line width as 3 points
pbx_set_line_width( $Box, 3 );
// Set line color of rectangle as black
pbx_set_stroke_color( $Box, ul_color_from_rgb( 0.0, 0.0, 0.0 ) );
// Draw dribble rectangle
pbx_rectangle( $Box, cx(55), cy(10), cx(90), cy(45) );
// ... and colorize it
pbx_stroke( $Box );
// Save the current graphics state on the graphics state stack.
pbx_state_store( $Box );
// Set the text font as Helvetica, size is 3% of page height
$FontId = pdffont_standard_append( $Doc, STDF_HELVETICA, ET_STANDARD_ENCODING );
pbx_set_active_font( $Box, $FontId , cy(3), false, false );
// Text Color set a black
pbx_set_fill_color( $Box, ul_color_from_rgb( 0, 0, 0 ) );
// Draw title 'Rotated rectangles'
pbx_text_out( $Box, cx(28) - pbx_get_text_width( $Box, "Ellipses" )/2, cy(49), 0, "Ellipses" );
// End the path object without filling or stroking it.
pbx_new_path( $Box );
// Draw big ellipse for inserting other ellipses
pbx_ellipse( $Box, cx(10), cy(55), cx(45), cy(90) );
// Check path for clipping
pbx_clip( $Box );
// Start new path for drawing
pbx_new_path( $Box );
// Set line width as 0.5 points
pbx_set_line_width( $Box, 0.5 );
// Draw ellipses in clipping path area
foreach ( range( 1, FIGCOUNT ) as $i ) {
// Set randomize stroke color
pbx_set_stroke_color( $Box, ul_color_from_rgb( rnd(), rnd(), rnd() ) );
// Set randomize fill color
pbx_set_fill_color( $Box, ul_color_from_rgb( rnd(), rnd(), rnd() ) );
// Random X-coordinate of left border
$a = cx( 5 ) + cx( 35 * rnd() );
// Random Y-coordinate of top border
$b = cy( 50 ) + cy( 35 * rnd() );
// Random width of ellipse
$c = cx( 10 * rnd() );
// Random height of ellipse
$d = cy( 10 * rnd() );
// Draw this ellipse
pbx_ellipse( $Box, $a, $b, $a + $c, $b + $d );
// ... and colorize it
pbx_fill_and_stroke( $Box );
}
// Restore the graphics state by removing the most recently saved state
// from the stack and making it the current state.
pbx_state_restore( $Box );
// Start new path for drawing without old slipping path
pbx_new_path( $Box );
// Set line width as 3 points
pbx_set_line_width( $Box, 3 );
// Set line color of rectangle as black
pbx_set_stroke_color( $Box, ul_color_from_rgb( 0.0, 0.0, 0.0 ) );
// Draw dribble ellipse
pbx_ellipse( $Box, cx(10), cy(55), cx(45), cy(90) );
// ... and colorize it
pbx_stroke( $Box );
// Save the current graphics state on the graphics state stack.
pbx_state_store( $Box );
// Set the text font as Helvetica, size is 3% of page height
$FontId = pdffont_standard_append( $Doc, STDF_HELVETICA, ET_STANDARD_ENCODING );
pbx_set_active_font( $Box, $FontId , cy(3), false, false );
// Text Color set a black
pbx_set_fill_color( $Box, ul_color_from_rgb( 0.0, 0.0, 0.0 ) );
// Draw title 'Circles'
pbx_text_out( $Box, cx(74) - pbx_get_text_width( $Box, "Circles" )/2, cy(49), 0, "Circles" );
// End the path object without filling or stroking it.
pbx_new_path( $Box );
// Draw big circle for inserting other circles
pbx_circle( $Box, cx(73), cy(73), cx(18) );
// Check path for clipping
pbx_clip( $Box );
// Start new path for drawing
pbx_new_path( $Box );
// Set line width as 0.5 points
pbx_set_line_width( $Box, 0.5 );
// Draw circles in clipping path area
foreach ( range ( 0, FIGCOUNT ) as $i ) {
// Set randomize stroke color
pbx_set_stroke_color( $Box, ul_color_from_rgb( rnd(), rnd(), rnd() ) );
// Set randomize fill color
pbx_set_fill_color( $Box, ul_color_from_rgb( rnd(), rnd(), rnd() ) );
// Random X-coordinate of circle center
$a = cx( 55 ) + cx( 35 * rnd() );
// Random Y-coordinate of circle center
$b = cy( 55 ) + cy( 35 * rnd() );
// Random radius of circle
$c = cx( 5 * rnd() );
// Draw this circle
pbx_circle( $Box, $a, $b, $c );
// ... and colorize it
pbx_fill_and_stroke( $Box );
}
// Restore the graphics state by removing the most recently saved state
// from the stack and making it the current state.
pbx_state_restore( $Box );
// Start new path for drawing without old slipping path
pbx_new_path( $Box );
// Set line width as 3 points
pbx_set_line_width( $Box, 3 );
// Set line color of rectangle as black
pbx_set_stroke_color( $Box, ul_color_from_rgb( 0.0, 0.0, 0.0 ) );
// Draw dribble circle
pbx_circle ( $Box, cx(73), cy(73), cx(18) );
// ... and colorize it
pbx_stroke( $Box );
// Save non-packed Page Content and Free $Box
pbx_close( $Box, false );
//**********************************************************************
// Draw round rectangles, pies and Bezier curves. Example.
//**********************************************************************
// Create new page in PDF document
$PageId = pdfdoc_append_page( $Doc, PAGEW, PAGEH );
// Create Page Content $Box with default resolution ( 72 dpi )
$Box = pdfpage_create_paint_box( $Doc, $PageId, 72 );
// Save the current graphics state on the graphics state stack.
pbx_state_store( $Box );
// Set the text font as Helvetica, size is 3% of page height
$FontId = pdffont_standard_append( $Doc, STDF_HELVETICA, ET_STANDARD_ENCODING );
pbx_set_active_font( $Box, $FontId , cy(3), false, false );
// Text Color set a black
pbx_set_fill_color( $Box, ul_color_from_rgb( 0.0, 0.0, 0.0 ) );
// Draw title 'Round rectangles'
pbx_text_out( $Box, cx(28) - pbx_get_text_width( $Box, "Round rectangles" )/2, cy(4), 0, "Round rectangles" );
// Stroke color set a maroon
pbx_set_stroke_color( $Box, ul_color_from_rgb( 0.6, 0.0, 0.0 ) );
// Fill color set a white
pbx_set_fill_color( $Box, ul_color_from_rgb( 1.0, 1.0, 1.0 ) );
// Draw 8 round rectangles with variable parameters
foreach ( range( 0, 7 ) as $i ) {
// Change line width from 0 to 5 points
pbx_set_line_width( $Box, 2*$i/3 );
// Draw round rectangle
pbx_round_rect( $Box, cx( 10 + $i), cy(10 + $i), cx(45 - $i), cy(45 - $i), cx(3 * $i), cy(3 * $i) );
// ... and colorize it
pbx_fill_and_stroke( $Box );
}
// Stroke color set a white
pbx_set_stroke_color( $Box, ul_color_from_rgb( 1.0, 1.0, 1.0 ) );
// Fill color set a maroon
pbx_set_fill_color( $Box, ul_color_from_rgb( 0.6, 0.0, 0.0 ) );
// Draw 8 round rectangles with variable parameters
foreach ( range( 8, 15 ) as $i ) {
// Change line width from 5 to 0 points
pbx_set_line_width( $Box, 10 - 2*$i/3 );
// Draw round rectangle
pbx_round_rect( $Box, cx( 10 + $i), cy(10 + $i), cx(45 - $i), cy(45 - $i), cx( 45 - 3 * $i ), cy( 45 - 3 * $i ) );
// ... and colorize it
pbx_fill_and_stroke( $Box );
}
// Restore the graphics state by removing the most recently saved state
// from the stack and making it the current state.
pbx_state_restore( $Box );
// Save the current graphics state on the graphics state stack.
pbx_state_store( $Box );
// Set the text font as Helvetica, size is 3% of page height
$FontId = pdffont_standard_append( $Doc, STDF_HELVETICA, ET_STANDARD_ENCODING );
pbx_set_active_font( $Box, $FontId , cy(3), false, false );
// Text Color set a black
pbx_set_fill_color( $Box, ul_color_from_rgb( 0.0, 0.0, 0.0 ) );
// Draw title 'Pies'
pbx_text_out( $Box, cx(74) - pbx_get_text_width( $Box, "Pies" )/2, cy(4), 0, "Pies" );
// Stroke color set a maroon
pbx_set_stroke_color( $Box, ul_color_from_rgb( 0.6, 0.0, 0.0 ) );
// Fill color set a red
pbx_set_fill_color( $Box, ul_color_from_rgb( 1.0, 0.0, 0.0 ) );
// Set line width as 1 point
pbx_set_line_width( $Box, 1 );
// Set join style as Mode 0
pbx_set_line_join( $Box, 1 );
// Draw big pie
pbx_pie( $Box, cx(50), cy(15), cx(85), cy(40), cx(90), cy(15), cx(90), cy(40) );
// ... and colorize it
pbx_fill_and_stroke( $Box );
// Stroke color set a dark green
pbx_set_stroke_color( $Box, ul_color_from_rgb( 0.0, 0.6, 0.0 ) );
// Fill color set a green
pbx_set_fill_color( $Box, ul_color_from_rgb( 0.0, 1.0, 0.0 ) );
// Draw small pie
pbx_pie( $Box, cx(60), cy(15), cx(95), cy(40), cx(100), cy(40), cx(100), cy(15) );
// ... and colorize it
pbx_fill_and_stroke( $Box );
// Restore the graphics state by removing the most recently saved state
// from the stack and making it the current state.
pbx_state_restore( $Box );
// Save the current graphics state on the graphics state stack.
pbx_state_store( $Box );
// Set the text font as Helvetica, size is 3% of page height
$FontId = pdffont_standard_append( $Doc, STDF_HELVETICA, ET_STANDARD_ENCODING );
pbx_set_active_font( $Box, $FontId , cy(3), false, false );
// Text Color set a black
pbx_set_fill_color( $Box, ul_color_from_rgb( 0.0, 0.0, 0.0 ) );
// Draw title 'Cubic Bezier curves'
pbx_text_out( $Box, cx(50) - pbx_get_text_width( $Box, "Cubic Bezier curves" )/2, cy(49), 0, "Cubic Bezier curves" );
// Set line color as black
pbx_set_stroke_color( $Box, ul_color_from_rgb( 0.0, 0.0, 0.0 ) );
// Set line width as 1 point
pbx_set_line_width( $Box, 1 );
// Set dash line style as Solid ( default )
pbx_no_dash( $Box );
// Move current position on $Box in start of Bezier Curve
pbx_moveto( $Box, cx(65), cy(90) );
// Draw Bezier Curve with cubic interpolation by 2 points and 1 destination point
pbx_curveto( $Box, cx(50), cy(70), cx(90), cy(70), cx(75), cy(85) );
// ... and colorize it
pbx_stroke( $Box );
// Set line color as gray
pbx_set_stroke_color( $Box, ul_color_from_rgb( 0.5, 0.5, 0.5 ) );
// Set line width as 0.25 points
pbx_set_line_width( $Box, 0.25 );
// Set dash line style as dash-dotted mode
pbx_set_dash( $Box, "[3 3] 0" );
// Move current position on $Box in start of Bezier Curve
pbx_moveto( $Box, cx(65), cy(90) );
// Draw interpolation vector from start to first interpolation point
pbx_lineto( $Box, cx(50), cy(70) );
// ... and colorize it
pbx_stroke( $Box );
// Move current position on $Box in finish of Bezier Curve
pbx_moveto( $Box, cx(75), cy(85) );
// Draw interpolation vector from finish to second interpolation point
pbx_lineto( $Box, cx(90), cy(70) );
// ... and colorize it
pbx_stroke( $Box );
// Draw bold maroon point as circle in start of Bezier Curve
pbx_set_fill_color( $Box, ul_color_from_rgb( 0.6, 0.0, 0.0 ) );
pbx_circle( $Box, cx(65), cy(90), 3 );
pbx_fill( $Box );
// Draw bold dark blue point as circle in first interpolation point
pbx_set_fill_color( $Box, ul_color_from_rgb( 0.0, 0.0, 0.3 ) );
pbx_circle( $Box, cx(50), cy(70), 2 );
pbx_fill( $Box );
// Draw bold dark blue point as circle in second interpolation point
pbx_set_fill_color( $Box, ul_color_from_rgb( 0.0, 0.0, 0.3 ) );
pbx_circle( $Box, cx(90), cy(70), 2 );
pbx_fill( $Box );
// Draw bold dark green point as circle in finish of Bezier Curve
pbx_set_fill_color( $Box, ul_color_from_rgb( 0.0, 0.6, 0.0 ) );
pbx_circle( $Box, cx(75), cy(85), 2.5 );
pbx_fill( $Box );
// Save the current graphics state on the graphics state stack.
pbx_state_store( $Box );
// Set the text font as Helvetica, size is 1% of page height
$FontId = pdffont_standard_append( $Doc, STDF_HELVETICA, ET_STANDARD_ENCODING );
pbx_set_active_font( $Box, $FontId , cy(1), false, false );
// Text Color set a black
pbx_set_fill_color( $Box, ul_color_from_rgb( 0.0, 0.0, 0.0 ) );
// Draw caption of point in start of Bezier Curve as 'x0, y0 - current point'
pbx_text_out( $Box, cx(67) - pbx_get_text_width( $Box, "x0, y0 - current point" )/2, cy(91), 0, "x0, y0 - current point" );
// Draw caption of first interpolation point as 'x1, y1 - interpolation point'
pbx_text_out( $Box, cx(52) - pbx_get_text_width( $Box, "x1, y1 - interpolation point" )/2, cy(71), 0, "x1, y1 - interpolation point" );
// Draw caption of second interpolation point as 'x2, y2 - interpolation point'
pbx_text_out( $Box, cx(92) - pbx_get_text_width( $Box, "x2, y2 - interpolation point" )/2, cy(71), 0, "x2, y2 - interpolation point" );
// Draw caption of point in finish of Bezier Curve as 'x3, y3 - destination point'
pbx_text_out( $Box, cx(77) - pbx_get_text_width( $Box, "x3, y3 - destination point" )/2, cy(86), 0, "x3, y3 - destination point" );
// Restore the graphics state by removing the most recently saved state
// from the stack and making it the current state.
pbx_state_restore( $Box );
//One more example of Cubic Bezier curves
pbx_set_stroke_color( $Box, ul_color_from_rgb( 0.0, 0.0, 0.0 ) );
pbx_set_line_width( $Box, 1 );
pbx_no_dash( $Box );
pbx_moveto( $Box, cx(10), cy(60) );
pbx_curveto( $Box, cx(20), cy(50), cx(40), cy(75), cx(45), cy(60) );
pbx_stroke( $Box );
pbx_set_stroke_color( $Box, ul_color_from_rgb( 0.5, 0.5, 0.5 ) );
pbx_set_line_width( $Box, 0.25 );
pbx_set_dash( $Box, "[3 3] 0" );
pbx_moveto( $Box, cx(10), cy(60) );
pbx_lineto( $Box, cx(20), cy(50) );
pbx_stroke( $Box );
pbx_moveto( $Box, cx(45), cy(60) );
pbx_lineto( $Box, cx(40), cy(75) );
pbx_stroke( $Box );
// One more example of Cubic Bezier curves
pbx_set_stroke_color( $Box, ul_color_from_rgb( 0.0, 0.0, 0.0 ) );
pbx_set_line_width( $Box, 1 );
pbx_no_dash( $Box );
pbx_moveto( $Box, cx(10), cy(90) );
pbx_curveto( $Box, cx(35), cy(88), cx(30), cy(75), cx(45), cy(90) );
pbx_stroke( $Box );
pbx_set_stroke_color( $Box, ul_color_from_rgb( 0.5, 0.5, 0.5 ) );
pbx_set_line_width( $Box, 0.25 );
pbx_set_dash( $Box, "[3 3] 0" );
pbx_moveto( $Box, cx(10), cy(90) );
pbx_lineto( $Box, cx(35), cy(88) );
pbx_stroke( $Box );
pbx_moveto( $Box, cx(45), cy(90) );
pbx_lineto( $Box, cx(30), cy(75) );
pbx_stroke( $Box );
// Close Paint Box
pbx_close( $Box, false );
//**********************************************************************
// Alpha blending example.
//**********************************************************************
// Create new page in PDF document
$PageId = pdfdoc_append_page( $Doc, PAGEW, PAGEH );
// Create Page Content $Box with default resolution ( 72 dpi )
$Box = pdfpage_create_paint_box( $Doc, $PageId, 72 );
// Save the current graphics state on the graphics state stack.
pbx_state_store( $Box );
// Set the text font as Helvetica, size is 3% of page height
$FontId = pdffont_standard_append( $Doc, STDF_HELVETICA, ET_STANDARD_ENCODING );
pbx_set_active_font( $Box, $FontId , cy(3), false, false );
// Text Color set a black
pbx_set_fill_color( $Box, ul_color_from_rgb( 0.0, 0.0, 0.0 ) );
// Draw title of current page
pbx_text_out( $Box, cx(50) - pbx_get_text_width( $Box, "Alpha blending" )/2, cy(4), 0, "Alpha blending" );
$i = pdfext_graphic_state_new( $Doc ); // Create Graphic state
pdfext_graphic_state_set_alpha_fill( $Doc, $i, 0.5 ); // Set fill alpha blending to 50 %
pdfext_graphic_state_set_alpha_stroke( $Doc, $i, 0.5 ); // Set lines alpha blending to 50 %
pdfext_graphic_state_set_alpha_is_shape( $Doc, $i, true ); // Set alpha blending to shapes
pbx_set_graphic_state( $Box, $i ); // Set graphic state as current
pbx_set_color( $Box, ul_color_from_rgb( 0.0, 0.0, 0.0 ) ); // Set line color as black
pbx_set_fill_color( $Box, ul_color_from_rgb( 1.0, 1.0, 0.0 ) ); // Set fill color as yellow
pbx_rectangle( $Box, cx(10), cy(10), cx(60), cy(60) ); // Draw rectangle
pbx_fill_and_stroke( $Box ); // Close and fill rectangle
pbx_set_color( $Box, ul_color_from_rgb( 0.0, 0.0, 0.0 ) ); // Set line color as black
pbx_set_fill_color( $Box, ul_color_from_rgb( 1.0, 0.0, 0.0 ) ); // Set fill color as red
pbx_rectangle( $Box, cx(20), cy(20), cx(70), cy(70) ); // Draw rectangle
pbx_fill_and_stroke( $Box ); // Close and fill rectangle
pbx_set_color( $Box, ul_color_from_rgb( 0.0, 0.0, 0.0 ) ); // Set line color as black
pbx_set_fill_color( $Box, ul_color_from_rgb( 0.0, 0.0, 1.0 ) ); // Set fill color as blue
pbx_rectangle( $Box, cx(30), cy(30), cx(80), cy(80) ); // Draw rectangle
pbx_fill_and_stroke( $Box ); // Close and fill rectangle
pbx_set_color( $Box, ul_color_from_rgb( 0.0, 0.0, 0.0 ) ); // Set line color as black
pbx_set_fill_color( $Box, ul_color_from_rgb( 0.0, 1.0, 0.0 ) ); // Set fill color as green
pbx_rectangle( $Box, cx(40), cy(40), cx(90), cy(90) ); // Draw rectangle
pbx_fill_and_stroke( $Box ); // Close and fill rectangle
pbx_close( $Box, false ); // Close $PaintBox
$SapiName = php_sapi_name();
if ( $SapiName != 'cli' ) {
$Mem = pdfdoc_save_to_buffer( $Doc, &$Size );
header( "Content-Disposition: inline; filename = Graphics.pdf", true );
header( "Content-Type: application/pdf", true );
header( "Content-Length: $Size", true );
echo( $Mem );
} else {
pdfdoc_save_to_file( $Doc, "out/pdf/Graphics.pdf" );
print "Success...\n";
}
pdfdoc_close( $Doc ); // Close PDF Document and free memory
// Free PDF Library
pdf_library_done( $Lib );
?>