[gs-devel] Writing an HPGL driver (with extra xefitra)

Ken Sharp ken.sharp at artifex.com
Tue Apr 29 07:15:23 PDT 2008


Hi Christian,

At 20:02 28/04/2008 +0100, you wrote:

>I was thinking of checking in text_begin whether the operation was a
>drawing operation. If this was the case I would start an almost
>exactly duplicated text enumeration, but with a charpath operation
>instead, collect the outlines, etc. However, this won't collect
>anything if the font in use isn't an outline one or doesn't support
>collecting its actual outlines, in which case just letting things fall
>through to being rastrised and eventually calling 'fill_rectangle'
>wold have been better.
>
>If anyone could advice me on what to do, ideally pointing me to some
>example code, that would be very much appreciated.

I don't have any example code I'm afraid, and my own experience doesn't 
cover PCL, are you intending to input PCL as well ?

But here's a few thoughts:

Font Types
===========
Some font types can only be outlines, one can only be bitmaps, and some can 
be either:

Type 0: A composite font, can have type 1 fonts as descendants, or can be 
produced as a CIDkeyed instance of a CIDFont. I think you can assume this 
is old-fashioned OCF fonts, and will contain outlines.

Type 1 (includes type 2, CFF): Can only be outlines, its perfectly safe to 
convert these to a charpath.

TrueType (includes TYpe 42): theoretically there is a bitmap TT 
implementation, but I've never actually seen one. I think its safe to 
assume that TrueType fonts are outlines, and these can be converted to 
outlines.

Type 3: These may contain fairly arbitrary PostScript, this may include 
image or imagemask operations (bitmaps).

CIDFonts: Type 0 CIDFonts contain type 1 outlines, type 2 CIDFonts contain 
TrueType outlines. Type 1 CIDFonts are analogous to type 3 and contain 
arbitrary PostScript. Type 4 CIDFonts *only* contain bitmaps.


Now, if a glyph *may* contain an image, there's no easy way to tell, so you 
basically have to assume that it does contain an image and render it.

This means you can safely do a charpath on types 0, 1, 2, 42 and CIDFonts 
type 0 and 2. For type 3 fonts, and CIDFonts whose type is 1 or 4 you 
should scan-convert to filled rectangles and draw those.


Text_begin
===========

Now, you will have noticed that the driver text_begin method takes a 
gs_font parameter. This is the current font for the text, and you can use 
this to determine the font type.

font->FontType gives the font's type, you can find the manifest constants 
for these in gxftype.h:

/* Define the known font types. */
/* These numbers must be the same as the values of FontType */
/* in font dictionaries. */
typedef enum {
     ft_composite = 0,
     ft_encrypted = 1,
     ft_encrypted2 = 2,
     ft_user_defined = 3,
     ft_disk_based = 4,
     ft_CID_encrypted = 9,   /* CIDFontType 0 */
     ft_CID_user_defined = 10,   /* CIDFontType 1 */
     ft_CID_TrueType = 11,   /* CIDFontType 2 */
     ft_Chameleon = 14,
     ft_CID_bitmap = 32,     /* CIDFontType 4 */
     ft_TrueType = 42,
     ft_MicroType = 51       /* MicroType 51 is arbitrary */
} font_type;

MicroType is a font format from Agfa Monotype and you need to licence UFST 
to use it, you won't find this in any PostScript or PDF file anyway. 
Chameleon is an Adobe proprietary format, again you shouldn't actually 
encounter these.

Using this you should be able to determine whether the font has guaranteed 
outlines which you can use. If it does, you should be able to alter the 
operation from (eg) TEXT_DO_DRAW to TEXT_DO_ANY_CHARPATH.

Of course, you will also need to deal with the path once you have it!

You will need to do something in the text_release routine with the current 
path, I'm afraid I don't know what you would want to do here.

Hope that's of some help,


                 Ken




More information about the gs-devel mailing list