[IMAGE-SIG] Question about t1lib/PIL integration

Fred L. Drake Fred L. Drake, Jr." <fdrake@acm.org
Thu, 30 Oct 1997 21:47:24 -0500

  I mentioned a week or so ago that I've been working on an extension
which provides access to the t1lib library; this library is a
rasterizer for Type1 fonts.  I have a question regarding how others
would like to see the integration of t1lib with PIL.
  The structure of my package includes the following modules:

	_t1lib	-- C extension providing low-level access to the C
		   t1lib implementation
	t1lib	-- Python modules which wraps things up in a sensible,
		   O-O interface which is what would actually be used
	t1Imaging -- Python module integrating the t1lib module with

  The t1lib module provides a number of functions and classes.  For my
question, only the organization of a few of these is really relevant.

class FontSetter -- provides operations to rasterize characters and
		    strings in a given font with parameters set
		    through the constructor

class Glyph	 -- the result of the rasterizing methods of the
		    FontSetter; encapsulates the bitmap information

  Both of these classes are subclassed by t1Imaging; the FontSetter
subclass creates instances of the Glyph subclass which actually
performs most of the integration.  The Glyph subclass provides a new
method which returns an Image.Image instance which can be used to feed
image operations or a graphical display.  This gets to the issue I
have and my question for the SIG.
  I am starting to think that the interface might be improved by doing
something a little different.  The Glyph subclass created to perform
the PIL integration could actually be a subclass of both Image.Image
and t1lib.Glyph; the glyph object returned by the rasterizing methods
could simply be used directly anywhere a PIL image is used.  This had
the advantage of a simple model, but the disadvantage of not being
able to delay creation of the PIL image until it's actually
requested.  (Creating the PIL image is actually pretty cheap, as it
uses the Image.fromstring(..., "raw", ...) operation.)
  What are other people's thoughts on this?  I still need to write a
demo program; perhaps seeing how that goes will help resolve the
  As far as my status on this goes:  the implementation seems stable,
but I'm still working on docstring and an HTML page will be
necessary.  I'd like to be able to generate a better document, so I've
spent a little time enhancing a .py->HTML converter I played with a
while ago, but I keep running across limitations in the work I'd done
on the thing long ago; so I may settle for docstrings only for now.
Once I've improved the documentation a bit I'll make it available for
the SIG.  I still have a few questions for the author of t1lib;
hopefully I'll be able to get a message off to him in the next day or


Fred L. Drake, Jr.
Corporation for National Research Initiatives
1895 Preston White Drive
Reston, VA    20191-5434

IMAGE-SIG - SIG on Image Processing with Python

send messages to: image-sig@python.org
administrivia to: image-sig-request@python.org