prawn 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. data/README +6 -10
  2. data/Rakefile +4 -13
  3. data/data/encodings/win_ansi.txt +29 -0
  4. data/data/images/fractal.jpg +0 -0
  5. data/data/images/letterhead.jpg +0 -0
  6. data/examples/bounding_box/bounding_boxes.rb +44 -0
  7. data/examples/bounding_box/lazy_bounding_boxes.rb +28 -0
  8. data/examples/bounding_box/padded_box.rb +24 -0
  9. data/examples/{russian_boxes.rb → bounding_box/russian_boxes.rb} +9 -6
  10. data/examples/general/background.rb +20 -0
  11. data/examples/{canvas.rb → general/canvas.rb} +6 -2
  12. data/examples/general/measurement_units.rb +52 -0
  13. data/examples/{multi_page_layout.rb → general/multi_page_layout.rb} +6 -3
  14. data/examples/{page_geometry.rb → general/page_geometry.rb} +6 -2
  15. data/examples/{image.rb → graphics/basic_images.rb} +8 -4
  16. data/examples/graphics/cmyk.rb +13 -0
  17. data/examples/graphics/curves.rb +12 -0
  18. data/examples/{hexagon.rb → graphics/hexagon.rb} +5 -5
  19. data/examples/graphics/image_fit.rb +16 -0
  20. data/examples/graphics/image_flow.rb +38 -0
  21. data/examples/graphics/image_position.rb +18 -0
  22. data/examples/{line.rb → graphics/line.rb} +4 -2
  23. data/examples/{png_types.rb → graphics/png_types.rb} +4 -4
  24. data/examples/{polygons.rb → graphics/polygons.rb} +5 -4
  25. data/examples/graphics/remote_images.rb +12 -0
  26. data/examples/{ruport_helpers.rb → graphics/ruport_style_helpers.rb} +8 -5
  27. data/examples/graphics/stroke_bounds.rb +23 -0
  28. data/examples/{chinese_text_wrapping.rb → m17n/chinese_text_wrapping.rb} +7 -4
  29. data/examples/m17n/euro.rb +16 -0
  30. data/examples/m17n/sjis.rb +29 -0
  31. data/examples/m17n/utf8.rb +14 -0
  32. data/examples/m17n/win_ansi_charset.rb +55 -0
  33. data/examples/{addressbook.csv → table/addressbook.csv} +0 -0
  34. data/examples/{cell.rb → table/cell.rb} +8 -6
  35. data/examples/{currency.csv → table/currency.csv} +0 -0
  36. data/examples/{fancy_table.rb → table/fancy_table.rb} +9 -6
  37. data/examples/{ruport_formatter.rb → table/ruport_formatter.rb} +6 -3
  38. data/examples/{table.rb → table/table.rb} +6 -2
  39. data/examples/table/table_alignment.rb +18 -0
  40. data/examples/table/table_border_color.rb +17 -0
  41. data/examples/table/table_colspan.rb +19 -0
  42. data/examples/table/table_header_color.rb +19 -0
  43. data/examples/table/table_header_underline.rb +15 -0
  44. data/examples/{alignment.rb → text/alignment.rb} +5 -2
  45. data/examples/text/family_based_styling.rb +25 -0
  46. data/examples/{flowing_text_with_header_and_footer.rb → text/flowing_text_with_header_and_footer.rb} +19 -8
  47. data/examples/text/font_calculations.rb +91 -0
  48. data/examples/text/font_size.rb +34 -0
  49. data/examples/{kerning.rb → text/kerning.rb} +5 -1
  50. data/examples/text/simple_text.rb +18 -0
  51. data/examples/text/simple_text_ttf.rb +18 -0
  52. data/examples/{span.rb → text/span.rb} +5 -2
  53. data/examples/text/text_box.rb +26 -0
  54. data/examples/{text_flow.rb → text/text_flow.rb} +5 -2
  55. data/lib/prawn.rb +26 -20
  56. data/lib/prawn/compatibility.rb +5 -8
  57. data/lib/prawn/document.rb +29 -13
  58. data/lib/prawn/document/annotations.rb +63 -0
  59. data/lib/prawn/document/bounding_box.rb +18 -3
  60. data/lib/prawn/document/destinations.rb +81 -0
  61. data/lib/prawn/document/internals.rb +16 -2
  62. data/lib/prawn/document/page_geometry.rb +58 -57
  63. data/lib/prawn/document/span.rb +8 -0
  64. data/lib/prawn/document/table.rb +81 -31
  65. data/lib/prawn/document/text.rb +66 -21
  66. data/lib/prawn/document/text/box.rb +77 -0
  67. data/lib/prawn/encoding.rb +121 -0
  68. data/lib/prawn/errors.rb +4 -0
  69. data/lib/prawn/font.rb +70 -42
  70. data/lib/prawn/font/metrics.rb +64 -119
  71. data/lib/prawn/graphics.rb +105 -87
  72. data/lib/prawn/graphics/cell.rb +55 -28
  73. data/lib/prawn/graphics/color.rb +8 -0
  74. data/lib/prawn/images.rb +55 -12
  75. data/lib/prawn/images/jpg.rb +2 -1
  76. data/lib/prawn/images/png.rb +2 -1
  77. data/lib/prawn/literal_string.rb +14 -0
  78. data/lib/prawn/measurement_extensions.rb +46 -0
  79. data/lib/prawn/measurements.rb +71 -0
  80. data/lib/prawn/name_tree.rb +165 -0
  81. data/lib/prawn/pdf_object.rb +8 -1
  82. data/spec/annotations_spec.rb +90 -0
  83. data/spec/destinations_spec.rb +15 -0
  84. data/spec/document_spec.rb +39 -2
  85. data/spec/font_spec.rb +22 -0
  86. data/spec/graphics_spec.rb +99 -87
  87. data/spec/images_spec.rb +29 -1
  88. data/spec/measurement_units_spec.rb +23 -0
  89. data/spec/metrics_spec.rb +3 -2
  90. data/spec/name_tree_spec.rb +103 -0
  91. data/spec/pdf_object_spec.rb +15 -5
  92. data/spec/png_spec.rb +14 -14
  93. data/spec/spec_helper.rb +8 -6
  94. data/spec/table_spec.rb +40 -0
  95. data/spec/text_spec.rb +6 -4
  96. data/vendor/ttfunk/data/fonts/DejaVuSans.ttf +0 -0
  97. data/vendor/ttfunk/data/fonts/comicsans.ttf +0 -0
  98. data/vendor/ttfunk/example.rb +5 -0
  99. data/vendor/ttfunk/lib/ttfunk.rb +48 -0
  100. data/vendor/ttfunk/lib/ttfunk/table.rb +27 -0
  101. data/vendor/ttfunk/lib/ttfunk/table/cmap.rb +94 -0
  102. data/vendor/ttfunk/lib/ttfunk/table/directory.rb +25 -0
  103. data/vendor/ttfunk/lib/ttfunk/table/head.rb +25 -0
  104. data/vendor/ttfunk/lib/ttfunk/table/hhea.rb +27 -0
  105. data/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +20 -0
  106. data/vendor/ttfunk/lib/ttfunk/table/kern.rb +48 -0
  107. data/vendor/ttfunk/lib/ttfunk/table/maxp.rb +17 -0
  108. data/vendor/ttfunk/lib/ttfunk/table/name.rb +52 -0
  109. metadata +93 -62
  110. data/examples/bounding_boxes.rb +0 -30
  111. data/examples/curves.rb +0 -10
  112. data/examples/family_based_styling.rb +0 -21
  113. data/examples/font_size.rb +0 -19
  114. data/examples/image2.rb +0 -13
  115. data/examples/image_flow.rb +0 -29
  116. data/examples/lazy_bounding_boxes.rb +0 -19
  117. data/examples/remote_images.rb +0 -7
  118. data/examples/simple_text.rb +0 -15
  119. data/examples/simple_text_ttf.rb +0 -16
  120. data/examples/sjis.rb +0 -21
  121. data/examples/utf8.rb +0 -12
  122. data/vendor/font_ttf/ttf.rb +0 -20
  123. data/vendor/font_ttf/ttf/datatypes.rb +0 -189
  124. data/vendor/font_ttf/ttf/encodings.rb +0 -140
  125. data/vendor/font_ttf/ttf/exceptions.rb +0 -28
  126. data/vendor/font_ttf/ttf/file.rb +0 -290
  127. data/vendor/font_ttf/ttf/fontchunk.rb +0 -77
  128. data/vendor/font_ttf/ttf/table/cmap.rb +0 -408
  129. data/vendor/font_ttf/ttf/table/cvt.rb +0 -49
  130. data/vendor/font_ttf/ttf/table/fpgm.rb +0 -48
  131. data/vendor/font_ttf/ttf/table/gasp.rb +0 -88
  132. data/vendor/font_ttf/ttf/table/glyf.rb +0 -452
  133. data/vendor/font_ttf/ttf/table/head.rb +0 -86
  134. data/vendor/font_ttf/ttf/table/hhea.rb +0 -96
  135. data/vendor/font_ttf/ttf/table/hmtx.rb +0 -98
  136. data/vendor/font_ttf/ttf/table/kern.rb +0 -186
  137. data/vendor/font_ttf/ttf/table/loca.rb +0 -75
  138. data/vendor/font_ttf/ttf/table/maxp.rb +0 -81
  139. data/vendor/font_ttf/ttf/table/name.rb +0 -222
  140. data/vendor/font_ttf/ttf/table/os2.rb +0 -172
  141. data/vendor/font_ttf/ttf/table/post.rb +0 -120
  142. data/vendor/font_ttf/ttf/table/prep.rb +0 -27
  143. data/vendor/font_ttf/ttf/table/vhea.rb +0 -45
  144. data/vendor/font_ttf/ttf/table/vmtx.rb +0 -36
