| 23 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
//require_once 'class.contentautostyle.php';
|
|
|
4 |
//require_once 'class.numberformat.php';
|
|
|
5 |
//require_once 'class.listlevelprop.php';
|
|
|
6 |
|
|
|
7 |
include_once 'phpodt.php';
|
|
|
8 |
|
|
|
9 |
/**
|
|
|
10 |
* A Class representing a list style.
|
|
|
11 |
*
|
|
|
12 |
* @author Issam RACHDI
|
|
|
13 |
*/
|
|
|
14 |
|
|
|
15 |
class ListStyle extends ContentAutoStyle {
|
|
|
16 |
|
|
|
17 |
private $levels;
|
|
|
18 |
const INDENT = 0.5;
|
|
|
19 |
const LABEL_DISTANCE = 0.5;
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
function __construct($name) {
|
|
|
23 |
if (empty($name)) {
|
|
|
24 |
$name = 'liststyle'.rand(100, 9999999);
|
|
|
25 |
}
|
|
|
26 |
parent::__construct($name, 'text:list-style');
|
|
|
27 |
$this->levels = array();
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* Specifies that the list in this level is a numbered list.
|
|
|
32 |
*
|
|
|
33 |
* @param integer $level
|
|
|
34 |
* @param {@link NumberFormat.html NumberFormat} $numFormat
|
|
|
35 |
* @param {@link TextStyle.html TextStyle} $textstyle The style to apply to the numbers
|
|
|
36 |
*/
|
|
|
37 |
function setNumberLevel($level, $numFormat = NULL, $textstyle = NULL) {
|
|
|
38 |
if (isNumeric($level, true)) {
|
|
|
39 |
$this->levels[$level] = $this->contentDocument->createElement('text:list-level-style-number');
|
|
|
40 |
$this->levels[$level]->setAttribute('text:level', $level);
|
|
|
41 |
if ($numFormat != NULL) {
|
|
|
42 |
$this->levels[$level]->setAttribute('style:num-format', $numFormat->getFormat());
|
|
|
43 |
$this->levels[$level]->setAttribute('style:num-prefix', $numFormat->getPrefix());
|
|
|
44 |
$this->levels[$level]->setAttribute('style:num-suffix', $numFormat->getSuffix());
|
|
|
45 |
}
|
|
|
46 |
if ($textstyle != NULL) {
|
|
|
47 |
$this->levels[$level]->setAttribute('text:style-name', $textstyle->getStyleName());
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
$this->styleElement->appendChild($this->levels[$level]);
|
|
|
51 |
|
|
|
52 |
$listLevelProp = new ListLevelProp();
|
|
|
53 |
$listLevelProp->setIndent(($level*self::INDENT).'cm');
|
|
|
54 |
$listLevelProp->setMinLabelDistance(self::LABEL_DISTANCE.'cm');
|
|
|
55 |
$this->setLevelProp($level, $listLevelProp);
|
|
|
56 |
} else {
|
|
|
57 |
throw new StyleException('Invalid level value');
|
|
|
58 |
}
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
/**
|
|
|
62 |
* Specifies that the list in this level is a bullet list.
|
|
|
63 |
*
|
|
|
64 |
* @param integer $level
|
|
|
65 |
* @param string $bulletChar The character to use as the bullet, may be StyleConstants::(BULLET|BLACK_CIRCLE|CHECK_MARK|RIGHT_ARROW|RIGHT_ARROWHEAD)
|
|
|
66 |
* @param string $prefix The characters to add before the bullet character.
|
|
|
67 |
* @param string $suffix The characters to add behind the bullet character.
|
|
|
68 |
* @param {@link TextStyle.html TextStyle} $textstyle The style to use to format the list bullet.
|
|
|
69 |
|
|
|
70 |
*/
|
|
|
71 |
function setBulletLevel($level, $bulletChar = StyleConstants::BULLET, $prefix = '', $suffix = '',
|
|
|
72 |
$textstyle = NULL) {
|
|
|
73 |
if (isNumeric($level, true)) {
|
|
|
74 |
$this->levels[$level] = $this->contentDocument->createElement('text:list-level-style-bullet');
|
|
|
75 |
$this->levels[$level]->setAttribute('text:level', $level);
|
|
|
76 |
switch ($bulletChar) {
|
|
|
77 |
case StyleConstants::BULLET:
|
|
|
78 |
case StyleConstants::BLACK_CIRCLE:
|
|
|
79 |
case StyleConstants::CHECK_MARK:
|
|
|
80 |
case StyleConstants::RIGHT_ARROW:
|
|
|
81 |
case StyleConstants::RIGHT_ARROWHEAD:
|
|
|
82 |
$this->levels[$level]->setAttribute('text:bullet-char', $bulletChar);break;
|
|
|
83 |
default:
|
|
|
84 |
throw new StyleException('Invalid bullet character value');
|
|
|
85 |
}
|
|
|
86 |
if ($textstyle != NULL) {
|
|
|
87 |
$this->levels[$level]->setAttribute('text:style-name', $textstyle->getStyleName());
|
|
|
88 |
}
|
|
|
89 |
$this->levels[$level]->setAttribute('style:num-prefix', $prefix);
|
|
|
90 |
$this->levels[$level]->setAttribute('style:num-suffix', $suffix);
|
|
|
91 |
|
|
|
92 |
$this->styleElement->appendChild($this->levels[$level]);
|
|
|
93 |
|
|
|
94 |
$listLevelProp = new ListLevelProp();
|
|
|
95 |
$listLevelProp->setIndent(($level*self::INDENT).'cm');
|
|
|
96 |
$listLevelProp->setMinLabelDistance(self::LABEL_DISTANCE.'cm');
|
|
|
97 |
$this->setLevelProp($level, $listLevelProp);
|
|
|
98 |
} else {
|
|
|
99 |
throw new StyleException('Invalid level value');
|
|
|
100 |
}
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
/**
|
|
|
104 |
* The list items in this level will be preceded by images.
|
|
|
105 |
*
|
|
|
106 |
* @param integer $level
|
|
|
107 |
* @param string $image The image's location.
|
|
|
108 |
*/
|
|
|
109 |
function setImageLevel($level, $image, $width = '.5cm', $height = '.5cm') {
|
|
|
110 |
if (isNumeric($level, true)) {
|
|
|
111 |
$this->levels[$level] = $this->contentDocument->createElement('text:list-level-style-image');
|
|
|
112 |
$this->levels[$level]->setAttribute('text:level', $level);
|
|
|
113 |
$file = fopen($image, 'r');
|
|
|
114 |
if (!$file) {
|
|
|
115 |
throw new StyleException('Failed to open image file');
|
|
|
116 |
}
|
|
|
117 |
$dataImg = fread($file, filesize($image));
|
|
|
118 |
$dateImgB64 = base64_encode($dataImg);
|
|
|
119 |
fclose($file);
|
|
|
120 |
$binaryElement = $this->contentDocument->createElement('office:binary-data', $dateImgB64);
|
|
|
121 |
$this->levels[$level]->appendChild($binaryElement);
|
|
|
122 |
|
|
|
123 |
$this->styleElement->appendChild($this->levels[$level]);
|
|
|
124 |
|
|
|
125 |
$listLevelProp = new ListLevelProp();
|
|
|
126 |
$listLevelProp->setIndent(($level*self::INDENT).'cm');
|
|
|
127 |
$listLevelProp->setMinLabelDistance(self::LABEL_DISTANCE.'cm');
|
|
|
128 |
$listLevelProp->setImageWidth($width);
|
|
|
129 |
$listLevelProp->setImageHeight($height);
|
|
|
130 |
$this->setLevelProp($level, $listLevelProp);
|
|
|
131 |
} else {
|
|
|
132 |
throw new StyleException('Invalid level value');
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
/**
|
|
|
137 |
* Set some properties of the list level specified.
|
|
|
138 |
*
|
|
|
139 |
* @param integer $level
|
|
|
140 |
* @param {@link ListLevelProp.html ListLevelProp} $levelProp
|
|
|
141 |
*/
|
|
|
142 |
function setLevelProp($level, $levelProp) {
|
|
|
143 |
if (isNumeric($level, true)) {
|
|
|
144 |
$element = $this->levels[$level];
|
|
|
145 |
$prop = $this->contentDocument->createElement('style:list-level-properties');
|
|
|
146 |
|
|
|
147 |
if ($levelProp->getAlign() != NULL) {
|
|
|
148 |
$prop->setAttribute('fo:text-align', $levelProp->getAlign());
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
if ($levelProp->getIndent() == NULL) {
|
|
|
152 |
$indent = ($level * 0.5).'cm';
|
|
|
153 |
} else {
|
|
|
154 |
$indent = $levelProp->getIndent();
|
|
|
155 |
}
|
|
|
156 |
$prop->setAttribute('text:space-before', $indent);
|
|
|
157 |
|
|
|
158 |
if ($levelProp->getMinLabelWidth() != NULL) {
|
|
|
159 |
$prop->setAttribute('text:min-label-width', $levelProp->getMinLabelWidth());
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
if ($levelProp->getMinLabelDistance() != NULL) {
|
|
|
163 |
$prop->setAttribute('text:min-label-distance', $levelProp->getMinLabelDistance());
|
|
|
164 |
}
|
|
|
165 |
if ($levelProp->getVAlign() != NULL) {
|
|
|
166 |
$prop->setAttribute('style:vertical-pos', $levelProp->getVAlign());break;
|
|
|
167 |
}
|
|
|
168 |
if ($levelProp->getImageWidth() != NULL) {
|
|
|
169 |
$prop->setAttribute('fo:width', $levelProp->getImageWidth());
|
|
|
170 |
}
|
|
|
171 |
if ($levelProp->getImageHeight() != NULL) {
|
|
|
172 |
$prop->setAttribute('fo:height', $levelProp->getImageHeight());
|
|
|
173 |
}
|
|
|
174 |
$element->appendChild($prop);
|
|
|
175 |
}
|
|
|
176 |
}
|
|
|
177 |
}
|
|
|
178 |
?>
|