|
| 1 | +<?php |
| 2 | + |
| 3 | +require_once DOKU_INC.'lib/plugins/odt/ODT/styleset.php'; |
| 4 | +require_once DOKU_INC.'lib/plugins/odt/ODT/page.php'; |
| 5 | + |
| 6 | +/** |
| 7 | + * ODTDefaultStyles: class for using the basic styles from styles.xml. |
| 8 | + * This is also used if a ODT template is used, as the style names |
| 9 | + * need to match the names in styles.xml. |
| 10 | + * |
| 11 | + * The class is doing nothing for import/export because it expects |
| 12 | + * the file styles.xml to be there. So the file is neither read nor written. |
| 13 | + * |
| 14 | + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) |
| 15 | + * @author LarsDW223 |
| 16 | + */ |
| 17 | +class ODTDefaultStyles extends ODTStyleSet |
| 18 | +{ |
| 19 | + // Font definitions. May not be present if in template mode, in which case they will be added to styles.xml |
| 20 | + var $fonts = array( |
| 21 | + "StarSymbol"=>'<style:font-face style:name="StarSymbol" svg:font-family="StarSymbol"/>', // for bullets |
| 22 | + "Bitstream Vera Sans Mono"=>'<style:font-face style:name="Bitstream Vera Sans Mono" svg:font-family="\'Bitstream Vera Sans Mono\'" style:font-family-generic="modern" style:font-pitch="fixed"/>', // for source code |
| 23 | + ); |
| 24 | + |
| 25 | + /** |
| 26 | + * @param null $source |
| 27 | + */ |
| 28 | + public function import($source=NULL) { |
| 29 | + // Do nothing. |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * @param null $destination |
| 34 | + */ |
| 35 | + public function export($destination=NULL) { |
| 36 | + // Do nothing. |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Return style name for queired basic style $style. |
| 41 | + * |
| 42 | + * The class simply returns the corresponding style names |
| 43 | + * used in styles.xml. |
| 44 | + * |
| 45 | + * @param string $style |
| 46 | + * @return null|string |
| 47 | + */ |
| 48 | + public function getStyleName($style) { |
| 49 | + switch ($style) { |
| 50 | + case 'standard': return 'Standard'; |
| 51 | + case 'body': return 'Text_20_body'; |
| 52 | + case 'heading1': return 'Heading_20_1'; |
| 53 | + case 'heading2': return 'Heading_20_2'; |
| 54 | + case 'heading3': return 'Heading_20_3'; |
| 55 | + case 'heading4': return 'Heading_20_4'; |
| 56 | + case 'heading5': return 'Heading_20_5'; |
| 57 | + case 'list': return 'List_20_1'; |
| 58 | + case 'numbering': return 'Numbering_20_1'; |
| 59 | + case 'table content': return 'Table_20_Contents'; |
| 60 | + case 'table heading': return 'Table_20_Heading'; |
| 61 | + case 'table header': return 'tableheader'; |
| 62 | + case 'table cell': return 'tablecell'; |
| 63 | + case 'tablealign center': return 'tablealign center'; |
| 64 | + case 'tablealign right': return 'tablealign right'; |
| 65 | + case 'tablealign left': return 'tablealign left'; |
| 66 | + case 'preformatted': return 'Preformatted_20_Text'; |
| 67 | + case 'source code': return 'Source_20_Code'; |
| 68 | + case 'source file': return 'Source_20_File'; |
| 69 | + case 'horizontal line': return 'Horizontal_20_Line'; |
| 70 | + case 'footnote': return 'Footnote'; |
| 71 | + case 'emphasis': return 'Emphasis'; |
| 72 | + case 'strong': return 'Strong_20_Emphasis'; |
| 73 | + case 'underline': return 'underline'; |
| 74 | + case 'sub': return 'sub'; |
| 75 | + case 'sup': return 'sup'; |
| 76 | + case 'del': return 'del'; |
| 77 | + case 'media': return 'media'; |
| 78 | + case 'media left': return 'medialeft'; |
| 79 | + case 'media right': return 'mediaright'; |
| 80 | + case 'media center': return 'mediacenter'; |
| 81 | + case 'legend center': return 'legendcenter'; |
| 82 | + case 'graphics': return 'Graphics'; |
| 83 | + case 'monospace': return 'Source_20_Text'; |
| 84 | + case 'quotation1': return 'Quotation 1'; |
| 85 | + case 'quotation2': return 'Quotation 2'; |
| 86 | + case 'quotation3': return 'Quotation 3'; |
| 87 | + case 'quotation4': return 'Quotation 4'; |
| 88 | + case 'quotation5': return 'Quotation 5'; |
| 89 | + } |
| 90 | + // Not supported basic style. |
| 91 | + return NULL; |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * @return array |
| 96 | + */ |
| 97 | + function getStyles (){ |
| 98 | + $styles = array( |
| 99 | + "Source_20_Text"=>' |
| 100 | + <style:style style:name="Source_20_Text" style:display-name="Source Text" style:family="text"> |
| 101 | + <style:text-properties style:font-name="Bitstream Vera Sans Mono" style:font-name-asian="Bitstream Vera Sans Mono" style:font-name-complex="Bitstream Vera Sans Mono"/> |
| 102 | + </style:style>', |
| 103 | + "Preformatted_20_Text"=>' |
| 104 | + <style:style style:name="Preformatted_20_Text" style:display-name="Preformatted Text" style:family="paragraph" style:parent-style-name="Standard" style:class="html"> |
| 105 | + <style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0.2cm"/> |
| 106 | + <style:text-properties style:font-name="Bitstream Vera Sans Mono" style:font-name-asian="Bitstream Vera Sans Mono" style:font-name-complex="Bitstream Vera Sans Mono"/> |
| 107 | + </style:style>', |
| 108 | + "Source_20_Code"=>' |
| 109 | + <style:style style:name="Source_20_Code" style:display-name="Source Code" style:family="paragraph" style:parent-style-name="Preformatted_20_Text"> |
| 110 | + <style:paragraph-properties fo:padding="0.05cm" style:shadow="none" fo:border="0.002cm solid #8cacbb" fo:background-color="#f7f9fa"/> |
| 111 | + </style:style>', |
| 112 | + "Source_20_File"=>' |
| 113 | + <style:style style:name="Source_20_File" style:display-name="Source File" style:family="paragraph" style:parent-style-name="Preformatted_20_Text"> |
| 114 | + <style:paragraph-properties fo:padding="0.05cm" style:shadow="none" fo:border="0.002cm solid #8cacbb" fo:background-color="#f1f4f5"/> |
| 115 | + </style:style>', |
| 116 | + "Horizontal_20_Line"=>' |
| 117 | + <style:style style:name="Horizontal_20_Line" style:display-name="Horizontal Line" style:family="paragraph" style:parent-style-name="Standard" style:next-style-name="Text_20_body" style:class="html"> |
| 118 | + <style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0.5cm" style:border-line-width-bottom="0.002cm 0.035cm 0.002cm" fo:padding="0cm" fo:border-left="none" fo:border-right="none" fo:border-top="none" fo:border-bottom="0.04cm double #808080" text:number-lines="false" text:line-number="0" style:join-border="false"/> |
| 119 | + <style:text-properties fo:font-size="6pt" style:font-size-asian="6pt" style:font-size-complex="6pt"/> |
| 120 | + </style:style>', |
| 121 | + "Footnote"=>' |
| 122 | + <style:style style:name="Footnote" style:family="paragraph" style:parent-style-name="Standard" style:class="extra"> |
| 123 | + <style:paragraph-properties fo:margin-left="0.5cm" fo:margin-right="0cm" fo:text-indent="-0.5cm" style:auto-text-indent="false" text:number-lines="false" text:line-number="0"/> |
| 124 | + <style:text-properties fo:font-size="10pt" style:font-size-asian="10pt" style:font-size-complex="10pt"/> |
| 125 | + </style:style>', |
| 126 | + "Emphasis"=>' |
| 127 | + <style:style style:name="Emphasis" style:family="text"> |
| 128 | + <style:text-properties fo:font-style="italic" style:font-style-asian="italic" style:font-style-complex="italic"/> |
| 129 | + </style:style>', |
| 130 | + "Strong_20_Emphasis"=>' |
| 131 | + <style:style style:name="Strong_20_Emphasis" style:display-name="Strong Emphasis" style:family="text"> |
| 132 | + <style:text-properties fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold"/> |
| 133 | + </style:style>',); |
| 134 | + return $styles; |
| 135 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * Return autostyles initial content. |
| 139 | + * Uses page parameters. |
| 140 | + * |
| 141 | + * @author LarsDW223 |
| 142 | + * |
| 143 | + * @param pageFormat $page |
| 144 | + * @return array |
| 145 | + */ |
| 146 | + function getAutoStyles (pageFormat $page){ |
| 147 | + $autostyles = array( |
| 148 | + "pm1"=>' |
| 149 | + <style:page-layout style:name="pm1"> |
| 150 | + <style:page-layout-properties fo:page-width="'.$page->getWidth().'cm" fo:page-height="'.$page->getHeight().'cm" style:num-format="1" style:print-orientation="portrait" fo:margin-top="'.$page->getMarginTop().'cm" fo:margin-bottom="'.$page->getMarginBottom().'cm" fo:margin-left="'.$page->getMarginLeft().'cm" fo:margin-right="'.$page->getMarginRight().'cm" style:writing-mode="lr-tb" style:footnote-max-height="0cm"> |
| 151 | + <style:footnote-sep style:width="0.018cm" style:distance-before-sep="0.1cm" style:distance-after-sep="0.1cm" style:adjustment="left" style:rel-width="25%" style:color="#000000"/> |
| 152 | + </style:page-layout-properties> |
| 153 | + <style:header-style/> |
| 154 | + <style:footer-style/> |
| 155 | + </style:page-layout>', |
| 156 | + "sub"=>' |
| 157 | + <style:style style:name="sub" style:family="text"> |
| 158 | + <style:text-properties style:text-position="-33% 80%"/> |
| 159 | + </style:style>', |
| 160 | + "sup"=>' |
| 161 | + <style:style style:name="sup" style:family="text"> |
| 162 | + <style:text-properties style:text-position="33% 80%"/> |
| 163 | + </style:style>', |
| 164 | + "del"=>' |
| 165 | + <style:style style:name="del" style:family="text"> |
| 166 | + <style:text-properties style:text-line-through-style="solid"/> |
| 167 | + </style:style>', |
| 168 | + "underline"=>' |
| 169 | + <style:style style:name="underline" style:family="text"> |
| 170 | + <style:text-properties style:text-underline-style="solid" |
| 171 | + style:text-underline-width="auto" style:text-underline-color="font-color"/> |
| 172 | + </style:style>', |
| 173 | + "media"=>' |
| 174 | + <style:style style:name="media" style:family="graphic" style:parent-style-name="'.$this->getStyleName('graphics').'"> |
| 175 | + <style:graphic-properties style:run-through="foreground" style:wrap="parallel" style:number-wrapped-paragraphs="no-limit" |
| 176 | + style:wrap-contour="false" style:vertical-pos="top" style:vertical-rel="baseline" style:horizontal-pos="left" |
| 177 | + style:horizontal-rel="paragraph"/> |
| 178 | + </style:style>', |
| 179 | + "medialeft"=>' |
| 180 | + <style:style style:name="medialeft" style:family="graphic" style:parent-style-name="'.$this->getStyleName('graphics').'"> |
| 181 | + <style:graphic-properties style:run-through="foreground" style:wrap="parallel" style:number-wrapped-paragraphs="no-limit" |
| 182 | + style:wrap-contour="false" style:horizontal-pos="left" style:horizontal-rel="paragraph"/> |
| 183 | + </style:style>', |
| 184 | + "mediaright"=>' |
| 185 | + <style:style style:name="mediaright" style:family="graphic" style:parent-style-name="'.$this->getStyleName('graphics').'"> |
| 186 | + <style:graphic-properties style:run-through="foreground" style:wrap="parallel" style:number-wrapped-paragraphs="no-limit" |
| 187 | + style:wrap-contour="false" style:horizontal-pos="right" style:horizontal-rel="paragraph"/> |
| 188 | + </style:style>', |
| 189 | + "mediacenter"=>' |
| 190 | + <style:style style:name="mediacenter" style:family="graphic" style:parent-style-name="'.$this->getStyleName('graphics').'"> |
| 191 | + <style:graphic-properties style:run-through="foreground" style:wrap="none" style:horizontal-pos="center" |
| 192 | + style:horizontal-rel="paragraph"/> |
| 193 | + </style:style>', |
| 194 | + "tablealigncenter"=>' |
| 195 | + <style:style style:name="tablealigncenter" style:family="paragraph" style:parent-style-name="'.$this->getStyleName('table content').'"> |
| 196 | + <style:paragraph-properties fo:text-align="center"/> |
| 197 | + </style:style>', |
| 198 | + "tablealignright"=>' |
| 199 | + <style:style style:name="tablealignright" style:family="paragraph" style:parent-style-name="'.$this->getStyleName('table content').'"> |
| 200 | + <style:paragraph-properties fo:text-align="end"/> |
| 201 | + </style:style>', |
| 202 | + "tablealignleft"=>' |
| 203 | + <style:style style:name="tablealignleft" style:family="paragraph" style:parent-style-name="'.$this->getStyleName('table content').'"> |
| 204 | + <style:paragraph-properties fo:text-align="left"/> |
| 205 | + </style:style>', |
| 206 | + "tableheader"=>' |
| 207 | + <style:style style:name="tableheader" style:family="table-cell"> |
| 208 | + <style:table-cell-properties fo:padding="0.05cm" fo:border-left="0.002cm solid #000000" fo:border-right="0.002cm solid #000000" fo:border-top="0.002cm solid #000000" fo:border-bottom="0.002cm solid #000000"/> |
| 209 | + </style:style>', |
| 210 | + "tablecell"=>' |
| 211 | + <style:style style:name="tablecell" style:family="table-cell"> |
| 212 | + <style:table-cell-properties fo:padding="0.05cm" fo:border-left="0.002cm solid #000000" fo:border-right="0.002cm solid #000000" fo:border-top="0.002cm solid #000000" fo:border-bottom="0.002cm solid #000000"/> |
| 213 | + </style:style>', |
| 214 | + "legendcenter"=>' |
| 215 | + <style:style style:name="legendcenter" style:family="paragraph" style:parent-style-name="Illustration"> |
| 216 | + <style:paragraph-properties fo:text-align="center"/> |
| 217 | + </style:style>', ); |
| 218 | + return $autostyles; |
| 219 | + } |
| 220 | + |
| 221 | + /** |
| 222 | + * @param string $filename |
| 223 | + * @return string |
| 224 | + */ |
| 225 | + function getMissingStyles($filename) { |
| 226 | + $styles = $this->getStyles(); |
| 227 | + $value = ''; |
| 228 | + //$existing_styles = io_readFile($this->temp_dir.'/styles.xml'); |
| 229 | + $existing_styles = io_readFile($filename); |
| 230 | + foreach ($styles as $stylename=>$stylexml) { |
| 231 | + if (strpos($existing_styles, 'style:name="'.$stylename.'"') === FALSE) { |
| 232 | + $value .= $stylexml; |
| 233 | + } |
| 234 | + } |
| 235 | + // Loop on bullet/numerotation styles |
| 236 | + if (strpos($existing_styles, 'style:name="List_20_1"') === FALSE) { |
| 237 | + $value .= '<text:list-style style:name="List_20_1" style:display-name="List 1">'; |
| 238 | + for ($i=1;$i<=10;$i++) { |
| 239 | + $value .= '<text:list-level-style-bullet text:level="'.$i.'" text:style-name="Numbering_20_Symbols" text:bullet-char="•"> |
| 240 | + <style:list-level-properties text:space-before="'.(0.4*($i-1)).'cm" text:min-label-width="0.4cm"/> |
| 241 | + <style:text-properties style:font-name="StarSymbol"/> |
| 242 | + </text:list-level-style-bullet>'; |
| 243 | + } |
| 244 | + $value .= '</text:list-style>'; |
| 245 | + } |
| 246 | + if (strpos($existing_styles, 'style:name="Numbering_20_1"') === FALSE) { |
| 247 | + $value .= '<text:list-style style:name="Numbering_20_1" style:display-name="Numbering 1">'; |
| 248 | + for ($i=1;$i<=10;$i++) { |
| 249 | + $value .= '<text:list-level-style-number text:level="'.$i.'" text:style-name="Numbering_20_Symbols" style:num-suffix="." style:num-format="1"> |
| 250 | + <style:list-level-properties text:space-before="'.(0.5*($i-1)).'cm" text:min-label-width="0.5cm"/> |
| 251 | + </text:list-level-style-number>'; |
| 252 | + } |
| 253 | + $value .= '</text:list-style>'; |
| 254 | + } |
| 255 | + return $value; |
| 256 | + } |
| 257 | + |
| 258 | + /** |
| 259 | + * @param string $filename |
| 260 | + * @return string |
| 261 | + */ |
| 262 | + function getMissingFonts($filename) { |
| 263 | + $value = ''; |
| 264 | + $existing_styles = io_readFile($filename); |
| 265 | + foreach ($this->fonts as $name=>$xml) { |
| 266 | + if (strpos($existing_styles, 'style:name="'.$name.'"') === FALSE) { |
| 267 | + $value .= $xml; |
| 268 | + } |
| 269 | + } |
| 270 | + return $value; |
| 271 | + } |
| 272 | +} |
| 273 | + |
0 commit comments