Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

65
Views
How to use a fallback font with javascript canvas

I would like to know if I can detect if my actual font support all the characters of a string.

For exemple, we can see there that the unsupported characters are filled with Times New Roman, and the normal text is filled with the selected font :

enter image description here

But I would like to first put the whole text with the same font if one character is not supported, and too switch the font with Arial.

Any idea about how can I do it ?

7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

ctx.font uses the same syntax as CSS'sfont shorthand (with the line-height param ignored), so you can specify the fallback fonts the same way as in CSS, i.e by adding multiple font-family values at the end:

ctx.font = "10px 'your font', Arial";
7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs