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

#do_type_check, #has_field?, included, #set_default_value, #set_default_values, #version_required

Methods inherited from Dictionary

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

Methods included from Object

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



574
575
576
577
578
# File 'lib/origami/page.rb', line 574

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::Dictionary

Instance Method Details

#add_annotation(*annotations) ⇒ Object

Add an Annotation to the Page.



617
618
619
620
621
622
623
624
625
626
627
628
# File 'lib/origami/page.rb', line 617

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.



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

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.



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

def annotations
    self.each_annotation.to_a
end

#content_streamsObject

Returns an Array of ContentStreams for the Page.



610
611
612
# File 'lib/origami/page.rb', line 610

def content_streams
    self.each_content_stream.to_a
end

#draw_imageObject

TODO :nodoc:

Raises:

  • (NotImplementedError)


449
450
451
# File 'lib/origami/graphics/xobject.rb', line 449

def draw_image
    raise NotImplementedError
end

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

See ContentStream#draw_line.



454
455
456
# File 'lib/origami/graphics/xobject.rb', line 454

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.



459
460
461
# File 'lib/origami/graphics/xobject.rb', line 459

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.



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

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.



633
634
635
636
637
638
639
640
641
642
# File 'lib/origami/page.rb', line 633

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.



589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
# File 'lib/origami/page.rb', line 589

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.



691
692
693
694
695
696
697
698
699
700
# File 'lib/origami/page.rb', line 691

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.



719
720
721
722
723
724
725
726
727
728
# File 'lib/origami/page.rb', line 719

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.



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

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.



677
678
679
680
681
682
683
684
685
686
# File 'lib/origami/page.rb', line 677

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:

Raises:

  • (NotImplementedError)


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

def paint_shading(shade)
    raise NotImplementedError
end

#pre_buildObject



580
581
582
583
584
# File 'lib/origami/page.rb', line 580

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

    super
end

#render(engine) ⇒ Object

:nodoc:



437
438
439
440
441
442
443
444
445
446
# File 'lib/origami/graphics/xobject.rb', line 437

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.



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

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

#set_fill_color(color) ⇒ Object

See ContentStream#set_fill_color.



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

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

#set_line_cap(cap) ⇒ Object

See ContentStream#set_line_cap.



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

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

#set_line_join(join) ⇒ Object

See ContentStream#set_line_join.



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

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

#set_line_width(width) ⇒ Object

See ContentStream#set_line_width.



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

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

#set_stroke_color(color) ⇒ Object

See ContentStream#set_stroke_color.



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

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.



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

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)


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

def set_text_font(font, size)
    raise NotImplementedError
end

#set_text_leading(leading) ⇒ Object

See ContentStream#set_text_leading.



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

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.



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

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.



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

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

#set_text_rise(rise) ⇒ Object

See ContentStream#set_text_rise.



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

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

#set_text_scale(scaling) ⇒ Object

See ContentStream#set_text_scale.



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

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.



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

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.



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

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