jdk/src/share/native/sun/font/FontInstanceAdapter.cpp
author prr
Thu, 07 Mar 2013 10:02:20 -0800
changeset 16891 91e99bed64ae
parent 9035 1255eb81cc2f
child 23010 6dadb192ad81
permissions -rw-r--r--
8001031: Better font processing Reviewed-by: srl, vadim
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7936
diff changeset
     2
 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
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
 * (C) Copyright IBM Corp. 1998-2001 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * The original version of this source code and documentation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * copyrighted and owned by IBM. These materials are provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * under terms of a License Agreement between IBM and Sun.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * This technology is protected by multiple US and International
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * patents. This notice and attribution to IBM may not be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include "FontInstanceAdapter.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
FontInstanceAdapter::FontInstanceAdapter(JNIEnv *theEnv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
                                         jobject theFont2D,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
                                         jobject theFontStrike,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
                                         float *matrix,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
                                         le_int32 xRes, le_int32 yRes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
                                         le_int32 theUPEM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
                                         TTLayoutTableCache *ltables)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    : env(theEnv), font2D(theFont2D), fontStrike(theFontStrike),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
      xppem(0), yppem(0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
      xScaleUnitsToPoints(0), yScaleUnitsToPoints(0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
      xScalePixelsToUnits(0), yScalePixelsToUnits(0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
      upem(theUPEM), layoutTables(ltables)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    xPointSize = euclidianDistance(matrix[0], matrix[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    yPointSize = euclidianDistance(matrix[2], matrix[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    txMat[0] = matrix[0]/xPointSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    txMat[1] = matrix[1]/xPointSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    txMat[2] = matrix[2]/yPointSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    txMat[3] = matrix[3]/yPointSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    xppem = ((float) xRes / 72) * xPointSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    yppem = ((float) yRes / 72) * yPointSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    xScaleUnitsToPoints = xPointSize / upem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    yScaleUnitsToPoints = yPointSize / upem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    xScalePixelsToUnits = upem / xppem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    yScalePixelsToUnits = upem / yppem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
    69
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
const void *FontInstanceAdapter::getFontTable(LETag tableTag) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
{
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
    72
  size_t ignored = 0;
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
    73
  return getFontTable(tableTag, ignored);
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
    74
}
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
    75
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
    76
static const LETag cacheMap[LAYOUTCACHE_ENTRIES] = {
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
    77
  GPOS_TAG, GDEF_TAG, GSUB_TAG, MORT_TAG, MORX_TAG, KERN_TAG
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
    78
};
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
    79
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
    80
const void *FontInstanceAdapter::getFontTable(LETag tableTag, size_t &length) const
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
    81
{
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
    82
  length = 0;
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
    83
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
  if (!layoutTables) { // t1 font
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
  // cache in font's pscaler object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
  // font disposer will handle for us
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
    91
  int cacheIdx;
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
    92
  for (cacheIdx=0;cacheIdx<LAYOUTCACHE_ENTRIES;cacheIdx++) {
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
    93
    if (tableTag==cacheMap[cacheIdx]) break;
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
    94
  }
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
    95
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
    96
  if (cacheIdx<LAYOUTCACHE_ENTRIES) { // if found
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
    97
    if (layoutTables->entries[cacheIdx].len != -1) {
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
    98
      length = layoutTables->entries[cacheIdx].len;
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
    99
      return layoutTables->entries[cacheIdx].ptr;
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
   100
    }
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
   101
  } else {
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
   102
    //fprintf(stderr, "unexpected table request from font instance adapter: %x\n", tableTag);
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
   103
    // (don't load any other tables)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
  jbyte* result = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
  jsize  len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
  jbyteArray tableBytes = (jbyteArray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    env->CallObjectMethod(font2D, sunFontIDs.getTableBytesMID, tableTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
  if (!IS_NULL(tableBytes)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    len = env->GetArrayLength(tableBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    result = new jbyte[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    env->GetByteArrayRegion(tableBytes, 0, len, result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
   117
  if (cacheIdx<LAYOUTCACHE_ENTRIES) { // if cacheable table
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
   118
    layoutTables->entries[cacheIdx].len = len;
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
   119
    layoutTables->entries[cacheIdx].ptr = (const void*)result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
   122
  length = len;
91e99bed64ae 8001031: Better font processing
prr
parents: 9035
diff changeset
   123
  return (const void*)result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
LEGlyphID FontInstanceAdapter::mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    LEUnicode32 mappedChar = mapper->mapChar(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    if (mappedChar == 0xFFFF || mappedChar == 0xFFFE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return 0xFFFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    if (mappedChar == 0x200C || mappedChar == 0x200D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    LEGlyphID id = (LEGlyphID)env->CallIntMethod(font2D, sunFontIDs.f2dCharToGlyphMID, (jint)mappedChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    return id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
LEGlyphID FontInstanceAdapter::mapCharToGlyph(LEUnicode32 ch) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    LEGlyphID id = (LEGlyphID)env->CallIntMethod(font2D, sunFontIDs.f2dCharToGlyphMID, ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    return id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
void FontInstanceAdapter::mapCharsToWideGlyphs(const LEUnicode chars[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    le_int32 offset, le_int32 count, le_bool reverse,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    const LECharMapper *mapper, le_uint32 glyphs[]) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    le_int32 i, out = 0, dir = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    if (reverse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        out = count - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        dir = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    for (i = offset; i < offset + count; i += 1, out += dir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                LEUnicode16 high = chars[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                LEUnicode32 code = high;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                if (i < offset + count - 1 && high >= 0xD800 && high <= 0xDBFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                        LEUnicode16 low = chars[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                        if (low >= 0xDC00 && low <= 0xDFFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                                code = (high - 0xD800) * 0x400 + low - 0xDC00 + 0x10000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        glyphs[out] = mapCharToWideGlyph(code, mapper);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                if (code >= 0x10000) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                        i += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                        glyphs[out += dir] = 0xFFFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
le_uint32 FontInstanceAdapter::mapCharToWideGlyph(LEUnicode32 ch, const LECharMapper *mapper) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    LEUnicode32 mappedChar = mapper->mapChar(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    if (mappedChar == 0xFFFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        return 0xFFFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    if (mappedChar == 0x200C || mappedChar == 0x200D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    return (LEGlyphID)env->CallIntMethod(font2D, sunFontIDs.charToGlyphMID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                                         mappedChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
void FontInstanceAdapter::getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    getWideGlyphAdvance((le_uint32)glyph, advance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
void FontInstanceAdapter::getKerningAdjustment(LEPoint &adjustment) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    float xx, xy, yx, yy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    le_bool isIdentityMatrix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    isIdentityMatrix = (txMat[0] == 1 && txMat[1] == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                        txMat[2] == 0 && txMat[3] == 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    if (!isIdentityMatrix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
      xx = adjustment.fX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
      xy = xx * txMat[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
      xx = xx * txMat[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
      yy = adjustment.fY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
      yx = yy * txMat[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
      yy = yy * txMat[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
      adjustment.fX = xx + yx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
      adjustment.fY = xy + yy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    jobject pt = env->NewObject(sunFontIDs.pt2DFloatClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                                sunFontIDs.pt2DFloatCtr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                                adjustment.fX, adjustment.fY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    env->CallObjectMethod(fontStrike, sunFontIDs.adjustPointMID, pt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    adjustment.fX = env->GetFloatField(pt, sunFontIDs.xFID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    adjustment.fY = env->GetFloatField(pt, sunFontIDs.yFID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
void FontInstanceAdapter::getWideGlyphAdvance(le_uint32 glyph, LEPoint &advance) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    if ((glyph & 0xfffe) == 0xfffe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        advance.fX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        advance.fY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    jobject pt = env->CallObjectMethod(fontStrike,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                                       sunFontIDs.getGlyphMetricsMID, glyph);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    if (pt != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        advance.fX = env->GetFloatField(pt, sunFontIDs.xFID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        advance.fY = env->GetFloatField(pt, sunFontIDs.yFID);
7936
4d5f799d3734 6951086: Excessive Local References in sun.font.SunLayoutEngine.nativeLayout
prr
parents: 5506
diff changeset
   242
        env->DeleteLocalRef(pt);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
le_bool FontInstanceAdapter::getGlyphPoint(LEGlyphID glyph,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                                           le_int32 pointNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                                           LEPoint &point) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
  /* This upcall is not ideal, since it will make another down call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
   * The intention is to move up some of this code into Java. But
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
   * a HashMap has been added to the Java PhysicalStrike object to cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
   * these points so that they don't need to be repeatedly recalculated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
   * which is expensive as it needs the font scaler to re-generate the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
   * hinted glyph outline. This turns out to be a huge win over 1.4.x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     jobject pt = env->CallObjectMethod(fontStrike,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                                        sunFontIDs.getGlyphPointMID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                                        glyph, pointNumber);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     if (pt != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
       /* point is a java.awt.geom.Point2D.Float */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        point.fX = env->GetFloatField(pt, sunFontIDs.xFID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        /* convert from java coordinate system to internal '+y up' coordinate system */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        point.fY = -env->GetFloatField(pt, sunFontIDs.yFID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
void FontInstanceAdapter::transformFunits(float xFunits, float yFunits, LEPoint &pixels) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    float xx, xy, yx, yy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    le_bool isIdentityMatrix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    isIdentityMatrix = (txMat[0] == 1 && txMat[1] == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                        txMat[2] == 0 && txMat[3] == 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    xx = xFunits * xScaleUnitsToPoints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    xy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    if (!isIdentityMatrix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        xy = xx * txMat[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        xx = xx * txMat[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    yx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    yy = yFunits * yScaleUnitsToPoints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    if (!isIdentityMatrix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        yx = yy * txMat[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        yy = yy * txMat[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    pixels.fX = xx + yx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    pixels.fY = xy + yy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
float FontInstanceAdapter::euclidianDistance(float a, float b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    if (a < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        a = -a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    if (b < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        b = -b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    if (a == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    if (b == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        return a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    float root = a > b ? a + (b / 2) : b + (a / 2); /* Do an initial approximation, in root */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        /* An unrolled Newton-Raphson iteration sequence */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    root = (root + (a * (a / root)) + (b * (b / root)) + 1) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    root = (root + (a * (a / root)) + (b * (b / root)) + 1) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    root = (root + (a * (a / root)) + (b * (b / root)) + 1) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    return root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
}