2002-03-30 14:16:35 +01:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* ftgloadr.c */
|
|
|
|
/* */
|
|
|
|
/* The FreeType glyph loader (body). */
|
|
|
|
/* */
|
2015-01-17 20:41:43 +01:00
|
|
|
/* Copyright 2002-2015 by */
|
2002-03-30 14:16:35 +01:00
|
|
|
/* 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. */
|
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
|
2002-02-22 18:58:05 +01:00
|
|
|
#include <ft2build.h>
|
2013-03-14 10:27:35 +01:00
|
|
|
#include FT_INTERNAL_DEBUG_H
|
2002-02-22 18:58:05 +01:00
|
|
|
#include FT_INTERNAL_GLYPH_LOADER_H
|
2002-02-24 03:59:24 +01:00
|
|
|
#include FT_INTERNAL_MEMORY_H
|
2003-12-26 08:26:08 +01:00
|
|
|
#include FT_INTERNAL_OBJECTS_H
|
2002-02-22 18:58:05 +01:00
|
|
|
|
|
|
|
#undef FT_COMPONENT
|
|
|
|
#define FT_COMPONENT trace_gloader
|
|
|
|
|
2002-03-30 14:16:35 +01:00
|
|
|
|
2002-02-22 18:58:05 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** *****/
|
|
|
|
/***** G L Y P H L O A D E R *****/
|
|
|
|
/***** *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* The glyph loader is a simple object which is used to load a set of */
|
|
|
|
/* glyphs easily. It is critical for the correct loading of composites. */
|
|
|
|
/* */
|
|
|
|
/* Ideally, one can see it as a stack of abstract `glyph' objects. */
|
|
|
|
/* */
|
|
|
|
/* loader.base Is really the bottom of the stack. It describes a */
|
|
|
|
/* single glyph image made of the juxtaposition of */
|
|
|
|
/* several glyphs (those `in the stack'). */
|
|
|
|
/* */
|
|
|
|
/* loader.current Describes the top of the stack, on which a new */
|
|
|
|
/* glyph can be loaded. */
|
|
|
|
/* */
|
|
|
|
/* Rewind Clears the stack. */
|
|
|
|
/* Prepare Set up `loader.current' for addition of a new glyph */
|
|
|
|
/* image. */
|
|
|
|
/* Add Add the `current' glyph image to the `base' one, */
|
|
|
|
/* and prepare for another one. */
|
|
|
|
/* */
|
|
|
|
/* The glyph loader is now a base object. Each driver used to */
|
|
|
|
/* re-implement it in one way or the other, which wasted code and */
|
|
|
|
/* energy. */
|
|
|
|
/* */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/* create a new glyph loader */
|
|
|
|
FT_BASE_DEF( FT_Error )
|
2002-03-30 14:16:35 +01:00
|
|
|
FT_GlyphLoader_New( FT_Memory memory,
|
|
|
|
FT_GlyphLoader *aloader )
|
2002-02-22 18:58:05 +01:00
|
|
|
{
|
2010-07-12 21:13:22 +02:00
|
|
|
FT_GlyphLoader loader = NULL;
|
2002-03-30 14:16:35 +01:00
|
|
|
FT_Error error;
|
2002-02-22 18:58:05 +01:00
|
|
|
|
|
|
|
|
2002-03-22 14:52:37 +01:00
|
|
|
if ( !FT_NEW( loader ) )
|
2002-02-22 18:58:05 +01:00
|
|
|
{
|
|
|
|
loader->memory = memory;
|
|
|
|
*aloader = loader;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* rewind the glyph loader - reset counters to 0 */
|
|
|
|
FT_BASE_DEF( void )
|
2002-03-30 14:16:35 +01:00
|
|
|
FT_GlyphLoader_Rewind( FT_GlyphLoader loader )
|
2002-02-22 18:58:05 +01:00
|
|
|
{
|
2002-02-24 03:59:24 +01:00
|
|
|
FT_GlyphLoad base = &loader->base;
|
|
|
|
FT_GlyphLoad current = &loader->current;
|
2002-02-22 18:58:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
base->outline.n_points = 0;
|
|
|
|
base->outline.n_contours = 0;
|
|
|
|
base->num_subglyphs = 0;
|
|
|
|
|
|
|
|
*current = *base;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* reset the glyph loader, frees all allocated tables */
|
|
|
|
/* and starts from zero */
|
|
|
|
FT_BASE_DEF( void )
|
2002-03-30 14:16:35 +01:00
|
|
|
FT_GlyphLoader_Reset( FT_GlyphLoader loader )
|
2002-02-22 18:58:05 +01:00
|
|
|
{
|
|
|
|
FT_Memory memory = loader->memory;
|
|
|
|
|
|
|
|
|
2002-03-22 14:52:37 +01:00
|
|
|
FT_FREE( loader->base.outline.points );
|
|
|
|
FT_FREE( loader->base.outline.tags );
|
|
|
|
FT_FREE( loader->base.outline.contours );
|
|
|
|
FT_FREE( loader->base.extra_points );
|
|
|
|
FT_FREE( loader->base.subglyphs );
|
2002-02-22 18:58:05 +01:00
|
|
|
|
2006-08-16 18:50:55 +02:00
|
|
|
loader->base.extra_points2 = NULL;
|
|
|
|
|
2002-02-22 18:58:05 +01:00
|
|
|
loader->max_points = 0;
|
|
|
|
loader->max_contours = 0;
|
|
|
|
loader->max_subglyphs = 0;
|
|
|
|
|
|
|
|
FT_GlyphLoader_Rewind( loader );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* delete a glyph loader */
|
|
|
|
FT_BASE_DEF( void )
|
2002-03-30 14:16:35 +01:00
|
|
|
FT_GlyphLoader_Done( FT_GlyphLoader loader )
|
2002-02-22 18:58:05 +01:00
|
|
|
{
|
|
|
|
if ( loader )
|
|
|
|
{
|
|
|
|
FT_Memory memory = loader->memory;
|
|
|
|
|
|
|
|
|
|
|
|
FT_GlyphLoader_Reset( loader );
|
2002-03-22 14:52:37 +01:00
|
|
|
FT_FREE( loader );
|
2002-02-22 18:58:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* re-adjust the `current' outline fields */
|
|
|
|
static void
|
2002-03-30 14:16:35 +01:00
|
|
|
FT_GlyphLoader_Adjust_Points( FT_GlyphLoader loader )
|
2002-02-22 18:58:05 +01:00
|
|
|
{
|
|
|
|
FT_Outline* base = &loader->base.outline;
|
|
|
|
FT_Outline* current = &loader->current.outline;
|
|
|
|
|
|
|
|
|
|
|
|
current->points = base->points + base->n_points;
|
|
|
|
current->tags = base->tags + base->n_points;
|
|
|
|
current->contours = base->contours + base->n_contours;
|
|
|
|
|
|
|
|
/* handle extra points table - if any */
|
|
|
|
if ( loader->use_extra )
|
2006-08-16 18:50:55 +02:00
|
|
|
{
|
|
|
|
loader->current.extra_points = loader->base.extra_points +
|
|
|
|
base->n_points;
|
|
|
|
|
|
|
|
loader->current.extra_points2 = loader->base.extra_points2 +
|
|
|
|
base->n_points;
|
|
|
|
}
|
2002-02-22 18:58:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_BASE_DEF( FT_Error )
|
2002-03-30 14:16:35 +01:00
|
|
|
FT_GlyphLoader_CreateExtra( FT_GlyphLoader loader )
|
2002-02-22 18:58:05 +01:00
|
|
|
{
|
|
|
|
FT_Error error;
|
|
|
|
FT_Memory memory = loader->memory;
|
|
|
|
|
|
|
|
|
2006-08-19 13:18:09 +02:00
|
|
|
if ( !FT_NEW_ARRAY( loader->base.extra_points, 2 * loader->max_points ) )
|
2002-02-22 18:58:05 +01:00
|
|
|
{
|
2006-08-16 18:50:55 +02:00
|
|
|
loader->use_extra = 1;
|
|
|
|
loader->base.extra_points2 = loader->base.extra_points +
|
|
|
|
loader->max_points;
|
|
|
|
|
2002-02-22 18:58:05 +01:00
|
|
|
FT_GlyphLoader_Adjust_Points( loader );
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* re-adjust the `current' subglyphs field */
|
|
|
|
static void
|
2002-03-30 14:16:35 +01:00
|
|
|
FT_GlyphLoader_Adjust_Subglyphs( FT_GlyphLoader loader )
|
2002-02-22 18:58:05 +01:00
|
|
|
{
|
2002-02-24 03:59:24 +01:00
|
|
|
FT_GlyphLoad base = &loader->base;
|
|
|
|
FT_GlyphLoad current = &loader->current;
|
2002-02-22 18:58:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
current->subglyphs = base->subglyphs + base->num_subglyphs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-13 14:59:59 +02:00
|
|
|
/* Ensure that we can add `n_points' and `n_contours' to our glyph. */
|
|
|
|
/* This function reallocates its outline tables if necessary. Note that */
|
|
|
|
/* it DOESN'T change the number of points within the loader! */
|
2002-02-22 18:58:05 +01:00
|
|
|
/* */
|
|
|
|
FT_BASE_DEF( FT_Error )
|
2002-03-30 14:16:35 +01:00
|
|
|
FT_GlyphLoader_CheckPoints( FT_GlyphLoader loader,
|
2004-05-13 14:59:59 +02:00
|
|
|
FT_UInt n_points,
|
|
|
|
FT_UInt n_contours )
|
2002-02-22 18:58:05 +01:00
|
|
|
{
|
|
|
|
FT_Memory memory = loader->memory;
|
|
|
|
FT_Error error = FT_Err_Ok;
|
|
|
|
FT_Outline* base = &loader->base.outline;
|
|
|
|
FT_Outline* current = &loader->current.outline;
|
2005-10-28 18:14:14 +02:00
|
|
|
FT_Bool adjust = 0;
|
2002-02-22 18:58:05 +01:00
|
|
|
|
|
|
|
FT_UInt new_max, old_max;
|
|
|
|
|
|
|
|
|
|
|
|
/* check points & tags */
|
|
|
|
new_max = base->n_points + current->n_points + n_points;
|
|
|
|
old_max = loader->max_points;
|
|
|
|
|
|
|
|
if ( new_max > old_max )
|
|
|
|
{
|
2003-12-24 02:10:46 +01:00
|
|
|
new_max = FT_PAD_CEIL( new_max, 8 );
|
2002-02-22 18:58:05 +01:00
|
|
|
|
2009-07-08 07:26:51 +02:00
|
|
|
if ( new_max > FT_OUTLINE_POINTS_MAX )
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Array_Too_Large );
|
2009-07-08 07:26:51 +02:00
|
|
|
|
2002-03-22 14:52:37 +01:00
|
|
|
if ( FT_RENEW_ARRAY( base->points, old_max, new_max ) ||
|
|
|
|
FT_RENEW_ARRAY( base->tags, old_max, new_max ) )
|
2002-03-30 14:16:35 +01:00
|
|
|
goto Exit;
|
2002-02-22 18:58:05 +01:00
|
|
|
|
2006-08-16 18:50:55 +02:00
|
|
|
if ( loader->use_extra )
|
|
|
|
{
|
2006-08-19 13:18:09 +02:00
|
|
|
if ( FT_RENEW_ARRAY( loader->base.extra_points,
|
|
|
|
old_max * 2, new_max * 2 ) )
|
2006-08-16 18:50:55 +02:00
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
FT_ARRAY_MOVE( loader->base.extra_points + new_max,
|
|
|
|
loader->base.extra_points + old_max,
|
|
|
|
old_max );
|
|
|
|
|
|
|
|
loader->base.extra_points2 = loader->base.extra_points + new_max;
|
|
|
|
}
|
2002-02-22 18:58:05 +01:00
|
|
|
|
|
|
|
adjust = 1;
|
|
|
|
loader->max_points = new_max;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check contours */
|
|
|
|
old_max = loader->max_contours;
|
|
|
|
new_max = base->n_contours + current->n_contours +
|
|
|
|
n_contours;
|
|
|
|
if ( new_max > old_max )
|
|
|
|
{
|
2003-12-24 02:10:46 +01:00
|
|
|
new_max = FT_PAD_CEIL( new_max, 4 );
|
2009-07-08 07:26:51 +02:00
|
|
|
|
|
|
|
if ( new_max > FT_OUTLINE_CONTOURS_MAX )
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Array_Too_Large );
|
2009-07-08 07:26:51 +02:00
|
|
|
|
2002-03-22 14:52:37 +01:00
|
|
|
if ( FT_RENEW_ARRAY( base->contours, old_max, new_max ) )
|
2002-02-22 18:58:05 +01:00
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
adjust = 1;
|
|
|
|
loader->max_contours = new_max;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( adjust )
|
|
|
|
FT_GlyphLoader_Adjust_Points( loader );
|
|
|
|
|
|
|
|
Exit:
|
2013-06-18 10:17:48 +02:00
|
|
|
if ( error )
|
|
|
|
FT_GlyphLoader_Reset( loader );
|
|
|
|
|
2002-02-22 18:58:05 +01:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Ensure that we can add `n_subglyphs' to our glyph. this function */
|
|
|
|
/* reallocates its subglyphs table if necessary. Note that it DOES */
|
|
|
|
/* NOT change the number of subglyphs within the loader! */
|
|
|
|
/* */
|
|
|
|
FT_BASE_DEF( FT_Error )
|
2002-03-30 14:16:35 +01:00
|
|
|
FT_GlyphLoader_CheckSubGlyphs( FT_GlyphLoader loader,
|
|
|
|
FT_UInt n_subs )
|
2002-02-22 18:58:05 +01:00
|
|
|
{
|
2002-03-30 14:16:35 +01:00
|
|
|
FT_Memory memory = loader->memory;
|
|
|
|
FT_Error error = FT_Err_Ok;
|
|
|
|
FT_UInt new_max, old_max;
|
2002-02-22 18:58:05 +01:00
|
|
|
|
2002-02-24 03:59:24 +01:00
|
|
|
FT_GlyphLoad base = &loader->base;
|
|
|
|
FT_GlyphLoad current = &loader->current;
|
2002-02-22 18:58:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
new_max = base->num_subglyphs + current->num_subglyphs + n_subs;
|
|
|
|
old_max = loader->max_subglyphs;
|
|
|
|
if ( new_max > old_max )
|
|
|
|
{
|
2003-12-24 02:10:46 +01:00
|
|
|
new_max = FT_PAD_CEIL( new_max, 2 );
|
2002-03-22 14:52:37 +01:00
|
|
|
if ( FT_RENEW_ARRAY( base->subglyphs, old_max, new_max ) )
|
2002-02-22 18:58:05 +01:00
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
loader->max_subglyphs = new_max;
|
|
|
|
|
|
|
|
FT_GlyphLoader_Adjust_Subglyphs( loader );
|
|
|
|
}
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* prepare loader for the addition of a new glyph on top of the base one */
|
|
|
|
FT_BASE_DEF( void )
|
2002-03-30 14:16:35 +01:00
|
|
|
FT_GlyphLoader_Prepare( FT_GlyphLoader loader )
|
2002-02-22 18:58:05 +01:00
|
|
|
{
|
2002-02-24 03:59:24 +01:00
|
|
|
FT_GlyphLoad current = &loader->current;
|
2002-02-22 18:58:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
current->outline.n_points = 0;
|
|
|
|
current->outline.n_contours = 0;
|
|
|
|
current->num_subglyphs = 0;
|
|
|
|
|
|
|
|
FT_GlyphLoader_Adjust_Points ( loader );
|
|
|
|
FT_GlyphLoader_Adjust_Subglyphs( loader );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-06 19:38:44 +02:00
|
|
|
/* add current glyph to the base image -- and prepare for another */
|
2002-02-22 18:58:05 +01:00
|
|
|
FT_BASE_DEF( void )
|
2002-03-30 14:16:35 +01:00
|
|
|
FT_GlyphLoader_Add( FT_GlyphLoader loader )
|
2002-02-22 18:58:05 +01:00
|
|
|
{
|
2005-08-18 09:40:32 +02:00
|
|
|
FT_GlyphLoad base;
|
|
|
|
FT_GlyphLoad current;
|
2002-02-22 18:58:05 +01:00
|
|
|
|
2005-08-18 09:40:32 +02:00
|
|
|
FT_UInt n_curr_contours;
|
|
|
|
FT_UInt n_base_points;
|
2002-03-30 14:16:35 +01:00
|
|
|
FT_UInt n;
|
2002-02-22 18:58:05 +01:00
|
|
|
|
|
|
|
|
2005-08-18 09:40:32 +02:00
|
|
|
if ( !loader )
|
|
|
|
return;
|
|
|
|
|
|
|
|
base = &loader->base;
|
|
|
|
current = &loader->current;
|
|
|
|
|
|
|
|
n_curr_contours = current->outline.n_contours;
|
|
|
|
n_base_points = base->outline.n_points;
|
|
|
|
|
2002-02-22 18:58:05 +01:00
|
|
|
base->outline.n_points =
|
|
|
|
(short)( base->outline.n_points + current->outline.n_points );
|
|
|
|
base->outline.n_contours =
|
|
|
|
(short)( base->outline.n_contours + current->outline.n_contours );
|
|
|
|
|
|
|
|
base->num_subglyphs += current->num_subglyphs;
|
|
|
|
|
|
|
|
/* adjust contours count in newest outline */
|
|
|
|
for ( n = 0; n < n_curr_contours; n++ )
|
|
|
|
current->outline.contours[n] =
|
|
|
|
(short)( current->outline.contours[n] + n_base_points );
|
|
|
|
|
|
|
|
/* prepare for another new glyph image */
|
|
|
|
FT_GlyphLoader_Prepare( loader );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_BASE_DEF( FT_Error )
|
2002-03-30 14:16:35 +01:00
|
|
|
FT_GlyphLoader_CopyPoints( FT_GlyphLoader target,
|
|
|
|
FT_GlyphLoader source )
|
2002-02-22 18:58:05 +01:00
|
|
|
{
|
|
|
|
FT_Error error;
|
|
|
|
FT_UInt num_points = source->base.outline.n_points;
|
|
|
|
FT_UInt num_contours = source->base.outline.n_contours;
|
|
|
|
|
|
|
|
|
2002-03-14 13:56:35 +01:00
|
|
|
error = FT_GlyphLoader_CheckPoints( target, num_points, num_contours );
|
2002-02-22 18:58:05 +01:00
|
|
|
if ( !error )
|
|
|
|
{
|
|
|
|
FT_Outline* out = &target->base.outline;
|
|
|
|
FT_Outline* in = &source->base.outline;
|
|
|
|
|
|
|
|
|
2004-01-15 20:07:44 +01:00
|
|
|
FT_ARRAY_COPY( out->points, in->points,
|
|
|
|
num_points );
|
|
|
|
FT_ARRAY_COPY( out->tags, in->tags,
|
|
|
|
num_points );
|
|
|
|
FT_ARRAY_COPY( out->contours, in->contours,
|
|
|
|
num_contours );
|
2002-02-22 18:58:05 +01:00
|
|
|
|
|
|
|
/* do we need to copy the extra points? */
|
|
|
|
if ( target->use_extra && source->use_extra )
|
2006-08-16 18:50:55 +02:00
|
|
|
{
|
2004-01-15 20:07:44 +01:00
|
|
|
FT_ARRAY_COPY( target->base.extra_points, source->base.extra_points,
|
|
|
|
num_points );
|
2006-08-16 18:50:55 +02:00
|
|
|
FT_ARRAY_COPY( target->base.extra_points2, source->base.extra_points2,
|
|
|
|
num_points );
|
|
|
|
}
|
2002-02-22 18:58:05 +01:00
|
|
|
|
|
|
|
out->n_points = (short)num_points;
|
|
|
|
out->n_contours = (short)num_contours;
|
|
|
|
|
|
|
|
FT_GlyphLoader_Adjust_Points( target );
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* END */
|