public function setUp()
 {
     parent::setUp();
     $style = new ezcDocumentPcssStyleInferencer();
     $style->appendStyleDirectives(array(new ezcDocumentPcssLayoutDirective(array('article'), array('font-family' => 'serif', 'text-columns' => '2', 'font-size' => '10pt', 'line-height' => '1')), new ezcDocumentPcssLayoutDirective(array('title'), array('font-family' => 'sans-serif', 'text-columns' => '2')), new ezcDocumentPcssLayoutDirective(array('page'), array('page-size' => 'A5'))));
     $this->docbook = new ezcDocumentDocbook();
     $this->docbook->loadFile(dirname(__FILE__) . '/../files/pdf/long_text.xml');
     $this->renderer = new ezcDocumentPdfMainRenderer(new ezcDocumentPdfSvgDriver(), $style);
 }
Example #2
0
File: base.php Project: bmdevel/ezc
 /**
  * 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);
 }
Example #3
0
 /**
  * Adds a PCSS stylesheet from the given file.
  *
  * Reads the given PCSS $file and adds the contained stylesheets to the 
  * styler.
  * 
  * @param string $file 
  */
 public function addStylesheetFile($file)
 {
     $parser = $this->createStyleParser();
     if (!file_exists($file)) {
         throw new ezcBaseFileNotFoundException($file, 'PCSS');
     }
     if (!is_readable($file)) {
         throw new ezcBaseFilePermissionException($file, ezcBaseFileException::READ);
     }
     $this->styleInferencer->appendStyleDirectives($parser->parseFile($file));
 }
Example #4
0
 public function testDefinitionExtraction2()
 {
     $inferencer = new ezcDocumentPcssStyleInferencer(false);
     $inferencer->appendStyleDirectives(array($d1 = new ezcDocumentPcssDeclarationDirective('@font-FACE', array('font-size' => '10')), new ezcDocumentPcssDeclarationDirective('@unknown', array('font-size' => '10'))));
     $this->assertEquals(array($d1), $inferencer->getDefinitions('font-face'));
 }
Example #5
0
 /**
  * Load style definition file
  *
  * Parse and load a PCSS file and use the resulting style definitions for
  * rendering.
  *
  * @param string $file
  * @return void
  */
 public function loadStyles($file)
 {
     $parser = new ezcDocumentPcssParser();
     $this->styles->appendStyleDirectives($parser->parseFile($file));
 }
Example #6
0
 /**
  * Create and append a new page.
  *
  * @param ezcDocumentPcssStyleInferencer $inferencer
  */
 public function appendPage(ezcDocumentPcssStyleInferencer $inferencer)
 {
     $current = $this->transactions[$this->transaction]->currentPage;
     // Check if the next page already exists
     if (isset($this->pages[$current + 1])) {
         $current = ++$this->transactions[$this->transaction]->currentPage;
         return $this->pages[$current];
     }
     $current = ++$this->transactions[$this->transaction]->currentPage;
     $styles = $inferencer->inferenceFormattingRules(new ezcDocumentPdfPage(0, 0, 0, 0, 0));
     $page = ezcDocumentPdfPage::createFromSpecification($current, $styles['page-size']->value, $styles['page-orientation']->value, $styles['margin']->value, $styles['padding']->value);
     // Store in which transaction the page has been created
     $this->pages[$current] = $page;
     $this->transactions[$this->transaction]->pageCreations[] = $current;
     // Tell driver about new page
     $this->createPage($page->width, $page->height);
     return $page;
 }
Example #7
0
 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__);
 }