Is there a supported way to specify fall back fonts?

0 votes
asked Nov 29, 2019 in Question / help by roxspring (260 points)

Specifying a specific font name for use in diagrams works great:

DefaultFontName "Proxima Nova Cn CF"

PNG images use the correct font if available, SVG images reference the correct font and render correctly where the client has the correct font available. But our preferred font isn't available everywhere and we'd like to make use of CSS font fallback. We tried the following:

DefaultFontName "Proxima Nova Cn CF", "DejaVu Sans", "SansSerif", sans-serif

This is great and means that SVGs fall back to some more commonly available fonts, but this breaks the PNG export because presumably the render is looking for a single font with that long compound name.

Is there a better way of achieving the result I'm after?

If not then could we have PNG renderer support a fallback list of fonts in DefaultFontName?

Thanks,

Rob

commented Oct 29, 2022 by Fuhrmanator (1,700 points)
edited Oct 30, 2022 by Fuhrmanator

I am interested in going a step further -- adding a URI for the font (for a style in the SVG). Unfortunately, when SVG is inside an <IMG> tag, I can't get the CSS from the HTML page @font-face style to apply. It seems you have to put the CSS in the SVG. This page also says "you will lose your fonts" if you use SVGs via IMG tags. In my case, I don't want to use object tags. EDIT: You have to specify everything (fonts included) in the SVG: https://stackoverflow.com/a/69160093/1168342

Here's an example with the xkcd Script font, that is CC 3.0 and is great when you want that "handwritten" feel with text.

<defs xmlns="http://www.w3.org/2000/svg">
    <style type="text/css">
        @font-face {
          font-family: 'xkcd Script';
          src: url('https://cdn.rawgit.com/dummy-index/xkcd-font/master/xkcd-script/font/xkcd-script.ttf') format('truetype'),
            url('https://cdn.rawgit.com/dummy-index/xkcd-font/master/xkcd-script/font/xkcd-script.woff') format('woff');
        }
    </style>
</defs>

I've tried to use the <style /> element in the web page, but none of my PlantUML images that are SVGs in a web page find that font. The above (including the <defs /> has to be in the actual SVG to work. 

I can't see any way to get PlantUML to generate it. Any hints?

For the record, I'm generating the SVGs on a docker that has the font in its system (so the widths of the images are OK), but the end result is going onto a web page, so I'd like to link to the xkcd Script font. 

2 Answers

0 votes
answered Dec 1, 2019 by plantuml (294,960 points)

It's not possible yet...

However, this is a nice suggestion so with last beta http://beta.plantuml.net/plantuml.jar , you can now have:

@startuml
skinparam DefaultFontName Proxima Nova Cn CF, DejaVu Sans, SansSerif, sans-serif
Alice -> Bob : hello
@enduml

In case you are interested, the patched code is here http://beta.plantuml.net/UFont.java

0 votes
answered Dec 20, 2019 by plantuml (294,960 points)
This has been released in last version V1.2019.13

Regards,
...