123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
-
- include_once('BCGFont.php');
- include_once('BCGColor.php');
-
- class BCGFontPhp implements BCGFont {
- private $font;
- private $text;
- private $rotationAngle;
- private $backgroundColor;
- private $foregroundColor;
-
-
-
- public function __construct($font) {
- $this->font = max(0, intval($font));
- $this->backgroundColor = new BCGColor('white');
- $this->foregroundColor = new BCGColor('black');
- $this->setRotationAngle(0);
- }
-
-
-
- public function getText() {
- return $this->text;
- }
-
-
-
- public function setText($text) {
- $this->text = $text;
- }
-
-
-
- public function getRotationAngle() {
- return (360 - $this->rotationAngle) % 360;
- }
-
-
-
- public function setRotationAngle($rotationAngle) {
- $this->rotationAngle = (int)$rotationAngle;
- if ($this->rotationAngle !== 90 && $this->rotationAngle !== 180 && $this->rotationAngle !== 270) {
- $this->rotationAngle = 0;
- }
-
- $this->rotationAngle = (360 - $this->rotationAngle) % 360;
- }
-
-
-
- public function getBackgroundColor() {
- return $this->backgroundColor;
- }
-
-
-
- public function setBackgroundColor($backgroundColor) {
- $this->backgroundColor = $backgroundColor;
- }
-
-
-
- public function getForegroundColor() {
- return $this->foregroundColor;
- }
-
-
-
- public function setForegroundColor($foregroundColor) {
- $this->foregroundColor = $foregroundColor;
- }
-
-
-
- public function getDimension() {
- $w = imagefontwidth($this->font) * strlen($this->text);
- $h = imagefontheight($this->font);
-
- $rotationAngle = $this->getRotationAngle();
- if ($rotationAngle === 90 || $rotationAngle === 270) {
- return array($h, $w);
- } else {
- return array($w, $h);
- }
- }
-
-
-
- public function draw($im, $x, $y) {
- if ($this->getRotationAngle() !== 0) {
- if (!function_exists('imagerotate')) {
- throw new BCGDrawException('The method imagerotate doesn\'t exist on your server. Do not use any rotation.');
- }
-
- $w = imagefontwidth($this->font) * strlen($this->text);
- $h = imagefontheight($this->font);
- $gd = imagecreatetruecolor($w, $h);
- imagefilledrectangle($gd, 0, 0, $w - 1, $h - 1, $this->backgroundColor->allocate($gd));
- imagestring($gd, $this->font, 0, 0, $this->text, $this->foregroundColor->allocate($gd));
- $gd = imagerotate($gd, $this->rotationAngle, 0);
- imagecopy($im, $gd, $x, $y, 0, 0, imagesx($gd), imagesy($gd));
- } else {
- imagestring($im, $this->font, $x, $y, $this->text, $this->foregroundColor->allocate($im));
- }
- }
- }
- ?>
|