Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
psd-parse-web
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
劳工
psd-parse-web
Commits
5feb8774
Commit
5feb8774
authored
Apr 28, 2021
by
张九刚
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复字体大小问题
parent
85064870
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
10 deletions
+28
-10
package-lock.json
package-lock.json
+1
-1
compilelocal.js
src/compilelocal.js
+26
-9
psd-tree.js
src/psd-tree.js
+1
-0
No files found.
package-lock.json
View file @
5feb8774
{
{
"name"
:
"psd-parse-web"
,
"name"
:
"psd-parse-web"
,
"version"
:
"
1.0.4
"
,
"version"
:
"
2.0.0
"
,
"lockfileVersion"
:
1
,
"lockfileVersion"
:
1
,
"requires"
:
true
,
"requires"
:
true
,
"dependencies"
:
{
"dependencies"
:
{
...
...
src/compilelocal.js
View file @
5feb8774
...
@@ -34,9 +34,7 @@ async function compilePsdToJson(psdFile, options) {
...
@@ -34,9 +34,7 @@ async function compilePsdToJson(psdFile, options) {
if
(
!
assetsPath
)
{
if
(
!
assetsPath
)
{
console
.
log
(
"没有指定assets目录"
);
console
.
log
(
"没有指定assets目录"
);
}
}
const
tree
=
await
getTree
(
psdFile
);
const
tree
=
await
getTree
(
psdFile
);
// console.log("tree:", tree);
let
viewRoot
=
{
let
viewRoot
=
{
name
:
path
.
basename
(
psdFile
,
'.psd'
),
name
:
path
.
basename
(
psdFile
,
'.psd'
),
...
@@ -44,12 +42,17 @@ async function compilePsdToJson(psdFile, options) {
...
@@ -44,12 +42,17 @@ async function compilePsdToJson(psdFile, options) {
uuid
:
generateUUID
(),
uuid
:
generateUUID
(),
children
:
[]
children
:
[]
};
};
const
assets
=
[];
const
assets
=
[];
const
pageList
=
tree
.
children
||
[];
const
pageList
=
tree
.
children
||
[];
// console.log("pageList:", pageList);
const
isHadErrorPage
=
pageList
.
filter
(
page
=>
!
page
.
children
);
if
(
isHadErrorPage
.
length
)
{
console
.
warn
(
`
${
isHadErrorPage
[
0
].
name
}
不合法,请保持设计稿根目录为全部文件夹形式`
);
return
{
error
:
true
,
errorName
:
isHadErrorPage
[
0
].
name
}
}
const
pr
=
pageList
.
map
(
async
(
page
,
index
)
=>
{
const
pr
=
pageList
.
map
(
async
(
page
,
index
)
=>
{
const
folderName
=
page
.
name
||
`未命名页面
${
Math
.
random
().
toFixed
(
2
)
*
100
}
`
;
const
folderName
=
page
.
name
||
`未命名页面
${
Math
.
random
().
toFixed
(
2
)
*
100
}
`
;
if
(
!
page
.
children
)
{
if
(
!
page
.
children
)
{
...
@@ -97,9 +100,8 @@ async function compilePsdToJson(psdFile, options) {
...
@@ -97,9 +100,8 @@ async function compilePsdToJson(psdFile, options) {
if
(
typeTool
)
{
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
let
fontInfo
=
typeTool
();
properties
.
attrs
.
text
=
fontInfo
.
textValue
;
properties
.
attrs
.
text
=
fontInfo
.
textValue
;
const
sizes
=
fontInfo
.
sizes
();
const
colors
=
fontInfo
.
colors
();
const
colors
=
fontInfo
.
colors
();
let
fsize
=
sizes
?
sizes
[
0
]
||
20
:
20
;
let
fsize
=
computeFontSize
(
fontInfo
)
properties
.
style
.
fontSize
=
parseInt
(
fsize
);
//字体取整
properties
.
style
.
fontSize
=
parseInt
(
fsize
);
//字体取整
let
[
r
,
g
,
b
,
a
]
=
colors
[
0
];
let
[
r
,
g
,
b
,
a
]
=
colors
[
0
];
properties
.
style
.
color
=
`rgba(
${
r
}
,
${
g
}
,
${
b
}
,
${
a
/
255
}
)`
;
properties
.
style
.
color
=
`rgba(
${
r
}
,
${
g
}
,
${
b
}
,
${
a
/
255
}
)`
;
...
@@ -172,7 +174,7 @@ async function compilePsdToJson(psdFile, options) {
...
@@ -172,7 +174,7 @@ async function compilePsdToJson(psdFile, options) {
if
(
!
viewParent
.
hasOwnProperty
(
'children'
))
{
if
(
!
viewParent
.
hasOwnProperty
(
'children'
))
{
viewParent
.
children
=
[];
viewParent
.
children
=
[];
}
}
console
.
log
(
"viewNode:"
,
viewNode
);
//
console.log("viewNode:", viewNode);
viewParent
.
children
.
push
(
viewNode
);
viewParent
.
children
.
push
(
viewNode
);
...
@@ -196,7 +198,7 @@ async function compilePsdToJson(psdFile, options) {
...
@@ -196,7 +198,7 @@ async function compilePsdToJson(psdFile, options) {
view
:
{
children
:
viewRoot
.
children
},
view
:
{
children
:
viewRoot
.
children
},
};
};
console
.
log
(
"data..."
,
JSON
.
stringify
(
data
));
//
console.log("data...", JSON.stringify(data));
return
data
;
return
data
;
}
}
...
@@ -225,6 +227,21 @@ function savePng(png, output) {
...
@@ -225,6 +227,21 @@ function savePng(png, output) {
});
});
});
});
}
}
const
computeFontSize
=
(
fontinfo
,
defValue
=
24
)
=>
{
const
sizes
=
fontinfo
.
sizes
();
let
size
;
if
(
sizes
&&
sizes
[
0
])
{
if
(
fontinfo
.
transform
.
yy
!==
1
)
{
size
=
Math
.
round
((
sizes
[
0
]
*
fontinfo
.
transform
.
yy
)
*
100
)
*
0.01
;
}
else
{
// transform.yy为1时,sizes[0]的值就是字体显示大小的值,不需要计算
size
=
sizes
[
0
].
toFixed
();
}
}
else
{
size
=
defValue
;
// 默认
}
return
size
;
}
...
...
src/psd-tree.js
View file @
5feb8774
...
@@ -10,6 +10,7 @@ async function getTree(psdFilePath) {
...
@@ -10,6 +10,7 @@ async function getTree(psdFilePath) {
const
psd
=
await
PSD
.
open
(
psdFilePath
);
const
psd
=
await
PSD
.
open
(
psdFilePath
);
const
root
=
{};
const
root
=
{};
console
.
log
(
'psd::::'
,
JSON
.
stringify
(
psd
.
tree
().
export
()));
walk
(
psd
.
tree
(),
root
);
walk
(
psd
.
tree
(),
root
);
return
root
;
return
root
;
...
...
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