<?php
# -----------------------------------------------------------------------------
#
# The base class of all the text in the plots
#
# -----------------------------------------------------------------------------
#
# Copyright (C) 2004 Christian Eheim
#
# This file is part of TVEz (tvez.sourceforge.net).
#
# TVEz 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.
#
# TVEz 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 TVEz; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# -----------------------------------------------------------------------------
#
# Created on 02/01/2004 by Christian Eheim (hide@address.com)
#
# LAST MODIFIED:
# $Date: 2004/02/03 00:02:17 $
# $Revision: 1.2 $
# $Author: eheim $
#
# -----------------------------------------------------------------------------
class Text {
var $_text;
var $_font;
var $_color;
var $_left;
var $_top;
var $_up;
var $_margin;
var $_width;
var $_height;
function Text($text=null, $font=0) {
$this->_text = $text;
$this->_font = $font;
$this->_color = array(0,0,0);
$this->_left = 0;
$this->_top = 0;
$this->_up = 0;
$this->_margin = 1;
$this->set_width();
$this->set_height();
}
# --------------------------------------------------------------------
# Public members
# --------------------------------------------------------------------
function set($text) {
$this->_text = $text;
$this->set_width();
$this->set_height();
}
function set_font($font) {
$this->_font = $font;
$this->set_width();
$this->set_height();
}
function set_color($color) {
$this->_color = $color;
}
function set_pos($x,$y) {
$this->_left = round($x);
$this->_top = round($y);
}
function get_height() {
return $this->_height;
}
function get_width() {
return $this->_width;
}
function set_margin($margin) {
$this->_margin = $margin;
$this->set_width();
$this->set_height();
}
function draw($image,$up=false) {
$color = $image->_rgb->allocate_color($this->_color);
if ($up) {
ImageStringUp(
$image->_image,
$this->_font,
$this->_left+$this->_margin, $this->_top-$this->_margin,
$this->_text,
$color
);
} else {
ImageString(
$image->_image,
$this->_font,
$this->_left+$this->_margin, $this->_top+$this->_margin,
$this->_text,
$color
);
}
}
# --------------------------------------------------------------------
# Private members
# --------------------------------------------------------------------
function set_height() {
$this->_height = ImageFontHeight( $this->_font ) + 2*$this->_margin;
}
function set_width() {
$cw = ImageFontWidth( $this->_font );
$len = strlen($this->_text);
$this->_width = ($cw*$len) + 2*$this->_margin;
}
}
?>