|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Graze\CiffRenderer\Parser\FieldParser; |
|
4
|
|
|
|
|
5
|
|
|
use Graze\CiffRenderer\Parser\FieldParser\FieldParserFixedText; |
|
6
|
|
|
use Graze\CiffRenderer\Parser\FieldParser\FieldParserInterface; |
|
7
|
|
|
use Graze\CiffRenderer\BarcodeGenerator\BarcodeGeneratorFactory; |
|
8
|
|
|
use Graze\CiffRenderer\Parser\FieldParserRegistry; |
|
9
|
|
|
use \SimpleXMLElement; |
|
10
|
|
|
|
|
11
|
|
|
class FieldParserBarcode extends FieldParserFixedText implements FieldParserInterface |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var float |
|
15
|
|
|
*/ |
|
16
|
|
|
const FONT_SIZE_MULTIPLIER = 141; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var BarcodeGeneratorFactory |
|
20
|
|
|
*/ |
|
21
|
|
|
private $barcodeGeneratorFactory; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param BarcodeGeneratorFactory $barcodeGeneratorFactory |
|
25
|
|
|
* @param FieldParserRegistry $fieldParserRegistry |
|
26
|
|
|
* @param SimpleXMLElement $xmlHeader |
|
27
|
|
|
* @param SimpleXMLElement $xmlField |
|
28
|
|
|
* @param float $scale |
|
29
|
|
|
*/ |
|
30
|
11 |
|
public function __construct( |
|
31
|
|
|
BarcodeGeneratorFactory $barcodeGeneratorFactory, |
|
32
|
|
|
FieldParserRegistry $fieldParserRegistry, |
|
33
|
|
|
SimpleXMLElement $xmlHeader, |
|
34
|
|
|
SimpleXMLElement $xmlField, |
|
35
|
|
|
$scale |
|
36
|
|
|
) { |
|
37
|
11 |
|
$this->barcodeGeneratorFactory = $barcodeGeneratorFactory; |
|
38
|
|
|
|
|
39
|
11 |
|
parent::__construct( |
|
40
|
11 |
|
$fieldParserRegistry, |
|
41
|
|
|
$xmlHeader, |
|
42
|
|
|
$xmlField, |
|
43
|
|
|
$scale |
|
44
|
|
|
); |
|
45
|
11 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return int |
|
49
|
|
|
*/ |
|
50
|
1 |
|
public function getFontSize() |
|
51
|
|
|
{ |
|
52
|
1 |
|
$size = (float) $this->xmlField->Barcode->HR->HRFont->Pitch; |
|
53
|
|
|
|
|
54
|
1 |
|
return (int) round($size * self::FONT_SIZE_MULTIPLIER * $this->scale); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getFontFace() |
|
61
|
|
|
{ |
|
62
|
|
|
return (string) $this->xmlField->Barcode->HR->HRFont->Family; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return bool |
|
67
|
|
|
*/ |
|
68
|
1 |
|
public function getIsInverse() |
|
69
|
|
|
{ |
|
70
|
1 |
|
return (bool) (string) $this->xmlField->Inverse; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Generate a barcode string. |
|
75
|
|
|
* |
|
76
|
|
|
* @return string |
|
77
|
|
|
*/ |
|
78
|
1 |
|
public function getText() |
|
79
|
|
|
{ |
|
80
|
1 |
|
$data = parent::getText(); |
|
81
|
1 |
|
$barcodeGenerator = $this->barcodeGeneratorFactory->getGenerator($this->xmlField->Barcode->Type); |
|
82
|
|
|
|
|
83
|
1 |
|
return $barcodeGenerator->generate($data); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param FieldParserRegistry $fieldParserRegistry |
|
88
|
|
|
* @param SimpleXMLElement $xmlHeader |
|
89
|
|
|
* @param SimpleXMLElement $xmlField |
|
90
|
|
|
* @param float $scale |
|
91
|
|
|
* @return FieldParserInterface |
|
92
|
|
|
*/ |
|
93
|
1 |
|
public static function factory( |
|
94
|
|
|
FieldParserRegistry $fieldParserRegistry, |
|
95
|
|
|
SimpleXMLElement $xmlHeader, |
|
96
|
|
|
SimpleXMLElement $xmlField, |
|
97
|
|
|
$scale |
|
98
|
|
|
) { |
|
99
|
1 |
|
return new static( |
|
100
|
1 |
|
new BarcodeGeneratorFactory(), |
|
101
|
|
|
$fieldParserRegistry, |
|
102
|
|
|
$xmlHeader, |
|
103
|
|
|
$xmlField, |
|
104
|
|
|
$scale |
|
105
|
|
|
); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|