pdf-wrapper 0.0.5 → 0.0.6
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/CHANGELOG +5 -2
- data/Rakefile +1 -1
- data/lib/pdf/wrapper.rb +8 -37
- data/specs/text_spec.rb +27 -3
- data/specs/wrapper_spec.rb +1 -1
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
v0.0.6 (28th April 2008)w
|
2
|
+
- Fix a nasty bug in text layout code
|
3
|
+
|
1
4
|
v0.0.5 (27th April 2008)
|
2
5
|
- Fix crash when inserting multiple images
|
3
6
|
- added PDF::Wrapper#pad
|
@@ -16,7 +19,7 @@ v0.0.4 (12th March 2008)
|
|
16
19
|
|
17
20
|
v0.0.3 (17th January 2008)
|
18
21
|
- added support for repeating elements (like page numbers) via repeating_element
|
19
|
-
- Ensured consistent behaviour WRT functions moving the internal cursor
|
22
|
+
- Ensured consistent behaviour WRT functions moving the internal cursor
|
20
23
|
- functions that require positioning info (cell, shapes, etc) will not move
|
21
24
|
the cursor at all
|
22
25
|
- functions where positioning info in optional (text, image, etc), the cursor
|
@@ -28,7 +31,7 @@ v0.0.3 (17th January 2008)
|
|
28
31
|
|
29
32
|
v0.0.2 (11th January 2008)
|
30
33
|
- Added support for a range of extra image formats (jpg, pdf, gif, etc)
|
31
|
-
- Various documentation improvements
|
34
|
+
- Various documentation improvements
|
32
35
|
- improved the text functions a little, but still lots more to go
|
33
36
|
|
34
37
|
v0.0.1 (9th January 2008)
|
data/Rakefile
CHANGED
data/lib/pdf/wrapper.rb
CHANGED
@@ -282,7 +282,7 @@ module PDF
|
|
282
282
|
# TODO: add an option to draw a border with rounded corners
|
283
283
|
|
284
284
|
options = default_text_options
|
285
|
-
options.merge!({:border => "tblr", :border_width => @default_line_width, :border_color => :black,
|
285
|
+
options.merge!({:border => "tblr", :border_width => @default_line_width, :border_color => :black, :fill_color => nil, :padding => 3})
|
286
286
|
options.merge!(opts)
|
287
287
|
options.assert_valid_keys(default_text_options.keys + [:width, :border, :border_width, :border_color, :fill_color, :padding])
|
288
288
|
|
@@ -300,7 +300,6 @@ module PDF
|
|
300
300
|
|
301
301
|
# TODO: raise an exception if the box coords or dimensions will place it off the canvas
|
302
302
|
rectangle(x,y,w,h, :color => options[:fill_color], :fill_color => options[:fill_color]) if options[:fill_color]
|
303
|
-
|
304
303
|
layout = build_pango_layout(str.to_s, textw, options)
|
305
304
|
|
306
305
|
set_color(options[:color])
|
@@ -1037,47 +1036,19 @@ module PDF
|
|
1037
1036
|
options = {:auto_new_page => true }
|
1038
1037
|
options.merge!(opts)
|
1039
1038
|
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
orig_y = y
|
1044
|
-
# for each line in the layout
|
1045
|
-
# layout.alignment = Pango::Layout::ALIGN_RIGHT
|
1046
|
-
# layout.lines.each do |line|
|
1047
|
-
# #calculate where the next line starts
|
1048
|
-
# ink_rect, logical_rect = line.extents
|
1049
|
-
# y = y + (logical_rect.height / Pango::SCALE * (3.0/4.0)) + 1
|
1050
|
-
# if y >= (orig_y + h)
|
1051
|
-
# # our text is using the maximum amount of vertical space we want it to
|
1052
|
-
# if options[:auto_new_page]
|
1053
|
-
# # create a new page and we can continue adding text
|
1054
|
-
# start_new_page
|
1055
|
-
# x = orig_x
|
1056
|
-
# y = orig_y
|
1057
|
-
# else
|
1058
|
-
# # the user doesn't want us to continue on the next page, so
|
1059
|
-
# # stop adding lines to the canvas
|
1060
|
-
# break
|
1061
|
-
# end
|
1062
|
-
# end
|
1063
|
-
#
|
1064
|
-
# # move to the start of the next line
|
1065
|
-
# move_to(x, y)
|
1066
|
-
# # draw the line on the canvas
|
1067
|
-
# @context.show_pango_layout_line(line)
|
1068
|
-
# end
|
1039
|
+
offset = 0
|
1040
|
+
baseline = 0
|
1041
|
+
|
1069
1042
|
iter = layout.iter
|
1070
1043
|
loop do
|
1071
1044
|
line = iter.line
|
1072
1045
|
ink_rect, logical_rect = iter.line_extents
|
1073
|
-
|
1074
|
-
if y >= (orig_y + h)
|
1046
|
+
if y + (baseline - offset) >= (y + h)
|
1075
1047
|
# our text is using the maximum amount of vertical space we want it to
|
1076
1048
|
if options[:auto_new_page]
|
1077
1049
|
# create a new page and we can continue adding text
|
1050
|
+
offset += baseline
|
1078
1051
|
start_new_page
|
1079
|
-
x = orig_x
|
1080
|
-
y = orig_y
|
1081
1052
|
else
|
1082
1053
|
# the user doesn't want us to continue on the next page, so
|
1083
1054
|
# stop adding lines to the canvas
|
@@ -1088,7 +1059,7 @@ module PDF
|
|
1088
1059
|
# move to the start of the next line
|
1089
1060
|
#move_to(x, y)
|
1090
1061
|
baseline = iter.baseline / Pango::SCALE
|
1091
|
-
@context.move_to(x + logical_rect.x / Pango::SCALE, y + baseline)
|
1062
|
+
@context.move_to(x + logical_rect.x / Pango::SCALE, y + baseline - offset)
|
1092
1063
|
|
1093
1064
|
# draw the line on the canvas
|
1094
1065
|
@context.show_pango_layout_line(line)
|
@@ -1097,7 +1068,7 @@ module PDF
|
|
1097
1068
|
end
|
1098
1069
|
|
1099
1070
|
# return the y co-ord we finished on
|
1100
|
-
return y
|
1071
|
+
return y + baseline - offset
|
1101
1072
|
end
|
1102
1073
|
|
1103
1074
|
def translate_color(c)
|
data/specs/text_spec.rb
CHANGED
@@ -27,6 +27,19 @@ context "The PDF::Wrapper class" do
|
|
27
27
|
receiver.content.first.should eql(msg)
|
28
28
|
end
|
29
29
|
|
30
|
+
specify "should be able to add unicode text that spans multiple pages to the canvas" do
|
31
|
+
msg = "James\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nHealy"
|
32
|
+
pdf = PDF::Wrapper.new
|
33
|
+
pdf.text msg
|
34
|
+
|
35
|
+
receiver = PageTextReceiver.new
|
36
|
+
reader = PDF::Reader.string(pdf.render, receiver)
|
37
|
+
|
38
|
+
receiver.content.size.should eql(2)
|
39
|
+
receiver.content[0].should eql("James")
|
40
|
+
receiver.content[1].should eql("Healy")
|
41
|
+
end
|
42
|
+
|
30
43
|
specify "should be align text on the left when using the text method" do
|
31
44
|
msg = "Chunky Bacon"
|
32
45
|
pdf = PDF::Wrapper.new
|
@@ -35,14 +48,25 @@ context "The PDF::Wrapper class" do
|
|
35
48
|
receiver = PDF::Reader::RegisterReceiver.new
|
36
49
|
reader = PDF::Reader.string(pdf.render, receiver)
|
37
50
|
|
38
|
-
#
|
51
|
+
# ensure the text is placed in the right location
|
52
|
+
params = receiver.first_occurance_of(:set_text_matrix_and_text_line_matrix)[:args]
|
53
|
+
params[4].should eql(pdf.margin_left.to_f)
|
54
|
+
end
|
55
|
+
|
56
|
+
specify "should be able to align text on the left when using the text method" do
|
57
|
+
msg = "Chunky Bacon"
|
58
|
+
pdf = PDF::Wrapper.new
|
59
|
+
pdf.text msg, :alignment => :left
|
60
|
+
|
61
|
+
receiver = PDF::Reader::RegisterReceiver.new
|
62
|
+
reader = PDF::Reader.string(pdf.render, receiver)
|
39
63
|
|
40
64
|
# ensure the text is placed in the right location
|
41
65
|
params = receiver.first_occurance_of(:set_text_matrix_and_text_line_matrix)[:args]
|
42
66
|
params[4].should eql(pdf.margin_left.to_f)
|
43
67
|
end
|
44
68
|
|
45
|
-
specify "should be align text in the centre when using the text method" do
|
69
|
+
specify "should be able to align text in the centre when using the text method" do
|
46
70
|
msg = "Chunky Bacon"
|
47
71
|
pdf = PDF::Wrapper.new
|
48
72
|
pdf.text msg, :alignment => :center
|
@@ -57,7 +81,7 @@ context "The PDF::Wrapper class" do
|
|
57
81
|
(params[4] > pdf.absolute_x_middle - 100).should be_true
|
58
82
|
end
|
59
83
|
|
60
|
-
specify "should be align text on the right when using the text method" do
|
84
|
+
specify "should be able to align text on the right when using the text method" do
|
61
85
|
msg = "Chunky Bacon"
|
62
86
|
pdf = PDF::Wrapper.new
|
63
87
|
pdf.text msg, :alignment => :right
|
data/specs/wrapper_spec.rb
CHANGED
@@ -329,7 +329,7 @@ context "The PDF::Wrapper class" do
|
|
329
329
|
pdf.text("Page #{pdf.page}!", :left => pdf.margin_left, :top => pdf.margin_top, :font_size => 18)
|
330
330
|
x, y = pdf.current_point
|
331
331
|
x.should eql(origx)
|
332
|
-
y.should eql(origy +
|
332
|
+
y.should eql(origy + 27)
|
333
333
|
|
334
334
|
# image() - palms it's works out to helper functions, so we have to check them individually
|
335
335
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdf-wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Healy
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-04-
|
12
|
+
date: 2008-04-28 00:00:00 +10:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|