XeTeXでpTeX+dvipdfmx用のVFを作る・GID/CIDアクセス

名前: ZR
日時: 2010-02-27 15:20:47
IPアドレス: 122.26.181.*

>>54564 に示した XeTeX を使う方法を発展させて、 LaTeX の欧文エンコーディングを実現する GID でのアクセスに よる仮想フォント を生成するプログラムを作ってみました。 CID-keyed OpenType フォントの場合は GID は CID に一致する ので CID-keyed OpenType フォントにも使えるはずです。 (誰か試してみませんか?) 実行手順は xetex gen-gid-pl opl2ofm meir-r-j40.opl pltotf meir-r-t1.pl ovp2ovf meir-r-t1.ovp meir-r-t1.ofm meir-r-t1.vf で、出力されるファイルの中で必要なものは meir-r-t1.tfm, meir-r-t1.vf, meir-r-j40.ofm の 3 つです。 dvipdfmx のマップ指定ですが、CID-keyed でない場合は meir-r-j40 Identity-H :0:meiryo.ttc/I のように後ろに "/I" が要ります。CID-keyed の場合は上のものから "/I" を取り去った形式になります。 %<gen-gid-pl.tex:in UTF-8>-------------- % % gen-pl.tex % \def\MainProgram{% \GenerateRawOPL{メイリオ}{meir-r-j40} \GenerateVirtual{メイリオ}\TiEncoding{meir-r-t1}{meir-r-j40} } % %---------------- % INTERNAL STUFFS %---------------- \catcode`\@=11 % \WriteBlock, etc. {\catcode13=13\catcode10=12\gdef\x@literal@cr{\def^^M{^^J}}} \def\x@hook@sp{\catcode32=12\catcode13=13\newlinechar=10\relax} \def\WriteBlock{\bgroup\x@hook@sp\x@literal@cr\x@writeblock@a} \def\x@writeblock@a#1#2{\immediate\write#1{#2}\egroup} \def\WriteBlockProc{\bgroup\x@hook@sp\x@writeblockproc@a} \def\x@writeblockproc@a#1#2{\gdef#1##1{\WriteBlock##1{#2}}\egroup} \def\OpenFile#1#2{\immediate\openout#1=#2\relax} \def\CloseFile{\immediate\closeout} % \ForEach...\Do \def\ForEach#1\Do{\edef\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}}} % \LetHex \def\LetHex#1{\def\x@nxt{\x@hex@b#1}% \afterassignment\x@hex@a \chardef\x@tmpa} \def\x@hex@a{\expandafter\x@nxt\meaning\x@tmpa\x@nil} \def\x@hex@b#1#2"#3\x@nil{\def#1{#3}} % %-------------- % PL-GENERATOR %-------------- \newbox\boxA \newdimen\dimA \newdimen\dimB \newdimen\dimC \newdimen\dimD \newcount\Pos \newcount\LimPos \newcount\Ucv \newbox\boxA \newwrite\fileA \newwrite\fileB %%<*> \GenerateRawOPL{<font_name>}{<pl_name>} \def\GenerateRawOPL#1#2{% \OpenFile\fileA{#2.opl}% \font\TheFont="#1"\relax % prologue \PrologueRawOPL\fileA % character \LimPos=\numexpr\XeTeXcountglyphs\TheFont+1\relax \Pos=1 \loop \setbox\boxA=\hbox{\TheFont\XeTeXglyph\Pos}% \dimA=\wd\boxA \CharacterRawOPL\fileA \advance\Pos1 \ifnum\Pos<\LimPos\repeat % done \CloseFile\fileA } \WriteBlockProc\CharacterRawOPL{% (CHARACTER D \the\Pos (CHARWD R \Rel\dimA) )} \WriteBlockProc\PrologueRawOPL{% (OFMLEVEL H 1) (FAMILY UNSPECIFIED) (CODINGSCHEME UNSPECIFIED) (DESIGNSIZE R 10.0) (DESIGNUNITS R 10.0) (FONTDIMEN (XHEIGHT R 10.0) (QUAD R 10.0) )} %%<*> \GenerateVirtual{<font_name>}{<pl/ovp_name>} \def\GenerateVirtual#1#2#3#4{% \OpenFile\fileA{#3.pl}% \OpenFile\fileB{#3.ovp}% \font\TheFont="#1"\relax \def\RefFont{#4}% \TheFont % 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' \ProloguePL\fileA \PrologueOVP\fileB % character \Pos=0 \ForEach#2\Do{% \Ucv="##1\relax \ifnum\Ucv=0\else\iffontchar\TheFont\Ucv \dimA=\fontcharwd\TheFont\Ucv \dimB=\fontcharht\TheFont\Ucv \dimC=\fontchardp\TheFont\Ucv \LetHex\Gid=\XeTeXcharglyph\Ucv \CharacterPL\fileA \CharacterOVP\fileB \fi\fi \advance\Pos1\relax}% % done \CloseFile\fileA \CloseFile\fileB } \WriteBlockProc\CharacterPL{% (CHARACTER D \the\Pos (CHARWD R \Rel\dimA) (CHARHT R \Rel\dimB) (CHARDP R \Rel\dimC) )} \WriteBlockProc\CharacterOVP{% (CHARACTER D \the\Pos (CHARWD R \Rel\dimA) (MAP (SETCHAR H \Gid) ) )} \WriteBlockProc\ProloguePL{% (FAMILY UNSPECIFIED) (CODINGSCHEME UNSPECIFIED) (DESIGNSIZE R 10.0) (DESIGNUNITS R 10.0) (FONTDIMEN (SPACE R \Rel\dimA) (STRETCH R \Rel\dimB) (SHRINK R \Rel\dimC) (XHEIGHT R \Rel\dimD) (QUAD R 10.0) (EXTRASPACE R \Rel\dimC) )} \WriteBlockProc\PrologueOVP{% (VTITLE ) (FAMILY UNSPECIFIED) (CODINGSCHEME UNSPECIFIED) (DESIGNSIZE R 10.0) (DESIGNUNITS R 10.0) (FONTDIMEN (XHEIGHT R 10.0) (QUAD R 10.0) ) (MAPFONT D 0 (FONTNAME \RefFont) )} % %% encoding vectors \def\TiEncoding{% {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}% } %-------------- \MainProgram \bye %<EOF>---------------------------------- 出力サンプルです。 %<sample.tex>--------------------------- \documentclass[a4paper]{jsarticle} \AtBeginDvi{\special{pdf:mapline meir-r-j40 Identity-H :0:meiryo.ttc/I}} \AtBeginDvi{\special{pdf:mapline rml H :0:meiryo.ttc}} \DeclareFontFamily{T1}{meiryo}{} \DeclareFontShape{T1}{meiryo}{m}{n}{<->s*[0.925]meir-r-t1}{} \begin{document} \usefont{T1}{meiryo}{m}{n} Windows のバージョンが違います. \end{document} %<EOF>---------------------------------- ポイントは、Unicode 値から GID(CID) への変換を自動的に行ってくれる ことなのですが、残念ながら、OpenType の feature を指定した状態の ものに対しては上手くいかないようです。これが可能ならば、Unicode 値のデータだけで feature 指定の状態が pTeX + dvipdfmx で使える ことになって、かなり強力なんですが…。 %<test.tex:in UTF-8>-------------------- % \XeTeXcharglyph で GID 番号を出力できる \font\meiryoA="メイリオ" \meiryoA メイリオ(Meiryo)は明瞭!〈M〉=\the\XeTeXcharglyph`M` \par % +ital で使用グリフは変わるが \XeTeXcharglyph は不変 (;_;) \font\meiryoB="メイリオ:+ital" \meiryoB メイリオ(Meiryo)は明瞭!〈M〉=\the\XeTeXcharglyph`M \par % /I だと別のフォント(シェープ)になるので当然 GID も変わる \font\meiryoC="メイリオ/I" \meiryoC メイリオ(Meiryo)は明瞭!〈M〉=\the\XeTeXcharglyph`M \bye %<EOF>----------------------------------

この書き込みへの返事:

お名前
題名 
メッセージ(タグは <a href="...">...</a> だけ使えます。適宜改行を入れてください)