Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add custom fonts #99

Open
iam-amanxz opened this issue Nov 29, 2022 · 2 comments
Open

How to add custom fonts #99

iam-amanxz opened this issue Nov 29, 2022 · 2 comments

Comments

@iam-amanxz
Copy link

How can I register custom fonts to the toolbar?

I am trying to import fonts as follows but I can't seem to get this working. However, the font sizes are registering correctly. What am I missing?

image

@kalmahik
Copy link

How can I register custom fonts to the toolbar?

I am trying to import fonts as follows but I can't seem to get this working. However, the font sizes are registering correctly. What am I missing?

image

Hello! I think I have the same(
Were you able to change font size?
Thx!

@kalmahik
Copy link

kalmahik commented Jul 11, 2024

I finally did it!

<QuillEditor
  ...
  defaultFontFamily={customFonts[0].name}
  customFonts={customFonts}
/>

const ABCMarfaRegularFontFace = `
@font-face {
  font-family: 'ABCMarfa';
  src: url('data:font/ttf;charset=utf-8;base64,${ABCMarfaRegularBase64}') format('opentype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}`;

const ABCMarfaBoldFontFace = `
@font-face {
  font-family: 'ABCMarfa';
  src: url('data:font/otf;charset=utf-8;base64,${ABCMarfaBoldBase64}') format('opentype');
  font-weight: bold;
  font-style: normal;
  font-display: swap;
}`;

const customFonts = [
  {
    name: 'ABCMarfa',
    css: ABCMarfaBoldFontFace,
  },
  {
    name: 'ABCMarfa',
    css: ABCMarfaRegularFontFace,
  },
];

Where is ABCMarfaRegularBase64 just base64 string generated from the font file

To have correct bold font on iOS, the font name and font-family should be the same, but font-weight should be different.
I can't make it work without base64, using otf/ttf file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants