We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

FontSettings.setFontsFolders - Specifying the order

Hi there,

Using FontSettings.setFontsFolders
(new String[] {“C:\MyFonts\”, “D:\Misc\Fonts\”}, true);
we can specify the folders where to search for the fonts.

Our requirement is such that we want “C:\MyFonts\” to be
searched first and if a font is not found here then go to
“D:\Misc\Fonts\”. I mean we want to specify the order along
with the font folders to ensure the folders are visited in
the order we specified.

Please look in to this.
Thanks.

Hi Praneeth,

Thanks for your inquiry. The FontSettings.setFontsFolders sets the folders where Aspose.Words looks for TrueType fonts when rendering documents or embedding fonts. This method does not follow the order in which font folders are mentioned.

However, I have logged a feature request as WORDSNET-10210 in our issue tracking system for your requirement. Our development team will look into the
possibility of implementation of this requested feature. Once we have
any information about this feature, we will update you via this thread.


Please let us know if you have any more queries.

Hi Praneeth,

Thanks for your patience. Regarding the implementation of WORDSNET-10210, It would be great if you please some more detail about your scenario in which you want this feature.

Please also share what problem you want to solve using this feature. Perhaps, there is some other way or workaround to achieve your requirements.

Hi Tahir,
Sorry for the late reply.
We want to utilize java fonts present in the system. We would be searching for server fonts first and then java fonts to avoid some conflicts with fonts. Since there could be fonts with same name present in both Java fonts and the system, these might have different character set and we want the result to be deterministic in every occurrence and want to utilize fonts in system directory first and then the java fonts in the system then the Aspose font substitution algorithm would come into the picture.
Thanks.

Hi Praneeth,

Thanks for your feedback. Unfortunately, I have not understood this detail. It seems that your query is different from this detail. It would be great if you please share some more detail about your requirements.

PraneethS:

Our requirement is such that we want “C:\MyFonts\” to be
searched first and if a font is not found here then go to
“D:\Misc\Fonts\”. I mean we want to specify the order along
with the font folders to ensure the folders are visited in
the order we specified.

Please share what problem you want to solve using this feature.

If you want to set the sources where Aspose.Words looks for TrueType fonts when rendering documents or embedding fonts, please use FontSettings.setFontsSources method. The following code demonstrates how to set
Aspose.Words to look for TrueType fonts in system folders as well as a
custom defined folder when scanning for fonts.

Document doc = new Document(getMyDir() + “Rendering.doc”);

// 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 a new folder source which will instruct Aspose.Words to search the following folder for fonts.
FolderFontSource folderFontSource = new FolderFontSource(“C:\MyFonts\”, true);

// Add the custom folder which contains our fonts to the list of existing font sources.
fontSources.add(folderFontSource);

// 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);

doc.save(getMyDir() + “Rendering.SetFontsFolders Out.pdf”);

Hi Tahir,
Our requirement is simple -
If there are two font sources -
sourceA = {fontA, fontB, fontC}
sourceB = {fontA, fontD, fontE, fontC}

if there is fontA and fontC used in the document and while converting to PDF it is to be looked up, then we want to give sourceA’s fonts priority than sourceB’s fonts.

So, all we want is sourceA’s fonts is to be used always even if fonts with same names exists in sourceB.


Given that, back to our original query, is there a way to do the same using Aspose?

Hope I make sense.
Thanks.

Hi Praneeth,

Thanks for sharing the detail. I have logged this detail with WORDSNET-10210. Our development team will look into the
possibility of implementation of this requested feature. Once we have
any information about this feature, we will update you via this thread.

PraneethS:

Given that, back to our original query, is there a way to do the same using Aspose?

In your case, I suggest you please use Document.FontInfos property which provide access to properties of fonts used in this document. You can list the font used in the document and find these fonts in sourceA and sourceB. Once you have the fonts used in the document, copy all fonts in a directory and use the code shared here to convert document to Pdf. Hope this helps you.

The issues you have found earlier (filed as WORDSNET-10210) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Hi Tahir,
Could you please help us in understanding how the new APIs are solving our problem of assigning priorities to fonts in some folder?


Our requirement is simple -
Suppose there are two font sources -
sourceA = {fontA, fontB, fontC}
sourceB = {fontA, fontD, fontE, fontC}

and if
there is fontA and fontC used in the DOCX document and while converting to
PDF, they are to be looked up, then we want to give sourceA’s fonts priority
than sourceB’s fonts.

So, all we want is sourceA’s fonts is to be used always even if fonts with same names exists in sourceB.

Thanks.

Hi Praneeth,

Thanks for your inquiry. Priority property has been added to the FontSourceBase class. This property is used when there are fonts with the same family name and style in different font sources. In this case Aspose.Words selects the font from the source with the higher priority value.

// Aspose.Words will prefer fonts from “Folder1” over the fonts from “Folder2”.
FolderFontSource folder1 = new FolderFontSource(“Folder1”, false, 2);
FolderFontSource folder2 = new FolderFontSource(“Folder2”, false, 1);
FontSettings.setFontsSources(new FontSourceBase[] {folder1, folder2});

Please read more about public API changes in Aspose.Words 14.7.0 from here:
http://www.aspose.com/docs/display/wordsjava/Public+API+Changes+in+Aspose.Words+14.7.0