Skip to content

Commit a9f23c3

Browse files
committed
add rounded_rect & polygon test
1 parent 87b77b6 commit a9f23c3

File tree

2 files changed

+87
-4
lines changed

2 files changed

+87
-4
lines changed

lib/rbpdf.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9432,9 +9432,9 @@ def Circle(x0, y0, r, angstr=0, angend=360, style='', line_style={}, fill_color=
94329432
# Draws a polygonal line
94339433
# [@param array :p] Points 0 to (:np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
94349434
# [@param string :style] Style of rendering. See the getPathPaintOperator() function for more information.
9435-
# [@param hash :line_style]
9435+
# [@param hash or array :line_style]
94369436
# Line style of polygon. Hash with keys among the following:
9437-
# * all: Line style of all lines. Array like for {@link SetLineStyle SetLineStyle}.
9437+
# * all: Line style of all lines. Hash like for {@link SetLineStyle SetLineStyle}.
94389438
# * 0 to (:np - 1): Line style of each line. Array like for {@link SetLineStyle SetLineStyle}.
94399439
# If a key is not present or is null, not draws the line. Default value is default line style (empty Hash).
94409440
# [@param array :fill_color] Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).
@@ -9451,9 +9451,9 @@ def PolyLine(p, style='', line_style={}, fill_color=[])
94519451
# Draws a polygon.
94529452
# [@param array :p] Points 0 to (np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1))
94539453
# [@param string :style] Style of rendering. See the getPathPaintOperator() function for more information.
9454-
# [@param hash :line_style]
9454+
# [@param hash or array :line_style]
94559455
# Line style of polygon. Hash with keys among the following:
9456-
# * all: Line style of all lines. Array like for {@link SetLineStyle SetLineStyle}.
9456+
# * all: Line style of all lines. Hash like for {@link SetLineStyle SetLineStyle}.
94579457
# * 0 to (:np - 1): Line style of each line. Array like for {@link SetLineStyle SetLineStyle}.
94589458
# If a key is not present or is null, not draws the line. Default value is default line style (empty Hash).
94599459
# [@param array :fill_color] Fill color. Format: array(GREY) or array(R,G,B) or array(C,M,Y,K). Default value: default color (empty array).

test/rbpdf_graphic_func_test.rb

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,87 @@ def getPageBuffer(page)
176176
assert_equal "S", content[before_size + 16]
177177
# line end
178178
end
179+
180+
test "rounded_rect basic test" do
181+
pdf = MYPDF.new
182+
pdf.add_page()
183+
page = pdf.get_page
184+
contents = pdf.getPageBuffer(page)
185+
before_size = contents.split("\n").size
186+
pdf.putshaders
187+
style = { 'L' => nil, 'T' => nil, 'R' => nil, 'B' => nil }
188+
pdf.rounded_rect(50, 255, 40, 30, 6.50)
189+
190+
content = []
191+
contents = pdf.getPageBuffer(page)
192+
contents.each_line {|line| content.push line.chomp }
193+
194+
assert_equal "160.16 119.06 m", content[before_size] # outPoint(x + rx, y)
195+
assert_equal "236.69 119.06 l", content[before_size + 1] # outLine(xc, y)
196+
assert_equal "246.87 119.06 255.12 110.81 255.12 100.63 c", content[before_size + 2] # outCurve(xc + (rx * myArc), yc - ry, xc + rx, yc - (ry * myArc), xc + rx, yc)
197+
assert_equal "255.12 52.44 l", content[before_size + 3] # outLine(x + w, yc)
198+
assert_equal "255.12 42.27 246.87 34.02 236.69 34.02 c", content[before_size + 4] # outCurve(xc + rx, yc + (ry * myArc), xc + (rx * myArc), yc + ry, xc, yc + ry)
199+
assert_equal "160.16 34.02 l", content[before_size + 5] # outLine(xc, y + h)
200+
assert_equal "149.98 34.02 141.73 42.27 141.73 52.44 c", content[before_size + 6] # outCurve(xc - (rx * myArc), yc + ry, xc - rx, yc + (ry * myArc), xc - rx, yc)
201+
assert_equal "141.73 100.63 l", content[before_size + 7] # outLine(x, yc)
202+
assert_equal "141.73 110.81 149.98 119.06 160.16 119.06 c", content[before_size + 8] # outCurve(xc - rx, yc - (ry * myArc), xc - (rx * myArc), yc - ry, xc, yc - ry)
203+
assert_equal "S", content[before_size + 9]
204+
end
205+
206+
test "polygon basic test" do
207+
pdf = MYPDF.new
208+
pdf.add_page()
209+
page = pdf.get_page
210+
contents = pdf.getPageBuffer(page)
211+
before_size = contents.split("\n").size
212+
pdf.putshaders
213+
style = { 'L' => nil, 'T' => nil, 'R' => nil, 'B' => nil }
214+
pdf.polygon([5,135,45,135,15,165])
215+
216+
content = []
217+
contents = pdf.getPageBuffer(page)
218+
contents.each_line {|line| content.push line.chomp }
219+
220+
# draw = true
221+
assert_equal "14.17 459.21 m", content[before_size] # outPoint(p[0], p[1])
222+
assert_equal "127.56 459.21 l", content[before_size + 1] # outLine(p[i], p[i + 1])
223+
assert_equal "42.52 374.17 l", content[before_size + 2] # outLine(p[i], p[i + 1])
224+
assert_equal "14.17 459.21 l", content[before_size + 3] # outLine(p[i], p[i + 1])
225+
assert_equal "127.56 459.21 l", content[before_size + 4] # outLine(p[i], p[i + 1])
226+
assert_equal "S", content[before_size + 5]
227+
end
228+
229+
test "polygon line_style test" do
230+
pdf = MYPDF.new
231+
pdf.add_page()
232+
page = pdf.get_page
233+
contents = pdf.getPageBuffer(page)
234+
before_size = contents.split("\n").size
235+
pdf.putshaders
236+
style = { 'L' => nil, 'T' => nil, 'R' => nil, 'B' => nil }
237+
style6 = {'width' => 0.5}
238+
pdf.polygon([5,135,45,135,15,165], 'D', [style6, 0, 0])
239+
240+
content = []
241+
contents = pdf.getPageBuffer(page)
242+
contents.each_line {|line| content.push line.chomp }
243+
# draw = true
244+
assert_equal "14.17 459.21 m", content[before_size] # outPoint(p[0], p[1])
245+
assert_equal "S", content[before_size + 1]
246+
247+
assert_equal "1.42 w", content[before_size + 2]
248+
assert_equal "14.17 459.21 m", content[before_size + 3] # outLine(p[i], p[i + 1])
249+
assert_equal "127.56 459.21 l", content[before_size + 4] # outLine(p[i], p[i + 1])
250+
assert_equal "S", content[before_size + 5]
251+
assert_equal "127.56 459.21 m", content[before_size + 6] # outLine(p[i], p[i + 1])
252+
assert_equal "S", content[before_size + 7]
253+
254+
assert_equal "1.42 w", content[before_size + 8]
255+
assert_equal "14.17 459.21 m", content[before_size + 9] # outLine(p[i], p[i + 1])
256+
assert_equal "127.56 459.21 l", content[before_size + 10] # outLine(p[i], p[i + 1])
257+
assert_equal "S", content[before_size + 11]
258+
259+
assert_equal "127.56 459.21 m", content[before_size + 12] # outLine(p[i], p[i + 1])
260+
assert_equal "S", content[before_size + 13]
261+
end
179262
end

0 commit comments

Comments
 (0)