Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bold / Italic doesn't work on custom fonts using PhantomJS

When I try to render a custom font with phantomJS, the bold and italic tags don't work / are not applied.

All my CSS is directly in the HTML template in the <head> in a <style> tag.

Here is what I have:

@font-face {
    font-family: userSelectedFont;
    src: url("/usr/share/fonts/dejavu/DejaVuSerif.ttf");
}

And then in my <body>:

<div style="font-family: userSelectedFont, sans-serif;"><strong><em>Test</em></strong></div>

But phantomJS generates this image: Good font but not in bold or italic

It's definitely using the good font but not applying bold and italic. Any idea ?

PS: If I delete the style="font-family: userSelectedFont-7, sans-serif;" part it works fine in bold and italic...

like image 466
Vincent Audebert Avatar asked Feb 14 '23 19:02

Vincent Audebert


2 Answers

I just found the solution. You need to provide a font-style and a font-weight to your font-face

Here is my final code:

@font-face {
    font-family: 'userSelectedFont';
    font-style: normal;
    font-weight: normal;
    src: url("/usr/share/fonts/dejavu/DejaVuSerif.ttf");
}
like image 179
Vincent Audebert Avatar answered Apr 01 '23 14:04

Vincent Audebert


I have been able to solve this problem in PhantomJS 2.x with CSS:

strong, b {font-weight: normal; -webkit-text-stroke: 0.05em;}

I apply a stroke to the font, which makes it look bold.

like image 33
Gerfried Avatar answered Apr 01 '23 13:04

Gerfried