READ_UINT16 (stream, table->EndSize);
READ_UINT16 (stream, table->DeltaFormat);
num = table->EndSize - table->StartSize + 1;
- OTF_MALLOC (table->DeltaValue, num, "");
+ if (num > 0 && table->DeltaFormat >= 1 && table->DeltaFormat <= 3)
+ {
+ OTF_MALLOC (table->DeltaValue, num, "");
- if (table->DeltaFormat == 1)
- for (i = 0; i < num; i++)
- {
- if ((i % 8) == 0)
- READ_UINT16 (stream, val);
- intval.int2 = (val >> (14 - (i % 8) * 2)) & 0x03;
- table->DeltaValue[i] = intval.int2;
- }
- else if (table->DeltaFormat == 2)
- for (i = 0; i < num; i++)
- {
- if ((i % 4) == 0)
- READ_UINT16 (stream, val);
- intval.int4 = (val >> (12 - (i % 4) * 4)) & 0x0F;
- table->DeltaValue[i] = intval.int4;
- }
- else if (table->DeltaFormat == 3)
- for (i = 0; i < num; i++)
- {
- if ((i % 2) == 0)
+ if (table->DeltaFormat == 1)
+ for (i = 0; i < num; i++)
{
- READ_UINT16 (stream, val);
- intval.int8 = val >> 8;
- table->DeltaValue[i] = intval.int8;
+ if ((i % 8) == 0)
+ READ_UINT16 (stream, val);
+ intval.int2 = (val >> (14 - (i % 8) * 2)) & 0x03;
+ table->DeltaValue[i] = intval.int2;
}
- else
+ else if (table->DeltaFormat == 2)
+ for (i = 0; i < num; i++)
{
- intval.int8 = val >> 8;
- table->DeltaValue[i] = intval.int8;
+ if ((i % 4) == 0)
+ READ_UINT16 (stream, val);
+ intval.int4 = (val >> (12 - (i % 4) * 4)) & 0x0F;
+ table->DeltaValue[i] = intval.int4;
}
- }
+ else /* (table->DeltaFormat == 3) */
+ for (i = 0; i < num; i++)
+ {
+ if ((i % 2) == 0)
+ {
+ READ_UINT16 (stream, val);
+ intval.int8 = val >> 8;
+ table->DeltaValue[i] = intval.int8;
+ }
+ else
+ {
+ intval.int8 = val >> 8;
+ table->DeltaValue[i] = intval.int8;
+ }
+ }
+ }
else
- OTF_ERROR (OTF_ERROR_TABLE, " (Invalid format)");
+ {
+ /* Invalid DeltaFormat but several fonts has such values (bug of
+ fontforge?). So accept it with NULL delta values. */
+ table->DeltaValue = NULL;
+ }
return 0;
}