jdk/src/share/native/sun/font/layout/KernTable.cpp
author srl
Mon, 06 Dec 2010 16:10:01 -0800
changeset 7486 6a36b1ebc620
parent 5506 202f599c92aa
child 8742 849c6970689b
permissions -rw-r--r--
6886358: layout code update Reviewed-by: igor, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3935
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3935
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3935
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3935
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3935
diff changeset
    22
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    28
 *
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    29
 * (C) Copyright IBM Corp. 2004-2010 - All Rights Reserved
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "KernTable.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "LEFontInstance.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "LEGlyphStorage.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "LESwaps.h"
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    38
#include "OpenTypeUtilities.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#define DEBUG 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    44
U_NAMESPACE_BEGIN
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
    45
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
struct PairInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
  le_uint32 key;   // sigh, MSVC compiler gags on union here
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
  le_int16  value; // fword, kern value in funits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#define KERN_PAIRINFO_SIZE 6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
struct Subtable_0 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
  le_uint16 nPairs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
  le_uint16 searchRange;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
  le_uint16 entrySelector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
  le_uint16 rangeShift;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
#define KERN_SUBTABLE_0_HEADER_SIZE 8
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
// Kern table version 0 only
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
struct SubtableHeader {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
  le_uint16 version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
  le_uint16 length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
  le_uint16 coverage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
#define KERN_SUBTABLE_HEADER_SIZE 6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
// Version 0 only, version 1 has different layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
struct KernTableHeader {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
  le_uint16 version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
  le_uint16 nTables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
#define KERN_TABLE_HEADER_SIZE 4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
#define COVERAGE_HORIZONTAL 0x1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
#define COVERAGE_MINIMUM 0x2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
#define COVERAGE_CROSS 0x4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
#define COVERAGE_OVERRIDE 0x8
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * This implementation has support for only one subtable, so if the font has
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * multiple subtables, only the first will be used.  If this turns out to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * be a problem in practice we should add it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * This also supports only version 0 of the kern table header, only
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * Apple supports the latter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * This implementation isn't careful about the kern table flags, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * might invoke kerning when it is not supposed to.  That too I'm
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * leaving for a bug fix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * TODO: support multiple subtables
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * TODO: respect header flags
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 */
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    95
KernTable::KernTable(const LEFontInstance* font_, const void* tableData)
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
    96
  : pairs(0), font(font_)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
  const KernTableHeader* header = (const KernTableHeader*)tableData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
  if (header == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
#if DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    fprintf(stderr, "no kern data\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
#if DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
  // dump first 32 bytes of header
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
  for (int i = 0; i < 64; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    fprintf(stderr, "%0.2x ", ((const char*)tableData)[i]&0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    if (((i+1)&0xf) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
      fprintf(stderr, "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    } else if (((i+1)&0x7) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
      fprintf(stderr, "  ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
  if (header->version == 0 && SWAPW(header->nTables) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    const SubtableHeader* subhead = (const SubtableHeader*)((char*)tableData + KERN_TABLE_HEADER_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    if (subhead->version == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
      coverage = SWAPW(subhead->coverage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
      if (coverage & COVERAGE_HORIZONTAL) { // only handle horizontal kerning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        const Subtable_0* table = (const Subtable_0*)((char*)subhead + KERN_SUBTABLE_HEADER_SIZE);
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   124
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   125
        nPairs        = SWAPW(table->nPairs);
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   126
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   127
#if 0   // some old fonts have bad values here...
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   128
        searchRange   = SWAPW(table->searchRange);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        entrySelector = SWAPW(table->entrySelector);
7486
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   130
        rangeShift    = SWAPW(table->rangeShift);
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   131
#else
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   132
        entrySelector = OpenTypeUtilities::highBit(nPairs);
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   133
        searchRange   = (1 << entrySelector) * KERN_PAIRINFO_SIZE;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   134
        rangeShift    = (nPairs * KERN_PAIRINFO_SIZE) - searchRange;
6a36b1ebc620 6886358: layout code update
srl
parents: 5506
diff changeset
   135
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        pairs = (PairInfo*)font->getKernPairs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if (pairs == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            char *pairData = (char*)table + KERN_SUBTABLE_0_HEADER_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            char *pptr = pairData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            pairs =  (PairInfo*)(malloc(nPairs*sizeof(PairInfo)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            PairInfo *p = (PairInfo*)pairs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            for (int i = 0; i < nPairs; i++, pptr += KERN_PAIRINFO_SIZE, p++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
              memcpy(p, pptr, KERN_PAIRINFO_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
              p->key = SWAPL(p->key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            font->setKernPairs((void*)pairs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
#if DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        fprintf(stderr, "coverage: %0.4x nPairs: %d pairs 0x%x\n", coverage, nPairs, pairs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        fprintf(stderr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
          "  searchRange(pairs): %d entrySelector: %d rangeShift(pairs): %d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
          searchRange, entrySelector, rangeShift);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
          // dump part of the pair list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
          char ids[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
          for (int i = 256; --i >= 0;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            LEGlyphID id = font->mapCharToGlyph(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            if (id < 256) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
              ids[id] = (char)i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
          PairInfo *p = pairs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
          for (int i = 0; i < nPairs; ++i, p++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            le_uint32 k = p->key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            le_uint16 left = (k >> 16) & 0xffff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            le_uint16 right = k & 0xffff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            if (left < 256 && right < 256) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
              char c = ids[left];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
              if (c > 0x20 && c < 0x7f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                fprintf(stderr, "%c/", c & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
              } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                fprintf(stderr, "%0.2x/", c & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
              c = ids[right];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
              if (c > 0x20 && c < 0x7f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                fprintf(stderr, "%c ", c & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
              } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                fprintf(stderr, "%0.2x ", c & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 * Process the glyph positions.  The positions array has two floats for each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 * glyph, plus a trailing pair to mark the end of the last glyph.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
void KernTable::process(LEGlyphStorage& storage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
  if (pairs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    LEErrorCode success = LE_NO_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    le_uint32 key = storage[0]; // no need to mask off high bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    float adjust = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    for (int i = 1, e = storage.getGlyphCount(); i < e; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
      key = key << 16 | (storage[i] & 0xffff);
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   206
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   207
      // argh, to do a binary search, we need to have the pair list in sorted order
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   208
      // but it is not in sorted order on win32 platforms because of the endianness difference
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   209
      // so either I have to swap the element each time I examine it, or I have to swap
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   210
      // all the elements ahead of time and store them in the font
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   211
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
      const PairInfo* p = pairs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
      const PairInfo* tp = (const PairInfo*)(p + rangeShift);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
      if (key > tp->key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        p = tp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
#if DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
      fprintf(stderr, "binary search for %0.8x\n", key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
      le_uint32 probe = searchRange;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
      while (probe > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        probe >>= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        tp = (const PairInfo*)(p + probe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        le_uint32 tkey = tp->key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
#if DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        fprintf(stdout, "   %.3d (%0.8x)\n", (tp - pairs), tkey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        if (tkey <= key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
          if (tkey == key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            le_int16 value = SWAPW(tp->value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
#if DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            fprintf(stdout, "binary found kerning pair %x:%x at %d, value: 0x%x (%g)\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                    storage[i-1], storage[i], i, value & 0xffff, font->xUnitsToPoints(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            fflush(stdout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            // Have to undo the device transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            // REMIND either find a way to do this only if there is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            // device transform, or a faster way, such as moving the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            // entire kern table up to Java.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            LEPoint pt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            pt.fX = font->xUnitsToPoints(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            pt.fY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            font->getKerningAdjustment(pt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            adjust += pt.fX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
          p = tp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
      storage.adjustPosition(i, adjust, 0, success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    storage.adjustPosition(storage.getGlyphCount(), adjust, 0, success);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
}
3935
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   259
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   260
U_NAMESPACE_END
afcdb712a9c5 6501644: sync LayoutEngine *code* structure to match ICU
srl
parents: 2
diff changeset
   261