prawn-core 0.5.0.1 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. data/LICENSE +1 -1
  2. data/README +21 -6
  3. data/Rakefile +1 -1
  4. data/examples/bounding_box/bounding_boxes.rb +1 -2
  5. data/examples/bounding_box/indentation.rb +34 -0
  6. data/examples/bounding_box/russian_boxes.rb +1 -2
  7. data/examples/column_box/column_box_example.rb +1 -2
  8. data/examples/example_helper.rb +3 -0
  9. data/examples/general/background.rb +11 -8
  10. data/examples/general/canvas.rb +1 -2
  11. data/examples/general/measurement_units.rb +1 -2
  12. data/examples/general/metadata-info.rb +1 -2
  13. data/examples/general/multi_page_layout.rb +1 -2
  14. data/examples/general/page_geometry.rb +1 -2
  15. data/examples/graphics/basic_images.rb +1 -2
  16. data/examples/graphics/cmyk.rb +1 -2
  17. data/examples/graphics/curves.rb +1 -2
  18. data/examples/graphics/hexagon.rb +1 -2
  19. data/examples/graphics/image_fit.rb +1 -2
  20. data/examples/graphics/image_flow.rb +1 -2
  21. data/examples/graphics/image_position.rb +1 -2
  22. data/examples/graphics/line.rb +1 -2
  23. data/examples/graphics/png_types.rb +1 -2
  24. data/examples/graphics/polygons.rb +1 -2
  25. data/examples/graphics/remote_images.rb +2 -2
  26. data/examples/graphics/ruport_style_helpers.rb +1 -2
  27. data/examples/graphics/stroke_bounds.rb +1 -2
  28. data/examples/m17n/chinese_text_wrapping.rb +5 -6
  29. data/examples/m17n/euro.rb +1 -2
  30. data/examples/m17n/sjis.rb +1 -2
  31. data/examples/m17n/utf8.rb +1 -2
  32. data/examples/m17n/win_ansi_charset.rb +1 -2
  33. data/examples/text/alignment.rb +1 -2
  34. data/examples/text/dfont.rb +1 -2
  35. data/examples/text/family_based_styling.rb +1 -2
  36. data/examples/text/font_calculations.rb +1 -2
  37. data/examples/text/font_size.rb +1 -2
  38. data/examples/text/kerning.rb +1 -2
  39. data/examples/text/simple_text.rb +1 -2
  40. data/examples/text/simple_text_ttf.rb +1 -2
  41. data/examples/text/span.rb +1 -2
  42. data/examples/text/text_box.rb +3 -4
  43. data/examples/text/text_flow.rb +2 -3
  44. data/lib/prawn/core.rb +12 -5
  45. data/lib/prawn/document/annotations.rb +15 -14
  46. data/lib/prawn/document/bounding_box.rb +36 -28
  47. data/lib/prawn/document/column_box.rb +15 -0
  48. data/lib/prawn/document/destinations.rb +10 -0
  49. data/lib/prawn/document/internals.rb +4 -0
  50. data/lib/prawn/document/page_geometry.rb +7 -3
  51. data/lib/prawn/document/text.rb +6 -15
  52. data/lib/prawn/document.rb +21 -2
  53. data/lib/prawn/errors.rb +2 -2
  54. data/lib/prawn/font/dfont.rb +3 -0
  55. data/lib/prawn/font/ttf.rb +2 -0
  56. data/lib/prawn/font.rb +2 -0
  57. data/lib/prawn/graphics.rb +0 -1
  58. data/lib/prawn/images/jpg.rb +2 -1
  59. data/lib/prawn/images/png.rb +2 -0
  60. data/spec/bounding_box_spec.rb +35 -0
  61. data/spec/font_spec.rb +1 -2
  62. metadata +4 -2
@@ -11,16 +11,14 @@ require 'prawn/literal_string'
11
11
  module Prawn
12
12
  class Document
13
13
 
