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 #include "layout/LETypes.h" 41 #include "layout/LEFontInstance.h" 42 #include "jni.h" 43 #include "sunfontids.h" 44 #include "fontscalerdefs.h" 45 #include <jni_util.h> 46 47 class FontInstanceAdapter : public LEFontInstance { 48 private: 49 JNIEnv *env; 50 jobject font2D; 51 jobject fontStrike; 52 53 float xppem; 54 float yppem; 55 56 float xScaleUnitsToPoints; 57 float yScaleUnitsToPoints; 58 59 float xScalePixelsToUnits; 60 float yScalePixelsToUnits; 61 62 le_int32 upem; 63 float xPointSize, yPointSize; 64 float txMat[4]; 65 66 float euclidianDistance(float a, float b); 67 68 /* Table format is the same as defined in the truetype spec. 69 Pointer can be NULL (e.g. for Type1 fonts). */ 70 TTLayoutTableCache* layoutTables; 71 72 public: 73 FontInstanceAdapter(JNIEnv *env, 74 jobject theFont2D, jobject theFontStrike, 75 float *matrix, le_int32 xRes, le_int32 yRes, 76 le_int32 theUPEM, TTLayoutTableCache *ltables); 77 78 virtual ~FontInstanceAdapter() { }; 79 80 virtual const LEFontInstance *getSubFont(const LEUnicode chars[], 81 le_int32 *offset, le_int32 limit, 82 le_int32 script, LEErrorCode &success) const { 83 return this; 84 } 85 86 // tables are cached with the native font scaler data 87 // only supports gsub, gpos, gdef, mort tables at present 88 virtual const void *getFontTable(LETag tableTag) const; 89 virtual const void *getFontTable(LETag tableTag, size_t &len) const; 90 91 virtual void *getKernPairs() const { 92 return layoutTables->kernPairs; 93 } 94 virtual void setKernPairs(void *pairs) const { 95 layoutTables->kernPairs = pairs; 96 } 97 98 virtual le_bool canDisplay(LEUnicode32 ch) const 99 { 100 return (le_bool)env->CallBooleanMethod(font2D, 101 sunFontIDs.canDisplayMID, ch); 102 }; 103 104 virtual le_int32 getUnitsPerEM() const { 105 return upem; 106 }; 107 108 virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper) const; 109 110 virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch) const; 111 112 virtual void mapCharsToWideGlyphs(const LEUnicode chars[], 113 le_int32 offset, le_int32 count, le_bool reverse, 114 const LECharMapper *mapper, le_uint32 glyphs[]) const; 115 116 virtual le_uint32 mapCharToWideGlyph(LEUnicode32 ch, 117 const LECharMapper *mapper) const; 118 119 virtual void getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const; 120 121 virtual void getKerningAdjustment(LEPoint &adjustment) const; 122 123 virtual void getWideGlyphAdvance(le_uint32 glyph, LEPoint &advance) const; 124 125 virtual le_bool getGlyphPoint(LEGlyphID glyph, 126 le_int32 pointNumber, LEPoint &point) const; 127 128 float getXPixelsPerEm() const 129 { 130 return xppem; 131 }; 132 133 float getYPixelsPerEm() const 134 { 135 return yppem; 136 }; 137 138 float xUnitsToPoints(float xUnits) const 139 { 140 return xUnits * xScaleUnitsToPoints; 141 }; 142 143 float yUnitsToPoints(float yUnits) const 144 { 145 return yUnits * yScaleUnitsToPoints; 146 }; 147 148 void unitsToPoints(LEPoint &units, LEPoint &points) const 149 { 150 points.fX = xUnitsToPoints(units.fX); 151 points.fY = yUnitsToPoints(units.fY); 152 } 153 154 float xPixelsToUnits(float xPixels) const 155 { 156 return xPixels * xScalePixelsToUnits; 157 }; 158 159 float yPixelsToUnits(float yPixels) const 160 { 161 return yPixels * yScalePixelsToUnits; 162 }; 163 164 void pixelsToUnits(LEPoint &pixels, LEPoint &units) const 165 { 166 units.fX = xPixelsToUnits(pixels.fX); 167 units.fY = yPixelsToUnits(pixels.fY); 168 }; 169 170 virtual float getScaleFactorX() const { 171 return xScalePixelsToUnits; 172 }; 173 174 virtual float getScaleFactorY() const { 175 return yScalePixelsToUnits; 176 }; 177 178 void transformFunits(float xFunits, float yFunits, LEPoint &pixels) const; 179 180 virtual le_int32 getAscent() const { return 0; }; // not used 181 virtual le_int32 getDescent() const { return 0; }; // not used 182 virtual le_int32 getLeading() const { return 0; }; // not used 183 }; 184 185 #endif