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

Print this page




  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 /*
  27  *
  28  * (C) Copyright IBM Corp. 2003 - All Rights Reserved
  29  */
  30 
  31 package sun.font;
  32 
  33 import sun.font.GlyphLayout.*;
  34 import java.awt.geom.Point2D;
  35 import java.lang.ref.SoftReference;
  36 import java.util.HashMap;
  37 import java.util.Locale;

  38 
  39 /*
  40  * different ways to do this
  41  * 1) each physical font2d keeps a hashtable mapping scripts to layout
  42  * engines, we query and fill this cache.
  43  * 2) we keep a mapping independent of font using the key Most likely
  44  * few fonts will be used, so option 2 seems better
  45  *
  46  * Once we know which engine to use for a font, we always know, so we
  47  * shouldn't have to recheck each time we do layout.  So the cache is
  48  * ok.
  49  *
  50  * Should we reuse engines?  We could instantiate an engine for each
  51  * font/script pair.  The engine would hold onto the table(s) from the
  52  * font that it needs.  If we have multiple threads using the same
  53  * engine, we still need to keep the state separate, so the native
  54  * engines would still need to be allocated for each call, since they
  55  * keep their state in themselves.  If they used the passed-in GVData
  56  * arrays directly (with some checks for space) then since each GVData
  57  * is different per thread, we could reuse the layout engines.  This


 112 
 113     private static LayoutEngineFactory instance;
 114 
 115     public static LayoutEngineFactory instance() {
 116         if (instance == null) {
 117             instance = new SunLayoutEngine();
 118         }
 119         return instance;
 120     }
 121 
 122     private SunLayoutEngine() {
 123         // actually a factory, key is null so layout cannot be called on it
 124     }
 125 
 126     public LayoutEngine getEngine(Font2D font, int script, int lang) {
 127         return getEngine(new LayoutEngineKey(font, script, lang));
 128     }
 129 
 130   // !!! don't need this unless we have more than one sun layout engine...
 131     public LayoutEngine getEngine(LayoutEngineKey key) {
 132         HashMap cache = (HashMap)cacheref.get();

 133         if (cache == null) {
 134             cache = new HashMap();
 135             cacheref = new SoftReference(cache);
 136         }
 137 
 138         LayoutEngine e = (LayoutEngine)cache.get(key);
 139         if (e == null) {
 140             e = new SunLayoutEngine(key.copy());
 141             cache.put(key, e);
 142         }
 143         return e;
 144     }
 145     private SoftReference cacheref = new SoftReference(null);
 146 
 147     private SunLayoutEngine(LayoutEngineKey key) {
 148         this.key = key;
 149     }
 150 
 151     public void layout(FontStrikeDesc desc, float[] mat, int gmask,
 152                        int baseIndex, TextRecord tr, int typo_flags,
 153                        Point2D.Float pt, GVData data) {
 154         Font2D font = key.font();


  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 /*
  27  *
  28  * (C) Copyright IBM Corp. 2003 - All Rights Reserved
  29  */
  30 
  31 package sun.font;
  32 
  33 import sun.font.GlyphLayout.*;
  34 import java.awt.geom.Point2D;
  35 import java.lang.ref.SoftReference;
  36 import java.util.HashMap;
  37 import java.util.Locale;
  38 import java.util.concurrent.ConcurrentHashMap;
  39 
  40 /*
  41  * different ways to do this
  42  * 1) each physical font2d keeps a hashtable mapping scripts to layout
  43  * engines, we query and fill this cache.
  44  * 2) we keep a mapping independent of font using the key Most likely
  45  * few fonts will be used, so option 2 seems better
  46  *
  47  * Once we know which engine to use for a font, we always know, so we
  48  * shouldn't have to recheck each time we do layout.  So the cache is
  49  * ok.
  50  *
  51  * Should we reuse engines?  We could instantiate an engine for each
  52  * font/script pair.  The engine would hold onto the table(s) from the
  53  * font that it needs.  If we have multiple threads using the same
  54  * engine, we still need to keep the state separate, so the native
  55  * engines would still need to be allocated for each call, since they
  56  * keep their state in themselves.  If they used the passed-in GVData
  57  * arrays directly (with some checks for space) then since each GVData
  58  * is different per thread, we could reuse the layout engines.  This


 113 
 114     private static LayoutEngineFactory instance;
 115 
 116     public static LayoutEngineFactory instance() {
 117         if (instance == null) {
 118             instance = new SunLayoutEngine();
 119         }
 120         return instance;
 121     }
 122 
 123     private SunLayoutEngine() {
 124         // actually a factory, key is null so layout cannot be called on it
 125     }
 126 
 127     public LayoutEngine getEngine(Font2D font, int script, int lang) {
 128         return getEngine(new LayoutEngineKey(font, script, lang));
 129     }
 130 
 131   // !!! don't need this unless we have more than one sun layout engine...
 132     public LayoutEngine getEngine(LayoutEngineKey key) {
 133         // Using ConcurrentHashMap instead of HashMap to resolve 7027300
 134         ConcurrentHashMap cache = (ConcurrentHashMap)cacheref.get();
 135         if (cache == null) {
 136             cache = new ConcurrentHashMap();
 137             cacheref = new SoftReference(cache);
 138         }
 139 
 140         LayoutEngine e = (LayoutEngine)cache.get(key);
 141         if (e == null) {
 142             e = new SunLayoutEngine(key.copy());
 143             cache.put(key, e);
 144         }
 145         return e;
 146     }
 147     private SoftReference cacheref = new SoftReference(null);
 148 
 149     private SunLayoutEngine(LayoutEngineKey key) {
 150         this.key = key;
 151     }
 152 
 153     public void layout(FontStrikeDesc desc, float[] mat, int gmask,
 154                        int baseIndex, TextRecord tr, int typo_flags,
 155                        Point2D.Float pt, GVData data) {
 156         Font2D font = key.font();