C++ で PowerPoint のシェイプをフォーマットする
はじめに
PowerPointでシェイプの輪郭、塗りつぶし、効果を調整してフォーマットします。Aspose.Slides for C++ を使用すると、透明度、回転、3D フォーマットなどの設定をプログラムで制御できます。

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に変更されます。
配列の要素はダッシュとギャップの長さを交互に指定し、ダッシュから始めます。各値は線幅の倍数です。たとえば幅 3 ポイントで { 4, 2 } を指定すると、12 ポイントのダッシュの後に 6 ポイントのギャップが続きます。有限かつ非負の値のペアを使用して完全なダッシュ‑ギャップセグメントを定義します。この例ではすべてのダッシュとギャップが見えるように正の値を使用しています。
この例は、同じ長さでフラットキャップを持つ青色の線を 5 本作成します。最初の 3 本は幅 3 ポイントでパターンを比較し、4 本目は最初のパターンを幅 2 倍で繰り返し、ダッシュとギャップの長さも 2 倍にします。5 本目はカスタムパターンから実線に切り替えます。
#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 列挙体は次の 3 つの明示的なキャップスタイルを提供します。
Flat: ストロークは端点で停止します。Round: 半円形のキャップが線幅の半分だけ端点を超えて伸びます。Square: 正方形のキャップが線幅の半分だけ端点を超えて伸びます。
列挙体には NotDefined も含まれ、これはキャップスタイルが明示的に割り当てられていないことを意味します。
キャップは、線端に記号を付加する矢印ヘッドや、線分間の角を制御する結合とは異なります。この例ではILineFormat::set_BeginArrowheadStyle と ILineFormat::set_EndArrowheadStyle で矢印ヘッドを無効にし、キャップ形状だけを比較します。
以下の例は、幅 20 ポイントの横線を 3 本作成します。上から下へ、それぞれフラット、ラウンド、スクエアキャップが使用されます。端点の水平座標は同じですが、ラウンドとスクエアキャップは各端点を 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。

シェイプ線へのスケッチ効果の適用
スケッチ効果はシェイプの線を手描きのように見せます。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 を読み取ります。Effective 値は継承が解決された後に実際に適用される書式を示します。この例は、最初のスライドに少なくとも 1 つのシェイプがある既存のプレゼンテーションを必要とし、両方の値を出力します。
#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();
結合スタイルの書式設定
以下は 3 つの結合タイプオプションです。
- ラウンド
- ミーター
- ベベル
結合スタイルは、2 本のアウトラインセグメントが角でどのように接続されるかを制御します。角を丸めるには ラウンド、鋭くするには ミーター、平らにするには ベベル を使用します。

この例は、青いアウトライン(幅 15 ポイント)を持つ黒い長方形を 3 つ作成します。ILineFormat::set_JoinStyle をそれぞれ 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 の値は線幅の最大 8 倍までミーター長さを許可します。これはポイントでの測定ではありません。角が制限を超える場合、PowerPoint はその角にベベル結合を使用します。制限を大きくするとより鋭いポイントが得られます。この設定はミーター結合のみに影響し、角が両方の制限内に収まっている場合は視覚的な変化はありません。
この例は、幅 20 ポイントのアウトラインを持つ同一の塗りなし三角形を 2 つ作成します。左側の三角形は制限 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) にカラーストップを配置します。既存のストップをクリアすると、この 2 色だけが使用されます。
#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) の範囲外の有限角度は 1 回転に正規化され、例として -45 は 315 に、360 は 0 になります。
この例は、位置 0、0.5、1 に同一の赤・緑・青ストップを持つ 6 つの長方形を作成します。スケーリングを無効にして、角度を長方形の比例に関係なく比較できるようにします。左から右への角度は、1 行目が 0、45、90、2 行目が 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 です。各列は上部に横長長方形、下部に縦長長方形を配置します。両方とも同じ横幅で開始し、2 番目の長方形の幅と高さを変更して、塗りつぶしがリサイズにどのように応答するかを示します。
#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] や GradientShape::Rectangle の塗りつぶしは制御しません。
角度とグラデーション方向の組み合わせ
IGradientFormat::set_GradientDirection は GradientDirection 列挙体からグラデーションスタイルを選択します。数値角度の代替ではありません。線形グラデーションの場合、コーナースタイルは IGradientFormat::set_LinearGradientAngle で割り当てた角度を変えずに色が分布する領域を変更できます。角度やスケーリングを比較する際は方向を変更しないでください。
以下の例は同じ設定を逆順で適用します。2 つの長方形は同一の外観になり、方向を角度の前後どちらに設定しても結果は変わりません。
#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();
パターン塗りつぶし
パターン塗りつぶしはドット、ストライプ、チェックなどの 2 色デザインを適用します。この例は 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 をタイルモードに設定すると、画像が長方形内で繰り返されます。使用されているソース画像は以下のとおりです。

