diff --git a/lib/rbpdf.rb b/lib/rbpdf.rb index f082974..e47a294 100755 --- a/lib/rbpdf.rb +++ b/lib/rbpdf.rb @@ -9432,9 +9432,9 @@ def Circle(x0, y0, r, angstr=0, angend=360, style='', line_style={}, fill_color= # Draws a polygonal line # [@param array :p] Points 0 to (:np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1)) # [@param string :style] Style of rendering. See the getPathPaintOperator() function for more information. - # [@param hash :line_style] + # [@param hash or array :line_style] # Line style of polygon. Hash with keys among the following: - # * all: Line style of all lines. Array like for {@link SetLineStyle SetLineStyle}. + # * all: Line style of all lines. Hash like for {@link SetLineStyle SetLineStyle}. # * 0 to (:np - 1): Line style of each line. Array like for {@link SetLineStyle SetLineStyle}. # If a key is not present or is null, not draws the line. Default value is default line style (empty Hash). # [@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=[]) # Draws a polygon. # [@param array :p] Points 0 to (np - 1). Array with values (x0, y0, x1, y1,..., x(np-1), y(np - 1)) # [@param string :style] Style of rendering. See the getPathPaintOperator() function for more information. - # [@param hash :line_style] + # [@param hash or array :line_style] # Line style of polygon. Hash with keys among the following: - # * all: Line style of all lines. Array like for {@link SetLineStyle SetLineStyle}. + # * all: Line style of all lines. Hash like for {@link SetLineStyle SetLineStyle}. # * 0 to (:np - 1): Line style of each line. Array like for {@link SetLineStyle SetLineStyle}. # If a key is not present or is null, not draws the line. Default value is default line style (empty Hash). # [@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). diff --git a/test/rbpdf_graphic_func_test.rb b/test/rbpdf_graphic_func_test.rb index 8486413..58b5fd3 100644 --- a/test/rbpdf_graphic_func_test.rb +++ b/test/rbpdf_graphic_func_test.rb @@ -176,4 +176,87 @@ def getPageBuffer(page) assert_equal "S", content[before_size + 16] # line end end + + test "rounded_rect basic test" do + pdf = MYPDF.new + pdf.add_page() + page = pdf.get_page + contents = pdf.getPageBuffer(page) + before_size = contents.split("\n").size + pdf.putshaders + style = { 'L' => nil, 'T' => nil, 'R' => nil, 'B' => nil } + pdf.rounded_rect(50, 255, 40, 30, 6.50) + + content = [] + contents = pdf.getPageBuffer(page) + contents.each_line {|line| content.push line.chomp } + + assert_equal "160.16 119.06 m", content[before_size] # outPoint(x + rx, y) + assert_equal "236.69 119.06 l", content[before_size + 1] # outLine(xc, y) + 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) + assert_equal "255.12 52.44 l", content[before_size + 3] # outLine(x + w, yc) + 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) + assert_equal "160.16 34.02 l", content[before_size + 5] # outLine(xc, y + h) + 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) + assert_equal "141.73 100.63 l", content[before_size + 7] # outLine(x, yc) + 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) + assert_equal "S", content[before_size + 9] + end + + test "polygon basic test" do + pdf = MYPDF.new + pdf.add_page() + page = pdf.get_page + contents = pdf.getPageBuffer(page) + before_size = contents.split("\n").size + pdf.putshaders + style = { 'L' => nil, 'T' => nil, 'R' => nil, 'B' => nil } + pdf.polygon([5,135,45,135,15,165]) + + content = [] + contents = pdf.getPageBuffer(page) + contents.each_line {|line| content.push line.chomp } + + # draw = true + assert_equal "14.17 459.21 m", content[before_size] # outPoint(p[0], p[1]) + assert_equal "127.56 459.21 l", content[before_size + 1] # outLine(p[i], p[i + 1]) + assert_equal "42.52 374.17 l", content[before_size + 2] # outLine(p[i], p[i + 1]) + assert_equal "14.17 459.21 l", content[before_size + 3] # outLine(p[i], p[i + 1]) + assert_equal "127.56 459.21 l", content[before_size + 4] # outLine(p[i], p[i + 1]) + assert_equal "S", content[before_size + 5] + end + + test "polygon line_style test" do + pdf = MYPDF.new + pdf.add_page() + page = pdf.get_page + contents = pdf.getPageBuffer(page) + before_size = contents.split("\n").size + pdf.putshaders + style = { 'L' => nil, 'T' => nil, 'R' => nil, 'B' => nil } + style6 = {'width' => 0.5} + pdf.polygon([5,135,45,135,15,165], 'D', [style6, 0, 0]) + + content = [] + contents = pdf.getPageBuffer(page) + contents.each_line {|line| content.push line.chomp } + # draw = true + assert_equal "14.17 459.21 m", content[before_size] # outPoint(p[0], p[1]) + assert_equal "S", content[before_size + 1] + + assert_equal "1.42 w", content[before_size + 2] + assert_equal "14.17 459.21 m", content[before_size + 3] # outLine(p[i], p[i + 1]) + assert_equal "127.56 459.21 l", content[before_size + 4] # outLine(p[i], p[i + 1]) + assert_equal "S", content[before_size + 5] + assert_equal "127.56 459.21 m", content[before_size + 6] # outLine(p[i], p[i + 1]) + assert_equal "S", content[before_size + 7] + + assert_equal "1.42 w", content[before_size + 8] + assert_equal "14.17 459.21 m", content[before_size + 9] # outLine(p[i], p[i + 1]) + assert_equal "127.56 459.21 l", content[before_size + 10] # outLine(p[i], p[i + 1]) + assert_equal "S", content[before_size + 11] + + assert_equal "127.56 459.21 m", content[before_size + 12] # outLine(p[i], p[i + 1]) + assert_equal "S", content[before_size + 13] + end end