Commit 44222d47 authored by rockyl's avatar rockyl

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

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