1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* citeproc-php |
4
|
|
|
* |
5
|
|
|
* @link http://github.com/seboettg/citeproc-php for the source repository |
6
|
|
|
* @copyright Copyright (c) 2017 Sebastian Böttger. |
7
|
|
|
* @license https://opensource.org/licenses/MIT |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Seboettg\CiteProc\Styles\Css; |
11
|
|
|
|
12
|
|
|
use Seboettg\CiteProc\Style\Options\BibliographyOptions; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class CssStyle |
16
|
|
|
* @package Seboettg\CiteProc\Styles |
17
|
|
|
* @author Sebastian Böttger <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class CssStyle |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var BibliographyOptions |
23
|
|
|
*/ |
24
|
|
|
private $bibliographyOptions; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var CssRules |
28
|
|
|
*/ |
29
|
|
|
private $cssRules = null; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* CssStyle constructor. |
33
|
|
|
* @param BibliographyOptions $bibliographyOptions |
34
|
|
|
*/ |
35
|
3 |
|
public function __construct(BibliographyOptions $bibliographyOptions) |
36
|
|
|
{ |
37
|
3 |
|
$this->bibliographyOptions = $bibliographyOptions; |
38
|
3 |
|
$this->cssRules = new CssRules(); |
39
|
3 |
|
$this->init(); |
40
|
3 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* renders CSS output |
44
|
|
|
* @return string |
45
|
|
|
*/ |
46
|
3 |
|
public function render() |
47
|
|
|
{ |
48
|
3 |
|
return implode("\n", $this->cssRules->toArray()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* initialize CSS rules |
53
|
|
|
*/ |
54
|
3 |
|
private function init() |
55
|
|
|
{ |
56
|
3 |
|
$lineSpacing = $this->bibliographyOptions->getLineSpacing(); |
57
|
3 |
|
$entrySpacing = $this->bibliographyOptions->getEntrySpacing(); |
58
|
3 |
|
$hangingIndent = $this->bibliographyOptions->getHangingIndent(); |
59
|
|
|
|
60
|
3 |
|
if ($lineSpacing || $entrySpacing || $hangingIndent) { |
61
|
2 |
|
$rule = $this->cssRules->getRule(".csl-entry"); |
62
|
2 |
|
if (!empty($lineSpacing)) { |
63
|
|
|
$rule->addDirective("line-height", intval($lineSpacing) . "em"); |
64
|
|
|
} |
65
|
|
|
|
66
|
2 |
|
if (!empty($entrySpacing)) { |
67
|
|
|
$rule->addDirective("margin-bottom", intval($entrySpacing) . "em"); |
68
|
|
|
} |
69
|
|
|
|
70
|
2 |
|
if (!empty($hangingIndent)) { |
71
|
2 |
|
$rule->addDirective("padding-left", "2em"); |
72
|
2 |
|
$rule->addDirective("text-indent", "-2em"); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
3 |
|
if ("flush" === $this->bibliographyOptions->getSecondFieldAlign()) { |
77
|
1 |
|
$rule = $this->cssRules->getRule(".csl-left-margin"); |
78
|
1 |
|
$rule->addDirective("display", "block"); |
79
|
1 |
|
$rule->addDirective("float", "left"); |
80
|
|
|
|
81
|
1 |
|
$rule = $this->cssRules->getRule(".csl-right-inline"); |
82
|
1 |
|
$rule->addDirective("margin-left", "35px"); |
83
|
|
|
} |
84
|
3 |
|
} |
85
|
|
|
} |
86
|
|
|
|