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

للعثور على نص حرفي أو مطابقة تعبيرات نمطية وتسليط الضوء عليها، راجع بحث واستبدال النص.
تعيين لون خلفية النص
استخدم ParagraphFormat.default_portion_format لتعيين لون التظليل الافتراضي للفقرة، أو استخدم BasePortionFormat.highlight_color لأجزاء النص الفردية.
المثال التالي يحدد تظليلًا رماديًا فاتحًا كإعداد افتراضي للفقرة الأولى. ألوان التظليل الصريحة على الأجزاء الفردية لها أولوية أعلى من هذا الإعداد الافتراضي:
import aspose.pydrawing as draw
import aspose.slides as slides
with slides.Presentation("sample.pptx") as presentation:
slide = presentation.slides[0]
auto_shape = slide.shapes[0]
paragraph = auto_shape.text_frame.paragraphs[0]
# تعيين لون التظليل للفقرة بأكملها.
paragraph.paragraph_format.default_portion_format.highlight_color.color = draw.Color.light_gray
presentation.save("gray_paragraph.pptx", slides.export.SaveFormat.PPTX)
النتيجة:

المثال البرمجي أدناه يوضح كيفية تعيين لون الخلفية لأجزاء النص ذات الخط الغامق:
import aspose.pydrawing as draw
import aspose.slides as slides
with slides.Presentation("sample.pptx") as presentation:
slide = presentation.slides[0]
auto_shape = slide.shapes[0]
paragraph = auto_shape.text_frame.paragraphs[0]
for portion in paragraph.portions:
if portion.portion_format.get_effective().font_bold:
# تعيين لون التظليل لجزء النص.
portion.portion_format.highlight_color.color = draw.Color.light_gray
presentation.save("gray_text_portions.pptx", slides.export.SaveFormat.PPTX)
النتيجة:

محاذاة فقرات النص
استخدم ParagraphFormat.alignment لتعيين محاذاة الفقرة داخل إطار النص. يمكن أن تكون القيمة مركزية، محاذاة إلى اليسار، إلى اليمين، مبررة، إلخ.
المثال البرمجي التالي يوضح كيفية محاذاة الفقرة إلى المركز:
import aspose.slides as slides
with slides.Presentation("sample.pptx") as presentation:
slide = presentation.slides[0]
auto_shape = slide.shapes[0]
paragraph = auto_shape.text_frame.paragraphs[0]
# تعيين محاذاة الفقرة إلى المركز.
paragraph.paragraph_format.alignment = slides.TextAlignment.CENTER
presentation.save("aligned_paragraph.pptx", slides.export.SaveFormat.PPTX)
النتيجة:

محاذاة الخطوط داخل السطر
استخدم ParagraphFormat.font_alignment لمحاذاة أجزاء النص ذات أحجام الخط المختلفة عموديًا داخل السطر. ينطبق هذا الإعداد على الفقرة بأكملها ويتحكم في المحاذاة داخل كل سطر منها.
المثال التالي المستقل ينشئ أربع صناديق نصية معنونة على شريحة واحدة. كل فقرة تحتوي على نفس النص بحجم 18، 36، و54 نقطة، مع محاذاة خط مختلفة. يستخدم الخط Arial، ويعطل الملاءمة التلقائية واللف، ويجعل إطارات النص كبيرة بما يكفي لسطر واحد.
import aspose.pydrawing as draw
import aspose.slides as slides
with slides.Presentation() as presentation:
slide = presentation.slides[0]
alignments = [slides.FontAlignment.BASELINE, slides.FontAlignment.TOP, slides.FontAlignment.CENTER, slides.FontAlignment.BOTTOM]
font_sizes = [18, 36, 54]
for i, alignment in enumerate(alignments):
shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 30, 20 + i * 130, 660, 120)
shape.fill_format.fill_type = slides.FillType.NO_FILL
shape.line_format.fill_format.fill_type = slides.FillType.NO_FILL
text_frame = shape.text_frame
text_frame.text_frame_format.anchoring_type = slides.TextAnchorType.TOP
text_frame.text_frame_format.autofit_type = slides.TextAutofitType.NONE
text_frame.text_frame_format.wrap_text = slides.NullableBool.FALSE
label = text_frame.paragraphs[0]
label.text = alignment.name.title()
label.paragraph_format.alignment = slides.TextAlignment.LEFT
label.paragraph_format.default_portion_format.font_height = 14
label.paragraph_format.default_portion_format.latin_font = slides.FontData("Arial")
label.paragraph_format.default_portion_format.fill_format.fill_type = slides.FillType.SOLID
label.paragraph_format.default_portion_format.fill_format.solid_fill_color.color = draw.Color.gray
paragraph = slides.Paragraph()
paragraph.paragraph_format.font_alignment = alignment
paragraph.paragraph_format.alignment = slides.TextAlignment.LEFT
paragraph.paragraph_format.default_portion_format.latin_font = slides.FontData("Arial")
paragraph.paragraph_format.default_portion_format.fill_format.fill_type = slides.FillType.SOLID
paragraph.paragraph_format.default_portion_format.fill_format.solid_fill_color.color = draw.Color.black
for font_size in font_sizes:
portion = slides.Portion("Ag ")
portion.portion_format.font_height = font_size
paragraph.portions.add(portion)
text_frame.paragraphs.add(paragraph)
presentation.save("font_alignment.pptx", slides.export.SaveFormat.PPTX)
النتيجة:

محاذاة الخط تستخدم مقاييس الخط، لذلك قد لا تتطابق حواف الحروف الفردية بالضبط. يتضمن المثال حرفًا كبيرًا وحرفًا منخفضًا لتوضيح الفرق بين المحاذاة القاعدية والسفلية. تتأثر النتيجة بتوفر الخط وبدائله، الأحرف المستخدمة، واختلاف أحجام الخطوط. أبعاد الإطار، الهوامش، تباعد الأسطر، اللف، والملاءمة التلقائية تؤثر أيضًا على التخطيط؛ استخدم نفس الخطوط وإعدادات التخطيط عند المقارنة بين الأنماط.
يختلف هذا الإعداد عن ParagraphFormat.alignment، الذي يتحكم في محاذاة الفقرة أفقياً، وعن TextFrameFormat.anchoring_type، الذي يحدد موضع كتلة النص عموديًا داخل الشكل. تنسيق السوبراسسكريبت والسوبسسكريبت عبر BasePortionFormat.escapement يحرك الأجزاء الفردية نسبةً إلى الخط القاعدي بدلاً من تعيين محاذاة الخط لأسطر الفقرة.
تعيين الشفافية للنص
تتحكم شفافية النص من خلال مكوّن ألفا للون المعيّن إلى BasePortionFormat.fill_format. في الأمثلة أدناه، alpha = 50 هو قيمة قناة ألفا ARGB على مقياس 0–255، وليس نسبة الشفافية.
المثال البرمجي التالي يوضح كيفية تطبيق الشفافية على الفقرة بأكملها:
import aspose.pydrawing as draw
import aspose.slides as slides
alpha = 50
with slides.Presentation("sample.pptx") as presentation:
slide = presentation.slides[0]
auto_shape = slide.shapes[0]
paragraph = auto_shape.text_frame.paragraphs[0]
# تعيين تعبئة سوداء شبه شفافة للنص.
paragraph.paragraph_format.default_portion_format.fill_format.fill_type = slides.FillType.SOLID
paragraph.paragraph_format.default_portion_format.fill_format.solid_fill_color.color = draw.Color.from_argb(alpha, draw.Color.black)
presentation.save("transparent_paragraph.pptx", slides.export.SaveFormat.PPTX)
النتيجة:

المثال البرمجي التالي يوضح كيفية تطبيق الشفافية على أجزاء النص ذات الخط الغامق:
import aspose.pydrawing as draw
import aspose.slides as slides
alpha = 50
with slides.Presentation("sample.pptx") as presentation:
slide = presentation.slides[0]
auto_shape = slide.shapes[0]
paragraph = auto_shape.text_frame.paragraphs[0]
for portion in paragraph.portions:
if portion.portion_format.get_effective().font_bold:
# تعيين شفافية جزء النص.
portion.portion_format.fill_format.fill_type = slides.FillType.SOLID
portion.portion_format.fill_format.solid_fill_color.color = draw.Color.from_argb(alpha, draw.Color.black)
presentation.save("transparent_text_portions.pptx", slides.export.SaveFormat.PPTX)
النتيجة:

تعيين تباعد الأحرف للنص
استخدم BasePortionFormat.spacing لتوسيع أو تقليل التباعد بين الأحرف في مربع نص. تُضيف الأمثلة 3 نقاط من التباعد؛ القيم السالبة تقرّب النص.
الكود التالي في بايثون يوضح كيفية توسيع تباعد الأحرف في الفقرة بأكملها:
import aspose.slides as slides
with slides.Presentation("sample.pptx") as presentation:
slide = presentation.slides[0]
auto_shape = slide.shapes[0]
paragraph = auto_shape.text_frame.paragraphs[0]
# ملاحظة: استخدم قيمًا سالبة لتقليل تباعد الأحرف.
paragraph.paragraph_format.default_portion_format.spacing = 3 # توسيع تباعد الأحرف.
presentation.save("character_spacing_in_paragraph.pptx", slides.export.SaveFormat.PPTX)
النتيجة:

المثال البرمجي أدناه يوضح كيفية توسيع تباعد الأحرف في أجزاء النص ذات الخط الغامق:
import aspose.slides as slides
with slides.Presentation("sample.pptx") as presentation:
slide = presentation.slides[0]
auto_shape = slide.shapes[0]
paragraph = auto_shape.text_frame.paragraphs[0]
for portion in paragraph.portions:
if portion.portion_format.get_effective().font_bold:
# ملاحظة: استخدم قيمًا سالبة لتقليل تباعد الأحرف.
portion.portion_format.spacing = 3 # توسيع تباعد الأحرف.
presentation.save("character_spacing_in_text_portions.pptx", slides.export.SaveFormat.PPTX)
النتيجة:

تعطيل التتبع (Kerning) لخطوط معينة
في بعض الحالات، قد يبدو النص المرسوم بواسطة Aspose.Slides أكثر تماسكًا قليلاً من النص نفسه في PowerPoint. يحدث هذا لأن PowerPoint قد يتجاهل بيانات التتبع لبعض الخطوط، حتى عندما يحتوي الخط على معلومات تتبع صالحة ويتم تمكين التتبع في إعدادات PowerPoint.
لتقريب الناتج المرسوم من مظهر PowerPoint في مثل هذه الحالات، يمكنك تعطيل التتبع لأجزاء النص التي تستخدم الخط المتأثر. اضبط BasePortionFormat.kerning_minimal_size إلى قيمة أكبر من الحجم الفعلي للخط. يتطلب هذا المثال ملف “presentation.pptx” يحتوي على مربع نص كشكل أول في الشريحة الأولى. يتحقق من أسماء الخطوط الفعالة، بما في ذلك الخطوط الموروثة، ويضبط عتبة 100 نقطة للأجزاء التي تستخدم Roboto. هذا يعطل التتبع للأجزاء المطابقة التي يكون حجم الخط أقل من 100 نقطة:
import aspose.slides as slides
with slides.Presentation("presentation.pptx") as presentation:
slide = presentation.slides[0]
auto_shape = slide.shapes[0]
target_font = "Roboto"
for paragraph in auto_shape.text_frame.paragraphs:
for portion in paragraph.portions:
text_format = portion.portion_format.get_effective()
fonts = (text_format.latin_font, text_format.east_asian_font, text_format.complex_script_font)
uses_target_font = any(font is not None and font.font_name == target_font for font in fonts)
if uses_target_font:
portion.portion_format.kerning_minimal_size = 100
presentation.save("output.pptx", slides.export.SaveFormat.PPTX)
بالنسبة للنص المطابق الذي يقل عن العتبة، يمنع هذا الإعداد التتبع وقد يساعد في مواءمة عرض Aspose.Slides مع المظهر البصري لـ PowerPoint للخطوط المتأثرة بهذا السلوك الخاص بـ PowerPoint.
إدارة خصائص خط النص
يمكن تعيين خصائص الخط على مستوى الفقرة عبر ParagraphFormat.default_portion_format أو على الأجزاء الفردية عبر PortionFormat.
المثال التالي يحدد الخط الافتراضي للفقرة الأولى إلى Times New Roman بحجم 12 نقطة مع تنسيق غامق، مائل، وتسطير منقط. تنسيق صريح على الأجزاء الفردية له أولوية على هذه الإعدادات الافتراضية.
import aspose.slides as slides
with slides.Presentation("sample.pptx") as presentation:
slide = presentation.slides[0]
auto_shape = slide.shapes[0]
paragraph = auto_shape.text_frame.paragraphs[0]
# تعيين خصائص الخط للفقرة.
portion_format = paragraph.paragraph_format.default_portion_format
portion_format.font_height = 12
portion_format.font_bold = slides.NullableBool.TRUE
portion_format.font_italic = slides.NullableBool.TRUE
portion_format.font_underline = slides.TextUnderlineType.DOTTED
portion_format.latin_font = slides.FontData("Times New Roman")
presentation.save("font_properties_for_paragraph.pptx", slides.export.SaveFormat.PPTX)
النتيجة:

المثال التالي يطبق Times New Roman بحجم 13 نقطة، تنسيق مائل، وتسطير منقط على الأجزاء التي يكون تنسيقها الفعّال غامقًا:
import aspose.slides as slides
with slides.Presentation("sample.pptx") as presentation:
slide = presentation.slides[0]
auto_shape = slide.shapes[0]
paragraph = auto_shape.text_frame.paragraphs[0]
for portion in paragraph.portions:
if portion.portion_format.get_effective().font_bold:
# تعيين خصائص الخط لجزء النص.
portion.portion_format.font_height = 13
portion.portion_format.font_italic = slides.NullableBool.TRUE
portion.portion_format.font_underline = slides.TextUnderlineType.DOTTED
portion.portion_format.latin_font = slides.FontData("Times New Roman")
presentation.save("font_properties_for_text_portions.pptx", slides.export.SaveFormat.PPTX)
النتيجة:

