prawn 2.0.2 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/GPLv2 +20 -21
- data/Gemfile +3 -9
- data/Rakefile +20 -23
- data/lib/prawn.rb +37 -49
- data/lib/prawn/document.rb +181 -133
- data/lib/prawn/document/bounding_box.rb +41 -29
- data/lib/prawn/document/column_box.rb +7 -7
- data/lib/prawn/document/internals.rb +18 -8
- data/lib/prawn/document/span.rb +21 -16
- data/lib/prawn/encoding.rb +69 -68
- data/lib/prawn/errors.rb +12 -7
- data/lib/prawn/font.rb +115 -69
- data/lib/prawn/font_metric_cache.rb +14 -8
- data/lib/prawn/{font → fonts}/afm.rb +102 -68
- data/lib/prawn/{font → fonts}/dfont.rb +5 -11
- data/lib/prawn/fonts/otf.rb +11 -0
- data/lib/prawn/fonts/ttc.rb +36 -0
- data/lib/prawn/{font → fonts}/ttf.rb +87 -68
- data/lib/prawn/graphics.rb +120 -80
- data/lib/prawn/graphics/blend_mode.rb +65 -0
- data/lib/prawn/graphics/cap_style.rb +3 -3
- data/lib/prawn/graphics/color.rb +27 -25
- data/lib/prawn/graphics/dash.rb +23 -11
- data/lib/prawn/graphics/join_style.rb +9 -3
- data/lib/prawn/graphics/patterns.rb +197 -67
- data/lib/prawn/graphics/transformation.rb +17 -8
- data/lib/prawn/graphics/transparency.rb +17 -13
- data/lib/prawn/grid.rb +48 -47
- data/lib/prawn/image_handler.rb +5 -5
- data/lib/prawn/images.rb +39 -30
- data/lib/prawn/images/image.rb +2 -1
- data/lib/prawn/images/jpg.rb +28 -22
- data/lib/prawn/images/png.rb +107 -66
- data/lib/prawn/measurement_extensions.rb +10 -9
- data/lib/prawn/measurements.rb +19 -15
- data/lib/prawn/outline.rb +97 -77
- data/lib/prawn/repeater.rb +14 -10
- data/lib/prawn/security.rb +81 -61
- data/lib/prawn/security/arcfour.rb +2 -2
- data/lib/prawn/soft_mask.rb +26 -26
- data/lib/prawn/stamp.rb +20 -13
- data/lib/prawn/text.rb +68 -52
- data/lib/prawn/text/box.rb +11 -8
- data/lib/prawn/text/formatted.rb +5 -5
- data/lib/prawn/text/formatted/arranger.rb +78 -49
- data/lib/prawn/text/formatted/box.rb +134 -100
- data/lib/prawn/text/formatted/fragment.rb +11 -14
- data/lib/prawn/text/formatted/line_wrap.rb +121 -63
- data/lib/prawn/text/formatted/parser.rb +139 -117
- data/lib/prawn/text/formatted/wrap.rb +43 -31
- data/lib/prawn/transformation_stack.rb +44 -0
- data/lib/prawn/utilities.rb +7 -22
- data/lib/prawn/version.rb +2 -2
- data/lib/prawn/view.rb +17 -7
- data/manual/basic_concepts/adding_pages.rb +6 -7
- data/manual/basic_concepts/basic_concepts.rb +31 -22
- data/manual/basic_concepts/creation.rb +10 -11
- data/manual/basic_concepts/cursor.rb +4 -5
- data/manual/basic_concepts/measurement.rb +6 -7
- data/manual/basic_concepts/origin.rb +5 -6
- data/manual/basic_concepts/other_cursor_helpers.rb +11 -12
- data/manual/basic_concepts/view.rb +22 -16
- data/manual/bounding_box/bounding_box.rb +29 -24
- data/manual/bounding_box/bounds.rb +11 -12
- data/manual/bounding_box/canvas.rb +4 -5
- data/manual/bounding_box/creation.rb +6 -7
- data/manual/bounding_box/indentation.rb +14 -15
- data/manual/bounding_box/nesting.rb +24 -17
- data/manual/bounding_box/russian_boxes.rb +14 -13
- data/manual/bounding_box/stretchy.rb +12 -13
- data/manual/contents.rb +28 -22
- data/manual/cover.rb +33 -28
- data/manual/document_and_page_options/background.rb +11 -13
- data/manual/document_and_page_options/document_and_page_options.rb +25 -20
- data/manual/document_and_page_options/metadata.rb +18 -16
- data/manual/document_and_page_options/page_margins.rb +18 -20
- data/manual/document_and_page_options/page_size.rb +13 -12
- data/manual/document_and_page_options/print_scaling.rb +17 -15
- data/manual/example_helper.rb +5 -4
- data/manual/graphics/blend_mode.rb +52 -0
- data/manual/graphics/circle_and_ellipse.rb +4 -5
- data/manual/graphics/color.rb +7 -9
- data/manual/graphics/common_lines.rb +7 -8
- data/manual/graphics/fill_and_stroke.rb +4 -5
- data/manual/graphics/fill_rules.rb +9 -10
- data/manual/graphics/gradients.rb +27 -21
- data/manual/graphics/graphics.rb +48 -39
- data/manual/graphics/helper.rb +12 -9
- data/manual/graphics/line_width.rb +8 -7
- data/manual/graphics/lines_and_curves.rb +7 -8
- data/manual/graphics/polygon.rb +6 -8
- data/manual/graphics/rectangle.rb +4 -5
- data/manual/graphics/rotate.rb +6 -7
- data/manual/graphics/scale.rb +14 -15
- data/manual/graphics/soft_masks.rb +4 -5
- data/manual/graphics/stroke_cap.rb +6 -7
- data/manual/graphics/stroke_dash.rb +11 -12
- data/manual/graphics/stroke_join.rb +5 -6
- data/manual/graphics/translate.rb +9 -10
- data/manual/graphics/transparency.rb +7 -8
- data/manual/how_to_read_this_manual.rb +6 -6
- data/manual/images/absolute_position.rb +6 -7
- data/manual/images/fit.rb +7 -8
- data/manual/images/horizontal.rb +9 -10
- data/manual/images/images.rb +28 -24
- data/manual/images/plain_image.rb +5 -6
- data/manual/images/scale.rb +9 -10
- data/manual/images/vertical.rb +13 -14
- data/manual/images/width_and_height.rb +10 -11
- data/manual/layout/boxes.rb +5 -6
- data/manual/layout/content.rb +7 -8
- data/manual/layout/layout.rb +18 -16
- data/manual/layout/simple_grid.rb +6 -7
- data/manual/outline/add_subsection_to.rb +20 -21
- data/manual/outline/insert_section_after.rb +15 -16
- data/manual/outline/outline.rb +21 -17
- data/manual/outline/sections_and_pages.rb +17 -18
- data/manual/repeatable_content/alternate_page_numbering.rb +21 -17
- data/manual/repeatable_content/page_numbering.rb +17 -16
- data/manual/repeatable_content/repeatable_content.rb +25 -19
- data/manual/repeatable_content/repeater.rb +14 -15
- data/manual/repeatable_content/stamp.rb +14 -15
- data/manual/security/encryption.rb +9 -10
- data/manual/security/permissions.rb +19 -14
- data/manual/security/security.rb +19 -16
- data/manual/table.rb +3 -3
- data/manual/text/alignment.rb +16 -17
- data/manual/text/color.rb +12 -11
- data/manual/text/column_box.rb +9 -10
- data/manual/text/fallback_fonts.rb +25 -21
- data/manual/text/font.rb +11 -12
- data/manual/text/font_size.rb +13 -14
- data/manual/text/font_style.rb +7 -8
- data/manual/text/formatted_callbacks.rb +25 -21
- data/manual/text/formatted_text.rb +33 -25
- data/manual/text/free_flowing_text.rb +20 -21
- data/manual/text/inline.rb +18 -19
- data/manual/text/kerning_and_character_spacing.rb +14 -15
- data/manual/text/leading.rb +7 -8
- data/manual/text/line_wrapping.rb +37 -18
- data/manual/text/paragraph_indentation.rb +13 -14
- data/manual/text/positioned_text.rb +15 -16
- data/manual/text/registering_families.rb +20 -21
- data/manual/text/rendering_and_color.rb +9 -10
- data/manual/text/right_to_left_text.rb +26 -19
- data/manual/text/rotation.rb +28 -23
- data/manual/text/single_usage.rb +8 -9
- data/manual/text/text.rb +57 -52
- data/manual/text/text_box_excess.rb +20 -17
- data/manual/text/text_box_extensions.rb +18 -15
- data/manual/text/text_box_overflow.rb +18 -19
- data/manual/text/utf8.rb +11 -12
- data/manual/text/win_ansi_charset.rb +21 -19
- data/prawn.gemspec +45 -33
- data/spec/extensions/encoding_helpers.rb +3 -3
- data/spec/prawn/document/bounding_box_spec.rb +546 -0
- data/spec/prawn/document/column_box_spec.rb +75 -0
- data/spec/prawn/document/security_spec.rb +176 -0
- data/spec/prawn/document_annotations_spec.rb +76 -0
- data/spec/prawn/document_destinations_spec.rb +15 -0
- data/spec/prawn/document_grid_spec.rb +99 -0
- data/spec/prawn/document_reference_spec.rb +27 -0
- data/spec/prawn/document_span_spec.rb +36 -0
- data/spec/prawn/document_spec.rb +802 -0
- data/spec/prawn/font_metric_cache_spec.rb +54 -0
- data/spec/prawn/font_spec.rb +542 -0
- data/spec/prawn/graphics/blend_mode_spec.rb +63 -0
- data/spec/prawn/graphics/transparency_spec.rb +81 -0
- data/spec/prawn/graphics_spec.rb +837 -0
- data/spec/prawn/graphics_stroke_styles_spec.rb +229 -0
- data/spec/prawn/image_handler_spec.rb +53 -0
- data/spec/prawn/images/jpg_spec.rb +20 -0
- data/spec/prawn/images/png_spec.rb +283 -0
- data/spec/prawn/images_spec.rb +224 -0
- data/spec/prawn/measurements_extensions_spec.rb +24 -0
- data/spec/prawn/outline_spec.rb +412 -0
- data/spec/prawn/repeater_spec.rb +165 -0
- data/spec/prawn/soft_mask_spec.rb +74 -0
- data/spec/prawn/stamp_spec.rb +172 -0
- data/spec/prawn/text/box_spec.rb +1112 -0
- data/spec/prawn/text/formatted/arranger_spec.rb +466 -0
- data/spec/prawn/text/formatted/box_spec.rb +846 -0
- data/spec/prawn/text/formatted/fragment_spec.rb +343 -0
- data/spec/prawn/text/formatted/line_wrap_spec.rb +494 -0
- data/spec/prawn/text/formatted/parser_spec.rb +697 -0
- data/spec/prawn/text_draw_text_spec.rb +149 -0
- data/spec/prawn/text_rendering_mode_spec.rb +48 -0
- data/spec/prawn/text_spacing_spec.rb +95 -0
- data/spec/prawn/text_spec.rb +603 -0
- data/spec/prawn/text_with_inline_formatting_spec.rb +35 -0
- data/spec/prawn/transformation_stack_spec.rb +66 -0
- data/spec/prawn/view_spec.rb +63 -0
- data/spec/prawn_manual_spec.rb +35 -0
- data/spec/spec_helper.rb +19 -23
- metadata +145 -185
- metadata.gz.sig +4 -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 +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/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 +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.rb +0 -24
- data/spec/annotations_spec.rb +0 -67
- 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 -742
- data/spec/extensions/mocha.rb +0 -45
- data/spec/font_metric_cache_spec.rb +0 -52
- data/spec/font_spec.rb +0 -475
- data/spec/formatted_text_arranger_spec.rb +0 -423
- data/spec/formatted_text_box_spec.rb +0 -716
- data/spec/formatted_text_fragment_spec.rb +0 -299
- data/spec/graphics_spec.rb +0 -666
- data/spec/grid_spec.rb +0 -95
- data/spec/image_handler_spec.rb +0 -53
- 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 -235
- 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 -1038
- data/spec/text_rendering_mode_spec.rb +0 -45
- data/spec/text_spacing_spec.rb +0 -93
- data/spec/text_spec.rb +0 -549
- 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/text_at_spec.rb
DELETED
@@ -1,142 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
-
|
5
|
-
describe "#draw_text" do
|
6
|
-
before(:each) { create_pdf }
|
7
|
-
|
8
|
-
it "should raise_error ArgumentError if :at option omitted" do
|
9
|
-
expect { @pdf.draw_text("hai", {}) }.to raise_error(ArgumentError)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should raise_error ArgumentError if :align option included" do
|
13
|
-
expect { @pdf.draw_text("hai", :at => [0, 0], :align => :center) }.to raise_error(ArgumentError)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should allow drawing empty strings to the page" do
|
17
|
-
@pdf.draw_text(" ", :at => [100, 100])
|
18
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
19
|
-
expect(text.strings.first).to eq(" ")
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should default to 12 point helvetica" do
|
23
|
-
@pdf.draw_text("Blah", :at => [100, 100])
|
24
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
25
|
-
expect(text.font_settings[0][:name]).to eq(:Helvetica)
|
26
|
-
expect(text.font_settings[0][:size]).to eq(12)
|
27
|
-
expect(text.strings.first).to eq("Blah")
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should allow setting font size" do
|
31
|
-
@pdf.draw_text("Blah", :at => [100, 100], :size => 16)
|
32
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
33
|
-
expect(text.font_settings[0][:size]).to eq(16)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should allow setting a default font size" do
|
37
|
-
@pdf.font_size = 16
|
38
|
-
@pdf.draw_text("Blah", :at => [0, 0])
|
39
|
-
|
40
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
41
|
-
expect(text.font_settings[0][:size]).to eq(16)
|
42
|
-
end
|
43
|
-
|
44
|
-
rotated_text_inspector = Class.new(PDF::Inspector) do
|
45
|
-
attr_reader :tm_operator_used
|
46
|
-
|
47
|
-
def initialize
|
48
|
-
@tm_operator_used = false
|
49
|
-
end
|
50
|
-
|
51
|
-
def set_text_matrix_and_text_line_matrix(*a)
|
52
|
-
@tm_operator_used = true
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should allow rotation" do
|
57
|
-
@pdf.draw_text("Test", :at => [100, 100], :rotate => 90)
|
58
|
-
|
59
|
-
text = rotated_text_inspector.analyze(@pdf.render)
|
60
|
-
|
61
|
-
expect(text.tm_operator_used).to(be_true)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should not use rotation matrix by default" do
|
65
|
-
@pdf.draw_text("Test", :at => [100, 100])
|
66
|
-
|
67
|
-
text = rotated_text_inspector.analyze(@pdf.render)
|
68
|
-
|
69
|
-
expect(text.tm_operator_used).to(be_false)
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should allow overriding default font for a single instance" do
|
73
|
-
@pdf.font_size = 16
|
74
|
-
|
75
|
-
@pdf.draw_text("Blah", :size => 11, :at => [0, 0])
|
76
|
-
@pdf.draw_text("Blaz", :at => [0, 0])
|
77
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
78
|
-
expect(text.font_settings[0][:size]).to eq(11)
|
79
|
-
expect(text.font_settings[1][:size]).to eq(16)
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should allow setting a font size transaction with a block" do
|
83
|
-
@pdf.font_size 16 do
|
84
|
-
@pdf.draw_text('Blah', :at => [0, 0])
|
85
|
-
end
|
86
|
-
|
87
|
-
@pdf.draw_text('blah', :at => [0, 0])
|
88
|
-
|
89
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
90
|
-
expect(text.font_settings[0][:size]).to eq(16)
|
91
|
-
expect(text.font_settings[1][:size]).to eq(12)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should allow manual setting the font size when in a font size block" do
|
95
|
-
@pdf.font_size(16) do
|
96
|
-
@pdf.draw_text('Foo', :at => [0, 0])
|
97
|
-
@pdf.draw_text('Blah', :size => 11, :at => [0, 0])
|
98
|
-
@pdf.draw_text('Blaz', :at => [0, 0])
|
99
|
-
end
|
100
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
101
|
-
expect(text.font_settings[0][:size]).to eq(16)
|
102
|
-
expect(text.font_settings[1][:size]).to eq(11)
|
103
|
-
expect(text.font_settings[2][:size]).to eq(16)
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should allow registering of built-in font_settings on the fly" do
|
107
|
-
@pdf.font "Times-Roman"
|
108
|
-
@pdf.draw_text("Blah", :at => [100, 100])
|
109
|
-
@pdf.font "Courier"
|
110
|
-
@pdf.draw_text("Blaz", :at => [150, 150])
|
111
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
112
|
-
expect(text.font_settings[0][:name]).to eq(:"Times-Roman")
|
113
|
-
expect(text.font_settings[1][:name]).to eq(:Courier)
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should raise_error an exception when an unknown font is used" do
|
117
|
-
expect { @pdf.font "Pao bu" }.to raise_error(Prawn::Errors::UnknownFont)
|
118
|
-
end
|
119
|
-
|
120
|
-
it "should correctly render a utf-8 string when using a built-in font" do
|
121
|
-
str = "©" # copyright symbol
|
122
|
-
@pdf.draw_text(str, :at => [0, 0])
|
123
|
-
|
124
|
-
# grab the text from the rendered PDF and ensure it matches
|
125
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
126
|
-
expect(text.strings.first).to eq(str)
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should raise_error an exception when a utf-8 incompatible string is rendered" do
|
130
|
-
str = "Blah \xDD"
|
131
|
-
expect { @pdf.draw_text(str, :at => [0, 0]) }.to raise_error(
|
132
|
-
Prawn::Errors::IncompatibleStringEncoding)
|
133
|
-
end
|
134
|
-
|
135
|
-
it "should not raise an exception when a shift-jis string is rendered" do
|
136
|
-
datafile = "#{Prawn::DATADIR}/shift_jis_text.txt"
|
137
|
-
sjis_str = File.open(datafile, "r:shift_jis") { |f| f.gets }
|
138
|
-
@pdf.font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf")
|
139
|
-
|
140
|
-
@pdf.draw_text(sjis_str, :at => [0, 0])
|
141
|
-
end
|
142
|
-
end
|
data/spec/text_box_spec.rb
DELETED
@@ -1,1038 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
-
|
5
|
-
describe "Text::Box#nothing_printed?" do
|
6
|
-
it "should be_true when nothing printed" do
|
7
|
-
create_pdf
|
8
|
-
string = "Hello world, how are you?\nI'm fine, thank you."
|
9
|
-
text_box = Prawn::Text::Box.new(string,
|
10
|
-
:height => 2,
|
11
|
-
:document => @pdf)
|
12
|
-
text_box.render
|
13
|
-
expect(text_box.nothing_printed?).to be_true
|
14
|
-
end
|
15
|
-
it "should be_false when something printed" do
|
16
|
-
create_pdf
|
17
|
-
string = "Hello world, how are you?\nI'm fine, thank you."
|
18
|
-
text_box = Prawn::Text::Box.new(string,
|
19
|
-
:height => 14,
|
20
|
-
:document => @pdf)
|
21
|
-
text_box.render
|
22
|
-
expect(text_box.nothing_printed?).to be_false
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "Text::Box#everything_printed?" do
|
27
|
-
it "should be_false when not everything printed" do
|
28
|
-
create_pdf
|
29
|
-
string = "Hello world, how are you?\nI'm fine, thank you."
|
30
|
-
text_box = Prawn::Text::Box.new(string,
|
31
|
-
:height => 14,
|
32
|
-
:document => @pdf)
|
33
|
-
text_box.render
|
34
|
-
expect(text_box.everything_printed?).to be_false
|
35
|
-
end
|
36
|
-
it "should be_true when everything printed" do
|
37
|
-
create_pdf
|
38
|
-
string = "Hello world, how are you?\nI'm fine, thank you."
|
39
|
-
text_box = Prawn::Text::Box.new(string,
|
40
|
-
:document => @pdf)
|
41
|
-
text_box.render
|
42
|
-
expect(text_box.everything_printed?).to be_true
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "Text::Box#line_gap" do
|
47
|
-
it "should == the line gap of the font when using a single " \
|
48
|
-
"font and font size" do
|
49
|
-
create_pdf
|
50
|
-
string = "Hello world, how are you?\nI'm fine, thank you."
|
51
|
-
text_box = Prawn::Text::Box.new(string,
|
52
|
-
:document => @pdf)
|
53
|
-
text_box.render
|
54
|
-
expect(text_box.line_gap).to be_within(0.0001).of(@pdf.font.line_gap)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "Text::Box" do
|
59
|
-
it "should be able to set text direction document-wide" do
|
60
|
-
create_pdf
|
61
|
-
@pdf.text_direction(:rtl)
|
62
|
-
@pdf.text_direction = :rtl
|
63
|
-
string = "Hello world, how are you?\nI'm fine, thank you."
|
64
|
-
text_box = Prawn::Text::Box.new(string,
|
65
|
-
:document => @pdf)
|
66
|
-
text_box.render
|
67
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
68
|
-
expect(text.strings[0]).to eq("?uoy era woh ,dlrow olleH")
|
69
|
-
expect(text.strings[1]).to eq(".uoy knaht ,enif m'I")
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should be able to reverse multi-byte text" do
|
73
|
-
create_pdf
|
74
|
-
@pdf.text_direction(:rtl)
|
75
|
-
@pdf.text_direction = :rtl
|
76
|
-
@pdf.text_direction = :rtl
|
77
|
-
@pdf.font("#{Prawn::DATADIR}/fonts/gkai00mp.ttf", :size => 16) do
|
78
|
-
@pdf.text "写个小"
|
79
|
-
end
|
80
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
81
|
-
expect(text.strings[0]).to eq("小个写")
|
82
|
-
end
|
83
|
-
|
84
|
-
it "option should be able to override document-wide text direction" do
|
85
|
-
create_pdf
|
86
|
-
@pdf.text_direction = :rtl
|
87
|
-
string = "Hello world, how are you?\nI'm fine, thank you."
|
88
|
-
text_box = Prawn::Text::Box.new(string,
|
89
|
-
:document => @pdf,
|
90
|
-
:direction => :ltr)
|
91
|
-
text_box.render
|
92
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
93
|
-
expect(text.strings[0]).to eq("Hello world, how are you?")
|
94
|
-
expect(text.strings[1]).to eq("I'm fine, thank you.")
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe "Text::Box" do
|
99
|
-
it "should be able to set leading document-wide" do
|
100
|
-
create_pdf
|
101
|
-
@pdf.default_leading(7)
|
102
|
-
@pdf.default_leading = 7
|
103
|
-
text_box = Prawn::Text::Box.new("hello world",
|
104
|
-
:document => @pdf)
|
105
|
-
expect(text_box.leading).to eq(7)
|
106
|
-
end
|
107
|
-
|
108
|
-
it "option should be able to override document-wide leading" do
|
109
|
-
create_pdf
|
110
|
-
@pdf.default_leading = 7
|
111
|
-
text_box = Prawn::Text::Box.new("hello world",
|
112
|
-
:document => @pdf,
|
113
|
-
:leading => 20)
|
114
|
-
expect(text_box.leading).to eq(20)
|
115
|
-
end
|
116
|
-
it "should default to document-wide leading if no" \
|
117
|
-
"leading option is provided" do
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe "Text::Box#render with :align => :justify" do
|
122
|
-
it "should draw the word spacing to the document" do
|
123
|
-
create_pdf
|
124
|
-
string = "hello world " * 20
|
125
|
-
options = { :document => @pdf, :align => :justify }
|
126
|
-
text_box = Prawn::Text::Box.new(string, options)
|
127
|
-
text_box.render
|
128
|
-
contents = PDF::Inspector::Text.analyze(@pdf.render)
|
129
|
-
expect(contents.word_spacing[0]).to be > 0
|
130
|
-
end
|
131
|
-
it "should not justify the last line of a paragraph" do
|
132
|
-
create_pdf
|
133
|
-
string = "hello world "
|
134
|
-
options = { :document => @pdf, :align => :justify }
|
135
|
-
text_box = Prawn::Text::Box.new(string, options)
|
136
|
-
text_box.render
|
137
|
-
contents = PDF::Inspector::Text.analyze(@pdf.render)
|
138
|
-
expect(contents.word_spacing).to be_empty
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
describe "Text::Box" do
|
143
|
-
it "should only require enough space for the descender and the ascender " \
|
144
|
-
"when determining whether a line can fit" do
|
145
|
-
create_pdf
|
146
|
-
text = "Oh hai text rect"
|
147
|
-
options = { :document => @pdf, :height => @pdf.font.ascender + @pdf.font.descender }
|
148
|
-
text_box = Prawn::Text::Box.new(text, options)
|
149
|
-
text_box.render
|
150
|
-
expect(text_box.text).to eq("Oh hai text rect")
|
151
|
-
|
152
|
-
text = "Oh hai text rect\nOh hai text rect"
|
153
|
-
options = { :document => @pdf, :height => @pdf.font.height + @pdf.font.ascender + @pdf.font.descender }
|
154
|
-
text_box = Prawn::Text::Box.new(text, options)
|
155
|
-
text_box.render
|
156
|
-
expect(text_box.text).to eq("Oh hai text rect\nOh hai text rect")
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
describe "Text::Box#height without leading" do
|
161
|
-
it "should == the sum of the height of each line, " \
|
162
|
-
"not including the space below the last line" do
|
163
|
-
create_pdf
|
164
|
-
text = "Oh hai text rect.\nOh hai text rect."
|
165
|
-
options = { :document => @pdf }
|
166
|
-
text_box = Prawn::Text::Box.new(text, options)
|
167
|
-
text_box.render
|
168
|
-
expect(text_box.height).to be_within(0.001).of(@pdf.font.height * 2 - @pdf.font.line_gap)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
describe "Text::Box#height with leading" do
|
173
|
-
it "should == the sum of the height of each line plus leading, " \
|
174
|
-
"but not including the space below the last line" do
|
175
|
-
create_pdf
|
176
|
-
text = "Oh hai text rect.\nOh hai text rect."
|
177
|
-
leading = 12
|
178
|
-
options = { :document => @pdf, :leading => leading }
|
179
|
-
text_box = Prawn::Text::Box.new(text, options)
|
180
|
-
text_box.render
|
181
|
-
expect(text_box.height).to be_within(0.001).of((@pdf.font.height + leading) * 2 - @pdf.font.line_gap - leading)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
describe "Text::Box with :draw_text_callback" do
|
186
|
-
before(:each) { create_pdf }
|
187
|
-
|
188
|
-
it "hits the callback whenever text is drawn" do
|
189
|
-
draw_block = stub
|
190
|
-
draw_block.expects(:kick).with("this text is long enough to")
|
191
|
-
draw_block.expects(:kick).with("span two lines")
|
192
|
-
|
193
|
-
@pdf.text_box "this text is long enough to span two lines",
|
194
|
-
:width => 150,
|
195
|
-
:draw_text_callback => lambda { |text, _| draw_block.kick(text) }
|
196
|
-
end
|
197
|
-
|
198
|
-
it "hits the callback once per fragment for :inline_format" do
|
199
|
-
draw_block = stub
|
200
|
-
draw_block.expects(:kick).with("this text has ")
|
201
|
-
draw_block.expects(:kick).with("fancy")
|
202
|
-
draw_block.expects(:kick).with(" formatting")
|
203
|
-
|
204
|
-
@pdf.text_box "this text has <b>fancy</b> formatting",
|
205
|
-
:inline_format => true, :width => 500,
|
206
|
-
:draw_text_callback => lambda { |text, _| draw_block.kick(text) }
|
207
|
-
end
|
208
|
-
|
209
|
-
it "does not call #draw_text!" do
|
210
|
-
@pdf.expects(:draw_text!).never
|
211
|
-
@pdf.text_box "some text", :width => 500,
|
212
|
-
:draw_text_callback => lambda { |_, _| }
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
describe "Text::Box#valid_options" do
|
217
|
-
it "should return an array" do
|
218
|
-
create_pdf
|
219
|
-
text_box = Prawn::Text::Box.new("", :document => @pdf)
|
220
|
-
expect(text_box.valid_options).to be_a_kind_of(Array)
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
describe "Text::Box#render" do
|
225
|
-
it "should not fail if height is smaller than 1 line" do
|
226
|
-
create_pdf
|
227
|
-
@text = "Oh hai text rect. " * 10
|
228
|
-
@options = {
|
229
|
-
:height => @pdf.font.height * 0.5,
|
230
|
-
:document => @pdf
|
231
|
-
}
|
232
|
-
text_box = Prawn::Text::Box.new(@text, @options)
|
233
|
-
text_box.render
|
234
|
-
expect(text_box.text).to eq("")
|
235
|
-
end
|
236
|
-
it "should draw content to the page" do
|
237
|
-
create_pdf
|
238
|
-
@text = "Oh hai text rect. " * 10
|
239
|
-
@options = { :document => @pdf }
|
240
|
-
text_box = Prawn::Text::Box.new(@text, @options)
|
241
|
-
text_box.render
|
242
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
243
|
-
expect(text.strings).not_to be_empty
|
244
|
-
end
|
245
|
-
it "should not draw a transformation matrix" do
|
246
|
-
create_pdf
|
247
|
-
@text = "Oh hai text rect. " * 10
|
248
|
-
@options = { :document => @pdf }
|
249
|
-
text_box = Prawn::Text::Box.new(@text, @options)
|
250
|
-
text_box.render
|
251
|
-
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
252
|
-
expect(matrices.matrices.length).to eq(0)
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
describe "Text::Box#render(:single_line => true)" do
|
257
|
-
it "should draw only one line to the page" do
|
258
|
-
create_pdf
|
259
|
-
@text = "Oh hai text rect. " * 10
|
260
|
-
@options = { :document => @pdf,
|
261
|
-
:single_line => true }
|
262
|
-
text_box = Prawn::Text::Box.new(@text, @options)
|
263
|
-
text_box.render
|
264
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
265
|
-
expect(text.strings.length).to eq(1)
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
describe "Text::Box#render(:dry_run => true)" do
|
270
|
-
it "should not draw any content to the page" do
|
271
|
-
create_pdf
|
272
|
-
@text = "Oh hai text rect. " * 10
|
273
|
-
@options = { :document => @pdf }
|
274
|
-
text_box = Prawn::Text::Box.new(@text, @options)
|
275
|
-
text_box.render(:dry_run => true)
|
276
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
277
|
-
expect(text.strings).to be_empty
|
278
|
-
end
|
279
|
-
|
280
|
-
it "subsequent calls to render should_not raise_error an ArgumentError exception" do
|
281
|
-
create_pdf
|
282
|
-
@text = "™©"
|
283
|
-
@options = { :document => @pdf }
|
284
|
-
text_box = Prawn::Text::Box.new(@text, @options)
|
285
|
-
text_box.render(:dry_run => true)
|
286
|
-
|
287
|
-
text_box.render
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
describe "Text::Box#render(:valign => :bottom)" do
|
292
|
-
it "#at should be the same from one dry run to the next" do
|
293
|
-
create_pdf
|
294
|
-
text = "this is center text " * 12
|
295
|
-
options = { :width => 162,
|
296
|
-
:valign => :bottom,
|
297
|
-
:document => @pdf }
|
298
|
-
text_box = Prawn::Text::Box.new(text, options)
|
299
|
-
|
300
|
-
text_box.render(:dry_run => true)
|
301
|
-
original_at = text_box.at.dup
|
302
|
-
|
303
|
-
text_box.render(:dry_run => true)
|
304
|
-
expect(text_box.at).to eq(original_at)
|
305
|
-
end
|
306
|
-
end
|
307
|
-
|
308
|
-
describe "Text::Box#render(:valign => :center)" do
|
309
|
-
it "#at should be the same from one dry run to the next" do
|
310
|
-
create_pdf
|
311
|
-
text = "this is center text " * 12
|
312
|
-
options = { :width => 162,
|
313
|
-
:valign => :center,
|
314
|
-
:document => @pdf }
|
315
|
-
text_box = Prawn::Text::Box.new(text, options)
|
316
|
-
|
317
|
-
text_box.render(:dry_run => true)
|
318
|
-
original_at = text_box.at.dup
|
319
|
-
|
320
|
-
text_box.render(:dry_run => true)
|
321
|
-
expect(text_box.at).to eq(original_at)
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
|
-
describe "Text::Box#render with :rotate option of 30)" do
|
326
|
-
before(:each) do
|
327
|
-
create_pdf
|
328
|
-
rotate = 30
|
329
|
-
@x = 300
|
330
|
-
@y = 70
|
331
|
-
@width = 100
|
332
|
-
@height = 50
|
333
|
-
@cos = Math.cos(rotate * Math::PI / 180)
|
334
|
-
@sin = Math.sin(rotate * Math::PI / 180)
|
335
|
-
@text = "Oh hai text rect. " * 10
|
336
|
-
@options = { :document => @pdf,
|
337
|
-
:rotate => rotate,
|
338
|
-
:at => [@x, @y],
|
339
|
-
:width => @width,
|
340
|
-
:height => @height }
|
341
|
-
end
|
342
|
-
context ":rotate_around option of :center" do
|
343
|
-
it "should draw content to the page rotated about the center of the text" do
|
344
|
-
@options[:rotate_around] = :center
|
345
|
-
text_box = Prawn::Text::Box.new(@text, @options)
|
346
|
-
text_box.render
|
347
|
-
|
348
|
-
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
349
|
-
x = @x + @width / 2
|
350
|
-
y = @y - @height / 2
|
351
|
-
x_prime = x * @cos - y * @sin
|
352
|
-
y_prime = x * @sin + y * @cos
|
353
|
-
expect(matrices.matrices[0]).to eq([1, 0, 0, 1,
|
354
|
-
reduce_precision(x - x_prime),
|
355
|
-
reduce_precision(y - y_prime)])
|
356
|
-
expect(matrices.matrices[1]).to eq([reduce_precision(@cos),
|
357
|
-
reduce_precision(@sin),
|
358
|
-
reduce_precision(-@sin),
|
359
|
-
reduce_precision(@cos), 0, 0])
|
360
|
-
|
361
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
362
|
-
expect(text.strings).not_to be_empty
|
363
|
-
end
|
364
|
-
end
|
365
|
-
context ":rotate_around option of :upper_left" do
|
366
|
-
it "should draw content to the page rotated about the upper left corner of the text" do
|
367
|
-
@options[:rotate_around] = :upper_left
|
368
|
-
text_box = Prawn::Text::Box.new(@text, @options)
|
369
|
-
text_box.render
|
370
|
-
|
371
|
-
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
372
|
-
x = @x
|
373
|
-
y = @y
|
374
|
-
x_prime = x * @cos - y * @sin
|
375
|
-
y_prime = x * @sin + y * @cos
|
376
|
-
expect(matrices.matrices[0]).to eq([1, 0, 0, 1,
|
377
|
-
reduce_precision(x - x_prime),
|
378
|
-
reduce_precision(y - y_prime)])
|
379
|
-
expect(matrices.matrices[1]).to eq([reduce_precision(@cos),
|
380
|
-
reduce_precision(@sin),
|
381
|
-
reduce_precision(-@sin),
|
382
|
-
reduce_precision(@cos), 0, 0])
|
383
|
-
|
384
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
385
|
-
expect(text.strings).not_to be_empty
|
386
|
-
end
|
387
|
-
end
|
388
|
-
context "default :rotate_around" do
|
389
|
-
it "should draw content to the page rotated about the upper left corner of the text" do
|
390
|
-
text_box = Prawn::Text::Box.new(@text, @options)
|
391
|
-
text_box.render
|
392
|
-
|
393
|
-
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
394
|
-
x = @x
|
395
|
-
y = @y
|
396
|
-
x_prime = x * @cos - y * @sin
|
397
|
-
y_prime = x * @sin + y * @cos
|
398
|
-
expect(matrices.matrices[0]).to eq([1, 0, 0, 1,
|
399
|
-
reduce_precision(x - x_prime),
|
400
|
-
reduce_precision(y - y_prime)])
|
401
|
-
expect(matrices.matrices[1]).to eq([reduce_precision(@cos),
|
402
|
-
reduce_precision(@sin),
|
403
|
-
reduce_precision(-@sin),
|
404
|
-
reduce_precision(@cos), 0, 0])
|
405
|
-
|
406
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
407
|
-
expect(text.strings).not_to be_empty
|
408
|
-
end
|
409
|
-
end
|
410
|
-
context ":rotate_around option of :upper_right" do
|
411
|
-
it "should draw content to the page rotated about the upper right corner of the text" do
|
412
|
-
@options[:rotate_around] = :upper_right
|
413
|
-
text_box = Prawn::Text::Box.new(@text, @options)
|
414
|
-
text_box.render
|
415
|
-
|
416
|
-
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
417
|
-
x = @x + @width
|
418
|
-
y = @y
|
419
|
-
x_prime = x * @cos - y * @sin
|
420
|
-
y_prime = x * @sin + y * @cos
|
421
|
-
expect(matrices.matrices[0]).to eq([1, 0, 0, 1,
|
422
|
-
reduce_precision(x - x_prime),
|
423
|
-
reduce_precision(y - y_prime)])
|
424
|
-
expect(matrices.matrices[1]).to eq([reduce_precision(@cos),
|
425
|
-
reduce_precision(@sin),
|
426
|
-
reduce_precision(-@sin),
|
427
|
-
reduce_precision(@cos), 0, 0])
|
428
|
-
|
429
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
430
|
-
expect(text.strings).not_to be_empty
|
431
|
-
end
|
432
|
-
end
|
433
|
-
context ":rotate_around option of :lower_right" do
|
434
|
-
it "should draw content to the page rotated about the lower right corner of the text" do
|
435
|
-
@options[:rotate_around] = :lower_right
|
436
|
-
text_box = Prawn::Text::Box.new(@text, @options)
|
437
|
-
text_box.render
|
438
|
-
|
439
|
-
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
440
|
-
x = @x + @width
|
441
|
-
y = @y - @height
|
442
|
-
x_prime = x * @cos - y * @sin
|
443
|
-
y_prime = x * @sin + y * @cos
|
444
|
-
expect(matrices.matrices[0]).to eq([1, 0, 0, 1,
|
445
|
-
reduce_precision(x - x_prime),
|
446
|
-
reduce_precision(y - y_prime)])
|
447
|
-
expect(matrices.matrices[1]).to eq([reduce_precision(@cos),
|
448
|
-
reduce_precision(@sin),
|
449
|
-
reduce_precision(-@sin),
|
450
|
-
reduce_precision(@cos), 0, 0])
|
451
|
-
|
452
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
453
|
-
expect(text.strings).not_to be_empty
|
454
|
-
end
|
455
|
-
end
|
456
|
-
context ":rotate_around option of :lower_left" do
|
457
|
-
it "should draw content to the page rotated about the lower left corner of the text" do
|
458
|
-
@options[:rotate_around] = :lower_left
|
459
|
-
text_box = Prawn::Text::Box.new(@text, @options)
|
460
|
-
text_box.render
|
461
|
-
|
462
|
-
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
463
|
-
x = @x
|
464
|
-
y = @y - @height
|
465
|
-
x_prime = x * @cos - y * @sin
|
466
|
-
y_prime = x * @sin + y * @cos
|
467
|
-
expect(matrices.matrices[0]).to eq([1, 0, 0, 1,
|
468
|
-
reduce_precision(x - x_prime),
|
469
|
-
reduce_precision(y - y_prime)])
|
470
|
-
expect(matrices.matrices[1]).to eq([reduce_precision(@cos),
|
471
|
-
reduce_precision(@sin),
|
472
|
-
reduce_precision(-@sin),
|
473
|
-
reduce_precision(@cos), 0, 0])
|
474
|
-
|
475
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
476
|
-
expect(text.strings).not_to be_empty
|
477
|
-
end
|
478
|
-
end
|
479
|
-
end
|
480
|
-
|
481
|
-
describe "Text::Box default height" do
|
482
|
-
before(:each) { create_pdf }
|
483
|
-
|
484
|
-
it "should be the height from the bottom bound to document.y" do
|
485
|
-
target_height = @pdf.y - @pdf.bounds.bottom
|
486
|
-
@text = "Oh hai\n" * 60
|
487
|
-
text_box = Prawn::Text::Box.new(@text, :document => @pdf)
|
488
|
-
text_box.render
|
489
|
-
expect(text_box.height).to be_within(@pdf.font.height).of(target_height)
|
490
|
-
end
|
491
|
-
|
492
|
-
it "should use the margin-box bottom if only in a stretchy bbox" do
|
493
|
-
@pdf.bounding_box([0, @pdf.cursor], :width => @pdf.bounds.width) do
|
494
|
-
target_height = @pdf.y - @pdf.bounds.bottom
|
495
|
-
@text = "Oh hai\n" * 60
|
496
|
-
text_box = Prawn::Text::Box.new(@text, :document => @pdf)
|
497
|
-
text_box.render
|
498
|
-
expect(text_box.height).to be_within(@pdf.font.height).of(target_height)
|
499
|
-
end
|
500
|
-
end
|
501
|
-
|
502
|
-
it "should use the parent-box bottom if in a stretchy bbox and " \
|
503
|
-
"overflow is :expand, even with an explicit height"do
|
504
|
-
@pdf.bounding_box([0, @pdf.cursor], :width => @pdf.bounds.width) do
|
505
|
-
target_height = @pdf.y - @pdf.bounds.bottom
|
506
|
-
@text = "Oh hai\n" * 60
|
507
|
-
text_box = Prawn::Text::Box.new(@text, :document => @pdf,
|
508
|
-
:height => 100,
|
509
|
-
:overflow => :expand)
|
510
|
-
text_box.render
|
511
|
-
expect(text_box.height).to be_within(@pdf.font.height).of(target_height)
|
512
|
-
end
|
513
|
-
end
|
514
|
-
|
515
|
-
it "should use the innermost non-stretchy bbox, not the margin box" do
|
516
|
-
@pdf.bounding_box([0, @pdf.cursor], :width => @pdf.bounds.width,
|
517
|
-
:height => 200) do
|
518
|
-
@pdf.bounding_box([0, @pdf.cursor], :width => @pdf.bounds.width) do
|
519
|
-
@text = "Oh hai\n" * 60
|
520
|
-
text_box = Prawn::Text::Box.new(@text, :document => @pdf)
|
521
|
-
text_box.render
|
522
|
-
expect(text_box.height).to be_within(@pdf.font.height).of(200)
|
523
|
-
end
|
524
|
-
end
|
525
|
-
end
|
526
|
-
end
|
527
|
-
|
528
|
-
describe "Text::Box default at" do
|
529
|
-
it "should be the left corner of the bounds, and the current document.y" do
|
530
|
-
create_pdf
|
531
|
-
target_at = [@pdf.bounds.left, @pdf.y]
|
532
|
-
@text = "Oh hai text rect. " * 100
|
533
|
-
@options = { :document => @pdf }
|
534
|
-
text_box = Prawn::Text::Box.new(@text, @options)
|
535
|
-
text_box.render
|
536
|
-
expect(text_box.at).to eq(target_at)
|
537
|
-
end
|
538
|
-
end
|
539
|
-
|
540
|
-
describe "Text::Box with text than can fit in the box" do
|
541
|
-
before(:each) do
|
542
|
-
create_pdf
|
543
|
-
@text = "Oh hai text rect. " * 10
|
544
|
-
@options = {
|
545
|
-
:width => 162.0,
|
546
|
-
:height => 162.0,
|
547
|
-
:document => @pdf
|
548
|
-
}
|
549
|
-
end
|
550
|
-
|
551
|
-
it "printed text should match requested text, except that preceding and " \
|
552
|
-
"trailing white space will be stripped from each line, and newlines may " \
|
553
|
-
"be inserted" do
|
554
|
-
text_box = Prawn::Text::Box.new(" " + @text, @options)
|
555
|
-
text_box.render
|
556
|
-
expect(text_box.text.gsub("\n", " ")).to eq(@text.strip)
|
557
|
-
end
|
558
|
-
|
559
|
-
it "render should return an empty string because no text remains unprinted" do
|
560
|
-
text_box = Prawn::Text::Box.new(@text, @options)
|
561
|
-
expect(text_box.render).to eq("")
|
562
|
-
end
|
563
|
-
|
564
|
-
it "should be truncated when the leading is set high enough to prevent all the lines from being printed" do
|
565
|
-
@options[:leading] = 40
|
566
|
-
text_box = Prawn::Text::Box.new(@text, @options)
|
567
|
-
text_box.render
|
568
|
-
expect(text_box.text.gsub("\n", " ")).not_to eq(@text.strip)
|
569
|
-
end
|
570
|
-
end
|
571
|
-
|
572
|
-
describe "Text::Box with text that fits exactly in the box" do
|
573
|
-
before(:each) do
|
574
|
-
create_pdf
|
575
|
-
@lines = 3
|
576
|
-
@interlines = @lines - 1
|
577
|
-
@text = (1..@lines).to_a.join("\n")
|
578
|
-
@options = {
|
579
|
-
:width => 162.0,
|
580
|
-
:height => @pdf.font.ascender + @pdf.font.height * @interlines + @pdf.font.descender,
|
581
|
-
:document => @pdf
|
582
|
-
}
|
583
|
-
end
|
584
|
-
|
585
|
-
it "should have the expected height" do
|
586
|
-
expected_height = @options.delete(:height)
|
587
|
-
text_box = Prawn::Text::Box.new(@text, @options)
|
588
|
-
text_box.render
|
589
|
-
expect(text_box.height).to be_within(0.0001).of(expected_height)
|
590
|
-
end
|
591
|
-
|
592
|
-
it "should print everything" do
|
593
|
-
text_box = Prawn::Text::Box.new(@text, @options)
|
594
|
-
text_box.render
|
595
|
-
expect(text_box.text).to eq(@text)
|
596
|
-
end
|
597
|
-
|
598
|
-
describe "with leading" do
|
599
|
-
before(:each) do
|
600
|
-
@options[:leading] = 15
|
601
|
-
end
|
602
|
-
|
603
|
-
it "should not overflow when enough height is added" do
|
604
|
-
@options[:height] += @options[:leading] * @interlines
|
605
|
-
text_box = Prawn::Text::Box.new(@text, @options)
|
606
|
-
text_box.render
|
607
|
-
expect(text_box.text).to eq(@text)
|
608
|
-
end
|
609
|
-
|
610
|
-
it "should overflow when insufficient height is added" do
|
611
|
-
@options[:height] += @options[:leading] * @interlines - 1
|
612
|
-
text_box = Prawn::Text::Box.new(@text, @options)
|
613
|
-
text_box.render
|
614
|
-
expect(text_box.text).not_to eq(@text)
|
615
|
-
end
|
616
|
-
end
|
617
|
-
|
618
|
-
describe "with negative leading" do
|
619
|
-
before(:each) do
|
620
|
-
@options[:leading] = -4
|
621
|
-
end
|
622
|
-
|
623
|
-
it "should not overflow when enough height is removed" do
|
624
|
-
@options[:height] += @options[:leading] * @interlines
|
625
|
-
text_box = Prawn::Text::Box.new(@text, @options)
|
626
|
-
text_box.render
|
627
|
-
expect(text_box.text).to eq(@text)
|
628
|
-
end
|
629
|
-
|
630
|
-
it "should overflow when too much height is removed" do
|
631
|
-
@options[:height] += @options[:leading] * @interlines - 1
|
632
|
-
text_box = Prawn::Text::Box.new(@text, @options)
|
633
|
-
text_box.render
|
634
|
-
expect(text_box.text).not_to eq(@text)
|
635
|
-
end
|
636
|
-
end
|
637
|
-
end
|
638
|
-
|
639
|
-
describe "Text::Box printing UTF-8 string with higher bit characters" do
|
640
|
-
before(:each) do
|
641
|
-
create_pdf
|
642
|
-
@text = "©"
|
643
|
-
# not enough height to print any text, so we can directly compare against
|
644
|
-
# the input string
|
645
|
-
bounding_height = 1.0
|
646
|
-
options = {
|
647
|
-
:height => bounding_height,
|
648
|
-
:document => @pdf
|
649
|
-
}
|
650
|
-
file = "#{Prawn::DATADIR}/fonts/Panic+Sans.dfont"
|
651
|
-
@pdf.font_families["Panic Sans"] = {
|
652
|
-
:normal => { :file => file, :font => "PanicSans" },
|
653
|
-
:italic => { :file => file, :font => "PanicSans-Italic" },
|
654
|
-
:bold => { :file => file, :font => "PanicSans-Bold" },
|
655
|
-
:bold_italic => { :file => file, :font => "PanicSans-BoldItalic" }
|
656
|
-
}
|
657
|
-
@text_box = Prawn::Text::Box.new(@text, options)
|
658
|
-
end
|
659
|
-
describe "when using a TTF font" do
|
660
|
-
it "unprinted text should be in UTF-8 encoding" do
|
661
|
-
@pdf.font("Panic Sans")
|
662
|
-
remaining_text = @text_box.render
|
663
|
-
expect(remaining_text).to eq(@text)
|
664
|
-
end
|
665
|
-
end
|
666
|
-
|
667
|
-
describe "when using an AFM font" do
|
668
|
-
it "unprinted text should be in UTF-8 encoding" do
|
669
|
-
remaining_text = @text_box.render
|
670
|
-
expect(remaining_text).to eq(@text)
|
671
|
-
end
|
672
|
-
end
|
673
|
-
end
|
674
|
-
|
675
|
-
describe "Text::Box with more text than can fit in the box" do
|
676
|
-
before(:each) do
|
677
|
-
create_pdf
|
678
|
-
@text = "Oh hai text rect. " * 30
|
679
|
-
@bounding_height = 162.0
|
680
|
-
@options = {
|
681
|
-
:width => 162.0,
|
682
|
-
:height => @bounding_height,
|
683
|
-
:document => @pdf
|
684
|
-
}
|
685
|
-
end
|
686
|
-
|
687
|
-
context "truncated overflow" do
|
688
|
-
before(:each) do
|
689
|
-
@options[:overflow] = :truncate
|
690
|
-
@text_box = Prawn::Text::Box.new(@text, @options)
|
691
|
-
end
|
692
|
-
it "should be truncated" do
|
693
|
-
@text_box.render
|
694
|
-
expect(@text_box.text.gsub("\n", " ")).not_to eq(@text.strip)
|
695
|
-
end
|
696
|
-
it "render should not return an empty string because some text remains unprinted" do
|
697
|
-
expect(@text_box.render).not_to be_empty
|
698
|
-
end
|
699
|
-
it "#height should be no taller than the specified height" do
|
700
|
-
@text_box.render
|
701
|
-
expect(@text_box.height).to be <= @bounding_height
|
702
|
-
end
|
703
|
-
it "#height should be within one font height of the specified height" do
|
704
|
-
@text_box.render
|
705
|
-
expect(@bounding_height).to be_within(@pdf.font.height).of(@text_box.height)
|
706
|
-
end
|
707
|
-
context "with :rotate option" do
|
708
|
-
it "unrendered text should be the same as when not rotated" do
|
709
|
-
remaining_text = @text_box.render
|
710
|
-
|
711
|
-
rotate = 30
|
712
|
-
x = 300
|
713
|
-
y = 70
|
714
|
-
width = @options[:width]
|
715
|
-
height = @options[:height]
|
716
|
-
@options[:document] = @pdf
|
717
|
-
@options[:rotate] = rotate
|
718
|
-
@options[:at] = [x, y]
|
719
|
-
rotated_text_box = Prawn::Text::Box.new(@text, @options)
|
720
|
-
expect(rotated_text_box.render).to eq(remaining_text)
|
721
|
-
end
|
722
|
-
end
|
723
|
-
end
|
724
|
-
|
725
|
-
context "truncated with text and size taken from the manual" do
|
726
|
-
it "should return the right text" do
|
727
|
-
@text = "This is the beginning of the text. It will be cut somewhere and " \
|
728
|
-
"the rest of the text will procede to be rendered this time by " \
|
729
|
-
"calling another method." + " . " * 50
|
730
|
-
@options[:width] = 300
|
731
|
-
@options[:height] = 50
|
732
|
-
@options[:size] = 18
|
733
|
-
@text_box = Prawn::Text::Box.new(@text, @options)
|
734
|
-
remaining_text = @text_box.render
|
735
|
-
expect(remaining_text).to eq("text will procede to be rendered this time by calling another method. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ")
|
736
|
-
end
|
737
|
-
end
|
738
|
-
|
739
|
-
context "expand overflow" do
|
740
|
-
before(:each) do
|
741
|
-
@options[:overflow] = :expand
|
742
|
-
@text_box = Prawn::Text::Box.new(@text, @options)
|
743
|
-
end
|
744
|
-
it "height should expand to encompass all the text (but not exceed the height of the page)" do
|
745
|
-
@text_box.render
|
746
|
-
expect(@text_box.height).to be > @bounding_height
|
747
|
-
end
|
748
|
-
it "should display the entire string (as long as there was space remaining on the page to print all the text)" do
|
749
|
-
@text_box.render
|
750
|
-
expect(@text_box.text.gsub("\n", " ")).to eq(@text.strip)
|
751
|
-
end
|
752
|
-
it "render should return an empty string because no text remains unprinted(as long as there was space remaining on the page to print all the text)" do
|
753
|
-
expect(@text_box.render).to eq("")
|
754
|
-
end
|
755
|
-
end
|
756
|
-
|
757
|
-
context "shrink_to_fit overflow" do
|
758
|
-
before(:each) do
|
759
|
-
@options[:overflow] = :shrink_to_fit
|
760
|
-
@options[:min_font_size] = 2
|
761
|
-
@text_box = Prawn::Text::Box.new(@text, @options)
|
762
|
-
end
|
763
|
-
it "should display the entire text" do
|
764
|
-
@text_box.render
|
765
|
-
expect(@text_box.text.gsub("\n", " ")).to eq(@text.strip)
|
766
|
-
end
|
767
|
-
it "render should return an empty string because no text remains unprinted" do
|
768
|
-
expect(@text_box.render).to eq("")
|
769
|
-
end
|
770
|
-
end
|
771
|
-
|
772
|
-
context "shrink_to_fit overflow" do
|
773
|
-
it "should not drop below the minimum font size" do
|
774
|
-
@options[:overflow] = :shrink_to_fit
|
775
|
-
@options[:min_font_size] = 10.1
|
776
|
-
@text_box = Prawn::Text::Box.new(@text, @options)
|
777
|
-
@text_box.render
|
778
|
-
|
779
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
780
|
-
expect(text.font_settings[0][:size]).to eq(10.1)
|
781
|
-
end
|
782
|
-
end
|
783
|
-
end
|
784
|
-
|
785
|
-
describe "Text::Box with enough space to fit the text but using the " \
|
786
|
-
"shrink_to_fit overflow" do
|
787
|
-
it "should not shrink the text when there is no need to" do
|
788
|
-
create_pdf
|
789
|
-
@bounding_height = 162.0
|
790
|
-
@options = {
|
791
|
-
:width => 162.0,
|
792
|
-
:height => @bounding_height,
|
793
|
-
:overflow => :shrink_to_fit,
|
794
|
-
:min_font_size => 5,
|
795
|
-
:document => @pdf
|
796
|
-
}
|
797
|
-
@text_box = Prawn::Text::Box.new("hello\nworld", @options)
|
798
|
-
@text_box.render
|
799
|
-
|
800
|
-
text = PDF::Inspector::Text.analyze(@pdf.render)
|
801
|
-
expect(text.font_settings[0][:size]).to eq(12)
|
802
|
-
end
|
803
|
-
end
|
804
|
-
|
805
|
-
describe "Text::Box with a solid block of Chinese characters" do
|
806
|
-
it "printed text should match requested text, except for newlines" do
|
807
|
-
create_pdf
|
808
|
-
@text = "写中国字" * 10
|
809
|
-
@options = {
|
810
|
-
:width => 162.0,
|
811
|
-
:height => 162.0,
|
812
|
-
:document => @pdf
|
813
|
-
}
|
814
|
-
@pdf.font "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
|
815
|
-
@options[:overflow] = :truncate
|
816
|
-
text_box = Prawn::Text::Box.new(@text, @options)
|
817
|
-
text_box.render
|
818
|
-
expect(text_box.text.gsub("\n", "")).to eq(@text)
|
819
|
-
end
|
820
|
-
end
|
821
|
-
|
822
|
-
describe "drawing bounding boxes" do
|
823
|
-
before(:each) { create_pdf }
|
824
|
-
|
825
|
-
it "should restore the margin box when bounding box exits" do
|
826
|
-
margin_box = @pdf.bounds
|
827
|
-
|
828
|
-
@pdf.text_box "Oh hai text box. " * 11, :height => @pdf.font.height * 10
|
829
|
-
|
830
|
-
expect(@pdf.bounds).to eq(margin_box)
|
831
|
-
end
|
832
|
-
end
|
833
|
-
|
834
|
-
describe "Text::Box#render with :character_spacing option" do
|
835
|
-
it "should draw the character spacing to the document" do
|
836
|
-
create_pdf
|
837
|
-
string = "hello world"
|
838
|
-
options = { :document => @pdf, :character_spacing => 10 }
|
839
|
-
text_box = Prawn::Text::Box.new(string, options)
|
840
|
-
text_box.render
|
841
|
-
contents = PDF::Inspector::Text.analyze(@pdf.render)
|
842
|
-
expect(contents.character_spacing[0]).to eq(10)
|
843
|
-
end
|
844
|
-
it "should take character spacing into account when wrapping" do
|
845
|
-
create_pdf
|
846
|
-
@pdf.font "Courier"
|
847
|
-
text_box = Prawn::Text::Box.new("hello world",
|
848
|
-
:width => 100,
|
849
|
-
:overflow => :expand,
|
850
|
-
:character_spacing => 10,
|
851
|
-
:document => @pdf)
|
852
|
-
text_box.render
|
853
|
-
expect(text_box.text).to eq("hello\nworld")
|
854
|
-
end
|
855
|
-
end
|
856
|
-
|
857
|
-
describe "Text::Box wrapping" do
|
858
|
-
before(:each) do
|
859
|
-
create_pdf
|
860
|
-
end
|
861
|
-
|
862
|
-
it "should wrap text" do
|
863
|
-
text = "Please wrap this text about HERE. More text that should be wrapped"
|
864
|
-
expect = "Please wrap this text about\nHERE. More text that should be\nwrapped"
|
865
|
-
|
866
|
-
@pdf.font "Courier"
|
867
|
-
text_box = Prawn::Text::Box.new(text,
|
868
|
-
:width => 220,
|
869
|
-
:overflow => :expand,
|
870
|
-
:document => @pdf)
|
871
|
-
text_box.render
|
872
|
-
expect(text_box.text).to eq(expect)
|
873
|
-
end
|
874
|
-
|
875
|
-
# white space was being stripped after the entire line was generated, meaning
|
876
|
-
# that leading white space characters reduced the amount of space on the line
|
877
|
-
# for other characters, so wrapping "hello hello" resulted in
|
878
|
-
# "hello\n\nhello", rather than "hello\nhello"
|
879
|
-
#
|
880
|
-
it "white space at beginning of line should not be taken into account when" \
|
881
|
-
" computing line width" do
|
882
|
-
text = "hello hello"
|
883
|
-
expect = "hello\nhello"
|
884
|
-
|
885
|
-
@pdf.font "Courier"
|
886
|
-
text_box = Prawn::Text::Box.new(text,
|
887
|
-
:width => 40,
|
888
|
-
:overflow => :expand,
|
889
|
-
:document => @pdf)
|
890
|
-
text_box.render
|
891
|
-
expect(text_box.text).to eq(expect)
|
892
|
-
end
|
893
|
-
|
894
|
-
it "should respect end of line when wrapping text" do
|
895
|
-
text = "Please wrap only before\nTHIS word. Don't wrap this"
|
896
|
-
expect = text
|
897
|
-
|
898
|
-
@pdf.font "Courier"
|
899
|
-
text_box = Prawn::Text::Box.new(text,
|
900
|
-
:width => 220,
|
901
|
-
:overflow => :expand,
|
902
|
-
:document => @pdf)
|
903
|
-
text_box.render
|
904
|
-
expect(text_box.text).to eq(expect)
|
905
|
-
end
|
906
|
-
|
907
|
-
it "should respect multiple newlines when wrapping text" do
|
908
|
-
text = "Please wrap only before THIS\n\nword. Don't wrap this"
|
909
|
-
expect = "Please wrap only before\nTHIS\n\nword. Don't wrap this"
|
910
|
-
|
911
|
-
@pdf.font "Courier"
|
912
|
-
text_box = Prawn::Text::Box.new(text,
|
913
|
-
:width => 200,
|
914
|
-
:overflow => :expand,
|
915
|
-
:document => @pdf)
|
916
|
-
text_box.render
|
917
|
-
expect(text_box.text).to eq(expect)
|
918
|
-
end
|
919
|
-
|
920
|
-
it "should respect multiple newlines when wrapping text when those newlines coincide with a line break" do
|
921
|
-
text = "Please wrap only before\n\nTHIS word. Don't wrap this"
|
922
|
-
expect = text
|
923
|
-
|
924
|
-
@pdf.font "Courier"
|
925
|
-
text_box = Prawn::Text::Box.new(text,
|
926
|
-
:width => 220,
|
927
|
-
:overflow => :expand,
|
928
|
-
:document => @pdf)
|
929
|
-
text_box.render
|
930
|
-
expect(text_box.text).to eq(expect)
|
931
|
-
end
|
932
|
-
|
933
|
-
it "should respect initial newlines" do
|
934
|
-
text = "\nThis should be on line 2"
|
935
|
-
expect = text
|
936
|
-
|
937
|
-
@pdf.font "Courier"
|
938
|
-
text_box = Prawn::Text::Box.new(text,
|
939
|
-
:width => 220,
|
940
|
-
:overflow => :expand,
|
941
|
-
:document => @pdf)
|
942
|
-
text_box.render
|
943
|
-
expect(text_box.text).to eq(expect)
|
944
|
-
end
|
945
|
-
|
946
|
-
it "should wrap lines comprised of a single word of the bounds when wrapping text" do
|
947
|
-
text = "You_can_wrap_this_text_HERE"
|
948
|
-
expect = "You_can_wrap_this_text_HE\nRE"
|
949
|
-
|
950
|
-
@pdf.font "Courier"
|
951
|
-
text_box = Prawn::Text::Box.new(text,
|
952
|
-
:width => 180,
|
953
|
-
:overflow => :expand,
|
954
|
-
:document => @pdf)
|
955
|
-
text_box.render
|
956
|
-
expect(text_box.text).to eq(expect)
|
957
|
-
end
|
958
|
-
|
959
|
-
it "should wrap lines comprised of a single word of the bounds when wrapping text" do
|
960
|
-
text = "©" * 30
|
961
|
-
|
962
|
-
@pdf.font "Courier"
|
963
|
-
text_box = Prawn::Text::Box.new(text, :width => 180,
|
964
|
-
:overflow => :expand,
|
965
|
-
:document => @pdf)
|
966
|
-
|
967
|
-
text_box.render
|
968
|
-
|
969
|
-
expected = "©" * 25 + "\n" + "©" * 5
|
970
|
-
@pdf.font.normalize_encoding!(expected)
|
971
|
-
expected = expected.force_encoding(Encoding::UTF_8)
|
972
|
-
expect(text_box.text).to eq(expected)
|
973
|
-
end
|
974
|
-
|
975
|
-
it "should wrap non-unicode strings using single-byte word-wrapping" do
|
976
|
-
text = "continúa esforzandote " * 5
|
977
|
-
text_box = Prawn::Text::Box.new(text, :width => 180,
|
978
|
-
:document => @pdf)
|
979
|
-
text_box.render
|
980
|
-
results_with_accent = text_box.text
|
981
|
-
|
982
|
-
text = "continua esforzandote " * 5
|
983
|
-
text_box = Prawn::Text::Box.new(text, :width => 180,
|
984
|
-
:document => @pdf)
|
985
|
-
text_box.render
|
986
|
-
results_without_accent = text_box.text
|
987
|
-
|
988
|
-
expect(first_line(results_with_accent).length).to eq(first_line(results_without_accent).length)
|
989
|
-
end
|
990
|
-
|
991
|
-
it "should allow you to disable wrapping by char" do
|
992
|
-
text = "You_cannot_wrap_this_text_at_all_because_we_are_disabling_wrapping_by_char_and_there_are_no_word_breaks"
|
993
|
-
|
994
|
-
@pdf.font "Courier"
|
995
|
-
text_box = Prawn::Text::Box.new(text,
|
996
|
-
:width => 180,
|
997
|
-
:overflow => :shrink_to_fit,
|
998
|
-
:disable_wrap_by_char => true,
|
999
|
-
:document => @pdf)
|
1000
|
-
expect { text_box.render }.to raise_error(Prawn::Errors::CannotFit)
|
1001
|
-
end
|
1002
|
-
|
1003
|
-
it "should retain full words with :shrink_to_fit if char wrapping is disabled" do
|
1004
|
-
text = "Wrapped_words"
|
1005
|
-
expect = "Wrapped_words"
|
1006
|
-
|
1007
|
-
@pdf.font "Courier"
|
1008
|
-
text_box = Prawn::Text::Box.new(text,
|
1009
|
-
:width => 50,
|
1010
|
-
:height => 50,
|
1011
|
-
:size => 50,
|
1012
|
-
:overflow => :shrink_to_fit,
|
1013
|
-
:disable_wrap_by_char => true,
|
1014
|
-
:document => @pdf)
|
1015
|
-
text_box.render
|
1016
|
-
expect(text_box.text).to eq(expect)
|
1017
|
-
end
|
1018
|
-
end
|
1019
|
-
|
1020
|
-
describe "Text::Box#render with :mode option" do
|
1021
|
-
it "should alter the text rendering mode of the document" do
|
1022
|
-
create_pdf
|
1023
|
-
string = "hello world"
|
1024
|
-
options = { :document => @pdf, :mode => :fill_stroke }
|
1025
|
-
text_box = Prawn::Text::Box.new(string, options)
|
1026
|
-
text_box.render
|
1027
|
-
contents = PDF::Inspector::Text.analyze(@pdf.render)
|
1028
|
-
expect(contents.text_rendering_mode).to eq([2, 0])
|
1029
|
-
end
|
1030
|
-
end
|
1031
|
-
|
1032
|
-
def reduce_precision(float)
|
1033
|
-
("%.5f" % float).to_f
|
1034
|
-
end
|
1035
|
-
|
1036
|
-
def first_line(str)
|
1037
|
-
str.each_line { |line| return line }
|
1038
|
-
end
|