14
- # Provides very low-level support for annotations. Those who are
15
- # interested should check out the text-format branch of sandal/prawn,
16
- # which includes much higher level interfaces to this code currently
17
- # being developed by Jamis Buck to be included in a Prawn release soon.
18
- #
19
- # Feedback is welcome!
20
- #
14
+ # Provides very low-level support for annotations. These extensions are
15
+ # mainly for use by prawn-format, so be sure to check that out if all
16
+ # you need is basic internal or external links.
21
17
  module Annotations
18
+
22
19
  # Adds a new annotation (section 8.4 in PDF spec) to the current page.
23
20
  # +options+ must be a Hash describing the annotation.
21
+ #
24
22
  def annotate(options)
25
23
  @current_page.data[:Annots] ||= []
26
24
  options = sanitize_annotation_hash(options)
@@ -31,6 +29,7 @@ module Prawn
31
29
  # A convenience method for creating Text annotations. +rect+ must be an array
32
30
  # of four numbers, describing the bounds of the annotation. +contents+ should
33
31
  # be a string, to be shown when the annotation is activated.
32
+ #
34
33
  def text_annotation(rect, contents, options={})
35
34
  options = options.merge(:Subtype => :Text, :Rect => rect, :Contents => contents)
36
35
  annotate(options)
@@ -42,6 +41,7 @@ module Prawn
42
41
  # string that has been recorded in the document's Dests tree), or :A (describing
43
42
  # an action to perform on clicking the link), or :PA (for describing a URL to
44
43
  # link to).
44
+ #
45
45
  def link_annotation(rect, options={})
46
46
  options = options.merge(:Subtype => :Link, :Rect => rect)
47
47
  annotate(options)
@@ -49,15 +49,16 @@ module Prawn
49
49
 
50
50
  private
51
51
 
52
- def sanitize_annotation_hash(options)
53
- options = options.merge(:Type => :Annot)
52
+ def sanitize_annotation_hash(options)
53
+ options = options.merge(:Type => :Annot)
54
54
 
55
- if options[:Dest].is_a?(String)
56
- options[:Dest] = Prawn::LiteralString.new(options[:Dest])
57
- end
58
-
59
- options
55
+ if options[:Dest].is_a?(String)
56
+ options[:Dest] = Prawn::LiteralString.new(options[:Dest])
60
57
  end
58
+
59
+ options
60
+ end
61
+
61
62
  end
62
63
  end
63
64
  end
@@ -14,8 +14,7 @@ module Prawn
14
14
  #
15
15
  # A bounding box serves two important purposes:
16
16
  # * Provide bounds for flowing text, starting at a given point
17
- # * Translate the origin (0,0) for graphics primitives, for the purposes
18
- # of simplifying coordinate math.
17
+ # * Translate the origin (0,0) for graphics primitives
19
18
  #
20
19
  # ==Positioning
21
20
  #
@@ -25,20 +24,20 @@ module Prawn
25
24
  #
26
25
  # Usage:
27
26
  #
28
- # * Bounding box 100pt x 100pt in the absolutle bottom left of the containing
29
- # box:
27
+ # * Bounding box 100pt x 100pt in the absolute bottom left of the
28
+ # containing box:
30
29
  #
31
- # pdf.bounding_box([0,100], :width => 100, :height => 100)
32
- # stroke_bounds
33
- # end
30
+ # pdf.bounding_box([0,100], :width => 100, :height => 100)
31
+ # stroke_bounds
32
+ # end
34
33
  #
35
34
  # * Bounding box 200pt x 400pt high in the center of the page:
36
35
  #
37
- # x_pos = ((bounds.width / 2) - 150)
38
- # y_pos = ((bounds.height / 2) + 200)
39
- # pdf.bounding_box([x_pos, y_pos], :width => 300, :height => 400) do
40
- # stroke_bounds
41
- # end
36
+ # x_pos = ((bounds.width / 2) - 150)
37
+ # y_pos = ((bounds.height / 2) + 200)
38
+ # pdf.bounding_box([x_pos, y_pos], :width => 300, :height => 400) do
39
+ # stroke_bounds
40
+ # end
42
41
  #
43
42
  # ==Flowing Text
44
43
  #
@@ -57,6 +56,10 @@ module Prawn
57
56
  # "and return to the margin_box"
58
57
  # end
59
58
  #
59
+ # Note that this is a low level tool and is designed primarily for
60
+ # building other abstractions. If you just want to flow some text on
61
+ # a page, look into span() or text_box()
62
+ #
60
63
  # ==Translating Coordinates
61
64
  #
62
65
  # When translating coordinates, the idea is to allow the user to draw
@@ -101,7 +104,7 @@ module Prawn
101
104
  #
102
105
  # ==Nesting Bounding Boxes
103
106
  #
104
- # By default, bounding boxes are specified relative to the document's
107
+ # At the top level, bounding boxes are specified relative to the document's
105
108
  # margin_box (which is itself a bounding box). You can also nest bounding
106
109
  # boxes, allowing you to build components which are relative to each other
107
110
  #
@@ -118,8 +121,8 @@ module Prawn
118
121
  #
119
122
  # ==Stretchyness
120
123
  #
121
- # If you do not specify a height to a boundng box, it will become stretchy
122
- # and it's height will be calculated according to the last drawing position
124
+ # If you do not specify a height to a bounding box, it will become stretchy
125
+ # and its height will be calculated according to the last drawing position
123
126
  # within the bounding box:
124
127
  #
125
128
  # pdf.bounding_box([100,400], :width => 400) do
@@ -184,7 +187,12 @@ module Prawn
184
187
 
185
188
  @bounding_box = parent_box
186
189
  end
187
-
190
+
191
+ # Low level layout helper that simplifies coordinate math.
192
+ #
193
+ # See Prawn::Document#bounding_box for a description of what this class
194
+ # is used for.
195
+ #
188
196
  class BoundingBox
189
197
 
190
198
  def initialize(parent, point, options={}) #:nodoc:
@@ -210,6 +218,18 @@ module Prawn
210
218
  0
211
219
  end
212
220
 
221
+
222
+ # Temporarily adjust the @x coordinate to allow for left_padding
223
+ #
224
+ def indent(left_padding, &block)
225
+ @x += left_padding
226
+ @width -= left_padding
227
+ yield
228
+ ensure
229
+ @x -= left_padding
230
+ @width += left_padding
231
+ end
232
+
213
233
  # Relative right x-coordinate of the bounding box. (Equal to the box width)
214
234
  #
215
235
  # Example, position some text 3 pts from the right of the containing box:
@@ -359,18 +379,6 @@ module Prawn
359
379
  !@height
360
380
  end
361
381
 
362
- def left_side
363
- absolute_left
364
- end
365
-
366
- def right_side
367
- absolute_right
368
- end
369
-
370
- def move_past_bottom
371
- @parent.start_new_page
372
- end
373
-
374
382
  end
375
383
 
376
384
  end
@@ -40,6 +40,21 @@ module Prawn
40
40
 
41
41
  @bounding_box = parent_box
42
42
  end
43
+
44
+ # Template methods to support ColumnBox extensions
45
+ class BoundingBox
46
+ def left_side
47
+ absolute_left
48
+ end
49
+
50
+ def right_side
51
+ absolute_right
52
+ end
53
+
54
+ def move_past_bottom
55
+ @parent.start_new_page
56
+ end
57
+ end
43
58
 
44
59
  class ColumnBox < BoundingBox
45
60
 
@@ -17,6 +17,7 @@ module Prawn
17
17
  # The Dests name tree in the Name dictionary (see Prawn::Document::Internal#names).
18
18
  # This name tree is used to store named destinations (PDF spec 8.2.1).
19
19
  # (For more on name trees, see section 3.8.4 in the PDF spec.)
20
+ #
20
21
  def dests
21
22
  names.data[:Dests] ||= ref(Prawn::NameTree::Node.new(self, NAME_TREE_CHILDREN_LIMIT))
22
23
  end
@@ -24,6 +25,7 @@ module Prawn
24
25
  # Adds a new destination to the dests name tree (see #dests). The
