Class: Preflight::Rules::PageBoxSize
- Inherits:
-
Object
- Object
- Preflight::Rules::PageBoxSize
- Includes:
- Measurements
- Defined in:
- lib/preflight/rules/page_box_size.rb
Overview
Ensure that the requests page box (MediaBox, TrimBox, etc) on every page has the requested size. Dimensions can be in points, mm or inches. Skips the page if the requested box isn’t defined, it’s up to other rules to check for the existence of the box. Pass an array of sizes to allow each of those sizes.
Usage:
class MyPreflight
include Preflight::Profile
rule Preflight::Rules::PageBoxSize, :MediaBox, [
{ :width => 100, :height => 200, :units => :mm },
{ :width => 200, :height => 400, :units => :mm }
]
rule Preflight::Rules::PageBoxSize, :TrimBox,
{ :width => 600, :height => 200, :units => :pts }
end
Instance Attribute Summary collapse
-
#issues ⇒ Object
readonly
Returns the value of attribute issues.
Instance Method Summary collapse
-
#initialize(box, sizes) ⇒ PageBoxSize
constructor
A new instance of PageBoxSize.
- #page=(page) ⇒ Object
Constructor Details
#initialize(box, sizes) ⇒ PageBoxSize
Returns a new instance of PageBoxSize.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/preflight/rules/page_box_size.rb', line 30 def initialize(box, sizes) @box, @units = box sizes = [sizes] if sizes.kind_of?(Hash) @orig_sizes = sizes @sizes = sizes.map do |size| size[:width] = length_to_points(size[:width], size[:units]) size[:height] = length_to_points(size[:height], size[:units]) size end end |
Instance Attribute Details
#issues ⇒ Object (readonly)
Returns the value of attribute issues.
28 29 30 |
# File 'lib/preflight/rules/page_box_size.rb', line 28 def issues @issues end |
Instance Method Details
#page=(page) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/preflight/rules/page_box_size.rb', line 42 def page=(page) @issues = [] dict = page.attributes if dict[@box] box_width = dict[@box][2] - dict[@box][0] box_height = dict[@box][3] - dict[@box][1] invalid_size = @sizes.none? do |size| size[:width].include?(box_width) && size[:height].include?(box_height) end if invalid_size @issues << Issue.new("#{@box} size didn't match provided size", self, :page => page.number, :box => @box, :box_height => box_height, :box_width => box_width) end end end |