[ID CC2023] Chinese phonetic scripts

sztaishuo

Участник
Топикстартер
Сообщения
21
Реакции
4
I found a script with Chinese characters plus pinyin, but it won't work, and I don't understand what went wrong'%)'



/**
#targetengine "pinyinzhushou" //建立新会话

var declare = "本脚本一切都开放,请任意使用!\n如果出错,请联系我:qq 7470718。\n请勿贩卖此脚本!!!!!!\n请把有问题的字及时发给我!\n加载字库文件时间稍长,请耐心等待!\n版权所有:闫刚,2012年2月25日";
alert (declare, "警告", undefined);

alert ("选中需要注音的文本框或者文本,点击按钮即可。", "警告", undefined);

ScriptPreference.enableRedraw = false;


////拼音字库文件
var ziFile = File ('/d/拼音助手/汉字.txt');

var ziBiao = createZiBiao(); //字表
//$.writeln(ziBiao["2"]);
var regHanZi = /^[\u4e00-\u9fa5]/; //汉字正则表达式

try{
var curDocument = app.activeDocument;
}catch(docError){
curDocument = app.documents.add();
var pinYinTextFrame = curDocument.pages.item(0).textFrames.add();
pinYinTextFrame.geometricBounds = ["6p", "6p", "44p", "44p"];
pinYinTextFrame.contents = declare;
}

try{
duoYinColor = myDocument.colors.item("duoYinColor");
//If the color does not exist, trying to get its name will generate an error.
duoYinColorName = duoYinColor.name;
}
catch (colorError){
//The color style did not exist, so create it.
duoYinColor = curDocument.colors.add({name:"duoYinColor", model:ColorModel.process,
colorValue:[15, 100, 100, 0]});
}


/////////////////////UI
var mainWindow = new Window ("palette", "拼音助手") ;
mainWindow.frameLocation= [600, 500];
mainWindow.size= [120, 300];

mainWindow.btnPanel = mainWindow.add('panel', [0 , 0, 120, 300]);
mainWindow.btnPanel.ziDongZhuYinBtn = mainWindow.btnPanel.add ('button', [10 , 20, 110, 60], '自动注音');
mainWindow.btnPanel.ziDongZhuYinBtn.onClick = ziDongZhuYin;

mainWindow.show();

///////////////////////////
//自动注音
///////////////////
function ziDongZhuYin()
{
//$.writeln("zidongzhuyin called!!");
sel = app.selection[0];
switch(sel.constructor.name)
{
case "Character":
{
addPinYin(sel);
break;
}

case "Word":
case "Text":
case "TextStyleRange":
case "TextFrame":
case "Paragraph":
{
var curChar = new Character;
$.writeln(sel.characters.length);
var length = sel.characters.length;

var count = 0;
while(count < length )
{
curChar = sel.characters[count];
//~ if(sel.characters.nextItem(curChar).constructor.name != 'Character')
//~ break;
if(regHanZi.test (curChar.contents.toString ()))//使用正则表达式检查是否是汉字
addPinYin (curChar);
count++;
//$.writeln(sel.characters.nextItem(curChar).constructor.name);

};//end of while
break;
} //end of case

default:
alert("请选择文本或文本框");
break;
}
}


//创建字表函数
function createZiBiao()
{
var ziBiao = new Array;
var haXiZiBiao = new Array;

var zi;
var pinyin;
var isDuoYinZi = false;

var tempString = new String;
tempString = "tempString";
var tempStringArray;
ziFile.open('read');

while(tempString!= ziFile.eof )
{
tempString = ziFile.readln();

if(tempString == '')
break;
// $.writeln (tempString);
tempStringArray = tempString.split('|');
// $.writeln (tempStringArray);
pinyin = tempStringArray[1].split(' ');
//$.writeln (pinyin);

zi = tempStringArray[0][0];
//$.writeln (zi);
if(pinyin.length>1)
isDuoYinZi = true;
hanzi = new HanZi (zi, pinyin, isDuoYinZi);
//$.writeln(hanzi.zi);
ziBiao.push (hanzi) ;
}//end of while

for(var i = 0 ; i<ziBiao.length; i++)
{
haXiZiBiao[ziBiao.zi] = ziBiao;
}

ziFile.close();
return haXiZiBiao;
}//end of createZiBiao()


//汉字类
function HanZi(zi, pinyin, isDuoYinZi)
{
this.zi = zi;
this.pinyin = pinyin;
this.isDuoYinZi = isDuoYinZi;
}

//添加拼音函数
function addPinYin(character)
{
pinyin = ziBiao[character.contents[0]].pinyin;
character.rubyFlag = true;
character.rubyString = pinyin[0];
if(pinyin.length>1)
{
character.fillColor = duoYinColor;
//character.rubyFill = duoYinZiYanSe.name;
}

}
1693639785243.png
Such an effect
 

sztaishuo

Участник
Топикстартер
Сообщения
21
Реакции
4
I bind the corresponding txt
 

Вложения

  • 汉字.rar
    74.1 КБ · Просм.: 82

sztaishuo

Участник
Топикстартер
Сообщения
21
Реакции
4
This is the general document, with no great god help'hz'
 

Вложения

  • 拼音.rar
    118 КБ · Просм.: 86

sztaishuo

Участник
Топикстартер
Сообщения
21
Реакции
4
Already resolved'thank'
 

sztaishuo

Участник
Топикстартер
Сообщения
21
Реакции
4
It should be polite to share the result with us, don't you agree? 8*)
Haha, I don't know if you guys need this kind of thing.({
You need to create a new folder on the D drive, name it "汉字加拼音", and put the text in
The Pinyin settings follow the ID Pinyin settings, and you can modify the rest of the values'beer1'
 

Вложения

  • 自动注音.rar
    84.1 КБ · Просм.: 73
  • Спасибо
Реакции: densen

densen

15 лет на форуме
Сообщения
753
Реакции
642
You need to create a new folder on the D drive, name it "汉字加拼音", and put the text in
I tried to put this text file on D drive and change var ziFile = File ('/d/拼音助手/汉字.txt') into var ziFile = File ('/d/ping.txt');. But it was all in vain. "自动注音" button was of no use, nothing happened. Fonts were installed in "AppData\Roaming\Adobe\Fonts\" folder. What else is wrong?
 

sztaishuo

Участник
Топикстартер
Сообщения
21
Реакции
4
I tried to put this text file on D drive and change var ziFile = File ('/d/拼音助手/汉字.txt') into var ziFile = File ('/d/ping.txt');. But it was all in vain. "自动注音" button was of no use, nothing happened. Fonts were installed in "AppData\Roaming\Adobe\Fonts\" folder. What else is wrong?
To convert text to pinyin, you need to change the paragraph to the screenshot option first, and scroll down the fourth in "Kerning ---typesetter"
 

Вложения

  • 1693652051225.png
    1693652051225.png
    68 КБ · Просм.: 82
  • Спасибо
Реакции: densen

sztaishuo

Участник
Топикстартер
Сообщения
21
Реакции
4
The name of the file given, as well as the naming of the folder, must be Chinese, otherwise it will not be recognized
 

densen

15 лет на форуме
Сообщения
753
Реакции
642
To convert text to pinyin, you need to change the paragraph to the screenshot option first
Yeah, there is no such Paragraph Style's Сomposer option in my InDesign CS6.
The name of the file given, as well as the naming of the folder, must be Chinese, otherwise it will not be recognized
The name of the file may be anything you want as long as its name is properly put in here: var ziFile = File ('/d/拼音助手/汉字.txt')
 

sztaishuo

Участник
Топикстартер
Сообщения
21
Реакции
4
Yes, the file name can be set by yourself
I ran smoothly on the 2023ID page,Your question I feel is the paragraph aspect
Yeah, there is no such Paragraph Style's Сomposer option in my InDesign CS6.

The name of the file may be anything you want as long as its name is properly put in here: var ziFile = File ('/d/拼音助手/汉字.txt')
 
  • Спасибо
Реакции: densen