إضافة معادلات رياضية إلى عروض PowerPoint التقديمية باستخدام C++
نظرة عامة
PowerPoint يخزن المعادلات بصيغة Office Math Markup Language (OMML). مع Aspose.Slides for C++، يمكنك إنشاء نفس نوع المحتوى الرياضي برمجيًا: الكسور، الجذور، الدوال، الحدود، عوامل N-ary، المصفوفات، المصفوفات المتجانسة، وكتل الرياضيات المنسقة.
في PowerPoint، يضيف المستخدمون عادةً المعادلات من Insert > Equation:

النتيجة هي نص رياضي قابل للتحرير على الشريحة:

يقوم Aspose.Slides بإنشاء ذلك النص الرياضي من خلال ثلاث كائنات رئيسية:
- شكل رياضي، يُنشأ باستخدام AddMathShape، وهو الشكل الذي يحتوي على المعادلة.
- يخزن MathPortion المحتوى الرياضي داخل إطار نص الشكل.
- يحتوي MathParagraph على كائن واحد أو أكثر من كائنات MathBlock.
معظم الأمثلة أدناه تستخدم MathematicalText والطرق السلسة من IMathElement للحفاظ على شفرة مختصرة وسهلة القراءة.
للتعرف على سيناريوهات تصدير MathML، راجع تصدير معادلات رياضية من العروض التقديمية في C++.
إنشاء معادلة
يستخدم هذا المثال AddMathShape لإنشاء شكل رياضي ويضيف مبرهنة فيثاغورس:

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathBlock.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/IMathSuperscriptElement.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 120.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto equation = System::MakeObject<MathematicalText>(u"c")
- >SetSuperscript(u"2")
- >Join(u"=")
- >Join(System::MakeObject<MathematicalText>(u"a")->SetSuperscript(u"2"))
- >Join(u"+")
- >Join(System::MakeObject<MathematicalText>(u"b")->SetSuperscript(u"2"));
mathParagraph->Add(equation);
presentation->Save(u"pythagorean-theorem.pptx", SaveFormat::Pptx);
presentation->Dispose();
Note
AddMathShape ينشئ شكلًا يحتوي مسبقًا على فقرة رياضية. قم بالوصول إلى أول MathPortion، استدعِ get_MathParagraph، وأضف كتل رياضية أو عناصر رياضية إليه.دمج كتل الرياضيات
عندما تُبنى أجزاء المعادلة بشكل مستقل ككائنات IMathBlock، استخدم JoinBlock لدمجها. يبني المثال c² = في الكتلة اليسرى وa² + b² في الكتلة اليمنى. SetSuperscript يُنشئ أسس رياضية قابلة للتحرير لجميع القوى الثلاث.
#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/IMathSuperscriptElement.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto shape = slide->get_Shapes()->AddMathShape(20, 20, 600, 100);
auto mathPortion = System::ExplicitCast<MathPortion>(shape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto leftBlock = System::MakeObject<MathBlock>();
auto cSquared = System::MakeObject<MathematicalText>(u"c")->SetSuperscript(u"2");
leftBlock->Add(cSquared);
auto equalsSign = System::MakeObject<MathematicalText>(u"=");
leftBlock->Add(equalsSign);
auto rightBlock = System::MakeObject<MathBlock>();
auto aSquared = System::MakeObject<MathematicalText>(u"a")->SetSuperscript(u"2");
rightBlock->Add(aSquared);
auto plusSign = System::MakeObject<MathematicalText>(u"+");
rightBlock->Add(plusSign);
auto bSquared = System::MakeObject<MathematicalText>(u"b")->SetSuperscript(u"2");
rightBlock->Add(bSquared);
auto combinedBlock = leftBlock->JoinBlock(rightBlock);
mathParagraph->Add(combinedBlock);
presentation->Save(u"equation.pptx", SaveFormat::Pptx);
presentation->Dispose();
JoinBlock تُعيد leftBlock نفسها، التي تحتوي الآن على الجزأين بترتيب، وتترك rightBlock فارغة. أضف الكتلة المدمجة إلى IMathParagraph مرة واحدة فقط. بعد إعادة فتح equation.pptx، تحتوي الفقرة على كتلة واحدة تمثل c² = a² + b²، مع الحفاظ على جميع القوى الثلاث كقواسم علوية رياضية.
استدعاء Add كـ leftBlock->Add(rightBlock) يحاول بدلاً من ذلك تضمين كتلة داخل أخرى مباشرة ويُطلق استثناء System::InvalidOperationException.
إضافة كسور
استخدم Divide لإنشاء كسر. يمكنك اختيار نمط الكسر باستخدام MathFractionTypes.

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathFractionTypes.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 100.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto fraction = System::MakeObject<MathematicalText>(u"1")
- >Divide(u"x", MathFractionTypes::Skewed);
mathParagraph->Add(System::MakeObject<MathBlock>(fraction));
presentation->Save(u"fraction.pptx", SaveFormat::Pptx);
presentation->Dispose();
لإنشاء كسر مكدس، استخدم MathFractionTypes::Bar:
#include <DOM/MathText/MathFractionTypes.h>
#include <DOM/MathText/MathematicalText.h>
using namespace Aspose::Slides::MathText;
auto stackedFraction = System::MakeObject<MathematicalText>(u"x + 1")->Divide(u"y - 1", MathFractionTypes::Bar);
إضافة جذور
استخدم Radical لإنشاء جذر تربيعي، جذر مكعب، أو أي جذر آخر. يصبح العنصر الحالي هو القاعدة، ويصبح الوسيط هو الدرجة.

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 100.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto radical = System::MakeObject<MathematicalText>(u"x")
- >Radical(u"n");
mathParagraph->Add(System::MakeObject<MathBlock>(radical));
presentation->Save(u"radical.pptx", SaveFormat::Pptx);
presentation->Dispose();
عرض أو إخفاء درجة الجذر التربيعي
يمكن للجذر التربيعي إظهار رقم 2 صريحًا أو استخدام الترميز التقليدي √x. استخدم IMathRadical::set_HideDegree للتبديل بين الشكلين. كلاهما يحتفظ بالدرجة 2 والمُعامل x في المعادلة القابلة للتحرير.

يحفظ المثال الجذر التربيعي نفسه مرتين. في visible-degree.pptx يكون الرقم 2 ظاهرًا. في hidden-degree.pptx يكون مخفيًا.
#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathRadical.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto radicand = System::MakeObject<MathematicalText>(u"x");
auto radical = radicand->Radical(u"2");
auto block = System::MakeObject<MathBlock>(radical);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 200.0f, 100.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
mathParagraph->Add(block);
radical->set_HideDegree(false);
presentation->Save(u"visible-degree.pptx", SaveFormat::Pptx);
radical->set_HideDegree(true);
presentation->Save(u"hidden-degree.pptx", SaveFormat::Pptx);
presentation->Dispose();
إضافة دوال وحدود
استخدم AsArgumentOfFunction أو Function للدوال مثل sin(x)، log(x)، أو أسماء دوال مخصصة. للحدود، ضع lim في MathLimit أو استخدم SetLowerLimit.

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathLimit.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 100.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto limit = System::MakeObject<MathematicalText>(u"lim")
- >SetLowerLimit(u"x→∞")
- >Function(u"x");
mathParagraph->Add(System::MakeObject<MathBlock>(limit));
presentation->Save(u"functions-and-limits.pptx", SaveFormat::Pptx);
presentation->Dispose();
لإنشاء اسم دالة مخصص، اجعل اسم الدالة هو العنصر الحالي واستدعي Function مع معاملها:
#include <DOM/MathText/MathematicalText.h>
using namespace Aspose::Slides::MathText;
auto customFunction = System::MakeObject<MathematicalText>(u"f")->Function(u"x + 1");
إضافة عوامل N-ary وتكاملات
استخدم Nary للجمعيات، الاتحاد، التقاطع، وغيرها من العوامل الكبيرة. استخدم Integral للتكاملات. تسمح لك الطريقتان بتحديد الحدود السفلية والعلوية.

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/IMathSuperscriptElement.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathNaryOperatorTypes.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 120.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto summationBase = System::MakeObject<MathematicalText>(u"x")
- >SetSuperscript(u"k")
- >Join(System::MakeObject<MathematicalText>(u"a")->SetSuperscript(u"n-k"));
auto summation = summationBase->Nary(MathNaryOperatorTypes::Summation, u"k=0", u"n");
mathParagraph->Add(System::MakeObject<MathBlock>(summation));
presentation->Save(u"nary-operators.pptx", SaveFormat::Pptx);
presentation->Dispose();
عوامل N-ary مخصصة للعمليات الكبيرة مع حدود اختيارية. تُضاف العوامل البسيطة مثل +، -، و = عادةً كـ MathematicalText وتُدمج في التعبير.
لإنشاء تكامل، استخدم Integral:
#include <DOM/MathText/IMathBlock.h>
#include <DOM/MathText/IMathBox.h>
#include <DOM/MathText/IMathElement.h>
#include <DOM/MathText/MathIntegralTypes.h>
#include <DOM/MathText/MathematicalText.h>
using namespace Aspose::Slides::MathText;
auto integralBase = System::MakeObject<MathematicalText>(u"x")->Join(System::MakeObject<MathematicalText>(u"dx")->ToBox());
auto integral = integralBase->Integral(MathIntegralTypes::Simple, u"0", u"1");
إضافة مصفوفات
استخدم MathMatrix للصفوف والأعمدة. لا تشمل المصفوفات الأقواس افتراضيًا، لذا قم بتغليف المصفوة عندما تحتاج إلى أقواس مستديرة أو مربعة أو معقوفة.

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathBlock.h>
#include <DOM/MathText/IMathElement.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathMatrix.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 120.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto matrix = System::MakeObject<MathMatrix>(2, 3);
matrix->idx_set(0, 0, System::MakeObject<MathematicalText>(u"1"));
matrix->idx_set(0, 1, System::MakeObject<MathematicalText>(u"x"));
matrix->idx_set(1, 0, System::MakeObject<MathematicalText>(u"x"));
matrix->idx_set(1, 1, System::MakeObject<MathematicalText>(u"2"));
matrix->idx_set(1, 2, System::MakeObject<MathematicalText>(u"y"));
mathParagraph->Add(System::MakeObject<MathBlock>(matrix));
presentation->Save(u"matrix.pptx", SaveFormat::Pptx);
presentation->Dispose();
تحرير مصفوفة موجودة
افترض أن درس الجبر الخطي يبدأ بمصفوفة المعاملات في matrix.pptx، التي تم حفظها في المثال السابق. للتمرين التالي، احتفظ بالمعادلة الأولى، واستبدل الثانية بمعادلتين جديدتين، وعدّل مجموعة المتغيرات. افتح المصفوفة الموجودة عبر IMathMatrix للاحتفاظ بالمعاملات التي ما زالت صالحة.

تبدأ فهارس الصفوف والأعمدة من الصفر وتشير إلى المصفوفة كما هي عند كل استدعاء. إدراج صف قبل الفهرس 1 يحرك الصف الثاني الأصلي إلى الفهرس 2. الإدراج بعد الفهرس 2 يضيف صفًا. حذف الصف 2 يزيل المعادلة الثانية الأصلية وينقل الصف المضاف إلى أعلى موقع واحد. تنتقل الأعمدة بنفس الطريقة.
#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IPortion.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathBlock.h>
#include <DOM/MathText/IMathElement.h>
#include <DOM/MathText/IMathMatrix.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/IMathPortion.h>
#include <DOM/MathText/MathHorizontalAlignment.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>(u"matrix.pptx");
auto shape = System::ExplicitCast<IAutoShape>(presentation->get_Slide(0)->get_Shape(0));
auto portion = System::ExplicitCast<IMathPortion>(shape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto block = portion->get_MathParagraph()->idx_get(0);
auto matrix = System::ExplicitCast<IMathMatrix>(block->idx_get(0));
matrix->InsertRowBefore(1);
matrix->InsertRowAfter(2);
matrix->DeleteRow(2);
matrix->InsertColumnBefore(1);
matrix->InsertColumnAfter(3);
matrix->DeleteColumn(3);
// الخلايا الجديدة تكون في البداية null. اضبط المعاملات غير الصفرية أولاً.
matrix->idx_set(1, 0, System::MakeObject<MathematicalText>(u"12"));
matrix->idx_set(1, 1, System::MakeObject<MathematicalText>(u"1"));
matrix->idx_set(2, 2, System::MakeObject<MathematicalText>(u"10"));
matrix->idx_set(2, 3, System::MakeObject<MathematicalText>(u"1"));
for (auto row = 0; row < matrix->get_RowCount(); ++row)
{
for (auto column = 0; column < matrix->get_ColumnCount(); ++column)
{
if (matrix->idx_get(row, column) == nullptr)
matrix->idx_set(row, column, System::MakeObject<MathematicalText>(u"0"));
}
}
matrix->SetColumnAlignment(0, MathHorizontalAlignment::Left);
matrix->SetColumnsAlignment(1, 3, MathHorizontalAlignment::Right);
presentation->Save(u"updated-matrix.pptx", SaveFormat::Pptx);
presentation->Dispose();
SetColumnAlignment يضبط المحاذاة للعمود الأول إلى اليسار. SetColumnsAlignment يضبط المحاذاة لثلاثة أعمدة متتالية إلى اليمين، بدءًا من الفهرس 1. في updated-matrix.pptx، تحتوي المصفوفة على ثلاث معادلات وأربعة متغيرات. معاملات الصف الأول الأصلية 1 و x تظهر الآن في العمودين الأول والثالث.

إضافة مصفوفات معادلات
استخدم ToMathArray عندما تحتاج إلى معادلات محاذية أو مجموعة رأسية من التعبيرات.

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 140.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto equationArray = System::MakeObject<MathematicalText>(u"x")
- >Join(u"y")
- >ToMathArray();
mathParagraph->Add(System::MakeObject<MathBlock>(equationArray));
presentation->Save(u"equation-array.pptx", SaveFormat::Pptx);
presentation->Dispose();
محاذاة مصفوفة مع العناصر المجاورة
IMathArray::set_BaseJustification يتحكم في محاذاة عمودية للمصفوفة بالنسبة للعناصر الرياضية المجاورة لها. يقارن المثال أدناه المحاذاة مع الصف الأول، مركز المصفوفة، والصف الأخير.
ينشئ المثال التالي ثلاث مصفوفات متطابقة، كل واحدة بثلاثة صفوف والعناصر المجاورة A= و =B. كل النص الرياضي يستخدم Cambria Math بحجم 24 نقطة. يتغير فقط محاذاة المصفوفة.
#include <system/array.h>
#include <system/console.h>
#include <drawing/color.h>
#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IParagraphFormat.h>
#include <DOM/IPortion.h>
#include <DOM/IPortionFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/Fonts/FontData.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathArray.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathJustification.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathVerticalAlignment.h>
#include <DOM/MathText/MathRowSpacingRule.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <DOM/FillType.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/ILineFormat.h>
#include <DOM/ISlideSize.h>
#include <DOM/ITextFrameFormat.h>
#include <DOM/ShapeType.h>
#include <DOM/SlideSizeScaleType.h>
#include <DOM/TextAnchorType.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto createText = [](System::String value)
{
auto text = System::MakeObject<MathematicalText>(value);
text->get_Format()->set_FontHeight(24);
auto font = System::MakeObject<FontData>(u"Cambria Math");
text->get_Format()->set_LatinFont(font);
return text;
};
auto presentation = System::MakeObject<Presentation>();
presentation->get_SlideSize()->SetSize(780, 200, SlideSizeScaleType::DoNotScale);
auto slide = presentation->get_Slide(0);
MathVerticalAlignment alignments[] = {MathVerticalAlignment::Top, MathVerticalAlignment::Center, MathVerticalAlignment::Bottom};
System::String labels[] = {u"Top", u"Center", u"Bottom"};
for (auto i = 0; i < 3; i++)
{
auto label = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 20 + i * 260, 10, 240, 30);
label->get_FillFormat()->set_FillType(FillType::NoFill);
label->get_LineFormat()->get_FillFormat()->set_FillType(FillType::NoFill);
label->get_TextFrame()->set_Text(labels[i]);
auto labelFormat = label->get_TextFrame()->get_Paragraph(0)->get_Portion(0)->get_PortionFormat();
labelFormat->set_FontHeight(16);
labelFormat->get_FillFormat()->set_FillType(FillType::Solid);
labelFormat->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Black());
auto mathShape = slide->get_Shapes()->AddMathShape(20 + i * 260, 60, 240, 130);
mathShape->get_TextFrame()->get_TextFrameFormat()->set_AnchoringType(TextAnchorType::Top);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
mathParagraph->set_Justification(MathJustification::LeftJustified);
auto rows = System::MakeArray<System::SharedPtr<IMathElement>>({createText(u"x+y=3"), createText(u"x-y=1"), createText(u"x=2")});
auto equationArray = System::MakeObject<MathArray>(rows);
equationArray->set_BaseJustification(alignments[i]);
auto leftText = createText(u"A=");
auto rightText = createText(u"=B");
auto equation = System::MakeObject<MathBlock>(leftText)->Join(equationArray)->Join(rightText);
mathParagraph->Add(equation);
}
presentation->Save(u"equation-array-alignment.pptx", SaveFormat::Pptx);
presentation->Dispose();
يعرض المقارنة التالية العرض التقديمي المحفوظ في PowerPoint. لاحظ موضع A= و =B بجانب كل مصفوفة.

تكوين تباعد الصفوف
set_RowSpacingRule يحدد قاعدة التباعد للصفوف داخل المصفوفة. set_RowSpacing يزود قيمة رقمية لقاعدة تباعد صريحة وتُتجاهل عند استخدام القواعد المحددة مسبقًا.
بالنسبة لتباعد دقيق، تُقاس القيمة بالنقاط. بالنسبة لتباعد نسبي، تُقاس بنصف السطور: القيمة 3 في المثال تعني 1.5 سطر. استدعِ كلا الدالتين عند تحديد قيمة صريحة؛ تغيير القيمة الرقمية وحدها لا يحدد قاعدة التباعد.
يحفظ المثال أدناه خمسة عروض تقديمية بنفس المعادلات والمحاذاة وإعدادات الخط. الثلاثة الأولى تستخدم القواعد المحددة مسبقًا؛ الأخيران يظهران قيمًا صريحة.
#include <system/array.h>
#include <system/console.h>
#include <drawing/color.h>
#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IParagraphFormat.h>
#include <DOM/IPortion.h>
#include <DOM/IPortionFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/Fonts/FontData.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathArray.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathJustification.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathVerticalAlignment.h>
#include <DOM/MathText/MathRowSpacingRule.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto createText = [](System::String value)
{
auto text = System::MakeObject<MathematicalText>(value);
text->get_Format()->set_FontHeight(24);
auto font = System::MakeObject<FontData>(u"Cambria Math");
text->get_Format()->set_LatinFont(font);
return text;
};
struct ArraySettings
{
MathRowSpacingRule rule;
uint32_t spacing;
System::String name;
};
ArraySettings settings[] =
{
{MathRowSpacingRule::SingleLineGap, 0, u"SingleLineGap"},
{MathRowSpacingRule::OneAndAHalfLineGap, 0, u"OneAndAHalfLineGap"},
{MathRowSpacingRule::TwoLineGap, 0, u"TwoLineGap"},
{MathRowSpacingRule::Exactly, 20, u"Exactly"},
{MathRowSpacingRule::Multiple, 3, u"Multiple"}
};
for (const auto& setting : settings)
{
auto fileName = u"equation-array-" + setting.name + u".pptx";
auto presentation = System::MakeObject<Presentation>();
auto mathShape = presentation->get_Slide(0)->get_Shapes()->AddMathShape(20, 20, 600, 300);
auto paragraph = mathShape->get_TextFrame()->get_Paragraph(0);
paragraph->get_ParagraphFormat()->set_SpaceBefore(0);
paragraph->get_ParagraphFormat()->set_SpaceAfter(0);
auto mathPortion = System::ExplicitCast<MathPortion>(paragraph->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
mathParagraph->set_Justification(MathJustification::LeftJustified);
auto rows = System::MakeArray<System::SharedPtr<IMathElement>>({createText(u"x+y=3"), createText(u"x-y=1"), createText(u"x=2")});
auto equationArray = System::MakeObject<MathArray>(rows);
equationArray->set_BaseJustification(MathVerticalAlignment::Center);
equationArray->set_RowSpacingRule(setting.rule);
equationArray->set_RowSpacing(setting.spacing);
auto leftText = createText(u"A=");
auto rightText = createText(u"=B");
auto equation = System::MakeObject<MathBlock>(leftText)->Join(equationArray)->Join(rightText);
mathParagraph->Add(equation);
presentation->Save(fileName, SaveFormat::Pptx);
presentation->Dispose();
}
تباعد صفوف المصفوفة منفصل عن تباعد الفقرة. set_SpaceBefore و set_SpaceAfter يضيفان مسافة حول الفقرة الحاوية، وليس بين صفوف المصفوفة. وبالمثل، IMathParagraph::set_Justification يحدد موضع الفقرة الرياضية بأكملها أفقياً؛ ولا يستبدل إعداد محاذاة المصفوفة العمودية.
إضافة دوال مثلثية
استخدم AsArgumentOfFunction عندما يكون الوسيط هو العنصر الحالي ويُعرف اسم الدالة.

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathFunctionsOfOneArgument.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 100.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto cosine = System::MakeObject<MathematicalText>(u"2x")
- >AsArgumentOfFunction(MathFunctionsOfOneArgument::Cos);
mathParagraph->Add(System::MakeObject<MathBlock>(cosine));
presentation->Save(u"trigonometric-function.pptx", SaveFormat::Pptx);
presentation->Dispose();
إضافة أسفلية وعليا
استخدم مساعدي الأسفلية والعليا للمؤشرات والقوى. عندما يجب أن تظهر المؤشرات على الجانب الأيسر من القاعدة، استخدم SetSubSuperscriptOnTheLeft.

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 100.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto scripts = System::MakeObject<MathematicalText>(u"Y")
- >SetSubSuperscriptOnTheLeft(u"1", u"n");
mathParagraph->Add(System::MakeObject<MathBlock>(scripts));
presentation->Save(u"subscript-superscript.pptx", SaveFormat::Pptx);
presentation->Dispose();
إضافة محددات
استخدم Enclose لوضع تعبير داخل محددات. يمكنك أيضًا تعيين حرف فاصل لتعبيرات محددات تحتوي على عدة عناصر.

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 100.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto delimiter = System::MakeObject<MathematicalText>(u"x")
- >Join(u"y")
- >Join(u"z")
- >Enclose(u'<', u'>', u'|');
mathParagraph->Add(System::MakeObject<MathBlock>(delimiter));
presentation->Save(u"delimiters.pptx", SaveFormat::Pptx);
presentation->Dispose();
حجم ومحاذاة المحددات
مرر true إلى set_GrowToMatchOperandHeight للسماح للأقواس بالنمو حول معامل عالي، أو false للحفاظ على حجمها الطبيعي. set_DelimiterShape يستقبل أحد قيمتين من MathDelimiterShape. Centered يوسّط الأقواس على محور الرياضيات، الذي يمر عبر منتصف إشارة المساواة. Match يطابقها مع المحتوى المحاط. كلا الإعدادين يؤثران فقط على المحددات. يبقى التعبير داخلها كما هو.
يوضّح المثال كسرًا في أس سـ x بحيث يمتد التعبير أعلى الخط الأساسي أكثر من أسفله. جميع المعادلات الأربعة تستخدم نفس الأقواس وإعدادات الخط.
#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/IPortionFormat.h>
#include <DOM/MathText/IMathBlock.h>
#include <DOM/MathText/IMathDelimiter.h>
#include <DOM/MathText/IMathFraction.h>
#include <DOM/MathText/IMathSuperscriptElement.h>
#include <DOM/MathText/MathDelimiterShape.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto addExpression = [slide](float left, float top, bool grow, MathDelimiterShape shape)
{
auto fraction = System::MakeObject<MathematicalText>(u"a + b")->Divide(u"c + d");
auto power = System::MakeObject<MathematicalText>(u"x")->SetSuperscript(fraction);
auto delimiter = power->Enclose(u'(', u')');
delimiter->set_GrowToMatchOperandHeight(grow);
delimiter->set_DelimiterShape(shape);
auto mathShape = slide->get_Shapes()->AddMathShape(left, top, 300, 100);
auto portion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
portion->get_PortionFormat()->set_FontHeight(32);
auto equation = System::MakeObject<MathematicalText>(u"y = ")->Join(delimiter);
portion->get_MathParagraph()->Add(equation);
};
addExpression(20, 20, true, MathDelimiterShape::Centered);
addExpression(350, 20, true, MathDelimiterShape::Match);
addExpression(20, 140, false, MathDelimiterShape::Centered);
addExpression(350, 140, false, MathDelimiterShape::Match);
presentation->Save(u"delimiter-sizing.pptx", SaveFormat::Pptx);
presentation->Dispose();
في PowerPoint، قارن الصفوف لرؤية تأثير النمو. في الصف العلوي، تنمو الأقواس لتغلق الأس وتظهر مماثلة لكلا الشكلين. في الصف السفلي، يكون النمو معطلًا. الأقواس الأصغر على اليسار (Centered) تتوازي مع إشارة المساواة، بينما الأقواس على اليمين (Match) تقع أعلى حول التعبير.

إضافة إطار حدّي
استدعِ ToBorderBox على كسر لتأطير التعبير بالكامل. يُظهر IMathBorderBox المرجع جميع الجوانب الأربعة افتراضيًا. استخدم set_HideTop، set_HideBottom، set_HideLeft، و set_HideRight لإزالة الجوانب الفردية.
يوضع المثال ست نسخ من نفس الكسر على شريحة واحدة. لإظهار الإلغاء، أخفِ جميع الجوانب الأربعة واضبط set_StrikethroughBottomLeftToTopRight لخط مائل صاعد (↗) أو set_StrikethroughTopLeftToBottomRight لخط مائل هابط (↘). يمكنك أيضًا استخدام set_StrikethroughHorizontal أو set_StrikethroughVertical مع أي تركيبة من الجوانب المرئية.
#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IPortionFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ISlideSize.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathBorderBox.h>
#include <DOM/MathText/IMathFraction.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <DOM/SlideSizeScaleType.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
presentation->get_SlideSize()->SetSize(540, 220, SlideSizeScaleType::DoNotScale);
auto slide = presentation->get_Slide(0);
auto addFraction = [slide](float x, float y, bool hideBorder = false)
{
auto fraction = System::MakeObject<MathematicalText>(u"x+1")->Divide(u"y+2");
auto box = fraction->ToBorderBox();
box->set_HideTop(hideBorder);
box->set_HideBottom(hideBorder);
box->set_HideLeft(hideBorder);
box->set_HideRight(hideBorder);
auto shape = slide->get_Shapes()->AddMathShape(x, y, 160, 90);
auto portion = System::ExplicitCast<MathPortion>(shape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
portion->get_PortionFormat()->set_FontHeight(28);
auto mathBlock = System::MakeObject<MathBlock>(box);
portion->get_MathParagraph()->Add(mathBlock);
return box;
};
addFraction(10, 10);
auto partial = addFraction(190, 10);
partial->set_HideTop(true);
partial->set_HideRight(true);
addFraction(370, 10, true)->set_StrikethroughBottomLeftToTopRight(true);
addFraction(10, 120, true)->set_StrikethroughTopLeftToBottomRight(true);
addFraction(190, 120, true)->set_StrikethroughHorizontal(true);
addFraction(370, 120)->set_StrikethroughVertical(true);
presentation->Save(u"border-box.pptx", SaveFormat::Pptx);
presentation->Dispose();

في هذا الكسر، يتقاطع الخط الأفقي مع شريط الكسر. الخط العمودي يعبر كلًا من البسط والمقام بينما يظل الإطار المحيط مرئيًا. هذه الخطوط تزين كامل التعبير. خط الشطب العادي يُطبق على الأحرف في مقطع نصي. بعد إعادة فتح العرض التقديمي في PowerPoint، لا يزال يمكنك تحرير البسط والمقام بشكل مستقل.
التحكم في الرؤية والتخطيط باستخدام عناصر Phantom
قم بتغليف تعبير داخل MathPhantom للتحكم في رؤيته والمسافة التي يضيفها إلى المعادلة بشكل مستقل. طرق الضبط في IMathPhantom تتحكم بما يلي:
| الطريقة | التأثير |
|---|---|
| set_Show | مرّر false لإخفاء التعبير. لا تزال أبعاده تُساهم في التخطيط ما لم تكن الإعدادات المقابلة أدناه true. |
| set_ZeroWidth | اعتبر عرض التعبير الأفقي صفرًا، مما يسمح للعناصر المجاورة بالاقتراب أكثر. |
| set_ZeroAsc | اعتبر صعوده، الارتفاع فوق الخط الأساسي، صفرًا. هذا يمكن أن يقلل المسافة المحجوزة فوق العناصر المجاورة. |
| set_ZeroDesc | اعتبر نزوله، العمق تحت الخط الأساسي، صفرًا. هذا يمكن أن يقرّب شريط الكسر أو محتوى آخر أسفل التعبير إلى الجيران. |
الخط الأساسي هو الخط المرجعي الذي تستند عليه الحروف الرياضية العادية. إخفاء المحتوى لا يزيل أبعاده، ومعاملة بُعد كصفر لا تحذف التعبير. يظل التعبير الأساسي متاحًا عبر get_Base. مرّر true إلى set_Show لعرضه مرة أخرى؛ تبقى إعدادات الأبعاد كما هي.
ينشئ المثال أدناه خمسة نماذج متجاورة: كسر مرئي، كسر مخفي يحتفظ بالمساحة، وثلاثة كسور مخفية مع بُعد واحد يُعامل كصفر. كل نموذج يستخدم نفس التعبير المحيط وخط Cambria Math بحجم 24 نقطة. جميع أشكال المعادلة لها نفس الموضع العلوي، المميز بدليل رمادي. وضع الـ phantom في البسط لكسر خارجي يجعل تغييرات التخطيط العمودي أسهل في الملاحظة.
#include <array>
#include <drawing/color.h>
#include <DOM/FillType.h>
#include <DOM/Fonts/FontData.h>
#include <DOM/IAutoShape.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/ILineFormat.h>
#include <DOM/IParagraph.h>
#include <DOM/IPortion.h>
#include <DOM/IPortionFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ISlideSize.h>
#include <DOM/ITextFrame.h>
#include <DOM/ITextFrameFormat.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathFraction.h>
#include <DOM/MathText/MathPhantom.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <DOM/SlideSizeScaleType.h>
#include <DOM/TextAnchorType.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto createText = [](System::String value)
{
auto text = System::MakeObject<MathematicalText>(value);
text->get_Format()->set_FontHeight(24);
auto font = System::MakeObject<FontData>(u"Cambria Math");
text->get_Format()->set_LatinFont(font);
return text;
};
auto presentation = System::MakeObject<Presentation>();
presentation->get_SlideSize()->SetSize(1000, 180, SlideSizeScaleType::DoNotScale);
auto slide = presentation->get_Slide(0);
std::array<System::String, 5> labels = {u"Visible", u"Hidden: reserves space", u"Hidden: ZeroWidth", u"Hidden: ZeroAsc", u"Hidden: ZeroDesc"};
auto guide = slide->get_Shapes()->AddAutoShape(ShapeType::Line, 10, 60, 980, 0);
guide->get_LineFormat()->get_FillFormat()->set_FillType(FillType::Solid);
guide->get_LineFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_LightGray());
for (auto i = 0; i < labels.size(); i++)
{
auto left = 10 + i * 200;
auto label = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, left, 10, 190, 30);
label->get_FillFormat()->set_FillType(FillType::NoFill);
label->get_LineFormat()->get_FillFormat()->set_FillType(FillType::NoFill);
label->get_TextFrame()->set_Text(labels[i]);
auto labelFormat = label->get_TextFrame()->get_Paragraph(0)->get_Portion(0)->get_PortionFormat();
labelFormat->set_FontHeight(14);
labelFormat->get_FillFormat()->set_FillType(FillType::Solid);
labelFormat->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Black());
auto fractionNumerator = createText(u"a+b");
auto fractionDenominator = createText(u"c+d");
auto fraction = System::MakeObject<MathFraction>(fractionNumerator, fractionDenominator);
auto phantom = System::MakeObject<MathPhantom>(fraction);
phantom->set_Show(i == 0);
phantom->set_ZeroWidth(i == 2);
phantom->set_ZeroAsc(i == 3);
phantom->set_ZeroDesc(i == 4);
auto leadingText = createText(u"x+");
auto trailingText = createText(u"+y");
auto numeratorBlock = System::MakeObject<MathBlock>(leadingText);
auto numerator = numeratorBlock->Join(phantom)->Join(trailingText);
auto denominator = createText(u"z");
auto equation = System::MakeObject<MathFraction>(numerator, denominator);
auto shape = slide->get_Shapes()->AddMathShape(left, 60, 190, 100);
shape->get_TextFrame()->get_TextFrameFormat()->set_AnchoringType(TextAnchorType::Top);
auto mathPortion = System::ExplicitCast<MathPortion>(shape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto mathBlock = System::MakeObject<MathBlock>(equation);
mathParagraph->Add(mathBlock);
}
presentation->Save(u"math-phantom.pptx", SaveFormat::Pptx);
presentation->Dispose();