25
26
  # +reference+ parameter will be converted into a Prawn::Reference if
26
27
  # it is not already one.
28
+ #
27
29
  def add_dest(name, reference)
28
30
  reference = ref(reference) unless reference.is_a?(Prawn::Reference)
29
31
  dests.data.add(name, reference)
@@ -31,48 +33,56 @@ module Prawn
31
33
 
32
34
  # Return a Dest specification for a specific location (and optional zoom
33
35
  # level).
36
+ #
34
37
  def dest_xyz(left, top, zoom=nil, page=@current_page)
35
38
  [page, :XYZ, left, top, zoom]
36
39
  end
37
40
 
38
41
  # Return a Dest specification that will fit the given page into the
39
42
  # viewport.
43
+ #
40
44
  def dest_fit(page=@current_page)
41
45
  [page, :Fit]
42
46
  end
43
47
 
44
48
  # Return a Dest specification that will fit the given page horizontally
45
49
  # into the viewport, aligned vertically at the given top coordinate.
50
+ #
46
51
  def dest_fit_horizontally(top, page=@current_page)
47
52
  [page, :FitH, top]
48
53
  end
49
54
 
50
55
  # Return a Dest specification that will fit the given page vertically
51
56
  # into the viewport, aligned horizontally at the given left coordinate.
57
+ #
52
58
  def dest_fit_vertically(left, page=@current_page)
53
59
  [page, :FitV, left]
54
60
  end
55
61
 
56
62
  # Return a Dest specification that will fit the given rectangle into the
57
63
  # viewport, for the given page.
64
+ #
58
65
  def dest_fit_rect(left, bottom, right, top, page=@current_page)
59
66
  [page, :FitR, left, bottom, right, top]
60
67
  end
61
68
 
62
69
  # Return a Dest specfication that will fit the given page's bounding box
63
70
  # into the viewport.
71
+ #
64
72
  def dest_fit_bounds(page=@current_page)
65
73
  [page, :FitB]
66
74
  end
67
75
 
68
76
  # Same as #dest_fit_horizontally, but works on the page's bounding box
69
77
  # instead of the entire page.
78
+ #
70
79
  def dest_fit_bounds_horizontally(top, page=@current_page)
71
80
  [page, :FitBH, top]
72
81
  end
73
82
 
74
83
  # Same as #dest_fit_vertically, but works on the page's bounding box
75
84
  # instead of the entire page.
85
+ #
76
86
  def dest_fit_bounds_vertically(left, page=@current_page)
77
87
  [page, :FitBV, left]
78
88
  end
@@ -15,6 +15,7 @@ module Prawn
15
15
  # are you won't need anything you find here.
16
16
  #
17
17
  module Internals
18
+
18
19
  # Creates a new Prawn::Reference and adds it to the Document's object
19
20
  # list. The +data+ argument is anything that Prawn::PdfObject() can convert.
20
21
  #
@@ -22,6 +23,7 @@ module Prawn
22
23
  # out to the PDF document stream. This allows you to do deferred processing
23
24
  # on some references (such as fonts, which you might know all the details
24
25
  # about until the last page of the document is finished).
26
+ #
25
27
  def ref(data, &block)
26
28
  @objects.push(Prawn::Reference.new(@objects.size + 1, data, &block)).last
27
29
  end
@@ -58,6 +60,7 @@ module Prawn
58
60
  end
59
61
 
60
62
  # The XObject dictionary for the current page
63
+ #
61
64
  def page_xobjects
62
65
  page_resources[:XObject] ||= {}
63
66
  end
@@ -65,6 +68,7 @@ module Prawn
65
68
  # The Name dictionary (PDF spec 3.6.3) for this document. It is
66
69
  # lazily initialized, so that documents that do not need a name
67
70
  # dictionary do not incur the additional overhead.
71
+ #
68
72
  def names
69
73
  @root.data[:Names] ||= ref(:Type => :Names)
70
74
  end
@@ -77,8 +77,7 @@ module Prawn
77
77
  # LEGAL:: => 612.00 x 1008.00
