|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Graze\CiffRenderer\Parser\FieldParser; |
|
4
|
|
|
|
|
5
|
|
|
use Graze\CiffRenderer\Parser\FieldParser\FieldParserInterface; |
|
6
|
|
|
|
|
7
|
|
|
class FieldParserFixedText extends AbstractFieldParser implements FieldParserInterface |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Increase Ciff's 'pitch' value to approximate size in pixels. |
|
11
|
|
|
* |
|
12
|
|
|
* @var float |
|
13
|
|
|
*/ |
|
14
|
|
|
const FONT_SIZE_MULTIPLIER = 35; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var int |
|
18
|
|
|
*/ |
|
19
|
|
|
const DEFAULT_FONT_SIZE = 13; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
const ALIGN_LEFT = 'left'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
const ALIGN_CENTRE = 'center'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
const ALIGN_RIGHT = 'right'; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @return int |
|
38
|
|
|
*/ |
|
39
|
1 |
|
public function getFontSize() |
|
40
|
|
|
{ |
|
41
|
1 |
|
$size = (float) $this->xmlField->Text->Font->Pitch; |
|
42
|
1 |
|
if (!$size) { |
|
43
|
|
|
$size = self::DEFAULT_FONT_SIZE; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
return (int) round($size * $this->scale * self::FONT_SIZE_MULTIPLIER); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @return string |
|
51
|
|
|
*/ |
|
52
|
1 |
|
public function getFontFace() |
|
53
|
|
|
{ |
|
54
|
1 |
|
return (string) $this->xmlField->Text->Font->Face; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return int |
|
59
|
|
|
*/ |
|
60
|
2 |
|
public function getOrientation() |
|
61
|
|
|
{ |
|
62
|
2 |
|
return (int) $this->xmlField->Orientation; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
2 |
|
public function getText() |
|
69
|
|
|
{ |
|
70
|
2 |
|
$text = ''; |
|
71
|
2 |
|
foreach ($this->xmlField->Data->Object as $object) { |
|
72
|
2 |
|
if ($object->SrcField) { // @codingStandardsIgnoreLine |
|
73
|
|
|
// Field is a merge field, fetch text from source field |
|
74
|
2 |
|
$sourceFieldName = (string) $object->SrcField->attributes()->SrcFieldName; // @codingStandardsIgnoreLine |
|
75
|
2 |
|
$sourceField = $this->fieldParserRegistry->getParser($sourceFieldName); |
|
76
|
2 |
|
$fieldText = $sourceField->getText(); |
|
77
|
|
|
} else { |
|
78
|
|
|
$fieldText = (string) $object->Default; // @codingStandardsIgnoreLine |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
2 |
|
$text .= $fieldText; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
2 |
|
return $text; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
1 |
|
public function getTextAlignment() |
|
91
|
|
|
{ |
|
92
|
1 |
|
if ($this->xmlField->Text->Block && $this->xmlField->Text->Block->BlkJustify) { |
|
93
|
1 |
|
return strtolower((string) $this->xmlField->Text->Block->BlkJustify); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
// default to left align |
|
97
|
|
|
return FieldParserFixedText::ALIGN_LEFT; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|