How to Get the Correct Fill of a Shape from a PowerPoint Presentation in C++?

Hi,

We are using Aspose.slides cpp 25.4 for extracting properties. For attached ppt
ATest_1.pptx.zip (22.2 KB)
there are 2 shapes both having fill as Slide Background Fill… but Aspose incorrectly returns fill as Solid for first shape and Gradient for the other. Fill Color is also coming as blue for these shapes.

Code snippet:

auto fillFormat = shape->get_FillFormat();
    SharedPtr<IFillFormatEffectiveData> fillFormatEffective = fillFormat->GetEffective();
    Aspose::Slides::FillType fillType = fillFormatEffective->get_FillType();

   if(fillType == FillType::Solid)
            Color fillColor = fillFormatEffective->get_SolidFillColor();

@pankajku

It seems that you are encountering issues with extracting the correct background fill properties of shapes in a PowerPoint presentation using Aspose.Slides for C++. Specifically, you mentioned that both shapes are set to use the slide background fill, yet the library is returning incorrect fill types (Solid for one shape and Gradient for another).

To address this issue, you can utilize the set_UseBackgroundFill method for your shapes. This method allows you to specify whether the shape should use the slide’s background fill instead of its own fill format. Here’s how you can implement it:

  1. Ensure that you are correctly setting the UseBackgroundFill property for both shapes.
  2. After setting this property, retrieve the effective fill format to ensure that it reflects the background fill correctly.

Here’s an example code snippet that demonstrates how to set the background fill for a shape:

// Assuming 'shape' is your shape object
shape->set_UseBackgroundFill(true); // Enable background fill

// Now retrieve the effective fill format
auto fillFormatEffective = shape->get_FillFormat()->GetEffective();
Aspose::Slides::FillType fillType = fillFormatEffective->get_FillType();

if (fillType == FillType::Solid) {
    Color fillColor = fillFormatEffective->get_SolidFillColor();
    // Use fillColor as needed
} else if (fillType == FillType::Gradient) {
    // Handle gradient fill if necessary
}

Make sure to check the background settings of the slide itself, as the effective fill type of the shape can depend on the background settings of the slide it resides on. If the slide’s background is set to a specific fill type, that may influence the fill type returned for the shape.

If you continue to experience discrepancies, please ensure that you are using the latest version of the Aspose.Slides library, as updates may include bug fixes related to fill formats.

For further details, you can refer to the Aspose.Slides Documentation regarding background fills and their properties.

If you have any more questions or need further assistance, feel free to ask!

The query is how to extract the correct fill of shape

@pankajku,
Thank you for reporting on the issue. I’ve reproduced the problem with retrieving the fill of the shapes from the PowerPoint presentation. We are sorry that you encountered this problem.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESCPP-4035

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

This is required on priority basis. I have raised a ticket with Paid support.

@pankajku,
Thank you for the information. The request will be prioritized accordingly.

@pankajku,
The issues you found earlier (filed as SLIDESCPP-4035) have been resolved in Aspose.Slides for C++ 25.6 (NuGet (x64), NuGet (x86), Windows, Linux, macOS).
You can check all fixes on the Release Notes page.
You can also find the latest version of our library on the Product Download page.

With Aspose.Slides for C++ 25.6, please try using the following code example:

auto presentation = MakeObject<Presentation>(u"ATest_1.pptx");
for (auto&& shape : presentation->get_Slide(0)->get_Shapes())
{
    auto fillFormat = shape->get_FillFormat()->GetEffective();
    auto fillType = fillFormat->get_FillType();

    Console::WriteLine(u"{0}:", shape->get_Name());

    if (ObjectExt::Is<IAutoShape>(shape))
    {
        auto autoShape = ExplicitCast<IAutoShape>(shape);
        Console::WriteLine(u"\tUse slide background: {0}", autoShape->get_UseBackgroundFill());
    }

    Console::WriteLine(u"\tFill type: {0}", ObjectExt::ToString(fillType));

    if (fillType == FillType::Solid)
    {
        auto fillColor = fillFormat->get_SolidFillColor();
        Console::WriteLine(u"\t{0}", fillColor);
    }
}

presentation->Dispose();

The result after the fix:

Rectangle 8:
    Use slide background: True
    Fill type: Solid
    Color [A=255, R=255, G=255, B=255]
Rounded Rectangle 11:
    Use slide background: True
    Fill type: Solid
    Color [A=255, R=255, G=255, B=255]

This means that the “Slide background fill” is enabled, and calculating the effective fill (taken from the slide background) shows that it is white.

IAutoShape::get_UseBackgroundFill() returns true if the “Slide background fill” option is selected for the shape; otherwise, it returns false. In the PowerPoint UI, all fill options—including “Slide background fill”—are presented in a single list. In Aspose.Slides, get_UseBackgroundFill() specifically indicates whether the “Slide background fill” option is enabled; if it isn’t, a Solid, Gradient, or other fill is applied.