C++에서 PowerPoint 도형 서식 지정

소개

PowerPoint에서 도형의 윤곽선, 채우기 및 효과를 조정하여 도형을 서식 지정합니다. Aspose.Slides for C++를 사용하면 투명도, 회전 및 3D 서식 지정 등을 프로그래밍 방식으로 제어할 수 있습니다.

PowerPoint의 도형 서식 옵션

Aspose.Slides for C++는 PowerPoint에서 사용할 수 있는 동일한 옵션을 사용하여 도형을 서식 지정할 수 있는 인터페이스와 메서드를 제공합니다.

선 서식 지정

형태의 윤곽선을 제어하려면 IShape::get_LineFormat를 사용합니다. 이 예제는 파란색 점선 윤곽선을 가진 채우지 않은 사각형을 만듭니다. ILineFormat::set_Style은 굵고 얇은 복합선을 선택하고, ILineFormat::set_Width은 너비를 7포인트로 설정하며, ILineFormat::set_DashStyle는 대시 패턴을 선택합니다.

#include <DOM/FillType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/ILineFillFormat.h>
#include <DOM/ILineFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/LineDashStyle.h>
#include <DOM/LineStyle.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>

using namespace Aspose::Slides;
using namespace System;
using namespace Aspose::Slides::Export;
using namespace System::Drawing;

auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);

auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 50, 150, 75);
shape->get_FillFormat()->set_FillType(FillType::NoFill);
shape->get_LineFormat()->set_Style(LineStyle::ThickThin);
shape->get_LineFormat()->set_Width(7);
shape->get_LineFormat()->set_DashStyle(LineDashStyle::Dash);
shape->get_LineFormat()->get_FillFormat()->set_FillType(FillType::Solid);
shape->get_LineFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Blue());

presentation->Save(u"formatted_lines.pptx", SaveFormat::Pptx);
presentation->Dispose();

결과:

프레젠테이션의 서식이 지정된 선들

사용자 지정 선 대시 패턴 설정

미리 정의된 선 스타일이 필요한 대시 길이와 간격을 제공하지 않을 때, 예를 들어 브랜드 윤곽선이나 기술 다이어그램에 사용하려면 ILineFormat::set_CustomDashPattern을 사용합니다. 패턴을 할당하면 대시 스타일이 자동으로 LineDashStyle::Custom으로 변경됩니다.

배열 항목은 대시와 간격 길이가 교대로 나타나며 대시부터 시작합니다. 각 값은 선 너비의 배수입니다: { 4, 2 }를 너비 3포인트에 적용하면 12포인트 대시와 6포인트 간격이 생성됩니다. 유한하고 음수가 아닌 값 쌍을 사용하여 완전한 대시‑간격 세그먼트를 정의합니다. 예제에서는 모든 대시와 간격이 보이도록 양수를 사용했습니다.

이 예제는 동일한 길이와 평면 캡을 가진 파란색 선 5개를 만듭니다. 처음 세 개는 3포인트 너비에서 패턴을 비교하고, 네 번째는 첫 번째 패턴을 두 배 너비로 반복하여 대시와 간격 길이 모두 두 배로 늘립니다. 다섯 번째는 사용자 지정 패턴에서 실선으로 전환합니다.

#include <DOM/FillType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/ILineFillFormat.h>
#include <DOM/ILineFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ISlideSize.h>
#include <DOM/LineArrowheadStyle.h>
#include <DOM/LineCapStyle.h>
#include <DOM/LineDashStyle.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <DOM/SlideSizeScaleType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>
#include <system/array.h>
#include <array>

using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;

auto presentation = MakeObject<Presentation>();
presentation->get_SlideSize()->SetSize(600, 300, SlideSizeScaleType::DoNotScale);
auto slide = presentation->get_Slide(0);

const auto patterns = std::array<ArrayPtr<float>, 5>{
    MakeArray<float>({ 4, 2 }),
    MakeArray<float>({ 1, 2 }),
    MakeArray<float>({ 6, 2, 1, 2 }),
    MakeArray<float>({ 4, 2 }),
    MakeArray<float>({ 4, 2 })
};

for (auto i = 0; i < patterns.size(); i++)
{
    auto line = slide->get_Shapes()->AddAutoShape(ShapeType::Line, 50, 50 + i * 50, 500, 0);
    line->get_LineFormat()->set_Width(i == 3 ? 6 : 3);
    line->get_LineFormat()->get_FillFormat()->set_FillType(FillType::Solid);
    line->get_LineFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_DarkBlue());
    line->get_LineFormat()->set_CapStyle(LineCapStyle::Flat);
    line->get_LineFormat()->set_BeginArrowheadStyle(LineArrowheadStyle::None);
    line->get_LineFormat()->set_EndArrowheadStyle(LineArrowheadStyle::None);
    line->get_LineFormat()->set_CustomDashPattern(patterns[i]);
}

// Return the last line to a solid style.
slide->get_Shape(4)->get_LineFormat()->set_DashStyle(LineDashStyle::Solid);

presentation->Save(u"custom_dash_patterns.pptx", SaveFormat::Pptx);
presentation->Dispose();

미리 정의된 점선 스타일로 다시 전환하려면 LineDashStyle::Dash을 ILineFormat::set_DashStyle에 전달하십시오. 선택된 스타일이 선의 외관을 제어합니다.

PowerPoint에서 위에서 아래 순서대로 결과: {4, 2}, 3 pt; {1, 2}, 3 pt; {6, 2, 1, 2}, 3 pt; {4, 2}, 6 pt; 및 Solid, 3 pt.

Three custom dash patterns, a wider line using the first pattern, and a solid line in PowerPoint

선 캡 설정

열린 선의 끝을 설정하려면 ILineFormat::set_CapStyle를 사용합니다. LineCapStyle 열거형은 세 가지 명시적 캡 스타일을 제공합니다:

  • Flat: 스트로크가 끝점에서 멈춥니다.
  • Round: 반원형 캡이 선 너비의 절반만큼 끝점 너머로 연장됩니다.
  • Square: 정사각형 캡이 선 너비의 절반만큼 끝점 너머로 연장됩니다.

열거형에는 NotDefined도 포함되어 있는데, 이는 캡 스타일이 명시적으로 할당되지 않았음을 의미합니다.

캡은 선 끝에 기호를 추가하는 화살촉과 선 세그먼트 사이 모서리를 제어하는 조인과는 다릅니다. 이 예제는 ILineFormat::set_BeginArrowheadStyle와 ILineFormat::set_EndArrowheadStyle를 사용해 화살촉을 비활성화하여 캡 모양만 비교합니다.

다음 예제는 너비가 20포인트인 세 개의 수평 선을 만들며, 위에서 아래 순서대로 평면, 원형, 정사각형 캡을 사용합니다. 끝점은 같은 수평 좌표를 가지지만 원형 및 정사각형 캡은 각 끝점에서 10포인트씩 연장됩니다.

#include <DOM/FillType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/ILineFillFormat.h>
#include <DOM/ILineFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ISlideSize.h>
#include <DOM/LineArrowheadStyle.h>
#include <DOM/LineCapStyle.h>
#include <DOM/LineDashStyle.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <DOM/SlideSizeScaleType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>
#include <array>

using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;

auto presentation = MakeObject<Presentation>();
presentation->get_SlideSize()->SetSize(500, 240, SlideSizeScaleType::DoNotScale);
auto slide = presentation->get_Slide(0);

const auto capStyles = std::array<LineCapStyle, 3>{ LineCapStyle::Flat, LineCapStyle::Round, LineCapStyle::Square };

for (auto i = 0; i < capStyles.size(); i++)
{
    auto line = slide->get_Shapes()->AddAutoShape(ShapeType::Line, 100, 50 + i * 70, 300, 0);
    line->get_LineFormat()->set_Width(20);
    line->get_LineFormat()->get_FillFormat()->set_FillType(FillType::Solid);
    line->get_LineFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_DarkBlue());
    line->get_LineFormat()->set_DashStyle(LineDashStyle::Solid);
    line->get_LineFormat()->set_CapStyle(capStyles[i]);
    line->get_LineFormat()->set_BeginArrowheadStyle(LineArrowheadStyle::None);
    line->get_LineFormat()->set_EndArrowheadStyle(LineArrowheadStyle::None);
}

presentation->Save(u"line_caps.pptx", SaveFormat::Pptx);
presentation->Dispose();

PowerPoint에서 위에서 아래 순서대로 결과: Flat, Round, Square.

Flat, round, and square caps on identical thick lines in PowerPoint

도형 선에 스케치 효과 적용

스케치 효과는 도형 선을 손으로 그린 것처럼 보이게 합니다. IShape::get_LineFormat를 사용해 선 설정에 접근하고, ILineFormat::get_SketchFormat으로 스케치 설정에 접근한 다음, ISketchFormat::set_SketchType을 사용해 LineSketchType 열거형에서 값을 선택합니다.

다음 C++ 코드에서는 LineSketchType::Curved 효과를 적용하고, 명시적으로 할당된 값을 읽으며, LineSketchType::None으로 효과를 제거하는 방법을 보여줍니다:

#include <DOM/IAutoShape.h>
#include <DOM/ILineFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISketchFormat.h>
#include <DOM/ISlide.h>
#include <DOM/LineSketchType.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <system/console.h>
#include <system/smart_ptr.h>

using namespace Aspose::Slides;
using namespace System;

auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);

auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 50, 200, 100);

auto sketchFormat = shape->get_LineFormat()->get_SketchFormat();
sketchFormat->set_SketchType(LineSketchType::Curved);
auto explicitSketchType = sketchFormat->get_SketchType();
Console::WriteLine(u"Explicit sketch type: {0}", explicitSketchType);
sketchFormat->set_SketchType(LineSketchType::None);

presentation->Dispose();

ISketchFormat::get_SketchType이 반환하는 값은 도형에 직접 할당된 설정을 나타냅니다. 선 서식이 테마, 마스터 슬라이드 또는 레이아웃 슬라이드에서 상속될 수 있는 경우, ILineFormat::GetEffective을 사용하고, ILineFormatEffectiveData::get_SketchFormat에 접근한 뒤, ISketchFormatEffectiveData::get_SketchType을 읽습니다. 유효 값은 상속이 해결된 후 실제 적용된 서식을 반영합니다. 이 예제는 첫 번째 슬라이드에 최소 하나의 도형이 있는 기존 프레젠테이션이 필요하며 두 값을 모두 출력합니다:

#include <DOM/ILineFormat.h>
#include <DOM/ILineFormatEffectiveData.h>
#include <DOM/IShape.h>
#include <DOM/ISketchFormat.h>
#include <DOM/ISketchFormatEffectiveData.h>
#include <DOM/ISlide.h>
#include <DOM/LineSketchType.h>
#include <DOM/Presentation.h>
#include <system/console.h>
#include <system/smart_ptr.h>

using namespace Aspose::Slides;
using namespace System;

auto presentation = MakeObject<Presentation>(u"presentation.pptx");
auto shape = presentation->get_Slide(0)->get_Shape(0);

auto lineFormat = shape->get_LineFormat();
auto explicitSketchType = lineFormat->get_SketchFormat()->get_SketchType();
auto effectiveLineFormat = lineFormat->GetEffective();
auto effectiveSketchType = effectiveLineFormat->get_SketchFormat()->get_SketchType();

Console::WriteLine(u"Explicit sketch type: {0}", explicitSketchType);
Console::WriteLine(u"Effective sketch type: {0}", effectiveSketchType);
presentation->Dispose();

조인 스타일 서식 지정

다음은 세 가지 조인 유형 옵션입니다:

  • Round
  • Miter
  • Bevel

조인 스타일은 두 윤곽선 세그먼트가 코너에서 어떻게 만나느냐를 제어합니다. 둥근 코너에는 Round, 날카로운 코너에는 Miter, 평평한 코너에는 Bevel을 사용합니다.

The join style in the presentation

이 예제는 파란색 윤곽선(너비 15포인트)을 가진 검은색 사각형 세 개를 만들고, 각각 LineJoinStyle의 miter, bevel, round 값을 ILineFormat::set_JoinStyle에 설정하여 코너가 어떻게 그려지는지 비교합니다.

#include <DOM/FillType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/ILineFillFormat.h>
#include <DOM/ILineFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/LineJoinStyle.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>

using namespace Aspose::Slides;
using namespace System;
using namespace Aspose::Slides::Export;
using namespace System::Drawing;

auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);

auto miterShape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 20, 20, 150, 75);
auto bevelShape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 210, 20, 150, 75);
auto roundShape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 20, 135, 150, 75);

miterShape->get_FillFormat()->set_FillType(FillType::Solid);
miterShape->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Black());
bevelShape->get_FillFormat()->set_FillType(FillType::Solid);
bevelShape->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Black());
roundShape->get_FillFormat()->set_FillType(FillType::Solid);
roundShape->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Black());

miterShape->get_LineFormat()->set_Width(15);
bevelShape->get_LineFormat()->set_Width(15);
roundShape->get_LineFormat()->set_Width(15);

miterShape->get_LineFormat()->get_FillFormat()->set_FillType(FillType::Solid);
miterShape->get_LineFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Blue());
bevelShape->get_LineFormat()->get_FillFormat()->set_FillType(FillType::Solid);
bevelShape->get_LineFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Blue());
roundShape->get_LineFormat()->get_FillFormat()->set_FillType(FillType::Solid);
roundShape->get_LineFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Blue());

