Completed
Push — master ( 2b7a2e...74ad36 )
by Michael
11:15
created

TTF   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 47
rs 10
c 1
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B writeText() 0 24 2
1
<?php
2
	/**
3
##DOC-SIGNATURE##
4
5
    This file is part of WideImage.
6
		
7
    WideImage is free software; you can redistribute it and/or modify
8
    it under the terms of the GNU Lesser General Public License as published by
9
    the Free Software Foundation; either version 2.1 of the License, or
10
    (at your option) any later version.
11
		
12
    WideImage is distributed in the hope that it will be useful,
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
    GNU Lesser General Public License for more details.
16
		
17
    You should have received a copy of the GNU Lesser General Public License
18
    along with WideImage; if not, write to the Free Software
19
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
21
    * @package WideImage
22
  **/
23
24
namespace WideImage\Font;
25
26
use WideImage\Coordinate;
27
28
/**
29
 * TTF font support class
30
 * 
31
 * @package WideImage
32
 */
33
class TTF
34
{
35
	public $face;
36
	public $size;
37
	public $color;
38
	
39
	public function __construct($face, $size, $color)
40
	{
41
		$this->face  = $face;
42
		$this->size  = $size;
43
		$this->color = $color;
44
	}
45
	
46
	/**
47
	 * Writes text onto an image
48
	 * 
49
	 * @param \WideImage\Image $image
50
	 * @param mixed $x smart coordinate
51
	 * @param mixed $y smart coordinate
52
	 * @param string $text
53
	 * @param int $angle Angle in degrees clockwise
54
	 */
55
	public function writeText($image, $x, $y, $text, $angle = 0)
56
	{
57
		if ($image->isTrueColor()) {
58
			$image->alphaBlending(true);
0 ignored issues
show
Documentation Bug introduced by
The method alphaBlending does not exist on object<WideImage\Image>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
59
		}
60
		
61
		$box  = imageftbbox($this->size, $angle, $this->face, $text);
62
		$obox = array(
63
			'left'   => min($box[0], $box[2], $box[4], $box[6]),
64
			'top'    => min($box[1], $box[3], $box[5], $box[7]),
65
			'right'  => max($box[0], $box[2], $box[4], $box[6]) - 1,
66
			'bottom' => max($box[1], $box[3], $box[5], $box[7]) - 1
67
		);
68
		$obox['width']  = abs($obox['left']) + abs($obox['right']);
69
		$obox['height'] = abs($obox['top']) + abs($obox['bottom']);
70
		
71
		$x = Coordinate::fix($x, $image->getWidth(), $obox['width']);
72
		$y = Coordinate::fix($y, $image->getHeight(), $obox['height']);
73
		
74
		$fixed_x = $x - $obox['left'];
75
		$fixed_y = $y - $obox['top'];
76
		
77
		imagettftext($image->getHandle(), $this->size, $angle, $fixed_x, $fixed_y, $this->color, $this->face, $text);
78
	}
79
}
80