1<?php
2
3//this script may only be included - so its better to die if called directly.
4if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) {
5  header("location: index.php");
6  exit;
7}
8
9
10/*This file is part of J4PHP - Ensembles de propriétés et méthodes permettant le developpment rapide d'application web modulaire
11Copyright (c) 2002-2004 @PICNet
12
13This program is free software; you can redistribute it and/or
14modify it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE
15as published by the Free Software Foundation.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20GNU LESSER GENERAL PUBLIC LICENSE for more details.
21
22You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
23along with this program; if not, write to the Free Software
24Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25*/
26APIC::import("org.apicnet.io.OOo.absOOo");
27
28/**
29 * OOoStyle
30 *
31 * @package
32 * @author apicnet
33 * @copyright Copyright (c) 2004
34 * @version $Id: OOoStyle.php,v 1.3 2005-05-18 11:01:39 mose Exp $
35 * @access public
36 **/
37class OOoStyle extends absOOo {
38
39	var $type;
40
41	var $STYLNUM = array(
42		'style_family_text' => 1,
43		'style_family_para' => 1,
44		'style_page_style'	=> 1
45	);
46
47	function __construct($dir){
48		parent::__construct();
49		$this->DIRXML = $dir;
50		$this->FILENAME = "styles.xml";
51
52		$file = new File($dir."/".$this->FILENAME);
53		if ($file->exists()) {
54			$this->xml = new DOMIT_Document();
55			$this->xml->loadXML($dir."/".$this->FILENAME, false);
56		} else {
57			$this->xml = new DOMIT_Document();
58			$this->create();
59		}
60		$this->xml->setDocType("<!DOCTYPE office:document-styles PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"office.dtd\">");
61	}
62
63
64	function create(){
65
66		$docStyleNode =& $this->xml->createElement("office:document-styles");
67		$docStyleNode->setAttribute("xmlns:office", "http://openoffice.org/2000/office");
68		$docStyleNode->setAttribute("xmlns:style", "http://openoffice.org/2000/style" );
69		$docStyleNode->setAttribute("xmlns:text", "http://openoffice.org/2000/text" );
70		$docStyleNode->setAttribute("xmlns:table", "http://openoffice.org/2000/table" );
71		$docStyleNode->setAttribute("xmlns:draw", "http://openoffice.org/2000/drawing" );
72		$docStyleNode->setAttribute("xmlns:fo", "http://www.w3.org/1999/XSL/Format" );
73		$docStyleNode->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink" );
74		$docStyleNode->setAttribute("xmlns:number", "http://openoffice.org/2000/datastyle" );
75		$docStyleNode->setAttribute("xmlns:svg", "http://www.w3.org/2000/svg" );
76		$docStyleNode->setAttribute("xmlns:chart", "http://openoffice.org/2000/chart" );
77		$docStyleNode->setAttribute("xmlns:dr3d", "http://openoffice.org/2000/dr3d" );
78		$docStyleNode->setAttribute("xmlns:math", "http://www.w3.org/1998/Math/MathML" );
79		$docStyleNode->setAttribute("xmlns:form", "http://openoffice.org/2000/form" );
80		$docStyleNode->setAttribute("xmlns:script", "http://openoffice.org/2000/script" );
81		$docStyleNode->setAttribute("office:version", "1.0");
82
83
84		$fontDeclsNode =& $this->xml->createElement("office:font-decls");
85		$fontDeclNode =& $this->xml->createElement("style:font-decl");
86		$fontDeclNode->setAttribute("style:name", "Tahoma1");
87		$fontDeclNode->setAttribute("fo:font-family", "Tahoma");
88		$fontDeclsNode->appendChild($fontDeclNode);
89		$fontDeclNode =& $this->xml->createElement("style:font-decl");
90		$fontDeclNode->setAttribute("style:name", "Andale Sans UI");
91		$fontDeclNode->setAttribute("fo:font-family", "&amp;apos;Andale Sans UI&amp;apos;");
92		$fontDeclNode->setAttribute("style:font-pitch", "variable");
93		$fontDeclsNode->appendChild($fontDeclNode);
94		$fontDeclNode =& $this->xml->createElement("style:font-decl");
95		$fontDeclNode->setAttribute("style:name", "Tahoma");
96		$fontDeclNode->setAttribute("fo:font-family", "Tahoma");
97		$fontDeclNode->setAttribute("style:font-pitch", "variable");
98		$fontDeclsNode->appendChild($fontDeclNode);
99		$fontDeclNode =& $this->xml->createElement("style:font-decl");
100		$fontDeclNode->setAttribute("style:name", "Thorndale");
101		$fontDeclNode->setAttribute("fo:font-family", "Thorndale");
102		$fontDeclNode->setAttribute("style:font-family-generic", "roman");
103		$fontDeclNode->setAttribute("style:font-pitch", "variable");
104		$fontDeclsNode->appendChild($fontDeclNode);
105		$fontDeclNode =& $this->xml->createElement("style:font-decl");
106		$fontDeclNode->setAttribute("style:name", "Arial");
107		$fontDeclNode->setAttribute("fo:font-family", "Arial");
108		$fontDeclNode->setAttribute("style:font-family-generic", "swiss");
109		$fontDeclNode->setAttribute("style:font-pitch", "variable");
110		$fontDeclsNode->appendChild($fontDeclNode);
111		$docStyleNode->appendChild($fontDeclsNode);
112
113		$docStyleNode->appendChild($this->ChildText("office:automatic-styles", ""));
114		$docStyleNode->appendChild($this->ChildText("office:master-styles", ""));
115
116		$stylesNode =& $this->xml->createElement("office:styles");
117		$styleNode = & $this->xml->createElement("style:style");
118		$styleNode->setAttribute("style:name", $type);
119		$styleNode->setAttribute("style:family", "paragraph");
120		$styleNode->setAttribute("style:parent-style-name", "Standard");
121		$styleNode->setAttribute("style:class", "extra");
122
123		$propertiesNode =& $this->xml->createElement("style:properties");
124		$propertiesNode->setAttribute("text:number-lines", "false");
125		$propertiesNode->setAttribute("text:line-number", "0");
126
127		$tabStopsNode =& $this->xml->createElement("style:tab-stops");
128		$tabStopNode =& $this->xml->createElement("style:tab-stop");
129		$tabStopNode->setAttribute("style:position", "8.498cm");
130		$tabStopNode->setAttribute("style:type", "center");
131		$tabStopsNode->appendChild($tabStopNode);
132		$tabStopNode =& $this->xml->createElement("style:tab-stop");
133		$tabStopNode->setAttribute("style:position", "16.999cm");
134		$tabStopNode->setAttribute("style:type", "right");
135		$tabStopsNode->appendChild($tabStopNode);
136
137		$propertiesNode->appendChild($tabStopsNode);
138		$styleNode->appendChild($propertiesNode);
139		$stylesNode->appendChild($styleNode);
140
141		$styleNode = & $this->xml->createElement("style:style");
142		$styleNode->setAttribute("style:name", "Standard");
143		$styleNode->setAttribute("style:family", "paragraph");
144		$styleNode->setAttribute("style:class", "text");
145
146		$propertiesNode =& $this->xml->createElement("style:properties");
147		$propertiesNode->setAttribute("fo:text-align", "justify");
148		$propertiesNode->setAttribute("style:justify-single-word", "false");
149
150		$stylesNode->appendChild($styleNode);
151		$docStyleNode->appendChild($stylesNode);
152
153		$this->xml->setDocumentElement($docStyleNode);
154		$this->xml->setXMLDeclaration("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
155
156
157		$argPage = array(
158			"NameStyle"		=> "Standard",
159			"pageWidth"		=> "20.999",
160			"pageHeight"	=> "29.699",
161			"printOrient"	=> "portrait",
162			"marginT"		=> "2",
163			"marginB"		=> "2",
164			"marginL"		=> "2",
165			"marginR"		=> "2",
166			"writingMode"	=> "lr-tb"
167		);
168		$this->addStylePage($argPage);
169		$this->addGraphicStyle();
170	}
171
172	function main(){
173		echo $this->toString();
174	}
175
176	/**
177	 * OOoStyle::addStyle()
178	 *
179	 * @param Array $styleArg
180	 * @return none
181	 **/
182	function addStyle($styleArg){
183		/*
184		* style:name
185		* style:family
186		* style:parent-style-name
187		* style:class
188		* style:next-style-name
189		* style:list-style-name
190		* style:master-page-name
191		*/
192		/*
193		<style:style style:name="Text body" style:family="paragraph" style:parent-style-name="Standard" style:class="text">
194         <style:properties fo:margin-top="0cm" fo:margin-bottom="0.212cm" style:font-name="Arial" fo:font-weight="bold" />
195      </style:style>*/
196	}
197
198	/**
199	 * OOoStyle::addStylePage() est une méthode d'ajout d'un entête ou d'un pied de page.
200	 *
201	 * @param Array $argPage de type
202	 * 	$argPage = array(
203			"NameStyle"		=> "Standard",
204			"NameStyleSuiv" => "Standard",
205			"pageWidth"		=> "20.999",			//text
206			"pageHeight"	=> "29.699",			// (top, bottom, or center) (left, right, or center)
207			"printOrient"	=> "portrait",			// Ecart entre l'entête et le corp du document
208			"marginT"		=> "2",
209			"marginB"		=> "2",
210			"marginL"		=> "2",					// Mager de gauche de l'entête
211			"marginR"		=> "2",					// Mager de Droite de l'entête
212			"writingMode"	=> "lr-tb"				// Hauteur de l'entête
213		);
214	 * @return none
215	 **/
216	function addStylePage($argPage){
217		$this->verifIntegrite($argPage, "PageStyle");
218		$automaticStylesNode = & $this->getNode("/office:document-styles/office:automatic-styles");
219
220		$pageMasterNode =& $this->xml->createElement("style:page-master");
221		$pageName = "pm".$this->STYLNUM['style_page_style'];
222		$pageMasterNode->setAttribute("style:name", $pageName );
223		$this->STYLNUM['style_page_style']++;
224
225		$propertieNode =& $this->xml->createElement("style:properties");
226		$propertieNode->setAttribute("fo:page-width", $argPage["pageWidth"]."cm");
227		$propertieNode->setAttribute("fo:page-height", $argPage["pageHeight"]."cm" );
228		$propertieNode->setAttribute("style:num-format", "1" );
229		$propertieNode->setAttribute("style:print-orientation", $argPage["printOrient"] );
230		$propertieNode->setAttribute("fo:margin-top", $argPage["marginT"]."cm" );
231		$propertieNode->setAttribute("fo:margin-bottom", $argPage["marginB"]."cm" );
232		$propertieNode->setAttribute("fo:margin-left", $argPage["marginL"]."cm" );
233		$propertieNode->setAttribute("fo:margin-right", $argPage["marginR"]."cm" );
234		$propertieNode->setAttribute("style:writing-mode", $argPage["writingMode"] );
235		$propertieNode->setAttribute("style:footnote-max-height", "0cm");
236
237		$footnoteSepNode =& $this->xml->createElement("style:footnote-sep");
238		$footnoteSepNode->setAttribute("style:width", "0.018cm");
239		$footnoteSepNode->setAttribute("style:distance-before-sep", "0.101cm");
240		$footnoteSepNode->setAttribute("style:distance-after-sep", "0.101cm");
241		$footnoteSepNode->setAttribute("style:adjustment", "left");
242		$footnoteSepNode->setAttribute("style:rel-width", "25%");
243		$footnoteSepNode->setAttribute("style:color", "#000000");
244
245		$propertieNode->appendChild($footnoteSepNode);
246		$pageMasterNode->appendChild($propertieNode);
247		$pageMasterNode->appendChild($this->ChildText("style:header-style", ""));
248		$pageMasterNode->appendChild($this->ChildText("style:footer-style", ""));
249
250		$automaticStylesNode->appendChild($pageMasterNode);
251
252		$masterStylesNode = & $this->getNode("/office:document-styles/office:master-styles");
253		$masterPageNode =& $this->xml->createElement("style:master-page");
254		$masterPageNode->setAttribute("style:name", $argPage["NameStyle"]);
255		$masterPageNode->setAttribute("style:page-master-name", $pageName);
256		if (isset($argPage["NameStyleSuiv"])) $masterPageNode->setAttribute("style:next-style-name", $argPage["NameStyleSuiv"]);
257
258		$masterStylesNode->appendChild($masterPageNode);
259
260
261		return $pageName;
262	}
263
264
265
266	/**
267	 * OOoStyle::addStyleHeadFoot() est une méthode d'ajout d'un entête ou d'un pied de page.
268	 *
269	 * @param Array $styleArg de type
270	 * 	$argHeager = array(
271			"Text"		=> "@PICNet",				//text
272			"img"		=> array(					// information sur l'image
273					"scr"		=> "E:/_WebDev/www/cOOlWare2/cache/c_projekte.png",
274					"type"		=> "no-repeat",		// (no-repeat|repeat|stretch)
275					"position"	=> "bottom right"),	// (top, bottom, or center) (left, right, or center)
276			"marginB"	=> "0.499",					// Ecart entre l'entête et le corp du document
277			"marginL"	=> "0.499",					// Mager de gauche de l'entête
278			"marginR"	=> "0.499",					// Mager de Droite de l'entête
279			"minHeight"	=> "0.998",					// Hauteur de l'entête
280			"align"		=> "center",				// Alignement du texte de l'entête (left|center|right)
281			"BgColor"	=> "CEFFB5",				// Couleur de fond de l'entête dans le cas ou ce dernier n'a pas d'image
282		);
283	 * @param String $type est le type a créer, soit un entête soit un pied de page
284	 * @param $pageMasterName
285	 * @return none
286	 **/
287	function addStyleHeadFoot($styleArg, $type, $pageMasterName){
288
289		if ($type != "Header" && $type != "Footer") {
290		    $this -> ErrorTracker(4, "Le type demander doit être Header ou Footer", 'addStyleHeadFoot', __FILE__, __LINE__);
291		}
292		$this->verifIntegrite($styleArg, $type);
293		$headerStyleNode = & $this->getNode("/office:document-styles/office:automatic-styles/style:page-master@[style:name='".$pageMasterName."']/style:".strtolower($type)."-style");
294		$headerStyleNode->appendChild($this->setProperties($styleArg, $this->DIRXML));
295
296		$automaticStylesNode = & $this->getNode("/office:document-styles/office:automatic-styles");
297		$StyleName = "S".$this->STYLNUM['style_family_text'];
298		if (!$this->ssNodeExist($automaticStylesNode, "style:style@[style:name='".$StyleName."']")){
299			$styleNode = & $this->xml->createElement("style:style");
300			$styleNode->setAttribute("style:name", $StyleName);
301			$STYLNUM['style_family_text']++;
302			$styleNode->setAttribute("style:family", "paragraph");
303			$styleNode->setAttribute("style:parent-style-name", $type);
304		}
305
306		$propertiesNode =& $this->xml->createElement("style:properties");
307		$propertiesNode->setAttribute("fo:text-align", $styleArg["align"]);
308		$propertiesNode->setAttribute("style:justify-single-word", "false");
309
310		$styleNode->appendChild($propertiesNode);
311		$automaticStylesNode->appendChild($styleNode);
312
313		$masterPageNode = & $this->getNode("/office:document-styles/office:master-styles/style:master-page@[style:page-master-name='".$pageMasterName."']");
314
315		$headerNode =& $this->xml->createElement("style:".strtolower($type));
316
317		/********************Création de la cellule********************/
318		if (isset($styleArg["Text"]) && is_object($styleArg["Text"])){
319
320			if ($styleArg["Text"]->className() == "oooimg") {
321				$pNode =& $this->xml->createElement("text:p");
322				$pNode->setAttribute("text:style-name", $StyleName);
323				$headerNode->appendChild($pNode);
324				$styleArg["Text"]->run($pNode, $automaticStylesNode, $this->DIRXML);
325			} else {
326				$styleArg["Text"]->run($headerNode, $automaticStylesNode, $this->DIRXML);
327			}
328
329		} else {
330			$pNode =& $this->xml->createElement("text:p");
331			$pNode->setAttribute("text:style-name", $StyleName);
332			$pNode->appendChild($this->xml->createTextNode($styleArg["Text"]));
333			$headerNode->appendChild($pNode);
334		}
335		/**********************Fin de Création*************************/
336		$masterPageNode->appendChild($headerNode);
337	}
338
339
340	function addGraphicStyle(){
341		$stylesNode = & $this->getNode("/office:document-styles/office:styles");
342		$styleNode = & $this->xml->createElement("style:default-style");
343		$styleNode->setAttribute("style:family", "graphics");
344
345		$propertiesNode =& $this->xml->createElement("style:properties");
346		$propertiesNode->setAttribute("draw:start-line-spacing-horizontal", "0.283cm");
347		$propertiesNode->setAttribute("draw:start-line-spacing-vertical", "0.283cm");
348		$propertiesNode->setAttribute("style:use-window-font-color", "true");
349		$propertiesNode->setAttribute("style:font-name", "Thorndale");
350		$propertiesNode->setAttribute("fo:font-size", "12pt");
351		$propertiesNode->setAttribute("fo:language", "fr");
352		$propertiesNode->setAttribute("fo:country", "FR");
353		$propertiesNode->setAttribute("style:font-name-asian", "Andale Sans UI");
354		$propertiesNode->setAttribute("style:font-size-asian", "12pt");
355		$propertiesNode->setAttribute("style:language-asian", "none");
356		$propertiesNode->setAttribute("style:font-name-complex", "none");
357		$propertiesNode->setAttribute("style:country-complex", "none");
358		$propertiesNode->setAttribute("style:text-autospace", "ideograph-alpha");
359		$propertiesNode->setAttribute("style:line-break", "strict");
360		$propertiesNode->setAttribute("style:writing-mode", "lr-tb");
361		$propertiesNode->setAttribute("country-asian", "none");
362
363		$tabStopsNode =& $this->xml->createElement("style:tab-stops");
364
365		$propertiesNode->appendChild($tabStopsNode);
366		$styleNode->appendChild($propertiesNode);
367		$stylesNode->appendChild($styleNode);
368	}
369
370
371
372
373}
374