def embed_images!(embed, str, layout, valign)
      return [] unless embed.rules.any?
      layout.markup = str
      clean_str     = layout.text
      attrs = layout.attributes || Pango::AttrList.new
      EmbeddingUtils.indices(clean_str, embed.rules.keys).each do |key, ranges|
        rule = embed.rules[key]
        ranges.each do |range|
          carve = Pango::Rectangle.new(0, 0, compute_carve(rule, range), 0)
          att = Pango::AttrShape.new(carve, carve, rule)
          att.start_index = range.first
          att.end_index = range.last
          attrs.insert(att)
        end
      end
      layout.attributes = attrs
      layout.context.set_shape_renderer do |cxt, att, do_path|
        unless do_path # when stroking the text
          rule = att.data
          x = Pango.pixels(layout.index_to_pos(att.start_index).x) +
              rule[:adjust].dx[@index]
          y = Pango.pixels(layout.index_to_pos(att.start_index).y) +
                rule[:adjust].dy[@index] +
                compute_valign(layout, valign, rule[:box].height[@index])
          rule[:draw].call(self, x, y)
          cxt.reset_clip
          [cxt, att, do_path]
        end
      end
    end
def embed_images!(embed, str, layout, valign)
      return [] unless embed.rules.any?
      layout.markup = str
      clean_str     = layout.text
      attrs = layout.attributes || Pango::AttrList.new
      EmbeddingUtils.indices(clean_str, embed.rules.keys).each do |key, ranges|
        rule = embed.rules[key]
        ranges.each do |range|
          carve = Pango::Rectangle.new(0, 0, compute_carve(rule, range), 0)
          att = Pango::AttrShape.new(carve, carve, rule)
          att.start_index = range.first
          att.end_index = range.last
          attrs.insert(att)
        end
      end
      layout.attributes = attrs
      layout.context.set_shape_renderer do |cxt, att, do_path|
        unless do_path # when stroking the text
          rule = att.data
          x = Pango.pixels(layout.index_to_pos(att.start_index).x) +
              rule[:adjust].dx[@index]
          y = Pango.pixels(layout.index_to_pos(att.start_index).y) +
                rule[:adjust].dy[@index] +
                compute_valign(layout, valign, rule[:box].height[@index])
          rule[:draw].call(self, x, y)
          cxt.reset_clip
          [cxt, att, do_path]
        end
      end
    end
# :nodoc:
 # @api private