ข้อความคณิตศาสตร์
Contents
[
Hide
]
บทความนี้สาธิตการทำงานกับรูปแบบข้อความคณิตศาสตร์และการจัดรูปแบบสมการโดยใช้ Aspose.Slides for Android via Java.
เพิ่มข้อความคณิตศาสตร์
สร้างรูปร่างคณิตศาสตร์ที่มีส่วนประกอบของเศษส่วนและสูตรพีทากอรัส.
static void addMathText() {
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
// เพิ่มรูปคณิตศาสตร์ไปยังสไลด์.
IAutoShape mathShape = slide.getShapes().addMathShape(0, 0, 720, 150);
// เข้าถึงย่อหน้าคณิตศาสตร์.
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();
}
}
เข้าถึงข้อความคณิตศาสตร์
ค้นหารูปร่างที่มีย่อหน้าคณิตศาสตร์บนสไลด์.
static void accessMathText() {
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
// Find the first shape that contains a math paragraph.
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();
// Example: create a fraction (not added here).
IMathElement fraction = new MathematicalText("x").divide("y");
// Use mathParagraph or fraction as needed...
}
} finally {
presentation.dispose();
}
}
ลบข้อความคณิตศาสตร์
ลบรูปร่างคณิตศาสตร์จากสไลด์.
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();
}
}
จัดรูปแบบข้อความคณิตศาสตร์
ตั้งค่าคุณสมบัติตัวอักษรสำหรับส่วนของคณิตศาสตร์.
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();
}
}