]> git.ipfire.org Git - thirdparty/cups.git/blob - pdftops/BuiltinFont.cxx
Merge changes from CUPS 1.4svn-r7199.
[thirdparty/cups.git] / pdftops / BuiltinFont.cxx
1 //========================================================================
2 //
3 // BuiltinFont.cc
4 //
5 // Copyright 2001-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #include <config.h>
10
11 #ifdef USE_GCC_PRAGMAS
12 #pragma implementation
13 #endif
14
15 #include <stdlib.h>
16 #include <string.h>
17 #include "gmem.h"
18 #include "FontEncodingTables.h"
19 #include "BuiltinFont.h"
20
21 //------------------------------------------------------------------------
22
23 BuiltinFontWidths::BuiltinFontWidths(BuiltinFontWidth *widths, int sizeA) {
24 int i, h;
25
26 size = sizeA;
27 tab = (BuiltinFontWidth **)gmallocn(size, sizeof(BuiltinFontWidth *));
28 for (i = 0; i < size; ++i) {
29 tab[i] = NULL;
30 }
31 for (i = 0; i < sizeA; ++i) {
32 h = hash(widths[i].name);
33 widths[i].next = tab[h];
34 tab[h] = &widths[i];
35 }
36 }
37
38 BuiltinFontWidths::~BuiltinFontWidths() {
39 gfree(tab);
40 }
41
42 GBool BuiltinFontWidths::getWidth(char *name, Gushort *width) {
43 int h;
44 BuiltinFontWidth *p;
45
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;
51 }
52 }
53 return gFalse;
54 }
55
56 int BuiltinFontWidths::hash(char *name) {
57 char *p;
58 unsigned int h;
59
60 h = 0;
61 for (p = name; *p; ++p) {
62 h = 17 * h + (int)(*p & 0xff);
63 }
64 return (int)(h % size);
65 }