2000-06-25 08:47:11 +02:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* psmodule.c */
|
|
|
|
/* */
|
|
|
|
/* PSNames module implementation (body). */
|
|
|
|
/* */
|
2001-06-28 19:49:10 +02:00
|
|
|
/* Copyright 1996-2001 by */
|
2000-06-25 08:47:11 +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. */
|
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2000-12-08 17:17:16 +01:00
|
|
|
|
2000-12-08 03:42:29 +01:00
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_INTERNAL_POSTSCRIPT_NAMES_H
|
|
|
|
#include FT_INTERNAL_OBJECTS_H
|
Complete redesign of error codes. Please check ftmoderr.h for more
details.
* include/freetype/internal/cfferrs.h,
include/freetype/internal/tterrors.h,
include/freetype/internal/t1errors.h: Removed. Replaced with files
local to the module. All extra error codes have been moved to
`fterrors.h'.
* src/sfnt/ttpost.h: Move error codes to `fterrors.h'.
* src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h,
src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h,
src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h,
src/smooth/ftsmerrs.h, src/truetype/tterrors.h,
src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the
error names for the module it belongs to.
* include/freetype/ftmoderr.h: New file, defining the module error
offsets. Its structure is similar to `fterrors.h'.
* include/freetype/fterrors.h (FT_NOERRORDEF): New macro.
(FT_ERRORDEF): Redefined to use module error offsets.
All internal error codes are now public; unused error codes have
been removed, some are new.
* include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New
macro.
* include/freetype/config/ftoption.h
(FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro.
All other source files have been updated to use the new error codes;
some already existing (internal) error codes local to a module have
been renamed to give them the same name as in the base module.
All make files have been updated to include the local error files.
* src/cid/cidtokens.h: Replaced with...
* src/cid/cidtoken.h: This file for 8+3 consistency.
* src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
|
|
|
|
2001-03-20 12:14:24 +01:00
|
|
|
#include "psmodule.h"
|
|
|
|
#include "pstables.h"
|
2000-12-08 17:17:16 +01:00
|
|
|
|
Complete redesign of error codes. Please check ftmoderr.h for more
details.
* include/freetype/internal/cfferrs.h,
include/freetype/internal/tterrors.h,
include/freetype/internal/t1errors.h: Removed. Replaced with files
local to the module. All extra error codes have been moved to
`fterrors.h'.
* src/sfnt/ttpost.h: Move error codes to `fterrors.h'.
* src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h,
src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h,
src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h,
src/smooth/ftsmerrs.h, src/truetype/tterrors.h,
src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the
error names for the module it belongs to.
* include/freetype/ftmoderr.h: New file, defining the module error
offsets. Its structure is similar to `fterrors.h'.
* include/freetype/fterrors.h (FT_NOERRORDEF): New macro.
(FT_ERRORDEF): Redefined to use module error offsets.
All internal error codes are now public; unused error codes have
been removed, some are new.
* include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New
macro.
* include/freetype/config/ftoption.h
(FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro.
All other source files have been updated to use the new error codes;
some already existing (internal) error codes local to a module have
been renamed to give them the same name as in the base module.
All make files have been updated to include the local error files.
* src/cid/cidtokens.h: Replaced with...
* src/cid/cidtoken.h: This file for 8+3 consistency.
* src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
|
|
|
#include "psnamerr.h"
|
|
|
|
|
2000-07-01 16:06:46 +02:00
|
|
|
#include <stdlib.h> /* for qsort() */
|
2000-06-25 08:47:11 +02:00
|
|
|
#include <string.h> /* for strcmp(), strncpy() */
|
|
|
|
|
2000-06-22 02:27:15 +02:00
|
|
|
|
|
|
|
#ifndef FT_CONFIG_OPTION_NO_POSTSCRIPT_NAMES
|
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
|
2000-06-22 02:27:15 +02:00
|
|
|
#ifdef FT_CONFIG_OPTION_ADOBE_GLYPH_LIST
|
2000-06-25 08:47:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* return the Unicode value corresponding to a given glyph. Note that */
|
|
|
|
/* we do deal with glyph variants by detecting a non-initial dot in */
|
|
|
|
/* the name, as in `A.swash' or `e.final', etc. */
|
|
|
|
/* */
|
2001-06-28 01:25:46 +02:00
|
|
|
static FT_ULong
|
|
|
|
PS_Unicode_Value( const char* glyph_name )
|
2000-06-22 02:27:15 +02:00
|
|
|
{
|
|
|
|
FT_Int n;
|
|
|
|
char first = glyph_name[0];
|
|
|
|
char temp[64];
|
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
|
|
|
|
/* if the name begins with `uni', then the glyph name may be a */
|
|
|
|
/* hard-coded unicode character code. */
|
2000-06-22 02:27:15 +02:00
|
|
|
if ( glyph_name[0] == 'u' &&
|
|
|
|
glyph_name[1] == 'n' &&
|
|
|
|
glyph_name[2] == 'i' )
|
|
|
|
{
|
2000-07-01 16:06:46 +02:00
|
|
|
/* determine whether the next four characters following are */
|
|
|
|
/* hexadecimal. */
|
|
|
|
|
|
|
|
/* XXX: Add code to deal with ligatures, i.e. glyph names like */
|
|
|
|
/* `uniXXXXYYYYZZZZ'... */
|
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
FT_Int count;
|
|
|
|
FT_ULong value = 0;
|
2001-10-05 11:42:50 +02:00
|
|
|
const char* p = glyph_name + 3;
|
2000-06-25 08:47:11 +02:00
|
|
|
|
2000-06-22 02:27:15 +02:00
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
for ( count = 4; count > 0; count--, p++ )
|
2000-06-22 02:27:15 +02:00
|
|
|
{
|
|
|
|
char c = *p;
|
2001-06-19 10:28:24 +02:00
|
|
|
unsigned int d;
|
2000-06-22 02:27:15 +02:00
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
|
|
|
|
d = (unsigned char)c - '0';
|
|
|
|
if ( d >= 10 )
|
2000-06-22 02:27:15 +02:00
|
|
|
{
|
|
|
|
d = (unsigned char)c - 'A';
|
|
|
|
if ( d >= 6 )
|
|
|
|
d = 16;
|
|
|
|
else
|
|
|
|
d += 10;
|
|
|
|
}
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
/* exit if a non-uppercase hexadecimal character was found */
|
2000-06-25 08:47:11 +02:00
|
|
|
if ( d >= 16 )
|
2000-06-22 02:27:15 +02:00
|
|
|
break;
|
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
value = ( value << 4 ) + d;
|
2000-06-22 02:27:15 +02:00
|
|
|
}
|
2001-10-05 11:42:50 +02:00
|
|
|
if ( count == 0 )
|
|
|
|
return value;
|
2000-06-22 02:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* look for a non-initial dot in the glyph name in order to */
|
2000-06-25 08:47:11 +02:00
|
|
|
/* sort-out variants like `A.swash', `e.final', etc. */
|
2000-06-22 02:27:15 +02:00
|
|
|
{
|
|
|
|
const char* p;
|
|
|
|
int len;
|
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
|
2000-06-22 02:27:15 +02:00
|
|
|
p = glyph_name;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
while ( *p && *p != '.' )
|
|
|
|
p++;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2001-03-10 18:07:42 +01:00
|
|
|
len = (int)( p - glyph_name );
|
2000-06-22 02:27:15 +02:00
|
|
|
|
|
|
|
if ( *p && len < 64 )
|
|
|
|
{
|
|
|
|
strncpy( temp, glyph_name, len );
|
|
|
|
temp[len] = 0;
|
|
|
|
glyph_name = temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-01 16:06:46 +02:00
|
|
|
/* now, look up the glyph in the Adobe Glyph List */
|
2000-06-22 02:27:15 +02:00
|
|
|
for ( n = 0; n < NUM_ADOBE_GLYPHS; n++ )
|
|
|
|
{
|
2001-10-08 23:18:11 +02:00
|
|
|
const char* name = sid_standard_names[n];
|
2000-06-22 02:27:15 +02:00
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
|
2000-06-22 02:27:15 +02:00
|
|
|
if ( first == name[0] && strcmp( glyph_name, name ) == 0 )
|
2001-10-08 23:18:11 +02:00
|
|
|
return ps_names_to_unicode[n];
|
2000-06-22 02:27:15 +02:00
|
|
|
}
|
2000-06-25 08:47:11 +02:00
|
|
|
|
2000-06-22 02:27:15 +02:00
|
|
|
/* not found, there is probably no Unicode value for this glyph name */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
/* qsort callback to sort the unicode map */
|
2001-06-28 01:25:46 +02:00
|
|
|
FT_CALLBACK_DEF( int )
|
2001-06-27 11:26:46 +02:00
|
|
|
compare_uni_maps( const void* a,
|
|
|
|
const void* b )
|
2000-06-22 02:27:15 +02:00
|
|
|
{
|
|
|
|
PS_UniMap* map1 = (PS_UniMap*)a;
|
|
|
|
PS_UniMap* map2 = (PS_UniMap*)b;
|
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
|
2000-07-01 21:33:40 +02:00
|
|
|
return ( map1->unicode - map2->unicode );
|
2000-06-22 02:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
/* Builds a table that maps Unicode values to glyph indices */
|
2001-06-28 01:25:46 +02:00
|
|
|
static FT_Error
|
|
|
|
PS_Build_Unicode_Table( FT_Memory memory,
|
|
|
|
FT_UInt num_glyphs,
|
|
|
|
const char** glyph_names,
|
|
|
|
PS_Unicodes* table )
|
2000-06-22 02:27:15 +02:00
|
|
|
{
|
|
|
|
FT_Error error;
|
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
|
2000-06-22 02:27:15 +02:00
|
|
|
/* we first allocate the table */
|
|
|
|
table->num_maps = 0;
|
|
|
|
table->maps = 0;
|
|
|
|
|
|
|
|
if ( !ALLOC_ARRAY( table->maps, num_glyphs, PS_UniMap ) )
|
|
|
|
{
|
|
|
|
FT_UInt n;
|
|
|
|
FT_UInt count;
|
|
|
|
PS_UniMap* map;
|
|
|
|
FT_ULong uni_char;
|
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
|
2000-06-22 02:27:15 +02:00
|
|
|
map = table->maps;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-06-22 02:27:15 +02:00
|
|
|
for ( n = 0; n < num_glyphs; n++ )
|
|
|
|
{
|
|
|
|
const char* gname = glyph_names[n];
|
2000-06-25 08:47:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
if ( gname )
|
2000-06-22 02:27:15 +02:00
|
|
|
{
|
2000-06-25 08:47:11 +02:00
|
|
|
uni_char = PS_Unicode_Value( gname );
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2001-10-08 23:18:11 +02:00
|
|
|
if ( uni_char != 0 && uni_char != 0xFFFF )
|
2000-06-22 02:27:15 +02:00
|
|
|
{
|
|
|
|
map->unicode = uni_char;
|
|
|
|
map->glyph_index = n;
|
|
|
|
map++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now, compress the table a bit */
|
2001-03-10 18:07:42 +01:00
|
|
|
count = (FT_UInt)( map - table->maps );
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-06-22 02:27:15 +02:00
|
|
|
if ( count > 0 && REALLOC( table->maps,
|
2000-06-25 08:47:11 +02:00
|
|
|
num_glyphs * sizeof ( PS_UniMap ),
|
|
|
|
count * sizeof ( PS_UniMap ) ) )
|
2000-06-22 02:27:15 +02:00
|
|
|
count = 0;
|
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
if ( count == 0 )
|
2000-06-22 02:27:15 +02:00
|
|
|
{
|
|
|
|
FREE( table->maps );
|
2000-06-25 08:47:11 +02:00
|
|
|
if ( !error )
|
Complete redesign of error codes. Please check ftmoderr.h for more
details.
* include/freetype/internal/cfferrs.h,
include/freetype/internal/tterrors.h,
include/freetype/internal/t1errors.h: Removed. Replaced with files
local to the module. All extra error codes have been moved to
`fterrors.h'.
* src/sfnt/ttpost.h: Move error codes to `fterrors.h'.
* src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h,
src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h,
src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h,
src/smooth/ftsmerrs.h, src/truetype/tterrors.h,
src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the
error names for the module it belongs to.
* include/freetype/ftmoderr.h: New file, defining the module error
offsets. Its structure is similar to `fterrors.h'.
* include/freetype/fterrors.h (FT_NOERRORDEF): New macro.
(FT_ERRORDEF): Redefined to use module error offsets.
All internal error codes are now public; unused error codes have
been removed, some are new.
* include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New
macro.
* include/freetype/config/ftoption.h
(FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro.
All other source files have been updated to use the new error codes;
some already existing (internal) error codes local to a module have
been renamed to give them the same name as in the base module.
All make files have been updated to include the local error files.
* src/cid/cidtokens.h: Replaced with...
* src/cid/cidtoken.h: This file for 8+3 consistency.
* src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
|
|
|
error = PSnames_Err_Invalid_Argument; /* no unicode chars here! */
|
2000-06-22 02:27:15 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
/* sort the table in increasing order of unicode values */
|
2000-06-25 08:47:11 +02:00
|
|
|
qsort( table->maps, count, sizeof ( PS_UniMap ), compare_uni_maps );
|
2000-06-22 02:27:15 +02:00
|
|
|
|
|
|
|
table->num_maps = count;
|
|
|
|
}
|
2000-06-25 08:47:11 +02:00
|
|
|
|
2000-06-22 02:27:15 +02:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
|
2001-06-28 01:25:46 +02:00
|
|
|
static FT_UInt
|
|
|
|
PS_Lookup_Unicode( PS_Unicodes* table,
|
|
|
|
FT_ULong unicode )
|
2000-06-22 02:27:15 +02:00
|
|
|
{
|
|
|
|
PS_UniMap *min, *max, *mid;
|
2000-06-25 08:47:11 +02:00
|
|
|
|
|
|
|
|
2000-06-22 02:27:15 +02:00
|
|
|
/* perform a binary search on the table */
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-06-22 02:27:15 +02:00
|
|
|
min = table->maps;
|
|
|
|
max = min + table->num_maps - 1;
|
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
while ( min <= max )
|
2000-06-22 02:27:15 +02:00
|
|
|
{
|
2000-06-25 08:47:11 +02:00
|
|
|
mid = min + ( max - min ) / 2;
|
2000-06-22 02:27:15 +02:00
|
|
|
if ( mid->unicode == unicode )
|
|
|
|
return mid->glyph_index;
|
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
if ( min == max )
|
2000-06-22 02:27:15 +02:00
|
|
|
break;
|
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
if ( mid->unicode < unicode )
|
|
|
|
min = mid + 1;
|
|
|
|
else
|
|
|
|
max = mid - 1;
|
2000-06-22 02:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0xFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
#endif /* FT_CONFIG_OPTION_ADOBE_GLYPH_LIST */
|
2000-06-22 02:27:15 +02:00
|
|
|
|
|
|
|
|
2001-06-28 01:25:46 +02:00
|
|
|
static const char*
|
|
|
|
PS_Macintosh_Name( FT_UInt name_index )
|
2000-06-22 02:27:15 +02:00
|
|
|
{
|
2000-06-25 08:47:11 +02:00
|
|
|
if ( name_index >= 258 )
|
2000-06-22 02:27:15 +02:00
|
|
|
name_index = 0;
|
|
|
|
|
2001-10-08 23:18:11 +02:00
|
|
|
return ps_glyph_names[mac_standard_names[name_index]];
|
2000-06-22 02:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 01:25:46 +02:00
|
|
|
static const char*
|
|
|
|
PS_Standard_Strings( FT_UInt sid )
|
2000-06-22 02:27:15 +02:00
|
|
|
{
|
2001-10-08 23:18:11 +02:00
|
|
|
return ( sid < NUM_SID_GLYPHS ? sid_standard_names[sid] : 0 );
|
2000-06-22 02:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-26 12:04:16 +02:00
|
|
|
static
|
|
|
|
const PSNames_Interface psnames_interface =
|
2000-06-22 02:27:15 +02:00
|
|
|
{
|
|
|
|
#ifdef FT_CONFIG_OPTION_ADOBE_GLYPH_LIST
|
2000-06-25 08:47:11 +02:00
|
|
|
|
|
|
|
(PS_Unicode_Value_Func) PS_Unicode_Value,
|
|
|
|
(PS_Build_Unicodes_Func) PS_Build_Unicode_Table,
|
|
|
|
(PS_Lookup_Unicode_Func) PS_Lookup_Unicode,
|
|
|
|
|
2000-06-22 02:27:15 +02:00
|
|
|
#else
|
2000-06-25 08:47:11 +02:00
|
|
|
|
2000-06-22 02:27:15 +02:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
#endif /* FT_CONFIG_OPTION_ADOBE_GLYPH_LIST */
|
|
|
|
|
|
|
|
(PS_Macintosh_Name_Func) PS_Macintosh_Name,
|
|
|
|
(PS_Adobe_Std_Strings_Func)PS_Standard_Strings,
|
2000-06-22 02:27:15 +02:00
|
|
|
|
|
|
|
t1_standard_encoding,
|
|
|
|
t1_expert_encoding
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
#endif /* !FT_CONFIG_OPTION_NO_POSTSCRIPT_NAMES */
|
2000-06-22 02:27:15 +02:00
|
|
|
|
|
|
|
|
2000-11-04 02:55:49 +01:00
|
|
|
FT_CALLBACK_TABLE_DEF
|
|
|
|
const FT_Module_Class psnames_module_class =
|
2000-06-22 02:27:15 +02:00
|
|
|
{
|
|
|
|
0, /* this is not a font driver, nor a renderer */
|
2000-06-25 08:47:11 +02:00
|
|
|
sizeof( FT_ModuleRec ),
|
2000-06-22 02:27:15 +02:00
|
|
|
|
|
|
|
"psnames", /* driver name */
|
2000-07-01 16:06:46 +02:00
|
|
|
0x10000L, /* driver version */
|
|
|
|
0x20000L, /* driver requires FreeType 2 or above */
|
2000-06-22 02:27:15 +02:00
|
|
|
|
|
|
|
#ifdef FT_CONFIG_OPTION_NO_POSTSCRIPT_NAMES
|
|
|
|
0,
|
|
|
|
#else
|
|
|
|
(void*)&psnames_interface, /* module specific interface */
|
|
|
|
#endif
|
2000-07-02 02:27:53 +02:00
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
(FT_Module_Constructor)0,
|
|
|
|
(FT_Module_Destructor) 0,
|
|
|
|
(FT_Module_Requester) 0
|
2000-06-22 02:27:15 +02:00
|
|
|
};
|
|
|
|
|
2000-06-25 08:47:11 +02:00
|
|
|
|
|
|
|
/* END */
|