beta-0.89.2
[luatex.git] / source / libs / poppler / poppler-src / poppler / BuiltinFont.cc
blob20a297d6135a69dc2dc90415996d451a59d4cebe
1 //========================================================================
2 //
3 // BuiltinFont.cc
4 //
5 // Copyright 2001-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
9 #include <config.h>
11 #ifdef USE_GCC_PRAGMAS
12 #pragma implementation
13 #endif
15 #include <stdlib.h>
16 #include <string.h>
17 #include "goo/gmem.h"
18 #include "FontEncodingTables.h"
19 #include "BuiltinFont.h"
21 //------------------------------------------------------------------------
23 BuiltinFontWidths::BuiltinFontWidths(BuiltinFontWidth *widths, int sizeA) {
24 int i, h;
26 size = sizeA;
27 tab = (BuiltinFontWidth **)gmallocn(size, sizeof(BuiltinFontWidth *));
28 for (i = 0; i < size; ++i) {
29 tab[i] = NULL;
31 for (i = 0; i < sizeA; ++i) {
32 h = hash(widths[i].name);
33 widths[i].next = tab[h];
34 tab[h] = &widths[i];
38 BuiltinFontWidths::~BuiltinFontWidths() {
39 gfree(tab);
42 GBool BuiltinFontWidths::getWidth(const char *name, Gushort *width) {
43 int h;
44 BuiltinFontWidth *p;
46 h = hash(name);
47 for (p = tab[h]; p; p = p->next) {
48 if (!strcmp(p->name, name)) {
49 *width = p->width;
50 return gTrue;
53 return gFalse;
56 int BuiltinFontWidths::hash(const char *name) {
57 const char *p;
58 unsigned int h;
60 h = 0;
61 for (p = name; *p; ++p) {
62 h = 17 * h + (int)(*p & 0xff);
64 return (int)(h % size);