asciidoctor / asciidoctor-pdf

:page_with_curl: Asciidoctor PDF: A native PDF converter for AsciiDoc based on Asciidoctor and Prawn, written entirely in Ruby.
https://docs.asciidoctor.org/pdf-converter/latest/
MIT License
1.14k stars 500 forks source link

Don't require the pdf-fontsdir attribute in order to use custom fonts #2349

Open mojavelinux opened 2 years ago

mojavelinux commented 2 years ago

When a theme uses custom fonts, it's mandatory to set the the pdf-fontsdir attribute. Otherwise, the converter will not be able to locate the font files. This requirement makes it slightly more difficult to create a custom theme. The converter should instead provide a reasonable fallback if this attribute is not set.

There are several ways which this could be done.

First, the theme could expand the token THEMES_DIR at the beginning of the font path in the theme, much like it does for the GEM_FONTS_DIR token. The THEMES_DIR token would resolve to the value of the pdf-themesdir attribute (which defaults to the directory of the main theme file that was loaded).

font:
  catalog:
    Lato: THEMES_DIR/Lato-Regular.ttf

Second, the default pdf-fontsdir could be changed from GEM_FONTS_DIR to {pdf-themesdir};GEM_FONTS_DIR, where {pdf-themesdir} represents the value of the pdf-themesdir attribute. When this default is used, relative font paths in the theme are resolved from the themes dir (the directory of the theme file) first before being resolved from the installed gem. The user will still be able to override this default by setting the pdf-fontsdir attribute. And this won't affect built-in themes, which use the GEM_FONTS_DIR token explicitly to refer to paths inside the gem.

For completeness, we could also consider allowing the attribute reference {pdf-themesdir} to be used in the value of pdf-fontsdir when set from the CLI or API (e.g., -a pdf-fontsdir={pdf-themesdir}/fonts). Though that's not really addressing the original issue.

mojavelinux commented 2 years ago

I'm also thinking that the pdf-fontsdir should expand to the current directory if the value is empty. Right now, this value is interpreted as GEM_FONTS_DIR. However, that's not very logical.

AndrewBloom commented 2 months ago

Hi, I think this may be related. I have a mac, asciidoctor installed via HomeBrew. if I try to modify the size of fonts for the outputted pdf through the yaml file nothing really happens. If I try to change fonts (I thought that maybe the fonts didn't support the sizes), I get the error: "No such file or directory - Geneva.ttf not found in GEM_FONTS_DIR". I have no idea which directory that is, if it's a shell variable or something related to Ruby or gem (which i don't have really a clear idea of what they are). So I tried to set pdf-fontsdir with -a pdf-fontsdir="/System/Library/Fonts/,GEM_FONTS_DIR" to use the system fonts and this way doesn't give any errors (but still the size of the fonts don't change).

Would be cool if pdf-fontsdir is set at least to use the fonts that are installed on the computer by default.

mojavelinux commented 2 months ago

If you need help using Asciidoctor PDF, please direct your question to https://chat.asciidoctor.org. The only comments here should be how to design and implement a solution to the specified request.

AndrewBloom commented 2 months ago

@life888888 Yes I tried both ; and , with " and without. I actually tried many other things too without luck. @mojavelinux Yes, I wanted to give some context. Thanks for the link with the chat.