prawn-git 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +10 -0
- data/COPYING +2 -0
- data/GPLv2 +340 -0
- data/GPLv3 +674 -0
- data/Gemfile +11 -0
- data/LICENSE +56 -0
- data/Rakefile +55 -0
- data/data/fonts/Courier-Bold.afm +342 -0
- data/data/fonts/Courier-BoldOblique.afm +342 -0
- data/data/fonts/Courier-Oblique.afm +342 -0
- data/data/fonts/Courier.afm +342 -0
- data/data/fonts/Helvetica-Bold.afm +2827 -0
- data/data/fonts/Helvetica-BoldOblique.afm +2827 -0
- data/data/fonts/Helvetica-Oblique.afm +3051 -0
- data/data/fonts/Helvetica.afm +3051 -0
- data/data/fonts/MustRead.html +19 -0
- data/data/fonts/Symbol.afm +213 -0
- data/data/fonts/Times-Bold.afm +2588 -0
- data/data/fonts/Times-BoldItalic.afm +2384 -0
- data/data/fonts/Times-Italic.afm +2667 -0
- data/data/fonts/Times-Roman.afm +2419 -0
- data/data/fonts/ZapfDingbats.afm +225 -0
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.color +0 -0
- data/data/images/16bit.png +0 -0
- data/data/images/arrow.png +0 -0
- data/data/images/arrow2.png +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.color +0 -0
- data/data/images/dice.png +0 -0
- data/data/images/dice_interlaced.png +0 -0
- data/data/images/fractal.jpg +0 -0
- data/data/images/indexed_color.dat +0 -0
- data/data/images/indexed_color.png +0 -0
- data/data/images/letterhead.jpg +0 -0
- data/data/images/license.md +8 -0
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.color +0 -0
- data/data/images/page_white_text.png +0 -0
- data/data/images/pal_bk.png +0 -0
- data/data/images/pigs.jpg +0 -0
- data/data/images/prawn.png +0 -0
- data/data/images/ruport.png +0 -0
- data/data/images/ruport_data.dat +0 -0
- data/data/images/ruport_transparent.png +0 -0
- data/data/images/ruport_type0.png +0 -0
- data/data/images/stef.jpg +0 -0
- data/data/images/tru256.bmp +0 -0
- data/data/images/web-links.dat +1 -0
- data/data/images/web-links.png +0 -0
- data/data/pdfs/complex_template.pdf +0 -0
- data/data/pdfs/contains_ttf_font.pdf +0 -0
- data/data/pdfs/encrypted.pdf +0 -0
- data/data/pdfs/form.pdf +820 -0
- data/data/pdfs/hexagon.pdf +61 -0
- data/data/pdfs/indirect_reference.pdf +86 -0
- data/data/pdfs/multipage_template.pdf +127 -0
- data/data/pdfs/nested_pages.pdf +118 -0
- data/data/pdfs/page_without_mediabox.pdf +193 -0
- data/data/pdfs/resources_as_indirect_object.pdf +83 -0
- data/data/pdfs/two_hexagons.pdf +90 -0
- data/data/pdfs/version_1_6.pdf +61 -0
- data/data/shift_jis_text.txt +1 -0
- data/lib/prawn.rb +89 -0
- data/lib/prawn/document.rb +706 -0
- data/lib/prawn/document/bounding_box.rb +539 -0
- data/lib/prawn/document/column_box.rb +144 -0
- data/lib/prawn/document/internals.rb +58 -0
- data/lib/prawn/document/span.rb +57 -0
- data/lib/prawn/encoding.rb +87 -0
- data/lib/prawn/errors.rb +80 -0
- data/lib/prawn/font.rb +413 -0
- data/lib/prawn/font/afm.rb +256 -0
- data/lib/prawn/font/dfont.rb +43 -0
- data/lib/prawn/font/ttf.rb +355 -0
- data/lib/prawn/font_metric_cache.rb +46 -0
- data/lib/prawn/graphics.rb +646 -0
- data/lib/prawn/graphics/cap_style.rb +47 -0
- data/lib/prawn/graphics/color.rb +232 -0
- data/lib/prawn/graphics/dash.rb +109 -0
- data/lib/prawn/graphics/join_style.rb +49 -0
- data/lib/prawn/graphics/patterns.rb +126 -0
- data/lib/prawn/graphics/transformation.rb +157 -0
- data/lib/prawn/graphics/transparency.rb +101 -0
- data/lib/prawn/grid.rb +279 -0
- data/lib/prawn/image_handler.rb +44 -0
- data/lib/prawn/images.rb +199 -0
- data/lib/prawn/images/image.rb +49 -0
- data/lib/prawn/images/jpg.rb +91 -0
- data/lib/prawn/images/png.rb +290 -0
- data/lib/prawn/measurement_extensions.rb +50 -0
- data/lib/prawn/measurements.rb +77 -0
- data/lib/prawn/outline.rb +289 -0
- data/lib/prawn/repeater.rb +124 -0
- data/lib/prawn/security.rb +288 -0
- data/lib/prawn/security/arcfour.rb +54 -0
- data/lib/prawn/soft_mask.rb +94 -0
- data/lib/prawn/stamp.rb +136 -0
- data/lib/prawn/text.rb +437 -0
- data/lib/prawn/text/box.rb +141 -0
- data/lib/prawn/text/formatted.rb +7 -0
- data/lib/prawn/text/formatted/arranger.rb +290 -0
- data/lib/prawn/text/formatted/box.rb +614 -0
- data/lib/prawn/text/formatted/fragment.rb +264 -0
- data/lib/prawn/text/formatted/line_wrap.rb +277 -0
- data/lib/prawn/text/formatted/parser.rb +224 -0
- data/lib/prawn/text/formatted/wrap.rb +160 -0
- data/lib/prawn/utilities.rb +46 -0
- data/lib/prawn/version.rb +5 -0
- data/lib/prawn/view.rb +91 -0
- data/manual/absolute_position.pdf +0 -0
- data/manual/basic_concepts/adding_pages.rb +27 -0
- data/manual/basic_concepts/basic_concepts.rb +36 -0
- data/manual/basic_concepts/creation.rb +39 -0
- data/manual/basic_concepts/cursor.rb +33 -0
- data/manual/basic_concepts/measurement.rb +25 -0
- data/manual/basic_concepts/origin.rb +38 -0
- data/manual/basic_concepts/other_cursor_helpers.rb +40 -0
- data/manual/basic_concepts/view.rb +42 -0
- data/manual/bounding_box/bounding_box.rb +39 -0
- data/manual/bounding_box/bounds.rb +49 -0
- data/manual/bounding_box/canvas.rb +24 -0
- data/manual/bounding_box/creation.rb +23 -0
- data/manual/bounding_box/indentation.rb +46 -0
- data/manual/bounding_box/nesting.rb +45 -0
- data/manual/bounding_box/russian_boxes.rb +40 -0
- data/manual/bounding_box/stretchy.rb +31 -0
- data/manual/contents.rb +29 -0
- data/manual/cover.rb +39 -0
- data/manual/document_and_page_options/background.rb +27 -0
- data/manual/document_and_page_options/document_and_page_options.rb +32 -0
- data/manual/document_and_page_options/metadata.rb +23 -0
- data/manual/document_and_page_options/page_margins.rb +38 -0
- data/manual/document_and_page_options/page_size.rb +34 -0
- data/manual/document_and_page_options/print_scaling.rb +20 -0
- data/manual/example_helper.rb +7 -0
- data/manual/graphics/circle_and_ellipse.rb +22 -0
- data/manual/graphics/color.rb +24 -0
- data/manual/graphics/common_lines.rb +30 -0
- data/manual/graphics/fill_and_stroke.rb +42 -0
- data/manual/graphics/fill_rules.rb +37 -0
- data/manual/graphics/gradients.rb +37 -0
- data/manual/graphics/graphics.rb +58 -0
- data/manual/graphics/helper.rb +24 -0
- data/manual/graphics/line_width.rb +35 -0
- data/manual/graphics/lines_and_curves.rb +41 -0
- data/manual/graphics/polygon.rb +29 -0
- data/manual/graphics/rectangle.rb +21 -0
- data/manual/graphics/rotate.rb +28 -0
- data/manual/graphics/scale.rb +41 -0
- data/manual/graphics/soft_masks.rb +46 -0
- data/manual/graphics/stroke_cap.rb +31 -0
- data/manual/graphics/stroke_dash.rb +48 -0
- data/manual/graphics/stroke_join.rb +30 -0
- data/manual/graphics/translate.rb +29 -0
- data/manual/graphics/transparency.rb +35 -0
- data/manual/how_to_read_this_manual.rb +40 -0
- data/manual/images/absolute_position.rb +23 -0
- data/manual/images/fit.rb +21 -0
- data/manual/images/horizontal.rb +25 -0
- data/manual/images/images.rb +40 -0
- data/manual/images/plain_image.rb +18 -0
- data/manual/images/scale.rb +22 -0
- data/manual/images/vertical.rb +28 -0
- data/manual/images/width_and_height.rb +25 -0
- data/manual/layout/boxes.rb +27 -0
- data/manual/layout/content.rb +25 -0
- data/manual/layout/layout.rb +28 -0
- data/manual/layout/simple_grid.rb +23 -0
- data/manual/outline/add_subsection_to.rb +61 -0
- data/manual/outline/insert_section_after.rb +47 -0
- data/manual/outline/outline.rb +32 -0
- data/manual/outline/sections_and_pages.rb +67 -0
- data/manual/repeatable_content/alternate_page_numbering.rb +32 -0
- data/manual/repeatable_content/page_numbering.rb +54 -0
- data/manual/repeatable_content/repeatable_content.rb +32 -0
- data/manual/repeatable_content/repeater.rb +55 -0
- data/manual/repeatable_content/stamp.rb +41 -0
- data/manual/security/encryption.rb +31 -0
- data/manual/security/permissions.rb +38 -0
- data/manual/security/security.rb +28 -0
- data/manual/table.rb +16 -0
- data/manual/text/alignment.rb +44 -0
- data/manual/text/color.rb +24 -0
- data/manual/text/column_box.rb +32 -0
- data/manual/text/fallback_fonts.rb +37 -0
- data/manual/text/font.rb +41 -0
- data/manual/text/font_size.rb +45 -0
- data/manual/text/font_style.rb +23 -0
- data/manual/text/formatted_callbacks.rb +60 -0
- data/manual/text/formatted_text.rb +50 -0
- data/manual/text/free_flowing_text.rb +51 -0
- data/manual/text/inline.rb +41 -0
- data/manual/text/kerning_and_character_spacing.rb +39 -0
- data/manual/text/leading.rb +25 -0
- data/manual/text/line_wrapping.rb +41 -0
- data/manual/text/paragraph_indentation.rb +34 -0
- data/manual/text/positioned_text.rb +38 -0
- data/manual/text/registering_families.rb +48 -0
- data/manual/text/rendering_and_color.rb +37 -0
- data/manual/text/right_to_left_text.rb +47 -0
- data/manual/text/rotation.rb +43 -0
- data/manual/text/single_usage.rb +37 -0
- data/manual/text/text.rb +73 -0
- data/manual/text/text_box_excess.rb +32 -0
- data/manual/text/text_box_extensions.rb +45 -0
- data/manual/text/text_box_overflow.rb +48 -0
- data/manual/text/utf8.rb +28 -0
- data/manual/text/win_ansi_charset.rb +60 -0
- data/prawn.gemspec +45 -0
- data/spec/acceptance/png.rb +25 -0
- data/spec/annotations_spec.rb +74 -0
- data/spec/bounding_box_spec.rb +510 -0
- data/spec/column_box_spec.rb +65 -0
- data/spec/data/curves.pdf +66 -0
- data/spec/destinations_spec.rb +15 -0
- data/spec/document_spec.rb +748 -0
- data/spec/extensions/encoding_helpers.rb +11 -0
- data/spec/extensions/mocha.rb +46 -0
- data/spec/font_metric_cache_spec.rb +52 -0
- data/spec/font_spec.rb +474 -0
- data/spec/formatted_text_arranger_spec.rb +421 -0
- data/spec/formatted_text_box_spec.rb +705 -0
- data/spec/formatted_text_fragment_spec.rb +298 -0
- data/spec/graphics_spec.rb +683 -0
- data/spec/grid_spec.rb +96 -0
- data/spec/image_handler_spec.rb +54 -0
- data/spec/images_spec.rb +153 -0
- data/spec/inline_formatted_text_parser_spec.rb +564 -0
- data/spec/jpg_spec.rb +25 -0
- data/spec/line_wrap_spec.rb +367 -0
- data/spec/measurement_units_spec.rb +25 -0
- data/spec/outline_spec.rb +430 -0
- data/spec/png_spec.rb +245 -0
- data/spec/reference_spec.rb +25 -0
- data/spec/repeater_spec.rb +160 -0
- data/spec/security_spec.rb +158 -0
- data/spec/soft_mask_spec.rb +79 -0
- data/spec/span_spec.rb +44 -0
- data/spec/spec_helper.rb +54 -0
- data/spec/stamp_spec.rb +160 -0
- data/spec/stroke_styles_spec.rb +211 -0
- data/spec/text_at_spec.rb +143 -0
- data/spec/text_box_spec.rb +1043 -0
- data/spec/text_rendering_mode_spec.rb +45 -0
- data/spec/text_spacing_spec.rb +93 -0
- data/spec/text_spec.rb +557 -0
- data/spec/text_with_inline_formatting_spec.rb +35 -0
- data/spec/transparency_spec.rb +91 -0
- data/spec/view_spec.rb +43 -0
- metadata +509 -0
@@ -0,0 +1,79 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
|
5
|
+
module SoftMaskHelper
|
6
|
+
def make_soft_mask
|
7
|
+
@pdf.save_graphics_state do
|
8
|
+
@pdf.soft_mask do
|
9
|
+
if block_given?
|
10
|
+
yield
|
11
|
+
else
|
12
|
+
@pdf.fill_color '808080'
|
13
|
+
@pdf.fill_rectangle [100, 100], 200, 200
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
@pdf.fill_color '000000'
|
18
|
+
@pdf.fill_rectangle [0, 0], 200, 200
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "Document with soft masks" do
|
24
|
+
|
25
|
+
include SoftMaskHelper
|
26
|
+
|
27
|
+
it "should have PDF version at least 1.4" do
|
28
|
+
create_pdf
|
29
|
+
make_soft_mask
|
30
|
+
str = @pdf.render
|
31
|
+
str[0,8].should == "%PDF-1.4"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should create a new extended graphics state for each unique soft mask" do
|
35
|
+
create_pdf
|
36
|
+
|
37
|
+
make_soft_mask do
|
38
|
+
@pdf.fill_color '808080'
|
39
|
+
@pdf.fill_rectangle [100, 100], 200, 200
|
40
|
+
end
|
41
|
+
|
42
|
+
make_soft_mask do
|
43
|
+
@pdf.fill_color '808080'
|
44
|
+
@pdf.fill_rectangle [10, 10], 200, 200
|
45
|
+
end
|
46
|
+
|
47
|
+
extgstates = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates
|
48
|
+
extgstates.length.should == 2
|
49
|
+
end
|
50
|
+
|
51
|
+
it "a new extended graphics state should contain soft mask with drawing instructions" do
|
52
|
+
create_pdf
|
53
|
+
|
54
|
+
make_soft_mask do
|
55
|
+
@pdf.fill_color '808080'
|
56
|
+
@pdf.fill_rectangle [100, 100], 200, 200
|
57
|
+
end
|
58
|
+
|
59
|
+
extgstate = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates.first
|
60
|
+
extgstate[:soft_mask][:G].data.should == "q\n/DeviceRGB cs\n0.000 0.000 0.000 scn\n/DeviceRGB CS\n0.000 0.000 0.000 SCN\n1 w\n0 J\n0 j\n[] 0 d\n/DeviceRGB cs\n0.502 0.502 0.502 scn\n100.0 -100.0 200.0 200.0 re\nf\nQ\n"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should not create duplicate extended graphics states" do
|
64
|
+
create_pdf
|
65
|
+
|
66
|
+
make_soft_mask do
|
67
|
+
@pdf.fill_color '808080'
|
68
|
+
@pdf.fill_rectangle [100, 100], 200, 200
|
69
|
+
end
|
70
|
+
|
71
|
+
make_soft_mask do
|
72
|
+
@pdf.fill_color '808080'
|
73
|
+
@pdf.fill_rectangle [100, 100], 200, 200
|
74
|
+
end
|
75
|
+
|
76
|
+
extgstates = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates
|
77
|
+
extgstates.length.should == 1
|
78
|
+
end
|
79
|
+
end
|
data/spec/span_spec.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
|
5
|
+
describe "drawing span" do
|
6
|
+
|
7
|
+
before do
|
8
|
+
Prawn.debug = false
|
9
|
+
create_pdf
|
10
|
+
end
|
11
|
+
|
12
|
+
after do
|
13
|
+
Prawn.debug = true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should only accept :position as option in debug mode" do
|
17
|
+
Prawn.debug = true
|
18
|
+
lambda { @pdf.span(350, {:x => 3}) {} }.should raise_error(Prawn::Errors::UnknownOption)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have raise an error if :position is invalid" do
|
22
|
+
lambda { @pdf.span(350, :position => :x) {} }.should raise_error(ArgumentError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should restore the margin box when bounding box exits" do
|
26
|
+
margin_box = @pdf.bounds
|
27
|
+
|
28
|
+
@pdf.span(350, :position => :center) do
|
29
|
+
@pdf.text "Here's some centered text in a 350 point column. " * 100
|
30
|
+
end
|
31
|
+
|
32
|
+
@pdf.bounds.should == margin_box
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should do create a margin box" do
|
36
|
+
y = @pdf.y
|
37
|
+
margin_box = @pdf.span(350, :position => :center) do
|
38
|
+
@pdf.text "Here's some centered text in a 350 point column. " * 100
|
39
|
+
end
|
40
|
+
|
41
|
+
margin_box.top.should == 792.0
|
42
|
+
margin_box.bottom.should == 0
|
43
|
+
end
|
44
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
puts "Prawn specs: Running on Ruby Version: #{RUBY_VERSION}"
|
4
|
+
|
5
|
+
require "bundler"
|
6
|
+
Bundler.setup
|
7
|
+
|
8
|
+
if ENV["COVERAGE"]
|
9
|
+
require "simplecov"
|
10
|
+
SimpleCov.start do
|
11
|
+
add_filter "/spec/"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
require_relative "../lib/prawn"
|
16
|
+
|
17
|
+
Prawn.debug = true
|
18
|
+
Prawn::Font::AFM.hide_m17n_warning = true
|
19
|
+
|
20
|
+
#require "test/spec"
|
21
|
+
require "rspec"
|
22
|
+
require "mocha/api"
|
23
|
+
require "pdf/reader"
|
24
|
+
require "pdf/inspector"
|
25
|
+
|
26
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
27
|
+
# in spec/extensions/ and its subdirectories.
|
28
|
+
Dir[File.dirname(__FILE__) + "/extensions/**/*.rb"].each {|f| require f }
|
29
|
+
|
30
|
+
RSpec.configure do |config|
|
31
|
+
config.mock_framework = :mocha
|
32
|
+
config.include EncodingHelpers
|
33
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_pdf(klass=Prawn::Document)
|
37
|
+
@pdf = klass.new(:margin => 0)
|
38
|
+
end
|
39
|
+
|
40
|
+
RSpec::Matchers.define :have_parseable_xobjects do
|
41
|
+
match do |actual|
|
42
|
+
expect { PDF::Inspector::XObject.analyze(actual.render) }.not_to raise_error
|
43
|
+
true
|
44
|
+
end
|
45
|
+
failure_message_for_should do |actual|
|
46
|
+
"expected that #{actual}'s XObjects could be successfully parsed"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Make some methods public to assist in testing
|
51
|
+
module Prawn::Graphics
|
52
|
+
public :map_to_absolute
|
53
|
+
end
|
54
|
+
|
data/spec/stamp_spec.rb
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
|
5
|
+
describe "create_stamp before any page is added" do
|
6
|
+
it "should work with the font class" do
|
7
|
+
@pdf = Prawn::Document.new(:skip_page_creation => true)
|
8
|
+
|
9
|
+
# If anything goes wrong, Prawn::Errors::NotOnPage will be raised
|
10
|
+
@pdf.create_stamp("my_stamp") do
|
11
|
+
@pdf.font.height
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should work with setting color" do
|
16
|
+
@pdf = Prawn::Document.new(:skip_page_creation => true)
|
17
|
+
|
18
|
+
# If anything goes wrong, Prawn::Errors::NotOnPage will be raised
|
19
|
+
@pdf.create_stamp("my_stamp") do
|
20
|
+
@pdf.fill_color = 'ff0000'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#stamp_at" do
|
26
|
+
it "should work" do
|
27
|
+
create_pdf
|
28
|
+
@pdf.create_stamp("MyStamp")
|
29
|
+
@pdf.stamp_at("MyStamp", [100, 200])
|
30
|
+
# I had modified PDF::Inspector::XObject to receive the
|
31
|
+
# invoke_xobject message and count the number of times it was
|
32
|
+
# called, but it was only called once, so I reverted checking the
|
33
|
+
# output with a regular expression
|
34
|
+
@pdf.render.should =~ /\/Stamp1 Do.*?/m
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "Document with a stamp" do
|
39
|
+
it "should raise_error NameTaken error when attempt to create stamp "+
|
40
|
+
"with same name as an existing stamp" do
|
41
|
+
create_pdf
|
42
|
+
@pdf.create_stamp("MyStamp")
|
43
|
+
lambda {
|
44
|
+
@pdf.create_stamp("MyStamp")
|
45
|
+
}.should raise_error(Prawn::Errors::NameTaken)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should raise_error InvalidName error when attempt to create "+
|
49
|
+
"stamp with a blank name" do
|
50
|
+
create_pdf
|
51
|
+
lambda {
|
52
|
+
@pdf.create_stamp("")
|
53
|
+
}.should raise_error(Prawn::Errors::InvalidName)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "a new XObject should be defined for each stamp created" do
|
57
|
+
create_pdf
|
58
|
+
@pdf.create_stamp("MyStamp")
|
59
|
+
@pdf.create_stamp("AnotherStamp")
|
60
|
+
@pdf.stamp("MyStamp")
|
61
|
+
@pdf.stamp("AnotherStamp")
|
62
|
+
|
63
|
+
inspector = PDF::Inspector::XObject.analyze(@pdf.render)
|
64
|
+
xobjects = inspector.page_xobjects.last
|
65
|
+
xobjects.length.should == 2
|
66
|
+
end
|
67
|
+
|
68
|
+
it "calling stamp with a name that does not match an existing stamp "+
|
69
|
+
"should raise_error UndefinedObjectName" do
|
70
|
+
create_pdf
|
71
|
+
@pdf.create_stamp("MyStamp")
|
72
|
+
lambda {
|
73
|
+
@pdf.stamp("OtherStamp")
|
74
|
+
}.should raise_error(Prawn::Errors::UndefinedObjectName)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "stamp should be drawn into the document each time stamp is called" do
|
78
|
+
create_pdf
|
79
|
+
@pdf.create_stamp("MyStamp")
|
80
|
+
@pdf.stamp("MyStamp")
|
81
|
+
@pdf.stamp("MyStamp")
|
82
|
+
@pdf.stamp("MyStamp")
|
83
|
+
# I had modified PDF::Inspector::XObject to receive the
|
84
|
+
# invoke_xobject message and count the number of times it was
|
85
|
+
# called, but it was only called once, so I reverted checking the
|
86
|
+
# output with a regular expression
|
87
|
+
@pdf.render.should =~ /(\/Stamp1 Do.*?){3}/m
|
88
|
+
end
|
89
|
+
|
90
|
+
it "resources added during stamp creation should be added to the "+
|
91
|
+
"stamp XObject, not the page" do
|
92
|
+
create_pdf
|
93
|
+
@pdf.create_stamp("MyStamp") do
|
94
|
+
@pdf.transparent(0.5) { @pdf.circle([100, 100], 10)}
|
95
|
+
end
|
96
|
+
@pdf.stamp("MyStamp")
|
97
|
+
|
98
|
+
# Inspector::XObject does not give information about resources, so
|
99
|
+
# resorting to string matching
|
100
|
+
|
101
|
+
output = @pdf.render
|
102
|
+
objects = output.split("endobj")
|
103
|
+
objects.each do |object|
|
104
|
+
if object =~ /\/Type \/Page$/
|
105
|
+
object.should_not =~ /\/ExtGState/
|
106
|
+
elsif object =~ /\/Type \/XObject$/
|
107
|
+
object.should =~ /\/ExtGState/
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
it "stamp stream should be wrapped in a graphic state" do
|
113
|
+
create_pdf
|
114
|
+
@pdf.create_stamp("MyStamp") do
|
115
|
+
@pdf.text "This should have a 'q' before it and a 'Q' after it"
|
116
|
+
end
|
117
|
+
@pdf.stamp("MyStamp")
|
118
|
+
stamps = PDF::Inspector::XObject.analyze(@pdf.render)
|
119
|
+
stamps.xobject_streams[:Stamp1].data.chomp.should =~ /q(.|\s)*Q\Z/
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should not add to the page graphic state stack " do
|
123
|
+
create_pdf
|
124
|
+
@pdf.state.page.stack.stack.size.should == 1
|
125
|
+
|
126
|
+
@pdf.create_stamp("MyStamp") do
|
127
|
+
@pdf.save_graphics_state
|
128
|
+
@pdf.save_graphics_state
|
129
|
+
@pdf.save_graphics_state
|
130
|
+
@pdf.text "This should have a 'q' before it and a 'Q' after it"
|
131
|
+
@pdf.restore_graphics_state
|
132
|
+
end
|
133
|
+
@pdf.state.page.stack.stack.size.should == 1
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should be able to change fill and stroke colors within the stamp stream" do
|
137
|
+
create_pdf
|
138
|
+
@pdf.create_stamp("MyStamp") do
|
139
|
+
@pdf.fill_color(100, 100, 20, 0)
|
140
|
+
@pdf.stroke_color(100, 100, 20, 0)
|
141
|
+
end
|
142
|
+
@pdf.stamp("MyStamp")
|
143
|
+
stamps = PDF::Inspector::XObject.analyze(@pdf.render)
|
144
|
+
stamp_stream = stamps.xobject_streams[:Stamp1].data
|
145
|
+
stamp_stream.should include("/DeviceCMYK cs\n1.000 1.000 0.200 0.000 scn")
|
146
|
+
stamp_stream.should include("/DeviceCMYK CS\n1.000 1.000 0.200 0.000 SCN")
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should save the color space even when same as current page color space" do
|
150
|
+
create_pdf
|
151
|
+
@pdf.stroke_color(100, 100, 20, 0)
|
152
|
+
@pdf.create_stamp("MyStamp") do
|
153
|
+
@pdf.stroke_color(100, 100, 20, 0)
|
154
|
+
end
|
155
|
+
@pdf.stamp("MyStamp")
|
156
|
+
stamps = PDF::Inspector::XObject.analyze(@pdf.render)
|
157
|
+
stamp_stream = stamps.xobject_streams[:Stamp1].data
|
158
|
+
stamp_stream.should include("/DeviceCMYK CS\n1.000 1.000 0.200 0.000 SCN")
|
159
|
+
end
|
160
|
+
end
|
@@ -0,0 +1,211 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
|
5
|
+
describe "When stroking with default settings" do
|
6
|
+
before(:each) { create_pdf }
|
7
|
+
it "cap_style should be :butt" do
|
8
|
+
@pdf.cap_style.should == :butt
|
9
|
+
end
|
10
|
+
|
11
|
+
it "join_style should be :miter" do
|
12
|
+
@pdf.join_style.should == :miter
|
13
|
+
end
|
14
|
+
|
15
|
+
it "dashed? should be_false" do
|
16
|
+
@pdf.should_not be_dashed
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "Cap styles" do
|
21
|
+
before(:each) { create_pdf }
|
22
|
+
|
23
|
+
it "should be able to use assignment operator" do
|
24
|
+
@pdf.cap_style = :round
|
25
|
+
@pdf.cap_style.should == :round
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#cap_style(:butt)" do
|
29
|
+
it "rendered PDF should include butt style cap" do
|
30
|
+
@pdf.cap_style(:butt)
|
31
|
+
cap_style = PDF::Inspector::Graphics::CapStyle.analyze(@pdf.render).cap_style
|
32
|
+
cap_style.should == 0
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#cap_style(:round)" do
|
37
|
+
it "rendered PDF should include round style cap" do
|
38
|
+
@pdf.cap_style(:round)
|
39
|
+
cap_style = PDF::Inspector::Graphics::CapStyle.analyze(@pdf.render).cap_style
|
40
|
+
cap_style.should == 1
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#cap_style(:projecting_square)" do
|
45
|
+
it "rendered PDF should include projecting_square style cap" do
|
46
|
+
@pdf.cap_style(:projecting_square)
|
47
|
+
cap_style = PDF::Inspector::Graphics::CapStyle.analyze(@pdf.render).cap_style
|
48
|
+
cap_style.should == 2
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should carry the current cap style settings over to new pages" do
|
53
|
+
@pdf.cap_style(:round)
|
54
|
+
@pdf.start_new_page
|
55
|
+
cap_styles = PDF::Inspector::Graphics::CapStyle.analyze(@pdf.render)
|
56
|
+
cap_styles.cap_style_count.should == 2
|
57
|
+
cap_styles.cap_style.should == 1
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "Join styles" do
|
62
|
+
before(:each) { create_pdf }
|
63
|
+
|
64
|
+
it "should be able to use assignment operator" do
|
65
|
+
@pdf.join_style = :round
|
66
|
+
@pdf.join_style.should == :round
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#join_style(:miter)" do
|
70
|
+
it "rendered PDF should include miter style join" do
|
71
|
+
@pdf.join_style(:miter)
|
72
|
+
join_style = PDF::Inspector::Graphics::JoinStyle.analyze(@pdf.render).join_style
|
73
|
+
join_style.should == 0
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#join_style(:round)" do
|
78
|
+
it "rendered PDF should include round style join" do
|
79
|
+
@pdf.join_style(:round)
|
80
|
+
join_style = PDF::Inspector::Graphics::JoinStyle.analyze(@pdf.render).join_style
|
81
|
+
join_style.should == 1
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#join_style(:bevel)" do
|
86
|
+
it "rendered PDF should include bevel style join" do
|
87
|
+
@pdf.join_style(:bevel)
|
88
|
+
join_style = PDF::Inspector::Graphics::JoinStyle.analyze(@pdf.render).join_style
|
89
|
+
join_style.should == 2
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should carry the current join style settings over to new pages" do
|
94
|
+
@pdf.join_style(:round)
|
95
|
+
@pdf.start_new_page
|
96
|
+
join_styles = PDF::Inspector::Graphics::JoinStyle.analyze(@pdf.render)
|
97
|
+
join_styles.join_style_count.should == 2
|
98
|
+
join_styles.join_style.should == 1
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "Dashes" do
|
103
|
+
before(:each) { create_pdf }
|
104
|
+
|
105
|
+
it "should be able to use assignment operator" do
|
106
|
+
@pdf.dash = 2
|
107
|
+
@pdf.should be_dashed
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "setting a dash" do
|
111
|
+
it "dashed? should be_true" do
|
112
|
+
@pdf.dash(2)
|
113
|
+
@pdf.should be_dashed
|
114
|
+
end
|
115
|
+
it "rendered PDF should include a stroked dash" do
|
116
|
+
@pdf.dash(2)
|
117
|
+
dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
|
118
|
+
dashes.stroke_dash.should == [[2, 2], 0]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "setting a dash by passing a single argument" do
|
123
|
+
it "space between dashes should be the same length as the dash in the rendered PDF" do
|
124
|
+
@pdf.dash(2)
|
125
|
+
dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
|
126
|
+
dashes.stroke_dash.should == [[2, 2], 0]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "with a space option that differs from the first argument" do
|
131
|
+
it "space between dashes in the rendered PDF should be different length than the length of the dash" do
|
132
|
+
@pdf.dash(2, :space => 3)
|
133
|
+
dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
|
134
|
+
dashes.stroke_dash.should == [[2, 3], 0]
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "with a non-zero phase option" do
|
139
|
+
it "rendered PDF should include a non-zero phase" do
|
140
|
+
@pdf.dash(2, :phase => 1)
|
141
|
+
dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
|
142
|
+
dashes.stroke_dash.should == [[2, 2], 1]
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "setting a dash by using an array" do
|
147
|
+
it "dash and spaces should be set from the array" do
|
148
|
+
@pdf.dash([1,2,3,4])
|
149
|
+
dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
|
150
|
+
dashes.stroke_dash.should == [[1, 2, 3, 4], 0]
|
151
|
+
end
|
152
|
+
it "space options has to be ignored" do
|
153
|
+
@pdf.dash([1,2,3,4], :space => 3)
|
154
|
+
dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
|
155
|
+
dashes.stroke_dash.should == [[1, 2, 3, 4], 0]
|
156
|
+
end
|
157
|
+
it "phase options should be correctly used" do
|
158
|
+
@pdf.dash([1,2,3,4], :phase => 3)
|
159
|
+
dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
|
160
|
+
dashes.stroke_dash.should == [[1, 2, 3, 4], 3]
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe "clearing stroke dash" do
|
165
|
+
it "should restore solid line" do
|
166
|
+
@pdf.dash(2)
|
167
|
+
@pdf.undash
|
168
|
+
dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
|
169
|
+
dashes.stroke_dash.should == [[], 0]
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should carry the current dash settings over to new pages" do
|
174
|
+
@pdf.dash(2)
|
175
|
+
@pdf.start_new_page
|
176
|
+
dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
|
177
|
+
dashes.stroke_dash_count.should == 2
|
178
|
+
dashes.stroke_dash.should == [[2, 2], 0]
|
179
|
+
end
|
180
|
+
|
181
|
+
describe "#dashed?" do
|
182
|
+
|
183
|
+
it "an initial document should not be dashed" do
|
184
|
+
@pdf.dashed?.should == false
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should return true if any of the currently active settings are dashed" do
|
188
|
+
@pdf.dash(2)
|
189
|
+
@pdf.save_graphics_state
|
190
|
+
@pdf.dashed?.should == true
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should return false if the document was most recently undashed" do
|
194
|
+
@pdf.dash(2)
|
195
|
+
@pdf.save_graphics_state
|
196
|
+
@pdf.undash
|
197
|
+
@pdf.save_graphics_state
|
198
|
+
@pdf.dashed?.should == false
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should return true when restoring to a state that was dashed" do
|
202
|
+
@pdf.dash(2)
|
203
|
+
@pdf.save_graphics_state
|
204
|
+
@pdf.undash
|
205
|
+
@pdf.restore_graphics_state
|
206
|
+
@pdf.dashed?.should == true
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|