From de9596375e2c2a51ba31574d6f206921f24bad4c Mon Sep 17 00:00:00 2001 From: onvia <272493431@qq.com> Date: Wed, 13 Dec 2023 10:35:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E5=9B=BE=E5=B1=82=20=E8=BF=9B=E8=A1=8C=E7=9F=A9=E9=98=B5?= =?UTF-8?q?=E7=BC=A9=E6=94=BE=E5=90=8E=E5=AD=97=E4=BD=93=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- psd2ui-tools/dist/index.js | 8 ++++- psd2ui-tools/package.json | 1 + psd2ui-tools/src/psd/PsdText.ts | 53 +++++++++++++++++++-------------- src/index.js | 2 +- 5 files changed, 40 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index 5c2becc..faf8800 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ccc-tnt-psd2ui", - "version": "1.0.3", + "version": "1.0.4", "description": "", "main": "index.js", "scripts": { diff --git a/psd2ui-tools/dist/index.js b/psd2ui-tools/dist/index.js index fc0a7c0..126a7d3 100644 --- a/psd2ui-tools/dist/index.js +++ b/psd2ui-tools/dist/index.js @@ -1549,7 +1549,13 @@ } } this.text = textSource.text; - this.fontSize = style.fontSize; + // 可能会对文本图层进行缩放,这里计算缩放之后的时机字体大小 + if (Math.abs(1 - textSource.transform[0]) > 0.001) { + this.fontSize = Math.round(style.fontSize * textSource.transform[0] * 100) / 100; + } + else { + this.fontSize = style.fontSize; + } this.offsetY = config.textOffsetY[this.fontSize] || config.textOffsetY["default"] || 0; this.parseSolidFill(); this.parseStroke(); diff --git a/psd2ui-tools/package.json b/psd2ui-tools/package.json index 093d265..2ef97c7 100644 --- a/psd2ui-tools/package.json +++ b/psd2ui-tools/package.json @@ -12,6 +12,7 @@ "test-init": "node dist/index.js --init --project-assets ./out/ --cache E:\\Git\\ccc-framework-3d\\tools\\psd2ui\\cache\\cache.json", "test-png9": "ts-node src/index.ts --engine-version v342 --pinyin --input ./test/png9.psd --output ./out/", "test-png9-2": "node dist/index.js --engine-version v342 --pinyin --input ./test/png9.psd --output ./out/", + "test-dpi": "ts-node src/index.ts --engine-version v342 --pinyin --input ./test/dpi-test.psd --output ./out/", "test-same-name": "ts-node src/index.ts --engine-version v342 --pinyin --input ./test/sameName.psd --output ./out/" }, "author": "", diff --git a/psd2ui-tools/src/psd/PsdText.ts b/psd2ui-tools/src/psd/PsdText.ts index 3d84f68..7818990 100644 --- a/psd2ui-tools/src/psd/PsdText.ts +++ b/psd2ui-tools/src/psd/PsdText.ts @@ -5,7 +5,7 @@ import { Vec2 } from "../values/Vec2"; import { PsdGroup } from "./PsdGroup"; import { PsdLayer } from "./PsdLayer"; -export class PsdText extends PsdLayer{ +export class PsdText extends PsdLayer { declare parent: PsdGroup; declare text: string; declare fontSize: number; @@ -13,19 +13,26 @@ export class PsdText extends PsdLayer{ declare outline: { width: number, color: Color }; // 描边 declare offsetY: number; - + parseSource(): boolean { super.parseSource(); let textSource = this.source.text; let style = textSource.style; - if(style){ + if (style) { let fillColor = style.fillColor; - if(fillColor){ - this.color = new Color(fillColor.r,fillColor.g,fillColor.b,fillColor.a * 255); + if (fillColor) { + this.color = new Color(fillColor.r, fillColor.g, fillColor.b, fillColor.a * 255); } } this.text = textSource.text; - this.fontSize = style.fontSize; + + // 可能会对文本图层进行缩放,这里计算缩放之后的时机字体大小 + if (Math.abs(1 - textSource.transform[0]) > 0.001) { + this.fontSize = Math.round(style.fontSize * textSource.transform[0] * 100) / 100; + } else { + this.fontSize = style.fontSize; + } + this.offsetY = config.textOffsetY[this.fontSize] || config.textOffsetY["default"] || 0; @@ -33,35 +40,35 @@ export class PsdText extends PsdLayer{ this.parseStroke(); return true; } - onCtor(){ - + onCtor() { + } - /** 描边 */ - parseStroke(){ - if(this.source.effects?.stroke){ + /** 描边 */ + parseStroke() { + if (this.source.effects?.stroke) { let stroke = this.source.effects?.stroke[0]; // 外描边 - if(stroke?.enabled && stroke?.position === "outside"){ + if (stroke?.enabled && stroke?.position === "outside") { let color = stroke.color; this.outline = { width: stroke.size.value, - color: new Color(color.r,color.g,color.b,stroke.opacity * 255) + color: new Color(color.r, color.g, color.b, stroke.opacity * 255) } } } } - /** 解析 颜色叠加 */ - parseSolidFill() { - if(this.source.effects?.solidFill){ - let solidFills = this.source.effects?.solidFill; - for (let i = 0; i < solidFills.length; i++) { - const solidFill = solidFills[i]; - if(solidFill.enabled){ - let color = solidFill.color; - this.color = new Color(color.r,color.g,color.b,solidFill.opacity * 255); - } + /** 解析 颜色叠加 */ + parseSolidFill() { + if (this.source.effects?.solidFill) { + let solidFills = this.source.effects?.solidFill; + for (let i = 0; i < solidFills.length; i++) { + const solidFill = solidFills[i]; + if (solidFill.enabled) { + let color = solidFill.color; + this.color = new Color(color.r, color.g, color.b, solidFill.opacity * 255); } } } + } } \ No newline at end of file diff --git a/src/index.js b/src/index.js index ac23380..20f01e3 100644 --- a/src/index.js +++ b/src/index.js @@ -188,7 +188,7 @@ function reWriteVersion() { } cocosVersion = "v3.4.+" -//cocosVersion = "v2.4.x" +cocosVersion = "v2.4.x" const pluginVersion = "1.0.3"; // 打包之前记得修改这里的版本号,第三位为只更新lib文件,前两位为更新整个插件。