prawn 1.0.0.rc2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +9 -0
  3. data/COPYING +2 -2
  4. data/Gemfile +8 -15
  5. data/LICENSE +1 -1
  6. data/Rakefile +25 -16
  7. data/data/images/16bit.alpha +0 -0
  8. data/data/images/16bit.color +0 -0
  9. data/data/images/dice.alpha +0 -0
  10. data/data/images/dice.color +0 -0
  11. data/data/images/indexed_color.dat +0 -0
  12. data/data/images/indexed_color.png +0 -0
  13. data/data/images/license.md +8 -0
  14. data/data/images/page_white_text.alpha +0 -0
  15. data/data/images/page_white_text.color +0 -0
  16. data/lib/prawn.rb +85 -23
  17. data/lib/prawn/document.rb +134 -116
  18. data/lib/prawn/document/bounding_box.rb +33 -4
  19. data/lib/prawn/document/column_box.rb +18 -6
  20. data/lib/prawn/document/graphics_state.rb +11 -74
  21. data/lib/prawn/document/internals.rb +24 -23
  22. data/lib/prawn/document/span.rb +12 -10
  23. data/lib/prawn/encoding.rb +8 -9
  24. data/lib/prawn/errors.rb +13 -32
  25. data/lib/prawn/font.rb +137 -105
  26. data/lib/prawn/font/afm.rb +76 -32
  27. data/lib/prawn/font/dfont.rb +4 -3
  28. data/lib/prawn/font/ttf.rb +33 -25
  29. data/lib/prawn/font_metric_cache.rb +47 -0
  30. data/lib/prawn/graphics.rb +177 -57
  31. data/lib/prawn/graphics/cap_style.rb +4 -3
  32. data/lib/prawn/graphics/color.rb +5 -4
  33. data/lib/prawn/graphics/dash.rb +53 -31
  34. data/lib/prawn/graphics/join_style.rb +9 -7
  35. data/lib/prawn/graphics/patterns.rb +4 -15
  36. data/lib/prawn/graphics/transformation.rb +10 -9
  37. data/lib/prawn/graphics/transparency.rb +3 -1
  38. data/lib/prawn/{layout/grid.rb → grid.rb} +72 -54
  39. data/lib/prawn/image_handler.rb +42 -0
  40. data/lib/prawn/images.rb +58 -54
  41. data/lib/prawn/images/image.rb +6 -22
  42. data/lib/prawn/images/jpg.rb +20 -14
  43. data/lib/prawn/images/png.rb +58 -121
  44. data/lib/prawn/layout.rb +12 -15
  45. data/lib/prawn/measurement_extensions.rb +10 -6
  46. data/lib/prawn/measurements.rb +27 -21
  47. data/lib/prawn/outline.rb +108 -147
  48. data/lib/prawn/repeater.rb +10 -8
  49. data/lib/prawn/security.rb +59 -40
  50. data/lib/prawn/security/arcfour.rb +52 -0
  51. data/lib/prawn/soft_mask.rb +4 -4
  52. data/lib/prawn/stamp.rb +5 -3
  53. data/lib/prawn/table.rb +83 -60
  54. data/lib/prawn/table/cell.rb +17 -21
  55. data/lib/prawn/table/cell/image.rb +2 -3
  56. data/lib/prawn/table/cell/in_table.rb +8 -2
  57. data/lib/prawn/table/cell/span_dummy.rb +5 -0
  58. data/lib/prawn/table/cell/subtable.rb +3 -2
  59. data/lib/prawn/table/cell/text.rb +14 -12
  60. data/lib/prawn/table/cells.rb +58 -14
  61. data/lib/prawn/table/column_width_calculator.rb +61 -0
  62. data/lib/prawn/text.rb +27 -26
  63. data/lib/prawn/text/box.rb +12 -6
  64. data/lib/prawn/text/formatted.rb +5 -4
  65. data/lib/prawn/text/formatted/arranger.rb +290 -0
  66. data/lib/prawn/text/formatted/box.rb +85 -57
  67. data/lib/prawn/text/formatted/fragment.rb +11 -11
  68. data/lib/prawn/text/formatted/line_wrap.rb +266 -0
  69. data/lib/prawn/text/formatted/parser.rb +11 -4
  70. data/lib/prawn/text/formatted/wrap.rb +156 -0
  71. data/lib/prawn/utilities.rb +5 -3
  72. data/manual/document_and_page_options/document_and_page_options.rb +2 -1
  73. data/manual/document_and_page_options/metadata.rb +3 -3
  74. data/manual/document_and_page_options/page_size.rb +2 -2
  75. data/manual/document_and_page_options/print_scaling.rb +20 -0
  76. data/manual/example_file.rb +2 -7
  77. data/manual/example_helper.rb +62 -81
  78. data/manual/graphics/common_lines.rb +2 -0
  79. data/manual/graphics/helper.rb +11 -4
  80. data/manual/graphics/stroke_dash.rb +19 -14
  81. data/manual/manual/cover.rb +16 -0
  82. data/manual/manual/manual.rb +1 -5
  83. data/manual/text/fallback_fonts.rb +4 -4
  84. data/manual/text/formatted_text.rb +5 -5
  85. data/manual/text/inline.rb +2 -4
  86. data/manual/text/registering_families.rb +12 -12
  87. data/manual/text/single_usage.rb +4 -4
  88. data/manual/text/text.rb +0 -2
  89. data/prawn.gemspec +21 -13
  90. data/spec/acceptance/png.rb +23 -0
  91. data/spec/annotations_spec.rb +16 -32
  92. data/spec/bounding_box_spec.rb +22 -5
  93. data/spec/cell_spec.rb +49 -5
  94. data/spec/column_box_spec.rb +32 -0
  95. data/spec/destinations_spec.rb +5 -5
  96. data/spec/document_spec.rb +112 -118
  97. data/spec/extensions/encoding_helpers.rb +5 -2
  98. data/spec/font_metric_cache_spec.rb +52 -0
  99. data/spec/font_spec.rb +121 -120
  100. data/spec/formatted_text_arranger_spec.rb +24 -24
  101. data/spec/formatted_text_box_spec.rb +31 -32
  102. data/spec/formatted_text_fragment_spec.rb +2 -2
  103. data/spec/graphics_spec.rb +63 -45
  104. data/spec/grid_spec.rb +24 -13
  105. data/spec/image_handler_spec.rb +54 -0
  106. data/spec/images_spec.rb +34 -21
  107. data/spec/inline_formatted_text_parser_spec.rb +69 -20
  108. data/spec/jpg_spec.rb +3 -3
  109. data/spec/line_wrap_spec.rb +25 -14
  110. data/spec/measurement_units_spec.rb +5 -5
  111. data/spec/outline_spec.rb +68 -64
  112. data/spec/png_spec.rb +15 -18
  113. data/spec/reference_spec.rb +2 -82
  114. data/spec/repeater_spec.rb +1 -1
  115. data/spec/security_spec.rb +41 -9
  116. data/spec/soft_mask_spec.rb +0 -40
  117. data/spec/span_spec.rb +6 -11
  118. data/spec/spec_helper.rb +20 -2
  119. data/spec/stamp_spec.rb +19 -20
  120. data/spec/stroke_styles_spec.rb +31 -13
  121. data/spec/table/span_dummy_spec.rb +17 -0
  122. data/spec/table_spec.rb +268 -43
  123. data/spec/text_at_spec.rb +13 -27
  124. data/spec/text_box_spec.rb +35 -30
  125. data/spec/text_spec.rb +56 -40
  126. data/spec/transparency_spec.rb +5 -5
  127. metadata +214 -217
  128. data/README.md +0 -98
  129. data/data/fonts/Action Man.dfont +0 -0
  130. data/data/fonts/Activa.ttf +0 -0
  131. data/data/fonts/Chalkboard.ttf +0 -0
  132. data/data/fonts/DejaVuSans.ttf +0 -0
  133. data/data/fonts/Dustismo_Roman.ttf +0 -0
  134. data/data/fonts/comicsans.ttf +0 -0
  135. data/data/fonts/gkai00mp.ttf +0 -0
  136. data/data/images/16bit.dat +0 -0
  137. data/data/images/barcode_issue.png +0 -0
  138. data/data/images/dice.dat +0 -0
  139. data/data/images/page_white_text.dat +0 -0
  140. data/data/images/rails.dat +0 -0
  141. data/data/images/rails.png +0 -0
  142. data/lib/prawn/compatibility.rb +0 -87
  143. data/lib/prawn/core.rb +0 -87
  144. data/lib/prawn/core/annotations.rb +0 -61
  145. data/lib/prawn/core/byte_string.rb +0 -9
  146. data/lib/prawn/core/destinations.rb +0 -90
  147. data/lib/prawn/core/document_state.rb +0 -79
  148. data/lib/prawn/core/literal_string.rb +0 -16
  149. data/lib/prawn/core/name_tree.rb +0 -177
  150. data/lib/prawn/core/object_store.rb +0 -320
  151. data/lib/prawn/core/page.rb +0 -212
  152. data/lib/prawn/core/pdf_object.rb +0 -125
  153. data/lib/prawn/core/reference.rb +0 -119
  154. data/lib/prawn/core/text.rb +0 -268
  155. data/lib/prawn/core/text/formatted/arranger.rb +0 -294
  156. data/lib/prawn/core/text/formatted/line_wrap.rb +0 -288
  157. data/lib/prawn/core/text/formatted/wrap.rb +0 -153
  158. data/lib/prawn/document/page_geometry.rb +0 -136
  159. data/lib/prawn/document/snapshot.rb +0 -89
  160. data/manual/manual/foreword.rb +0 -13
  161. data/manual/templates/full_template.rb +0 -23
  162. data/manual/templates/page_template.rb +0 -47
  163. data/manual/templates/templates.rb +0 -26
  164. data/manual/text/group.rb +0 -29
  165. data/spec/name_tree_spec.rb +0 -112
  166. data/spec/object_store_spec.rb +0 -170
  167. data/spec/pdf_object_spec.rb +0 -172
  168. data/spec/snapshot_spec.rb +0 -186
  169. data/spec/template_spec.rb +0 -351
@@ -1,46 +1,57 @@
1
1
  # encoding: utf-8
2
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
2
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
3
3
 
4
4
  describe "A document's grid" do
5
5
  before do
6
6
  @pdf = Prawn::Document.new
7
7
  end
8
-
8
+
9
9
  it "should allow definition of a grid" do
10
10
  @pdf.define_grid(:columns => 5, :rows => 8, :gutter => 0.1)
11
11
  @pdf.grid.columns.should == 5
12
12
  @pdf.grid.rows.should == 8
13
13
  @pdf.grid.gutter.should == 0.1
14
14
  end
15
-
15
+
16
+ it "should allow re-definition of a grid" do
17
+ @pdf.define_grid(:columns => 5, :rows => 8, :gutter => 0.1)
18
+ @pdf.grid.columns.should == 5
19
+ @pdf.grid.rows.should == 8
20
+ @pdf.grid.gutter.should == 0.1
21
+ @pdf.define_grid(:columns => 3, :rows => 6, :gutter => 0.1)
22
+ @pdf.grid.columns.should == 3
23
+ @pdf.grid.rows.should == 6
24
+ @pdf.grid.gutter.should == 0.1
25
+ end
26
+
16
27
  describe "when a grid is defined" do
17
28
  before do
18
29
  @num_columns = 5