التحكم في تطبيع ارتفاع النص
استخدم BasePortionFormat.normalise_height عند إعادة إنتاج طباعة القالب أو فحص الفروقات في ارتفاع الأحرف. في PowerPoint، يؤدي تمكين التطبيع إلى تمديد أو ضغط الأحرف عموديًا لمنحها ارتفاعًا مرئيًا موحدًا داخل جزء النص. لا يضمن ذلك ارتفاع نص موحد عبر خطوط مختلفة.
اضبط الخاصية إلى NullableBool.TRUE أو FALSE لتمكين أو تعطيل التطبيع صراحةً. NullableBool.NOT_DEFINED يترك الإعداد المحلي غير مضبوط بحيث يرث الجزء قيمته، على سبيل المثال، من default_portion_format الخاص بالفقرة. لا يعني ذلك False. استخدم PortionFormat.get_effective وقراءة IBasePortionFormatEffectiveData.normalise_height للحصول على القيمة البوليانية المحلولة.
المثال التالي المستقل يتطلب تثبيت Arial. ينشئ كتلتين نصيتين يحتويان على نفس الحروف الكبيرة، الصغيرة، الأحرف السفلية، والحروف ذات العلامات في 54 نقطة. تمكّن الفقرتان التطبيع افتراضيًا. الجزء العلوي يعطل التطبيع صراحةً؛ الجزء السفلي يرثه. أبعاد الإطار، الهوامش، وتباعد الفقرات متطابقة، مع تعطيل اللف والملاءمة التلقائية للحفاظ على مقارنة ثابتة. يطبع المثال FALSE: False وNOT_DEFINED: True، ثم يحفظ “text_height_normalization.pptx”.
import aspose.slides as slides
with slides.Presentation() as presentation:
slide = presentation.slides[0]
settings = [slides.NullableBool.FALSE, slides.NullableBool.NOT_DEFINED]
for i, setting in enumerate(settings):
shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 30, 60 + i * 200, 660, 150)
shape.fill_format.fill_type = slides.FillType.NO_FILL
shape.line_format.fill_format.fill_type = slides.FillType.NO_FILL
text_frame = shape.text_frame
text_frame.text = "Hxgjpq ÅÉ 0123"
text_frame.text_frame_format.autofit_type = slides.TextAutofitType.NONE
text_frame.text_frame_format.wrap_text = slides.NullableBool.FALSE
text_frame.text_frame_format.anchoring_type = slides.TextAnchorType.TOP
text_frame.text_frame_format.margin_top = 0
text_frame.text_frame_format.margin_left = 0
paragraph = text_frame.paragraphs[0]
paragraph.paragraph_format.alignment = slides.TextAlignment.LEFT
paragraph.paragraph_format.space_before = 0
paragraph.paragraph_format.space_after = 0
paragraph.paragraph_format.space_within = 100
paragraph.paragraph_format.default_portion_format.normalise_height = slides.NullableBool.TRUE
portion = paragraph.portions[0]
portion.portion_format.latin_font = slides.FontData("Arial")
portion.portion_format.font_height = 54
portion.portion_format.fill_format.fill_type = slides.FillType.SOLID
portion.portion_format.fill_format.solid_fill_color.color = "black"
portion.portion_format.normalise_height = setting
print(f"{setting.name}: {portion.portion_format.get_effective().normalise_height}")
presentation.save("text_height_normalization.pptx", slides.export.SaveFormat.PPTX)
تم تصدير المقارنة أدناه من العرض المحفوظ. الصف العلوي فيه التطبيع معطل (FALSE)، والصف السفلي يرث الإعداد المفعل (NOT_DEFINED → True). احرص على تثبيت Arial لتستعيد هذا المظهر.

يغيّر التطبيع ارتفاع الأحرف دون تعديل قيمة font_height المعينة، التي تحدد حجم الخط بالنقاط. يتحكم space_within في الفقرة لتباعد الأسطر، بينما يتحكم autofit_type لإطار النص في كيفية ضبط النص أو حاويته لتناسبه. هذه الإعدادات تخدم أغراضًا مختلفة ويمكن أن تؤثر على التخطيط العام بشكل مستقل. للمزيد حول تنسيق الفقرة والوراثة، راجع إدارة الفقرة.
تطبيق وإزالة خط الإلغاء (Strikethrough)
استخدم BasePortionFormat.strikethrough_type على جزء نص لإظهار تصحيحات أو مصطلحات ملغاة أو أسعار سابقة دون حذف النص الأصلي. اضبطه إلى TextStrikethroughType.SINGLE أو DOUBLE لسطر واحد أو مزدوج عبر النص.
لإزالة خط الإلغاء، عيّن TextStrikethroughType.NONE. هذا يعطل التأثير صراحةً، حتى إذا كان التنسيق المحيط يحدد خط إلغاء. بالمقابل، يترك TextStrikethroughType.NOT_DEFINED الإعداد المحلي غير معرف، مما يسمح للجزء بورث التنسيق، على سبيل المثال من الفقرة. لا يضمن ذلك إزالة خط الإلغاء. استخدم PortionFormat.get_effective لقراءة التنسيق الناتج، بما في ذلك القيم الموروثة.
المثال التالي المستقل ينشئ ثلاث مقارنات أسعار. كل فقرة لديها أجزاء منفصلة للملصق، السعر السابق، والسعر الحالي، بحيث يتأثر السعر السابق فقط. الصف الأول يطبق ثم يزيل خط الإلغاء؛ الصفوف الأخرى تحتفظ بخط إلغاء واحد أو مزدوج. تغيير هذه الخاصية يحافظ على النص وتنسيقه الآخر، بما في ذلك الغامق للسعر السابق.
import aspose.pydrawing as draw
import aspose.slides as slides
with slides.Presentation() as presentation:
slide = presentation.slides[0]
shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 50, 620, 220)
shape.fill_format.fill_type = slides.FillType.NO_FILL
shape.line_format.fill_format.fill_type = slides.FillType.NO_FILL
shape.text_frame.paragraphs.clear()
labels = ["None: ", "Single: ", "Double: "]
for label in labels:
paragraph = slides.Paragraph()
paragraph.paragraph_format.alignment = slides.TextAlignment.LEFT
paragraph.paragraph_format.space_after = 20
portion_format = paragraph.paragraph_format.default_portion_format
portion_format.font_height = 28
portion_format.latin_font = slides.FontData("Arial")
portion_format.fill_format.fill_type = slides.FillType.SOLID
portion_format.fill_format.solid_fill_color.color = draw.Color.black
paragraph.portions.add(slides.Portion(label))
previous_price = slides.Portion("$100")
previous_price.portion_format.font_bold = slides.NullableBool.TRUE
paragraph.portions.add(previous_price)
paragraph.portions.add(slides.Portion(" → $80"))
shape.text_frame.paragraphs.add(paragraph)
paragraphs = shape.text_frame.paragraphs
# تطبيق خط الإلغاء، ثم إزالته صراحةً من السعر السابق الأول.
paragraphs[0].portions[1].portion_format.strikethrough_type = slides.TextStrikethroughType.SINGLE
paragraphs[0].portions[1].portion_format.strikethrough_type = slides.TextStrikethroughType.NONE
paragraphs[1].portions[1].portion_format.strikethrough_type = slides.TextStrikethroughType.SINGLE
paragraphs[2].portions[1].portion_format.strikethrough_type = slides.TextStrikethroughType.DOUBLE
presentation.save("strikethrough.pptx", slides.export.SaveFormat.PPTX)
النتيجة من الأعلى إلى الأسفل: لا خط إلغاء، خط إلغاء واحد، وخط إلغاء مزدوج.

تعيين دوران النص
استخدم TextFrameFormat.text_vertical_type لتعيين توجيه نص مسبق داخل شكل.
المثال البرمجي التالي يضبط توجيه النص في الشكل إلى TextVerticalType.VERTICAL270، مما يدور النص 90 درجة عكس عقارب الساعة:
import aspose.slides as slides
with slides.Presentation("sample.pptx") as presentation:
slide = presentation.slides[0]
auto_shape = slide.shapes[0]
auto_shape.text_frame.text_frame_format.text_vertical_type = slides.TextVerticalType.VERTICAL270
presentation.save("text_rotation.pptx", slides.export.SaveFormat.PPTX)
النتيجة:

تعيين دوران مخصص لإطارات النص
استخدم TextFrameFormat.rotation_angle لتعيين زاوية دوران مخصصة لـ TextFrame.
المثال البرمجي أدناه يدير إطار النص بزاوية 3 درجات باتجاه عقارب الساعة داخل الشكل:
import aspose.slides as slides
with slides.Presentation("sample.pptx") as presentation:
slide = presentation.slides[0]
auto_shape = slide.shapes[0]
auto_shape.text_frame.text_frame_format.rotation_angle = 3
presentation.save("custom_text_rotation.pptx", slides.export.SaveFormat.PPTX)
النتيجة:

