prawn 0.2.1 → 0.2.2
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.
- data/Rakefile +1 -1
- data/examples/remote_images.rb +7 -0
- data/lib/prawn.rb +1 -1
- data/lib/prawn/document/span.rb +16 -0
- data/lib/prawn/images.rb +17 -3
- data/lib/prawn/images/jpg.rb +2 -1
- data/lib/prawn/images/png.rb +2 -1
- metadata +2 -1
data/Rakefile
CHANGED
data/lib/prawn.rb
CHANGED
data/lib/prawn/document/span.rb
CHANGED
@@ -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
|
data/lib/prawn/images.rb
CHANGED
@@ -15,14 +15,14 @@ module Prawn
|
|
15
15
|
# JPG and PNG files are supported.
|
16
16
|
#
|
17
17
|
# Arguments:
|
18
|
-
# <tt>
|
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.
|
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)
|
data/lib/prawn/images/jpg.rb
CHANGED
@@ -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
|
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
|
|
data/lib/prawn/images/png.rb
CHANGED
@@ -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
|
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.
|
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
|