Print Page | Close Window

Adding unicode text

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=3646
Printed Date: 29 Apr 24 at 3:42PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Adding unicode text
Posted By: kkesslau
Subject: Adding unicode text
Date Posted: 10 Dec 18 at 2:04PM
Hi,

i wanted to ask if there is a better way to add/use unicode text then what is presented here: http://www.quickpdf.org/forum/drawing-unicode-text_topic2090.html%20" rel="nofollow - http://www.quickpdf.org/forum/drawing-unicode-text_topic2090.html

I'm working with Delphi 10.2.3 and the DebenuPDFLibrary1411-Library.

Currently i'm using the AddUnicodeFont-Method, but it seems that this method is not fully functional or tested, because after calling DrawText there are temporary-ttf files in the AppData/Local/Temp-folder (on Windows). If i create a PDF with a lot of texts, then for every text there is such a file created. And this happends everytime (i have a workaround to manually detect and delete this files after the PDF is saved, there are named like "QuickPDFTempFontXXXXXXXXX.ttf").
Example code:
text := 'Hello World';
fontId := PdfLibrary.AddUnicodeFont(aFont, 0, 0);  //aFont is for example 'Arial'
PdfLibrary.SelectFont(fontId);
PdfLibrary.DrawText(startP.X, startP.Y, text);

I did some testing with the AddTrueTypeFont-method with explicit setting of the codepage, but this in my use-case the wrong method because i don't want to have to check everytime in which location the user is corrently working to manually set the codepage.

If anybody can point me in the right direction to handle unicode texts would help me a lot.

Thanks in advance,
Kevin




Replies:
Posted By: Ingo
Date Posted: 10 Dec 18 at 5:55PM
Hi Kevin,

in my opinion this won't matter you.
You put in "Hello World" with european characters.
If anybody will read it in India he'll see "Hello World".
If an indian guy will create a pdf perhaps it will be urdu and you'll see "Hello World" in Urdu language.
The only point you should have an eye on is if you're working with the dll-version of QuickPDF using an old ide like vb6 or vba.
In this case you have to convert all strings to and from unicode - that's all.

Cheers and welcome here,
Ingo



-------------
Cheers,
Ingo



Posted By: tfrost
Date Posted: 10 Dec 18 at 6:02PM
I have not used this function a lot, but from the way I read it the code page is optional for AddTrueTypeFont, and I have never set one.  If you pass a Unicode wide string to the 'draw' function in use with the font, the Unicode characters you pass will all be displayed if they have glyphs in the font.  

Once you have the characters you want to place on the PDF in a Unicode string, you only need to select a suitable TrueType font to display them. You may of course need to use different Unicode fonts depending on what languages your user needs, especially Asian ones, but you still do not need to specify a code page for the font.

AddUnicodeFont is shown as 'experimental' and so I would probably not consider using it, but it seems that (by implication) the standard function does not support Unicode above plane 0.  I have just verified this by trying to display a smiley (U1F600) using a Unicode font loaded with AddTrueTypeFont which I know contains this character.  So unless you need characters like Linear B or Emoji you should be fine with using AddTrueTypeFont - I suggest you try it and ask back here in case another user knows more about all this!



Posted By: kkesslau
Date Posted: 11 Dec 18 at 9:01AM
First thanks for your replies Smile

I did again some testing with the AddTrueTypeFont-method but it doesn't display all the characters in my test texts. Here there are, just Hello World in different languages, but all languages are supported by our software (we make a timberwood-cad-construction software):

Hello World! (english)
مرحبا بالعالم! (arabic)
Γεια σου κόσμο! (greek)
Hello дүйнөнү! (kirghiz)
Pozdrav svijetu! (croatian)
Witaj, świecie! (polish)
Привет мир! (russian)
Dobrý deň svet! (slovakin)
Dobrý den svět! (czech)
שלום עולם! (hebrew)
ěěěěĚĚĚĚššššŠŠŠŠččččČČČČřřřřŘŘŘŘžžžžŽŽŽŽýýýýÝÝÝÝááááÁÁÁÁííííÍÍÍÍééééÉÉÉÉÉúúúúÚÚÚÚůůůůŮŮŮŮ

The last one was the text a customer send to us which showed us the missing characters. It is in czech (i think).
Our software is only available on Windows, so I pass as the font-parameter in AddTrueTypeFont just 'Arial' or 'Verdana' for example. Our software displays all texts correct because of our use of FreeType. We are just working with the fonts found in the Windows/Fonts-folder. Also in Microsoft Word all texts are displayed correctly.

But when I create a PDF from our Software with AddTrueTypeFont and pass these test-strings (in Delphi strings are unicode-strings), some of them are not displayed. As a font I used 'Arial'.
The following links are the output from AddTrueTypeFont and AddUnicodeFont:
http://ibb.co/sQTLMdN" rel="nofollow - https://ibb.co/sQTLMdN
http://ibb.co/cvqp5Gk" rel="nofollow - https://ibb.co/cvqp5Gk



Posted By: Ingo
Date Posted: 11 Dec 18 at 9:21AM
Hi Kevin,

instead of using the normal Arial you should use "Arial Unicode MS".
You need the unicode variants of the common truetype fonts.
Verdana doesn't support all unicode characters.
Helvetica doesn't support unicode but there are "helvetica-like" fonts for unicode...
You'll find many online ressources regarding this subject.




-------------
Cheers,
Ingo



Posted By: tfrost
Date Posted: 11 Dec 18 at 9:49AM
You should be aware that Windows, so also Microsoft Word, takes a specific font request merely as a preference. It is capable of quietly substituting your requested font for another one, if it does not have the one you ask for or if it will not display the characters you want to show.  This can be quite annoying at times, though it is good for most users.  But it is generally helpful that QPDF respects your choice, even if you have, as Ingo points out, asked for a font which does not support Unicode well.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk