Class: Rouge::Formatters::Prawn::BackgroundColorizer

Inherits:
Object
  • Object
show all
Defined in:
lib/asciidoctor/pdf/ext/rouge/formatters/prawn.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ BackgroundColorizer

Returns a new instance of BackgroundColorizer.



181
182
183
# File 'lib/asciidoctor/pdf/ext/rouge/formatters/prawn.rb', line 181

def initialize opts = {}
  @line_gap = opts[:line_gap] || 0
end

Instance Method Details

#render_behind(fragment) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/asciidoctor/pdf/ext/rouge/formatters/prawn.rb', line 185

def render_behind fragment
  pdf = fragment.document
  data = fragment.format_state
  prev_fill_color = pdf.fill_color
  pdf.fill_color data[:background_color]
  if data[:inline_block]
    fragment_width = data[:extend] ? pdf.bounds.width - fragment.left : fragment.width
    v_gap = @line_gap
  else
    fragment_width = fragment.width
    v_gap = 0
  end
  pdf.fill_rectangle [fragment.left, fragment.top + v_gap * 0.5], fragment_width, (fragment.height + v_gap)
  pdf.fill_color prev_fill_color
  fragment.conceal true if fragment.text == DummyText
  nil
end