Class: HexaPDF::CLI::Images::ImageLocationProcessor
- Inherits:
-
HexaPDF::Content::Processor
- Object
- HexaPDF::Content::Processor
- HexaPDF::CLI::Images::ImageLocationProcessor
- Defined in:
- lib/hexapdf/cli/images.rb
Overview
Extracts the PPI (pixel per inch) information for each image of a content stream.
Constant Summary
Constants inherited from HexaPDF::Content::Processor
HexaPDF::Content::Processor::OPERATOR_MESSAGE_NAME_MAP
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
The mapping of XObject name to [x_ppi, y_ppi].
Attributes inherited from HexaPDF::Content::Processor
#graphics_object, #graphics_state, #operators, #resources
Instance Method Summary collapse
-
#initialize(names, user_unit) ⇒ ImageLocationProcessor
constructor
Initialize the processor with the names of the images for which the PPI should be determined.
-
#paint_xobject(name) ⇒ Object
Determine the PPI in x- and y-directions of the specified images.
Methods inherited from HexaPDF::Content::Processor
Constructor Details
#initialize(names, user_unit) ⇒ ImageLocationProcessor
Initialize the processor with the names of the images for which the PPI should be determined.
56 57 58 59 60 61 |
# File 'lib/hexapdf/cli/images.rb', line 56 def initialize(names, user_unit) super() @names = names @user_unit = user_unit @result = {} end |
Instance Attribute Details
#result ⇒ Object (readonly)
The mapping of XObject name to [x_ppi, y_ppi].
52 53 54 |
# File 'lib/hexapdf/cli/images.rb', line 52 def result @result end |
Instance Method Details
#paint_xobject(name) ⇒ Object
Determine the PPI in x- and y-directions of the specified images.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/hexapdf/cli/images.rb', line 64 def paint_xobject(name) super return unless @names.delete(name) xobject = resources.xobject(name) return unless xobject[:Subtype] == :Image w, h = xobject.width, xobject.height llx, lly = graphics_state.ctm.evaluate(0, 0).map {|i| i * @user_unit } lrx, lry = graphics_state.ctm.evaluate(1, 0).map {|i| i * @user_unit } ulx, uly = graphics_state.ctm.evaluate(0, 1).map {|i| i * @user_unit } x_ppi = 72.0 * w / Math.sqrt((lrx - llx)**2 + (lry - lly)**2) y_ppi = 72.0 * h / Math.sqrt((ulx - llx)**2 + (uly - lly)**2) @result[name] = [x_ppi.round, y_ppi.round] raise StopIteration if @names.empty? end |