           style += ';' if style
           node.setAttribute 'style', style + 'image-rendering:pixelated'
         ## Read file for width/height detection and/or inlining
-        for key in ['xlink:href', 'href']
-          if filename = node.getAttribute key
-            break
+        {href, key} = getHref node
+        filename = href
         filename = path.join @dirname, filename if @dirname? and filename
         if filename? and not /^data:|file:|[a-z]+:\/\//.test filename # skip URLs
           filedata = null

          catch e
            console.warn "Failed to read image '#{filename}': #{e}"
          ## Fill in width and height
          unless window? or (node.hasAttribute('width') and node.hasAttribute('height'))
            try
              size = require('image-size') filedata ? filename
            catch e
              console.warn "Failed to detect size of image '#{filename}': #{e}"
              size = null
            if size?
              ## If one of width and height is set, scale to match.
              if not isNaN width = parseFloat node.getAttribute 'width'
                node.setAttribute 'height', size.height * (width / size.width)
              else if not isNaN height = parseFloat node.getAttribute 'height'
                node.setAttribute 'width', size.width * (height / size.height)
              else
                ## If neither width nor height are set, set both.
                node.setAttribute 'width', size.width
                node.setAttribute 'height', size.height
          ## Inline
          if filedata? and Drawing.inlineImages
            type = contentType[extensionOf filename]
            if type?
              node.setAttribute key,
                "data:#{type};base64,#{filedata.toString 'base64'}"
        false
      else
        true

    @viewBox = svgBBox @xml
    # Overflow behavior
    overflow = attributeOrStyle @xml.documentElement, 'overflow'
    if @constructor.overflowDefault? and not overflow?

      version = @nversions++
      @versions[string] =
        Symbol.parse "#{@key}$v#{version}", result, @dirname
      @versions[string].setId "#{escapeId @key}$v#{version}"
    @versions[string]
  usesContext: true