تعيين تباعد السطر للفقرات
توفر Aspose.Slides الخصائص ParagraphFormat.space_after، ParagraphFormat.space_before، وParagraphFormat.space_within للتحكم بتباعد الفقرات. تُستخدم هذه الخصائص كالتالي:
- استخدم قيمة موجبة لتحديد تباعد السطر كنسبة مئوية من ارتفاع السطر.
- استخدم قيمة سالبة لتحديد تباعد السطر بالنقاط.
المثال التالي يحدد التباعد داخل الفقرة الأولى إلى 200% من ارتفاع السطر (تباعد مزدوج):
import aspose.slides as slides
with slides.Presentation("sample.pptx") as presentation:
slide = presentation.slides[0]
auto_shape = slide.shapes[0]
paragraph = auto_shape.text_frame.paragraphs[0]
paragraph.paragraph_format.space_within = 200
presentation.save("line_spacing.pptx", slides.export.SaveFormat.PPTX)
النتيجة:

التحكم في كسر السطر
قواعد كسر سطر الفقرة مفيدة في كتل نصية ضيقة وعروض تقديمية تمزج بين النص اللاتيني والآسيوي الشرقي. الخصائص التالية تنتمي إلى ParagraphFormat، لذا فهي تنطبق على الفقرة بأكملها:
- latin_line_break يتحكم في قواعد كسر السطر اللاتيني. في نص مختلط، يمكن لتغييره أيضًا تغيير موضع اللف للنص الآسيوي الشرقي وعلامات الترقيم المجاورة.
- east_asian_line_break يتحكم في قواعد كسر السطر الآسيوي الشرقي، بما في ذلك القيود على الأحرف في بداية ونهاية السطر.
هذه القواعد لا تحل محل TextFrameFormat.wrap_text، الذي يُمكّن اللف التلقائي داخل إطار النص. إنها تؤثر على التخطيط عندما يحدث اللف؛ لا تُدرج أحرف كسر السطر. كسر سطر صريح يُجبر سطرًا جديدًا داخل الفقرة بغض النظر عن العرض المتاح.
المثال التالي المستقل ينشئ كتلة نصية ضيقة تحتوي على نص صيني ولاتيني. يضبط كلا خاصيتي كسر السطر صراحةً ويحفظ “line_breaking.pptx”. لتجربة أي قاعدة، غير قيمة الخاصية مع إبقاء الإعدادات الأخرى ثابتة. يستخدم المثال خط Arial بحجم 24 نقطة وSimSun مع عرض إطار 160 نقطة وهوامش أفقية صفرية لإطار النص. يُضبط autofit_type إلى TextAutofitType.NONE للحفاظ على حجم النص وإطار النص ثابتين.
import aspose.pydrawing as draw
import aspose.slides as slides
with slides.Presentation() as presentation:
slide = presentation.slides[0]
shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 50, 160, 300)
shape.fill_format.fill_type = slides.FillType.NO_FILL
text_frame = shape.text_frame
text_frame.text_frame_format.wrap_text = slides.NullableBool.TRUE
text_frame.text_frame_format.autofit_type = slides.TextAutofitType.NONE
text_frame.text_frame_format.margin_left = 0
text_frame.text_frame_format.margin_right = 0
paragraph = text_frame.paragraphs[0]
paragraph.text = "中文排版测试,PowerPoint 中文演示。"
paragraph_format = paragraph.paragraph_format
paragraph_format.alignment = slides.TextAlignment.LEFT
paragraph_format.default_portion_format.font_height = 24
paragraph_format.default_portion_format.latin_font = slides.FontData("Arial")
paragraph_format.default_portion_format.east_asian_font = slides.FontData("SimSun")
paragraph_format.default_portion_format.fill_format.fill_type = slides.FillType.SOLID
paragraph_format.default_portion_format.fill_format.solid_fill_color.color = draw.Color.black
paragraph_format.latin_line_break = slides.NullableBool.FALSE
paragraph_format.east_asian_line_break = slides.NullableBool.TRUE
presentation.save("line_breaking.pptx", slides.export.SaveFormat.PPTX)
التحكم في علامات الترقيم المتدلية
يسمح ParagraphFormat.hanging_punctuation للعلامات الترقيمية المؤهلة بالتمدد خارج الحافة اليمنى لسطر النص بدلاً من احتلال السطر التالي. يطبق على الفقرة بأكملها وهو مختلف عن المسافة المتدلية.
المثال التالي المستقل يُفعّل علامات الترقيم المتدلية في إطار نص عرضه 100 نقطة ويحفظ “hanging_punctuation.pptx”. باستخدام Arial بحجم 24 نقطة وهوامش أفقية صفرية، يبقى النقطة النهائية بعد كلمة “sentence” وتمتد خارج حافة النص اليمنى. اضبط الخاصية إلى NullableBool.FALSE للمقارنة: بهذه الإعدادات، تحتل النقطة سطرًا منفصلًا. يُفعَّل اللف ويُعطَّل الملاءمة التلقائية للحفاظ على عرض ثابت.
import aspose.pydrawing as draw
import aspose.slides as slides
with slides.Presentation() as presentation:
slide = presentation.slides[0]
shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 50, 100, 200)
shape.fill_format.fill_type = slides.FillType.NO_FILL
text_frame = shape.text_frame
text_frame.text_frame_format.wrap_text = slides.NullableBool.TRUE
text_frame.text_frame_format.autofit_type = slides.TextAutofitType.NONE
text_frame.text_frame_format.margin_left = 0
text_frame.text_frame_format.margin_right = 0
paragraph = text_frame.paragraphs[0]
paragraph.text = "Simple text, next sentence."
paragraph_format = paragraph.paragraph_format
paragraph_format.alignment = slides.TextAlignment.LEFT
paragraph_format.default_portion_format.font_height = 24
paragraph_format.default_portion_format.latin_font = slides.FontData("Arial")
paragraph_format.default_portion_format.fill_format.fill_type = slides.FillType.SOLID
paragraph_format.default_portion_format.fill_format.solid_fill_color.color = draw.Color.black
paragraph_format.hanging_punctuation = slides.NullableBool.TRUE
presentation.save("hanging_punctuation.pptx", slides.export.SaveFormat.PPTX)
ليس كل علامة ترقيم يمكن أن تتدلى. النتيجة المرئية تعتمد على الخط وظروف التخطيط: تغيير الخط أو العرض المتاح أو الهوامش أو إعدادات الملاءمة التلقائية يمكن أن يزيل الفرق المرئي.
تعيين نوع الملاءمة التلقائية لإطارات النص
يحدد TextFrameFormat.autofit_type كيفية تصرف النص عندما يتجاوز حدود الحاوية. استخدمه للتحكم فيما إذا كان النص يُصغّر، يفيض، أو يُعيد تحجيم الشكل تلقائيًا. المثال التالي يضبط الشكل لإعادة التحجيم ليناسب النص ويحفظ النتيجة إلى “autofit_type.pptx”.
import aspose.slides as slides
with slides.Presentation("sample.pptx") as presentation:
slide = presentation.slides[0]
auto_shape = slide.shapes[0]
auto_shape.text_frame.text_frame_format.autofit_type = slides.TextAutofitType.SHAPE
presentation.save("autofit_type.pptx", slides.export.SaveFormat.PPTX)
لحساب عدد الأسطر بعد اللف التلقائي ورؤية كيف يتغيّر عرض النص أو الشكل، راجع عد الأسطر المُرسومة. عدد الأسطر وحده لا يدل على ما إذا كان النص يفيض عن الحاوية.
تعيين تثبيت إطارات النص
يعّرف TextFrameFormat.anchoring_type كيفية موضع النص عموديًا داخل الشكل، مثل الأعلى، الوسط، أو الأسفل. المثال التالي يثبت النص إلى أسفل الشكل الأول ويحفظ النتيجة إلى “text_anchor.pptx”.
import aspose.slides as slides
with slides.Presentation("sample.pptx") as presentation:
slide = presentation.slides[0]
auto_shape = slide.shapes[0]
auto_shape.text_frame.text_frame_format.anchoring_type = slides.TextAnchorType.BOTTOM
presentation.save("text_anchor.pptx", slides.export.SaveFormat.PPTX)
تعيين علامات التبويب للنص
استخدم ParagraphFormat.default_tab_size وParagraphFormat.tabs لتكوين نقاط التبويب في فقرة. المثال التالي يضبط الفاصل الزمني الافتراضي للعلامة إلى 100 نقطة ويضيف علامة تبويب محاذاة إلى اليسار عند 30 نقطة. تؤثر هذه الإعدادات على النص الذي يحتوي على أحرف تبويب.
import aspose.slides as slides
with slides.Presentation("sample.pptx") as presentation:
slide = presentation.slides[0]
auto_shape = slide.shapes[0]
paragraph = auto_shape.text_frame.paragraphs[0]
paragraph.paragraph_format.default_tab_size = 100
paragraph.paragraph_format.tabs.add(30, slides.TabAlignment.LEFT)
presentation.save("paragraph_tabs.pptx", slides.export.SaveFormat.PPTX)
النتيجة:

