Free Support Forum - aspose.com

Java Logical fonts support

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