PPT文件管理控件Aspose.Slides新功能示例详解——支持字体回退

元彦君
2023-12-01

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

近期,Aspose.Slides for .NET更新至最新版v19.10,现在有一些非常有趣且实用的功能值得为大家讲解一下,比如新增支持字体回退,以及在占位符中设置提示文本,接下来通过一些简单的示例来为大家说明一下!


支持字体回退

当遇到的字符不属于任何其他可用字体的组成部分时,将使用后备字体中的符号代替。通常,后备字体将包含代表各种类型的Unicode字符的符号。现在,该支持也已成为Aspose.Slides的一部分。

下面的代码示例演示如何使用FontFallBackRule对象设置字体回退。

 uint startUnicodeIndex = 0x0B80;
            uint endUnicodeIndex = 0x0BFF;

            IFontFallBackRule firstRule = new FontFallBackRule(startUnicodeIndex, endUnicodeIndex, "Vijaya");
            IFontFallBackRule secondRule = new FontFallBackRule(0x3040, 0x309F, "MS Mincho, MS Gothic");

            //字体列表也可以通过几种方式添加:
            string[] fontNames = new string[] { "Segoe UI Emoji, Segoe UI Symbol", "Arial" };

            IFontFallBackRule thirdRule = new FontFallBackRule(0x1F300, 0x1F64F, fontNames);

与此类似的基于Java的示例:

Presentation presentation = new Presentation();    
try {    
IFontFallBackRulesCollection userRulesList = new FontFallBackRulesCollection();    
userRulesList.add(new FontFallBackRule(0x0B80, 0x0BFF, "Vijaya"));    
userRulesList.add(new FontFallBackRule(0x3040, 0x309F, "MS Mincho, MS Gothic"));    
presentation.getFontsManager().setFontFallBackRulesCollection(userRulesList);    
} finally {    
if (presentation != null) presentation.dispose();    
}

在占位符中设置提示文本

一个提示文本是当它是第一负载,但是当用户开始输入到该消失出现在文本字段的文本的文本字段。基本上,这是为了使用户易于了解要在所选字段中输入的内容。我们知道标准布局和预构建布局包含带有默认文本的占位符,如Click添加标题  或  Click添加字幕。使用Aspose.Slides可以通过访问默认占位符来手动添加提示文本。下面的代码段显示了如何使用此功能:

// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Text();

using (Presentation pres = new Presentation(dataDir + "Presentation2.pptx"))
{
    ISlide slide = pres.Slides[0];
    foreach (IShape shape in slide.Slide.Shapes) // iterate through the slide
    {
        if (shape.Placeholder != null && shape is AutoShape)
        {
            string text = "";
            if (shape.Placeholder.Type == PlaceholderType.CenteredTitle) // title - the text is empty, PowerPoint displays "Click to add title". 
            {
                text = "Click to add custom title";
            }
            else if (shape.Placeholder.Type == PlaceholderType.Subtitle) // the same for subtitle.
            {
                text = "Click to add custom subtitle";
            }

            ((IAutoShape)shape).TextFrame.Text = text;

            Console.WriteLine($"Placeholder with text: {text}");
        }
    }

    pres.Save(dataDir + "Placeholders_PromptText.pptx", SaveFormat.Pptx);
}
 类似资料: