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

Monospaced fonts are not selected with "font-family: monospace" #67

Closed
szpak opened this issue Sep 23, 2016 · 16 comments
Closed

Monospaced fonts are not selected with "font-family: monospace" #67

szpak opened this issue Sep 23, 2016 · 16 comments

Comments

@szpak
Copy link

szpak commented Sep 23, 2016

It's great that in 1.0.0 text is properly kept in PDF (#3), however I discovered an issue with monospaced fonts rendering (a variable-width font is used) . It is especially problematic with source code. The following presentation fragment in remark.js (0.12) has been rendered with old decktape and 1.0.0 (attached).

# Power Assertions - basic case

 - reused Java `assert` keyword

```groovy
assert (2 + 3) * 4 != (2 * 4) + (3 * 4)
```

--
 - self explaining reason of failure

```groovy
Assertion failed:

assert (2 + 3) * 4 != (2 * 4) + (3 * 4)
          |    |   |     |    |    |
          5    20  false 8    20   12
```

In a case there would be a problem with reproduce that issue I can provide complete example.

@szpak szpak closed this as completed Sep 23, 2016
@szpak szpak reopened this Sep 23, 2016
@szpak szpak closed this as completed Sep 23, 2016
@szpak szpak reopened this Sep 23, 2016
@szpak
Copy link
Author

szpak commented Sep 23, 2016

@astefanutti
Copy link
Owner

What exact OS do you use?

I've exported default remark.js presentation using the Docker image (Debian 8) and it seems monospaced text renders correctly - test.pdf - though that's a Web font being used.

I've noticed that for local font family, results may vary depending on the distribution. It looks like the font used in fixed-1-0-0.pdf that gets picked up is not monospaced.

@szpak
Copy link
Author

szpak commented Sep 23, 2016

I've been using Docker image of 1.0.0.

@szpak
Copy link
Author

szpak commented Sep 23, 2016

Btw, there is something strange with font inside source code in test.pdf. E.g. on a page 15 the top of the question marks are not fully visible.

@szpak
Copy link
Author

szpak commented Sep 23, 2016

Maybe in my case there is a problem with used font. I will prepare a small presentation reproducing the problem.

@astefanutti
Copy link
Owner

Btw, there is something strange with font inside source code in test.pdf. E.g. on a page 15 the top of the question marks are not fully visible.

Slide 15 of test.pdf renders exactly as the original for me (Preview reader on Mac OS X). That would indicate a difference at the level of the PDF reader.

Maybe in my case there is a problem with used font. I will prepare a small presentation reproducing the problem.

Great, I'll wait for that and investigate. I've already noticed that local monospaced font may render differently from a distribution to another. So lets find out what's going on...

@szpak
Copy link
Author

szpak commented Sep 23, 2016

I dig a little bit and it turned out that the mentioned effect occurs in the situation where there is no font explicitly defined to handle text formatted as code (i.e. just "font-family: monospace" for given CSS class is not enough). When the font is defined explicitly the rendering works fine.

In general it is a good idea to have a concrete monospaced font defined (see your issues with the official remark presentation on MacOS), however, I wonder why QT doesn't fallback to default monospaced font installed in the system? Maybe there is non in the Debian image (such as Deja Vu)?

Sample code to reproduce the issue (tested with the Docker image). Uncomment the style definition to "fix" the issue:

<!DOCTYPE html>
<html>
<head>
    <title>7 reasons why bother learning Spock</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<!--
    <link href="https://fonts.googleapis.com/css?family=Roboto+Mono:400,400i,700,700i&subset=latin-ext" rel="stylesheet">
    <style type="text/css">
        code { font-family: 'Roboto Mono', monospace; }
    </style>
-->
</head>
<body>
    <textarea id="source">

# Power Assertions - basic case

 - reused Java `assert` keyword

```groovy
assert (2 + 3) * 4 != (2 * 4) + (3 * 4)
```

 - self explaining reason of failure

