|
From: <nma...@us...> - 2006-03-13 08:14:26
|
Revision: 19 Author: nmarkgraf Date: 2006-03-13 00:14:08 -0800 (Mon, 13 Mar 2006) ViewCVS: http://svn.sourceforge.net/opendocumentphp/?rev=19&view=rev Log Message: ----------- This is a major bug fixing and new stuff commit. - Reverted Alex deletion of TestOutput.php, because my new version is better than the old. - Put some new namespaces in OpenDocumentObjectAbstract to match more namespaces used in OpenDocument format documentation. - Rewrite OpenDocumentContent and OpenDocumentStyle classes to use style/FontFaceDeclaration and a new way to submit fo: and style: attributes. Take a look at samples/TestOutput.php to see what is new (compared to OpenDocumentOutput) - Also some comments and tiny typos are corrected. @Alex: I don't think we need an extra OpenDocumentOutput class, but I haven't changed it by now. Norman Modified Paths: -------------- poc/src/OpenDocumentContent.php poc/src/OpenDocumentMeta.php poc/src/OpenDocumentObjectAbstract.php poc/src/OpenDocumentSingle.php poc/src/OpenDocumentStyle.php Added Paths: ----------- poc/src/samples/TestOutput.php poc/src/styles/ poc/src/styles/FontFaceDeclaration.php Modified: poc/src/OpenDocumentContent.php =================================================================== --- poc/src/OpenDocumentContent.php 2006-03-13 07:42:56 UTC (rev 18) +++ poc/src/OpenDocumentContent.php 2006-03-13 08:14:08 UTC (rev 19) @@ -7,6 +7,8 @@ * @version $Revision$ * @package OpenDocument * + * @since 0.4.0 + * * $Id$ */ @@ -18,10 +20,13 @@ private $body; private $text; - /**I - * - */ - public function __construct( $dom=0 ) { + /** + * + * @access public + * + * @since 0.4.0 + */ + public function __construct( $dom=0, $root=0 ) { parent::__construct(); $this->logger->debug( "Constructing OpenDocumentContent." ); if (empty($dom)) { @@ -36,21 +41,19 @@ } else { // this is part of a single document $this->dom = $dom; - $this->content = $this->dom; + $this->content = $root; $this->root = $this->dom->createElementNS( self::NS_OFFICE, "office:content" ); } - $this->FontFaceDecl = $this->dom->createElementNS( self::NS_OFFICE, "office:font-face-decl" ); + $this->FontFaceDecl = new FontFaceDelcation(); $this->body = new OpenDocumentContentBody( $this->dom ); -/* - $this->body = $this->dom->createElementNS( self::NS_OFFICE, "office:body" ); - $this->text = $this->dom->createElementNS( self::NS_OFFICE, "office:text" ); -*/ - } - /** - * - */ + /** + * + * @access public + * + * @since 0.4.0 + */ public function __destruct() { unset( $this->dom ); unset( $this->root ); @@ -58,22 +61,54 @@ unset( $this->FontFaceDecl ); } + /** + * + * @access public + * + * @since 0.4.0 + */ public function addNoScript() { $this->root->appendChild( $this->dom->createElementNS( self::NS_OFFICE, "office:script" ) ); } - public function addFontFace( $name, $fontFamily ) { - $font = $this->dom->createElementNS( self::NS_STYLE, "style:font-face" ); - $font->setAttributeNS( self::NS_STYLE, "style:name", $name ); - $font->setAttributeNS( self::NS_SVG, "svg:font-family", $fontFamily ); - $this->FontFaceDecl->appendChild( $font ); - unset( $font ); + /** + * + * @deprecated + * + * @access public + * + * @since 0.4.0 + */ + public function addFontFace( $name, $fontFamily, $genericFamily=0, $fontPitch=0, $fontCharset=0 ) { + $this->FontFaceDecl->addFontFaceOld( $name, $fontFamily, $genericFamily, $fontPitch, $fontCharset ); } + /** + * + * @access public + * + * @since 0.4.2 + */ + public function getFontFaceDecl() { + return $this->FontFaceDecl; + } + + /** + * + * @access public + * + * @since 0.4.0 + */ public function addAutomaticStyles() { } + /** + * + * @access public + * + * @since 0.4.0 + */ public function addNoAutomaticStyles() { $this->root->appendChild( $this->dom->createElementNS( self::NS_OFFICE, "office:automatics-sytles" ) ); } @@ -89,26 +124,42 @@ */ - public function getBody() { - return $this->body; - } + /** + * + * @return + * + * @access public + * + * @since 0.4.0 + */ + public function getBody() { + return $this->body; + } - /** - * - */ + /** + * + * @access public + * + * @since 0.4.0 + */ public function commit() { - $this->root->appendChild( $this->FontFaceDecl ); - // $this->body->appendChild( $this->text ); + $this->root->appendChild( $this->FontFaceDecl->get() ); $this->root->appendChild( $this->body->get() ); $this->content->appendChild( $this->root ); $this->dom->normalize(); $this->isCommited = true; } - /** - * @return - */ + /** + * + * @return DOMDocument + * + * @access public + * @final + * + * @since 0.4.0 + */ final public function get() { if (!$this->isCommited) { $this->commit(); @@ -116,13 +167,18 @@ return $this->dom; } - /** - * - */ + /** + * + * @param $filename string + * + * @access public + * @final + * + * @since 0.4.0 + */ final public function save( $filename ) { $this->get()->save( $filename ); } } - ?> \ No newline at end of file Modified: poc/src/OpenDocumentMeta.php =================================================================== --- poc/src/OpenDocumentMeta.php 2006-03-13 07:42:56 UTC (rev 18) +++ poc/src/OpenDocumentMeta.php 2006-03-13 08:14:08 UTC (rev 19) @@ -3,7 +3,7 @@ * OpenDocumentMeta Class * * @license GNU General Public License - * @copyright Copyright © 2006, Norman Markgraf, et. al. + * @copyright Copyright © 2006, Norman Markgraf, et al. * @author Norman Markgraf <nma...@us...> * @version $Revision$ * @package OpenDocument @@ -24,7 +24,7 @@ * * @since 0.3.0 */ - public function __construct( $dom=0 ) { + public function __construct( $dom=0, $root=0 ) { parent::__construct(); $this->logger->debug( "Constructing OpenDocumentMeta." ); @@ -43,7 +43,7 @@ } else { // this is part of a single document $this->dom = $dom; - $this->meta = $this->dom; + $this->meta = $root; } $this->root = $this->dom->createElementNS( self::NS_OFFICE, "office:meta" ); } Modified: poc/src/OpenDocumentObjectAbstract.php =================================================================== --- poc/src/OpenDocumentObjectAbstract.php 2006-03-13 07:42:56 UTC (rev 18) +++ poc/src/OpenDocumentObjectAbstract.php 2006-03-13 08:14:08 UTC (rev 19) @@ -2,8 +2,8 @@ /** * OpenDocumentObjectAbstract Class * - * @license GNU General Public License - * @copyright Copyright © 2006, Norman Markgraf, et. al. + * @license GNU General Public License + * @copyright Copyright © 2006, Norman Markgraf, et al. * @author Norman Markgraf <nma...@us...> * @version $Revision$ * @package OpenDocument @@ -16,14 +16,9 @@ class OpenDocumentObjectAbstract extends OpenDocumentAbstract { /** - * namespace Dublin Core - */ - const NS_DC = "http://purl.org/dc/elements/1.1/"; - - /** * namespace OpenDocument meta */ - const NS_META = "urn:oasis:names:tc:opendocument:xmlns:meta:1.0"; + const NS_META = "urn:oasis:names:tc:opendocument:xmlns:meta:1.0"; /** * namespace OpenDocument office @@ -41,16 +36,6 @@ const NS_STYLE = "urn:oasis:names:tc:opendocument:xmlns:style:1.0"; /** - * namespace OpenDocument svg - */ - const NS_SVG = "urn:oasis:names:tc:openedocument:xmlsns:svg-compartible:1.0"; - - /** - * namespace OpenDocument fo (formation objects) - */ - const NS_FO = "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compartible:1.0"; - - /** * namespace OpenDocument text */ const NS_TEXT = "urn:oasis:names:tc:opendocument:xmlns:text:1.0"; @@ -79,9 +64,85 @@ * namespace OpenDocument form */ const NS_FORM = "urn:oasis:names:tc:opendocument:xmlns:form:1.0"; - + + /** + * namespace OpenDocument config + */ + const NS_CONFIG = "urn:oasis:names:tc:opendocument:xmlns:config:1.0"; + + /** + * namespace OpenDocument presentation + */ + const NS_PRESENTATION = "urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"; + + /** + * namespace OpenDocument dr3d + */ + const NS_DR3D = "urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"; + + /** + * namespace OpenDocument animation + */ + const NS_ANIM = "urn:oasis:names:tc:opendocument:xmlns:animation:1.0"; + + /** + * namespace OpenDocument chart + */ + const NS_CHART = "urn:oasis:names:tc:opendocument:xmlns:chart:1.0"; + + /** + * namespace OpenDocument script + */ + const NS_SCRIPT = "urn:oasis:names:tc:opendocument:xmlns:script:1.0"; + + /** + * namespace OpenDocument number + */ + const NS_NUMBER = "urn:oasis:names:tc:opendocument:xmlns:number:1.0"; + + /** + * namespace OpenDocument svg + */ + const NS_SVG = "urn:oasis:names:tc:openedocument:xmlsns:svg-compartible:1.0"; + + /** + * namespace OpenDocument fo (formation objects) + */ + const NS_FO = "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compartible:1.0"; + + /** + * namespace OpenDocument smil + */ + const NS_SMIL = "urn:oasis:names:tc:opendocument:xmlns:smil-compartible:1.0"; + + /** + * namespace Dublin Core + */ + const NS_DC = "http://purl.org/dc/elements/1.1/"; + + /** + * namespace XLink + */ + const NS_XLINK = "http://www.w3.org/1999/xlink"; + + /** + * namespace XForms + */ + const NS_XFORMS = "http://www.w3.org/2002/xforms"; + + /** + * namespace MathML + */ + const NS_MATHML = "http://www.w3.org/1998/Math/MathML"; + + /** + * @access protected + */ protected $dom; + /** + * @access protected + */ protected $isCommited; /** Modified: poc/src/OpenDocumentSingle.php =================================================================== --- poc/src/OpenDocumentSingle.php 2006-03-13 07:42:56 UTC (rev 18) +++ poc/src/OpenDocumentSingle.php 2006-03-13 08:14:08 UTC (rev 19) @@ -2,10 +2,13 @@ /** * OpenDocumentSingle Class * - * @copyright GNU General Public License + * @license GNU General Public License + * @copyright Copyright © 2006, Norman Markgraf, et al. * @author Norman Markgraf <nma...@us...> * @version $Revision$ * @package OpenDocument + * + * @since 0.3.0 * * $Id$ */ @@ -13,11 +16,15 @@ class OpenDocumentSingle extends OpenDocumentAbstract implements OpenDocument { private $isCommited; private $dom; + private $root; - /** - * - */ - public function __construct( $mimetype = "application/vnd.oasis.opendocument.text" ) { + /** + * + * @access public + * + * @since 0.3.0 + */ + public function __construct( $mimetype = self::defaultMimeType ) { parent::__construct( $mimetype ); $this->logger->debug( "Constructing OpenDocumentSingle." ); @@ -25,42 +32,66 @@ $this->isCommited = false; $this->dom = new DOMDocument( "1.0", "utf-8" ); + $this->root = $this->dom->createElementNS( self::NS_OFFICE, "office:document" ); + $this->root->setAttributeNS( self::NS_OFFICE, "office:mimetype", $mimetype ); } - /** - * - */ + /** + * + * @access public + * + * @since 0.3.0 + */ public function __destruct() { $this->logger->debug( "OpenDocumentSingle destructed." ); parent::__destruct(); } - /** - * - */ + /** + * + * @access public + * + * @since 0.3.0 + */ public function addImage( $fullpath, $origimage, $mimetype ) { $this->copyFileToPackage( $origimage, $fullpath ); $this->makeSubDir( "Pictures" ); $this->manifest->addEntryToManifest( $fullpath, $mimetype ); } - /** - * - */ + /** + * + * @access public + * + * @since 0.3.0 + */ public function addXMLDocument( $fullpath, $domFrag, $mimetype="text/xml" ) { $this->logger->info( "OpenDocumentSingle->addXMLDocument(" . $fullpath . ") with mimetype '" . $mimetype . "' to package '". $this->packagetmp . "'" ); $this->dom->appendChild( $domFrag ); } + /** + * + * @access private + * + * @since 0.3.0 + */ private function commit() { $this->logger->debug( "OpenDocumentSingle->commit()" ); foreach( $this->DocumentObjects as $key => $class) { $class->commit(); } + $this->dom->appendChild( $this->root ); $this->isCommited = true; } + /** + * + * @access public + * + * @since 0.3.0 + */ public function get() { if (!($this->isCommited)) { $this->commit(); @@ -69,31 +100,53 @@ return $this->dom->saveXML(); } + /** + * + * @access public + * + * @since 0.3.0 + */ public function save( $altFilename=0 ) { $this->writeZIPFile( $this->get() ); } + /** + * + * @access public + * + * @since 0.3.0 + */ public function getMeta() { - if (!array_key_exists ( "meta", $this->DocumentObjects) ) { - $this->DocumentObjects[ "meta" ] = new OpenDocumentMeta( $this->dom ); + if ( !array_key_exists( "meta", $this->DocumentObjects ) ) { + $this->DocumentObjects[ "meta" ] = new OpenDocumentMeta( $this->dom, $this->root ); } return $this->DocumentObjects[ "meta" ]; } + /** + * + * @access public + * + * @since 0.3.0 + */ public function getContent() { - if (!array_key_exists ( "content", $this->DocumentObjects) ) { - $this->DocumentObjects[ "content" ] = new OpenDocumentContent( $this->dom ); + if ( !array_key_exists( "content", $this->DocumentObjects ) ) { + $this->DocumentObjects[ "content" ] = new OpenDocumentContent( $this->dom, $this->root ); } return $this->DocumentObjects[ "content" ]; } + /** + * + * @access public + * + * @since 0.3.0 + */ public function getStyle() { - if (!array_key_exists ( "style", $this->DocumentObjects) ) { - $this->DocumentObjects[ "style" ] = new OpenDocumentStyle( $this->dom ); + if ( !array_key_exists( "style", $this->DocumentObjects ) ) { + $this->DocumentObjects[ "style" ] = new OpenDocumentStyle( $this->dom, $this->root ); } return $this->DocumentObjects[ "style" ]; } - } - ?> \ No newline at end of file Modified: poc/src/OpenDocumentStyle.php =================================================================== --- poc/src/OpenDocumentStyle.php 2006-03-13 07:42:56 UTC (rev 18) +++ poc/src/OpenDocumentStyle.php 2006-03-13 08:14:08 UTC (rev 19) @@ -2,14 +2,19 @@ /** * OpenDocumentStyle Class * - * @copyright GNU General Public License + * @license GNU General Public License + * @copyright Copyright © 2006, Norman Markgraf et al. * @author Norman Markgraf <nma...@us...> * @version $Revision$ * @package OpenDocument * + * @since 0.4.0 + * * $Id$ */ +//require_once( "styles/FontFaceDecl.php" ); + class OpenDocumentStyle extends OpenDocumentObjectAbstract { private $root; @@ -17,10 +22,14 @@ private $FontFaceDecl; private $Styles; private $DefaultStyles; - /** - * - */ - public function __construct( $dom=0 ) { + + /** + * + * @access public + * + * @since 0.4.0 + */ + public function __construct( $dom=0, $root=0 ) { parent::__construct(); if (empty($dom)) { @@ -35,104 +44,215 @@ } else { // this is part of a single document $this->dom = $dom; - $this->style = $this->dom; + $this->style = $root; $this->root = $this->dom->createElementNS( self::NS_OFFICE, "office:style" ); } - $this->FontFaceDecl = $this->dom->createElementNS( self::NS_OFFICE, "office:font-face-decl" ); + $this->FontFaceDecl = new FontFaceDeclaration( $this->dom ); $this->Styles = array(); $this->DefaultStyles = array(); } - /** - * - */ + /** + * + * @access public + * + * @since 0.4.0 + */ public function __destruct() { unset( $this->dom ); unset( $this->root ); unset( $this->style ); } + /** + * + * @deprecated + * + * @access public + * + * @since 0.4.0 + */ public function addFontFace( $name, $fontFamily, $genericFamily=0, $fontPitch=0, $fontCharset=0 ) { - $font = $this->dom->createElementNS( self::NS_STYLE, "style:font-face" ); - $font->setAttributeNS( self::NS_STYLE, "style:name", $name ); - $font->setAttributeNS( self::NS_SVG, "svg:font-family", $fontFamily ); - if (!empty($genericFamily)) { - $font->setAttributeNS( self::NS_STYLE, "style:font-family-genric", $genericFamily ); - } - if (!empty($fontPitch)) { - $font->setAttributeNS( self::NS_STYLE, "style:font-pitch", $fontPitch ); - } - if (!empty($fontCharset)) { - $font->setAttributeNS( self::NS_STYLE, "style:font-charset", $fontCharset ); - } - $this->FontFaceDecl->appendChild( $font ); - unset( $font ); + $this->FontFaceDecl->addFontFaceOld( $name, $fontFamily, $genericFamily, $fontPitch, $fontCharset ); } - public function getDom() { - return $this->dom; + /** + * + * common family names: graphic, paragraph, table, table-row + * + * @access public + * + * @since 0.4.2 + */ + public function addDefaultStyle( $family = 0 ) { + $node = $this->dom->createElementNS( self::NS_STYLE, "style:default-style" ); + if (!empty($family)) { + $node->setAttributeNS( self::NS_STYLE, "style:family", $family ); + } + $this->DefaultStyles[ $family ] = $node; } - /** - * - * common family names: graphic, paragraph, table, table-row - */ - public function getDefaultStyle( $family=0 ) { - if (!empty($gamily) && array_key_exists($family, $this->DefaultStyles) ) { - return $this->DefaultStyles[$name]; - } else { - $node = $this->dom->createElementNS( self::NS_STYLE, "style:default-style" ); - if (!empty($family)) { - $node->setAttributeNS( self::NS_STYLE, "style:family", $family ); + /** + * + * + * @access private + * + * @since 0.4.2 + */ + private function addParagraphPropertiesToNode( $node, $styleAttr, $foAttr ) { + $ParProp = $this->dom->createElementNS( self::NS_STYLE, "style:paragraph-properties" ); + if (!empty($styleAttr)) { + foreach( $styleAttr as $key=>$value ) { + $ParProp->setAttributeNS( self::NS_STYLE, "style:".$key, $value ); + } + } + if (!empty($foAttr)) { + foreach( $foAttr as $key=>$value ) { + $ParProp->setAttributeNS( self::NS_FO, "fo:".$key, $value ); + } + } + $node->appendChild( $ParProp ); + } + + /** + * + * + * @access private + * + * @since 0.4.2 + */ + private function addTextPropertiesToNode( $node, $styleAttr, $foAttr ) { + $ParProp = $this->dom->createElementNS( self::NS_STYLE, "style:text-properties" ); + if (!empty($styleAttr)) { + foreach( $styleAttr as $key=>$value ) { + $ParProp->setAttributeNS( self::NS_STYLE, "style:".$key, $value ); + } + } + if (!empty($foAttr)) { + foreach( $foAttr as $key=>$value ) { + $ParProp->setAttributeNS( self::NS_FO, "fo:".$key, $value ); + } + } + $node->appendChild( $ParProp ); + } + + /** + * + * + * @access public + * + * @since 0.4.2 + */ + public function addDefaultStyleParagraphProperties( $family, $styleAttr=0, $foAttr=0 ) { + $node = $this->getDefaultStyle( $family ); + if (empty($node)) { + die("W\xFCrg:" . $family ); } - return $node; - } + $this->addParagraphPropertiesToNode( $node, $styleAttr, $foAttr ); } - /** - * - * common family names: graphic, paragraph, table, table-row - */ - public function addDefaultStyle( $DefaultStyle, $family=0 ) { - if (empty($family)) { - $this->DefaultStyles[] = $DefaultStyle; - } else { - $this->DefaultStyles[$name] = $DefaultStyle; - } + + /** + * + * + * @access public + * + * @since 0.4.2 + */ + public function addStyleParagraphProperties( $name, $styleAttr=0, $foAttr=0 ) { + $node = $this->getStyle( $name ); + $this->addParagraphPropertiesToNode( $node, $styleAttr, $foAttr ); } + + /** + * + * + * @access public + * + * @since 0.4.2 + */ + public function addDefaultStyleTextProperties( $family, $styleAttr, $foAttr ) { + $node = $this->getDefaultStyle( $family ); + $this->addTextPropertiesToNode( $node, $styleAttr, $foAttr ); + } + + /** + * + * + * @access public + * + * @since 0.4.2 + */ + public function addStyleTextProperties( $name, $styleAttr, $foAttr ) { + $node = $this->getStyle( $name ); + $this->addTextPropertiesToNode( $node, $styleAttr, $foAttr ); + } + + /** + * + * common family names: graphic, paragraph, table, table-row + * + * @access public + * + * @since 0.4.2 + */ + public function getDefaultStyle( $family = 0 ) { + return $this->DefaultStyles[ $family ]; + } - public function getStyle( $name ) { - if (array_key_exists($name, $this->Styles) ) { - return $this->Styles[$name]; - } else { - $node = $this->dom->createElementNS( self::NS_STYLE, "style:style" ); - $node->setAttributeNS( self::NS_STYLE, "style:name", $name ); - return $node; - } + /** + * + * @access public + * + * @since 0.4.2 + */ + public function addStyle( $name, $styleAttr=0 ) { + $node = $this->dom->createElementNS( self::NS_STYLE, "style:style" ); + $node->setAttributeNS( self::NS_STYLE, "style:name", $name ); + if (!empty($styleAttr)) { + foreach( $styleAttr as $key=>$value ) { + $node->setAttributeNS ( self::NS_STYLE, "style:".$key, $value ); + } + } + $this->Styles[ $name ] = $node; } - public function addStyle( $Style, $name=0 ) { - if (empty($name)) { - $this->Styles[] = $Style; - } else { - $this->Styles[$name] = $Style; - } + /** + * + * @access public + * + * @since 0.4.2 + */ + public function getStyle( $name=0 ) { + return $this->Styles[ $name ]; } + + /** + * + * @access public + * + * @since 0.4.2 + */ + public function getFontFaceDecl() { + return $this->FontFaceDecl; + } - - /** - * - */ + /** + * + * @access public + * + * @since 0.4.0 + */ public function commit() { - $this->root->appendChild( $this->FontFaceDecl ); + $this->root->appendChild( $this->FontFaceDecl->get() ); $styleStyle = $this->dom->createElementNS( self::NS_OFFICE, "office:style" ); // Add all DefaultStyles - foreach( $this->DefaultStyles as $aDefaultStyle) { + foreach( $this->DefaultStyles as $aDefaultStyle ) { $styleStyle->appendChild( $aDefaultStyle ); } // Add all Styles - foreach( $this->Styles as $aStyle) { + foreach( $this->Styles as $aStyle ) { $styleStyle->appendChild( $aStyle ); } $this->root->appendChild( $styleStyle ); @@ -142,9 +262,14 @@ $this->isCommited = true; } - /** - * @return - */ + /** + * + * @return DOMDocument + * + * @access public + * + * @since 0.4.0 + */ final public function get() { if (!$this->isCommited) { $this->commit(); @@ -152,13 +277,15 @@ return $this->dom; } - /** - * - */ + /** + * + * @access public + * @final + * + * @since 0.4.0 + */ final public function save( $filename ) { $this->get()->save( $filename ); - } - + } } - ?> \ No newline at end of file Added: poc/src/samples/TestOutput.php =================================================================== --- poc/src/samples/TestOutput.php (rev 0) +++ poc/src/samples/TestOutput.php 2006-03-13 08:14:08 UTC (rev 19) @@ -0,0 +1,194 @@ +<?php +/** + * SampleClass produces a little OpenDocument and send it to the client + * + * @copyright GNU General Public License + * @author Norman Markgraf <nma...@us...> + * @author Alex Latchford <yan...@us...> + * @version $Revision$ + * @package OpenDocument/Samples + * @since 0.4.2 + * + * $Id$ + */ + +ini_set( "include_path", ini_get( "include_path" ). ";..\\;..\\styles" ); + +require_once( "OpenDocumentFactory.php" ); +require_once( "Log/observer.php" ); + +class TestOutput { + + const DocumentName = "test.odt"; + + const PathToDocument = "D:/PHP/OpenDocument/"; + + private $logger; + + function __construct() { + /* ***TO DO *** This raises a warning ... + // $conf = array( "mode" => 0600 ); + $this->logger = &Log_observer::factory( "file", "D:/PHP/OpenDocument.log", "OpenDocument", $conf ); + $this->logger = &Log_observer::factory( "console", "", "OpenDocument" ); + */ + + /* + Console output: + $this->logger = &Log_observer::factory( "console", "", "OpenDocument" ); + + File output: + $this->logger = &Log_observer::factory( "file", "OpenDocument.log", "OpenDocument" ); + */ + } + + function makeMeta( $meta, $creator="Norman Markgraf", $title="This is a test!", $language="en-EN" ) { + $meta->addDublinCore( "title", $title ); + $meta->addDublinCore( "creator", $creator ); + $meta->addDublinCore( "language", "en-EN" ); + $meta->addDublinCore( "date", date("Y-m-d\TH:i:s") ); + $meta->addGenerator( "" ); + $meta->addInitialCreator( $creator ); + $meta->addCreationDate(); + } + + function makeContent( $content ) { + $content->addNoScript(); + + $content->addFontFace( "Test", "Tahoma" ); + + $content->addNoAutomaticStyles(); + + $text = $content->getBody()->getText(); + + $text->addNoForms(); + + $text->addToText( $text->getTextHeading( "Heading", "The first step" ) ); + $text->addToText( $text->getTextParagraph( "Paragraph", "This is a little test!" ) ); + } + + function makeStyle( $style ) { + $styleAttr = array(); + $styleAttr[ "font-family" ] ="Tahoma"; + $style->getFontFaceDecl()->addFontFace( "Test", $styleAttr ); + unset( $styleAttr ); + + // Set default style + $style->addDefaultStyle( "paragraph" ); + + $foAttr = array( "hypenation-ladder-count" => "no-limit" ); + + $styleAttr = array(); + $styleAttr[ "text-autospace" ] = "ideograph-alpha"; + $styleAttr[ "punctuation-wrap" ] = "hanging"; + $styleAttr[ "line-break" ] = "strict"; + $styleAttr[ "tab-stop-distance" ] = "1.251cm"; + $styleAttr[ "writeing-mode" ] = "page"; + + $style->addDefaultStyleParagraphProperties( "paragraph", $styleAttr, $foAttr ); + + unset( $foAttr ); + unset( $styleAttr ); + + $foAttr = array(); + $foAttr[ "font-size" ] = "12pt"; + $foAttr[ "language" ] = "de"; + $foAttr[ "country" ] = "DE"; + $foAttr[ "hyphenate" ] = "false"; + $foAttr[ "hypenation-remain-char-count" ] = "2"; + $foAttr[ "hypenation-push-char-count" ] = "2"; + + $styleAttr = array(); + $styleAttr[ "use-window-font-color" ] = "true"; + $styleAttr[ "font-name" ] = "Times New Roman"; + $styleAttr[ "font-name-asian" ] = "Arial Unicode MS"; + $styleAttr[ "font-size-asian" ] = "12pt"; + $styleAttr[ "language-asian" ] = "none"; + $styleAttr[ "country-asian" ] = "none"; + $styleAttr[ "font-name-complex" ] = "Tahoma"; + $styleAttr[ "font-site-complex" ] = "12pt"; + $styleAttr[ "language-complex" ] = "none"; + $styleAttr[ "country-complex" ] = "none"; + + $style->addDefaultStyleTextProperties( "paragraph", $styleAttr, $foAttr ); + + //Set a style + $styleAttr = array( "family"=>"paragraph", "class"=>"text" ); + $style->addStyle( "Paragraph", $styleAttr ); + + //Set a style + $style->addStyle( "Heading", $styleAttr ); + + unset( $styleAttr ); + unset( $foAttr ); + + $foAttr = array( "margin-top"=>"0.423cm", "margin-bottom"=>"0.212cm", "keep-with-next"=>"always" ); + $style->addStyleParagraphProperties( "Heading", 0, $foAttr ); + + unset( $foAttr ); + + $foAttr = array( "font-size" => "20pt" ); + $styleAttr = array(); + $styleAttr[ "font-name" ] = "Arial"; + $styleAttr[ "font-name-asian" ] = "MS Mincho"; + $styleAttr[ "font-size" ] = "20pt"; + $styleAttr[ "font-name-complex" ] = "Tahoma1"; + $styleAttr[ "font-size-complex" ] = "20pt"; + $style->addStyleTextProperties( "Heading", $styleAttr, $foAttr ); + } + + function run($post) { + if (!function_exists('gzencode')) { + $out = "<p>You have to enable zlib at compile time of your PHP! "; + $out .= "use <emph>--with-zlib=[DIR]</emph> at the <emph>configure</emph> "; + $out .= "procedure</p>"; + echo $out; + return; + } + + $SingleDocument = ($post["SingleDocument"] == "true"); + $creator = $post["Creator"]; + $title = $post["Title"]; + + + + header( "Content-type: application/odt" ); + header( "Content-Disposition: attachment; filename=".self::DocumentName ); + header( "Cache-Control: no-store, no-cache, must-revalidate" ); // HTTP/1.1 + header( "Cache-Control: post-check=0, pre-check=0", false ); + header( "Pragma: no-cache" ); + + // Get a OpenDocument object from the factory: + + if(isset($SingleDocument)) + { + $TestDoc = OpenDocumentFactory::createOpenDocument( + self::DocumentName, + self::PathToDocument, + $SingleDocument + ); + + /* + $TestDoc->attachObserverToLogger( $this->logger ); + */ + + $this->makeMeta( $TestDoc->getMeta(), $creator, $title, "en-EN" ); + $this->makeStyle( $TestDoc->getStyle() ); + $this->makeContent( $TestDoc->getContent() ); + + echo $TestDoc->get(); + + //$TestDoc->save(); + } + + + } +} + +if(isset($_POST['SingleDocument'])) +{ + $TestOutput = new TestOutput(); + $TestOutput->run($_POST); +} + +// Do TestInput again ... +?> Property changes on: poc/src/samples/TestOutput.php ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: poc/src/styles/FontFaceDeclaration.php =================================================================== --- poc/src/styles/FontFaceDeclaration.php (rev 0) +++ poc/src/styles/FontFaceDeclaration.php 2006-03-13 08:14:08 UTC (rev 19) @@ -0,0 +1,168 @@ +<?php +/** + * FontFaceDeclaration Class + * + * @license GNU General Public License + * @copyright Copyright © 2006, Norman Markgraf + * @author Norman Markgraf <nma...@us...> + * @version $Revision$ + * @package OpenDocument + * + * @since 0.4.2 + * + * $Id$ + */ + +class FontFaceDeclaration extends OpenDocumentObjectAbstract { + + private $FontFaceDecl; + + /** + * + * @param DOMDocument $dom + * + * @access public + * + * @since 0.4.2 + */ + public function __construct( $dom ) { + parent::__construct(); + + $this->dom = $dom; + + $this->FontFaceDecl = $this->dom->createElementNS( self::NS_OFFICE, "office:font-face-decl" ); + } + + /** + * + * @access public + * + * @since 0.4.2 + */ + private function checkStyle( $key, $value ) { + switch ($key) { + case "font-family" : + case "font-style" : + case "font-variant" : + case "font-weight" : + case "font-size" : + case "unicode-range" : + case "units-per-em" : + case "panose-1" : + case "stemv" : + case "stemh" : + case "slope" : + case "cap-height" : + case "x-height" : + case "accent-height" : + case "ascent" : + case "descent" : + case "widths" : + case "bbox" : + case "ideographics" : + case "alphabetic" : + case "mathematical" : + case "hanging" : + // ***FIX ME*** here should be more ... + case "font-face-name" : + case "font-face-format" : return true; + case "font-strech" : + $values = array( "normal", "ultra-condensed", "extra-condensed", "condensed", "semi-condensed", + "semi-expanded", "expanded", "extra-expanded", "ultra-expanded" ); + return in_array( $value, $values ); + break; + default: // ***FIX ME*** should be "false"! + return true; + } + } + + /** + * + * @access public + * + * @since 0.4.2 + */ + private function checkStyle( $key, $value ) { + switch ($key) { + default: // ***FIX ME*** should be "false"! + return true; + } + } + + /** + * + * @access public + * + * @since 0.4.2 + */ + public function addFontFace( $name, $styleAttr=0, $SVGAttr=0 ) { + $font = $this->dom->createElementNS( self::NS_STYLE, "style:font-face" ); + $font->setAttributeNS( self::NS_STYLE, "style:name", $name ); + if (!empty($styleAttr)) { + foreach( $styleAttr as $key => $value ) { + // ***FIX ME*** Here we should check if the keys are possible + if ($this->checkStyle($key, $value)) { + $font->setAttributeNS( self::NS_STYLE, "style:".$key, $value ); + } + } + } + if (!empty($SVGAtrr)) { + foreach( $SVGAttr as $key => $value ) { + // ***FIX ME*** Here we should check if the keys are possible + if ($this->checkSVG( $key, $value )) { + $font->setAttributeNS( self::NS_SVG, "svg:".$key, $value ); + } + } + } + $this->FontFaceDecl->appendChild( $font ); + unset( $font ); + } + + /** + * + * @access public + * + * @since 0.4.2 + */ + public function addFontFaceOld( $name, $fontFamily, $genericFamily=0, $fontPitch=0, $fontCharset=0 ) { + $styleAttr = array( "font-family" => $fontFamily ); + if (!empty($genericFamily)) { + $styleAttr[ "font-family-generic" ] = $gernericFamily; + } + if (!empty($fontPitch)) { + $styleAttr[ "font-pitch" ] = $fontPitch; + } + if (!empty($fontCharset)) { + $styleAttr[ "font-charset" ] = $fontCharset; + } + $this->addFontFace( $name, $styleAttr ); + } + + /** + * + * @access public + * + * @since 0.4.2 + */ + public function commit() { + $this->isCommited = true; + } + + /** + * + * @return DOMDocument + * + * @access public + * @final + * + * @since 0.4.2 + */ + final public function get() { + if (!$this->isCommited) { + $this->commit(); + } + return $this->FontFaceDecl; + } + +} +?> \ No newline at end of file Property changes on: poc/src/styles/FontFaceDeclaration.php ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |