A Missing Font Is Not Substituted Using the Substitution Rules in Java

In Aspose Slides Java if you have a slides document with a invalid font or a missing font in the file in part of a paragraph the missing font it does not substitute using the substitution rules.

Sample code:

    @Test
    void fontReplacementMalfunctionTest() {
      final String doesNotExist = "This Font Doesn't Exist";
      // Instantiates Presentation
      final IFontSubstRuleCollection fontSubstitutions = new FontSubstRuleCollection();
      fontSubstitutions.add(
          new FontSubstRule(
              new FontData(doesNotExist),
              new FontData("Times New Roman"),
              FontSubstCondition.WhenInaccessible
          )
      );
      Presentation pres = new Presentation();
      pres.getFontsManager().setFontSubstRuleList(fontSubstitutions);
      try {
        // Gets the first slide in the presentation
        ISlide sld = pres.getSlides().get_Item(0);
    
        // Add AutoShape
        IAutoShape ashp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 150, 75, 150, 100);
        ITextFrame txtFrame = ashp.getTextFrame();
        txtFrame.setText("Text box starting text.");
    
        // Set font info
        IParagraph paragraph = new Paragraph();
        final IPortionCollection portions = paragraph.getPortions();
        final IPortion portion1 = new Portion("Portion 1 ");
        portion1.getPortionFormat().setLatinFont(new FontData(doesNotExist));
        portions.add(portion1);
        final IPortion portion2 = new Portion("Portion 2");
        portion2.getPortionFormat().setLatinFont(new FontData(doesNotExist));
        portion2.getPortionFormat().setFontBold(NullableBool.True);
        portions.add(portion2);
        txtFrame.getParagraphs().add(paragraph);
    
        // Saves the presentation to disk
        pres.save("replacementMalfunctionTest.pptx", SaveFormat.Pptx);
        pres.save("replacementMalfunctionTest.pdf", SaveFormat.Pdf);
      }
      finally {
        if (pres != null) {
          pres.dispose();
        }
      }
    }

Sample output files:
replacementMalfunctionTest.7z (57.1 KB)

@RyanWilliamsUSC,
Thank you for contacting support. I am working on the issue you described and will get back to you as soon as possible.

@RyanWilliamsUSC,
I’ve reproduced the problem with the font substitution and added a ticket with ID SLIDESJAVA-39085 to our issue-tracking system. We apologize for any inconvenience. Our development team will investigate the case. You will be notified when a new release of Aspose.Slides with the update is published.

Please also share the following additional information if it is possible:

  • OS version on which the code was executed
  • JDK version in your app

@Andrey_Potapov

Sorry for delay. This got lost in my email.

The above code has been tested in multiple environments by us:

  • JDK 8 on Windows 10 using amd64
  • JDK 11 on Windows 10 using amd64
  • JDK 17 on Windows 10 using amd64

For us any fix for also have to work in our server environments. I have not tested this code in these environments yet:

  • JDK 11 on RHEL 9 using amd64
  • JDK 11 on Ubuntu 22.04 LTS under docker using amd64

@RyanWilliamsUSC,
Thank you for the additional information. I’ve forwarded it to our developers.