- var $first = true;
- var $width = self::DEFAULT_WIDTH;
- var $height = self::DEFAULT_HEIGHT;
- function filter( $name, $attribs ) {
- if( $this->first ) {
- $defaultWidth = self::DEFAULT_WIDTH;
- $defaultHeight = self::DEFAULT_HEIGHT;
- $aspect = 1.0;
- $width = null;
- $height = null;
-
- if( isset( $attribs['viewBox'] ) ) {
- // min-x min-y width height
- $viewBox = preg_split( '/\s+/', trim( $attribs['viewBox'] ) );
- if( count( $viewBox ) == 4 ) {
- $viewWidth = $this->scaleSVGUnit( $viewBox[2] );
- $viewHeight = $this->scaleSVGUnit( $viewBox[3] );
- if( $viewWidth > 0 && $viewHeight > 0 ) {
- $aspect = $viewWidth / $viewHeight;
- $defaultHeight = $defaultWidth / $aspect;
- }
- }
+
+ private $reader = null;
+ private $mDebug = false;
+ private $metadata = Array();
+
+ /**
+ * Constructor
+ *
+ * Creates an SVGReader drawing from the source provided
+ * @param $source String: URI from which to read
+ */
+ function __construct( $source ) {
+ $this->reader = new XMLReader();
+ $this->reader->open( $source );
+
+ $this->metadata['width'] = self::DEFAULT_WIDTH;
+ $this->metadata['height'] = self::DEFAULT_HEIGHT;
+
+ $this->read();
+ }
+
+ /*
+ * @return Array with the known metadata
+ */
+ public function getMetadata() {
+ return $this->metadata;
+ }
+
+ /*
+ * Read the SVG
+ */
+ public function read() {
+ $this->reader->read();
+
+ if ( $this->reader->name != 'svg' ) {
+ throw new MWException( "Expected <svg> tag, got ".
+ $this->reader->name );
+ }
+ $this->debug( "<svg> tag is correct." );
+
+ $this->debug( "Starting primary dump processing loop." );
+ $this->handleSVGAttribs();
+ $exitDepth = $this->reader->depth;
+
+ $keepReading = $this->reader->read();
+ $skip = false;
+ while ( $keepReading ) {
+ $tag = $this->reader->name;
+ $type = $this->reader->nodeType;
+
+ $this->debug( "$tag" );
+
+ if ( $tag == 'svg' && $type == XmlReader::END_ELEMENT && $this->reader->depth <= $exitDepth ) {
+ break;
+ } elseif ( $tag == 'title' ) {
+ $this->readField( $tag, 'title' );
+ } elseif ( $tag == 'desc' ) {
+ $this->readField( $tag, 'description' );
+ } elseif ( $tag == 'metadata' && $type == XmlReader::ELEMENT ) {
+ $this->readXml( $tag, 'metadata' );
+ } elseif ( $tag !== '#text' ) {
+ $this->debug( "Unhandled top-level XML tag $tag" );
+ $this->animateFilter( $tag );
+ //$skip = true;