ErrorDrawer.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2004-2007 by Dmitry E. Demidov                          *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 /* $Id: ErrorDrawer.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     final class ErrorDrawer
00017     {
00018         const FONT_SIZE = 4;
00019         
00020         private static $drawError   = true;         
00021         
00022         public static function setDrawError($drawError = false)
00023         {
00024             self::$drawError = $drawError;
00025         }
00026         
00027         public static function isDrawError()
00028         {
00029             return self::$drawError;
00030         }
00031 
00032         public function __construct($turingImage)
00033         {
00034             $this->turingImage = $turingImage;
00035         }
00036         
00040         public function draw($string = 'ERROR!')
00041         {
00042             if (!ErrorDrawer::isDrawError())
00043                 return $this;
00044             
00045             $y = round(
00046                 $this->turingImage->getHeight() / 2
00047                 - imagefontheight(ErrorDrawer::FONT_SIZE) / 2
00048             );
00049             
00050             $textWidth = imagefontwidth(ErrorDrawer::FONT_SIZE) * strlen($string);
00051             
00052             if ($this->turingImage->getWidth() > $textWidth)
00053                 $x = round(($this->turingImage->getWidth() - $textWidth) / 2);
00054             else
00055                 $x = 0;
00056                 
00057             $color = $this->turingImage->getOneCharacterColor();
00058             
00059             imagestring(
00060                 $this->turingImage->getImageId(),
00061                 ErrorDrawer::FONT_SIZE,
00062                 $x,
00063                 $y,
00064                 $string,
00065                 $color
00066             );
00067             
00068             return $this;
00069         }
00070     }
00071 ?>

Generated on Sun Dec 9 21:56:24 2007 for onPHP by  doxygen 1.5.4