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.



641
642
643
644
645
# File 'lib/origami/page.rb', line 641

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

    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.



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

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

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

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

Embed a SWF Flash application in the page.



717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
# File 'lib/origami/page.rb', line 717

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.



710
711
712
# File 'lib/origami/page.rb', line 710

def annotations
    self.each_annotation.to_a
end

#content_streamsObject

Returns an Array of ContentStreams for the Page.



677
678
679
# File 'lib/origami/page.rb', line 677

def content_streams
    self.each_content_stream.to_a
end

#draw_imageObject

TODO :nodoc:

Raises:

  • (NotImplementedError)


464
465
466
# File 'lib/origami/graphics/xobject.rb', line 464

def draw_image
    raise NotImplementedError
end

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

See ContentStream#draw_line.



469
470
471
# File 'lib/origami/graphics/xobject.rb', line 469

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.



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

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.



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

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.



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

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.



656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
# File 'lib/origami/page.rb', line 656

def each_content_stream
    contents = self.Contents

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

    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.



750
751
752
753
754
755
# File 'lib/origami/page.rb', line 750

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.



770
771
772
773
774
775
# File 'lib/origami/page.rb', line 770

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.



760
761
762
763
764
765
# File 'lib/origami/page.rb', line 760

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.



740
741
742
743
744
745
# File 'lib/origami/page.rb', line 740

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

    self
end

#paint_shading(shade) ⇒ Object

TODO :nodoc:



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

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

#pre_buildObject



647
648
649
650
651
# File 'lib/origami/page.rb', line 647

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

    super
end

#render(engine) ⇒ Object

:nodoc:



452
453
454
455
456
457
458
459
460
461
# File 'lib/origami/graphics/xobject.rb', line 452

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.



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

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

#set_fill_color(color) ⇒ Object

See ContentStream#set_fill_color.



534
535
536
# File 'lib/origami/graphics/xobject.rb', line 534

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

#set_line_cap(cap) ⇒ Object

See ContentStream#set_line_cap.



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

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

#set_line_join(join) ⇒ Object

See ContentStream#set_line_join.



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

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

#set_line_width(width) ⇒ Object

See ContentStream#set_line_width.



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

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

#set_stroke_color(color) ⇒ Object

See ContentStream#set_stroke_color.



539
540
541
# File 'lib/origami/graphics/xobject.rb', line 539

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.



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

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)


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

def set_text_font(_font, _size)
    raise NotImplementedError
end

#set_text_leading(leading) ⇒ Object

See ContentStream#set_text_leading.



504
505
506
# File 'lib/origami/graphics/xobject.rb', line 504

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.



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

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.



509
510
511
# File 'lib/origami/graphics/xobject.rb', line 509

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

#set_text_rise(rise) ⇒ Object

See ContentStream#set_text_rise.



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

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

#set_text_scale(scaling) ⇒ Object

See ContentStream#set_text_scale.



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

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.



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

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
# File 'lib/origami/graphics/xobject.rb', line 484

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