00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 final class InclinedStringDrawer extends TextDrawer
00017 {
00018 const MAX_ANGLE = 70;
00019
00023 public function draw($string)
00024 {
00025 $textWidth = $this->getTextWidth($string);
00026 $textHeight = $this->getMaxCharacterHeight();
00027
00028 if ($textWidth < $this->getTuringImage()->getHeight()) {
00029 $maxAngle = 45;
00030 } else {
00031 $maxAngle =
00032 rad2deg(
00033 asin(
00034 ($this->getTuringImage()->getHeight() - $textHeight)
00035 / $textWidth
00036 )
00037 );
00038 }
00039
00040 $angle = mt_rand(-$maxAngle / 2, $maxAngle / 2);
00041
00042 if ($angle > self::MAX_ANGLE)
00043 $angle = self::MAX_ANGLE;
00044
00045 if ($angle < -self::MAX_ANGLE)
00046 $angle = -self::MAX_ANGLE;
00047
00048 if ($this->getTuringImage()->getWidth() > $textWidth) {
00049 $x = round(
00050 (
00051 ($this->getTuringImage()->getWidth() - $textWidth)
00052 * cos(deg2rad($angle))
00053 )
00054 / 2
00055 );
00056
00057 $y = round(
00058 (
00059 ($this->getTuringImage()->getHeight() + $textWidth)
00060 * sin(deg2rad($angle))
00061 )
00062 / 2
00063 + ($textHeight / 2)
00064 );
00065
00066 for ($i = 0, $length = strlen($string); $i < $length; ++$i) {
00067 $character = $string[$i];
00068
00069 $this->drawCraracter($angle, $x, $y, $character);
00070
00071 $charWidth =
00072 $this->getStringWidth($character)
00073 + $this->getSpace();
00074
00075 $y -= $charWidth * sin(deg2rad($angle));
00076 $x += $charWidth * cos(deg2rad($angle));
00077 }
00078 } else
00079 return $this->showError();
00080
00081 return $this;
00082 }
00083 }
00084 ?>