Example #1
0
 /**
  * Draw an awFileFont object on a GD ressource
  *
  * @param awGDDriver $driver The awGDDriver object containing the ressource to draw upon
  * @param awText $text The awText object containing the string to draw
  * @param awPoint $point Where to draw the string from
  * @param float $width The width of the area containing the text
  */
 private function gdString(awGDDriver $driver, awText $text, awPoint $point, $width = NULL)
 {
     // Make easier font positionment
     $text->setText($text->getText() . " ");
     $font = $text->getFont();
     if ($font instanceof awTTFFont === FALSE and $font->getExtension() === NULL) {
         $font->setExtension('ttf');
     }
     $box = imagettfbbox($font->size, $text->getAngle(), $font->name . '.' . $font->getExtension(), $text->getText());
     $textHeight = -$box[5];
     $box = imagettfbbox($font->size, 90, $font->name . '.' . $font->getExtension(), $text->getText());
     $textWidth = abs($box[6] - $box[2]);
     // Restore old text
     $text->setText(substr($text->getText(), 0, strlen($text->getText()) - 1));
     $textString = $text->getText();
     // Split text if needed
     if ($width !== NULL) {
         $characters = floor($width / $this->getGDAverageWidth($font));
         $textString = wordwrap($textString, $characters, "\n", TRUE);
     }
     $color = $text->getColor();
     $rgb = $driver->getColor($color);
     imagettftext($driver->resource, $font->size, $text->getAngle(), $driver->x + $point->x + $textWidth * sin($text->getAngle() / 180 * M_PI), $driver->y + $point->y + $textHeight, $rgb, $font->name . '.' . $font->getExtension(), $textString);
 }