Add text rotation
parent
cdc994b77a
commit
91e7adafd5
|
|
@ -39,13 +39,13 @@ module Squib
|
||||||
# @api public
|
# @api public
|
||||||
def text(opts = {})
|
def text(opts = {})
|
||||||
opts = needs(opts, [:range, :str, :font, :font_size, :x, :y, :width, :height, :color, :wrap,
|
opts = needs(opts, [:range, :str, :font, :font_size, :x, :y, :width, :height, :color, :wrap,
|
||||||
:align, :justify, :spacing, :valign, :markup, :ellipsize, :hint, :layout])
|
:align, :justify, :spacing, :valign, :markup, :ellipsize, :hint, :layout, :rotation])
|
||||||
opts[:range].each do |i|
|
opts[:range].each do |i|
|
||||||
@cards[i].text(opts[:str][i], opts[:font][i], opts[:font_size][i], opts[:color][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[:x][i], opts[:y][i], opts[:width][i], opts[:height][i],
|
||||||
opts[:markup][i], opts[:justify][i], opts[:wrap][i],
|
opts[:markup][i], opts[:justify][i], opts[:wrap][i],
|
||||||
opts[:ellipsize][i], opts[:spacing][i], opts[:align][i],
|
opts[:ellipsize][i], opts[:spacing][i], opts[:align][i],
|
||||||
opts[:valign][i], opts[:hint][i])
|
opts[:valign][i], opts[:hint][i], opts[:rotation][i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ module Squib
|
||||||
:progress_bar => false,
|
:progress_bar => false,
|
||||||
:range => :all,
|
:range => :all,
|
||||||
:rotate => false,
|
:rotate => false,
|
||||||
|
:rotation => 0,
|
||||||
:sheet => 0,
|
:sheet => 0,
|
||||||
:spacing => 0,
|
:spacing => 0,
|
||||||
:str => '',
|
:str => '',
|
||||||
|
|
@ -85,6 +86,7 @@ module Squib
|
||||||
:layout => :layout,
|
:layout => :layout,
|
||||||
:markup => :markup,
|
:markup => :markup,
|
||||||
:rect_radius => :radius,
|
:rect_radius => :radius,
|
||||||
|
:rotation => :rotation,
|
||||||
:spacing => :spacing,
|
:spacing => :spacing,
|
||||||
:str => :str,
|
:str => :str,
|
||||||
:stroke_color => :stroke_color,
|
:stroke_color => :stroke_color,
|
||||||
|
|
|
||||||
|
|
@ -88,11 +88,12 @@ module Squib
|
||||||
def text(str, font, font_size, color,
|
def text(str, font, font_size, color,
|
||||||
x, y, width, height,
|
x, y, width, height,
|
||||||
markup, justify, wrap, ellipsize,
|
markup, justify, wrap, ellipsize,
|
||||||
spacing, align, valign, hint)
|
spacing, align, valign, hint, rotation)
|
||||||
Squib.logger.debug {"Placing '#{str}'' with font '#{font}' @ #{x}, #{y}, color: #{color}, etc."}
|
Squib.logger.debug {"Placing '#{str}'' with font '#{font}' @ #{x}, #{y}, color: #{color}, etc."}
|
||||||
use_cairo do |cc|
|
use_cairo do |cc|
|
||||||
cc.set_source_color(color)
|
cc.set_source_color(color)
|
||||||
cc.move_to(x,y)
|
cc.move_to(x,y)
|
||||||
|
cc.rotate(rotation)
|
||||||
layout = cc.create_pango_layout
|
layout = cc.create_pango_layout
|
||||||
font_desc = Pango::FontDescription.new(font)
|
font_desc = Pango::FontDescription.new(font)
|
||||||
font_desc.size = font_size * Pango::SCALE unless font_size.nil?
|
font_desc.size = font_size * Pango::SCALE unless font_size.nil?
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,10 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
||||||
x: 565, y: 625,
|
x: 565, y: 625,
|
||||||
font: 'Arial 22'
|
font: 'Arial 22'
|
||||||
|
|
||||||
|
text str: "Rotated",
|
||||||
|
x: 565, y: 675, rotation: 0.1,
|
||||||
|
font: 'Arial 18'
|
||||||
|
|
||||||
text str: longtext, font: 'Arial 16',
|
text str: longtext, font: 'Arial 16',
|
||||||
x: 65, y: 700,
|
x: 65, y: 700,
|
||||||
width: inches(2.25), height: inches(1),
|
width: inches(2.25), height: inches(1),
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ describe Squib::Deck, '#text' do
|
||||||
it "should use the default font when #text and #set_font don't specify" do
|
it "should use the default font when #text and #set_font don't specify" do
|
||||||
card = instance_double(Squib::Card)
|
card = instance_double(Squib::Card)
|
||||||
expect(card).to receive(:text).with('a', 'Arial 36',
|
expect(card).to receive(:text).with('a', 'Arial 36',
|
||||||
anything, anything, anything,anything,anything,anything, anything, anything, anything,anything, anything, anything, anything, anything
|
anything, anything, anything,anything,anything,anything, anything, anything, anything,anything, anything, anything, anything, anything, anything
|
||||||
).once
|
).once
|
||||||
Squib::Deck.new do
|
Squib::Deck.new do
|
||||||
@cards = [card]
|
@cards = [card]
|
||||||
|
|
@ -18,7 +18,7 @@ describe Squib::Deck, '#text' do
|
||||||
it "should use the #set_font when #text doesn't specify" do
|
it "should use the #set_font when #text doesn't specify" do
|
||||||
card = instance_double(Squib::Card)
|
card = instance_double(Squib::Card)
|
||||||
expect(card).to receive(:text).with('a', 'Times New Roman 16',
|
expect(card).to receive(:text).with('a', 'Times New Roman 16',
|
||||||
anything, anything, anything, anything,anything,anything, anything, anything, anything,anything, anything, anything, anything, anything
|
anything, anything, anything, anything,anything,anything, anything, anything, anything,anything, anything, anything, anything, anything, anything
|
||||||
).once
|
).once
|
||||||
Squib::Deck.new do
|
Squib::Deck.new do
|
||||||
@cards = [card]
|
@cards = [card]
|
||||||
|
|
@ -30,7 +30,7 @@ describe Squib::Deck, '#text' do
|
||||||
it "should use the specified font no matter what" do
|
it "should use the specified font no matter what" do
|
||||||
card = instance_double(Squib::Card)
|
card = instance_double(Squib::Card)
|
||||||
expect(card).to receive(:text).with('a', 'Arial 18',
|
expect(card).to receive(:text).with('a', 'Arial 18',
|
||||||
anything, anything, anything, anything,anything,anything,anything, anything, anything,anything, anything, anything, anything, anything
|
anything, anything, anything, anything,anything,anything,anything, anything, anything,anything, anything, anything, anything, anything, anything
|
||||||
).once
|
).once
|
||||||
Squib::Deck.new do
|
Squib::Deck.new do
|
||||||
@cards = [card]
|
@cards = [card]
|
||||||
|
|
@ -40,4 +40,4 @@ describe Squib::Deck, '#text' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue