Add text rotation
parent
cdc994b77a
commit
91e7adafd5
|
|
@ -39,13 +39,13 @@ module Squib
|
|||
# @api public
|
||||
def text(opts = {})
|
||||
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|
|
||||
@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[:valign][i], opts[:hint][i])
|
||||
opts[:valign][i], opts[:hint][i], opts[:rotation][i])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ module Squib
|
|||
:progress_bar => false,
|
||||
:range => :all,
|
||||
:rotate => false,
|
||||
:rotation => 0,
|
||||
:sheet => 0,
|
||||
:spacing => 0,
|
||||
:str => '',
|
||||
|
|
@ -85,6 +86,7 @@ module Squib
|
|||
:layout => :layout,
|
||||
:markup => :markup,
|
||||
:rect_radius => :radius,
|
||||
:rotation => :rotation,
|
||||
:spacing => :spacing,
|
||||
:str => :str,
|
||||
:stroke_color => :stroke_color,
|
||||
|
|
|
|||
|
|
@ -88,11 +88,12 @@ module Squib
|
|||
def text(str, font, font_size, color,
|
||||
x, y, width, height,
|
||||
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."}
|
||||
use_cairo do |cc|
|
||||
cc.set_source_color(color)
|
||||
cc.move_to(x,y)
|
||||
cc.rotate(rotation)
|
||||
layout = cc.create_pango_layout
|
||||
font_desc = Pango::FontDescription.new(font)
|
||||
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,
|
||||
font: 'Arial 22'
|
||||
|
||||
text str: "Rotated",
|
||||
x: 565, y: 675, rotation: 0.1,
|
||||
font: 'Arial 18'
|
||||
|
||||
text str: longtext, font: 'Arial 16',
|
||||
x: 65, y: 700,
|
||||
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
|
||||
card = instance_double(Squib::Card)
|
||||
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
|
||||
Squib::Deck.new do
|
||||
@cards = [card]
|
||||
|
|
@ -18,7 +18,7 @@ describe Squib::Deck, '#text' do
|
|||
it "should use the #set_font when #text doesn't specify" do
|
||||
card = instance_double(Squib::Card)
|
||||
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
|
||||
Squib::Deck.new do
|
||||
@cards = [card]
|
||||
|
|
@ -30,7 +30,7 @@ describe Squib::Deck, '#text' do
|
|||
it "should use the specified font no matter what" do
|
||||
card = instance_double(Squib::Card)
|
||||
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
|
||||
Squib::Deck.new do
|
||||
@cards = [card]
|
||||
|
|
|
|||
Loading…
Reference in New Issue