Added line cap and join settings for rect and curve

More forthcoming - these are proof-of-concept
This commit is contained in:
Andy Meneely
2015-06-08 14:17:46 -04:00
parent c1e410fe72
commit 12c5cd675b
8 changed files with 82 additions and 10 deletions
+2 -1
View File
@@ -166,10 +166,11 @@ module Squib
def curve(opts = {})
opts = needs(opts, [:range, :x1, :y1, :cx1, :cy1, :x2, :y2, :cx2, :cy2,
:layout, :fill_color, :stroke_color, :stroke_width])
draw = Args::Draw.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
opts[:range].each do |i|
@cards[i].curve(opts[:x1][i], opts[:y1][i], opts[:cx1][i], opts[:cy1][i],
opts[:x2][i], opts[:y2][i], opts[:cx2][i], opts[:cy2][i],
opts[:fill_color][i], opts[:stroke_color][i], opts[:stroke_width][i])
draw[i])
end
end
+1
View File
@@ -1,5 +1,6 @@
require 'squib/constants'
require 'squib/conf'
require 'ostruct'
module Squib
# @api private
+29 -1
View File
@@ -1,3 +1,4 @@
require 'cairo'
require 'squib/args/arg_loader'
module Squib
@@ -8,7 +9,12 @@ module Squib
include ArgLoader
def self.parameters
{ fill_color: '#0000', stroke_color: :black, stroke_width: 2.0 }
{ fill_color: '#0000',
stroke_color: :black,
stroke_width: 2.0,
join: :miter,
cap: 'butt'
}
end
def self.expanding_parameters
@@ -19,6 +25,28 @@ module Squib
[:stroke_width]
end
def validate_join(arg, _i)
case arg.to_s.strip.downcase
when 'miter'
Cairo::LINE_JOIN_MITER
when 'round'
Cairo::LINE_JOIN_ROUND
when 'bevel'
Cairo::LINE_JOIN_BEVEL
end
end
def validate_cap(arg, _i)
case arg.to_s.strip.downcase
when 'butt'
Cairo::LINE_CAP_BUTT
when 'round'
Cairo::LINE_CAP_ROUND
when 'square'
Cairo::LINE_CAP_SQUARE
end
end
end
end
+6 -2
View File
@@ -24,7 +24,8 @@ module Squib
:set_source, :scale, :render_rsvg_handle, :circle, :triangle, :line_to,
: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
:stroke_preserve, :target, :new_path, :fill_preserve, :close_path,
:set_line_join, :set_line_cap
# :nodoc:
# @api private
@@ -51,13 +52,16 @@ module Squib
# Convenience method for a common task
# @api private
def fill_n_stroke(fill_color, stroke_color, stroke_width)
def fill_n_stroke(fill_color, stroke_color, stroke_width, line_join = 0, line_cap = Cairo::LINE_CAP_BUTT)
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)
stroke
end
end
end
end
+3 -3
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)
cc.fill_n_stroke(draw.fill_color, draw.stroke_color, draw.stroke_width, draw.join)
end
end
@@ -68,11 +68,11 @@ module Squib
# :nodoc:
# @api private
def curve(x1, y1, cx1, cy1, x2, y2, cx2, cy2, fill_color, stroke_color, stroke_width)
def curve(x1, y1, cx1, cy1, x2, y2, cx2, cy2, draw)
use_cairo do |cc|
cc.move_to(x1, y1)
cc.curve_to(cx1, cy1, cx2, cy2, x2, y2)
cc.fill_n_stroke(fill_color, stroke_color, stroke_width)
cc.fill_n_stroke(draw.fill_color, draw.stroke_color, draw.stroke_width, draw.join, draw.cap)
end
end