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);
}
De-serializing a wxFont for a pdf file fails.
De-serializing a wxFont for a pdf file fails.
Last edited by dkaip on Mon Jun 25, 2018 10:17 am, edited 3 times in total.
Re: De-serializing a wxFont for a pdf file fails.
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 have serialize a font as wxString and then de-serializing with wxFromString,
Please explain "nothing happens". What do you expect to happen?dkaip wrote:i am trying to register and set font for pdf document, but nothing happens. What i am doing wrong?
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.dkaip wrote:Code: Select all
if(!font.IsNull()) { wxFont f; wxFromString(font,&f); wxPdfFontManager* fm = wxPdfFontManager::GetFontManager(); fm->RegisterFont(font); aPDFfile.SetFont(f); }
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
Re: De-serializing a wxFont for a pdf file fails.
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
Thank you
Jim
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);
Jim
Re: De-serializing a wxFont for a pdf file fails.
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:In code below i take ...
wxPdfFontManagerBase::RegisterFont: Font file 'Sans 40' does not exist or is not readable.
Yes, this works, because method SetFont will register the font implicitly if it isn't registered yet.dkaip wrote:But then shows wxMessageBox("aaaa");, that means SetFont(f) returns true.
Replacedkaip 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);
Code: Select all
fm->RegisterFont(font);
Code: Select all
fm->RegisterFont(f);
Regards,
Ulrich