I would like to get rid of the "hardcoded" offset into the glyph name array and replace it with a macro ('GN_exclam', for example). Each font data file could then simply include a header that gets regenerated when- ever the glyphlist is changed -- eliminating the current requirement to regenerate all the font data.
Anyone see any problems with this? (There are currently 1258 built-in glyph names.)
Not really, but as an alternative solution you could has a structure instead of an array like:
typedef struct { GLYPHNAME A; GLYPHNAME AE; GLYPHNAME AEacute; GLYPHNAME AEsmall; /* ... */ } GLYPHNAMES;
Perhaps this is better since it doesn't use the preprocessor.
However I'm not sure if all C compilers supports 1258 structure members. Another possible problem is alignment on some platforms if you must be able for iterate over it and use it as and array. Of course you can simply have a seperate array of pointers like:
GLYPHNAMES glyphnames = { /* ... */ };
GLYPHNAME *pGlyphnames[] = { &glyphnames.A; &glyphnames.AE; &glyphnames.AEacute; &glyphnames.AEsmall; /* ... */ };
Patrik Stridvall wrote:
Not really, but as an alternative solution you could has a structure instead of an array like:
typedef struct { GLYPHNAME A; GLYPHNAME AE; GLYPHNAME AEacute; GLYPHNAME AEsmall; /* ... */ } GLYPHNAMES;
Perhaps this is better since it doesn't use the preprocessor.
I not thought of that -- neat idea. What is the downside of using the preprocessor, however?
However I'm not sure if all C compilers supports 1258 structure members. Another possible problem is alignment on some platforms if you must be able for iterate over it and use it as and array. Of course you can simply have a seperate array of pointers like:
I do need to iterate through it at one point. In fact I iterate through the array of names to create just such an array of pointers. The array may grow, however, so it has to be created dynamically. (I suppose I could start with a predefined array, copy it to the heap, and grow it there, but that seems inelegant and wasteful somehow.)
Thanks for your feedback!