Place embedded icons based on byte offset

Fixes #57
dev
Andy Meneely 2015-04-07 19:43:16 -04:00
parent 211e7c13b3
commit beb46a9e1c
3 changed files with 5 additions and 4 deletions

View File

@ -120,6 +120,7 @@ module Squib
rule = embed.rules[key] rule = embed.rules[key]
spacing = rule[:width] * Pango::SCALE 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>") str = str.sub(key, "<span size=\"#{ZERO_WIDTH_CHAR_SIZE}\">a<span letter_spacing=\"#{spacing.to_i}\">a</span>a</span>")
layout.markup = str layout.markup = str
clean_str = layout.text clean_str = layout.text

View File

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

View File

@ -185,7 +185,7 @@ cairo: translate([600, 320])
cairo: rotate([0]) cairo: rotate([0])
cairo: move_to([0, 0]) cairo: move_to([0, 0])
pango: font_description=([MockDouble]) 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: markup=(["foo"])
pango: width=([184320]) pango: width=([184320])
pango: height=([307200]) pango: height=([307200])