Update contrib.
2 * @(#)KernTable.cpp 1.1 04/10/13
4 * (C) Copyright IBM Corp. 2004-2005 - All Rights Reserved
19 le_uint32 key; // sigh, MSVC compiler gags on union here
20 le_int16 value; // fword, kern value in funits
22 #define KERN_PAIRINFO_SIZE 6
26 le_uint16 searchRange;
27 le_uint16 entrySelector;
30 #define KERN_SUBTABLE_0_HEADER_SIZE 8
32 // Kern table version 0 only
33 struct SubtableHeader {
38 #define KERN_SUBTABLE_HEADER_SIZE 6
40 // Version 0 only, version 1 has different layout
41 struct KernTableHeader {
45 #define KERN_TABLE_HEADER_SIZE 4
47 #define COVERAGE_HORIZONTAL 0x1
48 #define COVERAGE_MINIMUM 0x2
49 #define COVERAGE_CROSS 0x4
50 #define COVERAGE_OVERRIDE 0x8
52 KernTable::KernTable(const LEFontInstance* font, const void* tableData)
53 : pairs(0), font(font)
55 const KernTableHeader* header = (const KernTableHeader*)tableData;
58 fprintf(stderr, "no kern data\n");
65 // dump first 32 bytes of header
66 for (int i = 0; i < 64; ++i) {
67 fprintf(stderr, "%0.2x ", ((const char*)tableData)[i]&0xff);
68 if (((i+1)&0xf) == 0) {
69 fprintf(stderr, "\n");
70 } else if (((i+1)&0x7) == 0) {
77 if (header->version == 0 && SWAPW(header->nTables) > 0) {
78 const SubtableHeader* subhead = (const SubtableHeader*)((char*)tableData + KERN_TABLE_HEADER_SIZE);
79 if (subhead->version == 0) {
80 coverage = SWAPW(subhead->coverage);
81 if (coverage & COVERAGE_HORIZONTAL) { // only handle horizontal kerning
82 const Subtable_0* table = (const Subtable_0*)((char*)subhead + KERN_SUBTABLE_HEADER_SIZE);
83 nPairs = SWAPW(table->nPairs);
84 searchRange = SWAPW(table->searchRange);
85 entrySelector = SWAPW(table->entrySelector);
86 rangeShift = SWAPW(table->rangeShift);
87 pairs = (const PairInfo*)((char*)table + KERN_SUBTABLE_0_HEADER_SIZE);
90 fprintf(stderr, "coverage: %0.4x nPairs: %d pairs 0x%x\n", coverage, nPairs, pairs);
91 fprintf(stderr, " searchRange: %d entrySelector: %d rangeShift: %d\n", searchRange, entrySelector, rangeShift);
95 // dump part of the pair list
97 for (int i = 256; --i >= 0;) {
98 LEGlyphID id = font->mapCharToGlyph(i);
104 const PairInfo* p = pairs;
105 for (i = 0; i < nPairs; ++i, p = (const PairInfo*)((char*)p+KERN_PAIRINFO_SIZE)) {
106 le_uint32 k = SWAPL(p->key);
107 le_uint16 left = (k >> 16) & 0xffff;
108 le_uint16 right = k & 0xffff;
109 if (left < 256 && right < 256) {
111 if (c > 0x20 && c < 0x7f) {
112 fprintf(stderr, "%c/", c & 0xff);
114 fprintf(stderr, "%0.2x/", c & 0xff);
117 if (c > 0x20 && c < 0x7f) {
118 fprintf(stderr, "%c ", c & 0xff);
120 fprintf(stderr, "%0.2x ", c & 0xff);
134 * Process the glyph positions. The positions array has two floats for each
135 * glyph, plus a trailing pair to mark the end of the last glyph.
137 //void KernTable::process(const LEGlyphID glyphs[], float* positions, le_int32 glyphCount)
138 void KernTable::process(LEGlyphStorage& storage)
141 LEErrorCode success = LE_NO_ERROR;
143 le_uint32 key = storage[0]; // no need to mask off high bits
145 for (int i = 1, e = storage.getGlyphCount(); i < e; ++i) {
146 key = key << 16 | (storage[i] & 0xffff);
148 // argh, to do a binary search, we need to have the pair list in sorted order
149 // but it is not in sorted order on win32 platforms because of the endianness difference
150 // so either I have to swap the element each time I examine it, or I have to swap
151 // all the elements ahead of time and store them in the font
153 const PairInfo* p = pairs;
154 const PairInfo* tp = (const PairInfo*)((char*)p + rangeShift);
155 if (key > SWAPL(tp->key)) {
160 fprintf(stderr, "binary search for %0.8x\n", key);
164 le_uint32 probe = searchRange;
165 while (probe > KERN_PAIRINFO_SIZE) {
167 tp = (const PairInfo*)((char*)p + probe);
168 le_uint32 tkey = SWAPL(tp->key);
170 fprintf(stdout, " %.3d (%0.8x)\n", ((char*)tp - (char*)pairs)/KERN_PAIRINFO_SIZE, tkey);
175 le_int16 value = SWAPW(tp->value);
177 fprintf(stdout, "binary found kerning pair %x:%x at %d, value: 0x%x (%g)\n",
178 storage[i-1], storage[i], i, value & 0xffff, font->xUnitsToPoints(value));
181 adjust += font->xUnitsToPoints(value);
188 storage.adjustPosition(i, adjust, 0, success);
190 storage.adjustPosition(storage.getGlyphCount(), adjust, 0, success);