Class: Preflight::Rules::MinPpi
- Inherits:
-
Object
- Object
- Preflight::Rules::MinPpi
- Includes:
- Measurements
- Defined in:
- lib/preflight/rules/min_ppi.rb
Overview
For high quality prints, you generally want raster images to be AT LEAST 300 points-per-inch (ppi). 600 is better, 1200 better again.
Defined Under Namespace
Classes: Point
Constant Summary collapse
- DEFAULT_GRAPHICS_STATE =
{ :ctm => Matrix.identity(3) }
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
-
#begin_page(hash = {}) ⇒ Object
start fresh on every page.
-
#concatenate_matrix(*args) ⇒ Object
update the current transformation matrix.
-
#initialize(min_ppi) ⇒ MinPpi
constructor
A new instance of MinPpi.
-
#invoke_xobject(label) ⇒ Object
As each image is drawn on the canvas, determine the amount of device space it’s being crammed into and therefore the PPI.
-
#resource_xobject(label, stream) ⇒ Object
store sample width and height for each image on the current page.
- #restore_graphics_state ⇒ Object
- #save_graphics_state ⇒ Object
- #state ⇒ Object
Constructor Details
#initialize(min_ppi) ⇒ MinPpi
Returns a new instance of MinPpi.
21 22 23 24 25 |
# File 'lib/preflight/rules/min_ppi.rb', line 21 def initialize(min_ppi) @min_ppi = min_ppi.to_i @messages = [] @page_num = 0 end |
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
19 20 21 |
# File 'lib/preflight/rules/min_ppi.rb', line 19 def @messages end |
Instance Method Details
#begin_page(hash = {}) ⇒ Object
start fresh on every page
90 91 92 93 94 |
# File 'lib/preflight/rules/min_ppi.rb', line 90 def begin_page(hash = {}) @images = {} @page_num += 1 @stack = [DEFAULT_GRAPHICS_STATE] end |
#concatenate_matrix(*args) ⇒ Object
update the current transformation matrix.
If the CTM is currently undefined, just store the new values.
If there’s an existing CTM, then multiple the existing matrix with the new matrix to form the updated matrix.
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/preflight/rules/min_ppi.rb', line 57 def concatenate_matrix(*args) transform = Matrix[ [args[0], args[1], 0], [args[2], args[3], 0], [args[4], args[5], 1] ] if state[:ctm] state[:ctm] = transform * state[:ctm] else state[:ctm] = transform end end |
#invoke_xobject(label) ⇒ Object
As each image is drawn on the canvas, determine the amount of device space it’s being crammed into and therefore the PPI.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/preflight/rules/min_ppi.rb', line 73 def invoke_xobject(label) return unless @images[label] sample_w, sample_h = *@images[label] device_w = pt2in(image_width) device_h = pt2in(image_height) horizontal_ppi = (sample_w / device_w).round(3) vertical_ppi = (sample_h / device_h).round(3) if horizontal_ppi < @min_ppi || vertical_ppi < @min_ppi @messages << "Image with low PPI/DPI on page #{@page_num} (h:#{horizontal_ppi} v:#{vertical_ppi})" end end |
#resource_xobject(label, stream) ⇒ Object
store sample width and height for each image on the current page
41 42 43 44 45 46 47 48 |
# File 'lib/preflight/rules/min_ppi.rb', line 41 def resource_xobject(label, stream) return unless stream.hash[:Subtype] == :Image @images[label] = [ stream.hash[:Width], stream.hash[:Height] ] end |
#restore_graphics_state ⇒ Object
31 32 33 |
# File 'lib/preflight/rules/min_ppi.rb', line 31 def restore_graphics_state @stack.pop end |
#save_graphics_state ⇒ Object
27 28 29 |
# File 'lib/preflight/rules/min_ppi.rb', line 27 def save_graphics_state @stack.push clone_state end |
#state ⇒ Object
35 36 37 |
# File 'lib/preflight/rules/min_ppi.rb', line 35 def state @stack.last end |