file(s) added by xpdf 1.01.
[swftools.git] / pdf2swf / xpdf / BuiltinFont.cc
1 //========================================================================
2 //
3 // BuiltinFont.cc
4 //
5 // Copyright 2001-2002 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #ifdef __GNUC__
10 #pragma implementation
11 #endif
12
13 #include <aconf.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include "gmem.h"
17 #include "FontEncodingTables.h"
18 #include "BuiltinFont.h"
19
20 //------------------------------------------------------------------------
21
22 BuiltinFontWidths::BuiltinFontWidths(BuiltinFontWidth *widths, int sizeA) {
23   int i, h;
24
25   size = sizeA;
26   tab = (BuiltinFontWidth **)gmalloc(size * sizeof(BuiltinFontWidth *));
27   for (i = 0; i < size; ++i) {
28     tab[i] = NULL;
29   }
30   for (i = 0; i < sizeA; ++i) {
31     h = hash(widths[i].name);
32     widths[i].next = tab[h];
33     tab[h] = &widths[i];
34   }
35 }
36
37 BuiltinFontWidths::~BuiltinFontWidths() {
38   gfree(tab);
39 }
40
41 GBool BuiltinFontWidths::getWidth(char *name, Gushort *width) {
42   int h;
43   BuiltinFontWidth *p;
44
45   h = hash(name);
46   for (p = tab[h]; p; p = p->next) {
47     if (!strcmp(p->name, name)) {
48       *width = p->width;
49       return gTrue;
50     }
51   }
52   return gFalse;
53 }
54
55 int BuiltinFontWidths::hash(char *name) {
56   char *p;
57   unsigned int h;
58
59   h = 0;
60   for (p = name; *p; ++p) {
61     h = 17 * h + (int)(*p & 0xff);
62   }
63   return (int)(h % size);
64 }