miterShape->get_LineFormat()->set_JoinStyle(LineJoinStyle::Miter);
bevelShape->get_LineFormat()->set_JoinStyle(LineJoinStyle::Bevel);
roundShape->get_LineFormat()->set_JoinStyle(LineJoinStyle::Round);

miterShape->get_TextFrame()->set_Text(u"Miter Join Style");
bevelShape->get_TextFrame()->set_Text(u"Bevel Join Style");
roundShape->get_TextFrame()->set_Text(u"Round Join Style");

presentation->Save(u"join_styles.pptx", SaveFormat::Pptx);
presentation->Dispose();

날카로운 코너에서 마이터 조인 제한

LineJoinStyle::Miter로 설정된 ILineFormat::set_JoinStyle와 함께 ILineFormat::set_MiterLimit을 사용하여 날카로운 코너가 얼마나 멀리 뻗을 수 있는지를 제한합니다.

제한은 조인의 내부와 외부 코너 사이 거리와 선 너비의 비율입니다. 예를 들어 8값은 마이터 길이가 선 너비의 최대 8배까지 허용된다는 의미이며, 포인트 단위 측정이 아닙니다. 코너가 제한을 초과하면 PowerPoint는 해당 코너에서 베벨 조인을 사용합니다. 제한값을 크게 지정하면 더 날카로운 포인트가 가능해집니다. 이 설정은 마이터 조인에만 영향을 미치며, 코너가 두 제한 범위 내에 있으면 눈에 보이는 변화는 없습니다.

이 예제는 너비 20포인트 윤곽선을 가진 두 개의 동일한 비채우기 삼각형을 만듭니다. 왼쪽 삼각형은 제한값 2를 사용하고, 오른쪽은 8을 사용합니다. 각 삼각형은 너비 80포인트, 높이 160포인트이며, 상단 코너의 마이터‑길이 대 선 너비 비율은 약 4.12입니다. 따라서 PowerPoint는 왼쪽 꼭짓점을 베벨 처리하고 오른쪽 꼭짓점은 유지합니다.

#include <DOM/FillType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/ILineFillFormat.h>
#include <DOM/ILineFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ISlideSize.h>
#include <DOM/LineJoinStyle.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <DOM/SlideSizeScaleType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>
#include <array>

using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;

auto presentation = MakeObject<Presentation>();
presentation->get_SlideSize()->SetSize(500, 320, SlideSizeScaleType::DoNotScale);
auto slide = presentation->get_Slide(0);

const auto miterLimits = std::array<float, 2>{ 2.0f, 8.0f };

for (auto i = 0; i < miterLimits.size(); i++)
{
    auto triangle = slide->get_Shapes()->AddAutoShape(ShapeType::Triangle, 90 + i * 240, 110, 80, 160);
    triangle->get_FillFormat()->set_FillType(FillType::NoFill);
    triangle->get_LineFormat()->set_Width(20);
    triangle->get_LineFormat()->get_FillFormat()->set_FillType(FillType::Solid);
    triangle->get_LineFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_DarkBlue());
    triangle->get_LineFormat()->set_JoinStyle(LineJoinStyle::Miter);
    triangle->get_LineFormat()->set_MiterLimit(miterLimits[i]);
}

presentation->Save(u"miter_limits.pptx", SaveFormat::Pptx);
presentation->Dispose();

PowerPoint에서 결과: 왼쪽은 Miter limit 2, 오른쪽은 miter limit 8.

A beveled apex with miter limit 2 and a pointed apex with miter limit 8 in PowerPoint

그라디언트 채우기

그라디언트 채우기는 도형 전체에 걸쳐 색상을 혼합합니다. 이 예제는 빨간색에서 보라색으로 45도 각도의 선형 그라디언트를 사용해 타원을 채우며, 이를 위해 IFillFormat::get_GradientFormat를 사용합니다. IGradientStopCollection::Add 메서드는 그라디언트 시작점(0)과 끝점(1)에 색상 정지를 배치합니다. 기존 정지를 지우면 두 색상만 사용됩니다.

#include <DOM/FillType.h>
#include <DOM/GradientShape.h>
#include <DOM/IAutoShape.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/IGradientFormat.h>
#include <DOM/IGradientStopCollection.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <DOM/PresetColor.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>

using namespace Aspose::Slides;
using namespace System;
using namespace Aspose::Slides::Export;
using namespace System::Drawing;

auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);

auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Ellipse, 50, 50, 150, 75);
shape->get_FillFormat()->set_FillType(FillType::Gradient);
shape->get_FillFormat()->get_GradientFormat()->set_GradientShape(GradientShape::Linear);
shape->get_FillFormat()->get_GradientFormat()->set_LinearGradientAngle(45);
shape->get_FillFormat()->get_GradientFormat()->get_GradientStops()->Clear();
shape->get_FillFormat()->get_GradientFormat()->get_GradientStops()->Add(1.0f, PresetColor::Purple);
shape->get_FillFormat()->get_GradientFormat()->get_GradientStops()->Add(0.0f, PresetColor::Red);

presentation->Save(u"gradient_fill.pptx", SaveFormat::Pptx);
presentation->Dispose();

결과:

The ellipse with gradient fill

그라디언트가 내보낸 이미지에서 PowerPoint와 다르게 보이는 경우, 그라디언트 렌더링 스타일 선택 문서를 참조하십시오. 프레젠테이션에 저장된 그라디언트 채우기를 변경하지 않고도 렌더링 스타일을 선택할 수 있습니다.

선형 그라디언트 각도 설정

IGradientFormat::set_LinearGradientAngle를 사용해 GradientShape::Linear 채우기의 방향을 제어합니다. 각도는 도 단위이며 시계 방향으로 증가합니다: 0은 왼쪽→오른쪽, 90은 위→아래, 180은 오른쪽→왼쪽, 270은 아래→위입니다. 소수 각도도 지원됩니다. [0, 360) 범위를 벗어나는 유한 각도는 한 바퀴로 정규화됩니다; 예를 들어 -45는 315가 되고 360은 0이 됩니다.

이 예제는 빨강, 초록, 파랑 정지를 각각 위치 0, 0.5, 1에 동일하게 배치한 직사각형 6개를 만들며, 스케일을 비활성화해 각도를 사각형 비율과 무관하게 비교합니다. 각도는 왼쪽→오른쪽 순서대로 첫 번째 행이 0, 45, 90이고 두 번째 행이 135, 180, 270입니다.

