2002-04-20 07:38:33 +02:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* pfrcmap.c */
|
|
|
|
/* */
|
|
|
|
/* FreeType PFR cmap handling (body). */
|
|
|
|
/* */
|
2013-03-14 10:27:35 +01:00
|
|
|
/* Copyright 2002, 2007, 2009, 2013 by */
|
2002-04-20 07:38:33 +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. */
|
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
|
2013-03-14 10:27:35 +01:00
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_INTERNAL_DEBUG_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 )
|
[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
|
|
|
pfr_cmap_init( PFR_CMap cmap,
|
|
|
|
FT_Pointer pointer )
|
2002-04-19 17:13:47 +02:00
|
|
|
{
|
2013-03-14 11:21:17 +01:00
|
|
|
FT_Error error = FT_Err_Ok;
|
2007-06-06 06:47:49 +02:00
|
|
|
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
|
|
|
|
|
|
|
cmap->num_chars = face->phy_font.num_chars;
|
|
|
|
cmap->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
|
|
|
|
2002-04-19 17:13:47 +02:00
|
|
|
for ( n = 1; n < cmap->num_chars; n++ )
|
|
|
|
{
|
2002-04-20 07:38:33 +02:00
|
|
|
if ( cmap->chars[n - 1].char_code >= cmap->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 )
|
|
|
|
pfr_cmap_done( PFR_CMap cmap )
|
|
|
|
{
|
|
|
|
cmap->chars = NULL;
|
|
|
|
cmap->num_chars = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
|
|
|
pfr_cmap_char_index( PFR_CMap cmap,
|
|
|
|
FT_UInt32 char_code )
|
|
|
|
{
|
2013-08-01 12:20:20 +02:00
|
|
|
FT_UInt min = 0;
|
|
|
|
FT_UInt max = cmap->num_chars;
|
2002-04-19 17:13:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
while ( min < max )
|
|
|
|
{
|
2013-08-01 12:20:20 +02:00
|
|
|
PFR_Char gchar;
|
|
|
|
FT_UInt mid;
|
|
|
|
|
|
|
|
|
2002-04-19 17:13:47 +02:00
|
|
|
mid = min + ( max - min ) / 2;
|
|
|
|
gchar = cmap->chars + mid;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-31 17:32:09 +02:00
|
|
|
FT_CALLBACK_DEF( FT_UInt32 )
|
2002-04-20 07:38:33 +02:00
|
|
|
pfr_cmap_char_next( PFR_CMap cmap,
|
|
|
|
FT_UInt32 *pchar_code )
|
2002-04-19 17:13:47 +02:00
|
|
|
{
|
|
|
|
FT_UInt result = 0;
|
|
|
|
FT_UInt32 char_code = *pchar_code + 1;
|
|
|
|
|
|
|
|
|
|
|
|
Restart:
|
|
|
|
{
|
|
|
|
FT_UInt min = 0;
|
|
|
|
FT_UInt max = cmap->num_chars;
|
|
|
|
FT_UInt mid;
|
|
|
|
PFR_Char gchar;
|
|
|
|
|
|
|
|
|
|
|
|
while ( min < max )
|
|
|
|
{
|
|
|
|
mid = min + ( ( max - min ) >> 1 );
|
|
|
|
gchar = cmap->chars + mid;
|
|
|
|
|
|
|
|
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 )
|
|
|
|
min = mid+1;
|
|
|
|
else
|
|
|
|
max = mid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we didn't find it, but we have a pair just above it */
|
|
|
|
char_code = 0;
|
|
|
|
|
|
|
|
if ( min < cmap->num_chars )
|
|
|
|
{
|
|
|
|
gchar = cmap->chars + min;
|
|
|
|
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 ),
|
|
|
|
|
2002-04-20 07:38:33 +02:00
|
|
|
(FT_CMap_InitFunc) pfr_cmap_init,
|
|
|
|
(FT_CMap_DoneFunc) pfr_cmap_done,
|
|
|
|
(FT_CMap_CharIndexFunc)pfr_cmap_char_index,
|
Add support for cmap type 14.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_CMAP_FORMAT_14): New macro.
* include/freetype/internal/ftobjs.h (FT_CMap_CharVarIndexFunc,
FT_CMap_CharVarIsDefaultFunc, FT_CMap_VariantListFunc,
FT_CMap_CharVariantListFunc, FT_CMap_VariantCharListFunc): New
support function prototypes.
(FT_CMap_ClassRec): Add them.
Update all users.
* include/freetype/ttnameid.h (TT_APPLE_ID_VARIANT_SELECTOR): New
macro.
* include/freetype/freetype.h (FT_Get_Char_Variant_Index,
FT_Get_Char_Variant_IsDefault, FT_Get_Variant_Selectors,
FT_Get_Variants_Of_Char, FT_Get_Chars_Of_Variant): New API
functions.
* src/base/ftobjs.c (find_variant_selector_charmap): New auxiliary
function.
(FT_Set_Charmap): Disallow cmaps of type 14.
(FT_Get_Char_Variant_Index, FT_Get_Char_Variant_IsDefault,
FT_Get_Variant_Selectors, FT_Get_Variants_Of_Char,
FT_Get_Chars_Of_Variant): New API functions.
* src/sfnt/ttcmap.c (TT_PEEK_UINT24, TT_NEXT_UINT24): New macros.
(TT_CMap14Rec, tt_cmap14_init, tt_cmap14_validate,
tt_cmap14_char_index, tt_cmap14_char_next, tt_cmap14_get_info,
tt_cmap14_char_map_def_binary, tt_cmap14_char_map_nondef_binary,
tt_cmap14_find_variant, tt_cmap14_char_var_index,
tt_cmap14_char_var_isdefault, tt_cmap14_variants,
tt_cmap14_char_variants, tt_cmap14_def_char_count,
tt_cmap14_get_def_chars, tt_cmap14_get_nondef_chars,
tt_cmap14_variant_chars, tt_cmap14_class_rec): New functions and
structures for cmap 14 support.
(tt_cmap_classes): Register tt_cmap14_class_rec.
(tt_face_build_cmaps): One more error message.
* docs/CHANGES: Mention cmap 14 support.
2007-10-15 19:21:32 +02:00
|
|
|
(FT_CMap_CharNextFunc) pfr_cmap_char_next,
|
|
|
|
|
|
|
|
NULL, NULL, NULL, NULL, NULL
|
2002-04-19 17:13:47 +02:00
|
|
|
};
|
2002-04-20 07:38:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* END */
|