Class: Origami::Page

Inherits:
Dictionary show all
Includes:
ResourcesHolder, StandardObject
Defined in:
lib/origami/page.rb,
lib/origami/graphics/xobject.rb

Overview

class ContentStream

Defined Under Namespace

Modules: Format Classes: AdditionalActions, BoxColorInformation, BoxStyle, NavigationNode

Constant Summary

Constants included from StandardObject

StandardObject::DEFAULT_ATTRIBUTES

Constants inherited from Dictionary

Dictionary::TOKENS

Constants included from Object

Object::TOKENS

Instance Attribute Summary

Attributes included from ObjectCache

#names_cache, #strings_cache, #xref_cache

Attributes included from Object

#file_offset, #generation, #no, #objstm_offset, #parent

Instance Method Summary collapse

Methods included from ResourcesHolder

#add_colorspace, #add_extgstate, #add_font, #add_pattern, #add_properties, #add_resource, #add_shading, #add_xobject, #colorspaces, #each_colorspace, #each_extgstate, #each_font, #each_pattern, #each_property, #each_resource, #each_shading, #each_xobject, #extgstates, #fonts, #patterns, #properties, #resources, #shadings, #xobjects

Methods included from StandardObject

included, #version_required

Methods inherited from Dictionary

#[], #[]=, hint_type, #merge, parse, #to_h, #to_obfuscated_str, #to_s, #transform_values, #transform_values!

Methods included from TypeGuessing

#guess_type

Methods included from FieldAccessor

#method_missing, #respond_to_missing?

Methods included from CompoundObject

#copy, #delete, #include?, #update_values, #update_values!

Methods included from ObjectCache

#rebuild_caches

Methods included from Object

#cast_to, #copy, #document, #export, included, #indirect?, #indirect_parent, #logicalize, #logicalize!, #native_type, #numbered?, parse, #post_build, #reference, #set_document, #set_indirect, skip_until_next_obj, #solve, #to_o, #to_s, #type, typeof, #version_required, #xrefs

Constructor Details

#initialize(hash = {}, parser = nil) ⇒ Page

Returns a new instance of Page.



585
586
587
588
589
# File 'lib/origami/page.rb', line 585

def initialize(hash = {}, parser = nil)
  super

  set_indirect(true)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Origami::FieldAccessor

Instance Method Details

#add_annotation(*annotations) ⇒ Object

Add an Annotation to the Page.



630
631
632
633
634
635
636
637
# File 'lib/origami/page.rb', line 630

def add_annotation(*annotations)
  self.Annots ||= []

  annotations.each do |annot|
    annot.solve[:P] = self if indirect?
    self.Annots << annot
  end
end

#add_flash_application(swfspec, params = {}) ⇒ Object

Embed a SWF Flash application in the page.



663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
# File 'lib/origami/page.rb', line 663

def add_flash_application(swfspec, params = {})
  options =
    {
      windowed: false,
      transparent: false,
      navigation_pane: false,
      toolbar: false,
      pass_context_click: false,
      activation: Annotation::RichMedia::Activation::PAGE_OPEN,
      deactivation: Annotation::RichMedia::Deactivation::PAGE_CLOSE,
      flash_vars: nil
    }
  options.update(params)

  annot = create_richmedia(:Flash, swfspec, options)
  add_annotation(annot)

  annot
end

#annotationsObject

Returns the array of Annotation objects of the Page.



656
657
658
# File 'lib/origami/page.rb', line 656

def annotations
  each_annotation.to_a
end

#content_streamsObject

Returns an Array of ContentStreams for the Page.



623
624
625
# File 'lib/origami/page.rb', line 623

def content_streams
  each_content_stream.to_a
end

#draw_imageObject

TODO :nodoc:

Raises:

  • (NotImplementedError)


461
462
463
# File 'lib/origami/graphics/xobject.rb', line 461

def draw_image
  raise NotImplementedError
end

#draw_line(from, to, attr = {}) ⇒ Object

See ContentStream#draw_line.



466
467
468
469
# File 'lib/origami/graphics/xobject.rb', line 466

def draw_line(from, to, attr = {})
  last_content_stream.draw_line(from, to, attr)
  self
end

#draw_polygon(coords = [], attr = {}) ⇒ Object

See ContentStream#draw_polygon.



472
473
474
475
# File 'lib/origami/graphics/xobject.rb', line 472

def draw_polygon(coords = [], attr = {})
  last_content_stream.draw_polygon(coords, attr)
  self
end

#draw_rectangle(x, y, width, height, attr = {}) ⇒ Object

See ContentStream#draw_rectangle.



478
479
480
481
# File 'lib/origami/graphics/xobject.rb', line 478

def draw_rectangle(x, y, width, height, attr = {})
  last_content_stream.draw_rectangle(x, y, width, height, attr)
  self
end

#each_annotationObject

Iterate through each Annotation of the Page.



642
643
644
645
646
647
648
649
650
651
# File 'lib/origami/page.rb', line 642

def each_annotation
  annots = self.Annots

  return enum_for(__method__) { annots.is_a?(Array) ? annots.length : 0 } unless block_given?
  return unless annots.is_a?(Array)

  annots.each do |annot|
    yield(annot.solve)
  end
end

#each_content_streamObject

Iterates over all the ContentStreams of the Page.



600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
# File 'lib/origami/page.rb', line 600

def each_content_stream
  contents = self.Contents

  unless block_given?
    return enum_for(__method__) do
      case contents
      when Array then contents.length
      when Stream then 1
      else
        0
      end
    end
  end

  case contents
  when Stream then yield(contents)
  when Array then contents.each { |stm| yield(stm.solve) }
  end
end

#onClose(action) ⇒ Object

Will execute an action when the page is closed.



696
697
698
699
700
701
# File 'lib/origami/page.rb', line 696

def onClose(action)
  self.AA ||= Page::AdditionalActions.new
  self.AA.C = action

  self
end

#onNavigateBackward(action) ⇒ Object

Will execute an action when navigating backward from this page.



716
717
718
719
720
721
# File 'lib/origami/page.rb', line 716

def onNavigateBackward(action) # :nodoc:
  self.PresSteps ||= NavigationNode.new
  self.PresSteps.PA = action

  self
end

#onNavigateForward(action) ⇒ Object

Will execute an action when navigating forward from this page.



706
707
708
709
710
711
# File 'lib/origami/page.rb', line 706

def onNavigateForward(action) # :nodoc:
  self.PresSteps ||= NavigationNode.new
  self.PresSteps.NA = action

  self
end

#onOpen(action) ⇒ Object

Will execute an action when the page is opened.



686
687
688
689
690
691
# File 'lib/origami/page.rb', line 686

def onOpen(action)
  self.AA ||= Page::AdditionalActions.new
  self.AA.O = action

  self
end

#paint_shading(shade) ⇒ Object

TODO :nodoc:



490
491
492
# File 'lib/origami/graphics/xobject.rb', line 490

def paint_shading(shade)
  last_content_stream.paint_shading(shade)
end

#pre_buildObject



591
592
593
594
595
# File 'lib/origami/page.rb', line 591

def pre_build
  self.Resources = Resources.new.pre_build unless has_key?(:Resources)

  super
end

#render(engine) ⇒ Object

:nodoc:



449
450
451
452
453
454
455
456
457
458
# File 'lib/origami/graphics/xobject.rb', line 449

def render(engine) # :nodoc:
  contents = self.Contents
  contents = [contents] unless contents.is_a? Array

  contents.each do |stream|
    stream = stream.cast_to(ContentStream) unless stream.is_a? ContentStream

    stream.render(engine)
  end
end

#set_dash_pattern(pattern) ⇒ Object

See ContentStream#set_dash_pattern.



