From 67c834960ac29ffd804963797f7fd406c423465d Mon Sep 17 00:00:00 2001 From: pickfifteen Date: Mon, 30 Mar 2015 16:02:24 -0400 Subject: [PATCH] Embed fix size, first / last issue One more fix needed to fix wrapping-- draw_calls all need to be calculated after all string substitutions have been made. --- lib/squib/graphics/text.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/squib/graphics/text.rb b/lib/squib/graphics/text.rb index 9587c45..faca2b5 100644 --- a/lib/squib/graphics/text.rb +++ b/lib/squib/graphics/text.rb @@ -109,19 +109,18 @@ module Squib rule = embed.rules[key] spacing = rule[:width] * Pango::SCALE index = clean_str.index(key) - str.sub!(key, " ") + str.sub!(key, "aa") layout.markup = str clean_str = layout.text rect = layout.index_to_pos(index) iter = layout.iter while iter.next_char! && iter.index < index; end - letter_width = iter.char_extents.width - spacing # the width of our inserted space char 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 + (letter_width / 2)) + rule[:dx] + x = Pango.pixels(rect.x) + rule[:dx] y = Pango.pixels(rect.y) + rule[:dy] draw_calls << {x: x, y: y, draw: rule[:draw]} # defer drawing until we've valigned end