/src/xpdf-4.05/xpdf/BuiltinFont.cc
Line | Count | Source (jump to first uncovered line) |
1 | | //======================================================================== |
2 | | // |
3 | | // BuiltinFont.cc |
4 | | // |
5 | | // Copyright 2001-2003 Glyph & Cog, LLC |
6 | | // |
7 | | //======================================================================== |
8 | | |
9 | | #include <aconf.h> |
10 | | |
11 | | #include <stdlib.h> |
12 | | #include <string.h> |
13 | | #include "gmem.h" |
14 | | #include "gmempp.h" |
15 | | #include "FontEncodingTables.h" |
16 | | #include "BuiltinFont.h" |
17 | | |
18 | | //------------------------------------------------------------------------ |
19 | | |
20 | 45.2k | BuiltinFontWidths::BuiltinFontWidths(BuiltinFontWidth *widths, int sizeA) { |
21 | 45.2k | int i, h; |
22 | | |
23 | 45.2k | size = sizeA; |
24 | 45.2k | tab = (BuiltinFontWidth **)gmallocn(size, sizeof(BuiltinFontWidth *)); |
25 | 13.5M | for (i = 0; i < size; ++i) { |
26 | 13.4M | tab[i] = NULL; |
27 | 13.4M | } |
28 | 13.5M | for (i = 0; i < sizeA; ++i) { |
29 | 13.4M | h = hash(widths[i].name); |
30 | 13.4M | widths[i].next = tab[h]; |
31 | 13.4M | tab[h] = &widths[i]; |
32 | 13.4M | } |
33 | 45.2k | } |
34 | | |
35 | 45.2k | BuiltinFontWidths::~BuiltinFontWidths() { |
36 | 45.2k | gfree(tab); |
37 | 45.2k | } |
38 | | |
39 | 0 | GBool BuiltinFontWidths::getWidth(const char *name, Gushort *width) { |
40 | 0 | int h; |
41 | 0 | BuiltinFontWidth *p; |
42 | |
|
43 | 0 | h = hash(name); |
44 | 0 | for (p = tab[h]; p; p = p->next) { |
45 | 0 | if (!strcmp(p->name, name)) { |
46 | 0 | *width = p->width; |
47 | 0 | return gTrue; |
48 | 0 | } |
49 | 0 | } |
50 | 0 | *width = 0; |
51 | 0 | return gFalse; |
52 | 0 | } |
53 | | |
54 | 13.4M | int BuiltinFontWidths::hash(const char *name) { |
55 | 13.4M | const char *p; |
56 | 13.4M | unsigned int h; |
57 | | |
58 | 13.4M | h = 0; |
59 | 100M | for (p = name; *p; ++p) { |
60 | 86.7M | h = 17 * h + (int)(*p & 0xff); |
61 | 86.7M | } |
62 | 13.4M | return (int)(h % size); |
63 | 13.4M | } |