Text Extends Beyond Circle Boundaries When Converting Shape to Image in C++

Hi,

We are using Aspose.slides for c++
For attached ppt, there is sun image with text fully inside the circle. Using below code to generate thumbnail, the text in thumbnail goes outside circle boundaries.

shape->GetImage()

Attached is ppt and thumbnail image.
ppt_image_1.png (28.7 KB)

@pankajku

It appears you are encountering an issue with thumbnail generation where the text extends beyond the circular boundaries of the sun image. This typically occurs due to improper scaling or rendering settings during the thumbnail creation process.

Cause: The text overflow is likely a result of the scaling factors or the method used to generate the thumbnail not respecting the shape’s dimensions.

Solution: To resolve this issue, please follow these steps:

  1. Check Scaling Factors: Ensure that you are using appropriate scaling factors when generating the thumbnail. Adjust the scale values to better fit the content within the shape.

  2. Use Shape Bounds: Instead of relying on the default method, utilize the shape’s bounds for generating the thumbnail. This will help ensure that the thumbnail adheres to the shape’s dimensions.

Here’s a code snippet that demonstrates how to generate a thumbnail using the shape’s bounds:

auto presentation = MakeObject<Presentation>(u"YourPresentation.pptx");
auto slide = presentation->get_Slide(0);
auto shape = slide->get_Shape(0); // Adjust the index as needed

// Define the bounds and scaling
auto bounds = ShapeThumbnailBounds::Appearance; // Use appearance bounds
auto scale = 1.0f; // Adjust scaling as necessary

// Generate the thumbnail
auto image = shape->GetImage(bounds, scale, scale);
image->Save(u"Shape_thumbnail_out.png", ImageFormat::Png);
image->Dispose();
presentation->Dispose();
  1. Adjust Text Properties: If the text continues to overflow, modify the text properties such as font size or wrapping settings within the shape to ensure it fits properly.

Next Steps: Please implement these suggestions and check if the issue is resolved. If you continue to experience difficulties, feel free to reach out for further assistance.

Thank you, and I look forward to your feedback!

@pankajku,
Thank you for contacting free support.

Unfortunately, you forgot to attach the presentation file. Could you please share it?

wrong thumbnail_choladeck.pptx.zip (9.1 MB)

Tried with below sample as well:

auto bounds = ShapeThumbnailBounds::Appearance; // Use appearance bounds
auto scale = 1.0f; // Adjust scaling as necessary

// Generate the thumbnail
auto image = shape->GetImage(bounds, scale, scale);

Same issue

@pankajku,
Thank you for the presentation file. The text extends beyond the circle boundaries when converting the shape to an image because the Aptos font used in the presentation was missing on the operating system where the code ran, so it was substituted with Arial.

You can check the font substitution using the code below.

auto presentation = MakeObject<Presentation>(u"wrong thumbnail_choladeck.pptx");

auto fontSubstitutions = presentation->get_FontsManager()->GetSubstitutions();
for (auto fontSubstitution : fontSubstitutions)
{
    Console::WriteLine(u"Original Font: {0}, Substituted Font: {1}",
        fontSubstitution->get_OriginalFontName(),
        fontSubstitution->get_SubstitutedFontName());
}

presentation->Dispose();

To resolve the issue, you should install the Aptos font on the operating system or load it as an external font before converting the shape to an image, as shown below.

auto folderPaths = MakeObject<Array<String>>(1, u"path_to_folder_with_fonts");
FontsLoader::LoadExternalFonts(folderPaths);

Custom Font in C++|Aspose.Slides Documentation
FAQs|Aspose.Slides Documentation

Can you please explain LoadExternalFonts working in detail? I have read the documentation and am still not clear what path_to_folder_with_fonts should be?

@pankajku,
The LoadExternalFonts method lets you add extra folders at runtime to search for fonts beyond the system directories. For example, if you have a folder C:\MyFonts on Windows containing the Aptos font mentioned above, you can add it to the font search path as follows:

auto folderPaths = MakeObject<Array<String>>(1, u"C:\MyFonts");

Then, when you convert the presentation slide to an image, Aspose.Slides will locate the font and render the text correctly.

@andrey.potapov How do I search where Aptos or other fonts internal to microsoft powerpoint is? How do I search the paths in mac and win?
Also, FontsLoader::LoadExternalFonts(folderPaths); this should be called before calling shape->GetImage(bounds, scale, scale);?

@pankajku,

In your case, the Aptos font is missing in the operating system on which the code was executed.

You can use the GetFontFolders method of the FontsLoader class to locate all the font folders Aspose.Slides uses at runtime.

auto fontFolders = FontsLoader::GetFontFolders();
for(auto fontFolder : fontFolders) {
    Console::WriteLine(fontFolder);
}

Yes, you are right.

@andrey.potapov

auto fontFolders = FontsLoader::GetFontFolders();
for(auto fontFolder : fontFolders) {
  FontsLoader::LoadExternalFonts(fontFolder);
}
auto img = shape->GetImage();

this should work?
also, what needs to be added in header for FontsLoader?

@pankajku,
No, you shouldn’t load fonts from the folders returned by GetFontFolders. Aspose.Slides handles this automatically.

You need to obtain the Aptos font, place it in a local folder, and call LoadExternalFonts on that folder. Then, the GetImage method will work correctly.

Please use the following header:

#include <DOM/Fonts/FontsLoader.h>

A post was split to a new topic: Aspose.Slides for C++: LoadExternalFonts Call Is Very Slow