Some of the text that I'm trying to display in my PDF is from a database and I
cannot predict whether that text is going to be normal ASCII, some extended
characters like Latin-1, or something more challenging like Asian characters.
After doing some research and looking at various postings on this list, my
plan is to have a "cascading" set of fonts that I try when I want to display
this text. For example, suppose I like the font Verdana. I will first check
to see if the text that I'm trying to display will "work" in Verdana, and if
so, that's the font I use. If not, I try another font, and so on until I find
a font that will "work". In practice, I am only going to have two fonts that
I try, Verdana and then Arial Unicode with IDENTITY_H encoding as a catch-all.
The problem that I'm having is that I want the font to tell me if it
will "work" for a given string. I found the CharExists method, which seems
perfectly suited to my task. The problem is that it is returning "false" for
at least some Asian characters, even if the font is Arial Unicode with
IDENTITY_H encoding. What's puzzling is that if I use that font anyway, it
does manage to render the glyphs appropriately. An example of a character
that CharExists() returns false for has code 32076, or u7D4C. Am I missing
something?
Here are some of the relevant pieces of code (using iTextSharp):
FontFactory.Register("C:\\windows\\fonts\\verdana.ttf", "normal");
FontFactory.Register("C:\\windows\\fonts\\arialuni.ttf", "backup");
..
string text = "\u7D4C\u55B6\u8005\u304C";
...
// Here I am using a helper object of my own, s, that is
// just a few properties to represent a font and its style.
// Also imagine that I am looping over a list of s objects,
// looking for the first one that has all the characters
// in the "text" string. The first object in the list
// contains an object that represents Verdana, the second
// object in the list represents Arial Unicode.
Font f = FontFactory.GetFont(s.FontName.ToLower(), s.Encoding, s.FontSize);
BaseFont bf = f.GetCalculatedBaseFont(false);
bool valid = true;
foreach (char c in text)
{
if (!bf.CharExists(c))
{
valid = false;
break;
}
}
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions