prawn-svg 0.34.1 → 0.34.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0676f2574c6a16d7d1ea8bec6c43f807f6520a40f99d64ae7731646915576dc8
4
- data.tar.gz: a294ac8f3c92bf4bc5030958f1a3f242e4fcc3099fcb3ae7893bc7cdc522decc
3
+ metadata.gz: 2f405c26de28dcc55e41e63ee5a6f8d433ab7dc4e9900bc3012e869689516698
4
+ data.tar.gz: f6cfebbb831bbfd6a66608202285acd66a295de102ebd94a2a6be8e73454bec4
5
5
  SHA512:
6
- metadata.gz: bdd3bac1ac0b2ec43140a84f248acfae5839f51bd7bd757acfc8713e391d136e5753db8110bed039463a7d378c855573230eccdda23a28e11cea2555aa2cdbb7
7
- data.tar.gz: a702f63f43e0db24aef08edc8b12033d7dde1c7032746bc3ec7dc0a1e06002587d03d2145ec8e994416e886663013fc6c36153096b5c647f6549f283789913fb
6
+ metadata.gz: e9092e304d63b84b8947e585448b627be95fcfbaad38b02e386bb9ed0b585871990a3ab1bc87a0480949141010aea67cb60c5c1ddc1be19b674056f8b7adceab
7
+ data.tar.gz: 4dd717b2d65681f792951ef98a93df4dd1dd7a8f2f4f9caaa13ef7fce9a3428e8f2041e71537244167be257351f1a5720069e5b88c173145fc8f51ae31d1453f
@@ -1,5 +1,7 @@
1
1
  module Prawn::SVG::CSS
2
2
  class Stylesheets
3
+ USER_AGENT_STYLESHEET = 'svg, symbol, image, marker, pattern, foreignObject { overflow: hidden }'.freeze
4
+
3
5
  attr_reader :css_parser, :root, :media
4
6
 
5
7
  def initialize(css_parser, root, media = :all)
@@ -9,6 +11,7 @@ module Prawn::SVG::CSS
9
11
  end
10
12
 
11
13
  def load
14
+ load_user_agent_stylesheet
12
15
  load_style_elements
13
16
  xpath_styles = gather_xpath_styles
14
17
  associate_xpath_styles_with_elements(xpath_styles)
@@ -16,6 +19,10 @@ module Prawn::SVG::CSS
16
19
 
17
20
  private
18
21
 
22
+ def load_user_agent_stylesheet
23
+ css_parser.add_block!(USER_AGENT_STYLESHEET)
24
+ end
25
+
19
26
  def load_style_elements
20
27
  REXML::XPath.match(root, '//style').each do |source|
21
28
  data = source.texts.map(&:value).join
@@ -270,4 +270,14 @@ class Prawn::SVG::Elements::Base
270
270
  def href_attribute
271
271
  attributes['xlink:href'] || attributes['href']
272
272
  end
273
+
274
+ def overflow_hidden?
275
+ ['hidden', 'scroll'].include?(computed_properties.overflow)
276
+ end
277
+
278
+ def clone_element_source(source)
279
+ new_source = source.dup
280
+ document.element_styles[new_source] = document.element_styles[source]
281
+ new_source
282
+ end
273
283
  end
@@ -46,8 +46,7 @@ class Prawn::SVG::Elements::Marker < Prawn::SVG::Elements::Base
46
46
 
47
47
  element.add_call 'transformation_matrix', 1, 0, 0, 1, -ref_x * sizing.x_scale, ref_y * sizing.y_scale
48
48
 
49
- # `overflow: visible` must be on the <marker> element
50
- if properties.overflow != 'visible'
49
+ if overflow_hidden?
51
50
  point = [sizing.x_offset * sizing.x_scale, y(sizing.y_offset * sizing.y_scale)]
52
51
  element.add_call "rectangle", point, sizing.output_width, sizing.output_height
53
52
  element.add_call "clip"
@@ -53,7 +53,7 @@ class Prawn::SVG::Elements::Use < Prawn::SVG::Elements::Base
53
53
  def process_child_elements
54
54
  add_call 'save'
55
55
 
56
- source = referenced_element_source.dup
56
+ source = clone_element_source(referenced_element_source)
57
57
 
58
58
  if referenced_element_class == Prawn::SVG::Elements::Viewport
59
59
  source.attributes['width'] = @width || '100%'
