- First step is to find the font that you want, specifically a
.ttf
file for each style. (bold
,bolditalic
,normal
anditalic
). Save the raw files into the fonts folder for future reference - Upload the 4
.ttf
files to the jsPDF font converter tool- Make sure every file uses the same
fontName
- Select the correct
fontStyle
for each font - Use ES Modules
- Save the result the font folder
- Make sure every file uses the same
- The font doesn't quite match the style that we want so we have to tweak the generated file.
First thing is change them to .ts
files. Then they need to match the following structure:
import { jsPDF } from "jspdf";
var font = "<LONG_FONT_STRING_HERE>";
var callAddFont = function (this: any) {
this.addFileToVFS("OpenDyslexic-bold.ttf", font);
this.addFont("OpenDyslexic-bold.ttf", "OpenDyslexic", "bold");
};
export const initialise = () => {
jsPDF.API.events.push(["addFonts", callAddFont]);
};
- Then once you have created the 4 font TS files you import them into
font.ts
and call the import function. - Add an extra entry to the
FONT_OPTIONS
list infont.ts
so that users can select the new font - Add an attribution to the font in the main README.md
- Add font license in the
fonts
directory
When suggesting a new font make sure its available under an Open License. If the font you want is not available under an Open License, check out Google Fonts for an alternative as they often have Open Source 'reinterpretations' of popular fonts. For example, we don't use Comic Sans, instead we use Comic Neue from Google Fonts.
You can see the license for each font in this folder named <FONT NAME>-LICENSE
Currently the font style and the font are not dependent on each other. This means that we assume all font styles are available in the each font. If we ever add a font that doesn't have bold
, bolditalic
, normal
and italic
then we will have to do some work to make sure the user only selects valid font choices.