pdf_gen 0.7.1 → 0.8

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/CHANGES ADDED
@@ -0,0 +1,4 @@
1
+ Version 0.8
2
+ - Fix draw borders for a div
3
+ - Add samples
4
+ - Method cell (in the SmartTable) supports blocks
@@ -178,6 +178,21 @@ We can set the width of each column
178
178
  cell data[2], :width => av_width * 1/4
179
179
  end
180
180
 
181
+ Method cell supports blocks, for example:
182
+
183
+ body do
184
+ ds.each do |datarow|
185
+ row do
186
+ cell datarow[1], :width => av_width / 2
187
+ cell datarow[2], :width => av_width / 4
188
+ cell :div, :width => av_width / 4, :paddings => 0.2.cm do
189
+ image(open(File.expand_path("example_image.png"), "rb") { |file| file.read }, :width => av_width / 2)
190
+ end
191
+ end
192
+ end
193
+ end
194
+
195
+ In this case the first arguments can be ":div", ":span", ":table" and others
181
196
 
182
197
  == Credits
183
198
 
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.8
@@ -61,8 +61,12 @@ module PDFGen
61
61
  document.pdf.stroke_color! background_color
62
62
  document.pdf.stroke_style! PDF::Writer::StrokeStyle::SOLID
63
63
  document.pdf.fill_color! background_color
64
- document.pdf.rectangle(pos[0], pos[1] - height, width, height).fill.stroke
65
-
64
+ document.pdf.rectangle(
65
+ pos[0] + border_width / 2.0,
66
+ pos[1] - height + border_width / 2.0,
67
+ width - border_width,
68
+ height - border_width
69
+ ).fill.stroke
66
70
  document.pdf.restore_state
67
71
  end
68
72
  end
@@ -5,7 +5,7 @@ module PDFGen
5
5
  def caption(text = nil, style = nil)
6
6
  caption = Caption.new self
7
7
  caption.text = text if text
8
- caption.width = self.width - self.pad_left - self.pad_right
8
+ caption.width = self.av_width
9
9
  caption.set_properties style unless style.nil?
10
10
  self.add_region(caption)
11
11
  end
@@ -4,7 +4,7 @@ module PDFGen
4
4
 
5
5
  def div(style = nil, &initialization_block)
6
6
  div = Div.new(self)
7
- div.width = self.width - self.pad_left - self.pad_right
7
+ div.width = self.av_width
8
8
  div.set_properties style unless style.nil?
9
9
  div.instance_eval(&initialization_block) if initialization_block
10
10
  self.add_region(div)
@@ -4,7 +4,7 @@ module PDFGen
4
4
 
5
5
  def span(style = nil, &initialization_block)
6
6
  span = Span.new self
7
- span.width = self.width - self.pad_left - self.pad_right
7
+ span.width = self.av_width
8
8
  span.set_properties style unless style.nil?
9
9
  span.instance_eval(&initialization_block) if initialization_block
10
10
  self.add_region(span)
data/lib/div.rb CHANGED
@@ -55,12 +55,12 @@ module PDFGen
55
55
  end
56
56
 
57
57
  def calculate_minimal_height
58
- height = 0
59
- regions.each do |region|
60
- height += region.height
61
- height += horizontal_interval unless region == regions.last
58
+ sum_height = regions.inject(0) do |sum, region|
59
+ h = region.height
60
+ h += horizontal_interval unless region == regions.last
61
+ sum + h
62
62
  end
63
- height + pad_top + pad_bottom
63
+ sum_height + pad_top + pad_bottom
64
64
  end
65
65
 
66
66
  def render_regions(pos, av_height, test=false)
@@ -76,7 +76,7 @@ module PDFGen
76
76
  self.fit_width(region)
77
77
  if pos_y >= region.height
78
78
  @count_rendered_region += 1 unless test
79
-
79
+
80
80
  region_height = region.render([pos_x, pos_y], pos_y, test)[0]
81
81
 
82
82
  @rendered_height += region_height
@@ -118,13 +118,14 @@ module PDFGen
118
118
  def render(pos, av_height, test=false)
119
119
  pos_x, pos_y = pos
120
120
  fill(pos)
121
- add_border_top(pos_x, pos_y) if @rendered_height.zero?
121
+ add_border_top(pos_x, pos_y) if @rendered_height.zero?
122
122
  status = render_regions([pos_x, pos_y], av_height, test)
123
123
  pos_y -= status[0]
124
124
 
125
125
  if (status[1])
126
- add_border_bottom(pos_x, pos_y)
127
- add_border_sides(pos_x, av_height, pos_y)
126
+ bottom = (av_height - self.height) > 0 ? (av_height - self.height) : pos_y
127
+ add_border_bottom(pos_x, bottom)
128
+ add_border_sides(pos_x, av_height, bottom)
128
129
  else
129
130
  add_border_sides(pos_x, av_height, 0)
130
131
  end
@@ -32,8 +32,8 @@ module PDFGen
32
32
  def render(pos, av_height, test=false)
