Finishing first formatting/documenting etc. of the `base' dir. Some modules

are still badly documented, though...
This commit is contained in:
Werner Lemberg 2000-06-02 14:30:38 +00:00
parent 08edde5805
commit 91e52d416a
4 changed files with 453 additions and 339 deletions

View File

@ -126,13 +126,6 @@
/* All callers of FT_Realloc() _must_ provide the current block size */
/* as well as the new one. */
/* */
/* If the memory object's flag FT_SYSTEM_FLAG_NO_REALLOC is set, this */
/* function will try to emulate a reallocation using FT_Alloc() and */
/* FT_Free(). Otherwise, it will call the system-specific `realloc' */
/* implementation. */
/* */
/* (Some embedded systems do not have a working realloc function). */
/* */
BASE_FUNC( FT_Error ) FT_Realloc( FT_Memory memory,
FT_Long current,
FT_Long size,

View File

@ -1,3 +1,21 @@
/***************************************************************************/
/* */
/* ftstream.c */
/* */
/* I/O stream support (body). */
/* */
/* Copyright 2000 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used */
/* modified and distributed under the terms of the FreeType project */
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
/* this file you indicate that you have read the license and */
/* understand and accept it fully. */
/* */
/***************************************************************************/
#include <freetype/internal/ftstream.h>
#include <freetype/internal/ftdebug.h>
@ -25,17 +43,18 @@
{
FT_Error error;
stream->pos = pos;
if ( stream->read )
{
if ( stream->read( stream, pos, 0, 0 ) )
{
error = FT_Err_Invalid_Stream_Operation;
FT_ERROR(( "FT_Seek_Stream:" ));
FT_ERROR(( " invalid i/o, pos = 0x%lx, size = 0x%lx\n",
FT_ERROR(( " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
pos, stream->size ));
error = FT_Err_Invalid_Stream_Operation;
}
else
error = FT_Err_Ok;
@ -43,11 +62,11 @@
/* note that seeking to the first position after the file is valid */
else if ( pos > stream->size )
{
error = FT_Err_Invalid_Stream_Operation;
FT_ERROR(( "FT_Seek_Stream:" ));
FT_ERROR(( " invalid i/o, pos = 0x%lx, size = 0x%lx\n",
FT_ERROR(( " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
pos, stream->size ));
error = FT_Err_Invalid_Stream_Operation;
}
else
@ -64,7 +83,6 @@
}
BASE_FUNC( FT_Long ) FT_Stream_Pos( FT_Stream stream )
{
return stream->pos;
@ -87,10 +105,11 @@
FT_Error error = FT_Err_Ok;
FT_ULong read_bytes;
if ( pos >= stream->size )
{
FT_ERROR(( "FT_Read_Stream_At:" ));
FT_ERROR(( " invalid i/o, pos = 0x%lx, size = 0x%lx\n",
FT_ERROR(( " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
pos, stream->size ));
return FT_Err_Invalid_Stream_Operation;
@ -112,8 +131,9 @@
if ( read_bytes < count )
{
FT_ERROR(( "FT_Read_Stream_At:" ));
FT_ERROR(( " invalid read, expected %lu bytes, got %lu",
FT_ERROR(( " invalid read; expected %lu bytes, got %lu",
count, read_bytes ));
error = FT_Err_Invalid_Stream_Operation;
}
@ -127,15 +147,17 @@
{
FT_Error error;
error = FT_Access_Frame( stream, count );
if ( !error )
{
*pbytes = (FT_Byte*)stream->cursor;
/* equivalent to FT_Forget_Frame, with no memory block release */
/* equivalent to FT_Forget_Frame(), with no memory block release */
stream->cursor = 0;
stream->limit = 0;
}
return error;
}
@ -146,19 +168,21 @@
if ( stream->read )
{
FT_Memory memory = stream->memory;
FREE( *pbytes );
}
*pbytes = 0;
}
BASE_FUNC( FT_Error ) FT_Access_Frame( FT_Stream stream,
FT_ULong count )
{
FT_Error error = FT_Err_Ok;
FT_ULong read_bytes;
/* check for nested frame access */
FT_Assert( stream && stream->cursor == 0 );
@ -167,6 +191,7 @@
/* allocate the frame in memory */
FT_Memory memory = stream->memory;
if ( ALLOC( stream->base, count ) )
goto Exit;
@ -176,7 +201,7 @@
if ( read_bytes < count )
{
FT_ERROR(( "FT_Access_Frame:" ));
FT_ERROR(( " invalid read, expected %lu bytes, got %lu",
FT_ERROR(( " invalid read; expected %lu bytes, got %lu",
count, read_bytes ));
FREE( stream->base );
@ -189,10 +214,11 @@
else
{
/* check current and new position */
if (stream->pos >= stream->size || stream->pos + count > stream->size)
if ( stream->pos >= stream->size ||
stream->pos + count > stream->size )
{
FT_ERROR(( "FT_Access_Frame:" ));
FT_ERROR(( " invalid i/o, pos = 0x%lx, count = %lu, size = 0x%lx",
FT_ERROR(( " invalid i/o; pos = 0x%lx, count = %lu, size = 0x%lx",
stream->pos, count, stream->size ));
error = FT_Err_Invalid_Stream_Operation;
@ -204,6 +230,7 @@
stream->limit = stream->cursor + count;
stream->pos += count;
}
Exit:
return error;
}
@ -214,17 +241,19 @@
/* IMPORTANT: The assertion stream->cursor != 0 was removed, given */
/* that it is possible to access a frame of length 0 in */
/* some weird fonts (usually, when accessing an array of */
/* 0 records, like in some strange kern tables).. */
/* 0 records, like in some strange kern tables). */
/* */
/* In this case, the loader code handles the 0-length table */
/* gracefully, however, stream.cursor is really set to 0 by the */
/* FT_Access_Frame call, and this is not an error.. */
/* gracefully; however, stream.cursor is really set to 0 by the */
/* FT_Access_Frame() call, and this is not an error. */
/* */
FT_Assert( stream );
if ( stream->read )
{
FT_Memory memory = stream->memory;
FREE( stream->base );
}
stream->cursor = 0;
@ -236,6 +265,7 @@
{
FT_Char result;
FT_Assert( stream && stream->cursor );
result = 0;
@ -251,6 +281,7 @@
char* p;
FT_Short result;
FT_Assert( stream && stream->cursor );
result = 0;
@ -258,6 +289,7 @@
if ( p + 1 < stream->limit )
result = NEXT_Short( p );
stream->cursor = p;
return result;
}
@ -267,6 +299,7 @@
char* p;
FT_Long result;
FT_Assert( stream && stream->cursor );
result = 0;
@ -283,6 +316,7 @@
char* p;
FT_Long result;
FT_Assert( stream && stream->cursor );
result = 0;
@ -299,6 +333,7 @@
{
char result = 0;
FT_Assert( stream );
*error = FT_Err_Ok;
@ -316,13 +351,15 @@
goto Fail;
}
stream->pos++;
return result;
Fail:
*error = FT_Err_Invalid_Stream_Operation;
FT_ERROR(( "FT_Read_Char:" ));
FT_ERROR(( " invalid i/o, pos = 0x%lx, size = 0x%lx",
FT_ERROR(( " invalid i/o; pos = 0x%lx, size = 0x%lx",
stream->pos, stream->size ));
return 0;
}
@ -334,6 +371,7 @@
char* p = 0;
FT_Short result = 0;
FT_Assert( stream );
*error = FT_Err_Ok;
@ -355,16 +393,19 @@
if ( p )
result = NEXT_Short( p );
}
else goto Fail;
else
goto Fail;
stream->pos += 2;
return result;
Fail:
*error = FT_Err_Invalid_Stream_Operation;
FT_ERROR(( "FT_Read_Short:" ));
FT_ERROR(( " invalid i/o, pos = 0x%lx, size = 0x%lx",
FT_ERROR(( " invalid i/o; pos = 0x%lx, size = 0x%lx",
stream->pos, stream->size ));
return 0;
}
@ -376,6 +417,7 @@
char* p = 0;
FT_Long result = 0;
FT_Assert( stream );
*error = FT_Err_Ok;
@ -397,16 +439,19 @@
if ( p )
result = NEXT_Offset( p );
}
else goto Fail;
else
goto Fail;
stream->pos += 3;
return result;
Fail:
*error = FT_Err_Invalid_Stream_Operation;
FT_ERROR(( "FT_Read_Offset:" ));
FT_ERROR(( " invalid i/o, pos = 0x%lx, size = 0x%lx",
FT_ERROR(( " invalid i/o; pos = 0x%lx, size = 0x%lx",
stream->pos, stream->size ));
return 0;
}
@ -418,6 +463,7 @@
char* p = 0;
FT_Long result = 0;
FT_Assert( stream );
*error = FT_Err_Ok;
@ -439,19 +485,23 @@
if ( p )
result = NEXT_Long( p );
}
else goto Fail;
else
goto Fail;
stream->pos += 4;
return result;
Fail:
*error = FT_Err_Invalid_Stream_Operation;
FT_ERROR(( "FT_Read_Long:" ));
FT_ERROR(( " invalid i/o, pos = 0x%lx, size = 0x%lx",
FT_ERROR(( " invalid i/o; pos = 0x%lx, size = 0x%lx",
stream->pos, stream->size ));
*error = FT_Err_Invalid_Stream_Operation;
return 0;
}
BASE_FUNC( FT_Error ) FT_Read_Fields( FT_Stream stream,
const FT_Frame_Field* fields,
void* structure )
@ -459,6 +509,7 @@
FT_Error error;
FT_Bool frame_accessed = 0;
if ( !fields || !stream )
return FT_Err_Invalid_Argument;
@ -469,12 +520,14 @@
FT_Int sign_shift;
FT_Byte* p;
switch ( fields->value )
{
case ft_frame_start: /* access a new frame */
{
error = FT_Access_Frame( stream, fields->offset );
if (error) goto Exit;
if ( error )
goto Exit;
frame_accessed = 1;
fields++;
@ -524,6 +577,8 @@
case ft_frame_ulong_le: /* read a 4-byte little-endian long */
{
char* p;
value = 0;
p = stream->cursor;
if ( p + 3 < stream->limit )
@ -550,6 +605,8 @@
case ft_frame_uoff3_le: /* read a 3-byte little-endian long */
{
char* p;
value = 0;
p = stream->cursor;
if ( p + 3 < stream->limit )
@ -578,10 +635,20 @@
p = (FT_Byte*)structure + fields->offset;
switch ( fields->size )
{
case 1: *(FT_Byte*)p = (FT_Byte) value; break;
case 2: *(FT_UShort*)p = (FT_UShort)value; break;
case 4: *(FT_ULong*)p = (FT_ULong) value; break;
default: ; /* ignore !! */
case 1:
*(FT_Byte*)p = (FT_Byte)value;
break;
case 2:
*(FT_UShort*)p = (FT_UShort)value;
break;
case 4:
*(FT_ULong*)p = (FT_ULong)value;
break;
default:
; /* ignore! */
}
/* go to next field */
@ -597,3 +664,5 @@
return error;
}
/* END */

View File

@ -1,109 +1,99 @@
/**************************************************************************
*
* ftsystem.h 1.0
*
* ANSI-specific FreeType low-level system interface
*
* This file contains the definition of interface used by FreeType
* to access low-level, i.e. memory management, i/o access as well
* as thread synchronisation.
*
*
* Copyright 1996-1999 by
* David Turner, Robert Wilhelm, and Werner Lemberg
*
* This file is part of the FreeType project, and may only be used
* modified and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify, or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
**************************************************************************/
/***************************************************************************/
/* */
/* ftsystem.h */
/* */
/* ANSI-specific FreeType low-level system interface (body). */
/* */
/* Copyright 1996-2000 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used */
/* modified and distributed under the terms of the FreeType project */
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
/* this file you indicate that you have read the license and */
/* understand and accept it fully. */
/* */
/***************************************************************************/
/*************************************************************************/
/* */
/* This file contains the default interface used by FreeType to access */
/* low-level, i.e. memory management, i/o access as well as thread */
/* synchronisation. It can be replaced by user-specific routines if */
/* necessary. */
/* */
/*************************************************************************/
#include <freetype/config/ftconfig.h>
#include <freetype/ftsystem.h>
#include <freetype/fterrors.h>
#include <freetype/fttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*********************************************************************/
/*************************************************************************/
/* */
/* MEMORY MANAGEMENT INTERFACE */
/* */
/*************************************************************************/
/************************************************************************
*
* <FuncType>
* FT_Alloc_Func
*
* <Description>
* The memory allocator function type
*
* <Input>
* system :: pointer to the system object
* size :: requested size in bytes
*
* <Output>
* block :: address of newly allocated block
*
* <Return>
* Error code. 0 means success.
*
* <Note>
* If your allocation routine ALWAYS zeroes the new block, you
* should set the flag FT_SYSTEM_FLAG_ALLOC_ZEROES in your system
* object 'flags' field.
*
* If you have set the flag FT_SYSTEM_FLAG_REPORT_CURRENT_ALLOC in
* your system's "system_flags" field, this function should update
* the "current_alloc" field of the system object.
*
************************************************************************/
/*************************************************************************/
/* */
/* It is not necessary to do any error checking here. This will be done */
/* by the higher level routines like FT_Alloc() or FT_Realloc(). */
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* <Function> */
/* ft_alloc */
/* */
/* <Description> */
/* The memory allocation function. */
/* */
/* <Input> */
/* memory :: A pointer to the memory object. */
/* size :: The requested size in bytes. */
/* */
/* <Return> */
/* block :: The address of newly allocated block. */
/* */
static
void* ft_alloc( FT_Memory memory,
long size )
{
UNUSED( memory );
return malloc( size );
}
/************************************************************************
*
* <FuncType>
* FT_Realloc_Func
*
* <Description>
* The memory reallocator function type
*
* <Input>
* system :: pointer to the system object
* new_size :: new requested size in bytes
*
* <InOut>
* block :: address of block in memory
*
* <Return>
* Error code. 0 means success.
*
* <Note>
* This function is _never_ called when the system flag
* FT_SYSTEM_FLAG_NO_REALLOC is set. Instead, the engine will emulate
* realloc through "alloc" and "free".
*
* Note that this is possible due to the fact that FreeType's
* "FT_Realloc" always requests the _current_ size of the reallocated
* block as a parameter, thus avoiding memory leaks.
*
* If you have set the flag FT_SYSTEM_FLAG_REPORT_CURRENT_ALLOC in
* your system's "system_flags" field, this function should update
* the "current_alloc" field of the system object.
*
************************************************************************/
/*************************************************************************/
/* */
/* <Function> */
/* ft_realloc */
/* */
/* <Description> */
/* The memory reallocation function. */
/* */
/* <Input> */
/* memory :: A pointer to the memory object. */
/* */
/* cur_size :: The current size of the allocated memory block. */
/* */
/* new_size :: The newly requested size in bytes. */
/* */
/* block :: The current address of the block in memory. */
/* */
/* <Return> */
/* The address of the reallocated memory block. */
/* */
static
void* ft_realloc( FT_Memory memory,
long cur_size,
@ -117,47 +107,77 @@
}
/************************************************************************
*
* <FuncType>
* FT_Free_Func
*
* <Description>
* The memory release function type
*
* <Input>
* system :: pointer to the system object
* block :: address of block in memory
*
* <Note>
* If you have set the flag FT_SYSTEM_FLAG_REPORT_CURRENT_ALLOC in
* your system's "system_flags" field, this function should update
* the "current_alloc" field of the system object.
*
************************************************************************/
/*************************************************************************/
/* */
/* <Function> */
/* ft_free */
/* */
/* <Description> */
/* The memory release function. */
/* */
/* <Input> */
/* memory :: A pointer to the memory object. */
/* */
/* block :: The address of block in memory to be freed. */
/* */
static
void ft_free( FT_Memory memory,
void* block )
{
UNUSED( memory );
free( block );
}
/*********************************************************************/
/*************************************************************************/
/* */
/* RESOURCE MANAGEMENT INTERFACE */
/* */
/*************************************************************************/
#define STREAM_FILE( stream ) ( (FILE*)stream->descriptor.pointer )
/*************************************************************************/
/* */
/* <Function> */
/* ft_close_stream */
/* */
/* <Description> */
/* The function to close a stream. */
/* */
/* <Input> */
/* stream :: A pointer to the stream object. */
/* */
static
void ft_close_stream( FT_Stream stream )
{
fclose( STREAM_FILE( stream ) );
}
/*************************************************************************/
/* */
/* <Function> */
/* ft_io_stream */
/* */
/* <Description> */
/* The function to open a stream. */
/* */
/* <Input> */
/* stream :: A pointer to the stream object. */
/* */
/* offset :: The position in the data stream to start reading. */
/* */
/* buffer :: The address of buffer to store the read data. */
/* */
/* count :: The number of bytes to read from the stream. */
/* */
/* <Return> */
/* The number of bytes actually read. */
/* */
static
unsigned long ft_io_stream( FT_Stream stream,
unsigned long offset,
@ -166,18 +186,38 @@
{
FILE* file;
file = STREAM_FILE( stream );
fseek( file, offset, SEEK_SET );
return (unsigned long)fread( buffer, 1, count, file );
}
FT_EXPORT_FUNC(int) FT_New_Stream( const char* filepathname,
/*************************************************************************/
/* */
/* <Function> */
/* FT_New_Stream */
/* */
/* <Description> */
/* Creates a new stream object. */
/* */
/* <Input> */
/* filepathname :: The name of the stream (usually a file) to be */
/* opened. */
/* */
/* stream :: A pointer to the stream object. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
FT_EXPORT_FUNC( FT_Error ) FT_New_Stream( const char* filepathname,
FT_Stream stream )
{
FILE* file;
file = fopen( filepathname, "rb" );
if ( !file )
return FT_Err_Cannot_Open_Resource;
@ -192,14 +232,26 @@
stream->read = ft_io_stream;
stream->close = ft_close_stream;
return 0;
return FT_Err_Ok;
}
/*************************************************************************/
/* */
/* <Function> */
/* FT_New_Memory */
/* */
/* <Description> */
/* Creates a new memory object. */
/* */
/* <Return> */
/* A pointer to the new memory object. 0 in case of error. */
/* */
FT_EXPORT_FUNC( FT_Memory ) FT_New_Memory( void )
{
FT_Memory memory;
memory = (FT_Memory)malloc( sizeof ( *memory ) );
if ( memory )
{
@ -208,6 +260,9 @@
memory->realloc = ft_realloc;
memory->free = ft_free;
}
return memory;
}
/* END */

View File

@ -17,7 +17,7 @@
# after the call:
#
# BASE_H: The list of base layer header files on which the rest
# of the library (i.e., drivers) rely.
# of the library (i.e. drivers) rely.
#
# BASE_OBJ_S: The single-object base layer.
# BASE_OBJ_M: A list of all objects for a multiple-objects build.
@ -36,7 +36,6 @@ BASE_SRC := $(BASE_)ftcalc.c \
$(BASE_)ftstream.c \
$(BASE_)ftoutln.c
# Base layer headers
#
BASE_H := $(INTERNAL_)ftcalc.h \
@ -63,6 +62,10 @@ BASE_EXT_SRC := $(BASE_)ftraster.c \
#
BASE_EXT_H := $(BASE_EXT_SRC:%c=%h)
# Default extensions objects
#
BASE_EXT_OBJ := $(BASE_EXT_SRC:$(BASE_)%.c=$(OBJ_)%.$O)
# Base layer object(s)
#
@ -75,12 +78,6 @@ BASE_EXT_H := $(BASE_EXT_SRC:%c=%h)
BASE_OBJ_M := $(BASE_SRC:$(BASE_)%.c=$(OBJ_)%.$O)
BASE_OBJ_S := $(OBJ_)ftbase.$O
# Default extensions objects
#
BASE_EXT_OBJ := $(BASE_EXT_SRC:$(BASE_)%.c=$(OBJ_)%.$O)
# Base layer root source file(s)
#
BASE_SRC_M := $(BASE_SRC)