Commit 44222d47 authored by rockyl's avatar rockyl

解决字体大小找不到的问题

parent 3a07ad83
...@@ -259,8 +259,10 @@ async function execute$1(psdFile, options) { ...@@ -259,8 +259,10 @@ async function execute$1(psdFile, options) {
//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]; const sizes = fontInfo.sizes();
let [r, g, b, a] = fontInfo.colors()[0]; const colors = fontInfo.colors();
properties.size = sizes ? sizes[0] || 20 : 20;
let [r, g, b, a] = colors[0];
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`; properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
/*properties.textflow = { /*properties.textflow = {
fonts, styles, RunLengthArray, fonts, styles, RunLengthArray,
...@@ -272,15 +274,15 @@ async function execute$1(psdFile, options) { ...@@ -272,15 +274,15 @@ async function execute$1(psdFile, options) {
let color = Color({r, g, b}); let color = Color({r, g, b});
let paths = layer.vectorMask().paths; let paths = layer.vectorMask().paths;
if(paths[2].numPoints === 4){ if (paths[2].numPoints === 4) {
let isRect = true; let isRect = true;
for(let i = 3; i < paths.length; i++){ for (let i = 3; i < paths.length; i++) {
if(paths[i].recordType !== 2){ if (paths[i].recordType !== 2) {
isRect = false; isRect = false;
break; break;
} }
} }
if(isRect){ if (isRect) {
viewNode.type = 'rect'; viewNode.type = 'rect';
properties.fillColor = '#' + color.rgbNumber().toString(16); properties.fillColor = '#' + color.rgbNumber().toString(16);
dealLater = false; dealLater = false;
...@@ -288,7 +290,7 @@ async function execute$1(psdFile, options) { ...@@ -288,7 +290,7 @@ async function execute$1(psdFile, options) {
} }
} }
if(dealLater){ if (dealLater) {
if (node.hasOwnProperty('children')) { if (node.hasOwnProperty('children')) {
viewNode.type = 'node'; viewNode.type = 'node';
} else { } else {
...@@ -300,10 +302,11 @@ async function execute$1(psdFile, options) { ...@@ -300,10 +302,11 @@ async function execute$1(psdFile, options) {
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).catch(e=>{}); let buffer = await savePng(png, imageFilePath).catch(e => {
});
//await node.origin.saveAsPng(imageFilePath); //await node.origin.saveAsPng(imageFilePath);
if(buffer){ if (buffer) {
properties.source = 'asset://' + uuid; properties.source = 'asset://' + uuid;
const hashFileName = hash(buffer); const hashFileName = hash(buffer);
......
This diff is collapsed.
...@@ -265,8 +265,10 @@ async function execute$1(psdFile, options) { ...@@ -265,8 +265,10 @@ async function execute$1(psdFile, options) {
//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]; const sizes = fontInfo.sizes();
let [r, g, b, a] = fontInfo.colors()[0]; const colors = fontInfo.colors();
properties.size = sizes ? sizes[0] || 20 : 20;
let [r, g, b, a] = colors[0];
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`; properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
/*properties.textflow = { /*properties.textflow = {
fonts, styles, RunLengthArray, fonts, styles, RunLengthArray,
...@@ -278,15 +280,15 @@ async function execute$1(psdFile, options) { ...@@ -278,15 +280,15 @@ async function execute$1(psdFile, options) {
let color = Color({r, g, b}); let color = Color({r, g, b});
let paths = layer.vectorMask().paths; let paths = layer.vectorMask().paths;
if(paths[2].numPoints === 4){ if (paths[2].numPoints === 4) {
let isRect = true; let isRect = true;
for(let i = 3; i < paths.length; i++){ for (let i = 3; i < paths.length; i++) {
if(paths[i].recordType !== 2){ if (paths[i].recordType !== 2) {
isRect = false; isRect = false;
break; break;
} }
} }
if(isRect){ if (isRect) {
viewNode.type = 'rect'; viewNode.type = 'rect';
properties.fillColor = '#' + color.rgbNumber().toString(16); properties.fillColor = '#' + color.rgbNumber().toString(16);
dealLater = false; dealLater = false;
...@@ -294,7 +296,7 @@ async function execute$1(psdFile, options) { ...@@ -294,7 +296,7 @@ async function execute$1(psdFile, options) {
} }
} }
if(dealLater){ if (dealLater) {
if (node.hasOwnProperty('children')) { if (node.hasOwnProperty('children')) {
viewNode.type = 'node'; viewNode.type = 'node';
} else { } else {
...@@ -306,10 +308,11 @@ async function execute$1(psdFile, options) { ...@@ -306,10 +308,11 @@ async function execute$1(psdFile, options) {
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).catch(e=>{}); let buffer = await savePng(png, imageFilePath).catch(e => {
});
//await node.origin.saveAsPng(imageFilePath); //await node.origin.saveAsPng(imageFilePath);
if(buffer){ if (buffer) {
properties.source = 'asset://' + uuid; properties.source = 'asset://' + uuid;
const hashFileName = hash(buffer); const hashFileName = hash(buffer);
......
This diff is collapsed.
...@@ -265,8 +265,10 @@ ...@@ -265,8 +265,10 @@
//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]; const sizes = fontInfo.sizes();
let [r, g, b, a] = fontInfo.colors()[0]; const colors = fontInfo.colors();
properties.size = sizes ? sizes[0] || 20 : 20;
let [r, g, b, a] = colors[0];
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`; properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
/*properties.textflow = { /*properties.textflow = {
fonts, styles, RunLengthArray, fonts, styles, RunLengthArray,
...@@ -278,15 +280,15 @@ ...@@ -278,15 +280,15 @@
let color = Color({r, g, b}); let color = Color({r, g, b});
let paths = layer.vectorMask().paths; let paths = layer.vectorMask().paths;
if(paths[2].numPoints === 4){ if (paths[2].numPoints === 4) {
let isRect = true; let isRect = true;
for(let i = 3; i < paths.length; i++){ for (let i = 3; i < paths.length; i++) {
if(paths[i].recordType !== 2){ if (paths[i].recordType !== 2) {
isRect = false; isRect = false;
break; break;
} }
} }
if(isRect){ if (isRect) {
viewNode.type = 'rect'; viewNode.type = 'rect';
properties.fillColor = '#' + color.rgbNumber().toString(16); properties.fillColor = '#' + color.rgbNumber().toString(16);
dealLater = false; dealLater = false;
...@@ -294,7 +296,7 @@ ...@@ -294,7 +296,7 @@
} }
} }
if(dealLater){ if (dealLater) {
if (node.hasOwnProperty('children')) { if (node.hasOwnProperty('children')) {
viewNode.type = 'node'; viewNode.type = 'node';
} else { } else {
...@@ -306,10 +308,11 @@ ...@@ -306,10 +308,11 @@
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).catch(e=>{}); let buffer = await savePng(png, imageFilePath).catch(e => {
});
//await node.origin.saveAsPng(imageFilePath); //await node.origin.saveAsPng(imageFilePath);
if(buffer){ if (buffer) {
properties.source = 'asset://' + uuid; properties.source = 'asset://' + uuid;
const hashFileName = hash(buffer); const hashFileName = hash(buffer);
......
This diff is collapsed.
{ {
"name": "psd-parse", "name": "psd-parse",
"version": "1.0.3", "version": "1.0.4",
"main": "dist/index.js", "main": "dist/index.js",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
......
...@@ -109,8 +109,10 @@ async function execute(psdFile, options) { ...@@ -109,8 +109,10 @@ async function execute(psdFile, options) {
//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]; const sizes = fontInfo.sizes();
let [r, g, b, a] = fontInfo.colors()[0]; const colors = fontInfo.colors();
properties.size = sizes ? sizes[0] || 20 : 20;
let [r, g, b, a] = colors[0];
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`; properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
/*properties.textflow = { /*properties.textflow = {
fonts, styles, RunLengthArray, fonts, styles, RunLengthArray,
...@@ -122,15 +124,15 @@ async function execute(psdFile, options) { ...@@ -122,15 +124,15 @@ async function execute(psdFile, options) {
let color = Color({r, g, b}); let color = Color({r, g, b});
let paths = layer.vectorMask().paths; let paths = layer.vectorMask().paths;
if(paths[2].numPoints === 4){ if (paths[2].numPoints === 4) {
let isRect = true; let isRect = true;
for(let i = 3; i < paths.length; i++){ for (let i = 3; i < paths.length; i++) {
if(paths[i].recordType !== 2){ if (paths[i].recordType !== 2) {
isRect = false; isRect = false;
break; break;
} }
} }
if(isRect){ if (isRect) {
viewNode.type = 'rect'; viewNode.type = 'rect';
properties.fillColor = '#' + color.rgbNumber().toString(16); properties.fillColor = '#' + color.rgbNumber().toString(16);
dealLater = false; dealLater = false;
...@@ -138,7 +140,7 @@ async function execute(psdFile, options) { ...@@ -138,7 +140,7 @@ async function execute(psdFile, options) {
} }
} }
if(dealLater){ if (dealLater) {
if (node.hasOwnProperty('children')) { if (node.hasOwnProperty('children')) {
viewNode.type = 'node'; viewNode.type = 'node';
} else { } else {
...@@ -150,10 +152,11 @@ async function execute(psdFile, options) { ...@@ -150,10 +152,11 @@ async function execute(psdFile, options) {
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).catch(e=>{}); let buffer = await savePng(png, imageFilePath).catch(e => {
});
//await node.origin.saveAsPng(imageFilePath); //await node.origin.saveAsPng(imageFilePath);
if(buffer){ if (buffer) {
properties.source = 'asset://' + uuid; properties.source = 'asset://' + uuid;
const hashFileName = hash(buffer); const hashFileName = hash(buffer);
...@@ -208,7 +211,7 @@ function savePng(png, output) { ...@@ -208,7 +211,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/shapes.psd', { const {view, assets} = await execute('psd/test2.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/shapes.psd', { const {view, assets} = await toZeroing('psd/test2.psd', {
imagesPath, imagesPath,
}); });
......
...@@ -52,8 +52,10 @@ export async function execute(psdFile, options) { ...@@ -52,8 +52,10 @@ export async function execute(psdFile, options) {
//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]; const sizes = fontInfo.sizes();
let [r, g, b, a] = fontInfo.colors()[0]; const colors = fontInfo.colors();
properties.size = sizes ? sizes[0] || 20 : 20;
let [r, g, b, a] = colors[0];
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`; properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
/*properties.textflow = { /*properties.textflow = {
fonts, styles, RunLengthArray, fonts, styles, RunLengthArray,
...@@ -65,15 +67,15 @@ export async function execute(psdFile, options) { ...@@ -65,15 +67,15 @@ export async function execute(psdFile, options) {
let color = Color({r, g, b}); let color = Color({r, g, b});
let paths = layer.vectorMask().paths; let paths = layer.vectorMask().paths;
if(paths[2].numPoints === 4){ if (paths[2].numPoints === 4) {
let isRect = true; let isRect = true;
for(let i = 3; i < paths.length; i++){ for (let i = 3; i < paths.length; i++) {
if(paths[i].recordType !== 2){ if (paths[i].recordType !== 2) {
isRect = false; isRect = false;
break; break;
} }
} }
if(isRect){ if (isRect) {
viewNode.type = 'rect'; viewNode.type = 'rect';
properties.fillColor = '#' + color.rgbNumber().toString(16); properties.fillColor = '#' + color.rgbNumber().toString(16);
dealLater = false; dealLater = false;
...@@ -81,7 +83,7 @@ export async function execute(psdFile, options) { ...@@ -81,7 +83,7 @@ export async function execute(psdFile, options) {
} }
} }
if(dealLater){ if (dealLater) {
if (node.hasOwnProperty('children')) { if (node.hasOwnProperty('children')) {
viewNode.type = 'node'; viewNode.type = 'node';
} else { } else {
...@@ -93,10 +95,11 @@ export async function execute(psdFile, options) { ...@@ -93,10 +95,11 @@ export async function execute(psdFile, options) {
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).catch(e=>{}); let buffer = await savePng(png, imageFilePath).catch(e => {
});
//await node.origin.saveAsPng(imageFilePath); //await node.origin.saveAsPng(imageFilePath);
if(buffer){ if (buffer) {
properties.source = 'asset://' + uuid; properties.source = 'asset://' + uuid;
const hashFileName = hash(buffer); const hashFileName = hash(buffer);
......
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