|
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
|
|
|
public function __construct(BibliographyOptions $bibliographyOptions) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->bibliographyOptions = $bibliographyOptions; |
|
38
|
|
|
$this->cssRules = new CssRules(); |
|
39
|
|
|
$this->init(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* renders CSS output |
|
|
|
|
|
|
44
|
|
|
* @return string |
|
|
|
|
|
|
45
|
|
|
*/ |
|
46
|
|
|
public function render() |
|
47
|
|
|
{ |
|
48
|
|
|
return implode("\n", $this->cssRules->toArray()); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* initialize CSS rules |
|
|
|
|
|
|
53
|
|
|
*/ |
|
|
|
|
|
|
54
|
|
|
private function init() |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
|
|
$lineSpacing = $this->bibliographyOptions->getLineSpacing(); |
|
57
|
|
|
$entrySpacing = $this->bibliographyOptions->getEntrySpacing(); |
|
58
|
|
|
$hangingIndent = $this->bibliographyOptions->getHangingIndent(); |
|
59
|
|
|
|
|
60
|
|
|
if ($lineSpacing || $entrySpacing || $hangingIndent) { |
|
61
|
|
|
$rule = $this->cssRules->getRule(".csl-entry"); |
|
62
|
|
|
if (!empty($lineSpacing)) { |
|
63
|
|
|
$rule->addDirective("line-height", intval($lineSpacing) . "em"); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
if (!empty($entrySpacing)) { |
|
67
|
|
|
$rule->addDirective("margin-bottom", intval($entrySpacing) . "em"); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if (!empty($hangingIndent)) { |
|
71
|
|
|
$rule->addDirective("padding-left", "2em"); |
|
72
|
|
|
$rule->addDirective("text-indent", "-2em"); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
if ("flush" === $this->bibliographyOptions->getSecondFieldAlign()) { |
|
77
|
|
|
$rule = $this->cssRules->getRule(".csl-left-margin"); |
|
78
|
|
|
$rule->addDirective("display", "block"); |
|
79
|
|
|
$rule->addDirective("float", "left"); |
|
80
|
|
|
|
|
81
|
|
|
$rule = $this->cssRules->getRule(".csl-right-inline"); |
|
82
|
|
|
$rule->addDirective("margin-left", "35px"); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|