mack-pdf_writer 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/lib/gems/archive-tar-minitar-0.5.2/bin/minitar +27 -0
  2. data/lib/gems/archive-tar-minitar-0.5.2/lib/archive/tar/minitar/command.rb +814 -0
  3. data/lib/gems/archive-tar-minitar-0.5.2/lib/archive/tar/minitar.rb +979 -0
  4. data/lib/gems/color-1.4.0/lib/color/cmyk.rb +281 -0
  5. data/lib/gems/color-1.4.0/lib/color/css.rb +30 -0
  6. data/lib/gems/color-1.4.0/lib/color/grayscale.rb +214 -0
  7. data/lib/gems/color-1.4.0/lib/color/hsl.rb +223 -0
  8. data/lib/gems/color-1.4.0/lib/color/palette/adobecolor.rb +274 -0
  9. data/lib/gems/color-1.4.0/lib/color/palette/gimp.rb +118 -0
  10. data/lib/gems/color-1.4.0/lib/color/palette/monocontrast.rb +182 -0
  11. data/lib/gems/color-1.4.0/lib/color/palette.rb +18 -0
  12. data/lib/gems/color-1.4.0/lib/color/rgb/metallic.rb +45 -0
  13. data/lib/gems/color-1.4.0/lib/color/rgb-colors.rb +357 -0
  14. data/lib/gems/color-1.4.0/lib/color/rgb.rb +455 -0
  15. data/lib/gems/color-1.4.0/lib/color/yiq.rb +86 -0
  16. data/lib/gems/color-1.4.0/lib/color.rb +147 -0
  17. data/lib/gems/pdf-writer-1.1.8/bin/techbook +24 -0
  18. data/lib/gems/pdf-writer-1.1.8/lib/pdf/charts/stddev.rb +430 -0
  19. data/lib/gems/pdf-writer-1.1.8/lib/pdf/charts.rb +13 -0
  20. data/lib/gems/pdf-writer-1.1.8/lib/pdf/math.rb +108 -0
  21. data/lib/gems/pdf-writer-1.1.8/lib/pdf/quickref.rb +332 -0
  22. data/lib/gems/pdf-writer-1.1.8/lib/pdf/simpletable.rb +947 -0
  23. data/lib/gems/pdf-writer-1.1.8/lib/pdf/techbook.rb +901 -0
  24. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/arc4.rb +63 -0
  25. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fontmetrics.rb +203 -0
  26. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Courier-Bold.afm +342 -0
  27. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Courier-BoldOblique.afm +342 -0
  28. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Courier-Oblique.afm +342 -0
  29. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Courier.afm +342 -0
  30. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Helvetica-Bold.afm +2827 -0
  31. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Helvetica-BoldOblique.afm +2827 -0
  32. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Helvetica-Oblique.afm +3051 -0
  33. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Helvetica.afm +3051 -0
  34. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/MustRead.html +19 -0
  35. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Symbol.afm +213 -0
  36. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Times-Bold.afm +2588 -0
  37. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Times-BoldItalic.afm +2384 -0
  38. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Times-Italic.afm +2667 -0
  39. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/Times-Roman.afm +2419 -0
  40. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/fonts/ZapfDingbats.afm +225 -0
  41. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/graphics/imageinfo.rb +365 -0
  42. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/graphics.rb +813 -0
  43. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/lang/en.rb +99 -0
  44. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/lang.rb +43 -0
  45. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/action.rb +35 -0
  46. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/annotation.rb +42 -0
  47. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/catalog.rb +39 -0
  48. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/contents.rb +65 -0
  49. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/destination.rb +40 -0
  50. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/encryption.rb +53 -0
  51. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/font.rb +72 -0
  52. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/fontdescriptor.rb +34 -0
  53. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/fontencoding.rb +40 -0
  54. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/image.rb +304 -0
  55. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/info.rb +51 -0
  56. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/outline.rb +30 -0
  57. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/outlines.rb +30 -0
  58. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/page.rb +195 -0
  59. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/pages.rb +115 -0
  60. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/procset.rb +46 -0
  61. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/viewerpreferences.rb +74 -0
  62. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object.rb +23 -0
  63. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/ohash.rb +58 -0
  64. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/oreader.rb +25 -0
  65. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/state.rb +48 -0
  66. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer/strokestyle.rb +138 -0
  67. data/lib/gems/pdf-writer-1.1.8/lib/pdf/writer.rb +2729 -0
  68. data/lib/gems/transaction-simple-1.4.0/lib/transaction/simple/group.rb +146 -0
  69. data/lib/gems/transaction-simple-1.4.0/lib/transaction/simple/threadsafe/group.rb +36 -0
  70. data/lib/gems/transaction-simple-1.4.0/lib/transaction/simple/threadsafe.rb +68 -0
  71. data/lib/gems/transaction-simple-1.4.0/lib/transaction/simple.rb +486 -0
  72. data/lib/gems.rb +13 -0
  73. data/lib/mack-pdf_writer.rb +2 -0
  74. metadata +111 -16
