00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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 ?>