pdf-labels 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/History.txt +8 -0
  2. data/LICENCE +38 -0
  3. data/Manifest.txt +141 -0
  4. data/README.txt +72 -0
  5. data/Rakefile +30 -0
  6. data/lib/alias.rb +8 -0
  7. data/lib/glabel_template.rb +36 -0
  8. data/lib/label.rb +52 -0
  9. data/lib/layout.rb +13 -0
  10. data/lib/length_node.rb +47 -0
  11. data/lib/markup.rb +25 -0
  12. data/lib/pdf_label_page.rb +171 -0
  13. data/lib/pdf_labels.rb +6 -0
  14. data/lib/template.rb +37 -0
  15. data/templates/avery-iso-templates.xml +222 -0
  16. data/templates/avery-other-templates.xml +21 -0
  17. data/templates/avery-us-templates.xml +599 -0
  18. data/templates/glabels-2.0.dtd +329 -0
  19. data/templates/misc-iso-templates.xml +434 -0
  20. data/templates/misc-other-templates.xml +21 -0
  21. data/templates/misc-us-templates.xml +183 -0
  22. data/templates/paper-sizes.xml +37 -0
  23. data/templates/zweckform-iso-templates.xml +197 -0
  24. data/test/test_pdf_label_page.rb +91 -0
  25. data/vendor/color.rb +87 -0
  26. data/vendor/color/cmyk.rb +182 -0
  27. data/vendor/color/css.rb +27 -0
  28. data/vendor/color/grayscale.rb +135 -0
  29. data/vendor/color/hsl.rb +130 -0
  30. data/vendor/color/palette.rb +15 -0
  31. data/vendor/color/palette/gimp.rb +107 -0
  32. data/vendor/color/palette/monocontrast.rb +180 -0
  33. data/vendor/color/rgb-colors.rb +189 -0
  34. data/vendor/color/rgb.rb +311 -0
  35. data/vendor/color/rgb/metallic.rb +28 -0
  36. data/vendor/color/yiq.rb +78 -0
  37. data/vendor/pdf/charts.rb +13 -0
  38. data/vendor/pdf/charts/stddev.rb +433 -0
  39. data/vendor/pdf/grid.rb +135 -0
  40. data/vendor/pdf/math.rb +108 -0
  41. data/vendor/pdf/pagenumbers.rb +288 -0
  42. data/vendor/pdf/quickref.rb +331 -0
  43. data/vendor/pdf/simpletable.rb +947 -0
  44. data/vendor/pdf/techbook.rb +901 -0
  45. data/vendor/pdf/writer.rb +2801 -0
  46. data/vendor/pdf/writer/arc4.rb +63 -0
  47. data/vendor/pdf/writer/fontmetrics.rb +202 -0
  48. data/vendor/pdf/writer/fonts/Courier-Bold.afm +342 -0
  49. data/vendor/pdf/writer/fonts/Courier-BoldOblique.afm +342 -0
  50. data/vendor/pdf/writer/fonts/Courier-Oblique.afm +342 -0
  51. data/vendor/pdf/writer/fonts/Courier.afm +342 -0
  52. data/vendor/pdf/writer/fonts/Helvetica-Bold.afm +2827 -0
  53. data/vendor/pdf/writer/fonts/Helvetica-BoldOblique.afm +2827 -0
  54. data/vendor/pdf/writer/fonts/Helvetica-Oblique.afm +3051 -0
  55. data/vendor/pdf/writer/fonts/Helvetica.afm +3051 -0
  56. data/vendor/pdf/writer/fonts/Symbol.afm +213 -0
  57. data/vendor/pdf/writer/fonts/Times-Bold.afm +2588 -0
  58. data/vendor/pdf/writer/fonts/Times-BoldItalic.afm +2384 -0
  59. data/vendor/pdf/writer/fonts/Times-Italic.afm +2667 -0
  60. data/vendor/pdf/writer/fonts/Times-Roman.afm +2419 -0
  61. data/vendor/pdf/writer/fonts/ZapfDingbats.afm +225 -0
  62. data/vendor/pdf/writer/graphics.rb +813 -0
  63. data/vendor/pdf/writer/graphics/imageinfo.rb +365 -0
  64. data/vendor/pdf/writer/lang.rb +44 -0
  65. data/vendor/pdf/writer/lang/en.rb +104 -0
  66. data/vendor/pdf/writer/object.rb +23 -0
  67. data/vendor/pdf/writer/object/action.rb +40 -0
  68. data/vendor/pdf/writer/object/annotation.rb +42 -0
  69. data/vendor/pdf/writer/object/catalog.rb +39 -0
  70. data/vendor/pdf/writer/object/contents.rb +69 -0
  71. data/vendor/pdf/writer/object/destination.rb +40 -0
  72. data/vendor/pdf/writer/object/encryption.rb +53 -0
  73. data/vendor/pdf/writer/object/font.rb +68 -0
  74. data/vendor/pdf/writer/object/fontdescriptor.rb +34 -0
  75. data/vendor/pdf/writer/object/fontencoding.rb +40 -0
  76. data/vendor/pdf/writer/object/image.rb +308 -0
  77. data/vendor/pdf/writer/object/info.rb +79 -0
  78. data/vendor/pdf/writer/object/outline.rb +30 -0
  79. data/vendor/pdf/writer/object/outlines.rb +30 -0
  80. data/vendor/pdf/writer/object/page.rb +195 -0
  81. data/vendor/pdf/writer/object/pages.rb +115 -0
  82. data/vendor/pdf/writer/object/procset.rb +46 -0
  83. data/vendor/pdf/writer/object/viewerpreferences.rb +74 -0
  84. data/vendor/pdf/writer/ohash.rb +58 -0
  85. data/vendor/pdf/writer/oreader.rb +25 -0
  86. data/vendor/pdf/writer/state.rb +48 -0
  87. data/vendor/pdf/writer/strokestyle.rb +140 -0
  88. data/vendor/transaction/simple.rb +693 -0
  89. data/vendor/transaction/simple/group.rb +133 -0
  90. data/vendor/transaction/simple/threadsafe.rb +52 -0
  91. data/vendor/transaction/simple/threadsafe/group.rb +23 -0
  92. data/vendor/xml-mapping/ChangeLog +128 -0
  93. data/vendor/xml-mapping/LICENSE +56 -0
  94. data/vendor/xml-mapping/README +386 -0
  95. data/vendor/xml-mapping/README_XPATH +175 -0
  96. data/vendor/xml-mapping/Rakefile +214 -0
  97. data/vendor/xml-mapping/TODO.txt +32 -0
  98. data/vendor/xml-mapping/doc/xpath_impl_notes.txt +119 -0
  99. data/vendor/xml-mapping/examples/company.rb +34 -0
  100. data/vendor/xml-mapping/examples/company.xml +26 -0
  101. data/vendor/xml-mapping/examples/company_usage.intin.rb +19 -0
  102. data/vendor/xml-mapping/examples/company_usage.intout +39 -0
  103. data/vendor/xml-mapping/examples/order.rb +61 -0
  104. data/vendor/xml-mapping/examples/order.xml +54 -0
  105. data/vendor/xml-mapping/examples/order_signature_enhanced.rb +7 -0
  106. data/vendor/xml-mapping/examples/order_signature_enhanced.xml +9 -0
  107. data/vendor/xml-mapping/examples/order_signature_enhanced_usage.intin.rb +12 -0
  108. data/vendor/xml-mapping/examples/order_signature_enhanced_usage.intout +16 -0
  109. data/vendor/xml-mapping/examples/order_usage.intin.rb +73 -0
  110. data/vendor/xml-mapping/examples/order_usage.intout +147 -0
  111. data/vendor/xml-mapping/examples/time_augm.intin.rb +19 -0
  112. data/vendor/xml-mapping/examples/time_augm.intout +23 -0
  113. data/vendor/xml-mapping/examples/time_node.rb +27 -0
  114. data/vendor/xml-mapping/examples/xpath_create_new.intin.rb +85 -0
  115. data/vendor/xml-mapping/examples/xpath_create_new.intout +181 -0
  116. data/vendor/xml-mapping/examples/xpath_docvsroot.intin.rb +30 -0
  117. data/vendor/xml-mapping/examples/xpath_docvsroot.intout +34 -0
  118. data/vendor/xml-mapping/examples/xpath_ensure_created.intin.rb +62 -0
  119. data/vendor/xml-mapping/examples/xpath_ensure_created.intout +114 -0
  120. data/vendor/xml-mapping/examples/xpath_pathological.intin.rb +42 -0
  121. data/vendor/xml-mapping/examples/xpath_pathological.intout +56 -0
  122. data/vendor/xml-mapping/examples/xpath_usage.intin.rb +51 -0
  123. data/vendor/xml-mapping/examples/xpath_usage.intout +57 -0
  124. data/vendor/xml-mapping/install.rb +40 -0
  125. data/vendor/xml-mapping/lib/xml/mapping.rb +14 -0
  126. data/vendor/xml-mapping/lib/xml/mapping/base.rb +571 -0
  127. data/vendor/xml-mapping/lib/xml/mapping/standard_nodes.rb +343 -0
  128. data/vendor/xml-mapping/lib/xml/mapping/version.rb +8 -0
  129. data/vendor/xml-mapping/lib/xml/xxpath.rb +354 -0
  130. data/vendor/xml-mapping/test/all_tests.rb +6 -0
  131. data/vendor/xml-mapping/test/company.rb +56 -0
  132. data/vendor/xml-mapping/test/documents_folders.rb +33 -0
  133. data/vendor/xml-mapping/test/fixtures/bookmarks1.xml +24 -0
  134. data/vendor/xml-mapping/test/fixtures/company1.xml +85 -0
  135. data/vendor/xml-mapping/test/fixtures/documents_folders.xml +71 -0
  136. data/vendor/xml-mapping/test/fixtures/documents_folders2.xml +30 -0
  137. data/vendor/xml-mapping/test/multiple_mappings.rb +80 -0
  138. data/vendor/xml-mapping/test/tests_init.rb +2 -0
  139. data/vendor/xml-mapping/test/xml_mapping_adv_test.rb +84 -0
  140. data/vendor/xml-mapping/test/xml_mapping_test.rb +201 -0
  141. data/vendor/xml-mapping/test/xpath_test.rb +273 -0
  142. metadata +191 -0
