/** * Show the cached object. * * @param info the font info * @param character the encoded character */ public CharWidth showCachedCharacter( FontInfo info, AffineTransform ctm, Point2D curpt, String character) { this.character = character; CacheEntry key = new CacheEntry(info, character); CacheEntry val = (CacheEntry) cache.get(key); if (val == null) return null; ctm.translate(curpt.getX(), curpt.getY()); AffineTransform ftm = info.getFontMatrix(); ctm.concatenate(ftm); show(val.getObject(), ctm); return val.getCharWidth().transform(ftm); }
/** * Flush the cache device. * * @param info the font info * @param ctm the current transformation matrix */ public void flush(FontInfo info, AffineTransform ctm) { try { if (character != null) { displayList.trimToSize(); CharacterShape charShape = (CharacterShape) displayList; charShape.setCharCode(character); charShape.setCharWidth(charWidth); charShape.normalize(ctm); CacheEntry key = new CacheEntry(info, character, charWidth, charShape); cache.put(key, key); // TODO: redundant, we should use set instead of map show(charShape, ctm); } } catch (NoninvertibleTransformException ex) { System.err.println("warning: " + ex); } finally { character = null; charWidth = null; bounds = null; } }
/** @return the current cache size */ public int getMaxCacheSize() { return cache.getMaximumSize(); }
/** @return the current cache size */ public int getCacheSize() { return cache.getSize(); }
/** Clear the cache. */ public void clearCache() { cache.clear(); }
/** @return the current cache size */ public void setMaxCacheSize(int size) { cache.setMaximumSize(size); }