pdf-writer 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/demo/demo.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
7
  # for full licensing information.
8
8
  #
9
- # $Id: demo.rb,v 1.8 2005/06/29 03:00:31 austin Exp $
9
+ # $Id: demo.rb,v 1.8.2.1 2005/08/25 03:38:05 austin Exp $
10
10
  #++
11
11
  begin
12
12
  require 'pdf/writer'
@@ -50,7 +50,7 @@ end
50
50
  x = (x - xw - 2)
51
51
  end
52
52
 
53
- pdf.stroke_color(Color::Black)
53
+ pdf.stroke_color(Color::RGB::Black)
54
54
  pdf.stroke_style(PDF::Writer::StrokeStyle.new(1))
55
55
  pdf.rectangle(20, 20, 558, 802)
56
56
 
data/demo/pac.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
7
  # for full licensing information.
8
8
  #
9
- # $Id: pac.rb,v 1.4 2005/06/13 19:32:37 austin Exp $
9
+ # $Id: pac.rb,v 1.4.2.1 2005/08/25 03:38:05 austin Exp $
10
10
  #++
11
11
  begin
12
12
  require 'pdf/writer'
@@ -21,34 +21,34 @@ end
21
21
 
22
22
  pdf = PDF::Writer.new(:orientation => :landscape)
23
23
 
24
- pdf.fill_color Color::Black
24
+ pdf.fill_color Color::RGB::Black
25
25
  pdf.rectangle(0, 0, pdf.page_width, pdf.page_height).fill
26
26
 
27
27
  # Wall
28
- pdf.fill_color Color::Magenta
29
- pdf.stroke_color Color::Cyan
28
+ pdf.fill_color Color::RGB::Magenta
29
+ pdf.stroke_color Color::RGB::Cyan
30
30
  pdf.rounded_rectangle(20, 500, 750, 20, 10).close_fill_stroke
31
31
  pdf.rounded_rectangle(20, 200, 750, 20, 10).close_fill_stroke
32
32
 
33
33
  # Body
34
- pdf.fill_color Color::Yellow
35
- pdf.stroke_color Color::Black
34
+ pdf.fill_color Color::RGB::Yellow
35
+ pdf.stroke_color Color::RGB::Black
36
36
  pdf.circle_at(150, 350, 100).fill_stroke
37
37
 
38
38
  # Mouth
39
- pdf.fill_color Color::Black
39
+ pdf.fill_color Color::RGB::Black
40
40
  pdf.segment_at(150, 350, 100, 100, 30, -30).close_fill_stroke
41
41
 
42
42
  # Dot
43
- pdf.fill_color Color::Yellow
43
+ pdf.fill_color Color::RGB::Yellow
44
44
  pdf.circle_at(250, 350, 20).fill_stroke
45
45
  pdf.circle_at(300, 350, 10).fill_stroke
46
46
  pdf.circle_at(350, 350, 10).fill_stroke
47
47
  pdf.circle_at(400, 350, 10).fill_stroke
48
48
  pdf.circle_at(450, 350, 10).fill_stroke
49
49
 
50
- pdf.fill_color Color::Blue
51
- pdf.stroke_color Color::Cyan
50
+ pdf.fill_color Color::RGB::Blue
51
+ pdf.stroke_color Color::RGB::Cyan
52
52
  pdf.move_to(500, 250)
53
53
  pdf.line_to(500, 425)
54
54
  pdf.curve_to(550, 475, 600, 475, 650, 425)
@@ -60,10 +60,10 @@ pdf.line_to(550, 250)
60
60
  pdf.line_to(525, 275)
61
61
  pdf.line_to(500, 250).fill_stroke
62
62
 
63
- pdf.fill_color Color::White
63
+ pdf.fill_color Color::RGB::White
64
64
  pdf.rectangle(525, 375, 25, 25).fill
65
65
  pdf.rectangle(575, 375, 25, 25).fill
66
- pdf.fill_color Color::Black
66
+ pdf.fill_color Color::RGB::Black
67
67
  pdf.rectangle(525, 375, 10, 10).fill
68
68
  pdf.rectangle(575, 375, 10, 10).fill
69
69
 
data/demo/pagenumber.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
7
  # for full licensing information.
8
8
  #
9
- # $Id: pagenumber.rb,v 1.5 2005/06/13 19:32:37 austin Exp $
9
+ # $Id: pagenumber.rb,v 1.5.2.1 2005/08/25 03:38:05 austin Exp $
10
10
  #++
11
11
  begin
12
12
  require 'pdf/writer'
@@ -23,10 +23,10 @@ def grey_page(pdf)
23
23
  @page_num ||= 0
24
24
  @page_num += 1
25
25
  pdf.save_state
