/**
  * @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);
 }
Example #2
0
 /**
  * Tests for:
  *      Layout::getLastVersion
  *      Layout::getReportTitle
  *      Layout::getPagePaperType
  *      Layout::isUserPaperType
  *      Layout::isPortraitPage
  *      Layout::getPageSize
  *      Layout::getSVG
  */
 function test_getters_for_Layout_configuration()
 {
     $regular_paper_type_format = array('version' => '0.8.2', 'config' => array('title' => 'Report Title', 'page' => array('paper-type' => 'A4', 'orientation' => 'landscape')), 'svg' => '<svg></svg>');
     $layout = new Layout($regular_paper_type_format, array());
     $this->assertEquals('0.8.2', $layout->getLastVersion());
     $this->assertEquals('Report Title', $layout->getReportTitle());
     $this->assertEquals('A4', $layout->getPagePaperType());
     $this->assertFalse($layout->isUserPaperType());
     $this->assertFalse($layout->isPortraitPage());
     $this->assertNull($layout->getPageSize());
     $this->assertEquals('<svg></svg>', $layout->getSVG());
     $user_paper_type_format = array('version' => '0.8.2', 'config' => array('title' => 'Report Title', 'page' => array('paper-type' => 'user', 'orientation' => 'landscape', 'width' => 100.9, 'height' => 999.9)), 'svg' => '<svg></svg>');
     $layout = new Layout($user_paper_type_format, array());
     $this->assertEquals('user', $layout->getPagePaperType());
     $this->assertTrue($layout->isUserPaperType());
     $this->assertEquals(array(100.9, 999.9), $layout->getPageSize());
 }