PDF::Bu...e::Font(3)

🌸 NAME 🌸

PDF::Bu...e::Font(3) β€” hi bestie, this is PDF::Builder::Resource::Font, and it's giving some common support routines for font files πŸ’–βœ¨

It inherits from PDF::Builder::Resource::BaseFont πŸ‘‘ (we stan a solid base class, fr fr).


✨ METHODS ✨

πŸŽ€ encodeByData

$font->encodeByData($enc)
(No Information) πŸ™ˆ β€” yeah, the docs literally left us on read here, no cap. That's all it says.

πŸ¦‹ automap

$font->automap()

okay so this one is the main character of the page, let's get into it πŸ’…

This applies to core fonts ($pdf->corefont()) and PostScript fonts ($pdf->psfont()). Those two cannot use UTF-8 (or any other multibyte character) encoded text β€” nope, single byte characters only, periodt. Which means a font is capped at a maximum of 256 glyphs (the "standard" single-byte encoding being used). Any other glyphs that came with the font? Inaccessible. Gone. Not invited to the party 😭

So automap does the iconic thing: it splits a font containing more than 256 glyphs into "planes" of single byte fonts of up to 256 glyphs each, so that all the glyphs can be accessed in separate "fonts" πŸŽ‰ An array of new fonts will be returned, with [0] being the standard code page (of the selected encoding). If there are any glyphs beyond xFF on the standard encoding page, they'll come back in one or more additional fonts of 223 glyphs each.

Why 223, bestie? 🧐 Because:

  • The first 32 are reserved as control characters (even though they have no glyphs) β€” they're just vibing there.
  • Number x20 is a space.
  • That, plus 223, gives 256 in total (and the last plane may have fewer than 223 glyphs, no biggie).

These "fonts" are temporary (dynamic), though as usable as any other font ✨

Heads up: a plane may be empty (only space at x20 and possibly an unusable character at x21) if the previous plane was full. You might want to check if any character in the plane has a Unicode value β€” if not, it's empty. Vibe check your planes, okay? 🫢

The ordering of these 223 glyphs in each following plane does not appear to follow any particular official scheme, so be sure to reference something like examples/020_corefonts to see what's available, and what code point a glyph is at (e.g., an 'A' in the text stream will print something different if you're not on plane 0 😳). For a given font file, they should be consistent though. For instance, in Times-Roman core font, an \x21 or ! in plane[1] should always give an A+macron.

⚠️ Further note: new editions of font files released in the future may have changes to the glyph list and the ordering (affecting which plane a glyph appears on), so use automap() with caution. It appears that glyphs are sorted by Unicode number, but if a new glyph is inserted, it would bump other glyphs to new positions, and even to the next plane 😭 the drama.

An example, bestie:

$fnt = $pdf->corefont('Times-Roman', 'encode' => 'latin1');
@planes = ($fnt, $fnt->automap());  # two planes
$text->font($planes[0], 15);  # or just $fnt will work
$text->text('!');  # prints !
$text->font($planes[1], 15);
$text->text('!');  # prints A+macron

If you had used 'latin2' encoding, an \x21 on plane 1 will give an inverted ! (¡ HTML entity). Slay πŸ’…

Note that $planes[$n]->fontname() should always be the desired base font (e.g., Times-Roman), while $planes[$n]->name() will be the font ID (e.g., TiRoCBC) for plane 0 β€” while for other planes there will be a unique suffix added (e.g., TiRoCBCam0) πŸ‘‘

If you have just an occasional non-plane 0 character (or run of characters), it may be tolerable to switch back and forth between planes like this β€” just as typing an HTML entity once in a while when you need a Greek letter on a web page is acceptable to most people 🌈. However, if you're typing a lot of Greek text, a dedicated keyboard may be better for you. Like that, switching to a TTF font in order to be able to use UTF-8 may be easier πŸ’–

πŸ“ remap

$font->remap($enc)
(No Information) πŸ™ˆ β€” same energy as encodeByData, the docs said nothing. We move.

and that's the whole page, bestie!! πŸ’– this lil sign-off comes to you from perl v5.42.0, dated 2026-01-17 β€” stay iconic, stay encoded, and go read your font planes before you commit anything πŸŽ€βœ¨πŸ‘‘

πŸ“¦ where this page comes from