public function testLoadErroneousXmlDocumentSilent() { $doc = new ezcDocumentDocbook(); $doc->options->failOnError = false; $doc->loadFile(dirname(__FILE__) . '/files/xhtml_sample_errnous.xml'); $this->assertTrue($doc->getDomDocument() instanceof DOMDocument, 'DOMDocument not created properly'); }
/** * Converts the given DocBook $source to an ODT document. * * This method receives a DocBook $source document and returns the * converters ODT document. * * @param ezcDocumentDocbook $source * @return ezcDocumentOdt */ public function convert($source) { $destination = $this->initializeDocument(); $docBookDom = $this->makeLocateable($source->getDomDocument()); $this->options->styler->init($destination->ownerDocument); $this->imageLocator = new ezcDocumentOdtImageLocator($source); $destination = $this->visitChildren($docBookDom, $destination); return $this->createDocument($destination); }
/** * Convert documents between two formats * * Convert documents of the given type to the requested type. * * @param ezcDocumentDocbook $source * @return ezcDocumentDocument */ public function convert($source) { $destination = $this->initializeDocument(); $destination = $this->visitChildren($source->getDomDocument(), $destination); return $this->createDocument($destination); }
/** * Render given document * * Returns the rendered PDF as string * * @param ezcDocumentDocbook $document * @param ezcDocumentPdfHyphenator $hyphenator * @param ezcDocumentPdfTokenizer $tokenizer * @return string */ public function render(ezcDocumentDocbook $document, ezcDocumentPdfHyphenator $hyphenator = null, ezcDocumentPdfTokenizer $tokenizer = null) { $this->hyphenator = $hyphenator !== null ? $hyphenator : new ezcDocumentPdfDefaultHyphenator(); $this->tokenizer = $tokenizer !== null ? $tokenizer : new ezcDocumentPdfDefaultTokenizer(); $this->document = $document; // Register custom fonts in driver $this->registerFonts(); // Inject custom element class, for style inferencing $dom = $document->getDomDocument(); // Reload the XML document with to a DOMDocument with a custom element // class. Just registering it on the existing document seems not to // work in all cases. $reloaded = new DOMDocument(); $reloaded->registerNodeClass('DOMElement', 'ezcDocumentLocateableDomElement'); $reloaded->loadXml($dom->saveXml()); $this->process($reloaded); return $this->driver->save(); }
/** * @dataProvider getItemizedListTypes */ public function testRenderItemizedListTypes($type, array $items) { $mock = $this->getMock('ezcTestDocumentPdfMockDriver', array('createPage', 'drawWord')); // Expectations $mock->expects($this->at(1))->method('drawWord')->with($this->equalTo(10, 1.0), $this->equalTo(18, 1.0), $this->equalTo($items[0])); $mock->expects($this->at(4))->method('drawWord')->with($this->equalTo(10, 1.0), $this->equalTo(33, 1.0), $this->equalTo($items[1])); $docbook = new ezcDocumentDocbook(); $docbook->loadFile(dirname(__FILE__) . '/../files/pdf/bullet_list.xml'); // Set numeration type in document $dom = $docbook->getDomDocument(); $xpath = new DOMXPath($dom); $xpath->registerNamespace('doc', 'http://docbook.org/ns/docbook'); $list = $xpath->evaluate('//doc:itemizedlist')->item(0); $list->setAttribute('mark', $type); $docbook->setDomDocument($dom); $renderer = new ezcDocumentPdfMainRenderer($mock, $this->styles); $pdf = $renderer->render($docbook, new ezcDocumentPdfDefaultHyphenator()); }
/** * Create document from docbook document * * A document of the docbook format is provided and the internal document * structure should be created out of this. * * This method is required for all formats to have one central format, so * that each format can be compiled into each other format using docbook as * an intermediate format. * * You may of course just call an existing converter for this conversion. * * @param ezcDocumentDocbook $document * @return void */ public function createFromDocbook(ezcDocumentDocbook $document) { $this->document = $document->getDomDocument(); }