jdk/src/share/native/sun/font/FontInstanceAdapter.h
author prr
Thu, 07 Mar 2013 10:02:20 -0800
changeset 16891 91e99bed64ae
parent 5506 202f599c92aa
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
/*
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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * (C) Copyright IBM Corp. 1998-2001 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * The original version of this source code and documentation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * copyrighted and owned by IBM. These materials are provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * under terms of a License Agreement between IBM and Sun.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * This technology is protected by multiple US and International
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * patents. This notice and attribution to IBM may not be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#ifndef __FONTINSTANCEADAPTER_H
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#define __FONTINSTANCEADAPTER_H
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include "LETypes.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include "LEFontInstance.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include "jni.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#include "sunfontids.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#include "fontscalerdefs.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#include <jni_util.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
class FontInstanceAdapter : public LEFontInstance {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
private:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    jobject font2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    jobject fontStrike;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    float xppem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    float yppem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    float xScaleUnitsToPoints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    float yScaleUnitsToPoints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    float xScalePixelsToUnits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    float yScalePixelsToUnits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    le_int32 upem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    float xPointSize, yPointSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    float txMat[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    float euclidianDistance(float a, float b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /* Table format is the same as defined in the truetype spec.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
       Pointer can be NULL (e.g. for Type1 fonts). */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    TTLayoutTableCache* layoutTables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
public:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    FontInstanceAdapter(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                        jobject theFont2D, jobject theFontStrike,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                        float *matrix, le_int32 xRes, le_int32 yRes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                        le_int32 theUPEM, TTLayoutTableCache *ltables);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    virtual ~FontInstanceAdapter() { };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    virtual const LEFontInstance *getSubFont(const LEUnicode chars[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                            le_int32 *offset, le_int32 limit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                            le_int32 script, LEErrorCode &success) const {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
      return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    // tables are cached with the native font scaler data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    // only supports gsub, gpos, gdef, mort tables at present
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    virtual const void *getFontTable(LETag tableTag) const;
16891
91e99bed64ae 8001031: Better font processing
prr
parents: 5506
diff changeset
    89
    virtual const void *getFontTable(LETag tableTag, size_t &len) const;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    virtual void *getKernPairs() const {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return layoutTables->kernPairs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    virtual void setKernPairs(void *pairs) const {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        layoutTables->kernPairs = pairs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    virtual le_bool canDisplay(LEUnicode32 ch) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        return  (le_bool)env->CallBooleanMethod(font2D,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                                                sunFontIDs.canDisplayMID, ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    virtual le_int32 getUnitsPerEM() const {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
       return upem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper) const;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch) const;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    virtual void mapCharsToWideGlyphs(const LEUnicode chars[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        le_int32 offset, le_int32 count, le_bool reverse,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        const LECharMapper *mapper, le_uint32 glyphs[]) const;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    virtual le_uint32 mapCharToWideGlyph(LEUnicode32 ch,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        const LECharMapper *mapper) const;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    virtual void getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    virtual void getKerningAdjustment(LEPoint &adjustment) const;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    virtual void getWideGlyphAdvance(le_uint32 glyph, LEPoint &advance) const;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    virtual le_bool getGlyphPoint(LEGlyphID glyph,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        le_int32 pointNumber, LEPoint &point) const;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    float getXPixelsPerEm() const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        return xppem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    float getYPixelsPerEm() const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return yppem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    float xUnitsToPoints(float xUnits) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        return xUnits * xScaleUnitsToPoints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    float yUnitsToPoints(float yUnits) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        return yUnits * yScaleUnitsToPoints;
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 unitsToPoints(LEPoint &units, LEPoint &points) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        points.fX = xUnitsToPoints(units.fX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        points.fY = yUnitsToPoints(units.fY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    float xPixelsToUnits(float xPixels) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return xPixels * xScalePixelsToUnits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    float yPixelsToUnits(float yPixels) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        return yPixels * yScalePixelsToUnits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    void pixelsToUnits(LEPoint &pixels, LEPoint &units) const
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        units.fX = xPixelsToUnits(pixels.fX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        units.fY = yPixelsToUnits(pixels.fY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    virtual float getScaleFactorX() const {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        return xScalePixelsToUnits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    virtual float getScaleFactorY() const {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return yScalePixelsToUnits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    void transformFunits(float xFunits, float yFunits, LEPoint &pixels) const;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    virtual le_int32 getAscent() const { return 0; };  // not used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    virtual le_int32 getDescent() const { return 0; }; // not used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    virtual le_int32 getLeading() const { return 0; }; // not used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
#endif