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

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

Aspose.Slides FOSS for C++ provides fine-grained text formatting through the PortionFormat class. A 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: TextFrame तक पहुँचें

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 vs true

portion_format().set_font_bold() की अपेक्षा करता है NullableBool::TRUE, C++ नहीं true. पास करना true सीधे तौर पर यह संकलित नहीं होगा या ओवरलोड समाधान के आधार पर अनिर्धारित व्यवहार हो सकता है।.

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

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


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

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

सेट portion_format().set_latin_font():

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

FontData फ़ॉन्ट फ़ैमिली नाम को स्ट्रिंग के रूप में स्वीकार करता है।.

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

उपयोग करें 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

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

 हिन्दी