Coverage Report

Created: 2026-05-30 06:30

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