1<?php 2/** 3 * ODTUnknownStyle: class for unknown/not implemented ODT style families. 4 * The goal is to at least read in not supported style faimlies and return 5 * the original content on a call to toString(). 6 * 7 * The following has to be taken into account: 8 * - the properties of an ODTUnknownStyle can not be changed. 9 * - so setProperty() and importProperties() will do nothing. 10 * 11 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 12 * @author LarsDW223 13 */ 14 15require_once DOKU_INC.'lib/plugins/odt/ODT/styles/ODTStyle.php'; 16 17/** 18 * The ODTUnknownStyle class 19 */ 20class ODTUnknownStyle extends ODTStyle 21{ 22 // At least try to read in a name 23 static $unknown_fields = array( 24 'style-name' => array ('style:name', 'style', false), 25 'style-family' => array ('style:family', 'style', false), 26 ); 27 protected $element_name = NULL; 28 protected $style_content = NULL; 29 30 /** 31 * Get the element name for the ODT XML encoding of the style. 32 * 33 * @return string The element name 34 */ 35 public function getElementName() { 36 return ($this::element_name); 37 } 38 39 /** 40 * Set the element name. 41 * 42 * @param $element_name The element name to set 43 */ 44 public function setElementName($element_name) { 45 $this->element_name = $element_name; 46 } 47 48 /** 49 * Set style properties by importing values from a properties array. 50 * Properties might be disabled by setting them in $disabled. 51 * The style must have been previously created. 52 * 53 * Not supported, just a dummy! 54 * 55 * @param $properties Properties to be imported 56 * @param $disabled Properties to be ignored 57 */ 58 public function importProperties($properties, $disabled=array()) { 59 } 60 61 /** 62 * Check if a style is a common style. 63 * 64 * @return bool Is common style 65 */ 66 public function mustBeCommonStyle() { 67 return false; 68 } 69 70 /** 71 * Set a property. 72 * 73 * Not supported, just a dummy. 74 * 75 * @param $property The name of the property to set 76 * @param $value New value to set 77 */ 78 public function setProperty($property, $value) { 79 } 80 81 /** 82 * Set style content. This will be returned on toString(). 83 * 84 * @param $style_content The complete ODT XML style definition. 85 */ 86 public function setStyleContent($style_content) { 87 $this->importODTStyleInternal(self::$unknown_fields, $style_content); 88 $this->style_content = $style_content."\n"; 89 } 90 91 /** 92 * Create new style by importing ODT style definition. 93 * 94 * @param $xmlCode Style definition in ODT XML format 95 * @return ODTStyle New specific style 96 */ 97 static public function importODTStyle($xmlCode) { 98 $style = new ODTUnknownStyle(); 99 $style->setStyleContent($xmlCode); 100 return $style; 101 } 102 103 /** 104 * Encode current style values in a string and return it. 105 * 106 * @return string ODT XML encoded style 107 */ 108 public function toString() { 109 return $this->style_content; 110 } 111 112 /** 113 * Is the style a default style? 114 * 115 * @return boolean Is default. 116 */ 117 public function isDefault() { 118 if ($this->element_name == 'style:default-style') { 119 return true; 120 } 121 return false; 122 } 123 124 /** 125 * Get the style family of a style. 126 * 127 * @return string|NULL Style family 128 */ 129 public function getFamily() { 130 return $this->getProperty('style-family'); 131 } 132 133 /** 134 * The function deletes all properties that do not belong to the styles section, 135 * e.g. text properties or paragraph properties. 136 * For unknown styles this is just a dummy doing nothing. 137 */ 138 public function clearLayoutProperties() { 139 } 140 141 /** 142 * This function creates a frame style for multiple columns, using the style as set in the assoziative array $properties. 143 * The parameters in the array should be named as the CSS property names e.g. 'color' or 'background-color'. 144 * Properties which shall not be used in the style can be disabled by setting the value in disabled_props 145 * to 1 e.g. $disabled_props ['color'] = 1 would block the usage of the color property. 146 * 147 * The currently supported properties are: 148 * column-count, column-rule, column-gap 149 * 150 * The function returns the name of the new style or NULL if all relevant properties are empty. 151 * 152 * @author LarsDW223 153 * 154 * @param $style 155 * @param $properties 156 * @param null $disabled_props 157 * @return ODTUnknownStyle or NULL 158 */ 159 public static function createMultiColumnFrameStyle(array $properties, array $disabled_props = NULL) { 160 $attrs = 0; 161 162 $columns = ''; 163 if ( empty ($disabled_props ['column-count']) ) { 164 $columns = $properties ['column-count']; 165 $attrs++; 166 } 167 168 $rule_width = ''; 169 if ( empty ($disabled_props ['column-rule-width']) ) { 170 $rule_width = $properties ['column-rule-width']; 171 $attrs++; 172 } 173 174 $rule_style = ''; 175 if ( empty ($disabled_props ['column-rule-style']) ) { 176 $rule_style = $properties ['column-rule-style']; 177 $attrs++; 178 } 179 180 $rule_color = ''; 181 if ( empty ($disabled_props ['column-rule-color']) ) { 182 $rule_color = $properties ['column-rule-color']; 183 $attrs++; 184 } 185 186 $gap = ''; 187 if ( empty ($disabled_props ['column-gap']) ) { 188 $gap = $properties ['column-gap']; 189 $attrs++; 190 } 191 192 // If all relevant properties are empty or disabled, then there 193 // are no attributes for our style. Return NULL to indicate 'no style required'. 194 if ( $attrs == 0 ) { 195 return NULL; 196 } 197 198 // Create style name (if not given). 199 $style_name = $properties ['style-name']; 200 if ( empty($style_name) ) { 201 $style_name = self::getNewStylename ('Frame'); 202 $properties ['style-name'] = $style_name; 203 } 204 205 $width = '1000*'; 206 207 $style = '<style:style style:name="'.$style_name.'" style:family="graphic" style:parent-style-name="Frame"> 208 <style:graphic-properties fo:border="none" style:vertical-pos="top" style:vertical-rel="paragraph-content" style:horizontal-pos="center" style:horizontal-rel="paragraph"> 209<style:columns fo:column-count="'.$columns.'" fo:column-gap="'.$gap.'"> 210<style:column-sep style:style="'.$rule_style.'" style:color="'.$rule_color.'" style:width="'.$rule_width.'"/> 211<style:column style:rel-width="'.$width.'" fo:start-indent="0cm" fo:end-indent="0cm"/> 212<style:column style:rel-width="'.$width.'" fo:start-indent="0cm" fo:end-indent="0cm"/> 213<style:column style:rel-width="'.$width.'" fo:start-indent="0cm" fo:end-indent="0cm"/> 214</style:columns> 215</style:graphic-properties></style:style>'; 216 217 // Create empty frame style. 218 // Not supported yet, so we create an "unknown" style 219 $object = new ODTUnknownStyle(); 220 if (!isset($object)) { 221 return NULL; 222 } 223 $object->setStyleContent($style); 224 225 return $object; 226 } 227} 228