1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author: Martin Hall-May <[email protected]?subject=Transparency> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Royopa\AlphaPDF; |
7
|
|
|
|
8
|
|
|
class AlphaPDF extends Fpdi |
9
|
|
|
{ |
10
|
|
|
protected $extgstates = array(); |
11
|
|
|
protected $angle = 0; |
12
|
|
|
protected $PDFVersion = 1.4; |
13
|
|
|
|
14
|
|
|
// alpha: real value from 0 (transparent) to 1 (opaque) |
15
|
|
|
// bm: blend mode, one of the following: |
16
|
|
|
// Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, |
17
|
|
|
// HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity |
18
|
|
|
public function SetAlpha($alpha, $bm='Normal') |
19
|
|
|
{ |
20
|
|
|
// set alpha for stroking (CA) and non-stroking (ca) operations |
21
|
|
|
$gs = $this->AddExtGState(array('ca'=>$alpha, 'CA'=>$alpha, 'BM'=>'/'.$bm)); |
22
|
|
|
$this->SetExtGState($gs); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function AddExtGState($parms) |
26
|
|
|
{ |
27
|
|
|
$n = count($this->extgstates)+1; |
28
|
|
|
$this->extgstates[$n]['parms'] = $parms; |
29
|
|
|
return $n; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function SetExtGState($gs) |
33
|
|
|
{ |
34
|
|
|
$this->_out(sprintf('/GS%d gs', $gs)); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function _enddoc() |
38
|
|
|
{ |
39
|
|
|
if(!empty($this->extgstates) && $this->PDFVersion<'1.4') |
40
|
|
|
$this->PDFVersion='1.4'; |
41
|
|
|
parent::_enddoc(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function _putextgstates() |
45
|
|
|
{ |
46
|
|
|
$counter = count($this->extgstates); |
47
|
|
|
for ($i = 1; $i <= $counter; $i++) |
48
|
|
|
{ |
49
|
|
|
$this->_newobj(); |
50
|
|
|
$this->extgstates[$i]['n'] = $this->n; |
51
|
|
|
$this->_out('<</Type /ExtGState'); |
52
|
|
|
foreach ($this->extgstates[$i]['parms'] as $k=>$v) |
53
|
|
|
$this->_out('/'.$k.' '.$v); |
54
|
|
|
$this->_out('>>'); |
55
|
|
|
$this->_out('endobj'); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function _putresourcedict() |
60
|
|
|
{ |
61
|
|
|
parent::_putresourcedict(); |
62
|
|
|
$this->_out('/ExtGState <<'); |
63
|
|
|
foreach($this->extgstates as $k=>$extgstate) |
64
|
|
|
$this->_out('/GS'.$k.' '.$extgstate['n'].' 0 R'); |
65
|
|
|
$this->_out('>>'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function _putresources() |
69
|
|
|
{ |
70
|
|
|
$this->_putextgstates(); |
71
|
|
|
parent::_putresources(); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|