/** * Draw an awFileFont object on a Flash movie * * @param awGDDriver $driver The awMingDriver object containing the movie 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 mingString(awMingDriver $driver, awText $text, awPoint $point, $width = NULL) { $font = $text->getFont(); if ($font instanceof awFDBFont === FALSE and $font->getExtension() === NULL) { $font->setExtension('fdb'); } list($red, $green, $blue, $alpha) = $driver->getColor($text->getColor()); $fontPath = ARTICHOW_FONT . '/' . $font->name . '.' . $font->getExtension(); $flashFont = new SWFFont($fontPath); $flashText = new SWFText(); $flashText->setFont($flashFont); $flashText->setColor($red, $green, $blue, $alpha); // Multiply the font size by 1.33 to get the same size on screen as in GD (roughly) $flashText->setHeight($font->size * 1.33); $flashText->addString($text->getText()); $item = $driver->movie->add($flashText); $item->rotateTo($text->getAngle()); $box = awFileFontDriver::mingfdbbox($font->size, $text->getAngle(), $text->getText(), $flashText); $textHeight = -$box[5]; $box = awFileFontDriver::mingfdbbox($font->size, 90, $text->getText(), $flashText); $textWidth = abs($box[6] - $box[2]); // Reposition the text so it's in the same position than with the GD driver. $item->moveTo($driver->x + $point->x + $textWidth * sin($text->getAngle() / 180 * M_PI), $driver->y + $point->y + $textHeight); }
/** * 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'); } $filePath = $font->getName() . '.' . $font->getExtension(); $box = imagettfbbox($font->getSize(), $text->getAngle(), $filePath, $text->getText()); $textHeight = -$box[5]; $box = imagettfbbox($font->getSize(), 90, $filePath, $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->getSize(), $text->getAngle(), $driver->x + $point->x + $textWidth * sin($text->getAngle() / 180 * M_PI), $driver->y + $point->y + $textHeight, $rgb, $filePath, $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()); }