Fonts Whose Letters Cost One Byte
Make a font reached by one-byte codes fitted to the text you will actually draw: a lighter page, and a word space that has a code of its own.
See It in a Real PDF
A Page Whose Letters Cost One Byte Each
The same three lines written twice over — the ordinary way, then with each letter kept as a single byte — and the page states what each of the two came to. The short way also lets the space between the words of a line be set, which the ordinary way does not.
Open the PDF The Whole Example
Also shown in: Prices Crossed out, a Shadow behind the Title
Summary
Inside a PDF, every letter drawn on a page is written as a number, and normally that number takes two bytes. If you say in advance which letters your document will use — and a document uses far fewer than a font holds — each of them can be given a small number that fits in one byte instead. The second gain is less obvious: the setting that pushes words apart to justify a paragraph works on the code of the space, and that code only exists in this shape.
Technically
Written at the top level of a request, under
"simple_fonts"
simple_fonts builds, from a font already declared, a one-byte /Subtype /TrueType simple font items reach by codes rather than by glyph index. fitted_to is the text the /Differences encoding is fitted to: every character of it the font can draw is given a code, the space keeping 32 and the rest taking the lowest free code from 33 up, in the order they are met. A character that text leaves out is one the font cannot draw, so the string must hold every letter, accent and sign the document will show through that name. The source has to be a font with a file behind it — one the request embeds, one of the client's own, one from the font store — and never one of the fourteen standard fonts, which travel outside the document and so have nothing to recode. Two gains follow: a letter costs one byte of page stream instead of two, and word spacing has a code to reach — under two-byte codes the setting that widens the blank has no effect at all.
Request Schema
-
simple_fonts— array, optional, empty by default. -
simple_fonts[].name— string, required. The name items draw with this font by. -
simple_fonts[].from— string, required. The name of the font it is made from: one the request embeds infonts, one from the font store. Never one ofstandard_fonts: those fourteen fonts travel outside the file, so there is no file to give one-byte codes to. -
simple_fonts[].fitted_to— string, optional. The text the codes are fitted to. Every character of it the font can draw takes a code, the space keeping 32 and the rest taking the lowest free code from 33 up; a character it leaves out cannot be drawn through this name. Never stated besidecode_pageorslots. -
simple_fonts[].code_page— string, optional. A table of one-byte codes reading software already knows, named by its standard; a character it has no code for cannot be drawn through this name. Absent, andfitted_toabsent too, every code is free but the space at 32. Thirty values:win_ansi, the Windows code page the twelve text faces of the standard fourteen are reached through;standard, the one a PostScript program falls back on;pdf_doc, the one the strings outside a page's text are written in; the parts of ISO 8859,iso8859_1,iso8859_2,iso8859_3,iso8859_4,iso8859_5,iso8859_6,iso8859_7,iso8859_8,iso8859_9,iso8859_10,iso8859_11,iso8859_13,iso8859_14,iso8859_15andiso8859_16; the Windows code pageswindows874,windows1250,windows1251,windows1253,windows1254,windows1255,windows1256,windows1257andwindows1258;mac_roman; andibm037andibm500, two EBCDIC pages whose space sits at 64, where word spacing has no code to reach. -
simple_fonts[].slots— array, optional, empty by default. Characters set at codes of your own choosing, over the code page or over free codes, each an object ofcode, an integer from 1 to 255 other than 32, andcharacter, a string of one character. Each is one entry the document writes out; code 0, code 32 and a code named twice are refused.
Scope: the name declared, and it alone. The font it is made from stays reachable under its own name, unchanged. A document may carry both, and an item picks whichever it names.
A Whole Request That Creates a PDF
One name below stands for a font file: put the encoded file in its place, or send the file itself beside the description, as a supplied part of the same call. One page carries a real font already encoded, and its request posts as it stands.
{
"fonts": [{ "name": "body", "data": "PASTE_THE_FONT_FILE_BASE64_HERE" }],
"simple_fonts": [
{
"name": "coded",
"from": "body",
"fitted_to": "One byte a letter, and the file says which."
},
{ "name": "latin", "from": "body", "code_page": "win_ansi" }
],
"items": [
{
"type": "text",
"rect": { "llx": 72, "lly": 700, "urx": 523, "ury": 740 },
"content": ["One byte a letter"],
"font": "coded",
"font_size": 18
},
{
"type": "text",
"rect": { "llx": 72, "lly": 650, "urx": 523, "ury": 690 },
"content": ["One byte a letter"],
"font": "latin",
"font_size": 18
}
]
}
The fonts
Carrying a Font inside the Document The Older Type 1 Font Programs The Fourteen Fonts All Reading Software Owns The Typographic Niceties of a Font A Font Whose Letters You Draw Yourself A Backup Font for the Rarer Signs Fonts Whose Signs Come Out in Colour Fonts the Document Names without Carrying A Font Whose Makers Forbid Carrying It Fonts Carried Whole
Where to Go Next
Every JSON key of a request, in one page The other forty-one settings of a request