26
- pdf.fill_color Color::Grey90
27
- x = pdf.absolute_x_middle - (pdf.text_width(48, @page_num) / 2.0)
28
- y = pdf.absolute_y_middle - (pdf.font_height(48) / 2.0)
29
- pdf.add_text(x, y, 48, @page_num)
26
+ pdf.fill_color Color::RGB::Grey90
27
+ x = pdf.margin_x_middle - (pdf.text_width(@page_num, 48) / 2.0)
28
+ y = pdf.margin_y_middle - (pdf.font_height(48) / 2.0)
29
+ pdf.add_text(x, y, @page_num, 48)
30
30
  pdf.restore_state
31
31
  end
32
32
 
@@ -39,28 +39,32 @@ pdf = PDF::Writer.new(:paper => "A10")
39
39
  pdf.margins_pt 0
40
40
  pdf.select_font "Helvetica"
41
41
 
42
- grey_page(pdf) # Page 1: blank
43
- sa = pdf.start_page_numbering(5, 60, 9, nil, nil, 1)
42
+ x = pdf.absolute_x_middle
43
+
44
+ grey_page(pdf) # Page 1: 99 of 99
45
+ sa = pdf.start_page_numbering(x, 70, 9, :center, nil, 99)
46
+ pdf.stop_page_numbering(true, :current, sa)
44
47
  make_page(pdf) # Page 2: 1 of 2
48
+ sa = pdf.start_page_numbering(x, 60, 9, nil, nil, 1)
45
49
  make_page(pdf) # Page 3: 2 of 2
46
50
  pdf.stop_page_numbering(true, :current, sa)
47
51
  make_page(pdf) # Page 4: blank
48
- sb = pdf.start_page_numbering(5, 50, 9, :center, nil, 10)
52
+ sb = pdf.start_page_numbering(x, 50, 9, :center, nil, 10)
49
53
  make_page(pdf) # Page 5: 10 of 12
50
54
  make_page(pdf) # Page 6: 11 of 12
51
55
  pdf.stop_page_numbering(true, :next, sb)
52
56
  make_page(pdf) # Page 7: 12 of 12
53
- sc = pdf.start_page_numbering(5, 40, 9, nil, nil, 1)
57
+ sc = pdf.start_page_numbering(x, 40, 9, nil, nil, 1)
54
58
  make_page(pdf) # Page 8: 1 of 3
55
59
  make_page(pdf) # Page 9: 2 of 3
56
60
  make_page(pdf) # Page 10: 3 of 3
57
61
  pdf.stop_page_numbering(true, :current, sc)
58
62
  make_page(pdf) # Page 11: blank
59
- sd = pdf.start_page_numbering(5, 30, 9, nil, nil, 1)
63
+ sd = pdf.start_page_numbering(x, 30, 9, nil, nil, 1)
60
64
  make_page(pdf) # Page 12: 1 of 6
61
65
  make_page(pdf) # Page 13: 2 of 6
62
- se = pdf.start_page_numbering(5, 20, 9, nil, nil, 5)
63
- sf = pdf.start_page_numbering(5, 10, 9, :right, nil, 1)
66
+ se = pdf.start_page_numbering(x, 20, 9, nil, nil, 5)
67
+ sf = pdf.start_page_numbering(x, 10, 9, :right, nil, 1)
64
68
  make_page(pdf) # Page 14: 3 of 6, 5 of 10, 1 of 8
65
69
  make_page(pdf) # Page 15: 4 of 6, 6 of 10, 2 of 8
66
70
  make_page(pdf) # Page 16: 5 of 6, 7 of 10, 3 of 8
@@ -6,7 +6,7 @@
6
6
  # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
7
  # for full licensing information.
8
8
  #
9
- # $Id: stddev.rb,v 1.9 2005/07/01 16:48:26 austin Exp $
9
+ # $Id: stddev.rb,v 1.9.2.1 2005/08/25 03:38:05 austin Exp $
10
10
  #++
11
11
  require 'pdf/writer'
12
12
  require 'pdf/charts'
@@ -20,7 +20,7 @@ require 'ostruct'
20
20
  # The scale of responses is the vertical scale; the average data points
21
21
  # and standard deviation values are the horizontal scale.
22
22
  class PDF::Charts::StdDev
23
- VERSION = '1.1.1'
23
+ VERSION = '1.1.2'
24
24
 
25
25
  # A data element.
26
26
  DataPoint = Struct.new(:label, :average, :stddev)
@@ -117,7 +117,7 @@ class PDF::Charts::StdDev
117
117
  scale.show_labels = false
118
118
  scale.label = Label.new do |label|
119
119
  label.text_size = 8
120
- label.text_color = Color::Black
120
+ label.text_color = Color::RGB::Black
121
121
  label.pad = 2
122
122
  label.decimal_precision = 1
123
123
  end
@@ -126,32 +126,32 @@ class PDF::Charts::StdDev
126
126
  @show_labels = true
