/**
  * @param Layout $layout
  * @return self
  */
 public static function parse(Layout $layout)
 {
     $svg = preg_replace('<%.+?%>', '', $layout->getSVG());
     $xml = new \SimpleXMLElement($svg);
     $xml->registerXPathNamespace('svg', 'http://www.w3.org/2000/svg');
     $xml->registerXPathNamespace('xlink', 'http://www.w3.org/1999/xlink');
     $items = [];
     foreach ($xml->g->children() as $element) {
         $attributes = (array) $element->attributes();
         $attributes = $attributes['@attributes'];
         switch ($attributes['class']) {
             case 's-text':
                 $text_lines = [];
                 foreach ($element->text as $text_line) {
                     $text_lines[] = $text_line;
                 }
                 $attributes['content'] = implode("\n", $text_lines);
                 break;
             case 's-image':
                 $attributes['xlink:href'] = (string) $element->attributes('xlink', true)['href'];
                 break;
         }
         $items[] = $attributes;
     }
     return new self($items);
 }
Esempio n. 2
0
 /**
  * @param Layout $layout
  * @return array
  */
 public function buildPageFormat(Layout $layout)
 {
     $orientation = $layout->isPortraitPage() ? 'P' : 'L';
     if ($layout->isUserPaperType()) {
         $size = $layout->getPageSize();
     } else {
         switch ($layout->getPagePaperType()) {
             case 'B4_ISO':
                 $size = 'B4';
                 break;
             case 'B5_ISO':
                 $size = 'B5';
                 break;
             case 'B4':
                 $size = 'B4_JIS';
                 break;
             case 'B5':
                 $size = 'B5_JIS';
                 break;
             default:
                 $size = $layout->getPagePaperType();
                 break;
         }
     }
     return array('orientation' => $orientation, 'size' => $size);
 }
 /**
  * @param Layout $layout
  */
 public function renderLayout(Layout $layout)
 {
     $layout_identifier = $layout->getIdentifier();
     if (array_key_exists($layout_identifier, $this->layout_renderers)) {
         $renderer = $this->layout_renderers[$layout_identifier];
     } else {
         $renderer = LayoutRenderer::parse($layout);
         $this->layout_renderers[$layout_identifier] = $renderer;
     }
     $renderer->renderTo($this->pdf);
 }
Esempio n. 4
0
 /**
  * @param Layout $layout
  */
 public function renderLayout(Layout $layout)
 {
     $layout_identifier = $layout->getIdentifier();
     if (array_key_exists($layout_identifier, $this->layout_renderers)) {
         $renderer = $this->layout_renderers[$layout_identifier];
     } else {
         $renderer = new Renderer\LayoutRenderer($this->doc, $layout);
         $this->layout_renderers[$layout_identifier] = $renderer;
     }
     $renderer->render();
 }
Esempio n. 5
0
 /**
  * @param array $options {
  *      @option boolean "count" optional
  * }
  * @return Page\Page
  *
  * Usage example:
  *
  *  $page->addPage();
  *  $page->addPage(array('count' => false));
  */
 public function addPage()
 {
     $args = func_get_args();
     $layout = $this->layout;
     $options = null;
     if (isset($args) && array_key_exists('0', $args)) {
         if (is_string($args[0])) {
             $layout = Layout::loadFile($args[0]);
         } else {
             if (is_array($args[0])) {
                 $options = $args[0];
             }
         }
     } else {
         if (isset($args) && array_key_exists('1', $args)) {
             $options = $args[1];
         }
     }
     $options = $this->pageOptionValues($options);
     $page_number = $this->getNextPageNumber($options['count']);
     $new_page = new Page\Page($this, $layout, $page_number, $options['count']);
     $this->pages[] = $new_page;
     return $new_page;
 }
Esempio n. 6
0
 function test_getItemFormats()
 {
     $item_formats = array('rect_id' => array('type' => 's-rect'));
     $layout = new Layout(array('svg' => '<svg></svg>'), $item_formats);
     $this->assertSame($item_formats, $layout->getItemFormats());
 }
Esempio n. 7
0
 /**
  * @param string $layout_filename
  */
 public function __construct($layout_filename)
 {
     $this->layout = Layout::loadFile($layout_filename);
 }
Esempio n. 8
0
 /**
  * @param Layout $layout
  * @return array
  */
 public function registerPageFormat(Layout $layout)
 {
     $layout_identifier = $layout->getIdentifier();
     if (!array_key_exists($layout_identifier, $this->page_formats)) {
         $this->page_formats[$layout_identifier] = $this->buildPageFormat($layout);
     }
     return $this->getRegisteredPageFormat($layout_identifier);
 }
Esempio n. 9
0
 function test_getItemFormats()
 {
     $item_formats = ['rect_id' => ['type' => 's-rect']];
     $layout = new Layout(['svg' => '<svg></svg>'], $item_formats);
     $this->assertSame($item_formats, $layout->getItemFormats());
 }
Esempio n. 10
0
 /**
  * @access private
  *
  * @param string $layout_filename
  * @return Layout
  */
 public function buildLayout($layout_filename)
 {
     if (!array_key_exists($layout_filename, $this->layouts)) {
         $this->layouts[$layout_filename] = Layout::loadFile($layout_filename);
     }
     return $this->layouts[$layout_filename];
 }