|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Graze\CiffRenderer; |
|
4
|
|
|
|
|
5
|
|
|
use Graze\CiffRenderer\Renderer\RendererDocument; |
|
6
|
|
|
use Illuminate\Filesystem\Filesystem; |
|
7
|
|
|
|
|
8
|
|
|
class CiffRenderer |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var Filesystem |
|
12
|
|
|
*/ |
|
13
|
|
|
private $filesystem; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var RendererDocument |
|
17
|
|
|
*/ |
|
18
|
|
|
private $rendererDocument; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var callable |
|
22
|
|
|
*/ |
|
23
|
|
|
private $fontResolver; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var callable |
|
27
|
|
|
*/ |
|
28
|
|
|
private $graphicResolver; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param Filesystem $filesystem |
|
32
|
|
|
* @param RendererDocument $rendererDocument |
|
33
|
|
|
*/ |
|
34
|
2 |
|
public function __construct( |
|
35
|
|
|
Filesystem $filesystem, |
|
36
|
|
|
RendererDocument $rendererDocument |
|
37
|
|
|
) { |
|
38
|
2 |
|
$this->filesystem = $filesystem; |
|
39
|
2 |
|
$this->rendererDocument = $rendererDocument; |
|
40
|
2 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Render an image from a ciff file located on the filesystem. |
|
44
|
|
|
* |
|
45
|
|
|
* @param string $path |
|
46
|
|
|
* @return Intervention\Image\Image |
|
|
|
|
|
|
47
|
|
|
*/ |
|
48
|
1 |
|
public function renderFile($path) |
|
49
|
|
|
{ |
|
50
|
1 |
|
$string = $this->filesystem->get($path); |
|
51
|
1 |
|
return $this->renderString($string); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Render an image from ciff data contained within a string. |
|
56
|
|
|
* |
|
57
|
|
|
* @param string $string |
|
58
|
|
|
* @return Intervention\Image\Image |
|
59
|
|
|
*/ |
|
60
|
2 |
|
public function renderString($string) |
|
61
|
|
|
{ |
|
62
|
2 |
|
$xml = simplexml_load_string($string); |
|
63
|
|
|
|
|
64
|
2 |
|
return $this->rendererDocument->render( |
|
65
|
2 |
|
$xml, |
|
|
|
|
|
|
66
|
2 |
|
$this->fontResolver, |
|
67
|
2 |
|
$this->graphicResolver |
|
68
|
2 |
|
); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param callable $fontResolver |
|
73
|
|
|
*/ |
|
74
|
2 |
|
public function setFontResolver(callable $fontResolver) |
|
75
|
|
|
{ |
|
76
|
2 |
|
$this->fontResolver = $fontResolver; |
|
77
|
2 |
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param callable $graphicResolver |
|
81
|
|
|
*/ |
|
82
|
2 |
|
public function setGraphicResolver(callable $graphicResolver) |
|
83
|
|
|
{ |
|
84
|
2 |
|
$this->graphicResolver = $graphicResolver; |
|
85
|
2 |
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return CiffRenderer |
|
89
|
|
|
*/ |
|
90
|
|
|
public static function factory() |
|
91
|
|
|
{ |
|
92
|
|
|
return new static( |
|
93
|
|
|
new Filesystem(), |
|
94
|
|
|
RendererDocument::factory() |
|
95
|
|
|
); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|