fixed windows access violation which occurs if one tries to retrieve
[swftools.git] / pdf2swf / xpdf / BuiltinFont.cc
blob1b070646fd8323e864a0e5bbd6af1395a5c835c6
1 //========================================================================
2 //
3 // BuiltinFont.cc
4 //
5 // Copyright 2001-2002 Glyph & Cog, LLC
6 //
7 //========================================================================
9 #ifdef __GNUC__
10 #pragma implementation
11 #endif
13 #include <aconf.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include "gmem.h"
17 #include "FontEncodingTables.h"
18 #include "BuiltinFont.h"
20 //------------------------------------------------------------------------
22 BuiltinFontWidths::BuiltinFontWidths(BuiltinFontWidth *widths, int sizeA) {
23 int i, h;
25 size = sizeA;
26 tab = (BuiltinFontWidth **)gmalloc(size * sizeof(BuiltinFontWidth *));
27 for (i = 0; i < size; ++i) {
28 tab[i] = NULL;
30 for (i = 0; i < sizeA; ++i) {
31 h = hash(widths[i].name);
32 widths[i].next = tab[h];
33 tab[h] = &widths[i];
37 BuiltinFontWidths::~BuiltinFontWidths() {
38 gfree(tab);
41 GBool BuiltinFontWidths::getWidth(char *name, Gushort *width) {
42 int h;
43 BuiltinFontWidth *p;
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;
52 return gFalse;
55 int BuiltinFontWidths::hash(char *name) {
56 char *p;
57 unsigned int h;
59 h = 0;
60 for (p = name; *p; ++p) {
61 h = 17 * h + (int)(*p & 0xff);
63 return (int)(h % size);