#include <DOM/FillType.h>
#include <DOM/GradientShape.h>
#include <DOM/IAutoShape.h>
#include <DOM/IFillFormat.h>
#include <DOM/IGradientFormat.h>
#include <DOM/IGradientStopCollection.h>
#include <DOM/ILineFillFormat.h>
#include <DOM/ILineFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ISlideSize.h>
#include <DOM/NullableBool.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <DOM/SlideSizeScaleType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>
#include <array>

using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;

auto presentation = MakeObject<Presentation>();
presentation->get_SlideSize()->SetSize(720, 400, SlideSizeScaleType::DoNotScale);
auto slide = presentation->get_Slide(0);

const auto angles = std::array<float, 6>{ 0, 45, 90, 135, 180, 270 };

for (auto i = 0; i < angles.size(); i++)
{
    auto x = 30 + (i % 3) * 230;
    auto y = 30 + (i / 3) * 190;

    auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, x, y, 200, 150);
    shape->get_LineFormat()->get_FillFormat()->set_FillType(FillType::NoFill);
    shape->get_FillFormat()->set_FillType(FillType::Gradient);

    auto gradient = shape->get_FillFormat()->get_GradientFormat();
    gradient->set_GradientShape(GradientShape::Linear);
    gradient->get_GradientStops()->Clear();
    gradient->get_GradientStops()->Add(0.0f, Color::get_Red());
    gradient->get_GradientStops()->Add(0.5f, Color::get_Lime());
    gradient->get_GradientStops()->Add(1.0f, Color::get_Blue());
    gradient->set_LinearGradientScaled(NullableBool::False);
    gradient->set_LinearGradientAngle(angles[i]);
}

presentation->Save(u"linear_gradient_angles.pptx", SaveFormat::Pptx);
presentation->Dispose();

PowerPoint에서 결과:

Linear gradients at 0, 45, and 90 degrees in the top row, and 135, 180, and 270 degrees in the bottom row

도형과 함께 선형 그라디언트 스케일

IGradientFormat::set_LinearGradientScaled는 NullableBool 값을 받습니다. False로 명시적으로 설정하면 도형 비율이 변해도 기하학적 그라디언트 각도가 유지되고, True로 설정하면 도형의 너비와 높이에 따라 그라디언트가 스케일됩니다. 스케일이 활성화된 경우 비정사각형 도형에서는 보이는 각도가 할당된 각도와 다를 수 있습니다.

다음 예제는 45도 각도와 앞서 각도 비교에 사용한 동일한 색상 정지를 사용합니다. 왼쪽 열은 False, 오른쪽 열은 True를 사용합니다. 각 열에는 넓은 직사각형 위에 높은 직사각형이 배치됩니다. 두 번째 직사각형의 너비와 높이를 변경하면 색상 정지를 바꾸지 않고도 리사이징에 대한 채우기 반응을 보여줍니다.

#include <DOM/FillType.h>
#include <DOM/GradientShape.h>
#include <DOM/IAutoShape.h>
#include <DOM/IFillFormat.h>
#include <DOM/IGradientFormat.h>
#include <DOM/IGradientStopCollection.h>
#include <DOM/ILineFillFormat.h>
#include <DOM/ILineFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ISlideSize.h>
#include <DOM/NullableBool.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <DOM/SlideSizeScaleType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>
#include <array>

using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;

auto presentation = MakeObject<Presentation>();
presentation->get_SlideSize()->SetSize(720, 460, SlideSizeScaleType::DoNotScale);
auto slide = presentation->get_Slide(0);

const auto scalingOptions = std::array<NullableBool, 2>{ NullableBool::False, NullableBool::True };

for (auto column = 0; column < scalingOptions.size(); column++)
{
    for (auto row = 0; row < 2; row++)
    {
        auto x = 30 + column * 360;
        auto y = row == 0 ? 30 : 150;

        auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, x, y, 300, 90);
        shape->get_LineFormat()->get_FillFormat()->set_FillType(FillType::NoFill);
        shape->get_FillFormat()->set_FillType(FillType::Gradient);

        auto gradient = shape->get_FillFormat()->get_GradientFormat();
        gradient->set_GradientShape(GradientShape::Linear);
        gradient->get_GradientStops()->Clear();
        gradient->get_GradientStops()->Add(0.0f, Color::get_Red());
        gradient->get_GradientStops()->Add(0.5f, Color::get_Lime());
        gradient->get_GradientStops()->Add(1.0f, Color::get_Blue());
        gradient->set_LinearGradientAngle(45);
        gradient->set_LinearGradientScaled(scalingOptions[column]);

        if (row == 1)
        {
            shape->set_Width(90);
            shape->set_Height(280);
        }
    }
}

presentation->Save(u"linear_gradient_scaling.pptx", SaveFormat::Pptx);
presentation->Dispose();

PowerPoint에서 결과, 왼쪽은 스케일 비활성화, 오른쪽은 스케일 활성화:

Wide and tall rectangles with a 45-degree gradient, comparing LinearGradientScaled False on the left with True on the right

스케일이 비활성화된 경우 대각선 색상 밴드는 두 직사각형 모두에서 동일한 방향을 유지합니다. 스케일이 활성화되면 밴드가 도형 비율에 맞게 늘어납니다. 이는 템플릿의 그라디언트를 다른 크기의 도형에 적용할 때 유용합니다. 정사각형에서는 스케일을 활성화해도 이 45도 그라디언트의 모습은 변하지 않습니다.

각도와 스케일 설정은 모두 선형 그라디언트에만 적용되며, [GradientShape::Radial] 또는 GradientShape::Rectangle 채우기를 제어하지 않습니다.

각도와 그라디언트 방향 결합

IGradientFormat::set_GradientDirection는 GradientDirection 열거형에서 그라디언트 스타일을 선택합니다; 이는 숫자 각도의 대체가 아닙니다. 선형 그라디언트의 경우 코너 스타일이 색상이 분포되는 영역을 바꿀 수 있지만 IGradientFormat::set_LinearGradientAngle으로 할당된 각도는 그대로 유지됩니다. 각도 또는 스케일을 비교할 때 방향은 변경하지 않는 것이 좋습니다.

다음 예제는 설정 순서를 반대로 적용합니다. 두 직사각형은 동일한 외관을 가지며, 방향을 각도 전에 적용하든 후에 적용하든 결과는 동일합니다.

#include <DOM/FillType.h>
#include <DOM/GradientDirection.h>
#include <DOM/GradientShape.h>
#include <DOM/IAutoShape.h>
#include <DOM/IFillFormat.h>
#include <DOM/IGradientFormat.h>
#include <DOM/IGradientStopCollection.h>
#include <DOM/ILineFillFormat.h>
#include <DOM/ILineFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/NullableBool.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>

using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;

auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);

