specify fall back fonts is not working

+1 vote
asked Oct 28, 2021 in Bug by kirchsth (4,980 points)

Hi,

based on https://forum.plantuml.net/10498/is-there-a-supported-way-to-specify-fall-back-fonts it should be possible to define multiple default fonts. But I think it is not working. I tried it with following

@startuml
skinparam title{
  Fontsize 50
}
title TestTitle

' not working
' skinparam DefaultFontName NotExisting, Courier
' working
skinparam DefaultFontName Courier

[Room] --> [Chair] : "has several"
@enduml

Did I oversee something?

Thank you and best regards
Helmut

commented Feb 26, 2022 by Martin (8,360 points)

I'm not a coder, but I'm suspicious of this block of code in UFont.java:

  private static Font buildFont(String fontFamily, int fontStyle, int fontSize) {
    if (fontFamily.contains(",")) {
      for (String name : fontFamily.split(",")) {
        name = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(name).trim();
        if (doesFamilyExists(name)) {
          return new Font(fontFamily, fontStyle, fontSize);
        }
      }
    }
    return new Font(fontFamily, fontStyle, fontSize);
  }

In particular:

        if (doesFamilyExists(name)) {
          return new Font(fontFamily, fontStyle, fontSize);
        }

Surely if you're going to the trouble of checking that "name" is a font family, then it should return Font(name, fontstyle, fontsize) ?!

commented Feb 26, 2022 by kirchsth (4,980 points)

It could be that the problem is output format releated, eg. following works with svg but not with png

@startuml
skinparam TitleFontsize 50
title TestTitle

skinparam DefaultFontName NotExisting, Courier

[Room] --> [Chair] : "has several"
@enduml

With SVG it's working

http://www.plantuml.com/plantuml/svg/JSwzgi9G4CJnVfzYI7q3jx6na43KCeMa2oaMNCtY-P2p6n75TzTOsGq3F_WtvbnyZe7iekdAXIDSFSYJW7rERleGhFxfHTyRlPZtoo80-55REV4SV34THq6NVNTNSqtdFxHvBYg5Q3Za74VKzGP3Ex6M4MjK4njCRb8uLDH8Edw2tW00
With PNG it's not working 

http://www.plantuml.com/plantuml/png/JSwzgi9G4CJnVfzYI7q3jx6na43KCeMa2oaMNCtY-P2p6n75TzTOsGq3F_WtvbnyZe7iekdAXIDSFSYJW7rERleGhFxfHTyRlPZtoo80-55REV4SV34THq6NVNTNSqtdFxHvBYg5Q3Za74VKzGP3Ex6M4MjK4njCRb8uLDH8Edw2tW00
Thank you and best regards
Helmut

 

commented Feb 26, 2022 by Martin (8,360 points)
edited Feb 26, 2022 by Martin
Interesting.  That nearly blows my idea - unless the function should return "name" for png and  "fontFamily" for svg.
commented Feb 27, 2022 by kirchsth (4,980 points)

I found 2 better fonts that differences are more visible and added my test results.
@plantuml: can you please try Martins bugfix?

@startuml
' !$desc="valid (png) font name - (png) working"
' !$fontName="jlm_cmmi10"

' !$desc="valid (svg) font name - (svg) working"
' !$fontName="MS Gothic"

' !$desc="invalid and valid (png) font name - (png) not working"
' !$fontName="invalidFont, jlm_cmmi10"

' !$desc="invalid and valid (svg) font name - (svg) working"
' !$fontName="invalidFont, MS Gothic"

' !$desc="valid (png)+(svg) font name - (png) not working, (svg) working"
' !$fontName="jlm_cmmi10, MS Gothic"

!$desc="valid (svg)+(png) font name - (png) not working, (svg) working"
!$fontName="MS Gothic, jlm_cmmi10"

skinparam TitleFontSize 15

skinparam TitleFontName $fontName

Title "Test font settings << >> ? $ § [$desc] : $fontName
@enduml

E.g. last test output PNG

last test output SVG

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:

[Antispam2 Feature: please please wait 1 or 2 minutes (this message will disappear) before pressing the button otherwise it will fail](--------)
To avoid this verification in future, please log in or register.
...