Support Java Logical Fonts such as Monospaced and Dialog in Aspose.Words | Split Paragraph into Sections of Characters

Does Aspose.Word for Java already provide a built in support of logical Java fonts like Monospaced or Dialog? Since the actually used physical fonts may differ from character to character (e.g. if combining latin and chinese characters), it would be very helpful if the user doesn’t have to split a paragraph into sections of characters with the same physical font himself.

@JohnBill,

If Aspose.Words cannot find any fonts among the available font sources in your machine, then it renders the document using the free Fanwood font that is embedded inside the Aspose.Words. Can you please ZIP and upload a sample Word document containing text formatted with Monospaced or Dialog fonts here for testing? Are you intended to convert such documents to PDF format? We will then investigate the scenario/issue on our end and provide you more information.

Hello,
thank you for the fast response.

We see no need to convert the generated Word document to PDF since our Software already provides a PDF export. Nevertheless, the user can of course open the Word document with MS Word and save it as PDF.

I generated two examples of a JComponent showing a StyledDocument of text: one in font Dialog and one in Monospaced:
Dialog.zip (146.3 KB)
Monospaced.zip (144.6 KB)

Each Zip-Archive contains

  • the Word Document created with Aspose.Word for Java
  • a PDF Document, created using OpenPDF
  • a PNG image

Best regards

@JohnBill,

You can apply mixed Font formatting to text belonging to same Paragraphs. Can you please elaborate your inquiry a bit further and provide the following information?

  • What exact problem(s) are you observing in Aspose.Words generated documents?
  • Please ZIP and share the Monospaced and Dialog font files
  • Please provide complete steps that we can follow to observe the same problem on our end.

This will help us to understand your scenario, and we will be in a better position to address your concerns accordingly.

Monospaced and Dialog are no really physically installed fonts but so called logical fonts which are available for Java applications. When paint Java itself maps them to physical fonts depending on the system configuration and the current character. There is a file The Java configuration file lib\fontconfig.properties.src specifies this mapping. E.g. on my system for Dialog.plain:

dialog.plain.alphabetic=Arial
dialog.plain.chinese-ms950=MingLiU
dialog.plain.chinese-ms950-extb=MingLiU-ExtB
dialog.plain.hebrew=David
dialog.plain.japanese=MS Gothic
dialog.plain.korean=Gulim 

If it helps, we could provide a little Java example application to illustrate the problem, but it would simply create a word document containing a paragraph or text area with a text and assigns the font “Dialog”:

java.awt.Font javaFont = new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10);
Run run = new Run(documentBuilder.getDocument());
Font asposeFont = run.getFont();
asposeFont.setName(javaFont.getName());
asposeFont.setSize(javaFont.getSize());
asposeFont.setBold(javaFont.isBold());
asposeFont.setItalic(javaFont.isItalic());
asposeFont.setColor(textColor);
run.setText(...);
...

The open issue is, that, as I understand, this font name is just forwared into the Word document and, differing from Java, MS Word understandably doesn’t know how to deal with this unknown font.

@JohnBill,

Thanks for the details. We have logged your requirement in our issue tracking system. Your ticket number is:

  • WORDSJAVA-2472: Support Java Logical Fonts such as Monospaced and Dialog

We will further look into the details of this requirement and will keep you updated on the status of the linked issue.

1 Like

@JohnBill,

Regarding WORDSJAVA-2472, we have completed the work on this issue and concluded that we will not be able to implement the fix to your issue in Aspose.Words’ API. This is because Java Logical Font is not a physical font but a Composite Font that contains maps to several physical fonts depending on a symbol. For instance, it can be a different map for “windings”, “alphabetical”, Chinese, Hebrew, Japanese, Korean, Arabic, etc. symbols. The mapping is not static and is performed at run-time. Moreover, the mapping is implementation-dependent. Java specification doesn’t contain a standard API to get the maps. All open source code to get the maps are: 1) platform-dependent 2) using reflection to access non-public members. And it gets only list of mapped fonts. For instance:

Official documentation about JRE, OS and Locale dependent implementation:

  • https://docs.oracle.com/javase/7/docs/api/java/awt/font.html

Here is a relevant quote from above page:

And a relevant quote from above page:

So, it is extremely difficult and expensive to implement this feature in Aspose.Words API and this issue is now closed with “Won’t Fix” status.