for (auto i = 0; i < 2; i++)
{
    auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 30, 30 + i * 140, 320, 100);
    shape->get_LineFormat()->get_FillFormat()->set_FillType(FillType::NoFill);
    shape->get_FillFormat()->set_FillType(FillType::Gradient);

    auto gradient = shape->get_FillFormat()->get_GradientFormat();
    gradient->set_GradientShape(GradientShape::Linear);
    gradient->get_GradientStops()->Clear();
    gradient->get_GradientStops()->Add(0.0f, Color::get_Red());
    gradient->get_GradientStops()->Add(0.5f, Color::get_Lime());
    gradient->get_GradientStops()->Add(1.0f, Color::get_Blue());
    gradient->set_LinearGradientScaled(NullableBool::True);

    if (i == 0)
    {
        gradient->set_GradientDirection(GradientDirection::FromCorner1);
        gradient->set_LinearGradientAngle(30);
    }
    else
    {
        gradient->set_LinearGradientAngle(30);
        gradient->set_GradientDirection(GradientDirection::FromCorner1);
    }
}

presentation->Save(u"linear_gradient_direction.pptx", SaveFormat::Pptx);
presentation->Dispose();

패턴 채우기

패턴 채우기는 점, 줄무늬 또는 격자와 같은 두 색상 디자인을 적용합니다. 이 예제는 IPatternFormat::set_PatternStyle을 사용해 격자 패턴을 선택합니다. IPatternFormat::get_BackColor은 밝은 회색 배경을 제공하고, IPatternFormat::get_ForeColor은 노란색 패턴 색을 제공합니다.

#include <DOM/FillType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/IPatternFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/PatternStyle.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>

using namespace Aspose::Slides;
using namespace System;
using namespace Aspose::Slides::Export;
using namespace System::Drawing;

auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);

auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 50, 150, 75);
shape->get_FillFormat()->set_FillType(FillType::Pattern);
shape->get_FillFormat()->get_PatternFormat()->set_PatternStyle(PatternStyle::Trellis);
shape->get_FillFormat()->get_PatternFormat()->get_BackColor()->set_Color(Color::get_LightGray());
shape->get_FillFormat()->get_PatternFormat()->get_ForeColor()->set_Color(Color::get_Yellow());

presentation->Save(u"pattern_fill.pptx", SaveFormat::Pptx);
presentation->Dispose();

결과:

The rectangle with pattern fill

그림 채우기

그림 채우기는 도형 내부에 이미지를 사용합니다. 이 예제는 로컬 이미지를 필요로 하며, Images::FromFile을 사용해 프레젠테이션의 이미지 컬렉션에 로드합니다. IPictureFillFormat::set_PictureFillMode을 타일 모드로 설정하면 사각형 내부에 이미지가 반복됩니다. 아래에 사용된 원본 이미지는 다음과 같습니다:

The lotus picture

#include <DOM/FillType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IFillFormat.h>
#include <DOM/IImageCollection.h>
#include <DOM/IPictureFillFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ISlidesPicture.h>
#include <DOM/PictureFillMode.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <IImage.h>
#include <Util/Images.h>
#include <system/smart_ptr.h>

using namespace Aspose::Slides;
using namespace System;
using namespace Aspose::Slides::Export;

auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);

auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 50, 255, 130);
shape->get_FillFormat()->set_FillType(FillType::Picture);
shape->get_FillFormat()->get_PictureFillFormat()->set_PictureFillMode(PictureFillMode::Tile);

auto image = Images::FromFile(u"lotus.png");
auto presentationImage = presentation->get_Images()->AddImage(image);
shape->get_FillFormat()->get_PictureFillFormat()->get_Picture()->set_Image(presentationImage);

presentation->Save(u"picture_fill.pptx", SaveFormat::Pptx);
image->Dispose();
presentation->Dispose();

결과:

The shape with picture fill

텍스처로 그림 타일

타일 그림을 텍스처로 설정하고 타일 동작을 사용자 지정하려면 다음과 같은 IPictureFillFormat 인터페이스 및 PictureFillFormat 클래스의 메서드를 사용할 수 있습니다:

  • set_PictureFillMode: 그림 채우기 모드를 Tile 또는 Stretch 중 하나로 설정합니다.
  • set_TileAlignment: 도형 내에서 타일의 정렬을 지정합니다.
  • set_TileFlip: 타일을 수평, 수직 또는 둘 다 뒤집을지 제어합니다.
  • set_TileOffsetX: 도형 기준점으로부터 타일의 수평 오프셋(포인트)을 설정합니다.
  • set_TileOffsetY: 도형 기준점으로부터 타일의 수직 오프셋(포인트)을 설정합니다.
  • set_TileScaleX: 타일의 수평 스케일을 백분율로 정의합니다.
  • set_TileScaleY: 타일의 수직 스케일을 백분율로 정의합니다.

이 예제는 로컬 이미지를 필요로 하며, IPictureFillFormat을 원본 크기의 50%로 반복하도록 구성합니다. −32 포인트 오프셋은 타일을 수평·수직으로 이동시키고, 오른쪽 아래 정렬 및 양방향 플립은 반복 텍스처 배열 방식을 결정합니다.

#include <DOM/FillType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IFillFormat.h>
#include <DOM/IImageCollection.h>
#include <DOM/IPictureFillFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ISlidesPicture.h>
#include <DOM/PictureFillMode.h>
#include <DOM/Presentation.h>
#include <DOM/RectangleAlignment.h>
#include <DOM/ShapeType.h>
#include <DOM/TileFlip.h>
#include <Export/SaveFormat.h>
#include <IImage.h>
#include <Util/Images.h>
#include <system/smart_ptr.h>

using namespace Aspose::Slides;
using namespace System;
using namespace Aspose::Slides::Export;

auto presentation = MakeObject<Presentation>();
auto firstSlide = presentation->get_Slide(0);

auto shape = firstSlide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 50, 190, 95);
shape->get_FillFormat()->set_FillType(FillType::Picture);

auto sourceImage = Images::FromFile(u"lotus.png");
auto presentationImage = presentation->get_Images()->AddImage(sourceImage);

auto pictureFillFormat = shape->get_FillFormat()->get_PictureFillFormat();
pictureFillFormat->get_Picture()->set_Image(presentationImage);
pictureFillFormat->set_PictureFillMode(PictureFillMode::Tile);
pictureFillFormat->set_TileOffsetX(-32);
pictureFillFormat->set_TileOffsetY(-32);
pictureFillFormat->set_TileScaleX(50);
pictureFillFormat->set_TileScaleY(50);
pictureFillFormat->set_TileAlignment(RectangleAlignment::BottomRight);
pictureFillFormat->set_TileFlip(TileFlip::FlipBoth);

presentation->Save(u"tile.pptx", SaveFormat::Pptx);
sourceImage->Dispose();
presentation->Dispose();

결과:

The tile options

