prawn 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rake/testtask'
4
4
  require "rake/rdoctask"
5
5
  require "rake/gempackagetask"
6
6
 
7
- PRAWN_VERSION = "0.2.1"
7
+ PRAWN_VERSION = "0.2.2"
8
8
 
9
9
  task :default => [:test]
10
10
 
@@ -0,0 +1,7 @@
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require "prawn"
3
+ require "open-uri"
4
+
5
+ Prawn::Document.generate("remote_images.pdf") do
6
+ image open("http://prawn.majesticseacreature.com/media/prawn_logo.png")
7
+ end
@@ -20,7 +20,7 @@ module Prawn
20
20
  # The base source directory for Prawn as installed on the system
21
21
  BASEDIR = File.expand_path(File.join(dir, '..'))
22
22
 
23
- VERSION = "0.2.1"
23
+ VERSION = "0.2.2"
24
24
 
25
25
  extend self
26
26
 
@@ -1,5 +1,21 @@
1
1
  module Prawn
2
2
  class Document
3
+ # A span is a special purpose bounding box that allows a column of
4
+ # elements to be positioned relative to the margin_box.
5
+ #
6
+ # Arguments:
7
+ # +width+:: The width of the column in PDF points
8
+ #
9
+ # Options:
10
+ # <tt>:position</tt>:: One of :left, :center, :right or an x offset
11
+ #
12
+ # This method is typically used for flowing a column of text from one
13
+ # page to the next.
14
+ #
15
+ # span(350, :position => :center) do
16
+ # text "Here's some centered text in a 350 point column. " * 100
17
+ # end
18
+ #
3
19
  def span(width, options={})
4
20
  Prawn.verify_options [:position], options
5
21
  original_position = self.y
@@ -15,14 +15,14 @@ module Prawn
15
15
  # JPG and PNG files are supported.
16
16
  #
17
17
  # Arguments:
18
- # <tt>filename</tt>:: the path to the file to be embedded
18
+ # <tt>file</tt>:: path to file or an object that responds to #read
19
19
  #
20
20
  # Options:
21
21
  # <tt>:at</tt>:: 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
23
  # <tt>:height</tt>:: the height of the image [actual height of the image]
24
24
  # <tt>:width</tt>:: the width of the image [actual width of the image]
25
- # <tt>:scale</tt>:: scale the dimensions of the image proportionally
25
+ # <tt>:scale</tt>:: scale the dimensions of the image proportionally
26
26
  #
27
27
  # Prawn::Document.generate("image2.pdf", :page_layout => :landscape) do
28
28
  # pigs = "#{Prawn::BASEDIR}/data/images/pigs.jpg"
@@ -36,10 +36,24 @@ module Prawn
36
36
  # proportionally. When both are provided, the image will be stretched to
37
37
  # fit the dimensions without maintaining the aspect ratio.
38
38
  #
39
+ # If instead of an explicit filename, an object with a read method is
40
+ # passed as +file+, you can embed images from IO objects and things
41
+ # that act like them (including Tempfiles and open-uri objects).
42
+ #
43
+ # require "open-uri"
44
+ #
45
+ # Prawn::Document.generate("remote_images.pdf") do
46
+ # image open("http://prawn.majesticseacreature.com/media/prawn_logo.png")
47
+ # end
48
+ #
49
+ # This method returns an image info object which can be used to check the
50
+ # dimensions of an image object if needed.
51
+ # (See also: Prawn::Images::PNG , Prawn::Images::JPG)
52
+ #
39
53
  def image(file, options={})
40
54
  Prawn.verify_options [:at,:position, :height, :width, :scale], options
41
55
 
42
- if file.kind_of?(IO)
56
+ if file.respond_to?(:read)
43
57
  image_content = file.read
44
58
  else
45
59
  raise ArgumentError, "#{file} not found" unless File.file?(file)
@@ -12,7 +12,7 @@ module Prawn
12
12
  module Images
13
13
  # A convenience class that wraps the logic for extracting the parts
14
14
  # of a PNG image that we need to embed them in a PDF
15
- class JPG #:nodoc:
15
+ class JPG
16
16
  attr_reader :width, :height, :bits, :channels
17
17
 
18
18
  JPEG_SOF_BLOCKS = %W(\xc0 \xc1 \xc2 \xc3 \xc5 \xc6 \xc7 \xc9 \xca \xcb \xcd \xce \xcf)
@@ -21,6 +21,7 @@ module Prawn
21
21
  # Process a new JPG image
22
22
  #
23
23
  # <tt>:data</tt>:: A string containing a full PNG file
24
+ #
24
25
  def initialize(data)
25
26
  data = StringIO.new(data.dup)
26
27
 
@@ -14,7 +14,7 @@ module Prawn
14
14
  module Images
15
15
  # A convenience class that wraps the logic for extracting the parts
16
16
  # of a PNG image that we need to embed them in a PDF
17
- class PNG #:nodoc:
17
+ class PNG
18
18
  attr_reader :palette, :img_data, :transparency
19
19
  attr_reader :width, :height, :bits
20
20
  attr_reader :color_type, :compression_method, :filter_method
@@ -23,6 +23,7 @@ module Prawn
23
23
  # Process a new PNG image
24
24
  #
25
25
  # <tt>:data</tt>:: A string containing a full PNG file
26
+ #
26
27
  def initialize(data)
27
28
  data = StringIO.new(data.dup)
28
29
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory Brown
@@ -47,6 +47,7 @@ files:
47
47
  - examples/page_geometry.rb
48
48
  - examples/png_types.rb
49
49
  - examples/polygons.rb
50
+ - examples/remote_images.rb
50
51
  - examples/ruport_formatter.rb
51
52
  - examples/ruport_helpers.rb
52
53
  - examples/russian_boxes.rb