arachnys / athenapdf

Drop-in replacement for wkhtmltopdf built on Go, Electron and Docker
MIT License
2.26k stars 186 forks source link

Problem loading fonts #117

Open AliKamil opened 7 years ago

AliKamil commented 7 years ago

Testcase to reproduce the issue:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <style type="text/css">
        @import url('https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic&subset=latin');
        body {
          font-family: 'Lato', sans-serif ;
        }

        @media screen {
            [class*="printer only"] {
            display: none;
            }
        }

    </style>    
</head>
<body>

    Remove this text and the text below will ALSO disappear

    <div class="printer only" style="border: solid 1px red">
        This is the test string that should show up when printing
    </div>  
</body>
</html>

If font is not used outside of printer only block - it cannot be used from within either.

Can anyone suggest something on that matter?

MrSaints commented 7 years ago

Change printer only to print-only (sorry, I just want to isolate the problem).

AliKamil commented 7 years ago

I can do this in example to avoid confusion, but that doesn't fix an issue.

MrSaints commented 7 years ago

Interesting, can you try running it with a delay of 1s (-D 1000) ? I was able to replicate this on the latest v3 too.

AliKamil commented 7 years ago

Delay (1s or bigger) doesn't affect this issue at all.

lauri-elevant commented 7 years ago

If you add a <b>test</b> to the printer only tag, it will also not show up, unless you also add <b>foobar</b> into the body tag, outside of the printer only div. Also the same with some accented characters like Ł.

The cause seems to be that Electron can only draw fonts (or variants of it) that have been "required" outside of the printer only tag. If a bold variant of the font was not already used outside of the div, it will not be available.

Curiously enough, adding the accented character into the printer only div will make even the text outside disappear.

MrSaints commented 7 years ago

Okay, this is not a problem on v3 if a delay is set (~1s).