Add fc-glyphname to compute hash tables for Adobe glyph name to UCS4
conversion functions
This commit is contained in:
parent
11fec41c0e
commit
721d496d78
|
@ -0,0 +1,42 @@
|
|||
#
|
||||
# $Id $
|
||||
#
|
||||
# Copyright © 2003 Keith Packard
|
||||
#
|
||||
# Permission to use, copy, modify, distribute, and sell this software and its
|
||||
# documentation for any purpose is hereby granted without fee, provided that
|
||||
# the above copyright notice appear in all copies and that both that
|
||||
# copyright notice and this permission notice appear in supporting
|
||||
# documentation, and that the name of Keith Packard not be used in
|
||||
# advertising or publicity pertaining to distribution of the software without
|
||||
# specific, written prior permission. Keith Packard makes no
|
||||
# representations about the suitability of this software for any purpose. It
|
||||
# is provided "as is" without express or implied warranty.
|
||||
#
|
||||
# KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
# EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
||||
# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
# PERFORMANCE OF THIS SOFTWARE.
|
||||
#
|
||||
|
||||
INCLUDES=-I../src $(FREETYPE_CFLAGS)
|
||||
|
||||
TMPL=fcglyphname.tmpl.h
|
||||
TARG=fcglyphname.h
|
||||
|
||||
noinst_PROGRAMS=fc-glyphname
|
||||
|
||||
noinst_HEADERS=$(TARG)
|
||||
|
||||
noinst_MANS=fc-glyphname.man
|
||||
|
||||
GLYPHNAME=zapfdingbats.txt
|
||||
|
||||
EXTRA_DIST=$(TMPL) $(GLYPHNAME)
|
||||
|
||||
$(TARG): $(TMPL) fc-glyphname $(GLYPHNAME)
|
||||
rm -f $(TARG)
|
||||
./fc-glyphname $(GLYPHNAME) < $(TMPL) > $(TARG)
|
|
@ -0,0 +1,287 @@
|
|||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright © 2003 Keith Packard
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and its
|
||||
* documentation for any purpose is hereby granted without fee, provided that
|
||||
* the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
||||
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "fcint.h"
|
||||
|
||||
static FcGlyphName *
|
||||
FcAllocGlyphName (FcChar32 ucs, FcChar8 *name)
|
||||
{
|
||||
FcGlyphName *gn;
|
||||
|
||||
gn = malloc (sizeof (FcGlyphName) + strlen ((char *) name));
|
||||
if (!gn)
|
||||
return 0;
|
||||
gn->ucs = ucs;
|
||||
strcpy ((char *) gn->name, (char *) name);
|
||||
return gn;
|
||||
}
|
||||
|
||||
static void
|
||||
fatal (char *file, int lineno, char *msg)
|
||||
{
|
||||
fprintf (stderr, "%s:%d: %s\n", file, lineno, msg);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
#define MAX_GLYPHFILE 256
|
||||
#define MAX_GLYPHNAME 10240
|
||||
#define MAX_NAMELEN 1024
|
||||
|
||||
FcGlyphName *raw[MAX_GLYPHNAME];
|
||||
int nraw;
|
||||
int max_name_len;
|
||||
FcGlyphName *name_to_ucs[MAX_GLYPHNAME*2];
|
||||
FcGlyphName *ucs_to_name[MAX_GLYPHNAME*2];
|
||||
int hash, rehash;
|
||||
|
||||
int
|
||||
rawindex (FcGlyphName *gn)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nraw; i++)
|
||||
if (raw[i] == gn)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
scan (FILE *f, char *filename)
|
||||
{
|
||||
char buf[MAX_NAMELEN];
|
||||
char name[MAX_NAMELEN];
|
||||
unsigned long ucs;
|
||||
FcGlyphName *gn;
|
||||
int lineno = 0;
|
||||
int len;
|
||||
|
||||
while (fgets (buf, sizeof (buf), f))
|
||||
{
|
||||
lineno++;
|
||||
if (sscanf (buf, "%[^;];%lx\n", name, &ucs) != 2)
|
||||
continue;
|
||||
gn = FcAllocGlyphName ((FcChar32) ucs, (FcChar8 *) name);
|
||||
if (!gn)
|
||||
fatal (filename, lineno, "out of memory");
|
||||
len = strlen ((FcChar8 *) name);
|
||||
if (len > max_name_len)
|
||||
max_name_len = len;
|
||||
raw[nraw++] = gn;
|
||||
}
|
||||
}
|
||||
|
||||
static int compare_string (const void *a, const void *b)
|
||||
{
|
||||
const char *const *as = a, *const *bs = b;
|
||||
return strcmp (*as, *bs);
|
||||
}
|
||||
|
||||
static int compare_glyphname (const void *a, const void *b)
|
||||
{
|
||||
const FcGlyphName *const *ag = a, *const *bg = b;
|
||||
|
||||
return strcmp ((char *) (*ag)->name, (char *) (*bg)->name);
|
||||
}
|
||||
|
||||
static int
|
||||
isqrt (int a)
|
||||
{
|
||||
int l, h, m;
|
||||
|
||||
l = 2;
|
||||
h = a/2;
|
||||
while ((h-l) > 1)
|
||||
{
|
||||
m = (h+l) >> 1;
|
||||
if (m * m < a)
|
||||
l = m;
|
||||
else
|
||||
h = m;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
int
|
||||
isprime (int i)
|
||||
{
|
||||
int l, t;
|
||||
|
||||
if (i < 2)
|
||||
return FcFalse;
|
||||
if ((i & 1) == 0)
|
||||
{
|
||||
if (i == 2)
|
||||
return FcTrue;
|
||||
return FcFalse;
|
||||
}
|
||||
l = isqrt (i) + 1;
|
||||
for (t = 3; t <= l; t += 2)
|
||||
if (i % t == 0)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find a prime pair that leaves at least 25% of the hash table empty
|
||||
*/
|
||||
|
||||
void
|
||||
find_hash (void)
|
||||
{
|
||||
int h;
|
||||
|
||||
h = nraw + nraw / 4;
|
||||
if ((h & 1) == 0)
|
||||
h++;
|
||||
while (!isprime(h-2) || !isprime(h))
|
||||
h += 2;
|
||||
hash = h;
|
||||
rehash = h-2;
|
||||
}
|
||||
|
||||
FcChar32
|
||||
FcHashGlyphName (const FcChar8 *name)
|
||||
{
|
||||
FcChar32 h = 0;
|
||||
FcChar8 c;
|
||||
|
||||
while ((c = *name++))
|
||||
{
|
||||
h = ((h << 1) | (h >> 31)) ^ c;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
void
|
||||
insert (FcGlyphName *gn, FcGlyphName **table, FcChar32 h)
|
||||
{
|
||||
int i, r = 0;
|
||||
|
||||
i = (int) (h % hash);
|
||||
while (table[i])
|
||||
{
|
||||
if (!r) r = (int) (h % rehash);
|
||||
i += r;
|
||||
if (i >= hash)
|
||||
i -= hash;
|
||||
}
|
||||
table[i] = gn;
|
||||
}
|
||||
|
||||
void
|
||||
dump (FcGlyphName **table, char *name)
|
||||
{
|
||||
int i;
|
||||
|
||||
printf ("static FcGlyphName *%s[%d] = {\n", name, hash);
|
||||
|
||||
for (i = 0; i < hash; i++)
|
||||
if (table[i])
|
||||
printf ("(FcGlyphName *) &glyph%d,\n", rawindex(table[i]));
|
||||
else
|
||||
printf ("0,\n");
|
||||
|
||||
printf ("};\n");
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
char *files[MAX_GLYPHFILE];
|
||||
char line[1024];
|
||||
FILE *f;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (*++argv)
|
||||
{
|
||||
if (i == MAX_GLYPHFILE)
|
||||
fatal (*argv, 0, "Too many glyphname files");
|
||||
files[i++] = *argv;
|
||||
}
|
||||
files[i] = 0;
|
||||
qsort (files, i, sizeof (char *), compare_string);
|
||||
for (i = 0; files[i]; i++)
|
||||
{
|
||||
f = fopen (files[i], "r");
|
||||
if (!f)
|
||||
fatal (files[i], 0, strerror (errno));
|
||||
scan (f, files[i]);
|
||||
fclose (f);
|
||||
}
|
||||
qsort (raw, nraw, sizeof (FcGlyphName *), compare_glyphname);
|
||||
|
||||
find_hash ();
|
||||
|
||||
for (i = 0; i < nraw; i++)
|
||||
{
|
||||
insert (raw[i], name_to_ucs, FcHashGlyphName (raw[i]->name));
|
||||
insert (raw[i], ucs_to_name, raw[i]->ucs);
|
||||
}
|
||||
|
||||
/*
|
||||
* Scan the input until the marker is found
|
||||
*/
|
||||
|
||||
while (fgets (line, sizeof (line), stdin))
|
||||
{
|
||||
if (!strncmp (line, "@@@", 3))
|
||||
break;
|
||||
fputs (line, stdout);
|
||||
}
|
||||
|
||||
printf ("/* %d glyphnames in %d entries, %d%% occupancy */\n\n",
|
||||
nraw, hash, nraw * 100 / hash);
|
||||
|
||||
printf ("#define FC_GLYPHNAME_HASH %u\n", hash);
|
||||
printf ("#define FC_GLYPHNAME_REHASH %u\n", rehash);
|
||||
printf ("#define FC_GLYPHNAME_MAXLEN %d\n\n", max_name_len);
|
||||
|
||||
/*
|
||||
* Dump out entries
|
||||
*/
|
||||
|
||||
for (i = 0; i < nraw; i++)
|
||||
printf ("static struct { FcChar32 ucs; FcChar8 name[%d]; }"
|
||||
" glyph%d = { 0x%lx, \"%s\" };\n",
|
||||
strlen (raw[i]->name) + 1,
|
||||
i, (unsigned long) raw[i]->ucs, raw[i]->name);
|
||||
|
||||
/*
|
||||
* Dump out name_to_ucs table
|
||||
*/
|
||||
|
||||
dump (name_to_ucs, "name_to_ucs");
|
||||
|
||||
/*
|
||||
* Dump out ucs_to_name table
|
||||
*/
|
||||
dump (ucs_to_name, "ucs_to_name");
|
||||
|
||||
while (fgets (line, sizeof (line), stdin))
|
||||
fputs (line, stdout);
|
||||
|
||||
fflush (stdout);
|
||||
exit (ferror (stdout));
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright © 2003 Keith Packard
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and its
|
||||
* documentation for any purpose is hereby granted without fee, provided that
|
||||
* the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of Keith Packard not be used in
|
||||
* advertising or publicity pertaining to distribution of the software without
|
||||
* specific, written prior permission. Keith Packard makes no
|
||||
* representations about the suitability of this software for any purpose. It
|
||||
* is provided "as is" without express or implied warranty.
|
||||
*
|
||||
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
||||
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
@@@
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,212 @@
|
|||
# Name: ITC Zapf Dingbats Glyph List
|
||||
# Table version: 2.0
|
||||
# Date: September 20, 2002
|
||||
#
|
||||
# See http://partners.adobe.com/asn/developer/typeforum/unicodegn.html
|
||||
#
|
||||
# Format: Semicolon-delimited fields:
|
||||
# (1) glyph name
|
||||
# (2) Unicode scalar value
|
||||
#
|
||||
a100;275E
|
||||
a101;2761
|
||||
a102;2762
|
||||
a103;2763
|
||||
a104;2764
|
||||
a105;2710
|
||||
a106;2765
|
||||
a107;2766
|
||||
a108;2767
|
||||
a109;2660
|
||||
a10;2721
|
||||
a110;2665
|
||||
a111;2666
|
||||
a112;2663
|
||||
a117;2709
|
||||
a118;2708
|
||||
a119;2707
|
||||
a11;261B
|
||||
a120;2460
|
||||
a121;2461
|
||||
a122;2462
|
||||
a123;2463
|
||||
a124;2464
|
||||
a125;2465
|
||||
a126;2466
|
||||
a127;2467
|
||||
a128;2468
|
||||
a129;2469
|
||||
a12;261E
|
||||
a130;2776
|
||||
a131;2777
|
||||
a132;2778
|
||||
a133;2779
|
||||
a134;277A
|
||||
a135;277B
|
||||
a136;277C
|
||||
a137;277D
|
||||
a138;277E
|
||||
a139;277F
|
||||
a13;270C
|
||||
a140;2780
|
||||
a141;2781
|
||||
a142;2782
|
||||
a143;2783
|
||||
a144;2784
|
||||
a145;2785
|
||||
a146;2786
|
||||
a147;2787
|
||||
a148;2788
|
||||
a149;2789
|
||||
a14;270D
|
||||
a150;278A
|
||||
a151;278B
|
||||
a152;278C
|
||||
a153;278D
|
||||
a154;278E
|
||||
a155;278F
|
||||
a156;2790
|
||||
a157;2791
|
||||
a158;2792
|
||||
a159;2793
|
||||
a15;270E
|
||||
a160;2794
|
||||
a161;2192
|
||||
a162;27A3
|
||||
a163;2194
|
||||
a164;2195
|
||||
a165;2799
|
||||
a166;279B
|
||||
a167;279C
|
||||
a168;279D
|
||||
a169;279E
|
||||
a16;270F
|
||||
a170;279F
|
||||
a171;27A0
|
||||
a172;27A1
|
||||
a173;27A2
|
||||
a174;27A4
|
||||
a175;27A5
|
||||
a176;27A6
|
||||
a177;27A7
|
||||
a178;27A8
|
||||
a179;27A9
|
||||
a17;2711
|
||||
a180;27AB
|
||||
a181;27AD
|
||||
a182;27AF
|
||||
a183;27B2
|
||||
a184;27B3
|
||||
a185;27B5
|
||||
a186;27B8
|
||||
a187;27BA
|
||||
a188;27BB
|
||||
a189;27BC
|
||||
a18;2712
|
||||
a190;27BD
|
||||
a191;27BE
|
||||
a192;279A
|
||||
a193;27AA
|
||||
a194;27B6
|
||||
a195;27B9
|
||||
a196;2798
|
||||
a197;27B4
|
||||
a198;27B7
|
||||
a199;27AC
|
||||
a19;2713
|
||||
a1;2701
|
||||
a200;27AE
|
||||
a201;27B1
|
||||
a202;2703
|
||||
a203;2750
|
||||
a204;2752
|
||||
a205;276E
|
||||
a206;2770
|
||||
a20;2714
|
||||
a21;2715
|
||||
a22;2716
|
||||
a23;2717
|
||||
a24;2718
|
||||
a25;2719
|
||||
a26;271A
|
||||
a27;271B
|
||||
a28;271C
|
||||
a29;2722
|
||||
a2;2702
|
||||
a30;2723
|
||||
a31;2724
|
||||
a32;2725
|
||||
a33;2726
|
||||
a34;2727
|
||||
a35;2605
|
||||
a36;2729
|
||||
a37;272A
|
||||
a38;272B
|
||||
a39;272C
|
||||
a3;2704
|
||||
a40;272D
|
||||
a41;272E
|
||||
a42;272F
|
||||
a43;2730
|
||||
a44;2731
|
||||
a45;2732
|
||||
a46;2733
|
||||
a47;2734
|
||||
a48;2735
|
||||
a49;2736
|
||||
a4;260E
|
||||
a50;2737
|
||||
a51;2738
|
||||
a52;2739
|
||||
a53;273A
|
||||
a54;273B
|
||||
a55;273C
|
||||
a56;273D
|
||||
a57;273E
|
||||
a58;273F
|
||||
a59;2740
|
||||
a5;2706
|
||||
a60;2741
|
||||
a61;2742
|
||||
a62;2743
|
||||
a63;2744
|
||||
a64;2745
|
||||
a65;2746
|
||||
a66;2747
|
||||
a67;2748
|
||||
a68;2749
|
||||
a69;274A
|
||||
a6;271D
|
||||
a70;274B
|
||||
a71;25CF
|
||||
a72;274D
|
||||
a73;25A0
|
||||
a74;274F
|
||||
a75;2751
|
||||
a76;25B2
|
||||
a77;25BC
|
||||
a78;25C6
|
||||
a79;2756
|
||||
a7;271E
|
||||
a81;25D7
|
||||
a82;2758
|
||||
a83;2759
|
||||
a84;275A
|
||||
a85;276F
|
||||
a86;2771
|
||||
a87;2772
|
||||
a88;2773
|
||||
a89;2768
|
||||
a8;271F
|
||||
a90;2769
|
||||
a91;276C
|
||||
a92;276D
|
||||
a93;276A
|
||||
a94;276B
|
||||
a95;2774
|
||||
a96;2775
|
||||
a97;275B
|
||||
a98;275C
|
||||
a99;275D
|
||||
a9;2720
|
||||
#-- end
|
Loading…
Reference in New Issue