Commit 3a07ad83 authored by rockyl's avatar rockyl

修复矢量图的问题

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