class Podoff::Obj
Constants
- ATTRIBUTES
Attributes
attributes[R]
document[R]
end_index[R]
ref[R]
start_index[R]
stream[R]
Public Class Methods
extract(doc)
click to toggle source
# File lib/podoff.rb, line 340 def self.extract(doc) sca = doc.scanner re = sca.matched[0..-4].strip st = sca.pos - sca.matched.length i = sca.skip_until(/endobj/); return nil unless i en = sca.pos - 1 Podoff::Obj.new(doc, re, start_index: st, end_index: en) end
new(doc, ref, opts={})
click to toggle source
# File lib/podoff.rb, line 359 def initialize(doc, ref, opts={}) @document = doc @ref = ref @start_index = opts[:start_index] @end_index = opts[:end_index] @attributes = nil @source = opts[:source] @stream = opts[:stream] @stream.obj = self if @stream recompute_attributes #@source.obj = self if @source.is_a?(Podoff::Stream) @document.scanner.pos = @end_index if @document.scanner && @end_index end
Public Instance Methods
dup(new_doc)
click to toggle source
# File lib/podoff.rb, line 378 def dup(new_doc) self.class.new( new_doc, ref, start_index: start_index, end_index: end_index) end
insert_contents(obj_or_ref)
click to toggle source
# File lib/podoff.rb, line 427 def insert_contents(obj_or_ref) fail ArgumentError.new("target '#{ref}' not a replica") \ unless @source fail ArgumentError.new("target '#{ref}' doesn't have /Contents") \ unless @attributes[:contents] re = obj_or_ref re = re.obj if re.respond_to?(:obj) # Stream re = re.ref if re.respond_to?(:ref) add_to_attribute(:contents, re) end
Also aliased as: insert_content
insert_font(nick, obj_or_ref)
click to toggle source
# File lib/podoff.rb, line 414 def insert_font(nick, obj_or_ref) fail ArgumentError.new("target '#{ref}' not a replica") \ unless @source nick = nick[1..-1] if nick[0] == '/' re = obj_or_ref re = re.ref if re.respond_to?(:ref) @source = @source.gsub(/\/Font\s*<</, "/Font\n<<\n/#{nick} #{re} R") end
replica?()
click to toggle source
# File lib/podoff.rb, line 404 def replica? @source != nil end
replicate()
click to toggle source
def self.create(doc, ref, source)
self.new(doc, ref, nil, nil, nil, source)
end
# File lib/podoff.rb, line 389 def replicate self.class.new(document, ref, source: source.dup) end
source()
click to toggle source
# File lib/podoff.rb, line 399 def source @source || (@start_index && @document.source[@start_index..@end_index]) end
to_a()
click to toggle source
# File lib/podoff.rb, line 394 def to_a [ @ref, @start_index, @end_index, @attributes ] end
to_s()
click to toggle source
# File lib/podoff.rb, line 442 def to_s source || stream.to_s end
type()
click to toggle source
# File lib/podoff.rb, line 409 def type @attributes && @attributes[:type] end
Protected Instance Methods
add_to_attribute(key, ref)
click to toggle source
# File lib/podoff.rb, line 477 def add_to_attribute(key, ref) fail ArgumentError.new("obj not replicated") unless @source pkey = ATTRIBUTES[key] if v = @attributes[key] v = concat(v, ref) @source = @source.gsub(/#{pkey} ([\[\]0-9 R]+)/, "#{pkey} #{v}") else i = @source.index('/Type ') @source.insert(i, "/#{pkey} [#{ref} R]\n") end recompute_attributes end
concat(refs, ref)
click to toggle source
# File lib/podoff.rb, line 469 def concat(refs, ref) refs = refs.strip refs = refs[1..-2] if refs[0] == '[' "[#{refs} #{ref} R]" end
recompute_attributes()
click to toggle source
# File lib/podoff.rb, line 449 def recompute_attributes st, en, sca = if @start_index [ @start_index, @end_index, @document.scanner ] elsif @source [ 0, @source.length, ::StringScanner.new(@source) ] end return unless sca @attributes = ATTRIBUTES.inject({}) do |h, (k, v)| sca.pos = st i = sca.skip_until(/\/#{v}\b/) h[k] = sca.scan(/ *\/?[^\n\r\/>]+/).strip if i && sca.pos < en h end end