Changing fonts in the MainMaster

I would like to modify the font size for the title on a HeaderSlide, the font class does not appear to have a size property? I don’t want to alter the title font on every slide since that will break the powerpoint template functionality.

Dear Trond,

Before, I could tell you, how to change it through Master Slide. You can do it using another way.

Remember, Slide.Placeholders[0] is a title placeholder, you can convert it to TextHolder and then change all the portions’ Portion.FontIndex property to the newly added font index.

Here is a code example. Source code, source presentation and output presentation is attached.

Presentation srcPres = new Presentation(@"c:\ch01.ppt");

FontEntity fntEntNew = new FontEntity(srcPres, srcPres.Fonts[0]);
fntEntNew.FontName = "Comic Sans MS";
int fntEntNewIdx = srcPres.Fonts.Add(fntEntNew);

for (int i = 1; i <= srcPres.Slides.LastSlidePosition; i++)
{
    Slide sld = srcPres.GetSlideByPosition(1);
    if (sld.Placeholders[0] != null)
    {
        TextHolder thld = sld.Placeholders[0] as TextHolder;
        foreach (Paragraph para in thld.Paragraphs)
        {
            foreach (Portion port in para.Portions)
            {
                port.FontIndex = fntEntNewIdx;
            } //inner foreach
        }//outer foreach
    }
}

srcPres.Write(@"c:\out.ppt");

Thanks again!

How do I change the size of the font in the fonts collection? If i create a new font enity like your example:

FontEntity fntEntNew = new FontEntity(srcPres, srcPres.Fonts[0]);

I’ve not found a way to set the font size on the fntEntNew?

Trond

Dear Trond,

You can change the height of the font using Portion.FontHeight property. The other relevant properties are Portion.FontBold, Portion.FontItalic and Portion.FontUnderline.

Please refer to Aspose.Slides Help for more information. It is installed on your computer with Aspose.Slides installer.

Changing font on the portion will break the template functionality in PowerPoint. Why is there no FontHeight in the fontentity class?

Dear Trond,

Font name and height are two different things, so they are defined separately from each other.

A set of characters can have a single font but different heights, see the example below

Times New Roman Font

It shouldn’t break the functionality, if it there is any such problem, then please report it for investigation and a fix.

Thanks for beeing patient with me. I’m thinking we’re not on the same page here so I’ll try to explain in more detail what I would like to do or how I want my slide to work.

If you create a new presentation in powerpoint you should get a slide with a titel and subtitle where it says “Click to add title” and “Click to add subtitle”. Then go to the View menu, Master and Slide Master. Here you can set the font size for the title where it says “Click to edit Master title style” to for example 10. Then when you go back to the slide the “Click to add title” text has changed font size to 10. So using the master and setting the font size in the master enables the user to apply different designs using the design button ,usually located on the toolbar, to change to another design which contains another master. Doing this the title will change to the font and fontsize defined in that master. However if you change the fontsize of the title text to say 16 directly in the slide and then try to change the design the font stays at 16 even if the master in the choosen design says for example 24. And my experience with aspose.slides is exactly this. If I set the fontheight of a portion as you describe and a user wants to apply their own design the fontsize does not follow the users design. Since some users don’t apply their own designs I would like to be able to define a default design with a master where the fontsize is not the default size used in powerpoint.

Is it possible in aspose.slides to get the functionality I’m describing?

Trond

Dear Trond,

Currently, Aspose.Slides can only read style settings from Masters but cannot modify them. The support for it will be added later on, but not in near future.