@@ -16,8 +16,11 @@ class Prawn::SVG::Elements::Viewport < Prawn::SVG::Elements::Base
16
16
  add_call 'transformation_matrix', 1, 0, 0, 1, @x, -@y
17
17
  end
18
18
 
19
- add_call 'rectangle', [0, y(0)], @sizing.output_width, @sizing.output_height
20
- add_call 'clip'
19
+ if overflow_hidden?
20
+ add_call 'rectangle', [0, y(0)], @sizing.output_width, @sizing.output_height
21
+ add_call 'clip'
22
+ end
23
+
21
24
  add_call 'transformation_matrix', @sizing.x_scale, 0, 0, @sizing.y_scale, 0, 0
22
25
  add_call 'transformation_matrix', 1, 0, 0, 1, -@sizing.x_offset, @sizing.y_offset
23
26
  end
@@ -1,5 +1,5 @@
1
1
  module Prawn
2
2
  module SVG
3
- VERSION = '0.34.1'
3
+ VERSION = '0.34.2'
4
4
  end
5
5
  end
@@ -62,6 +62,7 @@ RSpec.describe Prawn::SVG::CSS::Stylesheets do
62
62
  width_and_styles = result.map { |k, v| [k.attributes["width"].to_i, v] }.sort_by(&:first)
63
63
 
64
64
  expected = [
65
+ [0, [["overflow", "hidden", false]]],
65
66
  [1, [["fill", "#ff0000", false]]],
66
67
  [2, [["fill", "#ff0000", false], ["fill", "#330000", false], ["fill", "#440000", false], ["fill", "#220000", false]]],
67
68
  [3, [["fill", "#ff0000", false], ["fill", "#00ff00", false]]],
@@ -114,6 +115,7 @@ z</style>
114
115
  it "scans the document for style tags and adds the style information to the css parser" do
115
116
  css_parser = instance_double(CssParser::Parser)
116
117
 
118
+ expect(css_parser).to receive(:add_block!).with("svg, symbol, image, marker, pattern, foreignObject { overflow: hidden }")
117
119
  expect(css_parser).to receive(:add_block!).with("a\n before>\n x y\n inside <>&gt;\n k j\n after\nz")
118
120
  expect(css_parser).to receive(:add_block!).with("hello")
119
121
  allow(css_parser).to receive(:each_rule_set)
@@ -18,18 +18,19 @@ RSpec.describe Prawn::SVG::Elements::Marker do
18
18
  end
19
19
 
20
20
  let(:document) { Prawn::SVG::Document.new(svg, [800, 600], {width: 800, height: 600}) }
21
- let(:state) { Prawn::SVG::State.new }
22
21
 
23
- let(:line_element) do
24
- Prawn::SVG::Elements::Line.new(document, document.root.elements[2], [], state)
22
+ def new_state
23
+ state = Prawn::SVG::State.new
24
+ state.viewport_sizing = document.sizing
25
+ state
25
26
  end
26
27
 
27
- subject do
28
- Prawn::SVG::Elements::Marker.new(document, document.root.elements[1], [], state)
28
+ let(:line_element) do
29
+ Prawn::SVG::Elements::Line.new(document, document.root.elements[2], [], new_state)
29
30
  end
30
31
 
31
- before do
32
- state.viewport_sizing = document.sizing
32
+ subject do
33
+ Prawn::SVG::Elements::Marker.new(document, document.root.elements[1], [], new_state)
33
34
  end
34
35
 
35
36
  describe "#parse" do
@@ -70,8 +71,8 @@ RSpec.describe Prawn::SVG::Elements::Marker do
70
71
  ["clip", [], {}, []],
71
72
  ["transformation_matrix", [0.3, 0, 0, 0.3, 0, 0], {}, []],
72
73
  ["transparent", [1.0, 1.0], {}, [
73
- ["stroke_color", ["000000"], {}, []],
74
- ["line_width", [100.0], {}, []],
74
+ ["fill_color", ["000000"], {}, []],
75
+ ["line_width", [1.0], {}, []],
75
76
  ["cap_style", [:butt], {}, []],
76
77
  ["join_style", [:miter], {}, []],
77
78
  ["undash", [], {}, []],
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn-svg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.34.1
4
+ version: 0.34.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mog Nesbitt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-06 00:00:00.000000000 Z
11
+ date: 2024-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: css_parser