소개

Aspose.Slides FOSS for C++ (aspose_slides_foss)는 PowerPoint 프레젠테이션을 프로그래밍 방식으로 생성하고 조작하기 위한 무료 오픈소스 C++20 라이브러리입니다. CMake 3.20 이상을 제외하고 외부 런타임 종속성이 전혀 없는 순수 C++로 완전히 구축되어, Microsoft Office나 기타 독점 소프트웨어 없이도 개발자가 PPTX 파일을 완전히 제어할 수 있게 합니다.

이 라이브러리는 MIT 라이선스로 배포되어 상업용 및 비상업용 프로젝트 모두에 적합합니다. 공개 API는 Aspose::Slides::Foss 네임스페이스에 위치하며 프레젠테이션, 슬라이드, 도형, 표, 텍스트 프레임, 문서 속성, 주석 및 PPTX 내보내기를 포괄하는 풍부한 객체 모델을 제공합니다.

이 글에서는 핵심 API 인터페이스를 살펴봅니다: 프레젠테이션을 만들고, 서식을 지정하고, 저장할 때 가장 자주 사용하게 될.


포함 내용

프레젠테이션 및 슬라이드 관리

Presentation 클래스는 진입점입니다. 새 인스턴스를 생성하면 즉시 콘텐츠를 넣을 수 있는 기본 슬라이드가 제공됩니다. 슬라이드는 slides()가 반환하는 SlideCollection을 통해 접근할 수 있으며, 인덱스 접근, 반복, 제거 및 재정렬을 지원합니다.

#include <Aspose/Slides/Foss/presentation.h>
using namespace Aspose::Slides::Foss;

Presentation pres;
auto& slide = pres.slides()[0]; // first slide
// Work with the slide...
pres.save("output.pptx", SaveFormat::PPTX);

도형 및 AutoShapes

각 슬라이드는 shapes() 액세서자를 통해 ShapeCollection을 노출합니다. 이 컬렉션은 다양한 도형 유형을 추가하기 위한 팩터리 메서드를 제공합니다: 표준 기하 도형(사각형, 타원, 삼각형)을 위한 add_auto_shape, 선 연결자를 위한 add_connector, 표를 위한 add_table, 이미지를 위한 add_picture_frame.

auto& slide = pres.slides()[0];

// Add a rectangle
auto& rect = slide.shapes().add_auto_shape(
    ShapeType::RECTANGLE, 50, 50, 300, 100);

// Add an ellipse
auto& ellipse = slide.shapes().add_auto_shape(
    ShapeType::ELLIPSE, 400, 50, 150, 150);

// Add a connector between shapes
auto& conn = slide.shapes().add_connector(
    ShapeType::BENT_CONNECTOR3, 0, 0, 1, 1);

ShapeCollection은(는) 생성 후 도형을 관리하기 위해 size(), remove(), remove_at(), reorder(), index_of(), clear()도 지원합니다.

텍스트 및 단락 서식

도형은 TextFrame을 통해 텍스트를 보유할 수 있습니다. 텍스트 내용을 첨부하려면 AutoShape에 add_text_frame()을 사용하거나, 기존 프레임은 text_frame()을 통해 접근합니다. 텍스트는 단락으로 구성되며, 각 단락은 하나 이상의 구역을 포함합니다. BasePortionFormat 클래스는 굵게, 기울임꼴, 밑줄 유형, 대소문자 변환, 취소선 및 글꼴 색상 등을 포함한 글꼴 스타일 속성을 노출합니다.

auto& shape = pres.slides()[0].shapes().add_auto_shape(
    ShapeType::RECTANGLE, 50, 50, 300, 100, false);
shape.add_text_frame("Hello, world!");
auto text = shape.text_frame()->text(); // "Hello, world!"

채우기, 그라데이션 및 시각 효과

각 도형은 fill_format()을 통해 접근 가능한 FillFormat을 제공합니다. set_fill_type() 메서드를 사용하여 단색 채우기, 그라데이션 채우기 또는 패턴 채우기를 설정할 수 있습니다. 그라데이션 채우기는 GradientFormat 객체를 통해 구성되며, 이 객체는 선형 각도, 그라데이션 형태 및 GradientStopCollection를 통한 색상 스톱을 지원합니다.

auto& shape = slide.shapes().add_auto_shape(
    ShapeType::RECTANGLE, 50, 50, 300, 150);
shape.fill_format().set_fill_type(FillType::GRADIENT);
auto& gf = shape.fill_format().gradient_format();
gf.set_gradient_shape(GradientShape::LINEAR);
gf.set_linear_gradient_angle(45);
gf.gradient_stops().add(0.0f, Color::blue);
gf.gradient_stops().add(1.0f, Color::red);

EffectFormat 클래스( effect_format()을 통해 접근) 는 글로우, 외부 그림자 및 부드러운 가장자리 효과를 추가합니다. 각 효과는 전용 메서드(enable_glow_effect(), enable_outer_shadow_effect(), enable_soft_edge_effect())로 활성화되며, 반환된 객체를 통해 구성됩니다.

테이블

테이블은 shape 컬렉션에서 add_table() 로 생성됩니다. 열 너비와 행 높이는 벡터로 제공합니다. 반환된 Table 객체는 rows() 및 columns() 컬렉션을 노출하고, 개별 Cell 객체는 TextFrame를 통해 텍스트 내용을 지원합니다.

std::vector<double> col_widths = {100, 150, 200};
std::vector<double> row_heights = {40, 40, 40};
auto& table = slide.shapes().add_table(
    50, 50, col_widths, row_heights);
// table.rows().size() == 3
// table.columns().size() == 3

문서 속성 및 주석

DocumentProperties 클래스는 제목, 저자, 주제, 키워드, 카테고리, 리비전 번호 및 타임스탬프와 같은 메타데이터를 설정할 수 있게 해줍니다. 프레젠테이션 객체를 통해 접근하세요.

주석은 CommentAuthorCollection와 CommentCollection을 통해 관리됩니다. add_author()로 저자를 추가한 후, 특정 좌표의 특정 슬라이드에 주석을 붙입니다.

Presentation pres;
auto& author = pres.comment_authors().add_author("Alice", "A");
auto& slide = pres.slides()[0];
auto& comment = author.comments().add_comment(
    "Review note", slide, PointF(2.0f, 3.0f), now);

빠른 시작

소스에서 빌드하기

이 라이브러리는 CMake 3.20 이상 및 C++20을 지원하는 컴파일러가 필요합니다. 저장소를 복제하고 빌드하십시오:

git clone https://github.com/aspose-slides-foss/Aspose.Slides-FOSS-for-Cpp.git
cd Aspose.Slides-FOSS-for-Cpp
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build

최소 예제

#include <Aspose/Slides/Foss/presentation.h>
using namespace Aspose::Slides::Foss;

int main() {
    Presentation pres;
    auto& slide = pres.slides()[0];

    // Add a shape with text
    auto& shape = slide.shapes().add_auto_shape(
        ShapeType::RECTANGLE, 50, 50, 300, 100, false);
    shape.add_text_frame("Hello from Aspose.Slides FOSS!");

    // Apply a solid fill
    shape.fill_format().set_fill_type(FillType::SOLID);
    shape.fill_format().solid_fill_color().set_color(Color::blue);

    // Save
    pres.save("hello.pptx", SaveFormat::PPTX);
    return 0;
}

지원되는 형식

SaveFormat 열거형은 모든 내보내기 대상을 정의합니다. 다음 형식들이 소스 코드에서 확인되었습니다:

형식확장자읽기쓰기
PPTX.pptx–예
PPT.ppt–Planned
PPSX.ppsx–Planned
PPTM.pptm–Planned
PPSM.ppsm–Planned
POTX.potx–Planned
POTM.potm–Planned
POT.pot–Planned
PPS.pps–Planned
ODP.odp–Planned
OTP.otp–Planned
FODP.fodp–Planned
PDF.pdf–Planned
XPS.xps–Planned
HTML.html–Planned
HTML5.html–Planned
TIFF.tiff–Planned
GIF.gif–Planned
SWF.swf–Planned
MD.md–Planned
XML.xml–Planned

참고: 현재는 PPTX 내보내기만 구현되어 있습니다. 다른 형식 값들은 SaveFormat 앞으로의 호환성을 위해 enum에 포함되어 있지만 아직 기능하지 않습니다. 해당 save() 이 메서드는 포맷 매개변수와 관계없이 항상 PPTX 출력을 생성합니다.


오픈 소스 및 라이선스

Aspose.Slides FOSS for C++는 MIT 라이선스로 배포됩니다. 개인 프로젝트, 상업용 애플리케이션, 재배포 라이브러리에서 자유롭게 사용할 수 있습니다. API 키, 워터마크, 사용 제한이 없습니다. 전체 소스 코드는 GitHub에 있으며, https://github.com/aspose-slides-foss/Aspose.Slides-FOSS-for-Cpp에서 확인할 수 있습니다.


시작하기

C++ 프로젝트에 Aspose.Slides FOSS을(를) 통합할 준비가 되셨나요? 주요 리소스를 소개합니다:

관련 리소스