prawn 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +4 -2
  3. data/lib/prawn.rb +5 -3
  4. data/lib/prawn/document.rb +7 -7
  5. data/lib/prawn/document/bounding_box.rb +1 -1
  6. data/lib/prawn/document/column_box.rb +3 -3
  7. data/lib/prawn/document/internals.rb +1 -1
  8. data/lib/prawn/font.rb +24 -8
  9. data/lib/prawn/font/afm.rb +4 -4
  10. data/lib/prawn/font_metric_cache.rb +1 -1
  11. data/lib/prawn/grid.rb +3 -1
  12. data/lib/prawn/image_handler.rb +3 -1
  13. data/lib/prawn/images/jpg.rb +1 -1
  14. data/lib/prawn/measurement_extensions.rb +1 -1
  15. data/lib/prawn/outline.rb +3 -1
  16. data/lib/prawn/security.rb +1 -1
  17. data/lib/prawn/security/arcfour.rb +4 -2
  18. data/lib/prawn/table.rb +14 -2
  19. data/lib/prawn/table/cell.rb +1 -1
  20. data/lib/prawn/table/cells.rb +1 -50
  21. data/lib/prawn/table/column_width_calculator.rb +131 -10
  22. data/lib/prawn/text.rb +1 -1
  23. data/lib/prawn/text/formatted.rb +2 -0
  24. data/lib/prawn/text/formatted/arranger.rb +1 -1
  25. data/lib/prawn/text/formatted/box.rb +5 -5
  26. data/lib/prawn/text/formatted/line_wrap.rb +1 -1
  27. data/lib/prawn/text/formatted/wrap.rb +2 -0
  28. data/lib/prawn/utilities.rb +3 -3
  29. data/manual/absolute_position.pdf +0 -0
  30. data/manual/basic_concepts/adding_pages.rb +3 -3
  31. data/manual/basic_concepts/basic_concepts.rb +6 -6
  32. data/manual/basic_concepts/cursor.rb +5 -5
  33. data/manual/basic_concepts/measurement.rb +2 -2
  34. data/manual/basic_concepts/origin.rb +3 -3
  35. data/manual/basic_concepts/other_cursor_helpers.rb +6 -6
  36. data/manual/bounding_box/bounding_box.rb +6 -6
  37. data/manual/bounding_box/bounds.rb +6 -6
  38. data/manual/bounding_box/canvas.rb +2 -2
  39. data/manual/bounding_box/creation.rb +3 -3
  40. data/manual/bounding_box/indentation.rb +9 -9
  41. data/manual/bounding_box/nesting.rb +8 -8
  42. data/manual/bounding_box/russian_boxes.rb +1 -1
  43. data/manual/bounding_box/stretchy.rb +8 -8
  44. data/manual/{manual/manual.rb → contents.rb} +6 -9
  45. data/manual/{manual/cover.rb → cover.rb} +6 -6
  46. data/manual/document_and_page_options/background.rb +2 -2
  47. data/manual/document_and_page_options/document_and_page_options.rb +4 -4
  48. data/manual/document_and_page_options/metadata.rb +2 -2
  49. data/manual/document_and_page_options/page_margins.rb +2 -2
  50. data/manual/document_and_page_options/page_size.rb +3 -3
  51. data/manual/example_helper.rb +5 -409
  52. data/manual/graphics/circle_and_ellipse.rb +4 -4
  53. data/manual/graphics/color.rb +4 -4
  54. data/manual/graphics/common_lines.rb +5 -5
  55. data/manual/graphics/fill_and_stroke.rb +5 -5
  56. data/manual/graphics/fill_rules.rb +1 -1
  57. data/manual/graphics/gradients.rb +1 -1
  58. data/manual/graphics/graphics.rb +8 -8
  59. data/manual/graphics/helper.rb +1 -1
  60. data/manual/graphics/line_width.rb +5 -5
  61. data/manual/graphics/lines_and_curves.rb +5 -5
  62. data/manual/graphics/polygon.rb +4 -4
  63. data/manual/graphics/rectangle.rb +3 -3
  64. data/manual/graphics/rotate.rb +5 -5
  65. data/manual/graphics/scale.rb +5 -5
  66. data/manual/graphics/soft_masks.rb +1 -1
  67. data/manual/graphics/stroke_cap.rb +3 -3
  68. data/manual/graphics/stroke_dash.rb +1 -1
  69. data/manual/graphics/stroke_join.rb +4 -4
  70. data/manual/graphics/translate.rb +5 -5
  71. data/manual/graphics/transparency.rb +5 -5
  72. data/manual/{manual/how_to_read_this_manual.rb → how_to_read_this_manual.rb} +16 -17
  73. data/manual/images/absolute_position.rb +3 -3
  74. data/manual/images/fit.rb +2 -2
  75. data/manual/images/horizontal.rb +3 -3
  76. data/manual/images/images.rb +7 -7
  77. data/manual/images/plain_image.rb +1 -1
  78. data/manual/images/scale.rb +3 -3
  79. data/manual/images/vertical.rb +3 -3
  80. data/manual/images/width_and_height.rb +3 -3
  81. data/manual/layout/boxes.rb +4 -4
  82. data/manual/layout/content.rb +3 -3
  83. data/manual/layout/layout.rb +5 -5
  84. data/manual/layout/simple_grid.rb +2 -2
  85. data/manual/outline/add_subsection_to.rb +7 -7
  86. data/manual/outline/insert_section_after.rb +5 -5
  87. data/manual/outline/outline.rb +6 -6
  88. data/manual/outline/sections_and_pages.rb +9 -9
  89. data/manual/repeatable_content/page_numbering.rb +3 -3
  90. data/manual/repeatable_content/repeatable_content.rb +5 -5
  91. data/manual/repeatable_content/repeater.rb +4 -4
  92. data/manual/repeatable_content/stamp.rb +4 -4
  93. data/manual/security/encryption.rb +2 -2
  94. data/manual/security/permissions.rb +2 -2
  95. data/manual/security/security.rb +5 -5
  96. data/manual/table/basic_block.rb +5 -5
  97. data/manual/table/before_rendering_page.rb +1 -1
  98. data/manual/table/cell_border_lines.rb +4 -4
  99. data/manual/table/cell_borders_and_bg.rb +4 -4
  100. data/manual/table/cell_dimensions.rb +3 -3
  101. data/manual/table/cell_text.rb +6 -6
  102. data/manual/table/column_widths.rb +4 -4
  103. data/manual/table/content_and_subtables.rb +5 -5
  104. data/manual/table/creation.rb +2 -2
  105. data/manual/table/filtering.rb +6 -6
  106. data/manual/table/flow_and_header.rb +2 -2
  107. data/manual/table/image_cells.rb +1 -1
  108. data/manual/table/position.rb +1 -1
  109. data/manual/table/row_colors.rb +3 -3
  110. data/manual/table/span.rb +1 -1
  111. data/manual/table/style.rb +3 -3
  112. data/manual/table/table.rb +7 -7
  113. data/manual/table/width.rb +3 -3
  114. data/manual/text/alignment.rb +1 -1
  115. data/manual/text/color.rb +1 -1
  116. data/manual/text/column_box.rb +1 -1
  117. data/manual/text/fallback_fonts.rb +3 -3
  118. data/manual/text/font.rb +7 -7
  119. data/manual/text/font_size.rb +9 -9
  120. data/manual/text/font_style.rb +3 -3
  121. data/manual/text/formatted_callbacks.rb +3 -3
  122. data/manual/text/formatted_text.rb +3 -3
  123. data/manual/text/free_flowing_text.rb +6 -6
  124. data/manual/text/inline.rb +5 -5
  125. data/manual/text/kerning_and_character_spacing.rb +7 -7
  126. data/manual/text/leading.rb +4 -4
  127. data/manual/text/line_wrapping.rb +4 -4
  128. data/manual/text/paragraph_indentation.rb +3 -3
  129. data/manual/text/positioned_text.rb +3 -3
  130. data/manual/text/registering_families.rb +6 -6
  131. data/manual/text/rendering_and_color.rb +2 -2
  132. data/manual/text/right_to_left_text.rb +2 -2
  133. data/manual/text/rotation.rb +4 -4
  134. data/manual/text/single_usage.rb +3 -3
  135. data/manual/text/text.rb +9 -9
  136. data/manual/text/text_box_excess.rb +2 -2
  137. data/manual/text/text_box_extensions.rb +3 -3
  138. data/manual/text/text_box_overflow.rb +4 -4
  139. data/manual/text/utf8.rb +5 -5
  140. data/manual/text/win_ansi_charset.rb +1 -1
  141. data/prawn.gemspec +5 -3
  142. data/spec/acceptance/png.rb +5 -3
  143. data/spec/cell_spec.rb +1 -0
  144. data/spec/column_box_spec.rb +1 -1
  145. data/spec/extensions/encoding_helpers.rb +2 -0
  146. data/spec/extensions/mocha.rb +2 -0
  147. data/spec/font_spec.rb +15 -0
  148. data/spec/measurement_units_spec.rb +2 -0
  149. data/spec/repeater_spec.rb +2 -0
  150. data/spec/soft_mask_spec.rb +2 -0
  151. data/spec/stamp_spec.rb +2 -0
  152. data/spec/table_spec.rb +103 -10
  153. data/spec/text_spec.rb +1 -1
  154. data/spec/transparency_spec.rb +2 -0
  155. metadata +42 -18
  156. data/lib/prawn/layout.rb +0 -17
  157. data/manual/example_file.rb +0 -111
  158. data/manual/example_package.rb +0 -53
  159. data/manual/example_section.rb +0 -46
  160. data/manual/syntax_highlight.rb +0 -52
@@ -16,10 +16,10 @@ require File.expand_path(File.join(File.dirname(__FILE__),
16
16
  %w[.. example_helper]))
17
17
 
18
18
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
19
- Prawn::Example.generate(filename) do
19
+ Prawn::ManualBuilder::Example.generate(filename) do
20
20
  fill_color "00ff00"
21
21
  stroke_color "0000ff"
22
-
22
+
23
23
  font_size(40) do
24
24
  # normal rendering mode: fill
25
25
  text "This text is filled with green."
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- #
2
+ #
3
3
  # Prawn can be used with right-to-left text. The direction can be set
4
4
  # document-wide, on particular text, or on a text-box. Setting the direction to
5
5
  # <code>:rtl</code> automatically changes the default alignment to
@@ -13,7 +13,7 @@ require File.expand_path(File.join(File.dirname(__FILE__),
13
13
  %w[.. example_helper]))
14
14
 
15
15
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
16
- Prawn::Example.generate(filename) do
16
+ Prawn::ManualBuilder::Example.generate(filename) do
17
17
  # set the direction document-wide
18
18
  self.text_direction = :rtl
19
19
 
@@ -12,7 +12,7 @@ require File.expand_path(File.join(File.dirname(__FILE__),
12
12
  %w[.. example_helper]))
13
13
 
14
14
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
15
- Prawn::Example.generate(filename) do
15
+ Prawn::ManualBuilder::Example.generate(filename) do
16
16
  width = 100
17
17
  height = 60
18
18
  angle = 30
@@ -22,15 +22,15 @@ Prawn::Example.generate(filename) do
22
22
  stroke_rectangle [0, y], width, height
23
23
  text_box("This text was not rotated",
24
24
  :at => [0, y], :width => width, :height => height)
25
-
25
+
26
26
  stroke_rectangle [0, y - 100], width, height
27
27
  text_box("This text was rotated around the center",
28
28
  :at => [0, y - 100], :width => width, :height => height,
29
29
  :rotate => angle, :rotate_around => :center)
30
-
30
+
31
31
  [:lower_left, :upper_left,
32
32
  :lower_right, :upper_right].each_with_index do |corner, index|
33
-
33
+
34
34
  y = y - 100 if index == 2
35
35
  stroke_rectangle [x + (index % 2) * 200, y], width, height
36
36
  text_box("This text was rotated around the #{corner} corner.",
@@ -17,16 +17,16 @@ require File.expand_path(File.join(File.dirname(__FILE__),
17
17
  %w[.. example_helper]))
18
18
 
19
19
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
20
- Prawn::Example.generate(filename) do
20
+ Prawn::ManualBuilder::Example.generate(filename) do
21
21
  # Using a TTF font file
22
22
  font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf") do
23
23
  text "Written with the DejaVu Sans TTF font."
24
24
  end
25
25
  move_down 20
26
-
26
+
27
27
  text "Written with the default font."
28
28
  move_down 20
29
-
29
+
30
30
  # Using an DFONT font file
31
31
  font("#{Prawn::DATADIR}/fonts/Panic+Sans.dfont") do
32
32
  text "Written with the Panic Sans DFONT font"
@@ -5,10 +5,10 @@
5
5
  require File.expand_path(File.join(File.dirname(__FILE__),
6
6
  %w[.. example_helper]))
7
7
 
8
- Prawn::Example.generate("text.pdf", :page_size => "FOLIO") do
9
-
8
+ Prawn::ManualBuilder::Example.generate("text.pdf", :page_size => "FOLIO") do
9
+
10
10
  package "text" do |p|
11
-
11
+
12
12
  p.section "Basics" do |s|
13
13
  s.example "free_flowing_text"
14
14
  s.example "positioned_text"
@@ -16,7 +16,7 @@ Prawn::Example.generate("text.pdf", :page_size => "FOLIO") do
16
16
  s.example "text_box_excess"
17
17
  s.example "column_box"
18
18
  end
19
-
19
+
20
20
  p.section "Styling" do |s|
21
21
  s.example "font"
22
22
  s.example "font_size"
@@ -28,7 +28,7 @@ Prawn::Example.generate("text.pdf", :page_size => "FOLIO") do
28
28
  s.example "paragraph_indentation"
29
29
  s.example "rotation"
30
30
  end
31
-
31
+
32
32
  p.section "Advanced Styling" do |s|
33
33
  s.example "inline"
34
34
  s.example "formatted_text"
@@ -36,12 +36,12 @@ Prawn::Example.generate("text.pdf", :page_size => "FOLIO") do
36
36
  s.example "rendering_and_color"
37
37
  s.example "text_box_extensions"
38
38
  end
39
-
39
+
40
40
  p.section "External Fonts" do |s|
41
41
  s.example "single_usage"
42
42
  s.example "registering_families"
43
43
  end
44
-
44
+
45
45
  p.section "M17n" do |s|
46
46
  s.example "utf8"
47
47
  s.example "line_wrapping"
@@ -49,7 +49,7 @@ Prawn::Example.generate("text.pdf", :page_size => "FOLIO") do
49
49
  s.example "fallback_fonts"
50
50
  s.example "win_ansi_charset"
51
51
  end
52
-
52
+
53
53
  p.intro do
54
54
  prose("This is probably the feature people will use the most. There is no shortage of options when it comes to text. You'll be hard pressed to find a use case that is not covered by one of the text methods and configurable options.
55
55
 
@@ -68,6 +68,6 @@ Prawn::Example.generate("text.pdf", :page_size => "FOLIO") do
68
68
  "What happens when rendering text in different languages"
69
69
  )
70
70
  end
71
-
71
+
72
72
  end
73
73
  end
@@ -13,7 +13,7 @@ require File.expand_path(File.join(File.dirname(__FILE__),
13
13
  %w[.. example_helper]))
14
14
 
15
15
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
16
- Prawn::Example.generate(filename) do
16
+ Prawn::ManualBuilder::Example.generate(filename) do
17
17
  string = "This is the beginning of the text. It will be cut somewhere and " +
18
18
  "the rest of the text will procede to be rendered this time by " +
19
19
  "calling another method." + " . " * 50
@@ -25,7 +25,7 @@ Prawn::Example.generate(filename) do
25
25
  :overflow => :truncate,
26
26
  :at => [100, y_position],
27
27
  :size => 18
28
-
28
+
29
29
  text_box excess_text,
30
30
  :width => 300,
31
31
  :at => [100, y_position - 100]
@@ -14,7 +14,7 @@ require File.expand_path(File.join(File.dirname(__FILE__),
14
14
  %w[.. example_helper]))
15
15
 
16
16
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
17
- Prawn::Example.generate(filename) do
17
+ Prawn::ManualBuilder::Example.generate(filename) do
18
18
  module TriangleBox
19
19
  def available_width
20
20
  height + 25
@@ -24,14 +24,14 @@ Prawn::Example.generate(filename) do
24
24
  y_position = cursor - 10
25
25
  width = 100
26
26
  height = 100
27
-
27
+
28
28
  Prawn::Text::Box.extensions << TriangleBox
29
29
  stroke_rectangle([0, y_position], width, height)
30
30
  text_box("A" * 100,
31
31
  :at => [0, y_position],
32
32
  :width => width,
33
33
  :height => height)
34
-
34
+
35
35
  Prawn::Text::Formatted::Box.extensions << TriangleBox
36
36
  stroke_rectangle([200, y_position], width, height)
37
37
  formatted_text_box([:text => "A" * 100, :color => "009900"],
@@ -16,22 +16,22 @@ require File.expand_path(File.join(File.dirname(__FILE__),
16
16
  %w[.. example_helper]))
17
17
 
18
18
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
19
- Prawn::Example.generate(filename) do
19
+ Prawn::ManualBuilder::Example.generate(filename) do
20
20
  string = "This is the sample text used for the text boxes. See how it " +
21
21
  "behave with the various overflow options used."
22
22
 
23
23
  text string
24
-
24
+
25
25
  y_position = cursor - 20
26
26
  [:truncate, :expand, :shrink_to_fit].each_with_index do |mode, i|
27
27
  text_box string, :at => [i * 150, y_position],
28
28
  :width => 100, :height => 50,
29
29
  :overflow => mode
30
30
  end
31
-
31
+
32
32
  string = "If the box is too small for the text, :shrink_to_fit " +
33
33
  "can render the text in a really small font size."
34
-
34
+
35
35
  move_down 120
36
36
  text string
37
37
  y_position = cursor - 20
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- #
2
+ #
3
3
  # Multilingualization isn't much of a problem on Prawn as its default encoding
4
4
  # is UTF-8. The only thing you need to worry about is if the font support the
5
5
  # glyphs of your language.
@@ -8,19 +8,19 @@ require File.expand_path(File.join(File.dirname(__FILE__),
8
8
  %w[.. example_helper]))
9
9
 
10
10
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
11
- Prawn::Example.generate(filename) do
11
+ Prawn::ManualBuilder::Example.generate(filename) do
12
12
  text "Take this example, a simple Euro sign:"
13
13
  text "€", :size => 32
14
14
  move_down 20
15
-
15
+
16
16
  text "Seems ok. Now let's try something more complex:"
17
17
  text "ὕαλον ϕαγεῖν δύναμαι· τοῦτο οὔ με βλάπτει."
18
18
  move_down 20
19
-
19
+
20
20
  text "Looks like the current font (#{font.inspect}) doesn't support those."
21
21
  text "Let's try them with another font."
22
22
  move_down 20
23
-
23
+
24
24
  font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf") do
25
25
  text "ὕαλον ϕαγεῖν δύναμαι· τοῦτο οὔ με βλάπτει."
26
26
  text "There you go."
@@ -8,7 +8,7 @@ require File.expand_path(File.join(File.dirname(__FILE__),
8
8
  %w[.. example_helper]))
9
9
 
10
10
  filename = File.basename(__FILE__).gsub('.rb', '.pdf')
11
- Prawn::Example.generate(filename) do
11
+ Prawn::ManualBuilder::Example.generate(filename) do
12
12
  FONT_SIZE = 9.5
13
13
 
14
14
  x = 0
@@ -20,17 +20,19 @@ Gem::Specification.new do |spec|
20
20
  spec.rubyforge_project = "prawn"
21
21
  spec.licenses = ['RUBY', 'GPL-2', 'GPL-3']
22
22
 
23
- spec.add_dependency('ttfunk', '~> 1.1.1')
24
- spec.add_dependency('pdf-core', "~> 0.2.2")
23
+ spec.add_dependency('ttfunk', '~> 1.2.0')
24
+ spec.add_dependency('pdf-core', "~> 0.2.5")
25
25
 
26
26
  spec.add_development_dependency('pdf-inspector', '~> 1.1.0')
27
27
  spec.add_development_dependency('coderay', '~> 1.0.7')
28
28
  spec.add_development_dependency('yard')
29
- spec.add_development_dependency('rspec')
29
+ spec.add_development_dependency('rspec', '2.14.1')
30
30
  spec.add_development_dependency('mocha')
31
31
  spec.add_development_dependency('rake')
32
32
  spec.add_development_dependency('simplecov')
33
+ spec.add_development_dependency('prawn-manual_builder', ">= 0.1.1")
33
34
  spec.add_development_dependency('pdf-reader', '~>1.2')
35
+ spec.add_development_dependency('rubocop', '0.20.1')
34
36
 
35
37
  spec.homepage = "http://prawn.majesticseacreature.com"
36
38
  spec.description = <<END_DESC
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require_relative "../../lib/prawn"
2
4
 
3
5
  images = [
@@ -15,9 +17,9 @@ Prawn::Document.generate("png_types.pdf", :page_size => "A5") do
15
17
  fill_color "FF0000"
16
18
 
17
19
  fill_rectangle bounds.top_left, bounds.width, bounds.height
18
- text header
19
-
20
+ text header
21
+
20
22
  image file, :at => [50,450]
21
- end
23
+ end
22
24
  end
23
25
 
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
+ require_relative "../lib/prawn/table"
4
5
 
5
6
  module CellHelpers
6
7
 
@@ -58,7 +58,7 @@ describe "A column box" do
58
58
  @pdf.bounds.move_past_bottom
59
59
  @pdf.bounds.move_past_bottom
60
60
 
61
- @pdf.bounds.absolute_top.should == page_top
61
+ @pdf.bounds.absolute_top.should == page_top
62
62
  @pdf.bounds.absolute_top.should_not == init_column_top
63
63
  end
64
64
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module EncodingHelpers
2
4
  def win1252_string(str)
3
5
  str.force_encoding(Encoding::Windows_1252)
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  # Allow speccing things when an expectation matcher runs. Similar to #with, but
2
4
  # always succeeds.
3
5
  #
@@ -159,6 +159,21 @@ describe "font style support" do
159
159
  name = name.sub(/\w+\+/, "subset+")
160
160
  name.should == "subset+DejaVuSans"
161
161
  end
162
+
163
+ it "should accept IO objects for font files" do
164
+ io = File.open "#{Prawn::DATADIR}/fonts/DejaVuSans.ttf"
165
+ @pdf.font_families["DejaVu Sans"] = {
166
+ normal: Prawn::Font.load(@pdf, io)
167
+ }
168
+
169
+ @pdf.font "DejaVu Sans"
170
+ @pdf.text "In DejaVu Sans"
171
+
172
+ text = PDF::Inspector::Text.analyze(@pdf.render)
173
+ name = text.font_settings.map { |e| e[:name] }.first.to_s
174
+ name = name.sub(/\w+\+/, "subset+")
175
+ name.should == "subset+DejaVuSans"
176
+ end
162
177
  end
163
178
 
164
179
  describe "Transactional font handling" do
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
2
4
  require "prawn/measurement_extensions"
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
2
4
 
3
5
  describe "Repeaters" do
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
2
4
 
3
5
  module SoftMaskHelper
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
2
4
 
3
5
  describe "create_stamp before any page is added" do
@@ -1,6 +1,12 @@
1
1
  # encoding: utf-8
2
2
 
3
+ # run rspec -t issue:XYZ to run tests for a specific github issue
4
+ # or rspec -t unresolved to run tests for all unresolved issues
5
+
6
+
3
7
  require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
8
+
9
+ require_relative "../lib/prawn/table"
4
10
  require 'set'
5
11
 
6
12
  describe "Prawn::Table" do
@@ -45,6 +51,48 @@ describe "Prawn::Table" do
45
51
  end
46
52
  end
47
53
 
54
+ describe "headers should allow for rowspan" do
55
+ it "should remember rowspans accross multiple pages", :issue => 721 do
56
+ pdf = Prawn::Document.new({:page_size => "A4", :page_layout => :portrait})
57
+ rows = [ [{:content=>"The\nNumber", :rowspan=>2}, {:content=>"Prefixed", :colspan=>2} ],
58
+ ["A's", "B's"] ]
59
+
60
+ (1..50).each do |n|
61
+ rows.push( ["#{n}", "A#{n}", "B#{n}"] )
62
+ end
63
+
64
+ pdf.table( rows, :header=>2 ) do
65
+ row(0..1).style :background_color=>"FFFFCC"
66
+ end
67
+
68
+ #ensure that the header on page 1 is identical to the header on page 0
69
+ output = PDF::Inspector::Page.analyze(pdf.render)
70
+ output.pages[0][:strings][0..4].should == output.pages[1][:strings][0..4]
71
+ end
72
+ end
73
+
74
+ describe "Text may be longer than the available space in a row on a single page" do
75
+ it "should not glitch the layout if there is too much text to fit onto a single row on a single page", :unresolved, :issue => 562 do
76
+ pdf = Prawn::Document.new({:page_size => "A4", :page_layout => :portrait})
77
+
78
+ table_data = Array.new
79
+ text = 'This will be a very long text. ' * 5
80
+ table_data.push([{:content => text, :rowspan => 2}, 'b', 'c'])
81
+ table_data.push(['b','c'])
82
+
83
+ column_widths = [50, 60, 400]
84
+
85
+ table = Prawn::Table.new table_data, pdf,:column_widths => column_widths
86
+
87
+ #render the table onto the pdf
88
+ table.draw
89
+
90
+ #expected behavior would be for the long text to be cut off or an exception to be raised
91
+ #thus we only expect a single page
92
+ pdf.page_count.should == 1
93
+ end
94
+ end
95
+
48
96
  describe "You can explicitly set the column widths and use a colspan > 1" do
49
97
 
50
98
  it "should tolerate floating point rounding errors < 0.000000001" do
@@ -53,9 +101,9 @@ describe "Prawn::Table" do
53
101
  ]
54
102
  #we need values with lots of decimals so that arithmetic errors will occur
55
103
  #the values are not arbitrary but where found converting mm to pdf pt
56
- column_widths=[137, 40, 40, 54.69291338582678, 54.69291338582678,
57
- 54.69291338582678, 54.69291338582678, 54.69291338582678,
58
- 54.69291338582678, 54.69291338582678, 54.69291338582678,
104
+ column_widths=[137, 40, 40, 54.69291338582678, 54.69291338582678,
105
+ 54.69291338582678, 54.69291338582678, 54.69291338582678,
106
+ 54.69291338582678, 54.69291338582678, 54.69291338582678,
59
107
  54.69291338582678]
60
108
 
61
109
  pdf = Prawn::Document.new({:page_size => 'A4', :page_layout => :landscape})
@@ -63,10 +111,10 @@ describe "Prawn::Table" do
63
111
  table.column_widths.should == column_widths
64
112
  end
65
113
 
66
- it "should work with two different given colspans", :issue => 628 do
114
+ it "should work with two different given colspans", :issue => 628 do
67
115
  data = [
68
- [" ", " ", " "],
69
- [{:content=>" ", :colspan=>3}],
116
+ [" ", " ", " "],
117
+ [{:content=>" ", :colspan=>3}],
70
118
  [" ", {:content=>" ", :colspan=>2}]
71
119
  ]
72
120
  column_widths = [60, 240, 60]
@@ -114,21 +162,49 @@ describe "Prawn::Table" do
114
162
  :unresolved, :issue => 612 do
115
163
 
116
164
  pdf = Prawn::Document.new
117
-
165
+
118
166
  first = {:content=>"Foooo fo foooooo",:width=>50,:align=>:center}
119
167
  second = {:content=>"Foooo",:colspan=>2,:width=>70,:align=>:center}
120
168
  third = {:content=>"fooooooooooo, fooooooooooooo, fooo, foooooo fooooo",:width=>50,:align=>:center}
121
169
  fourth = {:content=>"Bar",:width=>20,:align=>:center}
122
-
170
+
123
171
  table_content = [[
124
172
  first,
125
173
  [[second],[third,fourth]]
126
174
  ]]
127
-
175
+
128
176
  table = Prawn::Table.new table_content, pdf
129
177
  table.column_widths.should == [50.0, 70.0]
130
178
  end
131
179
 
180
+ it "illustrates issue #710", :issue => 710 do
181
+ partial_width = 40
182
+ pdf = Prawn::Document.new({page_size: "LETTER", page_layout: :portrait})
183
+ col_widths = [
184
+ 50,
185
+ partial_width, partial_width, partial_width, partial_width
186
+ ]
187
+
188
+ day_header = [{
189
+ content: "Monday, August 5th, A.S. XLIX",
190
+ colspan: 5,
191
+ }]
192
+
193
+ times = [{
194
+ content: "Loc",
195
+ colspan: 1,
196
+ }, {
197
+ content: "8:00",
198
+ colspan: 4,
199
+ }]
200
+
201
+ data = [ day_header ] + [ times ]
202
+
203
+ #raised a Prawn::Errors::CannotFit:
204
+ #Table's width was set larger than its contents' maximum width (max width 210, requested 218.0)
205
+ table = Prawn::Table.new data, pdf, :column_widths => col_widths
206
+ end
207
+
132
208
  it "illustrate issue #533" do
133
209
  data = [['', '', '', '', '',''],
134
210
  ['',{:content => '', :colspan => 5}]]
@@ -162,7 +238,7 @@ describe "Prawn::Table" do
162
238
  table.column_widths.should == [50.0, 200.0]
163
239
  end
164
240
 
165
- it "illustrates a variant of problem in issue #407 - comment 28556698" do
241
+ it "illustrates a variant of problem in issue #407 - comment 28556698" do
166
242
  pdf = Prawn::Document.new
167
243
  table_data = [["a", "b", "c"], [{:content=>"d", :colspan=>3}]]
168
244
  column_widths = [50, 60, 400]
@@ -711,6 +787,23 @@ describe "Prawn::Table" do
711
787
  output.pages[1][:strings].should == ["Header", "Body"]
712
788
  end
713
789
 
790
+ it 'should only draw first-page header if the first multi-row fits',
791
+ :issue => 707 do
792
+ pdf = Prawn::Document.new
793
+
794
+ pdf.y = 100 # not enough room for the header and multirow cell
795
+ pdf.table [
796
+ [{content: 'Header', colspan: 2}],
797
+ [{content: 'Multirow cell', rowspan: 3}, 'Line 1'],
798
+ ] + (2..3).map { |i| ["Line #{i}"] }, :header => true
799
+
800
+ output = PDF::Inspector::Page.analyze(pdf.render)
801
+ # Ensure we only drew the header once, on the second page
802
+ output.pages[0][:strings].should == []
803
+ output.pages[1][:strings].should == ['Header', 'Multirow cell', 'Line 1',
804
+ 'Line 2', 'Line 3']
805
+ end
806
+
714
807
  it "should draw background before borders, but only within pages" do
715
808
  seq = sequence("drawing_order")
716
809