@@ -0,0 +1,135 @@
1
+ #! /usr/bin/env ruby
2
+ #--
3
+ # PDF::Writer for Ruby.
4
+ # http://rubyforge.org/projects/ruby-pdf/
5
+ # Copyright 2003 - 2005 Austin Ziegler.
6
+ #
7
+ # Licensed under a MIT-style licence. See LICENCE in the main distribution
8
+ # for full licensing information.
9
+ #
10
+ # $Id: grid.rb,v 1.2 2005/08/12 03:19:44 austin Exp $
11
+ #++
12
+ require 'pdf/writer'
13
+
14
+ class PDF::Grid
15
+ # The scale of the grid lines in one direction. The scale always starts
16
+ # from the top or left of the page, depending on whether this is the X
17
+ # axis or Y axis. Minor lines are drawn before major lines.
18
+ class Scale
19
+ def initialize
20
+ @initial_gap = 0
21
+
22
+ yield self if block_given?
23
+ end
24
+
25
+ # The initial gap between the top or left of the page and the first
26
+ # grid line.
27
+ attr_accessor :initial_gap
28
+ # Major grid line style. The default is unset, which uses the current
29
+ # line style.
30
+ attr_accessor :major_style
31
+ # Major grid line colour. The default is unset, which uses the current
32
+ # line colour.
33
+ attr_accessor :major_color
34
+ # The number of units between each major line.
35
+ attr_accessor :major_step
36
+ # Minor grid line style. The default is unset, which uses the current
37
+ # line style.
38
+ attr_accessor :minor_style
39
+ # Minor grid line colour. The default is unset, which uses the current
40
+ # line colour.
41
+ attr_accessor :minor_color
42
+ # The number of units between each minor line.
43
+ attr_accessor :minor_step
44
+ end
45
+
46
+ def initialize
47
+ yield self if block_given?
48
+ end
49
+
50
+ # The X axis scale of the grid. X axis lines are drawn first.
51
+ attr_accessor :x_scale
52
+ # The Y axis scale of the grid. X axis lines are drawn first.
53
+ attr_accessor :y_scale
54
+
55
+ # Renders the grid on the document.
56
+ def render_on(pdf)
57
+ pdf.save_state
58
+
59
+ if @x_scale.minor_step and @x_scale.minor_step > 0
60
+ pdf.stroke_color! @x_scale.minor_color if @x_scale.minor_color
61
+ pdf.stroke_style! @x_scale.minor_style if @x_scale.minor_style
62
+
63
+ start = @x_scale.initial_gap
64
+ step = @x_scale.minor_step
65
+
66
+ start.step(pdf.page_width, step) do |x|
67
+ line(x, 0, x, pdf.page_height).stroke
68
+ end
69
+ end
70
+
71
+ if @y_scale.minor_step and @y_scale.minor_step > 0
72
+ pdf.stroke_color! @y_scale.minor_color if @y_scale.minor_color
73
+ pdf.stroke_style! @y_scale.minor_style if @y_scale.minor_style
74
+
75
+ start = pdf.page_height - @y_scale.initial_gap
76
+ step = -@y_scale.minor_step
77
+
78
+ start.step(0, step) do |y|
79
+ line(0, y, pdf.page_width, y).stroke
80
+ end
81
+ end
82
+
83
+ if @x_scale.major_step and @x_scale.major_step > 0
84
+ pdf.stroke_color! @x_scale.major_color if @x_scale.major_color
85
+ pdf.stroke_style! @x_scale.major_style if @x_scale.major_style
86
+
87
+ start = @x_scale.initial_gap
88
+ step = @x_scale.major_step
89
+
90
+ start.step(pdf.page_width, step) do |x|
91
+ line(x, 0, x, pdf.page_height).stroke
92
+ end
93
+ end
94
+
95
+ if @y_scale.major_step and @y_scale.major_step > 0
96
+ pdf.stroke_color! @y_scale.major_color if @y_scale.major_color
97
+ pdf.stroke_style! @y_scale.major_style if @y_scale.major_style
98
+
99
+ start = pdf.page_height - @y_scale.initial_gap
100
+ step = -@y_scale.major_step
101
+
102
+ start.step(0, step) do |y|
103
+ line(0, y, pdf.page_width, y).stroke
104
+ end
105
+ end
106
+
107
+ # stroke_color(Color::::RGB::Grey60)
108
+ # y = absolute_top_margin
109
+ # line(0, y, @page_width, y).stroke
110
+ # line(0, @bottom_margin, @page_width, @bottom_margin).stroke
111
+ # line(@left_margin, 0, @left_margin, @page_height).stroke
112
+ # x = absolute_right_margin
113
+ # line(x, 0, x, @page_height).stroke
114
+ # y = @page_height / 2.0
115
+ # line(0, y, @left_margin, y).stroke
116
+ # x = absolute_right_margin
117
+ # line(x, y, @page_width, y).stroke
118
+ # x = @page_width / 2.0
119
+ # line(x, 0, x, @bottom_margin).stroke
120
+ # y = absolute_top_margin
121
+ # line(x, y, x, @page_height).stroke
122
+
123
+ # 0.step(@page_width, 10) do |x|
124
+ # add_text(x, 0, 3, x.to_s)
125
+ # add_text(x, @page_height - 3, 3, x.to_s)
126
+ # end
127
+
128
+ # 0.step(@page_height, 10) do |y|
129
+ # add_text(0, y, 3, y.to_s)
130
+ # add_text(@page_width - 5, y, 3, y.to_s)
131
+ # end
132
+
133
+ restore_state
134
+ end
135
+ end
@@ -0,0 +1,108 @@
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: math.rb,v 1.3 2005/05/16 20:44:34 austin Exp $
10
+ #++
11
+ # Encapsulate some of the mathematical calculations that need to be
12
+ # performed when working with PDF documents. All angles in PDF::Writer are
13
+ # measured in degrees, but all angles in PDF documents are in radians. The
14
+ # standard conversions between radians, degrees, and gradians are
15
+ # provided.
16
+ #
17
+ # As with the Perl implementations of these conversions, they will be
18
+ # wrapped in the range of the target measurement (0..PI2 for radians,
19
+ # 0..360 for degrees, and 0..400 for gradians). To prevent this wrapping,
20
+ # provide a false value for the +wrap+ parameter.
21
+ #
22
+ # To wrap these values manually, use #rad2rad, #deg2deg, or #grad2grad.
23
+ module PDF::Math
24
+ class << self
25
+ PI2 = ::Math::PI * 2.0
26
+
27
+ # One degree of arc measured in terms of radians.
28
+ DR = PI2 / 360.0
29
+ # One radian of arc, measured in terms of degrees.
30
+ RD = 360 / PI2
31
+ # One degree of arc, measured in terms of gradians.
32
+ DG = 400 / 360.0
33
+ # One gradian of arc, measured in terms of degrees.
34
+ GD = 360 / 400.0
35
+ # One radian of arc, measured in terms of gradians.
36
+ RG = 400 / PI2
37
+ # One gradian of arc, measured in terms of radians.
38
+ GR = PI2 / 400.0
39
+
40
+ # Truncate the remainder.
41
+ def remt(num, den)
42
+ num - den * (num / den.to_f).to_i
43
+ end
44
+
45
+ # Wrap radian values within the range of radians (0..PI2).
46
+ def rad2rad(rad)
47
+ remt(rad, PI2)
48
+ end
49
+
50
+ # Wrap degree values within the range of degrees (0..360).
51
+ def deg2deg(deg)
52
+ remt(deg, 360)
53
+ end
54
+
55
+ # Wrap gradian values within the range of gradians (0..400).
56
+ def grad2grad(grad)
57
+ remt(grad, 400)
58
+ end
59
+
60
+ # Convert degrees to radians. The value will be constrained to the
61
+ # range of radians (0..PI2) unless +wrap+ is false.
62
+ def deg2rad(deg, wrap = true)
63
+ rad = DR * deg
64
+ rad = rad2rad(rad) if wrap
65
+ rad
66
+ end
67
+
68
+ # Convert degrees to gradians. The value will be constrained to the
69
+ # range of gradians (0..400) unless +wrap+ is false.
70
+ def deg2grad(deg, wrap = true)
71
+ grad = DG * deg
72
+ grad = grad2grad(grad) if wrap
73
+ grad
74
+ end
75
+
76
+ # Convert radians to degrees. The value will be constrained to the
77
+ # range of degrees (0..360) unless +wrap+ is false.
78
+ def rad2deg(rad, wrap = true)
79
+ deg = RD * rad
80
+ deg = deg2deg(deg) if wrap
81
+ deg
82
+ end
83
+
84
+ # Convert radians to gradians. The value will be constrained to the
85
+ # range of gradians (0..400) unless +wrap+ is false.
86
+ def rad2grad(rad, wrap = true)
87
+ grad = RG * rad
88
+ grad = grad2grad(grad) if wrap
89
+ grad
90
+ end
91
+
92
+ # Convert gradians to degrees. The value will be constrained to the
93
+ # range of degrees (0..360) unless +wrap+ is false.
94
+ def grad2deg(grad, wrap = true)
95
+ deg = GD * grad
96
+ deg = deg2deg(deg) if wrap
97
+ deg
98
+ end
99
+
100
+ # Convert gradians to radians. The value will be constrained to the
101
+ # range of radians (0..PI2) unless +wrap+ is false.
102
+ def grad2rad(grad, wrap = true)
103
+ rad = GR * grad
104
+ rad = rad2rad(rad) if wrap
105
+ rad
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,288 @@
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: pagenumbers.rb,v 1.3 2005/10/12 14:41:40 austin Exp $
10
+ #++
11
+ require 'pdf/writer'
12
+
13
+ # This class will create tables with a relatively simple API and internal
14
+ # implementation.
15
+ class PDF::PageNumbers
16
+ VERSION = '1.1.4'
17
+
18
+ # Creates a page numbering object. The
19
+ def initialize(x, y, options = {})
20
+ @x = x
21
+ @y = y
22
+
23
+ @font = options[:font]
24
+ @font_encoding = options[:font_encoding]
25
+ @font_size = options[:font_size]
26
+ @alignment = options[:alignment] || :left
27
+ @pattern = options[:pattern] || "<PAGE> of <TOTAL>"
28
+ @first_page_number = options[:first_page_number] || 1
29
+
30
+ @start_pages = []
31
+ @stop_pages = []
32
+
33
+ yield self if block_given?
34
+ end
35
+
36
+ # The +x+ position for the page numbering. This will be used as a
37
+ # relative position based on <tt>#alignment</tt>.
38
+ attr_accessor :x
39
+ # The +y+ position for the page numbering.
40
+ attr_accessor :y
41
+ # The font that will be used for rendering the page numbers. If not
42
+ # specified, the font currently active at the time of page rendering
43
+ # will be used.
44
+ attr_accessor :font
45
+ # The font encoding for rendering page numbers. If not specified, the
46
+ # default font encoding will be used.
47
+ attr_accessor :font_encoding
48
+ # The size of the font for rendering page numbers. If not specified, the
49
+ # current font size at the time of page rendering will be used.
50
+ attr_accessor :font_size
51
+ # The alignment of the page numbers relative to <tt>#x</tt>. The options
52
+ # are <tt>:left</tt> (the text *begins* at <tt>#x</tt>),
53
+ # <tt>:right</tt> (the text *ends* at <tt>#x</tt>), and <tt>:center</tt>
54
+ # (the text *surrounds* <tt>#x</tt>). The default alignment is
55
+ # <tt>:left</tt>.
56
+ attr_accessor :alignment
57
+ # The page numbering pattern object. This object must either be a String
58
+ # or an object that responds to #apply(page, total). String patterns
59
+ # will be searched for <PAGE> and <TOTAL> and these strings will be
60
+ # replaced with the current page number and the total page number values
61
+ # in Arabic (1, 2, 3, 4, ...) numeral values.
62
+ #
63
+ # Pattern objects will have their #apply method called with the current
64
+ # page number and the total page number values. They will be expected to
65
+ # return a String for writing on the page.
66
+ #
67
+ # The default pattern is "<PAGE> of <TOTAL>".
68
+ attr_accessor :pattern
69
+ # The page numbering style. This is a number "generator" object that
70
+ # responds to #[] and returns a string representing that number.
71
+ # Symbolic values <tt>:default</tt>
72
+ #
73
+ # The
74
+ # values <tt>:arabic</tt> and <tt>:roman</tt>
75
+ attr_accessor :numbering_style
76
+ # The first page number is the value that will be used as the
77
+ # generic page number reported by the PDF document during rendering.
78
+ # This allows physical page 10 to be presented as page 1.
79
+ attr_accessor :first_page_number
80
+
81
+ # Starts page numbering with this page numbering object. The page
82
+ # numbering will begin on +first_page+, which will be either
83
+ # <tt>:this_page</tt> or <tt>:next_page</tt>.
84
+ def start(pdf, first_page = :this_page)
85
+ end
86
+
87
+ .blist {{{
88
+ <b>:this_page</b> will add the object just to the current page.
89
+ <b>:all_pages</b> will add the object to the current and all following pages.
90
+ <b>:even_pages</b> will add the object to following even pages, including the current page if it is an even page.
91
+ <b>:odd_pages</b> will add the object to following odd pages, including the current page if it is an odd page.
92
+ <b>:all_following_pages</b> will add the object to the next page created and all following pages.
93
+ <b>:following_even_pages</b> will add to the next even page created and all following even pages.
94
+ <b>:following_odd_pages</b> will add to the next odd page created and all following odd pages.
95
+ .endblist }}}
96
+
97
+ def restart_numbering(pdf, page = :this_page)
98
+ end
99
+
100
+ def stop_on_current_page(pdf)
101
+ end
102
+
103
+ def stop_on_next_page(pdf)
104
+ end
105
+
106
+ #
107
+ def start(pdf, on_page = :current)
108
+ end
109
+
110
+ def stop(pdf, on_page = :next)
111
+ end
112
+
113
+ def render(pdf, debug = false)
114
+ end
115
+
116
+ # Put page numbers on the pages from the current page. Place them
117
+ # relative to the coordinates <tt>(x, y)</tt> with the text horizontally
118
+ # relative according to +pos+, which may be <tt>:left</tt>,
119
+ # <tt>:right</tt>, or <tt>:center</tt>. The page numbers will be written
120
+ # on each page using +pattern+.
121
+ #
122
+ # When +pattern+ is rendered, <PAGENUM> will be replaced with the
123
+ # current page number; <TOTALPAGENUM> will be replaced with the total
124
+ # number of pages in the page numbering scheme. The default +pattern+ is
125
+ # "<PAGENUM> of <TOTALPAGENUM>".
126
+ #
127
+ # If +starting+ is non-nil, this is the first page number. The number of
128
+ # total pages will be adjusted to account for this.
129
+ #
130
+ # Each time page numbers are started, a new page number scheme will be
131
+ # started. The scheme number will be returned.
132
+ def start_page_numbering(x, y, size, pos = nil, pattern = nil, starting = nil)
133
+ pos ||= :left
134
+ pattern ||= "<PAGENUM> of <TOTALPAGENUM>"
135
+
136
+ @page_numbering ||= []
137
+ @page_numbering << (o = {})
138
+
139
+ page = @pageset.size
140
+ o[page] = {
141
+ :x => x,
142
+ :y => y,
143
+ :pos => pos,
144
+ :pattern => pattern,
145
+ :starting => starting,
146
+ :size => size
147
+ }
148
+ @page_numbering.index(o)
149
+ end
150
+
151
+ # Given a particular generic page number +page_num+ (numbered
152
+ # sequentially from the beginning of the page set), return the page
153
+ # number under a particular page numbering +scheme+. Returns +nil+ if
154
+ # page numbering is not turned on.
155
+ def which_page_number(page_num, scheme = 0)
156
+ return nil unless @page_numbering
157
+
158
+ num = 0
159
+ start = start_num = 1
160
+
161
+ @page_numbering[scheme].each do |kk, vv|
162
+ if kk <= page_num
163
+ if vv.kind_of?(Hash)
164
+ unless vv[:starting].nil?
165
+ start = vv[:starting]
166
+ start_num = kk
167
+ num = page_num - start_num + start
168
+ end
169
+ else
170
+ num = 0
171
+ end
172
+ end
173
+ end
174
+ num
175
+ end
176
+
177
+ # Stop page numbering. Returns +false+ if page numbering is off.
178
+ #
179
+ # If +stop_total+ is true, then then the totaling of pages for this page
180
+ # numbering +scheme+ will be stopped as well. If +stop_at+ is
181
+ # <tt>:current</tt>, then the page numbering will stop at this page;
182
+ # otherwise, it will stop at the next page.
183
+ def stop_page_numbering(stop_total = false, stop_at = :current, scheme = 0)
184
+ return false unless @page_numbering
185
+
186
+ page = @pageset.size
187
+
188
+ if stop_at != :current and @page_numbering[scheme][page].kind_of?(Hash)
189
+ if stop_total
190
+ @page_numbering[scheme][page]["stoptn"] = true
191
+ else
192
+ @page_numbering[scheme][page]["stopn"] = true
193
+ end
194
+ else
195
+ if stop_total
196
+ @page_numbering[scheme][page] = "stopt"
197
+ else
198
+ @page_numbering[scheme][page] = "stop"
199
+ end
200
+
201
+ @page_numbering[scheme][page] << "n" unless stop_at == :current
202
+ end
203
+ end
204
+
205
+ def page_number_search(label, tmp)
206
+ tmp.each do |scheme, v|
207
+ if v.kind_of?(Hash)
208
+ return scheme unless v[label].nil?
209
+ else
210
+ return scheme if v == label
211
+ end
212
+ end
213
+ 0
214
+ end
215
+ private :page_number_search
216
+
217
+ def add_page_numbers
218
+ # This will go through the @page_numbering array and add the page
219
+ # numbers are required.
220
+ unless @page_numbering.nil?
221
+ total_pages1 = @pageset.size
222
+ tmp1 = @page_numbering
223
+ status = 0
224
+ info = {}
225
+ tmp1.each do |tmp|
226
+ # Do each of the page numbering systems. First, find the total
227
+ # pages for this one.
228
+ k = page_number_search("stopt", tmp)
229
+ if k and k > 0
230
+ total_pages = k - 1
231
+ else
232
+ l = page_number_search("stoptn", tmp)
233
+ if l and l > 0
234
+ total_pages = l
235
+ else
236
+ total_pages = total_pages1
237
+ end
238
+ end
239
+ @pageset.each_with_index do |id, page_num|
240
+ next if page_num == 0
241
+ if tmp[page_num].kind_of?(Hash) # This must be the starting page #s
242
+ status = 1
243
+ info = tmp[page_num]
244
+ if info[:starting]
245
+ info[:delta] = info[:starting] - page_num
246
+ else
247
+ info[:delta] = page_num
248
+ end
249
+ # Also check for the special case of the numbering stopping
250
+ # and starting on the same page.
251
+ status = 2 if info["stopn"] or info["stoptn"]
252
+ elsif tmp[page_num] == "stop" or tmp[page_num] == "stopt"
253
+ status = 0 # we are stopping page numbers
254
+ elsif status == 1 and (tmp[page_num] == "stoptn" or tmp[page_num] == "stopn")
255
+ status = 2
256
+ end
257
+
258
+ if status != 0
259
+ # Add the page numbering to this page
260
+ unless info[:delta]
261
+ num = page_num
262
+ else
263
+ num = page_num + info[:delta]
264
+ end
265
+
266
+ total = total_pages + num - page_num
267
+ pat = info[:pattern].gsub(/<PAGENUM>/, num.to_s).gsub(/<TOTALPAGENUM>/, total.to_s)
268
+ reopen_object(id.contents.first)
269
+
270
+ case info[:pos]
271
+ when :left # Write the page number from x.
272
+ w = 0
273
+ when :right # Write the page number to x.
274
+ w = text_width(pat, info[:size])
275
+ when :center # Write the page number around x.
276
+ w = text_width(pat, info[:size]) / 2.0
277
+ end
278
+ add_text(info[:x] - w, info[:y], pat, info[:size])
279
+ close_object
280
+ status = 0 if status == 2
281
+ end
282
+ end
283
+ end
284
+ end
285
+ end
286
+ private :add_page_numbers
287
+
288
+ end