Sha256: 7d4b00d9696551966d4c5e68e398874f6d004efcb57677d780cc26e879bc555b

Contents?: true

Size: 1007 Bytes

Versions: 3

Compression:

Stored size: 1007 Bytes

Contents

# frozen_string_literal: true

class PDF::Core::Page
  InitialPageContent = %(q\n)

  # Record the page's current state as the tare content stream (i.e., empty, meaning no content has been written).
  def tare_content_stream
    @tare_content_stream = content.stream.filtered_stream
  end

  # Returns whether the current page is empty based on tare content stream (i.e., no content has been written).
  # Returns false if a page has not yet been created.
  def empty?
    content.stream.filtered_stream == (@tare_content_stream ||= InitialPageContent) && document.page_number > 0
  end

  # Reset the content of the page.
  # Note that this method may leave behind an orphaned background image.
  def reset_content
    return if content.stream.filtered_stream == InitialPageContent
    xobjects.clear
    ext_gstates.clear
    new_content = document.state.store[document.ref({})]
    new_content << 'q' << ?\n
    content.replace new_content
    @tare_content_stream = InitialPageContent
    nil
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
asciidoctor-pdf-2.0.0.alpha.3 lib/asciidoctor/pdf/ext/pdf-core/page.rb
asciidoctor-pdf-2.0.0.alpha.2 lib/asciidoctor/pdf/ext/pdf-core/page.rb
asciidoctor-pdf-2.0.0.alpha.1 lib/asciidoctor/pdf/ext/pdf-core/page.rb