J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 3 | * |
| 4 | * This code is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License version 2 only, as |
| 6 | * published by the Free Software Foundation. Sun designates this |
| 7 | * particular file as subject to the "Classpath" exception as provided |
| 8 | * by Sun in the LICENSE file that accompanied this code. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 | * version 2 for more details (a copy is included in the LICENSE file that |
| 14 | * accompanied this code). |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License version |
| 17 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | * |
| 20 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 21 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 22 | * have any questions. |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | /* |
| 27 | * |
| 28 | * (C) Copyright IBM Corp. 1998 - 2005 - All Rights Reserved |
| 29 | * |
| 30 | */ |
| 31 | |
| 32 | #include "LETypes.h" |
| 33 | #include "OpenTypeTables.h" |
| 34 | #include "DeviceTables.h" |
| 35 | #include "LESwaps.h" |
| 36 | |
| 37 | const le_uint16 DeviceTable::fieldMasks[] = {0x0003, 0x000F, 0x00FF}; |
| 38 | const le_uint16 DeviceTable::fieldSignBits[] = {0x0002, 0x0008, 0x0080}; |
| 39 | const le_uint16 DeviceTable::fieldBits[] = { 2, 4, 8}; |
| 40 | |
| 41 | le_int16 DeviceTable::getAdjustment(le_uint16 ppem) const |
| 42 | { |
| 43 | le_uint16 start = SWAPW(startSize); |
| 44 | le_uint16 format = SWAPW(deltaFormat) - 1; |
| 45 | le_int16 result = 0; |
| 46 | |
| 47 | if (ppem >= start && ppem <= SWAPW(endSize)) { |
| 48 | le_uint16 sizeIndex = ppem - start; |
| 49 | le_uint16 bits = fieldBits[format]; |
| 50 | le_uint16 count = 16 / bits; |
| 51 | le_uint16 word = SWAPW(deltaValues[sizeIndex / count]); |
| 52 | le_uint16 fieldIndex = sizeIndex % count; |
| 53 | le_uint16 shift = 16 - (bits * (fieldIndex + 1)); |
| 54 | le_uint16 field = (word >> shift) & fieldMasks[format]; |
| 55 | |
| 56 | result = field; |
| 57 | |
| 58 | if ((field & fieldSignBits[format]) != 0) { |
| 59 | result |= ~ fieldMasks[format]; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | return result; |
| 64 | } |