Class: Preflight::Rules::NoTransparency

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Measurements
Defined in:
lib/preflight/rules/no_transparency.rb

Overview

For some print workflows transparency is forbidden.

Arguments: none

Usage:

class MyPreflight
  include Preflight::Profile

  rule Preflight::Rules::NoTransparency
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#issuesObject (readonly)

Returns the value of attribute issues.



30
31
32
# File 'lib/preflight/rules/no_transparency.rb', line 30

def issues
  @issues
end

Instance Method Details

#detect_transparent_form(form) ⇒ Object

As each xobject is drawn on the canvas, record if it’s Group XObject with transparency



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/preflight/rules/no_transparency.rb', line 55

def detect_transparent_form(form)
  xobject = form.xobject
  group   = deref(xobject.hash[:Group])
  stype   = deref(group[:S])            if group

  if stype == :Transparency
    bbox = xobject.hash[:BBox] || @page.attributes[:MediaBox]
    bbox = translate_to_device_space(bbox)
    @issues << Issue.new("Transparent xobject found", self, :page         => @page.number,
                                                            :top_left     => bbox[:tl],
                                                            :bottom_left  => bbox[:bl],
                                                            :bottom_right => bbox[:br],
                                                            :top_right    => bbox[:tr])
  end
end

#invoke_xobject(label) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/preflight/rules/no_transparency.rb', line 40

def invoke_xobject(label)
  @state.invoke_xobject(label) do |xobj|
    case xobj
    when PDF::Reader::FormXObject then
      detect_transparent_form(xobj)
      xobj.walk(self)
    else
      # TODO. can other xobjects have transparency?
    end
  end
end

#page=(page) ⇒ Object

we’re about to start a new page, reset state



34
35
36
37
38
# File 'lib/preflight/rules/no_transparency.rb', line 34

def page=(page)
  @page   = page
  @state  = PDF::Reader::PageState.new(page)
  @issues = []
end