彩票走势图

解读:Aspose.Slides for .NET新功能(2)——获取有效的字体高度值

翻译|行业资讯|编辑:李显亮|2019-09-24 09:51:32.277|阅读 317 次

概述:Aspose.Slides for .NET更新至最新版v19.9,本文接着给大家介绍有一些非常有趣且实用的功能——获取有效的字体高度值,接下来通过一些简单的示例来为大家说明一下!

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

推荐阅读:【解读:Aspose.Slides for .NET新功能(1)——通过“替代文本”隐藏形状】


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

Aspose.Slides for .NET更新至最新版v19.9,本文接着给大家介绍有一些非常有趣且实用的功能——获取有效的字体高度值,接下来通过一些简单的示例来为大家说明一下!

点击下载最新版Aspose.Slides for .NET

获取有效的字体高度值

下面的示例演示在不同的表示结构级别上设置本地字体高度值之后,该部分的有效字体高度值的变化。

// 文档目录的路径
string dataDir = RunExamples.GetDataDir_Text();

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);

    pres.Save(dataDir + "SetLocalFontHeightValues.pptx",SaveFormat.Pptx);
}

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

//文档目录的路径。   
String dataDir = Utils.getDataDir(SetLocalFontHeightValues.class);
           
Presentation pres = new Presentation();
 try
 {
     IAutoShape newShape = pres.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 400, 75, false);
     newShape.addTextFrame("");
     newShape.getTextFrame().getParagraphs().get_Item(0).getPortions().clear();

     IPortion portion0 = new Portion("Sample text with first portion");
     IPortion portion1 = new Portion(" and second portion.");

     newShape.getTextFrame().getParagraphs().get_Item(0).getPortions().add(portion0);
     newShape.getTextFrame().getParagraphs().get_Item(0).getPortions().add(portion1);

     System.out.println("Effective font height just after creation:");
     System.out.println("Portion #0: " + portion0.getPortionFormat().getEffective().getFontHeight());
     System.out.println("Portion #1: " + portion1.getPortionFormat().getEffective().getFontHeight());

     pres.getDefaultTextStyle().getLevel(0).getDefaultPortionFormat().setFontHeight(24);
     System.out.println("Effective font height after setting entire presentation default font height:");
     System.out.println("Portion #0: " + portion0.getPortionFormat().getEffective().getFontHeight());
     System.out.println("Portion #1: " + portion1.getPortionFormat().getEffective().getFontHeight());

     newShape.getTextFrame().getParagraphs().get_Item(0).getParagraphFormat().getDefaultPortionFormat().setFontHeight(40);
     System.out.println("Effective font height after setting paragraph default font height:");
     System.out.println("Portion #0: " + portion0.getPortionFormat().getEffective().getFontHeight());
     System.out.println("Portion #1: " + portion1.getPortionFormat().getEffective().getFontHeight());

     newShape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().setFontHeight(55);
     System.out.println("Effective font height after setting portion #0 font height:");
     System.out.println("Portion #0: " + portion0.getPortionFormat().getEffective().getFontHeight());
     System.out.println("Portion #1: " + portion1.getPortionFormat().getEffective().getFontHeight());

     newShape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(1).getPortionFormat().setFontHeight(18);
     System.out.println("Effective font height after setting portion #1 font height:");
     System.out.println("Portion #0: " + portion0.getPortionFormat().getEffective().getFontHeight());
     System.out.println("Portion #1: " + portion1.getPortionFormat().getEffective().getFontHeight());
     
     pres.save(dataDir + "SetLocalFontHeightValues.pptx",SaveFormat.Pptx);
 } finally {
     if (pres != null) pres.dispose();
 }

与此类似的基于C++的示例:

//文档目录的路径。 
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正版授权的朋友可以哦~


ASPOSE技术交流QQ群(642018183)已开通,各类资源及时分享,欢迎交流讨论!

扫描关注“慧聚IT”微信公众号,及时获取更多产品最新动态及最新资讯

慧聚IT公众号二维码



标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@capbkgr.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP