Exemplo n.º 1
0
 /**
  * @test
  */
 public function mergeColors()
 {
     $colors = array('blue' => '#0000ff', 'black' => '#000000');
     $palette = new ColorPalette($colors);
     $newColors = array('red' => '#ff0000', 'green' => '#00ff00');
     $palette->merge($newColors);
     $expectedColors = array_merge($colors, $newColors);
     $this->assertEquals($expectedColors, $palette->getAll());
 }
Exemplo n.º 2
0
 /**
  * Convert text document to pdf document
  * 
  * @param string|DataSource $documentContent Source document content
  * @param DataSource[]|string[]|DataSource|string $stylesheetContents Stylesheet source(s)
  * @param string|DataSource $colorPaletteContent Palette of colors source
  * 
  * @return string Content of pdf document
  * 
  * @throws PHPPdf\Exception\Exception
  */
 public function render($documentContent, $stylesheetContents = array(), $colorPaletteContent = null)
 {
     $colorPalette = new ColorPalette((array) $this->configurationLoader->createColorPalette());
     if ($colorPaletteContent) {
         $colorPalette->merge($this->parseColorPalette($colorPaletteContent));
     }
     $this->document->setColorPalette($colorPalette);
     $complexAttributeFactory = $this->configurationLoader->createComplexAttributeFactory();
     $this->getDocument()->setComplexAttributeFactory($complexAttributeFactory);
     $fontDefinitions = $this->configurationLoader->createFontRegistry($this->engineType);
     $this->getDocument()->addFontDefinitions($fontDefinitions);
     $this->getDocumentParser()->setComplexAttributeFactory($complexAttributeFactory);
     $this->getDocumentParser()->setNodeFactory($this->configurationLoader->createNodeFactory());
     $stylesheetConstraint = $this->retrieveStylesheetConstraint($stylesheetContents);
     foreach ($this->stringFilters as $filter) {
         $documentContent = $filter->filter($documentContent);
     }
     $pageCollection = $this->getDocumentParser()->parse($documentContent, $stylesheetConstraint);
     $this->updateStylesheetConstraintCacheIfNecessary($stylesheetConstraint);
     unset($stylesheetConstraint);
     return $this->doRender($pageCollection);
 }