10)テキストボックスに1行になるよう長体

| コメント(0) | トラックバック(0)

長体方法のうちのひとつ。テキストボックスに収まるように、まずテキストボックスの横幅を測り、1行のときの文字列の幅も測り比率をだして長体をかけます。ポイントはテキストボックスを複製し、横幅を10倍にします。(それで1行になると思われるため)さらに文字列をアウトラインし正確な文字幅を求めます。あとは比率を出してやるだけです。
もっと普通に長体をかける方法もありますがInDesignの長体を参照していただければと思います。

tell application "Adobe Illustrator"
	tell document 1
		set mySelObjList to selection --選択されたオブジェクトを調べる
		repeat with mySelObj in mySelObjList --選択分繰り返す
			if class of mySelObj is text frame then --もしtext frameなら
				my chouTai(mySelObj)
			end if
		end repeat
	end tell
end tell

on chouTai(mySelObj)
	tell application "Adobe Illustrator"
		set myW to width of mySelObj --text frameの幅を調べる
		--長体horizontal scaleを調べる(平体はvertical scale)--
		--Illustrator10ではscalingで縦横の比率がとれる
		set SCL to horizontal scale of paragraph 1 of mySelObj
		--横幅10倍サイズで複製する
		set dupTextObj to duplicate mySelObj to beginning of document 1 ¬
			with properties {width:myW * 10}
		--長体も10倍になるので長体を101%にする(なぜか100%にはならない)
		if SCL = 100 then
			set SCL to 101
		end if
		set horizontal scale of paragraph 1 of dupTextObj to SCL
		--行数を調べる
		set Pcount to count paragraph of dupTextObj
		if Pcount > 1 then --行数が2行以上なら
			display dialog "1行のテキストのみに有効です。"
			return --処理終了
		end if
		--行揃えを左にしておく。両揃えだと正しくはかれない
		set justification of paragraph 1 of dupTextObj to left
		--アウトライン作成
		set outLinePath to convert to paths dupTextObj
		--アウトラインの領域を調べる
		set myBounds to control bounds of outLinePath --control/visible
		--長さを取り出す
		set myW2 to (item 3 of myBounds) - (item 1 of myBounds) --(width of TBOX)
		delete outLinePath --アウトラインは消す
		if myW < myW2 then --もしアウトラインの方がtext frameよりも長ければ
			set myWhi to myW / myW2 --比率を求めて
			set SCL to SCL * myWhi - 1--誤差が出るので1%マイナスする
			set horizontal scale of paragraph 1 of mySelObj to SCL
		end if
	end tell
end chouTai

トラックバック(0)

トラックバックURL: http://www.adg7.com/mt/mt-tb.cgi/64

Comments are nofollow setting

コメントする

エントリー一覧

OpenID対応しています OpenIDについて
Powered by Movable Type 7.902.0
漢字イラストロジック-脳トレ京
FREE ONLINE SUDOKU