Page 1 of 1

wxPdfDocument wich fonts can I use?

Posted: Fri Jul 12, 2019 2:48 pm
by cutecode
Hi.

With wxPdfDocument wich fonts can I use?

In my project wxPdfDocument does not know "Arial" font, I see only '?' signes.
But if I use 'Microsoft Sans Serif' font then PDF file looks as it expected.

I added font path to variable, but in sane

Code: Select all

    if(wxDirExists(fontPath))
        wxSetEnv(_T("WXPDF_FONTPATH"), fontPath);
    else
        wxMessageBox("Folder " + fontPath + L" does not exist");
As readme.md states

Code: Select all

In addition to the 14 standard Adobe fonts it is possible to use other Type1, TrueType
or OpenType fonts - with or without embedding them into the generated
document
Or should I insert Arial font in my project manually? Then how to do it?

Thank you

Re: wxPdfDocument wich fonts can I use?

Posted: Fri Jul 12, 2019 3:51 pm
by Kvaz1r
I copied font file into project directory and did so:

Code: Select all

pdf.AddFont("PT","",wxS("PTM55FT.ttf"));
pdf.SetFont(wxS("PT"),wxS(""),12);
'?' instead of text could be happened because font don't recognize unicode symbols.

Re: wxPdfDocument wich fonts can I use?

Posted: Fri Jul 12, 2019 4:27 pm
by utelle
cutecode wrote: Fri Jul 12, 2019 2:48 pm With wxPdfDocument wich fonts can I use?
wxPdfDocument supports the standard PDF fonts (Courier, Times Roman, Helvetica - each in 4 variants: normal/bold/italic/bold-italic; Symbol, and ZapfDingBats). Additionally fonts in the formats Type1, TrueType, and OpenType are supported. The fonts can be installed in your operating system, or can be provided explicitly by your application.
cutecode wrote: Fri Jul 12, 2019 2:48 pm In my project wxPdfDocument does not know "Arial" font, I see only '?' signes.
The standard Adobe/PDF fonts can be used without providing a font file and without embedding the font in the resulting PDF. Arial is used as a synonym for Helvetica, because the main font characteristics are identical. The problem with the standard fonts is that they do not fully support Unicode. For example, cyrillic characters are not part of the standard fonts. This could explain, why you see questionmarks instead of the expected characters.
cutecode wrote: Fri Jul 12, 2019 2:48 pm But if I use 'Microsoft Sans Serif' font then PDF file looks as it expected.
How did you use the font?
cutecode wrote: Fri Jul 12, 2019 2:48 pm I added font path to variable, but in sane

Code: Select all

    if(wxDirExists(fontPath))
        wxSetEnv(_T("WXPDF_FONTPATH"), fontPath);
    else
        wxMessageBox("Folder " + fontPath + L" does not exist");
Which font path did you use? Does the folder really contain the font files you intend to use?
cutecode wrote: Fri Jul 12, 2019 2:48 pm As readme.md states

Code: Select all

In addition to the 14 standard Adobe fonts it is possible to use other Type1, TrueType
or OpenType fonts - with or without embedding them into the generated document
Or should I insert Arial font in my project manually? Then how to do it?
Yes. Usually the font Arial is provided by the operating system. That is using the following code

Code: Select all

  wxPdfFontManager::GetFontManager()->RegisterSystemFonts();
allows you to use (almost) all fonts installed on your operating system.

Alternatively, you may use method wxPdfFontManager::GetFontManager()->RegisterFont to explicitly load only those fonts you actually want to use. For example, under Windows fonts files are usually located in directory "C:\Windows\Fonts".

Regards,

Ulrich

Re: wxPdfDocument wich fonts can I use?

Posted: Fri Jul 12, 2019 4:44 pm
by cutecode
The fonts foder does exist, I use fonts folder from source files, I'm I right?

I have my own GridControl, wich has a drwaing faunction

Code: Select all

void CGrid::OnPrint(wxDC* pDC, int nPage, wxRect* rectDraw)
Then I use wxPdfDC and send this pointer to my drwaing faunction

Code: Select all

    wxPrintData printData = *g_printData;
    printData.SetFilename(lpszFileName);

    wxPdfDC dc(printData);
    
    .....
    
	for (int nPage = 1; nPage <= nPages; nPage++)
	{
	        dc.StartPage();
		
		....
		
		OnPrint(&dc, nPage, &rec);
    	}

Re: wxPdfDocument wich fonts can I use?

Posted: Fri Jul 12, 2019 5:15 pm
by cutecode
Just looked at my code.
Sorry not "Microsoft Sans Serif", the font is viwed as excpected when I use "Times New Roman", not ""Microsoft Sans Serif""

Re: wxPdfDocument wich fonts can I use?

Posted: Fri Jul 12, 2019 6:33 pm
by cutecode
I added to my code

Code: Select all

wxPdfFontManager::GetFontManager()->RegisterSystemFonts();
And now all fonts are drawn without '?'-sign. The PDF looks right on Debian too.
but after that I have plenty of warnings that some fonts can't be loaded.

Re: wxPdfDocument wich fonts can I use?

Posted: Fri Jul 12, 2019 6:37 pm
by cutecode
I changed my code to

Code: Select all

    {
        wxLogNull h;
        wxPdfFontManager::GetFontManager()->RegisterSystemFonts();
    }
and warnings are gone

THANK YOU

Re: wxPdfDocument wich fonts can I use?

Posted: Fri Jul 12, 2019 8:39 pm
by utelle
cutecode wrote: Fri Jul 12, 2019 4:44 pm The fonts foder does exist, I use fonts folder from source files, I'm I right?
Installed fonts usually reside in some system folder. Where exactly, depends on the actual operating system. If your application uses specific fonts, it is usually the best approach to provide the required font files together with the application in an application specific folder.
cutecode wrote: Fri Jul 12, 2019 4:44 pm I have my own GridControl, wich has a drwaing faunction

Code: Select all

void CGrid::OnPrint(wxDC* pDC, int nPage, wxRect* rectDraw)
Then I use wxPdfDC and send this pointer to my drwaing faunction

Code: Select all

    wxPrintData printData = *g_printData;
    printData.SetFilename(lpszFileName);

    wxPdfDC dc(printData);
    
    .....
    
	for (int nPage = 1; nPage <= nPages; nPage++)
	{
	        dc.StartPage();
		
		....
		
		OnPrint(&dc, nPage, &rec);
    	}
If you use wxPdfDC to create PDF documents, explicitly registering fonts should usually not be necessary, because the fonts corresponding to fonts selected via wxFont objects will be implicitly registered automatically.

Re: wxPdfDocument wich fonts can I use?

Posted: Fri Jul 12, 2019 8:46 pm
by utelle
cutecode wrote: Fri Jul 12, 2019 6:33 pm I added to my code

Code: Select all

wxPdfFontManager::GetFontManager()->RegisterSystemFonts();
And now all fonts are drawn without '?'-sign. The PDF looks right on Debian too.
but after that I have plenty of warnings that some fonts can't be loaded.
The problem is that the installed system fonts include also bitmap fonts which can't be used by wxPdfDocument. The wxPdfFontManager emits warning messages, when it tries to register such a bitmap font.

When registering a single font file it is certainly useful to get a warning message on registering a font file that is not usable by wxPdfDocument. However, for method RegisterSystemFonts most likely it would be more appropriate to silently ignore unusable font files.

I will consider to adjust method RegisterSystemFonts accordingly.

Regards,

Ulrich

Re: wxPdfDocument wich fonts can I use?

Posted: Mon Jul 29, 2019 8:39 pm
by utelle
utelle wrote: Fri Jul 12, 2019 8:46 pm The problem is that the installed system fonts include also bitmap fonts which can't be used by wxPdfDocument. The wxPdfFontManager emits warning messages, when it tries to register such a bitmap font.

When registering a single font file it is certainly useful to get a warning message on registering a font file that is not usable by wxPdfDocument. However, for method RegisterSystemFonts most likely it would be more appropriate to silently ignore unusable font files.
The behaviour of method wxPdfFontManager::RegisterSystemFonts has been changed to suppress error messages under Windows (see commit 8d61b16) in the wxPdfDocument GitHub repository.