Commit 3a07ad83 authored by rockyl's avatar rockyl

修复矢量图的问题

parent 8417141f
......@@ -235,7 +235,7 @@ async function execute$1(psdFile, options) {
const assets = [];
await walkNode(tree, async function (node, parent) {
const {name, x, y, width, height, alpha, visible, origin: {layer: {typeTool, solidColor}}} = node;
const {name, x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
let properties = {
width, height, alpha, visible,
};
......@@ -244,6 +244,7 @@ async function execute$1(psdFile, options) {
properties,
uuid: generateUUID(),
};
let dealLater = true;
if (x !== 0) {
properties.x = x;
}
......@@ -253,9 +254,9 @@ async function execute$1(psdFile, options) {
if (typeTool) {
let fontInfo = typeTool();
const fonts = fontInfo.fonts();
const styles = fontInfo.styles();
const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
//const fonts = fontInfo.fonts();
//const styles = fontInfo.styles();
//const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
properties.text = fontInfo.textValue;
properties.size = fontInfo.sizes()[0];
......@@ -265,13 +266,29 @@ async function execute$1(psdFile, options) {
fonts, styles, RunLengthArray,
};*/
viewNode.type = 'label';
dealLater = false;
} else if (solidColor) {
const {r, g, b} = solidColor();
let color = Color({r, g, b});
let paths = layer.vectorMask().paths;
if(paths[2].numPoints === 4){
let isRect = true;
for(let i = 3; i < paths.length; i++){
if(paths[i].recordType !== 2){
isRect = false;
break;
}
}
if(isRect){
viewNode.type = 'rect';
properties.fillColor = '#' + color.rgbNumber().toString(16);
} else {
dealLater = false;
}
}
}
if(dealLater){
if (node.hasOwnProperty('children')) {
viewNode.type = 'node';
} else {
......
This diff is collapsed.
......@@ -241,7 +241,7 @@ async function execute$1(psdFile, options) {
const assets = [];
await walkNode(tree, async function (node, parent) {
const {name, x, y, width, height, alpha, visible, origin: {layer: {typeTool, solidColor}}} = node;
const {name, x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
let properties = {
width, height, alpha, visible,
};
......@@ -250,6 +250,7 @@ async function execute$1(psdFile, options) {
properties,
uuid: generateUUID(),
};
let dealLater = true;
if (x !== 0) {
properties.x = x;
}
......@@ -259,9 +260,9 @@ async function execute$1(psdFile, options) {
if (typeTool) {
let fontInfo = typeTool();
const fonts = fontInfo.fonts();
const styles = fontInfo.styles();
const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
//const fonts = fontInfo.fonts();
//const styles = fontInfo.styles();
//const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
properties.text = fontInfo.textValue;
properties.size = fontInfo.sizes()[0];
......@@ -271,13 +272,29 @@ async function execute$1(psdFile, options) {
fonts, styles, RunLengthArray,
};*/
viewNode.type = 'label';
dealLater = false;
} else if (solidColor) {
const {r, g, b} = solidColor();
let color = Color({r, g, b});
let paths = layer.vectorMask().paths;
if(paths[2].numPoints === 4){
let isRect = true;
for(let i = 3; i < paths.length; i++){
if(paths[i].recordType !== 2){
isRect = false;
break;
}
}
if(isRect){
viewNode.type = 'rect';
properties.fillColor = '#' + color.rgbNumber().toString(16);
} else {
dealLater = false;
}
}
}
if(dealLater){
if (node.hasOwnProperty('children')) {
viewNode.type = 'node';
} else {
......
This diff is collapsed.
......@@ -241,7 +241,7 @@
const assets = [];
await walkNode(tree, async function (node, parent) {
const {name, x, y, width, height, alpha, visible, origin: {layer: {typeTool, solidColor}}} = node;
const {name, x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
let properties = {
width, height, alpha, visible,
};
......@@ -250,6 +250,7 @@
properties,
uuid: generateUUID(),
};
let dealLater = true;
if (x !== 0) {
properties.x = x;
}
......@@ -259,9 +260,9 @@
if (typeTool) {
let fontInfo = typeTool();
const fonts = fontInfo.fonts();
const styles = fontInfo.styles();
const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
//const fonts = fontInfo.fonts();
//const styles = fontInfo.styles();
//const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
properties.text = fontInfo.textValue;
properties.size = fontInfo.sizes()[0];
......@@ -271,13 +272,29 @@
fonts, styles, RunLengthArray,
};*/
viewNode.type = 'label';
dealLater = false;
} else if (solidColor) {
const {r, g, b} = solidColor();
let color = Color({r, g, b});
let paths = layer.vectorMask().paths;
if(paths[2].numPoints === 4){
let isRect = true;
for(let i = 3; i < paths.length; i++){
if(paths[i].recordType !== 2){
isRect = false;
break;
}
}
if(isRect){
viewNode.type = 'rect';
properties.fillColor = '#' + color.rgbNumber().toString(16);
} else {
dealLater = false;
}
}
}
if(dealLater){
if (node.hasOwnProperty('children')) {
viewNode.type = 'node';
} else {
......
This diff is collapsed.
{
"name": "psd-parse",
"version": "1.0.2",
"version": "1.0.3",
"main": "dist/index.js",
"license": "MIT",
"dependencies": {
......
......@@ -85,7 +85,7 @@ async function execute(psdFile, options) {
const assets = [];
await walkNode(tree, async function (node, parent) {
const {name, x, y, width, height, alpha, visible, origin: {layer: {typeTool, solidColor}}} = node;
const {name, x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
let properties = {
width, height, alpha, visible,
};
......@@ -94,6 +94,7 @@ async function execute(psdFile, options) {
properties,
uuid: generateUUID(),
};
let dealLater = true;
if (x !== 0) {
properties.x = x;
}
......@@ -103,24 +104,41 @@ async function execute(psdFile, options) {
if (typeTool) {
let fontInfo = typeTool();
const fonts = fontInfo.fonts();
const styles = fontInfo.styles();
const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
//const fonts = fontInfo.fonts();
//const styles = fontInfo.styles();
//const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
properties.text = fontInfo.textValue;
properties.size = fontInfo.sizes()[0];
let [r, g, b, a] = fontInfo.colors()[0];
properties.color = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
properties.textflow = {
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
/*properties.textflow = {
fonts, styles, RunLengthArray,
};
};*/
viewNode.type = 'label';
dealLater = false;
} else if (solidColor) {
const {r, g, b} = solidColor();
let color = Color({r, g, b});
let paths = layer.vectorMask().paths;
if(paths[2].numPoints === 4){
let isRect = true;
for(let i = 3; i < paths.length; i++){
if(paths[i].recordType !== 2){
isRect = false;
break;
}
}
if(isRect){
viewNode.type = 'rect';
properties.fillColor = '#' + color.rgbNumber().toString(16);
} else {
dealLater = false;
}
}
}
if(dealLater){
if (node.hasOwnProperty('children')) {
viewNode.type = 'node';
} else {
......@@ -129,14 +147,15 @@ async function execute(psdFile, options) {
const uuid = generateUUID();
const ext = '.png';
properties.source = 'asset://' + uuid;
const imageFilePath = path.join(imagesPath, uuid + ext);
await fs.ensureDir(path.dirname(imageFilePath));
let png = node.origin.toPng();
let buffer = await savePng(png, imageFilePath);
let buffer = await savePng(png, imageFilePath).catch(e=>{});
//await node.origin.saveAsPng(imageFilePath);
if(buffer){
properties.source = 'asset://' + uuid;
const hashFileName = hash(buffer);
const hashFilePath = path.join(imagesPath, hashFileName + ext);
await fs.rename(imageFilePath, hashFilePath);
......@@ -149,6 +168,7 @@ async function execute(psdFile, options) {
});
}
}
}
let viewParent = parent.view || viewRoot;
if (!viewParent.hasOwnProperty('children')) {
......@@ -188,7 +208,7 @@ function savePng(png, output) {
(async function generate() {
const imagesPath = 'zeroing-demo/images_' + Date.now();
const {view, assets} = await execute('psd/test.psd', {
const {view, assets} = await execute('psd/shapes.psd', {
imagesPath,
});
......
This diff is collapsed.
......@@ -7,7 +7,7 @@ import {toZeroing} from "../../src/index";
(async function generate() {
const imagesPath = 'zeroing-demo/images_' + Date.now();
const {view, assets} = await toZeroing('psd/test.psd', {
const {view, assets} = await toZeroing('psd/shapes.psd', {
imagesPath,
});
......
......@@ -28,7 +28,7 @@ export async function execute(psdFile, options) {
const assets = [];
await walkNode(tree, async function (node, parent) {
const {name, x, y, width, height, alpha, visible, origin: {layer: {typeTool, solidColor}}} = node;
const {name, x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
let properties = {
width, height, alpha, visible,
};
......@@ -37,6 +37,7 @@ export async function execute(psdFile, options) {
properties,
uuid: generateUUID(),
};
let dealLater = true;
if (x !== 0) {
properties.x = x;
}
......@@ -46,9 +47,9 @@ export async function execute(psdFile, options) {
if (typeTool) {
let fontInfo = typeTool();
const fonts = fontInfo.fonts();
const styles = fontInfo.styles();
const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
//const fonts = fontInfo.fonts();
//const styles = fontInfo.styles();
//const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
properties.text = fontInfo.textValue;
properties.size = fontInfo.sizes()[0];
......@@ -58,13 +59,29 @@ export async function execute(psdFile, options) {
fonts, styles, RunLengthArray,
};*/
viewNode.type = 'label';
dealLater = false;
} else if (solidColor) {
const {r, g, b} = solidColor();
let color = Color({r, g, b});
let paths = layer.vectorMask().paths;
if(paths[2].numPoints === 4){
let isRect = true;
for(let i = 3; i < paths.length; i++){
if(paths[i].recordType !== 2){
isRect = false;
break;
}
}
if(isRect){
viewNode.type = 'rect';
properties.fillColor = '#' + color.rgbNumber().toString(16);
} else {
dealLater = false;
}
}
}
if(dealLater){
if (node.hasOwnProperty('children')) {
viewNode.type = 'node';
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment