Back to index

tetex-bin  3.0
BuiltinFont.cc
Go to the documentation of this file.
00001 //========================================================================
00002 //
00003 // BuiltinFont.cc
00004 //
00005 // Copyright 2001-2003 Glyph & Cog, LLC
00006 //
00007 //========================================================================
00008 
00009 #include <aconf.h>
00010 
00011 #ifdef USE_GCC_PRAGMAS
00012 #pragma implementation
00013 #endif
00014 
00015 #include <stdlib.h>
00016 #include <string.h>
00017 #include "gmem.h"
00018 #include "FontEncodingTables.h"
00019 #include "BuiltinFont.h"
00020 
00021 //------------------------------------------------------------------------
00022 
00023 BuiltinFontWidths::BuiltinFontWidths(BuiltinFontWidth *widths, int sizeA) {
00024   int i, h;
00025 
00026   size = sizeA;
00027   tab = (BuiltinFontWidth **)gmalloc(size * sizeof(BuiltinFontWidth *));
00028   for (i = 0; i < size; ++i) {
00029     tab[i] = NULL;
00030   }
00031   for (i = 0; i < sizeA; ++i) {
00032     h = hash(widths[i].name);
00033     widths[i].next = tab[h];
00034     tab[h] = &widths[i];
00035   }
00036 }
00037 
00038 BuiltinFontWidths::~BuiltinFontWidths() {
00039   gfree(tab);
00040 }
00041 
00042 GBool BuiltinFontWidths::getWidth(char *name, Gushort *width) {
00043   int h;
00044   BuiltinFontWidth *p;
00045 
00046   h = hash(name);
00047   for (p = tab[h]; p; p = p->next) {
00048     if (!strcmp(p->name, name)) {
00049       *width = p->width;
00050       return gTrue;
00051     }
00052   }
00053   return gFalse;
00054 }
00055 
00056 int BuiltinFontWidths::hash(char *name) {
00057   char *p;
00058   unsigned int h;
00059 
00060   h = 0;
00061   for (p = name; *p; ++p) {
00062     h = 17 * h + (int)(*p & 0xff);
00063   }
00064   return (int)(h % size);
00065 }