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 inherited from Dictionary

#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

#[], #[]=, add_type_signature, #cast_to, #copy, #delete, guess_type, hint_type, #key?, #map!, #merge, parse, #to_h, #to_obfuscated_str, #to_s

Methods included from FieldAccessor

#method_missing, #respond_to_missing?

Methods included from Object

#<=>, #cast_to, #copy, #document, #export, included, #indirect?, #indirect_parent, #logicalize, #logicalize!, #native_type, 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.



570
571
572
573
574
# File 'lib/origami/page.rb', line 570

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.



613
614
615
616
617
618
619
620
621
622
623
624
# File 'lib/origami/page.rb', line 613

def add_annotation(*annotations)
    unless annotations.all?{|annot| annot.is_a?(Annotation) or annot.is_a?(Reference)}
        raise TypeError, "Only Annotation objects must be passed."
    end

    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.



650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
# File 'lib/origami/page.rb', line 650

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.



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

def annotations
    self.each_annotation.to_a
end

#content_streamsObject

Returns an Array of ContentStreams for the Page.



606
607
608
# File 'lib/origami/page.rb', line 606

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.



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

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.



585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
# File 'lib/origami/page.rb', line 585

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.



687
688
689
690
691
692
693
694
695
696
# File 'lib/origami/page.rb', line 687

def onClose(action)
    unless action.is_a?(Action) or action.is_a?(Reference)
        raise TypeError, "An Action object must be passed."
    end

    self.AA ||= Page::AdditionalActions.new
    self.AA.C = action

    self
end

#onNavigateBackward(action) ⇒ Object

Will execute an action when navigating backward from this page.



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

def onNavigateBackward(action) #:nodoc:
    unless action.is_a?(Action) or action.is_a?(Reference)
        raise TypeError, "An Action object must be passed."
    end

    self.PresSteps ||= NavigationNode.new
    self.PresSteps.PA = action

    self
end

#onNavigateForward(action) ⇒ Object

Will execute an action when navigating forward from this page.



701
702
703
704
705
706
707
708
709
710
# File 'lib/origami/page.rb', line 701

def onNavigateForward(action) #:nodoc:
    unless action.is_a?(Action) or action.is_a?(Reference)
        raise TypeError, "An Action object must be passed."
    end

    self.PresSteps ||= NavigationNode.new
    self.PresSteps.NA = action

    self
end

#onOpen(action) ⇒ Object

Will execute an action when the page is opened.



673
674
675
676
677
678
679
680
681
682
# File 'lib/origami/page.rb', line 673

def onOpen(action)
    unless action.is_a?(Action) or action.is_a?(Reference)
        raise TypeError, "An Action object must be passed."
    end

    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



576
577
578
579
580
# File 'lib/origami/page.rb', line 576

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