@@ -1,6 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
-
4
3
  # cell.rb : Table support functions
5
4
  #
6
5
  # Copyright June 2008, Gregory Brown. All Rights Reserved.
@@ -41,24 +40,33 @@ module Prawn
41
40
  # <tt>:point</tt>:: Absolute [x,y] coordinate of the top-left corner of the cell.
42
41
  # <tt>:document</tt>:: The Prawn::Document object to render on.
43
42
  # <tt>:text</tt>:: The text to be flowed within the cell
43
+ # <tt>:text_color</tt>:: The color of the text to be displayed
44
44
  # <tt>:width</tt>:: The width in PDF points of the cell.
45
- # <tt>:border</tt>:: The border line width. If omitted, no border will be drawn.
45
+ # <tt>:height</tt>:: The height in PDF points of the cell.
46
46
  # <tt>:horizontal_padding</tt>:: The horizontal padding in PDF points
47
47
  # <tt>:vertical_padding</tt>:: The vertical padding in PDF points
48
48
  # <tt>:padding</tt>:: Overrides both horizontal and vertical padding
49
- # <tt>:border_style</tt>:: One of <tt>:all</tt>, <tt>:no_top</tt>, <tt>:no_bottom</tt>, <tt>:sides</tt>
50
49
  # <tt>:align</tt>:: One of <tt>:left</tt>, <tt>:right</tt>, <tt>:center</tt>
50
+ # <tt>:borders</tt>:: An array of sides which should have a border. Any of <tt>:top</tt>, <tt>:left</tt>, <tt>:right</tt>, <tt>:bottom</tt>
51
+ # <tt>:border_width</tt>:: The border line width. Defaults to 1.
52
+ # <tt>:border_style</tt>:: One of <tt>:all</tt>, <tt>:no_top</tt>, <tt>:no_bottom</tt>, <tt>:sides</tt>, <tt>:none</tt>, <tt>:bottom_only</tt>. Defaults to :all.
53
+ # <tt>:border_color</tt>:: The color of the cell border.
54
+ # <tt>:font_size</tt>:: The font size for the cell text.
51
55
  #
52
56
  def initialize(options={})
53
57
  @point = options[:point]
54
58
  @document = options[:document]
55
59
  @text = options[:text].to_s
60
+ @text_color = options[:text_color]
56
61
  @width = options[:width]
62
+ @height = options[:height]
57
63
  @borders = options[:borders]
58
64
  @border_width = options[:border_width] || 1
59
65
  @border_style = options[:border_style] || :all
66
+ @border_color = options[:border_color]
60
67
  @background_color = options[:background_color]
61
68
  @align = options[:align] || :left
69
+ @font_size = options[:font_size]
62
70
 
63
71
  @horizontal_padding = options[:horizontal_padding] || 0
64
72
  @vertical_padding = options[:vertical_padding] || 0
@@ -70,7 +78,7 @@ module Prawn
70
78
 
71
79
  attr_accessor :point, :border_style, :border_width, :background_color,
72
80
  :document, :horizontal_padding, :vertical_padding, :align,
73
- :borders
81
+ :borders, :text_color, :border_color
74
82
 
75
83
  attr_writer :height, :width #:nodoc:
76
84
 
@@ -90,7 +98,7 @@ module Prawn
90
98
  #
91
99
  def width
92
100
  @width || (@document.font.metrics.string_width(@text,
93
- @document.font.size)) + 2*@horizontal_padding
101
+ @font_size || @document.font.size)) + 2*@horizontal_padding
94
102
  end
95
103
 
96
104
  # The height of the cell in PDF points
@@ -125,26 +133,30 @@ module Prawn
125
133
  @document.mask(:line_width) do
126
134
  @document.line_width = @border_width
127
135
 
128
- if borders.include?(:left)
129
- @document.stroke_line [rel_point[0], rel_point[1] + (@border_width / 2.0)],
130
- [rel_point[0], rel_point[1] - height - @border_width / 2.0 ]
131
- end
132
-
133
- if borders.include?(:right)
134
- @document.stroke_line(
135
- [rel_point[0] + width, rel_point[1] + (@border_width / 2.0)],
136
- [rel_point[0] + width, rel_point[1] - height - @border_width / 2.0] )
137
- end
138
-
139
- if borders.include?(:top)
140
- @document.stroke_line(
141
- [ rel_point[0] + @border_width / 2.0, rel_point[1] ],
142
- [ rel_point[0] - @border_width / 2.0 + width, rel_point[1] ])
143
- end
144
-
145
- if borders.include?(:bottom)
146
- @document.stroke_line [rel_point[0], rel_point[1] - height ],
147
- [rel_point[0] + width, rel_point[1] - height]
136
+ @document.mask(:stroke_color) do
137
+ @document.stroke_color @border_color if @border_color
138
+
139
+ if borders.include?(:left)
140
+ @document.stroke_line [rel_point[0], rel_point[1] + (@border_width / 2.0)],
141
+ [rel_point[0], rel_point[1] - height - @border_width / 2.0 ]
142
+ end
143
+
144
+ if borders.include?(:right)
145
+ @document.stroke_line(
146
+ [rel_point[0] + width, rel_point[1] + (@border_width / 2.0)],
147
+ [rel_point[0] + width, rel_point[1] - height - @border_width / 2.0] )
148
+ end
149
+
150
+ if borders.include?(:top)
151
+ @document.stroke_line(
152
+ [ rel_point[0] + @border_width / 2.0, rel_point[1] ],
153
+ [ rel_point[0] - @border_width / 2.0 + width, rel_point[1] ])
154
+ end
155
+
156
+ if borders.include?(:bottom)
157
+ @document.stroke_line [rel_point[0], rel_point[1] - height ],
158
+ [rel_point[0] + width, rel_point[1] - height]
159
+ end
148
160
  end
149
161
 
150
162
  end
@@ -157,7 +169,16 @@ module Prawn
157
169
  @point[1] - @vertical_padding],
158
170
  :width => text_area_width,
159
171
  :height => height - @vertical_padding) do
160
- @document.text @text, :align => @align
172
+ @document.move_up @document.font.line_gap
173
+
174
+ options = {:align => @align}
175
+
176
+ options[:size] = @font_size if @font_size
177
+
178
+ @document.mask(:fill_color) do
179
+ @document.fill_color @text_color if @text_color
180
+ @document.text @text, options
181
+ end
161
182
  end
162
183
  end
163
184
 
@@ -173,6 +194,10 @@ module Prawn
173
194
  [:left,:right,:bottom]
174
195
  when :no_bottom
175
196
  [:left,:right,:top]
197
+ when :bottom_only
198
+ [:bottom]
199
+ when :none
200
+ []
176
201
  end
177
202
  end
178
203
 
@@ -189,8 +214,8 @@ module Prawn
189
214
  @height = 0
190
215
  end
191
216
 
192
- attr_reader :width, :height
193
- attr_accessor :background_color
217
+ attr_reader :width, :height, :cells
218
+ attr_accessor :background_color, :text_color, :border_color
194
219
 
195
220
  def <<(cell)
196
221
  @cells << cell
@@ -208,6 +233,8 @@ module Prawn
208
233
  y - @document.bounds.absolute_bottom]
209
234
  e.height = @height
210
235
  e.background_color ||= @background_color
236
+ e.text_color ||= @text_color
237
+ e.border_color ||= @border_color
211
238
  e.draw
212
239
  x += e.width
213
240
  end
@@ -1,3 +1,11 @@
1
+ # encoding: utf-8
2
+
3
+ # color.rb : Implements color handling
4
+ #
5
+ # Copyright June 2008, Gregory Brown. All Rights Reserved.
6
+ #
7
+ # This is free software. Please see the LICENSE and COPYING files for details.
8
+ #
1
9
  module Prawn
2
10
  module Graphics
3
11
  module Color
@@ -18,11 +18,13 @@ module Prawn
18
18
  # <tt>file</tt>:: path to file or an object that responds to #read
19
19
  #
20
20
  # Options:
21
- # <tt>:at</tt>:: the location of the top left corner of the image.
21
+ # <tt>:at</tt>:: an array [x,y] with the location of the top left corner of the image.
22
22
  # <tt>:position</tt>:: One of (:left, :center, :right) or an x-offset
23
+ # <tt>:vposition</tt>:: One of (:top, :center, :center) or an y-offset
23
24
  # <tt>:height</tt>:: the height of the image [actual height of the image]
24
25
  # <tt>:width</tt>:: the width of the image [actual width of the image]
25
- # <tt>:scale</tt>:: scale the dimensions of the image proportionally
26
+ # <tt>:scale</tt>:: scale the dimensions of the image proportionally
27
+ # <tt>:fit</tt>:: scale the dimensions of the image proportionally to fit inside [width,height]
26
28
  #
27
29
  # Prawn::Document.generate("image2.pdf", :page_layout => :landscape) do
28
30
  # pigs = "#{Prawn::BASEDIR}/data/images/pigs.jpg"
@@ -36,6 +38,11 @@ module Prawn
36
38
  # proportionally. When both are provided, the image will be stretched to
37
39
  # fit the dimensions without maintaining the aspect ratio.
38
40
  #
41
+ #
42
+ # If :at is provided, the image will be place in the current page but
43
+ # the text position will not be changed.
44
+ #
45
+ #
39
46
  # If instead of an explicit filename, an object with a read method is
40
47
  # passed as +file+, you can embed images from IO objects and things
41
48
  # that act like them (including Tempfiles and open-uri objects).
@@ -50,14 +57,15 @@ module Prawn
50
57
  # dimensions of an image object if needed.
51
58
  # (See also: Prawn::Images::PNG , Prawn::Images::JPG)
52
59
  #
53
- def image(file, options={})
54
- Prawn.verify_options [:at,:position, :height, :width, :scale], options
55
-
60
+ def image(file, options={})
61
+ Prawn.verify_options [:at, :position, :vposition, :height,
62
+ :width, :scale, :fit], options
63
+
56
64
  if file.respond_to?(:read)
57
65
  image_content = file.read
58
66
  else
59
67
  raise ArgumentError, "#{file} not found" unless File.file?(file)
60
- image_content = File.read_binary(file)
68
+ image_content = File.binread(file)
61
69
  end
62
70
 