19
30
  @num_rows = 8
20
31
  @gutter = 10.0
21
32
  @pdf.define_grid(
22
- :columns => @num_columns,
23
- :rows => @num_rows,
33
+ :columns => @num_columns,
34
+ :rows => @num_rows,
24
35
  :gutter => @gutter
25
36
  )
26
37
  end
27
-
38
+
28
39
  it "should compute the column width" do
29
- (@pdf.grid.column_width * @num_columns.to_f +
40
+ (@pdf.grid.column_width * @num_columns.to_f +
30
41
  @gutter * (@num_columns - 1).to_f).should == @pdf.bounds.width
31
42
  end
32
-
43
+
33
44
  it "should compute the row height" do
34
- (@pdf.grid.row_height * @num_rows.to_f +
45
+ (@pdf.grid.row_height * @num_rows.to_f +
35
46
  @gutter * (@num_rows - 1).to_f).should == @pdf.bounds.height
36
47
  end
37
48
 
38
49
  it "should give the edges of a grid box" do
39
- grid_width = (@pdf.bounds.width.to_f -
50
+ grid_width = (@pdf.bounds.width.to_f -
40
51
  (@gutter * (@num_columns - 1).to_f )) / @num_columns.to_f
41
- grid_height = (@pdf.bounds.height.to_f -
52
+ grid_height = (@pdf.bounds.height.to_f -
42
53
  (@gutter * (@num_rows - 1).to_f ))/ @num_rows.to_f
43
-
54
+
44
55
  exp_tl_x = (grid_width + @gutter.to_f) * 4.0
45
56
  exp_tl_y = @pdf.bounds.height.to_f - (grid_height + @gutter.to_f)
46
57
 
@@ -64,7 +75,7 @@ describe "A document's grid" do
64
75
  colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
65
76
  colors.fill_color.should_not == [0.8,0.8,0.8]
66
77
  colors.stroke_color.should_not == [0.8,0.8,0.8]
67
-
78
+
68
79
  # Hardcoded default color as I haven't been able to come up with a stable converter
69
80
  # between fill_color without lots code.
70
81
  #colors.fill_color.should == [0.0,0.0,0.0]
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
+
5
+ describe "ImageHandler" do
6
+ let(:image_handler) { Prawn::ImageHandler.new }
7
+
8
+ let(:handler_a) { mock("Handler A") }
9
+ let(:handler_b) { mock("Handler B") }
10
+
11
+ it "finds the image handler for an image" do
12
+ handler_a.expects(:can_render? => true)
13
+
14
+ image_handler.register(handler_a)
15
+ image_handler.register(handler_b)
16
+
17
+ handler = image_handler.find("arbitrary blob")
18
+ handler.should == handler_a
19
+ end
20
+
21
+ it "can prepend handlers" do
22
+ handler_b.expects(:can_render? => true)
23
+
24
+ image_handler.register(handler_a)
25
+ image_handler.register!(handler_b)
26
+
27
+ handler = image_handler.find("arbitrary blob")
28
+ handler.should == handler_b
29
+ end
30
+
31
+ it "can unregister a handler" do
32
+ handler_b.expects(:can_render? => true)
33
+
34
+ image_handler.register(handler_a)
35
+ image_handler.register(handler_b)
36
+
37
+ image_handler.unregister(handler_a)
38
+
39
+ handler = image_handler.find('arbitrary blob')
40
+ handler.should == handler_b
41
+ end
42
+
43
+ it "raises an error when no matching handler is found" do
44
+ handler_a.expects(:can_render? => false)
45
+ handler_b.expects(:can_render? => false)
46
+
47
+ image_handler.register(handler_a)
48
+ image_handler.register(handler_b)
49
+
50
+ expect { image_handler.find("arbitrary blob") }.
51
+ to(raise_error(Prawn::Errors::UnsupportedImageType))
52
+ end
53
+
54
+ end
@@ -1,40 +1,40 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
4
  require 'set'
5
5
  require 'pathname'
6
6
 
7
7
  describe "the image() function" do
8
8
 
9
9
  before(:each) do
10
- @filename = "#{Prawn::DATADIR}/images/pigs.jpg"
10
+ @filename = "#{Prawn::DATADIR}/images/pigs.jpg"
11
11
  create_pdf
12
12
  end
13
13
 
14
14
  it "should only embed an image once, even if it's added multiple times" do
15
15
  @pdf.image @filename, :at => [100,100]
16
16
  @pdf.image @filename, :at => [300,300]
17
-
17
+
18
18
  output = @pdf.render
19
19
  images = PDF::Inspector::XObject.analyze(output)
20
20
  # there should be 2 images in the page resources
21
21
  images.page_xobjects.first.size.should == 2
22
22
  # but only 1 image xobject
23
23
  output.scan(/\/Type \/XObject/).size.should == 1
24
- end
25
-
24
+ end
25
+
26
26
  it "should return the image info object" do
27
27
  info = @pdf.image(@filename)
28
-
28
+
29
29
  info.should be_a_kind_of(Prawn::Images::JPG)
30
-
30
+
31
31
  info.height.should == 453
32
32
  end
33
-
33
+
34
34
  it "should accept IO objects" do
35
35
  file = File.open(@filename, "rb")
36
36
  info = @pdf.image(file)
37
-
37
+
38
38
  info.height.should == 453
39
39
  end
40
40
 
@@ -51,6 +51,23 @@ describe "the image() function" do
51
51
  info.height.should == 453
52
52
  end
53
53
 
54
+ context "setting the length of the bytestream" do
55
+ it "should correctly work with images from Pathname objects" do
56
+ info = @pdf.image(Pathname.new(@filename))
57
+ expect(@pdf).to have_parseable_xobjects
58
+ end
59
+
60
+ it "should correctly work with images from IO objects" do
61
+ info = @pdf.image(File.open(@filename, 'rb'))
62
+ expect(@pdf).to have_parseable_xobjects
63
+ end
64
+
65
+ it "should correctly work with images from IO objects not set to mode rb" do
66
+ info = @pdf.image(File.open(@filename, 'r'))
67
+ expect(@pdf).to have_parseable_xobjects
68
+ end
69
+ end
70
+
54
71
  it "should raise_error an UnsupportedImageType if passed a BMP" do
55
72
  filename = "#{Prawn::DATADIR}/images/tru256.bmp"
56
73
  lambda { @pdf.image filename, :at => [100,100] }.should raise_error(Prawn::Errors::UnsupportedImageType)
@@ -66,36 +83,32 @@ describe "the image() function" do
66
83
  @pdf.state.version.should >= 1.5
67
84
  end
68
85
 
69
- # to support Adobe Reader, which apparently doesn't handle 16-bit alpha
70
- # channels. Verified experimentally [BE] but not confirmed in documentation
71
- # or anything. OS X Preview handles those files just fine.
72
- #
73
- it "should embed 8-bit alpha channels for 16-bit PNGs" do
86
+ it "should embed 16-bit alpha channels for 16-bit PNGs" do
74
87
  @pdf.image "#{Prawn::DATADIR}/images/16bit.png"
75
88
 
76
89
  output = @pdf.render
77
90
  output.should =~ /\/BitsPerComponent 16/
78
- output.should =~ /\/BitsPerComponent 8/
91
+ output.should_not =~ /\/BitsPerComponent 8/
79
92
  end
80
-
93
+
81
94
  it "should flow an image to a new page if it will not fit on a page" do
82
95
  @pdf.image @filename, :fit => [600, 600]
83
96
  @pdf.image @filename, :fit => [600, 600]
84
97
  output = StringIO.new(@pdf.render, 'r+')
85
98
  hash = PDF::Reader::ObjectHash.new(output)
86
99
  pages = hash.values.find {|obj| obj.is_a?(Hash) && obj[:Type] == :Pages}[:Kids]
87
- pages.size.should == 2
100
+ pages.size.should == 2
88
101
  hash[pages[0]][:Resources][:XObject].keys.should == [:I1]
89
102
  hash[pages[1]][:Resources][:XObject].keys.should == [:I2]
90
- end
91
-
103
+ end
104
+
92
105
  it "should not flow an image to a new page if it will fit on one page" do
93
106
  @pdf.image @filename, :fit => [400, 400]
94
107
  @pdf.image @filename, :fit => [400, 400]
95
108
  output = StringIO.new(@pdf.render, 'r+')
96
109
  hash = PDF::Reader::ObjectHash.new(output)
97
110
  pages = hash.values.find {|obj| obj.is_a?(Hash) && obj[:Type] == :Pages}[:Kids]
98
- pages.size.should == 1
111
+ pages.size.should == 1
99
112
  Set.new(hash[pages[0]][:Resources][:XObject].keys).should ==
100
113
  Set.new([:I1, :I2])
101
114
  end
@@ -106,7 +119,7 @@ describe "the image() function" do
106
119
  @pdf.image @filename
107
120
  end
108
121
  end
109
-
122
+
110
123
  describe ":fit option" do
111
124
  it "should fit inside the defined constraints" do
112
125
  info = @pdf.image @filename, :fit => [100,400]
@@ -1,135 +1,159 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
3
3
 
4
- describe "Text::Formatted::Parser#to_array" do
4
+ describe "Text::Formatted::Parser#format" do
5
5
  it "should handle sup" do
6
6
  string = "<sup>superscript</sup>"
7
- array = Prawn::Text::Formatted::Parser.to_array(string)
7
+ array = Prawn::Text::Formatted::Parser.format(string)
8
8
  array[0].should == { :text => "superscript",
9
9
  :styles => [:superscript],
10
10
  :color => nil,
11
11
  :link => nil,
12
12
  :anchor => nil,
13
+ :local => nil,
13
14
  :font => nil,
14
15
  :size => nil,
15
16
  :character_spacing => nil }
16
17
  end
17
18
  it "should handle sub" do
18
19
  string = "<sub>subscript</sub>"
19
- array = Prawn::Text::Formatted::Parser.to_array(string)
20
+ array = Prawn::Text::Formatted::Parser.format(string)
20
21
  array[0].should == { :text => "subscript",
21
22
  :styles => [:subscript],
22
23
  :color => nil,
23
24
  :link => nil,
24
25
  :anchor => nil,
26
+ :local => nil,
25
27
  :font => nil,
26
28
  :size => nil,
27
29
  :character_spacing => nil }
28
30
  end
29
31
  it "should handle rgb" do
30
32
  string = "<color rgb='#ff0000'>red text</color>"
31
- array = Prawn::Text::Formatted::Parser.to_array(string)
33
+ array = Prawn::Text::Formatted::Parser.format(string)
32
34
  array[0].should == { :text => "red text",
33
35
  :styles => [],
34
36
  :color => "ff0000",
35
37
  :link => nil,
36
38
  :anchor => nil,
39
+ :local => nil,
37
40
  :font => nil,
38
41
  :size => nil,
39
42
  :character_spacing => nil }
40
43
  end
41
44
  it "# should be optional in rgb" do
42
45
  string = "<color rgb='ff0000'>red text</color>"
43
- array = Prawn::Text::Formatted::Parser.to_array(string)
46
+ array = Prawn::Text::Formatted::Parser.format(string)
44
47
  array[0].should == { :text => "red text",
45
48
  :styles => [],
46
49
  :color => "ff0000",
47
50
  :link => nil,
48
51
  :anchor => nil,
52
+ :local => nil,
49
53
  :font => nil,
50
54
  :size => nil,
51
55
  :character_spacing => nil }
52
56
  end
53
57
  it "should handle cmyk" do
54
58
  string = "<color c='0' m='100' y='0' k='0'>magenta text</color>"
55
- array = Prawn::Text::Formatted::Parser.to_array(string)
59
+ array = Prawn::Text::Formatted::Parser.format(string)
56
60
  array[0].should == { :text => "magenta text",
57
61
  :styles => [],
58
62
  :color => [0, 100, 0, 0],
59
63
  :link => nil,
60
64
  :anchor => nil,
65
+ :local => nil,
61
66
  :font => nil,
62
67
  :size => nil,
63
68
  :character_spacing => nil }
64
69
  end
65
70
  it "should handle fonts" do
66
71
  string = "<font name='Courier'>Courier text</font>"
67
- array = Prawn::Text::Formatted::Parser.to_array(string)
72
+ array = Prawn::Text::Formatted::Parser.format(string)
68
73
  array[0].should == { :text => "Courier text",
69
74
  :styles => [],
70
75
  :color => nil,
71
76
  :link => nil,
72
77
  :anchor => nil,
78
+ :local => nil,
73
79
  :font => "Courier",
74
80
  :size => nil,
75
81
  :character_spacing => nil }
76
82
  end
77
83
  it "should handle size" do
78
84
  string = "<font size='14'>14 point text</font>"
79
- array = Prawn::Text::Formatted::Parser.to_array(string)
85
+ array = Prawn::Text::Formatted::Parser.format(string)
80
86
  array[0].should == { :text => "14 point text",
81
87
  :styles => [],
82
88
  :color => nil,
83
89
  :link => nil,
84
90
  :anchor => nil,
91
+ :local => nil,
85
92
  :font => nil,
86
93
  :size => 14,
87
94
  :character_spacing => nil }
88
95
  end
89
96
  it "should handle character_spacing" do
90
97
  string = "<font character_spacing='2.5'>extra character spacing</font>"
91
- array = Prawn::Text::Formatted::Parser.to_array(string)
98
+ array = Prawn::Text::Formatted::Parser.format(string)
92
99
  array[0].should == { :text => "extra character spacing",
93
100
  :styles => [],
94
101
  :color => nil,
95
102
  :link => nil,
96
103
  :anchor => nil,
104
+ :local => nil,
97
105
  :font => nil,
98
106
  :size => nil,
99
107
  :character_spacing => 2.5 }
100
108
  end
101
109
  it "should handle links" do
102
110
  string = "<link href='http://example.com'>external link</link>"
103
- array = Prawn::Text::Formatted::Parser.to_array(string)
111
+ array = Prawn::Text::Formatted::Parser.format(string)
104
112
  array[0].should == { :text => "external link",
105
113
  :styles => [],
106
114
  :color => nil,
107
115
  :link => "http://example.com",
108
116
  :anchor => nil,
117
+ :local => nil,
118
+ :font => nil,
119
+ :size => nil,
120
+ :character_spacing => nil }
121
+ end
122
+ it "should handle local links" do
123
+ string = "<link local='/home/example/foo.bar'>local link</link>"
124
+ array = Prawn::Text::Formatted::Parser.format(string)
125
+ array[0].should == { :text => "local link",
126
+ :styles => [],
127
+ :color => nil,
128
+ :link => nil,
129
+ :anchor => nil,
130
+ :local => "/home/example/foo.bar",
109
131
  :font => nil,
110
132
  :size => nil,
111
133
  :character_spacing => nil }
112
134
  end
113
135
  it "should handle anchors" do
114
136
  string = "<link anchor='ToC'>internal link</link>"
115
- array = Prawn::Text::Formatted::Parser.to_array(string)
137
+ array = Prawn::Text::Formatted::Parser.format(string)
116
138
  array[0].should == { :text => "internal link",
117
139
  :styles => [],
118
140
  :color => nil,
119
141
  :link => nil,
120
142
  :anchor => "ToC",
143
+ :local => nil,
121
144
  :font => nil,
122
145
  :size => nil,
123
146
  :character_spacing => nil }
124
147
  end
125
148
  it "should handle higher order characters properly" do
126
149
  string = "<b>©\n©</b>"
127
- array = Prawn::Text::Formatted::Parser.to_array(string)
150
+ array = Prawn::Text::Formatted::Parser.format(string)
128
151
  array[0].should == { :text => "©",
129
152
  :styles => [:bold],
130
153
  :color => nil,
131
154
  :link => nil,
132
155
  :anchor => nil,
156
+ :local => nil,
133
157
  :font => nil,
134
158
  :size => nil,
135
159
  :character_spacing => nil }
@@ -138,6 +162,7 @@ describe "Text::Formatted::Parser#to_array" do
138
162
  :color => nil,
139
163
  :link => nil,
140
164
  :anchor => nil,
165
+ :local => nil,
141
166
  :font => nil,
142
167
  :size => nil,
143
168
  :character_spacing => nil }
@@ -146,55 +171,60 @@ describe "Text::Formatted::Parser#to_array" do
146
171
  :color => nil,
147
172
  :link => nil,
148
173
  :anchor => nil,
174
+ :local => nil,
149
175
  :font => nil,
150
176
  :size => nil,
151
177
  :character_spacing => nil }
152
178
  end
153
179
  it "should convert &lt; &gt;, and &amp; to <, >, and &, respectively" do
154
180
  string = "hello <b>&lt;, &gt;, and &amp;</b>"
155
- array = Prawn::Text::Formatted::Parser.to_array(string)
181
+ array = Prawn::Text::Formatted::Parser.format(string)
156
182
  array[1].should == { :text => "<, >, and &",
157
183
  :styles => [:bold],
158
184
  :color => nil,
159
185
  :link => nil,
160
186
  :anchor => nil,
187
+ :local => nil,
161
188
  :font => nil,
162
189
  :size => nil,
163
190
  :character_spacing => nil }
164
191
  end
165
192
  it "should handle double qoutes around tag attributes" do
166
193
  string = 'some <font size="14">sized</font> text'
167
- array = Prawn::Text::Formatted::Parser.to_array(string)
194
+ array = Prawn::Text::Formatted::Parser.format(string)
168
195
  array[1].should == { :text => "sized",
169
196
  :styles => [],
170
197
  :color => nil,
171
198
  :link => nil,
172
199
  :anchor => nil,
200
+ :local => nil,
173
201
  :font => nil,
174
202
  :size => 14,
175
203
  :character_spacing => nil }
176
204
  end
177
205
  it "should handle single qoutes around tag attributes" do
178
206
  string = "some <font size='14'>sized</font> text"
179
- array = Prawn::Text::Formatted::Parser.to_array(string)
207
+ array = Prawn::Text::Formatted::Parser.format(string)
180
208
  array[1].should == { :text => "sized",
181
209
  :styles => [],
182
210
  :color => nil,
183
211
  :link => nil,
184
212
  :anchor => nil,
213
+ :local => nil,
185
214
  :font => nil,
186
215
  :size => 14,
187
216
  :character_spacing => nil }
188
217
  end
189
218
  it "should construct a formatted text array from a string" do
190
219
  string = "hello <b>world\nhow <i>are</i></b> you?"
191
- array = Prawn::Text::Formatted::Parser.to_array(string)
220
+ array = Prawn::Text::Formatted::Parser.format(string)
192
221
 
193
222
  array[0].should == { :text => "hello ",
194
223
  :styles => [],
195
224
  :color => nil,
196
225
  :link => nil,
197
226
  :anchor => nil,
227
+ :local => nil,
198
228
  :font => nil,
199
229
  :size => nil,
200
230
  :character_spacing => nil }
@@ -203,6 +233,7 @@ describe "Text::Formatted::Parser#to_array" do
203
233
  :color => nil,
204
234
  :link => nil,
205
235
  :anchor => nil,
236
+ :local => nil,
206
237
  :font => nil,
207
238
  :size => nil,
208
239
  :character_spacing => nil }
@@ -211,6 +242,7 @@ describe "Text::Formatted::Parser#to_array" do
211
242
  :color => nil,
212
243
  :link => nil,
213
244
  :anchor => nil,
245
+ :local => nil,
214
246
  :font => nil,
215
247
  :size => nil,
216
248
  :character_spacing => nil }
