1<?php 2 3require_once DOKU_INC.'lib/plugins/odt/ODT/styleset.php'; 4require_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 */ 17class ODTDefaultStyles extends ODTStyleSet 18{ 19 protected $automatic = 20 '<office:automatic-styles> 21 <style:page-layout style:name="pm1"> 22 <style:page-layout-properties fo:page-width="21cm" fo:page-height="29.7cm" style:num-format="1" style:print-orientation="portrait" fo:margin-top="2cm" fo:margin-bottom="2cm" fo:margin-left="2cm" fo:margin-right="2cm" style:writing-mode="lr-tb" style:footnote-max-height="0cm"> 23 <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"/> 24 </style:page-layout-properties> 25 <style:header-style/> 26 <style:footer-style/> 27 </style:page-layout> 28 <style:style style:name="sub" style:family="text"> 29 <style:text-properties style:text-position="-33% 80%"/> 30 </style:style> 31 <style:style style:name="sup" style:family="text"> 32 <style:text-properties style:text-position="33% 80%"/> 33 </style:style> 34 <style:style style:name="del" style:family="text"> 35 <style:text-properties style:text-line-through-style="solid"/> 36 </style:style> 37 <style:style style:name="underline" style:family="text"> 38 <style:text-properties style:text-underline-style="solid" 39 style:text-underline-width="auto" style:text-underline-color="font-color"/> 40 </style:style> 41 <style:style style:name="media" style:family="graphic" style:parent-style-name="Graphics"> 42 <style:graphic-properties style:run-through="foreground" style:wrap="parallel" style:number-wrapped-paragraphs="no-limit" 43 style:wrap-contour="false" style:vertical-pos="top" style:vertical-rel="baseline" style:horizontal-pos="left" 44 style:horizontal-rel="paragraph"/> 45 </style:style> 46 <style:style style:name="medialeft" style:family="graphic" style:parent-style-name="Graphics"> 47 <style:graphic-properties style:run-through="foreground" style:wrap="parallel" style:number-wrapped-paragraphs="no-limit" 48 style:wrap-contour="false" style:horizontal-pos="left" style:horizontal-rel="paragraph"/> 49 </style:style> 50 <style:style style:name="mediaright" style:family="graphic" style:parent-style-name="Graphics"> 51 <style:graphic-properties style:run-through="foreground" style:wrap="parallel" style:number-wrapped-paragraphs="no-limit" 52 style:wrap-contour="false" style:horizontal-pos="right" style:horizontal-rel="paragraph"/> 53 </style:style> 54 <style:style style:name="mediacenter" style:family="graphic" style:parent-style-name="Graphics"> 55 <style:graphic-properties style:run-through="foreground" style:wrap="none" style:horizontal-pos="center" 56 style:horizontal-rel="paragraph"/> 57 </style:style> 58 <style:style style:name="Table" style:family="table"> 59 <style:table-properties table:border-model="collapsing" fo:margin-top="0.25cm" fo:margin-bottom="0.25cm"/> 60 </style:style> 61 <style:style style:name="tablealigncenter" style:family="paragraph" style:parent-style-name="Table_20_Contents"> 62 <style:paragraph-properties fo:text-align="center"/> 63 </style:style> 64 <style:style style:name="tablealignright" style:family="paragraph" style:parent-style-name="Table_20_Contents"> 65 <style:paragraph-properties fo:text-align="end"/> 66 </style:style> 67 <style:style style:name="tablealignleft" style:family="paragraph" style:parent-style-name="Table_20_Contents"> 68 <style:paragraph-properties fo:text-align="left"/> 69 </style:style> 70 <style:style style:name="tableheader" style:family="table-cell"> 71 <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"/> 72 </style:style> 73 <style:style style:name="tablecell" style:family="table-cell"> 74 <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"/> 75 </style:style> 76 <style:style style:name="legendcenter" style:family="paragraph" style:parent-style-name="Illustration"> 77 <style:paragraph-properties fo:text-align="center"/> 78 </style:style> 79 <style:style style:name="Table_Quotation1" style:family="table"> 80 <style:table-properties table:border-model="collapsing" fo:margin-top="0pt" fo:margin-bottom="16.8pt"/> 81 </style:style> 82 <style:style style:name="Table_Quotation2" style:family="table"> 83 <style:table-properties table:border-model="collapsing" fo:margin-top="0pt" fo:margin-bottom="0pt"/> 84 </style:style> 85 <style:style style:name="Table_Quotation3" style:family="table"> 86 <style:table-properties table:border-model="collapsing" fo:margin-top="0pt" fo:margin-bottom="0pt"/> 87 </style:style> 88 <style:style style:name="Table_Quotation4" style:family="table"> 89 <style:table-properties table:border-model="collapsing" fo:margin-top="0pt" fo:margin-bottom="0pt"/> 90 </style:style> 91 <style:style style:name="Table_Quotation5" style:family="table"> 92 <style:table-properties table:border-model="collapsing" fo:margin-top="0pt" fo:margin-bottom="0pt"/> 93 </style:style> 94 <style:style style:name="Cell_Quotation1" style:family="table-cell"> 95 <style:table-cell-properties fo:margin="0cm" fo:padding-left="6pt" fo:padding-right="6pt" fo:padding-top="0pt" fo:padding-bottom="0pt" fo:border-left="3pt solid #cccccc" fo:border-right="none" fo:border-top="none" fo:border-bottom="none"/> 96 </style:style> 97 <style:style style:name="Cell_Quotation2" style:family="table-cell"> 98 <style:table-cell-properties fo:margin="0cm" fo:padding-left="6pt" fo:padding-right="6pt" fo:padding-top="0pt" fo:padding-bottom="0pt" fo:border-left="3pt solid #cccccc" fo:border-right="none" fo:border-top="none" fo:border-bottom="none"/> 99 </style:style> 100 <style:style style:name="Cell_Quotation3" style:family="table-cell"> 101 <style:table-cell-properties fo:margin="0cm" fo:padding-left="6pt" fo:padding-right="6pt" fo:padding-top="0pt" fo:padding-bottom="0pt" fo:border-left="3pt solid #cccccc" fo:border-right="none" fo:border-top="none" fo:border-bottom="none"/> 102 </style:style> 103 <style:style style:name="Cell_Quotation4" style:family="table-cell"> 104 <style:table-cell-properties fo:margin="0cm" fo:padding-left="6pt" fo:padding-right="6pt" fo:padding-top="0pt" fo:padding-bottom="0pt" fo:border-left="3pt solid #cccccc" fo:border-right="none" fo:border-top="none" fo:border-bottom="none"/> 105 </style:style> 106 <style:style style:name="Cell_Quotation5" style:family="table-cell"> 107 <style:table-cell-properties fo:margin="0cm" fo:padding-left="6pt" fo:padding-right="6pt" fo:padding-top="0pt" fo:padding-bottom="0pt" fo:border-left="3pt solid #cccccc" fo:border-right="none" fo:border-top="none" fo:border-bottom="none"/> 108 </style:style> 109 </office:automatic-styles>'; 110 111 // Font definitions. May not be present if in template mode, in which case they will be added to styles.xml 112 var $fonts = array( 113 "StarSymbol"=>'<style:font-face style:name="StarSymbol" svg:font-family="StarSymbol"/>', // for bullets 114 "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 115 ); 116 117 /** 118 * @param null $source 119 */ 120 public function import($source=NULL) { 121 $auto_styles_ret = parent::importFromODT($this->automatic, 'office:automatic-styles'); 122 $styles_ret = parent::importFromODTFile(DOKU_INC.'lib/plugins/odt/styles.xml', 'office:styles'); 123 $master_styles_ret = parent::importFromODTFile(DOKU_INC.'lib/plugins/odt/styles.xml', 'office:master-styles'); 124 if (!$auto_styles_ret || !$styles_ret || !$master_styles_ret) { 125 return false; 126 } 127 return true; 128 } 129 130 /** 131 * @param null $destination 132 */ 133 public function export($root_element) { 134 return parent::exportToODT($root_element); 135 } 136 137 /** 138 * Return style name for queired basic style $style. 139 * 140 * The class simply returns the corresponding style names 141 * used in styles.xml. 142 * 143 * @param string $style 144 * @return null|string 145 */ 146 public function getStyleName($style) { 147 switch ($style) { 148 case 'standard': return 'Standard'; 149 case 'body': return 'Text_20_body'; 150 case 'heading1': return 'Heading_20_1'; 151 case 'heading2': return 'Heading_20_2'; 152 case 'heading3': return 'Heading_20_3'; 153 case 'heading4': return 'Heading_20_4'; 154 case 'heading5': return 'Heading_20_5'; 155 case 'list': return 'List_20_1'; 156 case 'list content': return 'List_20_1_Content'; 157 case 'list first': return 'List_20_1_Content_First'; 158 case 'list last': return 'List_20_1_Content_Last'; 159 case 'numbering': return 'Numbering_20_1'; 160 case 'numbering content': return 'Numbering_20_1_Content'; 161 case 'numbering first': return 'Numbering_20_1_Content_First'; 162 case 'numbering last': return 'Numbering_20_1_Content_Last'; 163 case 'table': return 'Table'; 164 case 'table content': return 'Table_20_Contents'; 165 case 'table heading': return 'Table_20_Heading'; 166 case 'table header': return 'tableheader'; 167 case 'table cell': return 'tablecell'; 168 case 'tablealign center': return 'tablealigncenter'; 169 case 'tablealign right': return 'tablealignright'; 170 case 'tablealign left': return 'tablealignleft'; 171 case 'preformatted': return 'Preformatted_20_Text'; 172 case 'source code': return 'Source_20_Code'; 173 case 'source file': return 'Source_20_File'; 174 case 'horizontal line': return 'Horizontal_20_Line'; 175 case 'footnote': return 'Footnote'; 176 case 'footnote anchor': return 'Footnote_20_Anchor'; 177 case 'footnote characters': return 'Footnote_20_Symbol'; 178 case 'emphasis': return 'Emphasis'; 179 case 'strong': return 'Strong_20_Emphasis'; 180 case 'underline': return 'underline'; 181 case 'sub': return 'sub'; 182 case 'sup': return 'sup'; 183 case 'del': return 'del'; 184 case 'media': return 'media'; 185 case 'media left': return 'medialeft'; 186 case 'media right': return 'mediaright'; 187 case 'media center': return 'mediacenter'; 188 case 'legend center': return 'legendcenter'; 189 case 'graphics': return 'Graphics'; 190 case 'monospace': return 'Source_20_Text'; 191 case 'table quotation1': return 'Table_Quotation1'; 192 case 'table quotation2': return 'Table_Quotation2'; 193 case 'table quotation3': return 'Table_Quotation3'; 194 case 'table quotation4': return 'Table_Quotation4'; 195 case 'table quotation5': return 'Table_Quotation5'; 196 case 'cell quotation1': return 'Cell_Quotation1'; 197 case 'cell quotation2': return 'Cell_Quotation2'; 198 case 'cell quotation3': return 'Cell_Quotation3'; 199 case 'cell quotation4': return 'Cell_Quotation4'; 200 case 'cell quotation5': return 'Cell_Quotation5'; 201 case 'first page': return 'pm1'; 202 case 'internet link': return 'Internet_20_link'; 203 case 'visited internet link': return 'Visited_20_Internet_20_Link'; 204 case 'local link': return 'Local_20_link'; 205 case 'visited local link': return 'Visited_20_Local_20_Link'; 206 case 'contents heading': return 'Contents_20_Heading'; 207 } 208 // Not supported basic style. 209 return NULL; 210 } 211 212 /** 213 * @param string $filename 214 * @return string 215 */ 216 function getMissingFonts($filename) { 217 $value = ''; 218 $existing_styles = io_readFile($filename); 219 foreach ($this->fonts as $name=>$xml) { 220 if (strpos($existing_styles, 'style:name="'.$name.'"') === FALSE) { 221 $value .= $xml; 222 } 223 } 224 return $value; 225 } 226} 227 228