554
555
556
557
# File 'lib/origami/graphics/xobject.rb', line 554

def set_dash_pattern(pattern)
  last_content_stream.set_dash_pattern(pattern)
  self
end

#set_fill_color(color) ⇒ Object

See ContentStream#set_fill_color.



542
543
544
545
# File 'lib/origami/graphics/xobject.rb', line 542

def set_fill_color(color)
  last_content_stream.set_fill_color(color)
  self
end

#set_line_cap(cap) ⇒ Object

See ContentStream#set_line_cap.



566
567
568
569
# File 'lib/origami/graphics/xobject.rb', line 566

def set_line_cap(cap)
  last_content_stream.set_line_cap(cap)
  self
end

#set_line_join(join) ⇒ Object

See ContentStream#set_line_join.



572
573
574
575
# File 'lib/origami/graphics/xobject.rb', line 572

def set_line_join(join)
  last_content_stream.set_line_join(join)
  self
end

#set_line_width(width) ⇒ Object

See ContentStream#set_line_width.



560
561
562
563
# File 'lib/origami/graphics/xobject.rb', line 560

def set_line_width(width)
  last_content_stream.set_line_width(width)
  self
end

#set_stroke_color(color) ⇒ Object

See ContentStream#set_stroke_color.



548
549
550
551
# File 'lib/origami/graphics/xobject.rb', line 548

def set_stroke_color(color)
  last_content_stream.set_stroke_color(color)
  self
end

#set_text_char_spacing(char_spacing) ⇒ Object

See ContentStream#set_text_char_spacing.



536
537
538
539
# File 'lib/origami/graphics/xobject.rb', line 536

def set_text_char_spacing(char_spacing)
  last_content_stream.set_text_char_spacing(char_spacing)
  self
end

#set_text_font(_font, _size) ⇒ Object

TODO :nodoc:

Raises:

  • (NotImplementedError)


495
496
497
# File 'lib/origami/graphics/xobject.rb', line 495

def set_text_font(_font, _size)
  raise NotImplementedError
end

#set_text_leading(leading) ⇒ Object

See ContentStream#set_text_leading.



506
507
508
509
# File 'lib/origami/graphics/xobject.rb', line 506

def set_text_leading(leading)
  last_content_stream.set_text_leading(leading)
  self
end

#set_text_pos(tx, ty) ⇒ Object

See ContentStream#set_text_pos.



500
501
502
503
# File 'lib/origami/graphics/xobject.rb', line 500

def set_text_pos(tx, ty)
  last_content_stream.set_text_pos(tx, ty)
  self
end

#set_text_rendering(rendering) ⇒ Object

See ContentStream#set_text_rendering.



512
513
514
515
# File 'lib/origami/graphics/xobject.rb', line 512

def set_text_rendering(rendering)
  last_content_stream.set_text_rendering(rendering)
  self
end

#set_text_rise(rise) ⇒ Object

See ContentStream#set_text_rise.



518
519
520
521
# File 'lib/origami/graphics/xobject.rb', line 518

def set_text_rise(rise)
  last_content_stream.set_text_rise(rise)
  self
end

#set_text_scale(scaling) ⇒ Object

See ContentStream#set_text_scale.



524
525
526
527
# File 'lib/origami/graphics/xobject.rb', line 524

def set_text_scale(scaling)
  last_content_stream.set_text_scale(scaling)
  self
end

#set_text_word_spacing(word_spacing) ⇒ Object

See ContentStream#set_text_word_spacing.



530
531
532
533
# File 'lib/origami/graphics/xobject.rb', line 530

def set_text_word_spacing(word_spacing)
  last_content_stream.set_text_word_spacing(word_spacing)
  self
end

#write(text, attr = {}) ⇒ Object

See ContentStream#write.



484
485
486
487
# File 'lib/origami/graphics/xobject.rb', line 484

def write(text, attr = {})
  last_content_stream.write(text, attr)
  self
end