freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: some more issues with the new API


From: Stefan Seefeld
Subject: Re: some more issues with the new API
Date: Wed, 15 Mar 2000 16:13:34 -0500

Just van Rossum wrote:
> 
> At 3:30 PM -0500 15-03-2000, Stefan Seefeld wrote:
> >I really just got confused by the FT_Init_FreeType call I guess...
> 
> ;-)
> 
> While further thinking about decoupling FT_Glyph(Slot) from FT_Face, I got
> stuck at the FT_Glyph->outline field. This is owned by the glyph, but what
> should a wrapper do? Keep a reference to the glyph so the glyph doesn't get
> destroyed before the outline does? What other options are there?

Hmm, that depends on what a glyph really is. Is it just the data so dependent
on some discriminator the structure contains an outline or a bitmap, or is it a
real object which can *create* an outline or a bitmap if asked to ?

The description of the 'FT_Get_Glyph_Bitmap' function implies the latter.
That's why I'd propose that the Glyph does indeed *not* contain such a
field, but rather that there be a function (or two)

FT_Error FT_Glyph_Get_Bitmap(FT_Glyph, FT_Bitmap *);
FT_Error FT_Glyph_Create_Bitmap(FT_Library, FT_Glyph, FT_Bitmap *);

If we follow this line of thought, the whole ensemble of types in FT2 can be
imagined as a hierarchy of factory classes:

Face creates Glyphs, Glyphs create Outlines and Bitmaps, Outline may create 
Bitmaps,
etc.

I'm not really sure about whether to 'get' or to 'create'. The reason why a
Bitmap can be preallocated is simply that it is a fixed size struct which 
*internally*
contains a pointer which in turn is probably allocated by the 'Get_Bitmap' 
function.
Thus, there is still some 'destructor' to be called to free it. In the sake of
clearness, why not simply make all factory functions create the object in 
question,
making it clear that the result is owned by the caller and should be released 
(with
an appropriate function) ?

So what I have in mind would look like (using C++ syntax):

--------------------------------------------------------------

using namespace FreeType;

//. Library is a static 'singleton' so we don't need to pass it around.

Face *face = new Face("my font file");
Glyph *glyph = face->glyph("my character or string");
Bitmap *bitmap = glyph->bitmap();
Outline *outline = glyph->outline();
Bitmap *bitmap2 = outline->bitmap();

//...

delete bitmap2;
delete outline;
delete bitmap;
delete glyph;
delete face;
----------------------------------------------------------------

Note that all constructors (or factory methods) can throw an exception,
so once the object exists, it is guaranteed to be valid

The C syntax could be fairly similar. Since there are no exceptions,
the return value needs to be the error code. Thus the function takes
two arguments (or three, if you want to pass the Library around)

FT_Face face; FT_Create_Face(library, file, &face);
FT_Glyph glyph; FT_Face_Create_Glyph(library, character, &glyph);
FT_Bitmap bitmap; FT_Glyph_Create_Bitmap(library, glyph, &bitmap);
FT_Outline outline; FT_Glyph_Create_Outline(library, glyph, &outline);
FT_Bitmap bitmap2; FT_Outline_Create_Bitmap(library, outline, &bitmap);

//...

Regards,        Stefan
_______________________________________________________              
              
Stefan Seefeld
Departement de Physique
Universite de Montreal
email: address@hidden

_______________________________________________________

      ...ich hab' noch einen Koffer in Berlin...



reply via email to

[Prev in Thread] Current Thread [Next in Thread]