wxPdfDocument wich fonts can I use? Topic is solved

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
User avatar
cutecode
Super wx Problem Solver
Super wx Problem Solver
Posts: 425
Joined: Fri Dec 09, 2016 7:28 am
Contact:

wxPdfDocument wich fonts can I use?

Post 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
wx 3.1.6 win/mac/linux

regards,
Alexander Saprykin
https://v2.dental-soft.ru
Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 357
Joined: Tue Jun 07, 2016 1:07 pm

Re: wxPdfDocument wich fonts can I use?

Post 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.
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPdfDocument wich fonts can I use?

Post 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
User avatar
cutecode
Super wx Problem Solver
Super wx Problem Solver
Posts: 425
Joined: Fri Dec 09, 2016 7:28 am
Contact:

Re: wxPdfDocument wich fonts can I use?

Post 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);
    	}
wx 3.1.6 win/mac/linux

regards,
Alexander Saprykin
https://v2.dental-soft.ru
User avatar
cutecode
Super wx Problem Solver
Super wx Problem Solver
Posts: 425
Joined: Fri Dec 09, 2016 7:28 am
Contact:

Re: wxPdfDocument wich fonts can I use?

Post 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""
wx 3.1.6 win/mac/linux

regards,
Alexander Saprykin
https://v2.dental-soft.ru
User avatar
cutecode
Super wx Problem Solver
Super wx Problem Solver
Posts: 425
Joined: Fri Dec 09, 2016 7:28 am
Contact:

Re: wxPdfDocument wich fonts can I use?

Post 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.
Attachments
1.png
1.png (32.01 KiB) Viewed 17328 times
wx 3.1.6 win/mac/linux

regards,
Alexander Saprykin
https://v2.dental-soft.ru
User avatar
cutecode
Super wx Problem Solver
Super wx Problem Solver
Posts: 425
Joined: Fri Dec 09, 2016 7:28 am
Contact:

Re: wxPdfDocument wich fonts can I use?

Post by cutecode »

I changed my code to

Code: Select all

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

THANK YOU
wx 3.1.6 win/mac/linux

regards,
Alexander Saprykin
https://v2.dental-soft.ru
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPdfDocument wich fonts can I use?

Post 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.
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPdfDocument wich fonts can I use?

Post 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
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPdfDocument wich fonts can I use?

Post 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.
Post Reply