X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fbackend%2FLogicalScreen.java;h=e8d2662943abd06d579fe86ff082c7fc482a900d;hb=027de5ae322ef58d3bc74051d3aa20847455361a;hp=513c599145440e8a9682ef5c764b8e5d650e9c29;hpb=03ae544a1639c127ebec9a46635f2ad465713908;p=fanfix.git diff --git a/src/jexer/backend/LogicalScreen.java b/src/jexer/backend/LogicalScreen.java index 513c599..e8d2662 100644 --- a/src/jexer/backend/LogicalScreen.java +++ b/src/jexer/backend/LogicalScreen.java @@ -28,9 +28,13 @@ */ package jexer.backend; +import java.awt.image.BufferedImage; + +import jexer.backend.GlyphMaker; import jexer.bits.Cell; import jexer.bits.CellAttributes; import jexer.bits.GraphicsChars; +import jexer.bits.StringUtils; /** * A logical screen composed of a 2D array of Cells. @@ -113,6 +117,17 @@ public class LogicalScreen implements Screen { */ protected int cursorY; + /** + * The last used height of a character cell in pixels, only used for + * full-width chars. + */ + private int lastTextHeight = -1; + + /** + * The glyph drawer for full-width chars. + */ + private GlyphMaker glyphMaker = null; + // ------------------------------------------------------------------------ // Constructors ----------------------------------------------------------- // ------------------------------------------------------------------------ @@ -379,6 +394,11 @@ public class LogicalScreen implements Screen { return; } + if ((StringUtils.width(ch.getChar()) == 2) && (!ch.isImage())) { + putFullwidthCharXY(x, y, ch); + return; + } + int X = x + offsetX; int Y = y + offsetY; @@ -421,6 +441,11 @@ public class LogicalScreen implements Screen { return; } + if (StringUtils.width(ch) == 2) { + putFullwidthCharXY(x, y, ch, attr); + return; + } + int X = x + offsetX; int Y = y + offsetY; @@ -461,6 +486,11 @@ public class LogicalScreen implements Screen { return; } + if (StringUtils.width(ch) == 2) { + putFullwidthCharXY(x, y, ch); + return; + } + int X = x + offsetX; int Y = y + offsetY; @@ -493,7 +523,7 @@ public class LogicalScreen implements Screen { for (int j = 0; j < str.length(); j++) { char ch = str.charAt(j); putCharXY(i, y, ch, attr); - i++; + i += StringUtils.width(ch); if (i == width) { break; } @@ -514,7 +544,7 @@ public class LogicalScreen implements Screen { for (int j = 0; j < str.length(); j++) { char ch = str.charAt(j); putCharXY(i, y, ch); - i++; + i += StringUtils.width(ch); if (i == width) { break; } @@ -927,4 +957,70 @@ public class LogicalScreen implements Screen { } } + /** + * Render one fullwidth cell. + * + * @param x column coordinate. 0 is the left-most column. + * @param y row coordinate. 0 is the top-most row. + * @param cell the cell to draw + */ + public final void putFullwidthCharXY(final int x, final int y, + final Cell cell) { + + if (lastTextHeight != getTextHeight()) { + glyphMaker = GlyphMaker.getInstance(getTextHeight()); + lastTextHeight = getTextHeight(); + } + 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(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(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); + } + + /** + * Render one fullwidth character with attributes. + * + * @param x column coordinate. 0 is the left-most column. + * @param y row coordinate. 0 is the top-most row. + * @param ch character to draw + * @param attr attributes to use (bold, foreColor, backColor) + */ + public final void putFullwidthCharXY(final int x, final int y, + final char ch, final CellAttributes attr) { + + Cell cell = new Cell(ch, attr); + putFullwidthCharXY(x, y, cell); + } + + /** + * Render one fullwidth character with attributes. + * + * @param x column coordinate. 0 is the left-most column. + * @param y row coordinate. 0 is the top-most row. + * @param ch character to draw + */ + public final void putFullwidthCharXY(final int x, final int y, + final char ch) { + + Cell cell = new Cell(ch); + cell.setAttr(getAttrXY(x, y)); + putFullwidthCharXY(x, y, cell); + } + }