added glyph zone objects

This commit is contained in:
David Turner 2000-02-21 16:00:36 +00:00
parent 4ea18e5573
commit cbfaedcefa
2 changed files with 197 additions and 17 deletions

View File

@ -2409,46 +2409,50 @@
FT_Error FT_Get_Outline_CBox( FT_Outline* outline,
FT_BBox* cbox )
{
FT_Pos xMin, yMin, xMax, yMax;
if ( outline && cbox )
{
if ( outline->n_points == 0 )
{
cbox->xMin = 0;
cbox->yMin = 0;
cbox->xMax = 0;
cbox->yMax = 0;
xMin = 0;
yMin = 0;
xMax = 0;
yMax = 0;
}
else
{
FT_UShort k;
FT_Vector* vec = outline->points;
FT_Vector* vec = outline->points;
FT_Vector* limit = vec + outline->n_points;
cbox->xMin = cbox->xMax = vec->x;
cbox->yMin = cbox->yMax = vec->y;
xMin = xMax = vec->x;
yMin = yMax = vec->y;
vec++;
for ( k = 1; k < outline->n_points; k++ )
for ( ; vec < limit; vec++ )
{
FT_Pos x, y;
x = vec->x;
if ( x < cbox->xMin ) cbox->xMin = x;
if ( x > cbox->xMax ) cbox->xMax = x;
if ( x < xMin ) xMin = x;
if ( x > xMax ) xMax = x;
y = vec->y;
if ( y < cbox->yMin ) cbox->yMin = y;
if ( y > cbox->yMax ) cbox->yMax = y;
vec++;
if ( y < yMin ) yMin = y;
if ( y > yMax ) yMax = y;
}
}
cbox->xMin = xMin;
cbox->xMax = xMax;
cbox->yMin = yMin;
cbox->yMax = yMax;
return FT_Err_Ok;
}
else
return FT_Err_Invalid_Argument;
}
/*************************************************************************/
/* */
@ -2474,7 +2478,6 @@
FT_UShort n;
FT_Vector* vec = outline->points;
for ( n = 0; n < outline->n_points; n++ )
{
vec->x += xOffset;
@ -2484,6 +2487,130 @@
}
/*************************************************************************/
/* */
/* <Function> */
/* FT_Done_GlyphZone */
/* */
/* <Description> */
/* Deallocates a glyph zone. */
/* */
/* <Input> */
/* zone :: pointer to the target glyph zone. */
/* */
BASE_FUNC
void FT_Done_GlyphZone( FT_GlyphZone* zone )
{
FT_Memory memory = zone->memory;
FREE( zone->contours );
FREE( zone->flags );
FREE( zone->cur );
FREE( zone->org );
zone->max_points = zone->n_points = 0;
zone->max_contours = zone->n_contours = 0;
}
/*************************************************************************/
/* */
/* <Function> */
/* FT_New_GlyphZone */
/* */
/* <Description> */
/* Allocates a new glyph zone. */
/* */
/* <Input> */
/* memory :: A handle to the current memory object. */
/* */
/* maxPoints :: The capacity of glyph zone in points. */
/* */
/* maxContours :: The capacity of glyph zone in contours. */
/* */
/* <Output> */
/* zone :: A pointer to the target glyph zone record. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
BASE_FUNC
FT_Error FT_New_GlyphZone( FT_Memory memory,
FT_UShort maxPoints,
FT_Short maxContours,
FT_GlyphZone* zone )
{
FT_Error error;
if (maxPoints > 0)
maxPoints += 2;
MEM_Set( zone, 0, sizeof(*zone) );
zone->memory = memory;
if ( ALLOC_ARRAY( zone->org, maxPoints*2, FT_F26Dot6 ) ||
ALLOC_ARRAY( zone->cur, maxPoints*2, FT_F26Dot6 ) ||
ALLOC_ARRAY( zone->flags, maxPoints, FT_Byte ) ||
ALLOC_ARRAY( zone->contours, maxContours, FT_UShort ) )
{
FT_Done_GlyphZone(zone);
}
return error;
}
/*************************************************************************/
/* */
/* <Function> */
/* FT_Update_GlyphZone */
/* */
/* <Description> */
/* Checks the size of a zone and reallocates it if necessary. */
/* */
/* <Input> */
/* newPoints :: The new capacity for points. We add two slots for */
/* phantom points. */
/* */
/* newContours :: The new capacity for contours. */
/* */
/* <InOut> */
/* zone :: The address of the target zone. */
/* */
/* maxPoints :: The address of the zone's current capacity for */
/* points. */
/* */
/* maxContours :: The address of the zone's current capacity for */
/* contours. */
/* */
BASE_FUNC
FT_Error FT_Update_GlyphZone( FT_GlyphZone* zone,
FT_UShort newPoints,
FT_Short newContours )
{
FT_Error error = FT_Err_Ok;
FT_Memory memory = zone->memory;
newPoints += 2;
if ( zone->max_points < newPoints )
{
/* reallocate the points arrays */
if ( REALLOC_ARRAY( zone->org, zone->max_points*2, newPoints*2, FT_F26Dot6 ) ||
REALLOC_ARRAY( zone->cur, zone->max_points*2, newPoints*2, FT_F26Dot6 ) ||
REALLOC_ARRAY( zone->flags, zone->max_points*2, newPoints, FT_Byte ) )
goto Exit;
zone->max_points = newPoints;
}
if ( zone->max_contours < newContours )
{
/* reallocate the contours array */
if ( REALLOC_ARRAY( zone->contours, zone->max_contours, newContours, FT_UShort ) )
goto Exit;
zone->max_contours = newContours;
}
Exit:
return error;
}

View File

@ -319,6 +319,59 @@
#ifdef FT_CONFIG_OPTION_ALTERNATE_GLYPH_FORMATS
/************************************************************************
*
* <Struct>
* FT_GlyphZone
*
* <Description>
* A glyph zone is used to load, scale and hint glyph outline
* coordinates.
*
* <Fields>
* memory :: handle to memory manager
* max_points :: max size in points of zone
* max_contours :: max size in contours of zone
* n_points :: current number of points in zone
* n_contours :: current number of contours in zone
* org :: original glyph coordinates (font units/scaled)
* cur :: current glyph coordinates (scaled/hinted)
* flags :: point control flags
* contours :: contour end points
*
***********************************************************************/
typedef struct FT_GlyphZone_
{
FT_Memory memory;
FT_UShort max_points;
FT_UShort max_contours;
FT_UShort n_points; /* number of points in zone */
FT_Short n_contours; /* number of contours */
FT_Vector* org; /* original point coordinates */
FT_Vector* cur; /* current point coordinates */
FT_Byte* flags; /* current touch flags */
FT_UShort* contours; /* contour end points */
} FT_GlyphZone;
BASE_DEF
FT_Error FT_New_GlyphZone( FT_Memory memory,
FT_UShort maxPoints,
FT_Short maxContours,
FT_GlyphZone* zone );
BASE_DEF
void FT_Done_GlyphZone( FT_GlyphZone* zone );
BASE_DEF
FT_Error FT_Update_GlyphZone( FT_GlyphZone* zone,
FT_UShort num_points,
FT_Short num_contours );
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/