InDesign テキストフレームの長体処理 AppleScript
2-2 04 選択されたテキストフレームがオーバーフローしているとき長体をかける(P105)
- 作者: (株)シータス,古籏一浩
- 出版社/メーカー: 技術評論社
- 発売日: 2008/11/25
- メディア: 大型本
- 購入: 5人 クリック: 91回
- この商品を含むブログ (8件) を見る
書籍では、テキストフレームを選択した状態でスクリプトを実行しているが、当ブログではスクリプトで対象オブジェクトを取得する方式に書き替えることにする(オブジェクトを選択する必要のない場合)。
また、書籍の解説部分(当ブログでは部品作製)はスクリプトが1行で書かれているが、なるべくハンドラ化するよう試みる。
部品作製
- InDesign ドキュメント
- AppleScript ハンドラ
-- 指定されたページのテキストフレームを返す on getTextFrames(myPage) tell document 1 of application "Adobe InDesign CS6" every text frame of page myPage end tell end getTextFrames -- テキストフレームがオーバーフローしているか? on isOverFlow(tfObj) tell application "Adobe InDesign CS6" overflows of tfObj end tell end isOverFlow -- テキストフレームの[tIdx]番目のテキストの長体率を取得する on horizontalScale(tfObj, tIdx) tell application "Adobe InDesign CS6" horizontal scale of text tIdx of tfObj end tell end horizontalScale -- テキストフレームの[tIdx]番目のテキストの長体率を変更する on setHorizontalScale(tfObj, tIdx, myScale) tell application "Adobe InDesign CS6" set horizontal scale of text tIdx of tfObj to myScale end tell end setHorizontalScale
部品が揃ったので、まとめ
set limitScale to 65 -- 最小長体率 set myList to getTextFrames(1) set loop to number of myList repeat with i from 1 to loop set myTF to item i of myList if isOverFlow(myTF) is true then set myScale to horizontalScale(myTF, 1) repeat set myScale to myScale - 1 if myScale < limitScale then exit repeat setHorizontalScale(myTF, 1, myScale) if isOverFlow(myTF) is false then exit repeat end repeat end if end repeat
実行結果
- テキストフレーム 1(以下 TF1)と TF2 の長体率が変更された。
- TF2 は長体率が最小長体率(上記スクリプトでは65%)に達したので処理が中断している。
- TF1 のオーバーフローは解消されたが、行頭と行末の長体率が異なっている。
処理中の画面を観察すると、どうやらTF外にある文字の長体率が変更されないようだ。
長体率を変更する対象を text から paragraph に変更すると、上手く動くようだ。
部品を追加
- AppleScript ハンドラ
-- テキストフレームの指定された段落(paragraph)の長体率を変更する -- pidx が 0 なら全ての段落が対象 on setParagraphScaleH(tfObj, pidx, myScale) tell application "Adobe InDesign CS6" if pidx > 0 then set horizontal scale of paragraph pidx of tfObj to myScale else set horizontal scale of every paragraph of tfObj to myScale end if end tell end setParagraphScaleH
改良版
set limitScale to 65 -- 最小長体率 set myList to getTextFrames(1) set loop to number of myList repeat with i from 1 to loop set myTF to item i of myList if isOverFlow(myTF) is true then set myScale to horizontalScale(myTF, 1) repeat set myScale to myScale - 1 if myScale < limitScale then exit repeat setParagraphScaleH(myTF, 0, myScale) if isOverFlow(myTF) is false then exit repeat end repeat end if end repeat
改良版:実行結果
- OS X 10.8.5
- Adobe InDesign CS6, version: 8.0.2.413