0
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
0
-class LineDrawingObserver
0
- attr_accessor :points, :strokes
0
- def append_line(*params)
0
- def begin_new_subpath(*params)
0
describe "When drawing a line" do
0
before(:each) { create_pdf }
0
@@ -26,7 +9,7 @@ describe "When drawing a line" do
0
it "should draw a line from (100,600) to (100,500)" do
0
@pdf.line([100,600],[100,500])
0
- line_drawing =
observer(LineDrawingObserver)
0
+ line_drawing =
PDF::Inspector::Graphics::Line.analyze(@pdf.render)
0
line_drawing.points.should == [[100,600],[100,500]]
0
@@ -36,24 +19,17 @@ describe "When drawing a line" do
0
@pdf.line(100,600,100,500)
0
@pdf.line(75,100,50,125)
0
- line_drawing =
observer(LineDrawingObserver)
0
+ line_drawing =
PDF::Inspector::Graphics::Line.analyze(@pdf.render)
0
line_drawing.points.should ==
0
[[100.0, 600.0], [100.0, 500.0], [75.0, 100.0], [50.0, 125.0]]
0
- def set_line_width(params)
0
it "should properly set line width" do
0
- line = observer(LineWidthReader)
0
- line.width.should == 10
0
+ line = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
0
+ line.widths.first.should == 10
0
describe "(Horizontally)" do
0
@@ -61,7 +37,7 @@ describe "When drawing a line" do
0
@pdf = Prawn::Document.new
0
@pdf.horizontal_line(100,150)
0
- @line =
observer(LineDrawingObserver) 0
+ @line =
PDF::Inspector::Graphics::Line.analyze(@pdf.render)0
it "should draw from [x1,pdf.y],[x2,pdf.y]" do
0
@@ -80,23 +56,12 @@ describe "When drawing a polygon" do
0
it "should draw each line passed to polygon()" do
0
@pdf.polygon([100,500],[100,400],[200,400])
0
- line_drawing =
observer(LineDrawingObserver)0
+ line_drawing =
PDF::Inspector::Graphics::Line.analyze(@pdf.render) 0
line_drawing.points.should == [[100,500],[100,400],[200,400],[100,500]]
0
-class RectangleDrawingObserver
0
- attr_reader :point, :width, :height
0
- def append_rectangle(*params)
0
describe "When drawing a rectangle" do
0
before(:each) { create_pdf }
0
@@ -104,33 +69,16 @@ describe "When drawing a rectangle" do
0
it "should use a point, width, and height for coords" do
0
@pdf.rectangle [200,200], 50, 100
0
- rectangle = observer(RectangleDrawingObserver)
0
+ rectangles = PDF::Inspector::Graphics::Rectangle.
0
+ analyze(@pdf.render).rectangles
0
# PDF uses bottom left corner
0
- rectangle.point.should == [200,100]
0
- rectangle.width.should == 50
0
- rectangle.height.should == 100
0
+ rectangles[0][:point].should == [200,100]
0
+ rectangles[0][:width].should == 50
0
+ rectangles[0][:height].should == 100
0
- def begin_new_subpath(*params)
0
- def append_curved_segment(*params)
0
describe "When drawing a curve" do
0
@@ -139,13 +87,13 @@ describe "When drawing a curve" do
0
it "should draw a bezier curve from 50,50 to 100,100" do
0
@pdf.curve_to [100,100],:bounds => [[20,90], [90,70]]
0
- curve =
observer(CurveObserver) 0
+ curve =
PDF::Inspector::Graphics::Curve.analyze(@pdf.render)0
curve.coords.should == [50.0, 50.0, 20.0, 90.0, 90.0, 70.0, 100.0, 100.0]
0
it "should draw a bezier curve from 100,100 to 50,50" do
0
@pdf.curve [100,100], [50,50], :bounds => [[20,90], [90,75]]
0
- curve =
observer(CurveObserver)0
+ curve =
PDF::Inspector::Graphics::Curve.analyze(@pdf.render) 0
curve.coords.should == [100.0, 100.0, 20.0, 90.0, 90.0, 75.0, 50.0, 50.0]
0
@@ -155,7 +103,7 @@ describe "When drawing an ellipse" do
0
@pdf.ellipse_at [100,100], 25, 50
0
- @curve =
observer(CurveObserver) 0
+ @curve =
PDF::Inspector::Graphics::Curve.analyze(@pdf.render) 0
it "should move the pointer to the center of the ellipse after drawing" do
0
@@ -169,7 +117,7 @@ describe "When drawing a circle" do
0
@pdf.circle_at [100,100], :radius => 25
0
@pdf.ellipse_at [100,100], 25, 25
0
- @curve =
observer(CurveObserver) 0
+ @curve =
PDF::Inspector::Graphics::Curve.analyze(@pdf.render) 0
it "should stroke the same path as the equivalent ellipse" do
0
@@ -178,66 +126,45 @@ describe "When drawing a circle" do
0
- attr_reader :stroke_color, :fill_color, :stroke_color_count,
0
- @stroke_color_count = 0
0
- def set_rgb_color_for_stroking(*params)
0
- @stroke_color_count += 1
0
- @stroke_color = params
0
- def set_rgb_color_for_nonstroking(*params)
0
- @fill_color_count += 1
0
describe "When setting colors" do
0
before(:each) { create_pdf }
0
it "should set stroke colors" do
0
@pdf.stroke_color "ffcccc"
0
- colors =
observer(ColorObserver)
0
+ colors =
PDF::Inspector::Graphics::Color.analyze(@pdf.render)
0
# 100% red, 80% green, 80% blue
0
colors.stroke_color.should == [1.0, 0.8, 0.8]
0
it "should set fill colors" do
0
@pdf.fill_color "ccff00"
0
- colors =
observer(ColorObserver)0
+ colors =
PDF::Inspector::Graphics::Color.analyze(@pdf.render) 0
# 80% red, 100% green, 0% blue
0
colors.fill_color.should == [0.8,1.0,0]
0
it "should reset the colors on each new page if they have been defined" do
0
@pdf.fill_color "ccff00"
0
- colors =
observer(ColorObserver)0
+ colors =
PDF::Inspector::Graphics::Color.analyze(@pdf.render) 0
colors.fill_color_count.should == 2
0
colors.stroke_color_count.should == 1
0
@pdf.stroke_color "ff00cc"
0
- colors =
observer(ColorObserver)0
+ colors =
PDF::Inspector::Graphics::Color.analyze(@pdf.render) 0
colors.fill_color_count.should == 3
0
colors.stroke_color_count.should == 3
0
- colors =
observer(ColorObserver)0
+ colors =
PDF::Inspector::Graphics::Color.analyze(@pdf.render) 0
colors.fill_color_count.should == 4
0
colors.stroke_color_count.should == 4
0
colors.fill_color.should == [0.8,1.0,0.0]
0
colors.stroke_color.should == [1.0,0.0,0.8]
0
@@ -262,4 +189,4 @@ describe "When using painting shortcuts" do
0
lambda { @pdf.i_have_a_pretty_girlfriend_named_jia }.
0
should.raise(NoMethodError)
0
\ No newline at end of file