Skip to content

Commit

Permalink
Draw embedded images only a single time
Browse files Browse the repository at this point in the history
Embedded images were previously drawn once for each character
in the embed key, causing issues for semi-transparent images.
See issue #278. With this commit, the embed image is only drawn
for the first character in the embed keys, and a sentinel
attribute is used for the remaining characters in the key to
draw neither text not an image for them.
  • Loading branch information
Mirko Kugelmeier committed Oct 24, 2019
1 parent 1b7dc67 commit 9ebd42d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/squib/graphics/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,21 @@ def embed_images!(embed, str, layout, valign, scale)
carve = Pango::Rectangle.new(0, 0, compute_carve(rule, range) * scale, 0)
att = Pango::AttrShape.new(carve, carve, rule)
att.start_index = range.first
att.end_index = range.last
att.end_index = range.first+1
attrs.insert(att)

# Add an empty draw for all but the first characters in the key, so they
# don't appear in the output, but we only draw the actual symbol once
att_nodraw = Pango::AttrShape.new(carve, carve, "nodraw")
att_nodraw.start_index = range.first + 1
att_nodraw.end_index = range.last
attrs.insert(att_nodraw)

end
end
layout.attributes = attrs
layout.context.set_shape_renderer do |cxt, att, do_path|
unless do_path # when stroking the text
unless do_path || att.data == "nodraw" # when stroking the text
rule = att.data
x = Pango.pixels(layout.index_to_pos(att.start_index).x) +
rule[:adjust].dx[@index]
Expand Down

0 comments on commit 9ebd42d

Please sign in to comment.