تنسيق نص العرض التقديمي على Android
نظرة عامة
توضح هذه المقالة كيفية تنسيق النص في عروض PowerPoint وOpenDocument باستخدام Aspose.Slides لنظام Android عبر Java. تغطي ألوان الخلفية، الشفافية، تباعد الأحرف، خصائص الخط، الدوران، تباعد الفقرات، سلوك الضبط التلقائي، تثبيت النص، علامات التبويب، وإعدادات اللغة.
ما لم يُذكر خلاف ذلك، تستخدم الأمثلة الملف sample.pptx. الشكل الأول في الشريحة الأولى هو مربع نص، والفقرة الأولى تحتوي على النص المعروض أدناه. كلا من مؤشرات الشرائح والأشكال تبدأ من الصفر. الأمثلة التي تختار أجزاءً غليظة تستخدم التنسيق الفعّال، بما في ذلك تنسيق الغليظ الموروث:

للعثور على نص حرفي أو مطابقة تعبير نمطي وتظليله، راجع البحث واستبدال النص.
ضبط لون خلفية النص
استخدم IParagraphFormat.getDefaultPortionFormat لتعيين لون التظليل الافتراضي للفقرة، أو استخدم IBasePortionFormat.getHighlightColor لأجزاء النص الفردية.
المثال التالي يضبط تظليلاً رماديًا فاتحًا كافتراضي للفقرة الأولى. الألوان الصريحة للتظليل على الأجزاء الفردية تتجاوز هذا الافتراضي:
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
// اضبط لون التظليل للفقرة بأكملها.
paragraph.getParagraphFormat().getDefaultPortionFormat().getHighlightColor().setColor(Color.LTGRAY);
presentation.save("gray_paragraph.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
النتيجة:

يُظهر مثال الشفرة أدناه كيفية تعيين لون الخلفية لأجزاء النص ذات الخط الغليظ:
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
for (IPortion portion : paragraph.getPortions()) {
if (portion.getPortionFormat().getEffective().getFontBold()) {
// اضبط لون التظليل لجزء النص.
portion.getPortionFormat().getHighlightColor().setColor(Color.LTGRAY);
}
}
presentation.save("gray_text_portions.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
النتيجة:

محاذاة فقرات النص
استخدم IParagraphFormat.setAlignment لتعيين محاذاة الفقرة داخل إطار النص. يمكن أن تكون القيمة مركزية، محاذاة إلى اليسار، محاذاة إلى اليمين، مبررة، وما إلى ذلك.
يوضح مثال الشفرة التالي كيفية محاذاة الفقرة إلى الوسط:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
// اضبط محاذاة الفقرة إلى الوسط.
paragraph.getParagraphFormat().setAlignment(TextAlignment.Center);
presentation.save("aligned_paragraph.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
النتيجة:

محاذاة الخطوط داخل سطر
استخدم IParagraphFormat.setFontAlignment لمحاذاة أجزاء النص ذات أحجام الخط المختلفة عموديًا داخل سطر. ينطبق هذا الإعداد على الفقرة بالكامل ويسيطر على المحاذاة داخل كل أحد أسطرها.
المثال المستقل التالي ينشئ أربعة صناديق نصية معنونة في شريحة واحدة. كل فقرة تحتوي على نفس النص بأحجام 18، 36، و54 نقطة، مع محاذاة خط مختلفة. يستخدم Arial، ويعطل الضبط التلقائي واللف، ويجعل إطارات النص كبيرة بما يكفي لسطر واحد.
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
int[] alignments = { FontAlignment.Baseline, FontAlignment.Top, FontAlignment.Center, FontAlignment.Bottom };
String[] alignmentNames = { "Baseline", "Top", "Center", "Bottom" };
float[] fontSizes = { 18f, 36f, 54f };
for (int i = 0; i < alignments.length; i++) {
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 30, 20 + i * 130, 660, 120);
shape.getFillFormat().setFillType(FillType.NoFill);
shape.getLineFormat().getFillFormat().setFillType(FillType.NoFill);
ITextFrame textFrame = shape.getTextFrame();
textFrame.getTextFrameFormat().setAnchoringType(TextAnchorType.Top);
textFrame.getTextFrameFormat().setAutofitType(TextAutofitType.None);
textFrame.getTextFrameFormat().setWrapText(NullableBool.False);
IParagraph label = textFrame.getParagraphs().get_Item(0);
label.setText(alignmentNames[i]);
label.getParagraphFormat().setAlignment(TextAlignment.Left);
label.getParagraphFormat().getDefaultPortionFormat().setFontHeight(14);
label.getParagraphFormat().getDefaultPortionFormat().setLatinFont(new FontData("Arial"));
label.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
label.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.GRAY);
Paragraph paragraph = new Paragraph();
paragraph.getParagraphFormat().setFontAlignment(alignments[i]);
paragraph.getParagraphFormat().setAlignment(TextAlignment.Left);
paragraph.getParagraphFormat().getDefaultPortionFormat().setLatinFont(new FontData("Arial"));
paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
for (float fontSize : fontSizes) {
Portion portion = new Portion("Ag ");
portion.getPortionFormat().setFontHeight(fontSize);
paragraph.getPortions().add(portion);
}
textFrame.getParagraphs().add(paragraph);
}
presentation.save("font_alignment.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
النتيجة:

محاذاة الخط تستخدم قياسات الخط، لذا قد لا تتطابق حواف الحروف الفردية تمامًا. يتضمن المثال حرفًا كبيرًا وحرفًا منخفضًا لتوضيح الفرق بين محاذاة الأساس والأسفل. تؤثر توفر الخط واستبداله، الأحرف المستخدمة، واختلاف أحجام الخطوط على النتيجة. كما تؤثر أبعاد الإطار، الهوامش، تباعد الأسطر، اللف، والضبط التلقائي على التخطيط؛ استخدم نفس الخطوط وإعدادات التخطيط عند مقارنة الأنماط.
هذا الإعداد يختلف عن IParagraphFormat.setAlignment، الذي يتحكم في محاذاة الفقرة أفقياً، وعن ITextFrameFormat.setAnchoringType، الذي يحدد موضع كتلة النص عمودياً داخل الشكل. تنسيق الحرف العلوي والسفلي عبر IBasePortionFormat.setEscapement ينقل الأجزاء الفردية بالنسبة إلى الأساس بدلاً من ضبط محاذاة الخط لأسطر الفقرة.
ضبط الشفافية للنص
يتم التحكم في شفافية النص عبر مكوّن ألفا للون المعين إلى IBasePortionFormat.getFillFormat. في الأمثلة أدناه، alpha = 50 هو قيمة قناة ألفا ARGB على مقياس 0‑255، وليس نسبة شفافية.
يُظهر مثال الشفرة أدناه كيفية تطبيق شفافية على الفقرة بالكامل:
import com.aspose.slides.*;
import android.graphics.Color;
int alpha = 50;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
// اضبط لون تعبئة النص إلى لون شفاف.
paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.argb(alpha, 0, 0, 0));
presentation.save("transparent_paragraph.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
النتيجة:

يُظهر مثال الشفرة التالي كيفية تطبيق شفافية على أجزاء النص ذات الخط الغليظ:
import com.aspose.slides.*;
import android.graphics.Color;
int alpha = 50;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
for (IPortion portion : paragraph.getPortions()) {
if (portion.getPortionFormat().getEffective().getFontBold()) {
// اضبط شفافية جزء النص.
portion.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
portion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.argb(alpha, 0, 0, 0));
}
}
presentation.save("transparent_text_portions.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
النتيجة:

ضبط تباعد الأحرف للنص
استخدم IBasePortionFormat.setSpacing لتوسيع أو تقليل التباعد بين الأحرف في مربع نص. تضيف الأمثلة 3 نقاط من التباعد؛ القيم السالبة تضغط النص.
يوضح مثال الشفرة التالي كيفية توسيع تباعد الأحرف في الفقرة بالكامل:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
// ملاحظة: استخدم القيم السالبة لضغط تباعد الأحرف.
paragraph.getParagraphFormat().getDefaultPortionFormat().setSpacing(3); // توسيع تباعد الأحرف.
presentation.save("character_spacing_in_paragraph.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
النتيجة:

يُظهر مثال الشفرة التالي كيفية توسيع تباعد الأحرف في أجزاء النص ذات الخط الغليظ:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
for (IPortion portion : paragraph.getPortions()) {
if (portion.getPortionFormat().getEffective().getFontBold()) {
// ملاحظة: استخدم القيم السالبة لضغط تباعد الأحرف.
portion.getPortionFormat().setSpacing(3); // توسيع تباعد الأحرف.
}
}
presentation.save("character_spacing_in_text_portions.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
النتيجة:

تعطيل التكييف للخطوط المحددة
في بعض الحالات، قد يبدو النص المُظهر بواسطة Aspose.Slides أكثر إحكامًا قليلاً من النص نفسه المعروض في PowerPoint. قد يحدث ذلك لأن PowerPoint قد يتجاهل بيانات التكييف لبعض الخطوط، حتى عندما يحتوي الخط على معلومات تكييف صالحة ويتم تمكين التكييف في إعدادات PowerPoint.
لجعل المخرجات المُعالجة أقرب إلى PowerPoint في مثل هذه الحالات، يمكنك تعطيل التكييف لأجزاء النص التي تستخدم الخط المتأثر. عيّن IBasePortionFormat.setKerningMinimalSize إلى قيمة أكبر من حجم الخط الفعلي. يتطلب هذا المثال الملف “presentation.pptx” مع مربع نص كأول شكل في الشريحة الأولى. يتحقق من أسماء الخطوط الفعّالة، بما في ذلك الخطوط الموروثة، ويضبط حدًا قدره 100 نقطة للأجزاء التي تستخدم Roboto. هذا يعطل التكييف للأجزاء المطابقة ذات حجم الخط أقل من 100 نقطة:
import com.aspose.slides.*;
Presentation presentation = new Presentation("presentation.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
String targetFont = "Roboto";
for (IParagraph paragraph : autoShape.getTextFrame().getParagraphs()) {
for (IPortion portion : paragraph.getPortions()) {
IPortionFormatEffectiveData portionFormat = portion.getPortionFormat().getEffective();
if ((portionFormat.getLatinFont() != null &&
portionFormat.getLatinFont().getFontName().equals(targetFont)) ||
(portionFormat.getEastAsianFont() != null &&
portionFormat.getEastAsianFont().getFontName().equals(targetFont)) ||
(portionFormat.getComplexScriptFont() != null &&
portionFormat.getComplexScriptFont().getFontName().equals(targetFont))) {
portion.getPortionFormat().setKerningMinimalSize(100);
}
}
}
presentation.save("output.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
للنص المطابق الذي يكون أدناه الحد، يمنع هذا الإعداد التكييف ويمكن أن يساعد على تقريب مخرجات Aspose.Slides إلى المظهر البصري في PowerPoint للخطوط المتأثرة بهذا السلوك الخاص بـ PowerPoint.
إدارة خصائص خط النص
يمكن ضبط خصائص الخط على مستوى الفقرة عبر IParagraphFormat.getDefaultPortionFormat أو على الأجزاء الفردية عبر IPortionFormat.
المثال التالي يضبط الخط الافتراضي للفقرة الأولى إلى Times New Roman بحجم 12 نقطة مع تنسيق غليظ، مائل، وتسطير منقط. التنسيق الصريح للأجزاء الفردية يمتد على هذه القيم الافتراضية:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
// اضبط خصائص الخط للفقرة.
paragraph.getParagraphFormat().getDefaultPortionFormat().setFontHeight(12);
paragraph.getParagraphFormat().getDefaultPortionFormat().setFontBold(NullableBool.True);
paragraph.getParagraphFormat().getDefaultPortionFormat().setFontItalic(NullableBool.True);
paragraph.getParagraphFormat().getDefaultPortionFormat().setFontUnderline(TextUnderlineType.Dotted);
paragraph.getParagraphFormat().getDefaultPortionFormat().setLatinFont(new FontData("Times New Roman"));
presentation.save("font_properties_for_paragraph.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
النتيجة:

المثال التالي يطبق Times New Roman بحجم 13 نقطة، تنسيق مائل، وتسطير منقط على الأجزاء التي يكون تنسيقها الفعّال غليظ:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
for (IPortion portion : paragraph.getPortions()) {
if (portion.getPortionFormat().getEffective().getFontBold()) {
// اضبط خصائص الخط لجزء النص.
portion.getPortionFormat().setFontHeight(13);
portion.getPortionFormat().setFontItalic(NullableBool.True);
portion.getPortionFormat().setFontUnderline(TextUnderlineType.Dotted);
portion.getPortionFormat().setLatinFont(new FontData("Times New Roman"));
}
}
presentation.save("font_properties_for_text_portions.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
النتيجة:

التحكم في تطبيع ارتفاع النص
استخدم IBasePortionFormat.setNormaliseHeight عند إعادة إنتاج طباعة القالب أو التحقيق في الاختلافات في ارتفاع الحروف. في PowerPoint، تمكين التطبيع يمدد أو يضغط الأحرف الفردية عموديًا لإعطائها ارتفاعًا مرئيًا موحدًا داخل جزء النص. لا يضمن ذلك تساوي ارتفاع النص بين الخطوط المختلفة.
عيّن الخاصية إلى NullableBool.True or False لتمكين أو تعطيل التطبيع صراحةً. NullableBool.NotDefined يترك الإعداد المحلي غير محدد بحيث يرث الجزء قيمته، على سبيل المثال، من getDefaultPortionFormat للفقرة. هذا لا يعني False. استخدم IPortionFormat.getEffective وقراءة IBasePortionFormatEffectiveData.getNormaliseHeight للحصول على القيمة المنطقية المحسوبة.
المثال المستقل التالي يتطلب Arial لتثبيته. ينشئ كتلتين نصيتين تحتويان على نفس الحروف الكبيرة، الحروف الصغيرة، الأحرف المنخفضة، وحروف مع تشكيل بحجم 54 نقطة. كلتا الفقرتين تمكّن التطبيع افتراضيًا. الجزء العلوي يعطّل التطبيع صراحةً؛ الجزء السفلي يرثه. أحجام الإطارات، الهوامش، وتباعد الفقرات متطابقة، مع تعطيل اللف والضبط التلقائي للحفاظ على التناسق. يطبع المثال False: false وNotDefined: true، ثم يحفظ “text_height_normalization.pptx”.
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
byte[] settings = { NullableBool.False, NullableBool.NotDefined };
String[] settingNames = { "False", "NotDefined" };
for (int i = 0; i < settings.length; i++) {
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 30, 60 + i * 200, 660, 150);
shape.getFillFormat().setFillType(FillType.NoFill);
shape.getLineFormat().getFillFormat().setFillType(FillType.NoFill);
ITextFrame textFrame = shape.getTextFrame();
textFrame.setText("Hxgjpq ÅÉ 0123");
textFrame.getTextFrameFormat().setAutofitType(TextAutofitType.None);
textFrame.getTextFrameFormat().setWrapText(NullableBool.False);
textFrame.getTextFrameFormat().setAnchoringType(TextAnchorType.Top);
textFrame.getTextFrameFormat().setMarginTop(0);
textFrame.getTextFrameFormat().setMarginLeft(0);
IParagraph paragraph = textFrame.getParagraphs().get_Item(0);
paragraph.getParagraphFormat().setAlignment(TextAlignment.Left);
paragraph.getParagraphFormat().setSpaceBefore(0);
paragraph.getParagraphFormat().setSpaceAfter(0);
paragraph.getParagraphFormat().setSpaceWithin(100);
paragraph.getParagraphFormat().getDefaultPortionFormat().setNormaliseHeight(NullableBool.True);
IPortion portion = paragraph.getPortions().get_Item(0);
FontData font = new FontData("Arial");
portion.getPortionFormat().setLatinFont(font);
portion.getPortionFormat().setFontHeight(54);
portion.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
portion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
portion.getPortionFormat().setNormaliseHeight(settings[i]);
System.out.println(settingNames[i] + ": " + portion.getPortionFormat().getEffective().getNormaliseHeight());
}
presentation.save("text_height_normalization.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
المقارنة أدناه تم تصديرها من العرض المحفوظ. الصف العلوي به تطبيع معطّل (False); الصف السفلي يرث الإعداد المفعّل (NotDefined → True). حافظ على تثبيت Arial لإعادة إنتاج هذا المظهر.

التطبيع يغيّر ارتفاع الحرف دون تغيير قيمة getFontHeight المعينة، التي تحدد حجم الخط بالنقاط. setSpaceWithin للفقرة يتحكم في تباعد السطر، بينما setAutofitType لإطار النص يتحكم في كيفية تعديل النص أو حاويته لتناسب. هذه الإعدادات لها أغراض مختلفة ويمكن أن تؤثر على التخطيط العام بشكل مستقل. لمزيد من المعلومات حول تنسيق الفقرة والوراثة، راجع إدارة الفقرة.
تطبيق وإزالة الخط عبر
استخدم IBasePortionFormat.setStrikethroughType على جزء نص لعرض التصحيحات، المصطلحات الملغاة، أو الأسعار السابقة دون حذف النص الأصلي. عيّنها إلى TextStrikethroughType.Single أو Double لسطر أو سطرين عبر النص.
لإزالة الخط عبر، مرّر TextStrikethroughType.None. هذا يعطّل التأثير صراحةً، حتى إذا كان التنسيق المحيط يحدّد الخط عبر. بالمقابل، TextStrikethroughType.NotDefined يترك الإعداد المحلي غير معرف، مما يسمح للجزء بوراثة التنسيق، على سبيل المثال، من الفقرة. لا يضمن ذلك إزالة الخط عبر. استخدم IPortionFormat.getEffective لقراءة التنسيق الناتج، بما في ذلك القيم الموروثة.
المثال المستقل التالي ينشئ ثلاث مقارنات أسعار. كل فقرة لديها أجزاء منفصلة للملصق، السعر السابق، والسعر الحالي، لذا يتأثر السعر السابق فقط. الصف الأول يطبق ثم يزيل الخط عبر؛ الصفوف الأخرى تحتفظ بخط عبر واحد ومزدوج. تغيير هذا الإعداد يحافظ على النص وتنسيقه الآخر، بما في ذلك السعر السابق الغليظ.
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 620, 220);
shape.getFillFormat().setFillType(FillType.NoFill);
shape.getLineFormat().getFillFormat().setFillType(FillType.NoFill);
shape.getTextFrame().getParagraphs().clear();
String[] labels = { "None: ", "Single: ", "Double: " };
for (String label : labels) {
Paragraph paragraph = new Paragraph();
paragraph.getParagraphFormat().setAlignment(TextAlignment.Left);
paragraph.getParagraphFormat().setSpaceAfter(20);
IPortionFormat format = paragraph.getParagraphFormat().getDefaultPortionFormat();
format.setFontHeight(28);
FontData font = new FontData("Arial");
format.setLatinFont(font);
format.getFillFormat().setFillType(FillType.Solid);
format.getFillFormat().getSolidFillColor().setColor(Color.BLACK);
Portion labelPortion = new Portion(label);
paragraph.getPortions().add(labelPortion);
Portion previousPrice = new Portion("$100");
previousPrice.getPortionFormat().setFontBold(NullableBool.True);
paragraph.getPortions().add(previousPrice);
Portion currentPrice = new Portion(" → $80");
paragraph.getPortions().add(currentPrice);
shape.getTextFrame().getParagraphs().add(paragraph);
}
IParagraphCollection paragraphs = shape.getTextFrame().getParagraphs();
// تطبيق الخط عبر، ثم إزالته صراحةً من السعر السابق الأول.
paragraphs.get_Item(0).getPortions().get_Item(1).getPortionFormat().setStrikethroughType(TextStrikethroughType.Single);
paragraphs.get_Item(0).getPortions().get_Item(1).getPortionFormat().setStrikethroughType(TextStrikethroughType.None);
paragraphs.get_Item(1).getPortions().get_Item(1).getPortionFormat().setStrikethroughType(TextStrikethroughType.Single);
paragraphs.get_Item(2).getPortions().get_Item(1).getPortionFormat().setStrikethroughType(TextStrikethroughType.Double);
presentation.save("strikethrough.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
النتيجة، من الأعلى إلى الأسفل: لا خط عبر، خط عبر واحد، وخط عبر مزدوج.

ضبط دوران النص
استخدم ITextFrameFormat.setTextVerticalType لتعيين اتجاه نص مسبق داخل شكل.
الكود التالي يضبط اتجاه النص في الشكل إلى TextVerticalType.Vertical270، الذي يدور النص 90 درجة عكس عقارب الساعة:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
autoShape.getTextFrame().getTextFrameFormat().setTextVerticalType(TextVerticalType.Vertical270);
presentation.save("text_rotation.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
النتيجة:

ضبط دوران مخصص لإطارات النص
استخدم ITextFrameFormat.setRotationAngle لتعيين زاوية دوران مخصصة لـ ITextFrame.
الكود التالي يدور إطار النص بـ 3 درجات باتجاه عقارب الساعة داخل الشكل:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
autoShape.getTextFrame().getTextFrameFormat().setRotationAngle(3);
presentation.save("custom_text_rotation.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
النتيجة:

ضبط تباعد السطور للفقرات
Aspose.Slides provides IParagraphFormat.setSpaceAfter, IParagraphFormat.setSpaceBefore, and IParagraphFormat.setSpaceWithin to control paragraph spacing. These properties are used as follows:
- استخدم قيمة موجبة لتحديد تباعد السطر كنسبة مئوية من ارتفاع السطر.
- استخدم قيمة سالبة لتحديد تباعد السطر بالنقاط.
المثال التالي يضبط التباعد داخل الفقرة الأولى إلى 200% من ارتفاع السطر (تباعد مزدوج):
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
paragraph.getParagraphFormat().setSpaceWithin(200);
presentation.save("line_spacing.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
النتيجة:

التحكم في كسر السطر
قواعد كسر سطر الفقرة مفيدة في كتل نصية ضيقة وعروض تمزج بين النص اللاتيني والآسيوي الشرقي. الطرق التالية تنتمي إلى IParagraphFormat، لذا تطبق على الفقرة بالكامل:
- setLatinLineBreak يتحكم في قواعد كسر سطر اللاتيني. في النص المختلط، تغييره قد يغيّر أيضًا موقع التفاف النص الآسيوي الشرقي وعلامات الترقيم المجاورة.
- setEastAsianLineBreak يتحكم في قواعد كسر سطر شرق آسيا، بما في ذلك القيود على الأحرف في بداية ونهاية السطر.
هذه القواعد لا تحل محل ITextFrameFormat.setWrapText، الذي يفعيل اللف التلقائي داخل إطار النص. إنها تؤثر على التخطيط عندما يحدث اللف؛ لا تُدرج أحرف كسر سطر. كسر سطر صريح يجبر سطرًا جديدًا داخل الفقرة بغض النظر عن العرض المتاح.
المثال المستقل التالي ينشئ كتلة نصية ضيقة تحتوي على نص صيني ولاتيني. يعيّن كلا خيارَي كسر السطر صراحةً ويحفظ “line_breaking.pptx”. لتجربة أي قاعدة، غير القيمة المقابلة مع إبقاء الإعدادات الأخرى ثابتة. يستخدم المثال Arial بحجم 24 نقطة وSimSun مع عرض إطار 160 نقطة وهوامش أفقيّة صفرية. يتم استدعاء ITextFrameFormat.setAutofitType مع TextAutofitType.None لضمان بقاء حجم النص وأبعاد الإطار ثابتة.
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 160, 300);
shape.getFillFormat().setFillType(FillType.NoFill);
ITextFrame textFrame = shape.getTextFrame();
textFrame.getTextFrameFormat().setWrapText(NullableBool.True);
textFrame.getTextFrameFormat().setAutofitType(TextAutofitType.None);
textFrame.getTextFrameFormat().setMarginLeft(0);
textFrame.getTextFrameFormat().setMarginRight(0);
IParagraph paragraph = textFrame.getParagraphs().get_Item(0);
paragraph.setText("中文排版测试,PowerPoint 中文演示。");
IParagraphFormat format = paragraph.getParagraphFormat();
format.setAlignment(TextAlignment.Left);
format.getDefaultPortionFormat().setFontHeight(24);
FontData latinFont = new FontData("Arial");
format.getDefaultPortionFormat().setLatinFont(latinFont);
FontData eastAsianFont = new FontData("SimSun");
format.getDefaultPortionFormat().setEastAsianFont(eastAsianFont);
format.getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
format.getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
format.setLatinLineBreak(NullableBool.False);
format.setEastAsianLineBreak(NullableBool.True);
presentation.save("line_breaking.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
التحكم في علامات الترقيم المتدلية
IParagraphFormat.setHangingPunctuation يسمح للعلامات المؤهلة بالتمدد إلى ما وراء الحافة اليمنى لسطر النص بدلاً من احتلال السطر التالي. ينطبق على الفقرة بالكامل ويختلف عن المسافة المتدلية.
المثال المستقل التالي يفعّل علامات الترقيم المتدلية في إطار نص بعرض 100 نقطة ويحفظ “hanging_punctuation.pptx”. مع Arial بحجم 24 نقطة وهوامش أفقية صفرية، يبقى النقطة النهائية بعد كلمة “sentence” وتمتد إلى ما وراء حافة النص اليمنى. اضبط الخاصية إلى NullableBool.False للمقارنة: مع هذه الإعدادات، تشغل النقطة سطرًا منفصلًا. اللف مفعّل والضبط التلقائي معطل للحفاظ على عرض ثابت.
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 100, 200);
shape.getFillFormat().setFillType(FillType.NoFill);
ITextFrame textFrame = shape.getTextFrame();
textFrame.getTextFrameFormat().setWrapText(NullableBool.True);
textFrame.getTextFrameFormat().setAutofitType(TextAutofitType.None);
textFrame.getTextFrameFormat().setMarginLeft(0);
textFrame.getTextFrameFormat().setMarginRight(0);
IParagraph paragraph = textFrame.getParagraphs().get_Item(0);
paragraph.setText("Simple text, next sentence.");
IParagraphFormat format = paragraph.getParagraphFormat();
format.setAlignment(TextAlignment.Left);
format.getDefaultPortionFormat().setFontHeight(24);
FontData latinFont = new FontData("Arial");
format.getDefaultPortionFormat().setLatinFont(latinFont);
format.getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
format.getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
format.setHangingPunctuation(NullableBool.True);
presentation.save("hanging_punctuation.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ليس كل علامة ترقيم يمكن أن تتدلى. شروط الخط والتخطيط المذكورة أعلاه (font and layout conditions described above) تنطبق أيضًا على هذه المقارنة: تغيير الخط، العرض المتاح، الهوامش، أو إعدادات الضبط التلقائي قد يزيل الفرق المرئي.
ضبط نوع الضبط التلقائي لإطارات النص
ITextFrameFormat.setAutofitType يحدد كيفية تصرف النص عندما يتجاوز حدود حاويته. استخدمه للتحكم ما إذا كان النص يتقلص، يتجاوز، أو يعيد تحجيم الشكل تلقائيًا. المثال التالي يضبط الشكل لإعادة التحجيم ليتناسب مع نصه ويحفظ النتيجة إلى “autofit_type.pptx”.
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
autoShape.getTextFrame().getTextFrameFormat().setAutofitType(TextAutofitType.Shape);
presentation.save("autofit_type.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
لعد السطور بعد اللف التلقائي ورؤية كيفية تغيير عرض النص أو الشكل للنتيجة، راجع عد السطور المعروضة. عدد السطور وحده لا يدل على ما إذا كان النص يتجاوز حاويته.
ضبط مرساة إطارات النص
ITextFrameFormat.setAnchoringType يحدد كيفية وضع النص عموديًا داخل الشكل، مثل الأعلى، المنتصف، أو الأسفل. المثال التالي يرسّخ النص إلى أسفل الشكل الأول ويحفظ النتيجة إلى “text_anchor.pptx”.
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
autoShape.getTextFrame().getTextFrameFormat().setAnchoringType(TextAnchorType.Bottom);
presentation.save("text_anchor.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ضبط علامات الجدولة للنص
استخدم IParagraphFormat.setDefaultTabSize وIParagraphFormat.getTabs لتكوين علامات التبويب في الفقرة. المثال التالي يضبط الفاصل الافتراضي للعلامة إلى 100 نقطة ويضيف علامة تبويب محاذاة إلى اليسار عند 30 نقطة. هذه الإعدادات تؤثر على النص الذي يحتوي على أحرف تبويب.
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
paragraph.getParagraphFormat().setDefaultTabSize(100);
paragraph.getParagraphFormat().getTabs().add(30, TabAlignment.Left);
presentation.save("paragraph_tabs.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
النتيجة:

ضبط لغة التدقيق
Aspose.Slides provides IBasePortionFormat.setLanguageId, which allows you to set the proofing language for a text portion. The proofing language determines the language used for spelling and grammar checks in PowerPoint.
المثال التالي يتطلب “presentation.pptx” مع مربع نص كأول شكل في الشريحة الأولى وعلى الأقل فقرة واحدة. يستبدل محتويات الفقرة الأولى بـ “1。"، يعيّن SimSun كخط لها، ويعيّن لغة التدقيق الصينية المبسطة (zh-CN). يحفظ النتيجة إلى “proofing_language.pptx”:
import com.aspose.slides.*;
Presentation presentation = new Presentation("presentation.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
paragraph.getPortions().clear();
FontData font = new FontData("SimSun");
Portion textPortion = new Portion();
textPortion.getPortionFormat().setComplexScriptFont(font);
textPortion.getPortionFormat().setEastAsianFont(font);
textPortion.getPortionFormat().setLatinFont(font);
// تعيين معرف لغة التدقيق.
textPortion.getPortionFormat().setLanguageId("zh-CN");
textPortion.setText("1。");
paragraph.getPortions().add(textPortion);
presentation.save("proofing_language.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
نسخ بيانات اللغة
عند نسخ نص متعدد اللغات من قالب، احفظ كل من IBasePortionFormat.getLanguageId وIBasePortionFormat.getAlternativeLanguageId. المثال المستقل التالي يُنشئ جزءًا مصدرًا بالإنجليزية الأمريكية كلغتها و الفرنسية كلغة بديلة وينسخ النص والمعرفات إلى جزء في عرض تقديمي جديد.
import com.aspose.slides.*;
Portion source = new Portion("Hello! Bonjour!");
source.getPortionFormat().setLanguageId("en-US");
source.getPortionFormat().setAlternativeLanguageId("fr-FR");
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 20, 20, 400, 80);
IParagraph paragraph = shape.getTextFrame().getParagraphs().get_Item(0);
paragraph.getPortions().clear();
Portion destination = new Portion();
destination.setText(source.getText());
destination.getPortionFormat().setLanguageId(source.getPortionFormat().getLanguageId());
// إذا لم يكن للمصدر لغة بديلة، فإن null يمسح قيمة الوجهة.
destination.getPortionFormat().setAlternativeLanguageId(source.getPortionFormat().getAlternativeLanguageId());
paragraph.getPortions().add(destination);
presentation.save("copied_language_metadata.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
لتجربة مصدر بدون لغة بديلة، احذف تعيين "fr-FR". يصبح المعرف البديل null، ويُحافظ أمر النسخ ذاته على غيابه دون إدخال قيمة افتراضية، حتى لو كان الوجهة قد عيّن لغة بديلة مسبقًا.
هذه المعرفات تُخزن كبيانات لغة. حفظها لا يحدّد أي قاموس يختاره PowerPoint للتدقيق الإملائي أو النحوي.
ضبط اللغة الافتراضية
استخدم LoadOptions.setDefaultTextLanguage لتعريف اللغة الافتراضية للنص الذي يُنشأ أثناء تحميل أو إنشاء عرض تقديمي. المثال التالي يخلق عرضًا تقديميًا بالإنجليزية الأمريكية كلغة نص افتراضية، يضيف مربع نص، ويطبع en-US للجزء النصي الأول.
import com.aspose.slides.*;
LoadOptions loadOptions = new LoadOptions();
loadOptions.setDefaultTextLanguage("en-US");
Presentation presentation = new Presentation(loadOptions);
try {
ISlide slide = presentation.getSlides().get_Item(0);
// أضف شكلًا مستطيلًا جديدًا مع نص.
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 20, 20, 150, 50);
shape.getTextFrame().setText("Sample text");
// تحقق من لغة الجزء الأول.
IPortion portion = shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0);
System.out.println(portion.getPortionFormat().getLanguageId());
} finally {
presentation.dispose();
}
ضبط نمط النص الافتراضي
لتطبيق تنسيق نص افتراضي على مستوى العرض، استخدم IPresentation.getDefaultTextStyle.
المثال التالي يضبط خطًا غليظًا بحجم 14 نقطة كافتراضي للفقرات العليا في عرض تقديمي جديد ويحفظه إلى “default_text_style.pptx”. يمكن للنص ورث هذه الافتراضات ما لم يُحكم تنسيق أكثر تحديدًا عليها.
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
// احصل على تنسيق الفقرة المستوى الأعلى.
IParagraphFormat paragraphFormat = presentation.getDefaultTextStyle().getLevel(0);
if (paragraphFormat != null) {
paragraphFormat.getDefaultPortionFormat().setFontHeight(14);
paragraphFormat.getDefaultPortionFormat().setFontBold(NullableBool.True);
}
presentation.save("default_text_style.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
استخراج النص مع تأثير الحروف الكبيرة
في PowerPoint، تطبيق تأثير كل الأحرف الكبيرة يجعل النص يظهر بأحرف كبيرة على الشريحة حتى لو كُتب أصلاً بأحرف صغيرة. عند استرجاع مثل هذا الجزء النصي باستخدام Aspose.Slides، تُعيد المكتبة النص كما تم إدخاله بالضبط. لمطابقة النص المعروض، تحقق من TextCapType وحوّل السلسلة المسترجعة إلى أحرف كبيرة عندما تكون القيمة All.
هذا المثال يتطلب “sample2.pptx” مع مربع نص كأول شكل في الشريحة الأولى. يحتوي الجزء الأول من الفقرة الأولى على “Hello, Aspose!” مع تطبيق تأثير كل الأحرف الكبيرة، كما هو موضح أدناه.

الكود التالي يوضح كيفية استخراج النص مع تطبيق كل الأحرف الكبيرة:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample2.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IPortion textPortion = autoShape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0);
System.out.println("Original text: " + textPortion.getText());
IPortionFormatEffectiveData textFormat = textPortion.getPortionFormat().getEffective();
if (textFormat.getTextCapType() == TextCapType.All) {
String text = textPortion.getText().toUpperCase();
System.out.println("All-Caps effect: " + text);
}
} finally {
presentation.dispose();
}
الإخراج:
Original text: Hello, Aspose!
All-Caps effect: HELLO, ASPOSE!
أسئلة شائعة
كيف يمكنني تعديل النص في جدول على شريحة؟
لتعديل النص في جدول على شريحة، استخدم ITable. استعرض الخلايا وحدث كل خلية عبر ICell.getTextFrame وتنسيق الفقرة عبر IParagraph.getParagraphFormat.
كيف يمكنني تطبيق لون متدرج على النص في شريحة PowerPoint؟
لتطبيق لون متدرج على النص، استخدم IBasePortionFormat.getFillFormat. عيّن IFillFormat.setFillType إلى FillType.Gradient وضبط نقاط التدرج، الاتجاه، والشفافية.