new psnames module

This commit is contained in:
David Turner 2000-02-10 13:10:32 +00:00
parent a9369f2dc9
commit 5c9a571a5a
6 changed files with 2646 additions and 0 deletions

6
src/psnames/module.mk Normal file
View File

@ -0,0 +1,6 @@
make_module_list: add_psnames_driver
add_psnames_driver:
$(OPEN_DRIVER)psnames_driver_interface$(CLOSE_DRIVER)
$(ECHO_DRIVER)psnames $(ECHO_DRIVER_DESC) Postscript & Unicode Glyph name handling $(ECHO_DRIVER_DONE)

258
src/psnames/psdriver.c Normal file
View File

@ -0,0 +1,258 @@
#include <psdriver.h>
#include <psnames.h>
#include <ftobjs.h>
#include <stdlib.h>
#ifndef FT_CONFIG_OPTION_NO_POSTSCRIPT_NAMES
/* see the python script "freetype2/docs/glnames.py" which is used */
/* to generate the following tables... */
#include <pstables.h>
#ifdef FT_CONFIG_OPTION_ADOBE_GLYPH_LIST
/* 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.. */
/* */
static
FT_ULong PS_Unicode_Value( const char* glyph_name )
{
FT_Int n;
char first = glyph_name[0];
char temp[64];
/* if the name begins with "uni", then the glyph name may be a */
/* hard-coded unicode character code.. */
if ( glyph_name[0] == 'u' &&
glyph_name[1] == 'n' &&
glyph_name[2] == 'i' )
{
/* determine wether the following characters are hexadecimal */
FT_Int count;
FT_ULong value = 0;
const char* p = glyph_name + 4;
for ( count = 4;count > 0; count--, p++ )
{
char c = *p;
unsigned char d;
d = (unsigned char)c-'0';
if (d >= 10)
{
d = (unsigned char)c - 'A';
if ( d >= 6 )
d = 16;
else
d += 10;
}
/* exit if one non-uppercase-hexadecimal character was found */
if (d >= 16)
break;
value = (value << 4) + d;
if (count == 0)
return value;
}
}
/* look for a non-initial dot in the glyph name in order to */
/* sort-out variants like "A.swash", "e.final", etc.. */
{
const char* p;
int len;
p = glyph_name;
while ( *p && *p != '.' ) p++;
len = p-glyph_name;
if ( *p && len < 64 )
{
strncpy( temp, glyph_name, len );
temp[len] = 0;
glyph_name = temp;
}
}
/* now, lookup the glyph in the Adobe Glyph List */
for ( n = 0; n < NUM_ADOBE_GLYPHS; n++ )
{
const char* name = t1_standard_glyphs[n];
if ( first == name[0] && strcmp( glyph_name, name ) == 0 )
return names_to_unicode[n];
}
/* not found, there is probably no Unicode value for this glyph name */
return 0;
}
/* qsort callback to sort the unicode map */
static
int compare_uni_maps( const void* a, const void* b )
{
PS_UniMap* map1 = (PS_UniMap*)a;
PS_UniMap* map2 = (PS_UniMap*)b;
return ( map1->unicode < map2->unicode ? -1 :
map1->unicode > map2->unicode ? 1 : 0 );
}
/* Builds a table that maps Unicode values to glyph indices */
static
FT_Error PS_Build_Unicode_Table( FT_Memory memory,
FT_UInt num_glyphs,
const char** glyph_names,
PS_Unicodes *table )
{
FT_Error error;
/* 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;
map = table->maps;
for ( n = 0; n < num_glyphs; n++ )
{
const char* gname = glyph_names[n];
if (gname)
{
uni_char = PS_Unicode_Value(gname);
if (uni_char && uni_char != 0xFFFF)
{
map->unicode = uni_char;
map->glyph_index = n;
map++;
}
}
}
/* now, compress the table a bit */
count = map - table->maps;
if ( count > 0 && REALLOC( table->maps,
num_glyphs*sizeof(PS_UniMap),
count*sizeof(PS_UniMap) ) )
{
count = 0;
}
if (count == 0)
{
FREE( table->maps );
if (!error)
error = FT_Err_Invalid_Argument; /* no unicode chars here !! */
}
else
/* sort the table in increasing order of unicode values */
qsort( table->maps, count, sizeof(PS_UniMap), compare_uni_maps );
table->num_maps = count;
}
return error;
}
static
FT_UInt PS_Lookup_Unicode( PS_Unicodes* table,
FT_ULong unicode )
{
PS_UniMap *min, *max, *mid;
/* perform a binary search on the table */
min = table->maps;
max = min + table->num_maps - 1;
while (min <= max)
{
mid = min + (max-min)/2;
if ( mid->unicode == unicode )
return mid->glyph_index;
if (min == max)
break;
if ( mid->unicode < unicode ) min = mid+1;
else max = mid-1;
}
return 0xFFFF;
}
#endif
static
const char* PS_Macintosh_Name( FT_UInt name_index )
{
if (name_index >= 258)
name_index = 0;
return standard_glyph_names[ mac_standard_names[name_index] ];
}
static
const char* PS_Standard_Strings( FT_UInt sid )
{
return (sid < NUM_STD_GLYPHS ? t1_standard_glyphs[sid] : 0);
}
static const PSNames_Interface psnames_interface =
{
#ifdef FT_CONFIG_OPTION_ADOBE_GLYPH_LIST
(PS_Unicode_Value_Func) PS_Unicode_Value,
(PS_Build_Unicodes_Func) PS_Build_Unicode_Table,
(PS_Lookup_Unicode_Func) PS_Lookup_Unicode,
#else
0,
0,
0,
#endif
(PS_Macintosh_Name_Func) PS_Macintosh_Name,
(PS_Adobe_Std_Strings_Func) PS_Standard_Strings,
t1_standard_encoding,
t1_expert_encoding
};
EXPORT_FUNC
const FT_DriverInterface psnames_driver_interface =
{
sizeof(FT_DriverRec),
0,
0,
0,
"psnames", /* driver name */
100, /* driver version */
200, /* driver requires FreeType 2 or above */
(void*)&psnames_interface
};
#else
EXPORT_FUNC
const FT_DriverInterface psnames_driver_interface =
{
0,
0,
0,
0,
0,
100, /* driver version */
200, /* driver requires FreeType 2 or above */
0,
};
#endif /* !FT_CONFIG_OPTION_NO_POSTSCRIPT_NAMES */