127
127
  @label = Label.new do |label|
128
128
  label.height = 25
129
- label.background_color = Color::Black
130
- label.text_color = Color::White
129
+ label.background_color = Color::RGB::Black
130
+ label.text_color = Color::RGB::White
131
131
  label.text_size = 12
132
132
  end
133
133
 
134
134
  @outer_borders = Marker.new do |marker|
135
135
  marker.style = PDF::Writer::StrokeStyle.new(1.5)
136
- marker.color = Color::Black
136
+ marker.color = Color::RGB::Black
137
137
  end
138
138
  @inner_borders = nil
139
139
 
140
140
  @dot = Marker.new do |marker|
141
141
  marker.style = PDF::Writer::StrokeStyle.new(5)
142
- marker.color = Color::Black
142
+ marker.color = Color::RGB::Black
143
143
  end
144
144
  @bar = Marker.new do |marker|
145
145
  marker.style = PDF::Writer::StrokeStyle.new(0.5)
146
- marker.color = Color::Black
146
+ marker.color = Color::RGB::Black
147
147
  end
148
148
  @upper_crossbar = Marker.new do |marker|
149
149
  marker.style = PDF::Writer::StrokeStyle.new(1)
150
- marker.color = Color::Black
150
+ marker.color = Color::RGB::Black
151
151
  end
152
152
  @lower_crossbar = Marker.new do |marker|
153
153
  marker.style = PDF::Writer::StrokeStyle.new(1)
154
- marker.color = Color::Black
154
+ marker.color = Color::RGB::Black
155
155
  end
156
156
 
157
157
  @height = 200
data/lib/pdf/quickref.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
7
  # for full licensing information.
8
8
  #
9
- # $Id: quickref.rb,v 1.10 2005/07/01 16:48:26 austin Exp $
9
+ # $Id: quickref.rb,v 1.10.2.2 2005/08/25 03:51:44 austin Exp $
10
10
  #++
11
11
  require 'pdf/simpletable'
12
12
 
@@ -51,7 +51,7 @@ require 'pdf/simpletable'
51
51
  # qr.lines "Text to put after the header."
52
52
  # qr.save_as "MyQuickRef.pdf"
53
53
  class PDF::QuickRef
54
- VERSION = '1.1.1'
54
+ VERSION = '1.1.2'
55
55
 
56
56
  # Create the quick reference document. +paper+ is passed unchanged to
57
57
  # the PDF::Writer.new; the page is always created landscape. Margins
@@ -110,7 +110,7 @@ class PDF::QuickRef
110
110
  # Put lines between the columns.
111
111
  all = @pdf.open_object
112
112
  @pdf.save_state
113
- @pdf.stroke_color! Color::Black
113
+ @pdf.stroke_color! Color::RGB::Black
114
114
  @pdf.stroke_style PDF::Writer::StrokeStyle::DEFAULT
115
115
  (1 .. (columns - 1)).each do |ii|
116
116
  x = @pdf.left_margin + (@pdf.column_width * ii)
@@ -287,7 +287,8 @@ class PDF::QuickRef
287
287
  end
288
288
 
289
289
  # Draws a horizontal line with the specified style and colour.
290
- def hline(style = PDF::Writer::StrokeStyle::DEFAULT, color = Color::Black)
290
+ def hline(style = PDF::Writer::StrokeStyle::DEFAULT,
291
+ color = Color::RGB::Black)
291
292
  @pdf.y -= 2.5
292
293
  @pdf.save_state
293
294
  @pdf.stroke_style style
@@ -6,7 +6,7 @@
6
6
  # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
7
  # for full licensing information.
8
8
  #
9
- # $Id: simpletable.rb,v 1.13 2005/07/01 16:48:26 austin Exp $
9
+ # $Id: simpletable.rb,v 1.13.2.1 2005/08/25 03:38:05 austin Exp $
10
10
  #++
11
11
  require 'pdf/writer'
12
12
  require 'transaction/simple/group'
@@ -14,7 +14,7 @@ require 'transaction/simple/group'
14
14
  # This class will create tables with a relatively simple API and internal
15
15
  # implementation.
16
16
  class PDF::SimpleTable
17
- VERSION = '1.1.1'
17
+ VERSION = '1.1.2'
18
18
 
19
19
  include Transaction::Simple
20
20
 
@@ -75,18 +75,18 @@ class PDF::SimpleTable
75
75
  @show_lines = :outer
76
76
  @show_headings = true
77
77
  @shade_rows = :shaded
78
- @shade_color = Color::Grey80
79
- @shade_color2 = Color::Grey70
78
+ @shade_color = Color::RGB::Grey80
79
+ @shade_color2 = Color::RGB::Grey70
80
80
  @shade_headings = false
81
- @shade_heading_color = Color::Grey90
81
+ @shade_heading_color = Color::RGB::Grey90
82
82
  @font_size = 10
