diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2024-05-31 05:13:13 -0400 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2024-05-31 03:13:41 -0600 |
| commit | f1d3561c2878b63bed8c8c7503f34f1429e0433c (patch) | |
| tree | 5acfc54fc7a4a439fa91357b86aa28ddf4603a2c | |
| parent | 3d0971c30aa067c0403802ff1aea9ac3f212f12c (diff) | |
resolves #2512 support base64-encoded SVG image reference in SVG (PR #2524)
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor/pdf/ext/prawn-svg/loaders/data.rb | 2 | ||||
| -rw-r--r-- | spec/fixtures/svg-with-data-uri-svg-image.svg | 7 | ||||
| -rw-r--r-- | spec/image_spec.rb | 6 |
4 files changed, 15 insertions, 1 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 527ee7c6..d7267267 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -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:: diff --git a/lib/asciidoctor/pdf/ext/prawn-svg/loaders/data.rb b/lib/asciidoctor/pdf/ext/prawn-svg/loaders/data.rb index 3f4882a4..34f4a3dd 100644 --- a/lib/asciidoctor/pdf/ext/prawn-svg/loaders/data.rb +++ b/lib/asciidoctor/pdf/ext/prawn-svg/loaders/data.rb @@ -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 diff --git a/spec/fixtures/svg-with-data-uri-svg-image.svg b/spec/fixtures/svg-with-data-uri-svg-image.svg new file mode 100644 index 00000000..612de276 --- /dev/null +++ b/spec/fixtures/svg-with-data-uri-svg-image.svg @@ -0,0 +1,7 @@ +<svg width="1.27cm" height="1.27cm" version="1.1" viewBox="0 0 5 5" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> +<defs> +<image id="img" width="5" height="5" xlink:href="data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDIwMCAyMDAiIHdpZHRoPSIyMDAiIGhlaWdodD0iMjAwIj48cmVjdCB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCIgZmlsbD0icmVkIj48L3JlY3Q+PC9zdmc+Cg=="/> +</defs> +<use xlink:href="#img" x="0" y="0" width="5" height="5"/> +<rect x="0.25" y="0.25" width="4.5" height="4.5" fill-opacity="0" stroke="#000" stroke-width="0.5"/> +</svg> diff --git a/spec/image_spec.rb b/spec/image_spec.rb index f6298827..c6c83e96 100644 --- a/spec/image_spec.rb +++ b/spec/image_spec.rb @@ -993,6 +993,12 @@ describe 'Asciidoctor::PDF::Converter - Image' do (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 |
