We were trying to add some fonts for entire presentation as we searched some examples
Masterslide
theme
But some of the namespaces dont work for eg:
// Set slide size for all slides
presentation->get_SlideSize()->SetSize(612.0f, 396.0f, Aspose::Slides::SlideSizeScaleType::EnsureFit);
// Access the master slide
System::SharedPtr<Aspose::Slides::IMasterSlide> masterSlide = presentation->get_Masters()->idx_get(0);
// Access the theme of the master slide
System::SharedPtr<Aspose::Slides::Theme::IFontScheme> fontScheme = masterSlide->get_FontScheme();
// Set the major font (for titles and headings)
System::SharedPtr<Aspose::Slides::IFontData> majorFont = System::MakeObject<Aspose::Slides::FontData>(u"Arial");
fontScheme->get_Major()->set_LatinFont(majorFont);
// Set the minor font (for body text)
System::SharedPtr<Aspose::Slides::IFontData> minorFont = System::MakeObject<Aspose::Slides::FontData>(u"Courier New");
fontScheme->get_Minor()->set_LatinFont(minorFont);
masterslide dont have get_fontscheme . Is there any other way to set the font in entire presentation other then iterating each slide and shapes / or setting individual text font while drawing individually?
To set fonts for an entire presentation in C++, you can utilize the FontsManager class provided by Aspose.Slides. Unfortunately, the IMasterSlide class does not have a get_FontScheme() method, which limits direct access to font settings through the master slide. However, you can still manage fonts effectively by embedding them and applying them to the presentation.
Here’s how you can embed fonts and ensure they are used throughout your presentation:
Embed Fonts: Use the AddEmbeddedFont() method from the FontsManager class to embed your desired fonts into the presentation.
Set Fonts for Slides: After embedding, you can iterate through the slides and set the font for each shape or text frame. While this involves some iteration, it ensures that the fonts are applied correctly.
Here’s a sample code snippet demonstrating how to embed a font and apply it to all slides:
#include <Aspose.Slides.h>
using namespace Aspose::Slides;
void SetFontsForPresentation(System::SharedPtr<Presentation> presentation) {
// Embed a font
System::SharedPtr<FontsManager> fontsManager = presentation->get_FontsManager();
fontsManager->AddEmbeddedFont(u"Arial.ttf", Aspose::Slides::EmbedFontCharacters::AllCharacters);
// Iterate through all slides
for (int i = 0; i < presentation->get_Slides()->get_Count(); i++) {
System::SharedPtr<ISlide> slide = presentation->get_Slides()->idx_get(i);
// Iterate through all shapes in the slide
for (int j = 0; j < slide->get_Shapes()->get_Count(); j++) {
System::SharedPtr<IShape> shape = slide->get_Shapes()->idx_get(j);
if (System::DynamicCast<IAutoShape>(shape)) {
System::SharedPtr<IAutoShape> autoShape = System::DynamicCast<IAutoShape>(shape);
// Set the font for the text frame
if (autoShape->get_TextFrame() != nullptr) {
autoShape->get_TextFrame()->get_TextRange()->get_Paragraphs()->idx_get(0)->get_Portions()->idx_get(0)->get_FontData()->set_Name(u"Arial");
}
}
}
}
}
In this example, the SetFontsForPresentation function embeds the Arial font and applies it to all text portions in the presentation. You can modify the font name and file path as needed.
For more detailed information on working with embedded fonts, you can refer to the Aspose.Slides documentation on embedded fonts here.
This approach ensures that your presentation maintains the desired font style across all slides without needing to set individual text fonts while drawing.
@ashvek,
The font scheme you are looking for is contained in the main theme, which can be extracted from the presentation. You can access the font scheme of a PowerPoint presentation as below.
presentation->get_MasterTheme()->get_FontScheme()
Complete code example:
// Access the font scheme of the presenation
SharedPtr<IFontScheme> fontScheme = presentation->get_MasterTheme()->get_FontScheme();
// Set the major font (for titles and headings)
SharedPtr<IFontData> majorFont = MakeObject<FontData>(u"Arial");
fontScheme->get_Major()->set_LatinFont(majorFont);
// Set the minor font (for body text)
SharedPtr<IFontData> minorFont = MakeObject<FontData>(u"Courier New");
fontScheme->get_Minor()->set_LatinFont(minorFont);