Add 'src/jexer/' from commit 'cf01c92f5809a0732409e280fb0f32f27393618d'
[nikiroo-utils.git] / src / jexer / backend / LogicalScreen.java
index 3149e68c282b3168bf5ed6cb78e29762bd06ee6e..4e4aecca7a349eb999b83a9ef4bc71c229ff650a 100644 (file)
@@ -369,7 +369,7 @@ public class LogicalScreen implements Screen {
      * @param ch character to draw
      * @param attr attributes to use (bold, foreColor, backColor)
      */
-    public final void putAll(final char ch, final CellAttributes attr) {
+    public final void putAll(final int ch, final CellAttributes attr) {
 
         for (int x = 0; x < width; x++) {
             for (int y = 0; y < height; y++) {
@@ -430,7 +430,7 @@ public class LogicalScreen implements Screen {
      * @param ch character to draw
      * @param attr attributes to use (bold, foreColor, backColor)
      */
-    public final void putCharXY(final int x, final int y, final char ch,
+    public final void putCharXY(final int x, final int y, final int ch,
         final CellAttributes attr) {
 
         if ((x < clipLeft)
@@ -476,8 +476,7 @@ public class LogicalScreen implements Screen {
      * @param y row coordinate.  0 is the top-most row.
      * @param ch character to draw
      */
-    public final void putCharXY(final int x, final int y, final char ch) {
-
+    public final void putCharXY(final int x, final int y, final int ch) {
         if ((x < clipLeft)
             || (x >= clipRight)
             || (y < clipTop)
@@ -520,10 +519,11 @@ public class LogicalScreen implements Screen {
         final CellAttributes attr) {
 
         int i = x;
-        for (int j = 0; j < str.length(); j++) {
-            char ch = str.charAt(j);
+        for (int j = 0; j < str.length();) {
+            int ch = str.codePointAt(j);
+            j += Character.charCount(ch);
             putCharXY(i, y, ch, attr);
-            i++;
+            i += StringUtils.width(ch);
             if (i == width) {
                 break;
             }
@@ -541,10 +541,11 @@ public class LogicalScreen implements Screen {
     public final void putStringXY(final int x, final int y, final String str) {
 
         int i = x;
-        for (int j = 0; j < str.length(); j++) {
-            char ch = str.charAt(j);
+        for (int j = 0; j < str.length();) {
+            int ch = str.codePointAt(j);
+            j += Character.charCount(ch);
             putCharXY(i, y, ch);
-            i++;
+            i += StringUtils.width(ch);
             if (i == width) {
                 break;
             }
@@ -561,7 +562,7 @@ public class LogicalScreen implements Screen {
      * @param attr attributes to use (bold, foreColor, backColor)
      */
     public final void vLineXY(final int x, final int y, final int n,
-        final char ch, final CellAttributes attr) {
+        final int ch, final CellAttributes attr) {
 
         for (int i = y; i < y + n; i++) {
             putCharXY(x, i, ch, attr);
@@ -578,7 +579,7 @@ public class LogicalScreen implements Screen {
      * @param attr attributes to use (bold, foreColor, backColor)
      */
     public final void hLineXY(final int x, final int y, final int n,
-        final char ch, final CellAttributes attr) {
+        final int ch, final CellAttributes attr) {
 
         for (int i = x; i < x + n; i++) {
             putCharXY(i, y, ch, attr);
@@ -802,11 +803,30 @@ public class LogicalScreen implements Screen {
         clipBottom = height - offsetY;
 
         for (int i = 0; i < boxHeight; i++) {
-            putAttrXY(boxLeft + boxWidth, boxTop + 1 + i, shadowAttr);
-            putAttrXY(boxLeft + boxWidth + 1, boxTop + 1 + i, shadowAttr);
+            Cell cell = getCharXY(offsetX + boxLeft + boxWidth,
+                offsetY + boxTop + 1 + i);
+            if (cell.getWidth() == Cell.Width.SINGLE) {
+                putAttrXY(boxLeft + boxWidth, boxTop + 1 + i, shadowAttr);
+            } else {
+                putCharXY(boxLeft + boxWidth, boxTop + 1 + i, ' ', shadowAttr);
+            }
+            cell = getCharXY(offsetX + boxLeft + boxWidth + 1,
+                offsetY + boxTop + 1 + i);
+            if (cell.getWidth() == Cell.Width.SINGLE) {
+                putAttrXY(boxLeft + boxWidth + 1, boxTop + 1 + i, shadowAttr);
+            } else {
+                putCharXY(boxLeft + boxWidth + 1, boxTop + 1 + i, ' ',
+                    shadowAttr);
+            }
         }
         for (int i = 0; i < boxWidth; i++) {
-            putAttrXY(boxLeft + 2 + i, boxTop + boxHeight, shadowAttr);
+            Cell cell = getCharXY(offsetX + boxLeft + 2 + i,
+                offsetY + boxTop + boxHeight);
+            if (cell.getWidth() == Cell.Width.SINGLE) {
+                putAttrXY(boxLeft + 2 + i, boxTop + boxHeight, shadowAttr);
+            } else {
+                putCharXY(boxLeft + 2 + i, boxTop + boxHeight, ' ', shadowAttr);
+            }
         }
         clipRight = oldClipRight;
         clipBottom = oldClipBottom;
@@ -967,31 +987,28 @@ public class LogicalScreen implements Screen {
     public final void putFullwidthCharXY(final int x, final int y,
         final Cell cell) {
 
-        if (lastTextHeight != getTextHeight()) {
-            glyphMaker = GlyphMaker.getInstance(getTextHeight());
-            lastTextHeight = getTextHeight();
+        int cellWidth = getTextWidth();
+        int cellHeight = getTextHeight();
+
+        if (lastTextHeight != cellHeight) {
+            glyphMaker = GlyphMaker.getInstance(cellHeight);
+            lastTextHeight = cellHeight;
         }
-        BufferedImage image = glyphMaker.getImage(cell, getTextWidth() * 2,
-            getTextHeight());
-        BufferedImage leftImage = image.getSubimage(0, 0, getTextWidth(),
-            getTextHeight());
-        BufferedImage rightImage = image.getSubimage(getTextWidth(), 0,
-            getTextWidth(), getTextHeight());
-
-        Cell left = new Cell();
-        left.setTo(cell);
+        BufferedImage image = glyphMaker.getImage(cell, cellWidth * 2,
+            cellHeight);
+        BufferedImage leftImage = image.getSubimage(0, 0, cellWidth,
+            cellHeight);
+        BufferedImage rightImage = image.getSubimage(cellWidth, 0, cellWidth,
+            cellHeight);
+
+        Cell left = new Cell(cell);
         left.setImage(leftImage);
         left.setWidth(Cell.Width.LEFT);
-        // Blank out the char itself, so that shadows do not leave artifacts.
-        left.setChar(' ');
         putCharXY(x, y, left);
 
-        Cell right = new Cell();
-        right.setTo(cell);
+        Cell right = new Cell(cell);
         right.setImage(rightImage);
         right.setWidth(Cell.Width.RIGHT);
-        // Blank out the char itself, so that shadows do not leave artifacts.
-        right.setChar(' ');
         putCharXY(x + 1, y, right);
     }
 
@@ -1004,10 +1021,9 @@ public class LogicalScreen implements Screen {
      * @param attr attributes to use (bold, foreColor, backColor)
      */
     public final void putFullwidthCharXY(final int x, final int y,
-        final char ch, final CellAttributes attr) {
+        final int ch, final CellAttributes attr) {
 
-        Cell cell = new Cell(ch);
-        cell.setAttr(attr);
+        Cell cell = new Cell(ch, attr);
         putFullwidthCharXY(x, y, cell);
     }
 
@@ -1019,7 +1035,7 @@ public class LogicalScreen implements Screen {
      * @param ch character to draw
      */
     public final void putFullwidthCharXY(final int x, final int y,
-        final char ch) {
+        final int ch) {
 
         Cell cell = new Cell(ch);
         cell.setAttr(getAttrXY(x, y));