2000-11-28 20:56:52 +00:00
|
|
|
/*
|
2002-03-27 00:34:56 +00:00
|
|
|
* @(#)DeviceTables.cpp 1.5 00/03/15
|
2000-11-28 20:56:52 +00:00
|
|
|
*
|
2006-11-14 19:24:02 +00:00
|
|
|
* (C) Copyright IBM Corp. 1998 - 2006 - All Rights Reserved
|
2000-11-28 20:56:52 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "LETypes.h"
|
|
|
|
#include "OpenTypeTables.h"
|
|
|
|
#include "DeviceTables.h"
|
|
|
|
#include "LESwaps.h"
|
|
|
|
|
2001-10-16 00:39:01 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2002-03-27 00:34:56 +00:00
|
|
|
const le_uint16 DeviceTable::fieldMasks[] = {0x0003, 0x000F, 0x00FF};
|
|
|
|
const le_uint16 DeviceTable::fieldSignBits[] = {0x0002, 0x0008, 0x0080};
|
|
|
|
const le_uint16 DeviceTable::fieldBits[] = { 2, 4, 8};
|
2000-11-28 20:56:52 +00:00
|
|
|
|
2006-11-14 19:24:02 +00:00
|
|
|
#define FORMAT_COUNT LE_ARRAY_SIZE(fieldBits)
|
|
|
|
|
2001-01-19 00:30:17 +00:00
|
|
|
le_int16 DeviceTable::getAdjustment(le_uint16 ppem) const
|
2000-11-28 20:56:52 +00:00
|
|
|
{
|
|
|
|
le_uint16 start = SWAPW(startSize);
|
|
|
|
le_uint16 format = SWAPW(deltaFormat) - 1;
|
|
|
|
le_int16 result = 0;
|
|
|
|
|
2006-11-14 19:24:02 +00:00
|
|
|
if (ppem >= start && ppem <= SWAPW(endSize) && format < FORMAT_COUNT) {
|
2000-11-28 20:56:52 +00:00
|
|
|
le_uint16 sizeIndex = ppem - start;
|
|
|
|
le_uint16 bits = fieldBits[format];
|
|
|
|
le_uint16 count = 16 / bits;
|
|
|
|
le_uint16 word = SWAPW(deltaValues[sizeIndex / count]);
|
|
|
|
le_uint16 fieldIndex = sizeIndex % count;
|
|
|
|
le_uint16 shift = 16 - (bits * (fieldIndex + 1));
|
|
|
|
le_uint16 field = (word >> shift) & fieldMasks[format];
|
|
|
|
|
|
|
|
result = field;
|
|
|
|
|
|
|
|
if ((field & fieldSignBits[format]) != 0) {
|
2004-10-29 19:24:42 +00:00
|
|
|
result |= ~ fieldMasks[format];
|
2000-11-28 20:56:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2001-10-16 00:39:01 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_END
|