2018-06-03 09:01:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* pfrcmap.c
|
|
|
|
*
|
|
|
|
* FreeType PFR cmap handling (body).
|
|
|
|
*
|
2023-01-17 09:18:25 +01:00
|
|
|
* Copyright (C) 2002-2023 by
|
2018-06-03 09:01:17 +02:00
|
|
|
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
|
|
|
*
|
|
|
|
* This file is part of the FreeType project, and may only be used,
|
|
|
|
* modified, and distributed under the terms of the FreeType project
|
|
|
|
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
|
|
|
* this file you indicate that you have read the license and
|
|
|
|
* understand and accept it fully.
|
|
|
|
*
|
|
|
|
*/
|
2002-04-20 07:38:33 +02:00
|
|
|
|
|
|
|
|
2020-06-08 13:31:55 +02:00
|
|
|
#include <freetype/internal/ftdebug.h>
|
2007-01-16 07:11:27 +01:00
|
|
|
#include "pfrcmap.h"
|
2002-04-19 17:13:47 +02:00
|
|
|
#include "pfrobjs.h"
|
|
|
|
|
2007-07-07 09:30:40 +02:00
|
|
|
#include "pfrerror.h"
|
|
|
|
|
2002-04-20 07:38:33 +02:00
|
|
|
|
2002-04-19 17:13:47 +02:00
|
|
|
FT_CALLBACK_DEF( FT_Error )
|
2023-05-07 15:57:06 +02:00
|
|
|
pfr_cmap_init( FT_CMap cmap, /* PFR_CMap */
|
[cff, pfr, psaux, winfonts] Fix Savannah bug #43676.
Don't cast cmap init function pointers to an incompatible type.
Without this patch, the number of parameters between declaration and
the real signature differs. Calling such a function results in
undefined behavior.
ISO/IEC 9899:TC3 (Committee Draft September 7, 2007)
6.5.2.2 Function calls
9 If the function is defined with a type that is not
compatible with the type (of the expression) pointed to by
the expression that denotes the called function, the
behavior is undefined.
On certain platforms (c -> js with emscripten) this causes
termination of execution or invalid calls because in the emscripten
implementation, function pointers of different types are stored in
different pointer arrays. Incorrect pointer type here results in
indexing of an incorrect array.
* src/cff/cffcmap.c (cff_cmap_encoding_init, cff_cmap_unicode_init),
src/pfr/pfrcmap.c (pfr_cmap_init), src/psaux/t1cmap.c
t1_cmap_standard_init, t1_cmap_expert_init, t1_cmap_custom_init,
t1_cmap_unicode_init), src/winfonts/winfnt.c (fnt_cmap_init): Fix
signature.
2014-11-24 09:53:07 +01:00
|
|
|
FT_Pointer pointer )
|
2002-04-19 17:13:47 +02:00
|
|
|
{
|
2023-05-07 15:57:06 +02:00
|
|
|
PFR_CMap pfrcmap = (PFR_CMap)cmap;
|
|
|
|
FT_Error error = FT_Err_Ok;
|
|
|
|
PFR_Face face = (PFR_Face)FT_CMAP_FACE( cmap );
|
2002-04-19 17:13:47 +02:00
|
|
|
|
[cff, pfr, psaux, winfonts] Fix Savannah bug #43676.
Don't cast cmap init function pointers to an incompatible type.
Without this patch, the number of parameters between declaration and
the real signature differs. Calling such a function results in
undefined behavior.
ISO/IEC 9899:TC3 (Committee Draft September 7, 2007)
6.5.2.2 Function calls
9 If the function is defined with a type that is not
compatible with the type (of the expression) pointed to by
the expression that denotes the called function, the
behavior is undefined.
On certain platforms (c -> js with emscripten) this causes
termination of execution or invalid calls because in the emscripten
implementation, function pointers of different types are stored in
different pointer arrays. Incorrect pointer type here results in
indexing of an incorrect array.
* src/cff/cffcmap.c (cff_cmap_encoding_init, cff_cmap_unicode_init),
src/pfr/pfrcmap.c (pfr_cmap_init), src/psaux/t1cmap.c
t1_cmap_standard_init, t1_cmap_expert_init, t1_cmap_custom_init,
t1_cmap_unicode_init), src/winfonts/winfnt.c (fnt_cmap_init): Fix
signature.
2014-11-24 09:53:07 +01:00
|
|
|
FT_UNUSED( pointer );
|
|
|
|
|
2002-04-19 17:13:47 +02:00
|
|
|
|
2023-05-07 15:57:06 +02:00
|
|
|
pfrcmap->num_chars = face->phy_font.num_chars;
|
|
|
|
pfrcmap->chars = face->phy_font.chars;
|
2007-01-16 07:11:27 +01:00
|
|
|
|
2002-04-19 17:13:47 +02:00
|
|
|
/* just for safety, check that the character entries are correctly */
|
2002-04-20 07:38:33 +02:00
|
|
|
/* sorted in increasing character code order */
|
2002-04-19 17:13:47 +02:00
|
|
|
{
|
|
|
|
FT_UInt n;
|
2007-01-16 07:11:27 +01:00
|
|
|
|
2002-04-20 07:38:33 +02:00
|
|
|
|
2023-05-07 15:57:06 +02:00
|
|
|
for ( n = 1; n < pfrcmap->num_chars; n++ )
|
2002-04-19 17:13:47 +02:00
|
|
|
{
|
2023-05-07 15:57:06 +02:00
|
|
|
if ( pfrcmap->chars[n - 1].char_code >= pfrcmap->chars[n].char_code )
|
2007-06-06 06:47:49 +02:00
|
|
|
{
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_Table );
|
2007-06-06 06:47:49 +02:00
|
|
|
goto Exit;
|
|
|
|
}
|
2002-04-19 17:13:47 +02:00
|
|
|
}
|
|
|
|
}
|
2007-01-16 07:11:27 +01:00
|
|
|
|
2007-06-06 06:47:49 +02:00
|
|
|
Exit:
|
|
|
|
return error;
|
2002-04-19 17:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_CALLBACK_DEF( void )
|
2023-05-07 15:57:06 +02:00
|
|
|
pfr_cmap_done( FT_CMap cmap ) /* PFR_CMap */
|
2002-04-19 17:13:47 +02:00
|
|
|
{
|
2023-05-07 15:57:06 +02:00
|
|
|
PFR_CMap pfrcmap = (PFR_CMap)cmap;
|
|
|
|
|
|
|
|
|
|
|
|
pfrcmap->chars = NULL;
|
|
|
|
pfrcmap->num_chars = 0;
|
2002-04-19 17:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
2023-05-07 15:57:06 +02:00
|
|
|
pfr_cmap_char_index( FT_CMap cmap, /* PFR_CMap */
|
2002-04-19 17:13:47 +02:00
|
|
|
FT_UInt32 char_code )
|
|
|
|
{
|
2023-05-07 15:57:06 +02:00
|
|
|
PFR_CMap pfrcmap = (PFR_CMap)cmap;
|
|
|
|
FT_UInt min = 0;
|
|
|
|
FT_UInt max = pfrcmap->num_chars;
|
|
|
|
FT_UInt mid = min + ( max - min ) / 2;
|
2022-11-06 19:12:47 +01:00
|
|
|
PFR_Char gchar;
|
2002-04-19 17:13:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
while ( min < max )
|
|
|
|
{
|
2023-05-07 15:57:06 +02:00
|
|
|
gchar = pfrcmap->chars + mid;
|
2002-04-19 17:13:47 +02:00
|
|
|
|
|
|
|
if ( gchar->char_code == char_code )
|
2002-06-17 10:01:32 +02:00
|
|
|
return mid + 1;
|
2002-04-19 17:13:47 +02:00
|
|
|
|
|
|
|
if ( gchar->char_code < char_code )
|
|
|
|
min = mid + 1;
|
|
|
|
else
|
|
|
|
max = mid;
|
2022-11-06 19:12:47 +01:00
|
|
|
|
|
|
|
/* reasonable prediction in a continuous block */
|
|
|
|
mid += char_code - gchar->char_code;
|
|
|
|
if ( mid >= max || mid < min )
|
|
|
|
mid = min + ( max - min ) / 2;
|
2002-04-19 17:13:47 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-10 17:30:43 +02:00
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
2023-05-07 15:57:06 +02:00
|
|
|
pfr_cmap_char_next( FT_CMap cmap, /* PFR_CMap */
|
2002-04-20 07:38:33 +02:00
|
|
|
FT_UInt32 *pchar_code )
|
2002-04-19 17:13:47 +02:00
|
|
|
{
|
2023-05-07 15:57:06 +02:00
|
|
|
PFR_CMap pfrcmap = (PFR_CMap)cmap;
|
2002-04-19 17:13:47 +02:00
|
|
|
FT_UInt result = 0;
|
|
|
|
FT_UInt32 char_code = *pchar_code + 1;
|
|
|
|
|
|
|
|
|
|
|
|
Restart:
|
|
|
|
{
|
|
|
|
FT_UInt min = 0;
|
2023-05-07 15:57:06 +02:00
|
|
|
FT_UInt max = pfrcmap->num_chars;
|
2022-11-06 19:12:47 +01:00
|
|
|
FT_UInt mid = min + ( max - min ) / 2;
|
2002-04-19 17:13:47 +02:00
|
|
|
PFR_Char gchar;
|
|
|
|
|
|
|
|
|
|
|
|
while ( min < max )
|
|
|
|
{
|
2023-05-07 15:57:06 +02:00
|
|
|
gchar = pfrcmap->chars + mid;
|
2002-04-19 17:13:47 +02:00
|
|
|
|
|
|
|
if ( gchar->char_code == char_code )
|
|
|
|
{
|
|
|
|
result = mid;
|
|
|
|
if ( result != 0 )
|
2002-06-17 10:01:32 +02:00
|
|
|
{
|
|
|
|
result++;
|
2002-04-19 17:13:47 +02:00
|
|
|
goto Exit;
|
2002-06-17 10:01:32 +02:00
|
|
|
}
|
2002-04-19 17:13:47 +02:00
|
|
|
|
|
|
|
char_code++;
|
|
|
|
goto Restart;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( gchar->char_code < char_code )
|
2015-10-27 19:27:39 +01:00
|
|
|
min = mid + 1;
|
2002-04-19 17:13:47 +02:00
|
|
|
else
|
|
|
|
max = mid;
|
2022-11-06 19:12:47 +01:00
|
|
|
|
|
|
|
/* reasonable prediction in a continuous block */
|
|
|
|
mid += char_code - gchar->char_code;
|
|
|
|
if ( mid >= max || mid < min )
|
|
|
|
mid = min + ( max - min ) / 2;
|
2002-04-19 17:13:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* we didn't find it, but we have a pair just above it */
|
|
|
|
char_code = 0;
|
|
|
|
|
2023-05-07 15:57:06 +02:00
|
|
|
if ( min < pfrcmap->num_chars )
|
2002-04-19 17:13:47 +02:00
|
|
|
{
|
2023-05-07 15:57:06 +02:00
|
|
|
gchar = pfrcmap->chars + min;
|
2002-04-19 17:13:47 +02:00
|
|
|
result = min;
|
|
|
|
if ( result != 0 )
|
2002-06-17 10:01:32 +02:00
|
|
|
{
|
|
|
|
result++;
|
2002-04-19 17:13:47 +02:00
|
|
|
char_code = gchar->char_code;
|
2002-06-17 10:01:32 +02:00
|
|
|
}
|
2002-04-19 17:13:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
*pchar_code = char_code;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
|
|
|
|
pfr_cmap_class_rec =
|
|
|
|
{
|
|
|
|
sizeof ( PFR_CMapRec ),
|
|
|
|
|
2016-09-17 17:12:50 +02:00
|
|
|
(FT_CMap_InitFunc) pfr_cmap_init, /* init */
|
|
|
|
(FT_CMap_DoneFunc) pfr_cmap_done, /* done */
|
|
|
|
(FT_CMap_CharIndexFunc)pfr_cmap_char_index, /* char_index */
|
|
|
|
(FT_CMap_CharNextFunc) pfr_cmap_char_next, /* char_next */
|
|
|
|
|
|
|
|
(FT_CMap_CharVarIndexFunc) NULL, /* char_var_index */
|
|
|
|
(FT_CMap_CharVarIsDefaultFunc)NULL, /* char_var_default */
|
|
|
|
(FT_CMap_VariantListFunc) NULL, /* variant_list */
|
|
|
|
(FT_CMap_CharVariantListFunc) NULL, /* charvariant_list */
|
|
|
|
(FT_CMap_VariantCharListFunc) NULL /* variantchar_list */
|
2002-04-19 17:13:47 +02:00
|
|
|
};
|
2002-04-20 07:38:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* END */
|