#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 で明示的に設定してください。
この例は左から右へ 3 つの長方形を作成します:ソース、テーマ対応コピー、固定 RGB コピーです。ソースは IColorFormat::set_SchemeColor で最初のアクセントカラーを参照し、IColorOperationCollection::Add でティントを追加します。RGB コピーはソースの有効塗りカラーを使用するため、最初は 3 つとも同一に見えます。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();
テーマ変更前は 3 つの塗りが一致しています:

テーマ変更後、ソースとテーマ対応コピーは新しいアクセントカラーに従いティントを保持します。固定 RGB コピーは青のままです:

コピーされた定義はソースとは独立しています。その後、ソースのテーマ参照や別の色への割り当て、変換の追加・削除を行っても宛先は変わりません。テーマ変更は両方のシェイプに影響しますが、各シェイプは同じテーマカラーを個別に参照しているためです。
保存・再オープンすると、コピーされた色のタイプは IColorFormat::get_ColorType で取得でき、テーマ参照と IColorFormat::get_ColorTransform で返される変換コレクションも保持されます。RGB へフラット化はされません。
異なるテーマコンテキスト(たとえばアクセント パレットが異なるプレゼンテーション)間でコピーすると、コピーされた参照は宛先のテーマに対して解決されます。同じ参照と変換でも、見た目の色が異なる場合があります。プレゼンテーションテーマ を参照してテーマカラーの設定方法を確認してください。
スライドの背景をシェイプの塗りつぶしとして使用
スライドの背景に合わせるシェイプが必要な場合(例: プレゼンテーションテンプレート)には、IAutoShape::set_UseBackgroundFill を使用します。まず IFillFormat::set_FillType を FillType::NotDefined に設定して明示的な塗りを除去します。この組み合わせにより、シェイプはスタイル塗りではなくスライドの背景を使用します。フラグだけを有効にしても既存の明示的塗りは除去されません。
これは FillType::NoFill とは異なります。背景塗りはシェイプの背後にあるオブジェクトをスライド背景の該当領域でカバーしますが、NoFill はそれらのオブジェクトを可視のままにします。グラデーションは各シェイプ内で再開するのではなく、スライドに合わせて配置され続けます。
以下の例はスライドが継承するマスターバックグラウンドを作成し、3 つの長方形の背後にマゼンタ帯を配置します。左の長方形は背景を使用し、中央は No Fill、右は背景塗りから明示的なオレンジ塗りに切り替えます。
#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 を使用してスライド平面上でシェイプを回転させます。角度は度数で測定され、この例は矩形を時計回りに 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();
結果:

3D ベベル効果の追加
IShape::get_ThreeDFormat を使用してシェイプに深さとベベルエッジを付加します。この例は緑の楕円にオレンジのアウトラインを付け、IThreeDFormat::set_Depth を 4 ポイントに設定し、IThreeDFormat::get_BevelTop を通じて幅・高さ 6 ポイントの円形トップベベルを適用します。前方向きの正投影カメラと 3 点照明によりベベルが見えるようになります。
#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();
結果:

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();
結果:

シェイプの白黒レンダリング制御
IShape::set_BlackWhiteMode メソッドは、プレゼンテーションが白黒モードで表示または処理されるときに個々のシェイプがどのようにレンダリングされるかを指定します。このメソッドだけで白黒表示が有効になるわけではなく、通常カラー表示時のシェイプの塗り、線、その他の書式設定は変更されません。
BlackWhiteMode 列挙体の値を使用して目的の動作を選択します。例として Automatic はレンダリングアプリが変換を選択させ、Gray と LightGray はグレイカラー、BlackWhite は黒と白だけ、Black と White は単一色、Color は通常カラーを保持、Hidden は白黒モードでシェイプを除外します。NotDefined はシェイプレベルのモードが割り当てられていないことを意味します。
この例はオレンジの長方形を作成し、IShape::set_BlackWhiteMode を Gray に設定します。保存されたシェイプは通常カラー表示ではオレンジ塗りを保持し、白黒表示設定を尊重するアプリケーションではグレイカラーを要求します。
#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
シェイプの書式設定は最終的なプレゼンテーションのファイルサイズに影響しますか?
色、線スタイル、効果設定は埋め込み画像やメディアに比べてデータがほとんど増加しません。画像塗りつぶしは画像がプレゼンテーションに保存されるため、ファイルサイズを増加させる可能性があります。
同一の書式設定を共有するスライド上のシェイプを検出してグループ化するにはどうすればよいですか?
シェイプごとに主要な書式プロパティ(塗り、線、効果設定)を比較します。すべての対応する値が一致すれば、スタイルが同一とみなし、論理的にグループ化できます。これにより、後のスタイル管理が簡素化されます。
カスタムシェイプスタイルのセットを別ファイルに保存し、他のプレゼンテーションで再利用できますか?
できます。目的のスタイルを持つサンプルシェイプをテンプレートスライドデッキまたは .POTX テンプレートファイルに保存します。新しいプレゼンテーションを作成するときにテンプレートを開き、必要なスタイル済みシェイプをクローンして、必要な場所で書式設定を再適用します。