Skip to content

Commit f9dab11

Browse files
committed
Improved handling of use tags for herf attribute.
See: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/use
1 parent 28ea478 commit f9dab11

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

lib/rbpdf.rb

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18122,9 +18122,10 @@ def startSVGElementHandler(name, attribs, clipping = false)
1812218122
@svggradients[@svggradientid]['gradientTransform'] = getSVGTransformMatrix(attribs['gradientTransform'])
1812318123
end
1812418124
@svggradients[@svggradientid]['coords'] = [x1, y1, x2, y2]
18125-
if attribs['xlink:href'] && !attribs['xlink:href'].empty?
18125+
if (attribs['href'] && !attribs['href'].empty?) || (attribs['xlink:href'] && !attribs['xlink:href'].empty?)
18126+
href = attribs['href'] ? 'href' : 'xlink:href'
1812618127
# gradient is defined on another place
18127-
@svggradients[@svggradientid]['xref'] = attribs['xlink:href'][1..-1]
18128+
@svggradients[@svggradientid]['xref'] = attribs[href][1..-1]
1812818129
end
1812918130
when 'radialGradient'
1813018131
@svggradientid = attribs['id']
@@ -18151,9 +18152,10 @@ def startSVGElementHandler(name, attribs, clipping = false)
1815118152
@svggradients[@svggradientid]['gradientTransform'] = getSVGTransformMatrix(attribs['gradientTransform'])
1815218153
end
1815318154
@svggradients[@svggradientid]['coords'] = [cx, cy, fx, fy, r]
18154-
if attribs['xlink:href'] && !attribs['xlink:href'].empty?
18155+
if (attribs['href'] && !attribs['href'].empty?) || (attribs['xlink:href'] && !attribs['xlink:href'].empty?)
18156+
href = attribs['href'] ? 'href' : 'xlink:href'
1815518157
# gradient is defined on another place
18156-
@svggradients[@svggradientid]['xref'] = attribs['xlink:href'][1..-1]
18158+
@svggradients[@svggradientid]['xref'] = attribs[href][1..-1]
1815718159
end
1815818160
when 'stop'
1815918161
# gradient stops
@@ -18311,12 +18313,13 @@ def startSVGElementHandler(name, attribs, clipping = false)
1831118313
end
1831218314
end
1831318315
when 'image' # image
18314-
if attribs['xlink:href'] && !attribs['xlink:href'].empty?
18316+
if (attribs['href'] && !attribs['href'].empty?) || (attribs['xlink:href'] && !attribs['xlink:href'].empty?)
18317+
href = attribs['href'] ? 'href' : 'xlink:href'
1831518318
x = attribs['x'] ? getHTMLUnitToUnits(attribs['x'], 0, @svgunit, false) : 0
1831618319
y = attribs['y'] ? getHTMLUnitToUnits(attribs['y'], 0, @svgunit, false) : 0
1831718320
w = attribs['width'] ? getHTMLUnitToUnits(attribs['width'], 0, @svgunit, false) : 0
1831818321
h = attribs['height'] ? getHTMLUnitToUnits(attribs['height'], 0, @svgunit, false) : 0
18319-
img = attribs['xlink:href']
18322+
img = attribs[href]
1832018323
unless clipping
1832118324
start_transform()
1832218325
svg_transform(tm)
@@ -18357,15 +18360,14 @@ def startSVGElementHandler(name, attribs, clipping = false)
1835718360
set_xy(x, y, true)
1835818361
@svgstyles.push(svgstyle)
1835918362
when 'use' # use
18360-
if attribs['xlink:href']
18361-
use = @svgdefs[attribs['xlink:href'][1..-1]]
18362-
if attribs['xlink:href']
18363-
attribs.delete('xlink:href')
18364-
end
18365-
if use['id']
18366-
use.delete('id')
18367-
end
18368-
attribs = use['attribs'].merge(attribs)
18363+
if attribs['href'] || attribs['xlink:href']
18364+
href = attribs['href'] ? 'href' : 'xlink:href'
18365+
use = @svgdefs[attribs[href][1..-1]]
18366+
# Most attributes (except for x, y, width, height and (xlink:)href) do not override those set in the ancestor.
18367+
['x', 'y', 'width', 'height', 'hred', 'xlink:href'].each do |attr|
18368+
use['attribs'].delete(attr) if attribs[attr]
18369+
end
18370+
attribs = attribs.merge(use['attribs'])
1836918371
startSVGElementHandler(use['name'], use['attribs'])
1837018372
end
1837118373
end

0 commit comments

Comments
 (0)