~ubuntu-branches/ubuntu/precise/ipe/precise

« back to all changes in this revision

Viewing changes to src/xpdflib/builtinfont.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2005-02-24 22:09:16 UTC
  • mfrom: (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050224220916-9vxiiqjz066r5489
Tags: 6.0pre23-2
debian/control: Ipe should depend on exact version of libipe.
Closes: #296771.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//========================================================================
2
 
//
3
 
// BuiltinFont.cc
4
 
//
5
 
// Copyright 2001-2002 Glyph & Cog, LLC
6
 
//
7
 
//========================================================================
8
 
 
9
 
#include "aconf.h"
10
 
 
11
 
#ifdef USE_GCC_PRAGMAS
12
 
#pragma implementation
13
 
#endif
14
 
 
15
 
#include <stdlib.h>
16
 
#include <string.h>
17
 
#include "gmem.h"
18
 
#include "fontencodingtables.h"
19
 
#include "builtinfont.h"
20
 
 
21
 
//------------------------------------------------------------------------
22
 
 
23
 
BuiltinFontWidths::BuiltinFontWidths(BuiltinFontWidth *widths, int sizeA) {
24
 
  int i, h;
25
 
 
26
 
  size = sizeA;
27
 
  tab = (BuiltinFontWidth **)gmalloc(size * sizeof(BuiltinFontWidth *));
28
 
  for (i = 0; i < size; ++i) {
29
 
    tab[i] = NULL;
30
 
  }
31
 
  for (i = 0; i < sizeA; ++i) {
32
 
    h = hash(widths[i].name);
33
 
    widths[i].next = tab[h];
34
 
    tab[h] = &widths[i];
35
 
  }
36
 
}
37
 
 
38
 
BuiltinFontWidths::~BuiltinFontWidths() {
39
 
  gfree(tab);
40
 
}
41
 
 
42
 
GBool BuiltinFontWidths::getWidth(char *name, Gushort *width) {
43
 
  int h;
44
 
  BuiltinFontWidth *p;
45
 
 
46
 
  h = hash(name);
47
 
  for (p = tab[h]; p; p = p->next) {
48
 
    if (!strcmp(p->name, name)) {
49
 
      *width = p->width;
50
 
      return gTrue;
51
 
    }
52
 
  }
53
 
  return gFalse;
54
 
}
55
 
 
56
 
int BuiltinFontWidths::hash(char *name) {
57
 
  char *p;
58
 
  unsigned int h;
59
 
 
60
 
  h = 0;
61
 
  for (p = name; *p; ++p) {
62
 
    h = 17 * h + (int)(*p & 0xff);
63
 
  }
64
 
  return (int)(h % size);
65
 
}