Skip to content

Commit

Permalink
resolves #2512 support base64-encoded SVG image reference in SVG (PR #…
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed May 31, 2024
1 parent 3d0971c commit f1d3561
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co
Improvements::

* don't hyphenate autolink when hyphenation is enabled (#2521) (*@meonkeys*)
* add support for base64-encoded SVG image reference in SVG (#2512)

Bug Fixes::

Expand Down
2 changes: 1 addition & 1 deletion lib/asciidoctor/pdf/ext/prawn-svg/loaders/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

class Prawn::SVG::Loaders::Data
remove_const :REGEXP
REGEXP = %r(\Adata:image/(?:png|jpe?g);base64(?:;[a-z0-9]+)*,)i
REGEXP = %r(\Adata:image/(?:png|jpe?g|svg\+xml);base64(?:;[a-z0-9]+)*,)i
end
7 changes: 7 additions & 0 deletions spec/fixtures/svg-with-data-uri-svg-image.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions spec/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,12 @@ def traverse node
(expect to_file).to visually_match 'image-block-svg-with-image.pdf'
end

it 'should embed SVG image from data-uri in SVG', visual: true do
pdf = to_pdf 'image::svg-with-data-uri-svg-image.svg[]', analyze: :rect
(expect pdf.rectangles).to have_size 1
(expect pdf.rectangles[0][:fill_color]).to eql 'FF0000'
end

it 'should support non-standard image/jpg MIME type', visual: true do
image_data = File.binread fixture_file 'square.jpg'
pdf = to_pdf 'image::svg-with-data-uri-jpg-image.svg[pdfwidth=1.27cm]', analyze: :image
Expand Down

0 comments on commit f1d3561

Please sign in to comment.