1<?php 2/** 3 * Helper class for creating ODT styles. 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author LarsDW223 7 */ 8 9// must be run within Dokuwiki 10if (!defined('DOKU_INC')) die(); 11 12require_once DOKU_INC.'lib/plugins/odt/ODT/styles/ODTTextStyle.php'; 13require_once DOKU_INC.'lib/plugins/odt/ODT/styles/ODTParagraphStyle.php'; 14require_once DOKU_INC.'lib/plugins/odt/ODT/styles/ODTTableStyle.php'; 15require_once DOKU_INC.'lib/plugins/odt/ODT/styles/ODTTableRowStyle.php'; 16require_once DOKU_INC.'lib/plugins/odt/ODT/styles/ODTTableColumnStyle.php'; 17require_once DOKU_INC.'lib/plugins/odt/ODT/styles/ODTTableCellStyle.php'; 18 19/** 20 * Class helper_plugin_odt_stylefactory 21 * 22 * @package helper\stylefactory 23 */ 24class helper_plugin_odt_stylefactory extends DokuWiki_Plugin { 25 protected static $style_base_name = 'PluginODTAutoStyle_'; 26 protected static $style_count = 0; 27 28 /** 29 * @return array 30 */ 31 function getMethods() { 32 $result = array(); 33 $result[] = array( 34 'name' => 'createTextStyle', 35 'desc' => 'Returns ODT text style definition in $style with the wanted properties. Returns NULL, if no relevant properties were found, otherwise the new style name.', 36 'params' => array('$style' => 'string', 37 '$properties' => 'array', 38 '$disabled_props' => 'array', 39 '$parent' => 'string'), 40 'return' => array('ODT text style name' => 'string'), 41 ); 42 $result[] = array( 43 'name' => 'createParagraphStyle', 44 'desc' => 'Returns ODT paragrap style definition in $style with the wanted properties. Returns NULL, if no relevant properties were found, otherwise the new style name.', 45 'params' => array('$style' => 'string', 46 '$properties' => 'array', 47 '$disabled_props' => 'array', 48 '$parent' => 'string'), 49 'return' => array('ODT paragraph style name' => 'string'), 50 ); 51 $result[] = array( 52 'name' => 'createTableTableStyle', 53 'desc' => 'Returns ODT table style definition in $style with the wanted properties. Returns NULL, if no relevant properties were found, otherwise the new style name.', 54 'params' => array('$style' => 'string', 55 '$properties' => 'array', 56 '$disabled_props' => 'array', 57 '$max_width_cm' => 'integer'), 58 'return' => array('ODT table style name' => 'string'), 59 ); 60 $result[] = array( 61 'name' => 'createTableRowStyle', 62 'desc' => 'Returns ODT table row style definition in $style with the wanted properties. Returns NULL, if no relevant properties were found, otherwise the new style name.', 63 'params' => array('$style' => 'string', 64 '$properties' => 'array', 65 '$disabled_props' => 'array'), 66 'return' => array('ODT table row style name' => 'string'), 67 ); 68 $result[] = array( 69 'name' => 'createTableCellStyle', 70 'desc' => 'Returns ODT table cell style definition in $style with the wanted properties. Returns NULL, if no relevant properties were found, otherwise the new style name.', 71 'params' => array('$style' => 'string', 72 '$properties' => 'array', 73 '$disabled_props' => 'array'), 74 'return' => array('ODT table cell style name' => 'string'), 75 ); 76 $result[] = array( 77 'name' => 'createTableColumnStyle', 78 'desc' => 'Returns ODT table column style definition in $style with the wanted properties. Returns NULL, if no relevant properties were found, otherwise the new style name.', 79 'params' => array('$style' => 'string', 80 '$properties' => 'array', 81 '$disabled_props' => 'array'), 82 'return' => array('ODT table column style name' => 'string'), 83 ); 84 return $result; 85 } 86 87 /** 88 * This function creates a text style using the style as set in the assoziative array $properties. 89 * The parameters in the array should be named as the CSS property names e.g. 'color' or 'background-color'. 90 * Properties which shall not be used in the style can be disabled by setting the value in disabled_props 91 * to 1 e.g. $disabled_props ['color'] = 1 would block the usage of the color property. 92 * 93 * The currently supported properties are: 94 * background-color, color, font-style, font-weight, font-size, border, font-family, font-variant, letter-spacing, 95 * vertical-align, background-image 96 * 97 * The function returns the name of the new style or NULL if all relevant properties are empty. 98 * 99 * @author LarsDW223 100 * @param $properties 101 * @param null $disabled_props 102 * @return ODTTextStyle or NULL 103 */ 104 public static function createTextStyle(array $properties, array $disabled_props = NULL){ 105 return ODTTextStyle::createTextStyle($properties, $disabled_props); 106 } 107 108 /** 109 * This function creates a paragraph style using the style as set in the assoziative array $properties. 110 * The parameters in the array should be named as the CSS property names e.g. 'color' or 'background-color'. 111 * Properties which shall not be used in the style can be disabled by setting the value in disabled_props 112 * to 1 e.g. $disabled_props ['color'] = 1 would block the usage of the color property. 113 * 114 * The currently supported properties are: 115 * background-color, color, font-style, font-weight, font-size, border, font-family, font-variant, letter-spacing, 116 * vertical-align, line-height, background-image 117 * 118 * The function returns the name of the new style or NULL if all relevant properties are empty. 119 * 120 * @author LarsDW223 121 * @param $properties 122 * @param null $disabled_props 123 * @return ODTParagraphStyle or NULL 124 */ 125 public static function createParagraphStyle(array $properties, array $disabled_props = NULL){ 126 return ODTParagraphStyle::createParagraphStyle($properties, $disabled_props); 127 } 128 129 /** 130 * This function creates a table table style using the style as set in the assoziative array $properties. 131 * The parameters in the array should be named as the CSS property names e.g. 'color' or 'background-color'. 132 * Properties which shall not be used in the style can be disabled by setting the value in disabled_props 133 * to 1 e.g. $disabled_props ['color'] = 1 would block the usage of the color property. 134 * 135 * The currently supported properties are: 136 * width, border-collapse, background-color 137 * 138 * The function returns the name of the new style or NULL if all relevant properties are empty. 139 * 140 * @author LarsDW223 141 * @param $properties 142 * @param null $disabled_props 143 * @param int $max_width_cm 144 * @return ODTTableStyle or NULL 145 */ 146 public static function createTableTableStyle(array $properties, array $disabled_props = NULL, $max_width_cm = 17){ 147 return ODTTableStyle::createTableTableStyle($properties, $disabled_props, $max_width_cm); 148 } 149 150 /** 151 * This function creates a table row style using the style as set in the assoziative array $properties. 152 * The parameters in the array should be named as the CSS property names e.g. 'color' or 'background-color'. 153 * Properties which shall not be used in the style can be disabled by setting the value in disabled_props 154 * to 1 e.g. $disabled_props ['color'] = 1 would block the usage of the color property. 155 * 156 * The currently supported properties are: 157 * height, background-color 158 * 159 * The function returns the name of the new style or NULL if all relevant properties are empty. 160 * 161 * @author LarsDW223 162 * @param $properties 163 * @param null $disabled_props 164 * @return ODTTableRowStyle 165 */ 166 public static function createTableRowStyle(array $properties, array $disabled_props = NULL){ 167 return ODTTableRowStyle::createTableRowStyle($properties, $disabled_props); 168 } 169 170 /** 171 * This function creates a table cell style using the style as set in the assoziative array $properties. 172 * The parameters in the array should be named as the CSS property names e.g. 'color' or 'background-color'. 173 * Properties which shall not be used in the style can be disabled by setting the value in disabled_props 174 * to 1 e.g. $disabled_props ['color'] = 1 would block the usage of the color property. 175 * 176 * The currently supported properties are: 177 * background-color, vertical-align 178 * 179 * The function returns the name of the new style or NULL if all relevant properties are empty. 180 * 181 * @author LarsDW223 182 * @param $properties 183 * @param null $disabled_props 184 * @return ODTTableCellStyle or NULL 185 */ 186 public static function createTableCellStyle(array $properties, array $disabled_props = NULL){ 187 return ODTTableCellStyle::createTableCellStyle($properties, $disabled_props); 188 } 189 190 /** 191 * This function creates a table column style using the style as set in the assoziative array $properties. 192 * The parameters in the array should be named as the CSS property names e.g. 'color' or 'background-color'. 193 * Properties which shall not be used in the style can be disabled by setting the value in disabled_props 194 * to 1 e.g. $disabled_props ['color'] = 1 would block the usage of the color property. 195 * 196 * The currently supported properties are: 197 * width 198 * 199 * The function returns the name of the new style or NULL if all relevant properties are empty. 200 * 201 * @author LarsDW223 202 * 203 * @param $style 204 * @param $properties 205 * @param null $disabled_props 206 * @param null $style_name 207 * @return ODTUnknownStyle or NULL 208 */ 209 public static function createTableColumnStyle(array $properties, array $disabled_props = NULL){ 210 return ODTTableColumnStyle::createTableColumnStyle($properties, $disabled_props); 211 } 212 213 /** 214 * This function creates a frame style for multiple columns, using the style as set in the assoziative array $properties. 215 * The parameters in the array should be named as the CSS property names e.g. 'color' or 'background-color'. 216 * Properties which shall not be used in the style can be disabled by setting the value in disabled_props 217 * to 1 e.g. $disabled_props ['color'] = 1 would block the usage of the color property. 218 * 219 * The currently supported properties are: 220 * column-count, column-rule, column-gap 221 * 222 * The function returns the name of the new style or NULL if all relevant properties are empty. 223 * 224 * @author LarsDW223 225 * 226 * @param $style 227 * @param $properties 228 * @param null $disabled_props 229 * @return ODTUnknownStyle or NULL 230 */ 231 public static function createMultiColumnFrameStyle(array $properties, array $disabled_props = NULL) { 232 return ODTUnknownStyle::createMultiColumnFrameStyle($properties, $disabled_props); 233 } 234 235 /** 236 * This function creates a page layout style with the parameters given in $properies. 237 * 238 * The currently supported properties are: 239 * style-name, width, height, margin-top, margin-bottom, margin-right and margin-left. 240 * All properties except the style-name are expected to be numeric values. 241 * The function will add 'cm' itself, so do not add any units. 242 * 243 * The function returns the name of the new style or NULL if all relevant properties are empty. 244 * 245 * @author LarsDW223 246 * 247 * @param $properties 248 * @param null $disabled_props 249 * @return ODTUnknownStyle or NULL 250 */ 251 public static function createPageLayoutStyle(array $properties, array $disabled_props = NULL) { 252 return ODTUnknownStyle::createPageLayoutStyle($properties, $disabled_props); 253 } 254 255 /** 256 * Simple helper function for creating a text style $name setting the specfied font size $size. 257 * 258 * @author LarsDW223 259 * 260 * @param string $name 261 * @param string $size 262 * @return ODTTextStyle 263 */ 264 public static function createSizeOnlyTextStyle ($name, $size) { 265 return ODTTextStyle::createSizeOnlyTextStyle ($name, $size); 266 } 267 268 /** 269 * Simple helper function for creating a paragrapg style for a pagebreak. 270 * 271 * @author LarsDW223 272 * 273 * @param string $parent Name of the parent style to set 274 * @param string $before Pagebreak before or after? 275 * @return ODTParagraphStyle 276 */ 277 public static function createPagebreakStyle($style_name, $parent=NULL,$before=true) { 278 return ODTParagraphStyle::createPagebreakStyle($style_name, $parent,$before); 279 } 280 281 /** 282 * The function adjusts the property value for ODT: 283 * - 'em' units are converted to 'pt' units 284 * - CSS color names are converted to its RGB value 285 * - short color values like #fff are converted to the long format, e.g #ffffff 286 * 287 * @author LarsDW223 288 * 289 * @param string $property The property name 290 * @param string $value The value 291 * @param integer $emValue Factor for conversion from 'em' to 'pt' 292 * @return string Converted value 293 */ 294 public function adjustValueForODT ($property, $value, $emValue = 0) { 295 return ODTUtility::adjustValueForODT ($property, $value, $emValue); 296 } 297} 298