| 1 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
//require_once 'class.contentautostyle.php';
|
|
|
4 |
//require_once 'exceptions/class.styleexception.php';
|
|
|
5 |
|
|
|
6 |
include_once 'phpodt.php';
|
|
|
7 |
|
|
|
8 |
/**
|
|
|
9 |
* A Class representing style properties for table rows.
|
|
|
10 |
*
|
|
|
11 |
* @author Issam RACHDI
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
class RowStyle extends ContentAutoStyle {
|
|
|
15 |
|
|
|
16 |
private $rowProp;
|
|
|
17 |
|
|
|
18 |
public function __construct($name) {
|
|
|
19 |
if (empty($name)) {
|
|
|
20 |
$name = 'rowstyle'.rand(100, 9999999);
|
|
|
21 |
}
|
|
|
22 |
parent::__construct($name);
|
|
|
23 |
$this->styleElement->setAttribute('style:family', 'table-row');
|
|
|
24 |
$this->rowProp = $this->contentDocument->createElement('style:table-row-properties');
|
|
|
25 |
$this->styleElement->appendChild($this->rowProp);
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
public function setMinHeight($minHeight) {
|
|
|
30 |
if(isLengthValue($minHeight, true)) {
|
|
|
31 |
$this->rowProp->setAttribute('style:min-row-height', $minHeight);
|
|
|
32 |
} else {
|
|
|
33 |
throw new StyleException('Invalid min-height value');
|
|
|
34 |
}
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
public function setHeight($height) {
|
|
|
38 |
if(isLengthValue($height, true)) {
|
|
|
39 |
$this->rowProp->setAttribute('style:row-height', $height);
|
|
|
40 |
} else {
|
|
|
41 |
throw new StyleException('Invalid height value');
|
|
|
42 |
}
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
/**
|
|
|
46 |
* Specifies if the row height should be recalculated automatically
|
|
|
47 |
* if some content in the row changes.
|
|
|
48 |
*
|
|
|
49 |
* @param type $optimalHeight
|
|
|
50 |
*/
|
|
|
51 |
public function setOptimalHeight($optimalHeight) {
|
|
|
52 |
if(is_bool($optimalHeight)) {
|
|
|
53 |
$this->rowProp->setAttribute('style:use-optimal-row-height', $optimalHeight);
|
|
|
54 |
} else {
|
|
|
55 |
throw new StyleException('Value is not boolean');
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
/**
|
|
|
60 |
* Sets the background color of the row
|
|
|
61 |
*
|
|
|
62 |
* @param color $color
|
|
|
63 |
*/
|
|
|
64 |
public function setBgColor($color) {
|
|
|
65 |
if (!isColor($color)) {
|
|
|
66 |
throw new StyleException('Invalid color value');
|
|
|
67 |
}
|
|
|
68 |
$this->rowProp->setAttribute('fo:background-color', $color);
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
/**
|
|
|
72 |
* Specifies a background image for a row. Note that if you specify the position, the image
|
|
|
73 |
* will not be repeated
|
|
|
74 |
*
|
|
|
75 |
* @param string $image The image's path.
|
|
|
76 |
* @param integer $repeat Specifies whether the background image is repeated or stretched.
|
|
|
77 |
* @param integer $position Specifies where to position the background image.
|
|
|
78 |
* Valid values are StyleConstants::(LEFT|RIGHT|CENTER|TOP|BOTTOM)
|
|
|
79 |
*/
|
|
|
80 |
//vertical and horizontal can be merged it seems, à revoir
|
|
|
81 |
public function setBgImage($image, $repeat = StyleConstants::REPEAT,
|
|
|
82 |
$position = -1) {
|
|
|
83 |
$file = fopen($image, 'r');
|
|
|
84 |
if (!$file) {
|
|
|
85 |
throw new StyleException('Cannot open image');
|
|
|
86 |
}
|
|
|
87 |
switch($repeat) {
|
|
|
88 |
case StyleConstants::REPEAT:
|
|
|
89 |
$repeat = 'repeat';break;
|
|
|
90 |
case StyleConstants::NO_REPEAT:
|
|
|
91 |
$repeat = 'no-repeat';break;
|
|
|
92 |
case StyleConstants::STRETCH:
|
|
|
93 |
$repeat = 'stretch';break;
|
|
|
94 |
default:
|
|
|
95 |
throw new StyleException('Invalid repeat value');
|
|
|
96 |
}
|
|
|
97 |
switch($position) {
|
|
|
98 |
case -1:
|
|
|
99 |
break;
|
|
|
100 |
case StyleConstants::LEFT:
|
|
|
101 |
$position = 'left';break;
|
|
|
102 |
case StyleConstants::RIGHT:
|
|
|
103 |
$position = 'right';break;
|
|
|
104 |
case StyleConstants::CENTER:
|
|
|
105 |
$position = 'center';break;
|
|
|
106 |
case StyleConstants::TOP:
|
|
|
107 |
$position = 'top';break;
|
|
|
108 |
case StyleConstants::BOTTOM:
|
|
|
109 |
$position = 'left';break;
|
|
|
110 |
default:
|
|
|
111 |
throw new StyleException('Invalid background-position value');
|
|
|
112 |
}
|
|
|
113 |
$dataImg = fread($file, filesize($image));
|
|
|
114 |
$dateImgB64 = base64_encode($dataImg);
|
|
|
115 |
fclose($file);
|
|
|
116 |
$binaryElement = $this->contentDocument->createElement('office:binary-data', $dateImgB64);
|
|
|
117 |
$imageElement = $this->contentDocument->createElement('style:background-image');
|
|
|
118 |
$imageElement->setAttribute('style:repeat', $repeat);
|
|
|
119 |
if ($position != -1) {
|
|
|
120 |
$imageElement->setAttribute('style:position', $position);
|
|
|
121 |
}
|
|
|
122 |
$imageElement->appendChild($binaryElement);
|
|
|
123 |
$this->rowProp->appendChild($imageElement);
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
/**
|
|
|
127 |
* Insert a page or column break before a table column
|
|
|
128 |
*
|
|
|
129 |
*/
|
|
|
130 |
// function setBreakBefore($breakBefore) {
|
|
|
131 |
// switch ($breakBefore) {
|
|
|
132 |
// case StyleConstants::PAGE:
|
|
|
133 |
// $breakBefore = 'page';break;
|
|
|
134 |
// case StyleConstants::COLUMN:
|
|
|
135 |
// $breakBefore = 'column';break;
|
|
|
136 |
// default:
|
|
|
137 |
// throw new StyleException('Invalid break-before value.');
|
|
|
138 |
// }
|
|
|
139 |
// $this->rowProp->setAttribute('fo:break-before', $breakBefore);
|
|
|
140 |
// }
|
|
|
141 |
|
|
|
142 |
/**
|
|
|
143 |
* Insert a page or column break after a table column
|
|
|
144 |
*
|
|
|
145 |
*/
|
|
|
146 |
// function setBreakAfter($breakAfter) {
|
|
|
147 |
// switch ($breakAfter) {
|
|
|
148 |
// case StyleConstants::PAGE:
|
|
|
149 |
// $breakAfter = 'page';break;
|
|
|
150 |
// case StyleConstants::COLUMN:
|
|
|
151 |
// $breakAfter = 'column';break;
|
|
|
152 |
// default:
|
|
|
153 |
// throw new StyleException('Invalid break-after value.');
|
|
|
154 |
// }
|
|
|
155 |
// $this->rowProp->setAttribute('fo:break-after', $breakAfter);
|
|
|
156 |
// }
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
?>
|