Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draw embedded images only a single time #292

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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