rfpdf 1.17.3 → 1.17.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/README.md +68 -0
- data/lib/rfpdf/version.rb +1 -1
- data/lib/tcpdf.rb +192 -3
- data/rfpdf.gemspec +1 -1
- data/test/tcpdf_cell_test.rb +178 -0
- data/test/tcpdf_image_test.rb +36 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 796b6a1fe25a0c554d948c5c28ef2610484f25db
|
4
|
+
data.tar.gz: b3c31fb2d5e7fd0967df31960b160df0a8262a07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b82b68c5973fc2eed86fd8ac2307c7f8158a7f6917878ae46874fca684bfc5ace5b0dd79dae0bfed9f2c54159089cbfaff4e4d75a07084e2d275ad8c3274b916
|
7
|
+
data.tar.gz: b20b66eabb47b0806599d47f78012e855072b990a3aa74ce93125d24cd8d89fc5f9d7d7ddeac4250baf432e937264a8c94ce69a02d4fd4cc9086b2c365ba6acc
|
data/CHANGELOG
CHANGED
@@ -17,4 +17,8 @@ put your assignment in a before_filter (perhaps overriding :filename, etc in you
|
|
17
17
|
1.17 2014-05-18 Update base version to TCPDF 5.1.002. Ruby 2.0/2.1 support. FPDF is deprecated.
|
18
18
|
1.17.2 2014-07-09 FreeSerif font added from GNU FreeFont(20080912).
|
19
19
|
1.17.3 2014-07-16 Several bug fixed.
|
20
|
+
1.17.4 2014-07-28
|
21
|
+
- getNumLines, getStringHeight, getMargins function added.
|
22
|
+
- fix large image file page break bug.
|
23
|
+
|
20
24
|
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
|
2
|
+
# RFPDF Template Plugin
|
3
|
+
|
4
|
+
A template plugin allowing the inclusion of ERB-enabled RFPDF template files.
|
5
|
+
|
6
|
+
##
|
7
|
+
##
|
8
|
+
## TCPDF Version (The New or UTF8 Version)
|
9
|
+
##
|
10
|
+
##
|
11
|
+
|
12
|
+
* Use UTF-8 encoding.
|
13
|
+
* RTL (Right-To-Left) languages support.
|
14
|
+
* HTML tag support.
|
15
|
+
* CSS minimum support.
|
16
|
+
* Image
|
17
|
+
- 8bit PNG image support without RMagick liblary.
|
18
|
+
- PNG/JPEG/GIF image support. (use RMagick liblary)
|
19
|
+
|
20
|
+
|
21
|
+
##
|
22
|
+
## Installing RFPDF
|
23
|
+
##
|
24
|
+
|
25
|
+
RFPDF is distributed via RubyGems, and can be installed the usual way that you install gems: by simply typing `gem install rfpdf` on the command line.
|
26
|
+
|
27
|
+
==
|
28
|
+
|
29
|
+
If you are using HTML, it is recommended you install:
|
30
|
+
```
|
31
|
+
gem install htmlentities
|
32
|
+
```
|
33
|
+
|
34
|
+
If you are using image file, it is recommended you install:
|
35
|
+
```
|
36
|
+
gem install rmagick
|
37
|
+
```
|
38
|
+
|
39
|
+
TCPDF Example of simple use in .html.erb:
|
40
|
+
|
41
|
+
```
|
42
|
+
<%
|
43
|
+
@pdf = TCPDF.new()
|
44
|
+
@pdf.set_margins(15, 27, 15)
|
45
|
+
@pdf.set_font('FreeSans','', 8)
|
46
|
+
@pdf.add_page()
|
47
|
+
@pdf.write(5, "text\n", '')
|
48
|
+
%><%==@pdf.output()%>
|
49
|
+
```
|
50
|
+
|
51
|
+
TCPDF Japanese Example of simple use in .html.erb:
|
52
|
+
```
|
53
|
+
<%
|
54
|
+
@pdf = TCPDF.new()
|
55
|
+
@pdf.set_margins(15, 27, 15)
|
56
|
+
@pdf.set_font('kozminproregular','', 8)
|
57
|
+
@pdf.add_page()
|
58
|
+
@pdf.write(5, "UTF-8 Japanese text.\n", '')
|
59
|
+
%><%==@pdf.output()%>
|
60
|
+
```
|
61
|
+
|
62
|
+
See the following files for sample of useage:
|
63
|
+
|
64
|
+
test_unicode.rfpdf
|
65
|
+
utf8test.txt
|
66
|
+
logo_example.png
|
67
|
+
|
68
|
+
ENJOY!
|
data/lib/rfpdf/version.rb
CHANGED
data/lib/tcpdf.rb
CHANGED
@@ -124,8 +124,6 @@ class TCPDF
|
|
124
124
|
|
125
125
|
attr_accessor :color_flag
|
126
126
|
|
127
|
-
attr_accessor :default_table_columns
|
128
|
-
|
129
127
|
attr_accessor :default_font
|
130
128
|
|
131
129
|
attr_accessor :draw_color
|
@@ -278,7 +276,6 @@ class TCPDF
|
|
278
276
|
@header_logo_width ||= 30
|
279
277
|
@header_title ||= ""
|
280
278
|
@header_string ||= ""
|
281
|
-
@default_table_columns ||= 4
|
282
279
|
@listordered ||= []
|
283
280
|
@listcount ||= []
|
284
281
|
@listindent ||= 0
|
@@ -3352,6 +3349,7 @@ class TCPDF
|
|
3352
3349
|
# [@see] Cell()
|
3353
3350
|
#
|
3354
3351
|
def getCellCode(w, h=0, txt='', border=0, ln=0, align='', fill=0, link=nil, stretch=0, ignore_min_height=false, calign='T', valign='M')
|
3352
|
+
txt = '' if txt.nil?
|
3355
3353
|
rs = "" # string to be returned
|
3356
3354
|
txt = removeSHY(txt)
|
3357
3355
|
if !ignore_min_height
|
@@ -4024,6 +4022,151 @@ class TCPDF
|
|
4024
4022
|
end
|
4025
4023
|
protected :getBorderMode
|
4026
4024
|
|
4025
|
+
#
|
4026
|
+
# This method return the estimated number of lines for print a simple text string in Multicell() method.
|
4027
|
+
# [@param string :txt] String for calculating his height
|
4028
|
+
# [@param float :w] Width of cells. If 0, they extend up to the right margin of the page.
|
4029
|
+
# [@param boolean :reseth] if true reset the last cell height (default false).
|
4030
|
+
# [@param boolean :autopadding] if true, uses internal padding and automatically adjust it to account for line width (default true).
|
4031
|
+
# [@param float :cellMargin] Internal cell margin, if empty or <= 0, extended up to current pdf cell margin (default '').
|
4032
|
+
# [@param float :lineWidth] Line width, if empty or <= 0, extended up to current pdf line width (default '').
|
4033
|
+
# [@return float] Return the minimal height needed for multicell method for printing the :txt param.
|
4034
|
+
# [@author] Alexander Escalona Fernendez, Nicola Asuni
|
4035
|
+
# [@access public]
|
4036
|
+
# [@since 4.5.011]
|
4037
|
+
#
|
4038
|
+
def getNumLines(txt, w=0, reseth=false, autopadding=true, cellMargin='', lineWidth='')
|
4039
|
+
if empty_string(w) or (w <= 0)
|
4040
|
+
if @rtl
|
4041
|
+
w = @x - @l_margin
|
4042
|
+
else
|
4043
|
+
w = @w - @r_margin - @x
|
4044
|
+
end
|
4045
|
+
end
|
4046
|
+
if empty_string(cellMargin) or (cellMargin <= 0)
|
4047
|
+
cellMargin = @c_margin
|
4048
|
+
end
|
4049
|
+
if empty_string(lineWidth) or (lineWidth <= 0)
|
4050
|
+
lineWidth = @line_width
|
4051
|
+
end
|
4052
|
+
if autopadding
|
4053
|
+
# adjust internal padding
|
4054
|
+
if cellMargin < (lineWidth / 2)
|
4055
|
+
cellMargin = lineWidth / 2
|
4056
|
+
end
|
4057
|
+
end
|
4058
|
+
wmax = w - (2 * cellMargin)
|
4059
|
+
if reseth
|
4060
|
+
@lasth = @font_size * @cell_height_ratio
|
4061
|
+
end
|
4062
|
+
lines = 1
|
4063
|
+
sum = 0
|
4064
|
+
chars = UTF8StringToArray(txt)
|
4065
|
+
chars = utf8Bidi(chars, txt, @tmprtl)
|
4066
|
+
charsWidth = GetArrStringWidth(chars, '', '', 0, true)
|
4067
|
+
if @rtl
|
4068
|
+
charsWidth.reverse!
|
4069
|
+
chars.reverse!
|
4070
|
+
end
|
4071
|
+
length = chars.length
|
4072
|
+
lastSeparator = -1
|
4073
|
+
|
4074
|
+
i = 0
|
4075
|
+
while i < length
|
4076
|
+
charWidth = charsWidth[i]
|
4077
|
+
if unichr(chars[i]) =~ /\s/
|
4078
|
+
lastSeparator = i
|
4079
|
+
end
|
4080
|
+
if sum + charWidth >= wmax
|
4081
|
+
lines += 1
|
4082
|
+
if lastSeparator != -1
|
4083
|
+
i = lastSeparator
|
4084
|
+
lastSeparator = -1
|
4085
|
+
sum = 0
|
4086
|
+
else
|
4087
|
+
sum = charWidth
|
4088
|
+
end
|
4089
|
+
else
|
4090
|
+
sum += charWidth
|
4091
|
+
end
|
4092
|
+
i += 1
|
4093
|
+
end
|
4094
|
+
return lines
|
4095
|
+
end
|
4096
|
+
alias_method :get_num_lines, :getNumLines
|
4097
|
+
|
4098
|
+
#
|
4099
|
+
# This method return the estimated needed height for print a simple text string in Multicell() method.
|
4100
|
+
# Generally, if you want to know the exact height for a block of content you can use the following technique:
|
4101
|
+
#
|
4102
|
+
# # store current object
|
4103
|
+
# pdf.start_transaction()
|
4104
|
+
# # store starting values
|
4105
|
+
# start_y = pdf.get_y()
|
4106
|
+
# start_page = pdf.get_page()
|
4107
|
+
# # call your printing functions with your parameters
|
4108
|
+
# # - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
4109
|
+
# pdf.multi_cell(w=0, h=0, txt, border=1, align='L', fill=0, ln=1, x='', y='', reseth=true, stretch=0, ishtml=false, autopadding=true, maxh=0)
|
4110
|
+
# # - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
4111
|
+
# # get the new Y
|
4112
|
+
# end_y = pdf.get_y()
|
4113
|
+
# end_page = pdf.get_page()
|
4114
|
+
# # calculate height
|
4115
|
+
# height = 0
|
4116
|
+
# if end_page == start_page
|
4117
|
+
# height = end_y - start_y
|
4118
|
+
# else
|
4119
|
+
# start_page.upto(end_page) do |page|
|
4120
|
+
# pdf.set_page(page)
|
4121
|
+
# if page == start_page
|
4122
|
+
# # first page
|
4123
|
+
# height = @h - start_y - @b_margin
|
4124
|
+
# elsif page == end_page
|
4125
|
+
# # last page
|
4126
|
+
# height = end_y - @t_margin
|
4127
|
+
# else
|
4128
|
+
# height = @h - @t_margin - @b_margin
|
4129
|
+
# end
|
4130
|
+
# end
|
4131
|
+
# end
|
4132
|
+
# # restore previous object
|
4133
|
+
# pdf = pdf.rollbackTransaction()
|
4134
|
+
#
|
4135
|
+
# [@param float :w] Width of cells. If 0, they extend up to the right margin of the page.
|
4136
|
+
# [@param string :txt] String for calculating his height
|
4137
|
+
# [@param boolean :reseth] if true reset the last cell height (default false).
|
4138
|
+
# [@param boolean :autopadding] if true, uses internal padding and automatically adjust it to account for line width (default true).
|
4139
|
+
# [@param float :cellMargin] Internal cell margin, if empty or <= 0, extended up to current pdf cell margin (default '').
|
4140
|
+
# [@param float :lineWidth] Line width, if empty or <= 0, extended up to current pdf line width (default '').
|
4141
|
+
# [@return float] Return the minimal height needed for multicell method for printing the :txt param.
|
4142
|
+
# [@author] Nicola Asuni, Alexander Escalona Fern<E1>ndez
|
4143
|
+
# [@access public]
|
4144
|
+
#
|
4145
|
+
def getStringHeight(w, txt, reseth=false, autopadding=true, cellMargin='', lineWidth='')
|
4146
|
+
lines = getNumLines(txt, w, reseth, autopadding, cellMargin, lineWidth)
|
4147
|
+
height = lines * (@font_size * @cell_height_ratio)
|
4148
|
+
if autopadding
|
4149
|
+
if empty_string(cellMargin) or (cellMargin <= 0)
|
4150
|
+
cellMargin = @c_margin
|
4151
|
+
end
|
4152
|
+
if empty_string(lineWidth) or (lineWidth <= 0)
|
4153
|
+
lineWidth = @line_width
|
4154
|
+
end
|
4155
|
+
# adjust internal padding
|
4156
|
+
if cellMargin < (lineWidth / 2)
|
4157
|
+
cellMargin = lineWidth / 2
|
4158
|
+
end
|
4159
|
+
# add top and bottom space if needed
|
4160
|
+
if (@lasth - @font_size) < lineWidth
|
4161
|
+
height += lineWidth
|
4162
|
+
end
|
4163
|
+
# add top and bottom padding
|
4164
|
+
height += 2 * cellMargin
|
4165
|
+
end
|
4166
|
+
return height
|
4167
|
+
end
|
4168
|
+
alias_method :get_string_height, :getStringHeight
|
4169
|
+
|
4027
4170
|
#
|
4028
4171
|
# This method prints text from the current position.
|
4029
4172
|
# [@param float :h] Line height
|
@@ -4618,6 +4761,23 @@ class TCPDF
|
|
4618
4761
|
w = h * pixw / pixh
|
4619
4762
|
end
|
4620
4763
|
end
|
4764
|
+
|
4765
|
+
# resize image to be contained on a single page # fix at page break case.
|
4766
|
+
if fitonpage
|
4767
|
+
ratio_wh = w / h
|
4768
|
+
if (@t_margin + h) > @page_break_trigger
|
4769
|
+
h = @page_break_trigger - @t_margin
|
4770
|
+
w = h * ratio_wh
|
4771
|
+
end
|
4772
|
+
if !@rtl and ((x + w) > (@w - @r_margin))
|
4773
|
+
w = @w - @r_margin - x
|
4774
|
+
h = w / ratio_wh
|
4775
|
+
elsif @rtl and ((x - w) < @l_margin)
|
4776
|
+
w = x - @l_margin
|
4777
|
+
h = w / ratio_wh
|
4778
|
+
end
|
4779
|
+
end
|
4780
|
+
|
4621
4781
|
# Check whether we need a new page first as this does not fit
|
4622
4782
|
prev_x = @x
|
4623
4783
|
if checkPageBreak(h, y)
|
@@ -9949,6 +10109,35 @@ public
|
|
9949
10109
|
alias_method :write_barcode, :writeBarcode
|
9950
10110
|
=end
|
9951
10111
|
|
10112
|
+
#
|
10113
|
+
# Returns an array containing current margins:
|
10114
|
+
#
|
10115
|
+
# * ret['left'] = left margin
|
10116
|
+
# * ret['right'] = right margin
|
10117
|
+
# * ret['top'] = top margin
|
10118
|
+
# * ret['bottom'] = bottom margin
|
10119
|
+
# * ret['header'] = header margin
|
10120
|
+
# * ret['footer'] = footer margin
|
10121
|
+
# * ret['cell'] = cell margin
|
10122
|
+
#
|
10123
|
+
# [@return array] containing all margins measures
|
10124
|
+
# [@access public]
|
10125
|
+
# [@since 3.2.000 (2008-06-23)]
|
10126
|
+
#
|
10127
|
+
def getMargins()
|
10128
|
+
ret = {
|
10129
|
+
'left' => @l_margin,
|
10130
|
+
'right' => @r_margin,
|
10131
|
+
'top' => @t_margin,
|
10132
|
+
'bottom' => @b_margin,
|
10133
|
+
'header' => @header_margin,
|
10134
|
+
'footer' => @footer_margin,
|
10135
|
+
'cell' => @c_margin,
|
10136
|
+
}
|
10137
|
+
return ret
|
10138
|
+
end
|
10139
|
+
alias_method :get_margins, :getMargins
|
10140
|
+
|
9952
10141
|
#
|
9953
10142
|
# Returns an array containing original margins:
|
9954
10143
|
# ret['left'] = left margin
|
data/rfpdf.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
Dir.glob("lib/fonts/dejavu-fonts-ttf-*/{AUTHORS,BUGS,LICENSE,NEWS,README}") +
|
21
21
|
Dir.glob("test/*") +
|
22
22
|
["Rakefile", "rfpdf.gemspec", "Gemfile",
|
23
|
-
"CHANGELOG", "test_unicode.rfpdf",
|
23
|
+
"CHANGELOG", "test_unicode.rfpdf", "README.md",
|
24
24
|
"utf8test.txt", "logo_example.png" ]
|
25
25
|
spec.rdoc_options += [ '--exclude', 'lib/fonts/',
|
26
26
|
'--exclude', 'lib/htmlcolors.rb',
|
data/test/tcpdf_cell_test.rb
CHANGED
@@ -51,4 +51,182 @@ class TcpdfTest < ActiveSupport::TestCase
|
|
51
51
|
# [(abc)] TJ
|
52
52
|
# ET
|
53
53
|
end
|
54
|
+
|
55
|
+
test "getStringHeight Basic test" do
|
56
|
+
pdf = TCPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
|
57
|
+
pdf.add_page
|
58
|
+
|
59
|
+
txt = 'abcdefg'
|
60
|
+
|
61
|
+
w = 50
|
62
|
+
y1 = pdf.get_y
|
63
|
+
pdf.multi_cell(w, 0, txt)
|
64
|
+
pno = pdf.get_page
|
65
|
+
assert_equal pno, 1
|
66
|
+
y2 = pdf.get_y
|
67
|
+
h1 = y2 - y1
|
68
|
+
|
69
|
+
h2 = pdf.getStringHeight(w, txt)
|
70
|
+
assert_in_delta h1, h2, 0.01
|
71
|
+
|
72
|
+
line = pdf.get_num_lines(txt, w)
|
73
|
+
assert_equal line, 1
|
74
|
+
|
75
|
+
w = 20
|
76
|
+
y1 = pdf.get_y
|
77
|
+
pdf.multi_cell(w, 0, txt)
|
78
|
+
pno = pdf.get_page
|
79
|
+
assert_equal pno, 1
|
80
|
+
y2 = pdf.get_y
|
81
|
+
h1 = y2 - y1
|
82
|
+
|
83
|
+
h2 = pdf.getStringHeight(w, txt)
|
84
|
+
assert_in_delta h1, h2, 0.01
|
85
|
+
|
86
|
+
line = pdf.get_num_lines(txt, w)
|
87
|
+
assert_equal line, 1
|
88
|
+
end
|
89
|
+
|
90
|
+
test "getStringHeight Line Break test" do
|
91
|
+
pdf = TCPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
|
92
|
+
pdf.add_page
|
93
|
+
|
94
|
+
txt = 'abcdefg'
|
95
|
+
|
96
|
+
w = 10
|
97
|
+
y1 = pdf.get_y
|
98
|
+
pdf.multi_cell(w, 0, txt)
|
99
|
+
pno = pdf.get_page
|
100
|
+
assert_equal pno, 1
|
101
|
+
y2 = pdf.get_y
|
102
|
+
h1 = y2 - y1
|
103
|
+
|
104
|
+
h2 = pdf.getStringHeight(w, txt)
|
105
|
+
assert_in_delta h1, h2, 0.01
|
106
|
+
|
107
|
+
line = pdf.get_num_lines(txt, w)
|
108
|
+
assert_equal line, 3
|
109
|
+
|
110
|
+
|
111
|
+
w = 5
|
112
|
+
y1 = pdf.get_y
|
113
|
+
pdf.multi_cell(w, 0, txt)
|
114
|
+
pno = pdf.get_page
|
115
|
+
assert_equal pno, 1
|
116
|
+
y2 = pdf.get_y
|
117
|
+
h1 = y2 - y1
|
118
|
+
|
119
|
+
h2 = pdf.getStringHeight(w, txt)
|
120
|
+
assert_in_delta h1, h2, 0.01
|
121
|
+
|
122
|
+
line = pdf.get_num_lines(txt, w)
|
123
|
+
assert_equal line, 7
|
124
|
+
end
|
125
|
+
|
126
|
+
test "getStringHeight Minimum Width test 1" do
|
127
|
+
pdf = TCPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
|
128
|
+
pdf.add_page
|
129
|
+
|
130
|
+
w = pdf.get_string_width('OO')
|
131
|
+
|
132
|
+
txt = "Export to PDF: align is Good."
|
133
|
+
|
134
|
+
y1 = pdf.get_y
|
135
|
+
pdf.multi_cell(w, 0, txt)
|
136
|
+
pno = pdf.get_page
|
137
|
+
assert_equal pno, 1
|
138
|
+
y2 = pdf.get_y
|
139
|
+
h1 = y2 - y1
|
140
|
+
|
141
|
+
h2 = pdf.getStringHeight(w, txt)
|
142
|
+
assert_in_delta h1, h2, 0.01
|
143
|
+
|
144
|
+
line = pdf.get_num_lines(txt, w)
|
145
|
+
assert_equal line, 16
|
146
|
+
end
|
147
|
+
|
148
|
+
test "getStringHeight Minimum Width test 2" do
|
149
|
+
pdf = TCPDF.new('L', 'mm', 'A4', true, "UTF-8", true)
|
150
|
+
pdf.set_font('kozminproregular', '', 8)
|
151
|
+
pdf.add_page
|
152
|
+
|
153
|
+
margins = pdf.get_margins
|
154
|
+
w = pdf.get_string_width('20') + margins['cell'] * 2
|
155
|
+
|
156
|
+
txt = "20"
|
157
|
+
|
158
|
+
y1 = pdf.get_y
|
159
|
+
pdf.multi_cell(w, 0, txt)
|
160
|
+
pno = pdf.get_page
|
161
|
+
assert_equal pno, 1
|
162
|
+
y2 = pdf.get_y
|
163
|
+
h1 = y2 - y1
|
164
|
+
|
165
|
+
h2 = pdf.getStringHeight(w, txt)
|
166
|
+
assert_in_delta h1, h2, 0.01
|
167
|
+
|
168
|
+
line = pdf.get_num_lines(txt, w)
|
169
|
+
assert_equal line, 2
|
170
|
+
end
|
171
|
+
|
172
|
+
test "getStringHeight Minimum Bidi test 1" do
|
173
|
+
pdf = TCPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
|
174
|
+
pdf.add_page
|
175
|
+
|
176
|
+
w = pdf.get_string_width('OO')
|
177
|
+
|
178
|
+
txt = "\xd7\xa2\xd7\x91\xd7\xa8\xd7\x99\xd7\xaa"
|
179
|
+
y1 = pdf.get_y
|
180
|
+
pdf.multi_cell(w, 0, txt)
|
181
|
+
pno = pdf.get_page
|
182
|
+
assert_equal pno, 1
|
183
|
+
y2 = pdf.get_y
|
184
|
+
h1 = y2 - y1
|
185
|
+
h2 = pdf.getStringHeight(w, txt)
|
186
|
+
assert_in_delta h1, h2, 0.01
|
187
|
+
|
188
|
+
line = pdf.get_num_lines(txt, w)
|
189
|
+
assert_equal line, 5
|
190
|
+
|
191
|
+
txt = "? \xd7\x93\xd7\x92 \xd7\xa1\xd7\xa7\xd7\xa8\xd7\x9f \xd7\xa9\xd7\x98 \xd7\x91\xd7\x99\xd7\x9d \xd7\x9e\xd7\x90\xd7\x95\xd7\x9b\xd7\x96\xd7\x91 \xd7\x95\xd7\x9c\xd7\xa4\xd7\xaa\xd7\xa2 \xd7\x9e\xd7\xa6\xd7\x90 \xd7\x9c\xd7\x95 \xd7\x97\xd7\x91\xd7\xa8\xd7\x94 \xd7\x90\xd7\x99\xd7\x9a \xd7\x94\xd7\xa7\xd7\x9c\xd7\x99\xd7\x98\xd7\x94"
|
192
|
+
|
193
|
+
y1 = pdf.get_y
|
194
|
+
pdf.multi_cell(w, 0, txt)
|
195
|
+
pno = pdf.get_page
|
196
|
+
assert_equal pno, 1
|
197
|
+
y2 = pdf.get_y
|
198
|
+
h1 = y2 - y1
|
199
|
+
|
200
|
+
h2 = pdf.getStringHeight(w, txt)
|
201
|
+
assert_in_delta h1, h2, 0.01
|
202
|
+
|
203
|
+
line = pdf.get_num_lines(txt, w)
|
204
|
+
assert_equal line, 41
|
205
|
+
end
|
206
|
+
|
207
|
+
test "getStringHeight Minimum Bidi test 2" do
|
208
|
+
pdf = TCPDF.new('P', 'mm', 'A4', true, "UTF-8", true)
|
209
|
+
pdf.set_font('freesans', '')
|
210
|
+
pdf.set_rtl(true)
|
211
|
+
pdf.set_temp_rtl('R')
|
212
|
+
pdf.add_page
|
213
|
+
|
214
|
+
margins = pdf.get_margins
|
215
|
+
w = pdf.get_string_width('OO') + margins['cell'] * 2
|
216
|
+
|
217
|
+
txt = "\xd7\x9c 000"
|
218
|
+
|
219
|
+
y1 = pdf.get_y
|
220
|
+
pdf.multi_cell(w, 0, txt)
|
221
|
+
pno = pdf.get_page
|
222
|
+
assert_equal pno, 1
|
223
|
+
y2 = pdf.get_y
|
224
|
+
h1 = y2 - y1
|
225
|
+
|
226
|
+
h2 = pdf.getStringHeight(w, txt)
|
227
|
+
assert_in_delta h1, h2, 0.01
|
228
|
+
|
229
|
+
line = pdf.get_num_lines(txt, w)
|
230
|
+
assert_equal line, 3
|
231
|
+
end
|
54
232
|
end
|
data/test/tcpdf_image_test.rb
CHANGED
@@ -69,4 +69,40 @@ class TcpdfTest < ActiveSupport::TestCase
|
|
69
69
|
}
|
70
70
|
assert_equal( err.message, 'TCPDF error: Missing image file: foo.png')
|
71
71
|
end
|
72
|
+
|
73
|
+
test "Image basic test" do
|
74
|
+
pdf = TCPDF.new
|
75
|
+
pdf.add_page
|
76
|
+
img_file = File.join(File.dirname(__FILE__), '..', 'logo_example.png')
|
77
|
+
|
78
|
+
result_img = pdf.image(img_file, 50, 0, 0, '', '', '', '', false, 300, '', true)
|
79
|
+
|
80
|
+
no = pdf.get_num_pages
|
81
|
+
assert_equal no, 1
|
82
|
+
end
|
83
|
+
|
84
|
+
test "Image fitonpage test 1" do
|
85
|
+
pdf = TCPDF.new
|
86
|
+
pdf.add_page
|
87
|
+
img_file = File.join(File.dirname(__FILE__), '..', 'logo_example.png')
|
88
|
+
|
89
|
+
result_img = pdf.image(img_file, 50, 140, 100, '', '', '', '', false, 300, '', true, false, 0, false, false, true)
|
90
|
+
|
91
|
+
no = pdf.get_num_pages
|
92
|
+
assert_equal no, 1
|
93
|
+
end
|
94
|
+
|
95
|
+
test "Image fitonpage test 2" do
|
96
|
+
pdf = TCPDF.new
|
97
|
+
pdf.add_page
|
98
|
+
img_file = File.join(File.dirname(__FILE__), '..', 'logo_example.png')
|
99
|
+
|
100
|
+
y = 100
|
101
|
+
w = pdf.get_page_width * 2
|
102
|
+
h = pdf.get_page_height
|
103
|
+
result_img = pdf.image(img_file, '', y, w, h, '', '', '', false, 300, '', true, false, 0, false, false, true)
|
104
|
+
|
105
|
+
no = pdf.get_num_pages
|
106
|
+
assert_equal no, 1
|
107
|
+
end
|
72
108
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rfpdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.17.
|
4
|
+
version: 1.17.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- NAITOH Jun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -48,6 +48,7 @@ extra_rdoc_files: []
|
|
48
48
|
files:
|
49
49
|
- CHANGELOG
|
50
50
|
- Gemfile
|
51
|
+
- README.md
|
51
52
|
- Rakefile
|
52
53
|
- lib/core/rmagick.rb
|
53
54
|
- lib/fonts/README.z
|