| 23 |
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 columns.
|
|
|
10 |
*
|
|
|
11 |
* @author Issam RACHDI
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
class ColumnStyle extends ContentAutoStyle {
|
|
|
15 |
|
|
|
16 |
private $colProp;
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
*
|
|
|
20 |
* @param type $contentDoc
|
|
|
21 |
* @param type $name
|
|
|
22 |
*/
|
|
|
23 |
public function __construct($name) {
|
|
|
24 |
if (empty($name)) {
|
|
|
25 |
$name = 'columnstyle'.rand(100, 9999999);
|
|
|
26 |
}
|
|
|
27 |
parent::__construct($name);
|
|
|
28 |
$this->styleElement->setAttribute('style:family', 'table-column');
|
|
|
29 |
$this->colProp = $this->contentDocument->createElement('style:table-column-properties');
|
|
|
30 |
$this->styleElement->appendChild($this->colProp);
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Sets the width of the table.
|
|
|
35 |
*
|
|
|
36 |
* @param length|percentage $width
|
|
|
37 |
*/
|
|
|
38 |
public function setWidth($width) {
|
|
|
39 |
if (isLengthValue($width, true) || isPercentage($width)) {
|
|
|
40 |
if (isLengthValue($width, true)) {
|
|
|
41 |
$this->colProp->setAttribute('style:column-width', $width);
|
|
|
42 |
} else if (isPercentage($width)){
|
|
|
43 |
$this->colProp->setAttribute('style:rel-column-width', $width);
|
|
|
44 |
}
|
|
|
45 |
} else {
|
|
|
46 |
throw new StyleException('Invalid table-width value');
|
|
|
47 |
}
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* Specifies if the column width should be recalculated automatically if some content in the column changes.
|
|
|
52 |
*
|
|
|
53 |
* @param boolean $optimal
|
|
|
54 |
*/
|
|
|
55 |
public function setOptimalWidth($optimalWidth) {
|
|
|
56 |
if (is_bool($optimalWidth)) {
|
|
|
57 |
$this->colProp->setAttribute('style:use-optimal-column-width', $optimalWidth);
|
|
|
58 |
} else {
|
|
|
59 |
throw new StyleException('Value must be boolean');
|
|
|
60 |
}
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
/**
|
|
|
64 |
* Insert a page or column break before a table column.
|
|
|
65 |
*
|
|
|
66 |
* @param integer $breakBefore Possible values: StyleConstants::(PAGE|COLUMN)
|
|
|
67 |
*/
|
|
|
68 |
function setBreakBefore($breakBefore) {
|
|
|
69 |
switch ($breakBefore) {
|
|
|
70 |
case StyleConstants::PAGE:
|
|
|
71 |
$breakBefore = 'page';break;
|
|
|
72 |
case StyleConstants::COLUMN:
|
|
|
73 |
$breakBefore = 'column';break;
|
|
|
74 |
default:
|
|
|
75 |
throw new StyleException('Invalid break-before value.');
|
|
|
76 |
}
|
|
|
77 |
$this->colProp->setAttribute('fo:break-before', $breakBefore);
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
/**
|
|
|
81 |
* Insert a page or column break after a table column
|
|
|
82 |
*
|
|
|
83 |
* @param integer $breakAfter Possible values: StyleConstants::(PAGE|COLUMN)
|
|
|
84 |
*/
|
|
|
85 |
function setBreakAfter($breakAfter) {
|
|
|
86 |
switch ($breakAfter) {
|
|
|
87 |
case StyleConstants::PAGE:
|
|
|
88 |
$breakAfter = 'page';break;
|
|
|
89 |
case StyleConstants::COLUMN:
|
|
|
90 |
$breakAfter = 'column';break;
|
|
|
91 |
default:
|
|
|
92 |
throw new StyleException('Invalid break-after value.');
|
|
|
93 |
}
|
|
|
94 |
$this->colProp->setAttribute('fo:break-after', $breakAfter);
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
?>
|