MemoryFontSource

Hello.
could you be so kind to provide any example of applying MemoryFontSource class for FontSettings (if there is java.awt.Font[]). I mean which way of getting bytes from Font is the most appropriate to generate MemoryFont?
thank you in advance

Hi Akane,


Thanks for your inquiry. You can instruct Aspose.Words to look for TrueType fonts in system folders as well as in a custom stream/byte[] object when scanning for fonts by using the following code snippet:
// Retrieve the array of environment-dependent font sources that are searched by default. For example this will contain a “Windows\Fonts” source on a Windows machines.
// We add this array to a new ArrayList to make adding or removing font entries much easier.
ArrayList fontSources = new ArrayList(Arrays.asList(FontSettings.getFontsSources()));

// Add your custom font to the list.
MemoryFontSource memoryFontSource = new MemoryFontSource(your byte[] font data here);
fontSources.add(memoryFontSource);

// Convert the Arraylist of source back into a primitive array of FontSource objects.
FontSourceBase[] updatedFontSources = (FontSourceBase[]) fontSources.toArray(new FontSourceBase[fontSources.size()]);

// Apply the new set of font sources to use.
FontSettings.setFontsSources(updatedFontSources);

I hope, this helps.

Best regards,