summaryrefslogtreecommitdiff
path: root/noncore/unsupported/qpdf/xpdf/BuiltinFont.cc
Unidiff
Diffstat (limited to 'noncore/unsupported/qpdf/xpdf/BuiltinFont.cc') (more/less context) (show whitespace changes)
-rw-r--r--noncore/unsupported/qpdf/xpdf/BuiltinFont.cc64
1 files changed, 64 insertions, 0 deletions
diff --git a/noncore/unsupported/qpdf/xpdf/BuiltinFont.cc b/noncore/unsupported/qpdf/xpdf/BuiltinFont.cc
new file mode 100644
index 0000000..a8cef7b
--- a/dev/null
+++ b/noncore/unsupported/qpdf/xpdf/BuiltinFont.cc
@@ -0,0 +1,64 @@
1//========================================================================
2//
3// BuiltinFont.cc
4//
5// Copyright 2001 Derek B. Noonburg
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
22BuiltinFontWidths::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
37BuiltinFontWidths::~BuiltinFontWidths() {
38 gfree(tab);
39}
40
41GBool 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
55int 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}