Skip to content

Commit 9c27d8f

Browse files
authored
Merge pull request #1 from Tokihana/setTextItem
处理换行符问题和字符样式保存问题
2 parents cde8289 + 906f19c commit 9c27d8f

15 files changed

Lines changed: 49 additions & 1 deletion

.vs/ConvertToSimplify_1.0.0/FileContentIndex/1f2738f4-08de-428c-8c11-c827639647d8.vsidx renamed to .vs/ConvertToSimplify_1.0.0/FileContentIndex/33dd54ca-45e5-4e92-a802-1bc6c6cd3624.vsidx

File renamed without changes.

.vs/ConvertToSimplify_1.0.0/FileContentIndex/e9e2eb7d-e970-48d6-beb8-edbee7dd1c95.vsidx renamed to .vs/ConvertToSimplify_1.0.0/FileContentIndex/6ee2e61f-ccd0-4f8e-9d30-3bed193510fa.vsidx

3.47 MB
Binary file not shown.
Binary file not shown.
Binary file not shown.
2.5 KB
Binary file not shown.
0 Bytes
Binary file not shown.
-2.14 KB
Binary file not shown.

.vs/slnx.sqlite

0 Bytes
Binary file not shown.

Convert.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,26 @@ function processLayers(layers) {
3030
var textItem = layers[j].textItem;
3131
var originalText = textItem.contents;
3232
var convertedText = convertText(originalText);
33-
textItem.contents = convertedText;
33+
34+
// 保存字符属性方式
35+
var characterStyle = textItem.characterStyle;
36+
var paragraphStyle = textItem.paragraphStyle;
37+
var warpStyle = textItem.warpStyle;
38+
var baseline = textItem.baseline;
39+
var tsume = textItem.tsume;
40+
41+
textItem.contents = convertedText.replace(/\n/g, '\r'); // 需要修改换行符,否则乱码
42+
// var visibleText = convertedText.replace(/\n/g, '\\n'); // 检查换行符
43+
// logFile.writeln(visibleText)
44+
45+
// 设置字符属性
46+
textItem.characterStyle = characterStyle;
47+
textItem.paragraphStyle = paragraphStyle;
48+
textItem.warpStyle = warpStyle;
49+
textItem.baseline = baseline;
50+
textItem.tsume = tsume;
51+
52+
3453
} else if (layers[j].typename == "LayerSet") {
3554
processLayers(layers[j].layers);
3655
}

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,17 @@ PS调用JS脚本,提取出文本框内的文本,调用Python脚本,使用o
114114
脚本和psd路径都不要有中文, 可能会有不可预想的bug。
115115

116116
代码运行后,需要检查是否有缺字,以及部分字符样式可能需要重设(已知有标准罗马对齐,比例间距等,换行符等)。这个是后面需要改进的问题。
117+
118+
119+
120+
# 2023/7/3 Fixed
121+
122+
1. 不能保留字符样式和段落样式
123+
124+
解决但没完全解决,可以事先保存`characterStyle`, `paragraphStyle`, `warpStyle`,但单个字符上的设置似乎还是没法保存?(指基线偏移和字符间距,该不会因为这两个是中日文独有的?)
125+
126+
2. 字符转换会将换行转换为不可读样式。
127+
128+
这个问题是因为换行符是`\r`,而不是`\n`,因此需要用.replace()`改过来。
129+
130+
3. 对于问题1中的不能完全保留字符样式和段落样式,是因为我会对对白中的某些字符样式做单独处理,这部分是需要单独划分出来并保存的。

0 commit comments

Comments
 (0)