تجميع المصطلحات
استخدم Group لوضع رمز تجميع فوق أو تحت تعبير. أضف حدًا لتسمية المصطلحات المجمعة.

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathGroupingCharacter.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathTopBotPositions.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 120.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto grouped = System::MakeObject<MathematicalText>(u"x + y")
- >Group(u'\u23DF', MathTopBotPositions::Bottom, MathTopBotPositions::Top)
- >SetLowerLimit(u"any text");
mathParagraph->Add(System::MakeObject<MathBlock>(grouped));
presentation->Save(u"grouped-terms.pptx", SaveFormat::Pptx);
presentation->Dispose();
تنسيق عناصر الرياضيات
استخدم مساعدي التنسيق فقط حيث يوضحون الصيغة. على سبيل المثال، Overbar يضع شريطًا فوق عنصر رياضي.

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 100.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto overbar = System::MakeObject<MathematicalText>(u"ABC")->Overbar();
mathParagraph->Add(System::MakeObject<MathBlock>(overbar));
presentation->Save(u"overbar.pptx", SaveFormat::Pptx);
presentation->Dispose();
تنسيق النص في معادلة موجودة
لتنسيق النص عبر معادلة موجودة، استعرض شجرة عناصر كل كتلة رياضية. IMathElement::GetChildren تُعيد فقط الأطفال المباشرين، لذا استدعِها بشكل تكراري للوصول إلى النص داخل الكسور، السُكربتات، الجذور، والهياكل المتداخلة الأخرى. تحقق من العنصر الحالي وكذلك أطفاله لتضمين العنصر الابتدائي عندما يكون MathematicalText.
يفترض هذا المثال أن عرضًا تقديميًا يحتوي على معادلة مثل z = xᵢ / ∛y، مع كسر يحتوي على أسفلية في البسط وجذر في المقام. معالجة العناصر العلوية فقط للكتلة سيتجاهل النص داخل الكسر. يجد المثال أجزاء رياضية في إطارات نص الشرائح، يصل إلى كتلها عبر IMathPortion::get_MathParagraph، ويضبط ارتفاع الخط إلى 28 نقطة باستخدام set_FontHeight، من خلال الوصول إلى تنسيق كل عنصر نصي عبر طريقة get_Format.
#include <functional>
#include <system/array.h>
#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IParagraphCollection.h>
#include <DOM/IPortion.h>
#include <DOM/IPortionCollection.h>
#include <DOM/IPortionFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ISlideCollection.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathBlock.h>
#include <DOM/MathText/IMathElement.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/IMathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
std::function<void(System::SharedPtr<IMathElement>)> formatMathText;
formatMathText = [&formatMathText](System::SharedPtr<IMathElement> element)
{
auto text = System::DynamicCast<MathematicalText>(element);
if (text != nullptr)
text->get_Format()->set_FontHeight(28.0f);
for (auto child : element->GetChildren())
formatMathText(child);
};
auto presentation = System::MakeObject<Presentation>(u"input.pptx");
for (auto slide : presentation->get_Slides())
{
for (auto shape : slide->get_Shapes())
{
auto autoShape = System::DynamicCast<IAutoShape>(shape);
if (autoShape == nullptr || autoShape->get_TextFrame() == nullptr)
continue;
for (auto paragraph : autoShape->get_TextFrame()->get_Paragraphs())
{
for (auto portion : paragraph->get_Portions())
{
auto mathPortion = System::DynamicCast<IMathPortion>(portion);
if (mathPortion != nullptr)
{
for (auto block : mathPortion->get_MathParagraph())
formatMathText(block);
}
}
}
}
}
presentation->Save(u"formatted-equations.pptx", SaveFormat::Pptx);
presentation->Dispose();
العرض المحفوظ يحتوي على تنسيق النص المحدث في كل مستوى من كل معادلة معالجة، مع الحفاظ على محتوى النص والبنية الرياضية.
مرجع سريع
| المهمة | الواجهة البرمجية الرئيسية |
|---|---|
| إنشاء نص رياضي | MathematicalText |
| دمج العناصر | IMathElement.Join |
| إنشاء كسور | IMathElement.Divide |
| إضافة أس فوقية أو أدنى | SetSuperscript, SetSubscript |
| إضافة دوال | Function, AsArgumentOfFunction |
| إضافة جذور | IMathElement.Radical |
| إضافة حدود | SetLowerLimit, SetUpperLimit |
| إضافة سكربتات على الجانب الأيسر | SetSubSuperscriptOnTheLeft |
| إضافة مجموعات وتكاملات | Nary, Integral |
| إضافة مصفوفات | MathMatrix |
| إضافة مصفوفات معادلات | ToMathArray |
| إضافة محددات | Enclose |
| إضافة أشرطة وإطارات | Overbar, ToBorderBox |
| تجميع المصطلحات | Group |
الأسئلة المتكررة
هل يمكنني تعديل معادلة PowerPoint موجودة؟
نعم. افتح العرض التقديمي، ابحث عن الشكل الذي يحتوي على MathPortion, استدعِ get_MathParagraph, وقم بتحديث كتل الرياضيات في تلك الفقرة.
هل تُحفظ المعادلات كرياضيات PowerPoint قابلة للتحرير؟
نعم. عند الحفظ بصيغة PPTX، يقوم Aspose.Slides بكتابة المعادلة كمحتوى Office math قابل للتحرير.
هل يمكنني تصدير المعادلات إلى LaTeX؟
نعم. احصل على IMathParagraph الخاص بالمعادلة من IMathPortion, واستدعِ IMathParagraph::ToLatex لتصديره مباشرة. للحصول على مثال كامل، راجع تصدير معادلات رياضية من العروض التقديمية في C++.