```groovy
Assertion failed:

assert (2 + 3) * 4 != (2 * 4) + (3 * 4)
          |    |   |     |    |    |
          5    20  false 8    20   12
```

    </textarea>
    <script src="js/remark-0.12.min.js" type="text/javascript">
    </script>
    <script type="text/javascript">
      var slideshow = remark.create({
        highlightStyle: 'idea',
        highlightLines: 'true',
        highlightSpans: 'true',
        ratio: '16:9',
        slideNumberFormat: ''
      });
    </script>
  </body>
</html>

@astefanutti
Copy link
Owner

"Deja Vu Sans Mono" seems to be already installed on the Docker image. By installing fontconfig and running:

# fc-match monospace
DejaVuSansMono.ttf: "DejaVu Sans Mono" "Book"

It seems that "DejaVu Sans Mono" correctly resolves for monospace.

A quick search into PhantomJS issue tracker leads to ariya/phantomjs#11764 and ariya/phantomjs#11468. I haven't yet dig into these though that may be a start.

@astefanutti astefanutti changed the title Monospaced fonts rendering issue with 1.0.0 Monospaced fonts rendering issue on Linux Sep 26, 2016
@astefanutti astefanutti changed the title Monospaced fonts rendering issue on Linux Monospaced fonts are not selected with "font-family: monospace" Sep 29, 2016
@astefanutti astefanutti removed the Linux label Sep 29, 2016
@astefanutti
Copy link
Owner

FWIW, I can reproduce it with the default reveal.js presentation on Mac OS X.

@astefanutti
Copy link
Owner

astefanutti commented Sep 29, 2016

With the minimal test case test.html hereafter:

<html>
<head>
<title>title</title>
</head>
<style>
    body {
        font-family: monospace
    }
</style>
<body>
    <div>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    </div>

</body>
</html>

Running phantomjs-osx-cocoa-x86-64 examples/rasterize.js test.html test.pdf with the pre 1.0.0 Mac OS X binary produces
test.pdf.

Running phantomjs-osx-cocoa-x86-64 examples/rasterize.js test.html test-1.0.0.pdf with the 1.0.0 Mac OS X binary produces
test-1.0.0.pdf.

So it's a regression introduced between astefanutti/phantomjs@cc06f44 and astefanutti/phantomjs@9462bc2. There has been the upgrade to Qt 5.6 in between. Hopefully that'll help narrowing down the analysis.

@astefanutti
Copy link
Owner

astefanutti commented Jan 27, 2017

Following-up on #79, I've just tried with an updated Docker image, having the ttf-mscorefonts-installer package installed in addition, and exporting an HTML page with some text styled with font-family: 'Georgia' produces a correct result. In that case, the Georgia.ttf font resolves:

$ fc-match 'Georgia'
Georgia.ttf: "Georgia" "Normal"

However, with font-family: serif it fails, using a sans-serif style font to render the text in the PDF. In that case:

$ fc-match serif    
DejaVuSerif.ttf: "DejaVu Serif" "Book"

So I suspect it happens whenever a generic font family is used (monospace, serif, sans-serif, ...), where it fails to pick the correct font, as resolved by Fontconfig, irrespective of the already present fonts in the image:

$ fc-list
/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf: DejaVu Serif:style=Bold
/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf: DejaVu Sans Mono:style=Book
/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf: DejaVu Sans:style=Book
/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf: DejaVu Sans:style=Bold
/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf: DejaVu Sans Mono:style=Bold
/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf: DejaVu Serif:style=Book

@wrzasa
Copy link

wrzasa commented Mar 20, 2017

Is there a quick workaround?

@astefanutti
Copy link
Owner

@wrzasa if you can easily change your CSS style, one alternative is to specify the font name directly instead of the font family.

@wrzasa
Copy link

wrzasa commented Mar 20, 2017

Thank you very much! Very helpful!

@wrzasa
Copy link

wrzasa commented Mar 20, 2017

For anyone looking for quick workaround, this worked for me:

.reveal code {
  font-family: "DejaVu Sans Mono";
}

@astefanutti
Copy link
Owner

Should be fixed in version 2.0.1 that uses headless Chrome. Let me know if you still face this issue.

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

No branches or pull requests

3 participants