/** * Test rendering of a full document * * Test the rendering of a given full document with an * additional set of user configured styles. * * @param string $file * @param string $fileName * @param array $styles * @return void */ protected function renderFullDocument($file, $fileName, array $styles = array()) { $docbook = new ezcDocumentDocbook(); $docbook->loadFile($file); $style = new ezcDocumentPcssStyleInferencer(); $style->appendStyleDirectives(array(new ezcDocumentPcssLayoutDirective(array('article'), array('font-family' => 'serif', 'line-height' => '1')), new ezcDocumentPcssLayoutDirective(array('title'), array('font-family' => 'sans-serif')))); $style->appendStyleDirectives($styles); $renderer = new ezcDocumentPdfMainRenderer(new ezcDocumentPdfSvgDriver(), $style, new ezcDocumentPdfOptions()); $pdf = $renderer->render($docbook, new ezcDocumentPdfDefaultHyphenator()); file_put_contents($this->tempDir . $fileName, $pdf); $this->assertXmlFileEqualsXmlFile($this->basePath . 'renderer/' . $fileName, $this->tempDir . $fileName); }
public function testRenderBlockquote() { // Additional formatting $mock = $this->getMock('ezcTestDocumentPdfMockDriver', array('createPage', 'drawWord')); // Expectations $mock->expects($this->at(0))->method('createPage')->with($this->equalTo(100, 1.0), $this->equalTo(100, 1.0)); $mock->expects($this->at(1))->method('drawWord')->with($this->equalTo(20, 1.0), $this->equalTo(21, 1.0), $this->equalTo("Some")); $mock->expects($this->at(2))->method('drawWord')->with($this->equalTo(35, 1.0), $this->equalTo(21, 1.0), $this->equalTo("random")); $mock->expects($this->at(4))->method('drawWord')->with($this->equalTo(20, 1.0), $this->equalTo(29.4, 1.0), $this->equalTo("which")); $mock->expects($this->at(13))->method('drawWord')->with($this->equalTo(25, 1.0), $this->equalTo(46.8, 1.0), $this->equalTo("Name")); $docbook = new ezcDocumentDocbook(); $docbook->loadFile(dirname(__FILE__) . '/../files/pdf/blockquote.xml'); $renderer = new ezcDocumentPdfMainRenderer($mock, $this->styles); $pdf = $renderer->render($docbook, new ezcDocumentPdfDefaultHyphenator()); }
public function testRenderDefinitionListWrapped() { $mock = $this->getMock('ezcTestDocumentPdfMockDriver', array('createPage', 'drawWord')); // Expectations $mock->expects($this->at(0))->method('createPage')->with($this->equalTo(100, 1.0), $this->equalTo(100, 1.0)); $mock->expects($this->at(1))->method('drawWord')->with($this->equalTo(10, 1.0), $this->equalTo(18, 1.0), $this->equalTo("A")); $mock->expects($this->at(4))->method('drawWord')->with($this->equalTo(10, 1.0), $this->equalTo(29.2, 1.0), $this->equalTo("is")); $mock->expects($this->at(10))->method('drawWord')->with($this->equalTo(15, 1.0), $this->equalTo(62.8, 1.0), $this->equalTo("The")); $mock->expects($this->at(20))->method('createPage')->with($this->equalTo(100, 1.0), $this->equalTo(100, 1.0)); $mock->expects($this->at(21))->method('drawWord')->with($this->equalTo(15, 1.0), $this->equalTo(18, 1.0), $this->equalTo("to")); $docbook = new ezcDocumentDocbook(); $docbook->loadFile(dirname(__FILE__) . '/../files/pdf/variablelist_long.xml'); $renderer = new ezcDocumentPdfMainRenderer($mock, $this->styles); $pdf = $renderer->render($docbook, new ezcDocumentPdfDefaultHyphenator()); }
public function testRenderLiterallayoutWrapped() { // Additional formatting $mock = $this->getMock('ezcTestDocumentPdfMockDriver', array('createPage', 'drawWord', 'drawPolygon', 'drawPolyline')); // Expectations $mock->expects($this->at(0))->method('createPage')->with($this->equalTo(100, 1.0), $this->equalTo(100, 1.0)); $mock->expects($this->at(5))->method('drawWord')->with($this->equalTo(12, 1.0), $this->equalTo(18, 1.0), $this->equalTo("1")); $mock->expects($this->at(13))->method('drawWord')->with($this->equalTo(12, 1.0), $this->equalTo(85.2, 1.0), $this->equalTo("9")); $mock->expects($this->at(14))->method('createPage')->with($this->equalTo(100, 1.0), $this->equalTo(100, 1.0)); $mock->expects($this->at(27))->method('createPage')->with($this->equalTo(100, 1.0), $this->equalTo(100, 1.0)); $mock->expects($this->at(32))->method('drawWord')->with($this->equalTo(12, 1.0), $this->equalTo(18, 1.0), $this->equalTo("9")); $mock->expects($this->at(33))->method('drawWord')->with($this->equalTo(12, 1.0), $this->equalTo(26.4, 1.0), $this->equalTo("0")); $docbook = new ezcDocumentDocbook(); $docbook->loadFile(dirname(__FILE__) . '/../files/pdf/literallayout_long.xml'); $renderer = new ezcDocumentPdfMainRenderer($mock, $this->styles); $pdf = $renderer->render($docbook, new ezcDocumentPdfDefaultHyphenator()); }
public function testRenderParagraphSplittingWithBorderLastPage() { // Additional formatting $this->styles->appendStyleDirectives(array(new ezcDocumentPcssLayoutDirective(array('para'), array('line-height' => '1', 'padding' => '5', 'margin' => '5', 'border' => '1mm solid #A00000', 'background-color' => '#eedbdb')))); $mock = $this->getMock('ezcTestDocumentPdfMockDriver', array('drawPolyline', 'drawPolygon', 'createPage', 'drawWord')); // Expectations for third page $mock->expects($this->at(38))->method('createPage')->with($this->equalTo(100, 1.0), $this->equalTo(100, 1.0)); $mock->expects($this->at(39))->method('drawPolygon')->with($this->equalTo(array(array(15, 15), array(85, 15), array(85, 51), array(15, 51)), 1.0), $this->equalTo(array('red' => 0.93, 'green' => 0.86, 'blue' => 0.86, 'alpha' => 0), 0.01)); $mock->expects($this->at(40))->method('drawPolyline')->with($this->equalTo(array(array(15.5, 15.5), array(15.5, 50.5)), 0.1), $this->equalTo(array('red' => 0.63, 'green' => 0.0, 'blue' => 0.0, 'alpha' => 0), 0.01)); $mock->expects($this->at(41))->method('drawPolyline')->with($this->equalTo(array(array(84.5, 15.5), array(84.5, 50.5)), 0.1), $this->equalTo(array('red' => 0.63, 'green' => 0.0, 'blue' => 0.0, 'alpha' => 0), 0.01)); $mock->expects($this->at(42))->method('drawPolyline')->with($this->equalTo(array(array(84.5, 50.5), array(15.5, 50.5)), 0.1), $this->equalTo(array('red' => 0.63, 'green' => 0.0, 'blue' => 0.0, 'alpha' => 0), 0.01)); $mock->expects($this->at(43))->method('drawWord')->with($this->equalTo(21, 1.0), $this->equalTo(29, 1.0), $this->equalTo('be')); $docbook = new ezcDocumentDocbook(); $docbook->loadFile(dirname(__FILE__) . '/../files/pdf/wrapping.xml'); $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) { if ($this->options->validate && $document->validateString($document) !== true) { $this->triggerError(E_WARNING, "You try to convert an invalid docbook document. This may lead to invalid output."); } $this->path = $document->getPath(); $this->options->driver->setOptions($this->options); $renderer = new ezcDocumentPdfMainRenderer($this->options->driver, $this->styles, $this->options); foreach ($this->pdfParts as $part) { $renderer->registerPdfPart($part); } $this->content = $renderer->render($document, $this->options->hyphenator, $this->options->tokenizer); // Merge errors from renderer $this->errors = array_merge($this->errors, $renderer->getErrors()); }
public function testRenderCustomFont() { $docbook = new ezcDocumentDocbook(); $docbook->loadFile(dirname(__FILE__) . '/../files/pdf/wrapping.xml'); $style = new ezcDocumentPcssStyleInferencer(); $style->appendStyleDirectives(array(new ezcDocumentPcssLayoutDirective(array('article'), array('font-family' => 'my-font')), new ezcDocumentPcssDeclarationDirective('@font-face', array('font-family' => 'my-font', 'src' => 'url( ' . dirname(__FILE__) . '/../files/fonts/font.ttf )')))); $renderer = new ezcDocumentPdfMainRenderer(new ezcDocumentPdfSvgDriver(), $style); $pdf = $renderer->render($docbook, new ezcDocumentPdfDefaultHyphenator()); $this->assertPdfDocumentsSimilar($pdf, __CLASS__ . '_' . __FUNCTION__); }
/** * @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()); }