83
83
  @heading_font_size = 12
84
84
  @title_font_size = 12
85
85
  @title_gap = 5
86
- @title_color = Color::Black
87
- @heading_color = Color::Black
88
- @text_color = Color::Black
89
- @line_color = Color::Black
86
+ @title_color = Color::RGB::Black
87
+ @heading_color = Color::RGB::Black
88
+ @text_color = Color::RGB::Black
89
+ @line_color = Color::RGB::Black
90
90
  @position = :center
91
91
  @orientation = :center
92
92
  @bold_headings = false
@@ -146,16 +146,16 @@ class PDF::SimpleTable
146
146
  # will be shaded with #shade_color; the rest of the
147
147
  # rows will be shaded with #shade_color2.
148
148
  attr_accessor :shade_rows
149
- # The main row shading colour. Defaults to Color::Grey80. Used with
149
+ # The main row shading colour. Defaults to Color::RGB::Grey80. Used with
150
150
  # #shade_rows of <tt>:shaded</tt> and <tt>:striped</tt>.
151
151
  attr_accessor :shade_color
152
152
  # The alternate row shading colour, used with #shade_rows of
153
- # <tt>:striped</tt>. Defaults to Color::Grey70.
153
+ # <tt>:striped</tt>. Defaults to Color::RGB::Grey70.
154
154
  attr_accessor :shade_color2
155
155
  # Places a background colour in the heading if +true+.
156
156
  attr_accessor :shade_headings
157
157
  # Defines the colour of the background shading for the heading if
158
- # #shade_headings is +true+. Default is Color::Grey90.
158
+ # #shade_headings is +true+. Default is Color::RGB::Grey90.
159
159
  attr_accessor :shade_heading_color
160
160
  # The font size of the data cells, in points. Defaults to 10 points.
161
161
  attr_accessor :font_size
@@ -166,13 +166,13 @@ class PDF::SimpleTable
166
166
  # The gap, in PDF units, between the title and the table. Defaults to 5
167
167
  # units.
168
168
  attr_accessor :title_gap
169
- # The text colour of the title. Defaults to Color::Black.
169
+ # The text colour of the title. Defaults to Color::RGB::Black.
170
170
  attr_accessor :title_color
171
- # The text colour of the heading. Defaults to Color::Black.
171
+ # The text colour of the heading. Defaults to Color::RGB::Black.
172
172
  attr_accessor :heading_color
173
- # The text colour of the body cells. Defaults to Color::Black.
173
+ # The text colour of the body cells. Defaults to Color::RGB::Black.
174
174
  attr_accessor :text_color
175
- # The colour of the table lines. Defaults to Color::Black.
175
+ # The colour of the table lines. Defaults to Color::RGB::Black.
176
176
  attr_accessor :line_color
177
177
  # The +x+ position of the table. This will be one of:
178
178
  #
data/lib/pdf/techbook.rb CHANGED
@@ -7,7 +7,7 @@
7
7
  # Licensed under a MIT-style licence. See LICENCE in the main distribution
8
8
  # for full licensing information.
9
9
  #
10
- # $Id: techbook.rb,v 1.17 2005/07/01 16:48:26 austin Exp $
10
+ # $Id: techbook.rb,v 1.17.2.1 2005/08/25 03:38:05 austin Exp $
11
11
  #++
12
12
  require 'pdf/simpletable'
13
13
  require 'pdf/charts/stddev'
@@ -396,36 +396,36 @@ class PDF::TechBook < PDF::Writer
396
396
  private :techbook_find_directive
397
397
 
398
398
  H1_STYLE = {
399
- :background => Color::Black,
400
- :foreground => Color::White,
399
+ :background => Color::RGB::Black,
400
+ :foreground => Color::RGB::White,
401
401
  :justification => :center,
402
402
  :font_size => 26,
403
403
  :bar => true
404
404
  }
405
405
  H2_STYLE = {
406
- :background => Color::Grey80,
407
- :foreground => Color::Black,
406
+ :background => Color::RGB::Grey80,
407
+ :foreground => Color::RGB::Black,
408
408
  :justification => :left,
409
409
  :font_size => 18,
410
410
  :bar => true
411
411
  }
412
412
  H3_STYLE = {
413
- :background => Color::White,
414
- :foreground => Color::Black,
413
+ :background => Color::RGB::White,
414
+ :foreground => Color::RGB::Black,
415
415
  :justification => :left,
416
416
  :font_size => 18,
417
417
  :bar => false
418
418
  }
419
419
  H4_STYLE = {
420
- :background => Color::White,
421
- :foreground => Color::Black,
420
+ :background => Color::RGB::White,
421
+ :foreground => Color::RGB::Black,
422
422
  :justification => :left,
423
423
  :font_size => 14,
424
424
  :bar => false
425
425
  }
426
426
  H5_STYLE = {
427
- :background => Color::White,
428
- :foreground => Color::Black,
427
+ :background => Color::RGB::White,
428
+ :foreground => Color::RGB::Black,
429
429
  :justification => :left,
430
430
  :font_size => 12,
431
431
  :bar => false
data/lib/pdf/writer.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
7
  # for full licensing information.
8
8
  #
9
- # $Id: writer.rb,v 1.38 2005/07/01 16:48:26 austin Exp $
9
+ # $Id: writer.rb,v 1.38.2.1 2005/08/25 03:38:05 austin Exp $
10
10
  #++
11
11
  require 'thread'
12
12
  require 'open-uri'
@@ -19,7 +19,7 @@ require 'color'
19
19
  module PDF
20
20
  class Writer
21
21
  # The version of PDF::Writer.
22
- VERSION = '1.1.1'
22
+ VERSION = '1.1.2'
23
23
 
24
24
  # Escape the text so that it's safe for insertion into the PDF
25
25
  # document.
@@ -194,9 +194,9 @@ class PDF::Writer
194
194
 
195
195
  all = pdf.open_object
196
196
  pdf.save_state
197
- k = Color::CMYK.new(0, 0, 0, 100)
198
- pdf.stroke_color! k
199
- pdf.fill_color! k
197
+ kk = Color::CMYK.new(0, 0, 0, 100)
198
+ pdf.stroke_color! kk
199
+ pdf.fill_color! kk
200
200
  pdf.stroke_style! StrokeStyle.new(0.3)
201
201
 
202
202
  pdf.prepress_clip_mark(tx1, ty0, 0, mark_length, bleed_size) # Upper Right
@@ -359,13 +359,10 @@ class PDF::Writer
359
359
  @pages = PDF::Writer::Object::Pages.new(self)
360
360
 
361
361
  @current_node = @pages
362
-
363
- @current_text_render_style = 0
364
-
365
362
  @procset = PDF::Writer::Object::Procset.new(self)
366
363
  @info = PDF::Writer::Object::Info.new(self)
367
364
  @page = PDF::Writer::Object::Page.new(self)
368
-
365
+ @current_text_render_style = 0
369
366
  @first_page = @page
370
367
 
371
368
  @version = version
@@ -405,8 +402,8 @@ class PDF::Writer
405
402
  # process.
406
403
  @pageset[1] = @pages.first_page
407
404
 
408
- fill_color! Color::Black
409
- stroke_color! Color::Black
405
+ fill_color! Color::RGB::Black
406
+ stroke_color! Color::RGB::Black
410
407
 
411
408
  yield self if block_given?
412
409
  end
@@ -600,6 +597,11 @@ class PDF::Writer
600
597
  start_new_page if @y < bottom # Make a new page
601
598
  end
602
599
 
600
+ # Allows the user to find out what the ID is of the first page that was
601
+ # created during startup - useful if they wish to add something to it
602
+ # later.
603
+ attr_reader :first_page
604
+
603
605
  # Add a new translation table for a font family. A font family will be
604
606
  # used to associate a single name and font styles with multiple fonts.
605
607
  # A style will be identified with a single-character style identifier or
@@ -619,11 +621,6 @@ class PDF::Writer
619
621
  # Each font family key is the base name for the font.
620
622
  attr_reader :font_families
621
623
 
622
- # Allows the user to find out what the ID is of the first page that was
623
- # created during startup - useful if they wish to add something to it
624
- # later.
625
- attr_reader :first_page
626
-
627
624
  # Initialize the font families for the default fonts.
628
625
  def init_font_families
629
626
  # Set the known family groups. These font families will be used to
@@ -700,33 +697,33 @@ class PDF::Writer
700
697
  :add => 32
701
698
  }
702
699
 
