Browse Source

Place embedded icons based on byte offset

Fixes #57
dev
Andy Meneely 11 years ago
parent
commit
beb46a9e1c
  1. 3
      lib/squib/graphics/text.rb
  2. 4
      samples/embed_text.rb
  3. 2
      spec/data/samples/embed_text.rb.txt

3
lib/squib/graphics/text.rb

@ -119,7 +119,8 @@ module Squib
while (key = next_embed(embed.rules.keys, clean_str)) != nil
rule = embed.rules[key]
spacing = rule[:width] * Pango::SCALE
index = clean_str.index(key)
index = clean_str.index(key)
index = clean_str[0..index].bytesize #convert to byte index (bug #57)
str = str.sub(key, "<span size=\"#{ZERO_WIDTH_CHAR_SIZE}\">a<span letter_spacing=\"#{spacing.to_i}\">a</span>a</span>")
layout.markup = str
clean_str = layout.text

4
samples/embed_text.rb

@ -66,8 +66,8 @@ Squib::Deck.new do
embed.png key: ':purse:', width: 28, height: 28, file: 'shiny-purse.png'
end
embed_text = 'Markup and typography replacements with ":tool:" icons <i>won\'t</i> fail'
text(str: embed_text, font: 'Serif 21', markup: true,
embed_text = 'Markup --- and typography replacements --- with ":tool:" icons <i>won\'t</i> fail'
text(str: embed_text, font: 'Serif 18', markup: true,
x: 600, y: 320, width: 180, height: 300,
align: :center, hint: :magenta) do |embed|
embed.svg key: ':tool:', width: 28, height: 28, file: 'spanner.svg'

2
spec/data/samples/embed_text.rb.txt

@ -185,7 +185,7 @@ cairo: translate([600, 320])
cairo: rotate([0])
cairo: move_to([0, 0])
pango: font_description=([MockDouble])
pango: text=(["Markup and typography replacements with \":tool:\" icons <i>won't</i> fail"])
pango: text=(["Markup --- and typography replacements --- with \":tool:\" icons <i>won't</i> fail"])
pango: markup=(["foo"])
pango: width=([184320])
pango: height=([307200])

Loading…
Cancel
Save