@@ -0,0 +1,332 @@
1
+ #--
2
+ # PDF::Writer for Ruby.
3
+ # http://rubyforge.org/projects/ruby-pdf/
4
+ # Copyright 2003 - 2005 Austin Ziegler.
5
+ #
6
+ # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
+ # for full licensing information.
8
+ #
9
+ # $Id: quickref.rb 186 2007-12-10 22:58:48Z sandal $
10
+ #++
11
+ require 'pdf/simpletable'
12
+
13
+ # = QuickRef
14
+ # A formatting language to create a quick reference sheet. This is a
15
+ # multi-column page in landscape mode that generally has three or four
16
+ # columns. This format may also be used for brochures, but brochure
17
+ # creation requires a bit of management to create properly.
18
+ #
19
+ # == Reference Sheets
20
+ # A three-column reference sheet is generally in the form of:
21
+ #
22
+ # Page 1:
23
+ # column 1 | column 2 | column 3
24
+ # Page 2:
25
+ # column 4 | column 5 | column 6
26
+ #
27
+ # The formatting language provided in QuickRef is based around this text
28
+ # flow. The title of the quick reference sheet is in column 1. The two
29
+ # pages are intended to be printed on both sides of pieces of paper so
30
+ # that columns 1 and 6 are matched. This will use a Z-fold that places
31
+ # columns 5 and 6 face to face and columns 2 and 3 face to face. In the
32
+ # folded reference sheet, columns 1 and 4 will be facing out.
33
+ #
34
+ # == Brochures
35
+ # In contrast, brochures differ vastly in their design, although the
36
+ # common brochure is also three columns and either follows the same layout
37
+ # as a reference sheet or uses an overlapping fold.
38
+ #
39
+ # When an overlapping fold is used, the title is typically on column 6
40
+ # (assuming a left-to-right reading order). A short summary will appear on
41
+ # column 4. Contact information about the maker of the brochure is
42
+ # typically in column 5. Columns 1, 2, and 3 will contain the main body of
43
+ # the brochure. The brochure will be folded so that columns 2 and 3 are
44
+ # face to face. After this, column 1 will face column 4 (exposed by the
45
+ # first fold). In the folded brochure, columns 5 and 6 are facing out.
46
+ #
47
+ # == Usage
48
+ # qr = PDF::QuickRef.new # 3-column LETTER
49
+ # qr.title "My QuickRef"
50
+ # qr.h1 "H1 Text"
51
+ # qr.lines "Text to put after the header."
52
+ # qr.save_as "MyQuickRef.pdf"
53
+ class PDF::QuickRef
54
+
55
+ # Create the quick reference document. +paper+ is passed unchanged to
56
+ # the PDF::Writer.new; the page is always created landscape. Margins
57
+ # are initialized to 18 points. After some additional initialization is
58
+ # performed, the quick reference document is yielded to an optional
59
+ # block for further configuration. All of this is done before the
60
+ # columns are started.
61
+ #
62
+ # After the columns are started, lines will be drawn between column
63
+ # positions.
64
+ def initialize(paper = "LETTER", columns = 3, column_separators_visible = true)
65
+ @pdf = PDF::Writer.new(:paper => paper, :orientation => :landscape)
66
+ @pdf.margins_pt 18
67
+ @pdf.y = @pdf.absolute_top_margin
68
+
69
+ @title_font = "Times-Roman"
70
+ @heading_font = "Times-Roman"
71
+ @body_font = "Times-Roman"
72
+ @code_font = "Courier"
73
+ @title_font_size = 14
74
+ @h1_font_size = 11
75
+ @h2_font_size = 9
76
+ @h3_font_size = 8
77
+ @h4_font_size = 7
78
+ @body_font_size = 6
79
+
80
+ @ptab = PDF::SimpleTable.new do |tab|
81
+ tab.column_order.replace %w(one two)
82
+
83
+ tab.font_size = @body_font_size
84
+ tab.show_lines = :none
85
+ tab.show_headings = false
86
+ tab.orientation = :center
87
+ tab.position = :center
88
+ end
89
+ @ltab = PDF::SimpleTable.new do |tab|
90
+ tab.column_order.replace %w(line)
91
+
92
+ tab.font_size = @body_font_size
93
+ tab.show_lines = :none
94
+ tab.show_headings = false
95
+ tab.orientation = :center
96
+ tab.position = :center
97
+ end
98
+
99
+ yield self if block_given?
100
+
101
+ @pdf.start_columns columns
102
+
103
+ @ptab.font_size = @body_font_size
104
+ @ltab.font_size = @body_font_size
105
+
106
+ @ptab.maximum_width = @pdf.column_width - 10
107
+ @ltab.maximum_width = @pdf.column_width - 10
108
+
109
+ if column_separators_visible
110
+ # Put lines between the columns.
111
+ all = @pdf.open_object
112
+ @pdf.save_state
113
+ @pdf.stroke_color! Color::RGB::Black
114
+ @pdf.stroke_style PDF::Writer::StrokeStyle::DEFAULT
115
+ (1 .. (columns - 1)).each do |ii|
116
+ x = @pdf.left_margin + (@pdf.column_width * ii)
117
+ x += (@pdf.column_gutter * (ii - 0.5))
118
+ @pdf.line(x, @pdf.page_height - @pdf.top_margin, x, @pdf.bottom_margin)
119
+ @pdf.stroke
120
+ end
121
+ @pdf.restore_state
122
+ @pdf.close_object
123
+ @pdf.add_object(all, :all_pages)
124
+ end
125
+ end
126
+
127
+ # Access to the raw PDF canvas for normal PDF::Writer configuration.
128
+ attr_reader :pdf
129
+
130
+ # The name of the font that will be used for #title text. The default
131
+ # font is Times-Roman.
132
+ attr_accessor :title_font
133
+ # The font encoding for #title text.
134
+ attr_accessor :title_font_encoding
135
+ # The size #title text. The default is 14 points.
136
+ attr_accessor :title_font_size
137
+
138
+ # The name of the font that will be used for #h1, #h2, #h3, and #h4
139
+ # text. The default is Times-Roman.
140
+ attr_accessor :heading_font
141
+ # The font encoding for #h1, #h2, #h3, and #h4 text.
142
+ attr_accessor :heading_font_encoding
143
+ # The size #h1 text. The default is 11 points.
144
+ attr_accessor :h1_font_size
145
+ # The size #h2 text. The default is 9 points.
146
+ attr_accessor :h2_font_size
147
+ # The size #h3 text. The default is 8 points.
148
+ attr_accessor :h3_font_size
149
+ # The size #h4 text. The default is 7 points.
150
+ attr_accessor :h4_font_size
151
+
152
+ # The name of the font that will be used for #body, #lines, and #pairs
153
+ # text. The default is 'Times-Roman'.
154
+ attr_accessor :body_font
155
+ # The font encoding for #body, #lines, and #pairs text.
156
+ attr_accessor :body_font_encoding
157
+ # The name of the font that will be used for #code, #codelines, and
158
+ # #codepairs text; this is generally a fixed-pitch font. The default is
159
+ # 'Courier'.
160
+ attr_accessor :code_font
161
+ # The font encoding for #code, #codelines, and #codepairs text.
162
+ attr_accessor :code_font_encoding
163
+ # The size #body and #code text. The default is 7 points.
164
+ attr_accessor :body_font_size
165
+
166
+ # Creates a two-column zebra-striped table using the #body font. Each
167
+ # line of the text is a separate row; the two columns are separated by
168
+ # tab characters.
169
+ def pairs(text)
170
+ data = text.split($/).map do |line|
171
+ one, two = line.split(/\t/)
172
+ { 'one' => one, 'two' => two }
173
+ end
174
+ @ptab.data.replace data
175
+ @ptab.render_on(@pdf)
176
+ @pdf.text "\n", :font_size => @body_font_size
177
+ end
178
+ # Creates a two-column zebra-striped table using the #code font. Each
179
+ # line of the text is a separate row; the two columns are separated by
180
+ # tab characters.
181
+ def codepairs(text)
182
+ data = text.split($/).map do |line|
183
+ one, two = line.split(/\t/)
184
+ { 'one' => one, 'two' => two }
185
+ end
186
+ @ptab.data.replace data
187
+ use_code_font
188
+ @ptab.render_on(@pdf)
189
+ use_body_font
190
+ @pdf.text "\n", :font_size => @body_font_size
191
+ end
192
+ # Creates a one-column zebra-striped table using the #body font. Each
193
+ # line of the text is a separate row.
194
+ def lines(text)
195
+ data = text.split($/).map { |line| { "line" => line } }
196
+ @ltab.data.replace data
197
+ @ltab.render_on(@pdf)
198
+ @pdf.text "\n", :font_size => @body_font_size
199
+ end
200
+ # Creates a one-column zebra-striped table using the #code font. Each
201
+ # line of the text is a separate row.
202
+ def codelines(text)
203
+ data = text.split($/).map { |line| { "line" => line } }
204
+ @ltab.data.replace data
205
+ use_code_font
206
+ @ltab.render_on(@pdf)
207
+ use_body_font
208
+ @pdf.text "\n", :font_size => @body_font_size
209
+ end
210
+
211
+ # Change the current font to the #title font.
212
+ def use_title_font
213
+ @pdf.select_font @title_font, @title_font_encoding
214
+ end
215
+ # Change the current font to the heading font (used normally by #h1,
216
+ # #h2, #h3, and #h4|).
217
+ def use_heading_font
218
+ @pdf.select_font @heading_font, @heading_font_encoding
219
+ end
220
+ # Change the current font to the #body font.
221
+ def use_body_font
222
+ @pdf.select_font @body_font, @body_font_encoding
223
+ end
224
+ # Change the current font to the #code font.
225
+ def use_code_font
226
+ @pdf.select_font @code_font, @code_font_encoding
227
+ end
228
+
229
+ # Writes the +text+ with the #title_font and #title_font_size centered
230
+ # in the column. After the title has been written, an #hline will be
231
+ # drawn under the title. The font is set to #body_font after the title
232
+ # is drawn.
233
+ def title(text)
234
+ use_title_font
235
+ @pdf.text text, :font_size => @title_font_size, :justification => :center
236
+ use_body_font
237
+ hline
238
+ end
239
+ # Writes the +text+ with the #heading_font and #h1_font_size left
240
+ # justified in the column. The font is set to #body_font after the
241
+ # heading is drawn.
242
+ def h1(text)
243
+ use_heading_font
244
+ @pdf.text text, :font_size => @h1_font_size
245
+ use_body_font
246
+ end
247
+ # Writes the +text+ with the #heading_font and #h2_font_size left
248
+ # justified in the column. The font is set to #body_font after the
249
+ # heading is drawn.
250
+ def h2(text)
251
+ use_heading_font
252
+ @pdf.text "<i>#{text}</i>", :font_size => @h2_font_size
253
+ use_body_font
254
+ end
255
+ # Writes the +text+ with the #heading_font and #h3_font_size left
256
+ # justified in the column. The font is set to #body_font after the
257
+ # heading is drawn.
258
+ def h3(text)
259
+ use_heading_font
260
+ @pdf.text "<i>#{text}</i>", :font_size => @h3_font_size
261
+ use_body_font
262
+ end
263
+ # Writes the +text+ with the #heading_font and #h4_font_size left
264
+ # justified in the column. The font is set to #body_font after the
265
+ # heading is drawn.
266
+ def h4(text)
267
+ use_heading_font
268
+ @pdf.text "<b><i>#{text}</i></b>", :font_size => @h4_font_size
269
+ use_body_font
270
+ end
271
+ # Writes body text. Paragraphs will be reflowed for optimal placement of
272
+ # text. Text separated by two line separators (e.g., \n\n, although the
273
+ # separator is platform dependent). The text will be placed with full
274
+ # justification.
275
+ def body(text)
276
+ # Transform the text a little.
277
+ paras = text.split(%r(#{$/}{2}))
278
+ paras.map! { |para| para.split($/).join(" ").squeeze(" ") }
279
+ text = paras.join("\n\n")
280
+
281
+ @pdf.text "#{text}\n", :font_size => @body_font_size, :justification => :full
282
+ end
283
+ # Writes code text. Newlines and spaces will be preserved.
284
+ def pre(text)
285
+ use_code_font
286
+ @pdf.text "#{text}\n", :font_size => @body_font_size
287
+ use_body_font
288
+ end
289
+
290
+ # Draws a horizontal line with the specified style and colour.
291
+ def hline(style = PDF::Writer::StrokeStyle::DEFAULT,
292
+ color = Color::RGB::Black)
293
+ @pdf.y -= 2.5
294
+ @pdf.save_state
295
+ @pdf.stroke_style style
296
+ @pdf.stroke_color! color
297
+ x0 = @pdf.left_margin
298
+ x1 = @pdf.left_margin + pdf.column_width
299
+ @pdf.line(x0, @pdf.y, x1, @pdf.y)
300
+ @pdf.stroke
301
+ @pdf.restore_state
302
+ @pdf.y -= 2.5
303
+ end
304
+
305
+ # Writes the Quick Reference to disk.
306
+ def save_as(filename)
307
+ @pdf.save_as(filename)
308
+ end
309
+
310
+ # Generates the PDF document as a string.
311
+ def render
312
+ @pdf.render
313
+ end
314
+
315
+ alias to_s render
316
+
317
+ # Creates a QuickRef document and then calls #instance_eval on the
318
+ # document. This allows for a more natural use of the QuickRef class as
319
+ # a DSL for creating these documents.
320
+ #
321
+ # === Using #make
322
+ # PDF::QuickRef.make do # 3-column LETTER
323
+ # title "My QuickRef"
324
+ # h1 "H1 Text"
325
+ # lines "Text to put after the header."
326
+ # save_as "MyQuickRef.pdf"
327
+ # end
328
+ def self.make(*args, &block)
329
+ qr = PDF::QuickRef.new(*args)
330
+ qr.__send__(:instance_eval, &block)
331
+ end
332
+ end