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 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
@@ -9,7 +9,7 @@ require 'roodi'
9
9
  require 'roodi_task'
10
10
 
11
11
 
12
- PKG_VERSION = "0.3.5"
12
+ PKG_VERSION = "0.4.0"
13
13
  PKG_NAME = "pdf-wrapper"
14
14
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
15
15
 
@@ -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>:center</tt>:: If the image is scaled, it will be centered horizontally and vertically
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, :center, :rotate])
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>desired_w</tt>:: The image width requested by the user
72
- # <tt>desired_h</tt>:: The image height requested by the user
73
- # <tt>actual_w</tt>:: The width of the image we're going to draw
74
- # <tt>actual_h</tt>:: The height of the image we're going to draw
75
- # <tt>centre</tt>:: True if the image should be shifted to the center of it's box
76
- def calc_image_coords(x, y, desired_w, desired_h, actual_w, actual_h, centre = false)
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 actual_w < desired_w && centre
81
- white_space = desired_w - actual_w
82
- x = x + (white_space / 2)
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 actual_h < desired_h && centre
88
- white_space = desired_h - actual_h
89
- y = y + (white_space / 2)
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[:center])
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, opts[:center])
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, opts[:center])
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, opts[:center])
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)
@@ -50,7 +50,7 @@ module PDF
50
50
  :width => self.width,
51
51
  :height => self.height - image_offset,
52
52
  :proportional => true,
53
- :center => true
53
+ :position => :center
54
54
  }
55
55
  end
56
56
 
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: 25
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 5
10
- version: 0.3.5
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-09-29 00:00:00 +10:00
18
+ date: 2010-10-12 00:00:00 +11:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency