From 36779f8dcf11dd46673918333db8c3a92b03954a Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Sun, 12 May 2024 21:25:38 +0200 Subject: [PATCH 01/37] Start working on memory management. --- Driver/Font/TrueType/FreeType/ttmemory.c | 34 +++++++++++++++++++++++- Driver/Font/TrueType/FreeType/ttmemory.h | 18 +++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/Driver/Font/TrueType/FreeType/ttmemory.c b/Driver/Font/TrueType/FreeType/ttmemory.c index 8253a7bdb..f42ca0457 100644 --- a/Driver/Font/TrueType/FreeType/ttmemory.c +++ b/Driver/Font/TrueType/FreeType/ttmemory.c @@ -27,7 +27,6 @@ #include "ttengine.h" #include "ttadapter.h" #include -#include #include #include @@ -142,4 +141,37 @@ return TT_Err_Ok; } +#else // ifdef __GEOS__ + + + EXPORT_FUNC + MemHandle GEO_Alloc( UShort Size ) + { + MemHandle memHandle; + + + if ( Size > MAX_BLOCK_SIZE ) + return NullHandle; + + if ( Size > 0 ) + memHandle = MemAllocSetOwner( GeodeGetCodeProcessHandle(), + Size, HF_SHARABLE | HF_SWAPABLE, HAF_ZERO_INIT ); + + return memHandle; + } + + + EXPORT_FUNC + TT_Error GEO_Free( MemHandle* memHandle ) + { + if ( !memHandle ) + return TT_Err_Ok; + + MemFree( memHandle ); + memHandle = NullHandle; + + return TT_Err_Ok; + } + + #endif diff --git a/Driver/Font/TrueType/FreeType/ttmemory.h b/Driver/Font/TrueType/FreeType/ttmemory.h index 3c1e3eeef..188e4f5cb 100644 --- a/Driver/Font/TrueType/FreeType/ttmemory.h +++ b/Driver/Font/TrueType/FreeType/ttmemory.h @@ -29,6 +29,7 @@ #include "ttconfig.h" #include "tttypes.h" #include +#include #ifdef __cplusplus @@ -87,6 +88,23 @@ TT_Error TT_Free( void** P ); + /* Allocate a movable and swapable block of memory of 'Size' bytes */ + /* from the heap, and return its handle. If 'Size' is 0, or in */ + /* case of error, the returned handle is always a NullHandle. */ + + EXPORT_DEF + MemHandle GEO_Alloc( UShort Size ); + + + /* Releases a block that was previously allocated through GEO_Alloc. */ + /* Note that the function returns successfully when MemHandle is */ + /* already NullHandle. The memHandle is set to NullHandle on exit in */ + /* case of success. */ + + EXPORT_DEF + TT_Error GEO_Free( MemHandle* memHandle ); + + LOCAL_DEF TT_Error TTMemory_Init( void ); LOCAL_DEF TT_Error TTMemory_Done( void ); From 9c957ca50d68282af8a203efd150e4dd3de327b8 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Sun, 12 May 2024 21:49:55 +0200 Subject: [PATCH 02/37] Comments and correction. --- Driver/Font/TrueType/FreeType/ttmemory.c | 41 ++++++++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/ttmemory.c b/Driver/Font/TrueType/FreeType/ttmemory.c index f42ca0457..c8d97673b 100644 --- a/Driver/Font/TrueType/FreeType/ttmemory.c +++ b/Driver/Font/TrueType/FreeType/ttmemory.c @@ -144,23 +144,50 @@ #else // ifdef __GEOS__ +/******************************************************************* + * + * Function : GEO_Alloc + * + * Description : Allocates movable/swappable memory from the heap buffer. + * + * Input : Size size of the memory to be allocated + * + * Output : Error code. + * + * NOTE : - The newly allocated block should _always_ be zeroed + * on return. Many parts of the engine rely on this to + * work properly. + * + ******************************************************************/ + EXPORT_FUNC MemHandle GEO_Alloc( UShort Size ) { - MemHandle memHandle; - - if ( Size > MAX_BLOCK_SIZE ) return NullHandle; if ( Size > 0 ) - memHandle = MemAllocSetOwner( GeodeGetCodeProcessHandle(), - Size, HF_SHARABLE | HF_SWAPABLE, HAF_ZERO_INIT ); + return MemAllocSetOwner( GeodeGetCodeProcessHandle(), + Size, HF_SHARABLE | HF_SWAPABLE, HAF_ZERO_INIT ); - return memHandle; + return NullHandle; } +/******************************************************************* + * + * Function : GEO_Free + * + * Description : Releases a previously allocated through GEO_Alloc + * block of memory. + * + * Input : memHandle handle to memory block + * + * Output : Always SUCCESS. + * + * Note : The handle must _always_ be set to NullHandle by this function. + * + ******************************************************************/ EXPORT_FUNC TT_Error GEO_Free( MemHandle* memHandle ) { @@ -168,7 +195,7 @@ return TT_Err_Ok; MemFree( memHandle ); - memHandle = NullHandle; + *memHandle = NullHandle; return TT_Err_Ok; } From 9e6798c30aab26528b76199721993b0a1dff9154 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Fri, 17 May 2024 22:02:52 +0200 Subject: [PATCH 03/37] Make glyphLocationBlock movable and swapable. --- Driver/Font/TrueType/FreeType/ttgload.c | 9 ++++++-- Driver/Font/TrueType/FreeType/ttload.c | 26 ++++++++++++++---------- Driver/Font/TrueType/FreeType/ttmemory.c | 11 +++++----- Driver/Font/TrueType/FreeType/ttmemory.h | 21 +++++++++++++++++-- Driver/Font/TrueType/FreeType/ttobjs.c | 4 +--- Driver/Font/TrueType/FreeType/ttobjs.h | 7 ++----- 6 files changed, 50 insertions(+), 28 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/ttgload.c b/Driver/Font/TrueType/FreeType/ttgload.c index 412593416..1267190aa 100644 --- a/Driver/Font/TrueType/FreeType/ttgload.c +++ b/Driver/Font/TrueType/FreeType/ttgload.c @@ -586,6 +586,8 @@ TPhases phase; PByte widths; + PStorage glyphLocations; + /* first of all, check arguments */ if ( !glyph ) @@ -725,8 +727,10 @@ case Load_Header: /* load glyph */ + glyphLocations = GEO_LOCK( face->glyphLocationBlock ); + if ( index + 1 < face->numLocations && - face->glyphLocations[index] == face->glyphLocations[index + 1] ) + glyphLocations[index] == glyphLocations[index + 1] ) { /* as described by Frederic Loyer, these are spaces, and */ /* not the unknown glyph. */ @@ -749,7 +753,8 @@ break; } - offset = glyph_offset + face->glyphLocations[index]; + offset = glyph_offset + glyphLocations[index]; + GEO_UNLOCK( face->glyphLocationBlock ); /* read first glyph header */ if ( FILE_Seek( offset ) || diff --git a/Driver/Font/TrueType/FreeType/ttload.c b/Driver/Font/TrueType/FreeType/ttload.c index 998592499..f42ff22a0 100644 --- a/Driver/Font/TrueType/FreeType/ttload.c +++ b/Driver/Font/TrueType/FreeType/ttload.c @@ -571,8 +571,9 @@ { DEFINE_LOCALS; - Short n, limit; - Short LongOffsets; + Short n, limit; + Short LongOffsets; + PStorage glyphLocations; LongOffsets = face->fontHeader.Index_To_Loc_Format; @@ -587,9 +588,9 @@ { face->numLocations = face->dirTables[n].Length >> 2; - if ( ALLOC_ARRAY( face->glyphLocations, - face->numLocations, - Long ) ) + if ( GEO_ALLOC_ARRAY( face->glyphLocationBlock, + face->numLocations, + Long )) return error; if ( ACCESS_Frame( face->numLocations * 4L ) ) @@ -597,18 +598,20 @@ limit = face->numLocations; + glyphLocations = GEO_LOCK( face->glyphLocationBlock ); for ( n = 0; n < limit; n++ ) - face->glyphLocations[n] = GET_Long(); + glyphLocations[n] = GET_Long(); + GEO_UNLOCK( face->glyphLocationBlock ); FORGET_Frame(); } else { face->numLocations = face->dirTables[n].Length >> 1; - if ( ALLOC_ARRAY( face->glyphLocations, - face->numLocations, - Long ) ) + if ( GEO_ALLOC_ARRAY( face->glyphLocationBlock, + face->numLocations, + Long )) return error; if ( ACCESS_Frame( face->numLocations * 2L ) ) @@ -616,10 +619,11 @@ limit = face->numLocations; + glyphLocations = GEO_LOCK( face->glyphLocationBlock ); for ( n = 0; n < limit; n++ ) - face->glyphLocations[n] = - (Long)((ULong)GET_UShort() * 2); + glyphLocations[n] = (Long)((ULong)GET_UShort() * 2); + GEO_UNLOCK( face->glyphLocationBlock ); FORGET_Frame(); } diff --git a/Driver/Font/TrueType/FreeType/ttmemory.c b/Driver/Font/TrueType/FreeType/ttmemory.c index c8d97673b..45c3744e1 100644 --- a/Driver/Font/TrueType/FreeType/ttmemory.c +++ b/Driver/Font/TrueType/FreeType/ttmemory.c @@ -151,6 +151,7 @@ * Description : Allocates movable/swappable memory from the heap buffer. * * Input : Size size of the memory to be allocated + * M pointer to memory handle * * Output : Error code. * @@ -161,16 +162,16 @@ ******************************************************************/ EXPORT_FUNC - MemHandle GEO_Alloc( UShort Size ) + TT_Error GEO_Alloc( UShort Size, MemHandle* M ) { if ( Size > MAX_BLOCK_SIZE ) - return NullHandle; + return TT_Err_Out_Of_Memory; if ( Size > 0 ) - return MemAllocSetOwner( GeodeGetCodeProcessHandle(), + *M = MemAllocSetOwner( GeodeGetCodeProcessHandle(), Size, HF_SHARABLE | HF_SWAPABLE, HAF_ZERO_INIT ); - return NullHandle; + return TT_Err_Ok; } @@ -194,7 +195,7 @@ if ( !memHandle ) return TT_Err_Ok; - MemFree( memHandle ); + MemFree( *memHandle ); *memHandle = NullHandle; return TT_Err_Ok; diff --git a/Driver/Font/TrueType/FreeType/ttmemory.h b/Driver/Font/TrueType/FreeType/ttmemory.h index 188e4f5cb..ee136d73d 100644 --- a/Driver/Font/TrueType/FreeType/ttmemory.h +++ b/Driver/Font/TrueType/FreeType/ttmemory.h @@ -88,12 +88,29 @@ TT_Error TT_Free( void** P ); + #define GEO_MEM_ALLOC( _memHandle_, _size_ ) \ + GEO_Alloc( _size_, (MemHandle*)&_memHandle_ ) + + #define GEO_ALLOC_ARRAY( _memHandle_, _count_, _type_ ) \ + ( ( error = GEO_MEM_ALLOC( _memHandle_, \ + (_count_) * sizeof ( _type_ ) ) ) != TT_Err_Ok ) + + #define GEO_FREE( _memHandle_ ) \ + GEO_Free( (MemHandle*)&_memHandle_ ) + + #define GEO_LOCK( _memHandle_ ) \ + MemLock( _memHandle_ ) + + #define GEO_UNLOCK( _memHandle_ ) \ + MemUnlock( _memHandle_ ) + + /* Allocate a movable and swapable block of memory of 'Size' bytes */ /* from the heap, and return its handle. If 'Size' is 0, or in */ /* case of error, the returned handle is always a NullHandle. */ EXPORT_DEF - MemHandle GEO_Alloc( UShort Size ); + TT_Error GEO_Alloc( UShort Size, MemHandle* M ); /* Releases a block that was previously allocated through GEO_Alloc. */ @@ -102,7 +119,7 @@ /* case of success. */ EXPORT_DEF - TT_Error GEO_Free( MemHandle* memHandle ); + TT_Error GEO_Free( MemHandle* memHandle ); LOCAL_DEF TT_Error TTMemory_Init( void ); diff --git a/Driver/Font/TrueType/FreeType/ttobjs.c b/Driver/Font/TrueType/FreeType/ttobjs.c index 2560cba2f..a9b016de6 100644 --- a/Driver/Font/TrueType/FreeType/ttobjs.c +++ b/Driver/Font/TrueType/FreeType/ttobjs.c @@ -1052,7 +1052,7 @@ face->numTables = 0; /* freeing the locations table */ - FREE( face->glyphLocations ); + GEO_FREE( face->glyphLocationBlock ); face->numLocations = 0; /* freeing the character mapping tables */ @@ -1094,8 +1094,6 @@ /* freeing the hdmx table */ Free_TrueType_Hdmx( face ); - /* TT_Close_Stream( &face->stream ); -- this is performed by the API */ - return TT_Err_Ok; } diff --git a/Driver/Font/TrueType/FreeType/ttobjs.h b/Driver/Font/TrueType/FreeType/ttobjs.h index 9845713f1..1baea6dfd 100644 --- a/Driver/Font/TrueType/FreeType/ttobjs.h +++ b/Driver/Font/TrueType/FreeType/ttobjs.h @@ -23,6 +23,7 @@ #include "ttcache.h" #include "tttables.h" #include "ttcmap.h" +#include #ifdef __cplusplus extern "C" { @@ -521,11 +522,7 @@ /* The glyph locations table */ ULong numLocations; /* UShort is not enough */ -#ifndef TT_HUGE_PTR - PStorage glyphLocations; -#else - Storage TT_HUGE_PTR * glyphLocations; -#endif + MemHandle glyphLocationBlock; /* NOTE : The "hmtx" is now part of the horizontal header */ From e7f4eaecfe81dc216273ce22b37496bf7162cc0d Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Sun, 19 May 2024 10:43:53 +0200 Subject: [PATCH 04/37] engineInstance is always present, it does not need to checked. --- Driver/Font/TrueType/FreeType/ttapi.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/ttapi.c b/Driver/Font/TrueType/FreeType/ttapi.c index 5ba5d4d7f..6352c47c9 100644 --- a/Driver/Font/TrueType/FreeType/ttapi.c +++ b/Driver/Font/TrueType/FreeType/ttapi.c @@ -144,9 +144,6 @@ extern TEngine_Instance engineInstance; PEngine_Instance _engine = &engineInstance; - if ( !_engine ) - return TT_Err_Ok; - TTRaster_Done( _engine ); TTObjs_Done ( _engine ); #ifdef TT_CONFIG_OPTION_EXTEND_ENGINE @@ -190,9 +187,6 @@ extern TEngine_Instance engineInstance; PFace _face; - if ( !_engine ) - return TT_Err_Invalid_Engine; - /* open the file */ error = TT_Open_Stream( file, &stream ); if ( error ) @@ -1308,9 +1302,6 @@ extern TEngine_Instance engineInstance; PEngine_Instance _engine = &engineInstance; - if ( !_engine ) - return TT_Err_Invalid_Engine; - if ( !outline || !map ) return TT_Err_Invalid_Argument; @@ -1342,9 +1333,6 @@ TT_Error TT_Get_Outline_Region( TT_Outline* outline, PEngine_Instance _engine = &engineInstance; - if ( !_engine ) - return TT_Err_Invalid_Engine; - if ( !outline || !map ) return TT_Err_Invalid_Argument; From f7ae14d68ec9f1c2c5c7dd64cfe94773907b9cbc Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Wed, 22 May 2024 23:42:04 +0200 Subject: [PATCH 05/37] Debugging vars removed. --- Driver/Font/TrueType/FreeType/ttgload.c | 8 ++--- Driver/Font/TrueType/FreeType/ttobjs.c | 30 ++++--------------- Driver/Font/TrueType/FreeType/ttobjs.h | 11 +------ .../Driver/Font/TrueType/dependencies.mk | 5 ++-- 4 files changed, 11 insertions(+), 43 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/ttgload.c b/Driver/Font/TrueType/FreeType/ttgload.c index 1267190aa..93ede7dd6 100644 --- a/Driver/Font/TrueType/FreeType/ttgload.c +++ b/Driver/Font/TrueType/FreeType/ttgload.c @@ -614,10 +614,7 @@ /* query new execution context */ - if ( instance && instance->debug ) - exec = instance->context; - else - exec = New_Context( face ); + exec = New_Context( face ); if ( !exec ) return TT_Err_Could_Not_Find_Context; @@ -1262,8 +1259,7 @@ /* reset the execution context */ exec->pts = base_pts; - if ( !instance || !instance->debug ) - Done_Context( exec ); + Done_Context( exec ); return error; } diff --git a/Driver/Font/TrueType/FreeType/ttobjs.c b/Driver/Font/TrueType/FreeType/ttobjs.c index a9b016de6..c8fd9920e 100644 --- a/Driver/Font/TrueType/FreeType/ttobjs.c +++ b/Driver/Font/TrueType/FreeType/ttobjs.c @@ -658,13 +658,6 @@ if ( !_instance ) return TT_Err_Ok; - if ( ins->debug ) - { - /* the debug context must be deleted by the debugger itself */ - ins->context = NULL; - ins->debug = FALSE; - } - FREE( ins->cvt ); ins->cvtSize = 0; @@ -789,11 +782,7 @@ PFace face = ins->owner; - if ( ins->debug ) - exec = ins->context; - else - exec = New_Context( face ); - /* debugging instances have their own context */ + exec = New_Context( face ); if ( !exec ) return TT_Err_Could_Not_Find_Context; @@ -863,9 +852,7 @@ Fin: Context_Save( exec, ins ); - if ( !ins->debug ) - Done_Context( exec ); - /* debugging instances keep their context */ + Done_Context( exec ); ins->valid = FALSE; @@ -956,11 +943,7 @@ /* get execution context and run prep program */ - if ( ins->debug ) - exec = ins->context; - else - exec = New_Context(face); - /* debugging instances have their own context */ + exec = New_Context(face); if ( !exec ) return TT_Err_Could_Not_Find_Context; @@ -985,8 +968,7 @@ if ( error ) goto Fin; - if ( !ins->debug ) - error = RunIns( exec ); + error = RunIns( exec ); } else error = TT_Err_Ok; @@ -997,9 +979,7 @@ Fin: Context_Save( exec, ins ); - if ( !ins->debug ) - Done_Context( exec ); - /* debugging instances keep their context */ + Done_Context( exec ); if ( !error ) ins->valid = TRUE; diff --git a/Driver/Font/TrueType/FreeType/ttobjs.h b/Driver/Font/TrueType/FreeType/ttobjs.h index 1baea6dfd..621b0be88 100644 --- a/Driver/Font/TrueType/FreeType/ttobjs.h +++ b/Driver/Font/TrueType/FreeType/ttobjs.h @@ -23,7 +23,7 @@ #include "ttcache.h" #include "tttables.h" #include "ttcmap.h" -#include +#include #ifdef __cplusplus extern "C" { @@ -603,15 +603,6 @@ PLong storage; /* instance */ TGlyph_Zone twilight; /* The instance's twilight zone */ - - /* debugging variables */ - - /* When using the debugger, we must keep the */ - /* execution context tied to the instance */ - /* object rather than asking it on demand */ - - Bool debug; - PExecution_Context context; }; diff --git a/Installed/Driver/Font/TrueType/dependencies.mk b/Installed/Driver/Font/TrueType/dependencies.mk index 024699079..a99802f5d 100644 --- a/Installed/Driver/Font/TrueType/dependencies.mk +++ b/Installed/Driver/Font/TrueType/dependencies.mk @@ -69,7 +69,8 @@ ttadapter.eobj: Adapter/ttadapter.h geos.h ec.h fontID.h file.h graphics.h \ Adapter/../FreeType/tttypes.h \ Adapter/../FreeType/ttconfig.h \ Adapter/../FreeType/ft_conf.h resource.h heap.h lmem.h \ - Ansi/stdlib.h Adapter/../FreeType/ttcalc.h geode.h + Ansi/stdlib.h Adapter/../FreeType/ttcalc.h \ + Adapter/ttcharmapper.h FreeType/freetype.h geode.h ttwidths.obj \ ttwidths.eobj: geos.h ec.h unicode.h graphics.h fontID.h font.h color.h \ heap.h Adapter/ttwidths.h Adapter/../FreeType/freetype.h \ @@ -94,7 +95,7 @@ ttpath.eobj: Adapter/ttadapter.h geos.h ec.h fontID.h file.h graphics.h \ Adapter/../FreeType/ft_conf.h resource.h heap.h lmem.h \ Ansi/stdlib.h Adapter/../FreeType/ttcalc.h \ Adapter/ttpath.h Adapter/ttcharmapper.h \ - FreeType/freetype.h + FreeType/freetype.h win.h ttcache.obj \ ttcache.eobj: FreeType/ttengine.h FreeType/tttypes.h FreeType/ttconfig.h \ FreeType/ft_conf.h geos.h file.h resource.h graphics.h \ From 0ccfd571b2e52b2dace6a7b843073d7615841cc3 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Thu, 30 May 2024 21:43:25 +0200 Subject: [PATCH 06/37] Revert "Debugging vars removed." This reverts commit f7ae14d68ec9f1c2c5c7dd64cfe94773907b9cbc. --- Driver/Font/TrueType/FreeType/ttgload.c | 8 +++-- Driver/Font/TrueType/FreeType/ttobjs.c | 30 +++++++++++++++---- Driver/Font/TrueType/FreeType/ttobjs.h | 11 ++++++- .../Driver/Font/TrueType/dependencies.mk | 5 ++-- 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/ttgload.c b/Driver/Font/TrueType/FreeType/ttgload.c index 93ede7dd6..1267190aa 100644 --- a/Driver/Font/TrueType/FreeType/ttgload.c +++ b/Driver/Font/TrueType/FreeType/ttgload.c @@ -614,7 +614,10 @@ /* query new execution context */ - exec = New_Context( face ); + if ( instance && instance->debug ) + exec = instance->context; + else + exec = New_Context( face ); if ( !exec ) return TT_Err_Could_Not_Find_Context; @@ -1259,7 +1262,8 @@ /* reset the execution context */ exec->pts = base_pts; - Done_Context( exec ); + if ( !instance || !instance->debug ) + Done_Context( exec ); return error; } diff --git a/Driver/Font/TrueType/FreeType/ttobjs.c b/Driver/Font/TrueType/FreeType/ttobjs.c index c8fd9920e..a9b016de6 100644 --- a/Driver/Font/TrueType/FreeType/ttobjs.c +++ b/Driver/Font/TrueType/FreeType/ttobjs.c @@ -658,6 +658,13 @@ if ( !_instance ) return TT_Err_Ok; + if ( ins->debug ) + { + /* the debug context must be deleted by the debugger itself */ + ins->context = NULL; + ins->debug = FALSE; + } + FREE( ins->cvt ); ins->cvtSize = 0; @@ -782,7 +789,11 @@ PFace face = ins->owner; - exec = New_Context( face ); + if ( ins->debug ) + exec = ins->context; + else + exec = New_Context( face ); + /* debugging instances have their own context */ if ( !exec ) return TT_Err_Could_Not_Find_Context; @@ -852,7 +863,9 @@ Fin: Context_Save( exec, ins ); - Done_Context( exec ); + if ( !ins->debug ) + Done_Context( exec ); + /* debugging instances keep their context */ ins->valid = FALSE; @@ -943,7 +956,11 @@ /* get execution context and run prep program */ - exec = New_Context(face); + if ( ins->debug ) + exec = ins->context; + else + exec = New_Context(face); + /* debugging instances have their own context */ if ( !exec ) return TT_Err_Could_Not_Find_Context; @@ -968,7 +985,8 @@ if ( error ) goto Fin; - error = RunIns( exec ); + if ( !ins->debug ) + error = RunIns( exec ); } else error = TT_Err_Ok; @@ -979,7 +997,9 @@ Fin: Context_Save( exec, ins ); - Done_Context( exec ); + if ( !ins->debug ) + Done_Context( exec ); + /* debugging instances keep their context */ if ( !error ) ins->valid = TRUE; diff --git a/Driver/Font/TrueType/FreeType/ttobjs.h b/Driver/Font/TrueType/FreeType/ttobjs.h index 621b0be88..1baea6dfd 100644 --- a/Driver/Font/TrueType/FreeType/ttobjs.h +++ b/Driver/Font/TrueType/FreeType/ttobjs.h @@ -23,7 +23,7 @@ #include "ttcache.h" #include "tttables.h" #include "ttcmap.h" -#include +#include #ifdef __cplusplus extern "C" { @@ -603,6 +603,15 @@ PLong storage; /* instance */ TGlyph_Zone twilight; /* The instance's twilight zone */ + + /* debugging variables */ + + /* When using the debugger, we must keep the */ + /* execution context tied to the instance */ + /* object rather than asking it on demand */ + + Bool debug; + PExecution_Context context; }; diff --git a/Installed/Driver/Font/TrueType/dependencies.mk b/Installed/Driver/Font/TrueType/dependencies.mk index a99802f5d..024699079 100644 --- a/Installed/Driver/Font/TrueType/dependencies.mk +++ b/Installed/Driver/Font/TrueType/dependencies.mk @@ -69,8 +69,7 @@ ttadapter.eobj: Adapter/ttadapter.h geos.h ec.h fontID.h file.h graphics.h \ Adapter/../FreeType/tttypes.h \ Adapter/../FreeType/ttconfig.h \ Adapter/../FreeType/ft_conf.h resource.h heap.h lmem.h \ - Ansi/stdlib.h Adapter/../FreeType/ttcalc.h \ - Adapter/ttcharmapper.h FreeType/freetype.h geode.h + Ansi/stdlib.h Adapter/../FreeType/ttcalc.h geode.h ttwidths.obj \ ttwidths.eobj: geos.h ec.h unicode.h graphics.h fontID.h font.h color.h \ heap.h Adapter/ttwidths.h Adapter/../FreeType/freetype.h \ @@ -95,7 +94,7 @@ ttpath.eobj: Adapter/ttadapter.h geos.h ec.h fontID.h file.h graphics.h \ Adapter/../FreeType/ft_conf.h resource.h heap.h lmem.h \ Ansi/stdlib.h Adapter/../FreeType/ttcalc.h \ Adapter/ttpath.h Adapter/ttcharmapper.h \ - FreeType/freetype.h win.h + FreeType/freetype.h ttcache.obj \ ttcache.eobj: FreeType/ttengine.h FreeType/tttypes.h FreeType/ttconfig.h \ FreeType/ft_conf.h geos.h file.h resource.h graphics.h \ From 3db80066b484b535c92817ae2595751baa8e2ccb Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Thu, 30 May 2024 22:08:36 +0200 Subject: [PATCH 07/37] Hdmx processing disabled. --- Driver/Font/TrueType/FreeType/freetype.h | 4 ++++ Driver/Font/TrueType/FreeType/ft_conf.h | 8 ++++++++ Driver/Font/TrueType/FreeType/ttapi.c | 3 +++ Driver/Font/TrueType/FreeType/ttgload.c | 4 ++++ Driver/Font/TrueType/FreeType/ttload.c | 2 ++ Driver/Font/TrueType/FreeType/ttobjs.c | 10 ++++++++-- Driver/Font/TrueType/FreeType/ttobjs.h | 2 ++ Installed/Driver/Font/TrueType/dependencies.mk | 5 +++-- 8 files changed, 34 insertions(+), 4 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/freetype.h b/Driver/Font/TrueType/FreeType/freetype.h index a184b9fe1..6ad3ac14c 100644 --- a/Driver/Font/TrueType/FreeType/freetype.h +++ b/Driver/Font/TrueType/FreeType/freetype.h @@ -565,7 +565,11 @@ TT_Horizontal_Header* horizontal; /* TrueType horizontal header */ TT_OS2* os2; /* TrueType OS/2 table */ TT_Postscript* postscript; /* TrueType Postscript table */ + +#ifdef TT_CONFIG_OPTION_PROCESS_HDMX TT_Hdmx* hdmx; /* TrueType hor. dev. metr. table */ +#endif + TT_Vertical_Header* vertical; /* TT Vertical header, if present */ }; diff --git a/Driver/Font/TrueType/FreeType/ft_conf.h b/Driver/Font/TrueType/FreeType/ft_conf.h index e60fe12a5..f56d2ccde 100644 --- a/Driver/Font/TrueType/FreeType/ft_conf.h +++ b/Driver/Font/TrueType/FreeType/ft_conf.h @@ -158,6 +158,14 @@ #define TT_CONFIG_OPTION_THREAD_SAFE +/*************************************************************************/ +/* Define TT_CONFIG_OPTION_PROCESS_HDMX if you want to process optional */ +/* hdmx table. The PC/Geos ttf driver does not need any information from */ +/* the htmx table. */ + +#undef TT_CONFIG_OPTION_PROCESS_HDMX + + /**********************************************************************/ /* */ /* The following macros are used to define the debug level, as well */ diff --git a/Driver/Font/TrueType/FreeType/ttapi.c b/Driver/Font/TrueType/FreeType/ttapi.c index 6352c47c9..d2570c6e8 100644 --- a/Driver/Font/TrueType/FreeType/ttapi.c +++ b/Driver/Font/TrueType/FreeType/ttapi.c @@ -257,7 +257,10 @@ extern TEngine_Instance engineInstance; properties->os2 = &_face->os2; properties->postscript = &_face->postscript; + + #ifdef TT_CONFIG_OPTION_PROCESS_HDMX properties->hdmx = &_face->hdmx; + #endif return TT_Err_Ok; } diff --git a/Driver/Font/TrueType/FreeType/ttgload.c b/Driver/Font/TrueType/FreeType/ttgload.c index 1267190aa..384229d60 100644 --- a/Driver/Font/TrueType/FreeType/ttgload.c +++ b/Driver/Font/TrueType/FreeType/ttgload.c @@ -99,6 +99,7 @@ } +#ifdef TT_CONFIG_OPTION_PROCESS_HDMX /********************************************************/ /* Return advance width table for a given pixel size */ /* if it is found in the font's `hdmx' table (if any). */ @@ -115,6 +116,7 @@ return NULL; } +#endif /********************************************************/ @@ -1239,6 +1241,7 @@ glyph->metrics.vertAdvance = advance; } +#ifdef TT_CONFIG_OPTION_PROCESS_HDMX /* Adjust advance width to the value contained in the hdmx table. */ if ( !exec->face->postscript.isFixedPitch && instance && subglyph->is_hinted ) @@ -1248,6 +1251,7 @@ if ( widths ) glyph->metrics.horiAdvance = widths[glyph_index] << 6; } +#endif glyph->outline.dropout_mode = (Char)exec->GS.scan_type; diff --git a/Driver/Font/TrueType/FreeType/ttload.c b/Driver/Font/TrueType/FreeType/ttload.c index f42ff22a0..96368d0dc 100644 --- a/Driver/Font/TrueType/FreeType/ttload.c +++ b/Driver/Font/TrueType/FreeType/ttload.c @@ -1121,6 +1121,7 @@ } +#ifdef TT_CONFIG_OPTION_PROCESS_HDMX /******************************************************************* * * Function : Load_TrueType_Hdmx @@ -1242,6 +1243,7 @@ return TT_Err_Ok; } +#endif /******************************************************************* diff --git a/Driver/Font/TrueType/FreeType/ttobjs.c b/Driver/Font/TrueType/FreeType/ttobjs.c index a9b016de6..f0abbcc35 100644 --- a/Driver/Font/TrueType/FreeType/ttobjs.c +++ b/Driver/Font/TrueType/FreeType/ttobjs.c @@ -1091,8 +1091,10 @@ /* freeing the name table */ Free_TrueType_Names( face ); +#ifdef TT_CONFIG_OPTION_PROCESS_HDMX /* freeing the hdmx table */ Free_TrueType_Hdmx( face ); +#endif return TT_Err_Ok; } @@ -1166,10 +1168,14 @@ LOAD_( OS2 ) || LOAD_( PostScript ) || - (error = Load_TrueType_Metrics_Header( face, 1 )) != TT_Err_Ok || + (error = Load_TrueType_Metrics_Header( face, 1 )) != TT_Err_Ok /* try to load the 'vhea' & 'vmtx' at once if present */ - LOAD_( Hdmx ) ) +#ifdef TT_CONFIG_OPTION_PROCESS_HDMX + || LOAD_( Hdmx ) +#endif + + ) goto Fail; diff --git a/Driver/Font/TrueType/FreeType/ttobjs.h b/Driver/Font/TrueType/FreeType/ttobjs.h index 1baea6dfd..804d77b19 100644 --- a/Driver/Font/TrueType/FreeType/ttobjs.h +++ b/Driver/Font/TrueType/FreeType/ttobjs.h @@ -505,7 +505,9 @@ TT_Postscript postscript; /* 'Post' table */ +#ifdef TT_CONFIG_OPTION_PROCESS_HDMX TT_Hdmx hdmx; /* 'Hdmx' table */ +#endif TName_Table nameTable; /* name table */ diff --git a/Installed/Driver/Font/TrueType/dependencies.mk b/Installed/Driver/Font/TrueType/dependencies.mk index 024699079..a99802f5d 100644 --- a/Installed/Driver/Font/TrueType/dependencies.mk +++ b/Installed/Driver/Font/TrueType/dependencies.mk @@ -69,7 +69,8 @@ ttadapter.eobj: Adapter/ttadapter.h geos.h ec.h fontID.h file.h graphics.h \ Adapter/../FreeType/tttypes.h \ Adapter/../FreeType/ttconfig.h \ Adapter/../FreeType/ft_conf.h resource.h heap.h lmem.h \ - Ansi/stdlib.h Adapter/../FreeType/ttcalc.h geode.h + Ansi/stdlib.h Adapter/../FreeType/ttcalc.h \ + Adapter/ttcharmapper.h FreeType/freetype.h geode.h ttwidths.obj \ ttwidths.eobj: geos.h ec.h unicode.h graphics.h fontID.h font.h color.h \ heap.h Adapter/ttwidths.h Adapter/../FreeType/freetype.h \ @@ -94,7 +95,7 @@ ttpath.eobj: Adapter/ttadapter.h geos.h ec.h fontID.h file.h graphics.h \ Adapter/../FreeType/ft_conf.h resource.h heap.h lmem.h \ Ansi/stdlib.h Adapter/../FreeType/ttcalc.h \ Adapter/ttpath.h Adapter/ttcharmapper.h \ - FreeType/freetype.h + FreeType/freetype.h win.h ttcache.obj \ ttcache.eobj: FreeType/ttengine.h FreeType/tttypes.h FreeType/ttconfig.h \ FreeType/ft_conf.h geos.h file.h resource.h graphics.h \ From 86d1870efa2dcd83e062977d0a6437ce9bbbce79 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Thu, 30 May 2024 22:17:56 +0200 Subject: [PATCH 08/37] Debugging variables removed. --- Driver/Font/TrueType/FreeType/ttgload.c | 9 ++------- Driver/Font/TrueType/FreeType/ttobjs.c | 25 +++++-------------------- Driver/Font/TrueType/FreeType/ttobjs.h | 9 --------- 3 files changed, 7 insertions(+), 36 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/ttgload.c b/Driver/Font/TrueType/FreeType/ttgload.c index 384229d60..f74e5b758 100644 --- a/Driver/Font/TrueType/FreeType/ttgload.c +++ b/Driver/Font/TrueType/FreeType/ttgload.c @@ -615,11 +615,7 @@ glyph_offset = face->dirTables[table].Offset; /* query new execution context */ - - if ( instance && instance->debug ) - exec = instance->context; - else - exec = New_Context( face ); + exec = New_Context( face ); if ( !exec ) return TT_Err_Could_Not_Find_Context; @@ -1266,8 +1262,7 @@ /* reset the execution context */ exec->pts = base_pts; - if ( !instance || !instance->debug ) - Done_Context( exec ); + Done_Context( exec ); return error; } diff --git a/Driver/Font/TrueType/FreeType/ttobjs.c b/Driver/Font/TrueType/FreeType/ttobjs.c index f0abbcc35..d9dd39ddf 100644 --- a/Driver/Font/TrueType/FreeType/ttobjs.c +++ b/Driver/Font/TrueType/FreeType/ttobjs.c @@ -658,12 +658,6 @@ if ( !_instance ) return TT_Err_Ok; - if ( ins->debug ) - { - /* the debug context must be deleted by the debugger itself */ - ins->context = NULL; - ins->debug = FALSE; - } FREE( ins->cvt ); ins->cvtSize = 0; @@ -789,10 +783,7 @@ PFace face = ins->owner; - if ( ins->debug ) - exec = ins->context; - else - exec = New_Context( face ); + exec = New_Context( face ); /* debugging instances have their own context */ if ( !exec ) @@ -863,8 +854,7 @@ Fin: Context_Save( exec, ins ); - if ( !ins->debug ) - Done_Context( exec ); + Done_Context( exec ); /* debugging instances keep their context */ ins->valid = FALSE; @@ -956,10 +946,7 @@ /* get execution context and run prep program */ - if ( ins->debug ) - exec = ins->context; - else - exec = New_Context(face); + exec = New_Context(face); /* debugging instances have their own context */ if ( !exec ) @@ -985,8 +972,7 @@ if ( error ) goto Fin; - if ( !ins->debug ) - error = RunIns( exec ); + error = RunIns( exec ); } else error = TT_Err_Ok; @@ -997,8 +983,7 @@ Fin: Context_Save( exec, ins ); - if ( !ins->debug ) - Done_Context( exec ); + Done_Context( exec ); /* debugging instances keep their context */ if ( !error ) diff --git a/Driver/Font/TrueType/FreeType/ttobjs.h b/Driver/Font/TrueType/FreeType/ttobjs.h index 804d77b19..f49023f35 100644 --- a/Driver/Font/TrueType/FreeType/ttobjs.h +++ b/Driver/Font/TrueType/FreeType/ttobjs.h @@ -605,15 +605,6 @@ PLong storage; /* instance */ TGlyph_Zone twilight; /* The instance's twilight zone */ - - /* debugging variables */ - - /* When using the debugger, we must keep the */ - /* execution context tied to the instance */ - /* object rather than asking it on demand */ - - Bool debug; - PExecution_Context context; }; From 5b2f840665da5f47e311a0147d115e779fdab4d6 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Thu, 30 May 2024 22:31:11 +0200 Subject: [PATCH 09/37] Another debugging variable removed. --- Driver/Font/TrueType/FreeType/ttgload.c | 4 ++-- Driver/Font/TrueType/FreeType/ttload.c | 4 ++-- Driver/Font/TrueType/FreeType/ttobjs.c | 8 ++------ Driver/Font/TrueType/FreeType/ttobjs.h | 3 +-- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/ttgload.c b/Driver/Font/TrueType/FreeType/ttgload.c index f74e5b758..4d695c1ef 100644 --- a/Driver/Font/TrueType/FreeType/ttgload.c +++ b/Driver/Font/TrueType/FreeType/ttgload.c @@ -382,7 +382,7 @@ exec->is_composite = FALSE; exec->pedantic_hinting = load_flags & TTLOAD_PEDANTIC; - error = Context_Run( exec, FALSE ); + error = Context_Run( exec ); if (error && exec->pedantic_hinting) return error; } @@ -482,7 +482,7 @@ exec->is_composite = TRUE; exec->pedantic_hinting = load_flags & TTLOAD_PEDANTIC; - error = Context_Run( exec, FALSE ); + error = Context_Run( exec ); if (error && exec->pedantic_hinting) return error; } diff --git a/Driver/Font/TrueType/FreeType/ttload.c b/Driver/Font/TrueType/FreeType/ttload.c index 96368d0dc..e52b4d12e 100644 --- a/Driver/Font/TrueType/FreeType/ttload.c +++ b/Driver/Font/TrueType/FreeType/ttload.c @@ -599,7 +599,7 @@ limit = face->numLocations; glyphLocations = GEO_LOCK( face->glyphLocationBlock ); - for ( n = 0; n < limit; n++ ) + for ( n = 0; n < limit; ++n ) glyphLocations[n] = GET_Long(); GEO_UNLOCK( face->glyphLocationBlock ); @@ -620,7 +620,7 @@ limit = face->numLocations; glyphLocations = GEO_LOCK( face->glyphLocationBlock ); - for ( n = 0; n < limit; n++ ) + for ( n = 0; n < limit; ++n ) glyphLocations[n] = (Long)((ULong)GET_UShort() * 2); GEO_UNLOCK( face->glyphLocationBlock ); diff --git a/Driver/Font/TrueType/FreeType/ttobjs.c b/Driver/Font/TrueType/FreeType/ttobjs.c index d9dd39ddf..5ac407a0d 100644 --- a/Driver/Font/TrueType/FreeType/ttobjs.c +++ b/Driver/Font/TrueType/FreeType/ttobjs.c @@ -577,8 +577,7 @@ *****************************************************************/ LOCAL_FUNC - TT_Error Context_Run( PExecution_Context exec, - Bool debug ) + TT_Error Context_Run( PExecution_Context exec ) { TT_Error error; @@ -609,10 +608,7 @@ exec->top = 0; exec->callTop = 0; - if ( !debug ) - return RunIns( exec ); - else - return TT_Err_Ok; + return RunIns( exec ); } diff --git a/Driver/Font/TrueType/FreeType/ttobjs.h b/Driver/Font/TrueType/FreeType/ttobjs.h index f49023f35..23257cea2 100644 --- a/Driver/Font/TrueType/FreeType/ttobjs.h +++ b/Driver/Font/TrueType/FreeType/ttobjs.h @@ -803,8 +803,7 @@ PInstance ins ); LOCAL_DEF - TT_Error Context_Run( PExecution_Context exec, - Bool debug ); + TT_Error Context_Run( PExecution_Context exec ); LOCAL_DEF TT_Error Instance_Init( PInstance ins ); From 4b8b52b9f7c6552bc7fbfaf07ae434febdd9cfd8 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Mon, 3 Jun 2024 21:34:27 +0200 Subject: [PATCH 10/37] Move cmap4 table from fixed to movable resource. --- Driver/Font/TrueType/FreeType/ttcmap.c | 54 ++++++++++++------------ Driver/Font/TrueType/FreeType/ttcmap.h | 2 +- Driver/Font/TrueType/FreeType/ttgload.c | 1 + Driver/Font/TrueType/FreeType/ttmemory.c | 2 +- 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/ttcmap.c b/Driver/Font/TrueType/FreeType/ttcmap.c index 9f0b9b182..9a56f5455 100644 --- a/Driver/Font/TrueType/FreeType/ttcmap.c +++ b/Driver/Font/TrueType/FreeType/ttcmap.c @@ -157,28 +157,29 @@ /* load segments */ - if ( ALLOC_ARRAY( cmap4->segments, - num_Seg, - TCMap4Segment ) || + if ( GEO_ALLOC_ARRAY( cmap4->segmentBlock, + num_Seg, + TCMap4Segment ) || ACCESS_Frame( (num_Seg * 4 + 1) * 2L ) ) goto Fail; - segments = cmap4->segments; + segments = GEO_LOCK( cmap4->segmentBlock ); - for ( i = 0; i < num_Seg; i++ ) + for ( i = 0; i < num_Seg; ++i ) segments[i].endCount = GET_UShort(); (void)GET_UShort(); - for ( i = 0; i < num_Seg; i++ ) + for ( i = 0; i < num_Seg; ++i ) segments[i].startCount = GET_UShort(); - for ( i = 0; i < num_Seg; i++ ) + for ( i = 0; i < num_Seg; ++i ) segments[i].idDelta = GET_Short(); - for ( i = 0; i < num_Seg; i++ ) + for ( i = 0; i < num_Seg; ++i ) segments[i].idRangeOffset = GET_UShort(); + GEO_UNLOCK( cmap4->segmentBlock ); FORGET_Frame(); cmap4->numGlyphId = l = @@ -190,7 +191,7 @@ ACCESS_Frame( l * 2L ) ) goto Fail; - for ( i = 0; i < l; i++ ) + for ( i = 0; i < l; ++i ) cmap4->glyphIdArray[i] = GET_UShort(); FORGET_Frame(); @@ -264,7 +265,7 @@ break; case 4: - FREE( cmap->c.cmap4.segments ); + GEO_FREE( cmap->c.cmap4.segmentBlock ); FREE( cmap->c.cmap4.glyphIdArray ); cmap->c.cmap4.segCountX2 = 0; break; @@ -427,42 +428,43 @@ PCMap4 cmap4 ) { UShort index1, segCount; - UShort i; + UShort i, result; TCMap4Segment seg4; + PCMap4Segment segments; segCount = cmap4->segCountX2 / 2; + segments = GEO_LOCK( cmap4->segmentBlock ); + result = 0; - for ( i = 0; i < segCount; i++ ) - if ( charCode <= cmap4->segments[i].endCount ) + for ( i = 0; i < segCount; ++i ) + if ( charCode <= segments[i].endCount ) break; /* Safety check - even though the last endCount should be 0xFFFF */ - if ( i >= segCount ) - return 0; + if ( i >= segCount ) + goto Fin; - seg4 = cmap4->segments[i]; + seg4 = segments[i]; if ( charCode < seg4.startCount ) - return 0; + goto Fin; if ( seg4.idRangeOffset == 0 ) - return ( charCode + seg4.idDelta ) & 0xFFFF; + result = ( charCode + seg4.idDelta ) & 0xFFFF; else { index1 = seg4.idRangeOffset / 2 + (charCode - seg4.startCount) - (segCount - i); if ( index1 < cmap4->numGlyphId ) - { - if ( cmap4->glyphIdArray[index1] == 0 ) - return 0; - else - return ( cmap4->glyphIdArray[index1] + seg4.idDelta ) & 0xFFFF; - } - else - return 0; + if ( cmap4->glyphIdArray[index1] != 0 ) + result = ( cmap4->glyphIdArray[index1] + seg4.idDelta ) & 0xFFFF; } + + Fin: + GEO_UNLOCK( cmap4->segmentBlock ); + return result; } diff --git a/Driver/Font/TrueType/FreeType/ttcmap.h b/Driver/Font/TrueType/FreeType/ttcmap.h index 43ca7887c..9fd64f3a5 100644 --- a/Driver/Font/TrueType/FreeType/ttcmap.h +++ b/Driver/Font/TrueType/FreeType/ttcmap.h @@ -87,7 +87,7 @@ UShort entrySelector; /* for a binary search */ UShort rangeShift; - PCMap4Segment segments; + MemHandle segmentBlock; PUShort glyphIdArray; UShort numGlyphId; /* control value */ }; diff --git a/Driver/Font/TrueType/FreeType/ttgload.c b/Driver/Font/TrueType/FreeType/ttgload.c index 4d695c1ef..ffd1f99f6 100644 --- a/Driver/Font/TrueType/FreeType/ttgload.c +++ b/Driver/Font/TrueType/FreeType/ttgload.c @@ -748,6 +748,7 @@ exec->glyphSize = 0; phase = Load_End; + GEO_UNLOCK( face->glyphLocationBlock ); break; } diff --git a/Driver/Font/TrueType/FreeType/ttmemory.c b/Driver/Font/TrueType/FreeType/ttmemory.c index 45c3744e1..5366f485b 100644 --- a/Driver/Font/TrueType/FreeType/ttmemory.c +++ b/Driver/Font/TrueType/FreeType/ttmemory.c @@ -192,7 +192,7 @@ EXPORT_FUNC TT_Error GEO_Free( MemHandle* memHandle ) { - if ( !memHandle ) + if ( *memHandle == NullHandle ) return TT_Err_Ok; MemFree( *memHandle ); From cf22ee6fc142b71ac1898cba1f56c8aef3a13891 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Thu, 6 Jun 2024 21:48:40 +0200 Subject: [PATCH 11/37] Memory blocks can be up to 64kb in size, multiple size parameters are resized accordingly. --- Driver/Font/TrueType/FreeType/ftxkern.c | 18 +++++------ Driver/Font/TrueType/FreeType/ttcmap.c | 18 +++++------ Driver/Font/TrueType/FreeType/ttfile.c | 12 ++++---- Driver/Font/TrueType/FreeType/ttfile.h | 8 ++--- Driver/Font/TrueType/FreeType/ttgload.c | 8 ++--- Driver/Font/TrueType/FreeType/ttload.c | 41 ++++++++++++------------- Driver/Font/TrueType/FreeType/ttload.h | 12 ++++---- 7 files changed, 58 insertions(+), 59 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/ftxkern.c b/Driver/Font/TrueType/FreeType/ftxkern.c index e519c3869..49b0f3c3a 100644 --- a/Driver/Font/TrueType/FreeType/ftxkern.c +++ b/Driver/Font/TrueType/FreeType/ftxkern.c @@ -66,7 +66,7 @@ extern TEngine_Instance engineInstance; UShort num_pairs, n; - if ( ACCESS_Frame( 8L ) ) + if ( ACCESS_Frame( 8 ) ) return error; num_pairs = GET_UShort(); @@ -82,7 +82,7 @@ extern TEngine_Instance engineInstance; if ( ALLOC_ARRAY( kern0->pairs, num_pairs, TT_Kern_0_Pair ) ) return error; - if ( ACCESS_Frame( num_pairs * 6L ) ) + if ( ACCESS_Frame( num_pairs * 6 ) ) goto Fail; for ( n = 0; n < num_pairs; n++ ) @@ -150,7 +150,7 @@ extern TEngine_Instance engineInstance; /* record the table offset */ table_base = FILE_Pos(); - if ( ACCESS_Frame( 8L ) ) + if ( ACCESS_Frame( 8 ) ) return error; kern2->rowWidth = GET_UShort(); @@ -163,7 +163,7 @@ extern TEngine_Instance engineInstance; /* first load left and right glyph classes */ if ( FILE_Seek( table_base + left_offset ) || - ACCESS_Frame( 4L ) ) + ACCESS_Frame( 4 ) ) return error; kern2->leftClass.firstGlyph = GET_UShort(); @@ -178,7 +178,7 @@ extern TEngine_Instance engineInstance; /* load left offsets */ - if ( ACCESS_Frame( kern2->leftClass.nGlyphs * 2L ) ) + if ( ACCESS_Frame( kern2->leftClass.nGlyphs << 1 ) ) goto Fail_Left; for ( n = 0; n < kern2->leftClass.nGlyphs; n++ ) @@ -189,7 +189,7 @@ extern TEngine_Instance engineInstance; /* right class */ if ( FILE_Seek( table_base + right_offset ) || - ACCESS_Frame( 4L ) ) + ACCESS_Frame( 4 ) ) goto Fail_Left; kern2->rightClass.firstGlyph = GET_UShort(); @@ -204,7 +204,7 @@ extern TEngine_Instance engineInstance; /* load right offsets */ - if ( ACCESS_Frame( kern2->rightClass.nGlyphs * 2L ) ) + if ( ACCESS_Frame( kern2->rightClass.nGlyphs << 1 ) ) goto Fail_Right; for ( n = 0; n < kern2->rightClass.nGlyphs; n++ ) @@ -306,7 +306,7 @@ extern TEngine_Instance engineInstance; return TT_Err_Ok; /* The table is optional */ if ( FILE_Seek( face->dirTables[table].Offset ) || - ACCESS_Frame( 4L ) ) + ACCESS_Frame( 4 ) ) return error; kern->version = GET_UShort(); @@ -327,7 +327,7 @@ extern TEngine_Instance engineInstance; for ( table = 0; table < num_tables; table++ ) { - if ( ACCESS_Frame( 6L ) ) + if ( ACCESS_Frame( 6 ) ) return error; sub->loaded = FALSE; /* redundant, but good to see */ diff --git a/Driver/Font/TrueType/FreeType/ttcmap.c b/Driver/Font/TrueType/FreeType/ttcmap.c index 9a56f5455..e8ca867a2 100644 --- a/Driver/Font/TrueType/FreeType/ttcmap.c +++ b/Driver/Font/TrueType/FreeType/ttcmap.c @@ -86,7 +86,7 @@ /* allocate subheader keys */ if ( ALLOC_ARRAY( cmap2->subHeaderKeys, 256, UShort ) || - ACCESS_Frame( 512L ) ) + ACCESS_Frame( 512 ) ) goto Fail; for ( i = 0; i < 256; i++ ) @@ -108,12 +108,12 @@ if ( ALLOC_ARRAY( cmap2->subHeaders, num_SH + 1, TCMap2SubHeader ) || - ACCESS_Frame( ( num_SH + 1 ) * 8L ) ) + ACCESS_Frame( ( num_SH + 1 ) << 3 ) ) goto Fail; cmap2sub = cmap2->subHeaders; - for ( i = 0; i <= num_SH; i++ ) + for ( i = 0; i <= num_SH; ++i ) { cmap2sub->firstCode = GET_UShort(); cmap2sub->entryCount = GET_UShort(); @@ -129,7 +129,7 @@ /* load glyph ids */ if ( ALLOC_ARRAY( cmap2->glyphIdArray, l, UShort ) || - ACCESS_Frame( l * 2L ) ) + ACCESS_Frame( l << 1 ) ) goto Fail; for ( i = 0; i < l; i++ ) @@ -143,7 +143,7 @@ /* load header */ - if ( ACCESS_Frame( 8L ) ) + if ( ACCESS_Frame( 8 ) ) goto Fail; cmap4->segCountX2 = GET_UShort(); @@ -160,7 +160,7 @@ if ( GEO_ALLOC_ARRAY( cmap4->segmentBlock, num_Seg, TCMap4Segment ) || - ACCESS_Frame( (num_Seg * 4 + 1) * 2L ) ) + ACCESS_Frame( (num_Seg * 4 + 1) * 2 ) ) goto Fail; segments = GEO_LOCK( cmap4->segmentBlock ); @@ -188,7 +188,7 @@ /* load ids */ if ( ALLOC_ARRAY( cmap4->glyphIdArray, l , UShort ) || - ACCESS_Frame( l * 2L ) ) + ACCESS_Frame( l << 1 ) ) goto Fail; for ( i = 0; i < l; ++i ) @@ -200,7 +200,7 @@ case 6: cmap6 = &cmap->c.cmap6; - if ( ACCESS_Frame( 4L ) ) + if ( ACCESS_Frame( 4 ) ) goto Fail; cmap6->firstCode = GET_UShort(); @@ -213,7 +213,7 @@ if ( ALLOC_ARRAY( cmap6->glyphIdArray, cmap6->entryCount, Short ) || - ACCESS_Frame( l * 2L ) ) + ACCESS_Frame( l << 1 ) ) goto Fail; for ( i = 0; i < l; i++ ) diff --git a/Driver/Font/TrueType/FreeType/ttfile.c b/Driver/Font/TrueType/FreeType/ttfile.c index ba847ef67..b730335e4 100644 --- a/Driver/Font/TrueType/FreeType/ttfile.c +++ b/Driver/Font/TrueType/FreeType/ttfile.c @@ -279,7 +279,7 @@ ******************************************************************/ EXPORT_FUNC - TT_Error TT_Access_Frame( STREAM_ARGS FRAME_ARGS Long size ) + TT_Error TT_Access_Frame( STREAM_ARGS FRAME_ARGS Short size ) { TT_Error error; @@ -346,7 +346,7 @@ ******************************************************************/ EXPORT_FUNC - TT_Error TT_Check_And_Access_Frame( STREAM_ARGS FRAME_ARGS Long size ) + TT_Error TT_Check_And_Access_Frame( STREAM_ARGS FRAME_ARGS Short size ) { TT_Error error; Long readBytes, requested; @@ -528,7 +528,7 @@ ******************************************************************/ EXPORT_FUNC - TT_Error TT_Access_Frame( STREAM_ARGS FRAME_ARGS Long size ) + TT_Error TT_Access_Frame( STREAM_ARGS FRAME_ARGS Short size ) { TT_Error error; @@ -584,7 +584,7 @@ ******************************************************************/ EXPORT_FUNC - TT_Error TT_Check_And_Access_Frame( STREAM_ARGS FRAME_ARGS Long size ) + TT_Error TT_Check_And_Access_Frame( STREAM_ARGS FRAME_ARGS Short size ) { TT_Error error; Long readBytes; @@ -911,9 +911,9 @@ ******************************************************************/ EXPORT_FUNC - TT_Error TT_Read_File( STREAM_ARGS void* buffer, Long count ) + TT_Error TT_Read_File( STREAM_ARGS void* buffer, Short count ) { - if ( FileRead( CUR_Stream->file, buffer, count, FALSE ) != (ULong)count ) + if ( FileRead( CUR_Stream->file, buffer, count, FALSE ) != count ) return TT_Err_Invalid_File_Read; return TT_Err_Ok; diff --git a/Driver/Font/TrueType/FreeType/ttfile.h b/Driver/Font/TrueType/FreeType/ttfile.h index bf4295312..1f061f551 100644 --- a/Driver/Font/TrueType/FreeType/ttfile.h +++ b/Driver/Font/TrueType/FreeType/ttfile.h @@ -129,7 +129,7 @@ EXPORT_DEF TT_Error TT_Read_File( STREAM_ARGS void* buffer, - Long count ); + Short count ); /* Seek file cursor to a given position */ @@ -177,7 +177,7 @@ { Byte* address; /* frame buffer */ Byte* cursor; /* current cursor position in frame */ - Long size; /* frame size */ + Short size; /* frame size */ }; typedef struct TFileFrame_ TFileFrame; @@ -223,7 +223,7 @@ /* Fails if all bytes cannot be read/accessed. */ EXPORT_DEF - TT_Error TT_Access_Frame( STREAM_ARGS FRAME_ARGS Long size ); + TT_Error TT_Access_Frame( STREAM_ARGS FRAME_ARGS Short size ); /* Access the bytes located in the next 'size' bytes of the file. */ @@ -231,7 +231,7 @@ /* at the end of the file). */ EXPORT_DEF - TT_Error TT_Check_And_Access_Frame( STREAM_ARGS FRAME_ARGS Long size ); + TT_Error TT_Check_And_Access_Frame( STREAM_ARGS FRAME_ARGS Short size ); /* Forget frame */ diff --git a/Driver/Font/TrueType/FreeType/ttgload.c b/Driver/Font/TrueType/FreeType/ttgload.c index ffd1f99f6..26cfe2890 100644 --- a/Driver/Font/TrueType/FreeType/ttgload.c +++ b/Driver/Font/TrueType/FreeType/ttgload.c @@ -248,7 +248,7 @@ /* read the flags */ - if ( CHECK_ACCESS_Frame( n_points * 5L ) ) + if ( CHECK_ACCESS_Frame( n_points * 5 ) ) return error; j = 0; @@ -425,7 +425,7 @@ if ( subg->is_hinted && subg->element_flag & WE_HAVE_INSTR ) { - if ( ACCESS_Frame( 2L ) ) + if ( ACCESS_Frame( 2 ) ) return error; n_ins = GET_UShort(); /* read size of instructions */ @@ -757,7 +757,7 @@ /* read first glyph header */ if ( FILE_Seek( offset ) || - ACCESS_Frame( 10L ) ) + ACCESS_Frame( 10 ) ) goto Fail_File; num_contours = GET_Short(); @@ -859,7 +859,7 @@ /* now read composite header */ - if ( ACCESS_Frame( 4L ) ) + if ( ACCESS_Frame( 4 ) ) goto Fail_File; subglyph->element_flag = new_flags = GET_UShort(); diff --git a/Driver/Font/TrueType/FreeType/ttload.c b/Driver/Font/TrueType/FreeType/ttload.c index e52b4d12e..02d83bd50 100644 --- a/Driver/Font/TrueType/FreeType/ttload.c +++ b/Driver/Font/TrueType/FreeType/ttload.c @@ -87,7 +87,7 @@ PTableDirEntry entry; - if ( FILE_Seek( 0L ) || ACCESS_Frame( 12L ) ) + if ( FILE_Seek( 0 ) || ACCESS_Frame( 12 ) ) return error; tableDir.version = GET_Long(); @@ -115,7 +115,7 @@ TTableDirEntry ) ) return error; - if ( ACCESS_Frame( face->numTables * 16L ) ) + if ( ACCESS_Frame( face->numTables * 16 ) ) return error; limit = face->numTables; @@ -164,7 +164,7 @@ if ( FILE_Seek( face->dirTables[i].Offset ) ) /* seek to maxprofile */ return error; - if ( ACCESS_Frame( 32L ) ) /* read into frame */ + if ( ACCESS_Frame( 32L) ) /* read into frame */ return error; /* read frame data into face table */ @@ -250,7 +250,7 @@ return TT_Err_Ok; /* gasp table is not required */ if ( FILE_Seek( face->dirTables[i].Offset ) || - ACCESS_Frame( 4L ) ) + ACCESS_Frame( 4 ) ) return error; gas = &face->gasp; @@ -261,7 +261,7 @@ FORGET_Frame(); if ( ALLOC_ARRAY( gaspranges, gas->numRanges, GaspRange ) || - ACCESS_Frame( gas->numRanges * 4L ) ) + ACCESS_Frame( gas->numRanges * 4 ) ) goto Fail; face->gasp.gaspRanges = gaspranges; @@ -308,7 +308,7 @@ return TT_Err_Header_Table_Missing; if ( FILE_Seek( face->dirTables[i].Offset ) || - ACCESS_Frame( 54L ) ) + ACCESS_Frame( 54 ) ) return error; header = &face->fontHeader; @@ -513,7 +513,7 @@ } if ( FILE_Seek( face->dirTables[i].Offset ) || - ACCESS_Frame( 36L ) ) + ACCESS_Frame( 36 ) ) return error; header->Version = GET_ULong(); @@ -593,7 +593,7 @@ Long )) return error; - if ( ACCESS_Frame( face->numLocations * 4L ) ) + if ( ACCESS_Frame( face->numLocations << 2 ) ) return error; limit = face->numLocations; @@ -614,7 +614,7 @@ Long )) return error; - if ( ACCESS_Frame( face->numLocations * 2L ) ) + if ( ACCESS_Frame( face->numLocations << 1 ) ) return error; limit = face->numLocations; @@ -662,7 +662,7 @@ /* Seek to the beginning of the table and check the frame access. */ /* The names table has a 6 byte header. */ if ( FILE_Seek( face->dirTables[n].Offset ) || - ACCESS_Frame( 6L ) ) + ACCESS_Frame( 6 ) ) return error; names = &face->nameTable; @@ -678,7 +678,7 @@ if ( ALLOC_ARRAY( names->names, names->numNameRecords, TNameRec ) || - ACCESS_Frame( names->numNameRecords * 12L ) ) + ACCESS_Frame( names->numNameRecords * 12 ) ) { names->numNameRecords = 0; goto Fail; @@ -810,7 +810,7 @@ return error; if ( FILE_Seek( face->dirTables[n].Offset ) || - ACCESS_Frame( face->cvtSize * 2L ) ) + ACCESS_Frame( face->cvtSize << 1 ) ) return error; limit = face->cvtSize; @@ -856,7 +856,7 @@ table_start = face->dirTables[n].Offset; if ( ( FILE_Seek( table_start ) ) || - ( ACCESS_Frame( 4L ) ) ) /* 4 bytes cmap header */ + ( ACCESS_Frame( 4 ) ) ) /* 4 bytes cmap header */ return error; cmap_dir.tableVersionNumber = GET_UShort(); @@ -879,8 +879,7 @@ for ( n = 0; n < limit; n++ ) { - if ( FILE_Seek( off ) || - ACCESS_Frame( 8L ) ) + if ( FILE_Seek( off ) || ACCESS_Frame( 8 ) ) return error; /* extra code using entry_ for platxxx could be cleaned up later */ @@ -895,7 +894,7 @@ off = FILE_Pos(); if ( FILE_Seek( table_start + entry_.offset ) || - ACCESS_Frame( 6L ) ) + ACCESS_Frame( 6 ) ) return error; cmap->format = GET_UShort(); @@ -1005,7 +1004,7 @@ } if ( FILE_Seek( face->dirTables[i].Offset ) || - ACCESS_Frame( 78L ) ) + ACCESS_Frame( 78 ) ) return error; os2 = &face->os2; @@ -1053,7 +1052,7 @@ { /* only version 1 tables */ - if ( ACCESS_Frame( 8L ) ) /* read into frame */ + if ( ACCESS_Frame( 8 ) ) /* read into frame */ return error; os2->ulCodePageRange1 = GET_ULong(); @@ -1097,7 +1096,7 @@ return TT_Err_Post_Table_Missing; if ( FILE_Seek( face->dirTables[i].Offset ) || - ACCESS_Frame( 32L ) ) + ACCESS_Frame( 32 ) ) return error; /* read frame data into face table */ @@ -1156,7 +1155,7 @@ return TT_Err_Ok; if ( FILE_Seek( face->dirTables[table].Offset ) || - ACCESS_Frame( 8L ) ) + ACCESS_Frame( 8 ) ) return error; hdmx.version = GET_UShort(); @@ -1181,7 +1180,7 @@ { /* read record */ - if ( ACCESS_Frame( 2L ) ) + if ( ACCESS_Frame( 2 ) ) goto Fail; rec->ppem = GET_Byte(); diff --git a/Driver/Font/TrueType/FreeType/ttload.h b/Driver/Font/TrueType/FreeType/ttload.h index 0eb9034ff..a3a46d286 100644 --- a/Driver/Font/TrueType/FreeType/ttload.h +++ b/Driver/Font/TrueType/FreeType/ttload.h @@ -115,11 +115,11 @@ #define ACCESS_Frame( _size_ ) \ ( (error = TT_Access_Frame( stream, \ &frame, \ - (Long)(_size_) )) != TT_Err_Ok ) + _size_ )) != TT_Err_Ok ) #define CHECK_ACCESS_Frame( _size_ ) \ ( (error = TT_Check_And_Access_Frame( stream, \ &frame, \ - (Long)(_size_) )) != TT_Err_Ok ) + _size_ )) != TT_Err_Ok ) #define FORGET_Frame() \ ( (void)TT_Forget_Frame( &frame ) ) @@ -158,7 +158,7 @@ #define FILE_Read( buffer, count ) \ ( (error = TT_Read_File ( stream, \ buffer, \ - (Long)(count) )) != TT_Err_Ok ) + count )) != TT_Err_Ok ) #define FILE_Read_At( pos, buffer, count ) \ ( (error = TT_Read_At_File( stream, \ (Long)(pos), \ @@ -191,9 +191,9 @@ #define ACCESS_Frame( _size_ ) \ - ( (error = TT_Access_Frame( (Long)(_size_) )) != TT_Err_Ok ) + ( (error = TT_Access_Frame( _size_ )) != TT_Err_Ok ) #define CHECK_ACCESS_Frame( _size_ ) \ - ( (error = TT_Check_And_Access_Frame( (Long)(_size_) )) != TT_Err_Ok ) + ( (error = TT_Check_And_Access_Frame( _size_ )) != TT_Err_Ok ) #define FORGET_Frame() \ ( (void)TT_Forget_Frame() ) @@ -213,7 +213,7 @@ ( (error = TT_Skip_File( (Long)(_distance_) )) != TT_Err_Ok ) #define FILE_Read( buffer, count ) \ ( (error = TT_Read_File ( buffer, \ - (Long)(count) )) != TT_Err_Ok ) + count )) != TT_Err_Ok ) #define FILE_Read_At( pos, buffer, count ) \ ( (error = TT_Read_At_File( (Long)(pos), \ buffer, \ From 3cc7e28b54000d1e14edf5b465655717ecd8a12c Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Fri, 7 Jun 2024 21:12:11 +0200 Subject: [PATCH 12/37] Cmap 6 support removed. --- Driver/Font/TrueType/FreeType/ft_conf.h | 7 +++++++ Driver/Font/TrueType/FreeType/ttcmap.c | 14 ++++++++++++++ Driver/Font/TrueType/FreeType/ttcmap.h | 2 ++ Driver/Font/TrueType/FreeType/ttfile.c | 2 +- Driver/Font/TrueType/FreeType/ttfile.h | 2 +- Driver/Font/TrueType/FreeType/ttload.h | 2 +- Driver/Font/TrueType/FreeType/ttobjs.h | 2 +- 7 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/ft_conf.h b/Driver/Font/TrueType/FreeType/ft_conf.h index f56d2ccde..8e4106fc3 100644 --- a/Driver/Font/TrueType/FreeType/ft_conf.h +++ b/Driver/Font/TrueType/FreeType/ft_conf.h @@ -166,6 +166,13 @@ #undef TT_CONFIG_OPTION_PROCESS_HDMX +/*************************************************************************/ +/* Define TT_CONFIG_OPTION_SUPPORT_CMAP6 if you want to support cmap 6 */ +/* support. In ttf fonts charmap 4 is the standard for char mapping. */ + +#undef TT_CONFIG_OPTION_SUPPORT_CMAP6 + + /**********************************************************************/ /* */ /* The following macros are used to define the debug level, as well */ diff --git a/Driver/Font/TrueType/FreeType/ttcmap.c b/Driver/Font/TrueType/FreeType/ttcmap.c index e8ca867a2..3ce92fe8a 100644 --- a/Driver/Font/TrueType/FreeType/ttcmap.c +++ b/Driver/Font/TrueType/FreeType/ttcmap.c @@ -56,7 +56,10 @@ PCMap0 cmap0; PCMap2 cmap2; PCMap4 cmap4; + +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP6 PCMap6 cmap6; +#endif PCMap2SubHeader cmap2sub; PCMap4Segment segments; @@ -197,6 +200,7 @@ FORGET_Frame(); break; +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP6 case 6: cmap6 = &cmap->c.cmap6; @@ -221,6 +225,7 @@ FORGET_Frame(); break; +#endif default: /* corrupt character mapping table */ return TT_Err_Invalid_CharMap_Format; @@ -270,10 +275,12 @@ cmap->c.cmap4.segCountX2 = 0; break; +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP6 case 6: FREE( cmap->c.cmap6.glyphIdArray ); cmap->c.cmap6.entryCount = 0; break; +#endif default: /* invalid table format, do nothing */ @@ -300,7 +307,10 @@ static UShort code_to_index0( UShort charCode, PCMap0 cmap0 ); static UShort code_to_index2( UShort charCode, PCMap2 cmap2 ); static UShort code_to_index4( UShort charCode, PCMap4 cmap4 ); + + #ifdef TT_CONFIG_OPTION_SUPPORT_CMAP6 static UShort code_to_index6( UShort charCode, PCMap6 cmap6 ); + #endif LOCAL_FUNC @@ -315,8 +325,10 @@ return code_to_index2( charcode, &cmap->c.cmap2 ); case 4: return code_to_index4( charcode, &cmap->c.cmap4 ); +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP6 case 6: return code_to_index6( charcode, &cmap->c.cmap6 ); +#endif default: return 0; } @@ -468,6 +480,7 @@ } +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP6 /******************************************************************* * * Function : code_to_index6 @@ -499,6 +512,7 @@ return cmap6->glyphIdArray[charCode - firstCode]; } +#endif /* END */ diff --git a/Driver/Font/TrueType/FreeType/ttcmap.h b/Driver/Font/TrueType/FreeType/ttcmap.h index 9fd64f3a5..9f962d0af 100644 --- a/Driver/Font/TrueType/FreeType/ttcmap.h +++ b/Driver/Font/TrueType/FreeType/ttcmap.h @@ -128,7 +128,9 @@ TCMap0 cmap0; TCMap2 cmap2; TCMap4 cmap4; +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP6 TCMap6 cmap6; +#endif } c; }; diff --git a/Driver/Font/TrueType/FreeType/ttfile.c b/Driver/Font/TrueType/FreeType/ttfile.c index b730335e4..9294a3a2b 100644 --- a/Driver/Font/TrueType/FreeType/ttfile.c +++ b/Driver/Font/TrueType/FreeType/ttfile.c @@ -937,7 +937,7 @@ EXPORT_FUNC TT_Error TT_Read_At_File( STREAM_ARGS Long position, void* buffer, - Long count ) + Short count ) { TT_Error error; diff --git a/Driver/Font/TrueType/FreeType/ttfile.h b/Driver/Font/TrueType/FreeType/ttfile.h index 1f061f551..30573ecee 100644 --- a/Driver/Font/TrueType/FreeType/ttfile.h +++ b/Driver/Font/TrueType/FreeType/ttfile.h @@ -149,7 +149,7 @@ EXPORT_DEF TT_Error TT_Read_At_File( STREAM_ARGS Long position, void* buffer, - Long count ); + Short count ); /* Return current file position */ diff --git a/Driver/Font/TrueType/FreeType/ttload.h b/Driver/Font/TrueType/FreeType/ttload.h index a3a46d286..17a48e639 100644 --- a/Driver/Font/TrueType/FreeType/ttload.h +++ b/Driver/Font/TrueType/FreeType/ttload.h @@ -163,7 +163,7 @@ ( (error = TT_Read_At_File( stream, \ (Long)(pos), \ buffer, \ - (Long)(count) )) != TT_Err_Ok ) + count )) != TT_Err_Ok ) #else /* thread-safe implementation */ diff --git a/Driver/Font/TrueType/FreeType/ttobjs.h b/Driver/Font/TrueType/FreeType/ttobjs.h index 23257cea2..71f8f9ee8 100644 --- a/Driver/Font/TrueType/FreeType/ttobjs.h +++ b/Driver/Font/TrueType/FreeType/ttobjs.h @@ -523,7 +523,7 @@ PCMapTable cMaps; /* The glyph locations table */ - ULong numLocations; /* UShort is not enough */ + UShort numLocations; MemHandle glyphLocationBlock; /* NOTE : The "hmtx" is now part of the horizontal header */ From e3ab2881fb38f5c422aca5b6b1e681307aafd882 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Fri, 7 Jun 2024 21:31:02 +0200 Subject: [PATCH 13/37] Avoid some long arithmetic. --- Driver/Font/TrueType/FreeType/ttraster.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/ttraster.c b/Driver/Font/TrueType/FreeType/ttraster.c index 9237684dc..a8345912a 100644 --- a/Driver/Font/TrueType/FreeType/ttraster.c +++ b/Driver/Font/TrueType/FreeType/ttraster.c @@ -1233,8 +1233,8 @@ else { /* two successive `off' points => create middle point */ - mx = ( cx + x ) / 2; - my = ( cy + y ) / 2; + mx = ( cx + x ) >> 1; + my = ( cy + y ) >> 1; if ( Bezier_To( RAS_VARS mx, my, cx, cy ) ) return FAILURE; @@ -1579,7 +1579,7 @@ break; case 4: - e1 = CEILING( (x1 + x2 + 1) / 2 ); + e1 = CEILING( (x1 + x2 + 1) >> 1 ); break; case 2: @@ -1634,7 +1634,7 @@ if ( ras.dropOutControl == 2 ) e1 = e2; else - e1 = CEILING( (x1 + x2 + 1) / 2 ); + e1 = CEILING( (x1 + x2 + 1) >> 1 ); break; @@ -1860,7 +1860,7 @@ break; case 4: - e1 = CEILING( (x1 + x2 + 1) / 2 ); + e1 = CEILING( (x1 + x2 + 1) >> 1 ); break; case 2: @@ -1898,7 +1898,7 @@ if ( ras.dropOutControl == 2 ) e1 = e2; else - e1 = CEILING( (x1 + x2 + 1) / 2 ); + e1 = CEILING( (x1 + x2 + 1) >> 1 ); break; @@ -2410,7 +2410,7 @@ Scan_DropOuts : i = ras.band_stack[ras.band_top].y_min; j = ras.band_stack[ras.band_top].y_max; - k = ( i + j ) / 2; + k = ( i + j ) >> 1; if ( ras.band_top >= 7 || k < i ) { From 650c20412d4d8995206fff94cf57a0bed2d8d73f Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Fri, 14 Jun 2024 18:06:52 +0200 Subject: [PATCH 14/37] GlyphIdBlock sharable and swapable. --- Driver/Font/TrueType/FreeType/ft_conf.h | 9 ++++++++- Driver/Font/TrueType/FreeType/ttcmap.c | 24 ++++++++++++++++-------- Driver/Font/TrueType/FreeType/ttcmap.h | 3 ++- Driver/Font/TrueType/FreeType/ttmemory.c | 2 ++ Driver/Font/TrueType/FreeType/ttmemory.h | 4 ++-- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/ft_conf.h b/Driver/Font/TrueType/FreeType/ft_conf.h index 8e4106fc3..00573db06 100644 --- a/Driver/Font/TrueType/FreeType/ft_conf.h +++ b/Driver/Font/TrueType/FreeType/ft_conf.h @@ -166,9 +166,16 @@ #undef TT_CONFIG_OPTION_PROCESS_HDMX +/*************************************************************************/ +/* Define TT_CONFIG_OPTION_SUPPORT_CMAP6 if you want to support cmap 2 */ +/* char mapping. Charmapping type 2 is now out of date. */ + +#undef TT_CONFIG_OPTION_SUPPORT_CMAP2 + + /*************************************************************************/ /* Define TT_CONFIG_OPTION_SUPPORT_CMAP6 if you want to support cmap 6 */ -/* support. In ttf fonts charmap 4 is the standard for char mapping. */ +/* char mapping. In ttf fonts charmap 4 is the standard for char mapping.*/ #undef TT_CONFIG_OPTION_SUPPORT_CMAP6 diff --git a/Driver/Font/TrueType/FreeType/ttcmap.c b/Driver/Font/TrueType/FreeType/ttcmap.c index 3ce92fe8a..b3bcb965f 100644 --- a/Driver/Font/TrueType/FreeType/ttcmap.c +++ b/Driver/Font/TrueType/FreeType/ttcmap.c @@ -53,6 +53,8 @@ UShort u, l; + PUShort glyphIdArray; + PCMap0 cmap0; PCMap2 cmap2; PCMap4 cmap4; @@ -190,13 +192,16 @@ /* load ids */ - if ( ALLOC_ARRAY( cmap4->glyphIdArray, l , UShort ) || + if ( GEO_ALLOC_ARRAY( cmap4->glyphIdBlock, l , UShort ) || ACCESS_Frame( l << 1 ) ) goto Fail; + glyphIdArray = GEO_LOCK( cmap4->glyphIdBlock ); + for ( i = 0; i < l; ++i ) - cmap4->glyphIdArray[i] = GET_UShort(); + glyphIdArray[i] = GET_UShort(); + GEO_UNLOCK( cmap4->glyphIdBlock ); FORGET_Frame(); break; @@ -271,7 +276,7 @@ case 4: GEO_FREE( cmap->c.cmap4.segmentBlock ); - FREE( cmap->c.cmap4.glyphIdArray ); + GEO_FREE( cmap->c.cmap4.glyphIdBlock ); cmap->c.cmap4.segCountX2 = 0; break; @@ -441,13 +446,15 @@ { UShort index1, segCount; UShort i, result; + PUShort glyphIdArray; TCMap4Segment seg4; PCMap4Segment segments; - segCount = cmap4->segCountX2 / 2; - segments = GEO_LOCK( cmap4->segmentBlock ); - result = 0; + segCount = cmap4->segCountX2 >> 1; + segments = GEO_LOCK( cmap4->segmentBlock ); + glyphIdArray = GEO_LOCK( cmap4->glyphIdBlock ); + result = 0; for ( i = 0; i < segCount; ++i ) if ( charCode <= segments[i].endCount ) @@ -470,12 +477,13 @@ (segCount - i); if ( index1 < cmap4->numGlyphId ) - if ( cmap4->glyphIdArray[index1] != 0 ) - result = ( cmap4->glyphIdArray[index1] + seg4.idDelta ) & 0xFFFF; + if ( glyphIdArray[index1] != 0 ) + result = ( glyphIdArray[index1] + seg4.idDelta ) & 0xFFFF; } Fin: GEO_UNLOCK( cmap4->segmentBlock ); + GEO_UNLOCK( cmap4->glyphIdBlock ); return result; } diff --git a/Driver/Font/TrueType/FreeType/ttcmap.h b/Driver/Font/TrueType/FreeType/ttcmap.h index 9f962d0af..94169283e 100644 --- a/Driver/Font/TrueType/FreeType/ttcmap.h +++ b/Driver/Font/TrueType/FreeType/ttcmap.h @@ -88,7 +88,8 @@ UShort rangeShift; MemHandle segmentBlock; - PUShort glyphIdArray; + MemHandle glyphIdBlock; + // PUShort glyphIdArray; UShort numGlyphId; /* control value */ }; diff --git a/Driver/Font/TrueType/FreeType/ttmemory.c b/Driver/Font/TrueType/FreeType/ttmemory.c index 5366f485b..09c2f794a 100644 --- a/Driver/Font/TrueType/FreeType/ttmemory.c +++ b/Driver/Font/TrueType/FreeType/ttmemory.c @@ -170,6 +170,8 @@ if ( Size > 0 ) *M = MemAllocSetOwner( GeodeGetCodeProcessHandle(), Size, HF_SHARABLE | HF_SWAPABLE, HAF_ZERO_INIT ); + else + *M = NullHandle; return TT_Err_Ok; } diff --git a/Driver/Font/TrueType/FreeType/ttmemory.h b/Driver/Font/TrueType/FreeType/ttmemory.h index ee136d73d..e68738fa3 100644 --- a/Driver/Font/TrueType/FreeType/ttmemory.h +++ b/Driver/Font/TrueType/FreeType/ttmemory.h @@ -99,10 +99,10 @@ GEO_Free( (MemHandle*)&_memHandle_ ) #define GEO_LOCK( _memHandle_ ) \ - MemLock( _memHandle_ ) + (( _memHandle_ ) != NullHandle ? MemLock( _memHandle_ ) : NULL ) #define GEO_UNLOCK( _memHandle_ ) \ - MemUnlock( _memHandle_ ) + (( _memHandle_ ) != NullHandle ? MemUnlock( _memHandle_ ) : (void)0 ) /* Allocate a movable and swapable block of memory of 'Size' bytes */ From 41925828336f95c5f0b823bb82dd36548347dee8 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Fri, 14 Jun 2024 18:19:16 +0200 Subject: [PATCH 15/37] Outdated cmap type 2 support disabled. --- Driver/Font/TrueType/FreeType/ttcmap.c | 6 ++++++ Driver/Font/TrueType/FreeType/ttcmap.h | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Driver/Font/TrueType/FreeType/ttcmap.c b/Driver/Font/TrueType/FreeType/ttcmap.c index b3bcb965f..5679fe87a 100644 --- a/Driver/Font/TrueType/FreeType/ttcmap.c +++ b/Driver/Font/TrueType/FreeType/ttcmap.c @@ -84,6 +84,7 @@ break; +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP2 case 2: num_SH = 0; cmap2 = &cmap->c.cmap2; @@ -142,6 +143,7 @@ FORGET_Frame(); break; +#endif case 4: cmap4 = &cmap->c.cmap4; @@ -268,11 +270,13 @@ FREE( cmap->c.cmap0.glyphIdArray ); break; +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP2 case 2: FREE( cmap->c.cmap2.subHeaderKeys ); FREE( cmap->c.cmap2.subHeaders ); FREE( cmap->c.cmap2.glyphIdArray ); break; +#endif case 4: GEO_FREE( cmap->c.cmap4.segmentBlock ); @@ -326,8 +330,10 @@ { case 0: return code_to_index0( charcode, &cmap->c.cmap0 ); +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP6 case 2: return code_to_index2( charcode, &cmap->c.cmap2 ); +#endif case 4: return code_to_index4( charcode, &cmap->c.cmap4 ); #ifdef TT_CONFIG_OPTION_SUPPORT_CMAP6 diff --git a/Driver/Font/TrueType/FreeType/ttcmap.h b/Driver/Font/TrueType/FreeType/ttcmap.h index 94169283e..7159c9aa4 100644 --- a/Driver/Font/TrueType/FreeType/ttcmap.h +++ b/Driver/Font/TrueType/FreeType/ttcmap.h @@ -89,7 +89,6 @@ MemHandle segmentBlock; MemHandle glyphIdBlock; - // PUShort glyphIdArray; UShort numGlyphId; /* control value */ }; @@ -127,7 +126,9 @@ union { TCMap0 cmap0; +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP2 TCMap2 cmap2; +#endif TCMap4 cmap4; #ifdef TT_CONFIG_OPTION_SUPPORT_CMAP6 TCMap6 cmap6; From e3599d688ef47f4cf2f968a9c306f8556088564a Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Fri, 14 Jun 2024 18:32:00 +0200 Subject: [PATCH 16/37] Forgotten parts added. --- Driver/Font/TrueType/FreeType/ttcmap.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/ttcmap.c b/Driver/Font/TrueType/FreeType/ttcmap.c index 5679fe87a..f7f2ed8a1 100644 --- a/Driver/Font/TrueType/FreeType/ttcmap.c +++ b/Driver/Font/TrueType/FreeType/ttcmap.c @@ -56,14 +56,17 @@ PUShort glyphIdArray; PCMap0 cmap0; +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP2 PCMap2 cmap2; +#endif PCMap4 cmap4; - #ifdef TT_CONFIG_OPTION_SUPPORT_CMAP6 PCMap6 cmap6; #endif +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP2 PCMap2SubHeader cmap2sub; +#endif PCMap4Segment segments; @@ -314,7 +317,11 @@ ******************************************************************/ static UShort code_to_index0( UShort charCode, PCMap0 cmap0 ); + + #ifdef TT_CONFIG_OPTION_SUPPORT_CMAP2 static UShort code_to_index2( UShort charCode, PCMap2 cmap2 ); + #endif + static UShort code_to_index4( UShort charCode, PCMap4 cmap4 ); #ifdef TT_CONFIG_OPTION_SUPPORT_CMAP6 @@ -330,7 +337,7 @@ { case 0: return code_to_index0( charcode, &cmap->c.cmap0 ); -#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP6 +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP2 case 2: return code_to_index2( charcode, &cmap->c.cmap2 ); #endif @@ -373,6 +380,7 @@ } +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP2 /******************************************************************* * * Function : code_to_index2 @@ -430,6 +438,7 @@ return 0; } } +#endif /******************************************************************* From 991958787762d9bb88d0cbaf241335636ff32557 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Sat, 15 Jun 2024 12:16:59 +0200 Subject: [PATCH 17/37] Typo fixed. --- Driver/Font/TrueType/FreeType/ft_conf.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Driver/Font/TrueType/FreeType/ft_conf.h b/Driver/Font/TrueType/FreeType/ft_conf.h index 00573db06..95b755ec7 100644 --- a/Driver/Font/TrueType/FreeType/ft_conf.h +++ b/Driver/Font/TrueType/FreeType/ft_conf.h @@ -161,11 +161,19 @@ /*************************************************************************/ /* Define TT_CONFIG_OPTION_PROCESS_HDMX if you want to process optional */ /* hdmx table. The PC/Geos ttf driver does not need any information from */ -/* the htmx table. */ +/* the hdmx table. */ #undef TT_CONFIG_OPTION_PROCESS_HDMX +/*************************************************************************/ +/* Define TT_CONFIG_OPTION_PROCESS_VMTX if you want to process optional */ +/* vtmx table. The PC/Geos ttf driver does not need any information from */ +/* the vtmx table. */ + +#undef TT_CONFIG_OPTION_PROCESS_VTMX + + /*************************************************************************/ /* Define TT_CONFIG_OPTION_SUPPORT_CMAP6 if you want to support cmap 2 */ /* char mapping. Charmapping type 2 is now out of date. */ From 5666c6ecab4caaf2f8c880449bbd954b6ddda652 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Sat, 15 Jun 2024 19:22:33 +0200 Subject: [PATCH 18/37] Some Warnings fixed. --- Driver/Font/TrueType/Adapter/ttcharmapper.h | 2 ++ Driver/Font/TrueType/Adapter/ttinit.c | 1 + Driver/Font/TrueType/FreeType/ttapi.c | 1 + 3 files changed, 4 insertions(+) diff --git a/Driver/Font/TrueType/Adapter/ttcharmapper.h b/Driver/Font/TrueType/Adapter/ttcharmapper.h index b4bc1ac26..e6ffc70e4 100644 --- a/Driver/Font/TrueType/Adapter/ttcharmapper.h +++ b/Driver/Font/TrueType/Adapter/ttcharmapper.h @@ -58,5 +58,7 @@ CharMapFlags GeosCharMapFlag( word geosChar ); char getGeosCharForIndex( word ttIndex ); +Boolean isGeosCharPair( word ttIndex_1, word ttIndex_2 ); + #endif /* _TTCHARMAPPER_H_ */ diff --git a/Driver/Font/TrueType/Adapter/ttinit.c b/Driver/Font/TrueType/Adapter/ttinit.c index 32a5263d9..567c2871d 100644 --- a/Driver/Font/TrueType/Adapter/ttinit.c +++ b/Driver/Font/TrueType/Adapter/ttinit.c @@ -28,6 +28,7 @@ #include #include #include +#include static word DetectFontFiles( MemHandle* fileEnumBlock ); diff --git a/Driver/Font/TrueType/FreeType/ttapi.c b/Driver/Font/TrueType/FreeType/ttapi.c index d2570c6e8..03aa82acb 100644 --- a/Driver/Font/TrueType/FreeType/ttapi.c +++ b/Driver/Font/TrueType/FreeType/ttapi.c @@ -36,6 +36,7 @@ #include "ttgload.h" #include "ttraster.h" #include "ttextend.h" +#include /* required by the tracing mode */ From 94a35dc6fb0937f39c28f4b6fd579faac96e64e0 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Sun, 16 Jun 2024 09:28:56 +0200 Subject: [PATCH 19/37] Kern 2 support disabled. --- Driver/Font/TrueType/FreeType/ft_conf.h | 8 ++++++++ Driver/Font/TrueType/FreeType/ftxkern.c | 10 ++++++++++ Driver/Font/TrueType/FreeType/ftxkern.h | 2 ++ 3 files changed, 20 insertions(+) diff --git a/Driver/Font/TrueType/FreeType/ft_conf.h b/Driver/Font/TrueType/FreeType/ft_conf.h index 95b755ec7..efbb0b7ba 100644 --- a/Driver/Font/TrueType/FreeType/ft_conf.h +++ b/Driver/Font/TrueType/FreeType/ft_conf.h @@ -188,6 +188,14 @@ #undef TT_CONFIG_OPTION_SUPPORT_CMAP6 +/*************************************************************************/ +/* Define TT_CONFIG_OPTION_SUPPORT_KERN2 if you want to support kerning */ +/* format 1. The ttf driver only supports format 0 because it is very */ +/* simple and common. */ + +#undef TT_CONFIG_OPTION_SUPPORT_KERN2 + + /**********************************************************************/ /* */ /* The following macros are used to define the debug level, as well */ diff --git a/Driver/Font/TrueType/FreeType/ftxkern.c b/Driver/Font/TrueType/FreeType/ftxkern.c index 49b0f3c3a..39392629b 100644 --- a/Driver/Font/TrueType/FreeType/ftxkern.c +++ b/Driver/Font/TrueType/FreeType/ftxkern.c @@ -112,6 +112,7 @@ extern TEngine_Instance engineInstance; return error; } +#ifdef TT_CONFIG_OPTION_SUPPORT_KERN2 /******************************************************************* * @@ -257,6 +258,7 @@ extern TEngine_Instance engineInstance; return error; } +#endif /******************************************************************* * @@ -401,6 +403,7 @@ extern TEngine_Instance engineInstance; sub->t.kern0.rangeShift = 0; break; +#ifdef TT_CONFIG_OPTION_SUPPORT_KERN2 case 2: FREE( sub->t.kern2.leftClass.classes ); sub->t.kern2.leftClass.firstGlyph = 0; @@ -413,6 +416,7 @@ extern TEngine_Instance engineInstance; FREE( sub->t.kern2.array ); sub->t.kern2.rowWidth = 0; break; +#endif default: ; /* invalid subtable format - do nothing */ @@ -518,7 +522,11 @@ extern TEngine_Instance engineInstance; sub = kern->tables + kern_index; +#ifdef TT_CONFIG_OPTION_SUPPORT_KERN2 if ( sub->format != 0 && sub->format != 2 ) +#else + if ( sub->format != 0 ) +#endif return TT_Err_Invalid_Kerning_Table_Format; /* now access stream */ @@ -530,8 +538,10 @@ extern TEngine_Instance engineInstance; if ( sub->format == 0 ) error = Subtable_Load_0( &sub->t.kern0, faze ); +#ifdef TT_CONFIG_OPTION_SUPPORT_KERN2 else if ( sub->format == 2 ) error = Subtable_Load_2( &sub->t.kern2, faze ); +#endif if ( !error ) sub->loaded = TRUE; diff --git a/Driver/Font/TrueType/FreeType/ftxkern.h b/Driver/Font/TrueType/FreeType/ftxkern.h index 3dd26fad3..afff0e237 100644 --- a/Driver/Font/TrueType/FreeType/ftxkern.h +++ b/Driver/Font/TrueType/FreeType/ftxkern.h @@ -126,7 +126,9 @@ extern "C" { union { TT_Kern_0 kern0; +#ifdef TT_CONFIG_OPTION_SUPPORT_KERN2 TT_Kern_2 kern2; +#endif } t; }; From fb94a7b29bae3c18e93b9414f0b536c8fda2b37e Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Sun, 16 Jun 2024 19:59:47 +0200 Subject: [PATCH 20/37] Memory leak related to font with kerning information fixed. --- Driver/Font/TrueType/FreeType/ftxkern.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Driver/Font/TrueType/FreeType/ftxkern.c b/Driver/Font/TrueType/FreeType/ftxkern.c index 39392629b..4776603b7 100644 --- a/Driver/Font/TrueType/FreeType/ftxkern.c +++ b/Driver/Font/TrueType/FreeType/ftxkern.c @@ -529,6 +529,9 @@ extern TEngine_Instance engineInstance; #endif return TT_Err_Invalid_Kerning_Table_Format; + if ( sub->loaded ) + return TT_Err_Ok; + /* now access stream */ if ( USE_Stream( faze->stream, stream ) ) return error; From b66e7b082d5b18edfc8475e1f53f8ab2cff160ea Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Tue, 18 Jun 2024 20:50:45 +0200 Subject: [PATCH 21/37] We do not need fontcomUtils. --- Driver/Font/TrueType/Main/mainManager.asm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Driver/Font/TrueType/Main/mainManager.asm b/Driver/Font/TrueType/Main/mainManager.asm index 725ca4034..e5a3ef784 100644 --- a/Driver/Font/TrueType/Main/mainManager.asm +++ b/Driver/Font/TrueType/Main/mainManager.asm @@ -87,7 +87,7 @@ WidthMod segment resource include truetypeWidths.asm ;include nimbusUtils.asm ;include nimbusSetTrans.asm -include ../FontCom/fontcomUtils.asm +;include ../FontCom/fontcomUtils.asm WidthMod ends CharMod segment resource From d6bc59975cc6847fe438a37325a4d7d43415eb72 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Tue, 18 Jun 2024 21:53:49 +0200 Subject: [PATCH 22/37] Use rTarget as buffer for regions. --- Driver/Font/TrueType/FreeType/ttobjs.c | 2 +- Driver/Font/TrueType/FreeType/ttraster.c | 34 +++++++++++------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/ttobjs.c b/Driver/Font/TrueType/FreeType/ttobjs.c index 5ac407a0d..ca2426721 100644 --- a/Driver/Font/TrueType/FreeType/ttobjs.c +++ b/Driver/Font/TrueType/FreeType/ttobjs.c @@ -1037,7 +1037,7 @@ face->numLocations = 0; /* freeing the character mapping tables */ - for ( n = 0; n < face->numCMaps; n++ ) + for ( n = 0; n < face->numCMaps; ++n ) CharMap_Free( face->cMaps + n ); FREE( face->cMaps ); diff --git a/Driver/Font/TrueType/FreeType/ttraster.c b/Driver/Font/TrueType/FreeType/ttraster.c index a8345912a..97c44578a 100644 --- a/Driver/Font/TrueType/FreeType/ttraster.c +++ b/Driver/Font/TrueType/FreeType/ttraster.c @@ -247,10 +247,7 @@ TPoint* arc; /* current Bezier arc pointer */ UShort bWidth; /* target bitmap width */ - PByte bTarget; /* target bitmap buffer */ -#ifdef __GEOS__ - PShort rTarget; /* target region buffer */ -#endif /* __GEOS__ */ + PByte bTarget; /* target bitmap or region buffer */ Long lastX, lastY, minY, maxY; @@ -1696,8 +1693,8 @@ PProfile left, PProfile right ) { - Long e1, e2; - Short* target; + Long e1, e2; + PShort target; /* Drop-out control */ @@ -1709,7 +1706,7 @@ else e2 = TRUNC( FLOOR( x2 ) ); - target = ras.rTarget + ras.traceOfs; + target = ( (PShort)ras.bTarget ) + ras.traceOfs; if ( ras.traceIncr == 0 ) target[ras.traceIncr++] = y; @@ -1735,12 +1732,12 @@ static void _near Vertical_Region_Sweep_Step( RAS_ARGS Short y ) { - Short* target; - Short* targetLastLine; + PShort target; + PShort targetLastLine; - target = ras.rTarget + ras.traceOfs; - targetLastLine = ras.rTarget + ras.traceOfsLastLine; + target = ( (PShort)ras.bTarget ) + ras.traceOfs; + targetLastLine = ( (PShort)ras.bTarget ) + ras.traceOfsLastLine; /* special case: the current line was empty */ @@ -1751,7 +1748,7 @@ /* finish current line */ - target[ras.traceIncr++] = EOREGREC; + target[ras.traceIncr++] = (Short)EOREGREC; /* special case: no differences between last and current line */ @@ -1779,9 +1776,9 @@ /* complete a region */ - target = ras.rTarget + ras.traceOfs; + target = ( (PShort)ras.bTarget ) + ras.traceOfs; - target[ras.traceIncr++] = EOREGREC; + target[ras.traceIncr++] = (Short)EOREGREC; ras.target.size = ( ras.traceOfs + ras.traceIncr ) * sizeof( Short ); } @@ -2356,7 +2353,6 @@ Scan_DropOuts : if ( P_Left->countL ) { P_Left->countL = 0; - /* dropouts--; -- this is useful when debugging only */ ras.Proc_Sweep_Drop( RAS_VARS y, P_Left->X, P_Right->X, @@ -2593,7 +2589,7 @@ TT_Error Render_Region_Glyph( RAS_ARGS TT_Outline* glyph, ras.band_stack[0].y_max = ras.target.rows - 1; ras.bWidth = ras.target.cols; - ras.rTarget = (Short*)ras.target.bitmap; + ras.bTarget = (PByte)ras.target.bitmap; if ( (error = Render_Single_Pass( RAS_VARS 0 )) != 0 ) return error; @@ -2606,13 +2602,13 @@ TT_Error Render_Region_Glyph( RAS_ARGS TT_Outline* glyph, static void Render_Region_Empty_Glyph( RAS_ARG ) { - Short* target = ras.rTarget; + PShort target = (PShort)ras.bTarget; /* complete a region */ - target[0] = EOREGREC; - target[1] = EOREGREC; + target[0] = (Short)EOREGREC; + target[1] = (Short)EOREGREC; ras.target.size = 2 * sizeof( Short ); } From 0087bebdba8a0053c0c0b920d3b31700cb700577 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Wed, 19 Jun 2024 20:53:08 +0200 Subject: [PATCH 23/37] Minimal optimizatioin in processing of kerning Information. --- Driver/Font/TrueType/FreeType/ftxkern.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/ftxkern.c b/Driver/Font/TrueType/FreeType/ftxkern.c index 4776603b7..7616f9612 100644 --- a/Driver/Font/TrueType/FreeType/ftxkern.c +++ b/Driver/Font/TrueType/FreeType/ftxkern.c @@ -85,7 +85,7 @@ extern TEngine_Instance engineInstance; if ( ACCESS_Frame( num_pairs * 6 ) ) goto Fail; - for ( n = 0; n < num_pairs; n++ ) + for ( n = 0; n < num_pairs; ++n ) { kern0->pairs[n].left = GET_UShort(); kern0->pairs[n].right = GET_UShort(); @@ -327,7 +327,7 @@ extern TEngine_Instance engineInstance; sub = kern->tables; - for ( table = 0; table < num_tables; table++ ) + for ( table = 0; table < num_tables; ++table ) { if ( ACCESS_Frame( 6 ) ) return error; @@ -389,7 +389,7 @@ extern TEngine_Instance engineInstance; /* scan the table directory and release loaded entries */ sub = kern->tables; - for ( n = 0; n < kern->nTables; n++ ) + for ( n = 0; n < kern->nTables; ++n ) { if ( sub->loaded ) { From af672b9d091fcba181275a05891de5dda366a6e1 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Thu, 20 Jun 2024 20:36:45 +0200 Subject: [PATCH 24/37] Optional fields are no longer processed. --- Driver/Font/TrueType/FreeType/freetype.h | 8 +++++++- Driver/Font/TrueType/FreeType/ft_conf.h | 7 +++++++ Driver/Font/TrueType/FreeType/ttload.c | 8 +++++++- Driver/Font/TrueType/FreeType/ttload.h | 1 + 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/freetype.h b/Driver/Font/TrueType/FreeType/freetype.h index 6ad3ac14c..91f062cb1 100644 --- a/Driver/Font/TrueType/FreeType/freetype.h +++ b/Driver/Font/TrueType/FreeType/freetype.h @@ -393,11 +393,13 @@ TT_FWord caret_Slope_Rise; TT_FWord caret_Slope_Run; +#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS TT_Short Reserved0, Reserved1, Reserved2, Reserved3, Reserved4; +#endif TT_Short metric_Data_Format; TT_UShort number_Of_HMetrics; @@ -433,12 +435,15 @@ TT_FWord yMax_Extent; /* xmax or ymax extents */ TT_FWord caret_Slope_Rise; TT_FWord caret_Slope_Run; + +#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS TT_FWord caret_Offset; TT_Short Reserved1, Reserved2, Reserved3, Reserved4; +#endif TT_Short metric_Data_Format; TT_UShort number_Of_VMetrics; @@ -498,10 +503,11 @@ TT_UShort usWinAscent; TT_UShort usWinDescent; +#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS /* only version 1 tables: */ - TT_ULong ulCodePageRange1; /* Bits 0-31 */ TT_ULong ulCodePageRange2; /* Bits 32-63 */ +#endif }; typedef struct TT_OS2_ TT_OS2; diff --git a/Driver/Font/TrueType/FreeType/ft_conf.h b/Driver/Font/TrueType/FreeType/ft_conf.h index efbb0b7ba..5b9cf2a5d 100644 --- a/Driver/Font/TrueType/FreeType/ft_conf.h +++ b/Driver/Font/TrueType/FreeType/ft_conf.h @@ -196,6 +196,13 @@ #undef TT_CONFIG_OPTION_SUPPORT_KERN2 +/*************************************************************************/ +/* Define TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS if you want to hold */ +/* optional fiels in freetype structures. */ + +#undef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS + + /**********************************************************************/ /* */ /* The following macros are used to define the debug level, as well */ diff --git a/Driver/Font/TrueType/FreeType/ttload.c b/Driver/Font/TrueType/FreeType/ttload.c index 02d83bd50..e49a4aa2b 100644 --- a/Driver/Font/TrueType/FreeType/ttload.c +++ b/Driver/Font/TrueType/FreeType/ttload.c @@ -529,12 +529,16 @@ header->caret_Slope_Rise = GET_Short(); header->caret_Slope_Run = GET_Short(); +#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS header->Reserved0 = GET_Short(); /* this is caret_Offset for vertical headers */ header->Reserved1 = GET_Short(); header->Reserved2 = GET_Short(); header->Reserved3 = GET_Short(); header->Reserved4 = GET_Short(); +#else + SKIP( 10 ); +#endif header->metric_Data_Format = GET_Short(); header->number_Of_HMetrics = GET_UShort(); @@ -1034,7 +1038,7 @@ os2->ulUnicodeRange3 = GET_ULong(); os2->ulUnicodeRange4 = GET_ULong(); - for ( i = 0; i < 4; i++ ) + for ( i = 0; i < 4; ++i ) os2->achVendID[i] = GET_Byte(); os2->fsSelection = GET_UShort(); @@ -1048,6 +1052,7 @@ FORGET_Frame(); +#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS if ( os2->version >= 0x0001 ) { /* only version 1 tables */ @@ -1065,6 +1070,7 @@ os2->ulCodePageRange1 = 0; os2->ulCodePageRange2 = 0; } +#endif return TT_Err_Ok; } diff --git a/Driver/Font/TrueType/FreeType/ttload.h b/Driver/Font/TrueType/FreeType/ttload.h index 17a48e639..97fb468cf 100644 --- a/Driver/Font/TrueType/FreeType/ttload.h +++ b/Driver/Font/TrueType/FreeType/ttload.h @@ -133,6 +133,7 @@ #define GET_Short() (Short) (frame.cursor += 2, \ (frame.cursor[-2] << 8) | \ frame.cursor[-1]) + #define SKIP( _size_ ) (frame.cursor += _size_ ) #else From 919791cf5ef1316c83bdcabe55b3459282aa1722 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Sat, 22 Jun 2024 14:45:16 +0200 Subject: [PATCH 25/37] Make block for kerningpairs movable. --- Driver/Font/TrueType/Adapter/ttinit.c | 20 +++++++++++--------- Driver/Font/TrueType/Adapter/ttwidths.c | 16 +++++++++------- Driver/Font/TrueType/FreeType/ftxkern.c | 22 +++++++++++++--------- Driver/Font/TrueType/FreeType/ftxkern.h | 4 ++-- Driver/Font/TrueType/FreeType/ttload.c | 24 ++++++++++++------------ Driver/Font/TrueType/FreeType/ttraster.c | 10 +++++----- 6 files changed, 52 insertions(+), 44 deletions(-) diff --git a/Driver/Font/TrueType/Adapter/ttinit.c b/Driver/Font/TrueType/Adapter/ttinit.c index 567c2871d..f34d286a7 100644 --- a/Driver/Font/TrueType/Adapter/ttinit.c +++ b/Driver/Font/TrueType/Adapter/ttinit.c @@ -20,6 +20,7 @@ #include "ttinit.h" #include "ttadapter.h" #include "ttcharmapper.h" +#include "ttmemory.h" #include "ftxkern.h" #include #include @@ -64,9 +65,9 @@ static word GetKernCount( TRUETYPE_VARS ); static word toHash( const char* str ); -static int strlen( const char* str ); +static word strlen( const char* str ); -static void strcpy( char* dest, const char* source ); +static char* strcpy( char* dest, const char* source ); static void strcpyname( char* dest, const char* source ); @@ -1004,6 +1005,7 @@ static word GetKernCount( TRUETYPE_VARS ) { TT_Kerning kerningDir; word table; + TT_Kern_0_Pair* pairs; word numGeosKernPairs = 0; if( TT_Get_Kerning_Directory( FACE, &kerningDir ) ) @@ -1020,16 +1022,15 @@ static word GetKernCount( TRUETYPE_VARS ) if( kerningDir.tables->format != 0 ) continue; - /* We only support decreasing the character spacing.*/ - if( kerningDir.tables->t.kern0.pairs[i].value > 0 ) - continue; + pairs = GEO_LOCK( kerningDir.tables->t.kern0.pairsBlock ); for( i = 0; i < kerningDir.tables->t.kern0.nPairs; ++i ) { - if( isGeosCharPair( kerningDir.tables->t.kern0.pairs[i].left, - kerningDir.tables->t.kern0.pairs[i].right ) ) + if( isGeosCharPair( pairs[i].left, pairs[i].right ) ) ++numGeosKernPairs; } + + GEO_UNLOCK( kerningDir.tables->t.kern0.pairsBlock ); } Fail: @@ -1042,7 +1043,7 @@ static word GetKernCount( TRUETYPE_VARS ) /* cycle. Therefore, the required functions are reimplemented here.*/ /*******************************************************************/ -static int strlen( const char* str ) +static word strlen( const char* str ) { const char *s; @@ -1052,9 +1053,10 @@ static int strlen( const char* str ) } -static void strcpy( char* dest, const char* source ) +static char* strcpy( char* dest, const char* source ) { while( (*dest++ = *source++) != '\0' ); + return dest; } diff --git a/Driver/Font/TrueType/Adapter/ttwidths.c b/Driver/Font/TrueType/Adapter/ttwidths.c index 4e928b1e6..38ed02bba 100644 --- a/Driver/Font/TrueType/Adapter/ttwidths.c +++ b/Driver/Font/TrueType/Adapter/ttwidths.c @@ -24,6 +24,7 @@ #include #include "ttwidths.h" #include "ttcharmapper.h" +#include "ttmemory.h" #include "ttinit.h" #include "freetype.h" #include "ftxkern.h" @@ -334,6 +335,7 @@ static void ConvertKernPairs( TRUETYPE_VARS, FontBuf* fontBuf ) { TT_Kerning kerningDir; word table; + TT_Kern_0_Pair* pairs; KernPair* kernPair = (KernPair*) ( ( (byte*)fontBuf ) + fontBuf->FB_kernPairs ); BBFixed* kernValue = (BBFixed*) ( ( (byte*)fontBuf ) + fontBuf->FB_kernValues ); @@ -357,15 +359,13 @@ EC( ECCheckBounds( (void*)kernValue ) ); if( kerningDir.tables->format != 0 ) continue; + pairs = GEO_LOCK( kerningDir.tables->t.kern0.pairsBlock ); + for( i = 0; i < kerningDir.tables->t.kern0.nPairs; ++i ) { - char left = getGeosCharForIndex( kerningDir.tables->t.kern0.pairs[i].left ); - char right = getGeosCharForIndex( kerningDir.tables->t.kern0.pairs[i].right ); - + char left = getGeosCharForIndex( pairs[i].left ); + char right = getGeosCharForIndex( pairs[i].right ); - /* We only support decreasing the character spacing.*/ - if( kerningDir.tables->t.kern0.pairs[i].value > 0 ) - continue; if( left && right ) { @@ -375,7 +375,7 @@ EC( ECCheckBounds( (void*)kernValue ) ); kernPair->KP_charRight = right; /* save scaled kerning value */ - scaledKernValue = SCALE_WORD( kerningDir.tables->t.kern0.pairs[i].value, SCALE_WIDTH ); + scaledKernValue = SCALE_WORD( pairs[i].value, SCALE_WIDTH ); kernValue->BBF_int = IntegerOf( scaledKernValue ); kernValue->BBF_frac = FractionOf( scaledKernValue ) >> 8; @@ -383,6 +383,8 @@ EC( ECCheckBounds( (void*)kernValue ) ); ++kernValue; } } + + GEO_UNLOCK( kerningDir.tables->t.kern0.pairsBlock ); } } diff --git a/Driver/Font/TrueType/FreeType/ftxkern.c b/Driver/Font/TrueType/FreeType/ftxkern.c index 7616f9612..9ab5990c4 100644 --- a/Driver/Font/TrueType/FreeType/ftxkern.c +++ b/Driver/Font/TrueType/FreeType/ftxkern.c @@ -63,7 +63,8 @@ extern TEngine_Instance engineInstance; { DEFINE_LOAD_LOCALS( input->stream ); - UShort num_pairs, n; + UShort num_pairs, n; + TT_Kern_0_Pair* pairs; if ( ACCESS_Frame( 8 ) ) @@ -79,20 +80,21 @@ extern TEngine_Instance engineInstance; FORGET_Frame(); - if ( ALLOC_ARRAY( kern0->pairs, num_pairs, TT_Kern_0_Pair ) ) + if ( GEO_ALLOC_ARRAY( kern0->pairsBlock, num_pairs, TT_Kern_0_Pair ) ) return error; if ( ACCESS_Frame( num_pairs * 6 ) ) goto Fail; + pairs = GEO_LOCK( kern0->pairsBlock ); + for ( n = 0; n < num_pairs; ++n ) { - kern0->pairs[n].left = GET_UShort(); - kern0->pairs[n].right = GET_UShort(); - kern0->pairs[n].value = GET_UShort(); + pairs[n].left = GET_UShort(); + pairs[n].right = GET_UShort(); + pairs[n].value = GET_UShort(); - if ( kern0->pairs[n].left >= input->numGlyphs || - kern0->pairs[n].right >= input->numGlyphs ) + if ( pairs[n].left >= input->numGlyphs || pairs[n].right >= input->numGlyphs ) { FORGET_Frame(); error = TT_Err_Invalid_Kerning_Table; @@ -100,6 +102,8 @@ extern TEngine_Instance engineInstance; } } + GEO_UNLOCK( kern0->pairsBlock ); + FORGET_Frame(); /* we're ok, set the pairs count */ @@ -108,7 +112,7 @@ extern TEngine_Instance engineInstance; return TT_Err_Ok; Fail: - FREE( kern0->pairs ); + GEO_FREE( kern0->pairsBlock ); return error; } @@ -396,7 +400,7 @@ extern TEngine_Instance engineInstance; switch ( sub->format ) { case 0: - FREE( sub->t.kern0.pairs ); + GEO_FREE( sub->t.kern0.pairsBlock ); sub->t.kern0.nPairs = 0; sub->t.kern0.searchRange = 0; sub->t.kern0.entrySelector = 0; diff --git a/Driver/Font/TrueType/FreeType/ftxkern.h b/Driver/Font/TrueType/FreeType/ftxkern.h index afff0e237..267c8e0ac 100644 --- a/Driver/Font/TrueType/FreeType/ftxkern.h +++ b/Driver/Font/TrueType/FreeType/ftxkern.h @@ -24,6 +24,7 @@ #define FTXKERN_H #include "freetype.h" +#include #ifdef __cplusplus extern "C" { @@ -77,8 +78,7 @@ extern "C" { TT_UShort searchRange; /* these values are defined by the TT spec */ TT_UShort entrySelector; /* for table searchs. */ TT_UShort rangeShift; - - TT_Kern_0_Pair* pairs; /* a table of nPairs `pairs' */ + MemHandle pairsBlock; /* a table of nPairs `pairs' */ }; typedef struct TT_Kern_0_ TT_Kern_0; diff --git a/Driver/Font/TrueType/FreeType/ttload.c b/Driver/Font/TrueType/FreeType/ttload.c index e49a4aa2b..cdce3b9f0 100644 --- a/Driver/Font/TrueType/FreeType/ttload.c +++ b/Driver/Font/TrueType/FreeType/ttload.c @@ -55,7 +55,7 @@ UShort i; - for ( i = 0; i < face->numTables; i++ ) + for ( i = 0; i < face->numTables; ++i ) if ( face->dirTables[i].Tag == tag ) return i; @@ -121,7 +121,7 @@ limit = face->numTables; entry = face->dirTables; - for ( n = 0; n < limit; n++ ) + for ( n = 0; n < limit; ++n ) { /* loop through the tables and get all entries */ entry->Tag = GET_Tag4(); entry->CheckSum = GET_ULong(); @@ -266,7 +266,7 @@ face->gasp.gaspRanges = gaspranges; - for ( j = 0; j < gas->numRanges; j++ ) + for ( j = 0; j < gas->numRanges; ++j ) { gaspranges[j].maxPPEM = GET_UShort(); gaspranges[j].gaspFlag = GET_UShort(); @@ -409,7 +409,7 @@ /* never trust derived values! */ num_shorts = face->maxProfile.numGlyphs - num_longs; - num_shorts_checked = ( face->dirTables[n].Length - num_longs * 4 ) / 2; + num_shorts_checked = ( face->dirTables[n].Length - num_longs * 4 ) >> 1; if ( num_shorts < 0 ) /* sanity check */ { @@ -428,7 +428,7 @@ return error; long_metric = *longs; - for ( n = 0; n < num_longs; n++ ) + for ( n = 0; n < num_longs; ++n ) { long_metric->advance = GET_UShort(); long_metric->bearing = GET_Short(); @@ -439,7 +439,7 @@ if ( num_shorts > num_shorts_checked ) { - for ( n = 0; n < num_shorts_checked; n++ ) + for ( n = 0; n < num_shorts_checked; ++n ) (*shorts)[n] = GET_Short(); /* we fill up the missing left side bearings with the */ @@ -451,7 +451,7 @@ } else { - for ( n = 0; n < num_shorts; n++ ) + for ( n = 0; n < num_shorts; ++n ) (*shorts)[n] = GET_Short(); } @@ -691,7 +691,7 @@ /* Load the name records and determine how much storage is needed */ /* to hold the strings themselves. */ - for ( i = bytes = 0; i < names->numNameRecords; i++ ) + for ( i = bytes = 0; i < names->numNameRecords; ++i ) { namerec = names->names + i; namerec->platformID = GET_UShort(); @@ -725,7 +725,7 @@ /* Go through and assign the string pointers to the name records. */ - for ( i = 0; i < names->numNameRecords; i++ ) + for ( i = 0; i < names->numNameRecords; ++i ) { namerec = names->names + i; namerec->string = storage + names->names[i].stringOffset; @@ -819,7 +819,7 @@ limit = face->cvtSize; - for ( n = 0; n < limit; n++ ) + for ( n = 0; n < limit; ++n ) face->cvt[n] = GET_Short(); FORGET_Frame(); @@ -881,7 +881,7 @@ limit = face->numCMaps; cmap = face->cMaps; - for ( n = 0; n < limit; n++ ) + for ( n = 0; n < limit; ++n ) { if ( FILE_Seek( off ) || ACCESS_Frame( 8 ) ) return error; @@ -1030,7 +1030,7 @@ os2->yStrikeoutPosition = GET_Short(); os2->sFamilyClass = GET_Short(); - for ( i = 0; i < 10; i++ ) + for ( i = 0; i < 10; ++i ) os2->panose[i] = GET_Byte(); os2->ulUnicodeRange1 = GET_ULong(); diff --git a/Driver/Font/TrueType/FreeType/ttraster.c b/Driver/Font/TrueType/FreeType/ttraster.c index 97c44578a..6a97e2cb9 100644 --- a/Driver/Font/TrueType/FreeType/ttraster.c +++ b/Driver/Font/TrueType/FreeType/ttraster.c @@ -1185,8 +1185,8 @@ /* if both first and last points are off the curve, */ /* start at their middle and record its position */ /* for closure */ - ras.lastX = (ras.lastX + x_last)/2; - ras.lastY = (ras.lastY + y_last)/2; + ras.lastX = (ras.lastX + x_last) >> 1; + ras.lastY = (ras.lastY + y_last) >> 1; x_last = ras.lastX; y_last = ras.lastY; @@ -1295,7 +1295,7 @@ start = 0; - for ( i = 0; i < ras.nContours; i++ ) + for ( i = 0; i < ras.nContours; ++i ) { ras.state = Unknown; ras.gProfile = NULL; @@ -1800,7 +1800,7 @@ } - static void _near Horizontal_Sweep_Span( RAS_ARGS Short y, + static void _near Horizontal_Sweep_Span( RAS_ARGS Short y, TT_F26Dot6 x1, TT_F26Dot6 x2, PProfile left, @@ -2337,7 +2337,7 @@ while ( y <= max_Y ) { ras.Proc_Sweep_Step( RAS_VARS y ); - y++; + ++y; } ras.Proc_Sweep_Finish( RAS_VAR ); From ef5d3d20ec8c513972fc34a5d6cc5f843e79993f Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Sat, 22 Jun 2024 18:51:10 +0200 Subject: [PATCH 26/37] Add some checks. --- Driver/Font/TrueType/Adapter/ttinit.c | 2 +- Driver/Font/TrueType/Adapter/ttwidths.c | 1 + Driver/Font/TrueType/FreeType/ftxkern.c | 2 ++ Driver/Font/TrueType/FreeType/ttraster.c | 2 ++ 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Driver/Font/TrueType/Adapter/ttinit.c b/Driver/Font/TrueType/Adapter/ttinit.c index f34d286a7..ab2624f19 100644 --- a/Driver/Font/TrueType/Adapter/ttinit.c +++ b/Driver/Font/TrueType/Adapter/ttinit.c @@ -1049,7 +1049,7 @@ static word strlen( const char* str ) for ( s = str; *s; ++s ) ; - return( s - str ); + return( s - str ); } diff --git a/Driver/Font/TrueType/Adapter/ttwidths.c b/Driver/Font/TrueType/Adapter/ttwidths.c index 38ed02bba..11ea4e2df 100644 --- a/Driver/Font/TrueType/Adapter/ttwidths.c +++ b/Driver/Font/TrueType/Adapter/ttwidths.c @@ -360,6 +360,7 @@ EC( ECCheckBounds( (void*)kernValue ) ); continue; pairs = GEO_LOCK( kerningDir.tables->t.kern0.pairsBlock ); +EC( ECCheckBounds( pairs ) ); for( i = 0; i < kerningDir.tables->t.kern0.nPairs; ++i ) { diff --git a/Driver/Font/TrueType/FreeType/ftxkern.c b/Driver/Font/TrueType/FreeType/ftxkern.c index 9ab5990c4..09e6c1225 100644 --- a/Driver/Font/TrueType/FreeType/ftxkern.c +++ b/Driver/Font/TrueType/FreeType/ftxkern.c @@ -27,6 +27,7 @@ #include "ttobjs.h" #include "ttload.h" /* For the macros */ #include "tttags.h" +#include /* Required by the tracing mode */ #undef TT_COMPONENT @@ -87,6 +88,7 @@ extern TEngine_Instance engineInstance; goto Fail; pairs = GEO_LOCK( kern0->pairsBlock ); +EC( ECCheckBounds( pairs ) ); for ( n = 0; n < num_pairs; ++n ) { diff --git a/Driver/Font/TrueType/FreeType/ttraster.c b/Driver/Font/TrueType/FreeType/ttraster.c index 6a97e2cb9..bd2f42f9a 100644 --- a/Driver/Font/TrueType/FreeType/ttraster.c +++ b/Driver/Font/TrueType/FreeType/ttraster.c @@ -2333,12 +2333,14 @@ } } +//#ifdef TT_CONFIG_OPTION_GRAY_SCALING /* for gray-scaling, flushes the bitmap scanline cache */ while ( y <= max_Y ) { ras.Proc_Sweep_Step( RAS_VARS y ); ++y; } +//#endif ras.Proc_Sweep_Finish( RAS_VAR ); return SUCCESS; From c88142838d28b2c8f2ca2ddaa8ab62b37d775afd Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Mon, 24 Jun 2024 20:18:47 +0200 Subject: [PATCH 27/37] Processing of other optional fields diasabled. --- Driver/Font/TrueType/FreeType/freetype.h | 3 +++ Driver/Font/TrueType/FreeType/ttload.c | 3 +++ Driver/Font/TrueType/FreeType/ttraster.c | 2 -- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/freetype.h b/Driver/Font/TrueType/FreeType/freetype.h index 91f062cb1..3931de166 100644 --- a/Driver/Font/TrueType/FreeType/freetype.h +++ b/Driver/Font/TrueType/FreeType/freetype.h @@ -522,10 +522,13 @@ TT_FWord underlinePosition; TT_FWord underlineThickness; TT_ULong isFixedPitch; + +#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS TT_ULong minMemType42; TT_ULong maxMemType42; TT_ULong minMemType1; TT_ULong maxMemType1; +#endif /* Glyph names follow in the file, but we don't */ /* load them by default. See the ftxpost.c extension. */ diff --git a/Driver/Font/TrueType/FreeType/ttload.c b/Driver/Font/TrueType/FreeType/ttload.c index cdce3b9f0..668918bd0 100644 --- a/Driver/Font/TrueType/FreeType/ttload.c +++ b/Driver/Font/TrueType/FreeType/ttload.c @@ -1112,10 +1112,13 @@ post->underlinePosition = GET_Short(); post->underlineThickness = GET_Short(); post->isFixedPitch = GET_ULong(); + +#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS post->minMemType42 = GET_ULong(); post->maxMemType42 = GET_ULong(); post->minMemType1 = GET_ULong(); post->maxMemType1 = GET_ULong(); +#endif FORGET_Frame(); diff --git a/Driver/Font/TrueType/FreeType/ttraster.c b/Driver/Font/TrueType/FreeType/ttraster.c index bd2f42f9a..6a97e2cb9 100644 --- a/Driver/Font/TrueType/FreeType/ttraster.c +++ b/Driver/Font/TrueType/FreeType/ttraster.c @@ -2333,14 +2333,12 @@ } } -//#ifdef TT_CONFIG_OPTION_GRAY_SCALING /* for gray-scaling, flushes the bitmap scanline cache */ while ( y <= max_Y ) { ras.Proc_Sweep_Step( RAS_VARS y ); ++y; } -//#endif ras.Proc_Sweep_Finish( RAS_VAR ); return SUCCESS; From 6bc9cdd15205218f02083ca1c7bd669bb8244d13 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Thu, 27 Jun 2024 22:27:57 +0200 Subject: [PATCH 28/37] Cmap 0 mapping disabled. --- Driver/Font/TrueType/Adapter/ttwidths.c | 2 +- Driver/Font/TrueType/FreeType/ft_conf.h | 9 ++++++++- Driver/Font/TrueType/FreeType/ttcmap.c | 26 ++++++++++++++++++------- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/Driver/Font/TrueType/Adapter/ttwidths.c b/Driver/Font/TrueType/Adapter/ttwidths.c index a625c0aac..be56ef040 100644 --- a/Driver/Font/TrueType/Adapter/ttwidths.c +++ b/Driver/Font/TrueType/Adapter/ttwidths.c @@ -302,7 +302,7 @@ EC( ECCheckBounds( (void*)charTableEntry ) ); (CTF_IS_FIRST_KERN | CTF_IS_SECOND_KERN)) break; - kernPair++; + ++kernPair; } } diff --git a/Driver/Font/TrueType/FreeType/ft_conf.h b/Driver/Font/TrueType/FreeType/ft_conf.h index 5b9cf2a5d..be86f0e04 100644 --- a/Driver/Font/TrueType/FreeType/ft_conf.h +++ b/Driver/Font/TrueType/FreeType/ft_conf.h @@ -175,7 +175,14 @@ /*************************************************************************/ -/* Define TT_CONFIG_OPTION_SUPPORT_CMAP6 if you want to support cmap 2 */ +/* Define TT_CONFIG_OPTION_SUPPORT_CMAP2 if you want to support cmap 0 */ +/* char mapping. Charmapping type 0 is now out of date. */ + +#undef TT_CONFIG_OPTION_SUPPORT_CMAP0 + + +/*************************************************************************/ +/* Define TT_CONFIG_OPTION_SUPPORT_CMAP2 if you want to support cmap 2 */ /* char mapping. Charmapping type 2 is now out of date. */ #undef TT_CONFIG_OPTION_SUPPORT_CMAP2 diff --git a/Driver/Font/TrueType/FreeType/ttcmap.c b/Driver/Font/TrueType/FreeType/ttcmap.c index f7f2ed8a1..ee6c653fb 100644 --- a/Driver/Font/TrueType/FreeType/ttcmap.c +++ b/Driver/Font/TrueType/FreeType/ttcmap.c @@ -55,7 +55,9 @@ PUShort glyphIdArray; +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP0 PCMap0 cmap0; +#endif #ifdef TT_CONFIG_OPTION_SUPPORT_CMAP2 PCMap2 cmap2; #endif @@ -78,6 +80,7 @@ switch ( cmap->format ) { +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP0 case 0: cmap0 = &cmap->c.cmap0; @@ -86,6 +89,7 @@ goto Fail; break; +#endif #ifdef TT_CONFIG_OPTION_SUPPORT_CMAP2 case 2: @@ -161,7 +165,7 @@ cmap4->entrySelector = GET_UShort(); cmap4->rangeShift = GET_UShort(); - num_Seg = cmap4->segCountX2 / 2; + num_Seg = cmap4->segCountX2 >> 1; FORGET_Frame(); @@ -170,7 +174,7 @@ if ( GEO_ALLOC_ARRAY( cmap4->segmentBlock, num_Seg, TCMap4Segment ) || - ACCESS_Frame( (num_Seg * 4 + 1) * 2 ) ) + ACCESS_Frame( (num_Seg * 4 + 1) << 1 ) ) goto Fail; segments = GEO_LOCK( cmap4->segmentBlock ); @@ -193,7 +197,7 @@ FORGET_Frame(); cmap4->numGlyphId = l = - ( ( cmap->length - ( 16L + 8L * num_Seg ) ) & 0xffff ) / 2; + ( ( cmap->length - ( 16L + 8L * num_Seg ) ) & 0xffff ) >> 1; /* load ids */ @@ -269,9 +273,11 @@ switch ( cmap->format ) { +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP0 case 0: FREE( cmap->c.cmap0.glyphIdArray ); break; +#endif #ifdef TT_CONFIG_OPTION_SUPPORT_CMAP2 case 2: @@ -316,17 +322,19 @@ * ******************************************************************/ +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP0 static UShort code_to_index0( UShort charCode, PCMap0 cmap0 ); +#endif - #ifdef TT_CONFIG_OPTION_SUPPORT_CMAP2 +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP2 static UShort code_to_index2( UShort charCode, PCMap2 cmap2 ); - #endif +#endif static UShort code_to_index4( UShort charCode, PCMap4 cmap4 ); - #ifdef TT_CONFIG_OPTION_SUPPORT_CMAP6 +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP6 static UShort code_to_index6( UShort charCode, PCMap6 cmap6 ); - #endif +#endif LOCAL_FUNC @@ -335,8 +343,10 @@ { switch ( cmap->format ) { +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP0 case 0: return code_to_index0( charcode, &cmap->c.cmap0 ); +#endif #ifdef TT_CONFIG_OPTION_SUPPORT_CMAP2 case 2: return code_to_index2( charcode, &cmap->c.cmap2 ); @@ -353,6 +363,7 @@ } +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP0 /******************************************************************* * * Function : code_to_index0 @@ -378,6 +389,7 @@ else return 0; } +#endif #ifdef TT_CONFIG_OPTION_SUPPORT_CMAP2 From 574f0b7ed0f7bf4f75bde39d31cd4b661bdf7395 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Fri, 28 Jun 2024 19:33:37 +0200 Subject: [PATCH 29/37] Few small optimizations. --- Driver/Font/TrueType/Adapter/ttinit.c | 2 -- Driver/Font/TrueType/FreeType/ttcmap.c | 9 +++++---- Driver/Font/TrueType/FreeType/ttfile.c | 1 - Driver/Font/TrueType/FreeType/ttgload.c | 3 +++ Driver/Font/TrueType/FreeType/ttload.c | 4 ++-- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Driver/Font/TrueType/Adapter/ttinit.c b/Driver/Font/TrueType/Adapter/ttinit.c index ab2624f19..e328feca0 100644 --- a/Driver/Font/TrueType/Adapter/ttinit.c +++ b/Driver/Font/TrueType/Adapter/ttinit.c @@ -1025,10 +1025,8 @@ static word GetKernCount( TRUETYPE_VARS ) pairs = GEO_LOCK( kerningDir.tables->t.kern0.pairsBlock ); for( i = 0; i < kerningDir.tables->t.kern0.nPairs; ++i ) - { if( isGeosCharPair( pairs[i].left, pairs[i].right ) ) ++numGeosKernPairs; - } GEO_UNLOCK( kerningDir.tables->t.kern0.pairsBlock ); } diff --git a/Driver/Font/TrueType/FreeType/ttcmap.c b/Driver/Font/TrueType/FreeType/ttcmap.c index ee6c653fb..6b2497d8b 100644 --- a/Driver/Font/TrueType/FreeType/ttcmap.c +++ b/Driver/Font/TrueType/FreeType/ttcmap.c @@ -49,10 +49,11 @@ { DEFINE_LOAD_LOCALS( input ); - UShort num_SH, num_Seg, i; - - UShort u, l; - +#ifdef TT_CONFIG_OPTION_SUPPORT_CMAP2 + UShort num_SH, u; +#endif + UShort num_Seg, i; + UShort l; PUShort glyphIdArray; #ifdef TT_CONFIG_OPTION_SUPPORT_CMAP0 diff --git a/Driver/Font/TrueType/FreeType/ttfile.c b/Driver/Font/TrueType/FreeType/ttfile.c index 9294a3a2b..05b85129f 100644 --- a/Driver/Font/TrueType/FreeType/ttfile.c +++ b/Driver/Font/TrueType/FreeType/ttfile.c @@ -762,7 +762,6 @@ TT_Error TT_Open_Stream( const FileHandle file, TT_Stream* stream ) { - Int len; TT_Error error; PStream_Rec stream_rec; diff --git a/Driver/Font/TrueType/FreeType/ttgload.c b/Driver/Font/TrueType/FreeType/ttgload.c index 26cfe2890..64099af8e 100644 --- a/Driver/Font/TrueType/FreeType/ttgload.c +++ b/Driver/Font/TrueType/FreeType/ttgload.c @@ -586,7 +586,10 @@ TGlyph_Zone base_pts; TPhases phase; + +#ifdef TT_CONFIG_OPTION_PROCESS_HDMX PByte widths; +#endif PStorage glyphLocations; diff --git a/Driver/Font/TrueType/FreeType/ttload.c b/Driver/Font/TrueType/FreeType/ttload.c index 668918bd0..7f9f835fc 100644 --- a/Driver/Font/TrueType/FreeType/ttload.c +++ b/Driver/Font/TrueType/FreeType/ttload.c @@ -625,7 +625,7 @@ glyphLocations = GEO_LOCK( face->glyphLocationBlock ); for ( n = 0; n < limit; ++n ) - glyphLocations[n] = (Long)((ULong)GET_UShort() * 2); + glyphLocations[n] = (Long)((ULong)GET_UShort() >> 1 ); GEO_UNLOCK( face->glyphLocationBlock ); FORGET_Frame(); @@ -806,7 +806,7 @@ return TT_Err_Ok; } - face->cvtSize = face->dirTables[n].Length / 2; + face->cvtSize = face->dirTables[n].Length << 1; if ( ALLOC_ARRAY( face->cvt, face->cvtSize, From 23e4489e4de14364cb4bc7e8e397edbca46197c9 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Sat, 29 Jun 2024 21:03:48 +0200 Subject: [PATCH 30/37] Access to tabledir fixed. --- Driver/Font/TrueType/FreeType/ttload.c | 12 ++++++------ Driver/Font/TrueType/FreeType/ttraster.c | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/ttload.c b/Driver/Font/TrueType/FreeType/ttload.c index 7f9f835fc..bb6c9f4e3 100644 --- a/Driver/Font/TrueType/FreeType/ttload.c +++ b/Driver/Font/TrueType/FreeType/ttload.c @@ -115,7 +115,7 @@ TTableDirEntry ) ) return error; - if ( ACCESS_Frame( face->numTables * 16 ) ) + if ( ACCESS_Frame( face->numTables << 4 ) ) return error; limit = face->numTables; @@ -164,7 +164,7 @@ if ( FILE_Seek( face->dirTables[i].Offset ) ) /* seek to maxprofile */ return error; - if ( ACCESS_Frame( 32L) ) /* read into frame */ + if ( ACCESS_Frame( 32 ) ) /* read into frame */ return error; /* read frame data into face table */ @@ -261,7 +261,7 @@ FORGET_Frame(); if ( ALLOC_ARRAY( gaspranges, gas->numRanges, GaspRange ) || - ACCESS_Frame( gas->numRanges * 4 ) ) + ACCESS_Frame( gas->numRanges << 2 ) ) goto Fail; face->gasp.gaspRanges = gaspranges; @@ -446,7 +446,7 @@ /* last valid value. Since this will occur for buggy CJK */ /* fonts usually, nothing serious will happen. */ - for ( n = num_shorts_checked; n < num_shorts; n++ ) + for ( n = num_shorts_checked; n < num_shorts; ++n ) (*shorts)[n] = (*shorts)[num_shorts_checked - 1]; } else @@ -625,7 +625,7 @@ glyphLocations = GEO_LOCK( face->glyphLocationBlock ); for ( n = 0; n < limit; ++n ) - glyphLocations[n] = (Long)((ULong)GET_UShort() >> 1 ); + glyphLocations[n] = (Long)((ULong)GET_UShort() << 1 ); GEO_UNLOCK( face->glyphLocationBlock ); FORGET_Frame(); @@ -806,7 +806,7 @@ return TT_Err_Ok; } - face->cvtSize = face->dirTables[n].Length << 1; + face->cvtSize = face->dirTables[n].Length >> 1; if ( ALLOC_ARRAY( face->cvt, face->cvtSize, diff --git a/Driver/Font/TrueType/FreeType/ttraster.c b/Driver/Font/TrueType/FreeType/ttraster.c index 6a97e2cb9..6cd08b2de 100644 --- a/Driver/Font/TrueType/FreeType/ttraster.c +++ b/Driver/Font/TrueType/FreeType/ttraster.c @@ -333,7 +333,7 @@ } ras.precision = 1 << ras.precision_bits; - ras.precision_half = ras.precision / 2; + ras.precision_half = ras.precision >> 1; ras.precision_shift = ras.precision_bits - Pixel_Bits; } @@ -473,7 +473,7 @@ /* look for first y value that is <= */ while ( n >= 0 && y < y_turns[n] ) - n--; + --n; /* if it is <, simply insert it, ignore if == */ if ( n >= 0 && y > y_turns[n] ) @@ -482,7 +482,7 @@ y2 = y_turns[n]; y_turns[n] = y; y = y2; - n--; + --n; } if ( n < 0 ) @@ -492,8 +492,8 @@ ras.error = Raster_Err_Overflow; return FAILURE; } - ras.maxBuff--; - ras.numTurns++; + --ras.maxBuff; + ++ras.numTurns; ras.sizeBuff[-ras.numTurns] = y; } @@ -1830,7 +1830,7 @@ } - static void _near Horizontal_Sweep_Drop( RAS_ARGS Short y, + static void _near Horizontal_Sweep_Drop( RAS_ARGS Short y, TT_F26Dot6 x1, TT_F26Dot6 x2, PProfile left, From 5ad1ef75131f3c3eb113e22d3d7b0ee1e1b836e5 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Sat, 29 Jun 2024 23:04:25 +0200 Subject: [PATCH 31/37] Update_Max() changed from Long to Short. --- Driver/Font/TrueType/FreeType/ttobjs.c | 37 +++----------------------- Driver/Font/TrueType/FreeType/ttobjs.h | 10 +++---- 2 files changed, 7 insertions(+), 40 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/ttobjs.c b/Driver/Font/TrueType/FreeType/ttobjs.c index ca2426721..9b504825d 100644 --- a/Driver/Font/TrueType/FreeType/ttobjs.c +++ b/Driver/Font/TrueType/FreeType/ttobjs.c @@ -195,35 +195,6 @@ } -#if 0 - -/******************************************************************* - * - * Function : Get_CodeRange - * - * Description : Returns a pointer to a given code range. Should - * be used only by the debugger. Returns NULL if - * 'range' is out of current bounds. - * - * Input : exec target execution context - * range new execution code range - * - * Output : Pointer to the code range record. NULL on failure. - * - *****************************************************************/ - - LOCAL_FUNC - PCodeRange Get_CodeRange( PExecution_Context exec, Int range ) - { - if ( range < 1 || range > 3 ) - return NULL; - else /* arrays start with 1 in Pascal, and with 0 in C */ - return &exec->codeRangeTable[range - 1]; - } - -#endif - - /******************************************************************* * * Function : Set_CodeRange @@ -400,10 +371,10 @@ /* new_max new capacity (size) of the buffer */ static - TT_Error Update_Max( ULong* size, - ULong multiplier, - void** buff, - ULong new_max ) + TT_Error Update_Max( UShort* size, + UShort multiplier, + void** buff, + UShort new_max ) { TT_Error error; diff --git a/Driver/Font/TrueType/FreeType/ttobjs.h b/Driver/Font/TrueType/FreeType/ttobjs.h index 71f8f9ee8..f70d8691c 100644 --- a/Driver/Font/TrueType/FreeType/ttobjs.h +++ b/Driver/Font/TrueType/FreeType/ttobjs.h @@ -625,7 +625,7 @@ Long top; /* top of exec. stack */ - ULong stackSize; /* size of exec. stack */ + UShort stackSize; /* size of exec. stack */ PStorage stack; /* current exec. stack */ Long args; @@ -654,7 +654,7 @@ ULong cvtSize; PLong cvt; - ULong glyphSize; /* glyph instructions buffer size */ + UShort glyphSize; /* glyph instructions buffer size */ PByte glyphIns; /* glyph instructions buffer */ UShort numFDefs; /* number of function defs */ @@ -686,10 +686,6 @@ TT_F26Dot6 phase; /* 'SuperRounding' */ TT_F26Dot6 threshold; - /* this seems to be unused */ -#if 0 - Int cur_ppem; /* ppem along the current proj vector */ -#endif Long scale1; /* scaling values along the current */ Long scale2; /* projection vector too.. */ Bool cached_metrics; /* the ppem is computed lazily. used */ @@ -721,7 +717,7 @@ TSet_CVT_Function func_write_cvt; /* write a cvt entry (in pixels) */ TSet_CVT_Function func_move_cvt; /* incr a cvt entry (in pixels) */ - ULong loadSize; + UShort loadSize; PSubglyph_Stack loadStack; /* loading subglyph stack */ }; From 8fe118217bf39ae605e481b400d8daa007b30ac1 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Sun, 30 Jun 2024 15:32:18 +0200 Subject: [PATCH 32/37] Further optimasations. --- Driver/Font/TrueType/FreeType/ttobjs.c | 14 +++++++------- Driver/Font/TrueType/FreeType/ttobjs.h | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/ttobjs.c b/Driver/Font/TrueType/FreeType/ttobjs.c index 9b504825d..1e39c0635 100644 --- a/Driver/Font/TrueType/FreeType/ttobjs.c +++ b/Driver/Font/TrueType/FreeType/ttobjs.c @@ -458,7 +458,7 @@ exec->maxFunc = ins->maxFunc; exec->maxIns = ins->maxIns; - for ( i = 0; i < MAX_CODE_RANGES; i++ ) + for ( i = 0; i < MAX_CODE_RANGES; ++i ) exec->codeRangeTable[i] = ins->codeRangeTable[i]; /* set graphics state */ @@ -534,7 +534,7 @@ ins->maxFunc = exec->maxFunc; ins->maxIns = exec->maxIns; - for ( i = 0; i < MAX_CODE_RANGES; i++ ) + for ( i = 0; i < MAX_CODE_RANGES; ++i ) ins->codeRangeTable[i] = exec->codeRangeTable[i]; return TT_Err_Ok; @@ -692,7 +692,7 @@ PIns_Metrics metrics = &ins->metrics; - metrics->pointSize = 10 * 64; /* default pointsize = 10pts */ + metrics->pointSize = 10 << 6; /* default pointsize = 10pts */ metrics->x_resolution = 72; /* default resolution = 72dpi */ metrics->y_resolution = 72; @@ -701,7 +701,7 @@ metrics->y_ppem = 0; /* set default compensation ( all 0 ) */ - for ( i = 0; i < 4; i++ ) + for ( i = 0; i < 4; ++i ) metrics->compensations[i] = 0; } @@ -849,7 +849,7 @@ PExecution_Context exec; TT_Error error; - ULong i; + UShort i; UShort j; PFace face; @@ -897,7 +897,7 @@ ins->metrics.scale2 ); /* All twilight points are originally zero */ - for ( j = 0; j < ins->twilight.n_points; j++ ) + for ( j = 0; j < ins->twilight.n_points; ++j ) { ins->twilight.org[j].x = 0; ins->twilight.org[j].y = 0; @@ -906,7 +906,7 @@ } /* clear storage area */ - for ( i = 0; i < ins->storeSize; i++ ) + for ( i = 0; i < ins->storeSize; ++i ) ins->storage[i] = 0; ins->GS = Default_GraphicsState; diff --git a/Driver/Font/TrueType/FreeType/ttobjs.h b/Driver/Font/TrueType/FreeType/ttobjs.h index f70d8691c..b69511a39 100644 --- a/Driver/Font/TrueType/FreeType/ttobjs.h +++ b/Driver/Font/TrueType/FreeType/ttobjs.h @@ -529,15 +529,15 @@ /* NOTE : The "hmtx" is now part of the horizontal header */ /* the font program, if any */ - ULong fontPgmSize; + UShort fontPgmSize; PByte fontProgram; /* the cvt program, if any */ - ULong cvtPgmSize; + UShort cvtPgmSize; PByte cvtProgram; /* the original, unscaled, control value table */ - ULong cvtSize; + UShort cvtSize; PShort cvt; /* The following values _must_ be set by the */ @@ -598,10 +598,10 @@ TGraphicsState GS; TGraphicsState default_GS; - ULong cvtSize; /* the scaled control value table */ + UShort cvtSize; /* the scaled control value table */ PLong cvt; - ULong storeSize; /* The storage area is now part of the */ + UShort storeSize; /* The storage area is now part of the */ PLong storage; /* instance */ TGlyph_Zone twilight; /* The instance's twilight zone */ @@ -651,7 +651,7 @@ Bool step_ins; /* true if the interpreter must */ /* increment IP after ins. exec */ - ULong cvtSize; + UShort cvtSize; PLong cvt; UShort glyphSize; /* glyph instructions buffer size */ @@ -679,7 +679,7 @@ TCodeRangeTable codeRangeTable; /* table of valid coderanges */ /* useful for the debugger */ - ULong storeSize; /* size of current storage */ + UShort storeSize; /* size of current storage */ PLong storage; /* storage area */ TT_F26Dot6 period; /* values used for the */ From 2c0645d28f29e5e632540bbbea3f195d261b6df6 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Tue, 2 Jul 2024 21:22:24 +0200 Subject: [PATCH 33/37] Move short and long metrics from fixed to movable block. --- Driver/Font/TrueType/FreeType/freetype.h | 17 +++-- Driver/Font/TrueType/FreeType/ft_conf.h | 2 +- Driver/Font/TrueType/FreeType/ttapi.c | 8 +- Driver/Font/TrueType/FreeType/ttgload.c | 20 +++-- Driver/Font/TrueType/FreeType/ttload.c | 95 +++++++++--------------- Driver/Font/TrueType/FreeType/ttload.h | 7 +- Driver/Font/TrueType/FreeType/ttobjs.c | 17 ++++- Driver/Font/TrueType/FreeType/ttobjs.h | 2 + 8 files changed, 84 insertions(+), 84 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/freetype.h b/Driver/Font/TrueType/FreeType/freetype.h index 3931de166..3afb9af33 100644 --- a/Driver/Font/TrueType/FreeType/freetype.h +++ b/Driver/Font/TrueType/FreeType/freetype.h @@ -390,10 +390,11 @@ TT_FWord min_Left_Side_Bearing; /* minimum left-sb */ TT_FWord min_Right_Side_Bearing; /* minimum right-sb */ TT_FWord xMax_Extent; /* xmax extents */ + +#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS TT_FWord caret_Slope_Rise; TT_FWord caret_Slope_Run; -#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS TT_Short Reserved0, Reserved1, Reserved2, @@ -408,8 +409,8 @@ /* but they're used to connect the metrics header to the relevant */ /* `HMTX' or `VMTX' table. */ - void* long_metrics; - void* short_metrics; + MemHandle long_metrics_block; + MemHandle short_metrics_block; }; typedef struct TT_Horizontal_Header_ TT_Horizontal_Header; @@ -433,10 +434,10 @@ TT_FWord min_Top_Side_Bearing; /* minimum left-sb or top-sb */ TT_FWord min_Bottom_Side_Bearing; /* minimum right-sb or bottom-sb */ TT_FWord yMax_Extent; /* xmax or ymax extents */ - TT_FWord caret_Slope_Rise; - TT_FWord caret_Slope_Run; #ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS + TT_FWord caret_Slope_Rise; + TT_FWord caret_Slope_Run; TT_FWord caret_Offset; TT_Short Reserved1, @@ -452,8 +453,8 @@ /* but they're used to connect the metrics header to the relevant */ /* `HMTX' or `VMTX' table. */ - void* long_metrics; - void* short_metrics; + MemHandle long_metrics_block; + MemHandle short_metrics_block; }; typedef struct TT_Vertical_Header_ TT_Vertical_Header; @@ -579,7 +580,9 @@ TT_Hdmx* hdmx; /* TrueType hor. dev. metr. table */ #endif +#ifdef TT_CONFIG_OPTION_PROCESS_VMTX TT_Vertical_Header* vertical; /* TT Vertical header, if present */ +#endif }; typedef struct TT_Face_Properties_ TT_Face_Properties; diff --git a/Driver/Font/TrueType/FreeType/ft_conf.h b/Driver/Font/TrueType/FreeType/ft_conf.h index be86f0e04..c819f5ef1 100644 --- a/Driver/Font/TrueType/FreeType/ft_conf.h +++ b/Driver/Font/TrueType/FreeType/ft_conf.h @@ -171,7 +171,7 @@ /* vtmx table. The PC/Geos ttf driver does not need any information from */ /* the vtmx table. */ -#undef TT_CONFIG_OPTION_PROCESS_VTMX +#undef TT_CONFIG_OPTION_PROCESS_VMTX /*************************************************************************/ diff --git a/Driver/Font/TrueType/FreeType/ttapi.c b/Driver/Font/TrueType/FreeType/ttapi.c index 03aa82acb..0cfe236c3 100644 --- a/Driver/Font/TrueType/FreeType/ttapi.c +++ b/Driver/Font/TrueType/FreeType/ttapi.c @@ -251,10 +251,12 @@ extern TEngine_Instance engineInstance; properties->header = &_face->fontHeader; properties->horizontal = &_face->horizontalHeader; +#ifdef TT_CONFIG_OPTION_PROCESS_VMTX if ( _face->verticalInfo ) properties->vertical = &_face->verticalHeader; else properties->vertical = NULL; +#endif properties->os2 = &_face->os2; properties->postscript = &_face->postscript; @@ -267,6 +269,7 @@ extern TEngine_Instance engineInstance; } +#ifndef __GEOS__ /******************************************************************* * * Function : TT_Get_Face_Metrics @@ -321,7 +324,7 @@ extern TEngine_Instance engineInstance; * MT-Note : YES! Reads only permanent data. * ******************************************************************/ -/* + EXPORT_FUNC TT_Error TT_Get_Face_Metrics( TT_Face face, TT_UShort firstGlyph, @@ -386,7 +389,8 @@ extern TEngine_Instance engineInstance; return TT_Err_Ok; } -*/ +#endif /* __GEOS__ */ + /******************************************************************* * diff --git a/Driver/Font/TrueType/FreeType/ttgload.c b/Driver/Font/TrueType/FreeType/ttgload.c index 64099af8e..10e98f24f 100644 --- a/Driver/Font/TrueType/FreeType/ttgload.c +++ b/Driver/Font/TrueType/FreeType/ttgload.c @@ -62,22 +62,24 @@ Short* bearing, UShort* advance ) { - PLongMetrics longs_m; - - UShort k = header->number_Of_HMetrics; + PLongMetrics longs_m = (PLongMetrics)GEO_LOCK( header->long_metrics_block ); + PShortMetrics shorts_m = (PShortMetrics)GEO_LOCK( header->short_metrics_block ); + UShort k = header->number_Of_HMetrics; if ( index < k ) { - longs_m = (PLongMetrics)header->long_metrics + index; - *bearing = longs_m->bearing; - *advance = longs_m->advance; + *bearing = longs_m[index].bearing; + *advance = longs_m[index].advance; } else { - *bearing = ((PShortMetrics)header->short_metrics)[index - k]; - *advance = ((PLongMetrics)header->long_metrics)[k - 1].advance; + *bearing = shorts_m[index - k]; + *advance = longs_m[k - 1].advance; } + + GEO_UNLOCK( header->long_metrics_block ); + GEO_UNLOCK( header->short_metrics_block ); } @@ -1169,6 +1171,7 @@ TT_Pos advance; /* scaled vertical advance height */ +#ifdef TT_CONFIG_OPTION_PROCESS_VMTX /* Get the unscaled `tsb' and `ah' values */ if ( face->verticalInfo && face->verticalHeader.number_Of_VMetrics > 0 ) @@ -1182,6 +1185,7 @@ &advance_height ); } else +#endif { /* Make up the distances from the horizontal header.. */ diff --git a/Driver/Font/TrueType/FreeType/ttload.c b/Driver/Font/TrueType/FreeType/ttload.c index bb6c9f4e3..068e8f277 100644 --- a/Driver/Font/TrueType/FreeType/ttload.c +++ b/Driver/Font/TrueType/FreeType/ttload.c @@ -353,58 +353,26 @@ * into face object. * * Input : face - * vertical set to true when loading the vmtx table, - * or false for hmtx * * Output : Error code. * ******************************************************************/ static - TT_Error Load_TrueType_Metrics( PFace face, - Bool vertical ) + TT_Error Load_TrueType_Metrics( PFace face ) { DEFINE_LOCALS; - Short n; - UShort num_shorts, num_shorts_checked, num_longs; + Short n, num_shorts; + UShort num_shorts_checked, num_longs; + PLongMetrics longs; + PShortMetrics shorts; - PLongMetrics* longs; - PShortMetrics* shorts; - PLongMetrics long_metric; + if ( ( n = TT_LookUp_Table( face, TTAG_hmtx ) ) < 0 ) + return TT_Err_Hmtx_Table_Missing; - - if ( vertical ) - { - /* The table is optional, quit silently if it wasn't found */ - /* XXX : Some fonts have a valid vertical header with a non-null */ - /* "number_of_VMetrics" fields, but no corresponding */ - /* 'vmtx' table to get the metrics from (e.g. mingliu) */ - /* */ - /* For safety, we set the field to 0 ! */ - /* */ - n = TT_LookUp_Table( face, TTAG_vmtx ); - if ( n < 0 ) - { - /* Set the number_Of_VMetrics to 0! */ - face->verticalHeader.number_Of_VMetrics = 0; - return TT_Err_Ok; - } - - num_longs = face->verticalHeader.number_Of_VMetrics; - longs = (PLongMetrics*)&face->verticalHeader.long_metrics; - shorts = (PShortMetrics*)&face->verticalHeader.short_metrics; - } - else - { - if ( ( n = TT_LookUp_Table( face, TTAG_hmtx ) ) < 0 ) - return TT_Err_Hmtx_Table_Missing; - - num_longs = face->horizontalHeader.number_Of_HMetrics; - longs = (PLongMetrics*)&face->horizontalHeader.long_metrics; - shorts = (PShortMetrics*)&face->horizontalHeader.short_metrics; - } + num_longs = face->horizontalHeader.number_Of_HMetrics; /* never trust derived values! */ @@ -412,27 +380,24 @@ num_shorts_checked = ( face->dirTables[n].Length - num_longs * 4 ) >> 1; if ( num_shorts < 0 ) /* sanity check */ - { - if ( vertical ) - return TT_Err_Invalid_Vert_Metrics; - else return TT_Err_Invalid_Horiz_Metrics; - } - if ( ALLOC_ARRAY( *longs, num_longs, TLongMetrics ) || - ALLOC_ARRAY( *shorts, num_shorts, TShortMetrics ) ) + if ( GEO_ALLOC_ARRAY( face->horizontalHeader.long_metrics_block, num_longs, TLongMetrics ) || + GEO_ALLOC_ARRAY( face->horizontalHeader.short_metrics_block, num_shorts, TShortMetrics ) ) return error; if ( FILE_Seek( face->dirTables[n].Offset ) || ACCESS_Frame( face->dirTables[n].Length ) ) return error; - long_metric = *longs; + longs = (PLongMetrics)GEO_LOCK( face->horizontalHeader.long_metrics_block ); + shorts = (PShortMetrics)GEO_LOCK( face->horizontalHeader.short_metrics_block ); + for ( n = 0; n < num_longs; ++n ) { - long_metric->advance = GET_UShort(); - long_metric->bearing = GET_Short(); - long_metric++; + longs->advance = GET_UShort(); + longs->bearing = GET_Short(); + longs++; } /* do we have an inconsistent number of metric values? */ @@ -440,19 +405,19 @@ if ( num_shorts > num_shorts_checked ) { for ( n = 0; n < num_shorts_checked; ++n ) - (*shorts)[n] = GET_Short(); + (shorts)[n] = GET_Short(); /* we fill up the missing left side bearings with the */ /* last valid value. Since this will occur for buggy CJK */ /* fonts usually, nothing serious will happen. */ for ( n = num_shorts_checked; n < num_shorts; ++n ) - (*shorts)[n] = (*shorts)[num_shorts_checked - 1]; + (shorts)[n] = (shorts)[num_shorts_checked - 1]; } else { for ( n = 0; n < num_shorts; ++n ) - (*shorts)[n] = GET_Short(); + (shorts)[n] = GET_Short(); } FORGET_Frame(); @@ -480,8 +445,11 @@ ******************************************************************/ LOCAL_FUNC - TT_Error Load_TrueType_Metrics_Header( PFace face, - Bool vertical ) + #ifdef TT_CONFIG_OPTION_PROCESS_VMTX + TT_Error Load_TrueType_Metrics_Header( PFace face, Bool vertical ) + #else + TT_Error Load_TrueType_Metrics_Header( PFace face ) + #endif { DEFINE_LOCALS; @@ -490,6 +458,7 @@ TT_Horizontal_Header* header; +#ifdef TT_CONFIG_OPTION_PROCESS_VMTX if ( vertical ) { face->verticalInfo = 0; @@ -503,6 +472,7 @@ header = (TT_Horizontal_Header*)&face->verticalHeader; } else +#endif { /* The orizontal header is mandatory, return an error if we */ /* don't find it. */ @@ -526,10 +496,11 @@ header->min_Left_Side_Bearing = GET_Short(); header->min_Right_Side_Bearing = GET_Short(); header->xMax_Extent = GET_Short(); + +#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS header->caret_Slope_Rise = GET_Short(); header->caret_Slope_Run = GET_Short(); -#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS header->Reserved0 = GET_Short(); /* this is caret_Offset for vertical headers */ header->Reserved1 = GET_Short(); @@ -537,7 +508,7 @@ header->Reserved3 = GET_Short(); header->Reserved4 = GET_Short(); #else - SKIP( 10 ); + SKIP( 14 ); #endif header->metric_Data_Format = GET_Short(); @@ -545,12 +516,16 @@ FORGET_Frame(); - header->long_metrics = NULL; - header->short_metrics = NULL; + header->long_metrics_block = NullHandle; + header->short_metrics_block = NullHandle; /* Now try to load the corresponding metrics */ +#ifdef TT_CONFIG_OPTION_PROCESS_VMTX return Load_TrueType_Metrics( face, vertical ); +#else + return Load_TrueType_Metrics( face ); +#endif } diff --git a/Driver/Font/TrueType/FreeType/ttload.h b/Driver/Font/TrueType/FreeType/ttload.h index 97fb468cf..2c6a99d4a 100644 --- a/Driver/Font/TrueType/FreeType/ttload.h +++ b/Driver/Font/TrueType/FreeType/ttload.h @@ -47,8 +47,11 @@ LOCAL_DEF TT_Error Load_TrueType_PostScript ( PFace face ); LOCAL_DEF TT_Error Load_TrueType_Hdmx ( PFace face ); - LOCAL_DEF TT_Error Load_TrueType_Metrics_Header( PFace face, - Bool vertical ); +#ifdef TT_CONFIG_OPTION_PROCESS_VMTX + LOCAL_DEF TT_Error Load_TrueType_Metrics_Header( PFace face, Bool vertical ); +#else + LOCAL_DEF TT_Error Load_TrueType_Metrics_Header( PFace face ); +#endif /* LOCAL_DEF TT_Error Load_TrueType_Any( PFace face, ULong tag, diff --git a/Driver/Font/TrueType/FreeType/ttobjs.c b/Driver/Font/TrueType/FreeType/ttobjs.c index 1e39c0635..6059e1de8 100644 --- a/Driver/Font/TrueType/FreeType/ttobjs.c +++ b/Driver/Font/TrueType/FreeType/ttobjs.c @@ -1019,9 +1019,10 @@ face->cvtSize = 0; /* freeing the horizontal metrics */ - FREE( face->horizontalHeader.long_metrics ); - FREE( face->horizontalHeader.short_metrics ); + GEO_FREE( face->horizontalHeader.long_metrics_block ); + GEO_FREE( face->horizontalHeader.short_metrics_block ); +#ifdef TT_CONFIG_OPTION_PROCESS_VMTX /* freeing the vertical ones, if any */ if (face->verticalInfo) { @@ -1029,6 +1030,7 @@ FREE( face->verticalHeader.short_metrics ); face->verticalInfo = 0; } +#endif /* freeing the programs */ FREE( face->fontProgram ); @@ -1109,8 +1111,13 @@ LOAD_( MaxProfile ) || LOAD_( Locations ) || +#ifdef TT_CONFIG_OPTION_PROCESS_VMTX (error = Load_TrueType_Metrics_Header( face, 0 )) != TT_Err_Ok || /* load the 'hhea' & 'hmtx' tables at once */ +#else + (error = Load_TrueType_Metrics_Header( face )) != TT_Err_Ok || + /* load the 'hhea' & 'hmtx' tables at once */ +#endif LOAD_( CMap ) || LOAD_( CVT ) || @@ -1118,10 +1125,12 @@ LOAD_( Gasp ) || LOAD_( Names ) || LOAD_( OS2 ) || - LOAD_( PostScript ) || + LOAD_( PostScript ) - (error = Load_TrueType_Metrics_Header( face, 1 )) != TT_Err_Ok +#ifdef TT_CONFIG_OPTION_PROCESS_VMTX + || (error = Load_TrueType_Metrics_Header( face, 1 )) != TT_Err_Ok /* try to load the 'vhea' & 'vmtx' at once if present */ +#endif #ifdef TT_CONFIG_OPTION_PROCESS_HDMX || LOAD_( Hdmx ) diff --git a/Driver/Font/TrueType/FreeType/ttobjs.h b/Driver/Font/TrueType/FreeType/ttobjs.h index b69511a39..68e908d63 100644 --- a/Driver/Font/TrueType/FreeType/ttobjs.h +++ b/Driver/Font/TrueType/FreeType/ttobjs.h @@ -498,8 +498,10 @@ /* found in the TTF file */ TT_Horizontal_Header horizontalHeader; /* the horizontal header */ +#ifdef TT_CONFIG_OPTION_PROCESS_VMTX Bool verticalInfo; /* True when vertical table */ TT_Vertical_Header verticalHeader; /* is present in the font */ +#endif TT_OS2 os2; /* 'OS/2' table */ From 82bba4c6bbc7880779a713f7a7c1378478a48399 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Wed, 3 Jul 2024 20:21:28 +0200 Subject: [PATCH 34/37] Some other fields that we do not need in the driver disabled. --- Driver/Font/TrueType/Adapter/ttinit.c | 2 +- Driver/Font/TrueType/FreeType/freetype.h | 19 +++++++++++++---- Driver/Font/TrueType/FreeType/ttapi.c | 2 +- Driver/Font/TrueType/FreeType/ttload.c | 26 ++++++++++++++++++++++-- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/Driver/Font/TrueType/Adapter/ttinit.c b/Driver/Font/TrueType/Adapter/ttinit.c index e328feca0..84028ad53 100644 --- a/Driver/Font/TrueType/Adapter/ttinit.c +++ b/Driver/Font/TrueType/Adapter/ttinit.c @@ -734,7 +734,7 @@ static sword getFontIDAvailIndex( FontID fontID, MemHandle fontInfoBlock ) ConstructOptr( fontInfoBlock, sizeof(LMemBlockHeader))) ); elements = LMemGetChunkSizePtr( fontsAvailEntrys ) / sizeof( FontsAvailEntry ); - for( element = 0; element < elements; element++ ) + for( element = 0; element < elements; ++element ) if( fontsAvailEntrys[element].FAE_fontID == fontID ) return element; diff --git a/Driver/Font/TrueType/FreeType/freetype.h b/Driver/Font/TrueType/FreeType/freetype.h index 3afb9af33..b0784a1c4 100644 --- a/Driver/Font/TrueType/FreeType/freetype.h +++ b/Driver/Font/TrueType/FreeType/freetype.h @@ -343,25 +343,31 @@ struct TT_Header_ { +#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS TT_Fixed Table_Version; TT_Fixed Font_Revision; TT_Long CheckSum_Adjust; TT_Long Magic_Number; +#endif TT_UShort Flags; TT_UShort Units_Per_EM; +#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS TT_Long Created [2]; TT_Long Modified[2]; +#endif TT_FWord xMin; TT_FWord yMin; TT_FWord xMax; TT_FWord yMax; +#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS TT_UShort Mac_Style; TT_UShort Lowest_Rec_PPEM; +#endif TT_Short Font_Direction; TT_Short Index_To_Loc_Format; @@ -389,9 +395,9 @@ TT_FWord min_Left_Side_Bearing; /* minimum left-sb */ TT_FWord min_Right_Side_Bearing; /* minimum right-sb */ - TT_FWord xMax_Extent; /* xmax extents */ - + #ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS + TT_FWord xMax_Extent; /* xmax extents */ TT_FWord caret_Slope_Rise; TT_FWord caret_Slope_Run; @@ -433,9 +439,9 @@ TT_FWord min_Top_Side_Bearing; /* minimum left-sb or top-sb */ TT_FWord min_Bottom_Side_Bearing; /* minimum right-sb or bottom-sb */ - TT_FWord yMax_Extent; /* xmax or ymax extents */ #ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS + TT_FWord yMax_Extent; /* xmax or ymax extents */ TT_FWord caret_Slope_Rise; TT_FWord caret_Slope_Run; TT_FWord caret_Offset; @@ -493,11 +499,13 @@ TT_ULong ulUnicodeRange3; /* Bits 64-95 */ TT_ULong ulUnicodeRange4; /* Bits 96-127 */ +#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS TT_Char achVendID[4]; - TT_UShort fsSelection; TT_UShort usFirstCharIndex; TT_UShort usLastCharIndex; +#endif + TT_Short sTypoAscender; TT_Short sTypoDescender; TT_Short sTypoLineGap; @@ -518,8 +526,11 @@ struct TT_Postscript_ { +#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS TT_Fixed FormatType; TT_Fixed italicAngle; +#endif + TT_FWord underlinePosition; TT_FWord underlineThickness; TT_ULong isFixedPitch; diff --git a/Driver/Font/TrueType/FreeType/ttapi.c b/Driver/Font/TrueType/FreeType/ttapi.c index 0cfe236c3..2558aec93 100644 --- a/Driver/Font/TrueType/FreeType/ttapi.c +++ b/Driver/Font/TrueType/FreeType/ttapi.c @@ -377,7 +377,7 @@ extern TEngine_Instance engineInstance; Short top_bearing; UShort advance_height; - for ( n = 0; n <= num; n++ ) + for ( n = 0; n <= num; ++n ) { TT_Get_Metrics( (TT_Horizontal_Header*)&_face->verticalHeader, firstGlyph + n, &top_bearing, &advance_height ); diff --git a/Driver/Font/TrueType/FreeType/ttload.c b/Driver/Font/TrueType/FreeType/ttload.c index 068e8f277..1e37887ea 100644 --- a/Driver/Font/TrueType/FreeType/ttload.c +++ b/Driver/Font/TrueType/FreeType/ttload.c @@ -313,27 +313,39 @@ header = &face->fontHeader; +#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS header->Table_Version = GET_ULong(); header->Font_Revision = GET_ULong(); header->CheckSum_Adjust = GET_Long(); header->Magic_Number = GET_Long(); +#else + SKIP( 16 ); +#endif header->Flags = GET_UShort(); header->Units_Per_EM = GET_UShort(); +#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS header->Created [0] = GET_Long(); header->Created [1] = GET_Long(); header->Modified[0] = GET_Long(); header->Modified[1] = GET_Long(); +#else + SKIP( 16 ); +#endif header->xMin = GET_Short(); header->yMin = GET_Short(); header->xMax = GET_Short(); header->yMax = GET_Short(); +#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS header->Mac_Style = GET_UShort(); header->Lowest_Rec_PPEM = GET_UShort(); +#else + SKIP( 4 ); +#endif header->Font_Direction = GET_Short(); header->Index_To_Loc_Format = GET_Short(); @@ -495,9 +507,9 @@ header->min_Left_Side_Bearing = GET_Short(); header->min_Right_Side_Bearing = GET_Short(); - header->xMax_Extent = GET_Short(); #ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS + header->xMax_Extent = GET_Short(); header->caret_Slope_Rise = GET_Short(); header->caret_Slope_Run = GET_Short(); @@ -508,7 +520,7 @@ header->Reserved3 = GET_Short(); header->Reserved4 = GET_Short(); #else - SKIP( 14 ); + SKIP( 16 ); #endif header->metric_Data_Format = GET_Short(); @@ -1013,12 +1025,17 @@ os2->ulUnicodeRange3 = GET_ULong(); os2->ulUnicodeRange4 = GET_ULong(); +#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS for ( i = 0; i < 4; ++i ) os2->achVendID[i] = GET_Byte(); os2->fsSelection = GET_UShort(); os2->usFirstCharIndex = GET_UShort(); os2->usLastCharIndex = GET_UShort(); +#else + SKIP( 10 ); +#endif + os2->sTypoAscender = GET_Short(); os2->sTypoDescender = GET_Short(); os2->sTypoLineGap = GET_Short(); @@ -1082,8 +1099,13 @@ /* read frame data into face table */ +#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS post->FormatType = GET_ULong(); post->italicAngle = GET_ULong(); +#else + SKIP( 8 ); +#endif + post->underlinePosition = GET_Short(); post->underlineThickness = GET_Short(); post->isFixedPitch = GET_ULong(); From ff5e2e0b9a4032845293a13126f04e637e4a07c3 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Wed, 3 Jul 2024 20:53:46 +0200 Subject: [PATCH 35/37] Codesequence only needed for gray-scale rendering disabled. --- Driver/Font/TrueType/FreeType/ttraster.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/ttraster.c b/Driver/Font/TrueType/FreeType/ttraster.c index 6cd08b2de..d1857e676 100644 --- a/Driver/Font/TrueType/FreeType/ttraster.c +++ b/Driver/Font/TrueType/FreeType/ttraster.c @@ -553,7 +553,7 @@ return FAILURE; p = p->link; - n--; + --n; } } else @@ -744,7 +744,7 @@ Ax -= Dy; x1 += Dx; } - size--; + --size; } ras.top = top; @@ -822,7 +822,7 @@ { if ( ras.joint ) { - top--; + --top; ras.joint = FALSE; } @@ -1196,7 +1196,7 @@ /* now process each contour point individually */ while ( index < last ) { - index++; + ++index; x = SCALED( ras.coords[index].x ); y = SCALED( ras.coords[index].y ); @@ -2333,12 +2333,14 @@ } } +#ifdef TT_CONFIG_OPTION_GRAY_SCALING /* for gray-scaling, flushes the bitmap scanline cache */ while ( y <= max_Y ) { ras.Proc_Sweep_Step( RAS_VARS y ); ++y; } +#endif ras.Proc_Sweep_Finish( RAS_VAR ); return SUCCESS; From cd0afc62742596585c7f07ae8affd282ab3e0bdf Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Fri, 5 Jul 2024 22:52:17 +0200 Subject: [PATCH 36/37] Some small optimizations. --- Driver/Font/TrueType/FreeType/freetype.h | 3 +- Driver/Font/TrueType/FreeType/ttapi.c | 131 ++--------------------- Driver/Font/TrueType/FreeType/ttload.c | 9 +- 3 files changed, 13 insertions(+), 130 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/freetype.h b/Driver/Font/TrueType/FreeType/freetype.h index b0784a1c4..32fceb34c 100644 --- a/Driver/Font/TrueType/FreeType/freetype.h +++ b/Driver/Font/TrueType/FreeType/freetype.h @@ -367,9 +367,10 @@ #ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS TT_UShort Mac_Style; TT_UShort Lowest_Rec_PPEM; + + TT_Short Font_Direction; #endif - TT_Short Font_Direction; TT_Short Index_To_Loc_Format; TT_Short Glyph_Data_Format; }; diff --git a/Driver/Font/TrueType/FreeType/ttapi.c b/Driver/Font/TrueType/FreeType/ttapi.c index 2558aec93..5d1846a19 100644 --- a/Driver/Font/TrueType/FreeType/ttapi.c +++ b/Driver/Font/TrueType/FreeType/ttapi.c @@ -354,7 +354,7 @@ extern TEngine_Instance engineInstance; UShort advance_width; - for ( n = 0; n <= num; n++ ) + for ( n = 0; n <= num; ++n ) { TT_Get_Metrics( &_face->horizontalHeader, firstGlyph + n, &left_bearing, &advance_width ); @@ -1080,125 +1080,6 @@ extern TEngine_Instance engineInstance; } */ -#ifdef __GEOS__ - - -/******************************************************************* - * - * Function : TT_Get_Glyph_Region - * - * Description : Produces a region from a glyph outline. - * - * Input : glyph the glyph container's handle - * map target region description block - * xOffset x offset in fractional pixels (26.6 format) - * yOffset y offset in fractional pixels (26.6 format) - * - * Output : Error code. - * - * Note : Only use integer pixel offsets to preserve the fine - * hinting of the glyph and the 'correct' anti-aliasing - * (where vertical and horizontal stems aren't grayed). - * This means that xOffset and yOffset must be multiples - * of 64! - * - * You can experiment with offsets of +32 to get 'blurred' - * versions of the glyphs (a nice effect at large sizes that - * some graphic designers may appreciate :) - * - * MT-Safe : NO! Glyph containers can't be shared. - * - ******************************************************************/ -/* - EXPORT_FUNC - TT_Error TT_Get_Glyph_Region( TT_Glyph glyph, - TT_Raster_Map* map, - TT_F26Dot6 xOffset, - TT_F26Dot6 yOffset ) - { - PEngine_Instance _engine; - TT_Error error; - PGlyph _glyph = HANDLE_Glyph( glyph ); - TT_Matrix flipmatrix = HORIZONTAL_FLIP_MATRIX; - - TT_Outline outline; - - - if ( !_glyph ) - return TT_Err_Invalid_Glyph_Handle; - - _engine = _glyph->face->engine; - - outline = _glyph->outline; - // XXX : For now, use only dropout mode 2 - // outline.dropout_mode = _glyph->scan_type; - outline.dropout_mode = 2; - - TT_Transform_Outline( &outline, &flipmatrix ); - TT_Translate_Outline( &outline, xOffset, yOffset + map->rows * 64 ); - error = TT_Get_Outline_Region( &outline, map ); - TT_Translate_Outline( &outline, -xOffset, - ( yOffset + map->rows * 64 ) ); - TT_Transform_Outline( &outline, &flipmatrix ); - - return error; - } -*/ - - /******************************************************************* - * - * Function : TT_Get_Glyph_In_Region - * - * Description : Renders a glyph into the given region path. - * - * Input : glyph the glyph container's handle - * bitmapBlock handle - * regionPath handle into the outline is to be written - * - * Output : Error code. - * - * MT-Safe : NO! Glyph containers can't be shared. - * - ******************************************************************/ -/* - EXPORT_FUNC - TT_Error TT_Get_Glyph_In_Region( TT_Glyph glyph, - MemHandle bitmapBlock, - Handle regionPath ) - { - PEngine_Instance _engine; - TT_Error error; - PGlyph _glyph = HANDLE_Glyph( glyph ); - - TT_Outline outline; - - if ( !_glyph ) - return TT_Err_Invalid_Glyph_Handle; - - _engine = _glyph->face->engine; - - outline = _glyph->outline; - - // calc region size - - // alloc bitmapBlock and init regionPath --> GrRegionPathInit - - // translate by current x,y position - - // iterate over contours - - // iterate over segments of current contour - - // switch over current segment - - // LINE_SEGMENT --> GrRegionAddLineAtCP - // CURVE_SEGMENT --> GrRegionAddBezierAtCP - // ... - - return TT_Err_Ok; - } -*/ -#endif /* __GEOS__ */ - static const TT_Outline null_outline = { 0, 0, NULL, NULL, NULL, 0, 0, 0, 0 }; @@ -1436,11 +1317,11 @@ TT_Error TT_Get_Outline_Region( TT_Outline* outline, TT_Vector* vec = outline->points; - for ( n = 0; n < outline->n_points; n++ ) + for ( n = 0; n < outline->n_points; ++n ) { vec->x += xOffset; vec->y += yOffset; - vec++; + ++vec; } } @@ -1483,9 +1364,9 @@ TT_Error TT_Get_Outline_Region( TT_Outline* outline, bbox->xMin = bbox->xMax = vec->x; bbox->yMin = bbox->yMax = vec->y; - vec++; + ++vec; - for ( k = 1; k < outline->n_points; k++ ) + for ( k = 1; k < outline->n_points; ++k ) { x = vec->x; if ( x < bbox->xMin ) bbox->xMin = x; @@ -1493,7 +1374,7 @@ TT_Error TT_Get_Outline_Region( TT_Outline* outline, y = vec->y; if ( y < bbox->yMin ) bbox->yMin = y; if ( y > bbox->yMax ) bbox->yMax = y; - vec++; + ++vec; } } return TT_Err_Ok; diff --git a/Driver/Font/TrueType/FreeType/ttload.c b/Driver/Font/TrueType/FreeType/ttload.c index 1e37887ea..b937b4681 100644 --- a/Driver/Font/TrueType/FreeType/ttload.c +++ b/Driver/Font/TrueType/FreeType/ttload.c @@ -128,7 +128,7 @@ entry->Offset = GET_Long(); entry->Length = GET_Long(); - entry++; + ++entry; } FORGET_Frame(); @@ -343,11 +343,12 @@ #ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS header->Mac_Style = GET_UShort(); header->Lowest_Rec_PPEM = GET_UShort(); + + header->Font_Direction = GET_Short(); #else - SKIP( 4 ); + SKIP( 6 ); #endif - header->Font_Direction = GET_Short(); header->Index_To_Loc_Format = GET_Short(); header->Glyph_Data_Format = GET_Short(); @@ -409,7 +410,7 @@ { longs->advance = GET_UShort(); longs->bearing = GET_Short(); - longs++; + ++longs; } /* do we have an inconsistent number of metric values? */ From e7e7bf2246ad95559c234d0659fe91d27e55e8a3 Mon Sep 17 00:00:00 2001 From: Jirka Kunze Date: Sat, 6 Jul 2024 15:28:41 +0200 Subject: [PATCH 37/37] Some further optimizations --- Driver/Font/TrueType/FreeType/freetype.h | 7 ++++++- Driver/Font/TrueType/FreeType/ft_conf.h | 7 +++++++ Driver/Font/TrueType/FreeType/ttextend.c | 8 ++++---- Driver/Font/TrueType/FreeType/ttload.c | 12 +++++++++++- Driver/Font/TrueType/FreeType/ttraster.c | 12 ++++++------ 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/Driver/Font/TrueType/FreeType/freetype.h b/Driver/Font/TrueType/FreeType/freetype.h index 32fceb34c..89ead1b34 100644 --- a/Driver/Font/TrueType/FreeType/freetype.h +++ b/Driver/Font/TrueType/FreeType/freetype.h @@ -481,6 +481,8 @@ TT_UShort usWeightClass; TT_UShort usWidthClass; TT_Short fsType; + +#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS TT_FWord ySubscriptXSize; TT_FWord ySubscriptYSize; TT_FWord ySubscriptXOffset; @@ -491,14 +493,17 @@ TT_FWord ySuperscriptYOffset; TT_FWord yStrikeoutSize; TT_FWord yStrikeoutPosition; - TT_Short sFamilyClass; +#endif + TT_Short sFamilyClass; TT_Byte panose[10]; +#ifdef TT_CONFIG_OPTION_SUPPORT_UNICODE_RANGES TT_ULong ulUnicodeRange1; /* Bits 0-31 */ TT_ULong ulUnicodeRange2; /* Bits 32-63 */ TT_ULong ulUnicodeRange3; /* Bits 64-95 */ TT_ULong ulUnicodeRange4; /* Bits 96-127 */ +#endif #ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS TT_Char achVendID[4]; diff --git a/Driver/Font/TrueType/FreeType/ft_conf.h b/Driver/Font/TrueType/FreeType/ft_conf.h index c819f5ef1..856a8d223 100644 --- a/Driver/Font/TrueType/FreeType/ft_conf.h +++ b/Driver/Font/TrueType/FreeType/ft_conf.h @@ -210,6 +210,13 @@ #undef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS +/*************************************************************************/ +/* Define TT_CONFIG_OPTION_SUPPORT_UNICODE_RANGES if you want to hold */ +/* unicode ranges in OS/2 table. */ + +#undef TT_CONFIG_OPTION_SUPPORT_UNICODE_RANGES + + /**********************************************************************/ /* */ /* The following macros are used to define the debug level, as well */ diff --git a/Driver/Font/TrueType/FreeType/ttextend.c b/Driver/Font/TrueType/FreeType/ttextend.c index 427b7ba91..90ad2285b 100644 --- a/Driver/Font/TrueType/FreeType/ttextend.c +++ b/Driver/Font/TrueType/FreeType/ttextend.c @@ -101,7 +101,7 @@ clazz->offset = exts->cur_offset; - exts->num_extensions++; + ++exts->num_extensions; exts->cur_offset += ( size + ALIGNMENT-1 ) & -ALIGNMENT; return TT_Err_Ok; @@ -125,7 +125,7 @@ registry = (PExtension_Registry)face->engine->extension_component; - for ( n = 0; n < face->n_extensions; n++ ) + for ( n = 0; n < face->n_extensions; ++n ) { clazz = registry->classes + n; if ( clazz->id == extension_id ) @@ -154,7 +154,7 @@ registry = (PExtension_Registry)engine->extension_component; - for ( n = 0; n < face->n_extensions; n++ ) + for ( n = 0; n < face->n_extensions; ++n ) { clazz = registry->classes + n; ext = (PByte)face->extension + clazz->offset; @@ -196,7 +196,7 @@ if ( ALLOC( face->extension, registry->cur_offset ) ) return error; - for ( n = 0; n < face->n_extensions; n++ ) + for ( n = 0; n < face->n_extensions; ++n ) { clazz = registry->classes + n; ext = (PByte)face->extension + clazz->offset; diff --git a/Driver/Font/TrueType/FreeType/ttload.c b/Driver/Font/TrueType/FreeType/ttload.c index b937b4681..96e4470c6 100644 --- a/Driver/Font/TrueType/FreeType/ttload.c +++ b/Driver/Font/TrueType/FreeType/ttload.c @@ -897,7 +897,7 @@ cmap->offset = FILE_Pos(); - cmap++; + ++cmap; } return TT_Err_Ok; @@ -1006,6 +1006,8 @@ os2->usWeightClass = GET_UShort(); os2->usWidthClass = GET_UShort(); os2->fsType = GET_Short(); + +#ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS os2->ySubscriptXSize = GET_Short(); os2->ySubscriptYSize = GET_Short(); os2->ySubscriptXOffset = GET_Short(); @@ -1016,15 +1018,23 @@ os2->ySuperscriptYOffset = GET_Short(); os2->yStrikeoutSize = GET_Short(); os2->yStrikeoutPosition = GET_Short(); +#else + SKIP( 20 ); +#endif + os2->sFamilyClass = GET_Short(); for ( i = 0; i < 10; ++i ) os2->panose[i] = GET_Byte(); +#ifdef TT_CONFIG_OPTION_SUPPORT_UNICODE_RANGES os2->ulUnicodeRange1 = GET_ULong(); os2->ulUnicodeRange2 = GET_ULong(); os2->ulUnicodeRange3 = GET_ULong(); os2->ulUnicodeRange4 = GET_ULong(); +#else + SKIP( 16 ); +#endif #ifdef TT_CONFIG_OPTION_SUPPORT_OPTIONAL_FIELDS for ( i = 0; i < 4; ++i ) diff --git a/Driver/Font/TrueType/FreeType/ttraster.c b/Driver/Font/TrueType/FreeType/ttraster.c index d1857e676..beb3a74d1 100644 --- a/Driver/Font/TrueType/FreeType/ttraster.c +++ b/Driver/Font/TrueType/FreeType/ttraster.c @@ -436,7 +436,7 @@ ras.cProfile->height = 0; ras.cProfile->offset = ras.top; oldProfile->next = ras.cProfile; - ras.num_Profs++; + ++ras.num_Profs; } if ( ras.top >= ras.maxBuff ) @@ -2202,7 +2202,7 @@ if ( ras.numTurns > 0 && ras.sizeBuff[-ras.numTurns] == min_Y ) - ras.numTurns--; + --ras.numTurns; while ( ras.numTurns > 0 ) { @@ -2273,7 +2273,7 @@ /* mark profile for drop-out processing */ P_Left->countL = 1; - dropouts++; + ++dropouts; goto Skip_To_Next; } @@ -2297,7 +2297,7 @@ ras.Proc_Sweep_Step( RAS_VARS y ); - y++; + ++y; if ( y < y_change ) { @@ -2421,13 +2421,13 @@ Scan_DropOuts : ras.band_stack[ras.band_top+1].y_max = j; ras.band_stack[ras.band_top].y_max = k - 1; - ras.band_top++; + ++ras.band_top; } else { if ( ras.fProfile ) if ( Draw_Sweep( RAS_VAR ) ) return ras.error; - ras.band_top--; + --ras.band_top; } }