تعيين لغة التدقيق
توفر Aspose.Slides الخاصية BasePortionFormat.language_id، التي تسمح لك بتعيين لغة التدقيق لجزء النص. تحدد لغة التدقيق اللغة المستخدمة لتدقيق الإملاء والقواعد في PowerPoint.
المثال التالي يتطلب “presentation.pptx” يحتوي على مربع نص كشكل أول في الشريحة الأولى وعلى الأقل فقرة واحدة. يستبدل محتويات الفقرة الأولى بـ “1。” ويضبط SimSun كخط لها، ويعيّن لغة التدقيق الصينية المبسطة (zh-CN). يحفظ النتيجة إلى “proofing_language.pptx”:
import aspose.slides as slides
with slides.Presentation("presentation.pptx") as presentation:
slide = presentation.slides[0]
auto_shape = slide.shapes[0]
paragraph = auto_shape.text_frame.paragraphs[0]
paragraph.portions.clear()
font = slides.FontData("SimSun")
text_portion = slides.Portion()
text_portion.portion_format.complex_script_font = font
text_portion.portion_format.east_asian_font = font
text_portion.portion_format.latin_font = font
# تعيين لغة التدقيق إلى الصينية المبسطة.
text_portion.portion_format.language_id = "zh-CN"
text_portion.text = "1。"
paragraph.portions.add(text_portion)
presentation.save("proofing_language.pptx", slides.export.SaveFormat.PPTX)
تعيين اللغة الافتراضية
استخدم LoadOptions.default_text_language لتحديد اللغة الافتراضية للنص المنشأ أثناء تحميل أو إنشاء عرض تقديمي. المثال التالي ينشئ عرضًا تقديميًا باللغة الإنجليزية الأمريكية كلغة نص افتراضية، يضيف مربع نص، ويطبع en-US للجزء النصي الأول.
import aspose.slides as slides
load_options = slides.LoadOptions()
load_options.default_text_language = "en-US"
with slides.Presentation(load_options) as presentation:
slide = presentation.slides[0]
# إضافة شكل مستطيل جديد مع نص.
shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 20, 20, 150, 50)
shape.text_frame.text = "Sample text"
# التحقق من لغة الجزء الأول.
portion = shape.text_frame.paragraphs[0].portions[0]
print(portion.portion_format.language_id)
تعيين نمط النص الافتراضي
لتطبيق تنسيق نص افتراضي على مستوى العرض، استخدم Presentation.default_text_style.
المثال التالي يعيّن خطًا غامقًا بحجم 14 نقطة كافتراضي للفقرات العليا في عرض تقديمي جديد ويحفظه إلى “default_text_style.pptx”. يمكن للنص أن يرث هذه الإعدادات ما لم يتجاوزها تنسيق أكثر تحديدًا.
import aspose.slides as slides
with slides.Presentation() as presentation:
# احصل على تنسيق الفقرة ذات المستوى الأعلى.
paragraph_format = presentation.default_text_style.get_level(0)
if paragraph_format is not None:
paragraph_format.default_portion_format.font_height = 14
paragraph_format.default_portion_format.font_bold = slides.NullableBool.TRUE
presentation.save("default_text_style.pptx", slides.export.SaveFormat.PPTX)
استخراج النص مع تأثير الحروف الكبيرة (All-Caps)
في PowerPoint، يؤدي تطبيق تأثير الخط All Caps إلى ظهور النص بأحرف كبيرة على الشريحة حتى وإن كان مكتوبًا أصلاً بأحرف صغيرة. عندما تسترجع مثل هذا الجزء النصي باستخدام Aspose.Slides، تُعيد المكتبة النص كما تم إدخاله. لمطابقة النص المعروض، تحقّق من TextCapType وحوّل السلسلة المسترجعة إلى أحرف كبيرة عندما تكون القيمة ALL.
يتطلب هذا المثال ملف “sample2.pptx” يحتوي على مربع نص كشكل أول في الشريحة الأولى. يحتوي الجزء الأول من الفقرة الأولى على “Hello, Aspose!” مع تطبيق تأثير All Caps، كما هو موضح أدناه.

