1.9 KiB
Fonts
Both text paths draw with fonts installed on the machine. Discover what is available with dapi fonts (filter by family, weight, or style); the active project's families are also on dapi context as fontFamilies. macOS resolves these families for both the native renderer and the browser, so there is nothing to bundle or load.
Native <text>
Name a family on the <text> element with fontFamily; pick the variant with fontWeight and fontStyle. The value must be a family present in dapi fonts; an unknown family falls back to the editor default.
<text fontFamily="Inter" fontWeight={700} fontSize={128} textAlign="center" textBaseline="middle">
Hello World
</text>
HTML
In <html> you style text with ordinary CSS, so use a locally installed font and name it directly. The browser resolves the family from the OS:
<html width={700} height={110}>
<div style="font:500 40px Inter;color:#fff;">Introduction</div>
</html>
Remote web fonts do not work: a Google Fonts <link> or an @font-face with a url() source is a cross-origin subresource, and those are excluded from the painted read-back (the same rule that drops remote images, see html.md). The glyphs would render on screen but come out blank in dapi node capture and exports. Stay on families from dapi fonts.
If you want to pin an exact variant, declare an @font-face whose source is the CSS local() string that dapi fonts reports for that variant (never a url()):
<html width={700} height={110}>
<style>{`
@font-face {
font-family: "Inter Display";
font-weight: 700;
src: local('Inter Display Bold'), local('Inter-DisplayBold');
}
`}</style>
<div style="font:700 40px 'Inter Display';color:#fff;">Introduction</div>
</html>