Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - Drawing unicode text
  FAQ FAQ  Forum Search   Register Register  Login Login

Drawing unicode text

 Post Reply Post Reply
Author
Message
ashmid View Drop Down
Beginner
Beginner


Joined: 06 Jan 12
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote ashmid Quote  Post ReplyReply Direct Link To This Post Topic: Drawing unicode text
    Posted: 06 Jan 12 at 9:20AM
I am currently evaluating the quickpdf library for purchase. Our primary work involves Hebrew texts, hence I began by experimenting with Quickpdf's ability to write Hebrew text within a PDF document. However, here I ran into a problem.
If I simply start by opening a file and calling DrawText with a Hebrew string, the string is not properly written to the file: viewing the file in Acrobat shows a blank screen. If I DrawText a string that is partially numbers and partially Hebrew letters, the numbers how but the Hebrew characters do not.
I tried adding a call to AddTrueTypeFont(), to specify the "Arial Unicode MS" font, which contains a fairly complete set of Hebrew codepoints. However, even with that call, and a subsequent call to select the font (both of which returned success), the Hebrew characters are still missing in the resulting PDF.
I did manage to successfully output Hebrew text by calling AddTrueTypeSubsettedFont(), and by providing it with the full Hebrew alphabet in quotes. However, I was then limited to that specific set of characters, and none of punctuation marks or numbers were output correctly. However, I don't want to be limited a specific set of characters; I want to be able to write out any unicode character.
I'm looking for a way to simply include a truetype font with all its relevant unicode codepoints (without necessarily embedding the font), and to then be able to write unicode text freely without having to create a font subset for each DrawText.  (I did try to feed AddTrueTypeSubsettedFont() a subset that included all ASCII characters and all characters in the Hebrew code page, but that didn't work either).
Any ideas?

Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Posted: 06 Jan 12 at 9:48AM
Hi!

Internally strings will be handled as unicode.
Up to library version 7.26 they were encoded as utf8.
Starting from 8.xx version they are encoded with utf16.
So if you wanna handle with unicode before input you
should use something like encodeUtf16 or for output
decodeUtf16.
Sorry... a pretty common answer but i think in this direction
you should search...
BTW: The searchfunction is here at the top right...
Give it a try ;-)

Cheers and welcome here,
Ingo

Back to Top
ashmid View Drop Down
Beginner
Beginner


Joined: 06 Jan 12
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote ashmid Quote  Post ReplyReply Direct Link To This Post Posted: 06 Jan 12 at 10:18AM
Hi Ingo,
Thank you for you quick reply.
I remain puzzled, though, by your use of the terms encodeUtf16 and decodeUtf16. A search for these terms in the Quickpdf documents (developer guide and function reference) does not turn up any results, nor are there any results when searching the forum for these terms (other than your message itself).
To what do you refer when you say "use something like encodeUtf16"?
(I'm using QuickPDF version 8.13. All of the strings that I am sending to DrawText are widechar Unicode16 strings).
Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Posted: 06 Jan 12 at 9:47PM
Hi!

It's functionality from my Delphi 2007.
There it's encodeUtf8/decodeUtf8 ...
There should be something similar in any
other language (for utf16, too).
This has nothing to do with QuickPDF.
If you wanna search here regarding
your issue you should search with
"unicode", "codepage" or similar. Here
are few threads regarding asian languages, too.

Cheers, Ingo 


Edited by Ingo - 06 Jan 12 at 9:49PM
Back to Top
edvoigt View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 Mar 11
Location: Berlin, Germany
Status: Offline
Points: 111
Post Options Post Options   Thanks (0) Thanks(0)   Quote edvoigt Quote  Post ReplyReply Direct Link To This Post Posted: 07 Jan 12 at 2:56PM
Hi ashmid,

I did a little play with your problem. It gives you a foot in the door. First a bad news:

It seems to be, that QuickPDF (8.13, Delphi 7, Windows XP) deals with unicode fonts only ouside the ascii-range, when you set a codepage. Ommitting the codepage in the fontname brings a lot of white screen but no text.

But independend from the codepage you have sure the ascii-codes<128 too.

The problem not so much inside QuickPDF, the most is around. In my example, I deal with unicodes as numbers. I did make no assumption about the real source of the text to draw.

Here the samplecode:
var
  QP: TQuickPDF;
  x, tw: double;
  i: integer;
  w: WideString;
  wc: wideChar;
  id_heb: integer;
const // example letters from start of genesis
// source: http://www.ancient-hebrew.org/14_htmlfonts.html)
  genesis: array[0..50] of integer =
 (1489,1468,1456,1512,1461,1513,1473,1460,1497,1514,
  1489,1468,1464,1512,1464,1488,1488,1457,1500,1465,
  1492,1460,1497,1501,1488,1461,1514,1492,1463,1513,
  1473,1468,1464,1502,1463,1497,1460,1501,1493,1456,
  1488,1461,1514,1492,1464,1488,1464,1512,1462,1509,1475);
  aleph: WideChar = WideChar($05D0); // give them names if you want
  holam: WideChar = WideChar($05B9);
begin
  QP := TQuickPDF.Create;
  QP.UnlockKey({$I PDFkey.inc});
  QP.SetMeasurementUnits(1);
  QP.SetOrigin(0);
  QP.SetPageDimensions(210, 297);
// for me it looks as AddTrueTypeFont without codepage does not work for unicode
// so we need the font multiple with different codepages for different languages

  id_heb := QP.AddTrueTypeFont('Microsoft Sans Serif {1255}', 0); // important
  QP.SelectFont(id_heb);
  QP.SetTextSize(16);

  w := '';
  for i:=0 to SizeOf(genesis)-1
  do w := WideChar(genesis[ i ])+w; // make it unicode from right to left
  QP.DrawText(20,270, w);

  QP.SetTextSize(8);
  QP.DrawText(20, 260, 'now we try to make it better:');

  QP.SetTextSize(16);
  x := 150; tw := 0;
  for i:=0 to SizeOf(genesis)-1
  do begin
    wc := WideChar(genesis[ i ]);
    if (ord(wc)>=$05D0)  // letter or other
    then begin
      x := x-tw;         // left by the size of last letter before
      tw := QP.GetTextWidth(wc);
      QP.DrawText(x, 260, wc);
    end
    else begin // here is more to do: depending on correct position to the letter
      QP.DrawText(x+tw/2, 260, wc); // but I have not the knowledge for this
    end;
  end;
// show letters + (ascii-)numbers
  w := '';
  for i:=$05D0 to $05EA  // hebrew letters
  do begin
    wc := WideChar(i);
    w := wc + w;         // bring the letters in right to left order
  end;
// and numbers too
  for i:=ord('9') downto ord('0') do w := WideChar(i) + w;
  QP.SelectFont(id_heb);
  QP.SetTextSize(16);
  QP.DrawText(180-QP.GetTextWidth(w), 250, w);

I don't know anything about rules for diacrytics-positions and what I really write in hebrew. You may see that I decide easy by unicode-value how to deal a single char and put the text char by char on the line. So you have a way for correct position of akcents and so on. There is something to do, but you may see it works.


Cheers,
Werner
Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post Posted: 09 Jan 12 at 5:25AM
Unicode text is pretty well supported in QPL 8.13 and above.  Here is some C# code that adds all characters in the Arial Unicode MS font using the QP.AddTrueTypeSubsettedFont.

Currently AddTrueTypeFont only adds the first 255 characters or the character encoding that was selected such as Codepage 1250.  We will be looking to fix this soon as is it a bit confusing.

            StringBuilder sb = new StringBuilder(65000);
            sb.Length = 65000;

            for (int i = 32; i < 65000; i++)
                sb[i-32] = (char)i;
            int id = QP.AddTrueTypeSubsettedFont("Arial Unicode MS", sb.ToString(), 0);

            // The line below should work just as well if you only need a subset.
            //int id = QP.AddTrueTypeSubsettedFont("Arial Unicode MS", "אבגדה   ABCDEF123456 " , 0);

            QP.SelectFont(id);

            QP.SetOrigin(1);
            QP.DrawText(10, 20, "12345 ABCDE abcde ÄæØòÿÜ£üäÆ");
            QP.DrawText(10, 40, "안녕하세요    ABCDEF123456");
            QP.DrawText(10, 60, "אבגדה   ABCDEF123456 " + (char)0x05D0 + (char)0x05D1);
            QP.DrawText(10, 80, "ФЫВА  ABCDEF123456");
            QP.DrawText(10, 100,  "联系电话 (Subset) Chinese");
            QP.DrawText(10, 120,  "これは、あなたが述べてきたように解決するために、ケビンの問題です");
            QP.DrawText(10, 140,  "私はこれが働くことを望んで which is \"I hope this works\" in Japanese");
            QP.DrawText(10, 160,  "联系电话");
            QP.DrawText(10, 180, "И β ϖ ∝ ⊕ ≈ ⅜ ∂");
            QP.SaveToFile("out.pdf");

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store