تنسيق أشكال PowerPoint في C++
المقدمة
قم بتنسيق الأشكال في PowerPoint عن طريق تعديل حدودها وتعبئتها وتأثيراتها. تتيح لك Aspose.Slides for C++ التحكم في هذه الإعدادات برمجياً، بما في ذلك الشفافية، والدوران، وتنسيق ثلاثي الأبعاد.

توفر 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 نقاط. استخدم أزواجًا من القيم النهائية غير السالبة لتحديد أقسام الفاصل والفجوة الكاملة. يستخدم المثال قيمًا موجبة للحفاظ على رؤية كل فاصل وفجوة.
ينشئ هذا المثال خمسة خطوط زرقاء بنفس الطول ونهايات مسطحة. الثلاثة الأولى تقارن الأنماط بعرض 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.

ضبط نهايات الخط
استخدم 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.

تطبيق تأثيرات الرسم التخطيطي على خطوط الشكل
يُظهر كود 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();
استخدم IShape::get_LineFormat للوصول إلى إعدادات الخط، وILineFormat::get_SketchFormat للوصول إلى إعدادات الرسم التخطيطي، وISketchFormat::set_SketchType لاختيار قيمة من تعداد LineSketchType .
القيمة التي تُرجعها 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 للزوايا المسطحة.

ينشئ هذا المثال ثلاثة مستطيلات سوداء بحدود زرقاء بعرض 15 نقطة. يضبط ILineFormat::set_JoinStyle إلى قيم الميتر والبقع والـ round من تعداد LineJoinStyle على التوالي، لمقارنة كيفية رسم الزوايا.
#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();
تقييد وصلات الميتر عند الزوايا الحادة
استخدم ILineFormat::set_MiterLimit مع ILineFormat::set_JoinStyle المضبوط إلى LineJoinStyle::Miter لتقييد مدى بُعد امتداد الزاوية الحادة.
الحد هو نسبة المسافة بين الزاويتين الداخلية والخارجية للوصلة إلى عرض الخط. على سبيل المثال، قيمة 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 على اليمين.

تعبئة تدرجية
تدمج تعبئة التدرج الألوان عبر الشكل. يملأ هذا المثال إهليلجًا بتدرج خطي بزاوية 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();
النتيجة:

إذا كان التدرج يبدو مختلفًا في صورة مُصدَّرة عما هو عليه في PowerPoint، راجع اختر نمط عرض التدرج. يمكنك اختيار نمط عرض دون تغيير تعبئة التدرج المخزنة في العرض التقدّمي.
ضبط زاوية التدرج الخطي
استخدم IGradientFormat::set_LinearGradientAngle للتحكم في اتجاه تعبئة GradientShape::Linear. تُقاس الزاوية بالدرجات وتزداد باتجاه عقارب الساعة: 0 من اليسار إلى اليمين، 90 من الأعلى إلى الأسفل، 180 من اليمين إلى اليسار، و270 من الأسفل إلى الأعلى. تدعم الزوايا الكسرية. تُعَدَّل الزوايا النهائية خارج النطاق [0, 360) إلى دورة واحدة؛ على سبيل المثال، -45 تصبح 315 و360 تصبح 0.
يُنشئ هذا المثال ستة مستطيلات بنقاط إيقاف حمراء، خضراء، وزرقاء متطابقة في المواضع 0، 0.5، و1. تم تعطيل التحجيم بحيث يمكن مقارنة الزاوية بغض النظر عن نسب المستطيلات. الزوايا، من اليسار إلى اليمين، هي 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:

تحجيم التدرج الخطي مع الشكل
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، مع تعطيل التحجيم على اليسار وتمكينه على اليمين:

مع تعطيل التحجيم، تحتفظ الشرائط اللونية القطرية بنفس الاتجاه في كلا المستطيلين. مع تمكين التحجيم، تتمدد الشرائط مع نسب الشكل. يساعد ذلك في استنساخ تدرج القالب عند تعديل الشكل إلى حجم مختلف. في الشكل المربع، لا يغيّر تمكين التحجيم مظهر هذا التدرج بزاوية 45 درجة.
تنطبق كل من إعدادات الزاوية والتحجيم على التدرجات الخطية. لا تتحكم في تعبئات GradientShape::Radial or 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();
النتيجة:

تعبئة بصورة
تعبئة الصورة تستخدم صورة داخل شكل. يتطلب هذا المثال صورة محلية ويستخدم Images::FromFile لتحميلها إلى مجموعة صور العرض التقديمي. تعيين IPictureFillFormat::set_PictureFillMode إلى وضع tiled يكرر الصورة داخل المستطيل. الصورة المصدر المستخدمة هنا موضحة أدناه:

#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();
النتيجة:

بلاط الصورة كنقش
إذا كنت ترغب في تعيين صورة مبلطة كنقش وتخصيص سلوك التبلط، يمكنك استخدام الطرق التالية من واجهة 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();
النتيجة:

تعبئة بلون صلب
تعبئة صلبة تعطي الشكل لونًا واحدًا موحدًا. يضبط هذا المثال 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();
النتيجة:

نسخ الألوان مع الحفاظ على مراجع السمة
استخدم 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();
// مراجع السمة تتبع اللون الأساسي الجديد؛ قيمة RGB الثابتة لا تفعل ذلك.
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();
قبل تغيير السمة، جميع التعبئات الثلاثة متطابقة:

