Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
psd.js
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
regiostart
psd.js
Commits
1bd1167c
Commit
1bd1167c
authored
Apr 24, 2014
by
Ryan LeFevre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add layer info parsing and unicode names
parent
28ac2075
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
78 additions
and
1 deletion
+78
-1
file.coffee
lib/psd/file.coffee
+10
-1
layer.coffee
lib/psd/layer.coffee
+2
-0
info.coffee
lib/psd/layer/info.coffee
+30
-0
layer_info.coffee
lib/psd/layer_info.coffee
+8
-0
unicode_name.coffee
lib/psd/layer_info/unicode_name.coffee
+11
-0
util.coffee
lib/psd/util.coffee
+17
-0
No files found.
lib/psd/file.coffee
View file @
1bd1167c
{
jspack
}
=
require
(
'jspack'
)
{
jspack
}
=
require
'jspack'
Util
=
require
'./util.coffee'
module
.
exports
=
class
File
FORMATS
=
...
...
@@ -38,4 +39,12 @@ module.exports = class File
seek
:
(
amt
,
rel
=
false
)
->
if
rel
then
@
pos
+=
amt
else
@
pos
=
amt
readString
:
(
length
)
->
@
read
(
length
).
toString
().
replace
/\u0000/g
,
''
readUnicodeString
:
(
length
=
null
)
->
length
or=
@
readInt
()
@
read
(
length
*
2
)
.
toJSON
()
.
map
((
c
)
->
Util
.
getUnicodeCharacter
(
c
))
.
join
(
''
)
.
replace
(
/\u0000/g
,
''
)
readByte
:
->
@
read
(
1
)[
0
]
\ No newline at end of file
lib/psd/layer.coffee
View file @
1bd1167c
...
...
@@ -6,6 +6,7 @@ module.exports = class Layer extends Module
@
includes
require
(
'./layer/mask.coffee'
)
@
includes
require
(
'./layer/blending_ranges.coffee'
)
@
includes
require
(
'./layer/name.coffee'
)
@
includes
require
(
'./layer/info.coffee'
)
# @includes require('./layer/channel_image.coffee')
constructor
:
(
@
file
,
@
header
)
->
...
...
@@ -28,6 +29,7 @@ module.exports = class Layer extends Module
@
parseMaskData
()
@
parseBlendingRanges
()
@
parseLegacyLayerName
()
@
parseLayerInfo
()
@
file
.
seek
@
layerEnd
return
@
...
...
lib/psd/layer/info.coffee
0 → 100644
View file @
1bd1167c
LazyExecute
=
require
'../lazy_execute.coffee'
Util
=
require
'../util.coffee'
LAYER_INFO
=
{
name
:
require
(
'../layer_info/unicode_name.coffee'
)
}
module
.
exports
=
parseLayerInfo
:
->
while
@
file
.
tell
()
<
@
layerEnd
@
file
.
seek
4
,
true
# sig
key
=
@
file
.
readString
(
4
)
length
=
Util
.
pad2
@
file
.
readInt
()
pos
=
@
file
.
tell
()
keyParseable
=
false
for
own
name
,
klass
of
LAYER_INFO
continue
unless
klass
.
shouldParse
(
key
)
i
=
new
klass
(
@
,
length
)
@
adjustments
[
name
]
=
new
LazyExecute
(
i
,
@
file
)
.
now
(
'skip'
)
.
later
(
'parse'
)
.
get
()
keyParseable
=
true
break
@
file
.
seek
length
,
true
if
not
keyParseable
\ No newline at end of file
lib/psd/layer_info.coffee
0 → 100644
View file @
1bd1167c
module
.
exports
=
class
LayerInfo
constructor
:
(
@
layer
,
@
length
)
->
@
file
=
@
layer
.
file
@
section_end
=
@
file
.
tell
()
+
@
length
@
data
=
{}
skip
:
->
@
file
.
seek
@
section_end
parse
:
->
@
skip
()
# skip by default
\ No newline at end of file
lib/psd/layer_info/unicode_name.coffee
0 → 100644
View file @
1bd1167c
LayerInfo
=
require
'../layer_info.coffee'
module
.
exports
=
class
UnicodeName
extends
LayerInfo
@
shouldParse
:
(
key
)
->
key
is
'luni'
parse
:
->
pos
=
@
file
.
tell
()
@
data
=
@
file
.
readUnicodeString
()
@
file
.
seek
pos
+
@
length
return
@
\ No newline at end of file
lib/psd/util.coffee
View file @
1bd1167c
module
.
exports
=
class
Util
@
pad2
:
(
i
)
->
(
i
+
1
)
&
~
0x01
@
pad4
:
(
i
)
->
((
i
+
4
)
&
~
0x03
)
-
1
@
getUnicodeCharacter
:
(
cp
)
->
if
cp
>=
0
and
cp
<=
0xD7FF
or
cp
>=
0xE000
and
cp
<=
0xFFFF
return
String
.
fromCharCode
(
cp
)
else
if
cp
>=
0x10000
and
cp
<=
0x10FFFF
# we substract 0x10000 from cp to get a 20-bits number
# in the range 0..0xFFFF
cp
-=
0x10000
# we add 0xD800 to the number formed by the first 10 bits
# to give the first byte
first
=
((
0xffc00
&
cp
)
>>
10
)
+
0xD800
# we add 0xDC00 to the number formed by the low 10 bits
# to give the second byte
second
=
(
0x3ff
&
cp
)
+
0xDC00
String
.
fromCharCode
(
first
)
+
String
.
fromCharCode
(
second
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment