解读:Aspose.Slides for .NET v19.8全新发布!什么是获取有效值的最佳方法?

Aspose.Slides for .NET是独特的演示处理API,使应用程序能够读取,编写,修改和转换PowerPoint演示文稿。作为独立的API,它提供了管理PowerPoint关键功能的功能,例如管理文本,形状,表格和动画,向幻灯片添加音频和视频,预览幻灯片等等。

Aspose.Slides for .NET(点击下载)更新至最新版v19.8,引入了用于获得有效值的新API,从而获取“本地”值和“有效”值。下面我们一起来了解一下具体内容吧!

什么是“本地”和“有效”值?

新的功能支持通过IPortion.PortionFormat在不同级别的表示结构层次结构中设置文本部分的属性。以下是其中一些:

  1. 在部分幻灯片的部分属性中
  2. 在布局或主幻灯片上的原型形状文本样式
  3. 在演示文稿全局文本设置中

对于任何这些级别,直接在此级别设置的值称为“本地”。在任何级别,可以定义或省略“本地”值。但最后,当应用程序(使用Aspose.Slides甚至PowerPoint本身构建)需要知道该部分应该是什么样的时候(在图像导出或在屏幕上绘图时),它使用“有效”值 - 完全使用层次结构构建的已定义值集,可能的值覆盖最低层的每个级别以及硬编码到PowerPoint中的默认值。

“有效数据”对象本质上是不可变的-它们仅用于获取最终的组合信息。“本地数据“”对象是可变的-它们用于设置属性。

获得有效值的最佳方法是什么?

启动Aspose.Slides v19.8所需要的只是从您希望获得有效值的本地格式调用GetEffective()方法。下面列举个例子说明:

 

using (Presentation pres = new Presentation("MyPresentation.pptx"))
{
    IAutoShape shape = pres.Slides[0].Shapes[0] as IAutoShape;
 
    ITextFrameFormat localTextFrameFormat = shape.TextFrame.TextFrameFormat;
    ITextFrameFormatEffectiveData effectiveTextFrameFormat = localTextFrameFormat.GetEffective();
 
    IPortionFormat localPortionFormat = shape.TextFrame.Paragraphs[0].Portions[0].PortionFormat;
    IPortionFormatEffectiveData effectivePortionFormat = localPortionFormat.GetEffective();
}

注意:

GetEffective()方法已添加到ITextFrameFormat、ITextStyle、IParagraphFormat、IPortionFormat、IFillFormat、ILineFormat、IEffectFormat、IThreeDFormat、ITableFormat、IRowFormat、IColumnFormat、ICellFormat、IBackground 和ITheme接口。

AccessibleEffectiveData和BaseEffectiveData类

这两个类都是抽象的,并在内部用于维护系统的统一有效值。AccessibleEffectiveData类是具有自己的继承层次结构的格式的有效数据类的基类。BaseEffectiveData类是AccessibleEffectiveData的基类,也是所有有效数据类的基类,它们没有自己的继承层次结构,并且作为更复杂的有效数据类的一部分。

以下是在不同的表示结构级别上设置本地字体高度值后,演示部分的有效字体高度值的代码。

using (Presentation pres = new Presentation())
{
    IAutoShape newShape = pres.Slides[0].Shapes.AddAutoShape(ShapeType.Rectangle, 100, 100, 400, 75, false);
    newShape.AddTextFrame("");
    newShape.TextFrame.Paragraphs[0].Portions.Clear();
 
    IPortion portion0 = new Portion("Sample text with first portion");
    IPortion portion1 = new Portion(" and second portion.");
 
    newShape.TextFrame.Paragraphs[0].Portions.Add(portion0);
    newShape.TextFrame.Paragraphs[0].Portions.Add(portion1);
 
    Console.WriteLine("Effective font height just after creation:");
    Console.WriteLine("Portion #0: " + portion0.PortionFormat.GetEffective().FontHeight);
    Console.WriteLine("Portion #1: " + portion1.PortionFormat.GetEffective().FontHeight);
 
    pres.DefaultTextStyle.GetLevel(0).DefaultPortionFormat.FontHeight = 24;
    Console.WriteLine("Effective font height after setting entire presentation default font height:");
    Console.WriteLine("Portion #0: " + portion0.PortionFormat.GetEffective().FontHeight);
    Console.WriteLine("Portion #1: " + portion1.PortionFormat.GetEffective().FontHeight);
 
    newShape.TextFrame.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 40;
    Console.WriteLine("Effective font height after setting paragraph default font height:");
    Console.WriteLine("Portion #0: " + portion0.PortionFormat.GetEffective().FontHeight);
    Console.WriteLine("Portion #1: " + portion1.PortionFormat.GetEffective().FontHeight);
 
    newShape.TextFrame.Paragraphs[0].Portions[0].PortionFormat.FontHeight = 55;
    Console.WriteLine("Effective font height after setting portion #0 font height:");
    Console.WriteLine("Portion #0: " + portion0.PortionFormat.GetEffective().FontHeight);
    Console.WriteLine("Portion #1: " + portion1.PortionFormat.GetEffective().FontHeight);
 
    newShape.TextFrame.Paragraphs[0].Portions[1].PortionFormat.FontHeight = 18;
    Console.WriteLine("Effective font height after setting portion #1 font height:");
    Console.WriteLine("Portion #0: " + portion0.PortionFormat.GetEffective().FontHeight);
    Console.WriteLine("Portion #1: " + portion1.PortionFormat.GetEffective().FontHeight);
}
 
// Output:
// Effective font height just after creation:
// Portion #0: 18
// Portion #1: 18
// Effective font height after setting entire presentation default font height:
// Portion #0: 24
// Portion #1: 24
// Effective font height after setting paragraph default font height:
// Portion #0: 40
// Portion #1: 40
// Effective font height after setting portion #0 font height:
// Portion #0: 55
// Portion #1: 40
// Effective font height after setting portion #1 font height:
// Portion #0: 55
// Portion #1: 18

转载于:https://my.oschina.net/u/4087915/blog/3101259

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值