1 //========================================================================
5 // Copyright 1999 Derek B. Noonburg
7 //========================================================================
10 #pragma implementation
18 #include "FontEncoding.h"
20 //------------------------------------------------------------------------
22 //------------------------------------------------------------------------
24 inline int FontEncoding::hash(char *name
) {
27 h
= (Guint
)name
[0] & 0xff;
29 h
= h
* 61 + ((Guint
)name
[1] & 0xff);
30 return (int)(h
% (Guint
)fontEncHashSize
);
33 FontEncoding::FontEncoding() {
36 encoding
= (char **)gmalloc(256 * sizeof(char *));
39 for (i
= 0; i
< 256; ++i
)
41 for (i
= 0; i
< fontEncHashSize
; ++i
)
45 FontEncoding::FontEncoding(char **encodingA
, int sizeA
) {
51 for (i
= 0; i
< fontEncHashSize
; ++i
)
53 for (i
= 0; i
< size
; ++i
) {
55 addChar1(i
, encoding
[i
]);
59 FontEncoding::FontEncoding(FontEncoding
*fontEnc
) {
62 encoding
= (char **)gmalloc(fontEnc
->size
* sizeof(char *));
65 for (i
= 0; i
< size
; ++i
) {
67 fontEnc
->encoding
[i
] ? copyString(fontEnc
->encoding
[i
]) : (char *)NULL
;
69 memcpy(hashTab
, fontEnc
->hashTab
, fontEncHashSize
* sizeof(short));
72 void FontEncoding::addChar(int code
, char *name
) {
75 // replace character associated with code
77 h
= hash(encoding
[code
]);
78 for (i
= 0; i
< fontEncHashSize
; ++i
) {
79 if (hashTab
[h
] == code
) {
83 if (++h
== fontEncHashSize
)
86 gfree(encoding
[code
]);
89 // associate name with code
90 encoding
[code
] = name
;
92 // insert name in hash table
96 void FontEncoding::addChar1(int code
, char *name
) {
99 // insert name in hash table
101 for (i
= 0; i
< fontEncHashSize
; ++i
) {
106 } else if (encoding
[code2
] && !strcmp(encoding
[code2
], name
)) {
107 // keep the highest code for each char -- this is needed because
108 // X won't display chars with codes < 32
109 //if (code > code2) removed by EL
113 if (++h
== fontEncHashSize
)
118 FontEncoding::~FontEncoding() {
122 for (i
= 0; i
< size
; ++i
) {
130 int FontEncoding::getCharCode(char *name
) {
134 for (i
= 0; i
< fontEncHashSize
; ++i
) {
137 (code
>= 0 && encoding
[code
] && !strcmp(encoding
[code
], name
)))
139 if (++h
>= fontEncHashSize
)