Bug 68137 - PPTX2PNG doesn't use fonts supplied via -fontdir
Summary: PPTX2PNG doesn't use fonts supplied via -fontdir
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-11-13 18:54 UTC by Jim Kelly
Modified: 2024-02-25 20:33 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jim Kelly 2023-11-13 18:54:15 UTC
The experience:

1. Install a distinctive TTF font into Windows. I used Agbalumo from fonts.google.com.
2. Using PowerPoint app, create a PPTX that uses it.
3. Uninstall the font from Windows.
4. Use PPTX2PNG to render the PPTX as a PDF, providing -fontdir option to .ttf file.
5. PDF gets rendered using Arial or similar default sans-serif font.

I've confirmed in the debugger that PDFFontMapper is indeed finding and reading the font, but it doesn't end up getting used.  DrawTextParagraph calls this code in DrawFontManagerDefault:

   @Override
    public Font createAWTFont(Graphics2D graphics, FontInfo fontInfo, double fontSize, boolean bold, boolean italic) {
        int style = (bold ? Font.BOLD : 0) | (italic ? Font.ITALIC : 0);
        Font font = new Font(fontInfo.getTypeface(), style, 12);
        if (Font.DIALOG.equals(font.getFamily())) {
            // SansSerif is a better choice than Dialog
            font = new Font(Font.SANS_SERIF, style, 12);
        }
        return font.deriveFont((float)fontSize);
    }

Things go south during the call to font.getFamily(), which causes a call to SunFontManager.findFont2D that initializes the system fonts, doesn't find our special one, and returns a composite font from the DIALOG family.

Seems to me this could work if PDFFontMapper.registerFonts actually registered the fonts with SunFontManager, but it doesn't; it just populates its own internal map. How is -fontdir resolution supposed to work?

I've also tried embedding the font within the PPTX file, which doesn't work either, though I haven't tracked down whether it goes wrong for the same reason.