1 | <?php |
||
15 | abstract class StyleHelperAbstract implements StyleHelperInterface |
||
16 | { |
||
17 | /** @var StyleManager Style manager */ |
||
18 | private $styleManager; |
||
19 | |||
20 | /** @var array [SERIALIZED_STYLE] => [STYLE_ID] mapping table, keeping track of the registered styles */ |
||
21 | protected $serializedStyleToStyleIdMappingTable = []; |
||
22 | |||
23 | /** @var array [STYLE_ID] => [STYLE] mapping table, keeping track of the registered styles */ |
||
24 | protected $styleIdToStyleMappingTable = []; |
||
25 | |||
26 | /** |
||
27 | * @param Style $defaultStyle |
||
28 | * @param StyleManager $styleManager |
||
29 | */ |
||
30 | 98 | public function __construct(Style $defaultStyle, StyleManager $styleManager) |
|
37 | |||
38 | /** |
||
39 | * Registers the given style as a used style. |
||
40 | * Duplicate styles won't be registered more than once. |
||
41 | * |
||
42 | * @param Style $style The style to be registered |
||
43 | * @return Style The registered style, updated with an internal ID. |
||
44 | */ |
||
45 | 98 | public function registerStyle($style) |
|
59 | |||
60 | /** |
||
61 | * Returns whether the given style has already been registered. |
||
62 | * |
||
63 | * @param Style $style |
||
64 | * @return bool |
||
65 | */ |
||
66 | 98 | protected function hasStyleAlreadyBeenRegistered($style) |
|
73 | |||
74 | /** |
||
75 | * Returns the registered style associated to the given serialization. |
||
76 | * |
||
77 | * @param string $serializedStyle The serialized style from which the actual style should be fetched from |
||
78 | * @return Style |
||
79 | */ |
||
80 | 98 | protected function getStyleFromSerializedStyle($serializedStyle) |
|
85 | |||
86 | /** |
||
87 | * @return Style[] List of registered styles |
||
88 | */ |
||
89 | 70 | protected function getRegisteredStyles() |
|
93 | |||
94 | /** |
||
95 | * Returns the default style |
||
96 | * |
||
97 | * @return Style Default style |
||
98 | */ |
||
99 | 34 | protected function getDefaultStyle() |
|
104 | |||
105 | /** |
||
106 | * Apply additional styles if the given row needs it. |
||
107 | * Typically, set "wrap text" if a cell contains a new line. |
||
108 | * |
||
109 | * @param Cell $cell |
||
110 | * @return Style |
||
111 | */ |
||
112 | 68 | public function applyExtraStylesIfNeeded(Cell $cell) |
|
117 | |||
118 | /** |
||
119 | * Set the "wrap text" option if a cell of the given row contains a new line. |
||
120 | * |
||
121 | * @NOTE: There is a bug on the Mac version of Excel (2011 and below) where new lines |
||
122 | * are ignored even when the "wrap text" option is set. This only occurs with |
||
123 | * inline strings (shared strings do work fine). |
||
124 | * A workaround would be to encode "\n" as "_x000D_" but it does not work |
||
125 | * on the Windows version of Excel... |
||
126 | * |
||
127 | * @param Cell $cell The cell the style should be applied to |
||
128 | * @return \Box\Spout\Writer\Common\Entity\Style\Style The eventually updated style |
||
129 | */ |
||
130 | 68 | protected function applyWrapTextIfCellContainsNewLine(Cell $cell) |
|
143 | } |
||
144 |