tell application "Adobe InDesign 2021" | |
try | |
--選択テキストを取得する | |
set curSelection to object reference of selection of document 1 | |
if class of curSelection is in {text, character, word, line, paragraph, text style range, text column} then | |
set everyChar to object reference of every character of curSelection | |
--1文字ずつ処理をする | |
repeat with aChar in everyChar | |
--OpenType featuresを取得 | |
set aOTF to OpenType features of aChar | |
--空ではなかったらフィーチャーを取得 | |
if aOTF is not {} then | |
set aOTF to item 1 of item 1 of aOTF | |
--フィーチャーがaaltかnaltならサブルーチンのreWriteで処理をする | |
if (aOTF is "aalt") or (aOTF is "nalt") then | |
my reWrite(aChar) | |
end if | |
end if | |
end repeat | |
end if | |
end try | |
end tell | |
--異体字属性を消すためにcontentsを書き換えるサブルーチン | |
on reWrite(theChar) | |
tell application "Adobe InDesign 2021" | |
if length of theChar is 1 then | |
--ruby flagがtrue | |
if ruby flag of theChar then | |
--ルビが消失しないように書き換える | |
--ここは達人に書いてもらったところなので私にもよくわからない | |
set theLineRange to object reference of paragraph 1 of theChar | |
set flagList_1 to ruby flag of every character of theLineRange | |
set theRubyString to ruby string of theChar | |
set theContents to contents of character 1 of theChar | |
set insertion point 2 of theChar to theContents | |
delete character 1 of theChar | |
set flagList_2 to ruby flag of every character of theLineRange | |
set n to count flagList_1 | |
set i to 1 | |
set numList to {} | |
repeat n times | |
if item i of flagList_1 and (not item i of flagList_2) then | |
set end of numList to i | |
end if | |
set i to i + 1 | |
end repeat | |
try | |
set properties of text from character (item 1 of numList) to character (item -1 of numList) of theLineRange to {ruby string:theRubyString, ruby flag:true} | |
end try | |
else | |
--ruby flagがfalse | |
--単純に書き換える | |
set theContents to contents of character 1 of theChar | |
set contents of character 1 of theChar to theContents | |
end if | |
end if | |
end tell | |
end reWrite |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment