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