👮 fix space after comma
parent
a768561e91
commit
8a9552126c
2
Rakefile
2
Rakefile
|
|
@ -10,7 +10,7 @@ task default: [:install, :spec]
|
|||
# Useful for hooking up with SublimeText.
|
||||
# e.g. rake sample[basic.rb]
|
||||
desc 'Run a specific sample'
|
||||
task :run,[:file] => :install do |t, args|
|
||||
task :run, [:file] => :install do |t, args|
|
||||
args.with_defaults(file: 'basic.rb')
|
||||
Dir.chdir('samples') do
|
||||
args[:file] << ".rb" unless args[:file].end_with? '.rb'
|
||||
|
|
|
|||
|
|
@ -13,13 +13,13 @@ module Squib
|
|||
s.default_sheet = s.sheets[input.sheet[0]]
|
||||
data = {}
|
||||
s.first_column.upto(s.last_column) do |col|
|
||||
header = s.cell(s.first_row,col).to_s
|
||||
header = s.cell(s.first_row, col).to_s
|
||||
header.strip! if import.strip?
|
||||
data[header] = []
|
||||
(s.first_row + 1).upto(s.last_row) do |row|
|
||||
cell = s.cell(row,col)
|
||||
cell = s.cell(row, col)
|
||||
# Roo hack for avoiding unnecessary .0's on whole integers (https://github.com/roo-rb/roo/issues/139)
|
||||
cell = s.excelx_value(row,col) if s.excelx_type(row,col) == [:numeric_or_formula, 'General']
|
||||
cell = s.excelx_value(row, col) if s.excelx_type(row, col) == [:numeric_or_formula, 'General']
|
||||
cell.strip! if cell.respond_to?(:strip) && import.strip?
|
||||
cell = yield(header, cell) if block_given?
|
||||
data[header] << cell
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ module Squib
|
|||
new_val = val.map.with_index{ |v, i| send(method, v, i) }
|
||||
instance_variable_set(attribute, new_val)
|
||||
else
|
||||
instance_variable_set(attribute,send(method, val))
|
||||
instance_variable_set(attribute, send(method, val))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ module Squib
|
|||
@progress_bar.start("Saving PDF to #{file}", range.size) do |bar|
|
||||
range.each do |i|
|
||||
card = @cards[i]
|
||||
cc.translate(x,y)
|
||||
cc.translate(x, y)
|
||||
cc.rectangle(sheet.trim, sheet.trim, card_width, card_height)
|
||||
cc.clip
|
||||
case card.backend.downcase.to_sym
|
||||
|
|
@ -23,7 +23,7 @@ module Squib
|
|||
when :svg
|
||||
card.cairo_surface.finish
|
||||
cc.save
|
||||
cc.scale(0.8,0.8) # I really don't know why I needed to do this at all. But 0.8 is the magic number to get this to scale right
|
||||
cc.scale(0.8, 0.8) # I really don't know why I needed to do this at all. But 0.8 is the magic number to get this to scale right
|
||||
cc.render_rsvg_handle(RSVG::Handle.new_from_file(card.svgfile), nil)
|
||||
cc.restore
|
||||
else
|
||||
|
|
@ -31,14 +31,14 @@ module Squib
|
|||
end
|
||||
bar.increment
|
||||
cc.reset_clip
|
||||
cc.translate(-x,-y)
|
||||
cc.translate(-x, -y)
|
||||
x += card.width + sheet.gap - 2*sheet.trim
|
||||
if x > (sheet.width - card_width - sheet.margin)
|
||||
x = sheet.margin
|
||||
y += card.height + sheet.gap - 2*sheet.trim
|
||||
if y > (sheet.height - card_height - sheet.margin)
|
||||
cc.show_page # next page
|
||||
x,y = sheet.margin,sheet.margin
|
||||
x, y = sheet.margin, sheet.margin
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -92,7 +92,7 @@ module Squib
|
|||
if trim > 0
|
||||
tmp = Cairo::ImageSurface.new(width-2*trim, height-2*trim)
|
||||
cc = Cairo::Context.new(tmp)
|
||||
cc.set_source(surface,-1*trim, -1*trim)
|
||||
cc.set_source(surface, -1*trim, -1*trim)
|
||||
cc.paint
|
||||
surface = tmp
|
||||
end
|
||||
|
|
|
|||
|
|
@ -52,9 +52,9 @@ module Squib
|
|||
tmp_cc.transform(matrix) # flips the coordinate system
|
||||
top_y = src.height # top of the reflection
|
||||
bottom_y = src.height * (1.0 - rpercent) + roffset # bottom of the reflection
|
||||
gradient = Cairo::LinearPattern.new(0,top_y, 0,bottom_y)
|
||||
gradient.add_color_stop_rgba(0.0, 0,0,0, rstrength) # start a little reflected
|
||||
gradient.add_color_stop_rgba(1.0, 0,0,0, 0.0) # fade to nothing
|
||||
gradient = Cairo::LinearPattern.new(0, top_y, 0, bottom_y)
|
||||
gradient.add_color_stop_rgba(0.0, 0, 0, 0, rstrength) # start a little reflected
|
||||
gradient.add_color_stop_rgba(1.0, 0, 0, 0, 0.0) # fade to nothing
|
||||
tmp_cc.set_source(src, 0, 0)
|
||||
tmp_cc.mask(gradient)
|
||||
return tmp_cc.target
|
||||
|
|
@ -74,7 +74,7 @@ module Squib
|
|||
dest_cxt.translate 0, src.height / 2.0 * (1.0 - factor)
|
||||
dest_cxt.scale factor * scale, factor
|
||||
dest_cxt.set_source src, 0, 0
|
||||
dest_cxt.rounded_rectangle i, 0, out_thickness, src.height, 0,0
|
||||
dest_cxt.rounded_rectangle i, 0, out_thickness, src.height, 0, 0
|
||||
dest_cxt.fill
|
||||
dest_cxt.restore
|
||||
end
|
||||
|
|
|
|||
|
|
@ -43,9 +43,9 @@ module Squib
|
|||
parent_keys.each do |parent_key|
|
||||
from_extends = yml[key].merge(recurse_extends(yml, parent_key, visited)) do |key, child_val, parent_val|
|
||||
if child_val.to_s.strip.start_with?('+=')
|
||||
parent_val + child_val.sub('+=','').strip.to_f
|
||||
parent_val + child_val.sub('+=', '').strip.to_f
|
||||
elsif child_val.to_s.strip.start_with?('-=')
|
||||
parent_val - child_val.sub('-=','').strip.to_f
|
||||
parent_val - child_val.sub('-=', '').strip.to_f
|
||||
else
|
||||
child_val #child overrides parent when merging, no +=
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
require 'squib'
|
||||
|
||||
data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
|
||||
'level' => [1,2,3]}
|
||||
'level' => [1, 2, 3]}
|
||||
|
||||
Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
||||
background color: :white
|
||||
|
|
@ -12,7 +12,7 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
|||
text str: data['level'], x: 75, y: 85, width: 128,
|
||||
font: 'Arial 72', align: :center
|
||||
|
||||
png range: [0,2], file: 'shiny-purse.png', x: 620, y: 75
|
||||
png range: [0, 2], file: 'shiny-purse.png', x: 620, y: 75
|
||||
svg range: 1..2, file: 'spanner.svg', x: 620, y: 218
|
||||
|
||||
save prefix: 'basic_', format: :png
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ end
|
|||
Squib::Deck.new(width: 3000, height: 1500) do
|
||||
colors = (Cairo::Color.constants - %i(HEX_RE Base RGB CMYK HSV X11))
|
||||
colors.sort_by! {|c| Cairo::Color.parse(c).to_s}
|
||||
x,y,w,h = 0,0,300,50
|
||||
x, y, w, h = 0, 0, 300, 50
|
||||
colors.each_with_index do |color, i|
|
||||
rect x: x, y: y, width: w, height: h, fill_color: color
|
||||
text str: color.to_s, x: x + 5, y: y+13, font: 'Sans Bold 16',
|
||||
|
|
|
|||
|
|
@ -67,6 +67,6 @@ Squib::Deck.new do
|
|||
use_layout file: 'custom-layout.yml'
|
||||
use_layout file: 'custom-layout2.yml'
|
||||
text str: 'The Title', layout: :title # from custom-layout.yml
|
||||
text str: 'The Subtitle',layout: :subtitle # redefined in custom-layout2.yml
|
||||
text str: 'The Subtitle', layout: :subtitle # redefined in custom-layout2.yml
|
||||
save_png prefix: 'layout3_'
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ require 'squib'
|
|||
|
||||
data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
|
||||
'type' => ['Thug', 'Thinker', 'Thinker'],
|
||||
'level' => [1,2,3]}
|
||||
'level' => [1, 2, 3]}
|
||||
|
||||
Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
||||
# Default range is :all
|
||||
|
|
@ -26,7 +26,7 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
|||
text range: -2..-1, str: 'Grifter and Mastermind only!', x: 25, y: 650
|
||||
|
||||
# We can use Arrays too!
|
||||
text range: [0,2], str: 'Thief and Mastermind only!!', x: 25, y:300
|
||||
text range: [0, 2], str: 'Thief and Mastermind only!!', x: 25, y:300
|
||||
|
||||
# Just about everything in Squib can be given an array that
|
||||
# corresponds to the deck's cards. This allows for each card to be styled differently
|
||||
|
|
@ -38,13 +38,13 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
|||
|
||||
# Useful idiom: construct a hash from card names back to its index (ID),
|
||||
# then use a range. No need to memorize IDs, and you can add cards easily
|
||||
id = {} ; data['name'].each_with_index{ |name,i| id[name] = i}
|
||||
id = {} ; data['name'].each_with_index{ |name, i| id[name] = i}
|
||||
text range: id['Thief']..id['Grifter'],
|
||||
str: 'Thief through Grifter with id lookup!!',
|
||||
x:25, y: 400
|
||||
|
||||
# Useful idiom: generate arrays from a column called 'type'
|
||||
type = {}; data['type'].each_with_index{ |t,i| (type[t] ||= []) << i}
|
||||
type = {}; data['type'].each_with_index{ |t, i| (type[t] ||= []) << i}
|
||||
text range: type['Thinker'],
|
||||
str: 'Only for Thinkers!',
|
||||
x:25, y: 500
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
require 'squib'
|
||||
|
||||
data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
|
||||
'level' => [1,2,3]}
|
||||
'level' => [1, 2, 3]}
|
||||
longtext = "This is left-justified text, with newlines.\nWhat do you know about tweetle beetles? well... When tweetle beetles fight, it's called a tweetle beetle battle. And when they battle in a puddle, it's a tweetle beetle puddle battle. AND when tweetle beetles battle with paddles in a puddle, they call it a tweetle beetle puddle paddle battle. AND... When beetles battle beetles in a puddle paddle battle and the beetle battle puddle is a puddle in a bottle... ..they call this a tweetle beetle bottle puddle paddle battle muddle."
|
||||
|
||||
Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ describe Squib::Graphics::CairoContextWrapper do
|
|||
before(:each) do
|
||||
dbl = double(Cairo::LinearPattern)
|
||||
mtx = double(Cairo::Matrix)
|
||||
expect(Cairo::LinearPattern).to receive(:new).with(1,2,3,4).and_return(dbl)
|
||||
expect(Cairo::LinearPattern).to receive(:new).with(1, 2, 3, 4).and_return(dbl)
|
||||
expect(dbl).to receive(:add_color_stop).with(0.0, 'blue')
|
||||
expect(dbl).to receive(:add_color_stop).with(1.0, 'red')
|
||||
expect(cairo).to receive(:matrix).and_return(mtx)
|
||||
|
|
@ -50,7 +50,7 @@ describe Squib::Graphics::CairoContextWrapper do
|
|||
before(:each) do
|
||||
dbl = double(Cairo::RadialPattern)
|
||||
mtx = double(Cairo::Matrix)
|
||||
expect(Cairo::RadialPattern).to receive(:new).with(1,2,5,3,4,6).and_return(dbl)
|
||||
expect(Cairo::RadialPattern).to receive(:new).with(1, 2, 5, 3, 4, 6).and_return(dbl)
|
||||
expect(dbl).to receive(:add_color_stop).with(0.0, 'blue')
|
||||
expect(dbl).to receive(:add_color_stop).with(1.0, 'red')
|
||||
expect(cairo).to receive(:matrix).and_return(mtx)
|
||||
|
|
@ -68,7 +68,7 @@ describe Squib::Graphics::CairoContextWrapper do
|
|||
it 'on radial patterns' do
|
||||
dbl = double(Cairo::RadialPattern)
|
||||
mtx = double(Cairo::Matrix)
|
||||
expect(Cairo::RadialPattern).to receive(:new).with(1,2,5,3,4,6).and_return(dbl)
|
||||
expect(Cairo::RadialPattern).to receive(:new).with(1, 2, 5, 3, 4, 6).and_return(dbl)
|
||||
expect(dbl).to receive(:add_color_stop).with(0.0, '#def')
|
||||
expect(dbl).to receive(:add_color_stop).with(1.0, '#112233')
|
||||
expect(cairo).to receive(:matrix).and_return(mtx)
|
||||
|
|
@ -80,7 +80,7 @@ describe Squib::Graphics::CairoContextWrapper do
|
|||
it 'on linear patterns' do
|
||||
dbl = double(Cairo::LinearPattern)
|
||||
mtx = double(Cairo::Matrix)
|
||||
expect(Cairo::LinearPattern).to receive(:new).with(1,2,3,4).and_return(dbl)
|
||||
expect(Cairo::LinearPattern).to receive(:new).with(1, 2, 3, 4).and_return(dbl)
|
||||
expect(dbl).to receive(:add_color_stop).with(0.0, '#def')
|
||||
expect(dbl).to receive(:add_color_stop).with(1.0, '#112233')
|
||||
expect(cairo).to receive(:matrix).and_return(mtx)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ describe Squib::Deck, '#save_pdf' do
|
|||
expect(cxt).to receive(:set_source) # place the card
|
||||
.with(instance_of(Cairo::ImageSurface), 0, 0).once
|
||||
expect(cxt).to receive(:paint).once # paint placed card
|
||||
expect(cxt).to receive(:translate).with(-x,-y).once
|
||||
expect(cxt).to receive(:translate).with(-x, -y).once
|
||||
expect(cxt).to receive(:reset_clip).once
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ describe Squib::LayoutParser do
|
|||
'b' => 106,
|
||||
},
|
||||
'child' => {
|
||||
'extends' => ['uncle','aunt'],
|
||||
'extends' => ['uncle', 'aunt'],
|
||||
'a' => 107, # my own
|
||||
'b' => 102, # from the younger aunt
|
||||
'c' => 103, # from aunt
|
||||
|
|
|
|||
|
|
@ -62,17 +62,17 @@ def overwrite_sample(sample_name, log)
|
|||
end
|
||||
|
||||
def scrub_hex(str)
|
||||
str.gsub(/0x\w{1,8}/,'')
|
||||
.gsub(/ptr=\w{1,8}/,'')
|
||||
.gsub(/#<Pango::FontDescription:.*>/,'')
|
||||
.gsub(/#<Cairo::ImageSurface:.*>/,'ImageSurface')
|
||||
.gsub(/#<Cairo::LinearPattern:.*>/,'LinearPattern')
|
||||
.gsub(/#<Cairo::RadialPattern:.*>/,'RadialPattern')
|
||||
.gsub(/#<Cairo::Matrix:.*>/,'Matrix')
|
||||
.gsub(/#<RSVG::Handle.*>/,'RSVG::Handle')
|
||||
.gsub(/#<RSpec::Mocks::Double:.*>/,'MockDouble')
|
||||
.gsub(/#<Double .*>/,'MockDouble')
|
||||
.gsub(/RGB:\w{1,8}/,'RGB:')
|
||||
str.gsub(/0x\w{1,8}/, '')
|
||||
.gsub(/ptr=\w{1,8}/, '')
|
||||
.gsub(/#<Pango::FontDescription:.*>/, '')
|
||||
.gsub(/#<Cairo::ImageSurface:.*>/, 'ImageSurface')
|
||||
.gsub(/#<Cairo::LinearPattern:.*>/, 'LinearPattern')
|
||||
.gsub(/#<Cairo::RadialPattern:.*>/, 'RadialPattern')
|
||||
.gsub(/#<Cairo::Matrix:.*>/, 'Matrix')
|
||||
.gsub(/#<RSVG::Handle.*>/, 'RSVG::Handle')
|
||||
.gsub(/#<RSpec::Mocks::Double:.*>/, 'MockDouble')
|
||||
.gsub(/#<Double .*>/, 'MockDouble')
|
||||
.gsub(/RGB:\w{1,8}/, 'RGB:')
|
||||
end
|
||||
|
||||
# Build a mock cairo instance that allows basically any method
|
||||
|
|
@ -90,22 +90,22 @@ def mock_cairo(strio)
|
|||
allow(Cairo::ImageSurface).to receive(:new).and_return(surface)
|
||||
allow(surface).to receive(:width).and_return(100)
|
||||
allow(surface).to receive(:height).and_return(101)
|
||||
allow(surface).to receive(:ink_extents).and_return([0,0,100,100])
|
||||
allow(surface).to receive(:ink_extents).and_return([0, 0, 100, 100])
|
||||
allow(Cairo::Context).to receive(:new).and_return(cxt)
|
||||
allow(cxt).to receive(:create_pango_layout).and_return(pango)
|
||||
allow(cxt).to receive(:target).and_return(surface)
|
||||
allow(cxt).to receive(:matrix).and_return(Cairo::Matrix.new(1,0,0,1,0,0))
|
||||
allow(cxt).to receive(:matrix).and_return(Cairo::Matrix.new(1, 0, 0, 1, 0, 0))
|
||||
allow(pango).to receive(:height).and_return(25)
|
||||
allow(pango).to receive(:width).and_return(25)
|
||||
allow(pango).to receive(:index_to_pos).and_return(Pango::Rectangle.new(0,0,0,0))
|
||||
allow(pango).to receive(:extents).and_return([Pango::Rectangle.new(0,0,0,0)]*2)
|
||||
allow(pango).to receive(:index_to_pos).and_return(Pango::Rectangle.new(0, 0, 0, 0))
|
||||
allow(pango).to receive(:extents).and_return([Pango::Rectangle.new(0, 0, 0, 0)]*2)
|
||||
allow(pango).to receive(:iter).and_return(iter)
|
||||
allow(pango).to receive(:alignment).and_return(Pango::Layout::Alignment::LEFT)
|
||||
allow(pango).to receive(:text).and_return("foo")
|
||||
allow(pango).to receive(:context).and_return(pango_cxt)
|
||||
allow(pango_cxt).to receive(:font_options=)
|
||||
allow(iter).to receive(:next_char!).and_return(false)
|
||||
allow(iter).to receive(:char_extents).and_return(Pango::Rectangle.new(5,5,5,5))
|
||||
allow(iter).to receive(:char_extents).and_return(Pango::Rectangle.new(5, 5, 5, 5))
|
||||
allow(iter).to receive(:index).and_return(1000)
|
||||
allow(Pango::FontDescription).to receive(:new).and_return(font)
|
||||
allow(Cairo::PDFSurface).to receive(:new).and_return(nil)
|
||||
|
|
|
|||
Loading…
Reference in New Issue