31
src/psnames/psdriver.h Normal file
View File

@ -0,0 +1,31 @@
/***************************************************************************/
/* */
/* psdriver.h */
/* */
/* High-level PSNames driver interface (specification). */
/* */
/* Copyright 1996-1999 by */
/* 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. */
/* */
/***************************************************************************/
#ifndef PSDRIVER_H
#define PSDRIVER_H
#include <freetype.h>
#include <ftdriver.h>
EXPORT_DEF
const FT_DriverInterface psnames_driver_interface;
#endif /* PSDRIVER_H */
/* END */

1
src/psnames/psnames.c Normal file
View File

@ -0,0 +1 @@
#include <psdriver.c>

2259
src/psnames/pstables.h Normal file

File diff suppressed because it is too large Load Diff

91
src/psnames/rules.mk Normal file
View File

@ -0,0 +1,91 @@
#****************************************************************************
#* *
#* PSNames driver Makefile *
#* *
#* Copyright 1996-2000 by *
#* 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. *
#* *
#****************************************************************************
ifndef PSNAMES_INCLUDE
PSNAMES_INCLUDED := 1
include $(SRC_)shared/rules.mk
# PSNAMES driver directory
#
PSNAMES_DIR := $(SRC_)psnames
PSNAMES_DIR_ := $(PSNAMES_DIR)$(SEP)
# additional include flags used when compiling the driver
#
PSNAMES_INCLUDE := $(SHARED) $(PSNAMES_DIR)
# compilation flags for the driver
#
PSNAMES_CFLAGS := $(PSNAMES_INCLUDE:%=$I%)
PSNAMES_COMPILE := $(FT_COMPILE) $(PSNAMES_CFLAGS)
# TrueType driver sources (i.e., C files)
#
PSNAMES_DRV_SRC := $(PSNAMES_DIR_)psdriver.c
# TrueType driver headers
#
PSNAMES_DRV_H := $(SHARED_H) \
$(PSNAMES_DIR_)psdriver.h \
$(PSNAMES_DIR_)pstables.h
# driver object(s)
#
# PSNAMES_DRV_OBJ_M is used during `debug' builds
# PSNAMES_DRV_OBJ_S is used during `release' builds
#
PSNAMES_DRV_OBJ_M := $(PSNAMES_DRV_SRC:$(PSNAMES_DIR_)%.c=$(OBJ_)%.$O)
PSNAMES_DRV_OBJ_S := $(OBJ_)psnames.$O
# driver root source file(s)
#
PSNAMES_DRV_SRC_M := $(PSNAMES_DRV_SRC)
PSNAMES_DRV_SRC_S := $(PSNAMES_DIR_)psdriver.c
# driver - single object
#
# the driver is recompiled if any of the header or source files is changed
# as well as any of the shared source files found in `shared/sfnt'
#
$(PSNAMES_DRV_OBJ_S): $(BASE_H) $(SHARED_H) $(PSNAMES_DRV_H) $(PSNAMES_DRV_SRC) $(PSNAMES_DRV_SRC_S)
$(PSNAMES_COMPILE) $T$@ $(PSNAMES_DRV_SRC_S)
# driver - multiple objects
#
# All objects are recompiled if any of the header files is changed
#
$(OBJ_)tt%.$O: $(PSNAMES_DIR_)tt%.c $(BASE_H) $(SHARED_H) $(PSNAMES_DRV_H)
$(PSNAMES_COMPILE) $T$@ $<
$(OBJ_)sf%.$O: $(PSNAMES_DIR_)sf%.c $(BASE_H) $(SHARED_H) $(PSNAMES_DRV_H)
$(PSNAMES_COMPILE) $T$@ $<
# update main driver object lists
#
DRV_OBJS_S += $(PSNAMES_DRV_OBJ_S)
DRV_OBJS_M += $(PSNAMES_DRV_OBJ_M)
endif
# END