ps_findfont

(PECL ps >= 1.1.0)

ps_findfontフォントを読み込む

説明

ps_findfont(
    resource $psdoc,
    string $fontname,
    string $encoding,
    bool $embed = false
): int

あとで使用するために、フォントを読み込みます。読み込んだフォントを実際に利用するためには、 ps_setfont() で設定しなければなりません。 文字の間隔を計算するため、この関数には adobe フォントメトリックファイルが必要です。 ページの内部で読み込まれたフォントは、 そのページ内でのみ有効となります。ドキュメント全体で使われるフォントは、 最初の ps_begin_page() の実行より前に読み込まれなければなりません。 ページとページの間で ps_findfont() が呼ばれた場合は、それ以降のページでフォントが有効になります。

afm ファイルの名前は、 fontname.afm でなければなりません。 フォントを埋め込む場合は、フォントのアウトラインを含む fontname.pfb が存在しなければなりません。

最初のページを処理する前に ps_findfont() をコール際、 postscript ヘッダが出力されます。ここには、ドキュメント全体に適用される BoundingBox が含まれます。 通常は、BoundingBox を設定するのは最初に ps_begin_page() がコールされたときで、これは ps_findfont() をコールした後になります。 したがって、ps_findfont() のコール時にはまだ BoundingBox が設定されておらず、警告が発生してしまいます。 こうなることを避けるため、ps_findfont() をコールする前に ps_set_parameter() をコールし、BoundingBox を設定しておくべきです。

パラメータ

psdoc

ps_new() が返す、postscript ファイルのリソース ID。

fontname

フォントの名前。

encoding

ps_findfont() は、encoding で渡されたファイルを読み込もうと試みます。 エンコーディングファイルは、 dvips(1) で使われるものと同形式です。 そこにはフォントエンコーディングベクタ(現在は利用されていませんが、 存在する必要があります)が含まれており、また afm ファイルから 生成されたリゲチャのリストを拡張するための拡張リゲチャが含まれています。

encodingnull または空文字列とすることも可能で、 その場合はデフォルトエンコーディング(TeXBase1)が用いられます。

encoding が builtin と指定された場合は、 エンコード処理は行われずにフォント固有のエンコーディングがそのまま用いられます。 これは、記号フォントを扱う場合に便利です。

embed

0 より大きい値を設定すると、フォントがドキュメントに埋め込まれます。 これを使用するには、フォントのアウトライン (.pfb ファイル) が必要です。

戻り値

成功した場合にフォントの ID を、失敗した場合にゼロを返します。 ID は正の数値です。

参考

add a note add a note

User Contributed Notes 4 notes

up
1
zeldorblat at gmail dot com
18 years ago
I found that my Postscript files were taking an incredibly long time to generate and the file sizes were abnormally large.  The problem was that, everytime I chose to set a font I would call ps_findfont() followed by ps_setfont().

It seems that every time ps_findfont() is called, the font gets embedded in the file.  To prevent this, I keep an array of fonts I've already loaded, keyed by the font name.  When I go to set the font, I first check this array to see if I've already loaded the font, and, if so, return the resource handle from that array.  Otherwise, I call ps_findfont() and store the handle in the array.

Note that, if your call to ps_findfont() occurs while inside a page, the font will not be available on other pages.  To get around this I just clear out the array at the end of each page.

My PS file went from 10 M to 75 K, and the time to create the file went from around 15 seconds to less than 1 second.
up
1
yarych at bigmir dot net
16 years ago
I've found out that pslib is searching for fonts in its data dir (/usr/share/pslib). There is no way to change the search path now.
up
1
pepe at dexef dot hu
17 years ago
I found out that you must copy the <fontname>.afm files next to your php because it's searched there in default.
up
0
yarych at bigmir dot net
15 years ago
Ok, now I found the way to set the path I need for fonts - before calling ps_findfont() make a call like this:
<?php ps_set_parameter($psdoc, 'SearchPath', $fonts_dir); ?>

It works for pslib 0.4.1 version. (Looks like it didn't work in some earlier versions.)
To Top