prawn-svg 0.23.1 → 0.24.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -3
  3. data/README.md +15 -9
  4. data/lib/prawn-svg.rb +3 -0
  5. data/lib/prawn/svg/attributes.rb +1 -1
  6. data/lib/prawn/svg/attributes/clip_path.rb +6 -7
  7. data/lib/prawn/svg/attributes/opacity.rb +3 -3
  8. data/lib/prawn/svg/attributes/stroke.rb +6 -4
  9. data/lib/prawn/svg/calculators/arc_to_bezier_curve.rb +114 -0
  10. data/lib/prawn/svg/elements.rb +4 -1
  11. data/lib/prawn/svg/elements/base.rb +76 -69
  12. data/lib/prawn/svg/elements/container.rb +5 -6
  13. data/lib/prawn/svg/elements/gradient.rb +4 -4
  14. data/lib/prawn/svg/elements/image.rb +1 -1
  15. data/lib/prawn/svg/elements/line.rb +15 -7
  16. data/lib/prawn/svg/elements/marker.rb +72 -0
  17. data/lib/prawn/svg/elements/path.rb +23 -147
  18. data/lib/prawn/svg/elements/polygon.rb +14 -6
  19. data/lib/prawn/svg/elements/polyline.rb +12 -11
  20. data/lib/prawn/svg/elements/root.rb +3 -1
  21. data/lib/prawn/svg/elements/text.rb +38 -17
  22. data/lib/prawn/svg/font.rb +6 -6
  23. data/lib/prawn/svg/interface.rb +3 -0
  24. data/lib/prawn/svg/pathable.rb +130 -0
  25. data/lib/prawn/svg/properties.rb +122 -0
  26. data/lib/prawn/svg/state.rb +7 -29
  27. data/lib/prawn/svg/version.rb +1 -1
  28. data/spec/prawn/svg/elements/base_spec.rb +19 -32
  29. data/spec/prawn/svg/elements/line_spec.rb +37 -0
  30. data/spec/prawn/svg/elements/marker_spec.rb +90 -0
  31. data/spec/prawn/svg/elements/path_spec.rb +10 -10
  32. data/spec/prawn/svg/elements/polygon_spec.rb +49 -0
  33. data/spec/prawn/svg/elements/polyline_spec.rb +47 -0
  34. data/spec/prawn/svg/elements/style_spec.rb +1 -1
  35. data/spec/prawn/svg/elements/text_spec.rb +37 -5
  36. data/spec/prawn/svg/pathable_spec.rb +92 -0
  37. data/spec/prawn/svg/properties_spec.rb +186 -0
  38. data/spec/sample_svg/arrows.svg +73 -0
  39. data/spec/sample_svg/marker.svg +32 -0
  40. data/spec/sample_svg/polygon01.svg +25 -5
  41. metadata +23 -8
  42. data/lib/prawn/svg/attributes/color.rb +0 -5
  43. data/lib/prawn/svg/attributes/display.rb +0 -5
  44. data/lib/prawn/svg/attributes/font.rb +0 -38
  45. data/spec/prawn/svg/attributes/font_spec.rb +0 -52
@@ -1,5 +0,0 @@
1
- module Prawn::SVG::Attributes::Color
2
- def parse_color_attribute
3
- state.color = attributes['color'] if attributes['color']
4
- end
5
- end
@@ -1,5 +0,0 @@
1
- module Prawn::SVG::Attributes::Display
2
- def parse_display_attribute
3
- state.display = attributes['display'].strip if attributes['display']
4
- end
5
- end
@@ -1,38 +0,0 @@
1
- module Prawn::SVG::Attributes::Font
2
- def parse_font_attributes_and_call
3
- if size = attributes['font-size']
4
- state.font_size = size.to_f
5
- end
6
- if weight = attributes['font-weight']
7
- font_updated = true
8
- state.font_weight = Prawn::SVG::Font.weight_for_css_font_weight(weight)
9
- end
10
- if style = attributes['font-style']
11
- font_updated = true
12
- state.font_style = style == 'italic' ? :italic : nil
13
- end
14
- if (family = attributes['font-family']) && family.strip != ""
15
- font_updated = true
16
- state.font_family = family
17
- end
18
- if (anchor = attributes['text-anchor'])
19
- state.text_anchor = anchor
20
- end
21
-
22
- if state.font_family && font_updated
23
- usable_font_families = [state.font_family, document.fallback_font_name]
24
-
25
- font_used = usable_font_families.compact.detect do |name|
26
- if font = document.font_registry.load(name, state.font_weight, state.font_style)
27
- state.font_subfamily = font.subfamily
28
- add_call_and_enter 'font', font.name, :style => state.font_subfamily
29
- true
30
- end
31
- end
32
-
33
- if font_used.nil?
34
- warnings << "Font family '#{state.font_family}' style '#{state.font_style || 'normal'}' is not a known font, and the fallback font could not be found."
35
- end
36
- end
37
- end
38
- end
@@ -1,52 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Prawn::SVG::Attributes::Font do
4
- class FontTestElement
5
- include Prawn::SVG::Attributes::Font
6
-
7
- attr_accessor :attributes, :warnings, :state, :document
8
-
9
- def initialize(document)
10
- @state = Prawn::SVG::State.new
11
- @document = document
12
- @warnings = []
13
- end
14
- end
15
-
16
- let(:pdf) { Prawn::Document.new }
17
- let(:font_registry) { Prawn::SVG::FontRegistry.new(pdf.font_families) }
18
- let(:document) { double(fallback_font_name: "Times-Roman", font_registry: font_registry) }
19
- let(:element) { FontTestElement.new(document) }
20
-
21
- before do
22
- allow(element).to receive(:document).and_return(document)
23
- element.attributes = {"font-family" => family}
24
- end
25
-
26
- describe "#parse_font_attributes_and_call" do
27
- context "with a specified existing font" do
28
- let(:family) { "Helvetica" }
29
-
30
- it "uses a font if it can find it" do
31
- expect(element).to receive(:add_call_and_enter).with("font", "Helvetica", style: :normal)
32
- element.parse_font_attributes_and_call
33
- end
34
- end
35
-
36
- context "with a specified non-existing font" do
37
- let(:family) { "Font That Doesn't Exist" }
38
-
39
- it "uses the fallback font if specified" do
40
- expect(element).to receive(:add_call_and_enter).with("font", "Times-Roman", style: :normal)
41
- element.parse_font_attributes_and_call
42
- end
43
-
44
- it "doesn't call the font method if there's no fallback font" do
45
- allow(document).to receive(:fallback_font_name).and_return(nil)
46
- expect(element).to_not receive(:add_call_and_enter)
47
- element.parse_font_attributes_and_call
48
- expect(element.warnings.length).to eq 1
49
- end
50
- end
51
- end
52
- end