Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
// $Id: textalignex1.php,v 1.1 2002/10/19 17:42:53 aditus Exp $
3
require_once "../jpgraph.php";
4
require_once "../jpgraph_canvas.php";
5
 
6
if( empty($_GET['a']) ) {
7
    $angle=40;
8
}
9
else {
10
    $angle=$_GET['a'];
11
}
12
 
13
$caption = "Demonstration of different anchor points for texts as specified with\nTextAlign(). The red cross marks the coordinate that was given to\nstroke each instance of the string.\n(The green box is the bounding rectangle for the text.)";
14
$txt="TextAlign()";
15
 
16
 
17
// Initial width and height since we need a "dummy" canvas to
18
// calculate the height of the text strings
19
$w=480;$h=50;
20
$xm=90;$ym=80;
21
 
22
$g = new CanvasGraph($w,$h);
23
 
24
$aImg = $g->img;
25
$aImg->SetFont(FF_ARIAL,FS_NORMAL,16);
26
$tw=$aImg->GetBBoxWidth($txt,$angle);
27
$th=$aImg->GetBBoxHeight($txt,$angle);
28
 
29
$aImg->SetFont(FF_ARIAL,FS_NORMAL,11);
30
$ch=$aImg->GetBBoxHeight($caption);
31
 
32
// Calculate needed height for the image
33
$h = 3*$th+2*$ym + $ch;
34
$g = new CanvasGraph($w,$h);
35
$aImg = $g->img;
36
 
37
$prof = array('left','top',
38
	      'center','top',
39
	      'right','top',
40
	      'left','center',
41
	      'center','center',
42
	      'right','center',
43
	      'left','bottom',
44
	      'center','bottom',
45
	      'right','bottom');
46
$n = count($prof)/2;
47
 
48
for( $i=0,$r=0,$c=0; $i < $n; ++$i ) {
49
    $x = $c*($tw+$xm)+$xm/2;
50
    $y = $r*($th+$ym)+$ym/2-10;
51
    $aImg->SetColor('blue');
52
    $aImg->SetTextAlign($prof[$i*2],$prof[$i*2+1]);
53
    $aImg->SetFont(FF_ARIAL,FS_NORMAL,16);
54
    $aImg->StrokeText($x,$y,$txt,$angle,"left",true);
55
 
56
    $aImg->SetColor('black');
57
    $aImg->SetFont(FF_FONT1,FS_BOLD);
58
    $aImg->SetTextAlign('center','top');
59
    $align = sprintf('("%s","%s")',$prof[$i*2],$prof[$i*2+1]);
60
    $aImg->StrokeText($c*($tw/2+$xm)+$xm/2+$tw/2,$r*($th/2+$ym)+$th+$ym/2-4,$align);
61
    $c++;
62
    if( $c==3 ) {
63
	$c=0;$r++;
64
    }
65
}
66
 
67
$aImg->SetTextAlign('center','bottom');
68
$aImg->SetFont(FF_ARIAL,FS_ITALIC,11);
69
$aImg->StrokeText($w/2,$h-10,$caption,0,'left');
70
 
71
$aImg->SetColor('navy');
72
$aImg->Rectangle(0,0,$w-1,$h-1);
73
 
74
$g->Stroke();
75
 
76
?>
77