63
71
  image_sha1 = Digest::SHA1.hexdigest(image_content)
@@ -86,7 +94,8 @@ module Prawn
86
94
 
87
95
  # find where the image will be placed and how big it will be
88
96
  w,h = calc_image_dimensions(info, options)
89
- if options[:at]
97
+
98
+ if options[:at]
90
99
  x,y = translate(options[:at])
91
100
  else
92
101
  x,y = image_position(w,h,options)
@@ -109,6 +118,7 @@ module Prawn
109
118
 
110
119
  def image_position(w,h,options)
111
120
  options[:position] ||= :left
121
+
112
122
  x = case options[:position]
113
123
  when :left
114
124
  bounds.absolute_left
@@ -118,8 +128,20 @@ module Prawn
118
128
  bounds.absolute_right - w
119
129
  when Numeric
120
130
  options[:position] + bounds.absolute_left
121
- end
122
-
131
+ end
132
+
133
+ y = case options[:vposition]
134
+ when :top
135
+ bounds.absolute_top
136
+ when :center
137
+ bounds.absolute_top - (bounds.height - h) / 2.0
138
+ when :bottom
139
+ bounds.absolute_bottom + h
140
+ when Numeric
141
+ bounds.absolute_top - options[:vposition]
142
+ else
143
+ self.y
144
+ end
123
145
  return [x,y]
124
146
  end
125
147
 
@@ -127,10 +149,12 @@ module Prawn
127
149
  color_space = case jpg.channels
128
150
  when 1
129
151
  :DeviceGray
152
+ when 3
153
+ :DeviceRGB
130
154
  when 4
131
155
  :DeviceCMYK
132
156
  else
133
- :DeviceRGB
157
+ raise ArgumentError, 'JPG uses an unsupported number of channels'
134
158
  end
135
159
  obj = ref(:Type => :XObject,
136
160
  :Subtype => :Image,
@@ -140,6 +164,14 @@ module Prawn
140
164
  :Width => jpg.width,
141
165
  :Height => jpg.height,
142
166
  :Length => data.size )
167
+
168
+ # add extra decode params for CMYK images. By swapping the
169
+ # min and max values from the default, we invert the colours. See
170
+ # section 4.8.4 of the spec.
171
+ if color_space == :DeviceCMYK
172
+ obj.data[:Decode] = [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ]
173
+ end
174
+
143
175
  obj << data
144
176
  return obj
145
177
  end
@@ -252,7 +284,6 @@ module Prawn
252
284
  end
253
285
 
254
286
  def calc_image_dimensions(info, options)
255
- # TODO: allow the image to be aligned in a box
256
287
  w = options[:width] || info.width
257
288
  h = options[:height] || info.height
258
289
 
@@ -267,8 +298,20 @@ module Prawn
267
298
  elsif options[:scale]
268
299
  w = info.width * options[:scale]
269
300
  h = info.height * options[:scale]
301
+ elsif options[:fit]
302
+ bw, bh = options[:fit]
303
+ bp = bw / bh.to_f
304
+ ip = info.width / info.height.to_f
305
+ if ip > bp
306
+ w = bw
307
+ h = bw / ip
308
+ else
309
+ h = bh
310
+ w = bh * ip
311
+ end
270
312
  end
271
-
313
+ info.scaled_width = w
314
+ info.scaled_height = h
272
315
  [w,h]
273
316
  end
274
317
 
@@ -14,7 +14,8 @@ module Prawn
14
14
  # of a PNG image that we need to embed them in a PDF
15
15
  class JPG
16
16
  attr_reader :width, :height, :bits, :channels
17
-
17
+ attr_accessor :scaled_width, :scaled_height
18
+
18
19
  JPEG_SOF_BLOCKS = %W(\xc0 \xc1 \xc2 \xc3 \xc5 \xc6 \xc7 \xc9 \xca \xcb \xcd \xce \xcf)
19
20
  JPEG_APP_BLOCKS = %W(\xe0 \xe1 \xe2 \xe3 \xe4 \xe5 \xe6 \xe7 \xe8 \xe9 \xea \xeb \xec \xed \xee \xef)
