Skip to content

Commit 8abac8c

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 a9ea06b commit 8abac8c

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
@@ -18139,9 +18139,10 @@ def startSVGElementHandler(name, attribs, clipping = false)
1813918139
@svggradients[@svggradientid]['gradientTransform'] = getSVGTransformMatrix(attribs['gradientTransform'])
1814018140
end
1814118141
@svggradients[@svggradientid]['coords'] = [x1, y1, x2, y2]
18142-
if attribs['xlink:href'] && !attribs['xlink:href'].empty?
18142+
if (attribs['href'] && !attribs['href'].empty?) || (attribs['xlink:href'] && !attribs['xlink:href'].empty?)
18143+
href = attribs['href'] ? 'href' : 'xlink:href'
1814318144
# gradient is defined on another place
18144-
@svggradients[@svggradientid]['xref'] = attribs['xlink:href'][1..-1]
18145+
@svggradients[@svggradientid]['xref'] = attribs[href][1..-1]
1814518146
end
1814618147
when 'radialGradient'
1814718148
@svggradientid = attribs['id']
@@ -18168,9 +18169,10 @@ def startSVGElementHandler(name, attribs, clipping = false)
1816818169
@svggradients[@svggradientid]['gradientTransform'] = getSVGTransformMatrix(attribs['gradientTransform'])
1816918170
end
1817018171
@svggradients[@svggradientid]['coords'] = [cx, cy, fx, fy, r]
18171-
if attribs['xlink:href'] && !attribs['xlink:href'].empty?
18172+
if (attribs['href'] && !attribs['href'].empty?) || (attribs['xlink:href'] && !attribs['xlink:href'].empty?)
18173+
href = attribs['href'] ? 'href' : 'xlink:href'
1817218174
# gradient is defined on another place
18173-
@svggradients[@svggradientid]['xref'] = attribs['xlink:href'][1..-1]
18175+
@svggradients[@svggradientid]['xref'] = attribs[href][1..-1]
1817418176
end
1817518177
when 'stop'
1817618178
# gradient stops
@@ -18328,12 +18330,13 @@ def startSVGElementHandler(name, attribs, clipping = false)
1832818330
end
1832918331
end
1833018332
when 'image' # image
18331-
if attribs['xlink:href'] && !attribs['xlink:href'].empty?
18333+
if (attribs['href'] && !attribs['href'].empty?) || (attribs['xlink:href'] && !attribs['xlink:href'].empty?)
18334+
href = attribs['href'] ? 'href' : 'xlink:href'
1833218335
x = attribs['x'] ? getHTMLUnitToUnits(attribs['x'], 0, @svgunit, false) : 0
1833318336
y = attribs['y'] ? getHTMLUnitToUnits(attribs['y'], 0, @svgunit, false) : 0
1833418337
w = attribs['width'] ? getHTMLUnitToUnits(attribs['width'], 0, @svgunit, false) : 0
1833518338
h = attribs['height'] ? getHTMLUnitToUnits(attribs['height'], 0, @svgunit, false) : 0
18336-
img = attribs['xlink:href']
18339+
img = attribs[href]
1833718340
unless clipping
1833818341
start_transform()
1833918342
svg_transform(tm)
@@ -18374,15 +18377,14 @@ def startSVGElementHandler(name, attribs, clipping = false)
1837418377
set_xy(x, y, true)
1837518378
@svgstyles.push(svgstyle)
1837618379
when 'use' # use
18377-
if attribs['xlink:href']
18378-
use = @svgdefs[attribs['xlink:href'][1..-1]]
18379-
if attribs['xlink:href']
18380-
attribs.delete('xlink:href')
18381-
end
18382-
if use['id']
18383-
use.delete('id')
18384-
end
18385-
attribs = use['attribs'].merge(attribs)
18380+
if attribs['href'] || attribs['xlink:href']
18381+
href = attribs['href'] ? 'href' : 'xlink:href'
18382+
use = @svgdefs[attribs[href][1..-1]]
18383+
# Most attributes (except for x, y, width, height and (xlink:)href) do not override those set in the ancestor.
18384+
['x', 'y', 'width', 'height', 'hred', 'xlink:href'].each do |attr|
18385+
use['attribs'].delete(attr) if attribs[attr]
18386+
end
18387+
attribs = attribs.merge(use['attribs'])
1838618388
startSVGElementHandler(use['name'], use['attribs'])
1838718389
end
1838818390
end

0 commit comments

Comments
 (0)