But in Libre Office appears ok. What i must do?
Code: Select all
pdf.AddPage(wxPORTRAIT,wxPAPER_A4);
pdf.SetFont(wxS("Times"),wxS("B"),16);
pdf.Cell(40,10,wxS("Hello World!"));
pdf.Cell(40,10,wxS("Στὸν ἱστοχῶρο αὐτὸν ..."));
Code: Select all
pdf.AddPage(wxPORTRAIT,wxPAPER_A4);
pdf.SetFont(wxS("Times"),wxS("B"),16);
pdf.Cell(40,10,wxS("Hello World!"));
pdf.Cell(40,10,wxS("Στὸν ἱστοχῶρο αὐτὸν ..."));
When you have Unicode resp Non-ASCII characters in the source code of your application, all depends on the encoding of your source code files. If you take care of that your source files are all encoded in UTF-8 encoding, then the code below would work ... if the selected font would support the requested characters. The problem here is that the PDF core font Times does not contain Greek characters.dkaip wrote:Hello. In Code bellow, adding unicode chars to pdf page with wxpdfdoc lib, the unicode chars appears as ??????
But in Libre Office appears ok. What i must do?
Code: Select all
pdf.AddPage(wxPORTRAIT,wxPAPER_A4);
pdf.SetFont(wxS("Times"),wxS("B"),16);
pdf.Cell(40,10,wxS("Hello World!"));
pdf.Cell(40,10,wxString::FromUTF8("Στὸν ἱστοχῶρο αὐτὸν ...");
Code: Select all
pdf.AddPage(wxPORTRAIT,wxPAPER_A4);
wxFont fontTimes(16, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, _T("Times"), wxFONTENCODING_DEFAULT);
wxPdfFontManager* fntMngr = wxPdfFontManager::GetFontManager();
fntMngr->RegisterFont(fontTimes);
pdf.SetFont(wxS("Times"),wxS("B"),16);
pdf.Cell(40,10,wxS("Hello World!"));
pdf.Cell(40,10,wxS("Στὸν ἱστοχῶρο αὐτὸν ..."));
The PDF format supports a number of so-called core fonts - Helvetica, Times Roman, Courier, and Symbol. These fonts can always be used to create PDF documents with wxPdfDocument without explicitly registering them. The font Helvetica is identical to Arial. Therefore Arial is an alias for Helvetica in wxPdfDocument. However, the PDF core fonts do not contain Greek characters - except for the Symbol font.dkaip wrote:On my computer I do not have the font Helvetica, but the program prints "Hello world" normally, and no print Greek text.
Sorry, no idea why that is so for your application.dkaip wrote:In Times that exist does not print "Hello world".
Installing the DejaVu fonts on your system is not enough. You have to register the font(s) for wxPdfDocument. You should use method wxPdfFontManager::GetFontManager()->RegisterFont to do this (see sample tutorial7 for an example).dkaip wrote:I installed Dejavu font and it does not print either the "Hello world" or the Greek text.
Code: Select all
wxFont fontTahoma("/home/a/.fonts/tahomabd.ttf");
wxPdfFontManager* fntTahoma = wxPdfFontManager::GetFontManager();
fntTahoma->RegisterFont(fontTahoma,_T("Tahoma"));
pdf.SetFont(wxS("Tahoma"),wxS(""),16);
pdf.Cell(40,10,wxS("Hello World!"));
pdf.Cell(40,10,wxS("Στὸν ἱστοχῶρο αὐτὸν ..."));
Also if i try...wxFont fontTahoma;
wxPdfFontManager* fntTahoma = wxPdfFontManager::GetFontManager();
fntTahoma->RegisterFont(fontTahoma,_T("Tahoma"));
Code: Select all
wxFont fontTahoma(16, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, _T("Tahoma132432"), wxFONTENCODING_DEFAULT);
wxPdfFontManager* fntTahoma = wxPdfFontManager::GetFontManager();
fntTahoma->RegisterFont(fontTahoma,_T("Tahoma"));
pdf.SetFont(wxS("Tahoma"),wxS(""),16);
pdf.Cell(40,10,wxS("Hello World!"));
pdf.Cell(40,10,wxS("Στὸν ἱστοχῶρο αὐτὸν ..."));
From your description it's not totally clear unfortunately, what your problem is.dkaip wrote:If i want to use for example Tahoma, that has all Unicode chars i want, how i choose font?
Great, i just did it.
Tahoma have family ... Tahoma, when open file tahomabd.ttf with Fontforge.
Trying wxFont fontTahoma(16, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, _T("Tahoma"), wxFONTENCODING_DEFAULT); i did nothing.
Well, if you know the font family and style, then create a wxFont instance using these font attributes and register it for use with wxPdfDocument by calling the RegisterFont method of the wxPdfFontManager.dkaip wrote:But if i want not to link to a certain font file, how i can choose it from OS with current settings automaticaly?
How i can know the FONTFAMILY and FONTSTYLE etc?
Suppose i must use wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL and wxFONTWEIGHT_NORMAL?