703
- # Encrypts the document. This will set the user and owner passwords that
704
- # will be used to access the document and set the permissions the user
705
- # has with the document. The passwords are limited to 32 characters.
706
- #
707
- # The permissions provided are an array of symbols, allowing identified
708
- # users to perform particular actions:
709
- # <tt>:print</tt>:: Print.
710
- # <tt>:modify</tt>:: Modify text or objects.
711
- # <tt>:copy</tt>:: Copy text or objects.
712
- # <tt>:add</tt>:: Add text or objects.
713
- def encrypt(user_pass = nil, owner_pass = nil, permissions = [])
714
- perms = ["11000000"].pack("B8")
715
-
716
- permissions.each do |perm|
717
- perms += ENCRYPT_OPTIONS[perm] if ENCRYPT_OPTIONS[perm]
718
- end
719
-
720
- @arc4 ||= PDF::ARC4.new
721
- owner_pass ||= user_pass
722
-
723
- options = {
724
- :owner_pass => owner_pass,
725
- :user_pass => user_pass,
726
- :permissions => perms,
727
- }
728
- @encryption = PDF::Writer::Object::Encryption.new(self, options)
729
- end
700
+ # Encrypts the document. This will set the user and owner passwords that
701
+ # will be used to access the document and set the permissions the user
702
+ # has with the document. The passwords are limited to 32 characters.
703
+ #
704
+ # The permissions provided are an array of symbols, allowing identified
705
+ # users to perform particular actions:
706
+ # <tt>:print</tt>:: Print.
707
+ # <tt>:modify</tt>:: Modify text or objects.
708
+ # <tt>:copy</tt>:: Copy text or objects.
709
+ # <tt>:add</tt>:: Add text or objects.
710
+ def encrypt(user_pass = nil, owner_pass = nil, permissions = [])
711
+ perms = ["11000000"].pack("B8")
712
+
713
+ permissions.each do |perm|
714
+ perms += ENCRYPT_OPTIONS[perm] if ENCRYPT_OPTIONS[perm]
715
+ end
716
+
717
+ @arc4 ||= PDF::ARC4.new
718
+ owner_pass ||= user_pass
719
+
720
+ options = {
721
+ :owner_pass => owner_pass,
722
+ :user_pass => user_pass,
723
+ :permissions => perms,
724
+ }
725
+ @encryption = PDF::Writer::Object::Encryption.new(self, options)
726
+ end
730
727
 
731
728
  def encrypted?
732
729
  not @encryption.nil?
@@ -738,7 +735,7 @@ class PDF::Writer
738
735
 
739
736
  # Return the PDF stream as a string.
740
737
  def render(debug = false)
741
- clean_up
738
+ add_page_numbers
742
739
  @compression = false if $DEBUG or debug
743
740
  @arc4.init(@encryption_key) unless @arc4.nil?
744
741
 
@@ -2197,30 +2194,35 @@ class PDF::Writer
2197
2194
  def start_page_numbering(x, y, size, pos = nil, pattern = nil, starting = nil)
2198
2195
  pos ||= :left
2199
2196
  pattern ||= "<PAGENUM> of <TOTALPAGENUM>"
2197
+ starting ||= 1
2200
2198
 
2201
2199
  @page_numbering ||= []
2202
2200
  @page_numbering << (o = {})
2203
2201
 
2204
- page = @pageset.size
2202
+ page = @pageset.size - 1
2205
2203
  o[page] = {
2206
2204
  :x => x,
2207
2205
  :y => y,
2208
2206
  :pos => pos,
2209
2207
  :pattern => pattern,
2210
2208
  :starting => starting,
2211
- :size => size
2209
+ :size => size,
2210
+ :start => true
2212
2211
  }
2213
2212
  @page_numbering.index(o)
2214
2213
  end
2215
2214
 
2216
2215
  # Given a particular generic page number +page_num+ (numbered
2217
2216
  # sequentially from the beginning of the page set), return the page
2218
- # number under a particular page numbering +scheme+. Returns +nil+ if
2219
- # page numbering is not turned on.
2217
+ # number under a particular page numbering +scheme+ (defaults to the
2218
+ # first scheme turned on). Returns +nil+ if page numbering is not turned
2219
+ # on or if the page is not under the current numbering scheme.
2220
+ #
2221
+ # This method has been dprecated.
2220
2222
  def which_page_number(page_num, scheme = 0)
2221
2223
  return nil unless @page_numbering
2222
2224
 
2223
- num = 0
2225
+ num = nil
2224
2226
  start = start_num = 1
2225
2227
 
2226
2228
  @page_numbering[scheme].each do |kk, vv|
@@ -2232,7 +2234,7 @@ class PDF::Writer
2232
2234
  num = page_num - start_num + start
2233
2235
  end
2234
2236
  else
2235
- num = 0
2237
+ num = nil
2236
2238
  end
2237
2239
  end
2238
2240
  end
@@ -2245,103 +2247,108 @@ class PDF::Writer
2245
2247
  # numbering +scheme+ will be stopped as well. If +stop_at+ is
2246
2248
  # <tt>:current</tt>, then the page numbering will stop at this page;
2247
2249
  # otherwise, it will stop at the next page.
2250
+ #
2251
+ # This method has been dprecated.
2248
2252
  def stop_page_numbering(stop_total = false, stop_at = :current, scheme = 0)
2249
2253
  return false unless @page_numbering
2250
2254
 
2251
- page = @pageset.size
2255
+ page = @pageset.size - 1
2252
2256
 
