6 |
# |
# |
7 |
|
|
8 |
|
|
9 |
# Copyright 1996-2000, 2003 by |
# Copyright 1996-2000, 2003, 2005 by |
10 |
# David Turner, Robert Wilhelm, and Werner Lemberg. |
# David Turner, Robert Wilhelm, and Werner Lemberg. |
11 |
# |
# |
12 |
# This file is part of the FreeType project, and may only be used, modified, |
# This file is part of the FreeType project, and may only be used, modified, |
20 |
|
|
21 |
usage: %s <output-file> |
usage: %s <output-file> |
22 |
|
|
23 |
This very simple python script is used to generate the glyph names |
This python script generates the glyph names tables defined in the |
24 |
tables defined in the PSNames module. |
PSNames module. |
25 |
|
|
26 |
Its single argument is the name of the header file to be created. |
Its single argument is the name of the header file to be created. |
27 |
""" |
""" |
28 |
|
|
29 |
|
|
30 |
import sys, string, struct |
import sys, string, struct, re, os.path |
31 |
|
|
32 |
|
|
33 |
# This table is used to name the glyphs according to the Macintosh |
# This table lists the glyphs according to the Macintosh specification. |
34 |
# specification. It is used by the TrueType Postscript names table. |
# It is used by the TrueType Postscript names table. |
35 |
|
# |
36 |
|
# See |
37 |
|
# |
38 |
|
# http://fonts.apple.com/TTRefMan/RM06/Chap6post.html |
39 |
# |
# |
|
# See http://fonts.apple.com/TTRefMan/RM06/Chap6post.html |
|
40 |
# for the official list. |
# for the official list. |
41 |
# |
# |
42 |
mac_standard_names = \ |
mac_standard_names = \ |
148 |
] |
] |
149 |
|
|
150 |
|
|
151 |
# The list of standard "SID" glyph names. For the official list, |
# The list of standard `SID' glyph names. For the official list, |
152 |
# see Annex A of document at |
# see Annex A of document at |
153 |
# http://partners.adobe.com/asn/developer/pdfs/tn/5176.CFF.pdf. |
# |
154 |
|
# http://partners.adobe.com/asn/developer/pdfs/tn/5176.CFF.pdf. |
155 |
# |
# |
156 |
sid_standard_names = \ |
sid_standard_names = \ |
157 |
[ |
[ |
4706 |
# string table management |
# string table management |
4707 |
# |
# |
4708 |
class StringTable: |
class StringTable: |
4709 |
def __init__(self,name_list): |
def __init__( self, name_list, master_table_name ): |
4710 |
self.names = name_list |
self.names = name_list |
4711 |
self.indices = {} |
self.master_table = master_table_name |
4712 |
index = 0 |
self.indices = {} |
4713 |
|
index = 0 |
4714 |
|
|
4715 |
for name in name_list: |
for name in name_list: |
4716 |
self.indices[name] = index |
self.indices[name] = index |
4717 |
index += len(name) + 1 |
index += len( name ) + 1 |
4718 |
|
|
4719 |
self.total = index |
self.total = index |
4720 |
|
|
4721 |
def dump(self,file,table_name): |
def dump( self, file ): |
4722 |
write = file.write |
write = file.write |
4723 |
write( "static const char " + table_name + "["+repr(self.total)+"] =\n" ) |
write( " static const char " + self.master_table + |
4724 |
write( "{\n" ) |
"[" + repr( self.total ) + "] =\n" ) |
4725 |
column = 0 |
write( " {\n" ) |
4726 |
line = " " |
|
4727 |
comma = "" |
line = "" |
4728 |
for name in self.names: |
for name in self.names: |
4729 |
for n in range(len(name)): |
line += " '" |
4730 |
line += comma |
line += string.join( ( re.findall( ".", name ) ), "','" ) |
4731 |
line += "'%c'" % name[n] |
line += "', 0,\n" |
4732 |
comma = "," |
|
4733 |
column += 1 |
write( line + " };\n\n\n" ) |
|
if column == 16: |
|
|
column = 0 |
|
|
comma = ",\n " |
|
|
line += comma |
|
|
line += " 0 " |
|
|
comma = "," |
|
|
column += 1 |
|
|
if column == 16: |
|
|
column = 0 |
|
|
comma = ",\n " |
|
|
|
|
|
if column != 0: |
|
|
line += "\n" |
|
|
|
|
|
write( line + "};\n\n" ) |
|
|
|
|
|
def dump_sublist(self,file,table_name,macro_name,sublist): |
|
|
write = file.write |
|
|
write( "#define "+macro_name+" "+repr(len(sublist))+"\n\n" ) |
|
|
write( "static const short " + table_name + "["+repr(len(sublist))+"] =\n" ) |
|
|
write( "{\n" ) |
|
|
line = " " |
|
|
comma = "" |
|
|
col = 0 |
|
|
for name in sublist: |
|
|
line += comma |
|
|
line += "%4d" % self.indices[name] |
|
|
col += 1 |
|
|
comma = "," |
|
|
if col == 14: |
|
|
col = 0 |
|
|
comma = ",\n " |
|
|
|
|
|
write( line + "\n};\n\n" ) |
|
|
|
|
|
|
|
|
class StringNode: |
|
|
def __init__(self,letter,value): |
|
|
self.letter = letter |
|
|
self.value = value |
|
|
self.children = {} |
|
|
|
|
|
def __cmp__(self,other): |
|
|
return ord(self.letter[0]) - ord(other.letter[0]) |
|
|
|
|
|
def add(self,word,value): |
|
|
if len(word) == 0: |
|
|
self.value = value |
|
|
return |
|
|
letter = word[0] |
|
|
word = word[1:] |
|
|
if self.children.has_key(letter): |
|
|
child = self.children[letter] |
|
|
else: |
|
|
child = StringNode(letter,0) |
|
|
self.children[letter] = child |
|
|
child.add(word,value) |
|
|
|
|
|
def optimize(self): |
|
|
# optimize all children first |
|
|
children = self.children.values() |
|
|
self.children = {} |
|
|
for child in children: |
|
|
self.children[child.letter[0]] = child.optimize() |
|
|
|
|
|
# don't optimize if there's a value, |
|
|
# if we don't have any child or if we |
|
|
# have more than one child |
|
|
if (self.value != 0) or (not children) or len(children) > 1: |
|
|
return self |
|
|
|
|
|
child = children[0] |
|
|
self.letter += child.letter |
|
|
self.value = child.value |
|
|
self.children = child.children |
|
|
return self |
|
|
|
|
|
def dump_debug(self,write,margin): |
|
|
# this is used during debugging |
|
|
line = margin + "+-" |
|
|
if len(self.letter) == 0: |
|
|
line += "<NOLETTER>" |
|
|
else: |
|
|
line += self.letter |
|
|
|
|
|
if self.value: |
|
|
line += " => " + repr(self.value) |
|
|
|
|
|
write( line+"\n" ) |
|
|
if self.children: |
|
|
margin += "| " |
|
|
for child in self.children.values(): |
|
|
child.dump_debug(write,margin) |
|
|
|
|
|
def locate(self,index): |
|
|
self.index = index |
|
|
if len(self.letter) > 0: |
|
|
index += len(self.letter)+1 |
|
|
else: |
|
|
index += 2 |
|
|
|
|
|
if self.value != 0: |
|
|
index += 2 |
|
|
|
|
|
children = self.children.values() |
|
|
children.sort() |
|
|
index += 2*len(children) |
|
|
for child in children: |
|
|
index = child.locate(index) |
|
|
|
|
|
return index |
|
|
|
|
|
def store(self,storage): |
|
|
# write the letters |
|
|
l = len(self.letter) |
|
|
if l == 0: |
|
|
storage += struct.pack("B",0) |
|
|
else: |
|
|
for n in range(l): |
|
|
val = ord(self.letter[n]) |
|
|
if n < l-1: |
|
|
val += 128 |
|
|
storage += struct.pack("B",val) |
|
|
|
|
|
# write the count |
|
|
children = self.children.values() |
|
|
children.sort() |
|
|
count = len(children) |
|
|
if self.value != 0: |
|
|
storage += struct.pack( "!BH", count+128, self.value ) |
|
|
else: |
|
|
storage += struct.pack( "B", count ) |
|
|
|
|
|
for child in children: |
|
|
storage += struct.pack( "!H", child.index ) |
|
|
|
|
|
for child in children: |
|
|
storage = child.store(storage) |
|
|
|
|
|
return storage |
|
4734 |
|
|
4735 |
t1_bias = 0 |
def dump_sublist( self, file, table_name, macro_name, sublist ): |
4736 |
glyph_list = [] |
write = file.write |
4737 |
|
write( "#define " + macro_name + " " + repr( len( sublist ) ) + "\n\n" ) |
4738 |
|
|
4739 |
|
write( " /* Values are offsets into the `" + |
4740 |
|
self.master_table + "' table */\n\n" ) |
4741 |
|
write( " static const short " + table_name + |
4742 |
|
"[" + macro_name + "] =\n" ) |
4743 |
|
write( " {\n" ) |
4744 |
|
|
4745 |
def adobe_glyph_names(): |
line = " " |
4746 |
"""return the list of glyph names from the adobe list""" |
comma = "" |
4747 |
|
col = 0 |
4748 |
|
|
4749 |
lines = string.split( adobe_glyph_list, '\n' ) |
for name in sublist: |
4750 |
glyphs = [] |
line += comma |
4751 |
|
line += "%4d" % self.indices[name] |
4752 |
|
col += 1 |
4753 |
|
comma = "," |
4754 |
|
if col == 14: |
4755 |
|
col = 0 |
4756 |
|
comma = ",\n " |
4757 |
|
|
4758 |
|
write( line + "\n };\n\n\n" ) |
4759 |
|
|
4760 |
|
|
4761 |
|
class StringNode: |
4762 |
|
def __init__( self, letter, value ): |
4763 |
|
self.letter = letter |
4764 |
|
self.value = value |
4765 |
|
self.children = {} |
4766 |
|
|
4767 |
|
def __cmp__( self, other ): |
4768 |
|
return ord( self.letter[0] ) - ord( other.letter[0] ) |
4769 |
|
|
4770 |
|
def add( self, word, value ): |
4771 |
|
if len( word ) == 0: |
4772 |
|
self.value = value |
4773 |
|
return |
4774 |
|
|
4775 |
|
letter = word[0] |
4776 |
|
word = word[1:] |
4777 |
|
|
4778 |
|
if self.children.has_key( letter ): |
4779 |
|
child = self.children[letter] |
4780 |
|
else: |
4781 |
|
child = StringNode( letter, 0 ) |
4782 |
|
self.children[letter] = child |
4783 |
|
|
4784 |
|
child.add( word, value ) |
4785 |
|
|
4786 |
|
def optimize( self ): |
4787 |
|
# optimize all children first |
4788 |
|
children = self.children.values() |
4789 |
|
self.children = {} |
4790 |
|
|
4791 |
|
for child in children: |
4792 |
|
self.children[child.letter[0]] = child.optimize() |
4793 |
|
|
4794 |
|
# don't optimize if there's a value, |
4795 |
|
# if we don't have any child or if we |
4796 |
|
# have more than one child |
4797 |
|
if ( self.value != 0 ) or ( not children ) or len( children ) > 1: |
4798 |
|
return self |
4799 |
|
|
4800 |
|
child = children[0] |
4801 |
|
|
4802 |
|
self.letter += child.letter |
4803 |
|
self.value = child.value |
4804 |
|
self.children = child.children |
4805 |
|
|
4806 |
|
return self |
4807 |
|
|
4808 |
|
def dump_debug( self, write, margin ): |
4809 |
|
# this is used during debugging |
4810 |
|
line = margin + "+-" |
4811 |
|
if len( self.letter ) == 0: |
4812 |
|
line += "<NOLETTER>" |
4813 |
|
else: |
4814 |
|
line += self.letter |
4815 |
|
|
4816 |
|
if self.value: |
4817 |
|
line += " => " + repr( self.value ) |
4818 |
|
|
4819 |
|
write( line + "\n" ) |
4820 |
|
|
4821 |
|
if self.children: |
4822 |
|
margin += "| " |
4823 |
|
for child in self.children.values(): |
4824 |
|
child.dump_debug( write, margin ) |
4825 |
|
|
4826 |
|
def locate( self, index ): |
4827 |
|
self.index = index |
4828 |
|
if len( self.letter ) > 0: |
4829 |
|
index += len( self.letter ) + 1 |
4830 |
|
else: |
4831 |
|
index += 2 |
4832 |
|
|
4833 |
|
if self.value != 0: |
4834 |
|
index += 2 |
4835 |
|
|
4836 |
|
children = self.children.values() |
4837 |
|
children.sort() |
4838 |
|
|
4839 |
|
index += 2 * len( children ) |
4840 |
|
for child in children: |
4841 |
|
index = child.locate( index ) |
4842 |
|
|
4843 |
|
return index |
4844 |
|
|
4845 |
|
def store( self, storage ): |
4846 |
|
# write the letters |
4847 |
|
l = len( self.letter ) |
4848 |
|
if l == 0: |
4849 |
|
storage += struct.pack( "B", 0 ) |
4850 |
|
else: |
4851 |
|
for n in range( l ): |
4852 |
|
val = ord( self.letter[n] ) |
4853 |
|
if n < l - 1: |
4854 |
|
val += 128 |
4855 |
|
storage += struct.pack( "B", val ) |
4856 |
|
|
4857 |
|
# write the count |
4858 |
|
children = self.children.values() |
4859 |
|
children.sort() |
4860 |
|
|
4861 |
|
count = len( children ) |
4862 |
|
|
4863 |
|
if self.value != 0: |
4864 |
|
storage += struct.pack( "!BH", count + 128, self.value ) |
4865 |
|
else: |
4866 |
|
storage += struct.pack( "B", count ) |
4867 |
|
|
4868 |
for line in lines: |
for child in children: |
4869 |
if line: |
storage += struct.pack( "!H", child.index ) |
|
fields = string.split( line, ';' ) |
|
|
# print fields[1] + ' - ' + fields[0] |
|
|
glyphs.append( fields[0] ) |
|
4870 |
|
|
4871 |
return glyphs |
for child in children: |
4872 |
|
storage = child.store( storage ) |
4873 |
|
|
4874 |
|
return storage |
4875 |
|
|
4876 |
|
|
4877 |
def adobe_glyph_values(): |
def adobe_glyph_values(): |
4894 |
|
|
4895 |
|
|
4896 |
def filter_glyph_names( alist, filter ): |
def filter_glyph_names( alist, filter ): |
4897 |
"""filter 'alist' by taking _out_ all glyph names that are in 'filter'""" |
"""filter `alist' by taking _out_ all glyph names that are in `filter'""" |
4898 |
|
|
4899 |
count = 0 |
count = 0 |
4900 |
extras = [] |
extras = [] |
4908 |
return extras |
return extras |
4909 |
|
|
4910 |
|
|
|
|
|
4911 |
def dump_encoding( file, encoding_name, encoding_list ): |
def dump_encoding( file, encoding_name, encoding_list ): |
4912 |
"""dumps a given encoding""" |
"""dump a given encoding""" |
4913 |
|
|
4914 |
write = file.write |
write = file.write |
4915 |
write( "/* the following are indices into the SID name table */\n" ) |
write( " /* the following are indices into the SID name table */\n" ) |
4916 |
write( "static const unsigned short " + encoding_name + "[" + \ |
write( " static const unsigned short " + encoding_name + |
4917 |
repr( len( encoding_list ) ) + "] =\n" ) |
"[" + repr( len( encoding_list ) ) + "] =\n" ) |
4918 |
write( "{\n" ) |
write( " {\n" ) |
4919 |
|
|
4920 |
line = " " |
line = " " |
4921 |
comma = "" |
comma = "" |
4922 |
col = 0 |
col = 0 |
4923 |
for value in encoding_list: |
for value in encoding_list: |
4924 |
line += comma |
line += comma |
4925 |
line += "%3d" % value |
line += "%3d" % value |
4926 |
comma = "," |
comma = "," |
4927 |
col += 1 |
col += 1 |
4928 |
if col == 16: |
if col == 16: |
4929 |
col = 0 |
col = 0 |
4930 |
comma = ",\n " |
comma = ",\n " |
4931 |
|
|
4932 |
write( line + "\n};\n\n" ) |
write( line + "\n };\n\n\n" ) |
4933 |
|
|
4934 |
|
|
4935 |
def dump_array( the_array, write, array_name ): |
def dump_array( the_array, write, array_name ): |
4936 |
"""dumps a given encoding""" |
"""dumps a given encoding""" |
4937 |
|
|
4938 |
write( "static const unsigned char " + array_name + "[" + \ |
write( " static const unsigned char " + array_name + |
4939 |
repr(len(the_array)) + "] =\n" ) |
"[" + repr( len( the_array ) ) + "] =\n" ) |
4940 |
write( "{\n" ) |
write( " {\n" ) |
4941 |
line = "" |
|
4942 |
comma = " " |
line = "" |
4943 |
|
comma = " " |
4944 |
col = 0 |
col = 0 |
4945 |
for value in the_array: |
|
4946 |
line += comma |
for value in the_array: |
4947 |
line += "%3d" % ord(value) |
line += comma |
4948 |
comma = "," |
line += "%3d" % ord( value ) |
4949 |
col += 1 |
comma = "," |
4950 |
if col == 16: |
col += 1 |
4951 |
col = 0 |
|
4952 |
comma = ",\n " |
if col == 16: |
4953 |
|
col = 0 |
4954 |
if len(line) > 1024: |
comma = ",\n " |
4955 |
write( line ) |
|
4956 |
line = "" |
if len( line ) > 1024: |
4957 |
|
write( line ) |
4958 |
write( line + "\n};\n\n" ) |
line = "" |
4959 |
|
|
4960 |
|
write( line + "\n };\n\n\n" ) |
4961 |
|
|
4962 |
|
|
4963 |
def main(): |
def main(): |
4964 |
"""main program body""" |
"""main program body""" |
4972 |
|
|
4973 |
count_sid = len( sid_standard_names ) |
count_sid = len( sid_standard_names ) |
4974 |
|
|
4975 |
# 'mac_extras' contains the list of glyph names in the Macintosh standard |
# `mac_extras' contains the list of glyph names in the Macintosh standard |
4976 |
# encoding which are not in the SID Standard Names. |
# encoding which are not in the SID Standard Names. |
4977 |
# |
# |
4978 |
mac_extras = filter_glyph_names( mac_standard_names, sid_standard_names ) |
mac_extras = filter_glyph_names( mac_standard_names, sid_standard_names ) |
4979 |
|
|
4980 |
# 'base_list' contains the names of our final glyph names table. |
# `base_list' contains the names of our final glyph names table. |
4981 |
# It consists of the 'mac_extras' glyph names, followed by the SID |
# It consists of the `mac_extras' glyph names, followed by the SID |
4982 |
# Standard names. |
# standard names. |
4983 |
# |
# |
4984 |
mac_extras_count = len( mac_extras ) |
mac_extras_count = len( mac_extras ) |
|
t1_bias = mac_extras_count |
|
4985 |
base_list = mac_extras + sid_standard_names |
base_list = mac_extras + sid_standard_names |
4986 |
|
|
4987 |
write( "/***************************************************************************/\n" ) |
write( "/***************************************************************************/\n" ) |
4988 |
write( "/* */\n" ) |
write( "/* */\n" ) |
4989 |
|
|
4990 |
write( "/* %-71s*/\n" % sys.argv[1] ) |
write( "/* %-71s*/\n" % os.path.basename( sys.argv[1] ) ) |
4991 |
|
|
4992 |
write( "/* */\n" ) |
write( "/* */\n" ) |
4993 |
write( "/* PostScript glyph names. */\n" ) |
write( "/* PostScript glyph names. */\n" ) |
5004 |
write( "/***************************************************************************/\n" ) |
write( "/***************************************************************************/\n" ) |
5005 |
write( "\n" ) |
write( "\n" ) |
5006 |
write( "\n" ) |
write( "\n" ) |
5007 |
write( " /* ALL of this file has been generated automatically -- do not edit! */\n" ) |
write( " /* This file has been generated automatically -- do not edit! */\n" ) |
5008 |
write( "\n" ) |
write( "\n" ) |
5009 |
write( "\n" ) |
write( "\n" ) |
5010 |
|
|
5011 |
# dump final glyph list (mac extras + sid standard names) |
# dump final glyph list (mac extras + sid standard names) |
5012 |
# |
# |
5013 |
st = StringTable(base_list) |
st = StringTable( base_list, "ft_standard_glyph_names" ) |
5014 |
|
|
5015 |
st.dump(file,"ft_standard_glyph_names") |
st.dump( file ) |
5016 |
st.dump_sublist(file,"ft_mac_names","FT_NUM_MAC_NAMES",mac_standard_names) |
st.dump_sublist( file, "ft_mac_names", |
5017 |
st.dump_sublist(file,"ft_sid_names","FT_NUM_SID_NAMES",sid_standard_names) |
"FT_NUM_MAC_NAMES", mac_standard_names ) |
5018 |
|
st.dump_sublist( file, "ft_sid_names", |
5019 |
|
"FT_NUM_SID_NAMES", sid_standard_names ) |
5020 |
|
|
5021 |
dump_encoding( file, "t1_standard_encoding", t1_standard_encoding ) |
dump_encoding( file, "t1_standard_encoding", t1_standard_encoding ) |
5022 |
dump_encoding( file, "t1_expert_encoding", t1_expert_encoding ) |
dump_encoding( file, "t1_expert_encoding", t1_expert_encoding ) |
5023 |
|
|
5024 |
# dump the AGL in its compressed form |
# dump the AGL in its compressed form |
5025 |
# |
# |
5026 |
agl_glyphs, agl_values = adobe_glyph_values() |
agl_glyphs, agl_values = adobe_glyph_values() |
5027 |
dict = StringNode( "", 0 ) |
dict = StringNode( "", 0 ) |
5028 |
for g in range(len(agl_glyphs)): |
|
5029 |
dict.add(agl_glyphs[g],eval("0x"+agl_values[g])) |
for g in range( len( agl_glyphs ) ): |
5030 |
|
dict.add( agl_glyphs[g], eval( "0x" + agl_values[g] ) ) |
5031 |
dict = dict.optimize() |
|
5032 |
dict_len = dict.locate(0) |
dict = dict.optimize() |
5033 |
dict_array = dict.store("") |
dict_len = dict.locate( 0 ) |
5034 |
|
dict_array = dict.store( "" ) |
5035 |
write( """ |
|
5036 |
/* this table is a compressed version of the Adobe Glyph List |
write( """\ |
5037 |
* which has been optimized for efficient searching. It has |
/* |
5038 |
* been generated by the 'glnames.py' python script located |
* This table is a compressed version of the Adobe Glyph List (AGL), |
5039 |
* in the 'src/tools' directory. |
* optimized for efficient searching. It has been generated by the |
5040 |
* |
* `glnames.py' python script located in the `src/tools' directory. |
5041 |
* the corresponding lookup function is defined just below |
* |
5042 |
* the table (several pages down this text :-) |
* The lookup function to get the Unicode value for a given string |
5043 |
*/ |
* is defined below the table. |
5044 |
""" ) |
*/ |
5045 |
|
""" ) |
5046 |
dump_array(dict_array,write,"ft_adobe_glyph_list") |
|
5047 |
|
dump_array( dict_array, write, "ft_adobe_glyph_list" ) |
5048 |
# write the lookup routine now |
|
5049 |
# |
# write the lookup routine now |
5050 |
write( """ |
# |
5051 |
/* this is the wicked routine used to search our compressed |
write( """\ |
5052 |
* table efficiently |
/* |
5053 |
*/ |
* This function searches the compressed table efficiently. |
5054 |
static unsigned long |
*/ |
5055 |
ft_get_adobe_glyph_index( const char* name, |
static unsigned long |
5056 |
const char* limit ) |
ft_get_adobe_glyph_index( const char* name, |
5057 |
{ |
const char* limit ) |
5058 |
int c = 0; |
{ |
5059 |
int count, min, max; |
int c = 0; |
5060 |
const unsigned char* p = ft_adobe_glyph_list; |
int count, min, max; |
5061 |
|
const unsigned char* p = ft_adobe_glyph_list; |
5062 |
if ( name == 0 || name >= limit ) |
|
5063 |
goto NotFound; |
|
5064 |
|
if ( name == 0 || name >= limit ) |
5065 |
c = *name++; |
goto NotFound; |
5066 |
count = p[1]; |
|
5067 |
p += 2; |
c = *name++; |
5068 |
|
count = p[1]; |
5069 |
min = 0; |
p += 2; |
5070 |
max = count; |
|
5071 |
|
min = 0; |
5072 |
while ( min < max ) |
max = count; |
5073 |
{ |
|
5074 |
int mid = (min+max) >> 1; |
while ( min < max ) |
5075 |
const unsigned char* q = p + mid*2; |
{ |
5076 |
int c2; |
int mid = ( min + max ) >> 1; |
5077 |
|
const unsigned char* q = p + mid * 2; |
5078 |
q = ft_adobe_glyph_list + (((int)q[0] << 8) | q[1]); |
int c2; |
5079 |
|
|
5080 |
c2 = q[0] & 127; |
|
5081 |
if ( c2 == c ) |
q = ft_adobe_glyph_list + ( ( (int)q[0] << 8 ) | q[1] ); |
5082 |
{ |
|
5083 |
p = q; |
c2 = q[0] & 127; |
5084 |
goto Found; |
if ( c2 == c ) |
5085 |
} |
{ |
5086 |
if ( c2 < c ) |
p = q; |
5087 |
min = mid+1; |
goto Found; |
5088 |
else |
} |
5089 |
max = mid; |
if ( c2 < c ) |
5090 |
} |
min = mid + 1; |
5091 |
goto NotFound; |
else |
5092 |
|
max = mid; |
5093 |
Found: |
} |
5094 |
for (;;) |
goto NotFound; |
5095 |
{ |
|
5096 |
/* assert (*p & 127) == c */ |
Found: |
5097 |
|
for (;;) |
5098 |
if ( name >= limit ) |
{ |
5099 |
{ |
/* assert (*p & 127) == c */ |
5100 |
if ( (p[0] & 128) == 0 && |
|
5101 |
(p[1] & 128) != 0 ) |
if ( name >= limit ) |
5102 |
return (unsigned long)(((int)p[2] << 8) | p[3]); |
{ |
5103 |
|
if ( (p[0] & 128) == 0 && |
5104 |
goto NotFound; |
(p[1] & 128) != 0 ) |
5105 |
} |
return (unsigned long)( ( (int)p[2] << 8 ) | p[3] ); |
5106 |
c = *name++; |
|
5107 |
if ( p[0] & 128 ) |
goto NotFound; |
5108 |
{ |
} |
5109 |
p++; |
c = *name++; |
5110 |
if ( c != (p[0] & 127) ) |
if ( p[0] & 128 ) |
5111 |
goto NotFound; |
{ |
5112 |
|
p++; |
5113 |
continue; |
if ( c != (p[0] & 127) ) |
5114 |
} |
goto NotFound; |
5115 |
|
|
5116 |
p++; |
continue; |
5117 |
count = p[0] & 127; |
} |
5118 |
if ( p[0] & 128 ) |
|
5119 |
p += 2; |
p++; |
5120 |
|
count = p[0] & 127; |
5121 |
p++; |
if ( p[0] & 128 ) |
5122 |
|
p += 2; |
5123 |
for ( ; count > 0; count--, p += 2 ) |
|
5124 |
{ |
p++; |
5125 |
int offset = ((int)p[0] << 8) | p[1]; |
|
5126 |
const unsigned char* q = ft_adobe_glyph_list + offset; |
for ( ; count > 0; count--, p += 2 ) |
5127 |
|
{ |
5128 |
if ( c == (q[0] & 127) ) |
int offset = ( (int)p[0] << 8 ) | p[1]; |
5129 |
{ |
const unsigned char* q = ft_adobe_glyph_list + offset; |
5130 |
p = q; |
|
5131 |
goto NextIter; |
if ( c == ( q[0] & 127 ) ) |
5132 |
} |
{ |
5133 |
} |
p = q; |
5134 |
goto NotFound; |
goto NextIter; |
5135 |
|
} |
5136 |
NextIter: |
} |
5137 |
; |
goto NotFound; |
5138 |
} |
|
5139 |
|
NextIter: |
5140 |
NotFound: |
; |
5141 |
return 0; |
} |
5142 |
} |
|
5143 |
|
NotFound: |
5144 |
""" ) |
return 0; |
5145 |
|
} |
5146 |
if 0: # generate unit test, or don't |
|
5147 |
# |
""" ) |
5148 |
# now write the unit test to check that everything works OK |
|
5149 |
# |
if 0: # generate unit test, or don't |
5150 |
write( "#ifdef TEST\n\n" ) |
# |
5151 |
|
# now write the unit test to check that everything works OK |
5152 |
write( "static const char* const the_names[] = {\n" ) |
# |
5153 |
for name in agl_glyphs: |
write( "#ifdef TEST\n\n" ) |
5154 |
write( ' "'+name+'",\n' ) |
|
5155 |
write( " 0\n};\n" ) |
write( "static const char* const the_names[] = {\n" ) |
5156 |
|
for name in agl_glyphs: |
5157 |
write( "static const unsigned long the_values[] = {\n" ) |
write( ' "' + name + '",\n' ) |
5158 |
for val in agl_values: |
write( " 0\n};\n" ) |
5159 |
write( ' 0x'+val+',\n' ) |
|
5160 |
write( " 0\n};\n" ) |
write( "static const unsigned long the_values[] = {\n" ) |
5161 |
|
for val in agl_values: |
5162 |
write( """ |
write( ' 0x' + val + ',\n' ) |
5163 |
#include <stdlib.h> |
write( " 0\n};\n" ) |
5164 |
#include <stdio.h> |
|
5165 |
|
write( """ |
5166 |
int main( void ) |
#include <stdlib.h> |
5167 |
{ |
#include <stdio.h> |
5168 |
int result = 0; |
|
5169 |
const char* const* names = the_names; |
int |
5170 |
const unsigned long* values = the_values; |
main( void ) |
5171 |
|
{ |
5172 |
for ( ; *names; names++, values++ ) |
int result = 0; |
5173 |
{ |
const char* const* names = the_names; |
5174 |
const char* name = *names; |
const unsigned long* values = the_values; |
5175 |
unsigned long reference = *values; |
|
5176 |
unsigned long value; |
|
5177 |
|
for ( ; *names; names++, values++ ) |
5178 |
value = ft_get_adobe_glyph_index( name, name + strlen(name) ); |
{ |
5179 |
if ( value != reference ) |
const char* name = *names; |
5180 |
{ |
unsigned long reference = *values; |
5181 |
result = 1; |
unsigned long value; |
5182 |
fprintf( stderr, "name '%s' => %04x instead of %04x\\n", |
|
5183 |
name, value, reference ); |
|
5184 |
} |
value = ft_get_adobe_glyph_index( name, name + strlen( name ) ); |
5185 |
} |
if ( value != reference ) |
5186 |
|
{ |
5187 |
return result; |
result = 1; |
5188 |
} |
fprintf( stderr, "name '%s' => %04x instead of %04x\\n", |
5189 |
""" ) |
name, value, reference ); |
5190 |
write( "#endif /* TEST */\n" ) |
} |
5191 |
|
} |
5192 |
write("/* END */\n") |
|
5193 |
|
return result; |
5194 |
|
} |
5195 |
|
""" ) |
5196 |
|
|
5197 |
|
write( "#endif /* TEST */\n" ) |
5198 |
|
|
5199 |
|
write("\n/* END */\n") |
5200 |
|
|
5201 |
|
|
5202 |
# Now run the main routine |
# Now run the main routine |