20
21
 
@@ -19,7 +19,8 @@ module Prawn
19
19
  attr_reader :width, :height, :bits
20
20
  attr_reader :color_type, :compression_method, :filter_method
21
21
  attr_reader :interlace_method, :alpha_channel
22
-
22
+ attr_accessor :scaled_width, :scaled_height
23
+
23
24
  # Process a new PNG image
24
25
  #
25
26
  # <tt>:data</tt>:: A string containing a full PNG file
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+ module Prawn
3
+ # This is used to differentiate strings that must be encoded as
4
+ # a *literal* string, versus those that can be encoded in
5
+ # the PDF hexadecimal format.
6
+ #
7
+ # Some features of the PDF format appear to require that literal
8
+ # strings be used. One such feature is the /Dest key of a link
9
+ # annotation; if a hex encoded string is used there, the links
10
+ # do not work (as tested in Mac OS X Preview, and Adobe Acrobat
11
+ # Reader).
12
+ class LiteralString < String #:nodoc:
13
+ end
14
+ end
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+ # measurement_extensions.rb: Core extensions for Prawn::Measurements
3
+ #
4
+ # Copyright December 2008, Florian Witteler. All Rights Reserved.
5
+ #
6
+ # This is free software. Please see the LICENSE and COPYING files for details.
7
+
8
+ require 'prawn/measurements'
9
+
10
+ class Numeric
11
+ include Prawn::Measurements
12
+ # prawns' basic unit is PostScript-Point
13
+ # 72 points per inch
14
+
15
+ def mm
16
+ return mm2pt(self)
17
+ end
18
+
19
+ def cm
20
+ return cm2pt(self)
21
+ end
22
+
23
+ def dm
24
+ return dm2pt(self)
25
+ end
26
+
27
+ def m
28
+ return m2pt(self)
29
+ end
30
+
31
+ def in
32
+ return in2pt(self)
33
+ end
34
+
35
+ def yd
36
+ return yd2pt(self)
37
+ end
38
+
39
+ def ft
40
+ return ft2pt(self)
41
+ end
42
+
43
+ def pt
44
+ return self
45
+ end
46
+ end
@@ -0,0 +1,71 @@
1
+ # encoding: utf-8
2
+ # measurements.rb: Conversions from other measurements to PDF points
3
+ #
4
+ # Copyright December 2008, Florian Witteler. All Rights Reserved.
5
+ #
6
+ module Prawn
7
+ module Measurements
8
+
9
+ # ============================================================================
10
+ #metric conversions
11
+ def cm2mm(cm)
12
+ return cm*10
13
+ end
14
+
15
+ def dm2mm(dm)
16
+ return dm*100
17
+ end
18
+
19
+ def m2mm(m)
20
+ return m*1000
21
+ end
22
+
23
+ # ============================================================================
24
+ # imperial conversions
25
+ # from http://en.wikipedia.org/wiki/Imperial_units
26
+
27
+ def ft2in(ft)
28
+ return ft * 12
29
+ end
30
+
31
+ def yd2in(yd)
32
+ return yd*36
33
+ end
34
+
35
+
36
+ # ============================================================================
37
+ # PostscriptPoint-converisons
38
+
39
+ def in2pt(inch)
40
+ return inch * 72
41
+ end
42
+
43
+ def ft2pt(ft)
44
+ return in2pt(ft2in(ft))
45
+ end
46
+
47
+ def yd2pt(yd)
48
+ return in2pt(yd2in(yd))
49
+ end
50
+
51
+ def mm2pt(mm)
52
+ return mm*(72 / 25.4)
53
+ end
54
+
55
+ def cm2pt(cm)
56
+ return mm2pt(cm2mm(cm))
57
+ end
58
+
59
+ def dm2pt(dm)
60
+ return mm2pt(dm2mm(dm))
61
+ end
62
+
63
+ def m2pt(m)
64
+ return mm2pt(m2mm(m))
65
+ end
66
+
67
+ def pt2mm(pt)
68
+ return pt * 1 / mm2pt(1)# (25.4 / 72)
69
+ end
70
+ end
71
+ end