Browse Source

More work on the conversion

dev
Andy Meneely 12 years ago
parent
commit
093b2cf15b
  1. 16
      lib/squib/api/save.rb
  2. 2
      lib/squib/api/settings.rb
  3. 15
      lib/squib/api/shapes.rb
  4. 14
      lib/squib/api/text.rb
  5. 15
      lib/squib/constants.rb
  6. 2
      lib/squib/deck.rb
  7. 2
      lib/squib/graphics/shapes.rb
  8. 9
      lib/squib/input_helpers.rb

16
lib/squib/api/save.rb

@ -7,10 +7,10 @@ module Squib
# @param dir: the directory for the output to be sent to. Will be created if it doesn't exist # @param dir: the directory for the output to be sent to. Will be created if it doesn't exist
# @param format: the format that this will be rendered too. Options `:pdf, :png`. Array of both is allowed: `[:pdf, :png]` # @param format: the format that this will be rendered too. Options `:pdf, :png`. Array of both is allowed: `[:pdf, :png]`
# @param prefix: the prefix of the file name to be printed # @param prefix: the prefix of the file name to be printed
def save(range: :all, dir: "_output", format: :png, prefix: "card_") def save(opts = {})
format = [format].flatten opts = needs(opts, [:range, :creatable_dir, :formats, :prefix])
save_png(range: range, dir: dir, prefix: prefix) if format.include? :png save_png(opts) if opts[:format].include? :png
save_pdf if format.include? :pdf save_pdf(opts) if opts[:format].include? :pdf
end end
# Saves the range of cards to PNG # Saves the range of cards to PNG
@ -18,9 +18,11 @@ module Squib
# @param range: the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges} # @param range: the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
# @param dir: the directory for the output to be sent to. Will be created if it doesn't exist # @param dir: the directory for the output to be sent to. Will be created if it doesn't exist
# @param prefix: the prefix of the file name to be printed # @param prefix: the prefix of the file name to be printed
def save_png(range: :all, dir: "_output", prefix: 'card_') def save_png(opts = {})
range = rangeify(range); dir = dirify(dir, allow_create: true) opts = needs(opts,[:range, :creatable_dir, :prefix])
range.each { |i| @cards[i].save_png(i, dir, prefix) } opts[:range].each do |i|
@cards[i].save_png(i, opts[:dir], opts[:prefix])
end
end end
end end

2
lib/squib/api/settings.rb

@ -10,7 +10,7 @@ module Squib
# @api public # @api public
def hint(text: nil) def hint(text: nil)
text = nil if text == :off text = nil if text == :off
@text_hint = colorify(text, nillable: true) @text_hint = text
end end
end end

15
lib/squib/api/shapes.rb

@ -14,14 +14,13 @@ module Squib
# @param stroke_color: the color with which to stroke the outside of the rectangle # @param stroke_color: the color with which to stroke the outside of the rectangle
# @param stroke_width: the width of the outside stroke # @param stroke_width: the width of the outside stroke
# @api public # @api public
def rect(range: :all, x: 0, y: 0, width: 825, height: 1125, \ def rect(opts = {})
radius: nil, x_radius: 0, y_radius: 0, \ opts = needs(opts, [:range, :x, :y, :width, :height, :radius,
fill_color: '#0000', stroke_color: :black, stroke_width: 2.0) :fill_color, :stroke_color, :stroke_width])
range = rangeify(range) opts[:range].each do |i|
color = colorify(color) @cards[i].rect(opts[:x], opts[:y], opts[:width], opts[:height],
x_radius,y_radius = radiusify(radius, x_radius, y_radius) opts[:x_radius], opts[:y_radius],
range.each do |i| opts[:fill_color], opts[:stroke_color], opts[:stroke_width])
@cards[i].draw_rectangle(x, y, width, height, x_radius, y_radius, fill_color, stroke_color, stroke_width)
end end
end end

14
lib/squib/api/text.rb

