public class FontSettings
Aspose.Words uses font settings to resolve the fonts in the document. Fonts are resolved mostly when building document layout
or rendering to fixed page formats. But when loading some formats, Aspose.Words also may require to resolve the fonts. For example, when
loading HTML documents Aspose.Words may resolve the fonts to perform font fallback. So it is recommended that you set the font settings in
By default all documents uses single static font settings instance. It could be accessed by
Changing font settings is safe at any time from any thread. But it is recommended that you do not change the font settings while
processing some documents which uses this settings. This can lead to the fact that the same font will be resolved differently
in different parts of the document. Example: Example: Example:
Document doc = new Document(getMyDir() + "Rendering.docx");
// Note that this setting will override any default font sources that are being searched by default
// Now only these folders will be searched for fonts when rendering or embedding fonts
// To add an extra font source while keeping system font sources then use both FontSettings.GetFontSources and
// FontSettings.SetFontSources instead
FontSettings.getDefaultInstance().setFontsFolder("C:\\MyFonts\\", false);
doc.save(getArtifactsDir() + "Rendering.SetTrueTypeFontsFolder.pdf");
Document doc = new Document(getMyDir() + "Rendering.docx");
// Note that this setting will override any default font sources that are being searched by default
// Now only these folders will be searched for fonts when rendering or embedding fonts
// To add an extra font source while keeping system font sources then use both FontSettings.GetFontSources and
// FontSettings.SetFontSources instead
FontSettings.getDefaultInstance().setFontsFolders(new String[]{"C:\\MyFonts\\", "D:\\Misc\\Fonts\\"}, true);
doc.save(getArtifactsDir() + "Rendering.SetFontsFoldersMultipleFolders.pdf");
Document doc = new Document(getMyDir() + "Rendering.docx");
// 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.getDefaultInstance().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.getDefaultInstance().setFontsSources(updatedFontSources);
doc.save(getArtifactsDir() + "Rendering.SetFontsFoldersSystemAndCustomFolder.pdf");
Constructor Summary |
---|
Property Getters/Setters Summary | ||
---|---|---|
static FontSettings | getDefaultInstance() | |
Static default font settings.
|
||
FontFallbackSettings | getFallbackSettings() | |
Settings related to font fallback mechanism.
|
||
FontSubstitutionSettings | getSubstitutionSettings() | |
Settings related to font substitution mechanism.
|
Method Summary | ||
---|---|---|
FontSourceBase[] | getFontsSources() | |
Gets a copy of the array that contains the list of sources where Aspose.Words looks for TrueType fonts.
|
||
void | resetFontSources() | |
Resets the fonts sources to the system default.
|
||
void | setFontsFolder(java.lang.String fontFolder, boolean recursive) | |
Sets the folder where Aspose.Words looks for TrueType fonts when rendering documents or embedding fonts.
This is a shortcut to |
||
void | setFontsFolders(java.lang.String[] fontsFolders, boolean recursive) | |
Sets the folders where Aspose.Words looks for TrueType fonts when rendering documents or embedding fonts.
|
||
void | setFontsSources(FontSourceBase[] sources) | |
Sets the sources where Aspose.Words looks for TrueType fonts when rendering documents or embedding fonts.
|
public static FontSettings getDefaultInstance()
public FontFallbackSettings getFallbackSettings()
public FontSubstitutionSettings getSubstitutionSettings()
public FontSourceBase[] getFontsSources()
The returned value is a copy of the data that Aspose.Words uses. If you change the entries
in the returned array, it will have no effect on document rendering. To specify new font sources
use the
Example:
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.docx"); // 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.getDefaultInstance().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.getDefaultInstance().setFontsSources(updatedFontSources); doc.save(getArtifactsDir() + "Rendering.SetFontsFoldersSystemAndCustomFolder.pdf");
public void resetFontSources()
public void setFontsFolder(java.lang.String fontFolder, boolean recursive)
fontFolder
- The folder that contains TrueType fonts.recursive
- True to scan the specified folders for fonts recursively.Example:
Demonstrates how to set the folder Aspose.Words uses to look for TrueType fonts during rendering or embedding of fonts.Document doc = new Document(getMyDir() + "Rendering.docx"); // Note that this setting will override any default font sources that are being searched by default // Now only these folders will be searched for fonts when rendering or embedding fonts // To add an extra font source while keeping system font sources then use both FontSettings.GetFontSources and // FontSettings.SetFontSources instead FontSettings.getDefaultInstance().setFontsFolder("C:\\MyFonts\\", false); doc.save(getArtifactsDir() + "Rendering.SetTrueTypeFontsFolder.pdf");
public void setFontsFolders(java.lang.String[] fontsFolders, boolean recursive)
By default, Aspose.Words looks for fonts installed to the system.
Setting this property resets the cache of all previously loaded fonts.
fontsFolders
- An array of folders that contain TrueType fonts.recursive
- True to scan the specified folders for fonts recursively.Example:
Demonstrates how to set Aspose.Words to look in multiple folders for TrueType fonts when rendering or embedding fonts.Document doc = new Document(getMyDir() + "Rendering.docx"); // Note that this setting will override any default font sources that are being searched by default // Now only these folders will be searched for fonts when rendering or embedding fonts // To add an extra font source while keeping system font sources then use both FontSettings.GetFontSources and // FontSettings.SetFontSources instead FontSettings.getDefaultInstance().setFontsFolders(new String[]{"C:\\MyFonts\\", "D:\\Misc\\Fonts\\"}, true); doc.save(getArtifactsDir() + "Rendering.SetFontsFoldersMultipleFolders.pdf");
public void setFontsSources(FontSourceBase[] sources)
By default, Aspose.Words looks for fonts installed to the system.
Setting this property resets the cache of all previously loaded fonts.
sources
- An array of sources that contain TrueType fonts.Example:
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.docx"); // 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.getDefaultInstance().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.getDefaultInstance().setFontsSources(updatedFontSources); doc.save(getArtifactsDir() + "Rendering.SetFontsFoldersSystemAndCustomFolder.pdf");