java.lang.Object
com.aspose.words.FontFallbackSettings
public class FontFallbackSettings
Example:
Document doc = new Document();
// Create a FontSettings object for our document and get its FallbackSettings attribute
FontSettings fontSettings = new FontSettings();
doc.setFontSettings(fontSettings);
FontFallbackSettings fontFallbackSettings = fontSettings.getFallbackSettings();
// Set our fonts to be sourced exclusively from the "MyFonts" folder
FolderFontSource folderFontSource = new FolderFontSource(getMyDir() + "\\MyFonts", false);
fontSettings.setFontsSources(new FontSourceBase[]{folderFontSource});
// Calling BuildAutomatic() will generate a fallback scheme that distributes accessible fonts across as many unicode character codes as possible
// In our case, it only has access to the handful of fonts inside the "MyFonts" folder
fontFallbackSettings.buildAutomatic();
fontFallbackSettings.save(getArtifactsDir() + "Font.FontFallbackSettings.BuildAutomatic.xml");
// We can also load a custom substitution scheme from a file like this
// This scheme applies the "Arvo" font across the "0000-00ff" unicode blocks, the "Squarish Sans CT" font across "0100-024f",
// and the "M+ 2m" font in every place that none of the other fonts cover
fontFallbackSettings.load(getMyDir() + "Font.FallbackSettings.Custom.xml");
// Create a document builder and set its font to one that doesn't exist in any of our sources
// In doing that we will rely completely on our font fallback scheme to render text
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getFont().setName("Missing Font");
// Type out every unicode character from 0x0021 to 0x052F, with descriptive lines dividing unicode blocks we defined in our custom font fallback scheme
for (int i = 0x0021; i < 0x0530; i++) {
switch (i) {
case 0x0021:
builder.writeln("\n\n0x0021 - 0x00FF: \nBasic Latin/Latin-1 Supplement unicode blocks in \"Arvo\" font:");
break;
case 0x0100:
builder.writeln("\n\n0x0100 - 0x024F: \nLatin Extended A/B blocks, mostly in \"Squarish Sans CT\" font:");
break;
case 0x0250:
builder.writeln("\n\n0x0250 - 0x052F: \nIPA/Greek/Cyrillic blocks in \"M+ 2m\" font:");
break;
}
builder.write(Character.toString((char) i));
}
doc.save(getArtifactsDir() + "Font.FallbackSettings.Custom.pdf");
| Method Summary | ||
|---|---|---|
void | buildAutomatic() | |
| Automatically builds the fallback settings by scanning available fonts. | ||
void | load(java.io.InputStream stream) | |
| Loads fallback settings from XML stream. | ||
void | load(java.lang.String fileName) | |
| Loads font fallback settings from XML file. | ||
void | loadMsOfficeFallbackSettings() | |
| Loads predefined fallback settings which mimics the Microsoft Word fallback and uses Microsoft office fonts. | ||
void | loadNotoFallbackSettings() | |
| Loads predefined fallback settings which uses Google Noto fonts. | ||
void | save(java.io.InputStream outputStream) | |
| Saves the current fallback settings to stream. | ||
void | save(java.lang.String fileName) | |
| Saves the current fallback settings to file. | ||
| Method Detail |
|---|
buildAutomatic | |
public void buildAutomatic() | |
Example:
Shows how to distribute fallback fonts across unicode character code ranges.
Document doc = new Document();
// Create a FontSettings object for our document and get its FallbackSettings attribute
FontSettings fontSettings = new FontSettings();
doc.setFontSettings(fontSettings);
FontFallbackSettings fontFallbackSettings = fontSettings.getFallbackSettings();
// Set our fonts to be sourced exclusively from the "MyFonts" folder
FolderFontSource folderFontSource = new FolderFontSource(getMyDir() + "\\MyFonts", false);
fontSettings.setFontsSources(new FontSourceBase[]{folderFontSource});
// Calling BuildAutomatic() will generate a fallback scheme that distributes accessible fonts across as many unicode character codes as possible
// In our case, it only has access to the handful of fonts inside the "MyFonts" folder
fontFallbackSettings.buildAutomatic();
fontFallbackSettings.save(getArtifactsDir() + "Font.FontFallbackSettings.BuildAutomatic.xml");
// We can also load a custom substitution scheme from a file like this
// This scheme applies the "Arvo" font across the "0000-00ff" unicode blocks, the "Squarish Sans CT" font across "0100-024f",
// and the "M+ 2m" font in every place that none of the other fonts cover
fontFallbackSettings.load(getMyDir() + "Font.FallbackSettings.Custom.xml");
// Create a document builder and set its font to one that doesn't exist in any of our sources
// In doing that we will rely completely on our font fallback scheme to render text
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getFont().setName("Missing Font");
// Type out every unicode character from 0x0021 to 0x052F, with descriptive lines dividing unicode blocks we defined in our custom font fallback scheme
for (int i = 0x0021; i < 0x0530; i++) {
switch (i) {
case 0x0021:
builder.writeln("\n\n0x0021 - 0x00FF: \nBasic Latin/Latin-1 Supplement unicode blocks in \"Arvo\" font:");
break;
case 0x0100:
builder.writeln("\n\n0x0100 - 0x024F: \nLatin Extended A/B blocks, mostly in \"Squarish Sans CT\" font:");
break;
case 0x0250:
builder.writeln("\n\n0x0250 - 0x052F: \nIPA/Greek/Cyrillic blocks in \"M+ 2m\" font:");
break;
}
builder.write(Character.toString((char) i));
}
doc.save(getArtifactsDir() + "Font.FallbackSettings.Custom.pdf");load | |
public void load(java.io.InputStream stream)
throws java.lang.Exception | |
stream - Input stream.Example:
Shows how to load and save font fallback settings from stream.
Document doc = new Document(getMyDir() + "Rendering.doc");
// By default fallback settings are initialized with predefined settings which mimics the Microsoft Word fallback.
InputStream fontFallbackStream = new FileInputStream(getMyDir() + "Fallback.xml");
try {
FontSettings fontSettings = new FontSettings();
// Note: Saves font fallback setting by stream is not implemented now
fontSettings.getFallbackSettings().load(fontFallbackStream);
doc.setFontSettings(fontSettings);
} finally {
if (fontFallbackStream != null) {
fontFallbackStream.close();
}
}
doc.save(getArtifactsDir() + "LoadFontFallbackSettingsFromStream.pdf");load | |
public void load(java.lang.String fileName)
throws java.lang.Exception | |
fileName - Input file name.Example:
Shows how to load and save font fallback settings from file.Document doc = new Document(getMyDir() + "Rendering.doc"); // By default fallback settings are initialized with predefined settings which mimics the Microsoft Word fallback. FontSettings fontSettings = new FontSettings(); fontSettings.getFallbackSettings().load(getMyDir() + "Fallback.xml"); doc.setFontSettings(fontSettings); doc.save(getArtifactsDir() + "LoadFontFallbackSettingsFromFile.pdf"); // Saves font fallback setting by string doc.getFontSettings().getFallbackSettings().save(getArtifactsDir() + "FallbackSettings.xml");
loadMsOfficeFallbackSettings | |
public void loadMsOfficeFallbackSettings() | |
Example:
Shows how to load pre-defined fallback font settings.Document doc = new Document(); // Create a FontSettings object for our document and get its FallbackSettings attribute FontSettings fontSettings = new FontSettings(); doc.setFontSettings(fontSettings); FontFallbackSettings fontFallbackSettings = fontSettings.getFallbackSettings(); // Save the default fallback font scheme in an XML document // For example, one of the elements has a value of "0C00-0C7F" for Range and a corresponding "Vani" value for FallbackFonts // This means that if the font we are using does not have symbols for the 0x0C00-0x0C7F unicode block, // the symbols from the "Vani" font will be used as a substitute fontFallbackSettings.save(getArtifactsDir() + "Font.FallbackSettings.Default.xml"); // There are two pre-defined font fallback schemes we can choose from // 1: Use the default Microsoft Office scheme, which is the same one as the default fontFallbackSettings.loadMsOfficeFallbackSettings(); fontFallbackSettings.save(getArtifactsDir() + "Font.FallbackSettings.LoadMsOfficeFallbackSettings.xml"); // 2: Use the scheme built from Google Noto fonts fontFallbackSettings.loadNotoFallbackSettings(); fontFallbackSettings.save(getArtifactsDir() + "Font.FallbackSettings.LoadNotoFallbackSettings.xml");
loadNotoFallbackSettings | |
public void loadNotoFallbackSettings()
throws java.lang.Exception | |
Example:
Shows how to load pre-defined fallback font settings.Document doc = new Document(); // Create a FontSettings object for our document and get its FallbackSettings attribute FontSettings fontSettings = new FontSettings(); doc.setFontSettings(fontSettings); FontFallbackSettings fontFallbackSettings = fontSettings.getFallbackSettings(); // Save the default fallback font scheme in an XML document // For example, one of the elements has a value of "0C00-0C7F" for Range and a corresponding "Vani" value for FallbackFonts // This means that if the font we are using does not have symbols for the 0x0C00-0x0C7F unicode block, // the symbols from the "Vani" font will be used as a substitute fontFallbackSettings.save(getArtifactsDir() + "Font.FallbackSettings.Default.xml"); // There are two pre-defined font fallback schemes we can choose from // 1: Use the default Microsoft Office scheme, which is the same one as the default fontFallbackSettings.loadMsOfficeFallbackSettings(); fontFallbackSettings.save(getArtifactsDir() + "Font.FallbackSettings.LoadMsOfficeFallbackSettings.xml"); // 2: Use the scheme built from Google Noto fonts fontFallbackSettings.loadNotoFallbackSettings(); fontFallbackSettings.save(getArtifactsDir() + "Font.FallbackSettings.LoadNotoFallbackSettings.xml");
Example:
Shows how to add predefined font fallback settings for Google Noto fonts.
FontSettings fontSettings = new FontSettings();
// These are free fonts licensed under SIL OFL
// They can be downloaded from https://www.google.com/get/noto/#sans-lgc
fontSettings.setFontsFolder(getFontsDir() + "Noto", false);
// Note that only Sans style Noto fonts with regular weight are used in the predefined settings
// Some of the Noto fonts uses advanced typography features
// Advanced typography is currently not supported by AW and these fonts may be rendered inaccurately
fontSettings.getFallbackSettings().loadNotoFallbackSettings();
fontSettings.getSubstitutionSettings().getFontInfoSubstitution().setEnabled(false);
fontSettings.getSubstitutionSettings().getDefaultFontSubstitution().setDefaultFontName("Noto Sans");
Document doc = new Document();
doc.setFontSettings(fontSettings);save | |
public void save(java.io.InputStream outputStream)
throws java.lang.Exception | |
outputStream - Output stream.save | |
public void save(java.lang.String fileName)
throws java.lang.Exception | |
fileName - Output file name.Example:
Shows how to load and save font fallback settings from file.Document doc = new Document(getMyDir() + "Rendering.doc"); // By default fallback settings are initialized with predefined settings which mimics the Microsoft Word fallback. FontSettings fontSettings = new FontSettings(); fontSettings.getFallbackSettings().load(getMyDir() + "Fallback.xml"); doc.setFontSettings(fontSettings); doc.save(getArtifactsDir() + "LoadFontFallbackSettingsFromFile.pdf"); // Saves font fallback setting by string doc.getFontSettings().getFallbackSettings().save(getArtifactsDir() + "FallbackSettings.xml");