修复 文本图层 进行矩阵缩放后字体显示不正确的问题

This commit is contained in:
onvia 2023-12-13 10:35:17 +08:00
parent 963a48256a
commit de9596375e
5 changed files with 40 additions and 26 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "ccc-tnt-psd2ui", "name": "ccc-tnt-psd2ui",
"version": "1.0.3", "version": "1.0.4",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@ -1549,7 +1549,13 @@
} }
} }
this.text = textSource.text; 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.offsetY = config.textOffsetY[this.fontSize] || config.textOffsetY["default"] || 0;
this.parseSolidFill(); this.parseSolidFill();
this.parseStroke(); this.parseStroke();

View File

@ -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-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": "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-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/" "test-same-name": "ts-node src/index.ts --engine-version v342 --pinyin --input ./test/sameName.psd --output ./out/"
}, },
"author": "", "author": "",

View File

@ -5,7 +5,7 @@ import { Vec2 } from "../values/Vec2";
import { PsdGroup } from "./PsdGroup"; import { PsdGroup } from "./PsdGroup";
import { PsdLayer } from "./PsdLayer"; import { PsdLayer } from "./PsdLayer";
export class PsdText extends PsdLayer{ export class PsdText extends PsdLayer {
declare parent: PsdGroup; declare parent: PsdGroup;
declare text: string; declare text: string;
declare fontSize: number; declare fontSize: number;
@ -18,14 +18,21 @@ export class PsdText extends PsdLayer{
super.parseSource(); super.parseSource();
let textSource = this.source.text; let textSource = this.source.text;
let style = textSource.style; let style = textSource.style;
if(style){ if (style) {
let fillColor = style.fillColor; let fillColor = style.fillColor;
if(fillColor){ if (fillColor) {
this.color = new Color(fillColor.r,fillColor.g,fillColor.b,fillColor.a * 255); this.color = new Color(fillColor.r, fillColor.g, fillColor.b, fillColor.a * 255);
} }
} }
this.text = textSource.text; 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.offsetY = config.textOffsetY[this.fontSize] || config.textOffsetY["default"] || 0;
@ -33,35 +40,35 @@ export class PsdText extends PsdLayer{
this.parseStroke(); this.parseStroke();
return true; return true;
} }
onCtor(){ onCtor() {
} }
/** 描边 */ /** 描边 */
parseStroke(){ parseStroke() {
if(this.source.effects?.stroke){ if (this.source.effects?.stroke) {
let stroke = this.source.effects?.stroke[0]; let stroke = this.source.effects?.stroke[0];
// 外描边 // 外描边
if(stroke?.enabled && stroke?.position === "outside"){ if (stroke?.enabled && stroke?.position === "outside") {
let color = stroke.color; let color = stroke.color;
this.outline = { this.outline = {
width: stroke.size.value, 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() { parseSolidFill() {
if(this.source.effects?.solidFill){ if (this.source.effects?.solidFill) {
let solidFills = this.source.effects?.solidFill; let solidFills = this.source.effects?.solidFill;
for (let i = 0; i < solidFills.length; i++) { for (let i = 0; i < solidFills.length; i++) {
const solidFill = solidFills[i]; const solidFill = solidFills[i];
if(solidFill.enabled){ if (solidFill.enabled) {
let color = solidFill.color; let color = solidFill.color;
this.color = new Color(color.r,color.g,color.b,solidFill.opacity * 255); this.color = new Color(color.r, color.g, color.b, solidFill.opacity * 255);
}
} }
} }
} }
}
} }

View File

@ -188,7 +188,7 @@ function reWriteVersion() {
} }
cocosVersion = "v3.4.+" cocosVersion = "v3.4.+"
//cocosVersion = "v2.4.x" cocosVersion = "v2.4.x"
const pluginVersion = "1.0.3"; // 打包之前记得修改这里的版本号第三位为只更新lib文件前两位为更新整个插件。 const pluginVersion = "1.0.3"; // 打包之前记得修改这里的版本号第三位为只更新lib文件前两位为更新整个插件。