簡體   English   中英

PoDoFo SetFontSize問題

[英]PoDoFo SetFontSize Issue

我在應用程序中包含了podofo。

設置:GUI Visual Studio 2017社區版C ++-14 Standard的Qt框架(我設置了這種語言,因為podofo仍在使用auto_ptr)。 Podofo是動態鏈接的。

標頭:pdf.hpp

namespace pdf {

struct customer {
    QString firstname;
    QString lastname;
    QString street;
    QString zip;
    QString city;

    QString customer_id = "";
    QString phone = "";
    QString mail = "";
};

struct company : public customer {
    QString cname;
    QString fax;
    QString uid;
    QString iban;
    QString bic;
    QString institute;
};

struct transaction {
    QString start_value;
    QString end_value;
    QString start_timestamp;
    QString end_timestamp;
};

struct Font {
    QString name;
    float size;
};

class pdf {
private:
    QString filename;
    float kwh_price;
    PoDoFo::PdfStreamedDocument document;
    customer stammdaten;
    company sender;
    transaction tx;
    //QString Font;
    Font font;

    QString last_error;
public:
    pdf(QString path);
    ~pdf();
    void setkWhPrice(float price);
    void createPage();
    void setFont(QString fname,float size);
    void setCustomer(QString firstname, QString lastname, QString street, QString zip, QString city, QString mail = "", QString phone = "", QString cid = "");
    void setSenderData(QString company, QString street, QString zip, QString city, QString uid, QString phone, QString fax, QString mail);
    //ERROR Functions
    QString getLastError();
};

char* UmauteString(QString str);

}

pdf.cpp

#include"pdf.hpp"
#include"header.hpp"

using namespace PoDoFo;


char* pdf::UmauteString(QString str) {
    char *result = new char[str.size()];
    uint i = 0;
    for (auto c : str) {
        if (c == 'Ä') result[i] = static_cast<unsigned char>(142);
        else
            if (c == 'ä') result[i] = static_cast<unsigned char>(132);
            else
                if (c == 'Ö') result[i] = static_cast<unsigned char>(153);
                else
                    if (c == 'ö') result[i] = static_cast<unsigned char>(148);
                    else
                        if (c == 'Ü') result[i] = static_cast<unsigned char>(154);
                        else
                            if (c == 'ü') result[i] = static_cast<unsigned char>(129);
                            else
                                if (c == 'ß') result[i] = static_cast<unsigned char>(225);
                                else result[i] = c.toLatin1();
        i++;
    }
    return result;
}

pdf::pdf::pdf(QString path) : document(path.toStdString().c_str()) {
    this->filename = path;
}

void pdf::pdf::setkWhPrice(float price) {
    this->kwh_price = price;
}

pdf::pdf::~pdf() {
    this->document.Close();
}

void pdf::pdf::createPage() {
    PdfPage *page;
    PdfPainter painter;
    PdfFont* pFont;
    page = document.CreatePage(PdfPage::CreateStandardPageSize(ePdfPageSize_A4));
    if (!page) {
        this->last_error = "PDF Page Invalid Handler";
        QMessageBox::warning(nullptr, "ERROR", "pdf::createPage(): Invalid PoDoFo::PdfPage Handler", QMessageBox::StandardButton::Ok);
        return;
    }
    painter.SetPage(page);

    pFont = document.CreateFont("Courier New");
    //Address Field
    pFont->SetFontSize((float)5); // <-- the issue

    painter.SetFont(pFont);
    std::string absender = sender.cname.toStdString() + " " + sender.street.toStdString() + " " + sender.zip.toStdString() + " " + sender.city.toStdString();
    PdfString str(absender.c_str());
    painter.DrawText(56.69, 700,str);
    painter.FinishPage();

}

QString pdf::pdf::getLastError() {
    return this->last_error;
}

void pdf::pdf::setFont(QString name, float size) {
    this->font.name = name;
    this->font.size = size;
}

void pdf::pdf::setCustomer(QString firstname, QString lastname, QString street, QString zip, QString city, QString mail , QString phone , QString cid ){
    auto d = &stammdaten;
    d->firstname = firstname;
    d->lastname = lastname;
    d->street = street;
    d->zip = zip;
    d->city = city;
    d->mail = mail;
    d->phone = phone;
    d->customer_id = cid;
}

void pdf::pdf::setSenderData(QString company, QString street, QString zip, QString city, QString uid, QString phone, QString fax, QString mail) {
    auto d = &this->sender;
    d->cname = company;
    d->street = street;
    d->zip = zip;
    d->city = city;
    d->uid = uid;
    d->phone = phone;
    d->fax = fax;
    d->mail = mail;
}

它除了pFont-> setFontSize()之外都有效! 如果將Font設置為500,它將拉伸文本。 如果將大小設置為0到12,則除了繪制文本外,將不執行任何操作。 大小無所謂,它們都具有相同的大小。

有誰能解決這個怪異的行為?

輸出看起來像這樣: https : //ibb.co/SPQkQYH

字體大小為50的輸出如下所示: 字體大小50

確定解決方案已清除。 似乎該dll只是很奇怪。 更改了Podofo的圖書館。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM