#35 CJK font wip
[fanfix.git] / src / jexer / bits / Cell.java
index d4c816f41ee88e202bf9e509af30b47630a97482..5db5f4387bdcfbf00f785834918d16407f488547 100644 (file)
@@ -40,6 +40,26 @@ public final class Cell extends CellAttributes {
     // Constants --------------------------------------------------------------
     // ------------------------------------------------------------------------
 
+    /**
+     * How this cell needs to be displayed if it is part of a larger glyph.
+     */
+    public enum Width {
+        /**
+         * This cell is an entire glyph on its own.
+         */
+        SINGLE,
+
+        /**
+         * This cell is the left half of a wide glyph.
+         */
+        LEFT,
+
+        /**
+         * This cell is the right half of a wide glyph.
+         */
+        RIGHT,
+    }
+
     /**
      * The special "this cell is unset" (null) value.  This is the Unicode
      * "not a character" value.
@@ -55,6 +75,11 @@ public final class Cell extends CellAttributes {
      */
     private char ch;
 
+    /**
+     * The display width of this cell.
+     */
+    private Width width = Width.SINGLE;
+
     /**
      * The image at this cell.
      */
@@ -113,7 +138,6 @@ public final class Cell extends CellAttributes {
     // Cell -------------------------------------------------------------------
     // ------------------------------------------------------------------------
 
-
     /**
      * Set the image data for this cell.
      *
@@ -122,6 +146,7 @@ public final class Cell extends CellAttributes {
     public void setImage(final BufferedImage image) {
         this.image = image;
         imageHashCode = image.hashCode();
+        width = Width.SINGLE;
     }
 
     /**
@@ -223,6 +248,25 @@ public final class Cell extends CellAttributes {
         this.ch = ch;
     }
 
+    /**
+     * Getter for cell width.
+     *
+     * @return Width.SINGLE, Width.LEFT, or Width.RIGHT
+     */
+    public Width getWidth() {
+        return width;
+    }
+
+    /**
+     * Setter for cell width.
+     *
+     * @param ch new cell width, one of Width.SINGLE, Width.LEFT, or
+     * Width.RIGHT
+     */
+    public void setWidth(final Width width) {
+        this.width = width;
+    }
+
     /**
      * Reset this cell to a blank.
      */
@@ -230,6 +274,7 @@ public final class Cell extends CellAttributes {
     public void reset() {
         super.reset();
         ch = ' ';
+        width = Width.SINGLE;
         image = null;
         imageHashCode = 0;
         invertedImage = null;
@@ -244,6 +289,7 @@ public final class Cell extends CellAttributes {
     public void unset() {
         super.reset();
         ch = UNSET_VALUE;
+        width = Width.SINGLE;
         image = null;
         imageHashCode = 0;
         invertedImage = null;
@@ -271,6 +317,7 @@ public final class Cell extends CellAttributes {
             && !isProtect()
             && !isRGB()
             && !isImage()
+            && (width == Width.SINGLE)
             && (ch == ' ')
         ) {
             return true;
@@ -327,7 +374,7 @@ public final class Cell extends CellAttributes {
         }
 
         // Normal case: character and attributes must match.
-        if (ch == that.ch) {
+        if ((ch == that.ch) && (width == that.width)) {
             return super.equals(rhs);
         }
         return false;
@@ -345,6 +392,7 @@ public final class Cell extends CellAttributes {
         int hash = A;
         hash = (B * hash) + super.hashCode();
         hash = (B * hash) + (int)ch;
+        hash = (B * hash) + width.hashCode();
         if (image != null) {
             /*
             hash = (B * hash) + image.hashCode();
@@ -371,11 +419,13 @@ public final class Cell extends CellAttributes {
         this.image = null;
         this.imageHashCode = 0;
         this.backgroundHashCode = 0;
+        this.width = Width.SINGLE;
         super.setTo(thatAttr);
 
         if (rhs instanceof Cell) {
             Cell that = (Cell) rhs;
             this.ch = that.ch;
+            this.width = that.width;
             this.image = that.image;
             this.invertedImage = that.invertedImage;
             this.background = that.background;