قالب‌بندی متن ارائه در JavaScript

بررسی کلی

این مقاله نشان می‌دهد که چگونه می‌توانید متن را در ارائه‌های PowerPoint و OpenDocument با استفاده از Aspose.Slides برای Node.js از طریق Java قالب‌بندی کنید. موضوعاتی مانند برجسته‌سازی، رنگ پس‌زمینه، شفافیت، فاصله‌گذاری حروف، ویژگی‌های قلم، چرخش، فاصله پاراگراف، رفتار Autofit، لنگر متن، ایست‌گاه‌های تب و تنظیمات زبان پوشش داده می‌شود.

در مثال‌های زیر از فایلی به نام “sample.pptx” استفاده خواهیم کرد که یک جعبه متن در اسلاید اول دارد و شامل متن زیر است:

متن نمونه

برجسته‌سازی متن

از متد TextFrame.highlightText هنگام نیاز به برجسته‌سازی متنی که با یک الگوی نمونه خاص در یک فریم متن مطابقت دارد، استفاده کنید. این متد یک رنگ برجسته به بخش‌های متن مطابقت یافته اعمال می‌کند و می‌تواند همراه با TextSearchOptions برای کنترل نحوه جستجو، برای مثال برای مطابقت فقط با کلمات کامل، به کار رود.

مثال کد زیر تمام رخدادهای کاراکترهای “try” را برجسته می‌کند و سپس فقط کلمه کامل “to” را برجسته می‌سازد.

const presentation = new aspose.slides.Presentation("sample.pptx");
try {
    const shape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);
    const textFrame = shape.getTextFrame();

    // کلمه "try" را در شکل برجسته کنید.
    textFrame.highlightText("try", java.getStaticFieldValue("java.awt.Color", "LIGHT_GRAY"));

    const searchOptions = new aspose.slides.TextSearchOptions();
    searchOptions.setWholeWordsOnly(true);

    // کلمه "to" را در شکل برجسته کنید.
    textFrame.highlightText("to", java.getStaticFieldValue("java.awt.Color", "MAGENTA"), searchOptions, null);

    presentation.save("highlighted_text.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

نتیجه:

متن برجسته شده

برجسته‌سازی متن با استفاده از عبارات منظم

متد TextFrame.highlightRegex متون مطابقت یافته توسط یک عبارت منظم را برجسته می‌کند. در Node.js از طریق Java، این API در TextFrame در دسترس است.

کد زیر تمام کلماتی را که هفت کاراکتر یا بیشتر دارند برجسته می‌کند:

const Pattern = java.import("java.util.regex.Pattern");
const presentation = new aspose.slides.Presentation("sample.pptx");
try {
    const shape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);
    const regex = Pattern.compile("\\b[^\\s]{7,}\\b");

    // تمام کلماتی که دارای هفت یا بیشتر کاراکتر هستند را برجسته کنید.
    shape.getTextFrame().highlightRegex(regex, java.getStaticFieldValue("java.awt.Color", "YELLOW"), null);

    presentation.save("highlighted_text_using_regex.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

نتیجه:

متن برجسته شده با استفاده از عبارت منظم

تنظیم رنگ پس‌زمینه متن

از ParagraphFormat.getDefaultPortionFormat برای تنظیم رنگ پیش‌فرض برجسته‌سازی یک پاراگراف، یا از PortionFormat.getHighlightColor برای بخش‌های متنی جداگانه استفاده کنید.

کد زیر رنگ پس‌زمینه تمام پاراگراف را تنظیم می‌کند:

const presentation = new aspose.slides.Presentation("sample.pptx");
try {
    const autoShape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);
    const paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);

    // رنگ برجسته‌سازی را برای تمام پاراگراف تنظیم کنید.
    paragraph.getParagraphFormat().getDefaultPortionFormat().getHighlightColor().setColor(java.getStaticFieldValue("java.awt.Color", "LIGHT_GRAY"));

    presentation.save("gray_paragraph.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

نتیجه:

پاراگراف خاکستری

کد زیر رنگ پس‌زمینه بخش‌های متنی با قلم بولد را تنظیم می‌کند:

const presentation = new aspose.slides.Presentation("sample.pptx");
try {
    const autoShape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);
    const paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
    const portions = paragraph.getPortions();
    const portionCount = portions.getCount();

    for (let portionIndex = 0; portionIndex < portionCount; portionIndex++) {
        const portion = portions.get_Item(portionIndex);
        if (portion.getPortionFormat().getEffective().getFontBold()) {
            // رنگ برجسته‌سازی را برای بخش متن تنظیم کنید.
            portion.getPortionFormat().getHighlightColor().setColor(java.getStaticFieldValue("java.awt.Color", "LIGHT_GRAY"));
        }
    }

    presentation.save("gray_text_portions.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

نتیجه:

بخش‌های متنی خاکستری

تراز کردن پاراگراف‌های متن

از ParagraphFormat.setAlignment برای تنظیم تراز پاراگراف داخل یک فریم متن استفاده کنید. مقدار می‌تواند وسط‌چین، چپ‌چین، راست‌چین، توجیه‌شده و غیره باشد.

کد زیر پاراگراف را به مرکز تراز می‌کند:

const presentation = new aspose.slides.Presentation("sample.pptx");
try {
    const autoShape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);
    const paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);

    // تراز پاراگراف را به مرکز تنظیم کنید.
    paragraph.getParagraphFormat().setAlignment(aspose.slides.TextAlignment.Center);

    presentation.save("aligned_paragraph.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

نتیجه:

پاراگراف تراز شده

تنظیم شفافیت برای متن

شفافیت متن از طریق مؤلفه آلفای رنگی که به PortionFormat.getFillFormat اختصاص داده می‌شود، کنترل می‌گردد. در مثال‌های زیر، alpha = 50 یک مقدار آلفا در مقیاس 0‑255 است، نه درصد شفافیت.

کد زیر شفافیت تمام پاراگراف را اعمال می‌کند:

const alpha = 50;
const transparentBlack = java.newInstanceSync("java.awt.Color", 0, 0, 0, alpha);
const presentation = new aspose.slides.Presentation("sample.pptx");
try {
    const autoShape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);
    const paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
    const fillFormat = paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat();

    // رنگ پر متن را به رنگ شفاف تنظیم کنید.
    fillFormat.setFillType(java.newByte(aspose.slides.FillType.Solid));
    fillFormat.getSolidFillColor().setColor(transparentBlack);

    presentation.save("transparent_paragraph.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

نتیجه:

پاراگراف شفاف

کد زیر شفافیت بخش‌های متنی با قلم بولد را اعمال می‌کند:

const alpha = 50;
const transparentBlack = java.newInstanceSync("java.awt.Color", 0, 0, 0, alpha);
const presentation = new aspose.slides.Presentation("sample.pptx");
try {
    const autoShape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);
    const paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
    const portions = paragraph.getPortions();
    const portionCount = portions.getCount();

    for (let portionIndex = 0; portionIndex < portionCount; portionIndex++) {
        const portion = portions.get_Item(portionIndex);
        if (portion.getPortionFormat().getEffective().getFontBold()) {
            const fillFormat = portion.getPortionFormat().getFillFormat();

            // شفافیت بخش متن را تنظیم کنید.
            fillFormat.setFillType(java.newByte(aspose.slides.FillType.Solid));
            fillFormat.getSolidFillColor().setColor(transparentBlack);
        }
    }

    presentation.save("transparent_text_portions.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

نتیجه:

بخش‌های متنی شفاف

تنظیم فاصله‌گذاری کاراکترها برای متن

از BasePortionFormat.setSpacing برای افزایش یا کاهش فاصله بین کاراکترها در یک جعبه متن استفاده کنید.

کد JavaScript زیر فاصله‌گذاری کاراکترها را در تمام پاراگراف گسترش می‌دهد:

const presentation = new aspose.slides.Presentation("sample.pptx");
try {
    const autoShape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);
    const paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);

    // توجه: برای فشرده‌کردن فاصله کاراکتر از مقادیر منفی استفاده کنید.
    paragraph.getParagraphFormat().getDefaultPortionFormat().setSpacing(3); // فاصله کاراکترها را گسترش دهید.

    presentation.save("character_spacing_in_paragraph.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

نتیجه:

فاصله‌گذاری کاراکترها در پاراگراف

کد زیر فاصله‌گذاری کاراکترها را در بخش‌های متنی با قلم بولد گسترش می‌دهد:

const presentation = new aspose.slides.Presentation("sample.pptx");
try {
    const autoShape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);
    const paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
    const portions = paragraph.getPortions();
    const portionCount = portions.getCount();

    for (let portionIndex = 0; portionIndex < portionCount; portionIndex++) {
        const portion = portions.get_Item(portionIndex);
        if (portion.getPortionFormat().getEffective().getFontBold()) {
            // توجه: برای فشرده‌کردن فاصله کاراکتر از مقادیر منفی استفاده کنید.
            portion.getPortionFormat().setSpacing(3); // فاصله کاراکترها را گسترش دهید.
        }
    }

    presentation.save("character_spacing_in_text_portions.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

نتیجه:

فاصله‌گذاری کاراکترها در بخش‌های متنی

غیرفعال کردن کرنینگ برای فونت‌های خاص

در برخی موارد، متنی که توسط Aspose.Slides رندر می‌شود، کمی فشرده‌تر از متن مشابه در PowerPoint به نظر می‌رسد. این می‌تواند به این دلیل باشد که PowerPoint داده‌های کرنینگ را برای برخی فونت‌ها نادیده می‌گیرد، حتی اگر فونت دارای اطلاعات کرنینگ معتبر باشد و کرنینگ در تنظیمات PowerPoint فعال باشد.

برای نزدیک‌تر کردن خروجی رندر به PowerPoint، می‌توانید کرنینگ را برای بخش‌های متنی که از فونت تحت تأثیر هستند غیرفعال کنید. مقدار BasePortionFormat.setKerningMinimalSize را به مقداری به‌طور قابل توجهی بزرگ‌تر از اندازه واقعی فونت تنظیم کنید:

const presentation = new aspose.slides.Presentation("presentation.pptx");
try {
    const autoShape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);
    const paragraphs = autoShape.getTextFrame().getParagraphs();
    const paragraphCount = paragraphs.getCount();
    const targetFont = "Roboto";

    for (let paragraphIndex = 0; paragraphIndex < paragraphCount; paragraphIndex++) {
        const portions = paragraphs.get_Item(paragraphIndex).getPortions();
        const portionCount = portions.getCount();

        for (let portionIndex = 0; portionIndex < portionCount; portionIndex++) {
            const portion = portions.get_Item(portionIndex);
            const portionFormat = portion.getPortionFormat();
            const latinFont = portionFormat.getLatinFont();
            const eastAsianFont = portionFormat.getEastAsianFont();
            const complexScriptFont = portionFormat.getComplexScriptFont();

            if ((latinFont !== null && latinFont.getFontName() === targetFont) ||
                (eastAsianFont !== null && eastAsianFont.getFontName() === targetFont) ||
                (complexScriptFont !== null && complexScriptFont.getFontName() === targetFont)) {
                portionFormat.setKerningMinimalSize(100);
            }
        }
    }

    presentation.save("output.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

این تنظیم از اعمال کرنینگ به بخش‌های متنی منطبق جلوگیری می‌کند و می‌تواند به هم‌راستا شدن رندر Aspose.Slides با خروجی بصری PowerPoint برای فونت‌های تحت تأثیر این رفتار خاص کمک کند.

مدیریت ویژگی‌های قلم متن

ویژگی‌های قلم می‌توانند در سطح پاراگراف از طریق ParagraphFormat.getDefaultPortionFormat یا در بخش‌های جداگانه از طریق PortionFormat تنظیم شوند.

کد زیر قلم و سبک متن را برای تمام پاراگراف تنظیم می‌کند: اندازه قلم، بولد، ایتالیک، خط تحت نقطه‌ای و قلم Times New Roman را برای تمام بخش‌های پاراگراف اعمال می‌نماید.

const presentation = new aspose.slides.Presentation("sample.pptx");
try {
    const autoShape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);
    const paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
    const defaultPortionFormat = paragraph.getParagraphFormat().getDefaultPortionFormat();

    // تنظیم ویژگی‌های قلم برای پاراگراف.
    defaultPortionFormat.setFontHeight(12);
    defaultPortionFormat.setFontBold(java.newByte(aspose.slides.NullableBool.True));
    defaultPortionFormat.setFontItalic(java.newByte(aspose.slides.NullableBool.True));
    defaultPortionFormat.setFontUnderline(java.newByte(aspose.slides.TextUnderlineType.Dotted));
    defaultPortionFormat.setLatinFont(new aspose.slides.FontData("Times New Roman"));

    presentation.save("font_properties_for_paragraph.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

نتیجه:

ویژگی‌های قلم برای پاراگراف

کد زیر ویژگی‌های مشابه را برای بخش‌های متنی با قلم بولد اعمال می‌کند:

const presentation = new aspose.slides.Presentation("sample.pptx");
try {
    const autoShape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);
    const paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
    const portions = paragraph.getPortions();
    const portionCount = portions.getCount();

    for (let portionIndex = 0; portionIndex < portionCount; portionIndex++) {
        const portion = portions.get_Item(portionIndex);
        if (portion.getPortionFormat().getEffective().getFontBold()) {
            const portionFormat = portion.getPortionFormat();

            // تنظیم ویژگی‌های قلم برای بخش متن.
            portionFormat.setFontHeight(13);
            portionFormat.setFontItalic(java.newByte(aspose.slides.NullableBool.True));
            portionFormat.setFontUnderline(java.newByte(aspose.slides.TextUnderlineType.Dotted));
            portionFormat.setLatinFont(new aspose.slides.FontData("Times New Roman"));
        }
    }

    presentation.save("font_properties_for_text_portions.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

نتیجه:

ویژگی‌های قلم برای بخش‌های متنی

تنظیم چرخش متن

از TextFrameFormat.setTextVerticalType برای تنظیم جهت از پیش تعریف‌شده متن در یک شکل استفاده کنید.

کد زیر جهت متن در شکل را به Vertical270 تنظیم می‌کند که متن را ۹۰ درجه در جهت خلاف ساعت می‌چرخاند:

const presentation = new aspose.slides.Presentation("sample.pptx");
try {
    const autoShape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);

    autoShape.getTextFrame().getTextFrameFormat().setTextVerticalType(java.newByte(aspose.slides.TextVerticalType.Vertical270));

    presentation.save("text_rotation.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

نتیجه:

چرخش متن

تنظیم چرخش سفارشی برای فریم‌های متنی

از TextFrameFormat.setRotationAngle برای تنظیم زاویه چرخش سفارشی یک TextFrame استفاده کنید.

کد زیر فریم متن را به میزان ۳ درجه در جهت ساعت درون شکل می‌چرخاند:

const presentation = new aspose.slides.Presentation("sample.pptx");
try {
    const autoShape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);

    autoShape.getTextFrame().getTextFrameFormat().setRotationAngle(3);

    presentation.save("custom_text_rotation.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

نتیجه:

چرخش سفارشی متن

تنظیم فاصله‌گذاری خطوط پاراگراف‌ها

Aspose.Slides متدهای ParagraphFormat.setSpaceAfter، ParagraphFormat.setSpaceBefore و ParagraphFormat.setSpaceWithin را برای کنترل فاصله‌گذاری پاراگراف فراهم می‌کند. این ویژگی‌ها به‌صورت زیر استفاده می‌شوند:

  • برای تعیین فاصله‌گذاری به‌عنوان درصدی از ارتفاع خط، مقدار مثبت استفاده کنید.
  • برای تعیین فاصله‌گذاری به‌عنوان نقطه، مقدار منفی استفاده کنید.

کد زیر نشان می‌دهد چگونه فاصله‌گذاری خطوط را داخل پاراگراف مشخص کنید:

const presentation = new aspose.slides.Presentation("sample.pptx");
try {
    const autoShape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);
    const paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);

    paragraph.getParagraphFormat().setSpaceWithin(200);

    presentation.save("line_spacing.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

نتیجه:

فاصله‌گذاری خطوط داخل پاراگراف

تنظیم نوع Autofit برای فریم‌های متنی

متد TextFrameFormat.setAutofitType تعیین می‌کند که متن وقتی از مرزهای محفظه‌اش فراتر می‌رود چگونه رفتار کند. از آن برای کنترل اینکه آیا متن کوچک می‌شود، سرریز می‌شود یا به‌صورت خودکار اندازه شکل را تغییر می‌دهد، استفاده کنید.

const presentation = new aspose.slides.Presentation("sample.pptx");
try {
    const autoShape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);

    autoShape.getTextFrame().getTextFrameFormat().setAutofitType(java.newByte(aspose.slides.TextAutofitType.Shape));

    presentation.save("autofit_type.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

تنظیم لنگر فریم‌های متنی

متد TextFrameFormat.setAnchoringType تعیین می‌کند که متن به‌صورت عمودی داخل یک شکل چگونه موقعیت یابد، برای مثال در بالا، وسط یا پایین.

const presentation = new aspose.slides.Presentation("sample.pptx");
try {
    const autoShape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);

    autoShape.getTextFrame().getTextFrameFormat().setAnchoringType(java.newByte(aspose.slides.TextAnchorType.Bottom));

    presentation.save("text_anchor.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

تنظیم تب‌بندی متن

از ParagraphFormat.setDefaultTabSize و ParagraphFormat.getTabs برای پیکربندی ایست‌گاه‌های تب در یک پاراگراف استفاده کنید.

const presentation = new aspose.slides.Presentation("sample.pptx");
try {
    const autoShape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);
    const paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);

    paragraph.getParagraphFormat().setDefaultTabSize(100);
    paragraph.getParagraphFormat().getTabs().add(30, java.newByte(aspose.slides.TabAlignment.Left));

    presentation.save("paragraph_tabs.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

نتیجه:

تب‌های پاراگراف

تنظیم زبان تصحیح املایی

Aspose.Slides متد PortionFormat.setLanguageId را فراهم می‌کند که به شما اجازه می‌دهد زبان تصحیح املایی برای یک بخش متنی را تنظیم کنید. زبان تصحیح املایی تعیین می‌کند در PowerPoint برای املاء و گرامر چه زبانی استفاده شود.

کد زیر نشان می‌دهد چگونه زبان تصحیح املایی برای یک بخش متنی تنظیم شود:

const presentation = new aspose.slides.Presentation("presentation.pptx");
try {
    const autoShape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);
    const paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
    paragraph.getPortions().clear();

    const font = new aspose.slides.FontData("SimSun");
    const textPortion = new aspose.slides.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", aspose.slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

تنظیم زبان پیش‌فرض

از LoadOptions.setDefaultTextLanguage برای تعریف زبان پیش‌فرض متنی که در هنگام بارگذاری یا ایجاد یک ارائه تولید می‌شود، استفاده کنید.

const loadOptions = new aspose.slides.LoadOptions();
loadOptions.setDefaultTextLanguage("en-US");

const presentation = new aspose.slides.Presentation(loadOptions);
try {
    const slide = presentation.getSlides().get_Item(0);

    // یک شکل مستطیل جدید با متن اضافه کنید.
    const shape = slide.getShapes().addAutoShape(aspose.slides.ShapeType.Rectangle, 20, 20, 150, 50);
    shape.getTextFrame().setText("Sample text");

    // زبان اولین بخش را بررسی کنید.
    const portion = shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0);
    console.log(portion.getPortionFormat().getLanguageId());
} finally {
    presentation.dispose();
}

تنظیم سبک متن پیش‌فرض

برای اعمال قالب‌بندی پیش‌فرض متن در سطح ارائه، از Presentation.getDefaultTextStyle استفاده کنید.

کد زیر نشان می‌دهد چگونه یک قلم بولد با اندازه ۱۴ پوینت به‌صورت پیش‌فرض برای تمام متن‌های اسلایدها در یک ارائه جدید تنظیم شود.

const presentation = new aspose.slides.Presentation();
try {
    // دریافت فرمت پاراگراف سطح بالا.
    const paragraphFormat = presentation.getDefaultTextStyle().getLevel(0);

    if (paragraphFormat !== null) {
        paragraphFormat.getDefaultPortionFormat().setFontHeight(14);
        paragraphFormat.getDefaultPortionFormat().setFontBold(java.newByte(aspose.slides.NullableBool.True));
    }

    presentation.save("default_text_style.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

استخراج متن با اثر تمام حروف بزرگ (All‑Caps)

در PowerPoint، اعمال اثر All Caps بر قلم باعث می‌شود متن روی اسلاید به صورت حروف بزرگ نمایش داده شود حتی اگر به‌صورت حروف کوچک تایپ شده باشد. هنگام دریافت چنین بخشی از متن با Aspose.Slides، کتابخانه متن دقیقاً همان‌گونه که وارد شده است برمی‌گرداند. برای هم‌خوانی با متن نمایش داده‌شده، TextCapType را بررسی کنید و هنگامی که مقدار All باشد، رشته برگردانده‌شده را به حروف بزرگ تبدیل کنید.

فرض کنید جعبه متنی زیر در اسلاید اول فایل sample2.pptx موجود است.

اثر All Caps

کد زیر نشان می‌دهد چگونه متنی که اثر All Caps روی آن اعمال شده است را استخراج کنید:

const presentation = new aspose.slides.Presentation("sample2.pptx");
try {
    const autoShape = presentation.getSlides().get_Item(0).getShapes().get_Item(0);
    const textPortion = autoShape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0);

    console.log("Original text: " + textPortion.getText());

    const textFormat = textPortion.getPortionFormat().getEffective();
    if (textFormat.getTextCapType() === aspose.slides.TextCapType.All) {
        const text = textPortion.getText().toUpperCase();
        console.log("All-Caps effect: " + text);
    }
} finally {
    presentation.dispose();
}

خروجی:

Original text: Hello, Aspose!
All-Caps effect: HELLO, ASPOSE!

سوالات متداول

چگونه متن داخل جدول در یک اسلاید را ویرایش کنیم؟

برای ویرایش متن داخل جدول در یک اسلاید، از Table استفاده کنید. سلول‌ها را پیمایش کنید و هر سلول را از طریق Cell.getTextFrame و قالب‌بندی پاراگراف‌ها از طریق Paragraph.getParagraphFormat به‌روزرسانی کنید.

چگونه رنگ گرادیان را به متن در یک اسلاید PowerPoint اعمال کنیم؟

برای اعمال رنگ گرادیان به متن، از PortionFormat.getFillFormat استفاده کنید. مقدار FillFormat.setFillType را به FillType.Gradient تنظیم کنید و ایست‌گاه‌های گرادیان، جهت و شفافیت را پیکربندی کنید.