Coverage Report

Created: 2026-07-04 07:11

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
232k
BuiltinFontWidths::BuiltinFontWidths(BuiltinFontWidth *widths, int sizeA) {
21
232k
  int i, h;
22
23
232k
  size = sizeA;
24
232k
  tab = (BuiltinFontWidth **)gmallocn(size, sizeof(BuiltinFontWidth *));
25
69.3M
  for (i = 0; i < size; ++i) {
26
69.1M
    tab[i] = NULL;
27
69.1M
  }
28
69.3M
  for (i = 0; i < sizeA; ++i) {
29
69.1M
    h = hash(widths[i].name);
30
69.1M
    widths[i].next = tab[h];
31
69.1M
    tab[h] = &widths[i];
32
69.1M
  }
33
232k
}
34
35
232k
BuiltinFontWidths::~BuiltinFontWidths() {
36
232k
  gfree(tab);
37
232k
}
38
39
3.98M
GBool BuiltinFontWidths::getWidth(const char *name, Gushort *width) {
40
3.98M
  int h;
41
3.98M
  BuiltinFontWidth *p;
42
43
3.98M
  h = hash(name);
44
5.73M
  for (p = tab[h]; p; p = p->next) {
45
5.67M
    if (!strcmp(p->name, name)) {
46
3.92M
      *width = p->width;
47
3.92M
      return gTrue;
48
3.92M
    }
49
5.67M
  }
50
57.8k
  *width = 0;
51
57.8k
  return gFalse;
52
3.98M
}
53
54
73.1M
int BuiltinFontWidths::hash(const char *name) {
55
73.1M
  const char *p;
56
73.1M
  unsigned int h;
57
58
73.1M
  h = 0;
59
539M
  for (p = name; *p; ++p) {
60
466M
    h = 17 * h + (int)(*p & 0xff);
61
466M
  }
62
73.1M
  return (int)(h % size);
63
73.1M
}