diff --git a/lib/squib/api/text.rb b/lib/squib/api/text.rb index ae97145..746536d 100644 --- a/lib/squib/api/text.rb +++ b/lib/squib/api/text.rb @@ -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 diff --git a/lib/squib/constants.rb b/lib/squib/constants.rb index 587c415..2b09400 100644 --- a/lib/squib/constants.rb +++ b/lib/squib/constants.rb @@ -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, diff --git a/lib/squib/graphics/text.rb b/lib/squib/graphics/text.rb index bd6a052..f8843c0 100644 --- a/lib/squib/graphics/text.rb +++ b/lib/squib/graphics/text.rb @@ -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? diff --git a/samples/text_options.rb b/samples/text_options.rb index 15dfc0f..e193e78 100644 --- a/samples/text_options.rb +++ b/samples/text_options.rb @@ -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), diff --git a/spec/api/api_text_spec.rb b/spec/api/api_text_spec.rb index 15382b0..3b06d36 100644 --- a/spec/api/api_text_spec.rb +++ b/spec/api/api_text_spec.rb @@ -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] @@ -40,4 +40,4 @@ describe Squib::Deck, '#text' do end end -end \ No newline at end of file +end