# LinearStringDrawer.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
    00015     final class LinearStringDrawer extends TextDrawer
    00016     {
    00020         public function draw($string)
    00021         {
    00022             $maxHeight = $this->getMaxCharacterHeight();
    00023             $y = round($this->getTuringImage()->getHeight() / 2 + $maxHeight / 2);
    00024
    00025             $textWidth = $this->getTextWidth($string);
    00026
    00027             if ($this->getTuringImage()->getWidth() <= $textWidth)
    00028                 return $this->showError();
    00029
    00030             $x = round(($this->getTuringImage()->getWidth() - $textWidth) / 2);
    00031             $angle = 0;
    00032
    00033             for ($i = 0, $length = strlen($string); $i < $length; ++$i) {
    00034                 $character = $string[$i];
    00035                 $this->drawCraracter($angle, $x, $y, $character);
    00036                 $x += $this->getStringWidth($character) + $this->getSpace();
    00037             }
    00038
    00039             return $this;
    00040         }
    00041     }
    00042 ?>