FontsManager
Inheritance: java.lang.Object
All Implemented Interfaces: com.aspose.slides.IFontsManager
public class FontsManager implements IFontsManager
Manages fonts across the presentation.
The following example shows how to add embedded fonts to PowerPoint Presentation. // Load presentation Presentation pres = new Presentation("Fonts.pptx"); try { // Load source font to be replaced IFontData sourceFont = new FontData("Arial"); IFontData[] allFonts = pres.getFontsManager().getFonts(); for (IFontData font : allFonts) { boolean fontAlreadyEmbedded = false; IFontData[] embeddedFonts = pres.getFontsManager().getEmbeddedFonts(); for (int i = 0; i < embeddedFonts.length; i++) { if (embeddedFonts[i].equals(font)) { fontAlreadyEmbedded = true; break; } } if (!fontAlreadyEmbedded) { pres.getFontsManager().addEmbeddedFont(font, EmbedFontCharacters.All); } } // Save the presentation pres.save("AddEmbeddedFont_out.pptx", SaveFormat.Pptx); } finally { if (pres != null) pres.dispose(); }
Methods
| Method | Description |
|---|---|
| getFontSubstRuleList() | Font substitutions to use when rendering. |
| setFontSubstRuleList(IFontSubstRuleCollection value) | Font substitutions to use when rendering. |
| getFontFallBackRulesCollection() | Represents a user’s collection of FontFallBack rules for managing of collections of fonts for proper substitutions by fallback functionality Read/write IFontFallBackRulesCollection. |
| setFontFallBackRulesCollection(IFontFallBackRulesCollection value) | Represents a user’s collection of FontFallBack rules for managing of collections of fonts for proper substitutions by fallback functionality Read/write IFontFallBackRulesCollection. |
| getFonts() | Returns the fonts used in the presentation |
| getSubstitutions() | Gets the information about fonts that will be replaced on the presentation’s rendering. |
| getSubstitutions(int[] slides) | Gets the information about fonts that will be replaced during rendering of the specified slides. |
| getPreferRegisteredFontsOverEmbedded() | Specifies whether registered fonts should be preferred over embedded fonts with the same font name and style. |
| setPreferRegisteredFontsOverEmbedded(boolean value) | Specifies whether registered fonts should be preferred over embedded fonts with the same font name and style. |
| getEmbeddedFonts() | Returns the fonts embedded in the presentation |
| removeEmbeddedFont(IFontData fontData) | Removes the embedded font |
| addEmbeddedFont(IFontData fontData, int embedFontRule) | Adds the embedded font |
| addEmbeddedFont(byte[] fontData, int embedFontRule) | Adds the embedded font |
| replaceFont(IFontData sourceFont, IFontData destFont) | Replace font in presentation |
| replaceFont(IFontSubstRule substRule) | Replace font in presentation using information provided in FontSubstRule |
| replaceFont(IFontSubstRuleCollection substRules) | Replace font in presentation using information provided in collection of FontSubstRule |
| getFontBytes(IFontData fontData, int fontStyle) | Retrieves the byte array representing the font data for a specified font style and font data. |
| getFontEmbeddingLevel(byte[] fontBytes, String fontName) | Determines the embedding level of a font from the given byte array and font name. |
getFontSubstRuleList()
public final IFontSubstRuleCollection getFontSubstRuleList()
Font substitutions to use when rendering. Read/write IFontSubstRuleCollection.
Returns: IFontSubstRuleCollection
setFontSubstRuleList(IFontSubstRuleCollection value)
public final void setFontSubstRuleList(IFontSubstRuleCollection value)
Font substitutions to use when rendering. Read/write IFontSubstRuleCollection.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| value | IFontSubstRuleCollection |
getFontFallBackRulesCollection()
public final IFontFallBackRulesCollection getFontFallBackRulesCollection()
Represents a user’s collection of FontFallBack rules for managing of collections of fonts for proper substitutions by fallback functionality Read/write IFontFallBackRulesCollection.
Presentation pres = new Presentation(); try { // Getting of empty or preinitialized rules collection from FontsManager IFontFallBackRulesCollection rulesList = pres.getFontsManager().getFontFallBackRulesCollection(); // adding of rules to collection rulesList.add(new FontFallBackRule(0x400,0x4FF, "Times New Roman")); // or // initialization of new instance of rules collection IFontFallBackRulesCollection rulesList = new FontFallBackRulesCollection(); // adding of rules to collection rulesList.add(new FontFallBackRule(0x400,0x4FF, "Times New Roman")); // and replacing of existing collection by the new one in FontsManager pres.getFontsManager().setFontFallBackRulesCollection(rulesList); } finally { if (pres != null) pres.dispose(); }
Returns: IFontFallBackRulesCollection
setFontFallBackRulesCollection(IFontFallBackRulesCollection value)
public final void setFontFallBackRulesCollection(IFontFallBackRulesCollection value)
Represents a user’s collection of FontFallBack rules for managing of collections of fonts for proper substitutions by fallback functionality Read/write IFontFallBackRulesCollection.
Presentation pres = new Presentation(); try { // Getting of empty or preinitialized rules collection from FontsManager IFontFallBackRulesCollection rulesList = pres.getFontsManager().getFontFallBackRulesCollection(); // adding of rules to collection rulesList.add(new FontFallBackRule(0x400,0x4FF, "Times New Roman")); // or // initialization of new instance of rules collection IFontFallBackRulesCollection rulesList = new FontFallBackRulesCollection(); // adding of rules to collection rulesList.add(new FontFallBackRule(0x400,0x4FF, "Times New Roman")); // and replacing of existing collection by the new one in FontsManager pres.getFontsManager().setFontFallBackRulesCollection(rulesList); } finally { if (pres != null) pres.dispose(); }
Parameters:
| Parameter | Type | Description |
|---|---|---|
| value | IFontFallBackRulesCollection |
getFonts()
public final IFontData[] getFonts()
Returns the fonts used in the presentation
Returns: com.aspose.slides.IFontData[] - An array of fonts
getSubstitutions()
public final System.Collections.Generic.IGenericEnumerable<FontSubstitutionInfo> getSubstitutions()
Gets the information about fonts that will be replaced on the presentation’s rendering.
Presentation pres = new Presentation("pres.pptx"); try { for (FontSubstitutionInfo fontSubstitution : pres.getFontsManager().getSubstitutions()) { System.out.println(fontSubstitution.getOriginalFontName() + " -> " + fontSubstitution.getSubstitutedFontName()); } } finally { if (pres != null) pres.dispose(); }
Returns: com.aspose.ms.System.Collections.Generic.IGenericEnumerable<com.aspose.slides.FontSubstitutionInfo> - Collection of all fonts substitution FontSubstitutionInfo.
getSubstitutions(int[] slides)
public final System.Collections.Generic.IGenericEnumerable<FontSubstitutionInfo> getSubstitutions(int[] slides)
Gets the information about fonts that will be replaced during rendering of the specified slides.
Presentation pres = new Presentation("pres.pptx"); try { int[] targetSlides = { 1, 2, 5 }; for (FontSubstitutionInfo fontSubstitution : pres.getFontsManager().getSubstitutions(targetSlides)) { System.out.println(fontSubstitution.getOriginalFontName() + " -> " + fontSubstitution.getSubstitutedFontName()); } } finally { if (pres != null) pres.dispose(); }
Parameters:
| Parameter | Type | Description |
|---|---|---|
| slides | int[] | An array of slide indexes for which to retrieve font substitution information, starting from 1. |
Returns: com.aspose.ms.System.Collections.Generic.IGenericEnumerable<com.aspose.slides.FontSubstitutionInfo> - A collection of all font substitutions (FontSubstitutionInfo) for the specified slides.
getPreferRegisteredFontsOverEmbedded()
public final boolean getPreferRegisteredFontsOverEmbedded()
Specifies whether registered fonts should be preferred over embedded fonts with the same font name and style. When enabled, matching embedded fonts are temporarily replaced with corresponding registered fonts during export.
Presentation pres = new Presentation("SomePresentation.pptx"); try { pres.getFontsManager().setPreferRegisteredFontsOverEmbedded(true); pres.save("Presentation-out.pdf", SaveFormat.Pdf); } finally { if (pres != null) pres.dispose(); }
Default is false.
Returns: boolean
setPreferRegisteredFontsOverEmbedded(boolean value)
public final void setPreferRegisteredFontsOverEmbedded(boolean value)
Specifies whether registered fonts should be preferred over embedded fonts with the same font name and style. When enabled, matching embedded fonts are temporarily replaced with corresponding registered fonts during export.
Presentation pres = new Presentation("SomePresentation.pptx"); try { pres.getFontsManager().setPreferRegisteredFontsOverEmbedded(true); pres.save("Presentation-out.pdf", SaveFormat.Pdf); } finally { if (pres != null) pres.dispose(); }
Default is false.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| value | boolean |
getEmbeddedFonts()
public final IFontData[] getEmbeddedFonts()
Returns the fonts embedded in the presentation
Returns: com.aspose.slides.IFontData[]
removeEmbeddedFont(IFontData fontData)
public final void removeEmbeddedFont(IFontData fontData)
Removes the embedded font
Parameters:
| Parameter | Type | Description |
|---|---|---|
| fontData | IFontData |
addEmbeddedFont(IFontData fontData, int embedFontRule)
public final void addEmbeddedFont(IFontData fontData, int embedFontRule)
Adds the embedded font
Parameters:
| Parameter | Type | Description |
|---|---|---|
| fontData | IFontData | |
| embedFontRule | int |
addEmbeddedFont(byte[] fontData, int embedFontRule)
public final void addEmbeddedFont(byte[] fontData, int embedFontRule)
Adds the embedded font
Parameters:
| Parameter | Type | Description |
|---|---|---|
| fontData | byte[] | |
| embedFontRule | int |
replaceFont(IFontData sourceFont, IFontData destFont)
public final void replaceFont(IFontData sourceFont, IFontData destFont)
Replace font in presentation
Parameters:
| Parameter | Type | Description |
|---|---|---|
| sourceFont | IFontData | Source font |
| destFont | IFontData | Destination font |
replaceFont(IFontSubstRule substRule)
public final void replaceFont(IFontSubstRule substRule)
Replace font in presentation using information provided in FontSubstRule
Parameters:
| Parameter | Type | Description |
|---|---|---|
| substRule | IFontSubstRule | Font substitution info |
replaceFont(IFontSubstRuleCollection substRules)
public final void replaceFont(IFontSubstRuleCollection substRules)
Replace font in presentation using information provided in collection of FontSubstRule
Parameters:
| Parameter | Type | Description |
|---|---|---|
| substRules | IFontSubstRuleCollection | Font substitution rules collection |
getFontBytes(IFontData fontData, int fontStyle)
public final byte[] getFontBytes(IFontData fontData, int fontStyle)
Retrieves the byte array representing the font data for a specified font style and font data.
Presentation pres = new Presentation ("Presentation.pptx"); try { // Retrieve all fonts used in the presentation IFontData[] fonts = pres.getFontsManager().getFonts(); // Get the byte array representing the regular style of the first font in the presentation byte[] fontBytes = pres.getFontsManager().getFontBytes(fonts[0], FontStyleType.Regular); } finally { if (pres != null) pres.dispose(); }
Parameters:
| Parameter | Type | Description |
|---|---|---|
| fontData | IFontData | The font data object containing the information about the font IFontData. |
| fontStyle | int | The style of the font for which the data is to be retrieved FontStyleType. |
Returns: byte[] - A byte array containing the font data for the specified font style. If the font data or style is not found, returns null.
getFontEmbeddingLevel(byte[] fontBytes, String fontName)
public final int getFontEmbeddingLevel(byte[] fontBytes, String fontName)
Determines the embedding level of a font from the given byte array and font name.
Presentation pres = new Presentation(pptxFileName); try { // Retrieve all fonts used in the presentation IFontData[] fontDatas = pres.getFontsManager().getFonts(); // Get the byte array representing the regular style of the first font in the presentation byte[] bytes = pres.getFontsManager().getFontBytes(fontDatas[0], FontStyle.Regular); // Determine the embedding level of the font int embeddingLevel = pres.getFontsManager().getFontEmbeddingLevel(bytes, fontDatas[0].getFontName()); } finally { if (pres != null) pres.dispose(); }
Parameters:
| Parameter | Type | Description |
|---|---|---|
| fontBytes | byte[] | The byte array containing the font data. |
| fontName | java.lang.String | The name of the font. |
Returns: int - The embedding level of the specified font.