Overview

Namespaces

  • Mapbender
    • Component
      • HTTP
    • CoreBundle
      • Command
      • Component
        • Exception
      • Controller
      • DataFixtures
        • ORM
      • DependencyInjection
      • Element
        • Type
      • Entity
      • EventListener
      • Extension
      • Form
        • DataTransformer
        • EventListener
        • Type
      • Security
      • Template
    • KmlBundle
      • Element
    • ManagerBundle
      • Controller
      • Form
        • DataTransformer
        • Type
    • MonitoringBundle
      • Command
      • Component
      • Controller
      • DependencyInjection
      • Entity
      • EventListener
      • Form
    • PrintBundle
      • Component
      • Controller
    • WmcBundle
      • Component
        • Exception
      • Element
        • Type
      • Entity
      • Form
        • Type
    • WmsBundle
      • Component
        • Exception
      • Controller
      • DependencyInjection
      • Element
        • Type
      • Entity
      • Event
      • Form
        • EventListener
        • Type
    • WmtsBundle
      • Component
        • Exception
      • Controller
      • Entity
      • Form
        • Type
  • None
  • PHP

Classes

  • OdgParser
  • PDF_ImageAlpha
  • PrintService
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
  1: <?php
  2: 
  3: namespace Mapbender\PrintBundle\Component;
  4: 
  5: use Symfony\Component\HttpFoundation\Response;
  6: 
  7: class OdgParser
  8: {
  9:     public function __construct($container)
 10:     {
 11:         $this->container = $container;
 12:     }
 13:     
 14:     private function readOdgFile($template, $file)
 15:     {
 16:         $resource_dir = $this->container->getParameter('kernel.root_dir') . '/Resources/MapbenderPrintBundle';
 17:         $odgfile = $resource_dir.'/templates/'.$template.'.odg';
 18:         $open = zip_open($odgfile);
 19:         while($zip_entry = zip_read($open)) {
 20:             if (zip_entry_name($zip_entry) == $file){
 21:                 zip_entry_open($open, $zip_entry);
 22:                 $xml = zip_entry_read($zip_entry, 51200);
 23:                 break;
 24:             }
 25:         }
 26:         zip_close($open);
 27:         return $xml;
 28:     }
 29:     
 30:     public function getMapSize($template) 
 31:     {       
 32:         $xml = $this->readOdgFile($template, 'content.xml');     
 33:         $doc = new \DOMDocument();
 34:         $doc->loadXML($xml);
 35:         $xpath = new \DOMXPath($doc);
 36: 
 37:         $node = $xpath->query("//draw:custom-shape[@draw:name='map']");
 38:         $width = $node->item(0)->getAttribute('svg:width');
 39:         $height = $node->item(0)->getAttribute('svg:height');
 40:         
 41:         $data = array();  
 42:         $data['width'] = substr($width, 0, -2);
 43:         $data['height'] = substr($height, 0, -2);
 44:     
 45:         $response = new Response();
 46:         $response->headers->set('Content-Type', 'application/json');    
 47:         $response->setContent(json_encode($data));
 48:         return $response;
 49:     }
 50:     
 51:     public function getConf($template)
 52:     {
 53:         $data = array();
 54: 
 55:         //orientation
 56:         $stylexml = $this->readOdgFile($template, 'styles.xml');   
 57:         $doc = new \DOMDocument();
 58:         $doc->loadXML($stylexml);
 59:         $xpath = new \DOMXPath($doc);
 60:         $node = $xpath->query("//style:page-layout-properties"); 
 61:         $orientation = $node->item(0)->getAttribute('style:print-orientation');
 62:         $data['orientation'] = $orientation;
 63:         
 64:         
 65:         $contentxml = $this->readOdgFile($template, 'content.xml');               
 66:         $doc = new \DOMDocument();
 67:         $doc->loadXML($contentxml);
 68:         $xpath = new \DOMXPath($doc);
 69: 
 70:         
 71:         //$node = $xpath->query("//draw:custom-shape[@draw:name='map']");
 72:         $imagenodes = $xpath->query("//draw:custom-shape");
 73:         
 74:         foreach ($imagenodes as $node){
 75:             $name = $node->getAttribute('draw:name');
 76:             $width = $node->getAttribute('svg:width');
 77:             $height = $node->getAttribute('svg:height');
 78:             $x= $node->getAttribute('svg:x');
 79:             $y = $node->getAttribute('svg:y');
 80: 
 81:             $data[$name]['width'] = substr($width, 0, -2);
 82:             $data[$name]['height'] = substr($height, 0, -2);
 83:             $data[$name]['x'] = substr($x, 0, -2);
 84:             $data[$name]['y'] = substr($y, 0, -2);
 85:         }
 86:             
 87:         $contextnode = $doc->getElementsByTagName('drawing')->item(0);
 88:         $textnodes = $xpath->query("draw:page/draw:frame",$contextnode);
 89:         foreach ($textnodes as $node)
 90:         {
 91:             $name = $node->getAttribute('draw:name');    
 92:             if ($name == '')
 93:             {
 94:                 continue;
 95:             }       
 96:             $width = $node->getAttribute('svg:width');
 97:             $height = $node->getAttribute('svg:height');
 98:             $x= $node->getAttribute('svg:x');
 99:             $y = $node->getAttribute('svg:y');
100:             
101:             $data['fields'][$name]['width'] = substr($width, 0, -2);
102:             $data['fields'][$name]['height'] = substr($height, 0, -2);
103:             $data['fields'][$name]['x'] = substr($x, 0, -2);
104:             $data['fields'][$name]['y'] = substr($y, 0, -2);
105:             
106:             
107:             $textnode = $xpath->query("draw:text-box/text:p/text:span",$node)->item(0);
108:             if ($textnode)
109:             {
110:                 $style = $textnode->getAttribute('text:style-name');
111:                 $stylenode = $xpath->query('//style:style[@style:name="'.$style.'"]/style:text-properties');
112:                 $fontsize = $stylenode->item(0)->getAttribute('fo:font-size');
113:                 $font = $stylenode->item(0)->getAttribute('fo:font-family');
114:                 $data['fields'][$name]['fontsize'] = $fontsize;
115:                 $data['fields'][$name]['font'] = $font;
116:             }
117:         }
118:         return $data;
119:     }
120:    
121: }
Mapbender3 API documenation API documentation generated by ApiGen 2.8.0