المثال البرمجي التالي يوضح كيفية استخراج النص مع تطبيق تأثير All Caps:
import aspose.slides as slides
with slides.Presentation("sample2.pptx") as presentation:
slide = presentation.slides[0]
auto_shape = slide.shapes[0]
text_portion = auto_shape.text_frame.paragraphs[0].portions[0]
print("Original text:", text_portion.text)
text_format = text_portion.portion_format.get_effective()
if text_format.text_cap_type == slides.TextCapType.ALL:
text = text_portion.text.upper()
print("All-Caps effect:", text)
المخرجات:
Original text: Hello, Aspose!
All-Caps effect: HELLO, ASPOSE!
الأسئلة الشائعة
كيف يمكنني تعديل النص في جدول على شريحة؟
لتعديل النص في جدول على شريحة، استخدم Table. تجول عبر الخلايا وقم بتحديث كل خلية عبر Cell.text_frame وتنسيق الفقرة عبر Paragraph.paragraph_format.
كيف يمكنني تطبيق لون متدرج للنص على شريحة PowerPoint؟
لتطبيق لون متدرج للنص، استخدم BasePortionFormat.fill_format. اضبط FillFormat.fill_type إلى FillType.GRADIENT واضبط نقاط التدرج والاتجاه والشفافية.
الميزة ذات الصلة: تنسيق النص داخل الشرائح.