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 ConcurrentHashMap cache = (ConcurrentHashMap)cacheref.get(); 133 if (cache == null) { 134 cache = new ConcurrentHashMap(); 135 cacheref = new SoftReference(cache); 136 } 137 138 LayoutEngine e = (LayoutEngine)cache.get(key); 139 if (e == null) { 140 LayoutEngineKey copy = key.copy(); 141 e = new SunLayoutEngine(copy); 142 cache.put(copy, e); 143 } 144 return e; 145 } 146 private SoftReference cacheref = new SoftReference(null); 147 148 private SunLayoutEngine(LayoutEngineKey key) { 149 this.key = key; 150 } 151 152 public void layout(FontStrikeDesc desc, float[] mat, int gmask, 153 int baseIndex, TextRecord tr, int typo_flags, 154 Point2D.Float pt, GVData data) { 155 Font2D font = key.font(); 156 FontStrike strike = font.getStrike(desc); 157 long layoutTables = 0; 158 if (font instanceof TrueTypeFont) { 159 layoutTables = ((TrueTypeFont) font).getLayoutTableCache(); 160 } 161 nativeLayout(font, strike, mat, gmask, baseIndex, 162 tr.text, tr.start, tr.limit, tr.min, tr.max, 163 key.script(), key.lang(), typo_flags, pt, data, 164 font.getUnitsPerEm(), layoutTables); 165 } 166 | 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 ConcurrentHashMap<LayoutEngineKey, LayoutEngine> cache = cacheref.get(); 133 if (cache == null) { 134 cache = new ConcurrentHashMap<>(); 135 cacheref = new SoftReference<>(cache); 136 } 137 138 LayoutEngine e = cache.get(key); 139 if (e == null) { 140 LayoutEngineKey copy = key.copy(); 141 e = new SunLayoutEngine(copy); 142 cache.put(copy, e); 143 } 144 return e; 145 } 146 private SoftReference<ConcurrentHashMap<LayoutEngineKey, LayoutEngine>> cacheref = 147 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(); 157 FontStrike strike = font.getStrike(desc); 158 long layoutTables = 0; 159 if (font instanceof TrueTypeFont) { 160 layoutTables = ((TrueTypeFont) font).getLayoutTableCache(); 161 } 162 nativeLayout(font, strike, mat, gmask, baseIndex, 163 tr.text, tr.start, tr.limit, tr.min, tr.max, 164 key.script(), key.lang(), typo_flags, pt, data, 165 font.getUnitsPerEm(), layoutTables); 166 } 167 |