Path: blob/master/src/java.desktop/share/classes/sun/font/PhysicalStrike.java
41154 views
/*1* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.font;2627import java.awt.Font;28import java.awt.geom.AffineTransform;29import java.awt.geom.GeneralPath;30import java.awt.geom.Point2D;31import java.awt.geom.Rectangle2D;32import java.util.concurrent.ConcurrentHashMap;333435public abstract class PhysicalStrike extends FontStrike {3637static final long INTMASK = 0xffffffffL;38static boolean longAddresses;39static {40switch (StrikeCache.nativeAddressSize) {41case 8: longAddresses = true; break;42case 4: longAddresses = false; break;43default: throw new RuntimeException("Unexpected address size");44}45}4647private PhysicalFont physicalFont;48protected CharToGlyphMapper mapper;49/* the ScalerContext is a native structure pre-filled with the50* info needed to setup the scaler for this strike. Its immutable51* so we set it up when the strike is created and free it when the52* strike is disposed. There's then no need to pass the info down53* separately to native on every call to the scaler.54*/55protected long pScalerContext;5657/* Only one of these two arrays is non-null.58* use the one that matches size of an address (32 or 64 bits)59*/60protected long[] longGlyphImages;61protected int[] intGlyphImages;6263/* Used by the TrueTypeFont subclass, which is the only client64* of getGlyphPoint(). The field and method are here because65* there is no TrueTypeFontStrike subclass.66* This map is a cache of the positions of points on the outline67* of a TrueType glyph. It is used by the OpenType layout engine68* to perform mark positioning. Without this cache every position69* request involves scaling and hinting the glyph outline potentially70* over and over again.71*/72ConcurrentHashMap<Integer, Point2D.Float> glyphPointMapCache;7374protected boolean getImageWithAdvance;75protected static final int complexTX =76AffineTransform.TYPE_FLIP |77AffineTransform.TYPE_GENERAL_SCALE |78AffineTransform.TYPE_GENERAL_ROTATION |79AffineTransform.TYPE_GENERAL_TRANSFORM |80AffineTransform.TYPE_QUADRANT_ROTATION;8182PhysicalStrike(PhysicalFont physicalFont, FontStrikeDesc desc) {83this.physicalFont = physicalFont;84this.desc = desc;85}8687protected PhysicalStrike() {88}89/* A number of methods are delegated by the strike to the scaler90* context which is a shared resource on a physical font.91*/9293public int getNumGlyphs() {94return physicalFont.getNumGlyphs();95}9697/* These 3 metrics methods below should be implemented to return98* values in user space.99*/100StrikeMetrics getFontMetrics() {101if (strikeMetrics == null) {102strikeMetrics =103physicalFont.getFontMetrics(pScalerContext);104}105return strikeMetrics;106}107108float getCodePointAdvance(int cp) {109return getGlyphAdvance(physicalFont.getMapper().charToGlyph(cp));110}111112Point2D.Float getCharMetrics(char ch) {113return getGlyphMetrics(physicalFont.getMapper().charToGlyph(ch));114}115116int getSlot0GlyphImagePtrs(int[] glyphCodes, long[] images, int len) {117return 0;118}119120/* Used by the OpenType engine for mark positioning.121*/122Point2D.Float getGlyphPoint(int glyphCode, int ptNumber) {123Point2D.Float gp = null;124Integer ptKey = Integer.valueOf(glyphCode<<16|ptNumber);125if (glyphPointMapCache == null) {126synchronized (this) {127if (glyphPointMapCache == null) {128glyphPointMapCache =129new ConcurrentHashMap<Integer, Point2D.Float>();130}131}132} else {133gp = glyphPointMapCache.get(ptKey);134}135136if (gp == null) {137gp = (physicalFont.getGlyphPoint(pScalerContext, glyphCode, ptNumber));138adjustPoint(gp);139glyphPointMapCache.put(ptKey, gp);140}141return gp;142}143144protected void adjustPoint(Point2D.Float pt) {145}146}147148149