78
78
  # LETTER:: => 612.00 x 792.00
79
79
  # TABLOID:: => 792.00 x 1224.00
80
-
81
-
80
+ #
82
81
  module PageGeometry
83
82
 
84
83
  SIZES = { "4A0" => [4767.87, 6740.79],
@@ -132,7 +131,12 @@ module Prawn
132
131
  "LETTER" => [612.00, 792.00],
133
132
  "TABLOID" => [792.00, 1224.00] }
134
133
 
135
- def page_dimensions #:nodoc:
134
+
135
+ # Returns the width and height of the current page in PDF points.
136
+ # Usually, you'll want the dimensions of the bounding_box or
137
+ # margin_box instead.
138
+ #
139
+ def page_dimensions
136
140
  coords = SIZES[page_size] || page_size
137
141
  [0,0] + case(page_layout)
138
142
  when :portrait
@@ -52,7 +52,7 @@ module Prawn
52
52
  # == Rotation
53
53
  #
54
54
  # Text can be rotated before it is placed on the canvas by specifying the
55
- # :rotate option. Rotation occurs counter-clockwise.
55
+ # +:rotate+ option with a given angle. Rotation occurs counter-clockwise.
56
56
  #
57
57
  # == Encoding
58
58
  #
@@ -73,7 +73,7 @@ module Prawn
73
73
  text = text.to_s.dup
74
74
 
75
75
  save_font do
76
- options = text_options.merge(options)
76
+ options = @text_options.merge(options)
77
77
  process_text_options(options)
78
78
 
79
79
  font.normalize_encoding!(text) unless @skip_encoding
@@ -89,21 +89,12 @@ module Prawn
89
89
  end
90
90
  end
91
91
  end
92
-
93
- # A hash of configuration options, to be used globally by text().
94
- #
95
- # pdf.text_options.update(:size => 16, :align => :right)
96
- # pdf.text "Hello World" #=> Size 16 w. right alignment
97
- #
98
- def text_options
99
- @text_options ||= {}
100
- end
101
-
92
+
102
93
  private
103
-
94
+
104
95
  def process_text_options(options)
105
96
  Prawn.verify_options [:style, :kerning, :size, :at, :wrap,
106
- :spacing, :align, :rotate, :final_gap ], options
97
+ :leading, :align, :rotate, :final_gap ], options
107
98
 
108
99
  if options[:style]
109
100
  raise "Bad font family" unless font.family
@@ -154,7 +145,7 @@ module Prawn
154
145
 
155
146
  if i < last_gap_before
156
147
  move_text_position(font.line_gap - font.descender)
157
- move_text_position(options[:spacing]) if options[:spacing]
148
+ move_text_position(options[:leading]) if options[:leading]
158
149
  end
159
150
  end
160
151
  end
@@ -17,6 +17,7 @@ require "prawn/document/annotations"
17
17
  require "prawn/document/destinations"
18
18
 
19
19
  module Prawn
20
+
20
21
  # The Prawn::Document class is how you start creating a PDF document.
21
22
  #
22
23
  # There are three basic ways you can instantiate PDF Documents in Prawn, they
@@ -49,6 +50,7 @@ module Prawn
49
50
  # that you want to immediately save or render out.
50
51
  #
51
52
  # See the new and generate methods for further details on the above.
53
+ #
52
54
  class Document
53
55
 
54
56
  include Text
@@ -108,6 +110,7 @@ module Prawn
108
110
  # <tt>:compress</tt>:: Compresses content streams before rendering them [false]
109
111
  # <tt>:background</tt>:: An image path to be used as background on all pages [nil]
110
112
  # <tt>:info</tt>:: Generic hash allowing for custom metadata properties [nil]
113
+ # <tt>:text_options</tt>:: A set of default options to be handed to text(). Be careful with this.
111
114
 
112
115
  # Additionally, :page_size can be specified as a simple two value array giving
113
116
  # the width and height of the document you need in PDF Points.
@@ -153,7 +156,7 @@ module Prawn
153
156
  @background = options[:background]
