Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get accented characters?

Character Encoding

How do I get accented characters?

by  tgreer  Posted    (Edited  )
Every PostScript Type 1 font contains glyphs (drawings) of all of the standard character shapes, including accented characters and special symbols (copyright, registration mark, etc.).

However, PostScript Type 1 fonts use an 8-bit encoding scheme, which means that only 256 of the characters are encoded (essentially, available for use).

The trick to getting access to these special characters is to re-encode the font. Here is the code to switch to the ISOLatin1 encoding vector, which encodes all the standard characters, numbers, and puncutation, but also includes the accented characters:

Code:
/HelveticaLatin
  << /Helvetica findfont {} forall >>
  begin
    /Encoding ISOLatin1Encoding 256 array copy def currentdict
  end
definefont pop

/HelveticaLatin 48 selectfont

First we give our new font a name, in this example, HelveticaLatin.

The next line is a clever way to copy a dictionary, which you have to do since font dictionaries are read-only.

The double open-angle brackets starts a new dictionary. Next we put the standard Helvetica font on the stack. The forall loop iterates through the dictionary, leaving each entry on the stack... performing the empty procedure {}.

When the loop completes, we have all the entries from the Helvetica font on the stack. The double close-angle brackets completes the new dictionary.

To change the encoding vector, we make this new dictionary the current dictionary with "begin", create an array, moving the ISOLatin1Encoding array values into it and defining it. We then put this dicitionary back on the operand stack, and then remove the dictionary from the dictionary stack.

We use the copy on the operand stack to pass to the definefont operator, creating our new font.

Accented characters are now encoded. Passing such characters as T and ¬ into your string will now work as well as any other character.

Thomas D. Greer
http://www.tgreer.com
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top