Beispiel #1
0
 /**
  * Imports an SVG file as a new <symbol>
  *
  * @param  string $file The name of the file to import from
  * @return void
  */
 private final function _createSymbol($file, $id)
 {
     if (!is_string($file)) {
         throw new \InvalidArgumentException(sprintf('%s expects a string but got a %s', __MEHTOD__, gettype($file)));
     } else {
         if (!file_exists($file)) {
             throw new \Exception(sprintf('%s not found', $file), 1);
         }
     }
     // Create a new SVG from the file
     $svg = parent::loadSVG($file);
     $symbol = $this->documentElement->appendChild($this->createElement('symbol'));
     $symbol->id = is_string($id) ? $id : basename($file, '.svg');
     // Attempt to set `viewBox` from either SVG's viewBox or dimensions
     if (isset($svg->documentElement->viewBox)) {
         $symbol->viewBox = $svg->documentElement->viewBox;
     } else {
         if (isset($svg->documentElement->width, $svg->documentElement->height)) {
             $symbol->viewBox = "0 0 {$svg->documentElement->width} {$svg->documentElement->height}";
         }
     }
     // Import and append SVG's childNodes
     foreach ($svg->documentElement->childNodes as $node) {
         $symbol->appendChild($this->importNode($node, true));
     }
 }