Class: Origami::FDF
- Inherits:
-
Object
- Object
- Origami::FDF
- Defined in:
- lib/origami/extensions/fdf.rb,
lib/origami/parsers/fdf.rb
Overview
Class representing an AcroForm Forms Data Format file.
Defined Under Namespace
Classes: Annotation, Catalog, Dictionary, Field, Header, IconFit, JavaScript, NamedPageReference, Page, Parser, Revision, Template
Instance Attribute Summary collapse
-
#header ⇒ Object
Returns the value of attribute header.
-
#revisions ⇒ Object
Returns the value of attribute revisions.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(object) ⇒ Object (also: #insert)
-
#cast_object(reference, type) ⇒ Object
:nodoc:.
- #Catalog ⇒ Object
-
#get_object(no, generation = 0) ⇒ Object
:nodoc:.
- #indirect_objects ⇒ Object (also: #root_objects)
-
#initialize(parser = nil) ⇒ FDF
constructor
:nodoc:.
- #save(path) ⇒ Object
Constructor Details
#initialize(parser = nil) ⇒ FDF
:nodoc:
210 211 212 213 214 215 216 217 |
# File 'lib/origami/extensions/fdf.rb', line 210 def initialize(parser = nil) #:nodoc: @header = FDF::Header.new @revisions = [ Revision.new(self) ] @revisions.first.trailer = Trailer.new @parser = parser init if parser.nil? end |
Instance Attribute Details
#header ⇒ Object
Returns the value of attribute header.
208 209 210 |
# File 'lib/origami/extensions/fdf.rb', line 208 def header @header end |
#revisions ⇒ Object
Returns the value of attribute revisions.
208 209 210 |
# File 'lib/origami/extensions/fdf.rb', line 208 def revisions @revisions end |
Class Method Details
Instance Method Details
#<<(object) ⇒ Object Also known as: insert
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/origami/extensions/fdf.rb', line 219 def <<(object) object.set_indirect(true) object.set_document(self) if object.no.zero? maxno = 1 maxno = maxno.succ while get_object(maxno) object.generation = 0 object.no = maxno end @revisions.first.body[object.reference] = object object.reference end |
#cast_object(reference, type) ⇒ Object
:nodoc:
255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/origami/extensions/fdf.rb', line 255 def cast_object(reference, type) #:nodoc: @revisions.each do |rev| if rev.body.include?(reference) and type < rev.body[reference].class rev.body[reference] = rev.body[reference].cast_to(type, @parser) rev.body[reference] else nil end end end |
#Catalog ⇒ Object
267 268 269 |
# File 'lib/origami/extensions/fdf.rb', line 267 def Catalog get_object(@revisions.first.trailer.Root) end |
#get_object(no, generation = 0) ⇒ Object
:nodoc:
237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/origami/extensions/fdf.rb', line 237 def get_object(no, generation = 0) #:nodoc: case no when Reference target = no when ::Integer target = Reference.new(no, generation) when Origami::Object return no end @revisions.first.body[target] end |
#indirect_objects ⇒ Object Also known as: root_objects
250 251 252 |
# File 'lib/origami/extensions/fdf.rb', line 250 def indirect_objects @revisions.inject([]) do |set, rev| set.concat(rev.objects) end end |
#save(path) ⇒ Object
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/origami/extensions/fdf.rb', line 271 def save(path) bin = "".b bin << @header.to_s lastno, brange = 0, 0 xrefs = [ XRef.new(0, XRef::FIRSTFREE, XRef::FREE) ] xrefsection = XRef::Section.new @revisions.first.body.values.sort.each { |obj| if (obj.no - lastno).abs > 1 xrefsection << XRef::Subsection.new(brange, xrefs) brange = obj.no xrefs.clear end xrefs << XRef.new(bin.size, obj.generation, XRef::USED) lastno = obj.no obj.pre_build bin << obj.to_s obj.post_build } xrefsection << XRef::Subsection.new(brange, xrefs) @xreftable = xrefsection @trailer ||= Trailer.new @trailer.Size = @revisions.first.body.size + 1 @trailer.startxref = bin.size bin << @xreftable.to_s bin << @trailer.to_s if path.respond_to?(:write) io = path else path = File.(path) io = File.open(path, "wb", encoding: 'binary') close = true end begin io.write(bin) ensure io.close if close end self end |