Adding Fonts

How can I add a font to the presentation that is not already present in the presentation’s font collection?

Dear Chrons,

You can clone any existing font and change everything.
As example TextDemo has function GetFontId.
It looks for font by his name and add new one if can’t find it.

static int GetFontId(Presentation ppt, string fontName)
{
// Find font by name. It doesn’t check anything except font name
for (int i = 0; i < ppt.Fonts.Count; i++)
if (fontName.CompareTo(ppt.Fonts[ i ].FontName) == 0)
return i;
// Add new font by cloning first font of the presentation,
// change necessary values and return new Id
FontEntity newFont = new FontEntity(ppt, ppt.Fonts[0]);
newFont.FontName = fontName;
return ppt.Fonts.Add(newFont);
}

alcrus,

I tied that with negative results. The GetFontId method does create a new FontEntity and sets it’s name equal to whatever I pass in as fontName and it returns the newly created font index; however when viewed in the presentation the font appears to be Arial. Yet when the text in PowerPoint is highlighted the font name on the toolbar is blank.

// My Sample Code:
Slide slide1 = GetSlideByPosition(pres, 1);
Shape shape = slide1.Shapes[0];
Paragraph para = shape.TextFrame.Paragraphs[0];

Portion port = para.Portions[0];
port.FontItalic = true;
port.FontShadow = true;
port.FontColor = Color.Green;
port.FontHeight = 55;
port.FontIndex = (short)GetFontId(pres, "Wing Dings");

Thanks,
Chrons

Dear Chrons,

Did you try “Wingdings” font name instead of “Wing Dings”?
If font not found then MS PowerPoint uses standard font substitution.

By the way, if you really need to add Wingdings font you should define
also correct values for Font.Charset and Font.Family.

int fontId = GetFontId(pres, “Wingdings”);
FontEntity font = pres.Fonts[fontId];
font.CharSet = FontCharSet.SYMBOL_CHARSET;
font.Family = FontFamily.DONTCARE;
sh.TextFrame.Paragraphs[0].Portions[0].FontIndex = (short)fontId;

I can still not get this to work. Are there any plans to possibly make this into an enum type instead of an index?
For example:

sh.TextFrame.Paragraphs[0].Portions[0].FontType = FontType.WingDings;

By the way I have also found what maybe a bug. In past releases of Aspose.PowerPoint I could use

pres.Masters[0].Background.FillFormat.BackColor = Color.Plum;

to set the background color of the slide master. Now this no longer works. However I can use

pres.Masters[0].Background.FillFormat.ForeColor = Color.Plum;

to achieve the intended results.

Dear Chrons,

Thousands of fonts exist in the world and anybody can create new fonts with any name.
How you think we can do enums for that?
I’d suggest to read msdn (or some other examples and documents on Internet) for better understanding how to work with fonts in Windows.

We had a bug with FillFormat in old versions. BackColor and ForeColor changed the same value in presentation. Now it works correctly.