Skip to content
Browse files

Hadean prawn is ready.

  • Loading branch information...
1 parent 78e15be commit 4a4facce347cb1402eba1281a5ce1cd800a4a149 Gregory Brown committed May 3, 2008
Showing with 50 additions and 4 deletions.
  1. +17 −3 lib/prawn/document/graphics.rb
  2. +33 −1 spec/graphics_spec.rb
View
20 lib/prawn/document/graphics.rb
@@ -152,24 +152,38 @@ def rectangle(point,width,height)
add_content("%.3f %.3f %.3f %.3f re" % [ x, y, width, height ])
end
+ # Sets the fill color. 6 digit HTML color codes are used.
+ #
+ # pdf.fill_color "f0ffc1"
+ #
def fill_color(color)
r,g,b = [color[0..1], color[2..3], color[4..5]].map { |e| e.to_i(16) }
add_content "%.3f %.3f %.3f rg" % [r / 255.0, g / 255.0, b / 255.0]
end
+ # Sets the line stroking color. 6 digit HTML color codes are used.
+ #
+ # pdf.stroke_color "cc2fde"
+ #
def stroke_color(color)
r,g,b = [color[0..1], color[2..3], color[4..5]].map { |e| e.to_i(16) }
add_content "%.3f %.3f %.3f RG" % [r / 255.0, g / 255.0, b / 255.0]
end
- def stroke #:nodoc:
+ # Strokes and closes the current path.
+ def stroke
add_content "S"
end
- def fill #:nodoc:
+ # Fills, strokes, and closes the current path.
+ def fill
add_content "b"
end
+ # Provides the following shortcuts:
+ #
+ # stroke_some_method(*args) #=> some_method(*args); stroke
+ # fill_some_method(*args) #=> some_method(*args); fill
def method_missing(id,*args,&block)
case(id.to_s)
when /^stroke_(.*)/
@@ -183,4 +197,4 @@ def method_missing(id,*args,&block)
end
end
-end
+end
View
34 spec/graphics_spec.rb
@@ -160,6 +160,38 @@ def append_curved_segment(*params)
end
end
+class ColorObserver
+ attr_reader :stroke_color, :fill_color
+
+ def set_rgb_color_for_stroking(*params)
+ @stroke_color = params
+ end
+
+ def set_rgb_color_for_nonstroking(*params)
+ @fill_color = params
+ end
+end
+
+describe "When setting colors" do
+
+ before(:each) { create_pdf }
+
+ it "should set stroke colors" do
+ @pdf.stroke_color "ffcccc"
+ colors = observer(ColorObserver)
+ # 100% red, 80% green, 80% blue
+ colors.stroke_color.should == [1.0, 0.8, 0.8]
+ end
+
+ it "should set fill colors" do
+ @pdf.fill_color "ccff00"
+ colors = observer(ColorObserver)
+ # 80% red, 100% green, 0% blue
+ colors.fill_color.should == [0.8,1.0,0]
+ end
+
+end
+
describe "When using painting shortcuts" do
before(:each) { create_pdf }
@@ -181,4 +213,4 @@ def append_curved_segment(*params)
lambda { @pdf.i_have_a_pretty_girlfriend_named_jia }.
should raise_error(NoMethodError)
end
-end
+end

0 comments on commit 4a4facc

Please sign in to comment.
Something went wrong with that request. Please try again.