/** * Draw a text * * @param awDrawer $drawer * @param awPoint $p Draw text at this point * @param awText $text The text */ public function draw(awDrawer $drawer, awPoint $p, awText $text) { // Make easier font positionment $textWorking = $text->getText(); $offsetTop = 0; $offsetRight = 0; /* Ugly font repositioning hack. FIXME: Make me not ugly.*/ if (strpos($textWorking, "||") === 0) { $textWorking = substr($textWorking, 2); $offsetTop += 10; $offsetRight += 2; } else { if (strpos($textWorking, "|") === 0) { $textWorking = substr($textWorking, 1); $offsetTop += 12; $offsetRight += 2; } else { if (strpos($textWorking, "}") === 0) { $textWorking = substr($textWorking, 1); $offsetTop += 3; $offsetRight -= 7; } } } $textParts = explode("\n", $textWorking); $textFirstPart = $textParts[0]; $text->setText($textWorking . " "); $color = $text->getColor(); $rgb = $color->getColor($drawer->resource); $box = imagettfbbox($this->size, $text->getAngle(), $this->font, $textWorking); $height = -$box[5]; $box = imagettfbbox($this->size, 90, $this->font, $textWorking); $width = abs($box[6] - $box[2]); // Restore old text $text->setText(substr($textWorking, 0, strlen($textWorking) - 1)); do { if (strpos($textWorking, "\n") !== false) { $theText = substr($textWorking, 0, strpos($textWorking, "\n")); $textWorking = substr($textWorking, strpos($textWorking, "\n") + 1); } else { $theText = $textWorking; $textWorking = ''; } if ($theText != '') { imagettftext($drawer->resource, $this->size, $text->getAngle(), $drawer->x + $p->x + $width * sin($text->getAngle() / 180 * M_PI) + $offsetRight, $drawer->y + $p->y + $height + $offsetTop, $rgb, $this->font, $theText); } $offsetTop += 15; } while ($textWorking != ''); }
/** * 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); }
/** * Draw a text * * @param awDrawer $drawer * @param awPoint $p Draw text at this point * @param awText $text The text */ public function draw(awDrawer $drawer, awPoint $p, awText $text) { // Make easier font positionment $text->setText($text->getText() . " "); $color = $text->getColor(); $rgb = $color->getColor($drawer->resource); $box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText()); $height = -$box[5]; $box = imagettfbbox($this->size, 90, $this->font, $text->getText()); $width = abs($box[6] - $box[2]); // Restore old text $text->setText(substr($text->getText(), 0, strlen($text->getText()) - 1)); imagettftext($drawer->resource, $this->size, $text->getAngle(), $drawer->x + $p->x + $width * sin($text->getAngle() / 180 * M_PI), $drawer->y + $p->y + $height, $rgb, $this->font, $text->getText()); }