pdf-wrapper 0.3.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +9 -0
- data/Rakefile +1 -1
- data/lib/pdf/wrapper/images.rb +28 -18
- data/lib/pdf/wrapper/text_image_cell.rb +1 -1
- metadata +5 -5
data/CHANGELOG
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
v0.4.0 (11th October 2010)
|
2
|
+
* Extra flexibility in positioning of images
|
3
|
+
* replace :center option to image() method with :position and :vposition
|
4
|
+
* API INCOMPATIBLE CHANGE. Forces a bump of minor version number
|
5
|
+
|
6
|
+
v0.3.5 (29th September 2010)
|
7
|
+
* Switch to using rubygems to satisfy gnome2 dependencies
|
8
|
+
- no more need to install mystery dependencies via other means
|
9
|
+
|
1
10
|
v0.3.4 (13th September 2010)
|
2
11
|
- remove check of cairo bindings version
|
3
12
|
- the dependency is already forced by rubygems
|
data/Rakefile
CHANGED
data/lib/pdf/wrapper/images.rb
CHANGED
@@ -12,7 +12,8 @@ module PDF
|
|
12
12
|
# <tt>:width</tt>:: The width of the image
|
13
13
|
# <tt>:proportional</tt>:: Boolean. Maintain image proportions when scaling. Defaults to false.
|
14
14
|
# <tt>:padding</tt>:: Add some padding between the image and the specified box.
|
15
|
-
# <tt>:
|
15
|
+
# <tt>:position</tt>:: (:left, :center, :right) If the image size is scaled down, sets the horizontal position.
|
16
|
+
# <tt>:vposition</tt>:: (:top, :middle, :bottom) If the image size is scaled down, sets the vertical position.
|
16
17
|
# <tt>:rotate</tt>:: The desired rotation. One of :counterclockwise, :upsidedown, :clockwise.
|
17
18
|
# Doesn't work with PNG, PDF or SVG files.
|
18
19
|
#
|
@@ -22,7 +23,7 @@ module PDF
|
|
22
23
|
def image(filename, opts = {})
|
23
24
|
# TODO: add some options for justification and padding
|
24
25
|
raise ArgumentError, "file #{filename} not found" unless File.file?(filename)
|
25
|
-
opts.assert_valid_keys(default_positioning_options.keys + [:padding, :proportional, :
|
26
|
+
opts.assert_valid_keys(default_positioning_options.keys + [:padding, :proportional, :position, :vposition, :rotate])
|
26
27
|
|
27
28
|
if opts[:padding]
|
28
29
|
opts[:left] += opts[:padding].to_i if opts[:left]
|
@@ -68,25 +69,34 @@ module PDF
|
|
68
69
|
# arguments:
|
69
70
|
# <tt>x</tt>:: The current x co-ord of the image
|
70
71
|
# <tt>y</tt>:: The current x co-ord of the image
|
71
|
-
# <tt>
|
72
|
-
# <tt>
|
73
|
-
# <tt>
|
74
|
-
# <tt>
|
75
|
-
# <tt>
|
76
|
-
|
72
|
+
# <tt>boxw</tt>:: The image width requested by the user
|
73
|
+
# <tt>boxh</tt>:: The image height requested by the user
|
74
|
+
# <tt>imgw</tt>:: The width of the image we're going to draw
|
75
|
+
# <tt>imgh</tt>:: The height of the image we're going to draw
|
76
|
+
# <tt>position</tt>:: [:left, :center, :right]
|
77
|
+
# <tt>vposition</tt>:: [:top, :middle, :bottom]
|
78
|
+
def calc_image_coords(x, y, boxw, boxh, imgw, imgh, position = :left, vposition = :top)
|
77
79
|
|
78
80
|
# if the width of the image is less than the requested box, calculate
|
79
81
|
# the white space buffer
|
80
|
-
if
|
81
|
-
white_space =
|
82
|
-
|
82
|
+
if imgw < boxw
|
83
|
+
white_space = boxw - imgw
|
84
|
+
if position == :center
|
85
|
+
x = x + (white_space / 2)
|
86
|
+
elsif position == :right
|
87
|
+
x = x + white_space
|
88
|
+
end
|
83
89
|
end
|
84
90
|
|
85
91
|
# if the height of the image is less than the requested box, calculate
|
86
92
|
# the white space buffer
|
87
|
-
if
|
88
|
-
white_space =
|
89
|
-
|
93
|
+
if imgh < boxh
|
94
|
+
white_space = boxh - imgh
|
95
|
+
if vposition == :middle
|
96
|
+
y = y + (white_space / 2)
|
97
|
+
elsif vposition == :bottom
|
98
|
+
y = y + white_space
|
99
|
+
end
|
90
100
|
end
|
91
101
|
|
92
102
|
return x, y
|
@@ -120,7 +130,7 @@ module PDF
|
|
120
130
|
page = Poppler::Document.new(filename).get_page(0)
|
121
131
|
w, h = page.size
|
122
132
|
width, height = calc_image_dimensions(opts[:width], opts[:height], w, h, opts[:proportional])
|
123
|
-
x, y = calc_image_coords(opts[:left] || x, opts[:top] || y, opts[:width] || w, opts[:height] || h, width, height, opts[:
|
133
|
+
x, y = calc_image_coords(opts[:left] || x, opts[:top] || y, opts[:width] || w, opts[:height] || h, width, height, opts[:position], opts[:vposition])
|
124
134
|
@context.save do
|
125
135
|
@context.translate(x, y)
|
126
136
|
@context.scale(width / w, height / h)
|
@@ -138,7 +148,7 @@ module PDF
|
|
138
148
|
pixbuf = pixbuf.rotate( rotation_constant( opts[:rotate] ) )
|
139
149
|
end
|
140
150
|
width, height = calc_image_dimensions(opts[:width], opts[:height], pixbuf.width, pixbuf.height, opts[:proportional])
|
141
|
-
x, y = calc_image_coords(opts[:left] || x, opts[:top] || y, opts[:width] || pixbuf.width, opts[:height] || pixbuf.height, width, height,
|
151
|
+
x, y = calc_image_coords(opts[:left] || x, opts[:top] || y, opts[:width] || pixbuf.width, opts[:height] || pixbuf.height, width, height, opts[:position], opts[:vposition])
|
142
152
|
@context.save do
|
143
153
|
@context.translate(x, y)
|
144
154
|
@context.scale(width / pixbuf.width, height / pixbuf.height)
|
@@ -159,7 +169,7 @@ module PDF
|
|
159
169
|
x, y = current_point
|
160
170
|
img_surface = Cairo::ImageSurface.from_png(filename)
|
161
171
|
width, height = calc_image_dimensions(opts[:width], opts[:height], img_surface.width, img_surface.height, opts[:proportional])
|
162
|
-
x, y = calc_image_coords(opts[:left] || x, opts[:top] || y, opts[:width] || img_surface.width, opts[:height] || img_surface.height, width, height,
|
172
|
+
x, y = calc_image_coords(opts[:left] || x, opts[:top] || y, opts[:width] || img_surface.width, opts[:height] || img_surface.height, width, height, opts[:position], opts[:vposition])
|
163
173
|
@context.save do
|
164
174
|
@context.translate(x, y)
|
165
175
|
@context.scale(width / img_surface.width, height / img_surface.height)
|
@@ -175,7 +185,7 @@ module PDF
|
|
175
185
|
x, y = current_point
|
176
186
|
handle = RSVG::Handle.new_from_file(filename)
|
177
187
|
width, height = calc_image_dimensions(opts[:width], opts[:height], handle.width, handle.height, opts[:proportional])
|
178
|
-
x, y = calc_image_coords(opts[:left] || x, opts[:top] || y, opts[:width] || handle.width, opts[:height] || handle.height, width, height,
|
188
|
+
x, y = calc_image_coords(opts[:left] || x, opts[:top] || y, opts[:width] || handle.width, opts[:height] || handle.height, width, height, opts[:position], opts[:vposition])
|
179
189
|
@context.save do
|
180
190
|
@context.translate(x, y)
|
181
191
|
@context.scale(width / handle.width, height / handle.height)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdf-wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- James Healy
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-12 00:00:00 +11:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|