Skip to content

Instantly share code, notes, and snippets.

@milligramme
Created September 21, 2010 01:41
Show Gist options
  • Save milligramme/589027 to your computer and use it in GitHub Desktop.
Save milligramme/589027 to your computer and use it in GitHub Desktop.
/**
飾り字形からパターンをつくる
"fill pattern to the frame"
使い方と注意:
テキストフレームまたはグラフィックフレームを1つ選択して実行。
フレーム内を消去して飾り字形のパターンで埋め、最後にグラフィックス化します。
オープンパスでもクローズドパスでも大丈夫のはず。
動作確認:OS10.4.11 InDesign CS3
milligramme
www.milligramme.cc
*/
if(app.documents.length==0 || app.selection.length!=1){
alert("select only one frame")
exit();
}
var selObj=app.selection[0];
switch(selObj.constructor.name){
case "TextFrame":
main (selObj); break;
case "Polygon":
case "Rectangle":
case "Oval":
selObj.contentType=ContentType.TEXT_TYPE;
//グラフィックフレームからテキストフレームに変換の手続き。contentType指定だけだとうまくいかない
selAsTF=app.selection[0];
selAsTF.parentStory.storyPreferences.storyOrientation=StoryHorizontalOrVertical.HORIZONTAL;
main(selAsTF); break;
default :
alert("select text frame or graphic frame");
exit();
}
function main(selObj){
var storyObj=selObj.parentStory;
storyObj.pointSize=9+Math.floor(Math.random()*30); //パターンの大きさを固定するならここを。
storyObj.leading=storyObj.pointSize;
storyObj.justification=Justification.LEFT_ALIGN;
var src;
var bkFontLock=app.fontLockingPreferences.fontChangeLocking;
app.fontLockingPreferences.fontChangeLocking=false; //バックアップとって一時字形保護を解除
storyObj.contents="";
//パターン字形の行列セット
var patType=Math.floor(Math.random()*2); //パターンの固定をするならここを。
if(patType==0){
src=["▁","▂","▃","▄","▅","▆","▇","█","▉","▊","▋","▌","▍","▎","▏"]; //0x8230 - 0x8238
try{
storyObj.appliedFont="小塚明朝 Pro R";
}catch(e){src=["x","-","+"];}
}
if(patType==1){
src=["░","▒","▓"]; //0x2591 - 0x2593
try{
storyObj.appliedFont="Batang"; //Arial, Batang, Century, Letter Gothic, Gulim, Orator, ST Heiti, Times New, MS Gothic & Mincho
}catch(e){src=["x","-","+"];}
}
app.fontLockingPreferences.fontChangeLocking=bkFontLock;
//領域内に文字をランダム埋めていく
while(selObj.parentStory.overflows==false){
storyObj.contents+=src[Math.floor(Math.random()*src.length)];
}
storyObj.characters[-1].remove(); //最後の文字を削除
//文字が打てなかった時のためのエラー処理
try{
var patObj=selObj.createOutlines (false);
}catch(e){}
//[黒]がオーバープリントオンになってしまうのでオフに。
for(var i=0, L=patObj[0].pageItems.length; i < L; i++ ){
try{
patObj[0].pageItems[i].overprintFill=false;
}catch(e){}
try{
patObj[0].pageItems[i].overprintStroke=false;
}catch(e){}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment