+
+/**
+ * GlyphMaker presents unified interface to all of its supported fonts to
+ * clients.
+ */
+public class GlyphMaker {
+
+ // ------------------------------------------------------------------------
+ // Constants --------------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ /**
+ * The mono font resource filename (terminus).
+ */
+ private static final String MONO = "terminus-ttf-4.39/TerminusTTF-Bold-4.39.ttf";
+
+ /**
+ * The CJKhk font resource filename.
+ */
+ // private static final String CJKhk = "NotoSansMonoCJKhk-Regular.otf";
+
+ /**
+ * The CJKkr font resource filename.
+ */
+ // private static final String CJKkr = "NotoSansMonoCJKkr-Regular.otf";
+
+ /**
+ * The CJKtc font resource filename.
+ */
+ private static final String CJKtc = "NotoSansMonoCJKtc-Regular.otf";
+
+ // ------------------------------------------------------------------------
+ // Variables --------------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ /**
+ * If true, enable debug messages.
+ */
+ private static boolean DEBUG = false;
+
+ /**
+ * Cache of font bundles by size.
+ */
+ private static HashMap<Integer, GlyphMaker> makers = new HashMap<Integer, GlyphMaker>();
+
+ /**
+ * The instance that has the mono (default) font.
+ */
+ private GlyphMakerFont makerMono;
+
+ /**
+ * The instance that has the CJKhk font.
+ */
+ // private GlyphMakerFont makerCJKhk;
+
+ /**
+ * The instance that has the CJKkr font.
+ */
+ // private GlyphMakerFont makerCJKkr;
+
+ /**
+ * The instance that has the CJKtc font.
+ */
+ private GlyphMakerFont makerCJKtc;
+
+ // ------------------------------------------------------------------------
+ // Constructors -----------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ /**
+ * Create an instance with references to the necessary fonts.
+ *
+ * @param fontSize the size of these fonts in pixels
+ */
+ private GlyphMaker(final int fontSize) {
+ makerMono = new GlyphMakerFont(MONO, fontSize);
+ // makerCJKhk = new GlyphMakerFont(CJKhk, fontSize);
+ // makerCJKkr = new GlyphMakerFont(CJKkr, fontSize);
+ makerCJKtc = new GlyphMakerFont(CJKtc, fontSize);
+ }
+
+ // ------------------------------------------------------------------------
+ // GlyphMaker -------------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ /**
+ * Obtain the GlyphMaker instance for a particular font size.
+ *
+ * @param fontSize the size of these fonts in pixels
+ * @return the instance
+ */
+ public static GlyphMaker getInstance(final int fontSize) {
+ synchronized (GlyphMaker.class) {
+ GlyphMaker maker = makers.get(fontSize);
+ if (maker == null) {
+ maker = new GlyphMaker(fontSize);
+ makers.put(fontSize, maker);
+ }
+ return maker;
+ }
+ }
+
+ /**
+ * Get a glyph image.
+ *
+ * @param cell the character to draw
+ * @param cellWidth the width of the text cell to draw into
+ * @param cellHeight the height of the text cell to draw into
+ * @return the glyph as an image
+ */
+ public BufferedImage getImage(final Cell cell, final int cellWidth,
+ final int cellHeight) {
+
+ return getImage(cell, cellWidth, cellHeight, true);
+ }
+
+ /**
+ * Get a glyph image.
+ *
+ * @param cell the character to draw
+ * @param cellWidth the width of the text cell to draw into
+ * @param cellHeight the height of the text cell to draw into
+ * @param blinkVisible if true, the cell is visible if it is blinking
+ * @return the glyph as an image
+ */
+ public BufferedImage getImage(final Cell cell, final int cellWidth,
+ final int cellHeight, final boolean blinkVisible) {
+
+ char ch = cell.getChar();
+ /*
+ if ((ch >= 0x4e00) && (ch <= 0x9fff)) {
+ return makerCJKhk.getImage(cell, cellWidth, cellHeight, blinkVisible);
+ }
+ if ((ch >= 0x4e00) && (ch <= 0x9fff)) {
+ return makerCJKkr.getImage(cell, cellWidth, cellHeight, blinkVisible);
+ }
+ */
+ if ((ch >= 0x2e80) && (ch <= 0x9fff)) {
+ return makerCJKtc.getImage(cell, cellWidth, cellHeight, blinkVisible);
+ }
+
+ // When all else fails, use the default.
+ return makerMono.getImage(cell, cellWidth, cellHeight, blinkVisible);
+ }
+
+}