2253
- if stop_at != :current and @page_numbering[scheme][page].kind_of?(Hash)
2254
- if stop_total
2255
- @page_numbering[scheme][page]["stoptn"] = true
2256
- else
2257
- @page_numbering[scheme][page]["stopn"] = true
2258
- end
2259
- else
2260
- if stop_total
2261
- @page_numbering[scheme][page] = "stopt"
2262
- else
2263
- @page_numbering[scheme][page] = "stop"
2264
- end
2257
+ @page_numbering[scheme][page] ||= {}
2258
+ o = @page_numbering[scheme][page]
2265
2259
 
2266
- @page_numbering[scheme][page] << "n" unless stop_at == :current
2260
+ case [ stop_total, stop_at == :current ]
2261
+ when [ true, true ]
2262
+ o[:stop] = :stop_total
2263
+ when [ true, false ]
2264
+ o[:stop] = :stop_total_next
2265
+ when [ false, true ]
2266
+ o[:stop] = :stop_next
2267
+ else
2268
+ o[:stop] = :stop
2267
2269
  end
2268
2270
  end
2269
2271
 
2270
- def page_number_search(label, tmp)
2271
- tmp.each do |scheme, v|
2272
- if v.kind_of?(Hash)
2273
- return scheme unless v[label].nil?
2274
- else
2275
- return scheme if v == label
2276
- end
2277
- end
2278
- 0
2272
+ def page_number_search(condition, scheme)
2273
+ res = nil
2274
+ scheme.each { |page, value| res = page if value[:stop] == condition }
2275
+ res
2279
2276
  end
2280
2277
  private :page_number_search
2281
2278
 
2282
2279
  def add_page_numbers
2283
2280
  # This will go through the @page_numbering array and add the page
2284
2281
  # numbers are required.
2285
- unless @page_numbering.nil?
2286
- total_pages1 = @pageset.size
2287
- tmp1 = @page_numbering
2288
- status = 0
2289
- info = {}
2290
- tmp1.each do |tmp|
2291
- # Do each of the page numbering systems. First, find the total
2292
- # pages for this one.
2293
- k = page_number_search("stopt", tmp)
2294
- if k and k > 0
2295
- total_pages = k - 1
2282
+ if @page_numbering
2283
+ page_count = @pageset.size
2284
+ pn_tmp = @page_numbering.dup
2285
+
2286
+ # Go through each of the page numbering schemes.
2287
+ pn_tmp.each do |scheme|
2288
+ # First, find the total pages for this schemes.
2289
+ page = page_number_search(:stop_total, scheme)
2290
+
2291
+ if page
2292
+ total_pages = page
2296
2293
  else
2297
- l = page_number_search("stoptn", tmp)
2298
- if l and l > 0
2299
- total_pages = l
2294
+ page = page_number_search(:stop_total_next, scheme)
2295
+ if page
2296
+ total_pages = page
2300
2297
  else
2301
- total_pages = total_pages1
2298
+ total_pages = page_count
2302
2299
  end
2303
2300
  end
2304
- @pageset.each_with_index do |id, page_num|
2305
- next if page_num == 0
2306
- if tmp[page_num].kind_of?(Hash) # This must be the starting page #s
2307
- status = 1
2308
- info = tmp[page_num]
2301
+
2302
+ status = nil
2303
+ delta = pattern = pos = x = y = size = nil
2304
+
2305
+ @pageset.each_with_index do |page, index|
2306
+ next if status.nil? and scheme[index].nil?
2307
+
2308
+ info = scheme[index]
2309
+ if info
2310
+ if info[:start]
2311
+ status = true
2309
2312
  if info[:starting]
2310
- info[:delta] = info[:starting] - page_num
2313
+ delta = info[:starting] - index
2311
2314
  else
2312
- info[:delta] = page_num
2315
+ delta = index
2316
+ end
2317
+
2318
+ pattern = info[:pattern]
2319
+ pos = info[:pos]
2320
+ x = info[:x]
2321
+ y = info[:y]
2322
+ size = info[:size]
2323
+
2324
+ # Check for the special case of page numbering starting and
2325
+ # stopping on the same page.
2326
+ status = :stop_next if info[:stop]
2327
+ elsif [:stop, :stop_total].include?(info[:stop])
2328
+ status = :stop_now
2329
+ elsif status == true and [:stop_next, :stop_total_next].include?(info[:stop])
2330
+ status = :stop_next
2313
2331
  end
2314
- # Also check for the special case of the numbering stopping
2315
- # and starting on the same page.
2316
- status = 2 if info["stopn"] or info["stoptn"]
2317
- elsif tmp[page_num] == "stop" or tmp[page_num] == "stopt"
2318
- status = 0 # we are stopping page numbers
2319
- elsif status == 1 and (tmp[page_num] == "stoptn" or tmp[page_num] == "stopn")
2320
- status = 2
2321
2332
  end
2322
2333
 
2323
- if status != 0
2334
+ if status
2324
2335
  # Add the page numbering to this page
2325
- unless info[:delta]
2326
- num = page_num
2327
- else
2328
- num = page_num + info[:delta]
2329
- end
2336
+ num = index + delta.to_i
2337
+ total = total_pages + num - index
2338
+ patt = pattern.gsub(/<PAGENUM>/, num.to_s).gsub(/<TOTALPAGENUM>/, total.to_s)
2339
+ reopen_object(page.contents.first)
2330
2340
 
2331
- total = total_pages + num - page_num
2332
- pat = info[:pattern].gsub(/<PAGENUM>/, num.to_s).gsub(/<TOTALPAGENUM>/, total.to_s)
2333
- reopen_object(id.contents.first)
2334
- case info[:pos]
2335
- when :right
2341
+ case pos
2342
+ when :left # Write the page number from x.
2336
2343
  w = 0
2337
- when :left
2338
- w = text_width(pat, info[:size])
2339
- when :center
2340
- w = text_width(pat, info[:size]) / 2.0
2344
+ when :right # Write the page number to x.
2345
+ w = text_width(patt, size)
2346
+ when :center # Write the page number around x.
2347
+ w = text_width(patt, size) / 2.0
2341
2348
  end
2342
- add_text(info[:x] + w, info[:y], pat, info[:size])
2349
+ add_text(x - w, y, patt, size)
2343
2350
  close_object
2344
- status = 0 if status == 2
2351
+ status = nil if [ :stop_now, :stop_next ].include?(status)
2345
2352
  end
2346
2353
  end
2347
2354
  end
@@ -2349,11 +2356,6 @@ class PDF::Writer
2349
2356
  end
2350
2357
  private :add_page_numbers
2351
2358
 
2352
- def clean_up
2353
- add_page_numbers
2354
- end
2355
- private :clean_up
2356
-
2357
2359
  def preprocess_text(text)
2358
2360
  text
2359
2361
  end
@@ -2530,8 +2532,8 @@ class PDF::Writer
2530
2532
  class TagAlink
2531
2533
  # The default anchored link style.
2532
2534
  DEFAULT_STYLE = {
2533
- :color => Color::Blue,
2534
- :text_color => Color::Blue,
2535
+ :color => Color::RGB::Blue,
2536
+ :text_color => Color::RGB::Blue,
2535
2537
  :draw_line => true,
2536
2538
  :line_style => { :dash => PDF::Writer::StrokeStyle::SOLID_LINE },
2537
2539
  :factor => 0.05
@@ -2542,9 +2544,9 @@ class PDF::Writer
2542
2544
  # is expected to be a hash with the following keys:
2543
2545
  #
2544
2546
  # <tt>:color</tt>:: The colour to be applied to the link
2545
- # underline. Default is Color::Blue.
2547
+ # underline. Default is Color::RGB::Blue.
2546
2548
  # <tt>:text_color</tt>:: The colour to be applied to the link text.
2547
- # Default is Color::Blue.
2549
+ # Default is Color::RGB::Blue.
2548
2550
  # <tt>:factor</tt>:: The size of the line, as a multiple of the
2549
2551
  # text height. Default is 0.05.
2550
2552
  # <tt>:draw_line</tt>:: Whether to draw the underline as part of
@@ -2691,11 +2693,11 @@ class PDF::Writer
2691
2693
  # with <C:bullet>.
2692
2694
  class TagBullet
2693
2695
  # The default bullet color.
2694
- DEFAULT_COLOR = Color::Black
2696
+ DEFAULT_COLOR = Color::RGB::Black
2695
2697
 
2696
2698
  class << self
2697
2699
  # Sets the style for <C:bullet> callback bullets that follow.
2698
- # Default is Color::Black.
2700
+ # Default is Color::RGB::Black.
2699
2701
  #
2700
2702
  # Set this to +nil+ to get the default colour.
2701
2703
  attr_accessor :color
@@ -2722,17 +2724,17 @@ class PDF::Writer
2722
2724
  # A callback function to support drawing of a disc bullet style.
2723
2725
  class TagDisc
2724
2726
  # The default disc bullet foreground.
2725
- DEFAULT_FOREGROUND = Color::Black
2727
+ DEFAULT_FOREGROUND = Color::RGB::Black
2726
2728
  # The default disc bullet background.
2727
- DEFAULT_BACKGROUND = Color::White
2729
+ DEFAULT_BACKGROUND = Color::RGB::White
2728
2730
  class << self
2729
2731
  # The foreground color for <C:disc> bullets. Default is
2730
- # Color::Black.
2732
+ # Color::RGB::Black.
2731
2733
  #
2732
2734
  # Set to +nil+ to get the default color.
2733
2735
  attr_accessor :foreground
2734
2736
  # The background color for <C:disc> bullets. Default is
2735
- # Color::White.
2737
+ # Color::RGB::White.
2736
2738
  #
2737
2739
  # Set to +nil+ to get the default color.
2738
2740
  attr_accessor :background