spec/graphics/graphics_text_spec.rb in squib-0.5.1 vs spec/graphics/graphics_text_spec.rb in squib-0.6.0
- old
+ new
@@ -14,10 +14,12 @@
allow(Cairo::Context).to receive(:new).and_return(context)
allow(deck).to receive(:dir).and_return('_output')
allow(deck).to receive(:count_format).and_return('%02d')
allow(deck).to receive(:prefix).and_return('card_')
allow(deck).to receive(:antialias).and_return('best')
+ allow(deck).to receive(:antialias).and_return('subpixel')
+ allow(deck).to receive(:backend).and_return('memory')
allow(layout).to receive(:context).and_return(pango_cxt)
end
it 'make all the expected calls on a smoke test' do
extent = Pango::Rectangle.new(50,60,100,200)
@@ -48,15 +50,16 @@
card = Squib::Card.new(deck, 100, 150)
# text(str, font, font_size, color,
# x, y, width, height,
# markup, justify, wrap, ellipsize,
- # spacing, align, valign, hint, angle)
+ # spacing, align, valign, hint, angle,
+ # stroke_width, stroke_color)
ret = card.text(Squib::TextEmbed.new,'foo', 'Sans 12', nil, '#abc',
10, 15, 20, 25,
nil, false, false, false,
- 1.0, :left, :top, nil, 0.0)
+ 1.0, :left, :top, nil, 0.0, '#fff', 0)
expect(ret).to eq({width: 0, height: 0})
end
end
context 'convenience lookups' do
@@ -69,82 +72,93 @@
allow(Cairo::Context).to receive(:new).and_return(context)
expect(context).to receive(:create_pango_layout).once.and_return(layout)
allow(deck).to receive(:dir).and_return('_output')
allow(deck).to receive(:count_format).and_return('%02d')
allow(deck).to receive(:prefix).and_return('card_')
- allow(deck).to receive(:antialias).and_return('best')
+ allow(deck).to receive(:antialias).and_return('subpixel')
+ allow(deck).to receive(:backend).and_return('memory')
end
it 'aligns right with strings' do
card = Squib::Card.new(deck, 100, 150)
expect(layout).to receive(:alignment=).with(Pango::Layout::ALIGN_RIGHT).once
card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
10, 15, 20, 50,
nil, false, false, false,
- 1.0, 'right', :top, nil, 0.0)
+ 1.0, 'right', :top, nil, 0.0, '#fff', 0)
end
it 'aligns center with strings' do
card = Squib::Card.new(deck, 100, 150)
expect(layout).to receive(:alignment=).with(Pango::Layout::ALIGN_CENTER).once
card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
10, 15, 20, 50,
nil, false, false, false,
- 1.0, 'center', :top, nil, 0.0)
+ 1.0, 'center', :top, nil, 0.0, '#fff', 0)
end
it 'sets wrap to char with string char' do
card = Squib::Card.new(deck, 100, 150)
expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_CHAR).once
card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
10, 15, 20, 50,
nil, false, 'char', false,
- 1.0, :left, :top, nil, 0.0)
+ 1.0, :left, :top, nil, 0.0, '#fff', 0)
end
it 'sets wrap to word with word string' do
card = Squib::Card.new(deck, 100, 150)
expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD).once
card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
10, 15, 20, 50,
nil, false, 'word', false,
- 1.0, :left, :top, nil, 0.0)
+ 1.0, :left, :top, nil, 0.0, '#fff', 0)
end
it 'sets wrap to word_char with symbol word_char' do
card = Squib::Card.new(deck, 100, 150)
expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD_CHAR).once
card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
10, 15, 20, 50,
nil, false, :word_char, false,
- 1.0, :left, :top, nil, 0.0)
+ 1.0, :left, :top, nil, 0.0, '#fff', 0)
end
it 'sets wrap to word_char with true' do
card = Squib::Card.new(deck, 100, 150)
expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD_CHAR).once
card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
10, 15, 20, 50,
nil, false, true, false,
- 1.0, :left, :top, nil, 0.0)
+ 1.0, :left, :top, nil, 0.0, '#fff', 0)
end
it 'sets ellipsize to start properly' do
card = Squib::Card.new(deck, 100, 150)
expect(layout).to receive(:ellipsize=).with(Pango::Layout::ELLIPSIZE_START).once
card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
10, 15, 20, 50,
nil, false, true, :start,
- 1.0, :left, :top, nil, 0.0)
+ 1.0, :left, :top, nil, 0.0, '#fff', 0)
end
it 'sets ellipsize to middle properly' do
card = Squib::Card.new(deck, 100, 150)
expect(layout).to receive(:ellipsize=).with(Pango::Layout::ELLIPSIZE_MIDDLE).once
card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
10, 15, 20, 50,
nil, false, true, 'middle',
- 1.0, :left, :top, nil, 0.0)
+ 1.0, :left, :top, nil, 0.0, '#fff', 0)
+ end
+
+ it 'implements stroke and fill when asked to' do
+ card = Squib::Card.new(deck, 100, 150)
+ expect(context).to receive(:set_line_width).with(3.0).once
+ expect(context).to receive(:pango_layout_path).once
+ card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
+ 10, 15, 20, 50,
+ nil, false, true, 'middle',
+ 1.0, :left, :top, nil, 0.0, '#f00', 3.0)
end
end
end