0

Google Cloud Dataflow - Problem reading font data

Hi,

I am trying to run a java application on Google cloud dataflow, however I am getting an exception

Error message from worker: java.lang.Exception:Problem reading font data. 

The exception only appears when I use the Dataflowrunner , but when I use the directRunner it works fine on my machine

The issue is basically with java.awt.Font in the line

 Font.createFonts(stream)
                        .first()
                        .deriveFont(fontSize * FONT_SIZE_MULTIPLIER)

I am assuming that the docker image that dataflow runner uses, is missing on of the configurations, but I am not quiet sure what is it

Would appreciate if anyone has any idea about this and wants to help

Thanks!

Ahmed Abdelhak
  • 239
  • 3
  • 7
  • where does Font data normally come from? A config file? – Pablo May 24 '23 at 21:42
  • Hi Pablo, thanks a lot for following up, I am fetching a custom font from GCS bucket, I checked that we get the bytestream, but the issue is with the java font library when `Font.createFonts(stream)` I tried to get the `fontconfig` system property during my application lifetime, and it returned null, so I am suspecting that the default Apache Beam SDK that dataflow runner is using doesn't have `fontconfig` library – Ahmed Abdelhak May 25 '23 at 08:38
  • I also tried to use one of the default fonts ( I pulled the docker image apache/beam_java17_sdk:latest , as I am expecting it's the one used on dataflow runner ) I used the font ```Font("DejaVuSerif-Bold", Font.BOLD, 18)``` and now I ran into another Issue: ```Error message from worker: java.lang.NoClassDefFoundError: Could not initialize class sun.font.SunFontManager\n java.desktop/sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:266)\n java.desktop/sun.java2d.SunGraphics2D.getFontMetrics(SunGraphics2D.java:863)\n``` – Ahmed Abdelhak May 25 '23 at 09:39
  • I found a similar issue : https://stackoverflow.com/questions/65683652/java-lang-noclassdeffounderror-could-not-initialize-class-sun-font-sunfontmanag it also mentioned the fontconfig – Ahmed Abdelhak May 25 '23 at 09:40

1 Answers1

0
apt-get update
apt-get install -y fonts-dejavu
apt-get install -y libfontconfig1-dev

Per this documentation also, register the created font with the graphics environment. For example:

try {
     GraphicsEnvironment ge = 
         GraphicsEnvironment.getLocalGraphicsEnvironment();
     ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File("A.ttf"));
} catch (IOException|FontFormatException e) {
     //Handle exception
}

After registering the font with the graphics environment, the font is available in calls to getAvailableFontFamilyNames() and can be used in font constructors.

Joevanie
  • 489
  • 2
  • 5
  • thanks for trying help, but I am using a different environment, where it requires to deal with external dependencies, I may not showed it in the main post, but I explained in the comments above – Ahmed Abdelhak Jun 06 '23 at 10:23