Updating regression tests, renamed bezier curve params
This commit is contained in:
+11
-7
@@ -116,20 +116,24 @@ module Squib
|
||||
# Draw a curve using the given coordinates
|
||||
#
|
||||
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
|
||||
# @option opts x1 [Integer] (0) the x-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
|
||||
# @option opts y1 [Integer] (0) the y-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
|
||||
# @option opts x2 [Integer] (50) the x-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
|
||||
# @option opts y2 [Integer] (50) the y-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
|
||||
# @option opts x1 [Integer] (0) the x-coordinate of the first endpoint. Supports Unit Conversion, see {file:README.md#Units Units}.
|
||||
# @option opts y1 [Integer] (0) the y-coordinate of the first endpoint. Supports Unit Conversion, see {file:README.md#Units Units}.
|
||||
# @option opts x2 [Integer] (50) the x-coordinate of the second endpoint. Supports Unit Conversion, see {file:README.md#Units Units}.
|
||||
# @option opts y2 [Integer] (50) the y-coordinate of the second endpoint. Supports Unit Conversion, see {file:README.md#Units Units}.
|
||||
# @option opts cx1 [Integer] (0) the x-coordinate of the first control point. Supports Unit Conversion, see {file:README.md#Units Units}.
|
||||
# @option opts cy1 [Integer] (0) the y-coordinate of the first control point. Supports Unit Conversion, see {file:README.md#Units Units}.
|
||||
# @option opts cx2 [Integer] (50) the x-coordinate of the second control point. Supports Unit Conversion, see {file:README.md#Units Units}.
|
||||
# @option opts cy2 [Integer] (50) the y-coordinate of the second control point. Supports Unit Conversion, see {file:README.md#Units Units}.
|
||||
# @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}.
|
||||
# @return [nil] intended to be void
|
||||
# @api public
|
||||
def curve(opts = {})
|
||||
opts = needs(opts, [:range, :x1, :y1, :dx1, :dy1, :x2, :y2, :dx2, :dy2,
|
||||
opts = needs(opts, [:range, :x1, :y1, :cx1, :cy1, :x2, :y2, :cx2, :cy2,
|
||||
:layout, :fill_color, :stroke_color, :stroke_width])
|
||||
opts[:range].each do |i|
|
||||
@cards[i].curve(opts[:x1][i], opts[:y1][i], opts[:dx1][i], opts[:dy1][i],
|
||||
opts[:x2][i], opts[:y2][i], opts[:dx2][i], opts[:dy2][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])
|
||||
end
|
||||
end
|
||||
|
||||
+16
-14
@@ -10,14 +10,14 @@ module Squib
|
||||
:color => :black,
|
||||
:columns => 5,
|
||||
:count_format => '%02d',
|
||||
:cx1 => 0,
|
||||
:cx2 => 0,
|
||||
:cy1 => 0,
|
||||
:cy2 => 0,
|
||||
:default_font => 'Arial 36',
|
||||
:dir => '_output',
|
||||
:dx => 0, # delta
|
||||
:dy => 0, # delta
|
||||
:dx1 => 0,
|
||||
:dx2 => 0,
|
||||
:dy1 => 0,
|
||||
:dy2 => 0,
|
||||
:ellipsize => :end,
|
||||
:face => :left,
|
||||
:fill_color => '#0000',
|
||||
@@ -103,10 +103,12 @@ module Squib
|
||||
:blend => :blend,
|
||||
:circle_radius => :radius,
|
||||
:color => :color,
|
||||
:dx1 => :dx1,
|
||||
:dx2 => :dx2,
|
||||
:dy1 => :dy1,
|
||||
:dy2 => :dy2,
|
||||
:cx1 => :cx1,
|
||||
:cx2 => :cx2,
|
||||
:cy1 => :cy1,
|
||||
:cy2 => :cy2,
|
||||
:dx => :dx,
|
||||
:dy => :dy,
|
||||
:ellipsize => :ellipsize,
|
||||
:files => :file,
|
||||
:fill_color => :fill_color,
|
||||
@@ -149,12 +151,12 @@ module Squib
|
||||
# value: the user-facing API key (e.g. radius: '1in')
|
||||
UNIT_CONVERSION_PARAMS = {
|
||||
:circle_radius => :radius,
|
||||
:dx => 0, # delta
|
||||
:dy => 0, # delta
|
||||
:dx1 => 0,
|
||||
:dx2 => 0,
|
||||
:dy1 => 0,
|
||||
:dy2 => 0,
|
||||
:cx1 => :cx1,
|
||||
:cx2 => :cx2,
|
||||
:cy1 => :cy1,
|
||||
:cy2 => :cy2,
|
||||
:dx => :dx, # delta
|
||||
:dy => :dx, # delta
|
||||
:gap => :gap,
|
||||
:height => :height,
|
||||
:margin => :margin,
|
||||
|
||||
@@ -60,15 +60,15 @@ module Squib
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
def curve(x1, y1, dx1, dy1, x2, y2, dx2, dy2, fill_color, stroke_color, stroke_width)
|
||||
def curve(x1, y1, cx1, cy1, x2, y2, cx2, cy2, fill_color, stroke_color, stroke_width)
|
||||
use_cairo do |cc|
|
||||
cc.move_to(x1, y1)
|
||||
cc.curve_to(dx1, dy1, dx2, dy2, x2, y2)
|
||||
cc.curve_to(cx1, cy1, cx2, cy2, x2, y2)
|
||||
cc.set_line_width(stroke_width)
|
||||
cc.set_source_squibcolor(stroke_color)
|
||||
cc.stroke
|
||||
cc.move_to(x1, y1)
|
||||
cc.curve_to(dx1, dy1, dx2, dy2, x2, y2)
|
||||
cc.move_to(x1, y1)
|
||||
cc.curve_to(cx1, cy1, cx2, cy2, x2, y2)
|
||||
cc.set_source_squibcolor(fill_color)
|
||||
cc.fill
|
||||
end
|
||||
|
||||
+13
-19
@@ -100,10 +100,11 @@ module Squib
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
def process_embeds(embed, str, layout, vertical_start)
|
||||
return unless embed.rules.any?
|
||||
def process_embeds(embed, str, layout)
|
||||
return [] unless embed.rules.any?
|
||||
layout.markup = str
|
||||
clean_str = layout.text
|
||||
draw_calls = []
|
||||
while (key = next_embed(embed.rules.keys, clean_str)) != nil
|
||||
rule = embed.rules[key]
|
||||
spacing = rule[:width] * Pango::SCALE
|
||||
@@ -121,18 +122,10 @@ module Squib
|
||||
Squib.logger.warn "Center- or right-aligned text do not always embed properly. This is a known issue with a workaround. See https://github.com/andymeneely/squib/issues/46"
|
||||
end
|
||||
x = Pango.pixels(rect.x + (letter_width / 2)) + rule[:dx]
|
||||
y = Pango.pixels(rect.y) + rule[:dy] + vertical_start
|
||||
puts <<-EOS
|
||||
Embed: #{key}
|
||||
Index: #{index}
|
||||
Spacing: #{spacing} or #{Pango.pixels(spacing)}px
|
||||
Markup string: #{str}
|
||||
index_to_pos: #{rect.x},#{rect.y} or #{Pango.pixels(rect.x)},#{Pango.pixels(rect.y)}
|
||||
Computed x,y: #{x},#{y}
|
||||
=================
|
||||
EOS
|
||||
rule[:draw].call(self, x, y)
|
||||
y = Pango.pixels(rect.y) + rule[:dy]
|
||||
draw_calls << {x: x, y: y, draw: rule[:draw]} # defer drawing until we've valigned
|
||||
end
|
||||
return draw_calls
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
@@ -154,8 +147,8 @@ module Squib
|
||||
font_desc.size = font_size * Pango::SCALE unless font_size.nil?
|
||||
layout = cc.create_pango_layout
|
||||
layout.font_description = font_desc
|
||||
layout.text = str
|
||||
layout.markup = str if markup
|
||||
layout.text = str
|
||||
layout.markup = str if markup
|
||||
|
||||
set_wh!(layout, width, height)
|
||||
set_wrap!(layout, wrap)
|
||||
@@ -166,15 +159,16 @@ module Squib
|
||||
layout.spacing = spacing * Pango::SCALE unless spacing.nil?
|
||||
cc.update_pango_layout(layout)
|
||||
|
||||
embed_draws = process_embeds(embed, str, layout)
|
||||
|
||||
vertical_start = compute_valign(layout, valign)
|
||||
|
||||
process_embeds(embed, str, layout, vertical_start)
|
||||
|
||||
cc.move_to(0, vertical_start)
|
||||
|
||||
cc.update_pango_layout(layout)
|
||||
|
||||
cc.show_pango_layout(layout)
|
||||
draw_text_hint(cc,x,y,layout,hint,angle)
|
||||
embed_draws.each { |ed| ed[:draw].call(self, ed[:x], ed[:y] + vertical_start) }
|
||||
draw_text_hint(cc, x, y, layout, hint, angle)
|
||||
extents = { width: layout.extents[1].width / Pango::SCALE,
|
||||
height: layout.extents[1].height / Pango::SCALE }
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user