jdk/src/share/native/sun/font/FontInstanceAdapter.cpp
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
child 7936 4d5f799d3734
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1999, 2007, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
const void *FontInstanceAdapter::getFontTable(LETag tableTag) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
  if (!layoutTables) { // t1 font
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
  // cache in font's pscaler object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
  // font disposer will handle for us
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
  switch(tableTag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  case GSUB_TAG: if (layoutTables->gsub_len != -1) return (void*)layoutTables->gsub; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
  case GPOS_TAG: if (layoutTables->gpos_len != -1) return (void*)layoutTables->gpos; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
  case GDEF_TAG: if (layoutTables->gdef_len != -1) return (void*)layoutTables->gdef; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
  case MORT_TAG: if (layoutTables->mort_len != -1) return (void*)layoutTables->mort; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
  case KERN_TAG: if (layoutTables->kern_len != -1) return (void*)layoutTables->kern; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
  default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
   //fprintf(stderr, "unexpected table request from font instance adapter: %x\n", tableTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
  jbyte* result = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
  jsize  len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
  jbyteArray tableBytes = (jbyteArray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    env->CallObjectMethod(font2D, sunFontIDs.getTableBytesMID, tableTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
  if (!IS_NULL(tableBytes)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    len = env->GetArrayLength(tableBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    result = new jbyte[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    env->GetByteArrayRegion(tableBytes, 0, len, result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
  switch(tableTag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
  case GSUB_TAG: layoutTables->gsub = (void*)result; layoutTables->gsub_len = len; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
  case GPOS_TAG: layoutTables->gpos = (void*)result; layoutTables->gpos_len = len; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
  case GDEF_TAG: layoutTables->gdef = (void*)result; layoutTables->gdef_len = len; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
  case MORT_TAG: layoutTables->mort = (void*)result; layoutTables->mort_len = len; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
  case KERN_TAG: layoutTables->kern = (void*)result; layoutTables->kern_len = len; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
  default: break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
  return (void*)result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
LEGlyphID FontInstanceAdapter::mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    LEUnicode32 mappedChar = mapper->mapChar(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    if (mappedChar == 0xFFFF || mappedChar == 0xFFFE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        return 0xFFFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    if (mappedChar == 0x200C || mappedChar == 0x200D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    LEGlyphID id = (LEGlyphID)env->CallIntMethod(font2D, sunFontIDs.f2dCharToGlyphMID, (jint)mappedChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    return id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
LEGlyphID FontInstanceAdapter::mapCharToGlyph(LEUnicode32 ch) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    LEGlyphID id = (LEGlyphID)env->CallIntMethod(font2D, sunFontIDs.f2dCharToGlyphMID, ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    return id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
void FontInstanceAdapter::mapCharsToWideGlyphs(const LEUnicode chars[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    le_int32 offset, le_int32 count, le_bool reverse,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    const LECharMapper *mapper, le_uint32 glyphs[]) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    le_int32 i, out = 0, dir = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    if (reverse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        out = count - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        dir = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    for (i = offset; i < offset + count; i += 1, out += dir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                LEUnicode16 high = chars[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                LEUnicode32 code = high;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                if (i < offset + count - 1 && high >= 0xD800 && high <= 0xDBFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                        LEUnicode16 low = chars[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                        if (low >= 0xDC00 && low <= 0xDFFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                                code = (high - 0xD800) * 0x400 + low - 0xDC00 + 0x10000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        glyphs[out] = mapCharToWideGlyph(code, mapper);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                if (code >= 0x10000) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                        i += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                        glyphs[out += dir] = 0xFFFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
le_uint32 FontInstanceAdapter::mapCharToWideGlyph(LEUnicode32 ch, const LECharMapper *mapper) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    LEUnicode32 mappedChar = mapper->mapChar(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    if (mappedChar == 0xFFFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        return 0xFFFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    if (mappedChar == 0x200C || mappedChar == 0x200D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    return (LEGlyphID)env->CallIntMethod(font2D, sunFontIDs.charToGlyphMID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                                         mappedChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
void FontInstanceAdapter::getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    getWideGlyphAdvance((le_uint32)glyph, advance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
void FontInstanceAdapter::getKerningAdjustment(LEPoint &adjustment) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    float xx, xy, yx, yy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    le_bool isIdentityMatrix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    isIdentityMatrix = (txMat[0] == 1 && txMat[1] == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                        txMat[2] == 0 && txMat[3] == 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    if (!isIdentityMatrix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
      xx = adjustment.fX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
      xy = xx * txMat[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
      xx = xx * txMat[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
      yy = adjustment.fY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
      yx = yy * txMat[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
      yy = yy * txMat[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
      adjustment.fX = xx + yx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
      adjustment.fY = xy + yy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    jobject pt = env->NewObject(sunFontIDs.pt2DFloatClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                                sunFontIDs.pt2DFloatCtr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                                adjustment.fX, adjustment.fY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    env->CallObjectMethod(fontStrike, sunFontIDs.adjustPointMID, pt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    adjustment.fX = env->GetFloatField(pt, sunFontIDs.xFID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    adjustment.fY = env->GetFloatField(pt, sunFontIDs.yFID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
void FontInstanceAdapter::getWideGlyphAdvance(le_uint32 glyph, LEPoint &advance) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    if ((glyph & 0xfffe) == 0xfffe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        advance.fX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        advance.fY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    jobject pt = env->CallObjectMethod(fontStrike,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                                       sunFontIDs.getGlyphMetricsMID, glyph);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    if (pt != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        advance.fX = env->GetFloatField(pt, sunFontIDs.xFID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        advance.fY = env->GetFloatField(pt, sunFontIDs.yFID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
le_bool FontInstanceAdapter::getGlyphPoint(LEGlyphID glyph,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                                           le_int32 pointNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                                           LEPoint &point) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
  /* This upcall is not ideal, since it will make another down call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
   * The intention is to move up some of this code into Java. But
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
   * a HashMap has been added to the Java PhysicalStrike object to cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
   * these points so that they don't need to be repeatedly recalculated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
   * which is expensive as it needs the font scaler to re-generate the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
   * hinted glyph outline. This turns out to be a huge win over 1.4.x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     jobject pt = env->CallObjectMethod(fontStrike,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                                        sunFontIDs.getGlyphPointMID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                                        glyph, pointNumber);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     if (pt != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
       /* point is a java.awt.geom.Point2D.Float */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        point.fX = env->GetFloatField(pt, sunFontIDs.xFID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        /* convert from java coordinate system to internal '+y up' coordinate system */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        point.fY = -env->GetFloatField(pt, sunFontIDs.yFID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
void FontInstanceAdapter::transformFunits(float xFunits, float yFunits, LEPoint &pixels) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    float xx, xy, yx, yy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    le_bool isIdentityMatrix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    isIdentityMatrix = (txMat[0] == 1 && txMat[1] == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                        txMat[2] == 0 && txMat[3] == 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    xx = xFunits * xScaleUnitsToPoints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    xy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    if (!isIdentityMatrix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        xy = xx * txMat[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        xx = xx * txMat[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    yx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    yy = yFunits * yScaleUnitsToPoints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    if (!isIdentityMatrix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        yx = yy * txMat[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        yy = yy * txMat[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    pixels.fX = xx + yx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    pixels.fY = xy + yy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
float FontInstanceAdapter::euclidianDistance(float a, float b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    if (a < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        a = -a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    if (b < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        b = -b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    if (a == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    if (b == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    float root = a > b ? a + (b / 2) : b + (a / 2); /* Do an initial approximation, in root */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        /* An unrolled Newton-Raphson iteration sequence */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    root = (root + (a * (a / root)) + (b * (b / root)) + 1) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    root = (root + (a * (a / root)) + (b * (b / root)) + 1) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    root = (root + (a * (a / root)) + (b * (b / root)) + 1) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    return root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
}