src/macosx/classes/sun/font/CStrike.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 29,39 **** import java.awt.geom.*; import java.util.*; import sun.awt.SunHints; ! public class CStrike extends FontStrike { // Creates the native strike private static native long createNativeStrikePtr(long nativeFontPtr, double[] glyphTx, double[] invDevTxMatrix, --- 29,39 ---- import java.awt.geom.*; import java.util.*; import sun.awt.SunHints; ! public final class CStrike extends FontStrike { // Creates the native strike private static native long createNativeStrikePtr(long nativeFontPtr, double[] glyphTx, double[] invDevTxMatrix,
*** 66,79 **** private static native void getNativeGlyphImageBounds(long nativeStrikePtr, int glyphCode, Rectangle2D.Float result, double x, double y); ! private CFont nativeFont; private AffineTransform invDevTx; ! private GlyphInfoCache glyphInfoCache; ! private GlyphAdvanceCache glyphAdvanceCache; private long nativeStrikePtr; CStrike(final CFont font, final FontStrikeDesc inDesc) { nativeFont = font; desc = inDesc; --- 66,79 ---- private static native void getNativeGlyphImageBounds(long nativeStrikePtr, int glyphCode, Rectangle2D.Float result, double x, double y); ! private final CFont nativeFont; private AffineTransform invDevTx; ! private final GlyphInfoCache glyphInfoCache; ! private final GlyphAdvanceCache glyphAdvanceCache; private long nativeStrikePtr; CStrike(final CFont font, final FontStrikeDesc inDesc) { nativeFont = font; desc = inDesc;
*** 82,96 **** disposer = glyphInfoCache; // Normally the device transform should be the identity transform // for screen operations. The device transform only becomes // interesting when we are outputting between different dpi surfaces, ! // like when we are printing to postscript. if (inDesc.devTx != null && !inDesc.devTx.isIdentity()) { try { invDevTx = inDesc.devTx.createInverse(); ! } catch (NoninvertibleTransformException e) { // ignored, since device transforms should not be that // complicated, and if they are - there is nothing we can do, // so we won't worry about it. } } --- 82,96 ---- disposer = glyphInfoCache; // Normally the device transform should be the identity transform // for screen operations. The device transform only becomes // interesting when we are outputting between different dpi surfaces, ! // like when we are printing to postscript or use retina. if (inDesc.devTx != null && !inDesc.devTx.isIdentity()) { try { invDevTx = inDesc.devTx.createInverse(); ! } catch (NoninvertibleTransformException ignored) { // ignored, since device transforms should not be that // complicated, and if they are - there is nothing we can do, // so we won't worry about it. } }
*** 132,150 **** disposeNativeStrikePtr(nativeStrikePtr); } nativeStrikePtr = 0; } - // the fractional metrics default on our platform is OFF - private boolean useFractionalMetrics() { - return desc.fmHint == SunHints.INTVAL_FRACTIONALMETRICS_ON; - } public int getNumGlyphs() { return nativeFont.getNumGlyphs(); } StrikeMetrics getFontMetrics() { if (strikeMetrics == null) { StrikeMetrics metrics = getFontMetrics(getNativeStrikePtr()); if (invDevTx != null) { metrics.convertToUserSpace(invDevTx); --- 132,148 ---- disposeNativeStrikePtr(nativeStrikePtr); } nativeStrikePtr = 0; } + @Override public int getNumGlyphs() { return nativeFont.getNumGlyphs(); } + @Override StrikeMetrics getFontMetrics() { if (strikeMetrics == null) { StrikeMetrics metrics = getFontMetrics(getNativeStrikePtr()); if (invDevTx != null) { metrics.convertToUserSpace(invDevTx);
*** 153,230 **** strikeMetrics = metrics; } return strikeMetrics; } ! float getGlyphAdvance(int glyphCode) { ! return getScaledAdvanceForAdvance(getCachedNativeGlyphAdvance(glyphCode)); ! } ! ! float getCodePointAdvance(int cp) { ! float advance = getCachedNativeGlyphAdvance(nativeFont.getMapper().charToGlyph(cp)); ! ! double glyphScaleX = desc.glyphTx.getScaleX(); ! double devScaleX = desc.devTx.getScaleX(); ! ! if (devScaleX == 0) { ! glyphScaleX = Math.sqrt(desc.glyphTx.getDeterminant()); ! devScaleX = Math.sqrt(desc.devTx.getDeterminant()); ! } ! ! if (devScaleX == 0) { ! devScaleX = Double.NaN; // this an undefined graphics state ! } ! advance = (float) (advance * glyphScaleX / devScaleX); ! return useFractionalMetrics() ? advance : Math.round(advance); ! } ! ! // calculate an advance, and round if not using fractional metrics ! private float getScaledAdvanceForAdvance(float advance) { ! if (invDevTx != null) { ! advance *= invDevTx.getScaleX(); ! } ! advance *= desc.glyphTx.getScaleX(); ! return useFractionalMetrics() ? advance : Math.round(advance); ! } ! ! Point2D.Float getCharMetrics(char ch) { ! return getScaledPointForAdvance(getCachedNativeGlyphAdvance(nativeFont.getMapper().charToGlyph(ch))); } ! Point2D.Float getGlyphMetrics(int glyphCode) { ! return getScaledPointForAdvance(getCachedNativeGlyphAdvance(glyphCode)); } ! // calculate an advance point, and round if not using fractional metrics ! private Point2D.Float getScaledPointForAdvance(float advance) { ! Point2D.Float pt = new Point2D.Float(advance, 0); ! ! if (!desc.glyphTx.isIdentity()) { ! return scalePoint(pt); ! } ! ! if (!useFractionalMetrics()) { ! pt.x = Math.round(pt.x); ! } ! return pt; ! } ! ! private Point2D.Float scalePoint(Point2D.Float pt) { ! if (invDevTx != null) { ! // transform the point out of the device space first ! invDevTx.transform(pt, pt); ! } ! desc.glyphTx.transform(pt, pt); ! pt.x -= desc.glyphTx.getTranslateX(); ! pt.y -= desc.glyphTx.getTranslateY(); ! ! if (!useFractionalMetrics()) { ! pt.x = Math.round(pt.x); ! pt.y = Math.round(pt.y); } ! return pt; } Rectangle2D.Float getGlyphOutlineBounds(int glyphCode) { GeneralPath gp = getGlyphOutline(glyphCode, 0f, 0f); Rectangle2D r2d = gp.getBounds2D(); --- 151,178 ---- strikeMetrics = metrics; } return strikeMetrics; } ! @Override ! float getGlyphAdvance(final int glyphCode) { ! return getCachedNativeGlyphAdvance(glyphCode); } ! @Override ! float getCodePointAdvance(final int cp) { ! return getGlyphAdvance(nativeFont.getMapper().charToGlyph(cp)); } ! @Override ! Point2D.Float getCharMetrics(final char ch) { ! return getGlyphMetrics(nativeFont.getMapper().charToGlyph(ch)); } ! @Override ! Point2D.Float getGlyphMetrics(final int glyphCode) { ! return new Point2D.Float(getGlyphAdvance(glyphCode), 0.0f); } Rectangle2D.Float getGlyphOutlineBounds(int glyphCode) { GeneralPath gp = getGlyphOutline(glyphCode, 0f, 0f); Rectangle2D r2d = gp.getBounds2D();
*** 412,424 **** private final long[] firstLayerCache; private SparseBitShiftingTwoLayerArray secondLayerCache; private HashMap<Integer, Long> generalCache; ! public GlyphInfoCache(final Font2D nativeFont, ! final FontStrikeDesc desc) ! { super(nativeFont, desc); firstLayerCache = new long[FIRST_LAYER_SIZE]; } public synchronized long get(final int index) { --- 360,370 ---- private final long[] firstLayerCache; private SparseBitShiftingTwoLayerArray secondLayerCache; private HashMap<Integer, Long> generalCache; ! GlyphInfoCache(final Font2D nativeFont, final FontStrikeDesc desc) { super(nativeFont, desc); firstLayerCache = new long[FIRST_LAYER_SIZE]; } public synchronized long get(final int index) {
*** 525,535 **** private static class SparseBitShiftingTwoLayerArray { final long[][] cache; final int shift; final int secondLayerLength; ! public SparseBitShiftingTwoLayerArray(final int size, final int shift) { this.shift = shift; this.cache = new long[1 << shift][]; this.secondLayerLength = size >> shift; } --- 471,481 ---- private static class SparseBitShiftingTwoLayerArray { final long[][] cache; final int shift; final int secondLayerLength; ! SparseBitShiftingTwoLayerArray(final int size, final int shift) { this.shift = shift; this.cache = new long[1 << shift][]; this.secondLayerLength = size >> shift; }
*** 557,566 **** --- 503,518 ---- private final float[] firstLayerCache = new float[FIRST_LAYER_SIZE]; private SparseBitShiftingTwoLayerArray secondLayerCache; private HashMap<Integer, Float> generalCache; + // Empty non private constructor was added because access to this + // class shouldn't be emulated by a synthetic accessor method. + GlyphAdvanceCache() { + super(); + } + public synchronized float get(final int index) { if (index < 0) { if (-index < SECOND_LAYER_SIZE) { // catch common unicodes if (secondLayerCache == null) return 0;
*** 607,619 **** private static class SparseBitShiftingTwoLayerArray { final float[][] cache; final int shift; final int secondLayerLength; ! public SparseBitShiftingTwoLayerArray(final int size, ! final int shift) ! { this.shift = shift; this.cache = new float[1 << shift][]; this.secondLayerLength = size >> shift; } --- 559,569 ---- private static class SparseBitShiftingTwoLayerArray { final float[][] cache; final int shift; final int secondLayerLength; ! SparseBitShiftingTwoLayerArray(final int size, final int shift) { this.shift = shift; this.cache = new float[1 << shift][]; this.secondLayerLength = size >> shift; }