prawn 0.4.1 → 0.5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. data/lib/prawn.rb +2 -72
  2. metadata +33 -224
  3. data/COPYING +0 -340
  4. data/LICENSE +0 -56
  5. data/README +0 -40
  6. data/Rakefile +0 -79
  7. data/data/encodings/win_ansi.txt +0 -29
  8. data/data/fonts/Action Man.dfont +0 -0
  9. data/data/fonts/Activa.ttf +0 -0
  10. data/data/fonts/Chalkboard.ttf +0 -0
  11. data/data/fonts/Courier-Bold.afm +0 -342
  12. data/data/fonts/Courier-BoldOblique.afm +0 -342
  13. data/data/fonts/Courier-Oblique.afm +0 -342
  14. data/data/fonts/Courier.afm +0 -342
  15. data/data/fonts/DejaVuSans.ttf +0 -0
  16. data/data/fonts/Dustismo_Roman.ttf +0 -0
  17. data/data/fonts/Helvetica-Bold.afm +0 -2827
  18. data/data/fonts/Helvetica-BoldOblique.afm +0 -2827
  19. data/data/fonts/Helvetica-Oblique.afm +0 -3051
  20. data/data/fonts/Helvetica.afm +0 -3051
  21. data/data/fonts/MustRead.html +0 -19
  22. data/data/fonts/Symbol.afm +0 -213
  23. data/data/fonts/Times-Bold.afm +0 -2588
  24. data/data/fonts/Times-BoldItalic.afm +0 -2384
  25. data/data/fonts/Times-Italic.afm +0 -2667
  26. data/data/fonts/Times-Roman.afm +0 -2419
  27. data/data/fonts/ZapfDingbats.afm +0 -225
  28. data/data/fonts/comicsans.ttf +0 -0
  29. data/data/fonts/gkai00mp.ttf +0 -0
  30. data/data/images/arrow.png +0 -0
  31. data/data/images/arrow2.png +0 -0
  32. data/data/images/barcode_issue.png +0 -0
  33. data/data/images/dice.alpha +0 -0
  34. data/data/images/dice.dat +0 -0
  35. data/data/images/dice.png +0 -0
  36. data/data/images/fractal.jpg +0 -0
  37. data/data/images/letterhead.jpg +0 -0
  38. data/data/images/page_white_text.alpha +0 -0
  39. data/data/images/page_white_text.dat +0 -0
  40. data/data/images/page_white_text.png +0 -0
  41. data/data/images/pigs.jpg +0 -0
  42. data/data/images/rails.dat +0 -0
  43. data/data/images/rails.png +0 -0
  44. data/data/images/ruport.png +0 -0
  45. data/data/images/ruport_data.dat +0 -0
  46. data/data/images/ruport_transparent.png +0 -0
  47. data/data/images/ruport_type0.png +0 -0
  48. data/data/images/stef.jpg +0 -0
  49. data/data/images/web-links.dat +0 -1
  50. data/data/images/web-links.png +0 -0
  51. data/data/shift_jis_text.txt +0 -1
  52. data/examples/bounding_box/bounding_boxes.rb +0 -44
  53. data/examples/bounding_box/lazy_bounding_boxes.rb +0 -28
  54. data/examples/bounding_box/padded_box.rb +0 -24
  55. data/examples/bounding_box/russian_boxes.rb +0 -37
  56. data/examples/general/background.rb +0 -20
  57. data/examples/general/canvas.rb +0 -16
  58. data/examples/general/measurement_units.rb +0 -52
  59. data/examples/general/multi_page_layout.rb +0 -17
  60. data/examples/general/page_geometry.rb +0 -32
  61. data/examples/graphics/basic_images.rb +0 -27
  62. data/examples/graphics/cmyk.rb +0 -13
  63. data/examples/graphics/curves.rb +0 -12
  64. data/examples/graphics/hexagon.rb +0 -14
  65. data/examples/graphics/image_fit.rb +0 -16
  66. data/examples/graphics/image_flow.rb +0 -38
  67. data/examples/graphics/image_position.rb +0 -18
  68. data/examples/graphics/line.rb +0 -33
  69. data/examples/graphics/png_types.rb +0 -23
  70. data/examples/graphics/polygons.rb +0 -17
  71. data/examples/graphics/remote_images.rb +0 -12
  72. data/examples/graphics/ruport_style_helpers.rb +0 -20
  73. data/examples/graphics/stroke_bounds.rb +0 -23
  74. data/examples/m17n/chinese_text_wrapping.rb +0 -20
  75. data/examples/m17n/euro.rb +0 -16
  76. data/examples/m17n/sjis.rb +0 -29
  77. data/examples/m17n/utf8.rb +0 -14
  78. data/examples/m17n/win_ansi_charset.rb +0 -55
  79. data/examples/text/alignment.rb +0 -19
  80. data/examples/text/dfont.rb +0 -49
  81. data/examples/text/family_based_styling.rb +0 -25
  82. data/examples/text/flowing_text_with_header_and_footer.rb +0 -37
  83. data/examples/text/font_calculations.rb +0 -92
  84. data/examples/text/font_size.rb +0 -34
  85. data/examples/text/kerning.rb +0 -31
  86. data/examples/text/simple_text.rb +0 -18
  87. data/examples/text/simple_text_ttf.rb +0 -18
  88. data/examples/text/span.rb +0 -30
  89. data/examples/text/text_box.rb +0 -26
  90. data/examples/text/text_flow.rb +0 -68
  91. data/lib/prawn/compatibility.rb +0 -38
  92. data/lib/prawn/document.rb +0 -309
  93. data/lib/prawn/document/annotations.rb +0 -63
  94. data/lib/prawn/document/bounding_box.rb +0 -368
  95. data/lib/prawn/document/destinations.rb +0 -81
  96. data/lib/prawn/document/internals.rb +0 -126
  97. data/lib/prawn/document/page_geometry.rb +0 -79
  98. data/lib/prawn/document/span.rb +0 -55
  99. data/lib/prawn/document/text.rb +0 -185
  100. data/lib/prawn/document/text/box.rb +0 -76
  101. data/lib/prawn/document/text/wrapping.rb +0 -59
  102. data/lib/prawn/encoding.rb +0 -121
  103. data/lib/prawn/errors.rb +0 -40
  104. data/lib/prawn/font.rb +0 -277
  105. data/lib/prawn/font/afm.rb +0 -202
  106. data/lib/prawn/font/dfont.rb +0 -31
  107. data/lib/prawn/font/ttf.rb +0 -326
  108. data/lib/prawn/graphics.rb +0 -257
  109. data/lib/prawn/graphics/color.rb +0 -140
  110. data/lib/prawn/images.rb +0 -339
  111. data/lib/prawn/images/jpg.rb +0 -45
  112. data/lib/prawn/images/png.rb +0 -199
  113. data/lib/prawn/literal_string.rb +0 -14
  114. data/lib/prawn/measurement_extensions.rb +0 -46
  115. data/lib/prawn/measurements.rb +0 -71
  116. data/lib/prawn/name_tree.rb +0 -165
  117. data/lib/prawn/pdf_object.rb +0 -73
  118. data/lib/prawn/reference.rb +0 -59
  119. data/spec/annotations_spec.rb +0 -90
  120. data/spec/bounding_box_spec.rb +0 -141
  121. data/spec/destinations_spec.rb +0 -15
  122. data/spec/document_spec.rb +0 -193
  123. data/spec/font_spec.rb +0 -234
  124. data/spec/graphics_spec.rb +0 -209
  125. data/spec/images_spec.rb +0 -68
  126. data/spec/jpg_spec.rb +0 -25
  127. data/spec/measurement_units_spec.rb +0 -23
  128. data/spec/name_tree_spec.rb +0 -103
  129. data/spec/pdf_object_spec.rb +0 -112
  130. data/spec/png_spec.rb +0 -196
  131. data/spec/reference_spec.rb +0 -42
  132. data/spec/spec_helper.rb +0 -23
  133. data/spec/text_spec.rb +0 -178
  134. data/vendor/pdf-inspector/README +0 -18
  135. data/vendor/pdf-inspector/lib/pdf/inspector.rb +0 -25
  136. data/vendor/pdf-inspector/lib/pdf/inspector/graphics.rb +0 -80
  137. data/vendor/pdf-inspector/lib/pdf/inspector/page.rb +0 -16
  138. data/vendor/pdf-inspector/lib/pdf/inspector/text.rb +0 -31
  139. data/vendor/pdf-inspector/lib/pdf/inspector/xobject.rb +0 -19
  140. data/vendor/ttfunk/data/fonts/DejaVuSans.ttf +0 -0
  141. data/vendor/ttfunk/data/fonts/comicsans.ttf +0 -0
  142. data/vendor/ttfunk/example.rb +0 -45
  143. data/vendor/ttfunk/lib/ttfunk.rb +0 -102
  144. data/vendor/ttfunk/lib/ttfunk/directory.rb +0 -17
  145. data/vendor/ttfunk/lib/ttfunk/encoding/mac_roman.rb +0 -88
  146. data/vendor/ttfunk/lib/ttfunk/encoding/windows_1252.rb +0 -69
  147. data/vendor/ttfunk/lib/ttfunk/reader.rb +0 -44
  148. data/vendor/ttfunk/lib/ttfunk/resource_file.rb +0 -78
  149. data/vendor/ttfunk/lib/ttfunk/subset.rb +0 -18
  150. data/vendor/ttfunk/lib/ttfunk/subset/base.rb +0 -141
  151. data/vendor/ttfunk/lib/ttfunk/subset/mac_roman.rb +0 -46
  152. data/vendor/ttfunk/lib/ttfunk/subset/unicode.rb +0 -48
  153. data/vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb +0 -63
  154. data/vendor/ttfunk/lib/ttfunk/subset/windows_1252.rb +0 -51
  155. data/vendor/ttfunk/lib/ttfunk/subset_collection.rb +0 -72
  156. data/vendor/ttfunk/lib/ttfunk/table.rb +0 -46
  157. data/vendor/ttfunk/lib/ttfunk/table/cmap.rb +0 -34
  158. data/vendor/ttfunk/lib/ttfunk/table/cmap/format00.rb +0 -54
  159. data/vendor/ttfunk/lib/ttfunk/table/cmap/format04.rb +0 -126
  160. data/vendor/ttfunk/lib/ttfunk/table/cmap/subtable.rb +0 -79
  161. data/vendor/ttfunk/lib/ttfunk/table/glyf.rb +0 -64
  162. data/vendor/ttfunk/lib/ttfunk/table/glyf/compound.rb +0 -81
  163. data/vendor/ttfunk/lib/ttfunk/table/glyf/simple.rb +0 -37
  164. data/vendor/ttfunk/lib/ttfunk/table/head.rb +0 -44
  165. data/vendor/ttfunk/lib/ttfunk/table/hhea.rb +0 -41
  166. data/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +0 -47
  167. data/vendor/ttfunk/lib/ttfunk/table/kern.rb +0 -79
  168. data/vendor/ttfunk/lib/ttfunk/table/kern/format0.rb +0 -62
  169. data/vendor/ttfunk/lib/ttfunk/table/loca.rb +0 -43
  170. data/vendor/ttfunk/lib/ttfunk/table/maxp.rb +0 -40
  171. data/vendor/ttfunk/lib/ttfunk/table/name.rb +0 -119
  172. data/vendor/ttfunk/lib/ttfunk/table/os2.rb +0 -78
  173. data/vendor/ttfunk/lib/ttfunk/table/post.rb +0 -91
  174. data/vendor/ttfunk/lib/ttfunk/table/post/format10.rb +0 -43
  175. data/vendor/ttfunk/lib/ttfunk/table/post/format20.rb +0 -35
  176. data/vendor/ttfunk/lib/ttfunk/table/post/format25.rb +0 -23
  177. data/vendor/ttfunk/lib/ttfunk/table/post/format30.rb +0 -17
  178. data/vendor/ttfunk/lib/ttfunk/table/post/format40.rb +0 -17
  179. data/vendor/ttfunk/lib/ttfunk/table/simple.rb +0 -14
@@ -1,68 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # Basic text flowing example including the use of bounding boxes. A somewhat
4
- # old example, mostly retained for nostalgia.
5
- #
6
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
7
- require "prawn"
8
-
9
- content = <<-EOS
10
- How does
11
- Prawn deal with
12
- white
13
- space
14
-
15
- and
16
-
17
- line
18
- breaks?
19
- EOS
20
-
21
- poem = <<-EOS
22
- GOOD-BYE
23
-
24
- Good-bye, proud world! I'm going home: Thou art not my friend, and I'm not thine. Long through thy weary crowds I roam; A river-ark on the ocean brine, Long I've been tossed like the driven foam: But now, proud world! I'm going home.
25
-
26
- Good-bye to Flattery's fawning face; To Grandeur with his wise grimace; To upstart Wealth's averted eye; To supple Office, low and high; To crowded halls, to court and street; To frozen hearts and hasting feet; To those who go, and those who come; Good-bye, proud world! I'm going home.
27
-
28
- I am going to my own hearth-stone, Bosomed in yon green hills alone,-- secret nook in a pleasant land, Whose groves the frolic fairies planned; Where arches green, the livelong day, Echo the blackbird's roundelay, And vulgar feet have never trod A spot that is sacred to thought and God.
29
-
30
- O, when I am safe in my sylvan home, I tread on the pride of Greece and Rome; And when I am stretched beneath the pines, Where the evening star so holy shines, I laugh at the lore and the pride of man, At the sophist schools and the learned clan; For what are they all, in their high conceit, When man in the bush with God may meet?
31
- EOS
32
-
33
- overflow = "This text should flow gracefully onto the next page, like a stream"+
34
- " flows elegantly from a mountain lake down into the village below."
35
-
36
- Prawn::Document.generate("flow.pdf") do |pdf|
37
-
38
- pdf.font "Times-Roman"
39
- pdf.stroke_line [pdf.bounds.left, pdf.bounds.top],
40
- [pdf.bounds.right, pdf.bounds.top]
41
-
42
- pdf.text content, :size => 10
43
-
44
- pdf.bounding_box([100,600], :width => 200, :height => 525) do
45
- pdf.stroke_line [pdf.bounds.left, pdf.bounds.top],
46
- [pdf.bounds.right, pdf.bounds.top]
47
- pdf.text poem, :size => 12
48
- end
49
-
50
- pdf.bounding_box([325,600], :width => 200, :height => 525) do
51
- pdf.stroke_line [pdf.bounds.left, pdf.bounds.top],
52
- [pdf.bounds.right, pdf.bounds.top]
53
- pdf.text poem.reverse, :size => 12
54
- end
55
-
56
- pdf.text overflow * 10, :size => 14
57
-
58
- pdf.text "Hooray! We've conquered the evil PDF gods", :size => 36
59
-
60
- pdf.bounding_box([100,450], :width => 300) do
61
- pdf.stroke_line [pdf.bounds.left, pdf.bounds.top],
62
- [pdf.bounds.right, pdf.bounds.top]
63
- pdf.text poem, :size => 10, :spacing => 5
64
- end
65
-
66
- pdf.text "And this text automatically goes below the poem", :size => 18
67
-
68
- end
@@ -1,38 +0,0 @@
1
- # coding: utf-8
2
- #
3
- # Why would we ever use Ruby 1.8.7 when we can backport with something
4
- # as simple as this?
5
- #
6
- class String #:nodoc:
7
- unless "".respond_to?(:lines)
8
- alias_method :lines, :to_a
9
- end
10
- end
11
-
12
- unless File.respond_to?(:binread)
13
- def File.binread(file)
14
- File.open(file,"rb") { |f| f.read }
15
- end
16
- end
17
-
18
- if RUBY_VERSION < "1.9"
19
-
20
- def ruby_18 #:nodoc:
21
- yield
22
- end
23
-
24
- def ruby_19 #:nodoc:
25
- false
26
- end
27
-
28
- else
29
-
30
- def ruby_18 #:nodoc:
31
- false
32
- end
33
-
34
- def ruby_19 #:nodoc:
35
- yield
36
- end
37
-
38
- end
@@ -1,309 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # document.rb : Implements PDF document generation for Prawn
4
- #
5
- # Copyright April 2008, Gregory Brown. All Rights Reserved.
6
- #
7
- # This is free software. Please see the LICENSE and COPYING files for details.
8
-
9
- require "stringio"
10
- require "prawn/document/page_geometry"
11
- require "prawn/document/bounding_box"
12
- require "prawn/document/internals"
13
- require "prawn/document/span"
14
- require "prawn/document/text"
15
- require "prawn/document/annotations"
16
- require "prawn/document/destinations"
17
-
18
- module Prawn
19
- class Document
20
-
21
- include Text
22
- include PageGeometry
23
- include Internals
24
- include Annotations
25
- include Destinations
26
- include Prawn::Graphics
27
- include Prawn::Images
28
-
29
- attr_accessor :y, :margin_box
30
- attr_reader :margins, :page_size, :page_layout
31
- attr_writer :font_size
32
-
33
- # Creates and renders a PDF document.
34
- #
35
- # When using the implicit block form, Prawn will evaluate the block
36
- # within an instance of Prawn::Document, simplifying your syntax.
37
- # However, please note that you will not be able to reference variables
38
- # from the enclosing scope within this block.
39
- #
40
- # # Using implicit block form and rendering to a file
41
- # Prawn::Document.generate "foo.pdf" do
42
- # font "Times-Roman"
43
- # text "Hello World", :at => [200,720], :size => 32
44
- # end
45
- #
46
- # If you need to access your local and instance variables, use the explicit
47
- # block form shown below. In this case, Prawn yields an instance of
48
- # PDF::Document and the block is an ordinary closure:
49
- #
50
- # # Using explicit block form and rendering to a file
51
- # content = "Hello World"
52
- # Prawn::Document.generate "foo.pdf" do |pdf|
53
- # pdf.font "Times-Roman"
54
- # pdf.text content, :at => [200,720], :size => 32
55
- # end
56
- #
57
- def self.generate(filename,options={},&block)
58
- pdf = new(options,&block)
59
- pdf.render_file(filename)
60
- end
61
-
62
- # Creates a new PDF Document. The following options are available:
63
- #
64
- # <tt>:page_size</tt>:: One of the Document::PageGeometry::SIZES [LETTER]
65
- # <tt>:page_layout</tt>:: Either <tt>:portrait</tt> or <tt>:landscape</tt>
66
- # <tt>:left_margin</tt>:: Sets the left margin in points [ 0.5 inch]
67
- # <tt>:right_margin</tt>:: Sets the right margin in points [ 0.5 inch]
68
- # <tt>:top_margin</tt>:: Sets the top margin in points [ 0.5 inch]
69
- # <tt>:bottom_margin</tt>:: Sets the bottom margin in points [0.5 inch]
70
- # <tt>:skip_page_creation</tt>:: Creates a document without starting the first page [false]
71
- # <tt>:compress</tt>:: Compresses content streams before rendering them [false]
72
- # <tt>:background</tt>:: An image path to be used as background on all pages [nil]
73
- #
74
- # Usage:
75
- #
76
- # # New document, US Letter paper, portrait orientation
77
- # pdf = Prawn::Document.new
78
- #
79
- # # New document, A4 paper, landscaped
80
- # pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
81
- #
82
- # # New document, with background
83
- # pdf = Prawn::Document.new(:background => "#{Prawn::BASEDIR}/data/images/pigs.jpg")
84
- #
85
- def initialize(options={},&block)
86
- Prawn.verify_options [:page_size, :page_layout, :left_margin,
87
- :right_margin, :top_margin, :bottom_margin, :skip_page_creation,
88
- :compress, :skip_encoding, :text_options, :background ], options
89
-
90
- @objects = []
91
- @info = ref(:Creator => "Prawn", :Producer => "Prawn")
92
- @pages = ref(:Type => :Pages, :Count => 0, :Kids => [])
93
- @root = ref(:Type => :Catalog, :Pages => @pages)
94
- @page_size = options[:page_size] || "LETTER"
95
- @page_layout = options[:page_layout] || :portrait
96
- @compress = options[:compress] || false
97
- @skip_encoding = options[:skip_encoding]
98
- @background = options[:background]
99
- @font_size = 12
100
-
101
- text_options.update(options[:text_options] || {})
102
-
103
- @margins = { :left => options[:left_margin] || 36,
104
- :right => options[:right_margin] || 36,
105
- :top => options[:top_margin] || 36,
106
- :bottom => options[:bottom_margin] || 36 }
107
-
108
- generate_margin_box
109
-
110
- @bounding_box = @margin_box
111
-
112
- start_new_page unless options[:skip_page_creation]
113
-
114
- if block
115
- block.arity < 1 ? instance_eval(&block) : block[self]
116
- end
117
- end
118
-
119
- # Creates and advances to a new page in the document.
120
- #
121
- # Page size, margins, and layout can also be set when generating a
122
- # new page. These values will become the new defaults for page creation
123
- #
124
- # pdf.start_new_page(:size => "LEGAL", :layout => :landscape)
125
- # pdf.start_new_page(:left_margin => 50, :right_margin => 50)
126
- #
127
- def start_new_page(options = {})
128
- @page_size = options[:size] if options[:size]
129
- @page_layout = options[:layout] if options[:layout]
130
-
131
- [:left,:right,:top,:bottom].each do |side|
132
- if options[:"#{side}_margin"]
133
- @margins[side] = options[:"#{side}_margin"]
134
- end
135
- end
136
-
137
- finish_page_content if @page_content
138
- build_new_page_content
139
-
140
- @pages.data[:Kids] << @current_page
141
- @pages.data[:Count] += 1
142
-
143
- add_content "q"
144
-
145
- @y = @bounding_box.absolute_top
146
-
147
- image(@background, :at => [0,@y]) if @background
148
- end
149
-
150
- # Returns the number of pages in the document
151
- #
152
- # pdf = Prawn::Document.new
153
- # pdf.page_count #=> 1
154
- # 3.times { pdf.start_new_page }
155
- # pdf.page_count #=> 4
156
- #
157
- def page_count
158
- @pages.data[:Count]
159
- end
160
-
161
- # The current y drawing position relative to the innermost bounding box,
162
- # or to the page margins at the top level.
163
- #
164
- def cursor
165
- y - bounds.absolute_bottom
166
- end
167
-
168
- # Renders the PDF document to string
169
- #
170
- def render
171
- output = StringIO.new
172
- finish_page_content
173
-
174
- render_header(output)
175
- render_body(output)
176
- render_xref(output)
177
- render_trailer(output)
178
- str = output.string
179
- str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
180
- str
181
- end
182
-
183
- # Renders the PDF document to file.
184
- #
185
- # pdf.render_file "foo.pdf"
186
- #
187
- def render_file(filename)
188
- Kernel.const_defined?("Encoding") ? mode = "wb:ASCII-8BIT" : mode = "wb"
189
- File.open(filename,mode) { |f| f << render }
190
- end
191
-
192
- # Returns the current BoundingBox object, which is by default
193
- # the box represented by the margin box. When called from within
194
- # a <tt>bounding_box</tt> block, the box defined by that call will
195
- # be used.
196
- #
197
- def bounds
198
- @bounding_box
199
- end
200
-
201
- # Sets Document#bounds to the BoundingBox provided. If you don't know
202
- # why you'd need to do this, chances are, you can ignore this feature
203
- #
204
- def bounds=(bounding_box)
205
- @bounding_box = bounding_box
206
- end
207
-
208
- # Moves up the document by n points
209
- #
210
- def move_up(n)
211
- self.y += n
212
- end
213
-
214
- # Moves down the document by n point
215
- #
216
- def move_down(n)
217
- self.y -= n
218
- end
219
-
220
- # Moves down the document and then executes a block.
221
- #
222
- # pdf.text "some text"
223
- # pdf.pad_top(100) do
224
- # pdf.text "This is 100 points below the previous line of text"
225
- # end
226
- # pdf.text "This text appears right below the previous line of text"
227
- #
228
- def pad_top(y)
229
- move_down(y)
230
- yield
231
- end
232
-
233
- # Executes a block then moves down the document
234
- #
235
- # pdf.text "some text"
236
- # pdf.pad_bottom(100) do
237
- # pdf.text "This text appears right below the previous line of text"
238
- # end
239
- # pdf.text "This is 100 points below the previous line of text"
240
- #
241
- def pad_bottom(y)
242
- yield
243
- move_down(y)
244
- end
245
-
246
- # Moves down the document by y, executes a block, then moves down the
247
- # document by y again.
248
- #
249
- # pdf.text "some text"
250
- # pdf.pad(100) do
251
- # pdf.text "This is 100 points below the previous line of text"
252
- # end
253
- # pdf.text "This is 100 points below the previous line of text"
254
- #
255
- def pad(y)
256
- move_down(y)
257
- yield
258
- move_down(y)
259
- end
260
-
261
- def mask(*fields) # :nodoc:
262
- # Stores the current state of the named attributes, executes the block, and
263
- # then restores the original values after the block has executed.
264
- # -- I will remove the nodoc if/when this feature is a little less hacky
265
- stored = {}
266
- fields.each { |f| stored[f] = send(f) }
267
- yield
268
- fields.each { |f| send("#{f}=", stored[f]) }
269
- end
270
-
271
- # Returns true if content streams will be compressed before rendering,
272
- # false otherwise
273
- #
274
- def compression_enabled?
275
- !!@compress
276
- end
277
-
278
- private
279
-
280
- # See Prawn::Document::Internals for low-level PDF functions
281
-
282
- def build_new_page_content
283
- generate_margin_box
284
- @page_content = ref(:Length => 0)
285
-
286
- @current_page = ref(:Type => :Page,
287
- :Parent => @pages,
288
- :MediaBox => page_dimensions,
289
- :Contents => @page_content)
290
- update_colors
291
- end
292
-
293
- def generate_margin_box
294
- old_margin_box = @margin_box
295
- @margin_box = BoundingBox.new(
296
- self,
297
- [ @margins[:left], page_dimensions[-1] - @margins[:top] ] ,
298
- :width => page_dimensions[-2] - (@margins[:left] + @margins[:right]),
299
- :height => page_dimensions[-1] - (@margins[:top] + @margins[:bottom])
300
- )
301
-
302
- # update bounding box if not flowing from the previous page
303
- # FIXME: This may have a bug where the old margin is restored
304
- # when the bounding box exits.
305
- @bounding_box = @margin_box if old_margin_box == @bounding_box
306
- end
307
-
308
- end
309
- end
@@ -1,63 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # annotations.rb : Implements low-level annotation support for PDF
4
- #
5
- # Copyright November 2008, Jamis Buck. All Rights Reserved.
6
- #
7
- # This is free software. Please see the LICENSE and COPYING files for details.
8
-
9
- require 'prawn/literal_string'
10
-
11
- module Prawn
12
- class Document
13
-
14
- # Provides very low-level support for annotations. Those who are
15
- # interested should check out the text-format branch of sandal/prawn,
16
- # which includes much higher level interfaces to this code currently
17
- # being developed by Jamis Buck to be included in a Prawn release soon.
18
- #
19
- # Feedback is welcome!
20
- #
21
- module Annotations
22
- # Adds a new annotation (section 8.4 in PDF spec) to the current page.
23
- # +options+ must be a Hash describing the annotation.
24
- def annotate(options)
25
- @current_page.data[:Annots] ||= []
26
- options = sanitize_annotation_hash(options)
27
- @current_page.data[:Annots] << ref(options)
28
- return options
29
- end
30
-
31
- # A convenience method for creating Text annotations. +rect+ must be an array
32
- # of four numbers, describing the bounds of the annotation. +contents+ should
33
- # be a string, to be shown when the annotation is activated.
34
- def text_annotation(rect, contents, options={})
35
- options = options.merge(:Subtype => :Text, :Rect => rect, :Contents => contents)
36
- annotate(options)
37
- end
38
-
39
- # A convenience method for creating Link annotations. +rect+ must be an array
40
- # of four numbers, describing the bounds of the annotation. The +options+ hash
41
- # should include either :Dest (describing the target destination, usually as a
42
- # string that has been recorded in the document's Dests tree), or :A (describing
43
- # an action to perform on clicking the link), or :PA (for describing a URL to
44
- # link to).
45
- def link_annotation(rect, options={})
46
- options = options.merge(:Subtype => :Link, :Rect => rect)
47
- annotate(options)
48
- end
49
-
50
- private
51
-
52
- def sanitize_annotation_hash(options)
53
- options = options.merge(:Type => :Annot)
54
-
55
- if options[:Dest].is_a?(String)
56
- options[:Dest] = Prawn::LiteralString.new(options[:Dest])
57
- end
58
-
59
- options
60
- end
61
- end
62
- end
63
- end