VBScript : TCPDFで MSフォントが使えるようにする全自動スクリプト


  概要




重要

TCPDF に付属されている  Arial Uni CID0(arialunicid0) 日本語フォントは
非埋め込み型の日本語フォントで、Windows にフォント本体があります。

この定義ファイルが、他の日本語フォントを TCPDF に組み込むためのサンプルで、同様の手順で
昔ながらの MS フォントを手作業で組み込んでみましたが、結構面倒なので全て自動化しました。


自動化のプロセス

1) TTC 分解用のアプリケーションのダウンロード

	エクセルソフトさんからダウンロードして解凍し、それで実行します
	それにより、5つの TTF フォントができあがります
	( Windows ディリクトリより直接取り出しているので、本体はそのままです )

2) TCPDF の仕様に基づいて、定義ファイルを作成

	TCPDF に付属している ttf2ufm.exe で .ufm を作成します
	その .ufm と元の .ttf を使って .php ファイルを作成
	この処理には、TCPDF 付属の makefont.php を使用しますが、
	このファイルの3番目の引数として、0 を渡す事によって、非埋め込み型になります
	( README.TXT に記述されています )
	-----------------------------------------------------------------------
	$embedded : Set to false to not embed the font, true otherwise (default).
	-----------------------------------------------------------------------

3) README.TXT の記述に基づいて、出来上がった .php ファイルを編集

	-----------------------------------------------------------------------
	a) change the font type to: $type='cidfont0';
	b) set the default font width by adding the line: $dw=1000;
	c) remove the $enc, $file and $ctg variables definitions
	d) add one of the following blocks of text at the end of the file
	// Japanese
	$enc='UniJIS-UTF16-H';
	$cidinfo=array('Registry'=>'Adobe', 'Ordering'=>'Japan1','Supplement'=>5);
	include(dirname(__FILE__).'/uni2cid_aj16.php');
	-----------------------------------------------------------------------

4) TCPDF のフォントディレクトリに保存

	-----------------------------------------------------------------------
	copy the .php file to the TCPDF fonts directory.
	-----------------------------------------------------------------------

※ TCPDF の仕様では個別にイタリックやボールド書体を用意しないとその機能は使えないようです
※ ですから、.php という定義ファイルは書体一つについて一つしか作成していません。
※ サンプルの arialunicid0 も一つしかありませんでした。
※ 小塚ゴシックPro Mや小塚明朝Pro M は、Adobe のフォントである為フォント本体はありません
  ( フォントの詳細に関しては専門外なので良く解りませんが、特殊な定義ファイルになっていました )








  TCPDF 用全自動スクリプト




このままでは使えませんので注意して下さい。

TCPDF のインストールディレクトリと、PHP のインストールディレクトリを
ご自分の環境にあわせて変更していただく必要があります



処理終了後のカレントのファイル群について

これらは、TCPDF の処理には必要ありませんので全て削除していただいて結構です

ブラウザでダウンロード

書体印字サンプル

元々利用可能なフォントに加えて、MSフォントの印字サンプルです

<JOB>
<COMMENT>
************************************************************
■ 1) BREAKTTC.EXE をダウンロードする
■ 2) TTC であるMSゴシックとMS明朝を分解する
■ 3) TCPDF に登録する

■ 著作権その他

このプログラムはフリーです。どうぞ自由に御使用ください。
著作権は作者である私(lightbox)が保有しています。
また、本ソフトを運用した結果については、作者は一切責任を
負えせんのでご了承ください。
************************************************************
</COMMENT>

<COMMENT>
************************************************************
 外部スクリプト定義
************************************************************
</COMMENT>
<SCRIPT
	language="VBScript"
	src="http://homepage2.nifty.com/lightbox/laylaClass.vbs">
</SCRIPT>

<SCRIPT language=VBScript>
' ***********************************************************
' 処理開始
' ***********************************************************
Call laylaFunctionTarget( "http://homepage2.nifty.com/lightbox/" )
Call laylaLoadFunction( "baseFunction.vbs" )
Call laylaLoadFunction( "toolFunction.vbs" )


' ***********************************************************
' 対象
' ***********************************************************
strTarget = "ttsdk.zip"
strTTCTargetMSG = "MSGOTHIC.TTC"
strTTCTargetMSM = "MSMINCHO.TTC"
' PHP で使用する時のパス
strTCPDF = "C:\user\web\tcpdf_5_5_001"
' PHP のパス
strPHP = "C:\php"

strFont1 = "msgothic"
strFont2 = "msgothicp"
strFont3 = "msgothicui"
strFont4 = "msmincho"
strFont5 = "msminchop"

' ***********************************************************
' Cscript.exe の実行
' ***********************************************************
Crun2 80

if not OkCancel( "BREAKTTC.EXE をダウンロードして .TTC を TTF に分解する処理を実行してもよろしいですか?" ) then
	Wscript.Quit
end if


' ***********************************************************
' ダウンロードする URL
' ***********************************************************
strDownloadPlace = "http://www.xlsoft.com/jp/products/indigorose/files/" & strTarget
ret = HTTPDownload( strDownloadPlace, TempDir & "\" & strTarget )
if not ret then
	Wscript.Echo ErrorMessage
	Wscript.Quit
end if

Wscript.Echo strDownloadPlace & " をダウンロードしました"

' ***********************************************************
' 解凍ソフトのダウンロード
' ***********************************************************
strDownloadPlace = "http://homepage2.nifty.com/lightbox/Lhasa.exe"
ret = HTTPDownload( strDownloadPlace, TempDir & "\Lhasa.exe" )
if not ret then
	Wscript.Echo ErrorMessage
	Wscript.Quit
end if

Wscript.Echo strDownloadPlace & " をダウンロードしました"

' ***********************************************************
' 解凍
' ***********************************************************
strCommand = Dd( TempDir & "\Lhasa.exe" ) & " -d- -a -q -f -e- " & Dd(TempDir & "\" & strTarget )
RunSync(strCommand)


' ***********************************************************
' フォント分解
' ***********************************************************
strFontsDir = GetSpecialFolder("Fonts")
strExe = Dd(TempDir & "\ttsdk\TTC\BREAKTTC.EXE")

GetFso 
GetWshShell
strCurrentDirectory = WshShell.CurrentDirectory

on error resume next
Fso.CreateFolder("FONT1")
Fso.CreateFolder("FONT2")
on error goto 0

WshShell.CurrentDirectory = strCurrentDirectory & "\FONT1"

strFont = Dd(strFontsDir & "\" & strTTCTargetMSG)
strCommand = strExe & " " & strFont
Wscript.Echo "フォント分解を開始します"
RunSync2(strCommand)
Wscript.Echo "フォント分解を終了しました"

WshShell.CurrentDirectory = strCurrentDirectory & "\FONT2"

strFont = Dd(strFontsDir & "\" & strTTCTargetMSM)
strCommand = strExe & " " & strFont
Wscript.Echo "フォント分解を開始します"
RunSync2(strCommand)
Wscript.Echo "フォント分解を終了しました"

WshShell.CurrentDirectory = strCurrentDirectory


' ***********************************************************
' フォント名を小文字に
' ***********************************************************
on error resume next
Set objFile = Fso.GetFile( strCurrentDirectory & "\FONT1\FONT00.TTF" )
objFile.Name = strFont1 & ".ttf"
Set objFile = Fso.GetFile( strCurrentDirectory & "\FONT1\FONT01.TTF" )
objFile.Name = strFont2 & ".ttf"
Set objFile = Fso.GetFile( strCurrentDirectory & "\FONT1\FONT02.TTF" )
objFile.Name = strFont3 & ".ttf"

Set objFile = Fso.GetFile( strCurrentDirectory & "\FONT2\FONT00.TTF" )
objFile.Name = strFont4 & ".ttf"
Set objFile = Fso.GetFile( strCurrentDirectory & "\FONT2\FONT01.TTF" )
objFile.Name = strFont5 & ".ttf"
on error goto 0



' ***********************************************************
' UFM 作成
' ***********************************************************
Call CreateUfm( "FONT1", strFont1 )
Call CreateUfm( "FONT1", strFont2 )
Call CreateUfm( "FONT1", strFont3 )
Call CreateUfm( "FONT2", strFont4 )
Call CreateUfm( "FONT2", strFont5 )


' ***********************************************************
' 編集
' ***********************************************************
EditPhp( strFont1 )
EditPhp( strFont2 )
EditPhp( strFont3 )
EditPhp( strFont4 )
EditPhp( strFont5 )


' ***********************************************************
' 処理終了
' ***********************************************************
MsgOk( "処理が終了しました   " )




' ***********************************************************
' 
' ***********************************************************
Function CreateUfm( strDir, str )

	strCommand = Dd(strTCPDF & "\tcpdf\fonts\utils\ttf2ufm.exe") & " -a -F " & Dd(strCurrentDirectory & "\" & strDir & "\" & str & ".ttf")
	RunSync(strCommand)
	strCommand = Dd(strPHP & "\php.exe") & " " & Dd(strTCPDF & _
		"\tcpdf\fonts\utils\makefont.php") & _
		" " & Dd(strCurrentDirectory & "\" & strDir & "\" & str & ".ttf") & _
		" " & Dd(strCurrentDirectory & "\" & strDir & "\" & str & ".ufm") & " 0"
	RunSync(strCommand)

End Function

Function EditPhp( str )

	Set regEx = New RegExp
	regEx.Pattern = "TrueTypeUnicode"
	regEx.IgnoreCase = True
	strFontPhp = GetTextFile(str & ".php")
	strFontPhp = regEx.Replace(strFontPhp, "cidfont0")

	regEx.Pattern = "\$dw=.+?;"
	strFontPhp = regEx.Replace(strFontPhp, "$dw=1000;")
	regEx.Pattern = "\$enc=.+?;"
	strFontPhp = regEx.Replace(strFontPhp, "$enc='UniJIS-UTF16-H';" & vbCrLf & _
	"$cidinfo=array('Registry'=>'Adobe', 'Ordering'=>'Japan1','Supplement'=>5);" & vbCrLf & _
	"include(dirname(__FILE__).'/uni2cid_aj16.php');" )
	regEx.Pattern = "\$file=.+?;"
	strFontPhp = regEx.Replace(strFontPhp, "")
	regEx.Pattern = "\$ctg=.+?;"
	strFontPhp = regEx.Replace(strFontPhp, "")
	Call PutTextFile( str & ".php", strFontPhp )
	Call Fso.CopyFile( str & ".php", strTCPDF & "\tcpdf\fonts\" & str & ".php", True ) 

End Function


</SCRIPT>

</JOB>





yahoo  google  MSDN  MSDN(us)  WinFAQ  Win Howto  tohoho  ie_DHTML  vector  wdic  辞書  天気 


[sh_web]
CCBot/2.0 (https://commoncrawl.org/faq/)
25/03/26 20:17:47
InfoBoard Version 1.00 : Language=Perl

1 BatchHelper COMprog CommonSpec Cprog CprogBase CprogSAMPLE CprogSTD CprogSTD2 CprogWinsock Cygwin GameScript HTML HTMLcss InstallShield InstallShieldFunc JScript JScriptSAMPLE Jsfuncs LLINK OldProg OracleGold OracleSilver PRO PRObrowser PROc PROconePOINT PROcontrol PROftpclient PROjscript PROmailer PROperl PROperlCHAT PROphp PROphpLesson PROphpLesson2 PROphpLesson3 PROphpfunction PROphpfunctionArray PROphpfunctionMisc PROphpfunctionString PROsql PROvb PROvbFunction PROvbString PROvbdbmtn PROvbonepoint PROwebapp PROwin1POINT PROwinSYSTEM PROwinYOROZU PROwindows ProjectBoard RealPHP ScriptAPP ScriptMaster VBRealtime Vsfuncs a1root access accreq adsi ajax amazon argus asp aspSample aspVarious aspdotnet aw2kinst cappvariety centura ckeyword classStyle cmaterial cmbin cmdbapp cmenum cmlang cmlistbox cmstd cmstdseed cmtxt cs daz3d db dbCommon dbaccess dnettool dos download flex2 flex3 flex4 framemtn framereq freeWorld freesoft gimp ginpro giodownload google hdml home hta htmlDom ie9svg install java javaSwing javascript jetsql jquery jsp jspTest jspVarious lightbox listasp listmsapi listmsie listmsiis listmsnt listmspatch listmsscript listmsvb listmsvc memo ms msde mysql netbeans oraPlsql oracle oracleWiper oraclehelper orafunc other panoramio pear perl personal pgdojo pgdojo_cal pgdojo_holiday pgdojo_idx pgdojo_ref pgdojo_req php phpVarious phpguide plsql postgres ps r205 realC realwebapp regex rgaki ruby rule sboard sc scprint scquest sdb sdbquest seesaa setup sh_Imagick sh_canvas sh_dotnet sh_google sh_tool sh_web shadowbox shgm shjquery shvbs shweb sjscript skadai skywalker smalltech sperl sqlq src systemdoc tcpip tegaki three toolbox twitter typeface usb useXML vb vbdb vbsfunc vbsguide vbsrc vpc wcsignup webanymind webappgen webclass webparts webtool webwsh win8 winofsql wmi work wp youtube