Saving a wonky bug example for posterity
parent
c18096ecaf
commit
c6cb0ca288
|
|
@ -96,6 +96,8 @@ module Squib
|
|||
ret_key
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
def process_embeds(embed, str, layout, cc)
|
||||
return unless embed.rules.any?
|
||||
while (key = next_embed(embed.rules.keys, str)) != nil
|
||||
|
|
@ -105,20 +107,31 @@ module Squib
|
|||
str = str.sub(key, "<span letter_spacing=\"#{spacing.to_i}\"> </span>")
|
||||
layout.markup = str
|
||||
cc.update_pango_layout(layout)
|
||||
iter = layout.iter
|
||||
while iter.next_char! && iter.index < index; end
|
||||
rect = layout.index_to_pos(index)
|
||||
letter_width = iter.char_extents.width - spacing # the spacing of our actual letter
|
||||
x = (rect.x + letter_width / 2) / Pango::SCALE
|
||||
# x = rect.x / Pango::SCALE
|
||||
y = rect.y / Pango::SCALE
|
||||
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
|
||||
para_x = case layout.alignment
|
||||
when Pango::Layout::Alignment::CENTER
|
||||
(layout.width - iter.line_extents[0].width) / 2
|
||||
when Pango::Layout::Alignment::RIGHT
|
||||
layout.width - iter.line_extents[0].width
|
||||
else
|
||||
0
|
||||
end
|
||||
x = Pango.pixels(rect.x + (letter_width / 2))
|
||||
y = Pango.pixels(rect.y)
|
||||
circle(x, y + 2, 2, :red, :red, 0)
|
||||
# circle(x,y + 2, 2, :red, :red, 0)
|
||||
puts <<-EOS
|
||||
Embedding #{key}
|
||||
at index: #{index}
|
||||
iter index #{iter.index}
|
||||
layout width: #{layout.width}
|
||||
line width: #{iter.line_extents[0].width} or #{Pango.pixels iter.line_extents[0].width}px
|
||||
pango's x at start of paragraph is #{Pango.pixels para_x}px
|
||||
pango's index_to_ps xy #{rect.x},#{rect.y} or #{Pango.pixels rect.x},#{Pango.pixels rect.y} (px)
|
||||
xy #{x},#{y}
|
||||
spacing at #{spacing} or #{spacing / Pango::SCALE}px
|
||||
spacing at #{spacing} or #{Pango.pixels spacing}px
|
||||
space character width #{letter_width} or #{letter_width / Pango::SCALE}px
|
||||
and string is:
|
||||
#{str}
|
||||
|
|
@ -126,13 +139,6 @@ module Squib
|
|||
svg(rule[:file], rule[:id], x, y, rule[:width], rule[:height],
|
||||
rule[:alpha], rule[:blend], rule[:angle], SYSTEM_DEFAULTS[:mask])
|
||||
end
|
||||
# embed.rules.each do |rule|
|
||||
# cc.update_pango_layout(layout)
|
||||
# index = str.index(rule[:key])
|
||||
# unless index.nil?
|
||||
# puts "embed #{rule[:type]} #{rule[:file]} into #{rule[:key]} at #{x},#{y}, index #{index}"
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
|
|
@ -170,8 +176,6 @@ module Squib
|
|||
cc.update_pango_layout(layout)
|
||||
|
||||
process_embeds(embed, str, layout, cc)
|
||||
cc.update_pango_layout(layout)
|
||||
|
||||
cc.show_pango_layout(layout)
|
||||
draw_text_hint(cc,x,y,layout,hint,angle)
|
||||
extents = { width: layout.extents[1].width / Pango::SCALE,
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
require 'squib'
|
||||
|
||||
Squib::Deck.new do
|
||||
background color: :white
|
||||
rect x: 0, y: 0, width: 825, height: 1125
|
||||
rect x: 0, y: 0, width: 180, height: 180, stroke_color: :red
|
||||
|
||||
# embed_text = 'Take 1:tool:and gain 2 :health:. Take 2 :tool: if level 2'
|
||||
embed_text = '1 :tool: 2 :health:'
|
||||
embed_text = ' 1:tool: 2 :health:'
|
||||
text(str: embed_text, font: 'Sans 18',
|
||||
x: 0, y: 0, width: 180,
|
||||
align: :center, ellipsize: false, justify: false) do |embed|
|
||||
align: :right, ellipsize: false, justify: false) 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'
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue