1/* 2 * Copyright (c) 1999, 2013, 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 "LETypes.h" 41#include "LEFontInstance.h" 42#include "jni.h" 43#include "sunfontids.h" 44#include "fontscalerdefs.h" 45#include <jni_util.h> 46 47class FontInstanceAdapter : public LEFontInstance { 48private: 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 72public: 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, size_t &len) const; 89 90 virtual void *getKernPairs() const { 91 return layoutTables->kernPairs; 92 } 93 virtual void setKernPairs(void *pairs) const { 94 layoutTables->kernPairs = pairs; 95 } 96 97 virtual le_bool canDisplay(LEUnicode32 ch) const 98 { 99 return (le_bool)env->CallBooleanMethod(font2D, 100 sunFontIDs.canDisplayMID, ch); 101 }; 102 103 virtual le_int32 getUnitsPerEM() const { 104 return upem; 105 }; 106 107 virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper) const; 108 109 virtual LEGlyphID mapCharToGlyph(LEUnicode32 ch) const; 110 111 virtual void mapCharsToWideGlyphs(const LEUnicode chars[], 112 le_int32 offset, le_int32 count, le_bool reverse, 113 const LECharMapper *mapper, le_uint32 glyphs[]) const; 114 115 virtual le_uint32 mapCharToWideGlyph(LEUnicode32 ch, 116 const LECharMapper *mapper) const; 117 118 virtual void getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const; 119 120 virtual void getKerningAdjustment(LEPoint &adjustment) const; 121 122 virtual void getWideGlyphAdvance(le_uint32 glyph, LEPoint &advance) const; 123 124 virtual le_bool getGlyphPoint(LEGlyphID glyph, 125 le_int32 pointNumber, LEPoint &point) const; 126 127 float getXPixelsPerEm() const 128 { 129 return xppem; 130 }; 131 132 float getYPixelsPerEm() const 133 { 134 return yppem; 135 }; 136 137 float xUnitsToPoints(float xUnits) const 138 { 139 return xUnits * xScaleUnitsToPoints; 140 }; 141 142 float yUnitsToPoints(float yUnits) const 143 { 144 return yUnits * yScaleUnitsToPoints; 145 }; 146 147 void unitsToPoints(LEPoint &units, LEPoint &points) const 148 { 149 points.fX = xUnitsToPoints(units.fX); 150 points.fY = yUnitsToPoints(units.fY); 151 } 152 153 float xPixelsToUnits(float xPixels) const 154 { 155 return xPixels * xScalePixelsToUnits; 156 }; 157 158 float yPixelsToUnits(float yPixels) const 159 { 160 return yPixels * yScalePixelsToUnits; 161 }; 162 163 void pixelsToUnits(LEPoint &pixels, LEPoint &units) const 164 { 165 units.fX = xPixelsToUnits(pixels.fX); 166 units.fY = yPixelsToUnits(pixels.fY); 167 }; 168 169 virtual float getScaleFactorX() const { 170 return xScalePixelsToUnits; 171 }; 172 173 virtual float getScaleFactorY() const { 174 return yScalePixelsToUnits; 175 }; 176 177 void transformFunits(float xFunits, float yFunits, LEPoint &pixels) const; 178 179 virtual le_int32 getAscent() const { return 0; }; // not used 180 virtual le_int32 getDescent() const { return 0; }; // not used 181 virtual le_int32 getLeading() const { return 0; }; // not used 182}; 183 184#endif 185