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

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

推荐阅读:

获取有效的字体高度值

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

// 文档目录的路径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群()已开通,各类资源及时分享,欢迎交流讨论!

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

标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年8月20日
下一篇 2019年8月20日

相关推荐

发表回复

登录后才能评论