Coverage Report

Created: 2026-03-15 06:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/xpdf-4.06/xpdf/BuiltinFont.cc
Line
Count
Source
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
305k
BuiltinFontWidths::BuiltinFontWidths(BuiltinFontWidth *widths, int sizeA) {
21
305k
  int i, h;
22
23
305k
  size = sizeA;
24
305k
  tab = (BuiltinFontWidth **)gmallocn(size, sizeof(BuiltinFontWidth *));
25
91.3M
  for (i = 0; i < size; ++i) {
26
91.0M
    tab[i] = NULL;
27
91.0M
  }
28
91.3M
  for (i = 0; i < sizeA; ++i) {
29
91.0M
    h = hash(widths[i].name);
30
91.0M
    widths[i].next = tab[h];
31
91.0M
    tab[h] = &widths[i];
32
91.0M
  }
33
305k
}
34
35
305k
BuiltinFontWidths::~BuiltinFontWidths() {
36
305k
  gfree(tab);
37
305k
}
38
39
3.71M
GBool BuiltinFontWidths::getWidth(const char *name, Gushort *width) {
40
3.71M
  int h;
41
3.71M
  BuiltinFontWidth *p;
42
43
3.71M
  h = hash(name);
44
5.35M
  for (p = tab[h]; p; p = p->next) {
45
5.32M
    if (!strcmp(p->name, name)) {
46
3.68M
      *width = p->width;
47
3.68M
      return gTrue;
48
3.68M
    }
49
5.32M
  }
50
25.3k
  *width = 0;
51
25.3k
  return gFalse;
52
3.71M
}
53
54
94.7M
int BuiltinFontWidths::hash(const char *name) {
55
94.7M
  const char *p;
56
94.7M
  unsigned int h;
57
58
94.7M
  h = 0;
59
700M
  for (p = name; *p; ++p) {
60
605M
    h = 17 * h + (int)(*p & 0xff);
61
605M
  }
62
94.7M
  return (int)(h % size);
63
94.7M
}