class SVGMetadataExtractor {
static function getMetadata( $filename ) {
$svg = new SVGReader( $filename );
+
return $svg->getMetadata();
}
}
const NS_SVG = 'http://www.w3.org/2000/svg';
private $reader = null;
+
private $mDebug = false;
- private $metadata = Array();
+
+ private $metadata = array();
/**
* Constructor
wfSuppressWarnings();
try {
$this->read();
- } catch( Exception $e ) {
+ } catch ( Exception $e ) {
// Note, if this happens, the width/height will be taken to be 0x0.
// Should we consider it the default 512x512 instead?
wfRestoreWarnings();
while ( $keepReading ) {
$tag = $this->reader->localName;
$type = $this->reader->nodeType;
- $isSVG = ($this->reader->namespaceURI == self::NS_SVG);
+ $isSVG = ( $this->reader->namespaceURI == self::NS_SVG );
$this->debug( "$tag" );
- if ( $isSVG && $tag == 'svg' && $type == XmlReader::END_ELEMENT && $this->reader->depth <= $exitDepth ) {
+ if ( $isSVG && $tag == 'svg' && $type == XmlReader::END_ELEMENT
+ && $this->reader->depth <= $exitDepth
+ ) {
break;
} elseif ( $isSVG && $tag == 'title' ) {
$this->readField( $tag, 'title' );
}
$keepReading = $this->reader->read();
while ( $keepReading ) {
- if ( $this->reader->localName == $name && $this->reader->namespaceURI == self::NS_SVG && $this->reader->nodeType == XmlReader::END_ELEMENT ) {
+ if ( $this->reader->localName == $name
+ && $this->reader->namespaceURI == self::NS_SVG
+ && $this->reader->nodeType == XmlReader::END_ELEMENT
+ ) {
break;
} elseif ( $this->reader->nodeType == XmlReader::TEXT ) {
$this->metadata[$metafield] = trim( $this->reader->value );
if ( method_exists( $this->reader, 'readInnerXML' ) ) {
$this->metadata[$metafield] = trim( $this->reader->readInnerXML() );
} else {
- throw new MWException( "The PHP XMLReader extension does not come with readInnerXML() method. Your libxml is probably out of date (need 2.6.20 or later)." );
+ throw new MWException( "The PHP XMLReader extension does not come " .
+ "with readInnerXML() method. Your libxml is probably out of " .
+ "date (need 2.6.20 or later)." );
}
$this->reader->next();
}
$keepReading = $this->reader->read();
while ( $keepReading ) {
if ( $this->reader->localName == $name && $this->reader->depth <= $exitDepth
- && $this->reader->nodeType == XmlReader::END_ELEMENT ) {
+ && $this->reader->nodeType == XmlReader::END_ELEMENT
+ ) {
break;
- } elseif ( $this->reader->namespaceURI == self::NS_SVG && $this->reader->nodeType == XmlReader::ELEMENT ) {
- switch( $this->reader->localName ) {
+ } elseif ( $this->reader->namespaceURI ==
+ self::NS_SVG && $this->reader->nodeType == XmlReader::ELEMENT
+ ) {
+ switch ( $this->reader->localName ) {
case 'script':
// Normally we disallow files with
// <script>, but its possible
* http://www.w3.org/TR/SVG11/coords.html#UnitIdentifiers
*
* @param string $length CSS/SVG length.
- * @param $viewportSize: Float optional scale for percentage units...
+ * @param $viewportSize : Float optional scale for percentage units...
* @return float: length in pixels
*/
static function scaleSVGUnit( $length, $viewportSize = 512 ) {
'em' => 16.0, // fake it?
'ex' => 12.0, // fake it?
'' => 1.0, // "User units" pixels by default
- );
+ );
$matches = array();
if ( preg_match( '/^\s*(\d+(?:\.\d+)?)(em|ex|px|pt|pc|cm|mm|in|%|)\s*$/', $length, $matches ) ) {
$length = floatval( $matches[1] );