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 word spacing that has a code to reach.
In plain words
Written for anybody. It says what this puts on a sheet of paper, and asks nothing of you beyond that.
Inside a PDF, every letter drawn on a page is written as a number. 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. The page then weighs about half as much for the same text. There is a second gain, 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. So a font declared this way is both lighter and the one a well-justified paragraph needs.
For a developer
Written for somebody who writes the calling program: the model, the units, and the settings that carry the weight.
Written at the top level of a request, under
"simple_fonts"
simple_fonts builds, from a font already declared, a font items reach by one-byte codes rather than by glyph index. fitted_to is the text the codes are fitted to: every character of it the face 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 of the library's — and never one of the fourteen standard faces, 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.
Every key, with its default
The reference: which keys are required, which are optional, what each one defaults to and which combinations the server declines.
-
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 of the client's own, or one of the library's. Never one ofstandard_fonts: those fourteen faces travel outside the file, so there is no file to give one-byte codes to. -
simple_fonts[].fitted_to— string, required. The text the codes are fitted to. Every character of it the face can draw takes a code; a character it leaves out cannot be drawn through this name.
Scope: the name declared, and it alone. The font it is made from stays reachable under its own name, unchanged. A document may hold both, and an item picks whichever it names.
A whole request that draws it
Post this as it stands and a PDF comes back. Nothing has been left out of it.
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 part of the same call.
{
"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."
}
],
"items": [
{
"type": "text",
"rect": { "llx": 72, "lly": 700, "urx": 523, "ury": 740 },
"content": ["One byte a letter"],
"font": "coded",
"font_size": 18
}
]
}
The lettering
Carrying a font inside the document The older Type 1 font programs The fourteen faces every reader owns The typographic niceties of a face A face whose letters you draw yourself A backup face for the rarer signs
Where to go next
Every key of a request, in one page The other thirty-two settings of a request
Glossary
- PDF library
- A piece of software your own programs use to write PDF documents. It has no window and no buttons: your program tells it what to draw, and it hands the finished file back. This site also calls it the engine, which is the same thing under another name. The server is a second program that holds the engine and answers whoever asks it for a document over the network, and the rendering service is that server running on our machines rather than on yours.
- byte
- The unit a file's weight is counted in, the way a parcel is counted in grams. A thousand of them make a kilobyte, and a million make a megabyte — the size of one photograph taken with a telephone. A one-page PDF here weighs between six thousand and a hundred and twenty thousand, so a hundred of them fit in the space of five photographs.
- standard
- A rule argued out in committee, published under a number anybody may buy and read, and identical for every firm claiming it. A claim to follow one can therefore be checked against the text. A way of working that merely spread because it worked is a habit of the trade: useful, widespread, and answerable to no text at all.
- font
- The drawing of every letter, digit and mark a document writes, held in a file of its own. A PDF carries the fonts it is set in inside itself, which is why it opens looking the same on a machine that has never had them. Leave them out and a reader puts another font in their place, and the layout moves.
- glyph
- One drawn shape of a typeface. The letter A is a character; the particular drawing of it that lands on the page is a glyph. The same letter is drawn differently in every typeface.
- request
- One call to the service: you send what the document should say, and get the document back. Your bill counts these calls, one for each document. The number of pages inside a document is never counted.