class PDFWalker::Walker::ObjectView

Attributes

parent[R]
pdfpanel[R]
valuepanel[R]

Public Class Methods

new(parent) click to toggle source
Calls superclass method
# File lib/pdfwalker/textview.rb, line 35
def initialize(parent)
    @parent = parent
    super()

    @pdfbuffer = TextBuffer.new
    @pdfview = TextView.new(@pdfbuffer).set_editable(false).set_cursor_visible(false).set_left_margin(5)

    @pdfpanel = ScrolledWindow.new.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
    @pdfpanel.add_with_viewport @pdfview
    append_page(@pdfpanel, Label.new("PDF Code"))

    @pdfbuffer.create_tag("Default",
        weight: Pango::Weight::BOLD,
        family: "monospace",
        scale: Pango::Scale::LARGE
    )
end

Public Instance Methods

clear() click to toggle source
# File lib/pdfwalker/textview.rb, line 82
def clear
    @pdfbuffer.set_text("")
end
load(object) click to toggle source
# File lib/pdfwalker/textview.rb, line 53
def load(object)
    begin
        self.clear

        case object
        when Origami::PDF::Header, Origami::FDF::Header, Origami::PPKLite::Header
            text = object.to_s
            @pdfbuffer.set_text(text)
            @pdfbuffer.apply_tag("Default", @pdfbuffer.start_iter, @pdfbuffer.end_iter)

        when Origami::Object
            if object.is_a?(Origami::Stream)
                text = [ "#{object.no} #{object.generation} obj", object.dictionary ].join($/)
            else
                text = object.to_s
            end

            text.encode!("UTF-8", replace: '.')
                .tr!("\x00", '.')

            @pdfbuffer.set_text(text)
            @pdfbuffer.apply_tag("Default", @pdfbuffer.start_iter, @pdfbuffer.end_iter)
        end

    rescue
        @parent.error("An error occured while loading this object.\n#{$!} (#{$!.class})")
    end
end