From 2041c65cd263717928302ad3b709d267030e5bec Mon Sep 17 00:00:00 2001 From: Alexei Podtelezhnikov Date: Fri, 20 Jun 2025 20:20:54 -0400 Subject: [PATCH] [truetype] Simplify twilight zone management. * include/freetype/internal/tttypes.h (TT_GlyphZone): Remove 'memory'. * src/truetype/ttobjs.c (tt_glyphzone_done): Use 'memory' as argument. (tt_glyphzone_new, tt_glyphzone_done): Allocate/free as a single block. (tt_size_init_bytecode, tt_size_done_bytecode): Updated. * src/truetype/ttobjs.h (tt_glyphzone_done): Updated signature. --- include/freetype/internal/tttypes.h | 4 --- src/truetype/ttobjs.c | 47 +++++++++++------------------ src/truetype/ttobjs.h | 3 +- 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/include/freetype/internal/tttypes.h b/include/freetype/internal/tttypes.h index d919ca51c..245954f9f 100644 --- a/include/freetype/internal/tttypes.h +++ b/include/freetype/internal/tttypes.h @@ -1613,9 +1613,6 @@ FT_BEGIN_HEADER * coordinates. * * @fields: - * memory :: - * A handle to the memory manager. - * * n_points :: * The current number of points in the zone. * @@ -1639,7 +1636,6 @@ FT_BEGIN_HEADER */ typedef struct TT_GlyphZoneRec_ { - FT_Memory memory; FT_UShort n_points; /* number of points in zone */ FT_UShort n_contours; /* number of contours */ diff --git a/src/truetype/ttobjs.c b/src/truetype/ttobjs.c index 8ea3064b9..53f6019ea 100644 --- a/src/truetype/ttobjs.c +++ b/src/truetype/ttobjs.c @@ -67,23 +67,13 @@ * A pointer to the target glyph zone. */ FT_LOCAL_DEF( void ) - tt_glyphzone_done( TT_GlyphZone zone ) + tt_glyphzone_done( FT_Memory memory, + TT_GlyphZone zone ) { - FT_Memory memory = zone->memory; + FT_FREE( zone->org ); - - if ( memory ) - { - FT_FREE( zone->contours ); - FT_FREE( zone->tags ); - FT_FREE( zone->cur ); - FT_FREE( zone->org ); - FT_FREE( zone->orus ); - - zone->n_points = 0; - zone->n_contours = 0; - zone->memory = NULL; - } + zone->n_points = 0; + zone->n_contours = 0; } @@ -119,23 +109,22 @@ TT_GlyphZone zone ) { FT_Error error; + FT_Long size = 3 * maxPoints * sizeof ( FT_Vector ) + + maxContours * sizeof ( FT_UShort ) + + maxPoints * sizeof ( FT_Byte ); - FT_ZERO( zone ); - zone->memory = memory; - - if ( FT_NEW_ARRAY( zone->org, maxPoints ) || - FT_NEW_ARRAY( zone->cur, maxPoints ) || - FT_NEW_ARRAY( zone->orus, maxPoints ) || - FT_NEW_ARRAY( zone->tags, maxPoints ) || - FT_NEW_ARRAY( zone->contours, maxContours ) ) - { - tt_glyphzone_done( zone ); - } - else + if ( !FT_ALLOC( zone->org, size ) ) { zone->n_points = maxPoints; zone->n_contours = maxContours; + + zone->cur = zone->org + maxPoints; + zone->orus = zone->cur + maxPoints; + zone->contours = (FT_UShort*)( zone->orus + maxPoints ); + zone->tags = (FT_Byte*)( zone->contours + maxContours ); + + zone->first_point = 0; } return error; @@ -1051,7 +1040,7 @@ size->storage_size = 0; /* twilight zone */ - tt_glyphzone_done( &size->twilight ); + tt_glyphzone_done( memory, &size->twilight ); FT_FREE( size->function_defs ); FT_FREE( size->instruction_defs ); @@ -1092,7 +1081,7 @@ if ( size->context ) TT_Done_Context( size->context ); - tt_glyphzone_done( &size->twilight ); + tt_glyphzone_done( memory, &size->twilight ); size->bytecode_ready = -1; size->cvt_ready = -1; diff --git a/src/truetype/ttobjs.h b/src/truetype/ttobjs.h index 58629328f..6902f3d30 100644 --- a/src/truetype/ttobjs.h +++ b/src/truetype/ttobjs.h @@ -101,7 +101,8 @@ FT_BEGIN_HEADER #ifdef TT_USE_BYTECODE_INTERPRETER FT_LOCAL( void ) - tt_glyphzone_done( TT_GlyphZone zone ); + tt_glyphzone_done( FT_Memory memory, + TT_GlyphZone zone ); FT_LOCAL( FT_Error ) tt_glyphzone_new( FT_Memory memory,