nurettin-prawn 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +2 -0
- data/GPLv2 +340 -0
- data/GPLv3 +674 -0
- data/Gemfile +18 -0
- data/LICENSE +56 -0
- data/README.md +98 -0
- data/Rakefile +45 -0
- data/data/encodings/win_ansi.txt +29 -0
- data/data/fonts/Action Man.dfont +0 -0
- data/data/fonts/Activa.ttf +0 -0
- data/data/fonts/Chalkboard.ttf +0 -0
- data/data/fonts/Courier-Bold.afm +342 -0
- data/data/fonts/Courier-BoldOblique.afm +342 -0
- data/data/fonts/Courier-Oblique.afm +342 -0
- data/data/fonts/Courier.afm +342 -0
- data/data/fonts/DejaVuSans.ttf +0 -0
- data/data/fonts/Dustismo_Roman.ttf +0 -0
- data/data/fonts/Helvetica-Bold.afm +2827 -0
- data/data/fonts/Helvetica-BoldOblique.afm +2827 -0
- data/data/fonts/Helvetica-Oblique.afm +3051 -0
- data/data/fonts/Helvetica.afm +3051 -0
- data/data/fonts/MustRead.html +19 -0
- data/data/fonts/Symbol.afm +213 -0
- data/data/fonts/Times-Bold.afm +2588 -0
- data/data/fonts/Times-BoldItalic.afm +2384 -0
- data/data/fonts/Times-Italic.afm +2667 -0
- data/data/fonts/Times-Roman.afm +2419 -0
- data/data/fonts/ZapfDingbats.afm +225 -0
- data/data/fonts/comicsans.ttf +0 -0
- data/data/fonts/gkai00mp.ttf +0 -0
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.dat +0 -0
- data/data/images/16bit.png +0 -0
- data/data/images/arrow.png +0 -0
- data/data/images/arrow2.png +0 -0
- data/data/images/barcode_issue.png +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.dat +0 -0
- data/data/images/dice.png +0 -0
- data/data/images/dice_interlaced.png +0 -0
- data/data/images/fractal.jpg +0 -0
- data/data/images/letterhead.jpg +0 -0
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.dat +0 -0
- data/data/images/page_white_text.png +0 -0
- data/data/images/pigs.jpg +0 -0
- data/data/images/prawn.png +0 -0
- data/data/images/rails.dat +0 -0
- data/data/images/rails.png +0 -0
- data/data/images/ruport.png +0 -0
- data/data/images/ruport_data.dat +0 -0
- data/data/images/ruport_transparent.png +0 -0
- data/data/images/ruport_type0.png +0 -0
- data/data/images/stef.jpg +0 -0
- data/data/images/tru256.bmp +0 -0
- data/data/images/web-links.dat +1 -0
- data/data/images/web-links.png +0 -0
- data/data/pdfs/complex_template.pdf +0 -0
- data/data/pdfs/contains_ttf_font.pdf +0 -0
- data/data/pdfs/encrypted.pdf +0 -0
- data/data/pdfs/form.pdf +820 -0
- data/data/pdfs/hexagon.pdf +61 -0
- data/data/pdfs/indirect_reference.pdf +86 -0
- data/data/pdfs/multipage_template.pdf +127 -0
- data/data/pdfs/nested_pages.pdf +118 -0
- data/data/pdfs/page_without_mediabox.pdf +193 -0
- data/data/pdfs/resources_as_indirect_object.pdf +83 -0
- data/data/pdfs/two_hexagons.pdf +90 -0
- data/data/pdfs/version_1_6.pdf +61 -0
- data/data/shift_jis_text.txt +1 -0
- data/lib/prawn.rb +29 -0
- data/lib/prawn/compatibility.rb +87 -0
- data/lib/prawn/core.rb +87 -0
- data/lib/prawn/core/annotations.rb +61 -0
- data/lib/prawn/core/byte_string.rb +9 -0
- data/lib/prawn/core/destinations.rb +90 -0
- data/lib/prawn/core/document_state.rb +79 -0
- data/lib/prawn/core/literal_string.rb +16 -0
- data/lib/prawn/core/name_tree.rb +177 -0
- data/lib/prawn/core/object_store.rb +320 -0
- data/lib/prawn/core/page.rb +212 -0
- data/lib/prawn/core/pdf_object.rb +125 -0
- data/lib/prawn/core/reference.rb +119 -0
- data/lib/prawn/core/text.rb +268 -0
- data/lib/prawn/core/text/formatted/arranger.rb +294 -0
- data/lib/prawn/core/text/formatted/line_wrap.rb +288 -0
- data/lib/prawn/core/text/formatted/wrap.rb +153 -0
- data/lib/prawn/document.rb +707 -0
- data/lib/prawn/document/bounding_box.rb +510 -0
- data/lib/prawn/document/column_box.rb +132 -0
- data/lib/prawn/document/graphics_state.rb +136 -0
- data/lib/prawn/document/internals.rb +173 -0
- data/lib/prawn/document/page_geometry.rb +136 -0
- data/lib/prawn/document/snapshot.rb +89 -0
- data/lib/prawn/document/span.rb +55 -0
- data/lib/prawn/encoding.rb +121 -0
- data/lib/prawn/errors.rb +99 -0
- data/lib/prawn/font.rb +386 -0
- data/lib/prawn/font/afm.rb +203 -0
- data/lib/prawn/font/dfont.rb +42 -0
- data/lib/prawn/font/ttf.rb +343 -0
- data/lib/prawn/graphics.rb +523 -0
- data/lib/prawn/graphics/cap_style.rb +46 -0
- data/lib/prawn/graphics/color.rb +231 -0
- data/lib/prawn/graphics/dash.rb +82 -0
- data/lib/prawn/graphics/join_style.rb +47 -0
- data/lib/prawn/graphics/patterns.rb +137 -0
- data/lib/prawn/graphics/transformation.rb +156 -0
- data/lib/prawn/graphics/transparency.rb +99 -0
- data/lib/prawn/images.rb +196 -0
- data/lib/prawn/images/image.rb +65 -0
- data/lib/prawn/images/jpg.rb +85 -0
- data/lib/prawn/images/png.rb +362 -0
- data/lib/prawn/layout.rb +20 -0
- data/lib/prawn/layout/grid.rb +259 -0
- data/lib/prawn/measurement_extensions.rb +46 -0
- data/lib/prawn/measurements.rb +71 -0
- data/lib/prawn/outline.rb +326 -0
- data/lib/prawn/repeater.rb +122 -0
- data/lib/prawn/security.rb +269 -0
- data/lib/prawn/soft_mask.rb +94 -0
- data/lib/prawn/stamp.rb +134 -0
- data/lib/prawn/table.rb +609 -0
- data/lib/prawn/table/cell.rb +776 -0
- data/lib/prawn/table/cell/image.rb +70 -0
- data/lib/prawn/table/cell/in_table.rb +27 -0
- data/lib/prawn/table/cell/span_dummy.rb +88 -0
- data/lib/prawn/table/cell/subtable.rb +65 -0
- data/lib/prawn/table/cell/text.rb +152 -0
- data/lib/prawn/table/cells.rb +260 -0
- data/lib/prawn/text.rb +420 -0
- data/lib/prawn/text/box.rb +141 -0
- data/lib/prawn/text/formatted.rb +4 -0
- data/lib/prawn/text/formatted/box.rb +563 -0
- data/lib/prawn/text/formatted/fragment.rb +253 -0
- data/lib/prawn/text/formatted/parser.rb +217 -0
- data/lib/prawn/utilities.rb +44 -0
- data/manual/basic_concepts/adding_pages.rb +27 -0
- data/manual/basic_concepts/basic_concepts.rb +34 -0
- data/manual/basic_concepts/creation.rb +39 -0
- data/manual/basic_concepts/cursor.rb +33 -0
- data/manual/basic_concepts/measurement.rb +25 -0
- data/manual/basic_concepts/origin.rb +38 -0
- data/manual/basic_concepts/other_cursor_helpers.rb +40 -0
- data/manual/bounding_box/bounding_box.rb +39 -0
- data/manual/bounding_box/bounds.rb +49 -0
- data/manual/bounding_box/canvas.rb +24 -0
- data/manual/bounding_box/creation.rb +23 -0
- data/manual/bounding_box/indentation.rb +46 -0
- data/manual/bounding_box/nesting.rb +45 -0
- data/manual/bounding_box/russian_boxes.rb +40 -0
- data/manual/bounding_box/stretchy.rb +31 -0
- data/manual/document_and_page_options/background.rb +27 -0
- data/manual/document_and_page_options/document_and_page_options.rb +31 -0
- data/manual/document_and_page_options/metadata.rb +23 -0
- data/manual/document_and_page_options/page_margins.rb +38 -0
- data/manual/document_and_page_options/page_size.rb +34 -0
- data/manual/example_file.rb +116 -0
- data/manual/example_helper.rb +430 -0
- data/manual/example_package.rb +53 -0
- data/manual/example_section.rb +46 -0
- data/manual/graphics/circle_and_ellipse.rb +22 -0
- data/manual/graphics/color.rb +24 -0
- data/manual/graphics/common_lines.rb +28 -0
- data/manual/graphics/fill_and_stroke.rb +42 -0
- data/manual/graphics/fill_rules.rb +37 -0
- data/manual/graphics/gradients.rb +37 -0
- data/manual/graphics/graphics.rb +58 -0
- data/manual/graphics/helper.rb +17 -0
- data/manual/graphics/line_width.rb +35 -0
- data/manual/graphics/lines_and_curves.rb +41 -0
- data/manual/graphics/polygon.rb +29 -0
- data/manual/graphics/rectangle.rb +21 -0
- data/manual/graphics/rotate.rb +28 -0
- data/manual/graphics/scale.rb +41 -0
- data/manual/graphics/soft_masks.rb +46 -0
- data/manual/graphics/stroke_cap.rb +31 -0
- data/manual/graphics/stroke_dash.rb +43 -0
- data/manual/graphics/stroke_join.rb +30 -0
- data/manual/graphics/translate.rb +29 -0
- data/manual/graphics/transparency.rb +35 -0
- data/manual/images/absolute_position.rb +23 -0
- data/manual/images/fit.rb +21 -0
- data/manual/images/horizontal.rb +25 -0
- data/manual/images/images.rb +40 -0
- data/manual/images/plain_image.rb +18 -0
- data/manual/images/scale.rb +22 -0
- data/manual/images/vertical.rb +28 -0
- data/manual/images/width_and_height.rb +25 -0
- data/manual/layout/boxes.rb +27 -0
- data/manual/layout/content.rb +25 -0
- data/manual/layout/layout.rb +28 -0
- data/manual/layout/simple_grid.rb +23 -0
- data/manual/manual/cover.rb +26 -0
- data/manual/manual/foreword.rb +13 -0
- data/manual/manual/how_to_read_this_manual.rb +41 -0
- data/manual/manual/manual.rb +36 -0
- data/manual/outline/add_subsection_to.rb +61 -0
- data/manual/outline/insert_section_after.rb +47 -0
- data/manual/outline/outline.rb +32 -0
- data/manual/outline/sections_and_pages.rb +67 -0
- data/manual/repeatable_content/page_numbering.rb +54 -0
- data/manual/repeatable_content/repeatable_content.rb +31 -0
- data/manual/repeatable_content/repeater.rb +55 -0
- data/manual/repeatable_content/stamp.rb +41 -0
- data/manual/security/encryption.rb +31 -0
- data/manual/security/permissions.rb +38 -0
- data/manual/security/security.rb +28 -0
- data/manual/syntax_highlight.rb +52 -0
- data/manual/table/basic_block.rb +53 -0
- data/manual/table/before_rendering_page.rb +26 -0
- data/manual/table/cell_border_lines.rb +24 -0
- data/manual/table/cell_borders_and_bg.rb +31 -0
- data/manual/table/cell_dimensions.rb +30 -0
- data/manual/table/cell_text.rb +38 -0
- data/manual/table/column_widths.rb +30 -0
- data/manual/table/content_and_subtables.rb +39 -0
- data/manual/table/creation.rb +27 -0
- data/manual/table/filtering.rb +36 -0
- data/manual/table/flow_and_header.rb +17 -0
- data/manual/table/image_cells.rb +33 -0
- data/manual/table/position.rb +29 -0
- data/manual/table/row_colors.rb +20 -0
- data/manual/table/span.rb +30 -0
- data/manual/table/style.rb +22 -0
- data/manual/table/table.rb +52 -0
- data/manual/table/width.rb +27 -0
- data/manual/templates/full_template.rb +23 -0
- data/manual/templates/page_template.rb +47 -0
- data/manual/templates/templates.rb +26 -0
- data/manual/text/alignment.rb +44 -0
- data/manual/text/color.rb +24 -0
- data/manual/text/column_box.rb +32 -0
- data/manual/text/fallback_fonts.rb +37 -0
- data/manual/text/font.rb +41 -0
- data/manual/text/font_size.rb +45 -0
- data/manual/text/font_style.rb +23 -0
- data/manual/text/formatted_callbacks.rb +60 -0
- data/manual/text/formatted_text.rb +50 -0
- data/manual/text/free_flowing_text.rb +51 -0
- data/manual/text/group.rb +29 -0
- data/manual/text/inline.rb +43 -0
- data/manual/text/kerning_and_character_spacing.rb +39 -0
- data/manual/text/leading.rb +25 -0
- data/manual/text/line_wrapping.rb +41 -0
- data/manual/text/paragraph_indentation.rb +26 -0
- data/manual/text/positioned_text.rb +38 -0
- data/manual/text/registering_families.rb +48 -0
- data/manual/text/rendering_and_color.rb +37 -0
- data/manual/text/right_to_left_text.rb +43 -0
- data/manual/text/rotation.rb +43 -0
- data/manual/text/single_usage.rb +37 -0
- data/manual/text/text.rb +75 -0
- data/manual/text/text_box_excess.rb +32 -0
- data/manual/text/text_box_extensions.rb +45 -0
- data/manual/text/text_box_overflow.rb +44 -0
- data/manual/text/utf8.rb +28 -0
- data/manual/text/win_ansi_charset.rb +59 -0
- data/prawn.gemspec +46 -0
- data/spec/annotations_spec.rb +90 -0
- data/spec/bounding_box_spec.rb +493 -0
- data/spec/cell_spec.rb +584 -0
- data/spec/column_box_spec.rb +33 -0
- data/spec/data/curves.pdf +66 -0
- data/spec/destinations_spec.rb +15 -0
- data/spec/document_spec.rb +736 -0
- data/spec/extensions/encoding_helpers.rb +6 -0
- data/spec/extensions/mocha.rb +44 -0
- data/spec/font_spec.rb +433 -0
- data/spec/formatted_text_arranger_spec.rb +421 -0
- data/spec/formatted_text_box_spec.rb +640 -0
- data/spec/formatted_text_fragment_spec.rb +298 -0
- data/spec/graphics_spec.rb +651 -0
- data/spec/grid_spec.rb +85 -0
- data/spec/images_spec.rb +140 -0
- data/spec/inline_formatted_text_parser_spec.rb +515 -0
- data/spec/jpg_spec.rb +25 -0
- data/spec/line_wrap_spec.rb +333 -0
- data/spec/measurement_units_spec.rb +23 -0
- data/spec/name_tree_spec.rb +112 -0
- data/spec/object_store_spec.rb +170 -0
- data/spec/outline_spec.rb +426 -0
- data/spec/pdf_object_spec.rb +172 -0
- data/spec/png_spec.rb +240 -0
- data/spec/reference_spec.rb +105 -0
- data/spec/repeater_spec.rb +158 -0
- data/spec/security_spec.rb +126 -0
- data/spec/snapshot_spec.rb +186 -0
- data/spec/soft_mask_spec.rb +117 -0
- data/spec/span_spec.rb +49 -0
- data/spec/spec_helper.rb +36 -0
- data/spec/stamp_spec.rb +159 -0
- data/spec/stroke_styles_spec.rb +193 -0
- data/spec/table_spec.rb +1209 -0
- data/spec/template_spec.rb +351 -0
- data/spec/text_at_spec.rb +129 -0
- data/spec/text_box_spec.rb +1029 -0
- data/spec/text_rendering_mode_spec.rb +45 -0
- data/spec/text_spacing_spec.rb +93 -0
- data/spec/text_spec.rb +421 -0
- data/spec/text_with_inline_formatting_spec.rb +35 -0
- data/spec/transparency_spec.rb +89 -0
- metadata +544 -0
data/spec/jpg_spec.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# Spec'ing the PNG class. Not complete yet - still needs to check the
|
4
|
+
# contents of palette and transparency to ensure they're correct.
|
5
|
+
# Need to find files that have these sections first.
|
6
|
+
|
7
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
8
|
+
|
9
|
+
describe "When reading a JPEG file" do
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
@filename = "#{Prawn::DATADIR}/images/pigs.jpg"
|
13
|
+
@img_data = File.open(@filename, "rb") { |f| f.read }
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should read the basic attributes correctly" do
|
17
|
+
jpg = Prawn::Images::JPG.new(@img_data)
|
18
|
+
|
19
|
+
jpg.width.should == 604
|
20
|
+
jpg.height.should == 453
|
21
|
+
jpg.bits.should == 8
|
22
|
+
jpg.channels.should == 3
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,333 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
|
5
|
+
describe "Core::Text::Formatted::LineWrap#wrap_line" do
|
6
|
+
before(:each) do
|
7
|
+
create_pdf
|
8
|
+
@arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
9
|
+
@line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
|
10
|
+
@one_word_width = 50
|
11
|
+
end
|
12
|
+
it "should strip leading and trailing spaces" do
|
13
|
+
array = [{ :text => " hello world, " },
|
14
|
+
{ :text => "goodbye ", :style => [:bold] }]
|
15
|
+
@arranger.format_array = array
|
16
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
17
|
+
:width => 300,
|
18
|
+
:document => @pdf)
|
19
|
+
string.should == "hello world, goodbye"
|
20
|
+
end
|
21
|
+
it "should strip trailing spaces when a white-space-only fragment was" +
|
22
|
+
" successfully pushed onto the end of a line but no other non-white" +
|
23
|
+
" space fragment fits after it" do
|
24
|
+
array = [{ :text => "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa " },
|
25
|
+
{ :text => " ", :style => [:bold] },
|
26
|
+
{ :text => " bbbbbbbbbbbbbbbbbbbbbbbbbbbb" }]
|
27
|
+
@arranger.format_array = array
|
28
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
29
|
+
:width => 300,
|
30
|
+
:document => @pdf)
|
31
|
+
string.should == "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
32
|
+
end
|
33
|
+
it "should raise_error CannotFit if a too-small width is given" do
|
34
|
+
array = [{ :text => " hello world, " },
|
35
|
+
{ :text => "goodbye ", :style => [:bold] }]
|
36
|
+
@arranger.format_array = array
|
37
|
+
lambda do
|
38
|
+
@line_wrap.wrap_line(:arranger => @arranger,
|
39
|
+
:width => 1,
|
40
|
+
:document => @pdf)
|
41
|
+
end.should raise_error(Prawn::Errors::CannotFit)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should break on space" do
|
45
|
+
array = [{ :text => "hello world" }]
|
46
|
+
@arranger.format_array = array
|
47
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
48
|
+
:width => @one_word_width,
|
49
|
+
:document => @pdf)
|
50
|
+
string.should == "hello"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should break on zero-width space" do
|
54
|
+
@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
|
55
|
+
array = [{ :text => "hello#{Prawn::Text::ZWSP}world" }]
|
56
|
+
@arranger.format_array = array
|
57
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
58
|
+
:width => @one_word_width,
|
59
|
+
:document => @pdf)
|
60
|
+
string.should == "hello"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should not display zero-width space" do
|
64
|
+
@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
|
65
|
+
array = [{ :text => "hello#{Prawn::Text::ZWSP}world" }]
|
66
|
+
@arranger.format_array = array
|
67
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
68
|
+
:width => 300,
|
69
|
+
:document => @pdf)
|
70
|
+
string.should == "helloworld"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should break on tab" do
|
74
|
+
array = [{ :text => "hello\tworld" }]
|
75
|
+
@arranger.format_array = array
|
76
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
77
|
+
:width => @one_word_width,
|
78
|
+
:document => @pdf)
|
79
|
+
string.should == "hello"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should break on hyphens" do
|
83
|
+
array = [{ :text => "hello-world" }]
|
84
|
+
@arranger.format_array = array
|
85
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
86
|
+
:width => @one_word_width,
|
87
|
+
:document => @pdf)
|
88
|
+
string.should == "hello-"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should not break after a hyphen that follows white space and" +
|
92
|
+
"precedes a word" do
|
93
|
+
array = [{ :text => "hello -" }]
|
94
|
+
@arranger.format_array = array
|
95
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
96
|
+
:width => @one_word_width,
|
97
|
+
:document => @pdf)
|
98
|
+
string.should == "hello -"
|
99
|
+
|
100
|
+
array = [{ :text => "hello -world" }]
|
101
|
+
@arranger.format_array = array
|
102
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
103
|
+
:width => @one_word_width,
|
104
|
+
:document => @pdf)
|
105
|
+
string.should == "hello"
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should break on a soft hyphen" do
|
109
|
+
string = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}world")
|
110
|
+
array = [{ :text => string }]
|
111
|
+
@arranger.format_array = array
|
112
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
113
|
+
:width => @one_word_width,
|
114
|
+
:document => @pdf)
|
115
|
+
expected = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}")
|
116
|
+
expected.force_encoding("utf-8") if "".respond_to?(:force_encoding)
|
117
|
+
string.should == expected
|
118
|
+
|
119
|
+
@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
|
120
|
+
@line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
|
121
|
+
|
122
|
+
string = "hello#{Prawn::Text::SHY}world"
|
123
|
+
array = [{ :text => string }]
|
124
|
+
@arranger.format_array = array
|
125
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
126
|
+
:width => @one_word_width,
|
127
|
+
:document => @pdf)
|
128
|
+
string.should == "hello#{Prawn::Text::SHY}"
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should not display soft hyphens except at the end of a line" do
|
132
|
+
string = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}world")
|
133
|
+
array = [{ :text => string }]
|
134
|
+
@arranger.format_array = array
|
135
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
136
|
+
:width => 300,
|
137
|
+
:document => @pdf)
|
138
|
+
string.should == "helloworld"
|
139
|
+
|
140
|
+
@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
|
141
|
+
@line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
|
142
|
+
|
143
|
+
string = "hello#{Prawn::Text::SHY}world"
|
144
|
+
array = [{ :text => string }]
|
145
|
+
@arranger.format_array = array
|
146
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
147
|
+
:width => 300,
|
148
|
+
:document => @pdf)
|
149
|
+
string.should == "helloworld"
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should not break before a hard hyphen that follows a word" do
|
153
|
+
enough_width_for_hello_world = 60
|
154
|
+
|
155
|
+
array = [{ :text => "hello world" }]
|
156
|
+
@arranger.format_array = array
|
157
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
158
|
+
:width => enough_width_for_hello_world,
|
159
|
+
:document => @pdf)
|
160
|
+
string.should == "hello world"
|
161
|
+
|
162
|
+
array = [{ :text => "hello world-" }]
|
163
|
+
@arranger.format_array = array
|
164
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
165
|
+
:width => enough_width_for_hello_world,
|
166
|
+
:document => @pdf)
|
167
|
+
string.should == "hello"
|
168
|
+
|
169
|
+
@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
|
170
|
+
@line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
|
171
|
+
enough_width_for_hello_world = 68
|
172
|
+
|
173
|
+
array = [{ :text => "hello world" }]
|
174
|
+
@arranger.format_array = array
|
175
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
176
|
+
:width => enough_width_for_hello_world,
|
177
|
+
:document => @pdf)
|
178
|
+
string.should == "hello world"
|
179
|
+
|
180
|
+
array = [{ :text => "hello world-" }]
|
181
|
+
@arranger.format_array = array
|
182
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
183
|
+
:width => enough_width_for_hello_world,
|
184
|
+
:document => @pdf)
|
185
|
+
string.should == "hello"
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should not break after a hard hyphen that follows a soft hyphen and" +
|
189
|
+
"precedes a word" do
|
190
|
+
string = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}-")
|
191
|
+
array = [{ :text => string }]
|
192
|
+
@arranger.format_array = array
|
193
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
194
|
+
:width => @one_word_width,
|
195
|
+
:document => @pdf)
|
196
|
+
string.should == "hello-"
|
197
|
+
|
198
|
+
string = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}-world")
|
199
|
+
array = [{ :text => string }]
|
200
|
+
@arranger.format_array = array
|
201
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
202
|
+
:width => @one_word_width,
|
203
|
+
:document => @pdf)
|
204
|
+
expected = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}")
|
205
|
+
expected.force_encoding("utf-8") if "".respond_to?(:force_encoding)
|
206
|
+
string.should == expected
|
207
|
+
|
208
|
+
@pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
|
209
|
+
@line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
|
210
|
+
|
211
|
+
string = "hello#{Prawn::Text::SHY}-"
|
212
|
+
array = [{ :text => string }]
|
213
|
+
@arranger.format_array = array
|
214
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
215
|
+
:width => @one_word_width,
|
216
|
+
:document => @pdf)
|
217
|
+
string.should == "hello-"
|
218
|
+
|
219
|
+
string = "hello#{Prawn::Text::SHY}-world"
|
220
|
+
array = [{ :text => string }]
|
221
|
+
@arranger.format_array = array
|
222
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
223
|
+
:width => @one_word_width,
|
224
|
+
:document => @pdf)
|
225
|
+
string.should == "hello#{Prawn::Text::SHY}"
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
describe "Core::Text::Formatted::LineWrap#space_count" do
|
230
|
+
before(:each) do
|
231
|
+
create_pdf
|
232
|
+
@arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
233
|
+
@line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
|
234
|
+
end
|
235
|
+
it "should return the number of spaces in the last wrapped line" do
|
236
|
+
array = [{ :text => "hello world, " },
|
237
|
+
{ :text => "goodbye", :style => [:bold] }]
|
238
|
+
@arranger.format_array = array
|
239
|
+
@line_wrap.wrap_line(:arranger => @arranger,
|
240
|
+
:width => 300,
|
241
|
+
:document => @pdf)
|
242
|
+
@line_wrap.space_count.should == 2
|
243
|
+
end
|
244
|
+
it "should exclude preceding and trailing spaces from the count" do
|
245
|
+
array = [{ :text => " hello world, " },
|
246
|
+
{ :text => "goodbye ", :style => [:bold] }]
|
247
|
+
@arranger.format_array = array
|
248
|
+
@line_wrap.wrap_line(:arranger => @arranger,
|
249
|
+
:width => 300,
|
250
|
+
:document => @pdf)
|
251
|
+
@line_wrap.space_count.should == 2
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
describe "Core::Text::Formatted::LineWrap" do
|
256
|
+
before(:each) do
|
257
|
+
create_pdf
|
258
|
+
@arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
259
|
+
array = [{ :text => "hello\nworld\n\n\nhow are you?" },
|
260
|
+
{ :text => "\n" },
|
261
|
+
{ :text => "\n" },
|
262
|
+
{ :text => "" },
|
263
|
+
{ :text => "fine, thanks. " * 4 },
|
264
|
+
{ :text => "" },
|
265
|
+
{ :text => "\n" },
|
266
|
+
{ :text => "" }]
|
267
|
+
@arranger.format_array = array
|
268
|
+
@line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
|
269
|
+
end
|
270
|
+
it "should only return an empty string if nothing fit or there" +
|
271
|
+
"was nothing to wrap" do
|
272
|
+
8.times do
|
273
|
+
line = @line_wrap.wrap_line(:arranger => @arranger,
|
274
|
+
:width => 200,
|
275
|
+
:document => @pdf)
|
276
|
+
line.should_not be_empty
|
277
|
+
end
|
278
|
+
line = @line_wrap.wrap_line(:arranger => @arranger,
|
279
|
+
:width => 200,
|
280
|
+
:document => @pdf)
|
281
|
+
line.should be_empty
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
describe "Core::Text::Formatted::LineWrap#paragraph_finished?" do
|
286
|
+
before(:each) do
|
287
|
+
create_pdf
|
288
|
+
@arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
|
289
|
+
@line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
|
290
|
+
@one_word_width = 50
|
291
|
+
end
|
292
|
+
it "should be_false when the last printed line is not the end of the paragraph" do
|
293
|
+
array = [{ :text => "hello world" }]
|
294
|
+
@arranger.format_array = array
|
295
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
296
|
+
:width => @one_word_width,
|
297
|
+
:document => @pdf)
|
298
|
+
|
299
|
+
@line_wrap.paragraph_finished?.should == false
|
300
|
+
end
|
301
|
+
it "should be_true when the last printed line is the last fragment to print" do
|
302
|
+
array = [{ :text => "hello world" }]
|
303
|
+
@arranger.format_array = array
|
304
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
305
|
+
:width => @one_word_width,
|
306
|
+
:document => @pdf)
|
307
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
308
|
+
:width => @one_word_width,
|
309
|
+
:document => @pdf)
|
310
|
+
|
311
|
+
@line_wrap.paragraph_finished?.should == true
|
312
|
+
end
|
313
|
+
it "should be_true when a newline exists on the current line" do
|
314
|
+
array = [{ :text => "hello\n world" }]
|
315
|
+
@arranger.format_array = array
|
316
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
317
|
+
:width => @one_word_width,
|
318
|
+
:document => @pdf)
|
319
|
+
|
320
|
+
@line_wrap.paragraph_finished?.should == true
|
321
|
+
end
|
322
|
+
it "should be_true when a newline exists in the next fragment" do
|
323
|
+
array = [{ :text => "hello " },
|
324
|
+
{ :text => " \n" },
|
325
|
+
{ :text => "world" }]
|
326
|
+
@arranger.format_array = array
|
327
|
+
string = @line_wrap.wrap_line(:arranger => @arranger,
|
328
|
+
:width => @one_word_width,
|
329
|
+
:document => @pdf)
|
330
|
+
|
331
|
+
@line_wrap.paragraph_finished?.should == true
|
332
|
+
end
|
333
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
2
|
+
require "prawn/measurement_extensions"
|
3
|
+
|
4
|
+
describe "Measurement units" do
|
5
|
+
|
6
|
+
it "should convert units to PostScriptPoints" do
|
7
|
+
1.mm.should be_within(0.000000001).of(2.834645669)
|
8
|
+
1.mm.should == (72 / 25.4)
|
9
|
+
2.mm.should == (2 * 72 / 25.4)
|
10
|
+
3.mm.should == 3 * 72 / 25.4
|
11
|
+
-3.mm.should == -3 * 72/25.4
|
12
|
+
1.cm.should == 10 * 72 / 25.4
|
13
|
+
1.dm.should == 100 * 72 / 25.4
|
14
|
+
1.m.should == 1000 * 72 / 25.4
|
15
|
+
|
16
|
+
1.in.should == 72
|
17
|
+
1.ft.should == 72 * 12
|
18
|
+
1.yd.should == 72 * 12 * 3
|
19
|
+
1.pt.should == 1
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
2
|
+
|
3
|
+
def tree_dump(tree)
|
4
|
+
if tree.is_a?(Prawn::Core::NameTree::Node)
|
5
|
+
"[" + tree.children.map { |child| tree_dump(child) }.join(",") + "]"
|
6
|
+
else
|
7
|
+
"#{tree.name}=#{tree.value}"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def tree_add(tree, *args)
|
12
|
+
args.each do |(name, value)|
|
13
|
+
tree.add(name, value)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def tree_value(name, value)
|
18
|
+
Prawn::Core::NameTree::Value.new(name, value)
|
19
|
+
end
|
20
|
+
|
21
|
+
class RefExposingDocument < Prawn::Document
|
22
|
+
def object_store
|
23
|
+
state.store
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "Name Tree" do
|
28
|
+
before(:each) { create_pdf(RefExposingDocument) }
|
29
|
+
|
30
|
+
it "should have no children when first initialized" do
|
31
|
+
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
32
|
+
node.children.length.should == 0
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should have no subtrees while child limit is not reached" do
|
36
|
+
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
37
|
+
tree_add(node, ["one", 1], ["two", 2], ["three", 3])
|
38
|
+
tree_dump(node).should == "[one=1,three=3,two=2]"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should split into subtrees when limit is exceeded" do
|
42
|
+
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
43
|
+
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
44
|
+
tree_dump(node).should == "[[four=4,one=1],[three=3,two=2]]"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should create a two new references when root is split" do
|
48
|
+
ref_count = @pdf.object_store.length
|
49
|
+
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
50
|
+
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
51
|
+
@pdf.object_store.length.should == ref_count+2
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should create a one new reference when subtree is split" do
|
55
|
+
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
56
|
+
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
57
|
+
|
58
|
+
ref_count = @pdf.object_store.length # save when root is split
|
59
|
+
tree_add(node, ["five", 5], ["six", 6], ["seven", 7])
|
60
|
+
tree_dump(node).should == "[[five=5,four=4,one=1],[seven=7,six=6],[three=3,two=2]]"
|
61
|
+
@pdf.object_store.length.should == ref_count+1
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should keep tree balanced when subtree split cascades to root" do
|
65
|
+
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
66
|
+
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
67
|
+
tree_add(node, ["five", 5], ["six", 6], ["seven", 7], ["eight", 8])
|
68
|
+
tree_dump(node).should == "[[[eight=8,five=5],[four=4,one=1]],[[seven=7,six=6],[three=3,two=2]]]"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should maintain order of already properly ordered nodes" do
|
72
|
+
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
73
|
+
tree_add(node, ["eight", 8], ["five", 5], ["four", 4], ["one", 1])
|
74
|
+
tree_add(node, ['seven', 7], ['six', 6], ['three', 3], ['two', 2])
|
75
|
+
tree_dump(node).should == "[[[eight=8,five=5],[four=4,one=1]],[[seven=7,six=6],[three=3,two=2]]]"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should emit only :Names key with to_hash if root is only node" do
|
79
|
+
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
80
|
+
tree_add(node, ["one", 1], ["two", 2], ["three", 3])
|
81
|
+
node.to_hash.should ==(
|
82
|
+
{ :Names => [tree_value("one", 1), tree_value("three", 3), tree_value("two", 2)] }
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should emit only :Kids key with to_hash if root has children" do
|
87
|
+
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
88
|
+
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
89
|
+
node.to_hash.should ==({ :Kids => node.children.map { |child| child.ref } })
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should emit :Limits and :Names keys with to_hash for leaf node" do
|
93
|
+
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
94
|
+
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
95
|
+
node.children.first.to_hash.should ==(
|
96
|
+
{ :Limits => %w(four one),
|
97
|
+
:Names => [tree_value("four", 4), tree_value("one", 1)] }
|
98
|
+
)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should emit :Limits and :Kids keys with to_hash for inner node" do
|
102
|
+
node = Prawn::Core::NameTree::Node.new(@pdf, 3)
|
103
|
+
tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4])
|
104
|
+
tree_add(node, ["five", 5], ["six", 6], ["seven", 7], ["eight", 8])
|
105
|
+
tree_add(node, ["nine", 9], ["ten", 10], ["eleven", 11], ["twelve", 12])
|
106
|
+
tree_add(node, ["thirteen", 13], ["fourteen", 14], ["fifteen", 15], ["sixteen", 16])
|
107
|
+
node.children.first.to_hash.should ==(
|
108
|
+
{ :Limits => %w(eight one),
|
109
|
+
:Kids => node.children.first.children.map { |child| child.ref } }
|
110
|
+
)
|
111
|
+
end
|
112
|
+
end
|