翻譯|行業資訊|編輯:李顯亮|2019-09-24 09:51:32.277|閱讀 370 次
概述: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,本文接著給大家介紹有一些非常有趣且實用的功能——獲取有效的字體高度值,接下來通過一些簡單的示例來為大家說明一下!
下面的示例演示在不同的表示結構級別上設置本地字體高度值之后,該部分的有效字體高度值的變化。
// 文檔目錄的路徑 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”微信公眾號,及時獲取更多產品最新動態及最新資訊
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn