Add dash option to drawing operations

Currently only impacts rect, but it will impact others with the new design shortly
This commit is contained in:
Andy Meneely
2015-06-08 15:26:33 -04:00
parent 12c5cd675b
commit 8a7841d64f
8 changed files with 47 additions and 7 deletions
+3
View File
@@ -22,6 +22,8 @@ module Squib
# @option opts fill_color [String] ('#0000') the color with which to fill the rectangle. See {file:README.md#Specifying_Colors___Gradients Specifying Colors & Gradients}
# @option opts stroke_color [String] (:black) the color with which to stroke the outside of the rectangle. {file:README.md#Specifying_Colors___Gradients Specifying Colors & Gradients}
# @option opts stroke_width [Decimal] (2.0) the width of the outside stroke. Supports Unit Conversion, see {file:README.md#Units Units}.
# @option opts join [String] ('miter') how corners will be drawn on stroke. Options are 'miter', 'bevel', or 'round'. Note that this is separate from the x_radius and y_radius of the rounded rectangle. Becomes more obvious with wider strokes.
# @option opts dash [String] ('') define a dash pattern for the stroke. Provide a string with space-separated numbers that define the pattern of on-and-off alternating strokes, measured in pixels by defautl. Supports Unit Conversion, see {file:README.md#Units Units} (e.g. `'0.02in 0.02in'`).
# @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:README.md#Custom_Layouts Custom Layouts}
# @return [nil] intended to be void
# @api public
@@ -160,6 +162,7 @@ module Squib
# @option opts stroke_color [String] (:black) the color with which to stroke the line. See {file:README.md#Specifying_Colors___Gradients Specifying Colors & Gradients}.
# @option opts stroke_width [Decimal] (2.0) the width of the outside stroke. Supports Unit Conversion, see {file:README.md#Units Units}.
# @option opts fill_color [String] ('#0000') the color with which to fill the triangle. See {file:README.md#Specifying_Colors___Gradients Specifying Colors & Gradients}
# @option opts cap [String] ('butt') how the end of the line is drawn. Options are "square", "butt", and "round"
# @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:README.md#Custom_Layouts Custom Layouts}
# @return [nil] intended to be void
# @api public
+1
View File
@@ -12,6 +12,7 @@ module Squib
# Main class invoked by the client (i.e. api/ methods)
def load!(args, expand_by: 1, layout: {}, dpi: 300)
@dpi = dpi
set_attributes(args: args)
expand(by: expand_by)
layout_args = prep_layout_args(args[:layout], expand_by: expand_by)
+8 -1
View File
@@ -13,7 +13,8 @@ module Squib
stroke_color: :black,
stroke_width: 2.0,
join: :miter,
cap: 'butt'
cap: 'butt',
dash: ''
}
end
@@ -47,6 +48,12 @@ module Squib
end
end
def validate_dash(arg, _i)
arg.to_s.split.collect do |x|
convert_unit(x, @dpi).to_f
end
end
end
end
+5 -2
View File
@@ -25,7 +25,7 @@ module Squib
:operator=, :show_page, :clip, :transform, :mask, :create_pango_layout,
:antialias=, :curve_to, :matrix, :matrix=, :identity_matrix, :pango_layout_path,
:stroke_preserve, :target, :new_path, :fill_preserve, :close_path,
:set_line_join, :set_line_cap
:set_line_join, :set_line_cap, :set_dash
# :nodoc:
# @api private
@@ -52,13 +52,16 @@ module Squib
# Convenience method for a common task
# @api private
def fill_n_stroke(fill_color, stroke_color, stroke_width, line_join = 0, line_cap = Cairo::LINE_CAP_BUTT)
def fill_n_stroke(fill_color, stroke_color, stroke_width,
line_join = 0, line_cap = Cairo::LINE_CAP_BUTT,
dash = [])
set_source_squibcolor(fill_color)
fill_preserve
set_source_squibcolor(stroke_color)
set_line_width(stroke_width)
set_line_join(line_join)
set_line_cap(line_cap)
set_dash(dash)
stroke
end
+1 -1
View File
@@ -7,7 +7,7 @@ module Squib
def rect(box, draw)
use_cairo do |cc|
cc.rounded_rectangle(box.x, box.y, box.width, box.height, box.x_radius, box.y_radius)
cc.fill_n_stroke(draw.fill_color, draw.stroke_color, draw.stroke_width, draw.join)
cc.fill_n_stroke(draw.fill_color, draw.stroke_color, draw.stroke_width, draw.join, draw.cap, draw.dash)
end
end