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

MethodDescription
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.
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:

ParameterTypeDescription
valueIFontSubstRuleCollection

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:

ParameterTypeDescription
valueIFontFallBackRulesCollection

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.

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:

ParameterTypeDescription
fontDataIFontData

addEmbeddedFont(IFontData fontData, int embedFontRule)

public final void addEmbeddedFont(IFontData fontData, int embedFontRule)

Adds the embedded font

Parameters:

ParameterTypeDescription
fontDataIFontData
embedFontRuleint

addEmbeddedFont(byte[] fontData, int embedFontRule)

public final void addEmbeddedFont(byte[] fontData, int embedFontRule)

Adds the embedded font

Parameters:

ParameterTypeDescription
fontDatabyte[]
embedFontRuleint

replaceFont(IFontData sourceFont, IFontData destFont)

public final void replaceFont(IFontData sourceFont, IFontData destFont)

Replace font in presentation

Parameters:

ParameterTypeDescription
sourceFontIFontDataSource font
destFontIFontDataDestination font

replaceFont(IFontSubstRule substRule)

public final void replaceFont(IFontSubstRule substRule)

Replace font in presentation using information provided in FontSubstRule

Parameters:

ParameterTypeDescription
substRuleIFontSubstRuleFont substitution info

replaceFont(IFontSubstRuleCollection substRules)

public final void replaceFont(IFontSubstRuleCollection substRules)

Replace font in presentation using information provided in collection of FontSubstRule

Parameters:

ParameterTypeDescription
substRulesIFontSubstRuleCollectionFont 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], FontStyle.Regular);
 } finally {
     if (pres != null) pres.dispose();
 }

Parameters:

ParameterTypeDescription
fontDataIFontDataThe font data object containing the information about the font FontData.
fontStyleintThe style of the font for which the data is to be retrieved FontStyle.

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:

ParameterTypeDescription
fontBytesbyte[]The byte array containing the font data.
fontNamejava.lang.StringThe name of the font.

Returns: int - The embedding level of the specified font.