Fonts
The code on this page is React’s. How Vue writes it
| React | Vue | |
|---|---|---|
| Classes | className="p-4" | class="p-4" |
| Props | headerRows={1} | :header-rows="1" or :headerRows="1" |
A prop that is true | hyphenate | hyphenate |
| Content per page | render={({ pageNumber }) => …} | <template #render="{ pageNumber, totalPages }">…</template> |
| The page, deeper down | usePage() | usePage() (it injects the page) |
| What to render | <Invoice invoice={invoice} /> | h(Invoice, { invoice }) |
A template for generate | Template: ComponentType<{ data }> | Template: a component with the prop data |
The rest, and Vue’s own API, is in the Vue guide.
The code on this page is React’s. How Svelte writes it
| React | Svelte | |
|---|---|---|
| Classes | className="p-4" | class="p-4" (a list or an object of flags too) |
| Content per page | render={({ pageNumber }) => …} | {#snippet render(page)}{page.pageNumber}{/snippet} inside the Text or View |
| The page, deeper down | usePage() | usePage(), while the component is created |
| What to render | <Invoice invoice={invoice} /> | { component: Invoice, props: { invoice } } |
A template for generate | Template: ComponentType<{ data }> | Template: a component with the prop data |
The rest, and Svelte’s own API, is in the Svelte guide.
The code on this page is React’s. How Angular writes it
| React | Angular | |
|---|---|---|
| Components | <View>, <Path>, <TextField> | <ink-view>, <ink-path>, <ink-text-field>: ink- and the name in kebab case |
| Classes | className="p-4" | class="p-4", [class]="…" |
| Props | headerRows={1}, size="A4" | [headerRows]="1", size="A4" (an attribute is a string: bind numbers) |
A prop that is true | hyphenate | hyphenate |
| Style | style={{ padding: 20 }} | [style]="{ padding: 20 }"; [inkStyle] for @media blocks and lists of styles |
| Content per page | render={({ pageNumber }) => …} | [render]="footer" with <ng-template #footer let-page>{{ page.pageNumber }}</ng-template> |
| The page, deeper down | usePage() | injectPage() |
| What to render | <Invoice invoice={invoice} /> | { component: Invoice, inputs: { invoice } } |
A template for generate | Template: ComponentType<{ data }> | Template: a component with the input data |
The rest, and Angular’s own API, is in the Angular guide.
Four families ship with the package, so nothing needs registering:
| Family | Faces | Use it with |
|---|---|---|
| Inter | regular, italic, bold | the default (font-sans) |
| Inter Display | bold | font-display, for large headings |
| Roboto Mono | regular | font-mono |
| Noto Sans | regular | automatic, for characters Inter lacks (fallbackFonts) |
font-semibold and other weights without a face of their own use the nearest one (bold), as in
CSS.
No serif face ships with the package, so font-serif sets Noto Sans. For serif text, register
a serif family and use it with fontFamily or font-[…], or set --font-serif in the theme you
pass to initTailwind({ css }) from @inkoxide/tailwind.
Add your own fonts with Font.register:
import { Font } from '@inkoxide/react';
Font.register({ family: 'Lora', src: './fonts/Lora-Regular.ttf' });
Font.register({
family: 'Source Serif',
fonts: [
{ src: './fonts/SourceSerif-Regular.ttf' },
{ src: './fonts/SourceSerif-Bold.ttf', fontWeight: 'bold' },
{ src: 'https://example.com/fonts/SourceSerif-Italic.ttf', fontStyle: 'italic' },
],
});
Then use it with style={{ fontFamily: 'Lora' }}, or with className="font-[Lora]".
-
Sources.
srcis a file path, afile:,https:orhttp:URL, the bytes (Uint8ArrayorArrayBuffer), or aBlob, such as aFilethe user picked (read before the next render, as a path is). Preferhttps:: a font fetched overhttp:can be changed on the way. Formats are TrueType (.ttf), OpenType (.otf), WOFF (.woff) and WOFF2 (.woff2). Font collections (.ttc) are not supported: register each font as its own file. -
Loading.
registeris synchronous. The file is read or fetched just before the next render, and a font that cannot be loaded fails that render withINVALID_FONT. The fonts registered with it still load, and later renders can use them. The face that failed is then dropped, and is not tried again: later renders succeed, and text in it falls back as for a face never registered (to the nearest face of its family, else toInter), with only a warning in thewarningsofgenerate. Register it again, from the same source or another, to try once more. To refuse to render without it, load your fonts at startup withawait init()and stop when it throws. A URL is fetched with a 30-second limit for the whole download and a 50 MiB size limit, and redirects are followed; renders wait for it, so for a font over that size or from a slow host, read the bytes yourself and register them. -
Weights. Weights are numbers (1–1000, as in CSS) or names (
'light','medium','bold'). Missing weights and styles fall back to the nearest one, as in CSS. -
Widths.
fontStretchpicks a face by width, a percentage of the normal one (75,'75%') or a CSS keyword ('condensed','expanded'), in a style, inFont.registerand on SVG text (font-stretch-condensedin Tailwind). A face registered without one is 100%. CSS matches the width before the style and the weight: at 100% or less the nearest narrower face first, above it the nearest wider. -
Variable fonts. Register a variable font with the range of weights it covers, as CSS
@font-facedoes:Font.register({ family: 'Inter Var', src: './fonts/InterVariable.ttf', fontWeight: [100, 900] }); Font.register({ family: 'Inter Var', src: './fonts/InterVariable-Italic.ttf', fontWeight: [100, 900], fontStyle: 'italic', });Each weight in the range draws at that
wght(fontWeight: 450is the 450 instance), and a weight outside it at the nearer end. A range of widths,fontStretch: [75, 100], draws each width in it at thatwdththe same way. A font with anopszaxis draws text at the optical size of its font size, as CSSfont-optical-sizing: autodoes; anopszinfontVariationSettingssets it instead.fontVariationSettingssets other axes, as in CSS:"'wdth' 75, 'opsz' 32"or{ wdth: 75 }, inherited like other text styles; itswghtwins overfontWeight, and on a face registered with one weight it picks an instance too. A face can takefontVariationSettingsinFont.register({ ital: 1 }), so one file can be the italic as well. Each combination a document uses is a static instance, embedded as TrueType (CFF2 outlines too), so viewers show exactly what was laid out. TrueType (gvar) and CFF2 variable fonts work; one with more than 63 axes or anavartable other than version 1.0 is refused when it loads. A document uses at most 64 instances picked by a weight, a width orfontVariationSettings(OUT_OF_RANGEatfonts). Optical sizes add at most 64 instances to each face or instance, and 1024 to a document; text at a size past them draws at its face's own. Text in an<Svg>takes the nearest instance the document declares. -
Colour emoji. Register a colour emoji font, such as Noto Color Emoji, and list it in
fallbackFonts:Font.register({ family: 'Noto Color Emoji', src: './fonts/Noto-COLRv1.ttf' }); <Document fallbackFonts={['NotoSans-Regular', 'Noto-Color-Emoji-400']}>…</Document>An emoji (
😀,❤️, a flag, a keycap, a skin tone, a sequence such as👩💻) goes to the first colour font infallbackFontsthat has it, then to the run's font, then to the other fallbacks. Followed by U+FE0E (text presentation), or as a character that is text by default (❤,©), it is text like any other. Colour glyphs come from the font'sCOLRtable (versions 0 and 1, with their gradients, sweeps and blend modes), itsSVGtable or its PNG bitmaps (CBDT, as in Noto Color Emoji's bitmap build, orsbix); a font with bitmaps and no outlines works too, but cannot be a form field's font. They are drawn as the glyphs of Type 3 fonts, so each glyph's image is in the PDF once, and copy and search as their text.COLRlayers in the foreground colour, andSVGglyphs incurrentColororcontext-fill, take the run'scolor, as in browsers (in the text of an SVG image, black); the colour's alpha fades the whole glyph. A colour glyph that is malformed or takes too much work to draw (over 10 000 drawing steps) draws without colour, and so do colour glyphs past the first 4096 of a render (one that takes the run's colour counts once per colour) or its first 32 MB of colour glyph images. In a font with bitmaps and no outlines, which has nothing else to draw them with, such glyphs are not drawn, but they still copy and search as their text. PDF/A-1b forbids transparency: there, a colour glyph that needs it (a bitmap with an alpha channel, as in every emoji bitmap font, or a layer with an opacity) fails the render withPDFA_CONFLICTat the path of its run (at thesrcof an SVG whose text has it), and inline images and emoji images that need it fail it at theirsrcoremojiImageskey. OpaqueCOLRglyphs draw in colour there. -
Emoji from images.
Font.registerEmojiSourcedraws emoji from an image set instead:{ url, format }adds each emoji's code points and the format to the URL (https://cdn.example.com/emoji/1f469-200d-1f4bb.png;withVariationSelectors: truekeepsfe0fin them), and{ builder }turns the code points into any imagesrc. The images load like<Image src>: a URL must be allowed byremoteImages(else the render fails, naming the emoji), a path needslocalImages, and images fetched from URLs are kept between renders (16 MB of them, each render still holding them to its ownremoteImages.maxBytes). An emoji image is 1em high with its aspect ratio, its bottom 0.1em below the baseline (raised or lowered with the text byverticalAlign: 'super'or'sub'), and copies as the emoji. An emoji whose image cannot be loaded, or is not an image the engine can draw (other bytes, an image over the size limits), is drawn by the fonts, with a warning; a ZWJ sequence (👩💻) without an image of its own uses the images of its parts.nullremoves the source.Font.registerEmojiSource({ url: 'https://cdn.example.com/emoji/72x72/', format: 'png' }); -
Faces. A face is a family, a weight and a style. Registering one again from the same source (the same path, URL, bytes or
Blobobject) does nothing, and from another source throws; two differentBlobs are different sources, even with the same bytes. A face the bundled fonts have (Inter400) cannot be replaced: register your build under another family name. You can add the faces they lack, such asInterbold italic. Two family names that differ only in spaces and hyphens (Brand Two,Brand-Two) give the same font id to faces of the same weight and style, so such a face cannot be registered under both:Brand Two400 andBrand-Two400 throw,Brand Two400 andBrand-Two700 do not.
Synced from packages/react/GUIDE.md in the inkoxide repository.