154
157
  @font_size = 12
155
158
 
156
- text_options.update(options[:text_options] || {})
159
+ @text_options = options[:text_options] || {}
157
160
 
158
161
  @margins = { :left => options[:left_margin] || 36,
159
162
  :right => options[:right_margin] || 36,
@@ -347,6 +350,21 @@ module Prawn
347
350
  yield
348
351
  move_down(y)
349
352
  end
353
+
354
+
355
+ # Indents the specified number of PDF points for the duration of the block
356
+ #
357
+ # pdf.text "some text"
358
+ # pdf.indent(20) do
359
+ # pdf.text "This is indented 20 points"
360
+ # end
361
+ # pdf.text "This starts 20 points left of the above line " +
362
+ # "and is flush with the first line"
363
+ #
364
+ def indent(x, &block)
365
+ bounds.indent(x, &block)
366
+ end
367
+
350
368
 
351
369
  def mask(*fields) # :nodoc:
352
370
  # Stores the current state of the named attributes, executes the block, and
@@ -389,7 +407,8 @@ module Prawn
389
407
  :height => page_dimensions[-1] - (@margins[:top] + @margins[:bottom])
390
408
  )
391
409
 
392
- # update bounding box if not flowing from the previous page
410
+ # we must update bounding box if not flowing from the previous page
411
+ #
393
412
  # FIXME: This may have a bug where the old margin is restored
394
413
  # when the bounding box exits.
395
414
  @bounding_box = @margin_box if old_margin_box == @bounding_box
data/lib/prawn/errors.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  # encoding: utf-8
2
-
2
+ #
3
3
  # errors.rb : Implements custom error classes for Prawn
4
4
  #
5
5
  # Copyright April 2008, Gregory Brown. All Rights Reserved.
6
6
  #
7
7
  # This is free software. Please see the LICENSE and COPYING files for details.
8
-
8
+ #
9
9
  module Prawn
10
10
  module Errors
11
11
 
@@ -3,11 +3,13 @@ require 'prawn/font/ttf'
3
3
  module Prawn
4
4
  class Font
5
5
  class DFont < TTF
6
+
6
7
  # Returns a list of the names of all named fonts in the given dfont file.
7
8
  # Note that fonts are not required to be named in a dfont file, so the
8
9
  # list may be empty even if the file does contain fonts. Also, note that
9
10
  # the list is returned in no particular order, so the first font in the
10
11
  # list is not necessarily the font at index 0 in the file.
12
+ #
11
13
  def self.named_fonts(file)
12
14
  TTFunk::ResourceFile.open(file) do |file|
13
15
  return file.resources_for("sfnt")
@@ -15,6 +17,7 @@ module Prawn
15
17
  end
16
18
 
17
19
  # Returns the number of fonts contained in the dfont file.
20
+ #
18
21
  def self.font_count(file)
19
22
  TTFunk::ResourceFile.open(file) do |file|
20
23
  return file.map["sfnt"][:list].length
@@ -23,6 +23,7 @@ module Prawn
23
23
  end
24
24
 
25
25
  # +string+ must be UTF8-encoded.
26
+ #
26
27
  def compute_width_of(string, options={})
27
28
  scale = (options[:size] || size) / 1000.0
28
29
  if options[:kerning]
@@ -55,6 +56,7 @@ module Prawn
55
56
  # either a string or an array (for kerned text).
56
57
  #
57
58
  # The +text+ parameter must be UTF8-encoded.
59
+ #
58
60
  def encode_text(text,options={})
59
61
  text = text.chomp
60
62
 
data/lib/prawn/font.rb CHANGED
@@ -78,6 +78,7 @@ module Prawn
78
78
 
79
79
  # Sets the font directly, given an actual Font object
80
80
  # and size.
81
+ #
81
82
  def set_font(font, size=nil) # :nodoc:
82
83
  @font = font
83
84
  @font_size = size if size
@@ -85,6 +86,7 @@ module Prawn
85
86
 
86
87
  # Saves the current font, and then yields. When the block
87
88
  # finishes, the original font is restored.
89
+ #
88
90
  def save_font
89
91
  @font ||= find_font("Helvetica")
90
92
  original_font = @font
@@ -6,7 +6,6 @@
6
6
  #
7
7
  # This is free software. Please see the LICENSE and COPYING files for details.
8
8
 
9
- require "enumerator"
10
9
  require "prawn/graphics/color"
11
10
 
12
11
  module Prawn
@@ -11,7 +11,8 @@ require 'stringio'
11
11
  module Prawn
12
12
  module Images
13
13
  # A convenience class that wraps the logic for extracting the parts
14
- # of a PNG image that we need to embed them in a PDF
14
+ # of a JPG image that we need to embed them in a PDF
15
+ #
15
16
  class JPG
16
17
  attr_reader :width, :height, :bits, :channels
17
18
  attr_accessor :scaled_width, :scaled_height
@@ -9,11 +9,13 @@
9
9
  # This is free software. Please see the LICENSE and COPYING files for details.
10
10
 
11
11
  require 'stringio'
12
+ require 'enumerator'
12
13
 
13
14
  module Prawn
14
15
  module Images
15
16
  # A convenience class that wraps the logic for extracting the parts
16
17
  # of a PNG image that we need to embed them in a PDF
18
+ #
17
19
  class PNG
18
20
  attr_reader :palette, :img_data, :transparency
19
21
  attr_reader :width, :height, :bits
@@ -128,6 +128,41 @@ describe "drawing bounding boxes" do
128
128
 
129
129
  end
130
130
 
131
+ describe "Indentation" do
132
+ before(:each) { create_pdf }
133
+
134
+ it "should temporarily shift the x coordinate and width" do
135
+ @pdf.bounding_box([100,100], :width => 200) do
136
+ @pdf.indent(20) do
137
+ @pdf.bounds.absolute_left.should == 120
138
+ @pdf.bounds.width.should == 180
139
+ end
140
+ end
141
+ end
142
+
143
+ it "should restore the x coordinate and width after block exits" do
144
+ @pdf.bounding_box([100,100], :width => 200) do
145
+ @pdf.indent(20) do
146
+ # no-op
147
+ end
148
+ @pdf.bounds.absolute_left.should == 100
149
+ @pdf.bounds.width.should == 200
150
+ end
151
+ end
152
+
153
+ it "should restore the x coordinate and width on error" do
154
+ @pdf.bounding_box([100,100], :width => 200) do
155
+ begin
156
+ @pdf.indent(20) { raise }
157
+ rescue
158
+ @pdf.bounds.absolute_left.should == 100
159
+ @pdf.bounds.width.should == 200
160
+ end
161
+ end
162
+ end
163
+
164
+ end
165
+
131
166
  describe "A canvas" do
132
167
  before(:each) { create_pdf }
133
168
 
data/spec/font_spec.rb CHANGED
@@ -57,8 +57,7 @@ describe "font style support" do
57
57
  @pdf.text "In ActionMan-Italic"
58
58
 
59
59
  text = PDF::Inspector::Text.analyze(@pdf.render)
60
- name = text.font_settings.map { |e| e[:name] }.first
61
- name = name.unpack("n*")[2..-1].pack("U*")
60
+ name = text.font_settings.map { |e| e[:name] }.first.to_s
62
61
  name = name.sub(/\w+\+/, "subset+")
63
62
  name.should == "subset+ActionMan-Italic"
64
63
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.1
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory Brown
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-15 00:00:00 -04:00
12
+ date: 2009-09-22 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -25,8 +25,10 @@ extra_rdoc_files:
25
25
  - COPYING
26
26
  files:
27
27
  - examples/bounding_box/bounding_boxes.rb
28
+ - examples/bounding_box/indentation.rb
28
29
  - examples/bounding_box/russian_boxes.rb
29
30
  - examples/column_box/column_box_example.rb
31
+ - examples/example_helper.rb
30
32
  - examples/general/background.rb
31
33
  - examples/general/canvas.rb
32
34
  - examples/general/measurement_units.rb