Browse Source

Added a font_size override for font description

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

4
lib/squib/api/text.rb

@ -36,10 +36,10 @@ module Squib
# @return [nil] Returns nothing
# @api public
def text(opts = {})
opts = needs(opts, [:range, :str, :font, :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])
opts[:range].each do |i|
@cards[i].text(opts[:str][i], opts[:font][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[:markup][i], opts[:justify][i], opts[:wrap][i],
opts[:ellipsize][i], opts[:spacing][i], opts[:align][i],

2
lib/squib/constants.rb

@ -13,6 +13,7 @@ module Squib
:fill_color => '#0000',
:force_id => false,
:font => :use_set,
:font_size => nil,
:format => :png,
:gap => 0,
:height => :native,
@ -77,6 +78,7 @@ module Squib
:fill_color => :fill_color,
:force_svgid => :force_id,
:font => :font,
:font_size => :font_size,
:height => :height,
:hint => :hint,
:justify => :justify,

6
lib/squib/graphics/text.rb

@ -85,7 +85,7 @@ module Squib
# :nodoc:
# @api private
def text(str, font, color,
def text(str, font, font_size, color,
x, y, width, height,
markup, justify, wrap, ellipsize,
spacing, align, valign, hint)
@ -94,7 +94,9 @@ module Squib
cc.set_source_color(color)
cc.move_to(x,y)
layout = cc.create_pango_layout
layout.font_description = Pango::FontDescription.new(font)
font_desc = Pango::FontDescription.new(font)
font_desc.size = font_size * Pango::SCALE unless font_size.nil?
layout.font_description = font_desc
layout.text = str.to_s
layout.markup = str.to_s if markup
layout = setwh(layout, width, height)

3
samples/text_options.rb

@ -22,6 +22,9 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
text str: "Font strings are expressive!", x:65, y: 300,
font: 'Arial,Verdana weight=900 style=oblique 36'
text str: "Font string sizes can be overridden per card.", x: 65, y: 350,
font: 'Impact 36', font_size: [16, 20, 24]
text str: "This text has fixed width, fixed height, center-aligned, middle-valigned, and has a red hint",
hint: :red,
x: 65, y: 400,

6
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
).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
).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
).once
Squib::Deck.new do
@cards = [card]

Loading…
Cancel
Save