@@ -219,6 +251,7 @@ describe "Text::Formatted::Parser#to_array" do
219
251
  :color => nil,
220
252
  :link => nil,
221
253
  :anchor => nil,
254
+ :local => nil,
222
255
  :font => nil,
223
256
  :size => nil,
224
257
  :character_spacing => nil }
@@ -227,6 +260,7 @@ describe "Text::Formatted::Parser#to_array" do
227
260
  :color => nil,
228
261
  :link => nil,
229
262
  :anchor => nil,
263
+ :local => nil,
230
264
  :font => nil,
231
265
  :size => nil,
232
266
  :character_spacing => nil }
@@ -235,19 +269,21 @@ describe "Text::Formatted::Parser#to_array" do
235
269
  :color => nil,
236
270
  :link => nil,
237
271
  :anchor => nil,
272
+ :local => nil,
238
273
  :font => nil,
239
274
  :size => nil,
240
275
  :character_spacing => nil }
241
276
  end
242
277
  it "should accept <strong> as an alternative to <b>" do
243
278
  string = "<strong>bold</strong> not bold"
244
- array = Prawn::Text::Formatted::Parser.to_array(string)
279
+ array = Prawn::Text::Formatted::Parser.format(string)
245
280
 
246
281
  array[0].should == { :text => "bold",
247
282
  :styles => [:bold],
248
283
  :color => nil,
249
284
  :link => nil,
250
285
  :anchor => nil,
286
+ :local => nil,
251
287
  :font => nil,
252
288
  :size => nil,
253
289
  :character_spacing => nil }
