Coverage Report

Created: 2026-09-01 07:01

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