C++ में टेक्स्ट को फ़ॉर्मेट कैसे करें

C++ में टेक्स्ट को फ़ॉर्मेट कैसे करें

Aspose.Slides FOSS for C++ PortionFormat क्लास के माध्यम से सूक्ष्म-स्तरीय टेक्स्ट फ़ॉर्मेटिंग प्रदान करता है। Portion टेक्स्ट की सबसे छोटी स्वतंत्र इकाई है; यह पैराग्राफ के भीतर एकल फ़ॉर्मेटिंग रन से मेल खाती है। यह गाइड प्रस्तुति में टेक्स्ट पर बोल्ड, इटैलिक, फ़ॉन्ट आकार और रंग फ़ॉर्मेटिंग कैसे लागू करें, यह दर्शाता है।

चरण-दर-चरण गाइड

चरण 1: लाइब्रेरी बनाएं और लिंक करें

git clone https://github.com/aspose-slides-foss/Aspose.Slides-FOSS-for-Cpp.git
cd Aspose.Slides-FOSS-for-Cpp && mkdir build && cd build
cmake .. && cmake --build .

चरण 2: टेक्स्ट फ्रेम के साथ एक आकार जोड़ें

टेक्स्ट को फ़ॉर्मेट करने से पहले, एक आकार जोड़ें और उसके टेक्स्ट कंटेंट को shape.text_frame()->set_text() के माध्यम से सेट करें।

#include <Aspose/Slides/Foss/presentation.h>

int main() {
    namespace asf = Aspose::Slides::Foss;

    asf::Presentation prs;
    auto& slide = prs.slides()[0];
    auto& shape = slide.shapes().add_auto_shape(
        asf::ShapeType::RECTANGLE, 50, 50, 500, 150);
    shape.text_frame()->set_text("Default text: will be formatted");
    prs.save("output.pptx", asf::SaveFormat::PPTX);
    return 0;
}

चरण 3: टेक्स्टफ़्रेम तक पहुँचें

shape.text_frame() शैप के TextFrame के लिए एक पॉइंटर लौटाता है। -> का उपयोग करके उस पर मेथड्स को कॉल करें।

auto* tf = shape.text_frame();          // pointer to the shape's text frame
tf->set_text("your text here");

एक TextFrame में Paragraph वस्तुएँ (tf->paragraphs()) होती हैं। प्रत्येक Paragraph में Portion वस्तुएँ (paragraph.portions()) होती हैं।


चरण 4: बोल्ड और इटैलिक फ़ॉर्मेटिंग लागू करें

portion_format().set_font_bold() और portion_format().set_font_italic() का उपयोग करें। ये विधियाँ NullableBool::TRUE, NullableBool::FALSE, या NullableBool::NOT_DEFINED (मास्टर से विरासत में) को स्वीकार करती हैं।

#include <Aspose/Slides/Foss/presentation.h>

int main() {
    namespace asf = Aspose::Slides::Foss;

    asf::Presentation prs;
    auto& slide = prs.slides()[0];
    auto& shape = slide.shapes().add_auto_shape(
        asf::ShapeType::RECTANGLE, 50, 50, 500, 150);
    shape.text_frame()->set_text("Bold and italic text");
    auto* tf = shape.text_frame();

    auto& fmt = tf->paragraphs()[0].portions()[0].portion_format();
    fmt.set_font_bold(asf::NullableBool::TRUE);
    fmt.set_font_italic(asf::NullableBool::TRUE);

    prs.save("bold-italic.pptx", asf::SaveFormat::PPTX);
    return 0;
}

चरण 5: फ़ॉन्ट आकार और रंग सेट करें

आकार (पॉइंट्स में) के लिए portion_format().set_font_height() सेट करें और रंग के लिए fill_format() का उपयोग करें।

#include <Aspose/Slides/Foss/presentation.h>

int main() {
    namespace asf = Aspose::Slides::Foss;

    asf::Presentation prs;
    auto& slide = prs.slides()[0];
    auto& shape = slide.shapes().add_auto_shape(
        asf::ShapeType::RECTANGLE, 50, 50, 500, 150);
    shape.text_frame()->set_text("Large corporate-blue heading");
    auto* tf = shape.text_frame();

    auto& fmt = tf->paragraphs()[0].portions()[0].portion_format();
    fmt.set_font_height(32);                               // 32pt font
    fmt.set_font_bold(asf::NullableBool::TRUE);
    fmt.fill_format().set_fill_type(asf::FillType::SOLID);
    fmt.fill_format().solid_fill_color().set_color(
        asf::Color::from_argb(255, 0, 70, 127));

    prs.save("colored-text.pptx", asf::SaveFormat::PPTX);
    return 0;
}

Color::from_argb(alpha, red, green, blue) प्रत्येक चैनल के लिए 0-255 मान स्वीकार करता है।


चरण 6: एक पैराग्राफ में कई भाग

एक पैराग्राफ में विभिन्न स्वरूपण वाले कई भाग हो सकते हैं। एक नया Portion पैराग्राफ के portions() संग्रह में जोड़ें:

#include <Aspose/Slides/Foss/presentation.h>

int main() {
    namespace asf = Aspose::Slides::Foss;

    asf::Presentation prs;
    auto& slide = prs.slides()[0];
    auto& shape = slide.shapes().add_auto_shape(
        asf::ShapeType::RECTANGLE, 50, 50, 600, 100);
    shape.text_frame()->set_text(""); // start with empty text
    auto* tf = shape.text_frame();

    auto& paragraph = tf->paragraphs()[0];

    // First portion: normal text
    auto& portion1 = paragraph.portions()[0];
    portion1.set_text("Normal text followed by ");
    portion1.portion_format().set_font_height(20);

    // Second portion: bold red text
    asf::Portion portion2;
    portion2.set_text("bold red text");
    portion2.portion_format().set_font_height(20);
    portion2.portion_format().set_font_bold(asf::NullableBool::TRUE);
    portion2.portion_format().fill_format().set_fill_type(asf::FillType::SOLID);
    portion2.portion_format().fill_format().solid_fill_color().set_color(
        asf::Color::from_argb(255, 200, 0, 0));
    paragraph.portions().add(portion2);

    prs.save("mixed-format.pptx", asf::SaveFormat::PPTX);
    return 0;
}

सामान्य समस्याएँ और समाधान

रंग सेट करने के बाद भी टेक्स्ट काला दिखता है

रंग असाइन करने से पहले सुनिश्चित करें कि fill_format().set_fill_type(FillType::SOLID) सेट हो। फ़िल टाइप सेट किए बिना, रंग परिवर्तन का कोई प्रभाव नहीं हो सकता।

NullableBool::TRUE वर्सस true

portion_format().set_font_bold() अपेक्षा करता है NullableBool::TRUE, न कि C++ truetrue को सीधे पास करने से कंपाइल नहीं होगा या ओवरलोड रिज़ॉल्यूशन पर निर्भर करते हुए अनिर्धारित व्यवहार हो सकता है।

फ़ॉन्ट सहेजी गई फ़ाइल में नहीं दिखता

set_latin_font() विधि लैटिन फ़ॉन्ट फ़ैमिली सेट करती है। यदि सेट नहीं किया गया है, तो प्रस्तुति थीम फ़ॉन्ट का उपयोग किया जाता है। कस्टम फ़ॉन्ट्स को एम्बेड किया जाना चाहिए या दर्शक मशीन पर उपलब्ध होना चाहिए।


अक्सर पूछे जाने वाले प्रश्न

फ़ॉन्ट फ़ैमिली कैसे बदलें?

सेट portion_format().set_latin_font():

fmt.set_latin_font(asf::FontData("Arial"));

FontData font family name को स्ट्रिंग के रूप में स्वीकार करता है।

मैं पैराग्राफ संरेखण कैसे सेट करूँ?

उपयोग करें paragraph_format().set_alignment():

tf.paragraphs()[0].paragraph_format().set_alignment(asf::TextAlignment::CENTER);

समर्थित मान: LEFT, CENTER, RIGHT, JUSTIFY.

मैं लाइन स्पेसिंग कैसे सेट करूँ?

paragraph_format().set_space_before() (पैराग्राफ से पहले बिंदु) या paragraph_format().set_space_after() (पैराग्राफ के बाद बिंदु) का उपयोग करें:

tf.paragraphs()[0].paragraph_format().set_space_before(12); // 12pt before
tf.paragraphs()[0].paragraph_format().set_space_after(6);   // 6pt after

संबंधित देखें

 हिन्दी