形状有效属性
在本主题中,我们将讨论 有效 和 本地 属性。当我们在这些层次上直接设置值时
- 在部分属性的部分幻灯片上。
- 在布局或母版幻灯片上的原型形状文本样式中(如果部分的文本框形状有一个)。
- 在演示文稿全局文本设置中。
那么这些值被称为 本地 值。在任何层次上,本地 值可以被定义或省略。但是最终当应用程序需要知道部分应该呈现为何种样子时,它使用 有效 值。您可以通过使用 GetEffective() 方法从本地格式获取有效值。
以下示例展示了如何获取有效值。
// The path to the documents directory. | |
const String templatePath = u"../templates/Presentation1.pptx"; | |
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(templatePath); | |
System::SharedPtr<IAutoShape> shape = System::DynamicCast_noexcept<Aspose::Slides::IAutoShape>(pres->get_Slides()->idx_get(0)->get_Shapes()->idx_get(0)); | |
System::SharedPtr<ITextFrameFormat> localTextFrameFormat = shape->get_TextFrame()->get_TextFrameFormat(); | |
System::SharedPtr<ITextFrameFormatEffectiveData> effectiveTextFrameFormat = localTextFrameFormat->GetEffective(); | |
System::SharedPtr<IPortionFormat> localPortionFormat = shape->get_TextFrame()->get_Paragraphs()->idx_get(0)->get_Portions()->idx_get(0)->get_PortionFormat(); | |
System::SharedPtr<IPortionFormatEffectiveData> effectivePortionFormat = localPortionFormat->GetEffective(); | |
获取相机的有效属性
Aspose.Slides for C++ 允许开发人员获取相机的有效属性。为此,Aspose.Slides 中添加了 CameraEffectiveData 类。CameraEffectiveData 类代表一个不可变对象,包含有效的相机属性。CameraEffectiveData 类的一个实例被用作 ThreeDFormatEffectiveData 类的一部分,该类是 ThreeDFormat 类的有效值对。
以下代码示例展示了如何获取相机的有效属性。
// The path to the documents directory. | |
const String templatePath = u"../templates/Presentation1.pptx"; | |
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(templatePath); | |
System::SharedPtr<IThreeDFormatEffectiveData> threeDEffectiveData = pres->get_Slides()->idx_get(0)->get_Shapes()->idx_get(0)->get_ThreeDFormat()->GetEffective(); | |
System::Console::WriteLine(u"= Effective camera properties ="); | |
System::Console::WriteLine(System::String(u"Type: ") + System::ObjectExt::ToString((int)threeDEffectiveData->get_Camera()->get_CameraType())); | |
System::Console::WriteLine(System::String(u"Field of view: ") + threeDEffectiveData->get_Camera()->get_FieldOfViewAngle()); | |
System::Console::WriteLine(System::String(u"Zoom: ") + threeDEffectiveData->get_Camera()->get_Zoom()); | |
获取灯光设备的有效属性
Aspose.Slides for C++ 允许开发人员获取灯光设备的有效属性。为此,Aspose.Slides 中添加了 LightRigEffectiveData 类。LightRigEffectiveData 类代表一个不可变对象,包含有效的灯光设备属性。LightRigEffectiveData 类的一个实例被用作 ThreeDFormatEffectiveData 类的一部分,该类是 ThreeDFormat 类的有效值对。
以下代码示例展示了如何获取灯光设备的有效属性。
// The path to the documents directory. | |
const String templatePath = u"../templates/Presentation1.pptx"; | |
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(templatePath); | |
System::SharedPtr<IThreeDFormatEffectiveData> threeDEffectiveData = pres->get_Slides()->idx_get(0)->get_Shapes()->idx_get(0)->get_ThreeDFormat()->GetEffective(); | |
System::Console::WriteLine(u"= Effective light rig properties ="); | |
System::Console::WriteLine(System::String(u"Type: ") + System::ObjectExt::ToString((int)threeDEffectiveData->get_LightRig()->get_LightType())); | |
System::Console::WriteLine(System::String(u"Direction: ") + System::ObjectExt::ToString((int)threeDEffectiveData->get_LightRig()->get_Direction())); | |
获取斜切形状的有效属性
Aspose.Slides for C++ 允许开发人员获取斜切形状的有效属性。为此,Aspose.Slides 中添加了 ShapeBevelEffectiveData 类。ShapeBevelEffectiveData 类代表一个不可变对象,包含有效形状的面浮雕属性。ShapeBevelEffectiveData 类的一个实例被用作 ThreeDFormatEffectiveData 类的一部分,该类是 ThreeDFormat 类的有效值对。
以下代码示例展示了如何获取斜切形状的有效属性。
// The path to the documents directory. | |
const String templatePath = u"../templates/Presentation1.pptx"; | |
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(templatePath); | |
System::SharedPtr<IThreeDFormatEffectiveData> threeDEffectiveData = pres->get_Slides()->idx_get(0)->get_Shapes()->idx_get(0)->get_ThreeDFormat()->GetEffective(); | |
System::Console::WriteLine(u"= Effective shape's top face relief properties ="); | |
System::Console::WriteLine(System::String(u"Type: ") + System::ObjectExt::ToString((int)threeDEffectiveData->get_BevelTop()->get_BevelType())); | |
System::Console::WriteLine(System::String(u"Width: ") + threeDEffectiveData->get_BevelTop()->get_Width()); | |
System::Console::WriteLine(System::String(u"Height: ") + threeDEffectiveData->get_BevelTop()->get_Height()); | |
获取文本框的有效属性
使用 Aspose.Slides for C++,您可以获取文本框的有效属性。为此,Aspose.Slides 中添加了 TextFrameFormatEffectiveData 类,该类包含有效的文本框格式属性。
以下代码示例展示了如何获取有效的文本框格式属性。
// The path to the documents directory. | |
const String templatePath = u"../templates/Presentation1.pptx"; | |
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(templatePath); | |
System::SharedPtr<IAutoShape> shape = System::DynamicCast_noexcept<Aspose::Slides::IAutoShape>(pres->get_Slides()->idx_get(0)->get_Shapes()->idx_get(0)); | |
System::SharedPtr<ITextFrameFormatEffectiveData> effectiveTextFrameFormat = shape->get_TextFrame()->get_TextFrameFormat()->GetEffective(); | |
System::Console::WriteLine(System::String(u"Anchoring type: ") + System::ObjectExt::ToString((int)effectiveTextFrameFormat->get_AnchoringType())); | |
System::Console::WriteLine(System::String(u"Autofit type: ") + System::ObjectExt::ToString((int)effectiveTextFrameFormat->get_AutofitType())); | |
System::Console::WriteLine(System::String(u"Text vertical type: ") + System::ObjectExt::ToString((int)effectiveTextFrameFormat->get_TextVerticalType())); | |
System::Console::WriteLine(u"Margins"); | |
System::Console::WriteLine(System::String(u" Left: ") + effectiveTextFrameFormat->get_MarginLeft()); | |
System::Console::WriteLine(System::String(u" Top: ") + effectiveTextFrameFormat->get_MarginTop()); | |
System::Console::WriteLine(System::String(u" Right: ") + effectiveTextFrameFormat->get_MarginRight()); | |
System::Console::WriteLine(System::String(u" Bottom: ") + effectiveTextFrameFormat->get_MarginBottom()); | |
获取文本样式的有效属性
使用 Aspose.Slides for C++,您可以获取文本样式的有效属性。为此,Aspose.Slides 中添加了 TextStyleEffectiveData 类,该类包含有效的文本样式属性。
以下代码示例展示了如何获取有效的文本样式属性。
// The path to the documents directory. | |
const String templatePath = u"../templates/Presentation1.pptx"; | |
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(templatePath); | |
System::SharedPtr<IAutoShape> shape = System::DynamicCast_noexcept<Aspose::Slides::IAutoShape>(pres->get_Slides()->idx_get(0)->get_Shapes()->idx_get(0)); | |
System::SharedPtr<ITextStyleEffectiveData> effectiveTextStyle = shape->get_TextFrame()->get_TextFrameFormat()->get_TextStyle()->GetEffective(); | |
for (int32_t i = 0; i <= 8; i++) | |
{ | |
System::SharedPtr<IParagraphFormatEffectiveData> effectiveStyleLevel = effectiveTextStyle->GetLevel(i); | |
System::Console::WriteLine(System::String(u"= Effective paragraph formatting for style level #") + i + u" ="); | |
System::Console::WriteLine(System::String(u"Depth: ") + effectiveStyleLevel->get_Depth()); | |
System::Console::WriteLine(System::String(u"Indent: ") + effectiveStyleLevel->get_Indent()); | |
System::Console::WriteLine(System::String(u"Alignment: ") + System::ObjectExt::ToString(effectiveStyleLevel->get_Alignment())); | |
System::Console::WriteLine(System::String(u"Font alignment: ") + System::ObjectExt::ToString(effectiveStyleLevel->get_FontAlignment())); | |
} | |
获取有效的字体高度值
使用 Aspose.Slides for C++,您可以获取字体高度的有效属性。以下是代码示例,演示在不同演示文稿结构层次设置本地字体高度值后,部分的有效字体高度值发生了改变。
// The path to the documents directory. | |
const String outPath = u"../out/SetLocalFontHeightValues.pptx"; | |
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(); | |
System::SharedPtr<IAutoShape> newShape = pres->get_Slides()->idx_get(0)->get_Shapes()->AddAutoShape(Aspose::Slides::ShapeType::Rectangle, 100.0f, 100.0f, 400.0f, 75.0f, false); | |
newShape->AddTextFrame(u""); | |
newShape->get_TextFrame()->get_Paragraphs()->idx_get(0)->get_Portions()->Clear(); | |
System::SharedPtr<IPortion> portion0 = System::MakeObject<Portion>(u"Sample text with first portion"); | |
System::SharedPtr<IPortion> portion1 = System::MakeObject<Portion>(u" and second portion."); | |
newShape->get_TextFrame()->get_Paragraphs()->idx_get(0)->get_Portions()->Add(portion0); | |
newShape->get_TextFrame()->get_Paragraphs()->idx_get(0)->get_Portions()->Add(portion1); | |
System::Console::WriteLine(u"Effective font height just after creation:"); | |
System::Console::WriteLine(System::String(u"Portion #0: ") + portion0->get_PortionFormat()->GetEffective()->get_FontHeight()); | |
System::Console::WriteLine(System::String(u"Portion #1: ") + portion1->get_PortionFormat()->GetEffective()->get_FontHeight()); | |
pres->get_DefaultTextStyle()->GetLevel(0)->get_DefaultPortionFormat()->set_FontHeight(24.0f); | |
System::Console::WriteLine(u"Effective font height after setting entire presentation default font height:"); | |
System::Console::WriteLine(System::String(u"Portion #0: ") + portion0->get_PortionFormat()->GetEffective()->get_FontHeight()); | |
System::Console::WriteLine(System::String(u"Portion #1: ") + portion1->get_PortionFormat()->GetEffective()->get_FontHeight()); | |
newShape->get_TextFrame()->get_Paragraphs()->idx_get(0)->get_ParagraphFormat()->get_DefaultPortionFormat()->set_FontHeight(40.0f); | |
System::Console::WriteLine(u"Effective font height after setting paragraph default font height:"); | |
System::Console::WriteLine(System::String(u"Portion #0: ") + portion0->get_PortionFormat()->GetEffective()->get_FontHeight()); | |
System::Console::WriteLine(System::String(u"Portion #1: ") + portion1->get_PortionFormat()->GetEffective()->get_FontHeight()); | |
newShape->get_TextFrame()->get_Paragraphs()->idx_get(0)->get_Portions()->idx_get(0)->get_PortionFormat()->set_FontHeight(55.0f); | |
System::Console::WriteLine(u"Effective font height after setting portion #0 font height:"); | |
System::Console::WriteLine(System::String(u"Portion #0: ") + portion0->get_PortionFormat()->GetEffective()->get_FontHeight()); | |
System::Console::WriteLine(System::String(u"Portion #1: ") + portion1->get_PortionFormat()->GetEffective()->get_FontHeight()); | |
newShape->get_TextFrame()->get_Paragraphs()->idx_get(0)->get_Portions()->idx_get(1)->get_PortionFormat()->set_FontHeight(18.0f); | |
System::Console::WriteLine(u"Effective font height after setting portion #1 font height:"); | |
System::Console::WriteLine(System::String(u"Portion #0: ") + portion0->get_PortionFormat()->GetEffective()->get_FontHeight()); | |
System::Console::WriteLine(System::String(u"Portion #1: ") + portion1->get_PortionFormat()->GetEffective()->get_FontHeight()); | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); |
获取表格的有效填充格式
使用 Aspose.Slides for C++,您可以获取不同表格逻辑部分的有效填充格式。为此,Aspose.Slides 中添加了 IFillFormatEffectiveData 接口,该接口包含有效的填充格式属性。请注意,单元格格式始终优先于行格式,行的优先级高于列,列的优先级高于整个表格。
因此,CellFormatEffectiveData 属性始终用于绘制表格。以下代码示例展示了如何获取不同表格逻辑部分的有效填充格式。
// The path to the documents directory. | |
const String templatePath = u"../templates/Presentation1.pptx"; | |
System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(templatePath); | |
System::SharedPtr<ITable> tbl = System::DynamicCast_noexcept<Aspose::Slides::ITable>(pres->get_Slides()->idx_get(0)->get_Shapes()->idx_get(0)); | |
System::SharedPtr<ITableFormatEffectiveData> tableFormatEffective = tbl->get_TableFormat()->GetEffective(); | |
System::SharedPtr<IRowFormatEffectiveData> rowFormatEffective = tbl->get_Rows()->idx_get(0)->get_RowFormat()->GetEffective(); | |
System::SharedPtr<IColumnFormatEffectiveData> columnFormatEffective = tbl->get_Columns()->idx_get(0)->get_ColumnFormat()->GetEffective(); | |
System::SharedPtr<ICellFormatEffectiveData> cellFormatEffective = tbl->idx_get(0, 0)->get_CellFormat()->GetEffective(); | |
System::SharedPtr<IFillFormatEffectiveData> tableFillFormatEffective = tableFormatEffective->get_FillFormat(); | |
System::SharedPtr<IFillFormatEffectiveData> rowFillFormatEffective = rowFormatEffective->get_FillFormat(); | |
System::SharedPtr<IFillFormatEffectiveData> columnFillFormatEffective = columnFormatEffective->get_FillFormat(); | |
System::SharedPtr<IFillFormatEffectiveData> cellFillFormatEffective = cellFormatEffective->get_FillFormat(); | |