De-serializing a wxFont for a pdf file fails.

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
dkaip
I live to help wx-kind
I live to help wx-kind
Posts: 170
Joined: Wed Jan 20, 2010 1:15 pm

De-serializing a wxFont for a pdf file fails.

Postby dkaip » Sun Jun 24, 2018 7:02 pm

Hi, "nothing happens" means that in pdf page file the text have the default fonts, not the chosen fonts.
I have serialize a font as wxString and then de-serializing with wxFromString, i am trying to register and set font for pdf document, but nothing happens. What i am doing wrong?
Thank's
Jim

if(!font.IsNull())
{
wxFont f;
wxFromString(font,&f);
wxPdfFontManager* fm = wxPdfFontManager::GetFontManager();
fm->RegisterFont(font);
aPDFfile.SetFont(f);
}
Last edited by dkaip on Mon Jun 25, 2018 10:17 am, edited 3 times in total.

utelle
Moderator
Moderator
Posts: 808
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: De-serializing a wxFont for a pdf file fails.

Postby utelle » Mon Jun 25, 2018 7:29 am

dkaip wrote:I have serialize a font as wxString and then de-serializing with wxFromString,

Have you tested and verified that you get the same font on deserializing to a wxFont instance as the one you used to serialize?

dkaip wrote:i am trying to register and set font for pdf document, but nothing happens. What i am doing wrong?

Please explain "nothing happens". What do you expect to happen?

dkaip wrote:

Code: Select all

    if(!font.IsNull())
    {
        wxFont f;
        wxFromString(font,&f);
        wxPdfFontManager* fm = wxPdfFontManager::GetFontManager();
        fm->RegisterFont(font);
        aPDFfile.SetFont(f);
    }


In your code snippet you don't use the font f to write any text to the resulting PDF. To actually "see" anything in the PDF you have to add a page first, and then to add some text.

Have you tested that font f was correctly initialized? Do you get any warning/error from wxPdfDocument? Method SetFont returns a boolean value telling you whether setting the font succeeded or not. Please check the return value of SetFont.

Regards,

Ulrich

dkaip
I live to help wx-kind
I live to help wx-kind
Posts: 170
Joined: Wed Jan 20, 2010 1:15 pm

Re: De-serializing a wxFont for a pdf file fails.

Postby dkaip » Mon Jun 25, 2018 10:12 am

In code below i take ...
wxPdfFontManagerBase::RegisterFont: Font file 'Sans 40' does not exist or is not readable.
But then shows wxMessageBox("aaaa");, that means SetFont(f) returns true.
Sans 40 exists in my linux system, that i have take from with

Code: Select all

 wxFontData data;
wxFontDialog fnt(this, data);
if ( fnt.ShowModal() != wxID_OK )return;
data = fnt.GetFontData();
font=wxToString(data.GetChosenFont());
---------------
if(!font.IsNull())
    {
        wxFont f;
        wxFromString(font,&f);
        wxPdfFontManager* fm = wxPdfFontManager::GetFontManager();
        fm->RegisterFont(font);
        if(aPDFfile.SetFont(f))wxMessageBox("aaaa");
    }
aPDFfile.PrintChapter(MyText);


Thank you
Jim

utelle
Moderator
Moderator
Posts: 808
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: De-serializing a wxFont for a pdf file fails.

Postby utelle » Mon Jun 25, 2018 3:33 pm

dkaip wrote:In code below i take ...
wxPdfFontManagerBase::RegisterFont: Font file 'Sans 40' does not exist or is not readable.

This can't work. Method RegisterFont expects the name of a font file or a wxFont object. You should use your wxFont object f to register the font.

dkaip wrote:But then shows wxMessageBox("aaaa");, that means SetFont(f) returns true.

Yes, this works, because method SetFont will register the font implicitly if it isn't registered yet.

dkaip wrote:Sans 40 exists in my linux system, that i have take from with

Code: Select all

 wxFontData data;
wxFontDialog fnt(this, data);
if ( fnt.ShowModal() != wxID_OK )return;
data = fnt.GetFontData();
font=wxToString(data.GetChosenFont());
---------------
if(!font.IsNull())
    {
        wxFont f;
        wxFromString(font,&f);
        wxPdfFontManager* fm = wxPdfFontManager::GetFontManager();
        fm->RegisterFont(font);
        if(aPDFfile.SetFont(f))wxMessageBox("aaaa");
    }
aPDFfile.PrintChapter(MyText);

Replace

Code: Select all

fm->RegisterFont(font);

by

Code: Select all

fm->RegisterFont(f);

and your code should work as expected.


Regards,

Ulrich


Return to “wxCode”

Who is online

Users browsing this forum: No registered users and 0 guests