欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

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

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);
}复制代码

如果您有任何疑问或需求,请随时加入aspose技术交流群(642018183)!