react-pdf-builder
Version:
Build beautiful PDF documents in React.
167 lines (166 loc) • 6.68 kB
TypeScript
import { FontWeight } from '@react-pdf/types';
/** Matches font loading interface expected by React-PDF */
export interface BulkLoad {
family: string;
fonts: {
src: string;
fontStyle?: string;
fontWeight?: FontWeight;
}[];
}
export interface FontFilesDefinition {
type: string;
dir: string;
family: string;
fonts: {
filename: string;
fontStyle?: string;
fontWeight?: FontWeight;
}[];
}
/**
* Defines font files for commonly used modern fonts.
*/
export declare const fontDefinitions: FontFilesDefinition[];
/**
* Allows drop-in support for common font families. See documentation for `Fonts.load()` for more info.
*
* Read more about [fonts in React PDF Builder here](https://justinmahar.github.io/react-pdf-builder/?path=/docs/documentation-fonts--docs).
*
* You can download TTF and WOFF fonts here: https://gwfh.mranftl.com/fonts
*
* For additional font support, see https://react-pdf.org/fonts
*/
export declare class Fonts {
static mono: {
courierPrime: string;
dmMono: string;
jetbrainsMono: string;
robotoMono: string;
sourceCodePro: string;
spaceMono: string;
ubuntuMono: string;
};
static sansSerif: {
inter: string;
lato: string;
montserrat: string;
notoSans: string;
openSans: string;
poppins: string;
raleway: string;
robotoCondensed: string;
roboto: string;
};
static serif: {
bitter: string;
crimsonText: string;
ebGaramond: string;
libreBaskerville: string;
lora: string;
merriweather: string;
notoSerif: string;
playfairDisplay: string;
ptSerif: string;
};
static emojis: {
/**
* Twemoji emoji source that can be passed into `Font.registerEmojiSource()`.
*
* Emoji source GitHub project: https://github.com/twitter/twemoji
*
* @param size Default `72`.
* @param version Version string. Default `14.0.2`. See all releases here: https://github.com/twitter/twemoji/releases
*/
twemoji: (size?: number, version?: string) => {
format: string;
url: string;
};
/**
* JoyPixels emoji source that can be passed into `Font.registerEmojiSource()`.
*
* Emoji source GitHub project: https://github.com/joypixels/emoji-toolkit
*
* @param size `32` or `64`. Default `64`.
* @param version Version string. Default `9.0`. See all releases here: https://github.com/joypixels/emoji-toolkit/releases
*/
joyPixels: (size?: number, version?: string) => {
format: string;
url: string;
};
/**
* OpenMoji Color emoji source that can be passed into `Font.registerEmojiSource()`.
*
* Emoji source GitHub project: https://github.com/hfg-gmuend/openmoji
*
* @param size `72` or `618`. Default `72`.
* @param version Version string. Default `15.1.0`. See all version tags here: https://github.com/hfg-gmuend/openmoji/releases
*/
openMojiColor: (size?: number, version?: string) => {
format: string;
builder: (code: string) => string;
};
/**
* OpenMoji Black emoji source that can be passed into `Font.registerEmojiSource()`.
*
* Emoji source GitHub project: https://github.com/hfg-gmuend/openmoji
*
* @param size `72` or `618`. Default `72`.
* @param version Version string. Default `15.1.0`. See all version tags here: https://github.com/hfg-gmuend/openmoji/releases
*/
openMojiBlack: (size?: number, version?: string) => {
format: string;
builder: (code: string) => string;
};
/**
* NotoEmoji emoji source that can be passed into `Font.registerEmojiSource()`.
*
* Emoji source GitHub project: https://github.com/googlefonts/noto-emoji
*
* @param size `32`, `72`, `128`, or `512`. Default `72`.
* @param version Version string. Default `v2.047`. See all versions tags here: https://github.com/googlefonts/noto-emoji/releases
*/
notoEmoji: (size?: number, version?: string) => {
format: string;
builder: (code: string) => string;
};
};
/**
* Constructs a BulkLoad object compatible with React PDF for the provided font family, specifying all font files
* required for Latin support with bold and italics (if available for the font).
* Pass the returned BulkLoad object to `Font.register()`.
*
* All supported font family names are defined in Fonts, such as `Fonts.sansSerif.roboto`.
*
* By default, the fonts are loaded from cdn.jsdelivr.net, allowing you to drop in
* font support very quickly. However, you may want to self-host the font files at some point. As such, you can
* provide the `fontsDirUrl` prop pointing to the root path where your font files are located, and the fonts will
* be loaded from there instead. The expected font files for each family can be found in the
* [project repo](https://github.com/justinmahar/react-pdf-builder/tree/master/public/fonts).
*
* Read more about [fonts in React PDF Builder here](https://justinmahar.github.io/react-pdf-builder/?path=/docs/documentation-fonts--docs).
*
* You can download TTF and WOFF fonts here: https://gwfh.mranftl.com/fonts
*
* For additional font support, see https://react-pdf.org/fonts
*
* @param fontFamily The name of the font family to load, defined by `Fonts`.
* @param fontsDirUrl Optional. URL path where font files are located. Otherwise, fonts will be loaded from cdn.jsdelivr.net.
* @returns A BulkLoad compatible with React PDF, that can be passed into `Font.register()`
*/
static load: (fontFamily: string, fontsDirUrl?: string) => BulkLoad;
/**
* To disable word hyphenation, pass this function into `Font.registerHyphenationCallback()`.
*
* Pass the actual function (do not call it), like so:
*
* ```
* Font.registerHyphenationCallback(Fonts.noHyphenation);
* ```
*
* Read more about [fonts in React PDF Builder here](https://justinmahar.github.io/react-pdf-builder/?path=/docs/documentation-fonts--docs).
*
* Read even more here: https://react-pdf.org/fonts#registerhyphenationcallback
*/
static noHyphenation: (word: string) => string[];
}