-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from redcap97/resolution_info
added support for ResolutionInfo
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'psd/resources/base' | ||
|
||
class PSD | ||
class Resource | ||
module Section | ||
class ResolutionInfo < Base | ||
RES_UNIT_NAMES = %w(pixel/inch pixel/cm).freeze | ||
UNIT_NAMES = %w(in cm pt picas columns).freeze | ||
|
||
resource_id 1005 | ||
name :resolution_info | ||
|
||
attr_reader :h_res, :h_res_unit, :width_unit | ||
attr_reader :v_res, :v_res_unit, :height_unit | ||
|
||
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 | ||
|
||
def h_res_unit_name | ||
RES_UNIT_NAMES.fetch(h_res_unit - 1, 'unknown') | ||
end | ||
|
||
def v_res_unit_name | ||
RES_UNIT_NAMES.fetch(v_res_unit - 1, 'unknown') | ||
end | ||
|
||
def width_unit_name | ||
UNIT_NAMES.fetch(width_unit - 1, 'unknown') | ||
end | ||
|
||
def height_unit_name | ||
UNIT_NAMES.fetch(height_unit - 1, 'unknown') | ||
end | ||
end | ||
end | ||
end | ||
end |