名前: ZR 日時: 2010-02-20 14:10:17 IPアドレス: 122.26.181.*
>>54562 TTF/OTF に対する TeX 用のフォント設定を作る場合、まず最初に何らかの 方法で当該フォントのメトリック(字幅など)を取得する必要があり、 その手段が例えば ttf2tfm や otftotfm や FontForge(旧 Pfaedit) だったりするわけです。 で、私の場合、この作業のために XeTeX を使っています。(つまり従来 の TeX/(u)pTeX のための TFM を XeTeX で作っている。) といっても 普段は Perl 等の他のプログラム言語と併用するのですが、ここでは 敢えて plain XeTeX 単独で動作するプログラムを作ってみました。 以下のソースでは、 「IPA P明朝」/「IPA Pゴシック」の欧文部分(T1エンコーディング) の PL ファイルを ipam-r-t1.pl/ipag-r-t1.pl の名で作る ことをしています。PL から TFM への変換は pltotf を使います。 つまり、 xetex gen-pl.tex pltotf ipam-r-t1.pl pltotf ipag-r-t1.pl で目的の TFM が生成されます。 冒頭の \MainProgram を書き換えれば他の TTF/OTF で使えるはずです。 %<gen-pl.tex;文字コードはUTF-8>-------------- % % gen-pl.tex % \def\MainProgram{% \GeneratePL{IPA P明朝}{ipam-r-t1.pl}% \GeneratePL{IPA Pゴシック}{ipag-r-t1.pl}% } % %---------------- % INTERNAL STUFFS %---------------- \catcode`\@=11 % \WriteBlock, etc. \newwrite\x@file\relax {\catcode13=13\catcode10=12\gdef\x@literal@cr{\def^^M{^^J}}} \def\x@hook@sp{\catcode32=12\catcode13=13\relax} \def\WriteBlock{\bgroup\x@hook@sp\x@literal@cr\x@writeblock@a} \def\x@writeblock@a#1{\xdef\x@content{\x@content#1}\egroup} \def\WriteBlockProc{\bgroup\x@hook@sp\x@writeblockproc@a} \def\x@writeblockproc@a#1#2{\gdef#1{\WriteBlock{#2}}\egroup} \def\OpenFile#1{\immediate\openout\x@file=#1\relax \let\x@content\empty} \def\CloseFile{{\newlinechar=10\immediate\write\x@file{\x@content}}% \immediate\closeout\x@file} % \ForEach...\Do \def\ForEach#1\Do{\def\x@list{#1}% \afterassignment\x@foreach@a\def\x@do##1} \def\x@nil{}\def\x@nil@arg{\x@nil} \def\x@foreach@a{\expandafter\x@foreach@b\x@list\x@nil} \def\x@foreach@b#1{\def\x@arg{#1}% \ifx\x@arg\x@nil@arg\else\x@do{#1}\expandafter\x@foreach@b\fi} % \Rel \newdimen\x@dima \def\Rel{\expandafter\x@rel@a\the} {\lccode`8=`p\lccode`9=`t\lowercase{\gdef\x@rel@a#189{#1}}} \catcode`\@=12 % %-------------- % PL-GENERATOR %-------------- \newbox\boxA \newdimen\dimA \newdimen\dimB \newdimen\dimC \newdimen\dimD \newcount\Pos \newcount\Ucv %%<*> \GeneratePL{<font_name>}{<pl_name>} \def\GeneratePL#1#2{% % open file \OpenFile{#2}% \font\TheFont="#1"\relax % write prologue \dimA=\fontcharwd\TheFont32 % SPACE = width of space \dimB=\dimexpr\dimA/2\relax % STRETCH = SPACE/2 \dimC=\dimexpr\dimA/3\relax % SHRINK = SPACE/3 \dimD=\fontcharht\TheFont`x % XHEIGHT = height of 'x' \Prologue % write each character element \Pos=0 \ForEach {0060}{00B4}{02C6}{02DC}{00A8}{02DD}{02DA}{02C7}% {02D8}{00AF}{02D9}{00B8}{02DB}{201A}{2039}{203A}% {201C}{201D}{201E}{00AB}{00BB}{2013}{2014}{200C}% {2080}{0131}{0237}{FB00}{FB01}{FB02}{FB03}{FB04}% {2423}{0021}{0022}{0023}{0024}{0025}{0026}{2019}% {0028}{0029}{002A}{002B}{002C}{002D}{002E}{002F}% {0030}{0031}{0032}{0033}{0034}{0035}{0036}{0037}% {0038}{0039}{003A}{003B}{003C}{003D}{003E}{003F}% {0040}{0041}{0042}{0043}{0044}{0045}{0046}{0047}% {0048}{0049}{004A}{004B}{004C}{004D}{004E}{004F}% {0050}{0051}{0052}{0053}{0054}{0055}{0056}{0057}% {0058}{0059}{005A}{005B}{005C}{005D}{005E}{005F}% {2018}{0061}{0062}{0063}{0064}{0065}{0066}{0067}% {0068}{0069}{006A}{006B}{006C}{006D}{006E}{006F}% {0070}{0071}{0072}{0073}{0074}{0075}{0076}{0077}% {0078}{0079}{007A}{007B}{007C}{007D}{007E}{002D}% {0102}{0104}{0106}{010C}{010E}{011A}{0118}{011E}% {0139}{013D}{0141}{0143}{0147}{014A}{0150}{0154}% {0158}{015A}{0160}{015E}{0164}{0162}{0170}{016E}% {0178}{0179}{017D}{017B}{0132}{0130}{0111}{00A7}% {0103}{0105}{0107}{010D}{010F}{011B}{0119}{011F}% {013A}{013E}{0142}{0144}{0148}{014B}{0151}{0155}% {0159}{015B}{0161}{015F}{0165}{0163}{0171}{016F}% {00FF}{017A}{017E}{017C}{0133}{00A1}{00BF}{00A3}% {00C0}{00C1}{00C2}{00C3}{00C4}{00C5}{00C6}{00C7}% {00C8}{00C9}{00CA}{00CB}{00CC}{00CD}{00CE}{00CF}% {00D0}{00D1}{00D2}{00D3}{00D4}{00D5}{00D6}{0152}% {00D8}{00D9}{00DA}{00DB}{00DC}{00DD}{00DE}{0000}% {00E0}{00E1}{00E2}{00E3}{00E4}{00E5}{00E6}{00E7}% {00E8}{00E9}{00EA}{00EB}{00EC}{00ED}{00EE}{00EF}% {00F0}{00F1}{00F2}{00F3}{00F4}{00F5}{00F6}{0153}% {00F8}{00F9}{00FA}{00FB}{00FC}{00FD}{00FE}{00DF}% \Do{% \Ucv="##1\relax \ifnum\Ucv=0\else\iffontchar\TheFont\Ucv \dimA\fontcharwd\TheFont\Ucv \dimB\fontcharht\TheFont\Ucv \dimC\fontchardp\TheFont\Ucv \Character \fi\fi \advance\Pos1\relax}% % done \CloseFile } %% templates \WriteBlockProc\Character{% (CHARACTER D \the\Pos (CHARWD R \Rel\dimA) (CHARHT R \Rel\dimB) (CHARDP R \Rel\dimC) ) } \WriteBlockProc\Prologue{% (FAMILY UNSPECIFIED) (CODINGSCHEME UNSPECIFIED) (DESIGNSIZE R 10.0) (DESIGNUNITS R 10.0) (FONTDIMEN (SLANT R 0.0) (SPACE R \Rel\dimA) (STRETCH R \Rel\dimB) (SHRINK R \Rel\dimC) (XHEIGHT R \Rel\dimD) (QUAD R 10.0) (EXTRASPACE R \Rel\dimC) ) } %-------------- \MainProgram \bye %<EOF>--------------
この書き込みへの返事: