prawn 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +2 -0
- data.tar.gz.sig +0 -0
- data/Gemfile +1 -9
- data/Rakefile +12 -22
- data/lib/prawn.rb +29 -48
- data/lib/prawn/document.rb +148 -123
- data/lib/prawn/document/bounding_box.rb +33 -26
- data/lib/prawn/document/column_box.rb +5 -7
- data/lib/prawn/document/internals.rb +6 -6
- data/lib/prawn/document/span.rb +20 -17
- data/lib/prawn/encoding.rb +65 -67
- data/lib/prawn/errors.rb +10 -7
- data/lib/prawn/font.rb +78 -62
- data/lib/prawn/font/afm.rb +93 -66
- data/lib/prawn/font/dfont.rb +2 -10
- data/lib/prawn/font/ttc.rb +34 -0
- data/lib/prawn/font/ttf.rb +73 -65
- data/lib/prawn/font_metric_cache.rb +9 -8
- data/lib/prawn/graphics.rb +110 -70
- data/lib/prawn/graphics/blend_mode.rb +7 -8
- data/lib/prawn/graphics/cap_style.rb +2 -4
- data/lib/prawn/graphics/color.rb +23 -26
- data/lib/prawn/graphics/dash.rb +22 -12
- data/lib/prawn/graphics/join_style.rb +8 -4
- data/lib/prawn/graphics/patterns.rb +185 -96
- data/lib/prawn/graphics/transformation.rb +11 -9
- data/lib/prawn/graphics/transparency.rb +15 -13
- data/lib/prawn/grid.rb +20 -20
- data/lib/prawn/image_handler.rb +4 -6
- data/lib/prawn/images.rb +22 -15
- data/lib/prawn/images/image.rb +0 -1
- data/lib/prawn/images/jpg.rb +26 -22
- data/lib/prawn/images/png.rb +60 -57
- data/lib/prawn/measurement_extensions.rb +8 -9
- data/lib/prawn/measurements.rb +14 -15
- data/lib/prawn/outline.rb +96 -78
- data/lib/prawn/repeater.rb +12 -10
- data/lib/prawn/security.rb +66 -48
- data/lib/prawn/security/arcfour.rb +1 -3
- data/lib/prawn/soft_mask.rb +23 -25
- data/lib/prawn/stamp.rb +16 -12
- data/lib/prawn/text.rb +59 -45
- data/lib/prawn/text/box.rb +9 -8
- data/lib/prawn/text/formatted.rb +4 -6
- data/lib/prawn/text/formatted/arranger.rb +51 -30
- data/lib/prawn/text/formatted/box.rb +112 -88
- data/lib/prawn/text/formatted/fragment.rb +10 -15
- data/lib/prawn/text/formatted/line_wrap.rb +118 -61
- data/lib/prawn/text/formatted/parser.rb +134 -110
- data/lib/prawn/text/formatted/wrap.rb +42 -32
- data/lib/prawn/transformation_stack.rb +3 -4
- data/lib/prawn/utilities.rb +6 -21
- data/lib/prawn/version.rb +1 -3
- data/lib/prawn/view.rb +4 -2
- data/manual/basic_concepts/adding_pages.rb +4 -7
- data/manual/basic_concepts/basic_concepts.rb +29 -22
- data/manual/basic_concepts/creation.rb +8 -11
- data/manual/basic_concepts/cursor.rb +2 -5
- data/manual/basic_concepts/measurement.rb +3 -6
- data/manual/basic_concepts/origin.rb +3 -6
- data/manual/basic_concepts/other_cursor_helpers.rb +9 -12
- data/manual/basic_concepts/view.rb +20 -16
- data/manual/bounding_box/bounding_box.rb +27 -24
- data/manual/bounding_box/bounds.rb +9 -12
- data/manual/bounding_box/canvas.rb +2 -5
- data/manual/bounding_box/creation.rb +4 -7
- data/manual/bounding_box/indentation.rb +12 -15
- data/manual/bounding_box/nesting.rb +22 -17
- data/manual/bounding_box/russian_boxes.rb +8 -9
- data/manual/bounding_box/stretchy.rb +10 -13
- data/manual/contents.rb +26 -22
- data/manual/cover.rb +22 -20
- data/manual/document_and_page_options/background.rb +9 -13
- data/manual/document_and_page_options/document_and_page_options.rb +23 -20
- data/manual/document_and_page_options/metadata.rb +16 -16
- data/manual/document_and_page_options/page_margins.rb +16 -20
- data/manual/document_and_page_options/page_size.rb +11 -12
- data/manual/document_and_page_options/print_scaling.rb +15 -15
- data/manual/example_helper.rb +2 -4
- data/manual/graphics/blend_mode.rb +10 -9
- data/manual/graphics/circle_and_ellipse.rb +2 -5
- data/manual/graphics/color.rb +5 -9
- data/manual/graphics/common_lines.rb +5 -8
- data/manual/graphics/fill_and_stroke.rb +2 -5
- data/manual/graphics/fill_rules.rb +7 -10
- data/manual/graphics/gradients.rb +25 -21
- data/manual/graphics/graphics.rb +49 -43
- data/manual/graphics/helper.rb +10 -9
- data/manual/graphics/line_width.rb +5 -7
- data/manual/graphics/lines_and_curves.rb +5 -8
- data/manual/graphics/polygon.rb +4 -8
- data/manual/graphics/rectangle.rb +2 -5
- data/manual/graphics/rotate.rb +4 -7
- data/manual/graphics/scale.rb +12 -15
- data/manual/graphics/soft_masks.rb +1 -4
- data/manual/graphics/stroke_cap.rb +3 -6
- data/manual/graphics/stroke_dash.rb +9 -12
- data/manual/graphics/stroke_join.rb +2 -5
- data/manual/graphics/translate.rb +7 -10
- data/manual/graphics/transparency.rb +5 -8
- data/manual/how_to_read_this_manual.rb +4 -6
- data/manual/images/absolute_position.rb +4 -7
- data/manual/images/fit.rb +5 -8
- data/manual/images/horizontal.rb +6 -9
- data/manual/images/images.rb +25 -23
- data/manual/images/plain_image.rb +3 -6
- data/manual/images/scale.rb +7 -10
- data/manual/images/vertical.rb +10 -13
- data/manual/images/width_and_height.rb +8 -11
- data/manual/layout/boxes.rb +3 -6
- data/manual/layout/content.rb +5 -8
- data/manual/layout/layout.rb +16 -16
- data/manual/layout/simple_grid.rb +4 -7
- data/manual/outline/add_subsection_to.rb +18 -21
- data/manual/outline/insert_section_after.rb +13 -16
- data/manual/outline/outline.rb +19 -17
- data/manual/outline/sections_and_pages.rb +15 -18
- data/manual/repeatable_content/alternate_page_numbering.rb +19 -17
- data/manual/repeatable_content/page_numbering.rb +15 -16
- data/manual/repeatable_content/repeatable_content.rb +23 -19
- data/manual/repeatable_content/repeater.rb +12 -15
- data/manual/repeatable_content/stamp.rb +12 -15
- data/manual/security/encryption.rb +7 -10
- data/manual/security/permissions.rb +17 -14
- data/manual/security/security.rb +17 -16
- data/manual/table.rb +2 -4
- data/manual/text/alignment.rb +14 -17
- data/manual/text/color.rb +10 -11
- data/manual/text/column_box.rb +5 -8
- data/manual/text/fallback_fonts.rb +23 -21
- data/manual/text/font.rb +9 -12
- data/manual/text/font_size.rb +11 -14
- data/manual/text/font_style.rb +4 -7
- data/manual/text/formatted_callbacks.rb +23 -21
- data/manual/text/formatted_text.rb +31 -25
- data/manual/text/free_flowing_text.rb +18 -21
- data/manual/text/inline.rb +16 -19
- data/manual/text/kerning_and_character_spacing.rb +12 -15
- data/manual/text/leading.rb +5 -8
- data/manual/text/line_wrapping.rb +33 -17
- data/manual/text/paragraph_indentation.rb +11 -14
- data/manual/text/positioned_text.rb +13 -16
- data/manual/text/registering_families.rb +16 -19
- data/manual/text/rendering_and_color.rb +7 -10
- data/manual/text/right_to_left_text.rb +24 -19
- data/manual/text/rotation.rb +26 -23
- data/manual/text/single_usage.rb +6 -9
- data/manual/text/text.rb +56 -52
- data/manual/text/text_box_excess.rb +18 -17
- data/manual/text/text_box_extensions.rb +16 -15
- data/manual/text/text_box_overflow.rb +15 -18
- data/manual/text/utf8.rb +9 -12
- data/manual/text/win_ansi_charset.rb +18 -19
- data/prawn.gemspec +37 -27
- data/spec/extensions/encoding_helpers.rb +0 -2
- data/spec/manual_spec.rb +33 -0
- data/spec/prawn/document/bounding_box_spec.rb +546 -0
- data/spec/prawn/document/column_box_spec.rb +73 -0
- data/spec/prawn/document/security_spec.rb +173 -0
- data/spec/prawn/document_annotations_spec.rb +74 -0
- data/spec/prawn/document_destinations_spec.rb +13 -0
- data/spec/prawn/document_grid_spec.rb +96 -0
- data/spec/prawn/document_reference_spec.rb +25 -0
- data/spec/prawn/document_span_spec.rb +34 -0
- data/spec/prawn/document_spec.rb +751 -0
- data/spec/prawn/font_metric_cache_spec.rb +52 -0
- data/spec/prawn/font_spec.rb +513 -0
- data/spec/prawn/graphics/blend_mode_spec.rb +61 -0
- data/spec/prawn/graphics/transparency_spec.rb +79 -0
- data/spec/prawn/graphics_spec.rb +817 -0
- data/spec/prawn/graphics_stroke_styles_spec.rb +227 -0
- data/spec/{image_handler_spec.rb → prawn/image_handler_spec.rb} +13 -15
- data/spec/prawn/images/jpg_spec.rb +18 -0
- data/spec/prawn/images/png_spec.rb +281 -0
- data/spec/prawn/images_spec.rb +170 -0
- data/spec/prawn/measurements_extensions_spec.rb +22 -0
- data/spec/prawn/outline_spec.rb +408 -0
- data/spec/prawn/repeater_spec.rb +163 -0
- data/spec/prawn/soft_mask_spec.rb +72 -0
- data/spec/prawn/stamp_spec.rb +168 -0
- data/spec/prawn/text/box_spec.rb +1113 -0
- data/spec/prawn/text/formatted/arranger_spec.rb +464 -0
- data/spec/prawn/text/formatted/box_spec.rb +825 -0
- data/spec/prawn/text/formatted/fragment_spec.rb +341 -0
- data/spec/prawn/text/formatted/line_wrap_spec.rb +491 -0
- data/spec/prawn/text/formatted/parser_spec.rb +667 -0
- data/spec/prawn/text_draw_text_spec.rb +147 -0
- data/spec/prawn/text_rendering_mode_spec.rb +42 -0
- data/spec/prawn/text_spacing_spec.rb +93 -0
- data/spec/prawn/text_spec.rb +601 -0
- data/spec/prawn/text_with_inline_formatting_spec.rb +33 -0
- data/spec/{transformation_stack_spec.rb → prawn/transformation_stack_spec.rb} +21 -20
- data/spec/prawn/view_spec.rb +45 -0
- data/spec/spec_helper.rb +16 -16
- metadata +96 -151
- metadata.gz.sig +1 -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/blend_modes_bottom_layer.jpg +0 -0
- data/data/images/blend_modes_top_layer.jpg +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/indexed_transparency.png +0 -0
- data/data/images/indexed_transparency_alpha.dat +0 -0
- data/data/images/indexed_transparency_color.dat +0 -0
- data/data/images/letterhead.jpg +0 -0
- data/data/images/license.md +0 -8
- 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/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 +0 -1
- 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 +1 -819
- data/data/pdfs/hexagon.pdf +0 -61
- data/data/pdfs/indirect_reference.pdf +0 -86
- data/data/pdfs/multipage_template.pdf +0 -127
- data/data/pdfs/nested_pages.pdf +0 -118
- data/data/pdfs/page_without_mediabox.pdf +0 -193
- data/data/pdfs/resources_as_indirect_object.pdf +0 -83
- data/data/pdfs/two_hexagons.pdf +0 -90
- data/data/pdfs/version_1_6.pdf +0 -61
- data/data/shift_jis_text.txt +0 -1
- data/spec/acceptance/png_spec.rb +0 -35
- data/spec/annotations_spec.rb +0 -67
- data/spec/blend_mode_spec.rb +0 -71
- data/spec/bounding_box_spec.rb +0 -501
- data/spec/column_box_spec.rb +0 -59
- data/spec/destinations_spec.rb +0 -13
- data/spec/document_spec.rb +0 -738
- data/spec/font_metric_cache_spec.rb +0 -52
- data/spec/font_spec.rb +0 -475
- data/spec/formatted_text_arranger_spec.rb +0 -452
- data/spec/formatted_text_box_spec.rb +0 -716
- data/spec/formatted_text_fragment_spec.rb +0 -299
- data/spec/graphics_spec.rb +0 -705
- data/spec/grid_spec.rb +0 -95
- data/spec/images_spec.rb +0 -167
- data/spec/inline_formatted_text_parser_spec.rb +0 -568
- data/spec/jpg_spec.rb +0 -23
- data/spec/line_wrap_spec.rb +0 -366
- data/spec/measurement_units_spec.rb +0 -22
- data/spec/outline_spec.rb +0 -409
- data/spec/png_spec.rb +0 -257
- data/spec/reference_spec.rb +0 -25
- data/spec/repeater_spec.rb +0 -154
- data/spec/security_spec.rb +0 -151
- data/spec/soft_mask_spec.rb +0 -78
- data/spec/span_spec.rb +0 -43
- data/spec/stamp_spec.rb +0 -179
- data/spec/stroke_styles_spec.rb +0 -208
- data/spec/text_at_spec.rb +0 -142
- data/spec/text_box_spec.rb +0 -1042
- data/spec/text_rendering_mode_spec.rb +0 -45
- data/spec/text_spacing_spec.rb +0 -93
- data/spec/text_spec.rb +0 -543
- data/spec/text_with_inline_formatting_spec.rb +0 -35
- data/spec/transparency_spec.rb +0 -91
- data/spec/view_spec.rb +0 -42
data/spec/soft_mask_spec.rb
DELETED
@@ -1,78 +0,0 @@
|
|
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
|
-
include SoftMaskHelper
|
25
|
-
|
26
|
-
it "should have PDF version at least 1.4" do
|
27
|
-
create_pdf
|
28
|
-
make_soft_mask
|
29
|
-
str = @pdf.render
|
30
|
-
expect(str[0, 8]).to eq("%PDF-1.4")
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should create a new extended graphics state for each unique soft mask" do
|
34
|
-
create_pdf
|
35
|
-
|
36
|
-
make_soft_mask do
|
37
|
-
@pdf.fill_color '808080'
|
38
|
-
@pdf.fill_rectangle [100, 100], 200, 200
|
39
|
-
end
|
40
|
-
|
41
|
-
make_soft_mask do
|
42
|
-
@pdf.fill_color '808080'
|
43
|
-
@pdf.fill_rectangle [10, 10], 200, 200
|
44
|
-
end
|
45
|
-
|
46
|
-
extgstates = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates
|
47
|
-
expect(extgstates.length).to eq(2)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "a new extended graphics state should contain soft mask with drawing instructions" do
|
51
|
-
create_pdf
|
52
|
-
|
53
|
-
make_soft_mask do
|
54
|
-
@pdf.fill_color '808080'
|
55
|
-
@pdf.fill_rectangle [100, 100], 200, 200
|
56
|
-
end
|
57
|
-
|
58
|
-
extgstate = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates.first
|
59
|
-
expect(extgstate[:soft_mask][:G].data).to eq("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")
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should not create duplicate extended graphics states" do
|
63
|
-
create_pdf
|
64
|
-
|
65
|
-
make_soft_mask do
|
66
|
-
@pdf.fill_color '808080'
|
67
|
-
@pdf.fill_rectangle [100, 100], 200, 200
|
68
|
-
end
|
69
|
-
|
70
|
-
make_soft_mask do
|
71
|
-
@pdf.fill_color '808080'
|
72
|
-
@pdf.fill_rectangle [100, 100], 200, 200
|
73
|
-
end
|
74
|
-
|
75
|
-
extgstates = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates
|
76
|
-
expect(extgstates.length).to eq(1)
|
77
|
-
end
|
78
|
-
end
|
data/spec/span_spec.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
-
|
5
|
-
describe "drawing span" do
|
6
|
-
before do
|
7
|
-
Prawn.debug = false
|
8
|
-
create_pdf
|
9
|
-
end
|
10
|
-
|
11
|
-
after do
|
12
|
-
Prawn.debug = true
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should only accept :position as option in debug mode" do
|
16
|
-
Prawn.debug = true
|
17
|
-
expect { @pdf.span(350, :x => 3) {} }.to raise_error(Prawn::Errors::UnknownOption)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should have raise an error if :position is invalid" do
|
21
|
-
expect { @pdf.span(350, :position => :x) {} }.to raise_error(ArgumentError)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should restore the margin box when bounding box exits" do
|
25
|
-
margin_box = @pdf.bounds
|
26
|
-
|
27
|
-
@pdf.span(350, :position => :center) do
|
28
|
-
@pdf.text "Here's some centered text in a 350 point column. " * 100
|
29
|
-
end
|
30
|
-
|
31
|
-
expect(@pdf.bounds).to eq(margin_box)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should do create a margin box" do
|
35
|
-
y = @pdf.y
|
36
|
-
margin_box = @pdf.span(350, :position => :center) do
|
37
|
-
@pdf.text "Here's some centered text in a 350 point column. " * 100
|
38
|
-
end
|
39
|
-
|
40
|
-
expect(margin_box.top).to eq(792.0)
|
41
|
-
expect(margin_box.bottom).to eq(0)
|
42
|
-
end
|
43
|
-
end
|
data/spec/stamp_spec.rb
DELETED
@@ -1,179 +0,0 @@
|
|
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
|
-
expect(@pdf.render).to match(/\/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
|
-
expect {
|
44
|
-
@pdf.create_stamp("MyStamp")
|
45
|
-
}.to 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
|
-
expect {
|
52
|
-
@pdf.create_stamp("")
|
53
|
-
}.to 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
|
-
expect(xobjects.length).to eq(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
|
-
expect {
|
73
|
-
@pdf.stamp("OtherStamp")
|
74
|
-
}.to 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
|
-
expect(@pdf.render).to match(/(\/Stamp1 Do.*?){3}/m)
|
88
|
-
end
|
89
|
-
|
90
|
-
it "stamp should render clickable links" do
|
91
|
-
create_pdf
|
92
|
-
@pdf.create_stamp 'bar' do
|
93
|
-
@pdf.text '<b>Prawn</b> <link href="http://github.com">GitHub</link>', inline_format: true
|
94
|
-
end
|
95
|
-
@pdf.stamp 'bar'
|
96
|
-
|
97
|
-
output = @pdf.render
|
98
|
-
objects = output.split("endobj")
|
99
|
-
|
100
|
-
objects.each do |obj|
|
101
|
-
if obj =~ /\/Type \/Page$/
|
102
|
-
# The page object must contain the annotation reference
|
103
|
-
# to render a clickable link
|
104
|
-
expect(obj).to match(/^\/Annots \[\d \d .\]$/)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
it "resources added during stamp creation should be added to the " \
|
110
|
-
"stamp XObject, not the page" do
|
111
|
-
create_pdf
|
112
|
-
@pdf.create_stamp("MyStamp") do
|
113
|
-
@pdf.transparent(0.5) { @pdf.circle([100, 100], 10) }
|
114
|
-
end
|
115
|
-
@pdf.stamp("MyStamp")
|
116
|
-
|
117
|
-
# Inspector::XObject does not give information about resources, so
|
118
|
-
# resorting to string matching
|
119
|
-
|
120
|
-
output = @pdf.render
|
121
|
-
objects = output.split("endobj")
|
122
|
-
objects.each do |object|
|
123
|
-
if object =~ /\/Type \/Page$/
|
124
|
-
expect(object).not_to match(/\/ExtGState/)
|
125
|
-
elsif object =~ /\/Type \/XObject$/
|
126
|
-
expect(object).to match(/\/ExtGState/)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
it "stamp stream should be wrapped in a graphic state" do
|
132
|
-
create_pdf
|
133
|
-
@pdf.create_stamp("MyStamp") do
|
134
|
-
@pdf.text "This should have a 'q' before it and a 'Q' after it"
|
135
|
-
end
|
136
|
-
@pdf.stamp("MyStamp")
|
137
|
-
stamps = PDF::Inspector::XObject.analyze(@pdf.render)
|
138
|
-
expect(stamps.xobject_streams[:Stamp1].data.chomp).to match(/q(.|\s)*Q\Z/)
|
139
|
-
end
|
140
|
-
|
141
|
-
it "should not add to the page graphic state stack " do
|
142
|
-
create_pdf
|
143
|
-
expect(@pdf.state.page.stack.stack.size).to eq(1)
|
144
|
-
|
145
|
-
@pdf.create_stamp("MyStamp") do
|
146
|
-
@pdf.save_graphics_state
|
147
|
-
@pdf.save_graphics_state
|
148
|
-
@pdf.save_graphics_state
|
149
|
-
@pdf.text "This should have a 'q' before it and a 'Q' after it"
|
150
|
-
@pdf.restore_graphics_state
|
151
|
-
end
|
152
|
-
expect(@pdf.state.page.stack.stack.size).to eq(1)
|
153
|
-
end
|
154
|
-
|
155
|
-
it "should be able to change fill and stroke colors within the stamp stream" do
|
156
|
-
create_pdf
|
157
|
-
@pdf.create_stamp("MyStamp") do
|
158
|
-
@pdf.fill_color(100, 100, 20, 0)
|
159
|
-
@pdf.stroke_color(100, 100, 20, 0)
|
160
|
-
end
|
161
|
-
@pdf.stamp("MyStamp")
|
162
|
-
stamps = PDF::Inspector::XObject.analyze(@pdf.render)
|
163
|
-
stamp_stream = stamps.xobject_streams[:Stamp1].data
|
164
|
-
expect(stamp_stream).to include("/DeviceCMYK cs\n1.000 1.000 0.200 0.000 scn")
|
165
|
-
expect(stamp_stream).to include("/DeviceCMYK CS\n1.000 1.000 0.200 0.000 SCN")
|
166
|
-
end
|
167
|
-
|
168
|
-
it "should save the color space even when same as current page color space" do
|
169
|
-
create_pdf
|
170
|
-
@pdf.stroke_color(100, 100, 20, 0)
|
171
|
-
@pdf.create_stamp("MyStamp") do
|
172
|
-
@pdf.stroke_color(100, 100, 20, 0)
|
173
|
-
end
|
174
|
-
@pdf.stamp("MyStamp")
|
175
|
-
stamps = PDF::Inspector::XObject.analyze(@pdf.render)
|
176
|
-
stamp_stream = stamps.xobject_streams[:Stamp1].data
|
177
|
-
expect(stamp_stream).to include("/DeviceCMYK CS\n1.000 1.000 0.200 0.000 SCN")
|
178
|
-
end
|
179
|
-
end
|
data/spec/stroke_styles_spec.rb
DELETED
@@ -1,208 +0,0 @@
|
|
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
|
-
expect(@pdf.cap_style).to eq(:butt)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "join_style should be :miter" do
|
12
|
-
expect(@pdf.join_style).to eq(:miter)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "dashed? should be_false" do
|
16
|
-
expect(@pdf).not_to 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
|
-
expect(@pdf.cap_style).to eq(: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
|
-
expect(cap_style).to eq(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
|
-
expect(cap_style).to eq(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
|
-
expect(cap_style).to eq(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
|
-
expect(cap_styles.cap_style_count).to eq(2)
|
57
|
-
expect(cap_styles.cap_style).to eq(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
|
-
expect(@pdf.join_style).to eq(: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
|
-
expect(join_style).to eq(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
|
-
expect(join_style).to eq(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
|
-
expect(join_style).to eq(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
|
-
expect(join_styles.join_style_count).to eq(2)
|
98
|
-
expect(join_styles.join_style).to eq(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
|
-
expect(@pdf).to be_dashed
|
108
|
-
end
|
109
|
-
|
110
|
-
describe "setting a dash" do
|
111
|
-
it "dashed? should be_true" do
|
112
|
-
@pdf.dash(2)
|
113
|
-
expect(@pdf).to 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
|
-
expect(dashes.stroke_dash).to eq([[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
|
-
expect(dashes.stroke_dash).to eq([[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
|
-
expect(dashes.stroke_dash).to eq([[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
|
-
expect(dashes.stroke_dash).to eq([[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
|
-
expect(dashes.stroke_dash).to eq([[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
|
-
expect(dashes.stroke_dash).to eq([[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
|
-
expect(dashes.stroke_dash).to eq([[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
|
-
expect(dashes.stroke_dash).to eq([[], 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
|
-
expect(dashes.stroke_dash_count).to eq(2)
|
178
|
-
expect(dashes.stroke_dash).to eq([[2, 2], 0])
|
179
|
-
end
|
180
|
-
|
181
|
-
describe "#dashed?" do
|
182
|
-
it "an initial document should not be dashed" do
|
183
|
-
expect(@pdf.dashed?).to eq(false)
|
184
|
-
end
|
185
|
-
|
186
|
-
it "should return true if any of the currently active settings are dashed" do
|
187
|
-
@pdf.dash(2)
|
188
|
-
@pdf.save_graphics_state
|
189
|
-
expect(@pdf.dashed?).to eq(true)
|
190
|
-
end
|
191
|
-
|
192
|
-
it "should return false if the document was most recently undashed" do
|
193
|
-
@pdf.dash(2)
|
194
|
-
@pdf.save_graphics_state
|
195
|
-
@pdf.undash
|
196
|
-
@pdf.save_graphics_state
|
197
|
-
expect(@pdf.dashed?).to eq(false)
|
198
|
-
end
|
199
|
-
|
200
|
-
it "should return true when restoring to a state that was dashed" do
|
201
|
-
@pdf.dash(2)
|
202
|
-
@pdf.save_graphics_state
|
203
|
-
@pdf.undash
|
204
|
-
@pdf.restore_graphics_state
|
205
|
-
expect(@pdf.dashed?).to eq(true)
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|