@@ -256,19 +292,21 @@ describe "Text::Formatted::Parser#to_array" do
256
292
  :color => nil,
257
293
  :link => nil,
258
294
  :anchor => nil,
295
+ :local => nil,
259
296
  :font => nil,
260
297
  :size => nil,
261
298
  :character_spacing => nil }
262
299
  end
263
300
  it "should accept <em> as an alternative to <i>" do
264
301
  string = "<em>italic</em> not italic"
265
- array = Prawn::Text::Formatted::Parser.to_array(string)
302
+ array = Prawn::Text::Formatted::Parser.format(string)
266
303
 
267
304
  array[0].should == { :text => "italic",
268
305
  :styles => [:italic],
269
306
  :color => nil,
270
307
  :link => nil,
271
308
  :anchor => nil,
309
+ :local => nil,
272
310
  :font => nil,
273
311
  :size => nil,
274
312
  :character_spacing => nil }
@@ -277,19 +315,21 @@ describe "Text::Formatted::Parser#to_array" do
277
315
  :color => nil,
278
316
  :link => nil,
279
317
  :anchor => nil,
318
+ :local => nil,
280
319
  :font => nil,
281
320
  :size => nil,
282
321
  :character_spacing => nil }
283
322
  end
284
323
  it "should accept <a> as an alternative to <link>" do
285
324
  string = "<a href='http://example.com'>link</a> not a link"
286
- array = Prawn::Text::Formatted::Parser.to_array(string)
325
+ array = Prawn::Text::Formatted::Parser.format(string)
287
326
 
288
327
  array[0].should == { :text => "link",
289
328
  :styles => [],
290
329
  :color => nil,
291
330
  :link => "http://example.com",
292
331
  :anchor => nil,
332
+ :local => nil,
293
333
  :font => nil,
294
334
  :size => nil,
295
335
  :character_spacing => nil }
@@ -298,13 +338,14 @@ describe "Text::Formatted::Parser#to_array" do
298
338
  :color => nil,
299
339
  :link => nil,
300
340
  :anchor => nil,
341
+ :local => nil,
301
342
  :font => nil,
302
343
  :size => nil,
303
344
  :character_spacing => nil }
304
345
  end
305
346
 
306
347
  it "should turn <br>, <br/> into newline" do
307
- array = Prawn::Text::Formatted::Parser.to_array("hello<br>big<br/>world")
348
+ array = Prawn::Text::Formatted::Parser.format("hello<br>big<br/>world")
308
349
  array.map { |frag| frag[:text] }.join.should == "hello\nbig\nworld"
309
350
  end
310
351
  end
@@ -318,6 +359,7 @@ describe "Text::Formatted::Parser#to_string" do
318
359
  :color => nil,
319
360
  :link => nil,
320
361
  :anchor => nil,
362
+ :local => nil,
321
363
  :font => nil,
322
364
  :size => nil,
323
365
  :character_spacing => nil }]
@@ -330,6 +372,7 @@ describe "Text::Formatted::Parser#to_string" do
330
372
  :color => nil,
331
373
  :link => nil,
332
374
  :anchor => nil,
375
+ :local => nil,
333
376
  :font => nil,
334
377
  :size => nil,
335
378
  :character_spacing => nil }]
@@ -342,6 +385,7 @@ describe "Text::Formatted::Parser#to_string" do
342
385
  :color => "ff0000",
343
386
  :link => nil,
344
387
  :anchor => nil,
388
+ :local => nil,
345
389
  :font => nil,
346
390
  :size => nil,
347
391
  :character_spacing => nil }]
@@ -354,6 +398,7 @@ describe "Text::Formatted::Parser#to_string" do
354
398
  :color => [0, 100, 0, 0],
355
399
  :link => nil,
356
400
  :anchor => nil,
401
+ :local => nil,
357
402
  :font => nil,
358
403
  :size => nil,
359
404
  :character_spacing => nil }]
@@ -366,6 +411,7 @@ describe "Text::Formatted::Parser#to_string" do
366
411
  :color => nil,
367
412
  :link => nil,
368
413
  :anchor => nil,
414
+ :local => nil,
369
415
  :font => "Courier",
370
416
  :size => nil,
371
417
  :character_spacing => nil }]
@@ -378,6 +424,7 @@ describe "Text::Formatted::Parser#to_string" do
378
424
  :color => nil,
379
425
  :link => nil,
380
426
  :anchor => nil,
427
+ :local => nil,
381
428
  :font => nil,
382
429
  :size => 14,
383
430
  :character_spacing => nil }]
@@ -390,6 +437,7 @@ describe "Text::Formatted::Parser#to_string" do
390
437
  :color => nil,
391
438
  :link => nil,
392
439
  :anchor => nil,
440
+ :local => nil,
393
441
  :font => nil,
394
442
  :size => nil,
395
443
  :character_spacing => 2.5 }]
@@ -401,6 +449,7 @@ describe "Text::Formatted::Parser#to_string" do
401
449
  :color => nil,
402
450
  :link => "http://example.com",
403
451
  :anchor => nil,
452
+ :local => nil,
404
453
  :font => nil,
405
454
  :size => nil,
406
455
  :character_spacing => nil }]