Class: Pdfrb::Model::Type::GenericAppearance

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfrb/model/type/generic_appearance.rb

Direct Known Subclasses

LinkAppearance, TextAppearance, WidgetAppearance

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(annotation, document) ⇒ GenericAppearance

Returns a new instance of GenericAppearance.



9
10
11
12
# File 'lib/pdfrb/model/type/generic_appearance.rb', line 9

def initialize(annotation, document)
  @annotation = annotation
  @document = document
end

Instance Attribute Details

#annotationObject (readonly)

Returns the value of attribute annotation.



7
8
9
# File 'lib/pdfrb/model/type/generic_appearance.rb', line 7

def annotation
  @annotation
end

#documentObject (readonly)

Returns the value of attribute document.



7
8
9
# File 'lib/pdfrb/model/type/generic_appearance.rb', line 7

def document
  @document
end

Instance Method Details

#create_appearanceObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pdfrb/model/type/generic_appearance.rb', line 14

def create_appearance
  rect = annotation[:Rect]
  return nil unless rect.is_a?(::Array) && rect.length == 4

  x0, y0, x1, y1 = rect
  width = (x1 - x0).abs
  height = (y1 - y0).abs
  return nil if width.zero? || height.zero?

  stream = document.add(
    {
      Type: :XObject,
      Subtype: :Form,
      BBox: [0, 0, width, height],
      Matrix: [1, 0, 0, 1, 0, 0],
      Length: 0,
    },
    type: Pdfrb::Model::Cos::Stream
  )
  stream.stream = "q Q\n"
  annotation[:AP] = { N: Pdfrb::Model::Reference.new(stream.oid, stream.gen) }
  stream
end