christianvoigt / argdown

a simple syntax for complex argumentation
https://argdown.org
923 stars 30 forks source link

Support using custom font for pdf export (unicode support) #213

Open 6-AND-9 opened 3 years ago

6-AND-9 commented 3 years ago

Hi again Christian,

Just wanted to inform you of this. When trying to export the map in PDF, Unicode/Cyrillic text is garbled. Only universal characters (such as numbers and punctuation) are shown as they should be.

Check the included PDF for an example. Example Cyrillic argument.pdf

You can't see now, but all nodes are full of Cyrillic text.

christianvoigt commented 3 years ago

Yes, the built-in fonts of pdfkit only have a limited character set (see this issue and the Readme).

The PdfExportPlugin should offer the option to use a different font, using SVG-to-PDFKit's method to do so.

christianvoigt commented 3 years ago

Ok, I added support for this in the upcoming v1.7.0. Here is an example of how to use this (with some arbitrary cyrillic letters that hopefully do not mean anything ;)):

    ===
    svgToPdf:
        fonts:
            - {name: "arial", path: "./DejaVuSans.ttf"}
            - {name: "arial Bold", path: "./DejaVuSans-Bold.ttf"}
    ===

        [B]: ДҖЛ̕

        <A>: ДҖЛ̕
            - [B]
            + <C>: ДҖЛ̕

Basically you tell the PDF export to substitute the DejaVu font in the pdf file wherever "arial" is used in the svg file. I only tried this for the regular and bold font variants, but you should probably also add an entry for "arial Italic". Once you started defining custom fonts for the pdf, the export plugin will throw an error if it does not find a font name in this list. So you can simply iteratively add those names the plugin does not find until everything works (it is probably easiest to use @argdown/cli for that, but you should see these errors also in the "Argdown" output channel of VSCode).

Note that this might lead to layout errors if you substitute a font with very different glyph sizes. So ideally you should substitute Arial with "Arial Unicode" (I used a free software font in my tests, so I could add it to this repository).

Please let me know if this works for you (it might still take a few days until I have published all Argdown packages, but this feature is the last one that landed in v1.7.0).

christianvoigt commented 3 years ago

@andrejdam v1.7.0 is now published, it would be great if you could try this out, so that I can close this issue.

6-AND-9 commented 3 years ago

@christianvoigt , thanks for letting me know. You'll have to excuse me for a few days as I got sick with COVID and am unable to stay too long on my computer. As soon as I catch up my strength I'll try this out and confirm.

christianvoigt commented 3 years ago

Oh, I am so sorry to hear that and hope that you will get well soon! Thanks for letting me know.

InventorisVitu commented 1 year ago

Hello! I don’t know if my problem is related to this one, but using Cyrillic creates long round boxes: the text itself is displayed only on the left side of the box, and the right side is empty (but I can see my text). Is this can be fixed somehow, for example, how it works in Latex for text input like \text{} command or how it works in python using print() function?