Browse Source

Renamed text :rotation => :angle

dev
Andy Meneely 11 years ago
parent
commit
393eeae450
  1. 5
      lib/squib/api/text.rb
  2. 4
      lib/squib/constants.rb
  3. 6
      lib/squib/graphics/text.rb
  4. 2
      samples/text_options.rb

5
lib/squib/api/text.rb

@ -34,18 +34,19 @@ 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 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
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, :rotation]) :align, :justify, :spacing, :valign, :markup, :ellipsize, :hint, :layout, :angle])
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[:rotation][i]) opts[:valign][i], opts[:hint][i], opts[:angle][i])
end end
end end

4
lib/squib/constants.rb

@ -5,6 +5,7 @@ module Squib
SYSTEM_DEFAULTS = { SYSTEM_DEFAULTS = {
:align => :left, :align => :left,
:alpha => 1.0, :alpha => 1.0,
:angle => 0,
:blend => :none, :blend => :none,
:color => :black, :color => :black,
:default_font => 'Arial 36', :default_font => 'Arial 36',
@ -26,7 +27,6 @@ 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 => '',
@ -71,6 +71,7 @@ module Squib
EXPANDING_PARAMS = { EXPANDING_PARAMS = {
:align => :align, :align => :align,
:alpha => :alpha, :alpha => :alpha,
:angle => :angle,
:blend => :blend, :blend => :blend,
:circle_radius => :radius, :circle_radius => :radius,
:color => :color, :color => :color,
@ -86,7 +87,6 @@ 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,

6
lib/squib/graphics/text.rb

@ -88,12 +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, rotation) spacing, align, valign, hint, angle)
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}, rotate: #{rotation} 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) cc.rotate(angle)
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?

2
samples/text_options.rb

@ -48,7 +48,7 @@ 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, rotation: 0.1, x: 565, y: 675, angle: 0.1,
font: 'Arial 18' font: 'Arial 18'
text str: longtext, font: 'Arial 16', text str: longtext, font: 'Arial 16',

Loading…
Cancel
Save