PHP 8.1.28 Released!

ps_findfont

(PECL ps >= 1.1.0)

ps_findfontCargar una fuente

Descripción

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

Carga una fuente para su uso posterior. Antes de que un texto se imprima con una fuente cargada, ésta debe establecerse con a la función ps_setfont(). Esta función necesita el fichero de métrica de fuentes de Adobe para poder calcular el espacio utilizado por los caracteres. Una fuente que sea cargada dentro de una página solamente estára disponible en esta página. Las fuentes que van a ser usadas en el documento completo tienen que ser cargadas antes de llamar por primera vez a la función ps_begin_page(). Llamar a la función ps_findfont() entre páginas hará que esa fuente esté disponible para todas las páginas siguientes.

El nombre del fichero afm debe ser nombre_de_fuente.afm. Si la fuente estará embebida, el fichero nombre_de_fuente.pfb que contiene el esquema de la fuente también debe estar presente.

Llamar a la función ps_findfont() antes de la primera página requiere imprimir la cabecera postscript que incluya el campo BoundingBox para el documento entero. Normalmente BoundingBox se establece con la primera llamada a la fucnión ps_begin_page(), que ahora va después de la función ps_findfont(). Por lo tanto, BoundingBox no se ha establecido y se emitirá una advertencia al llamar a la función ps_findfont(). Para prevenir esta situación, se debería llamar a la función ps_set_parameter() para establecer BoundingBox antes de llamar a la función ps_findfont().

Parámetros

psdoc

El identificador de recursos del fichero postscript, como el devuelto por la función ps_new().

fontname

El nombre de la fuente.

encoding

ps_findfont() intentará cargar el fichero pasado al parámetro encoding. Los archivos codificados tienen la misma sintaxis que los utilizados por dvips(1). Contienen un vector de codificación de fuente (que actualmente no se usa pero debe estar presente) y una lista de ligaduras extra para prolongar la lista de ligaduras derivada del fichero afm.

encoding puede ser null o la cadena vacía si se usará la codificación predeterminada (TeXBase1).

Si la codificación se establece a builtin no habrá recodificación y se usará la codificación específica de la fuente. Esto es muy útil con fuentes de símbolos.

embed

Si se establece a un valor >0 la fuente será embebida en el documento. Esto requiere que el esquema de la fuente (fichero .pfb) esté presente.

Valores devueltos

Devuelve el identificador de la fuente, o cero en caso de error. El identificador es un número positivo.

Ver también

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
18 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
16 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