Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

BuiltinFont.cc

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

Generated on Sat Nov 5 16:18:12 2005 for OPIE by  doxygen 1.4.2