推荐阅读:
获取有效的字体高度值
下面的示例演示在不同的表示结构级别上设置本地字体高度值之后,该部分的有效字体高度值的变化。
// 文档目录的路径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群()已开通,各类资源及时分享,欢迎交流讨论!
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!