Class: PSD::Resource::Section::ResolutionInfo

Inherits:
Base
  • Object
show all
Defined in:
lib/psd/resources/resolution_info.rb

Constant Summary collapse

RES_UNIT_NAMES =
%w(pixel/inch pixel/cm).freeze
UNIT_NAMES =
%w(in cm pt picas columns).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, name, #name, #resource_id, resource_id

Constructor Details

This class inherits a constructor from PSD::Resource::Section::Base

Instance Attribute Details

#h_resObject (readonly)

Returns the value of attribute h_res.



13
14
15
# File 'lib/psd/resources/resolution_info.rb', line 13

def h_res
  @h_res
end

#h_res_unitObject (readonly)

Returns the value of attribute h_res_unit.



13
14
15
# File 'lib/psd/resources/resolution_info.rb', line 13

def h_res_unit
  @h_res_unit
end

#height_unitObject (readonly)

Returns the value of attribute height_unit.



14
15
16
# File 'lib/psd/resources/resolution_info.rb', line 14

def height_unit
  @height_unit
end

#v_resObject (readonly)

Returns the value of attribute v_res.



14
15
16
# File 'lib/psd/resources/resolution_info.rb', line 14

def v_res
  @v_res
end

#v_res_unitObject (readonly)

Returns the value of attribute v_res_unit.



14
15
16
# File 'lib/psd/resources/resolution_info.rb', line 14

def v_res_unit
  @v_res_unit
end

#width_unitObject (readonly)

Returns the value of attribute width_unit.



13
14
15
# File 'lib/psd/resources/resolution_info.rb', line 13

def width_unit
  @width_unit
end

Instance Method Details

#h_res_unit_nameObject



30
31
32
# File 'lib/psd/resources/resolution_info.rb', line 30

def h_res_unit_name
  RES_UNIT_NAMES.fetch(h_res_unit - 1, 'unknown')
end

#height_unit_nameObject



42
43
44
# File 'lib/psd/resources/resolution_info.rb', line 42

def height_unit_name
  UNIT_NAMES.fetch(height_unit - 1, 'unknown')
end

#parseObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/psd/resources/resolution_info.rb', line 16

def parse
  # 32-bit fixed-point number (16.16)
  @h_res = @file.read_uint.to_f / (1 << 16)
  @h_res_unit = @file.read_ushort
  @width_unit = @file.read_ushort

  # 32-bit fixed-point number (16.16)
  @v_res = @file.read_uint.to_f / (1 << 16)
  @v_res_unit = @file.read_ushort
  @height_unit = @file.read_ushort

  @resource.data = self
end

#v_res_unit_nameObject



34
35
36
# File 'lib/psd/resources/resolution_info.rb', line 34

def v_res_unit_name
  RES_UNIT_NAMES.fetch(v_res_unit - 1, 'unknown')
end

#width_unit_nameObject



38
39
40
# File 'lib/psd/resources/resolution_info.rb', line 38

def width_unit_name
  UNIT_NAMES.fetch(width_unit - 1, 'unknown')
end