Added a font_size override for font description
parent
350314f2a8
commit
fd2d10771a
|
|
@ -36,10 +36,10 @@ module Squib
|
||||||
# @return [nil] Returns nothing
|
# @return [nil] Returns nothing
|
||||||
# @api public
|
# @api public
|
||||||
def text(opts = {})
|
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])
|
:align, :justify, :spacing, :valign, :markup, :ellipsize, :hint, :layout])
|
||||||
opts[:range].each do |i|
|
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[: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],
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ module Squib
|
||||||
:fill_color => '#0000',
|
:fill_color => '#0000',
|
||||||
:force_id => false,
|
:force_id => false,
|
||||||
:font => :use_set,
|
:font => :use_set,
|
||||||
|
:font_size => nil,
|
||||||
:format => :png,
|
:format => :png,
|
||||||
:gap => 0,
|
:gap => 0,
|
||||||
:height => :native,
|
:height => :native,
|
||||||
|
|
@ -77,6 +78,7 @@ module Squib
|
||||||
:fill_color => :fill_color,
|
:fill_color => :fill_color,
|
||||||
:force_svgid => :force_id,
|
:force_svgid => :force_id,
|
||||||
:font => :font,
|
:font => :font,
|
||||||
|
:font_size => :font_size,
|
||||||
:height => :height,
|
:height => :height,
|
||||||
:hint => :hint,
|
:hint => :hint,
|
||||||
:justify => :justify,
|
:justify => :justify,
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ module Squib
|
||||||
|
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
# @api private
|
# @api private
|
||||||
def text(str, font, 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)
|
spacing, align, valign, hint)
|
||||||
|
|
@ -94,7 +94,9 @@ module Squib
|
||||||
cc.set_source_color(color)
|
cc.set_source_color(color)
|
||||||
cc.move_to(x,y)
|
cc.move_to(x,y)
|
||||||
layout = cc.create_pango_layout
|
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.text = str.to_s
|
||||||
layout.markup = str.to_s if markup
|
layout.markup = str.to_s if markup
|
||||||
layout = setwh(layout, width, height)
|
layout = setwh(layout, width, height)
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,9 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
||||||
text str: "Font strings are expressive!", x:65, y: 300,
|
text str: "Font strings are expressive!", x:65, y: 300,
|
||||||
font: 'Arial,Verdana weight=900 style=oblique 36'
|
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",
|
text str: "This text has fixed width, fixed height, center-aligned, middle-valigned, and has a red hint",
|
||||||
hint: :red,
|
hint: :red,
|
||||||
x: 65, y: 400,
|
x: 65, y: 400,
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ describe Squib::Deck, '#text' do
|
||||||
it "should use the default font when #text and #set_font don't specify" do
|
it "should use the default font when #text and #set_font don't specify" do
|
||||||
card = instance_double(Squib::Card)
|
card = instance_double(Squib::Card)
|
||||||
expect(card).to receive(:text).with('a', 'Arial 36',
|
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
|
).once
|
||||||
Squib::Deck.new do
|
Squib::Deck.new do
|
||||||
@cards = [card]
|
@cards = [card]
|
||||||
|
|
@ -18,7 +18,7 @@ describe Squib::Deck, '#text' do
|
||||||
it "should use the #set_font when #text doesn't specify" do
|
it "should use the #set_font when #text doesn't specify" do
|
||||||
card = instance_double(Squib::Card)
|
card = instance_double(Squib::Card)
|
||||||
expect(card).to receive(:text).with('a', 'Times New Roman 16',
|
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
|
).once
|
||||||
Squib::Deck.new do
|
Squib::Deck.new do
|
||||||
@cards = [card]
|
@cards = [card]
|
||||||
|
|
@ -30,7 +30,7 @@ describe Squib::Deck, '#text' do
|
||||||
it "should use the specified font no matter what" do
|
it "should use the specified font no matter what" do
|
||||||
card = instance_double(Squib::Card)
|
card = instance_double(Squib::Card)
|
||||||
expect(card).to receive(:text).with('a', 'Arial 18',
|
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
|
).once
|
||||||
Squib::Deck.new do
|
Squib::Deck.new do
|
||||||
@cards = [card]
|
@cards = [card]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue