|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
|
|
|
|
|
3
|
|
|
* citeproc-php |
|
4
|
|
|
* |
|
5
|
|
|
* @link http://github.com/seboettg/citeproc-php for the source repository |
|
6
|
|
|
* @copyright Copyright (c) 2016 Sebastian Böttger. |
|
7
|
|
|
* @license https://opensource.org/licenses/MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Seboettg\CiteProc\Styles; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
use Seboettg\Collection\ArrayList; |
|
14
|
|
|
use SimpleXMLElement; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Trait FormattingTrait |
|
18
|
|
|
* @package Seboettg\CiteProc\Styles |
|
|
|
|
|
|
19
|
|
|
* @author Sebastian Böttger <[email protected]> |
|
|
|
|
|
|
20
|
|
|
*/ |
|
|
|
|
|
|
21
|
|
|
trait FormattingTrait |
|
22
|
|
|
{ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
|
|
|
|
|
25
|
|
|
* @var array |
|
26
|
|
|
*/ |
|
27
|
|
|
static $formattingAttributes = ['font-style', 'font-family', 'font-weight', 'font-variant', 'text-decoration', 'vertical-align']; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
|
|
|
|
|
30
|
|
|
* @var ArrayList |
|
31
|
|
|
*/ |
|
32
|
|
|
private $formattingOptions; |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
/** |
|
|
|
|
|
|
35
|
|
|
* @var bool |
|
36
|
|
|
*/ |
|
37
|
|
|
private $stripPeriods = false; |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
|
|
|
|
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
private $format; |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
/** |
|
|
|
|
|
|
45
|
|
|
* @param SimpleXMLElement $node |
|
|
|
|
|
|
46
|
|
|
*/ |
|
|
|
|
|
|
47
|
144 |
|
protected function initFormattingAttributes(SimpleXMLElement $node) |
|
48
|
|
|
{ |
|
49
|
144 |
|
$this->formattingOptions = new ArrayList(); |
|
50
|
|
|
|
|
51
|
|
|
/** @var SimpleXMLElement $attribute */ |
|
|
|
|
|
|
52
|
144 |
|
foreach ($node->attributes() as $attribute) { |
|
53
|
|
|
|
|
54
|
|
|
/** @var string $name */ |
|
|
|
|
|
|
55
|
144 |
|
$name = (string) $attribute->getName(); |
|
56
|
144 |
|
$value = (string) $attribute; |
|
57
|
|
|
|
|
58
|
144 |
|
if (in_array($name, self::$formattingAttributes)) { |
|
59
|
42 |
|
$this->formattingOptions->add($name, $value); |
|
60
|
42 |
|
continue; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
144 |
|
} |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
140 |
|
protected function format($text) |
|
|
|
|
|
|
67
|
|
|
{ |
|
68
|
140 |
|
if (empty($text)) { |
|
69
|
1 |
|
return $text; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
140 |
|
if (!empty($this->formattingOptions)) { |
|
73
|
140 |
|
$format = ""; |
|
74
|
140 |
|
foreach ($this->formattingOptions as $option => $optionValue) { |
|
75
|
32 |
|
if ($optionValue === "italic") { |
|
76
|
26 |
|
$text = "<i>$text</i>"; |
|
77
|
12 |
|
} else if ($optionValue === "bold") { |
|
78
|
6 |
|
$text = "<b>$text</b>"; |
|
79
|
8 |
|
} else if ($optionValue === "normal") { |
|
80
|
|
|
//$text = $text; |
|
81
|
8 |
|
} else if ($option === "vertical-align") { |
|
82
|
2 |
|
if ($optionValue === "sub") { |
|
83
|
1 |
|
$text = "<sub>$text</sub>"; |
|
84
|
2 |
|
} else if ($optionValue === "sup") { |
|
85
|
1 |
|
$text = "<sup>$text</sup>"; |
|
86
|
|
|
} |
|
87
|
6 |
|
} else if ($option === "text-decoration" && $optionValue === "none") { |
|
88
|
|
|
|
|
89
|
|
|
} else { |
|
90
|
6 |
|
$format .= "$option: $optionValue;"; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
140 |
|
if (!empty($format)) { |
|
94
|
6 |
|
$text = '<span style="' . $format . '">' . $text . '</span>'; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
140 |
|
return $text; |
|
98
|
|
|
} |
|
99
|
|
|
} |