1 /*
   2  * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 
  27 /*
  28  * (C) Copyright IBM Corp. 1998-2001 - All Rights Reserved
  29  *
  30  * The original version of this source code and documentation is
  31  * copyrighted and owned by IBM. These materials are provided
  32  * under terms of a License Agreement between IBM and Sun.
  33  * This technology is protected by multiple US and International
  34  * patents. This notice and attribution to IBM may not be removed.
  35  */
  36 
  37 #ifndef __FONTINSTANCEADAPTER_H
  38 #define __FONTINSTANCEADAPTER_H
  39 
  40 #ifdef USE_EXTERNAL_ICU_LE
  41 #include <layout/LETypes.h>
  42 #include <layout/LEFontInstance.h>
  43 #else
  44 #include "layout/LETypes.h"
  45 #include "layout/LEFontInstance.h"
  46 #endif
  47 #include "jni.h"
  48 #include "sunfontids.h"
  49 #include "fontscalerdefs.h"
  50 #include <jni_util.h>
  51 
  52 class FontInstanceAdapter : public LEFontInstance {
  53 private:
  54     JNIEnv *env;
  55     jobject font2D;
  56     jobject fontStrike;
  57 
  58     float xppem;
  59     float yppem;
  60 
  61     float xScaleUnitsToPoints;
  62     float yScaleUnitsToPoints;
  63 
  64     float xScalePixelsToUnits;
  65     float yScalePixelsToUnits;
  66 
  67     le_int32 upem;
  68     float xPointSize, yPointSize;
  69     float txMat[4];
  70 
  71     float euclidianDistance(float a, float b);
  72 
  73     /* Table format is the same as defined in the truetype spec.
  74        Pointer can be NULL (e.g. for Type1 fonts). */
  75     TTLayoutTableCache* layoutTables;
  76 
  77 public:
  78     FontInstanceAdapter(JNIEnv *env,
  79                         jobject theFont2D, jobject theFontStrike,
  80                         float *matrix, le_int32 xRes, le_int32 yRes,
  81                         le_int32 theUPEM, TTLayoutTableCache *ltables);
  82 
  83     virtual ~FontInstanceAdapter() { };
  84 
  85     virtual const LEFontInstance *getSubFont(const LEUnicode chars[],
  86                             le_int32 *offset, le_int32 limit,
  87                             le_int32 script, LEErrorCode &success) const {
  88       return this;
  89     }
  90 
  91     // tables are cached with the native font scaler data
  92     // only supports gsub, gpos, gdef, mort tables at present
  93     virtual const void *getFontTable(LETag tableTag) const;
  94     virtual const void *getFontTable(LETag tableTag, size_t &len) const;
  95 
  96     virtual void *getKernPairs() const {
  97         return layoutTables->kernPairs;
  98     }
  99     virtual void setKernPairs(void *pairs) const {
 100         layoutTables->kernPairs = pairs;
 101     }
 102 
 103     virtual le_bool canDisplay(LEUnicode32 ch) const
 104     {
 105         return  (le_bool)env->CallBooleanMethod(font2D,
 106                                                 sunFontIDs.canDisplayMID, ch);
 107     };
 108 
 109     virtual le_int32 getUnitsPerEM() const {
 110        return upem;
 111     };
 112 
 113     virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper) const;
 114 
 115     virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch) const;
 116 
 117     virtual void mapCharsToWideGlyphs(const LEUnicode chars[],
 118         le_int32 offset, le_int32 count, le_bool reverse,
 119         const LECharMapper *mapper, le_uint32 glyphs[]) const;
 120 
 121     virtual le_uint32 mapCharToWideGlyph(LEUnicode32 ch,
 122         const LECharMapper *mapper) const;
 123 
 124     virtual void getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const;
 125 
 126     virtual void getKerningAdjustment(LEPoint &adjustment) const;
 127 
 128     virtual void getWideGlyphAdvance(le_uint32 glyph, LEPoint &advance) const;
 129 
 130     virtual le_bool getGlyphPoint(LEGlyphID glyph,
 131         le_int32 pointNumber, LEPoint &point) const;
 132 
 133     float getXPixelsPerEm() const
 134     {
 135         return xppem;
 136     };
 137 
 138     float getYPixelsPerEm() const
 139     {
 140         return yppem;
 141     };
 142 
 143     float xUnitsToPoints(float xUnits) const
 144     {
 145         return xUnits * xScaleUnitsToPoints;
 146     };
 147 
 148     float yUnitsToPoints(float yUnits) const
 149     {
 150         return yUnits * yScaleUnitsToPoints;
 151     };
 152 
 153     void unitsToPoints(LEPoint &units, LEPoint &points) const
 154     {
 155         points.fX = xUnitsToPoints(units.fX);
 156         points.fY = yUnitsToPoints(units.fY);
 157     }
 158 
 159     float xPixelsToUnits(float xPixels) const
 160     {
 161         return xPixels * xScalePixelsToUnits;
 162     };
 163 
 164     float yPixelsToUnits(float yPixels) const
 165     {
 166         return yPixels * yScalePixelsToUnits;
 167     };
 168 
 169     void pixelsToUnits(LEPoint &pixels, LEPoint &units) const
 170     {
 171         units.fX = xPixelsToUnits(pixels.fX);
 172         units.fY = yPixelsToUnits(pixels.fY);
 173     };
 174 
 175     virtual float getScaleFactorX() const {
 176         return xScalePixelsToUnits;
 177     };
 178 
 179     virtual float getScaleFactorY() const {
 180         return yScalePixelsToUnits;
 181     };
 182 
 183     void transformFunits(float xFunits, float yFunits, LEPoint &pixels) const;
 184 
 185     virtual le_int32 getAscent() const { return 0; };  // not used
 186     virtual le_int32 getDescent() const { return 0; }; // not used
 187     virtual le_int32 getLeading() const { return 0; }; // not used
 188 };
 189 
 190 #endif