إدارة الخطوط في العروض التقديمية باستخدام Java

إدارة خصائص الخط ذات الصلة

لإدارة خصائص الخط لفقرة باستخدام Aspose.Slides for Java:

  1. إنشاء مثيل من فئة Presentation.
  2. الحصول على مرجع الشريحة باستخدام فهرسها.
  3. الوصول إلى أشكال Placeholder في الشريحة وتحويل نوعها إلى AutoShape.
  4. الحصول على Paragraph من TextFrame المعروض بواسطة AutoShape.
  5. محاذاة الفقرة إلى الضبط.
  6. الوصول إلى Portion النصية في Paragraph.
  7. تعريف الخط باستخدام FontData وتعيين Font لجزء النص Portion وفقًا لذلك.
    1. ضبط الخط إلى غامق.
    2. ضبط الخط إلى مائل.
  8. ضبط لون الخط باستخدام FillFormat المعروض بواسطة كائن Portion.
  9. حفظ العرض المُعدَّل إلى ملف PPTX.

التنفيذ للخطوات المذكورة أعلاه موضح أدناه. يأخذ عرضًا غير مزخرف ويُنسق الخطوط في إحدى الشرائح. تُظهر اللقطات الشاشة التي تلي ذلك ملف الإدخال وكيف تغيّر مقتطفات الشفرة ذلك. تُغيّر الشفرة الخط واللون ونمط الخط.

todo:image_alt_text
الشكل: النص في الملف الإدخالي
todo:image_alt_text
الشكل: نفس النص مع تنسيق محدث
// إنشاء كائن Presentation يمثل ملف PPTX
Presentation pres = new Presentation("FontProperties.pptx");
try {
	// الوصول إلى شريحة باستخدام موقعها
	ISlide slide = pres.getSlides().get_Item(0);

	// الوصول إلى العنصر النائب الأول والثاني في الشريحة وتحويل النوع إلى AutoShape
	ITextFrame tf1 = ((IAutoShape) slide.getShapes().get_Item(0)).getTextFrame();
	ITextFrame tf2 = ((IAutoShape) slide.getShapes().get_Item(1)).getTextFrame();

	// الوصول إلى الفقرة الأولى
	IParagraph para1 = tf1.getParagraphs().get_Item(0);
	IParagraph para2 = tf2.getParagraphs().get_Item(0);

	// محاذاة الفقرة
	para2.getParagraphFormat().setAlignment(TextAlignment.JustifyLow);

	// الوصول إلى الجزء الأول
	IPortion port1 = para1.getPortions().get_Item(0);
	IPortion port2 = para2.getPortions().get_Item(0);

	// تعريف خطوط جديدة
	FontData fd1 = new FontData("Elephant");
	FontData fd2 = new FontData("Castellar");

	// تعيين خطوط جديدة للجزء
	port1.getPortionFormat().setLatinFont(fd1);
	port2.getPortionFormat().setLatinFont(fd2);

	// تعيين الخط إلى غامق
	port1.getPortionFormat().setFontBold(NullableBool.True);
	port2.getPortionFormat().setFontBold(NullableBool.True);

	// تعيين الخط إلى مائل
	port1.getPortionFormat().setFontItalic(NullableBool.True);
	port2.getPortionFormat().setFontItalic(NullableBool.True);

	// تعيين لون الخط
	port1.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
	port1.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
	port2.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
	port2.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.GREEN);

	// حفظ ملف PPTX إلى القرص
	pres.save("WelcomeFont.pptx", SaveFormat.Pptx);
} finally {
	if (pres != null) pres.dispose();
}

تعيين خصائص خط النص

لإنشاء مربع نص وتعيين خصائص خط النص فيه:

  1. إنشاء مثيل من فئة Presentation.
  2. الحصول على مرجع شريحة باستخدام فهرسها.
  3. إضافة AutoShape من النوع Rectangle إلى الشريحة.
  4. إزالة نمط التعبئة المرتبط بـ AutoShape.
  5. الوصول إلى TextFrame الخاص بـ AutoShape.
  6. إضافة بعض النص إلى TextFrame.
  7. الوصول إلى كائن Portion المرتبط بـ TextFrame.
  8. تعريف الخط المستخدم لـ Portion.
  9. ضبط خصائص الخط الأخرى مثل الغامق والمائل والتسطير واللون والارتفاع باستخدام الخصائص المناسبة المعروضة بواسطة كائن Portion.
  10. كتابة العرض المُعدَّل كملف PPTX.

التنفيذ للخطوات المذكورة أعلاه موضح أدناه.

todo:image_alt_text
الشكل: نص مع بعض خصائص الخط التي تم ضبطها بواسطة Aspose.Slides for Java
// إنشاء كائن Presentation يمثل ملف PPTX
Presentation pres = new Presentation();
try {
	// الحصول على الشريحة الأولى
	ISlide sld = pres.getSlides().get_Item(0);
	
	// إضافة AutoShape من النوع Rectangle
	IAutoShape ashp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 200, 50);
	
	// إزالة أي نمط تعبئة مرتبط بالـ AutoShape
	ashp.getFillFormat().setFillType(FillType.NoFill);
	
	// الوصول إلى TextFrame المرتبط بالـ AutoShape
	ITextFrame tf = ashp.getTextFrame();
	tf.setText("Aspose TextBox");
	
	// الوصول إلى Portion المرتبط بالـ TextFrame
	IPortion port = tf.getParagraphs().get_Item(0).getPortions().get_Item(0);
	
	// تعيين الخط للـ Portion
	port.getPortionFormat().setLatinFont(new FontData("Times New Roman"));
	
	// تعيين خاصية الخط الغامق
	port.getPortionFormat().setFontBold(NullableBool.True);
	
	// تعيين خاصية الخط المائل
	port.getPortionFormat().setFontItalic(NullableBool.True);
	
	// تعيين خاصية تسطير الخط
	port.getPortionFormat().setFontUnderline(TextUnderlineType.Single);
	
	// تعيين ارتفاع الخط
	port.getPortionFormat().setFontHeight(25);
	
	// تعيين لون الخط
	port.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
	port.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
	
	// حفظ العرض على القرص
	pres.save("pptxFont.pptx", SaveFormat.Pptx);
} finally {
	if (pres != null) pres.dispose();
}