Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add workaround for lack of TTF font support.

Rename image generators so that PHP detects them without needing .htaccess support.
Improve Unicode support.
Use HTML5 for templates.
Modify license information for code borrowed from a PHP documentation comment.
Remove some trailing whitespace.
  • Loading branch information...
commit 89b1059423ed23e725913d04b39f6504ee2e2cbe 1 parent 9d92d83
@GPHemsley authored
View
40 index.php
@@ -7,12 +7,12 @@
// 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
@@ -51,10 +51,10 @@
$_SESSION['data'] = trim( $_POST['data'] );
- $_SESSION['color'] = ( isset( $_POST['color'] ) ? TRUE : FALSE );
- $_SESSION['antialias'] = ( isset( $_POST['antialias'] ) ? TRUE : FALSE );
- $_SESSION['autosub'] = ( isset( $_POST['autosub'] ) ? TRUE : FALSE );
- $_SESSION['triangles'] = ( isset( $_POST['triangles'] ) ? TRUE : FALSE );
+ $_SESSION['color'] = ( isset( $_POST['color'] ) ? TRUE : FALSE );
+ $_SESSION['antialias'] = ( isset( $_POST['antialias'] ) ? TRUE : FALSE );
+ $_SESSION['autosub'] = ( isset( $_POST['autosub'] ) ? TRUE : FALSE );
+ $_SESSION['triangles'] = ( isset( $_POST['triangles'] ) ? TRUE : FALSE );
if ( isset( $_POST['font'] ) )
{
@@ -63,22 +63,22 @@
{
case 'vera_sans':
break;
-
+
case 'vera_serif':
$font = 'VeraSe.ttf';
break;
-
+
default:
break;
}
-
+
$_SESSION['fontsel'] = $_POST['font'];
$_SESSION['font'] = $font;
}
-
- $_SESSION['fontsize'] = isset( $_POST['fontsize'] )
+
+ $_SESSION['fontsize'] = isset( $_POST['fontsize'] )
? intval( $_POST['fontsize'] ) : 8;
-
+
// Increment phrase counter (displayed on the bottom of the page)
AddCounter();
@@ -91,7 +91,7 @@
if ( LOG_LANG )
LogLangSettings();
} else {
- // If no phrase was submitted, show
+ // If no phrase was submitted, show
// usage information, news, etc. .
$page = new CTemplate( GetLocalizedFname( 'tpl/intro.html' ));
@@ -103,9 +103,9 @@
if ( !isset( $_SESSION['data'] ) )
{
- $_SESSION['data'] = file_get_contents( GetLocalizedFname( "var/sample.phrase" ));
- $_SESSION['color'] = TRUE;
- $_SESSION['antialias'] = TRUE;
+ $_SESSION['data'] = file_get_contents( GetLocalizedFname( "var/sample.phrase" ));
+ $_SESSION['color'] = TRUE;
+ $_SESSION['antialias'] = TRUE;
$_SESSION['autosub'] = TRUE;
$_SESSION['triangles'] = TRUE;
$_SESSION['fontsel'] = "vera_sans";
@@ -115,12 +115,12 @@
// Render the page
-$phrase = htmlentities( $_SESSION['data'] );
+$phrase = htmlentities( $_SESSION['data'], ENT_QUOTES, 'UTF-8' );
-$img = sprintf( "<img src=\"stgraph.png?%s\" alt=\"\" title=\"%s\"/>", SID, $phrase );
+$img = sprintf( "<img src=\"stgraph.png.php?%s\" alt=\"\" title=\"%s\"/>", SID, $phrase );
$graph = sprintf( "<a href=\"dnlgraph.php?%s\">%s</a>", SID, $img );
$icon = "<img src=\"img/vectorgfx.png\" alt=\"SVG\" />";
-$svg = sprintf( "<div id=\"svg\"><a href=\"stgraph.svg?%s\">%s</a></div>", SID, $icon );
+$svg = sprintf( "<div id=\"svg\"><a href=\"stgraph.svg.php?%s\">%s</a></div>", SID, $icon );
$fontoption = sprintf( "SELECT_%s", $_SESSION['fontsel'] );
$sizeoption = sprintf( "SELECT_size_%d", $_SESSION['fontsize'] );
@@ -128,7 +128,7 @@
$page->SetValues( array(
'VERSION' => VERSION,
'FORM_ACTION' => sprintf( "?%s", strip_tags( SID )),
- 'GRAPH' => $graph,
+ 'GRAPH' => $graph,
'SVG' => $svg,
'PHRASE' => $phrase,
'DATA_VAL' => $phrase,
View
16 src/class.stringparser.php
@@ -35,7 +35,7 @@ function escape_high_ascii( $s )
if ( ord( $c ) < 127 )
$html .= $c;
else
- $html .= sprintf( '&#%d;', ord( $c ) );
+ $html .= "\x1A";//sprintf( '&#%d;', ord( $c ) ); // @TODO: No support for Unicode; using SUB character instead.
}
return $html;
@@ -50,7 +50,7 @@ class CStringParser
function CStringParser( $s )
{
// Clean up the data a little to make processing easier
-
+
$s = str_replace( "\t", "", $s );
$s = str_replace( " ", " ", $s );
$s = str_replace( "] [", "][", $s );
@@ -59,11 +59,11 @@ function CStringParser( $s )
$s = escape_high_ascii( $s );
// Store it for later...
-
+
$this->data = $s;
- // Initialize internal element list
-
+ // Initialize internal element list
+
$this->elist = new CElementList();
}
@@ -73,7 +73,7 @@ function Validate()
return FALSE;
// TODO: Currently the only real validation is that the brackets match up. There's room for improvement here.
-
+
$open = 0;
for( $i=0; $i<strlen( $this->data ); $i++ )
@@ -103,7 +103,7 @@ function AutoSubscript()
{
$elements = $this->elist->GetElements();
$tmpcnt = array();
-
+
foreach( $elements as $element )
{
if ( $element->type == ETYPE_NODE )
@@ -129,7 +129,7 @@ function AutoSubscript()
return $this->tncnt;
}
-
+
// ----------------------------------------------------------------------
// PRIVATE FUNCTIONS
// ----------------------------------------------------------------------
View
11 src/imgutils.php
@@ -21,12 +21,17 @@
//
// $Id: imgutils.php,v 1.1.1.1 2005/01/05 17:49:14 int2str Exp $
+if( !function_exists( 'imagettftext' ) || !function_exists( 'imagettfbbox' ) )
+{
+ require_once( 'ttf_hacks.php' );
+}
+
function ImgGetTxtWidth( $text, $font, $font_size )
{
$bbox = imagettfbbox( $font_size, 0, $font, $text );
- $width =
- ( ($bbox[0] > 0 && $bbox[2] > 0) || ($bbox[0] < 0 && $bbox[2] < 0) )
- ? abs( $bbox[2] - $bbox[0] )
+ $width =
+ ( ($bbox[0] > 0 && $bbox[2] > 0) || ($bbox[0] < 0 && $bbox[2] < 0) )
+ ? abs( $bbox[2] - $bbox[0] )
: ( abs( $bbox[2] ) + abs( $bbox[0] ) + 1 );
return $width;
View
14 src/smoothline.php
@@ -1,13 +1,15 @@
-<?php
+<?php
// smoothline.php - Anti-aliased line drawing
//
-// From the PHP documentation at http://php.net/imageline
+// From the PHP documentation at http://php.net/imageline#33122
// Original author: nanobot@chipx86.com
//
-// NOTE: It is not yet clear which license the code below
-// was released under (by posting it on php.net). Therefore
-// this code may be removed int the future.
+// NOTE: As part of a comment on PHP documentation, this code is licensed
+// under the Creative Commons Attribution 3.0 License (CC-BY-3.0).
+//
+// http://php.net/license/#doc-lic
+// http://creativecommons.org/licenses/by/3.0/
//
// TODO: Use faster GPL licensed/free algorithm for anti-aliasing if available.
//
@@ -16,7 +18,7 @@
function imagesmoothline( $image, $x1, $y1, $x2, $y2, $color )
{
$colors = imagecolorsforindex( $image, $color );
-
+
if ($x1 == $x2)
{
imageline ($image, $x1, $y1, $x2, $y2, $color); // Vertical line
View
76 src/ttf_hacks.php
@@ -0,0 +1,76 @@
+<?php
+
+// ttf_hacks.php - Image utility functions to work around lack of TTF support
+// Copyright (c) 2011 Gordon P. Hemsley <me@gphemsley.org>
+//
+// ttf_hacks.php 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$
+
+// If PHP is not compiled with FreeType support, we can't use TTF fonts.
+// There are hacky workarounds for that problem.
+
+define( 'STRING_FONT', 2 );
+define( 'STRING_FONT_WIDTH', imagefontwidth( STRING_FONT ) );
+define( 'STRING_FONT_HEIGHT', imagefontheight( STRING_FONT ) );
+
+function xy_ttf2string( $old_x, $old_y )
+{
+ $new_x = $old_x;
+ $new_y = $old_y - STRING_FONT_HEIGHT;
+
+ return array( $new_x, $new_y );
+}
+
+function imagestringbbox( $text, $size, $x = 0, $y = 0 )
+{
+ $string_width = strlen( $text ) * STRING_FONT_WIDTH;
+
+ $top = $y;
+ $bottom = $y - STRING_FONT_HEIGHT;
+ $left = $x;
+ $right = $x + $string_width;
+
+ return array( $left, $bottom, $right, $bottom, $right, $top, $left, $top );
+}
+
+if( !function_exists( 'imagettftext' ) )
+{
+ function imagettftext( $image, $size, $angle, $x, $y, $color, $fontfile, $text )
+ {
+ list( $x, $y ) = xy_ttf2string( $x, $y );
+
+ if( imagestring( $image, STRING_FONT, $x, $y, $text, $color ) )
+ {
+ return imagestringbbox( $text, $size, $x, $y );
+ }
+ else
+ {
+ return FALSE;
+ }
+ }
+}
+
+if( !function_exists( 'imagettfbbox' ) )
+{
+ function imagettfbbox( $size, $angle, $fontfile, $text )
+ {
+ return imagestringbbox( $text, $size );
+ }
+}
+
+?>
View
0  stgraph.png → stgraph.png.php
File renamed without changes
View
0  stgraph.svg → stgraph.svg.php
File renamed without changes
View
9 tpl/header.html
@@ -1,16 +1,14 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/tr/xhtml1/DTD/xhtml1-strict.dtd">
-
+<!DOCTYPE html>
<html>
-
<head>
+ <meta charset="UTF-8" />
+
<title>phpSyntaxTree - drawing syntax trees made easy</title>
<link rel="stylesheet" type="text/css" href="css/default.css" title="Standard" />
<link rel="stylesheet" type="text/css" href="css/print.css" media="print" />
<link rel="alternate stylesheet" type="text/css" href="css/print.css" title="Print" />
- <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />
-
<meta name="author" content="Andre Eisenbach" />
<meta name="description" content="phpSyntaxtree - a syntax tree generator for linguists. Draw syntax trees from labelled bracket notation phrases and include them into your assignment/homework." />
<meta name="keywords" content="syntax tree, linguists, homework, labelled bracket notation" />
@@ -25,7 +23,6 @@
urchinTracker();
</script>
</head>
-
<body>
<h1>phpSyntaxTree - drawing syntax trees made easy</h1>
Please sign in to comment.
Something went wrong with that request. Please try again.