上付き文字と下付き文字
Contents
[
Hide
]
上付き文字と下付き文字のテキストを管理する
任意の段落部分に上付き文字と下付き文字のテキストを追加できます。Aspose.Slides テキストフレームに上付き文字または下付き文字のテキストを追加するには、Escapement プロパティを PortionFormat クラスで使用する必要があります。
このプロパティは、上付き文字または下付き文字のテキストを返すか設定します (値は -100% (下付き文字) から 100% (上付き文字) まで)。例えば:
- Presentation クラスのインスタンスを作成します。
- インデックスを使用してスライドの参照を取得します。
- スライドに長方形型の IAutoShape を追加します。
- IAutoShape に関連付けられた ITextFrame にアクセスします。
- 既存の段落をクリアします。
- 上付き文字テキストを保持するための新しい段落オブジェクトを作成し、ITextFrame の IParagraphs コレクションに追加します。
- 新しいポーションオブジェクトを作成します。
- 上付き文字を追加するためにポーションの Escapement プロパティを 0 から 100 の間に設定します。(0 は上付き文字なしを意味します)
- ポーションにテキストを設定し、それを段落のポーションコレクションに追加します。
- 下付き文字テキストを保持するための新しい段落オブジェクトを作成し、ITextFrame の IParagraphs コレクションに追加します。
- 新しいポーションオブジェクトを作成します。
- 下付き文字を追加するためにポーションの Escapement プロパティを 0 から -100 の間に設定します。(0 は下付き文字なしを意味します)
- ポーションにテキストを設定し、それを段落のポーションコレクションに追加します。
- プレゼンテーションを PPTX ファイルとして保存します。
上記のステップの実装は以下に示されています。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
const String outPath = u"../out/AddingSuperscriptAndSubscriptTextInTextFrame_out.pptx"; | |
//const String templatePath = u"../templates/DefaultFonts.pptx"; | |
// Load the desired the presentation | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(); | |
// Access first slide | |
SharedPtr<ISlide> sld = pres->get_Slides()->idx_get(0); | |
// Add an AutoShape of Rectangle type | |
SharedPtr<IAutoShape> ashp = sld->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 100, 100, 300, 300); | |
// Add TextFrame to the Rectangle | |
SharedPtr<ITextFrame> tf = ashp->AddTextFrame(String::Empty); | |
tf->get_Paragraphs()->Clear(); | |
// Adding the first Paragraph | |
SharedPtr<Paragraph> superPar = MakeObject<Paragraph>(); | |
SharedPtr<Portion> portion1 = MakeObject<Portion>(u"SlideTitle"); | |
superPar->get_Portions()->Add(portion1); | |
SharedPtr<Portion> superPortion = MakeObject<Portion>(); | |
superPortion->get_PortionFormat()->set_Escapement(30); | |
superPortion->set_Text(u"TM"); | |
superPar->get_Portions()->Add(superPortion); | |
// Adding the first Paragraph | |
SharedPtr<Paragraph> subPar = MakeObject<Paragraph>(); | |
SharedPtr<Portion> portion2 = MakeObject<Portion>(u"a"); | |
subPar->get_Portions()->Add(portion2); | |
SharedPtr<Portion> subPortion = MakeObject<Portion>(); | |
subPortion->get_PortionFormat()->set_Escapement(-25); | |
subPortion->set_Text(u"i"); | |
subPar->get_Portions()->Add(subPortion); | |
//Adding to text frame | |
ashp->get_TextFrame()->get_Paragraphs()->Add(superPar); | |
ashp->get_TextFrame()->get_Paragraphs()->Add(subPar); | |
// Save PPTX to Disk | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |