Skip to content

Commit

Permalink
Add Point structure
Browse files Browse the repository at this point in the history
  • Loading branch information
stil committed Jun 4, 2017
1 parent e6c2d2c commit 9f9a19a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 44 deletions.
25 changes: 14 additions & 11 deletions src/Box.php
@@ -1,6 +1,7 @@
<?php
namespace GDText;

use GDText\Struct\Point;
use GDText\Struct\Rectangle;

class Box
Expand Down Expand Up @@ -137,8 +138,7 @@ public function setTextShadow(Color $color, $xShift, $yShift)
{
$this->textShadow = array(
'color' => $color,
'x' => $xShift,
'y' => $yShift
'offset' => new Point($xShift, $yShift)
);
}

Expand Down Expand Up @@ -311,18 +311,21 @@ public function draw($text)

if ($this->textShadow !== false) {
$this->drawInternal(
$xMOD + $this->textShadow['x'],
$yMOD + $this->textShadow['y'],
new Point(
$xMOD + $this->textShadow['offset']->getX(),
$yMOD + $this->textShadow['offset']->getY()
),
$this->textShadow['color'],
$line
);

}

$this->strokeText($xMOD, $yMOD, $line);
$this->drawInternal(
$xMOD,
$yMOD,
new Point(
$xMOD,
$yMOD
),
$this->fontColor,
$line
);
Expand Down Expand Up @@ -390,19 +393,19 @@ protected function strokeText($x, $y, $text)
if ($size <= 0) return;
for ($c1 = $x - $size; $c1 <= $x + $size; $c1++) {
for ($c2 = $y - $size; $c2 <= $y + $size; $c2++) {
$this->drawInternal($c1, $c2, $this->strokeColor, $text);
$this->drawInternal(new Point($c1, $c2), $this->strokeColor, $text);
}
}
}

protected function drawInternal($x, $y, Color $color, $text)
protected function drawInternal(Point $position, Color $color, $text)
{
imagefttext(
$this->im,
$this->getFontSizeInPoints(),
0, // no rotation
$x,
$y,
$position->getX(),
$position->getY(),
$color->getIndex($this->im),
$this->fontFace,
$text
Expand Down
43 changes: 43 additions & 0 deletions src/Struct/Point.php
@@ -0,0 +1,43 @@
<?php

namespace GDText\Struct;

class Point
{
/**
* @var int
*/
private $x;

/**
* @var int
*/
private $y;

/**
* Point constructor.
* @param int $x
* @param int $y
*/
public function __construct($x, $y)
{
$this->x = $x;
$this->y = $y;
}

/**
* @return int
*/
public function getX()
{
return $this->x;
}

/**
* @return int
*/
public function getY()
{
return $this->y;
}
}
39 changes: 6 additions & 33 deletions src/Struct/Rectangle.php
Expand Up @@ -2,18 +2,8 @@

namespace GDText\Struct;

class Rectangle
class Rectangle extends Point
{
/**
* @var int
*/
private $x;

/**
* @var int
*/
private $y;

/**
* @var int
*/
Expand All @@ -33,28 +23,11 @@ class Rectangle
*/
public function __construct($x, $y, $width, $height)
{
$this->x = $x;
$this->y = $y;
parent::__construct($x, $y);
$this->width = $width;
$this->height = $height;
}

/**
* @return int
*/
public function getX()
{
return $this->x;
}

/**
* @return int
*/
public function getY()
{
return $this->y;
}

/**
* @return int
*/
Expand All @@ -76,30 +49,30 @@ public function getHeight()
*/
public function getLeft()
{
return $this->x;
return $this->getX();
}

/**
* @return int
*/
public function getTop()
{
return $this->y;
return $this->getY();
}

/**
* @return int
*/
public function getRight()
{
return $this->x + $this->width;
return $this->getX() + $this->width;
}

/**
* @return int
*/
public function getBottom()
{
return $this->y + $this->height;
return $this->getY() + $this->height;
}
}

0 comments on commit 9f9a19a

Please sign in to comment.