اضافه کردن معادلات ریاضی به ارائههای PowerPoint در Android
مرور کلی
PowerPoint معادلات را به صورت Office Math Markup Language (OMML) ذخیره میکند. با Aspose.Slides برای Android از طریق Java میتوانید همان نوع محتوای ریاضی را بهصورت برنامهنویسی ایجاد کنید: کسرها، رادیکالها، توابع، حدها، عملگرهای N-ary، ماتریکسها، آرایهها و بلوکهای ریاضی قالببندیشده.
در PowerPoint، کاربران معمولاً معادلات را از Insert > Equation اضافه میکنند:

نتیجه متن ریاضی قابل ویرایش روی اسلاید است:

Aspose.Slides این متن ریاضی را از طریق سه شیء اصلی میسازد:
- یک شکل ریاضی، که با addMathShape ایجاد میشود، شکلی است که معادله را شامل میشود.
- MathPortion محتویات ریاضی را داخل قاب متن شکل ذخیره میکند.
- MathParagraph یک یا چند شیء MathBlock را در بر میگیرد.
اکثریت مثالهای زیر از MathematicalText و متدهای fluent از IMathElement برای کوتاه و خوانا نگهداشتن کد استفاده میکنند.
برای سناریوهای استخراج MathML، به Export Math Equations from Presentations on Android مراجعه کنید.
ایجاد یک معادله
این مثال از addMathShape برای ایجاد یک شکل ریاضی استفاده میکند و قضیه فیثاغورث را اضافه میکند:

import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 120);
IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0)).getMathParagraph();
IMathBlock equation = new MathematicalText("c")
.setSuperscript("2")
.join("=")
.join(new MathematicalText("a").setSuperscript("2"))
.join("+")
.join(new MathematicalText("b").setSuperscript("2"));
mathParagraph.add(equation);
presentation.save("pythagorean-theorem.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
Note
addMathShape یک شکل ایجاد میکند که از پیش شامل یک پاراگراف ریاضی است. اولین MathPortion را دریافت کنید، getMathParagraph را فراخوانی کنید و بلوکها یا عناصر ریاضی را به آن اضافه کنید.اضافه کردن کسرها
از divide برای ایجاد یک کسر استفاده کنید. میتوانید سبک کسر را با MathFractionTypes انتخاب کنید.

import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0)).getMathParagraph();
IMathFraction fraction = new MathematicalText("1")
.divide("x", MathFractionTypes.Skewed);
mathParagraph.add(new MathBlock(fraction));
presentation.save("fraction.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
برای یک کسر پشتهای، از MathFractionTypes.Bar استفاده کنید:
import com.aspose.slides.*;
IMathFraction stackedFraction = new MathematicalText("x + 1").divide("y - 1", MathFractionTypes.Bar);
اضافه کردن رادیکالها
از radical برای ایجاد رادیکال درجه دوم، سوم یا سایر رادیکالها استفاده کنید. عنصر فعلی به پایه تبدیل میشود و آرگومان به درجه رادیکال.

import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0)).getMathParagraph();
IMathRadical radical = new MathematicalText("x")
.radical("n");
mathParagraph.add(new MathBlock(radical));
presentation.save("radical.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
اضافه کردن توابع و حدها
از asArgumentOfFunction یا function برای توابعی مانند sin(x)، log(x) یا نامهای تابع سفارشی استفاده کنید. برای حدها، lim را در یک MathLimit بگذارید یا از setLowerLimit استفاده کنید.

import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0)).getMathParagraph();
IMathFunction limit = new MathematicalText("lim")
.setLowerLimit("x→∞")
.function("x");
mathParagraph.add(new MathBlock(limit));
presentation.save("functions-and-limits.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
برای نام تابع سفارشی، نام تابع را عنصر فعلی کنید و function را با آرگومان آن فراخوانی کنید:
import com.aspose.slides.*;
IMathFunction customFunction = new MathematicalText("f").function("x + 1");
اضافه کردن عملگرهای N‑ary و انتگرالها
از nary برای جمعها، اجتماعها، اشتراکها و سایر عملگرهای بزرگ استفاده کنید. برای انتگرالها از integral استفاده کنید. هر دو متد امکان تنظیم حد پایین و بالایی را فراهم میآورند.

import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 120);
IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0)).getMathParagraph();
IMathBlock summationBase = new MathematicalText("x")
.setSuperscript("k")
.join(new MathematicalText("a").setSuperscript("n-k"));
IMathNaryOperator summation = summationBase.nary(MathNaryOperatorTypes.Summation, "k=0", "n");
mathParagraph.add(new MathBlock(summation));
presentation.save("nary-operators.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
عملگرهای N‑ary برای عملگرهای بزرگ با حدهای اختیاری هستند. عملگرهای ساده مثل +، - و = معمولاً بهصورت MathematicalText اضافه شده و به عبارت متصل میشوند.
برای یک انتگرال، از integral استفاده کنید:
import com.aspose.slides.*;
IMathBlock integralBase = new MathematicalText("x").join(new MathematicalText("dx").toBox());
IMathNaryOperator integral = integralBase.integral(MathIntegralTypes.Simple, "0", "1");
اضافه کردن ماتریکسها
از MathMatrix برای ردیفها و ستونها استفاده کنید. بهصورت پیشفرض ماتریکسها علامت قوس ندارند، بنابراین برای نیاز به پرانتز، کروشه یا آکولاد ماتریکس را درون این نمادها بپیچید.

import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 120);
IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0)).getMathParagraph();
MathMatrix matrix = new MathMatrix(2, 3);
matrix.set_Item(0, 0, new MathematicalText("1"));
matrix.set_Item(0, 1, new MathematicalText("x"));
matrix.set_Item(1, 0, new MathematicalText("x"));
matrix.set_Item(1, 1, new MathematicalText("2"));
matrix.set_Item(1, 2, new MathematicalText("y"));
mathParagraph.add(new MathBlock(matrix));
presentation.save("matrix.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
اضافه کردن آرایههای معادله
از toMathArray وقتی به معادلات همراستا یا یک پشته عمودی از عبارات نیاز دارید، استفاده کنید.

import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 140);
IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0)).getMathParagraph();
IMathArray equationArray = new MathematicalText("x")
.join("y")
.toMathArray();
mathParagraph.add(new MathBlock(equationArray));
presentation.save("equation-array.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
همراستایی آرایه با عناصر اطراف
setBaseJustification تنظیمات عمودی آرایه نسبت به عناصر ریاضی کناری را کنترل میکند. مثال زیر همراستایی ردیف اول، مرکز آرایه و ردیف آخر را مقایسه میکند.
مثال زیر سه آرایه یکسان با هر کدام سه ردیف و عناصری همجوار A= و =B ایجاد میکند. تمام متنهای ریاضی از Cambria Math با اندازه ۲۴ پوینت استفاده میکنند. فقط همراستایی آرایه تغییر میکند.
import com.aspose.slides.*;
import android.graphics.Color;
class MathTextFactory {
MathematicalText createText(String value) {
MathematicalText text = new MathematicalText(value);
text.getFormat().setFontHeight(24);
text.getFormat().setLatinFont(new FontData("Cambria Math"));
return text;
}
}
MathTextFactory factory = new MathTextFactory();
Presentation presentation = new Presentation();
try {
presentation.getSlideSize().setSize(780, 200, SlideSizeScaleType.DoNotScale);
ISlide slide = presentation.getSlides().get_Item(0);
int[] alignments = { MathVerticalAlignment.Top, MathVerticalAlignment.Center, MathVerticalAlignment.Bottom };
String[] alignmentNames = { "Top", "Center", "Bottom" };
for (int i = 0; i < alignments.length; i++) {
IAutoShape label = slide.getShapes().addAutoShape(ShapeType.Rectangle, 20 + i * 260, 10, 240, 30);
label.getFillFormat().setFillType(FillType.NoFill);
label.getLineFormat().getFillFormat().setFillType(FillType.NoFill);
label.getTextFrame().setText(alignmentNames[i]);
IPortionFormat labelFormat = label.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat();
labelFormat.setFontHeight(16);
labelFormat.getFillFormat().setFillType(FillType.Solid);
labelFormat.getFillFormat().getSolidFillColor().setColor(Color.BLACK);
IAutoShape mathShape = slide.getShapes().addMathShape(20 + i * 260, 60, 240, 130);
mathShape.getTextFrame().getTextFrameFormat().setAnchoringType(TextAnchorType.Top);
IMathParagraph mathParagraph = ((IMathPortion) mathShape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0)).getMathParagraph();
mathParagraph.setJustification(MathJustification.LeftJustified);
IMathElement[] rows = { factory.createText("x+y=3"), factory.createText("x-y=1"), factory.createText("x=2") };
MathArray equationArray = new MathArray(rows[0]);
equationArray.getArguments().add(rows[1]);
equationArray.getArguments().add(rows[2]);
equationArray.setBaseJustification(alignments[i]);
MathematicalText leftText = factory.createText("A=");
MathematicalText rightText = factory.createText("=B");
IMathBlock equation = new MathBlock(leftText).join(equationArray).join(rightText);
mathParagraph.add(equation);
}
presentation.save("equation-array-alignment.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
مقایسه زیر ارائه ذخیرهشده در PowerPoint را نشان میدهد. به موقعیت A= و =B کنار هر آرایه توجه کنید.

پیکربندی فاصله بین ردیفها
setRowSpacingRule قانون فاصلهگذاری بین ردیفهای داخل آرایه را انتخاب میکند. setRowSpacing مقدار عددی برای یک قانون فاصلهگذاری صریح فراهم میکند و توسط قوانین پیشفرض نادیده گرفته میشود.
برای فاصله دقیق، مقدار بر حسب پوینت اندازهگیری میشود. برای فاصله نسبی، بر حسب نیمخط اندازهگیری میشود: مقدار 3 در مثال برابر با ۱٫۵ خط است. هنگام تعیین مقدار صریح، هر دو ویژگی را تنظیم کنید؛ تغییر تنها مقدار عددی قانون فاصلهگذاری را انتخاب نمیکند.
مثال زیر پنج ارائه با معادلات، همراستایی و تنظیمات قلم یکسان ذخیره میکند. سه مورد اول از پیشتنظیمها استفاده میکنند؛ دو مورد آخر مقادیر صریح را نشان میدهند.
import com.aspose.slides.*;
class MathTextFactory {
MathematicalText createText(String value) {
MathematicalText text = new MathematicalText(value);
text.getFormat().setFontHeight(24);
text.getFormat().setLatinFont(new FontData("Cambria Math"));
return text;
}
}
MathTextFactory factory = new MathTextFactory();
int[] rules = { MathRowSpacingRule.SingleLineGap, MathRowSpacingRule.OneAndAHalfLineGap, MathRowSpacingRule.TwoLineGap, MathRowSpacingRule.Exactly, MathRowSpacingRule.Multiple };
int[] spacingValues = { 0, 0, 0, 20, 3 };
String[] ruleNames = { "SingleLineGap", "OneAndAHalfLineGap", "TwoLineGap", "Exactly", "Multiple" };
for (int i = 0; i < rules.length; i++) {
String fileName = "equation-array-" + ruleNames[i] + ".pptx";
Presentation presentation = new Presentation();
try {
IAutoShape mathShape = presentation.getSlides().get_Item(0).getShapes().addMathShape(20, 20, 600, 300);
IParagraph paragraph = mathShape.getTextFrame().getParagraphs().get_Item(0);
paragraph.getParagraphFormat().setSpaceBefore(0);
paragraph.getParagraphFormat().setSpaceAfter(0);
IMathParagraph mathParagraph = ((IMathPortion) paragraph.getPortions().get_Item(0)).getMathParagraph();
mathParagraph.setJustification(MathJustification.LeftJustified);
IMathElement[] rows = { factory.createText("x+y=3"), factory.createText("x-y=1"), factory.createText("x=2") };
MathArray equationArray = new MathArray(rows[0]);
equationArray.getArguments().add(rows[1]);
equationArray.getArguments().add(rows[2]);
equationArray.setBaseJustification(MathVerticalAlignment.Center);
equationArray.setRowSpacingRule(rules[i]);
equationArray.setRowSpacing(spacingValues[i]);
MathematicalText leftText = factory.createText("A=");
MathematicalText rightText = factory.createText("=B");
IMathBlock equation = new MathBlock(leftText).join(equationArray).join(rightText);
mathParagraph.add(equation);
presentation.save(fileName, SaveFormat.Pptx);
} finally {
presentation.dispose();
}
}
فاصله ردیفهای آرایه جدا از فاصله پاراگراف است. setSpaceBefore و setSpaceAfter فضای اطراف پاراگراف حاوی را اضافه میکنند، نه بین ردیفهای آرایه. بهطور مشابه، IMathParagraph.setJustification کل پاراگراف ریاضی را افقی موقعیت میدهد؛ تنظیم عمودی آرایه را جایگزین نمیکند.
اضافه کردن توابع مثلثاتی
از asArgumentOfFunction وقتی آرگومان عنصر فعلی است و نام تابع شناختهشده است، استفاده کنید.

import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0)).getMathParagraph();
IMathFunction cosine = new MathematicalText("2x")
.asArgumentOfFunction(MathFunctionsOfOneArgument.Cos);
mathParagraph.add(new MathBlock(cosine));
presentation.save("trigonometric-function.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
اضافه کردن زیرنویس و بالانس
از کمککنندههای زیرنویس و بالانس برای نماهای نمایهای و توانها استفاده کنید. وقتی نماها باید در سمت چپ پایه ظاهر شوند، از setSubSuperscriptOnTheLeft استفاده کنید.

import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0)).getMathParagraph();
IMathLeftSubSuperscriptElement scripts = new MathematicalText("Y")
.setSubSuperscriptOnTheLeft("1", "n");
mathParagraph.add(new MathBlock(scripts));
presentation.save("subscript-superscript.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
اضافه کردن جداکنندهها
از enclose برای قرار دادن یک عبارت داخل جداکنندهها استفاده کنید. میتوانید یک کاراکتر جداکننده برای عبارات شامل چند عنصر تنظیم کنید.

import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0)).getMathParagraph();
IMathDelimiter delimiter = new MathematicalText("x")
.join("y")
.join("z")
.enclose('<', '>');
delimiter.setSeparatorCharacter('|');
mathParagraph.add(new MathBlock(delimiter));
presentation.save("delimiters.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
اندازه و همراستایی جداکنندهها
به setGrowToMatchOperandHeight مقدار true بدهید تا پرانتزها برای عملوند بلندتر بزرگ شوند، یا مقدار false بدهید تا اندازهٔ معمولی خود را حفظ کنند. از setDelimiterShape همراه با یکی از مقادیر MathDelimiterShape استفاده کنید. Centered پرانتزها را بر محور ریاضی (میان علامت مساوی) مرکز میکند؛ Match آنها را با محتوای داخل همراستا میکند. هر دو تنظیم تنها روی جداکنندهها اثر میگذارند؛ عبارت داخل همانطور میماند.
مثال یک کسر را در توان x قرار میدهد تا عبارت بالاتر از خط پایه بسط یابد. هر چهار معادله از همان پرانتزها و تنظیمات قلم استفاده میکنند.
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
for (int row = 0; row < 2; row++) {
for (int column = 0; column < 2; column++) {
IMathFraction fraction = new MathematicalText("a + b").divide("c + d");
IMathSuperscriptElement power = new MathematicalText("x").setSuperscript(fraction);
IMathDelimiter delimiter = power.enclose('(', ')');
delimiter.setGrowToMatchOperandHeight(row == 0);
delimiter.setDelimiterShape(column == 0 ? MathDelimiterShape.Centered : MathDelimiterShape.Match);
IAutoShape mathShape = slide.getShapes().addMathShape(20 + 330 * column, 20 + 120 * row, 300, 100);
MathPortion portion = (MathPortion) mathShape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0);
portion.getPortionFormat().setFontHeight(32);
IMathBlock equation = new MathematicalText("y = ").join(delimiter);
portion.getMathParagraph().add(equation);
}
}
presentation.save("delimiter-sizing.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
در PowerPoint، ردیفها را مقایسه کنید تا اثر رشد را ببینید. در ردیف بالا، پرانتزها برای بستن توان رشد میکنند و برای هر دو شکل یکند. در ردیف پایین، رشد غیرفعال است. پرانتزهای کوچکتر در سمت چپ (Centered) با علامت مساوی همراستا هستند، در حالی که آنهای راست (Match) بالاتر از عبارت قرار میگیرند.

اضافه کردن جعبه حاشیهای
روی یک کسر متد toBorderBox را فراخوانی کنید تا کل عبارت را در یک قاب بگذارید. شیء بازگشتی IMathBorderBox بهطور پیشفرض چهار طرف را نشان میدهد. برای حذف هر طرف به ترتیب از setHideTop، setHideBottom، setHideLeft و setHideRight استفاده کنید.
مثال شش نسخه از همان کسر را روی یک اسلاید قرار میدهد. برای نشان دادن حذف، چهار طرف را مخفی کنید و به setStrikethroughBottomLeftToTopRight مقدار true بدهید تا خط مورب صعودی (↗) یا به setStrikethroughTopLeftToBottomRight مقدار true بدهید تا خط مورب نزولی (↘) ایجاد شود. همچنین میتوانید از setStrikethroughHorizontal یا setStrikethroughVertical همراه با هر ترکیبی از طرفهای قابل مشاهده استفاده کنید.
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
presentation.getSlideSize().setSize(540, 220, SlideSizeScaleType.DoNotScale);
ISlide slide = presentation.getSlides().get_Item(0);
class FractionBuilder {
IMathBorderBox addFraction(float x, float y, boolean hideBorder) {
IMathFraction fraction = new MathematicalText("x+1").divide("y+2");
IMathBorderBox box = fraction.toBorderBox();
box.setHideTop(hideBorder);
box.setHideBottom(hideBorder);
box.setHideLeft(hideBorder);
box.setHideRight(hideBorder);
IAutoShape shape = slide.getShapes().addMathShape(x, y, 160, 90);
MathPortion portion = (MathPortion) shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0);
portion.getPortionFormat().setFontHeight(28);
portion.getMathParagraph().add(new MathBlock(box));
return box;
}
}
FractionBuilder builder = new FractionBuilder();
builder.addFraction(10, 10, false);
IMathBorderBox partial = builder.addFraction(190, 10, false);
partial.setHideTop(true);
partial.setHideRight(true);
builder.addFraction(370, 10, true).setStrikethroughBottomLeftToTopRight(true);
builder.addFraction(10, 120, true).setStrikethroughTopLeftToBottomRight(true);
builder.addFraction(190, 120, true).setStrikethroughHorizontal(true);
builder.addFraction(370, 120, false).setStrikethroughVertical(true);
presentation.save("border-box.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}

در این کسر، خط افقی بر روی نوار کسر همپوشانی دارد. خط عمودی هر دو صورت و مخرج را قطع میکند در حالی که حاشیه اطراف قابل رؤیت میماند. این خطوط تمام عبارت را تزئین میکنند. خطخوردهٔ متن معمولی فقط بر روی کاراکترهای یک برش متن اعمال میشود. پس از باز کردن مجدد ارائه در PowerPoint، میتوانید صورت و مخرج را بهطور مستقل ویرایش کنید.
کنترل نمایش و چیدمان با عناصر فانتوم
یک عبارت را با MathPhantom بپیچید تا نمایش آن و فضای اشغالشده توسط معادله را بهطور مستقل کنترل کنید. متدهای IMathPhantom موارد زیر را تنظیم میکنند:
| متد | اثر |
|---|---|
| setShow | مقدار false را برای مخفی کردن عبارت بدهید. ابعاد آن همچنان در چیدمان شرکت میکند مگر زمانی که متدهای زیر مقدار true دریافت کنند. |
| setZeroWidth | عرض افقی عبارت را صفر در نظر بگیرد و اجازه دهد عناصر همجوار به هم نزدیکتر شوند. |
| setZeroAsc | ارتفاع بالای خط پایه (ascender) را صفر در نظر بگیرد؛ این میتواند فضای بالای عناصر همجوار را کاهش دهد. |
| setZeroDesc | عمق زیر خط پایه (descender) را صفر در نظر بگیرد؛ این میتواند نوار کسر یا محتوای دیگر زیر عبارت را به عناصر همجوار نزدیکتر کند. |
خط پایه، خط مرجع است که حروف ریاضی معمولی بر روی آن قرار میگیرند. مخفی کردن محتوا ابعاد آن را حذف نمیکند و در نظر گرفتن یک بعد بهعنوان صفر نیز عبارت را حذف نمیسازد. عبارت پایه از طریق getBase در دسترس است. برای نمایش مجدد، مقدار true را به setShow بدهید؛ تنظیمات ابعاد دستنخورده میمانند.
مثال زیر پنج نسخهٔ کنار هم ایجاد میکند: یک کسر قابل مشاهده، یک کسر مخفی که فضا را حفظ میکند و سه کسر مخفی که هر یک یک بعد را صفر در نظر میگیرد. هر نسخه از همان عبارت اطراف و Cambria Math با اندازهٔ ۲۴ پوینت استفاده میکند. تمام اشکال معادله موقعیت رأس بالا یکسانی دارند که با راهنمای خاکستری نشان داده شده است. قرار دادن فانتوم در صورت یک کسر خارجی باعث میشود تغییرات چیدمان عمودی واضحتر دیده شود.
import com.aspose.slides.*;
import android.graphics.Color;
class MathTextFactory {
MathematicalText createText(String value) {
MathematicalText text = new MathematicalText(value);
text.getFormat().setFontHeight(24);
text.getFormat().setLatinFont(new FontData("Cambria Math"));
return text;
}
}
MathTextFactory factory = new MathTextFactory();
Presentation presentation = new Presentation();
try {
presentation.getSlideSize().setSize(1000, 180, SlideSizeScaleType.DoNotScale);
ISlide slide = presentation.getSlides().get_Item(0);
String[] labels = { "Visible", "Hidden: reserves space", "Hidden: ZeroWidth", "Hidden: ZeroAsc", "Hidden: ZeroDesc" };
IAutoShape guide = slide.getShapes().addAutoShape(ShapeType.Line, 10, 60, 980, 0);
guide.getLineFormat().getFillFormat().setFillType(FillType.Solid);
guide.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.LTGRAY);
for (int i = 0; i < labels.length; i++) {
int left = 10 + i * 200;
IAutoShape label = slide.getShapes().addAutoShape(ShapeType.Rectangle, left, 10, 190, 30);
label.getFillFormat().setFillType(FillType.NoFill);
label.getLineFormat().getFillFormat().setFillType(FillType.NoFill);
label.getTextFrame().setText(labels[i]);
IPortionFormat labelFormat = label.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat();
labelFormat.setFontHeight(14);
labelFormat.getFillFormat().setFillType(FillType.Solid);
labelFormat.getFillFormat().getSolidFillColor().setColor(Color.BLACK);
MathematicalText fractionNumerator = factory.createText("a+b");
MathematicalText fractionDenominator = factory.createText("c+d");
MathFraction fraction = new MathFraction(fractionNumerator, fractionDenominator);
MathPhantom phantom = new MathPhantom(fraction);
phantom.setShow(i == 0);
phantom.setZeroWidth(i == 2);
phantom.setZeroAsc(i == 3);
phantom.setZeroDesc(i == 4);
MathematicalText leftText = factory.createText("x+");
MathematicalText rightText = factory.createText("+y");
IMathBlock numerator = new MathBlock(leftText).join(phantom).join(rightText);
MathematicalText denominator = factory.createText("z");
MathFraction equation = new MathFraction(numerator, denominator);
IAutoShape shape = slide.getShapes().addMathShape(left, 60, 190, 100);
shape.getTextFrame().getTextFrameFormat().setAnchoringType(TextAnchorType.Top);
IMathPortion mathPortion = (IMathPortion) shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0);
IMathParagraph mathParagraph = mathPortion.getMathParagraph();
mathParagraph.add(new MathBlock(equation));
}
presentation.save("math-phantom.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}

گروهبندی عناصری
از group برای قرار دادن یک کاراکتر گروهبندی بالا یا پایین یک عبارت استفاده کنید. میتوانید یک حد اضافه کنید تا عناصری که گروهبندی شدهاند را برچسبگذاری کنید.

import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 120);
IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0)).getMathParagraph();
IMathLimit grouped = new MathematicalText("x + y")
.group('\u23DF', MathTopBotPositions.Bottom, MathTopBotPositions.Top)
.setLowerLimit("any text");
mathParagraph.add(new MathBlock(grouped));
presentation.save("grouped-terms.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
قالببندی عناصر ریاضی
از کمککنندههای قالببندی فقط در مواردی استفاده کنید که فرمول را روشنتر میسازند. برای مثال، overbar یک خط بالای یک عنصر ریاضی میگذارد.

import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0)).getMathParagraph();
IMathBar overbar = new MathematicalText("ABC").overbar();
mathParagraph.add(new MathBlock(overbar));
presentation.save("overbar.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
قالببندی متن در یک معادلهٔ موجود
برای قالببندی متن در تمام معادلهٔ موجود، درخت عنصر هر بلوک ریاضی را پیمایش کنید. IMathElement.getChildren فقط فرزندان مستقیم را برمیگرداند، بنابراین برای دسترسی به متن داخل کسرها، نمایهها، رادیکالها و سایر ساختارهای تو در تو باید بهصورت بازگشتی فراخوانی شود. عنصر فعلی و فرزندانش را نیز بررسی کنید تا زمانی که عنصر MathematicalText باشد، شامل شود.
این مثال فرض میکند input.pptx شامل معادلهای مانند z = xᵢ / ∛y است که یک کسر با زیرنویس در صورت و رادیکال در مخرج دارد. پردازش تنها عناصر سطح بالای بلوک متن را از دست میدهد. مثال بخشهای ریاضی در قابهای متن اسلاید را پیدا میکند، بلوکهایشان را از طریق IMathPortion.getMathParagraph دسترسی مییابد و با setFontHeight اندازهٔ قلم را به ۲۸ پوینت برای هر عنصر متنی از طریق متد getFormat تنظیم میکند.
import com.aspose.slides.*;
class MathTextFormatter {
void formatMathText(IMathElement element) {
if (element instanceof MathematicalText) {
MathematicalText text = (MathematicalText) element;
text.getFormat().setFontHeight(28);
}
for (IMathElement child : element.getChildren()) {
formatMathText(child);
}
}
}
MathTextFormatter formatter = new MathTextFormatter();
Presentation presentation = new Presentation("input.pptx");
try {
for (ISlide slide : presentation.getSlides()) {
for (IShape shape : slide.getShapes()) {
if (!(shape instanceof IAutoShape)) {
continue;
}
IAutoShape autoShape = (IAutoShape) shape;
if (autoShape.getTextFrame() == null) {
continue;
}
for (IParagraph paragraph : autoShape.getTextFrame().getParagraphs()) {
for (IPortion portion : paragraph.getPortions()) {
if (portion instanceof IMathPortion) {
IMathPortion mathPortion = (IMathPortion) portion;
for (IMathBlock block : mathPortion.getMathParagraph()) {
formatter.formatMathText(block);
}
}
}
}
}
}
presentation.save("formatted-equations.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ارائهٔ ذخیرهشده متن قالببندیشده را در هر سطح از هر معادلهٔ پردازششده دارد، در حالی که محتوا و ساختار ریاضی آن حفظ میشود.
مرجع سریع
| کار | API اصلی |
|---|---|
| ایجاد متن ریاضی | MathematicalText |
| ترکیب عناصر | IMathElement.join |
| ایجاد کسرها | IMathElement.divide |
| اضافه کردن بالانس یا زیرنویس | setSuperscript, setSubscript |
| اضافه کردن توابع | function, asArgumentOfFunction |
| اضافه کردن رادیکالها | IMathElement.radical |
| اضافه کردن حدها | setLowerLimit, setUpperLimit |
| اضافه کردن اسکریپتهای چپدست | setSubSuperscriptOnTheLeft |
| اضافه کردن جمعها و انتگرالها | nary, integral |
| اضافه کردن ماتریکسها | MathMatrix |
| اضافه کردن آرایههای معادله | toMathArray |
| اضافه کردن جداکنندهها | enclose |
| اضافه کردن خطها و حاشیهها | overbar, toBorderBox |
| گروهبندی عناصری | group |
سوالات متداول
آیا میتوانم معادلهٔ موجود در PowerPoint را ویرایش کنم؟
بله. ارائه را باز کنید، شکل حاوی یک MathPortion را پیدا کنید، getMathParagraph را فراخوانی کنید و بلوکهای ریاضی آن پاراگراف را بهروز کنید.
آیا معادلات بهعنوان ریاضی قابل ویرایش در PowerPoint ذخیره میشوند؟
بله. هنگام ذخیره به فرمت PPTX، Aspose.Slides معادله را بهصورت محتویات Office Math قابل ویرایش مینویسد.
آیا میتوانم معادلات را به LaTeX صادر کنم؟
بله. معادلهٔ موردنظر را از طریق IMathPortion به IMathParagraph تبدیل کنید و سپس IMathParagraph.toLatex را فراخوانی کنید تا مستقیم صادر شود. برای مثال کامل، به Export Math Equations from Presentations in Android via Java مراجعه کنید.