freetype
[Top][All Lists]
Advanced

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

RE: [Freetype] Freetype design problem?...


From: Pedriana, Paul
Subject: RE: [Freetype] Freetype design problem?...
Date: Tue, 21 Aug 2001 15:01:19 -0700

Well, after writing some more code, I did notice that
there is the descriptor field. I imagine I can take
that field and store a pointer to custom data (in addition
to storing a FILE* pointer). This seems to me to be 
more or less a satisfactory solution to the problem 
of being able to store custom data in the FT_Stream 
record, as long as nobody but the (replaceable) stream
IO functions do anything with that data.

Paul




-----Original Message-----
From: Pedriana, Paul [mailto:address@hidden
Sent: Tuesday, August 21, 2001 2:32 PM
To: address@hidden
Subject: [Freetype] Freetype design problem?...


I have a small problem with the design of the stream 
interface in FreeType, as exemplified in the code below.
The 'ft_new_input_stream' function (below) creates a 
new FTStream. The problem is that *it* is allocating 
the memory for FTStream, when in fact the FT_New_Memory_Stream
function or FT_New_Stream function should be doing the
allocation. The problem with the way it is now is that
you can't write a custom version of FT_New_Stream very
easily because it can't extend the definition of the 
FT_Stream record. It can't do this because somebody 
else allocated the stream record data for it. To be 
able to make anything but the most trivial implementation
of your own FT_New_Stream, you need to store more data
than that provided in the FT_Stream record. The pattern 
of letting the 'plug-innable' driver implement the 
allocation of the resources it uses is a common paradigm.

Now if there is an alternative solution to this problem,
I'd like to hear about it. The best I can do for now 
is do hacks to stuff properietary data into unused parts
of the FT_Stream record, like the 'pathname' field.

Thanks,

Paul Pedriana



-----------------------------------------------------------------
  static
  FT_Error  ft_new_input_stream( FT_Library     library,
                                 FT_Open_Args*  args,
                                 FT_Stream*     astream )
  {
    FT_Error   error;
    FT_Memory  memory;
    FT_Stream  stream;


    if ( !library )
      return FT_Err_Invalid_Library_Handle;

    if ( !args )
      return FT_Err_Invalid_Argument;

    *astream = 0;
    memory   = library->memory;
    if ( ALLOC( stream, sizeof ( *stream ) ) )
      goto Exit;

    stream->memory = memory;

    /* now, look at the stream flags */
    if ( args->flags & ft_open_memory )
    {
      error = 0;
      FT_New_Memory_Stream( library,
                            (FT_Byte*)args->memory_base,
                            args->memory_size,
                            stream );
    }
    else if ( args->flags & ft_open_pathname )
    {
      error = FT_New_Stream( args->pathname, stream );
      stream->pathname.pointer = args->pathname;
    }
    else if ( ( args->flags & ft_open_stream ) && args->stream )
    {
      /* in this case, we do not need to allocate a new stream object */
      /* since the caller is responsible for closing it himself       */
      FREE( stream );
      stream = args->stream;
    }
    else
      error = FT_Err_Invalid_Argument;

    if ( error )
      FREE( stream );

    *astream = stream;

  Exit:
    return error;
  }





_______________________________________________
Freetype mailing list
address@hidden
http://www.freetype.org/mailman/listinfo/freetype



reply via email to

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