33
33
  self.check_fit_in_height
34
34
  if av_height >= self.height
35
- document.pdf.add_image(@image, pos[0]+pad_left, pos[1]-height+pad_bottom,
36
- width-pad_left-pad_right, height-pad_top-pad_bottom)
35
+ document.pdf.add_image(@image, pos[0] + pad_left, pos[1] - height + pad_bottom,
36
+ width - pad_left - pad_right, height-pad_top - pad_bottom)
37
37
  super
38
38
  [self.height, true]
39
39
  else
@@ -21,11 +21,14 @@ module PDFGen
21
21
  parent.data_source
22
22
  end
23
23
 
24
- def cell(region=nil,style=nil)
25
- if region.is_a?(Array)
26
- @cells << region.last #todo
27
- region.delete(region.last)
28
- else
24
+ def cell(region=nil,style=nil,&initialization_block)
25
+ if initialization_block
26
+ cell = PDFGen.const_get(region.to_s.capitalize).new(self)
27
+ cell.border_left = true
28
+ cell.set_properties style unless style.nil?
29
+ cell.instance_eval(&initialization_block)
30
+ @cells << cell
31
+ else
29
32
  caption = Caption.new(parent)
30
33
  caption.text = region
31
34
  caption.border_left = true
@@ -59,7 +62,7 @@ module PDFGen
59
62
  @body = RowsContainer.new(self)
60
63
  @footer = RowsContainer.new(self)
61
64
 
62
- init_width(parent)
65
+ self.width = parent.av_width
63
66
 
64
67
  @data_source = nil
65
68
  @header_data = nil
@@ -45,7 +45,7 @@ module PDFGen
45
45
  end
46
46
  else
47
47
  if vertical_align && !test
48
- region.height = height
48
+ region.height = self.height - self.pad_top - self.pad_bottom
49
49
  end
50
50
  region.render([(x + content_width), (y - pad_top)], y-pad_top) unless test
51
51
 
@@ -14,16 +14,13 @@ module PDFGen
14
14
  @header = Div.new(self)
15
15
  @body = Div.new(self)
16
16
  @footer = Div.new(self)
17
-
18
- init_width(parent)
17
+
18
+ self.width = parent.av_width
19
19
 
20
20
  @repeat_header_on_each_page = false
21
21
  @repeat_footer_on_each_page = false
22
22
  end
23
23
 
24
- def init_width(parent)
25
- self.width = parent.width - parent.pad_left - parent.pad_right
26
- end
27
24
 
28
25
  def width=(value)
29
26
  [@title,@header,@body,@footer].each do |region|
@@ -70,7 +67,7 @@ module PDFGen
70
67
 
71
68
  footer_height = @footer.render([pos_x, pos_y], pos_y, true)
72
69
  if footer_height[0] > pos[1]
73
- return [av_height-pos_y, false]
70
+ return [av_height - pos_y, false]
74
71
  end
75
72
 
76
73
  if status[1]
@@ -84,7 +81,7 @@ module PDFGen
84
81
  end
85
82
  pos_y -= footer_status[0] if footer_status
86
83
 
87
- [av_height-pos_y, status[1] && footer_status[1]]
84
+ [av_height - pos_y, status[1] && footer_status[1]]
88
85
  end
89
86
 
90
87
 
@@ -1,7 +1,6 @@
1
1
  $:.unshift(File.expand_path(File.dirname(__FILE__) + "/../"))
2
2
  require "lib/pdf_gen"
3
3
 
4
- image_data = open(File.expand_path('ruby_logo.jpg'), "rb") { |file| file.read }
5
4
 
6
5
  PDFGen::document PDF::Writer.new, 2.cm do
7
6
  div :paddings => 15 do
@@ -75,7 +75,7 @@ describe "New span" do
75
75
  caption1.set_properties(:width => 50)
76
76
 
77
77
  span_el.add_region(caption1)
78
- span_el.render_regions
78
+ span_el.render_regions(0, 500, false)
79
79
  caption1.height.should == 100
80
80
  end
81
81
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdf_gen
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 7
9
- - 1
10
- version: 0.7.1
8
+ - 8
9
+ version: "0.8"
11
10
  platform: ruby
12
11
  authors:
13
12
  - Sphere Consulting Inc.
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-11-19 00:00:00 +02:00
17
+ date: 2010-11-24 00:00:00 +02:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -43,6 +42,7 @@ extensions: []
43
42
  extra_rdoc_files: []
44
43
 
45
44
  files:
45
+ - CHANGES
46
46
  - lib/base_region.rb
47
47
  - lib/caption.rb
48
48
  - lib/containers/caption_container.rb
@@ -94,6 +94,7 @@ files:
94
94
  - test/shared_examples.rb
95
95
  - test/span_test.rb
96
96
  - test/table_test.rb
97
+ - VERSION
97
98
  has_rdoc: true
98
99
  homepage: https://github.com/SphereConsultingInc/pdf_gen/
99
100
  licenses: []