podofo / podofo

A C++17 PDF manipulation library

Home Page:https://podofo.github.io/podofo/documentation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to add text in PDF with UCS4: 8800 (0x2260), for example

igormironchik opened this issue · comments

  • I'm submitting a:

    • Vulnerability report -> use the specific form instead!
    • Bug report
    • Feature request/suggestion
  • [Bug report] What is the current behavior?

    I'm unable to add to PDF file some characters from Droid Serif font (attached). These characters are in the font. For example, I try to add ≠ symbol (UCS4: 8800 (0x2260), UTF8: \xE2\x89\xA0).

    What I do:

    PdfPainter p ...
    
    p.TextObject.Begin();
    p.TextObject.MoveTo( x, y );
    p.TextState.SetFont( font, 8.0 );
    p.TextState.SetFontScale( 1.0 );
    const QByteArray utf8 = qstring.toUtf8();
    p.TextObject.AddText( utf8.data() /* const char * here */ );
    p.TextObject.End();

    I don't receive any exceptions here, but in PDF on place of ≠ symbol is empty space.

    What's wrong?

  • [Bug report] What is the expected behavior?

    I'd like to see in generated PDF ≠ symbol as well.

  • Please tell us about your environment:

    • Version/git revision: [0.10.3]
    • Operating System: [Linux (64 bits)]
    • Package manager used: [source]
  • [Bug report/Feature request] Other information

    droid_serif.zip
    1.pdf

This worked for me in C++17 compilation with master (currently it's 0.11-dev):

    PdfMemDocument document;
    PdfPainter painter;
    auto& page = document.GetPages().CreatePage(PdfPage::CreateStandardPageSize(PdfPageSize::A4));
    painter.SetCanvas(page);
    auto& font = document.GetFonts().GetOrCreateFont(R"(D:\Downloads\droid_serif\droid_serif.ttf)");
    painter.TextState.SetFont(font, 18);

    painter.TextObject.Begin();
    painter.TextObject.MoveTo(56.69, page.GetRect().Height - 56.69);
    painter.TextState.SetFont(font, 12);
    painter.TextState.SetFontScale(1.0);
    painter.TextObject.AddText(u8"\u2260"); // Or painter.TextObject.AddText("\342\211\240"), it's the same
    painter.TextObject.End();
    painter.FinishDrawing();
    document.Save(R"(D:\test.pdf)");

And produces test.pdf. Can you test both 0.10.3 and 0.11-dev with that snippet in your machine?

Got it. My issue. Sorry for your time.