nurettin-prawn 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +2 -0
- data/GPLv2 +340 -0
- data/GPLv3 +674 -0
- data/Gemfile +18 -0
- data/LICENSE +56 -0
- data/README.md +98 -0
- data/Rakefile +45 -0
- data/data/encodings/win_ansi.txt +29 -0
- data/data/fonts/Action Man.dfont +0 -0
- data/data/fonts/Activa.ttf +0 -0
- data/data/fonts/Chalkboard.ttf +0 -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/DejaVuSans.ttf +0 -0
- data/data/fonts/Dustismo_Roman.ttf +0 -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/fonts/comicsans.ttf +0 -0
- data/data/fonts/gkai00mp.ttf +0 -0
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.dat +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/barcode_issue.png +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.dat +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/letterhead.jpg +0 -0
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.dat +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/rails.dat +0 -0
- data/data/images/rails.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 +29 -0
- data/lib/prawn/compatibility.rb +87 -0
- data/lib/prawn/core.rb +87 -0
- data/lib/prawn/core/annotations.rb +61 -0
- data/lib/prawn/core/byte_string.rb +9 -0
- data/lib/prawn/core/destinations.rb +90 -0
- data/lib/prawn/core/document_state.rb +79 -0
- data/lib/prawn/core/literal_string.rb +16 -0
- data/lib/prawn/core/name_tree.rb +177 -0
- data/lib/prawn/core/object_store.rb +320 -0
- data/lib/prawn/core/page.rb +212 -0
- data/lib/prawn/core/pdf_object.rb +125 -0
- data/lib/prawn/core/reference.rb +119 -0
- data/lib/prawn/core/text.rb +268 -0
- data/lib/prawn/core/text/formatted/arranger.rb +294 -0
- data/lib/prawn/core/text/formatted/line_wrap.rb +288 -0
- data/lib/prawn/core/text/formatted/wrap.rb +153 -0
- data/lib/prawn/document.rb +707 -0
- data/lib/prawn/document/bounding_box.rb +510 -0
- data/lib/prawn/document/column_box.rb +132 -0
- data/lib/prawn/document/graphics_state.rb +136 -0
- data/lib/prawn/document/internals.rb +173 -0
- data/lib/prawn/document/page_geometry.rb +136 -0
- data/lib/prawn/document/snapshot.rb +89 -0
- data/lib/prawn/document/span.rb +55 -0
- data/lib/prawn/encoding.rb +121 -0
- data/lib/prawn/errors.rb +99 -0
- data/lib/prawn/font.rb +386 -0
- data/lib/prawn/font/afm.rb +203 -0
- data/lib/prawn/font/dfont.rb +42 -0
- data/lib/prawn/font/ttf.rb +343 -0
- data/lib/prawn/graphics.rb +523 -0
- data/lib/prawn/graphics/cap_style.rb +46 -0
- data/lib/prawn/graphics/color.rb +231 -0
- data/lib/prawn/graphics/dash.rb +82 -0
- data/lib/prawn/graphics/join_style.rb +47 -0
- data/lib/prawn/graphics/patterns.rb +137 -0
- data/lib/prawn/graphics/transformation.rb +156 -0
- data/lib/prawn/graphics/transparency.rb +99 -0
- data/lib/prawn/images.rb +196 -0
- data/lib/prawn/images/image.rb +65 -0
- data/lib/prawn/images/jpg.rb +85 -0
- data/lib/prawn/images/png.rb +362 -0
- data/lib/prawn/layout.rb +20 -0
- data/lib/prawn/layout/grid.rb +259 -0
- data/lib/prawn/measurement_extensions.rb +46 -0
- data/lib/prawn/measurements.rb +71 -0
- data/lib/prawn/outline.rb +326 -0
- data/lib/prawn/repeater.rb +122 -0
- data/lib/prawn/security.rb +269 -0
- data/lib/prawn/soft_mask.rb +94 -0
- data/lib/prawn/stamp.rb +134 -0
- data/lib/prawn/table.rb +609 -0
- data/lib/prawn/table/cell.rb +776 -0
- data/lib/prawn/table/cell/image.rb +70 -0
- data/lib/prawn/table/cell/in_table.rb +27 -0
- data/lib/prawn/table/cell/span_dummy.rb +88 -0
- data/lib/prawn/table/cell/subtable.rb +65 -0
- data/lib/prawn/table/cell/text.rb +152 -0
- data/lib/prawn/table/cells.rb +260 -0
- data/lib/prawn/text.rb +420 -0
- data/lib/prawn/text/box.rb +141 -0
- data/lib/prawn/text/formatted.rb +4 -0
- data/lib/prawn/text/formatted/box.rb +563 -0
- data/lib/prawn/text/formatted/fragment.rb +253 -0
- data/lib/prawn/text/formatted/parser.rb +217 -0
- data/lib/prawn/utilities.rb +44 -0
- data/manual/basic_concepts/adding_pages.rb +27 -0
- data/manual/basic_concepts/basic_concepts.rb +34 -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/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/document_and_page_options/background.rb +27 -0
- data/manual/document_and_page_options/document_and_page_options.rb +31 -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/example_file.rb +116 -0
- data/manual/example_helper.rb +430 -0
- data/manual/example_package.rb +53 -0
- data/manual/example_section.rb +46 -0
- data/manual/graphics/circle_and_ellipse.rb +22 -0
- data/manual/graphics/color.rb +24 -0
- data/manual/graphics/common_lines.rb +28 -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 +17 -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 +43 -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/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/manual/cover.rb +26 -0
- data/manual/manual/foreword.rb +13 -0
- data/manual/manual/how_to_read_this_manual.rb +41 -0
- data/manual/manual/manual.rb +36 -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/page_numbering.rb +54 -0
- data/manual/repeatable_content/repeatable_content.rb +31 -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/syntax_highlight.rb +52 -0
- data/manual/table/basic_block.rb +53 -0
- data/manual/table/before_rendering_page.rb +26 -0
- data/manual/table/cell_border_lines.rb +24 -0
- data/manual/table/cell_borders_and_bg.rb +31 -0
- data/manual/table/cell_dimensions.rb +30 -0
- data/manual/table/cell_text.rb +38 -0
- data/manual/table/column_widths.rb +30 -0
- data/manual/table/content_and_subtables.rb +39 -0
- data/manual/table/creation.rb +27 -0
- data/manual/table/filtering.rb +36 -0
- data/manual/table/flow_and_header.rb +17 -0
- data/manual/table/image_cells.rb +33 -0
- data/manual/table/position.rb +29 -0
- data/manual/table/row_colors.rb +20 -0
- data/manual/table/span.rb +30 -0
- data/manual/table/style.rb +22 -0
- data/manual/table/table.rb +52 -0
- data/manual/table/width.rb +27 -0
- data/manual/templates/full_template.rb +23 -0
- data/manual/templates/page_template.rb +47 -0
- data/manual/templates/templates.rb +26 -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/group.rb +29 -0
- data/manual/text/inline.rb +43 -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 +26 -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 +43 -0
- data/manual/text/rotation.rb +43 -0
- data/manual/text/single_usage.rb +37 -0
- data/manual/text/text.rb +75 -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 +44 -0
- data/manual/text/utf8.rb +28 -0
- data/manual/text/win_ansi_charset.rb +59 -0
- data/prawn.gemspec +46 -0
- data/spec/annotations_spec.rb +90 -0
- data/spec/bounding_box_spec.rb +493 -0
- data/spec/cell_spec.rb +584 -0
- data/spec/column_box_spec.rb +33 -0
- data/spec/data/curves.pdf +66 -0
- data/spec/destinations_spec.rb +15 -0
- data/spec/document_spec.rb +736 -0
- data/spec/extensions/encoding_helpers.rb +6 -0
- data/spec/extensions/mocha.rb +44 -0
- data/spec/font_spec.rb +433 -0
- data/spec/formatted_text_arranger_spec.rb +421 -0
- data/spec/formatted_text_box_spec.rb +640 -0
- data/spec/formatted_text_fragment_spec.rb +298 -0
- data/spec/graphics_spec.rb +651 -0
- data/spec/grid_spec.rb +85 -0
- data/spec/images_spec.rb +140 -0
- data/spec/inline_formatted_text_parser_spec.rb +515 -0
- data/spec/jpg_spec.rb +25 -0
- data/spec/line_wrap_spec.rb +333 -0
- data/spec/measurement_units_spec.rb +23 -0
- data/spec/name_tree_spec.rb +112 -0
- data/spec/object_store_spec.rb +170 -0
- data/spec/outline_spec.rb +426 -0
- data/spec/pdf_object_spec.rb +172 -0
- data/spec/png_spec.rb +240 -0
- data/spec/reference_spec.rb +105 -0
- data/spec/repeater_spec.rb +158 -0
- data/spec/security_spec.rb +126 -0
- data/spec/snapshot_spec.rb +186 -0
- data/spec/soft_mask_spec.rb +117 -0
- data/spec/span_spec.rb +49 -0
- data/spec/spec_helper.rb +36 -0
- data/spec/stamp_spec.rb +159 -0
- data/spec/stroke_styles_spec.rb +193 -0
- data/spec/table_spec.rb +1209 -0
- data/spec/template_spec.rb +351 -0
- data/spec/text_at_spec.rb +129 -0
- data/spec/text_box_spec.rb +1029 -0
- data/spec/text_rendering_mode_spec.rb +45 -0
- data/spec/text_spacing_spec.rb +93 -0
- data/spec/text_spec.rb +421 -0
- data/spec/text_with_inline_formatting_spec.rb +35 -0
- data/spec/transparency_spec.rb +89 -0
- metadata +544 -0
data/spec/cell_spec.rb
ADDED
@@ -0,0 +1,584 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
|
5
|
+
module CellHelpers
|
6
|
+
|
7
|
+
# Build, but do not draw, a cell on @pdf.
|
8
|
+
def cell(options={})
|
9
|
+
at = options[:at] || [0, @pdf.cursor]
|
10
|
+
Prawn::Table::Cell::Text.new(@pdf, at, options)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "Prawn::Table::Cell" do
|
16
|
+
before(:each) do
|
17
|
+
@pdf = Prawn::Document.new
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "Prawn::Document#cell" do
|
21
|
+
include CellHelpers
|
22
|
+
|
23
|
+
it "should draw the cell" do
|
24
|
+
Prawn::Table::Cell::Text.any_instance.expects(:draw).once
|
25
|
+
@pdf.cell(:content => "text")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return a Cell" do
|
29
|
+
@pdf.cell(:content => "text").should be_a_kind_of Prawn::Table::Cell
|
30
|
+
end
|
31
|
+
|
32
|
+
it "accepts :content => nil in a hash" do
|
33
|
+
@pdf.cell(:content => nil).should be_a_kind_of(Prawn::Table::Cell::Text)
|
34
|
+
@pdf.make_cell(:content => nil).should be_a_kind_of(Prawn::Table::Cell::Text)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should convert nil, Numeric, and Date values to strings" do
|
38
|
+
[nil, 123, 123.45, Date.today].each do |value|
|
39
|
+
c = @pdf.cell(:content => value)
|
40
|
+
c.should be_a_kind_of Prawn::Table::Cell::Text
|
41
|
+
c.content.should == value.to_s
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should allow inline styling with a hash argument" do
|
46
|
+
# used for table([[{:text => "...", :font_style => :bold, ...}, ...]])
|
47
|
+
c = Prawn::Table::Cell.make(@pdf,
|
48
|
+
{:content => 'hello', :font_style => :bold})
|
49
|
+
c.should be_a_kind_of Prawn::Table::Cell::Text
|
50
|
+
c.content.should == "hello"
|
51
|
+
c.font.name.should == 'Helvetica-Bold'
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should draw text at the given point plus padding, with the given " +
|
55
|
+
"size and style" do
|
56
|
+
@pdf.expects(:bounding_box).yields
|
57
|
+
@pdf.expects(:move_down)
|
58
|
+
@pdf.expects(:draw_text!).with { |text, options| text == "hello world" }
|
59
|
+
|
60
|
+
@pdf.cell(:content => "hello world",
|
61
|
+
:at => [10, 20],
|
62
|
+
:padding => [30, 40],
|
63
|
+
:size => 7,
|
64
|
+
:font_style => :bold)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "Prawn::Document#make_cell" do
|
69
|
+
it "should not draw the cell" do
|
70
|
+
Prawn::Table::Cell::Text.any_instance.expects(:draw).never
|
71
|
+
@pdf.make_cell("text")
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should return a Cell" do
|
75
|
+
@pdf.make_cell("text", :size => 7).should be_a_kind_of Prawn::Table::Cell
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "#style" do
|
80
|
+
include CellHelpers
|
81
|
+
|
82
|
+
it "should set each property in turn" do
|
83
|
+
c = cell(:content => "text")
|
84
|
+
|
85
|
+
c.expects(:padding=).with(50)
|
86
|
+
c.expects(:size=).with(7)
|
87
|
+
|
88
|
+
c.style(:padding => 50, :size => 7)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "cell width" do
|
93
|
+
include CellHelpers
|
94
|
+
|
95
|
+
it "should be calculated for text" do
|
96
|
+
c = cell(:content => "text")
|
97
|
+
c.width.should == @pdf.width_of("text") + c.padding[1] + c.padding[3]
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should be overridden by manual :width" do
|
101
|
+
c = cell(:content => "text", :width => 400)
|
102
|
+
c.width.should == 400
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should incorporate padding when specified" do
|
106
|
+
c = cell(:content => "text", :padding => [1, 2, 3, 4])
|
107
|
+
c.width.should be_within(0.01).of(@pdf.width_of("text") + 6)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should allow width to be reset after it has been calculated" do
|
111
|
+
# to ensure that if we memoize width, it can still be overridden
|
112
|
+
c = cell(:content => "text")
|
113
|
+
c.width
|
114
|
+
c.width = 400
|
115
|
+
c.width.should == 400
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should return proper width with size set" do
|
119
|
+
text = "text " * 4
|
120
|
+
c = cell(:content => text, :size => 7)
|
121
|
+
c.width.should ==
|
122
|
+
@pdf.width_of(text, :size => 7) + c.padding[1] + c.padding[3]
|
123
|
+
end
|
124
|
+
|
125
|
+
it "content_width should exclude padding" do
|
126
|
+
c = cell(:content => "text", :padding => 10)
|
127
|
+
c.content_width.should == @pdf.width_of("text")
|
128
|
+
end
|
129
|
+
|
130
|
+
it "content_width should exclude padding even with manual :width" do
|
131
|
+
c = cell(:content => "text", :padding => 10, :width => 400)
|
132
|
+
c.content_width.should be_within(0.01).of(380)
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should have a reasonable minimum width that can fit @content" do
|
136
|
+
c = cell(:content => "text", :padding => 10)
|
137
|
+
min_content_width = c.min_width - c.padding[1] - c.padding[3]
|
138
|
+
|
139
|
+
lambda { @pdf.height_of("text", :width => min_content_width) }.
|
140
|
+
should_not raise_error(Prawn::Errors::CannotFit)
|
141
|
+
|
142
|
+
@pdf.height_of("text", :width => min_content_width).should be <
|
143
|
+
(5 * @pdf.height_of("text"))
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should defer min_width's evaluation of padding" do
|
147
|
+
c = cell(:content => "text", :padding => 100)
|
148
|
+
c.padding = 0
|
149
|
+
|
150
|
+
# Make sure we use the new value of padding in calculating min_width
|
151
|
+
c.min_width.should be < 100
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should defer min_width's evaluation of size" do
|
155
|
+
c = cell(:content => "text", :size => 50)
|
156
|
+
c.size = 8
|
157
|
+
c.padding = 0
|
158
|
+
c.min_width.should be < 10
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
describe "cell height" do
|
164
|
+
include CellHelpers
|
165
|
+
|
166
|
+
it "should be calculated for text" do
|
167
|
+
c = cell(:content => "text")
|
168
|
+
c.height.should ==
|
169
|
+
@pdf.height_of("text", :width => @pdf.width_of("text")) +
|
170
|
+
c.padding[0] + c.padding[3]
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should be overridden by manual :height" do
|
174
|
+
c = cell(:content => "text", :height => 400)
|
175
|
+
c.height.should == 400
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should incorporate :padding when specified" do
|
179
|
+
c = cell(:content => "text", :padding => [1, 2, 3, 4])
|
180
|
+
c.height.should be_within(0.01).of(1 + 3 +
|
181
|
+
@pdf.height_of("text", :width => @pdf.width_of("text")))
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should allow height to be reset after it has been calculated" do
|
185
|
+
# to ensure that if we memoize height, it can still be overridden
|
186
|
+
c = cell(:content => "text")
|
187
|
+
c.height
|
188
|
+
c.height = 400
|
189
|
+
c.height.should == 400
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should return proper height for blocks of text" do
|
193
|
+
content = "words " * 10
|
194
|
+
c = cell(:content => content, :width => 100)
|
195
|
+
c.height.should == @pdf.height_of(content, :width => 100) +
|
196
|
+
c.padding[0] + c.padding[2]
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should return proper height for blocks of text with size set" do
|
200
|
+
content = "words " * 10
|
201
|
+
c = cell(:content => content, :width => 100, :size => 7)
|
202
|
+
|
203
|
+
correct_content_height = nil
|
204
|
+
@pdf.font_size(7) do
|
205
|
+
correct_content_height = @pdf.height_of(content, :width => 100)
|
206
|
+
end
|
207
|
+
|
208
|
+
c.height.should == correct_content_height + c.padding[0] + c.padding[2]
|
209
|
+
end
|
210
|
+
|
211
|
+
it "content_height should exclude padding" do
|
212
|
+
c = cell(:content => "text", :padding => 10)
|
213
|
+
c.content_height.should == @pdf.height_of("text")
|
214
|
+
end
|
215
|
+
|
216
|
+
it "content_height should exclude padding even with manual :height" do
|
217
|
+
c = cell(:content => "text", :padding => 10, :height => 400)
|
218
|
+
c.content_height.should be_within(0.01).of(380)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
describe "cell padding" do
|
223
|
+
include CellHelpers
|
224
|
+
|
225
|
+
it "should default to zero" do
|
226
|
+
c = cell(:content => "text")
|
227
|
+
c.padding.should == [5, 5, 5, 5]
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should accept a numeric value, setting all padding" do
|
231
|
+
c = cell(:content => "text", :padding => 10)
|
232
|
+
c.padding.should == [10, 10, 10, 10]
|
233
|
+
end
|
234
|
+
|
235
|
+
it "should accept [v,h]" do
|
236
|
+
c = cell(:content => "text", :padding => [20, 30])
|
237
|
+
c.padding.should == [20, 30, 20, 30]
|
238
|
+
end
|
239
|
+
|
240
|
+
it "should accept [t,h,b]" do
|
241
|
+
c = cell(:content => "text", :padding => [10, 20, 30])
|
242
|
+
c.padding.should == [10, 20, 30, 20]
|
243
|
+
end
|
244
|
+
|
245
|
+
it "should accept [t,l,b,r]" do
|
246
|
+
c = cell(:content => "text", :padding => [10, 20, 30, 40])
|
247
|
+
c.padding.should == [10, 20, 30, 40]
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should reject other formats" do
|
251
|
+
lambda{
|
252
|
+
cell(:content => "text", :padding => [10])
|
253
|
+
}.should raise_error(ArgumentError)
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
describe "background_color" do
|
258
|
+
include CellHelpers
|
259
|
+
|
260
|
+
it "should fill a rectangle with the given background color" do
|
261
|
+
@pdf.stubs(:mask).yields
|
262
|
+
@pdf.expects(:mask).with(:fill_color).yields
|
263
|
+
|
264
|
+
@pdf.stubs(:fill_color)
|
265
|
+
@pdf.expects(:fill_color).with('123456')
|
266
|
+
@pdf.expects(:fill_rectangle).checking do |(x, y), w, h|
|
267
|
+
x.should be_within(0.01).of(0)
|
268
|
+
y.should be_within(0.01).of(@pdf.cursor)
|
269
|
+
w.should be_within(0.01).of(29.344)
|
270
|
+
h.should be_within(0.01).of(23.872)
|
271
|
+
end
|
272
|
+
@pdf.cell(:content => "text", :background_color => '123456')
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should draw the background in the right place if cell is drawn at a " +
|
276
|
+
"different location" do
|
277
|
+
@pdf.stubs(:mask).yields
|
278
|
+
@pdf.expects(:mask).with(:fill_color).yields
|
279
|
+
|
280
|
+
@pdf.stubs(:fill_color)
|
281
|
+
@pdf.expects(:fill_color).with('123456')
|
282
|
+
@pdf.expects(:fill_rectangle).checking do |(x, y), w, h|
|
283
|
+
x.should be_within(0.01).of(12.0)
|
284
|
+
y.should be_within(0.01).of(34.0)
|
285
|
+
w.should be_within(0.01).of(29.344)
|
286
|
+
h.should be_within(0.01).of(23.872)
|
287
|
+
end
|
288
|
+
c = @pdf.make_cell(:content => "text", :background_color => '123456')
|
289
|
+
c.draw([12.0, 34.0])
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
describe "color" do
|
294
|
+
it "should set fill color when :text_color is provided" do
|
295
|
+
pdf = Prawn::Document.new
|
296
|
+
pdf.stubs(:fill_color)
|
297
|
+
pdf.expects(:fill_color).with('555555')
|
298
|
+
pdf.cell :content => 'foo', :text_color => '555555'
|
299
|
+
end
|
300
|
+
|
301
|
+
it "should reset the fill color to the original one" do
|
302
|
+
pdf = Prawn::Document.new
|
303
|
+
pdf.fill_color = '333333'
|
304
|
+
pdf.cell :content => 'foo', :text_color => '555555'
|
305
|
+
pdf.fill_color.should == '333333'
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
describe "Borders" do
|
310
|
+
it "should draw all borders by default" do
|
311
|
+
@pdf.expects(:stroke_line).times(4)
|
312
|
+
@pdf.cell(:content => "text")
|
313
|
+
end
|
314
|
+
|
315
|
+
it "should draw all borders when requested" do
|
316
|
+
@pdf.expects(:stroke_line).times(4)
|
317
|
+
@pdf.cell(:content => "text", :borders => [:top, :right, :bottom, :left])
|
318
|
+
end
|
319
|
+
|
320
|
+
# Only roughly verifying the integer coordinates so that we don't have to
|
321
|
+
# do any FP closeness arithmetic. Can plug in that math later if this goes
|
322
|
+
# wrong.
|
323
|
+
it "should draw top border when requested" do
|
324
|
+
@pdf.expects(:stroke_line).checking do |from, to|
|
325
|
+
@pdf.map_to_absolute(from).map{|x| x.round}.should == [36, 756]
|
326
|
+
@pdf.map_to_absolute(to).map{|x| x.round}.should == [65, 756]
|
327
|
+
end
|
328
|
+
@pdf.cell(:content => "text", :borders => [:top])
|
329
|
+
end
|
330
|
+
|
331
|
+
it "should draw bottom border when requested" do
|
332
|
+
@pdf.expects(:stroke_line).checking do |from, to|
|
333
|
+
@pdf.map_to_absolute(from).map{|x| x.round}.should == [36, 732]
|
334
|
+
@pdf.map_to_absolute(to).map{|x| x.round}.should == [65, 732]
|
335
|
+
end
|
336
|
+
@pdf.cell(:content => "text", :borders => [:bottom])
|
337
|
+
end
|
338
|
+
|
339
|
+
it "should draw left border when requested" do
|
340
|
+
@pdf.expects(:stroke_line).checking do |from, to|
|
341
|
+
@pdf.map_to_absolute(from).map{|x| x.round}.should == [36, 756]
|
342
|
+
@pdf.map_to_absolute(to).map{|x| x.round}.should == [36, 732]
|
343
|
+
end
|
344
|
+
@pdf.cell(:content => "text", :borders => [:left])
|
345
|
+
end
|
346
|
+
|
347
|
+
it "should draw right border when requested" do
|
348
|
+
@pdf.expects(:stroke_line).checking do |from, to|
|
349
|
+
@pdf.map_to_absolute(from).map{|x| x.round}.should == [65, 756]
|
350
|
+
@pdf.map_to_absolute(to).map{|x| x.round}.should == [65, 732]
|
351
|
+
end
|
352
|
+
@pdf.cell(:content => "text", :borders => [:right])
|
353
|
+
end
|
354
|
+
|
355
|
+
it "should draw borders at the same location when in or out of bbox" do
|
356
|
+
@pdf.expects(:stroke_line).checking do |from, to|
|
357
|
+
@pdf.map_to_absolute(from).map{|x| x.round}.should == [36, 756]
|
358
|
+
@pdf.map_to_absolute(to).map{|x| x.round}.should == [65, 756]
|
359
|
+
end
|
360
|
+
@pdf.bounding_box([0, @pdf.cursor], :width => @pdf.bounds.width) do
|
361
|
+
@pdf.cell(:content => "text", :borders => [:top])
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
it "should set border color with :border_..._color" do
|
366
|
+
@pdf.ignores(:stroke_color=).with("000000")
|
367
|
+
@pdf.expects(:stroke_color=).with("ff0000")
|
368
|
+
|
369
|
+
c = @pdf.cell(:content => "text", :border_top_color => "ff0000")
|
370
|
+
c.border_top_color.should == "ff0000"
|
371
|
+
c.border_colors[0].should == "ff0000"
|
372
|
+
end
|
373
|
+
|
374
|
+
it "should set border colors with :border_color" do
|
375
|
+
@pdf.ignores(:stroke_color=).with("000000")
|
376
|
+
@pdf.expects(:stroke_color=).with("ff0000")
|
377
|
+
@pdf.expects(:stroke_color=).with("00ff00")
|
378
|
+
@pdf.expects(:stroke_color=).with("0000ff")
|
379
|
+
@pdf.expects(:stroke_color=).with("ff00ff")
|
380
|
+
|
381
|
+
c = @pdf.cell(:content => "text",
|
382
|
+
:border_color => %w[ff0000 00ff00 0000ff ff00ff])
|
383
|
+
|
384
|
+
c.border_colors.should == %w[ff0000 00ff00 0000ff ff00ff]
|
385
|
+
end
|
386
|
+
|
387
|
+
it "border_..._width should return 0 if border not selected" do
|
388
|
+
c = @pdf.cell(:content => "text", :borders => [:top])
|
389
|
+
c.border_bottom_width.should == 0
|
390
|
+
end
|
391
|
+
|
392
|
+
it "should set border width with :border_..._width" do
|
393
|
+
@pdf.ignores(:line_width=).with(1)
|
394
|
+
@pdf.expects(:line_width=).with(2)
|
395
|
+
|
396
|
+
c = @pdf.cell(:content => "text", :border_bottom_width => 2)
|
397
|
+
c.border_bottom_width.should == 2
|
398
|
+
c.border_widths[2].should == 2
|
399
|
+
end
|
400
|
+
|
401
|
+
it "should set border widths with :border_width" do
|
402
|
+
@pdf.ignores(:line_width=).with(1)
|
403
|
+
@pdf.expects(:line_width=).with(2)
|
404
|
+
@pdf.expects(:line_width=).with(3)
|
405
|
+
@pdf.expects(:line_width=).with(4)
|
406
|
+
@pdf.expects(:line_width=).with(5)
|
407
|
+
|
408
|
+
c = @pdf.cell(:content => "text",
|
409
|
+
:border_width => [2, 3, 4, 5])
|
410
|
+
c.border_widths.should == [2, 3, 4, 5]
|
411
|
+
end
|
412
|
+
|
413
|
+
it "should set default border lines to :solid" do
|
414
|
+
c = @pdf.cell(:content => "text")
|
415
|
+
c.border_top_line.should == :solid
|
416
|
+
c.border_right_line.should == :solid
|
417
|
+
c.border_bottom_line.should == :solid
|
418
|
+
c.border_left_line.should == :solid
|
419
|
+
c.border_lines.should == [:solid] * 4
|
420
|
+
end
|
421
|
+
|
422
|
+
it "should set border line with :border_..._line" do
|
423
|
+
c = @pdf.cell(:content => "text", :border_bottom_line => :dotted)
|
424
|
+
c.border_bottom_line.should == :dotted
|
425
|
+
c.border_lines[2].should == :dotted
|
426
|
+
end
|
427
|
+
|
428
|
+
it "should set border lines with :border_lines" do
|
429
|
+
c = @pdf.cell(:content => "text",
|
430
|
+
:border_lines => [:solid, :dotted, :dashed, :solid])
|
431
|
+
c.border_lines.should == [:solid, :dotted, :dashed, :solid]
|
432
|
+
end
|
433
|
+
end
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
|
440
|
+
describe "Text cell attributes" do
|
441
|
+
include CellHelpers
|
442
|
+
|
443
|
+
it "should pass through text options like :align to Text::Box" do
|
444
|
+
c = cell(:content => "text", :align => :right)
|
445
|
+
|
446
|
+
box = Prawn::Text::Box.new("text", :document => @pdf)
|
447
|
+
|
448
|
+
Prawn::Text::Box.expects(:new).checking do |text, options|
|
449
|
+
text.should == "text"
|
450
|
+
options[:align].should == :right
|
451
|
+
end.at_least_once.returns(box)
|
452
|
+
|
453
|
+
c.draw
|
454
|
+
end
|
455
|
+
|
456
|
+
it "should use font_style for Text::Box#style" do
|
457
|
+
c = cell(:content => "text", :font_style => :bold)
|
458
|
+
|
459
|
+
box = Prawn::Text::Box.new("text", :document => @pdf)
|
460
|
+
|
461
|
+
Prawn::Text::Box.expects(:new).checking do |text, options|
|
462
|
+
text.should == "text"
|
463
|
+
options[:style].should == :bold
|
464
|
+
end.at_least_once.returns(box)
|
465
|
+
|
466
|
+
c.draw
|
467
|
+
end
|
468
|
+
|
469
|
+
it "should allow inline formatting in cells" do
|
470
|
+
c = cell(:content => "foo <b>bar</b> baz", :inline_format => true)
|
471
|
+
|
472
|
+
box = Prawn::Text::Formatted::Box.new([], :document => @pdf)
|
473
|
+
|
474
|
+
Prawn::Text::Formatted::Box.expects(:new).checking do |array, options|
|
475
|
+
array[0][:text].should == "foo "
|
476
|
+
array[0][:styles].should == []
|
477
|
+
|
478
|
+
array[1][:text].should == "bar"
|
479
|
+
array[1][:styles].should == [:bold]
|
480
|
+
|
481
|
+
array[2][:text].should == " baz"
|
482
|
+
array[2][:styles].should == []
|
483
|
+
end.at_least_once.returns(box)
|
484
|
+
|
485
|
+
c.draw
|
486
|
+
end
|
487
|
+
|
488
|
+
end
|
489
|
+
|
490
|
+
describe "Font handling" do
|
491
|
+
include CellHelpers
|
492
|
+
|
493
|
+
it "should allow only :font_style to be specified, defaulting to the " +
|
494
|
+
"document's font" do
|
495
|
+
c = cell(:content => "text", :font_style => :bold)
|
496
|
+
c.font.name.should == 'Helvetica-Bold'
|
497
|
+
end
|
498
|
+
|
499
|
+
it "should accept a font name for :font" do
|
500
|
+
c = cell(:content => "text", :font => 'Helvetica-Bold')
|
501
|
+
c.font.name.should == 'Helvetica-Bold'
|
502
|
+
end
|
503
|
+
|
504
|
+
it "should allow style to be changed after initialize" do
|
505
|
+
c = cell(:content => "text")
|
506
|
+
c.font_style = :bold
|
507
|
+
c.font.name.should == 'Helvetica-Bold'
|
508
|
+
end
|
509
|
+
|
510
|
+
it "should default to the document's font, if none is specified" do
|
511
|
+
c = cell(:content => "text")
|
512
|
+
c.font.should == @pdf.font
|
513
|
+
end
|
514
|
+
|
515
|
+
it "should use the metrics of the selected font (even if it is a variant " +
|
516
|
+
"of the document's font) to calculate width" do
|
517
|
+
c = cell(:content => "text", :font_style => :bold)
|
518
|
+
font = @pdf.find_font('Helvetica-Bold')
|
519
|
+
c.content_width.should == font.compute_width_of("text")
|
520
|
+
end
|
521
|
+
|
522
|
+
it "should properly calculate inline-formatted text" do
|
523
|
+
c = cell(:content => "<b>text</b>", :inline_format => true)
|
524
|
+
font = @pdf.find_font('Helvetica-Bold')
|
525
|
+
c.content_width.should == font.compute_width_of("text")
|
526
|
+
end
|
527
|
+
end
|
528
|
+
end
|
529
|
+
|
530
|
+
describe "Image cells" do
|
531
|
+
before(:each) do
|
532
|
+
create_pdf
|
533
|
+
end
|
534
|
+
|
535
|
+
describe "with default options" do
|
536
|
+
before(:each) do
|
537
|
+
@cell = Prawn::Table::Cell.make(@pdf,
|
538
|
+
:image => "#{Prawn::DATADIR}/images/prawn.png")
|
539
|
+
end
|
540
|
+
|
541
|
+
it "should create a Cell::Image" do
|
542
|
+
@cell.should be_a_kind_of(Prawn::Table::Cell::Image)
|
543
|
+
end
|
544
|
+
|
545
|
+
it "should pull the natural width and height from the image" do
|
546
|
+
@cell.natural_content_width.should == 141
|
547
|
+
@cell.natural_content_height.should == 142
|
548
|
+
end
|
549
|
+
end
|
550
|
+
|
551
|
+
describe "hash syntax" do
|
552
|
+
before(:each) do
|
553
|
+
@table = @pdf.make_table([[{
|
554
|
+
:image => "#{Prawn::DATADIR}/images/prawn.png",
|
555
|
+
:scale => 2,
|
556
|
+
:fit => [100, 200],
|
557
|
+
:image_width => 123,
|
558
|
+
:image_height => 456,
|
559
|
+
:position => :center,
|
560
|
+
:vposition => :center
|
561
|
+
}]])
|
562
|
+
@cell = @table.cells[0, 0]
|
563
|
+
end
|
564
|
+
|
565
|
+
|
566
|
+
it "should create a Cell::Image" do
|
567
|
+
@cell.should be_a_kind_of(Prawn::Table::Cell::Image)
|
568
|
+
end
|
569
|
+
|
570
|
+
it "should pass through image options" do
|
571
|
+
@pdf.expects(:embed_image).checking do |_, _, options|
|
572
|
+
options[:scale].should == 2
|
573
|
+
options[:fit].should == [100, 200]
|
574
|
+
options[:width].should == 123
|
575
|
+
options[:height].should == 456
|
576
|
+
options[:position].should == :center
|
577
|
+
options[:vposition].should == :center
|
578
|
+
end
|
579
|
+
|
580
|
+
@table.draw
|
581
|
+
end
|
582
|
+
end
|
583
|
+
|
584
|
+
end
|