@ -40,14 +40,12 @@ module Squib
# @option hint: show a text hint with the given color. Overrides global hints (see {Deck#hint}). # @option hint: show a text hint with the given color. Overrides global hints (see {Deck#hint}).
# @return [nil] Returns nothing # @return [nil] Returns nothing
# @api public # @api public
def text(range: :all, str: '', font: :use_set, x: 0, y: 0, **options) def text(opts = {})
range = rangeify(range) opts = needs(opts, [:range, :str, :font, :x, :y, :width, :height, :color, :wrap,
str = [str] * @cards.size unless str.respond_to? :each :fitxy, :align, :justify, :valign, :ellipsize, :hint])
font = fontify(font) str = [opts[:str]] * @cards.size unless str.respond_to? :each
color = colorify(options[:color], nillable: false) opts[:range].each do |i|
options[:hint] = colorify(options[:hint]) unless options[:hint].nil? @cards[i].text(str[i], opts[:font], opts[:x], opts[:y], opts[:color], opts) #TODO split this out
range.each do |i|
cards[i].text(str[i], font, x, y, color, options)
end end
end end

15
lib/squib/constants.rb

@ -4,11 +4,24 @@ module Squib
SYSTEM_DEFAULTS = { SYSTEM_DEFAULTS = {
:range => :all, :range => :all,
:color => :white, :color => :white,
:str => '',
:fill_color => '#0000',
:stroke_color => :black,
:font => 'Arial, Sans 36', :font => 'Arial, Sans 36',
:sheet => 0, :sheet => 0,
:x => 0, :x => 0,
:y => 0, :y => 0,
:alpha => 1.0 :fitxy => false,
:align => :left,
:valign => :top,
:justify => false,
:ellipsize => :end,
:width => :native,
:height => :native,
:alpha => 1.0,
:format => :png,
:dir => "_output",
:prefix => "card_"
} }
end end

2
lib/squib/deck.rb

@ -3,7 +3,6 @@ require 'squib/card'
require 'squib/input_helpers' require 'squib/input_helpers'
require 'squib/constants' require 'squib/constants'
# The project module # The project module
# #
# @api public # @api public
@ -15,7 +14,6 @@ module Squib
class Deck class Deck
include Enumerable include Enumerable
include Squib::InputHelpers include Squib::InputHelpers
include Squib::Constants
attr_reader :width, :height attr_reader :width, :height
attr_reader :cards attr_reader :cards
attr_reader :text_hint attr_reader :text_hint

2
lib/squib/graphics/shapes.rb

@ -1,7 +1,7 @@
module Squib module Squib
class Card class Card
def draw_rectangle(x, y, width, height, x_radius, y_radius, fill_color, stroke_color, stroke_width) def rect(x, y, width, height, x_radius, y_radius, fill_color, stroke_color, stroke_width)
cc = cairo_context cc = cairo_context
cc.rounded_rectangle(x, y, width, height, x_radius, y_radius) cc.rounded_rectangle(x, y, width, height, x_radius, y_radius)
cc.set_source_color(stroke_color) cc.set_source_color(stroke_color)

9
lib/squib/input_helpers.rb

@ -15,9 +15,16 @@ module Squib
opts = fontify(opts) if params.include? :font opts = fontify(opts) if params.include? :font
opts = radiusify(opts) if params.include? :radius opts = radiusify(opts) if params.include? :radius
opts = svgidify(opts) if params.include? :svgid opts = svgidify(opts) if params.include? :svgid
opts = formatify(opts) if params.include? :formats
end end
module_function :needs module_function :needs
def formatify(opts)
opts[:format] = [opts[:format]].flatten
opts
end
module_function :formatify
def rangeify (opts) def rangeify (opts)
range = opts[:range] range = opts[:range]
raise 'Range cannot be nil' if range.nil? raise 'Range cannot be nil' if range.nil?
@ -88,7 +95,7 @@ module Squib
end end
opts opts
end end
module_function :idify module_function :svgidify
def xyify def xyify
#TODO: Allow negative numbers that subtract from the card width & height. #TODO: Allow negative numbers that subtract from the card width & height.

Loading…
Cancel
Save