Illustrator JavaScript
文字あふれをチェックする

イラストレータファイルの文字あふれをチェックします。

旧バージョンからの変換時や、オブジェクトが入り組んでいて文字のあふれ表示が見えにくい時に使ってみてください。

2007.4.11 バージョン10に対応しました。


動作環境・注意

Illustrator 10、CS および CS2(12.0.1) で動作確認をしています。

CS2を12.0.1にアップデートしていない場合は正しく動作しない可能性があります。

実行時に文字あふれのあるテキストフレームを選択状態にします。従って実行前に選択状態になっていたオブジェクトの選択は解除されます。

ソースを変更する場合は保存時の文字エンコーディングに注意して下さい。CSの場合はシフトJIS、CS2の場合はUTF-8で保存して下さい。


ソース

CSおよびCS2

//選択状態のものがあれば解除する
if (activeDocument.selection.length > 0 ){
    activeDocument.selection = null;
}

for ( i=0 ; i < activeDocument.textFrames.length ; i++ ){
    txf = activeDocument.textFrames[i];
    //テキストフレームの文字数から改行の数を除いたもの
    charlength = txf.characters.length - txf.paragraphs.length + 1;
    //各行の文字数の合計を求める
    linelengths = 0;
    for ( j=0 ; j < txf.lines.length ; j++ ){
        linelengths += txf.lines[j].length;
    }
    //比較して文字数が異なれば選択状態にする
    if ( linelengths != charlength ){
        txf.selected = true;
    }
}
if (activeDocument.selection.length > 0 ){
    alert("あふれているテキストがあります");
} else {
    alert("文字あふれはありません");
}

10

//選択状態のものがあれば解除する
if (activeDocument.selection.length > 0 ){
    for ( i = 0 ; i < activeDocument.selection.length ; i++ )
        activeDocument.selection[i].selected = false;
    }
}

for ( i=0 ; i < activeDocument.textArtItems.length ; i++ ){
    txr = activeDocument.textArtItems[i].textRange();
    //テキストフレームの文字数から改行の数を除いたもの
    charlength = txr.characters.length - txr.paragraphs.length + 1;
    //各行の文字数の合計を求める
    linelengths = 0;
    for ( j=0 ; j < txr.textLines.length ; j++ ){
        linelengths += txr.textLines[j].length;
    }
    //比較して文字数が異なれば選択状態にする
    if ( linelengths != charlength ){
        activeDocument.textArtItems[i].selected = true;
    }
}
if (activeDocument.selection.length > 0 ){
    alert("あふれているテキストがあります");
} else {
    alert("文字あふれはありません");
}

[HOME]