piglop-prawn 0.10.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +340 -0
- data/HACKING +49 -0
- data/LICENSE +56 -0
- data/README +140 -0
- data/Rakefile +52 -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/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/hexagon.pdf +61 -0
- data/data/pdfs/indirect_reference.pdf +86 -0
- data/data/pdfs/nested_pages.pdf +118 -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/examples/bounding_box/bounding_boxes.rb +43 -0
- data/examples/bounding_box/indentation.rb +34 -0
- data/examples/bounding_box/russian_boxes.rb +36 -0
- data/examples/bounding_box/stretched_nesting.rb +67 -0
- data/examples/example_helper.rb +4 -0
- data/examples/general/background.rb +23 -0
- data/examples/general/canvas.rb +15 -0
- data/examples/general/context_sensitive_headers.rb +37 -0
- data/examples/general/float.rb +11 -0
- data/examples/general/margin.rb +36 -0
- data/examples/general/measurement_units.rb +51 -0
- data/examples/general/metadata-info.rb +16 -0
- data/examples/general/multi_page_layout.rb +18 -0
- data/examples/general/outlines.rb +50 -0
- data/examples/general/page_geometry.rb +31 -0
- data/examples/general/page_numbering.rb +15 -0
- data/examples/general/repeaters.rb +47 -0
- data/examples/general/stamp.rb +41 -0
- data/examples/general/templates.rb +13 -0
- data/examples/graphics/basic_images.rb +23 -0
- data/examples/graphics/cmyk.rb +12 -0
- data/examples/graphics/curves.rb +11 -0
- data/examples/graphics/hexagon.rb +13 -0
- data/examples/graphics/image_fit.rb +15 -0
- data/examples/graphics/image_flow.rb +37 -0
- data/examples/graphics/image_position.rb +17 -0
- data/examples/graphics/line.rb +32 -0
- data/examples/graphics/png_types.rb +22 -0
- data/examples/graphics/polygons.rb +16 -0
- data/examples/graphics/remote_images.rb +12 -0
- data/examples/graphics/rounded_polygons.rb +19 -0
- data/examples/graphics/rounded_rectangle.rb +20 -0
- data/examples/graphics/ruport_style_helpers.rb +19 -0
- data/examples/graphics/stroke_bounds.rb +20 -0
- data/examples/graphics/stroke_cap_and_join.rb +45 -0
- data/examples/graphics/stroke_dash.rb +42 -0
- data/examples/graphics/transformations.rb +52 -0
- data/examples/graphics/transparency.rb +26 -0
- data/examples/m17n/chinese_text_wrapping.rb +17 -0
- data/examples/m17n/euro.rb +15 -0
- data/examples/m17n/sjis.rb +28 -0
- data/examples/m17n/utf8.rb +13 -0
- data/examples/m17n/win_ansi_charset.rb +54 -0
- data/examples/security/hello_foo.rb +8 -0
- data/examples/table/bill.rb +53 -0
- data/examples/table/cell.rb +12 -0
- data/examples/table/checkerboard.rb +22 -0
- data/examples/table/header.rb +14 -0
- data/examples/table/inline_format_table.rb +12 -0
- data/examples/table/multi_page_table.rb +9 -0
- data/examples/table/simple_table.rb +24 -0
- data/examples/table/subtable.rb +12 -0
- data/examples/table/widths.rb +20 -0
- data/examples/text/alignment.rb +18 -0
- data/examples/text/dfont.rb +48 -0
- data/examples/text/family_based_styling.rb +24 -0
- data/examples/text/font_calculations.rb +91 -0
- data/examples/text/font_size.rb +33 -0
- data/examples/text/hyphenation.rb +45 -0
- data/examples/text/indent_paragraphs.rb +18 -0
- data/examples/text/inline_format.rb +72 -0
- data/examples/text/kerning.rb +30 -0
- data/examples/text/rotated.rb +98 -0
- data/examples/text/shaped_text_box.rb +31 -0
- data/examples/text/simple_text.rb +17 -0
- data/examples/text/simple_text_ttf.rb +17 -0
- data/examples/text/text_box.rb +88 -0
- data/examples/text/text_box_returning_excess.rb +51 -0
- data/examples/text/text_flow.rb +67 -0
- data/lib/prawn/compatibility.rb +51 -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 +84 -0
- data/lib/prawn/core/literal_string.rb +16 -0
- data/lib/prawn/core/name_tree.rb +165 -0
- data/lib/prawn/core/object_store.rb +219 -0
- data/lib/prawn/core/page.rb +179 -0
- data/lib/prawn/core/pdf_object.rb +83 -0
- data/lib/prawn/core/reference.rb +112 -0
- data/lib/prawn/core/text/formatted/arranger.rb +260 -0
- data/lib/prawn/core/text/formatted/line_wrap.rb +127 -0
- data/lib/prawn/core/text/formatted/wrap.rb +113 -0
- data/lib/prawn/core/text/line_wrap.rb +198 -0
- data/lib/prawn/core/text/wrap.rb +80 -0
- data/lib/prawn/core/text.rb +115 -0
- data/lib/prawn/core.rb +89 -0
- data/lib/prawn/document/bounding_box.rb +425 -0
- data/lib/prawn/document/graphics_state.rb +48 -0
- data/lib/prawn/document/internals.rb +176 -0
- data/lib/prawn/document/page_geometry.rb +136 -0
- data/lib/prawn/document/snapshot.rb +87 -0
- data/lib/prawn/document.rb +573 -0
- data/lib/prawn/encoding.rb +121 -0
- data/lib/prawn/errors.rb +94 -0
- data/lib/prawn/font/afm.rb +225 -0
- data/lib/prawn/font/dfont.rb +42 -0
- data/lib/prawn/font/ttf.rb +350 -0
- data/lib/prawn/font.rb +342 -0
- data/lib/prawn/graphics/cap_style.rb +38 -0
- data/lib/prawn/graphics/color.rb +205 -0
- data/lib/prawn/graphics/dash.rb +71 -0
- data/lib/prawn/graphics/join_style.rb +38 -0
- data/lib/prawn/graphics/transformation.rb +156 -0
- data/lib/prawn/graphics/transparency.rb +99 -0
- data/lib/prawn/graphics.rb +321 -0
- data/lib/prawn/images/jpg.rb +46 -0
- data/lib/prawn/images/png.rb +226 -0
- data/lib/prawn/images.rb +348 -0
- data/lib/prawn/measurement_extensions.rb +46 -0
- data/lib/prawn/measurements.rb +71 -0
- data/lib/prawn/outline.rb +278 -0
- data/lib/prawn/repeater.rb +129 -0
- data/lib/prawn/security/arcfour.rb +51 -0
- data/lib/prawn/security.rb +262 -0
- data/lib/prawn/stamp.rb +126 -0
- data/lib/prawn/table/accessors.rb +180 -0
- data/lib/prawn/table/cell/in_table.rb +27 -0
- data/lib/prawn/table/cell/subtable.rb +65 -0
- data/lib/prawn/table/cell/text.rb +128 -0
- data/lib/prawn/table/cell.rb +330 -0
- data/lib/prawn/table.rb +421 -0
- data/lib/prawn/text/box.rb +380 -0
- data/lib/prawn/text/formatted/box.rb +215 -0
- data/lib/prawn/text/formatted/fragment.rb +127 -0
- data/lib/prawn/text/formatted/parser.rb +202 -0
- data/lib/prawn/text/formatted.rb +4 -0
- data/lib/prawn/text.rb +442 -0
- data/lib/prawn.rb +25 -0
- data/spec/annotations_spec.rb +90 -0
- data/spec/bounding_box_spec.rb +190 -0
- data/spec/cell_spec.rb +337 -0
- data/spec/destinations_spec.rb +15 -0
- data/spec/document_spec.rb +461 -0
- data/spec/font_spec.rb +314 -0
- data/spec/formatted_text_arranger_spec.rb +400 -0
- data/spec/formatted_text_box_spec.rb +659 -0
- data/spec/formatted_text_fragment_spec.rb +211 -0
- data/spec/graphics_spec.rb +446 -0
- data/spec/images_spec.rb +96 -0
- data/spec/inline_formatted_text_parser_spec.rb +446 -0
- data/spec/jpg_spec.rb +25 -0
- data/spec/line_wrap_spec.rb +341 -0
- data/spec/measurement_units_spec.rb +23 -0
- data/spec/name_tree_spec.rb +112 -0
- data/spec/object_store_spec.rb +160 -0
- data/spec/outline_spec.rb +229 -0
- data/spec/pdf_object_spec.rb +127 -0
- data/spec/png_spec.rb +237 -0
- data/spec/reference_spec.rb +82 -0
- data/spec/repeater_spec.rb +96 -0
- data/spec/security_spec.rb +120 -0
- data/spec/snapshot_spec.rb +138 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/stamp_spec.rb +108 -0
- data/spec/stroke_styles_spec.rb +163 -0
- data/spec/table_spec.rb +583 -0
- data/spec/template_spec.rb +158 -0
- data/spec/text_at_spec.rb +119 -0
- data/spec/text_box_spec.rb +675 -0
- data/spec/text_spacing_spec.rb +57 -0
- data/spec/text_spec.rb +328 -0
- data/spec/text_with_inline_formatting_spec.rb +193 -0
- data/spec/transparency_spec.rb +75 -0
- data/vendor/pdf-inspector/README +18 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/extgstate.rb +18 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/graphics.rb +131 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/page.rb +25 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/text.rb +46 -0
- data/vendor/pdf-inspector/lib/pdf/inspector/xobject.rb +19 -0
- data/vendor/pdf-inspector/lib/pdf/inspector.rb +26 -0
- data/vendor/ttfunk/data/fonts/DejaVuSans.ttf +0 -0
- data/vendor/ttfunk/data/fonts/comicsans.ttf +0 -0
- data/vendor/ttfunk/example.rb +45 -0
- data/vendor/ttfunk/lib/ttfunk/directory.rb +17 -0
- data/vendor/ttfunk/lib/ttfunk/encoding/mac_roman.rb +88 -0
- data/vendor/ttfunk/lib/ttfunk/encoding/windows_1252.rb +69 -0
- data/vendor/ttfunk/lib/ttfunk/reader.rb +44 -0
- data/vendor/ttfunk/lib/ttfunk/resource_file.rb +78 -0
- data/vendor/ttfunk/lib/ttfunk/subset/base.rb +141 -0
- data/vendor/ttfunk/lib/ttfunk/subset/mac_roman.rb +50 -0
- data/vendor/ttfunk/lib/ttfunk/subset/unicode.rb +48 -0
- data/vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb +63 -0
- data/vendor/ttfunk/lib/ttfunk/subset/windows_1252.rb +55 -0
- data/vendor/ttfunk/lib/ttfunk/subset.rb +18 -0
- data/vendor/ttfunk/lib/ttfunk/subset_collection.rb +72 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap/format00.rb +54 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap/format04.rb +126 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap/subtable.rb +79 -0
- data/vendor/ttfunk/lib/ttfunk/table/cmap.rb +34 -0
- data/vendor/ttfunk/lib/ttfunk/table/glyf/compound.rb +81 -0
- data/vendor/ttfunk/lib/ttfunk/table/glyf/simple.rb +37 -0
- data/vendor/ttfunk/lib/ttfunk/table/glyf.rb +64 -0
- data/vendor/ttfunk/lib/ttfunk/table/head.rb +44 -0
- data/vendor/ttfunk/lib/ttfunk/table/hhea.rb +41 -0
- data/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +47 -0
- data/vendor/ttfunk/lib/ttfunk/table/kern/format0.rb +62 -0
- data/vendor/ttfunk/lib/ttfunk/table/kern.rb +79 -0
- data/vendor/ttfunk/lib/ttfunk/table/loca.rb +43 -0
- data/vendor/ttfunk/lib/ttfunk/table/maxp.rb +40 -0
- data/vendor/ttfunk/lib/ttfunk/table/name.rb +125 -0
- data/vendor/ttfunk/lib/ttfunk/table/os2.rb +78 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format10.rb +43 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format20.rb +35 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format25.rb +23 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format30.rb +17 -0
- data/vendor/ttfunk/lib/ttfunk/table/post/format40.rb +17 -0
- data/vendor/ttfunk/lib/ttfunk/table/post.rb +91 -0
- data/vendor/ttfunk/lib/ttfunk/table/simple.rb +14 -0
- data/vendor/ttfunk/lib/ttfunk/table.rb +46 -0
- data/vendor/ttfunk/lib/ttfunk.rb +102 -0
- metadata +364 -0
@@ -0,0 +1,675 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
|
5
|
+
describe "Text::Box#extensions" do
|
6
|
+
it "should be able to override default line wrapping" do
|
7
|
+
create_pdf
|
8
|
+
Prawn::Text::Box.extensions << TestWrapOverride
|
9
|
+
@pdf.text_box("hello world", {})
|
10
|
+
text = PDF::Inspector::Text.analyze(@pdf.render)
|
11
|
+
text.strings[0].should == "all your base are belong to us"
|
12
|
+
Prawn::Text::Box.extensions.delete(TestWrapOverride)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "Text::Box#render with :align => :justify" do
|
17
|
+
it "should draw the character spacing to the document" do
|
18
|
+
create_pdf
|
19
|
+
string = "hello world " * 10
|
20
|
+
options = { :document => @pdf, :align => :justify }
|
21
|
+
text_box = Prawn::Text::Box.new(string, options)
|
22
|
+
text_box.render
|
23
|
+
contents = PDF::Inspector::Text.analyze(@pdf.render)
|
24
|
+
contents.word_spacing[0].should.be > 0
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "Text::Box#height without leading" do
|
29
|
+
it "should equal the sum of the height of each line" do
|
30
|
+
create_pdf
|
31
|
+
text = "Oh hai text rect.\nOh hai text rect."
|
32
|
+
options = { :document => @pdf }
|
33
|
+
text_box = Prawn::Text::Box.new(text, options)
|
34
|
+
text_box.render
|
35
|
+
text_box.height.should == @pdf.font.height * 2
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "Text::Box#height with leading" do
|
40
|
+
it "should equal the sum of the height of each line" do
|
41
|
+
create_pdf
|
42
|
+
text = "Oh hai text rect.\nOh hai text rect."
|
43
|
+
leading = 12
|
44
|
+
options = { :document => @pdf, :leading => leading }
|
45
|
+
text_box = Prawn::Text::Box.new(text, options)
|
46
|
+
text_box.render
|
47
|
+
text_box.height.should == @pdf.font.height * 2 + leading
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "Text::Box#valid_options" do
|
52
|
+
it "should return an array" do
|
53
|
+
create_pdf
|
54
|
+
text_box = Prawn::Text::Box.new("", :document => @pdf)
|
55
|
+
text_box.valid_options.should.be.kind_of(Array)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "Text::Box#render" do
|
60
|
+
it "should not fail if height is smaller than 1 line" do
|
61
|
+
create_pdf
|
62
|
+
@text = "Oh hai text rect. " * 10
|
63
|
+
@options = {
|
64
|
+
:height => @pdf.font.height * 0.5,
|
65
|
+
:document => @pdf
|
66
|
+
}
|
67
|
+
text_box = Prawn::Text::Box.new(@text, @options)
|
68
|
+
text_box.render
|
69
|
+
text_box.text.should == ""
|
70
|
+
end
|
71
|
+
it "should draw content to the page" do
|
72
|
+
create_pdf
|
73
|
+
@text = "Oh hai text rect. " * 10
|
74
|
+
@options = { :document => @pdf }
|
75
|
+
text_box = Prawn::Text::Box.new(@text, @options)
|
76
|
+
text_box.render
|
77
|
+
text = PDF::Inspector::Text.analyze(@pdf.render)
|
78
|
+
text.strings.should.not.be.empty
|
79
|
+
end
|
80
|
+
it "should not draw a transformation matrix" do
|
81
|
+
create_pdf
|
82
|
+
@text = "Oh hai text rect. " * 10
|
83
|
+
@options = { :document => @pdf }
|
84
|
+
text_box = Prawn::Text::Box.new(@text, @options)
|
85
|
+
text_box.render
|
86
|
+
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
87
|
+
matrices.matrices.length.should == 0
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "Text::Box#render(:single_line => true)" do
|
92
|
+
it "should draw only one line to the page" do
|
93
|
+
create_pdf
|
94
|
+
@text = "Oh hai text rect. " * 10
|
95
|
+
@options = { :document => @pdf,
|
96
|
+
:single_line => true }
|
97
|
+
text_box = Prawn::Text::Box.new(@text, @options)
|
98
|
+
text_box.render
|
99
|
+
text = PDF::Inspector::Text.analyze(@pdf.render)
|
100
|
+
text.strings.length.should == 1
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "Text::Box#render(:dry_run => true)" do
|
105
|
+
it "should not draw any content to the page" do
|
106
|
+
create_pdf
|
107
|
+
@text = "Oh hai text rect. " * 10
|
108
|
+
@options = { :document => @pdf }
|
109
|
+
text_box = Prawn::Text::Box.new(@text, @options)
|
110
|
+
text_box.render(:dry_run => true)
|
111
|
+
text = PDF::Inspector::Text.analyze(@pdf.render)
|
112
|
+
text.strings.should.be.empty
|
113
|
+
end
|
114
|
+
it "subsequent calls to render should not raise an ArgumentError exception" do
|
115
|
+
create_pdf
|
116
|
+
@text = "™©"
|
117
|
+
@options = { :document => @pdf }
|
118
|
+
text_box = Prawn::Text::Box.new(@text, @options)
|
119
|
+
text_box.render(:dry_run => true)
|
120
|
+
lambda { text_box.render }.should.not.raise(ArgumentError)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "Text::Box#render with :rotate option of 30)" do
|
125
|
+
before(:each) do
|
126
|
+
create_pdf
|
127
|
+
rotate = 30
|
128
|
+
@x = 300
|
129
|
+
@y = 70
|
130
|
+
@width = 100
|
131
|
+
@height = 50
|
132
|
+
@cos = Math.cos(rotate * Math::PI / 180)
|
133
|
+
@sin = Math.sin(rotate * Math::PI / 180)
|
134
|
+
@text = "Oh hai text rect. " * 10
|
135
|
+
@options = { :document => @pdf,
|
136
|
+
:rotate => rotate,
|
137
|
+
:at => [@x, @y],
|
138
|
+
:width => @width,
|
139
|
+
:height => @height }
|
140
|
+
end
|
141
|
+
context ":rotate_around option of :center" do
|
142
|
+
it "should draw content to the page rotated about the center of the text" do
|
143
|
+
@options[:rotate_around] = :center
|
144
|
+
text_box = Prawn::Text::Box.new(@text, @options)
|
145
|
+
text_box.render
|
146
|
+
|
147
|
+
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
148
|
+
x = @x + @width / 2
|
149
|
+
y = @y - @height / 2
|
150
|
+
x_prime = x * @cos - y * @sin
|
151
|
+
y_prime = x * @sin + y * @cos
|
152
|
+
matrices.matrices[0].should == [1, 0, 0, 1,
|
153
|
+
reduce_precision(x - x_prime),
|
154
|
+
reduce_precision(y - y_prime)]
|
155
|
+
matrices.matrices[1].should == [reduce_precision(@cos),
|
156
|
+
reduce_precision(@sin),
|
157
|
+
reduce_precision(-@sin),
|
158
|
+
reduce_precision(@cos), 0, 0]
|
159
|
+
|
160
|
+
text = PDF::Inspector::Text.analyze(@pdf.render)
|
161
|
+
text.strings.should.not.be.empty
|
162
|
+
end
|
163
|
+
end
|
164
|
+
context ":rotate_around option of :upper_left" do
|
165
|
+
it "should draw content to the page rotated about the upper left corner of the text" do
|
166
|
+
@options[:rotate_around] = :upper_left
|
167
|
+
text_box = Prawn::Text::Box.new(@text, @options)
|
168
|
+
text_box.render
|
169
|
+
|
170
|
+
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
171
|
+
x = @x
|
172
|
+
y = @y
|
173
|
+
x_prime = x * @cos - y * @sin
|
174
|
+
y_prime = x * @sin + y * @cos
|
175
|
+
matrices.matrices[0].should == [1, 0, 0, 1,
|
176
|
+
reduce_precision(x - x_prime),
|
177
|
+
reduce_precision(y - y_prime)]
|
178
|
+
matrices.matrices[1].should == [reduce_precision(@cos),
|
179
|
+
reduce_precision(@sin),
|
180
|
+
reduce_precision(-@sin),
|
181
|
+
reduce_precision(@cos), 0, 0]
|
182
|
+
|
183
|
+
text = PDF::Inspector::Text.analyze(@pdf.render)
|
184
|
+
text.strings.should.not.be.empty
|
185
|
+
end
|
186
|
+
end
|
187
|
+
context "default :rotate_around" do
|
188
|
+
it "should draw content to the page rotated about the upper left corner of the text" do
|
189
|
+
text_box = Prawn::Text::Box.new(@text, @options)
|
190
|
+
text_box.render
|
191
|
+
|
192
|
+
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
193
|
+
x = @x
|
194
|
+
y = @y
|
195
|
+
x_prime = x * @cos - y * @sin
|
196
|
+
y_prime = x * @sin + y * @cos
|
197
|
+
matrices.matrices[0].should == [1, 0, 0, 1,
|
198
|
+
reduce_precision(x - x_prime),
|
199
|
+
reduce_precision(y - y_prime)]
|
200
|
+
matrices.matrices[1].should == [reduce_precision(@cos),
|
201
|
+
reduce_precision(@sin),
|
202
|
+
reduce_precision(-@sin),
|
203
|
+
reduce_precision(@cos), 0, 0]
|
204
|
+
|
205
|
+
text = PDF::Inspector::Text.analyze(@pdf.render)
|
206
|
+
text.strings.should.not.be.empty
|
207
|
+
end
|
208
|
+
end
|
209
|
+
context ":rotate_around option of :upper_right" do
|
210
|
+
it "should draw content to the page rotated about the upper right corner of the text" do
|
211
|
+
@options[:rotate_around] = :upper_right
|
212
|
+
text_box = Prawn::Text::Box.new(@text, @options)
|
213
|
+
text_box.render
|
214
|
+
|
215
|
+
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
216
|
+
x = @x + @width
|
217
|
+
y = @y
|
218
|
+
x_prime = x * @cos - y * @sin
|
219
|
+
y_prime = x * @sin + y * @cos
|
220
|
+
matrices.matrices[0].should == [1, 0, 0, 1,
|
221
|
+
reduce_precision(x - x_prime),
|
222
|
+
reduce_precision(y - y_prime)]
|
223
|
+
matrices.matrices[1].should == [reduce_precision(@cos),
|
224
|
+
reduce_precision(@sin),
|
225
|
+
reduce_precision(-@sin),
|
226
|
+
reduce_precision(@cos), 0, 0]
|
227
|
+
|
228
|
+
text = PDF::Inspector::Text.analyze(@pdf.render)
|
229
|
+
text.strings.should.not.be.empty
|
230
|
+
end
|
231
|
+
end
|
232
|
+
context ":rotate_around option of :lower_right" do
|
233
|
+
it "should draw content to the page rotated about the lower right corner of the text" do
|
234
|
+
@options[:rotate_around] = :lower_right
|
235
|
+
text_box = Prawn::Text::Box.new(@text, @options)
|
236
|
+
text_box.render
|
237
|
+
|
238
|
+
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
239
|
+
x = @x + @width
|
240
|
+
y = @y - @height
|
241
|
+
x_prime = x * @cos - y * @sin
|
242
|
+
y_prime = x * @sin + y * @cos
|
243
|
+
matrices.matrices[0].should == [1, 0, 0, 1,
|
244
|
+
reduce_precision(x - x_prime),
|
245
|
+
reduce_precision(y - y_prime)]
|
246
|
+
matrices.matrices[1].should == [reduce_precision(@cos),
|
247
|
+
reduce_precision(@sin),
|
248
|
+
reduce_precision(-@sin),
|
249
|
+
reduce_precision(@cos), 0, 0]
|
250
|
+
|
251
|
+
text = PDF::Inspector::Text.analyze(@pdf.render)
|
252
|
+
text.strings.should.not.be.empty
|
253
|
+
end
|
254
|
+
end
|
255
|
+
context ":rotate_around option of :lower_left" do
|
256
|
+
it "should draw content to the page rotated about the lower left corner of the text" do
|
257
|
+
@options[:rotate_around] = :lower_left
|
258
|
+
text_box = Prawn::Text::Box.new(@text, @options)
|
259
|
+
text_box.render
|
260
|
+
|
261
|
+
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
262
|
+
x = @x
|
263
|
+
y = @y - @height
|
264
|
+
x_prime = x * @cos - y * @sin
|
265
|
+
y_prime = x * @sin + y * @cos
|
266
|
+
matrices.matrices[0].should == [1, 0, 0, 1,
|
267
|
+
reduce_precision(x - x_prime),
|
268
|
+
reduce_precision(y - y_prime)]
|
269
|
+
matrices.matrices[1].should == [reduce_precision(@cos),
|
270
|
+
reduce_precision(@sin),
|
271
|
+
reduce_precision(-@sin),
|
272
|
+
reduce_precision(@cos), 0, 0]
|
273
|
+
|
274
|
+
text = PDF::Inspector::Text.analyze(@pdf.render)
|
275
|
+
text.strings.should.not.be.empty
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
describe "Text::Box default height" do
|
281
|
+
it "should be the height from the bottom bound to document.y" do
|
282
|
+
create_pdf
|
283
|
+
target_height = @pdf.y - @pdf.bounds.bottom
|
284
|
+
@text = "Oh hai\n" * 60
|
285
|
+
@options = { :document => @pdf }
|
286
|
+
text_box = Prawn::Text::Box.new(@text, @options)
|
287
|
+
text_box.render
|
288
|
+
text_box.height.should.be.close(target_height, @pdf.font.height)
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
describe "Text::Box default at" do
|
293
|
+
it "should be the left corner of the bounds, and the current document.y" do
|
294
|
+
create_pdf
|
295
|
+
target_at = [@pdf.bounds.left, @pdf.y]
|
296
|
+
@text = "Oh hai text rect. " * 100
|
297
|
+
@options = { :document => @pdf }
|
298
|
+
text_box = Prawn::Text::Box.new(@text, @options)
|
299
|
+
text_box.render
|
300
|
+
text_box.at.should == target_at
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
describe "Text::Box with text than can fit in the box" do
|
305
|
+
before(:each) do
|
306
|
+
create_pdf
|
307
|
+
@text = "Oh hai text rect. " * 10
|
308
|
+
@options = {
|
309
|
+
:width => 162.0,
|
310
|
+
:height => 162.0,
|
311
|
+
:document => @pdf
|
312
|
+
}
|
313
|
+
end
|
314
|
+
|
315
|
+
it "printed text should match requested text, except for trailing or leading white space and that spaces may be replaced by newlines" do
|
316
|
+
text_box = Prawn::Text::Box.new(@text, @options)
|
317
|
+
text_box.render
|
318
|
+
text_box.text.gsub("\n", " ").should == @text.strip
|
319
|
+
end
|
320
|
+
|
321
|
+
it "render should return an empty string because no text remains unprinted" do
|
322
|
+
text_box = Prawn::Text::Box.new(@text, @options)
|
323
|
+
text_box.render.should == ""
|
324
|
+
end
|
325
|
+
|
326
|
+
it "should be truncated when the leading is set high enough to prevent all the lines from being printed" do
|
327
|
+
@options[:leading] = 40
|
328
|
+
text_box = Prawn::Text::Box.new(@text, @options)
|
329
|
+
text_box.render
|
330
|
+
text_box.text.gsub("\n", " ").should.not == @text.strip
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
describe "Text::Box with text than can fit in the box with :ellipses overflow and :valign => :bottom" do
|
335
|
+
it "should not print ellipses" do
|
336
|
+
create_pdf
|
337
|
+
@text = "Oh hai text rect. " * 10
|
338
|
+
@options = {
|
339
|
+
:width => 162.0,
|
340
|
+
:height => 162.0,
|
341
|
+
:overflow => :ellipses,
|
342
|
+
:valign => :bottom,
|
343
|
+
:document => @pdf
|
344
|
+
}
|
345
|
+
@text_box = Prawn::Text::Box.new(@text, @options)
|
346
|
+
@text_box.render
|
347
|
+
@text_box.text.should.not =~ /\.\.\./
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
describe "Text::Box printing UTF-8 string with higher bit characters" do
|
354
|
+
before(:each) do
|
355
|
+
create_pdf
|
356
|
+
@text = "©"
|
357
|
+
# not enough height to print any text, so we can directly compare against
|
358
|
+
# the input string
|
359
|
+
bounding_height = 1.0
|
360
|
+
options = {
|
361
|
+
:height => bounding_height,
|
362
|
+
:document => @pdf
|
363
|
+
}
|
364
|
+
file = "#{Prawn::BASEDIR}/data/fonts/Action Man.dfont"
|
365
|
+
@pdf.font_families["Action Man"] = {
|
366
|
+
:normal => { :file => file, :font => "ActionMan" },
|
367
|
+
:italic => { :file => file, :font => "ActionMan-Italic" },
|
368
|
+
:bold => { :file => file, :font => "ActionMan-Bold" },
|
369
|
+
:bold_italic => { :file => file, :font => "ActionMan-BoldItalic" }
|
370
|
+
}
|
371
|
+
@text_box = Prawn::Text::Box.new(@text, options)
|
372
|
+
end
|
373
|
+
describe "when using a TTF font" do
|
374
|
+
it "unprinted text should be in UTF-8 encoding" do
|
375
|
+
@pdf.font("Action Man")
|
376
|
+
remaining_text = @text_box.render
|
377
|
+
remaining_text.should == @text
|
378
|
+
end
|
379
|
+
it "subsequent calls to Text::Box need not include the" +
|
380
|
+
" :skip_encoding => true option" do
|
381
|
+
@pdf.font("Action Man")
|
382
|
+
remaining_text = @text_box.render
|
383
|
+
lambda {
|
384
|
+
@pdf.text_box(remaining_text, :document => @pdf)
|
385
|
+
}.should.not.raise(ArgumentError)
|
386
|
+
end
|
387
|
+
end
|
388
|
+
describe "when using an AFM font" do
|
389
|
+
it "unprinted text should be in WinAnsi encoding" do
|
390
|
+
remaining_text = @text_box.render
|
391
|
+
remaining_text.should == @pdf.font.normalize_encoding(@text)
|
392
|
+
end
|
393
|
+
it "subsequent calls to Text::Box must include the" +
|
394
|
+
" :skip_encoding => true option" do
|
395
|
+
remaining_text = @text_box.render
|
396
|
+
lambda {
|
397
|
+
@pdf.text_box(remaining_text, :document => @pdf)
|
398
|
+
}.should.raise(ArgumentError)
|
399
|
+
lambda {
|
400
|
+
@pdf.text_box(remaining_text, :skip_encoding => true,
|
401
|
+
:document => @pdf)
|
402
|
+
}.should.not.raise(ArgumentError)
|
403
|
+
end
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
|
408
|
+
describe "Text::Box with more text than can fit in the box" do
|
409
|
+
before(:each) do
|
410
|
+
create_pdf
|
411
|
+
@text = "Oh hai text rect. " * 30
|
412
|
+
@bounding_height = 162.0
|
413
|
+
@options = {
|
414
|
+
:width => 162.0,
|
415
|
+
:height => @bounding_height,
|
416
|
+
:document => @pdf
|
417
|
+
}
|
418
|
+
end
|
419
|
+
|
420
|
+
context "truncated overflow" do
|
421
|
+
before(:each) do
|
422
|
+
@options[:overflow] = :truncate
|
423
|
+
@text_box = Prawn::Text::Box.new(@text, @options)
|
424
|
+
end
|
425
|
+
it "should not display ellipses" do
|
426
|
+
@text_box.render
|
427
|
+
@text_box.text.should.not =~ /\.\.\./
|
428
|
+
end
|
429
|
+
it "should be truncated" do
|
430
|
+
@text_box.render
|
431
|
+
@text_box.text.gsub("\n", " ").should.not == @text.strip
|
432
|
+
end
|
433
|
+
it "render should not return an empty string because some text remains unprinted" do
|
434
|
+
@text_box.render.should.not == ""
|
435
|
+
end
|
436
|
+
it "#height should be no taller than the specified height" do
|
437
|
+
@text_box.render
|
438
|
+
@text_box.height.should.be <= @bounding_height
|
439
|
+
end
|
440
|
+
it "#height should be within one font height of the specified height" do
|
441
|
+
@text_box.render
|
442
|
+
@bounding_height.should.be.close(@text_box.height, @pdf.font.height)
|
443
|
+
end
|
444
|
+
context "with :rotate option" do
|
445
|
+
it "unrendered text should be the same as when not rotated" do
|
446
|
+
remaining_text = @text_box.render
|
447
|
+
|
448
|
+
rotate = 30
|
449
|
+
x = 300
|
450
|
+
y = 70
|
451
|
+
width = @options[:width]
|
452
|
+
height = @options[:height]
|
453
|
+
@options[:document] = @pdf
|
454
|
+
@options[:rotate] = rotate
|
455
|
+
@options[:at] = [x, y]
|
456
|
+
rotated_text_box = Prawn::Text::Box.new(@text, @options)
|
457
|
+
rotated_text_box.render.should == remaining_text
|
458
|
+
end
|
459
|
+
end
|
460
|
+
end
|
461
|
+
|
462
|
+
context "ellipses overflow" do
|
463
|
+
before(:each) do
|
464
|
+
@options[:overflow] = :ellipses
|
465
|
+
@text_box = Prawn::Text::Box.new(@text, @options)
|
466
|
+
end
|
467
|
+
it "should display ellipses" do
|
468
|
+
@text_box.render
|
469
|
+
@text_box.text.should =~ /\.\.\./
|
470
|
+
end
|
471
|
+
it "render should not return an empty string because some text remains unprinted" do
|
472
|
+
@text_box.render.should.not == ""
|
473
|
+
end
|
474
|
+
end
|
475
|
+
|
476
|
+
context "expand overflow" do
|
477
|
+
before(:each) do
|
478
|
+
@options[:overflow] = :expand
|
479
|
+
@text_box = Prawn::Text::Box.new(@text, @options)
|
480
|
+
end
|
481
|
+
it "height should expand to encompass all the text (but not exceed the height of the page)" do
|
482
|
+
@text_box.render
|
483
|
+
@text_box.height.should > @bounding_height
|
484
|
+
end
|
485
|
+
it "should display the entire string (as long as there was space remaining on the page to print all the text)" do
|
486
|
+
@text_box.render
|
487
|
+
@text_box.text.gsub("\n", " ").should == @text.strip
|
488
|
+
end
|
489
|
+
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
|
490
|
+
@text_box.render.should == ""
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
494
|
+
context "shrink_to_fit overflow" do
|
495
|
+
before(:each) do
|
496
|
+
@options[:overflow] = :shrink_to_fit
|
497
|
+
@options[:min_font_size] = 2
|
498
|
+
@text_box = Prawn::Text::Box.new(@text, @options)
|
499
|
+
end
|
500
|
+
it "should display the entire text" do
|
501
|
+
@text_box.render
|
502
|
+
@text_box.text.gsub("\n", " ").should == @text.strip
|
503
|
+
end
|
504
|
+
it "render should return an empty string because no text remains unprinted" do
|
505
|
+
@text_box.render.should == ""
|
506
|
+
end
|
507
|
+
end
|
508
|
+
end
|
509
|
+
|
510
|
+
describe "Text::Box with a solid block of Chinese characters" do
|
511
|
+
it "printed text should match requested text, except for newlines" do
|
512
|
+
create_pdf
|
513
|
+
@text = "写中国字" * 10
|
514
|
+
@options = {
|
515
|
+
:width => 162.0,
|
516
|
+
:height => 162.0,
|
517
|
+
:document => @pdf
|
518
|
+
}
|
519
|
+
@pdf.font "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
|
520
|
+
@options[:overflow] = :truncate
|
521
|
+
text_box = Prawn::Text::Box.new(@text, @options)
|
522
|
+
text_box.render
|
523
|
+
text_box.text.gsub("\n", "").should == @text.strip
|
524
|
+
end
|
525
|
+
end
|
526
|
+
|
527
|
+
|
528
|
+
describe "drawing bounding boxes" do
|
529
|
+
|
530
|
+
before(:each) { create_pdf }
|
531
|
+
|
532
|
+
it "should restore the margin box when bounding box exits" do
|
533
|
+
margin_box = @pdf.bounds
|
534
|
+
|
535
|
+
@pdf.text_box "Oh hai text box. " * 11, :height => @pdf.font.height * 10
|
536
|
+
|
537
|
+
@pdf.bounds.should == margin_box
|
538
|
+
|
539
|
+
end
|
540
|
+
|
541
|
+
end
|
542
|
+
|
543
|
+
|
544
|
+
describe "Text::Box wrapping" do
|
545
|
+
before(:each) do
|
546
|
+
create_pdf
|
547
|
+
end
|
548
|
+
|
549
|
+
it "should wrap text" do
|
550
|
+
text = "Please wrap this text about HERE. More text that should be wrapped"
|
551
|
+
expect = "Please wrap this text about\nHERE. More text that should be\nwrapped"
|
552
|
+
|
553
|
+
@pdf.font "Courier"
|
554
|
+
text_box = Prawn::Text::Box.new(text,
|
555
|
+
:width => 220,
|
556
|
+
:overflow => :expand,
|
557
|
+
:document => @pdf)
|
558
|
+
text_box.render
|
559
|
+
text_box.text.should == expect
|
560
|
+
end
|
561
|
+
|
562
|
+
it "should respect end of line when wrapping text" do
|
563
|
+
text = "Please wrap only before\nTHIS word. Don't wrap this"
|
564
|
+
expect = text
|
565
|
+
|
566
|
+
@pdf.font "Courier"
|
567
|
+
text_box = Prawn::Text::Box.new(text,
|
568
|
+
:width => 220,
|
569
|
+
:overflow => :expand,
|
570
|
+
:document => @pdf)
|
571
|
+
text_box.render
|
572
|
+
text_box.text.should == expect
|
573
|
+
end
|
574
|
+
|
575
|
+
it "should respect multiple newlines when wrapping text" do
|
576
|
+
text = "Please wrap only before THIS\n\nword. Don't wrap this"
|
577
|
+
expect= "Please wrap only before\nTHIS\n\nword. Don't wrap this"
|
578
|
+
|
579
|
+
@pdf.font "Courier"
|
580
|
+
text_box = Prawn::Text::Box.new(text,
|
581
|
+
:width => 200,
|
582
|
+
:overflow => :expand,
|
583
|
+
:document => @pdf)
|
584
|
+
text_box.render
|
585
|
+
text_box.text.should == expect
|
586
|
+
end
|
587
|
+
|
588
|
+
it "should respect multiple newlines when wrapping text when those newlines coincide with a line break" do
|
589
|
+
text = "Please wrap only before\n\nTHIS word. Don't wrap this"
|
590
|
+
expect = text
|
591
|
+
|
592
|
+
@pdf.font "Courier"
|
593
|
+
text_box = Prawn::Text::Box.new(text,
|
594
|
+
:width => 220,
|
595
|
+
:overflow => :expand,
|
596
|
+
:document => @pdf)
|
597
|
+
text_box.render
|
598
|
+
text_box.text.should == expect
|
599
|
+
end
|
600
|
+
|
601
|
+
it "should respect initial newlines" do
|
602
|
+
text = "\nThis should be on line 2"
|
603
|
+
expect = text
|
604
|
+
|
605
|
+
@pdf.font "Courier"
|
606
|
+
text_box = Prawn::Text::Box.new(text,
|
607
|
+
:width => 220,
|
608
|
+
:overflow => :expand,
|
609
|
+
:document => @pdf)
|
610
|
+
text_box.render
|
611
|
+
text_box.text.should == expect
|
612
|
+
end
|
613
|
+
|
614
|
+
it "should wrap lines comprised of a single word of the bounds when wrapping text" do
|
615
|
+
text = "You_can_wrap_this_text_HERE"
|
616
|
+
expect = "You_can_wrap_this_text_HE\nRE"
|
617
|
+
|
618
|
+
@pdf.font "Courier"
|
619
|
+
text_box = Prawn::Text::Box.new(text,
|
620
|
+
:width => 180,
|
621
|
+
:overflow => :expand,
|
622
|
+
:document => @pdf)
|
623
|
+
text_box.render
|
624
|
+
text_box.text.should == expect
|
625
|
+
end
|
626
|
+
|
627
|
+
it "should wrap lines comprised of a single word of the bounds when wrapping text" do
|
628
|
+
text = "©" * 30
|
629
|
+
|
630
|
+
@pdf.font "Courier"
|
631
|
+
text_box = Prawn::Text::Box.new(text, :width => 180,
|
632
|
+
:overflow => :expand,
|
633
|
+
:document => @pdf)
|
634
|
+
|
635
|
+
text_box.render
|
636
|
+
|
637
|
+
expected = "©" * 25 + "\n" + "©" * 5
|
638
|
+
@pdf.font.normalize_encoding!(expected)
|
639
|
+
|
640
|
+
text_box.text.should == expected
|
641
|
+
end
|
642
|
+
|
643
|
+
it "should wrap non-unicode strings using single-byte word-wrapping" do
|
644
|
+
text = "continúa esforzandote " * 5
|
645
|
+
text_box = Prawn::Text::Box.new(text, :width => 180,
|
646
|
+
:document => @pdf)
|
647
|
+
text_box.render
|
648
|
+
results_with_accent = text_box.text
|
649
|
+
|
650
|
+
text = "continua esforzandote " * 5
|
651
|
+
text_box = Prawn::Text::Box.new(text, :width => 180,
|
652
|
+
:document => @pdf)
|
653
|
+
text_box.render
|
654
|
+
results_without_accent = text_box.text
|
655
|
+
|
656
|
+
results_with_accent.first_line.length.should == results_without_accent.first_line.length
|
657
|
+
end
|
658
|
+
|
659
|
+
end
|
660
|
+
|
661
|
+
def reduce_precision(float)
|
662
|
+
("%.5f" % float).to_f
|
663
|
+
end
|
664
|
+
|
665
|
+
module TestWrapOverride
|
666
|
+
def wrap(string)
|
667
|
+
@text = nil
|
668
|
+
@line_height = @document.font.height
|
669
|
+
@descender = @document.font.descender
|
670
|
+
@ascender = @document.font.ascender
|
671
|
+
@baseline_y = -@ascender
|
672
|
+
draw_line("all your base are belong to us")
|
673
|
+
""
|
674
|
+
end
|
675
|
+
end
|