G
grishin-mailing-lists
Hi there,
I've been writing a program that generates a subfont-file of a given
font and number of needed glyphs. User decides which glyphs to
preserve and which to remove. Though it's not really important.
What is important that I have to rebuild some font tables -> their
checksums will change.
When I start the project I was dealing with tables of plain
structures, like:
typedef struct
{
USHORT MajorVersion;
USHORT MinorVersion;
USHORT NumTables;
USHORT SearchRange;
USHORT EntrySelector;
USHORT RangeShift;
} ttFontHeader;
I used casting to char * and calculated all of the new checksums by
this routine:
ULONG CalcTableChecksum(ULONG *Table, ULONG Length)
{
ULONG Sum = 0L;
ULONG *EndPtr = Table+((Length+3) & ~3) / sizeof(ULONG);
while (Table < EndPtr)
{
Sum += swap32(*Table++);
}
return Sum;
}
It worked well.
I've ended up with rebuilding cmap format 4 table which has a
sophisticated structure. I had to use vectors:
typedef struct
{ /* ÐÏÐÙÔËÁ ÓÄÅÌÁÔØ ÏÂÝÅÅ ÈÒÁÎÉÌÉÝÅ ÄÌÑ ÞÁÓÔÏ ÉÓÐÏÌØÚÕÅÍÙÈ ÆÏÒÍÁÔÏ×
(0 É 4) */
USHORT Format;
USHORT Length;
USHORT Language;
unsigned SegCount;
signed SearchRange;
signed EntrySelector;
signed RangeShift;
std::vector<ttCmapSegment> Segments;
std::vector<USHORT> GlyphIDs;
} ttCmapSubtable;
typedef struct
{
USHORT Version;
USHORT NumTables;
std::vector<ttCmapEncodingRecord> EncRecords;
std::vector<ttCmapSubtable> Subtables;
} ttCmap;
and now I can't just cast this to char* but I still need to calculate
its' checksum somehow.
For now I've written a special routine that calculates checksum
specially for cmap table.
What if I have to rebuild other 31 table? I have to write 31 checksum
functions -- one for the table!
There should be more elegant solution.
Thank you.
I've been writing a program that generates a subfont-file of a given
font and number of needed glyphs. User decides which glyphs to
preserve and which to remove. Though it's not really important.
What is important that I have to rebuild some font tables -> their
checksums will change.
When I start the project I was dealing with tables of plain
structures, like:
typedef struct
{
USHORT MajorVersion;
USHORT MinorVersion;
USHORT NumTables;
USHORT SearchRange;
USHORT EntrySelector;
USHORT RangeShift;
} ttFontHeader;
I used casting to char * and calculated all of the new checksums by
this routine:
ULONG CalcTableChecksum(ULONG *Table, ULONG Length)
{
ULONG Sum = 0L;
ULONG *EndPtr = Table+((Length+3) & ~3) / sizeof(ULONG);
while (Table < EndPtr)
{
Sum += swap32(*Table++);
}
return Sum;
}
It worked well.
I've ended up with rebuilding cmap format 4 table which has a
sophisticated structure. I had to use vectors:
typedef struct
{ /* ÐÏÐÙÔËÁ ÓÄÅÌÁÔØ ÏÂÝÅÅ ÈÒÁÎÉÌÉÝÅ ÄÌÑ ÞÁÓÔÏ ÉÓÐÏÌØÚÕÅÍÙÈ ÆÏÒÍÁÔÏ×
(0 É 4) */
USHORT Format;
USHORT Length;
USHORT Language;
unsigned SegCount;
signed SearchRange;
signed EntrySelector;
signed RangeShift;
std::vector<ttCmapSegment> Segments;
std::vector<USHORT> GlyphIDs;
} ttCmapSubtable;
typedef struct
{
USHORT Version;
USHORT NumTables;
std::vector<ttCmapEncodingRecord> EncRecords;
std::vector<ttCmapSubtable> Subtables;
} ttCmap;
and now I can't just cast this to char* but I still need to calculate
its' checksum somehow.
For now I've written a special routine that calculates checksum
specially for cmap table.
What if I have to rebuild other 31 table? I have to write 31 checksum
functions -- one for the table!
There should be more elegant solution.
Thank you.