src/share/classes/sun/font/StandardGlyphVector.java

Print this page


   1 /*
   2  * Copyright (c) 1998, 2005, 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


 710     /**
 711      * Sometimes I wish java had covariant return types...
 712      */
 713     public StandardGlyphVector copy() {
 714         return (StandardGlyphVector)clone();
 715     }
 716 
 717     /**
 718      * As a concrete subclass of GlyphVector, this must implement clone.
 719      */
 720     public Object clone() {
 721         // positions, gti are mutable so we have to clone them
 722         // font2d can be shared
 723         // fsref is a cache and can be shared
 724         try {
 725             StandardGlyphVector result = (StandardGlyphVector)super.clone();
 726 
 727             result.clearCaches();
 728 
 729             if (positions != null) {
 730                 result.positions = (float[])positions.clone();
 731             }
 732 
 733             if (gti != null) {
 734                 result.gti = new GlyphTransformInfo(result, gti);
 735             }
 736 
 737             return result;
 738         }
 739         catch (CloneNotSupportedException e) {
 740         }
 741 
 742         return this;
 743     }
 744 
 745     //////////////////////
 746     // StandardGlyphVector new public methods
 747     /////////////////////
 748 
 749     /*
 750      * Set a multiple glyph positions at one time.  GlyphVector only


 758 
 759         initPositions();
 760         for (int i = start * 2, e = i + count * 2, p = srcStart; i < e; ++i, ++p) {
 761             positions[i] = srcPositions[p];
 762         }
 763 
 764         clearCaches();
 765         addFlags(FLAG_HAS_POSITION_ADJUSTMENTS);
 766     }
 767 
 768     /**
 769      * Set all the glyph positions, including the 'after last glyph' position.
 770      * The srcPositions array must be of length (numGlyphs + 1) * 2.
 771      */
 772     public void setGlyphPositions(float[] srcPositions) {
 773         int requiredLength = glyphs.length * 2 + 2;
 774         if (srcPositions.length != requiredLength) {
 775             throw new IllegalArgumentException("srcPositions.length != " + requiredLength);
 776         }
 777 
 778         positions = (float[])srcPositions.clone();
 779 
 780         clearCaches();
 781         addFlags(FLAG_HAS_POSITION_ADJUSTMENTS);
 782     }
 783 
 784     /**
 785      * This is a convenience overload that gets all the glyph positions, which
 786      * is what you usually want to do if you're getting more than one.
 787      * !!! should I bother taking result parameter?
 788      */
 789     public float[] getGlyphPositions(float[] result) {
 790         return internalGetGlyphPositions(0, glyphs.length + 1, 0, result);
 791     }
 792 
 793     /**
 794      * Get transform information for the requested range of glyphs.
 795      * If no glyphs have a transform, return null.
 796      * If a glyph has no transform (or is the identity transform) its entry in the result array will be null.
 797      * If the passed-in result is null an array will be allocated for the caller.
 798      * Each transform instance in the result array will unique, and independent of the GlyphVector's transform.


1374     // !!! I have this as a separate class instead of just inside SGV,
1375     // but I previously didn't bother.  Now I'm trying this again.
1376     // Probably still not worth it, but I'd like to keep sgv's small in the common case.
1377 
1378     static final class GlyphTransformInfo {
1379         StandardGlyphVector sgv;  // reference back to glyph vector - yuck
1380         int[] indices;            // index into unique strikes
1381         double[] transforms;      // six doubles per unique transform, because AT is a pain to manipulate
1382         SoftReference strikesRef; // ref to unique strikes, one per transform
1383         boolean haveAllStrikes;   // true if the strike array has been filled by getStrikes().
1384 
1385         // used when first setting a transform
1386         GlyphTransformInfo(StandardGlyphVector sgv) {
1387             this.sgv = sgv;
1388         }
1389 
1390         // used when cloning a glyph vector, need to set back link
1391         GlyphTransformInfo(StandardGlyphVector sgv, GlyphTransformInfo rhs) {
1392             this.sgv = sgv;
1393 
1394             this.indices = rhs.indices == null ? null : (int[])rhs.indices.clone();
1395             this.transforms = rhs.transforms == null ? null : (double[])rhs.transforms.clone();
1396             this.strikesRef = null; // can't share cache, so rather than clone, we just null out
1397         }
1398 
1399         // used in sgv equality
1400         public boolean equals(GlyphTransformInfo rhs) {
1401             if (rhs == null) {
1402                 return false;
1403             }
1404             if (rhs == this) {
1405                 return true;
1406             }
1407             if (this.indices.length != rhs.indices.length) {
1408                 return false;
1409             }
1410             if (this.transforms.length != rhs.transforms.length) {
1411                 return false;
1412             }
1413 
1414             // slow since we end up processing the same transforms multiple
1415             // times, but since transforms can be in any order, we either do


   1 /*
   2  * Copyright (c) 1998, 2014, 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


 710     /**
 711      * Sometimes I wish java had covariant return types...
 712      */
 713     public StandardGlyphVector copy() {
 714         return (StandardGlyphVector)clone();
 715     }
 716 
 717     /**
 718      * As a concrete subclass of GlyphVector, this must implement clone.
 719      */
 720     public Object clone() {
 721         // positions, gti are mutable so we have to clone them
 722         // font2d can be shared
 723         // fsref is a cache and can be shared
 724         try {
 725             StandardGlyphVector result = (StandardGlyphVector)super.clone();
 726 
 727             result.clearCaches();
 728 
 729             if (positions != null) {
 730                 result.positions = positions.clone();
 731             }
 732 
 733             if (gti != null) {
 734                 result.gti = new GlyphTransformInfo(result, gti);
 735             }
 736 
 737             return result;
 738         }
 739         catch (CloneNotSupportedException e) {
 740         }
 741 
 742         return this;
 743     }
 744 
 745     //////////////////////
 746     // StandardGlyphVector new public methods
 747     /////////////////////
 748 
 749     /*
 750      * Set a multiple glyph positions at one time.  GlyphVector only


 758 
 759         initPositions();
 760         for (int i = start * 2, e = i + count * 2, p = srcStart; i < e; ++i, ++p) {
 761             positions[i] = srcPositions[p];
 762         }
 763 
 764         clearCaches();
 765         addFlags(FLAG_HAS_POSITION_ADJUSTMENTS);
 766     }
 767 
 768     /**
 769      * Set all the glyph positions, including the 'after last glyph' position.
 770      * The srcPositions array must be of length (numGlyphs + 1) * 2.
 771      */
 772     public void setGlyphPositions(float[] srcPositions) {
 773         int requiredLength = glyphs.length * 2 + 2;
 774         if (srcPositions.length != requiredLength) {
 775             throw new IllegalArgumentException("srcPositions.length != " + requiredLength);
 776         }
 777 
 778         positions = srcPositions.clone();
 779 
 780         clearCaches();
 781         addFlags(FLAG_HAS_POSITION_ADJUSTMENTS);
 782     }
 783 
 784     /**
 785      * This is a convenience overload that gets all the glyph positions, which
 786      * is what you usually want to do if you're getting more than one.
 787      * !!! should I bother taking result parameter?
 788      */
 789     public float[] getGlyphPositions(float[] result) {
 790         return internalGetGlyphPositions(0, glyphs.length + 1, 0, result);
 791     }
 792 
 793     /**
 794      * Get transform information for the requested range of glyphs.
 795      * If no glyphs have a transform, return null.
 796      * If a glyph has no transform (or is the identity transform) its entry in the result array will be null.
 797      * If the passed-in result is null an array will be allocated for the caller.
 798      * Each transform instance in the result array will unique, and independent of the GlyphVector's transform.


1374     // !!! I have this as a separate class instead of just inside SGV,
1375     // but I previously didn't bother.  Now I'm trying this again.
1376     // Probably still not worth it, but I'd like to keep sgv's small in the common case.
1377 
1378     static final class GlyphTransformInfo {
1379         StandardGlyphVector sgv;  // reference back to glyph vector - yuck
1380         int[] indices;            // index into unique strikes
1381         double[] transforms;      // six doubles per unique transform, because AT is a pain to manipulate
1382         SoftReference strikesRef; // ref to unique strikes, one per transform
1383         boolean haveAllStrikes;   // true if the strike array has been filled by getStrikes().
1384 
1385         // used when first setting a transform
1386         GlyphTransformInfo(StandardGlyphVector sgv) {
1387             this.sgv = sgv;
1388         }
1389 
1390         // used when cloning a glyph vector, need to set back link
1391         GlyphTransformInfo(StandardGlyphVector sgv, GlyphTransformInfo rhs) {
1392             this.sgv = sgv;
1393 
1394             this.indices = rhs.indices == null ? null : rhs.indices.clone();
1395             this.transforms = rhs.transforms == null ? null : rhs.transforms.clone();
1396             this.strikesRef = null; // can't share cache, so rather than clone, we just null out
1397         }
1398 
1399         // used in sgv equality
1400         public boolean equals(GlyphTransformInfo rhs) {
1401             if (rhs == null) {
1402                 return false;
1403             }
1404             if (rhs == this) {
1405                 return true;
1406             }
1407             if (this.indices.length != rhs.indices.length) {
1408                 return false;
1409             }
1410             if (this.transforms.length != rhs.transforms.length) {
1411                 return false;
1412             }
1413 
1414             // slow since we end up processing the same transforms multiple
1415             // times, but since transforms can be in any order, we either do