단색 채우기

단색 채우기는 도형에 단일, 균일한 색을 적용합니다. 이 예제는 IFillFormat::set_FillType을 단색 채우기 모드로 설정하고, IFillFormat::get_SolidFillColor을 통해 노란색을 할당한 뒤, 사각형을 프레젠테이션에 저장합니다.

#include <DOM/FillType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>

using namespace Aspose::Slides;
using namespace System;
using namespace Aspose::Slides::Export;
using namespace System::Drawing;

auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);

auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 50, 150, 75);
shape->get_FillFormat()->set_FillType(FillType::Solid);
shape->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Yellow());

presentation->Save(u"solid_color_fill.pptx", SaveFormat::Pptx);
presentation->Dispose();

결과:

The shape with solid color fill

테마 참조를 유지하면서 색 복사

IColorFormat::CopyFrom를 사용하면 색 유형, 테마 참조 및 변환을 포함한 색 정의를 복사할 수 있습니다. 이는 채우기 색이 프레젠테이션 테마를 계속 따르도록 해야 할 때 도형 간에 색을 전달하는 데 유용합니다. 이 메서드는 색만 복사하고, 채우기 유형, 윤곽선 또는 기타 도형 서식은 복사하지 않습니다. 대상 도형의 채우기 유형은 IFillFormat::set_FillType으로 명시적으로 설정하십시오.

이 예제는 좌측→우측 순서로 세 개의 사각형을 만들며, 원본, 테마 인식 복사본, 고정 RGB 복사본을 배치합니다. 원본은 IColorFormat::set_SchemeColor을 사용해 첫 번째 강조 색을 참조하고, IColorOperationCollection::Add으로 색조를 추가합니다. RGB 복사본은 원본의 유효 채우기 색을 사용하여 처음에는 세 개가 동일하게 보입니다. IColorFormat::set_Color을 호출하면 고정 RGB 값이 설정되고 기존 색 변환이 제거됩니다.

#include <DOM/ColorTransformOperation.h>
#include <DOM/FillType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IColorFormat.h>
#include <DOM/IColorOperationCollection.h>
#include <DOM/IFillFormat.h>
#include <DOM/IFillFormatEffectiveData.h>
#include <DOM/ILineFillFormat.h>
#include <DOM/ILineFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ISlideSize.h>
#include <DOM/Presentation.h>
#include <DOM/SchemeColor.h>
#include <DOM/ShapeType.h>
#include <DOM/SlideSizeScaleType.h>
#include <DOM/Theme/IColorScheme.h>
#include <DOM/Theme/IMasterTheme.h>
#include <Export/SaveFormat.h>
#include <IImage.h>
#include <ImageFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>
#include <initializer_list>

using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::Drawing;

auto presentation = MakeObject<Presentation>();
presentation->get_SlideSize()->SetSize(660, 220, SlideSizeScaleType::DoNotScale);
auto slide = presentation->get_Slide(0);

presentation->get_MasterTheme()->get_ColorScheme()->get_Accent1()->set_Color(Color::get_RoyalBlue());

auto source = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 30, 40, 180, 140);
auto themeCopy = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 240, 40, 180, 140);
auto rgbCopy = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 450, 40, 180, 140);

for (auto shape : { source, themeCopy, rgbCopy })
{
    shape->get_FillFormat()->set_FillType(FillType::Solid);
    shape->get_LineFormat()->get_FillFormat()->set_FillType(FillType::NoFill);
}

auto sourceColor = source->get_FillFormat()->get_SolidFillColor();
sourceColor->set_SchemeColor(SchemeColor::Accent1);
sourceColor->get_ColorTransform()->Add(ColorTransformOperation::Tint, 0.75f);

themeCopy->get_FillFormat()->get_SolidFillColor()->CopyFrom(sourceColor);
auto effectiveFill = source->get_FillFormat()->GetEffective();
rgbCopy->get_FillFormat()->get_SolidFillColor()->set_Color(effectiveFill->get_SolidFillColor());

auto before = slide->GetImage(1.0f, 1.0f);
before->Save(u"color-copy-before.png", ImageFormat::Png);
before->Dispose();

// Theme references follow the new accent color; the fixed RGB value does not.
presentation->get_MasterTheme()->get_ColorScheme()->get_Accent1()->set_Color(Color::get_OrangeRed());

auto after = slide->GetImage(1.0f, 1.0f);
after->Save(u"color-copy-after.png", ImageFormat::Png);
after->Dispose();
presentation->Save(u"copied_colors.pptx", SaveFormat::Pptx);
presentation->Dispose();

테마 변경 전, 세 개의 채우기가 모두 일치합니다:

Source, CopyFrom destination, and fixed RGB destination with identical blue fills

테마가 변경된 후, 원본과 테마 인식 복사본은 새로운 강조 색을 따르고 색조를 유지합니다. 고정 RGB 복사본은 그대로 파란색으로 유지됩니다:

Source and CopyFrom destination with orange fills, while the fixed RGB destination remains blue

복사된 정의는 원본과 독립적입니다. 이후 원본의 테마 참조를 변경하거나 다른 색을 할당하거나 변환을 추가·제거해도 대상에는 영향을 주지 않습니다. 테마가 변경되면 두 도형 모두 동일한 테마 색을 각각 독립적으로 참조하고 있기 때문에 영향을 받습니다.

PPTX를 저장하고 다시 열면 복사된 색의 유형이 IColorFormat::get_ColorType을 통해 보존되고, 테마 참조와 IColorFormat::get_ColorTransform이 반환하는 변환 컬렉션도 유지됩니다; 정의가 RGB로 평탄화되지 않습니다.

다른 테마 컨텍스트(예: 강조 색 팔레트가 다른 프레젠테이션) 사이에서 복사할 경우, 복사된 참조는 대상의 테마에 따라 해석됩니다. 동일한 참조와 변환이 다른 가시 색상을 만들 수 있습니다. 자세한 내용은 Presentation Theme을 참조하십시오.

슬라이드 배경을 도형 채우기로 사용

IAutoShape::set_UseBackgroundFill를 사용하면 도형이 슬라이드 배경과 일치하도록 설정할 수 있습니다(예: 프레젠테이션 템플릿). 먼저 IFillFormat::set_FillType을 FillType::NotDefined으로 설정해 명시적 채우기를 제거합니다. 이 조합으로 도형은 스타일 채우기가 아니라 슬라이드 배경을 사용합니다. 플래그만 활성화해도 기존 명시적 채우기가 제거되지는 않습니다.

이는 FillType::NoFill과 다릅니다. 배경 채우기는 도형 뒤에 있는 객체를 슬라이드 배경 영역으로 가리며, NoFill은 해당 객체를 그대로 표시합니다. 그라디언트는 각 도형 내부에서 다시 시작되는 것이 아니라 슬라이드와 정렬된 상태를 유지합니다.

다음 예제는 슬라이드가 상속받는 마스터 배경을 만들고, 세 개의 사각형 뒤에 마젠타 밴드를 배치합니다. 왼쪽 사각형은 배경을 사용하고, 가운데 사각형은 채우기가 없으며, 오른쪽 사각형은 배경 채우기에서 명시적 주황색 채우기로 전환합니다.

#include <DOM/BackgroundType.h>
#include <DOM/FillType.h>
#include <DOM/GradientShape.h>
#include <DOM/IAutoShape.h>
#include <DOM/IBackground.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/IGradientFormat.h>
#include <DOM/IGradientStopCollection.h>
#include <DOM/ILayoutSlide.h>
#include <DOM/ILineFillFormat.h>
#include <DOM/ILineFormat.h>
#include <DOM/IMasterSlide.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ISlideSize.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <DOM/SlideSizeScaleType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>

using namespace Aspose::Slides;
using namespace System;
using namespace Aspose::Slides::Export;
using namespace System::Drawing;

auto presentation = MakeObject<Presentation>();
presentation->get_SlideSize()->SetSize(720, 400, SlideSizeScaleType::DoNotScale);
auto slide = presentation->get_Slide(0);

// 마스터에서 그라디언트를 상속합니다.
slide->get_Background()->set_Type(BackgroundType::NotDefined);
slide->get_LayoutSlide()->get_Background()->set_Type(BackgroundType::NotDefined);
auto background = slide->get_LayoutSlide()->get_MasterSlide()->get_Background();
background->set_Type(BackgroundType::OwnBackground);
background->get_FillFormat()->set_FillType(FillType::Gradient);
auto gradient = background->get_FillFormat()->get_GradientFormat();
gradient->set_GradientShape(GradientShape::Linear);
gradient->set_LinearGradientAngle(0);
gradient->get_GradientStops()->Clear();
gradient->get_GradientStops()->Add(0, Color::get_DarkBlue());
gradient->get_GradientStops()->Add(1, Color::get_LightSkyBlue());

// 먼저 이 객체를 추가하면 사각형 뒤에 배치됩니다.
auto band = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 25, 150, 670, 100);
band->get_FillFormat()->set_FillType(FillType::Solid);
band->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Magenta());
band->get_LineFormat()->get_FillFormat()->set_FillType(FillType::NoFill);

auto backgroundShape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 100, 160, 200);
backgroundShape->get_FillFormat()->set_FillType(FillType::NotDefined);
backgroundShape->set_UseBackgroundFill(true);

auto noFillShape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 280, 100, 160, 200);
noFillShape->get_FillFormat()->set_FillType(FillType::NoFill);

auto explicitShape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 510, 100, 160, 200);
explicitShape->get_FillFormat()->set_FillType(FillType::NotDefined);
explicitShape->set_UseBackgroundFill(true);

// 배경 채우기를 비활성화한 후 명시적 채우기를 적용합니다.
explicitShape->set_UseBackgroundFill(false);
explicitShape->get_FillFormat()->set_FillType(FillType::Solid);
explicitShape->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Orange());

presentation->Save(u"background_fill.pptx", SaveFormat::Pptx);
presentation->Dispose();

결과(왼쪽→오른쪽): background fill, no fill, explicit fill. 마젠타 밴드는 왼쪽과 오른쪽 사각형에 가려지지만 가운데 사각형을 통해서는 보입니다.

Background fill, no fill, and explicit orange fill over a magenta band

동일한 동작은 슬라이드에 직접 정의된 배경이나 레이아웃에서 상속된 배경에도 적용됩니다. 도형은 슬라이드에서 해석된 배경을 사용합니다; 예제에서는 슬라이드와 레이아웃 배경을 모두 정의하지 않아 마스터가 제공하도록 했습니다.

투명도 설정

단색 채우기의 경우 색상의 알파 구성 요소가 불투명도를 제어합니다: 0은 완전 투명, 255는 완전 불투명합니다. 이 예제는 알파 값 128을 사용해 노란색 사각형을 약 50% 투명하게 만들며, 아래에 있는 사각형이 보이도록 합니다. 색상은 IFillFormat::get_SolidFillColor을 통해 할당됩니다.

#include <DOM/FillType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>

using namespace Aspose::Slides;
using namespace System;
using namespace Aspose::Slides::Export;
using namespace System::Drawing;

const int alpha = 128;

auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);

auto solidShape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 50, 150, 75);

auto transparentShape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 80, 80, 150, 75);
transparentShape->get_FillFormat()->set_FillType(FillType::Solid);
transparentShape->get_FillFormat()->get_SolidFillColor()->set_Color(Color::FromArgb(alpha, Color::get_Yellow()));

presentation->Save(u"shape_transparency.pptx", SaveFormat::Pptx);
presentation->Dispose();

결과:

The transparent shape

도형 회전

IShape::set_Rotation을 사용해 슬라이드 평면에서 도형을 회전시킵니다. 각도는 도 단위이며, 이 예제는 사각형을 시계 방향으로 5도 회전시킨 뒤 프레젠테이션을 저장합니다.

#include <DOM/IAutoShape.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <system/smart_ptr.h>

using namespace Aspose::Slides;
using namespace System;
using namespace Aspose::Slides::Export;

auto presentation = MakeObject<Presentation>();
auto ...

결과:

The shape rotation

3D 베벨 효과 추가

IShape::get_ThreeDFormat을 사용해 도형에 깊이와 베벨 가장자리를 부여합니다. 이 예제는 녹색 타원을 주황색 윤곽선으로 만들고, IThreeDFormat::set_Depth을 4포인트로 설정한 뒤, IThreeDFormat::get_BevelTop을 통해 폭과 높이가 6포인트인 원형 상단 베벨을 적용합니다. 앞면을 향한 직교 카메라와 삼점 조명이 베벨을 가시화합니다.

#include <DOM/BevelPresetType.h>
#include <DOM/CameraPresetType.h>
#include <DOM/FillType.h>
#include <DOM/IAutoShape.h>
#include <DOM/ICamera.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/ILightRig.h>
#include <DOM/ILineFillFormat.h>
#include <DOM/ILineFormat.h>
#include <DOM/IShapeBevel.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/IThreeDFormat.h>
#include <DOM/LightRigPresetType.h>
#include <DOM/LightingDirection.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>

using namespace Aspose::Slides;
using namespace System;
using namespace Aspose::Slides::Export;
using namespace System::Drawing;

auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);

auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Ellipse, 50, 50, 100, 100);
shape->get_FillFormat()->set_FillType(FillType::Solid);
shape->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Green());
shape->get_LineFormat()->get_FillFormat()->set_FillType(FillType::Solid);
shape->get_LineFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Orange());
shape->get_LineFormat()->set_Width(2.0);
shape->get_ThreeDFormat()->set_Depth(4);
shape->get_ThreeDFormat()->get_BevelTop()->set_BevelType(BevelPresetType::Circle);
shape->get_ThreeDFormat()->get_BevelTop()->set_Height(6);
shape->get_ThreeDFormat()->get_BevelTop()->set_Width(6);
shape->get_ThreeDFormat()->get_Camera()->set_CameraType(CameraPresetType::OrthographicFront);
shape->get_ThreeDFormat()->get_LightRig()->set_LightType(LightRigPresetType::ThreePt);
shape->get_ThreeDFormat()->get_LightRig()->set_Direction(LightingDirection::Top);

presentation->Save(u"3D_bevel_effect.pptx", SaveFormat::Pptx);
presentation->Dispose();

결과:

The 3D bevel effect

3D 회전 효과 추가

도형의 3D 뷰는 카메라 설정으로 제어됩니다. 이 예제는 ICamera::SetRotation을 사용해 위도, 경도, 회전 각도를 각각 40°, 35°, 20°로 지정합니다. ICamera::set_CameraType으로 등축 카메라를 선택하고, ILightRig::set_LightType으로 균형 조명을 설정한 뒤 포맷된 사각형을 저장합니다.

#include <DOM/CameraPresetType.h>
#include <DOM/IAutoShape.h>
#include <DOM/ICamera.h>
#include <DOM/ILightRig.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/IThreeDFormat.h>
#include <DOM/LightRigPresetType.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <system/smart_ptr.h>

using namespace Aspose::Slides;
using namespace System;
using namespace Aspose::Slides::Export;

auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);

auto autoShape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 50, 150, 75);
autoShape->get_TextFrame()->set_Text(u"Hello, Aspose!");
autoShape->get_ThreeDFormat()->get_Camera()->set_CameraType(CameraPresetType::IsometricLeftUp);
autoShape->get_ThreeDFormat()->get_Camera()->SetRotation(40, 35, 20);
autoShape->get_ThreeDFormat()->get_LightRig()->set_LightType(LightRigPresetType::Balanced);

presentation->Save(u"3D_rotation_effect.pptx", SaveFormat::Pptx);
presentation->Dispose();

결과:

The 3D rotation effect

도형의 흑백 렌더링 제어

IShape::set_BlackWhiteMode 메서드는 프레젠테이션이 흑백 모드로 표시되거나 처리될 때 개별 도형이 어떻게 렌더링되는지를 지정합니다. 이 메서드만으로 흑백 표시가 활성화되는 것은 아니며, 일반 색상 모드에서는 도형의 채우기, 선 또는 기타 서식을 변경하지도 않습니다.

BlackWhiteMode 열거형의 값을 사용해 원하는 동작을 선택합니다. 예를 들어 Automatic은 렌더링 애플리케이션이 변환을 선택하도록 하고, Gray와 LightGray는 회색 색상을 사용하며, BlackWhite는 검정·흰색만 사용하고, Black과 White는 단일 색을 강제하며, Color는 일반 색상을 유지하고, Hidden은 흑백 모드에서 도형을 생략합니다. NotDefined는 도형 수준 모드가 지정되지 않았음을 의미합니다.

이 예제는 주황색 사각형을 만들고 IShape::set_BlackWhiteMode을 회색으로 설정합니다. 저장된 사각형은 일반 색상 표시에서는 주황색 채우기를 유지하고, 흑백 디스플레이 설정을 지원하는 애플리케이션에서는 회색 색상을 요청합니다:

#include <DOM/BlackWhiteMode.h>
#include <DOM/FillType.h>
#include <DOM/IAutoShape.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <drawing/color.h>
#include <system/smart_ptr.h>

using namespace Aspose::Slides;
using namespace System;
using namespace Aspose::Slides::Export;
using namespace System::Drawing;

auto presentation = MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);

auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 50, 200, 100);
shape->get_FillFormat()->set_FillType(FillType::Solid);
shape->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Orange());
shape->set_BlackWhiteMode(BlackWhiteMode::Gray);

presentation->Save(u"shape_black_white_mode.pptx", SaveFormat::Pptx);
presentation->Dispose();

일반 색상 모드에서는 사각형이 주황색 채우기를 유지합니다. 흑백 디스플레이 워크플로에서는 Gray 모드가 설정되어 있기 때문에 회색으로 표시됩니다. 이를 통해 전체 색상 슬라이드를 보존하면서 인쇄, 미리보기 또는 흑백 표시 설정을 따르는 기타 워크플로에 대해 별도 모습을 정의할 수 있습니다.

서식 재설정

ISlide::Reset을 사용하면 레이아웃 자리표시자에 해당하는 슬라이드 자리표시자의 위치, 크기 및 서식을 복원합니다. 이 예제는 레이아웃에 연결된 자리표시자가 있는 기존 프레젠테이션이 필요하며, 저장하기 전에 모든 슬라이드를 재설정합니다. 해당 레이아웃 자리표시자가 없는 도형은 재설정되지 않습니다.

#include <DOM/ISlide.h>
#include <DOM/ISlideCollection.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <system/enumerator_adapter.h>
#include <system/smart_ptr.h>

using namespace Aspose::Slides;
using namespace System;
using namespace Aspose::Slides::Export;

auto presentation = MakeObject<Presentation>(u"sample.pptx");
for (auto&& slide : IterateOver(presentation->get_Slides()))
{
    slide->Reset();
}

presentation->Save(u"reset_formatting.pptx", SaveFormat::Pptx);
presentation->Dispose();

FAQ

Does shape formatting affect the final presentation file size?
도형 서식은 일반적으로 이미지 및 미디어와 비교해 데이터 양이 작아 최종 프레젠테이션 파일 크기에 큰 영향을 주지 않습니다. 그림 채우기는 이미지가 프레젠테이션에 저장되므로 파일 크기를 증가시킬 수 있습니다.

How can I detect shapes on a slide that share identical formatting so I can group them?
각 도형의 핵심 서식 속성(채우기, 선, 효과 설정)을 비교하십시오. 모든 해당 값이 일치하면 스타일이 동일하다고 보고 논리적으로 그룹화하면 이후 스타일 관리가 쉬워집니다.

Can I save a set of custom shape styles to a separate file for reuse in other presentations?
예. 원하는 스타일이 적용된 샘플 도형을 템플릿 슬라이드 파일(.POTX)이나 별도 슬라이드 덱에 저장하십시오. 새 프레젠테이션을 만들 때 템플릿을 열고 필요한 스타일 도형을 복제한 뒤 필요한 곳에 서식을 다시 적용하면 됩니다.