-
Notifications
You must be signed in to change notification settings - Fork 2
/
stgraph.svg.php
85 lines (65 loc) · 2.61 KB
/
stgraph.svg.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
// stgraph.svg - Syntax tree SVG image generator script
// Copyright (c) 2003-2004 Andre Eisenbach <[email protected]>
//
// stgraph.svg is part of phpSyntaxTree.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// $Id: stgraph.svg,v 1.3 2006/07/21 22:27:52 int2str Exp $
require_once( "src/class.elementlist.php" );
require_once( "src/class.stringparser.php" );
require_once( "src/class.svggraph.php" );
// Start session to retrieve graph data
session_start();
// We force the web server (via .htaccess usually)
// to treat this file as PHP. Now tell the user agent
// that we are a PNG image...
if ( !isset( $_GET['debug'] ) )
header("Content-type: image/svg+xml");
else
header("Content-type: text/plain");
// Read session data
if ( !isset( $_SESSION['data'] ) )
exit;
$data = $_SESSION['data'];
$color = isset( $_SESSION['color'] ) ? $_SESSION['color'] : 0;
$triangles = isset( $_SESSION['triangles'] ) ? $_SESSION['triangles'] : FALSE;
$antialias = isset( $_SESSION['antialias'] ) ? $_SESSION['antialias'] : 0;
$autosub = isset( $_SESSION['autosub'] ) ? $_SESSION['autosub'] : 0;
$font = isset( $_SESSION['font'] ) ? $_SESSION['font'] : 'Vera.ttf';
$fontsize = 12;
// Validate the phrase and draw the tree
$sp = new CStringParser( $data );
if (!$sp->Validate() )
{
// Display an error if the phrase doesn't validate.
// Right now that only means the brackets didn't
// match up. More tests could be added in the future.
print( "Sentence brackets don't match up...<br />\n" );
} else {
// If all is well, go ahead and draw the graph ...
$sp->Parse();
if ( $autosub )
$sp->AutoSubscript();
$elist = $sp->GetElementList();
// Draw the graph
$fontpath = dirname( $_SERVER['SCRIPT_FILENAME'] ) . '/ttf/';
$graph = new CSVGGraph( $elist
, $color, $antialias, $triangles
, $fontpath . $font, $fontsize );
$graph->Draw();
}
?>