نص رياضي
Contents
[
Hide
]
يوضح هذا المقال كيفية العمل مع أشكال النص الرياضي وتنسيق المعادلات باستخدام Aspose.Slides for Java.
Add Math Text
إنشاء شكل رياضي يحتوي على كسر ومعادلة فيثاغورث.
static void addMathText() {
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
// إضافة شكل رياضي إلى الشريحة.
// الوصول إلى الفقرة الرياضية.
IParagraph paragraph = mathShape.getTextFrame().getParagraphs().get_Item(0);
IPortion textPortion = paragraph.getPortions().get_Item(0);
IMathParagraph mathParagraph = ((MathPortion) textPortion).getMathParagraph();
// إضافة كسر بسيط: x / y.
IMathElement fraction = new MathematicalText("x").divide("y");
mathParagraph.add(new MathBlock(fraction));
// إضافة معادلة: c² = a² + b².
IMathBlock mathBlock = new MathematicalText("c")
.setSuperscript("2")
.join("=")
.join(new MathematicalText("a").setSuperscript("2"))
.join("+")
.join(new MathematicalText("b").setSuperscript("2"));
mathParagraph.add(mathBlock);
} finally {
presentation.dispose();
}
}
Access Math Text
تحديد شكل يحتوي على فقرة رياضية في الشريحة.
static void accessMathText() {
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
// العثور على الشكل الأول الذي يحتوي على فقرة رياضية.
IAutoShape mathShape = null;
for (IShape shape : slide.getShapes()) {
if (shape instanceof IAutoShape) {
IAutoShape autoShape = (IAutoShape) shape;
ITextFrame textFrame = autoShape.getTextFrame();
if (textFrame != null) {
boolean hasMath = false;
for (IParagraph paragraph : textFrame.getParagraphs()) {
for (IPortion portion : paragraph.getPortions()) {
if (portion instanceof MathPortion) {
hasMath = true;
break;
}
}
if (hasMath) break;
}
if (hasMath) {
mathShape = autoShape;
break;
}
}
}
}
if (mathShape != null) {
IParagraph paragraph = mathShape.getTextFrame().getParagraphs().get_Item(0);
IPortion textPortion = paragraph.getPortions().get_Item(0);
IMathParagraph mathParagraph = ((MathPortion) textPortion).getMathParagraph();
// مثال: إنشاء كسر (لم يتم إضافته هنا).
IMathElement fraction = new MathematicalText("x").divide("y");
// استخدم mathParagraph أو fraction حسب الحاجة...
}
} finally {
presentation.dispose();
}
}
Remove Math Text
حذف الشكل الرياضي من الشريحة.
static void removeMathText() {
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape mathShape = slide.getShapes().addMathShape(50, 50, 100, 50);
IParagraph paragraph = mathShape.getTextFrame().getParagraphs().get_Item(0);
IPortion textPortion = paragraph.getPortions().get_Item(0);
IMathParagraph mathParagraph = ((MathPortion) textPortion).getMathParagraph();
IMathElement fraction = new MathematicalText("x").divide("y");
mathParagraph.add(new MathBlock(fraction));
// إزالة الشكل الرياضي.
slide.getShapes().remove(mathShape);
} finally {
presentation.dispose();
}
}
Format Math Text
ضبط خصائص الخط لجزء رياضي.
static void formatMathText() {
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape mathShape = slide.getShapes().addMathShape(50, 50, 100, 50);
IParagraph paragraph = mathShape.getTextFrame().getParagraphs().get_Item(0);
IPortion textPortion = paragraph.getPortions().get_Item(0);
IMathParagraph mathParagraph = ((MathPortion) textPortion).getMathParagraph();
IMathElement fraction = new MathematicalText("x").divide("y");
mathParagraph.add(new MathBlock(fraction));
textPortion.getPortionFormat().setFontHeight(20);
} finally {
presentation.dispose();
}
}