Beispiel #1
0
/* Fill encodings */
long encodingFill(tcCtx g)
	{
	encodingCtx h = g->ctx.encoding;
	int i;
	Offset offset;

	offset = 0;
	for (i = 0; i < h->encodings.cnt; i++)
		{
		int j;
		Encoding *encoding = &h->encodings.array[i];
		long size0;
		long size1;

		/* Count ranges */
		encoding->nRanges = 1;
		for (j = 1; j < encoding->nCodes; j++)
			if (encoding->code[j - 1] + 1 != encoding->code[j])
				encoding->nRanges++;

		/* Save format and offset */
		size0 = FORMAT0_SIZE(encoding->nCodes);
		size1 = FORMAT1_SIZE(encoding->nRanges);
		encoding->format = size0 > size1;
		encoding->offset = offset;
		offset += (size0 > size1)? size1: size0;
		if (encoding->nSups > 0)
			{
			encoding->format |= 0x80;
			offset += SUPPLEMENTAL_SIZE(encoding->nSups);
			}
		}
	return offset;
	}
/* Fill encodings and return total size of all encodings. */
long cfwEncodingFill(cfwCtx g) {
    encodingCtx h = g->ctx.encoding;
    int i;
    Offset offset;

    offset = 0;
    for (i = 0; i < h->encodings.cnt; i++) {
        int j;
        Encoding *encoding = &h->encodings.array[i];
        long size0;
        long size1;

        /* Count ranges */
        encoding->nRanges = 1;
        for (j = 1; j < encoding->codes.cnt; j++) {
            if (encoding->codes.array[j - 1] + 1 != encoding->codes.array[j]) {
                encoding->nRanges++;
            }
        }

        encoding->offset = offset;

        /* Save format and offset */
        size0 = FORMAT0_SIZE(encoding->codes.cnt);
        size1 = FORMAT1_SIZE(encoding->nRanges);
        if (size0 < size1) {
            /* Select format 0 */
            offset += size0;
            encoding->format = 0;
        } else {
            /* Select format 1 */
            offset += size1;
            encoding->format = 1;
        }
        if (encoding->supcodes.cnt > 0) {
            encoding->format |= 0x80;
            offset += SUPPLEMENTAL_SIZE(encoding->supcodes.cnt);
        }
    }
    return offset;
}