From 03e41c7e811cf15b8adc426ec8923260b2e7d518 Mon Sep 17 00:00:00 2001 From: Andy Meneely Date: Tue, 31 Mar 2015 17:05:03 -0400 Subject: [PATCH] Adding regression tests for various cases to test PR #53 Close #53. --- lib/squib/graphics/text.rb | 5 ----- samples/embed_text.rb | 29 +++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/squib/graphics/text.rb b/lib/squib/graphics/text.rb index 1887f64..3ace5af 100644 --- a/lib/squib/graphics/text.rb +++ b/lib/squib/graphics/text.rb @@ -117,11 +117,6 @@ module Squib end searches.each do |search| rect = layout.index_to_pos(search[:index]) - case layout.alignment - when Pango::Layout::Alignment::CENTER, - Pango::Layout::Alignment::RIGHT - Squib.logger.warn "Center- or right-aligned text do not always embed properly. This is a known issue with a workaround. See https://github.com/andymeneely/squib/issues/46" - end x = Pango.pixels(rect.x) + search[:rule][:dx] y = Pango.pixels(rect.y) + search[:rule][:dy] draw_calls << {x: x, y: y, draw: search[:rule][:draw]} # defer drawing until we've valigned diff --git a/samples/embed_text.rb b/samples/embed_text.rb index 8ada5f7..b49dcd3 100644 --- a/samples/embed_text.rb +++ b/samples/embed_text.rb @@ -32,14 +32,39 @@ Squib::Deck.new do embed.png key: ':purse:', width: 28, height: 28, file: 'shiny-purse.png' end - embed_text = 'Justify will :tool: work too :purse: with more words just for fun' + embed_text = 'Wrapping multiples: These are 1 :tool::tool::tool: and these are multiple :tool::tool: :tool::tool:' text(str: embed_text, font: 'Sans 21', - x: 0, y: 300, width: 180, height: 300, valign: :bottom, + x: 600, y: 0, width: 180, height: 300, valign: :middle, + align: :left, ellipsize: false, justify: false, hint: :cyan) do |embed| + embed.svg key: ':tool:', width: 28, height: 28, file: 'spanner.svg' + end + + embed_text = ':tool:Justify will :tool: work too, and :purse: with more words just for fun' + text(str: embed_text, font: 'Sans 21', + x: 0, y: 320, width: 180, height: 300, valign: :bottom, align: :left, ellipsize: false, justify: true, hint: :magenta) do |embed| embed.svg key: ':tool:', width: 28, height: 28, file: 'spanner.svg' embed.svg key: ':health:', width: 28, height: 28, file: 'glass-heart.svg' embed.png key: ':purse:', width: 28, height: 28, file: 'shiny-purse.png' end + embed_text = 'Right-aligned works :tool: with :health: and :purse:' + text(str: embed_text, font: 'Sans 21', + x: 200, y: 320, width: 180, height: 300, valign: :bottom, + align: :right, ellipsize: false, justify: false, hint: :magenta) do |embed| + embed.svg key: ':tool:', width: 28, height: 28, file: 'spanner.svg' + embed.svg key: ':health:', width: 28, height: 28, file: 'glass-heart.svg' + embed.png key: ':purse:', width: 28, height: 28, file: 'shiny-purse.png' + end + + embed_text = ':tool:Center-aligned works :tool: with :health: and :purse:' + text(str: embed_text, font: 'Sans 21', + x: 400, y: 320, width: 180, height: 300, + align: :center, ellipsize: false, justify: false, hint: :magenta) do |embed| + embed.svg key: ':tool:', width: 28, height: 28, file: 'spanner.svg' + embed.svg key: ':health:', width: 28, height: 28, file: 'glass-heart.svg' + embed.png key: ':purse:', width: 28, height: 28, file: 'shiny-purse.png' + end + save_png prefix: 'embed_' end \ No newline at end of file