بعد تغيير السمة، يتبع المصدر ونسخة الوعي بالسمة اللون الاكستنت الجديد وتحتفظان بتدرجهما. تبقى نسخة RGB الثابتة زرقاء:

التعريف المنسوخ مستقل عن المصدر. تعديل مرجع سمة المصدر لاحقًا، أو تعيين لون آخر، أو إضافة أو إزالة التحويلات لا يغيّر الوجهة. لا يزال تغيير السمة يؤثر على الشكلين لأن كلًا منهما يشير مستقلاً إلى نفس لون السمة.
يحتفظ حفظ وإعادة فتح ملف PPTX بنوع اللون المنسوخ، المتاح عبر IColorFormat::get_ColorType, مرجع السمة، ومجموعة التحويلات التي تُرجعها IColorFormat::get_ColorTransform. لا يتم تحويل التعريف إلى RGB.
عند النسخ بين سياقات سمة مختلفة، مثل عروض تقديمية ذات لوحات ألوان اكستنت مختلفة، يُحلّ المرجع المنسوخ مقابل سمة الوجهة. يمكن لنفس المرجع والتحويلات أن ينتج عنه لون مرئي مختلف. انظر سمة العرض التقديمي للمزيد حول تكوين ألوان السمة.
استخدام خلفية الشريحة كتعبئة للشكل
استخدم IAutoShape::set_UseBackgroundFill عندما يجب أن يتطابق الشكل مع خلفية الشريحة، على سبيل المثال في قالب عرض تقديمي. اضبط IFillFormat::set_FillType إلى FillType::NotDefined أولاً لإزالة أي تعبئة صريحة. مع هذا الجمع، يستخدم الشكل خلفية الشريحة بدلاً من تعبئة نمطه. تمكين العلامة بمفردها لا يزيل تعبئة صريحة موجودة.
هذا يختلف عن FillType::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. يتم إخفاء الشريط الأرجواني بواسطة المستطيلين الأيسر والأيمن لكنه يظل مرئيًا من خلال المستطيل الأوسط.

ينطبق نفس السلوك على خلفية معرفّة مباشرةً على الشريحة أو موروثة من تخطيط. يستخدم الشكل خلفية الشريحة المُحلَّة؛ يترك المثال خلفيات الشريحة والتخطيط غير معرفة بحيث يوفّرها الرئيس.
ضبط الشفافية
في التعبئة الصلبة، يتحكم مكوّن ألفا للون في الشفافية: 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();
النتيجة:

تدوير الأشكال
استخدم IShape::set_Rotation لتدوير شكل في plane الشريحة. تُقاس الزاوية بالدرجات؛ يدور هذا المثال مستطيلًا 5 درجات باتجاه عقارب الساعة ويحفظ العرض التقديمي.
#include <DOM/IAutoShape.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.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 shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 50, 150, 75);
shape->set_Rotation(5);
presentation->Save(u"shape_rotation.pptx", SaveFormat::Pptx);
presentation->Dispose();
النتيجة:

إضافة تأثيرات تقويس ثلاثية الأبعاد
استخدم IShape::get_ThreeDFormat لإعطاء الشكل عمقًا وحوافًا مقلَّبة. يخلق هذا المثال إهليلجًا أخضر بحد برتقالي، يضبط IThreeDFormat::set_Depth إلى 4 نقاط، ويطبق تقويسًا علويًا دائريًا بعرض وارتفاع 6 نقاط عبر IThreeDFormat::get_BevelTop. تجعل كاميرا أرثوغرافية موجهة للأمام وإضاءة ثلاثية النقاط التقويس مرئيًا.
#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();
النتيجة:

إضافة تأثيرات دوران ثلاثية الأبعاد
يتم التحكم في عرض الشكل ثلاثي الأبعاد من خلال إعدادات الكاميرا. يستخدم هذا المثال 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();
النتيجة:

التحكم في العرض بالأبيض والأسود للأشكال
تحدد طريقة 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();
الأسئلة المتكررة
هل يؤثر تنسيق الشكل على حجم ملف العرض التقديمي النهائي؟
عمومًا، الألوان وأنماط الخط وإعدادات التأثير تضيف بيانات قليلة مقارنةً بالصور والوسائط المضمّنة. يمكن لتعبئات الصور زيادة حجم الملف لأن صورها تُخزن في العرض التقديمي.
كيف يمكنني اكتشاف الأشكال في شريحة تشترك في تنسيق متماثل لأتمكن من تجميعها؟
قارن خصائص التنسيق الرئيسية لكل شكل — التعبئة، الخط، وإعدادات التأثير. إذا تطابقت جميع القيم المقابلة، اعتبر أن أنماطها متماثلة وقم بتجميع هذه الأشكال منطقيًا، مما يبسط إدارة الأنماط لاحقًا.
هل يمكنني حفظ مجموعة من أنماط الشكل المخصّصة في ملف منفصل لإعادة استخدامها في عروض تقديمية أخرى؟
نعم. خزن أشكالًا نموذجية بالأنماط المطلوبة في مجموعة شرائح قالب أو ملف قالب .POTX. عند إنشاء عرض تقديمي جديد، افتح القالب، استنسخ الأشكال المنمّطة التي تحتاجها، وأعد تطبيق تنسيقاتها حيثما كان ذلك مطلوبًا.