gs01
February 25, 2025, 3:09pm
1
Hi
We are using Aspose Words to convert plain text and HTML to PDF.
We need to deploy our app in docker so the only fonts available to us are the fonts that we explicitly package with the image.
We need to be able to support multiple languages as well as emojis.
Does Aspose Words only try to use MS Word fonts by default? If so, is there a list of fonts that it tries to use that we can re-map?
It would be unfeasible for us to provide a mapping for every font type.
Could you suggest a way by which we could tell Aspose Word to use a particular font for a particular language or emojis?
Thanks
@gs01
Can you please specify which languages you need to support and if you have any specific fonts in mind for those languages or emojis?
gs01
February 25, 2025, 4:05pm
3
The language is Java and we have not decided on the fonts yet.
@gs01 To build an accurate document layout the fonts are required. If Aspose.Words cannot find the fonts used in the document the fonts are substituted . This might lead into the layout differences due to differences in fonts metrics. You can implement IWarningCallback to get a notification when font substitution is performed.
Please see our documentation to learn where Aspose.Words looks for fonts and how to specify fonts location
https://docs.aspose.com/words/java/specify-truetype-fonts-location/
https://docs.aspose.com/words/java/install-truetype-fonts-on-linux/
gs01
February 27, 2025, 9:09am
5
Is there a way to map character ranges to fonts in Aspose Words?
@gs01 Do you mean font fallback settings:
https://docs.aspose.com/words/java/manipulate-and-substitute-truetype-fonts/#font-fallback-settings-from-xml
You can save fallback settings using FontFallbackSettings.save
method, then modify settings and load them back using FontFallbackSettings.load
method.
Aspose.Words also allows to use predefined fallback settings which mimics the Microsoft Word fallback and uses Microsoft office fonts or predefined fallback settings which uses Google Noto fonts. You can load them using FontFallbackSettings.loadMsOfficeFallbackSettings and FontFallbackSettings.loadNotoFallbackSettings .
gs01
February 27, 2025, 1:14pm
7
I cant seem to get font fallback to work. My code is as below -
FontSettings fontSettings = new FontSettings();
FontSourceBase liberationSans = new StreamFontSource() {
@Override
public InputStream openFontDataStream() throws Exception {
return new ByteArrayInputStream(LIBERATION_SANS);
}
};
FontSourceBase liberationMono = new StreamFontSource() {
@Override
public InputStream openFontDataStream() throws Exception {
return new ByteArrayInputStream(LIBERATION_MONO);
}
};
fontSettings.setFontsSources(new FontSourceBase[]{liberationSans, emojisFont});
fontSettings.getSubstitutionSettings().getFontConfigSubstitution().setEnabled(false);
fontSettings.getSubstitutionSettings().getFontNameSubstitution().setEnabled(false);
fontSettings.getSubstitutionSettings().getFontInfoSubstitution().setEnabled(false);
try {
fontSettings.getFallbackSettings().load(this.getClass().getResourceAsStream("/font_fallback.xml"));
} catch (Exception e) {
}
Document rootDocument = new Document();
rootDocument.setFontSettings(fontSettings);
...
Document documentToAppend = new Document(inputStream, new HtmlLoadOptions());
rootDocument.appendDocument(documentToAppend, ImportFormatMode.KEEP_SOURCE_FORMATTING);
...
rootDocument.save(outputStream, new PdfSaveOptions());
My fallback file is as below -
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
FontFallbackSettings
FallbackTable
Rule Ranges="0041-0047" FallbackFonts="Liberation Mono"
Rule FallbackFonts="Liberation Sans"
FallbackTable
FontFallbackSettings
(I have not put the full tags in the xml file posted here because the chat does not let me.)
Basically, I want to use Liberation Mono for characters A - G and Liberation Sans for everything else.
@gs01 I am afraid, there is no way to achieve this. Fallback settings are applied only if Aspose.Words cannot find the appropriate glyphs in the font specified in the document or in the appropriate substitution font.
gs01
February 27, 2025, 2:01pm
9
In the example similar to the above, I am loading two fonts - Liberation Sans and Noto Emoji. In my fallback settings, I have the setting -
Rule Ranges="1F000-1FFFF" FallbackFonts="Noto Emoji"
I set a callback warning for font substitution and it is saying -
“Font ‘Segoe UI Emoji’ has not been found. Using ‘Liberation Sans’ font instead. Reason: first available font”
For Segoe UI Emoji - it is the char range I have set so it should pick up Noto Emoji but it is not doing that.
@gs01 Could you please attach your sample input, output and expected output documents along with fonts used for rendering. We will test the scenario and provide you more information.