Rubocop: Trailing Whitespace
This commit is contained in:
+5
-5
@@ -8,15 +8,15 @@ require 'squib/deck'
|
||||
require 'squib/card'
|
||||
|
||||
module Squib
|
||||
|
||||
|
||||
# Access the internal logger that Squib uses. By default, Squib configure the logger to the WARN level
|
||||
# Use this to suppress or increase output levels.
|
||||
# Use this to suppress or increase output levels.
|
||||
# @example
|
||||
# Squib.logger.level = Logger::DEBUG #show waaaay more information than you probably need, unless you're a dev
|
||||
# Squib.logger.level = Logger::ERROR #basically turns it off
|
||||
#
|
||||
#
|
||||
# @return [Logger] the ruby logger
|
||||
# @api public
|
||||
# @api public
|
||||
def logger
|
||||
if @logger.nil?
|
||||
@logger = Logger.new(STDOUT);
|
||||
@@ -28,5 +28,5 @@ module Squib
|
||||
@logger
|
||||
end
|
||||
module_function :logger
|
||||
|
||||
|
||||
end
|
||||
@@ -1,6 +1,6 @@
|
||||
module Squib
|
||||
class Deck
|
||||
# Fills the background with the given color
|
||||
# Fills the background with the given color
|
||||
# @example
|
||||
# background color: :white
|
||||
#
|
||||
@@ -14,6 +14,6 @@ module Squib
|
||||
opts = needs(opts,[:range, :color])
|
||||
opts[:range].each { |i| @cards[i].background(opts[:color][i]) }
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
@@ -4,13 +4,13 @@ module Squib
|
||||
|
||||
# Pulls Excel data from `.xlsx` files into a column-based hash
|
||||
#
|
||||
# Pulls the data into a Hash of arrays based on the columns. First row is assumed to be the header row.
|
||||
# Pulls the data into a Hash of arrays based on the columns. First row is assumed to be the header row.
|
||||
# See the example `samples/excel.rb` in the [source repository](https://github.com/andymeneely/squib/tree/master/samples)
|
||||
#
|
||||
# @example
|
||||
# # Excel file looks like this:
|
||||
# # | h1 | h2 |
|
||||
# # ------------
|
||||
# # ------------
|
||||
# # | 1 | 2 |
|
||||
# # | 3 | 4 |
|
||||
# data = xlsx file: 'data.xlsx', sheet: 0
|
||||
@@ -41,11 +41,11 @@ module Squib
|
||||
module_function :xlsx
|
||||
|
||||
class Deck
|
||||
|
||||
|
||||
# Convenience call for Squib.xlsx
|
||||
def xlsx(opts = {})
|
||||
Squib.xlsx(opts)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -21,8 +21,8 @@ module Squib
|
||||
opts = needs(opts, [:range, :files, :x, :y, :alpha, :layout, :blend])
|
||||
Dir.chdir(@img_dir) do
|
||||
@progress_bar.start("Loading PNG(s)", opts[:range].size) do |bar|
|
||||
opts[:range].each do |i|
|
||||
@cards[i].png(opts[:file][i], opts[:x][i], opts[:y][i], opts[:alpha][i], opts[:blend][i])
|
||||
opts[:range].each do |i|
|
||||
@cards[i].png(opts[:file][i], opts[:x][i], opts[:y][i], opts[:alpha][i], opts[:blend][i])
|
||||
bar.increment
|
||||
end
|
||||
end
|
||||
@@ -32,7 +32,7 @@ module Squib
|
||||
# Renders an entire svg file at the given location. Uses the SVG-specified units and DPI to determine the pixel width and height.
|
||||
#
|
||||
# See {file:samples/load-images.rb samples/load-images.rb} and {file:samples/tgc-overlay.rb samples/tgc-overlay.rb} as examples.
|
||||
# @example
|
||||
# @example
|
||||
# svg 1..2, 'icon.svg', '#stone', x: 50, y:50
|
||||
#
|
||||
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
|
||||
@@ -54,8 +54,8 @@ module Squib
|
||||
@progress_bar.start("Loading SVG(s)", p[:range].size) do |bar|
|
||||
p[:range].each do |i|
|
||||
unless p[:force_id][i] && p[:id][i].to_s.empty?
|
||||
@cards[i].svg(p[:file][i], p[:id][i], p[:x][i], p[:y][i],
|
||||
p[:width][i], p[:height][i], p[:alpha][i], p[:blend][i])
|
||||
@cards[i].svg(p[:file][i], p[:id][i], p[:x][i], p[:y][i],
|
||||
p[:width][i], p[:height][i], p[:alpha][i], p[:blend][i])
|
||||
end
|
||||
bar.increment
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module Squib
|
||||
class Deck
|
||||
|
||||
|
||||
# Saves the given range of cards to either PNG or PDF
|
||||
#
|
||||
# @option opts [Enumerable] range (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
|
||||
@@ -16,8 +16,8 @@ module Squib
|
||||
save_pdf(opts) if opts[:format].include? :pdf
|
||||
self
|
||||
end
|
||||
|
||||
# Saves the given range of cards to a PNG
|
||||
|
||||
# Saves the given range of cards to a PNG
|
||||
#
|
||||
# @example
|
||||
# save range: 1..8, dir: '_pnp', prefix: 'bw_'
|
||||
@@ -31,7 +31,7 @@ module Squib
|
||||
def save_png(opts = {})
|
||||
opts = needs(opts,[:range, :creatable_dir, :prefix, :rotate])
|
||||
@progress_bar.start("Saving PNGs to #{opts[:dir]}/#{opts[:prefix]}*", @cards.size) do |bar|
|
||||
opts[:range].each do |i|
|
||||
opts[:range].each do |i|
|
||||
@cards[i].save_png(i, opts[:dir], opts[:prefix], opts[:rotate], opts[:angle])
|
||||
bar.increment
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module Squib
|
||||
class Deck
|
||||
|
||||
# Toggle hints globally.
|
||||
# Toggle hints globally.
|
||||
#
|
||||
# Text hints are rectangles around where the text will be laid out. They are intended to be temporary.
|
||||
# Setting a hint to nil or to :off will disable hints. @see samples/text.rb
|
||||
@@ -9,7 +9,7 @@ module Squib
|
||||
# hint text: :cyan
|
||||
# hint text: :cyan
|
||||
#
|
||||
# @param [String] text the color of the text hint. To turn off use :off. @see README.md
|
||||
# @param [String] text the color of the text hint. To turn off use :off. @see README.md
|
||||
# @return [nil] Returns nothing
|
||||
# @api public
|
||||
def hint(text: :off)
|
||||
@@ -17,7 +17,7 @@ module Squib
|
||||
end
|
||||
|
||||
# Sets various defaults for this deck. Defaults can be overriden by the commands themselves when that command supports it.
|
||||
# @example
|
||||
# @example
|
||||
# set font: 'Arial 26'
|
||||
# text 'blah' # in Arial 26
|
||||
# text 'blah24', font: 'Arial 24' # in Arial 24
|
||||
@@ -31,7 +31,7 @@ module Squib
|
||||
opts = needs(opts, [:font, :img_dir])
|
||||
@font = opts[:font][0] #was expanded - just need the first
|
||||
@img_dir = opts[:img_dir]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
+19
-19
@@ -1,11 +1,11 @@
|
||||
module Squib
|
||||
class Deck
|
||||
|
||||
|
||||
# Draw a rounded rectangle
|
||||
#
|
||||
# @example
|
||||
#
|
||||
# @example
|
||||
# rect x: 0, y: 0, width: 825, height: 1125, radius: 25
|
||||
#
|
||||
#
|
||||
# Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
||||
#
|
||||
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
|
||||
@@ -26,16 +26,16 @@ module Squib
|
||||
opts = needs(opts, [:range, :x, :y, :width, :height, :rect_radius, :x_radius, :y_radius,
|
||||
:fill_color, :stroke_color, :stroke_width, :layout])
|
||||
opts[:range].each do |i|
|
||||
@cards[i].rect(opts[:x][i], opts[:y][i], opts[:width][i], opts[:height][i],
|
||||
opts[:x_radius][i], opts[:y_radius][i],
|
||||
opts[:fill_color][i], opts[:stroke_color][i],
|
||||
@cards[i].rect(opts[:x][i], opts[:y][i], opts[:width][i], opts[:height][i],
|
||||
opts[:x_radius][i], opts[:y_radius][i],
|
||||
opts[:fill_color][i], opts[:stroke_color][i],
|
||||
opts[:stroke_width][i])
|
||||
end
|
||||
end
|
||||
|
||||
# Draw a circle centered at the given coordinates
|
||||
#
|
||||
# @example
|
||||
#
|
||||
# @example
|
||||
# circle x: 0, y: 0, radius: 100
|
||||
#
|
||||
# Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
||||
@@ -54,14 +54,14 @@ module Squib
|
||||
opts = needs(opts, [:range, :x, :y, :circle_radius, :layout,
|
||||
:fill_color, :stroke_color, :stroke_width])
|
||||
opts[:range].each do |i|
|
||||
@cards[i].circle(opts[:x][i], opts[:y][i], opts[:radius][i],
|
||||
@cards[i].circle(opts[:x][i], opts[:y][i], opts[:radius][i],
|
||||
opts[:fill_color][i], opts[:stroke_color][i], opts[:stroke_width][i])
|
||||
end
|
||||
end
|
||||
|
||||
# Draw a triangle using the given coordinates
|
||||
#
|
||||
# @example
|
||||
#
|
||||
# @example
|
||||
# triangle :x1 => 0, :y1 => 0, :x2 => 50, :y2 => 50, :x3 => 0, :y3 => 50
|
||||
#
|
||||
# Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
||||
@@ -82,17 +82,17 @@ module Squib
|
||||
opts = needs(opts, [:range, :x1, :y1, :x2, :y2, :x3, :y3, :layout,
|
||||
:fill_color, :stroke_color, :stroke_width])
|
||||
opts[:range].each do |i|
|
||||
@cards[i].triangle(opts[:x1][i], opts[:y1][i],
|
||||
opts[:x2][i], opts[:y2][i],
|
||||
opts[:x3][i], opts[:y3][i],
|
||||
opts[:fill_color][i], opts[:stroke_color][i],
|
||||
@cards[i].triangle(opts[:x1][i], opts[:y1][i],
|
||||
opts[:x2][i], opts[:y2][i],
|
||||
opts[:x3][i], opts[:y3][i],
|
||||
opts[:fill_color][i], opts[:stroke_color][i],
|
||||
opts[:stroke_width][i])
|
||||
end
|
||||
end
|
||||
|
||||
# Draw a line using the given coordinates
|
||||
#
|
||||
# @example
|
||||
#
|
||||
# @example
|
||||
# triangle :x1 => 0, :y1 => 0, :x2 => 50, :y2 => 50
|
||||
#
|
||||
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
|
||||
@@ -112,6 +112,6 @@ module Squib
|
||||
opts[:stroke_color][i], opts[:stroke_width][i])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
+10
-10
@@ -3,20 +3,20 @@ module Squib
|
||||
|
||||
# Renders a string at a given location, width, alignment, font, etc.
|
||||
#
|
||||
# Unix-like newlines are interpreted even on Windows.
|
||||
# Unix-like newlines are interpreted even on Windows.
|
||||
# See the {file:samples/text-options.rb samples/text.rb} for a lengthy example.
|
||||
#
|
||||
# @example
|
||||
# @example
|
||||
# text str: 'hello'
|
||||
# text str: 'hello', x: 50, y:50, align: center
|
||||
#
|
||||
#
|
||||
# Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
||||
#
|
||||
# @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 str [String, Array] ('') the string to be rendered. Must support `#to_s`. If the card responds to `#each`, it's mapped out one at a time across the cards.
|
||||
# @option opts font [String] (Arial 36 or whatever was set with `set`) the Font description string, including family, styles, and size.
|
||||
# (e.g. `'Arial bold italic 12'`)
|
||||
# For the official documentation, see the [Pango docs](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Pango%3A%3AFontDescription#style).
|
||||
# For the official documentation, see the [Pango docs](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Pango%3A%3AFontDescription#style).
|
||||
# This [description](http://www.pygtk.org/pygtk2reference/class-pangofontdescription.html) is also quite good.
|
||||
# See the {file:samples/text-options.rb samples/text.rb} as well.
|
||||
# @option opts font_size [Integer] (nil) an override of font string description, for scaling the font according to the size of the string
|
||||
@@ -27,15 +27,15 @@ module Squib
|
||||
# @option opts width [Integer, :native] (:native) the width of the box the string will be placed in. Stretches to the content by default.
|
||||
# @option opts height [Integer, :native] the height of the box the string will be placed in. Stretches to the content by default.
|
||||
# @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}
|
||||
# @option opts wrap [:none, :word, :char, :word_char, true, false] (:word_char) When height is set, determines the behavior of how the string wraps. The `:word_char` option will break at words, but then fall back to characters when the word cannot fit. #
|
||||
# @option opts wrap [:none, :word, :char, :word_char, true, false] (:word_char) When height is set, determines the behavior of how the string wraps. The `:word_char` option will break at words, but then fall back to characters when the word cannot fit. #
|
||||
# Options are `:none, :word, :char, :word_char`. Also: `true` is the same as `:word_char`, `false` is the same as `:none`. Default `:word_char`
|
||||
# @option opts spacing [Integer] (0) Adjust the spacing when the text is multiple lines. No effect when the text does not wrap.
|
||||
# @option opts align [:left, right, :center] (:left) The alignment of the text
|
||||
# @option opts justify [Boolean] (false) toggles whether or not the text is justified or not.
|
||||
# @option opts justify [Boolean] (false) toggles whether or not the text is justified or not.
|
||||
# @option opts valign [:top, :middle, :bottom] (:top) When width and height are set, align text vertically according to the ink extents of the text.
|
||||
# @option opts ellipsize [:none, :start, :middle, :end, true, false] (:end) When width and height are set, determines the behavior of overflowing text. Also: `true` maps to `:end` and `false` maps to `:none`. Default `:end`
|
||||
# @option opts angle [FixNum] (0) Rotation of the text in radians.
|
||||
# @option opts hint [String] (:nil) draw a rectangle around the text with the given color. Overrides global hints (see {Deck#hint}).
|
||||
# @option opts angle [FixNum] (0) Rotation of the text in radians.
|
||||
# @option opts hint [String] (:nil) draw a rectangle around the text with the given color. Overrides global hints (see {Deck#hint}).
|
||||
# @return [nil] Returns nothing
|
||||
# @api public
|
||||
def text(opts = {})
|
||||
@@ -44,8 +44,8 @@ module Squib
|
||||
opts[:range].each do |i|
|
||||
@cards[i].text(opts[:str][i], opts[:font][i], opts[:font_size][i], opts[:color][i],
|
||||
opts[:x][i], opts[:y][i], opts[:width][i], opts[:height][i],
|
||||
opts[:markup][i], opts[:justify][i], opts[:wrap][i],
|
||||
opts[:ellipsize][i], opts[:spacing][i], opts[:align][i],
|
||||
opts[:markup][i], opts[:justify][i], opts[:wrap][i],
|
||||
opts[:ellipsize][i], opts[:spacing][i], opts[:align][i],
|
||||
opts[:valign][i], opts[:hint][i], opts[:angle][i])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,8 +2,8 @@ module Squib
|
||||
class Deck
|
||||
|
||||
# Given inches, returns the number of pixels according to the deck's DPI.
|
||||
#
|
||||
# @example
|
||||
#
|
||||
# @example
|
||||
# inches(2.5) # 750 (for default Deck::dpi of 300)
|
||||
#
|
||||
# @param [Decimal] n, the number of inches
|
||||
|
||||
+4
-4
@@ -7,15 +7,15 @@ module Squib
|
||||
include Squib::InputHelpers
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
attr_reader :width, :height
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
attr_accessor :cairo_surface, :cairo_context
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
def initialize(deck, width, height)
|
||||
@deck=deck; @width=width; @height=height
|
||||
@cairo_surface = Cairo::ImageSurface.new(width,height)
|
||||
@@ -37,6 +37,6 @@ module Squib
|
||||
require 'squib/graphics/save_images'
|
||||
require 'squib/graphics/shapes'
|
||||
require 'squib/graphics/text'
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
@@ -6,9 +6,9 @@ module Squib
|
||||
|
||||
# Generate a new Squib project into a fresh directory.
|
||||
#
|
||||
# Provides conventions for using Git (you are using version control, right??).
|
||||
# Provides conventions for using Git (you are using version control, right??).
|
||||
# Also provides some basic layout and config files to start from, along with templates for instructions and other notes you don't want to forget.
|
||||
#
|
||||
#
|
||||
#
|
||||
# @example
|
||||
# squib new foo-blasters
|
||||
@@ -22,7 +22,7 @@ module Squib
|
||||
class New
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
def process(args)
|
||||
raise ArgumentError.new('Please specify a path.') if args.empty?
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
module Squib
|
||||
# Squib's defaults for when arguments are not specified in the command nor layouts.
|
||||
#
|
||||
#
|
||||
# @api public
|
||||
SYSTEM_DEFAULTS = {
|
||||
SYSTEM_DEFAULTS = {
|
||||
:align => :left,
|
||||
:alpha => 1.0,
|
||||
:angle => 0,
|
||||
@@ -40,7 +40,7 @@ module Squib
|
||||
:x1 => 100,
|
||||
:x2 => 150,
|
||||
:x3 => 100,
|
||||
:x_radius => 0,
|
||||
:x_radius => 0,
|
||||
:y => 0,
|
||||
:y1 => 100,
|
||||
:y2 => 150,
|
||||
@@ -49,9 +49,9 @@ module Squib
|
||||
}
|
||||
|
||||
# Squib's configuration defaults
|
||||
#
|
||||
#
|
||||
# @api public
|
||||
CONFIG_DEFAULTS = {
|
||||
CONFIG_DEFAULTS = {
|
||||
'custom_colors' => {},
|
||||
'dpi' => 300,
|
||||
'hint' => :none,
|
||||
@@ -59,8 +59,8 @@ module Squib
|
||||
'img_dir' => '.',
|
||||
}
|
||||
|
||||
# These are parameters that are intended to be "expanded" across
|
||||
# range if they are singletons.
|
||||
# These are parameters that are intended to be "expanded" across
|
||||
# range if they are singletons.
|
||||
#
|
||||
# For example, using a different font for each card, using one `text`
|
||||
#
|
||||
|
||||
+18
-18
@@ -19,37 +19,37 @@ module Squib
|
||||
include Squib::InputHelpers
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
attr_reader :width, :height
|
||||
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
attr_reader :cards
|
||||
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
attr_reader :text_hint
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
attr_reader :layout, :config
|
||||
|
||||
# Squib's constructor that sets the immutable properties.
|
||||
#
|
||||
# This is the starting point for Squib. In providing a block to the constructor, you have access to all of Deck's instance methods.
|
||||
# The documented methods in Deck are the ones intended for use by most users.
|
||||
# This is the starting point for Squib. In providing a block to the constructor, you have access to all of Deck's instance methods.
|
||||
# The documented methods in Deck are the ones intended for use by most users.
|
||||
# If your game requires multiple different sizes or orientations, I recommend using multiple `Squib::Deck`s in your `deck.rb`. You can modify the internals of `Squib::Deck` (e.g. `@cards`), but that's not recommended.
|
||||
# @example
|
||||
# @example
|
||||
# require 'squib'
|
||||
# Squib::Deck.new do
|
||||
# text str: 'Hello, World!'
|
||||
# end
|
||||
#
|
||||
# @param width: [Integer] the width of each card in pixels
|
||||
# @param height: [Integer] the height of each card in pixels
|
||||
# @param cards: [Integer] the number of cards in the deck
|
||||
# @param dpi: [Integer] the pixels per inch when rendering out to PDF or calculating using inches.
|
||||
# @param config: [String] the file used for global settings of this deck
|
||||
#
|
||||
# @param width [Integer] the width of each card in pixels
|
||||
# @param height [Integer] the height of each card in pixels
|
||||
# @param cards [Integer] the number of cards in the deck
|
||||
# @param dpi [Integer] the pixels per inch when rendering out to PDF or calculating using inches.
|
||||
# @param config [String] the file used for global settings of this deck
|
||||
# @param block [Block] the main body of the script.
|
||||
# @api public
|
||||
def initialize(width: 825, height: 1125, cards: 1, dpi: 300, config: 'config.yml', layout: nil, &block)
|
||||
@@ -77,7 +77,7 @@ module Squib
|
||||
end
|
||||
|
||||
# Iterates over each card in the deck
|
||||
#
|
||||
#
|
||||
# @api private
|
||||
def each(&block)
|
||||
@cards.each { |card| block.call(card) }
|
||||
@@ -129,10 +129,10 @@ module Squib
|
||||
parent_val + child_val.sub("+=",'').strip.to_f
|
||||
elsif child_val.to_s.strip.start_with?('-=')
|
||||
parent_val - child_val.sub("-=",'').strip.to_f
|
||||
else
|
||||
else
|
||||
child_val #child overrides parent when merging, no +=
|
||||
end
|
||||
end
|
||||
end
|
||||
h = h.merge(from_extends) do |key, older_sibling, younger_sibling|
|
||||
younger_sibling #when two siblings have the same entry, the "younger" (lower one) overrides
|
||||
end
|
||||
|
||||
@@ -2,13 +2,13 @@ module Squib
|
||||
class Card
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
def background(color)
|
||||
use_cairo do |cc|
|
||||
cc.set_source_color(color)
|
||||
cc.paint
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
module Squib
|
||||
|
||||
# Cache all pngs we've already loaded
|
||||
#
|
||||
#
|
||||
# :nodoc:
|
||||
# @api private
|
||||
def cache_load_image(file)
|
||||
@@ -13,7 +13,7 @@ module Squib
|
||||
class Card
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
def png(file, x, y, alpha, blend)
|
||||
return if file.nil? or file.eql? ''
|
||||
png = Squib.cache_load_image(file)
|
||||
@@ -25,7 +25,7 @@ module Squib
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
def svg(file, id, x, y, width, height, alpha, blend)
|
||||
Squib.logger.debug {"Rendering: #{file}, #{id} #{x}, #{y}, #{width}, #{height}, #{alpha}, #{blend}"}
|
||||
return if file.nil? or file.eql? ''
|
||||
|
||||
@@ -9,7 +9,7 @@ module Squib
|
||||
# @option opts file [String] the name of the PDF file to save. See {file:README.md#Specifying_Files Specifying Files}
|
||||
# @option opts dir [String] (_output) the directory to save to. Created if it doesn't exist.
|
||||
# @option opts margin [Integer] (75) the margin around the outside of the page
|
||||
# @option opts gap [Integer] (0) the space in pixels between the cards
|
||||
# @option opts gap [Integer] (0) the space in pixels between the cards
|
||||
# @option opts trim [Integer] (0) the space around the edge of each card to trim (e.g. to cut off the bleed margin for print-and-play)
|
||||
# @return [nil]
|
||||
# @api public
|
||||
@@ -39,7 +39,7 @@ module Squib
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
def trim(surface, trim, width, height)
|
||||
if trim > 0
|
||||
tmp = Cairo::ImageSurface.new(width-2*trim, height-2*trim)
|
||||
|
||||
@@ -2,7 +2,7 @@ module Squib
|
||||
class Card
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
def save_png(i, dir, prefix, do_rotate, angle)
|
||||
if [true, :clockwise, :counterclockwise].include?(do_rotate)
|
||||
surface = rotated_image(angle)
|
||||
@@ -24,7 +24,7 @@ module Squib
|
||||
rotated_cc.target
|
||||
end
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
def write_png(surface, i, dir, prefix)
|
||||
surface.write_to_png("#{dir}/#{prefix}#{i}.png")
|
||||
end
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
module Squib
|
||||
class Card
|
||||
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
def rect(x, y, width, height, x_radius, y_radius, fill_color, stroke_color, stroke_width)
|
||||
width=@width if width==:native; height=@height if height==:native
|
||||
use_cairo do |cc|
|
||||
@@ -17,7 +17,7 @@ module Squib
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
def circle(x, y, radius, fill_color, stroke_color, stroke_width)
|
||||
use_cairo do |cc|
|
||||
cc.circle(x, y, radius)
|
||||
@@ -31,7 +31,7 @@ module Squib
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
def triangle(x1, y1, x2, y2, x3, y3, fill_color, stroke_color, stroke_width)
|
||||
use_cairo do |cc|
|
||||
cc.triangle(x1, y1, x2, y2, x3, y3)
|
||||
@@ -45,7 +45,7 @@ module Squib
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
def line(x1, y1, x2, y2, stroke_color, stroke_width)
|
||||
use_cairo do |cc|
|
||||
cc.move_to(x1, y1)
|
||||
@@ -55,6 +55,6 @@ module Squib
|
||||
cc.stroke
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
+13
-13
@@ -4,7 +4,7 @@ module Squib
|
||||
class Card
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
def draw_text_hint(cc,x,y,layout, color,angle)
|
||||
color = @deck.text_hint if color.to_s.eql? 'off' and not @deck.text_hint.to_s.eql? 'off'
|
||||
return if color.to_s.eql? 'off' or color.nil?
|
||||
@@ -22,7 +22,7 @@ module Squib
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
def ellipsize(layout, ellipsize)
|
||||
unless ellipsize.nil?
|
||||
h = { :none => Pango::Layout::ELLIPSIZE_NONE,
|
||||
@@ -38,7 +38,7 @@ module Squib
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
def wrap(layout, wrap)
|
||||
unless wrap.nil?
|
||||
h = { :word => Pango::Layout::WRAP_WORD,
|
||||
@@ -54,7 +54,7 @@ module Squib
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
def align(layout, align)
|
||||
unless align.nil?
|
||||
h = { :left => Pango::ALIGN_LEFT,
|
||||
@@ -67,9 +67,9 @@ module Squib
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
def valign(cc, layout, x, y, valign)
|
||||
if layout.height > 0
|
||||
if layout.height > 0
|
||||
ink_extents = layout.extents[1]
|
||||
case valign
|
||||
when :middle
|
||||
@@ -81,7 +81,7 @@ module Squib
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
# @api private
|
||||
def setwh(layout, width, height)
|
||||
layout.width = width * Pango::SCALE unless width.nil? || width == :native
|
||||
layout.height = height * Pango::SCALE unless height.nil? || height == :native
|
||||
@@ -89,17 +89,17 @@ module Squib
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
def text(str, font, font_size, color,
|
||||
# @api private
|
||||
def text(str, font, font_size, color,
|
||||
x, y, width, height,
|
||||
markup, justify, wrap, ellipsize,
|
||||
markup, justify, wrap, ellipsize,
|
||||
spacing, align, valign, hint, angle)
|
||||
Squib.logger.debug {"Placing '#{str}'' with font '#{font}' @ #{x}, #{y}, color: #{color}, angle: #{angle} etc."}
|
||||
use_cairo do |cc|
|
||||
cc.set_source_color(color)
|
||||
cc.move_to(x,y)
|
||||
cc.rotate(angle)
|
||||
|
||||
|
||||
layout = cc.create_pango_layout
|
||||
font_desc = Pango::FontDescription.new(font)
|
||||
font_desc.size = font_size * Pango::SCALE unless font_size.nil?
|
||||
@@ -111,8 +111,8 @@ module Squib
|
||||
layout = ellipsize(layout, ellipsize)
|
||||
layout = align(layout, align)
|
||||
layout.justify = justify unless justify.nil?
|
||||
layout.spacing = spacing * Pango::SCALE unless spacing.nil?
|
||||
cc.update_pango_layout(layout)
|
||||
layout.spacing = spacing * Pango::SCALE unless spacing.nil?
|
||||
cc.update_pango_layout(layout)
|
||||
valign(cc, layout, x,y, valign)
|
||||
cc.update_pango_layout(layout) ; cc.show_pango_layout(layout)
|
||||
draw_text_hint(cc,x,y,layout,hint,angle)
|
||||
|
||||
+10
-10
@@ -12,7 +12,7 @@ module Squib
|
||||
opts = layoutify(opts) if params.include? :layout
|
||||
opts = Squib::SYSTEM_DEFAULTS.merge(opts)
|
||||
opts = expand_singletons(opts, params)
|
||||
opts = rangeify(opts) if params.include? :range
|
||||
opts = rangeify(opts) if params.include? :range
|
||||
opts = fileify(opts) if params.include? :file
|
||||
opts = fileify(opts, false) if params.include? :file_to_save
|
||||
opts = colorify(opts, true) if params.include? :nillable_color
|
||||
@@ -37,7 +37,7 @@ module Squib
|
||||
Squib::EXPANDING_PARAMS.each_pair do |param_name, api_param|
|
||||
if needed_params.include? param_name
|
||||
unless opts[api_param].respond_to?(:each)
|
||||
opts[api_param] = [opts[api_param]] * @cards.size
|
||||
opts[api_param] = [opts[api_param]] * @cards.size
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -50,8 +50,8 @@ module Squib
|
||||
# :nodoc:
|
||||
# @api private
|
||||
def layoutify(opts)
|
||||
unless opts[:layout].respond_to?(:each)
|
||||
opts[:layout] = [opts[:layout]] * @cards.size
|
||||
unless opts[:layout].respond_to?(:each)
|
||||
opts[:layout] = [opts[:layout]] * @cards.size
|
||||
end
|
||||
opts[:layout].each_with_index do |layout, i|
|
||||
unless layout.nil?
|
||||
@@ -61,7 +61,7 @@ module Squib
|
||||
opts[key.to_sym] = [] if opts[key.to_sym].nil?
|
||||
opts[key.to_sym][i] ||= entry[key] #don't override if it's already there
|
||||
end
|
||||
else
|
||||
else
|
||||
Squib.logger.warn ("Layout entry '#{layout}' does not exist." )
|
||||
end
|
||||
end
|
||||
@@ -99,7 +99,7 @@ module Squib
|
||||
# @api private
|
||||
def fileify(opts, file_must_exist=true)
|
||||
[opts[:file]].flatten.each do |file|
|
||||
if file_must_exist and !File.exists?(file)
|
||||
if file_must_exist and !File.exists?(file)
|
||||
raise "File #{File.expand_path(file)} does not exist!"
|
||||
end
|
||||
end
|
||||
@@ -114,7 +114,7 @@ module Squib
|
||||
if allow_create
|
||||
Squib.logger.warn {"Dir #{opts[key]} does not exist, creating it."}
|
||||
Dir.mkdir opts[key]
|
||||
return opts
|
||||
return opts
|
||||
else
|
||||
raise "'#{opts[key]}' does not exist!"
|
||||
end
|
||||
@@ -145,14 +145,14 @@ module Squib
|
||||
opts[:font][i] = Squib::SYSTEM_DEFAULTS[:default_font] if font == :default
|
||||
end
|
||||
Squib.logger.debug {"After fontify: #{opts}"}
|
||||
opts
|
||||
opts
|
||||
end
|
||||
module_function :fontify
|
||||
module_function :fontify
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
def radiusify(opts)
|
||||
opts[:radius].each_with_index do |radius, i|
|
||||
opts[:radius].each_with_index do |radius, i|
|
||||
unless radius.nil?
|
||||
opts[:x_radius][i] = radius
|
||||
opts[:y_radius][i] = radius
|
||||
|
||||
@@ -25,10 +25,10 @@ module Squib
|
||||
|
||||
def start(title="", total=100, &block)
|
||||
if @enabled
|
||||
@bar = ProgressBar.create(title: title, total: total, format: '%t <%B> %p%% %a')
|
||||
@bar = ProgressBar.create(title: title, total: total, format: '%t <%B> %p%% %a')
|
||||
yield(@bar)
|
||||
@bar.finish
|
||||
else
|
||||
else
|
||||
yield(Squib::DoNothing.new)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'squib'
|
||||
|
||||
Squib::Deck.new(cards: 3, layout: 'layout.yml') do
|
||||
Squib::Deck.new(cards: 3, layout: 'layout.yml') do
|
||||
text str: "Hello, World!"
|
||||
save format: :png
|
||||
end
|
||||
@@ -3,8 +3,8 @@ module Squib
|
||||
# The next version to be released.
|
||||
# Uses semantic versioning: http://semver.org/
|
||||
#
|
||||
# Most of the time this is in the alpha of the next release.
|
||||
# Most of the time this is in the alpha of the next release.
|
||||
# e.g. v0.0.5a is on its way to becoming v0.0.5
|
||||
#
|
||||
#
|
||||
VERSION = "0.0.5a"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user