Rotation works better now!!
parent
59e8576616
commit
20600a97e6
|
|
@ -34,7 +34,7 @@ module Squib
|
||||||
# @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 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 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 angle [FixNum] (0) Rotation of the text in radians. Note that this rotates around the upper-left corner of the text box, making the placement of x-y coordinates slightly tricky.
|
||||||
# @option opts hint [String] (:nil) draw a rectangle around the text with the given color. Overrides global hints (see {Deck#hint}).
|
# @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
|
# @return [nil] Returns nothing
|
||||||
# @api public
|
# @api public
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,6 @@ module Squib
|
||||||
w = layout.extents[1].width / Pango::SCALE if w < 0
|
w = layout.extents[1].width / Pango::SCALE if w < 0
|
||||||
h = layout.height / Pango::SCALE
|
h = layout.height / Pango::SCALE
|
||||||
h = layout.extents[1].height / Pango::SCALE if h < 0
|
h = layout.extents[1].height / Pango::SCALE if h < 0
|
||||||
|
|
||||||
Squib.logger.warn 'Text hints are broken on non-zero angles' if angle > 0
|
|
||||||
cc.rounded_rectangle(x,y,w,h,0,0)
|
cc.rounded_rectangle(x,y,w,h,0,0)
|
||||||
cc.set_source_color(color)
|
cc.set_source_color(color)
|
||||||
cc.set_line_width(2.0)
|
cc.set_line_width(2.0)
|
||||||
|
|
@ -52,7 +50,7 @@ module Squib
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
# @api private
|
# @api private
|
||||||
def set_align!(layout, align)
|
def set_align!(layout, align)
|
||||||
case align.to_s
|
case align.to_s.downcase
|
||||||
when 'left'
|
when 'left'
|
||||||
layout.alignment = Pango::ALIGN_LEFT
|
layout.alignment = Pango::ALIGN_LEFT
|
||||||
when 'right'
|
when 'right'
|
||||||
|
|
@ -93,8 +91,10 @@ module Squib
|
||||||
Squib.logger.debug {"Placing '#{str}'' with font '#{font}' @ #{x}, #{y}, color: #{color}, angle: #{angle} etc."}
|
Squib.logger.debug {"Placing '#{str}'' with font '#{font}' @ #{x}, #{y}, color: #{color}, angle: #{angle} 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.translate(x,y)
|
||||||
cc.rotate(angle)
|
cc.rotate(angle)
|
||||||
|
cc.translate(-1*x,-1*y)
|
||||||
|
cc.move_to(x,y)
|
||||||
|
|
||||||
layout = cc.create_pango_layout
|
layout = cc.create_pango_layout
|
||||||
font_desc = Pango::FontDescription.new(font)
|
font_desc = Pango::FontDescription.new(font)
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
||||||
hint: :red,
|
hint: :red,
|
||||||
x: 65, y: 400,
|
x: 65, y: 400,
|
||||||
width: 300, height: 200,
|
width: 300, height: 200,
|
||||||
align: :center, valign: :middle,
|
align: :center, valign: 'MIDDLE', #case-insenstive strings allowed too.
|
||||||
font: 'Arial 18'
|
font: 'Arial 18'
|
||||||
|
|
||||||
text str: 'Ellipsization!\nThe ultimate question of life, the universe, and everything to life and everything is 42',
|
text str: 'Ellipsization!\nThe ultimate question of life, the universe, and everything to life and everything is 42',
|
||||||
|
|
@ -48,8 +48,8 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
||||||
font: 'Arial 22'
|
font: 'Arial 22'
|
||||||
|
|
||||||
text str: 'Rotated',
|
text str: 'Rotated',
|
||||||
x: 565, y: 675, angle: 0.1,
|
x: 565, y: 675, angle: 0.2,
|
||||||
font: 'Arial 18'
|
font: 'Arial 18', hint: :red
|
||||||
|
|
||||||
text str: longtext, font: 'Arial 16',
|
text str: longtext, font: 'Arial 16',
|
||||||
x: 65, y: 700,
|
x: 65, y: 700,
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,9 @@ describe Squib::Card, '#text' do
|
||||||
expect(@context).to receive(:save).once
|
expect(@context).to receive(:save).once
|
||||||
expect(@context).to receive(:set_source_color).once
|
expect(@context).to receive(:set_source_color).once
|
||||||
expect(@context).to receive(:move_to).with(10, 15).once
|
expect(@context).to receive(:move_to).with(10, 15).once
|
||||||
|
expect(@context).to receive(:translate).with(-10, -15).once
|
||||||
expect(@context).to receive(:rotate).with(0.0).once
|
expect(@context).to receive(:rotate).with(0.0).once
|
||||||
|
expect(@context).to receive(:translate).with(10, 15).once
|
||||||
expect(@context).to receive(:create_pango_layout).once.and_return(@layout)
|
expect(@context).to receive(:create_pango_layout).once.and_return(@layout)
|
||||||
expect(@layout).to receive(:font_description=).with(Pango::FontDescription.new('Sans 12')).once
|
expect(@layout).to receive(:font_description=).with(Pango::FontDescription.new('Sans 12')).once
|
||||||
expect(@layout).to receive(:text=).with('foo').once
|
expect(@layout).to receive(:text=).with('foo').once
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue