- private void putDoubleWidthCharXY(final DisplayLine line, final int x,
- final int y, final Cell cell) {
-
- int textWidth = getScreen().getTextWidth();
- int textHeight = getScreen().getTextHeight();
- boolean cursorBlinkVisible = true;
-
- if (getScreen() instanceof SwingTerminal) {
- SwingTerminal terminal = (SwingTerminal) getScreen();
- cursorBlinkVisible = terminal.getCursorBlinkVisible();
- } else if (getScreen() instanceof ECMA48Terminal) {
- ECMA48Terminal terminal = (ECMA48Terminal) getScreen();
-
- if (!terminal.hasSixel()) {
- // The backend does not have sixel support, draw this as text
- // and bail out.
- putCharXY(x, y, cell);
- putCharXY(x + 1, y, ' ', cell);
- return;
- }
- cursorBlinkVisible = blinkState;
- } else {
- // We don't know how to dray glyphs to this screen, draw them as
- // text and bail out.
- putCharXY(x, y, cell);
- putCharXY(x + 1, y, ' ', cell);
- return;
- }
-
- if ((textWidth != lastTextWidth) || (textHeight != lastTextHeight)) {
- // Screen size has changed, reset all fonts.
- setupFonts(textHeight);
- lastTextWidth = textWidth;
- lastTextHeight = textHeight;
- }
- assert (doubleFont != null);
-
- BufferedImage image = null;
- if (cell.isBlink() && !cursorBlinkVisible) {
- image = glyphCacheBlink.get(cell);
- } else {
- image = glyphCache.get(cell);
- }
- if (image == null) {
- // Generate glyph and draw it to an image.
- image = new BufferedImage(textWidth * 2, textHeight * 2,
- BufferedImage.TYPE_INT_ARGB);
- Graphics2D gr2 = image.createGraphics();
- gr2.setFont(doubleFont);
-
- // Draw the background rectangle, then the foreground character.
- if (getScreen() instanceof ECMA48Terminal) {
- // BUG: the background color is coming in the same as the
- // foreground color. For now, don't draw it.
- } else {
- gr2.setColor(SwingTerminal.attrToBackgroundColor(cell));
- gr2.fillRect(0, 0, image.getWidth(), image.getHeight());
- }
- if (!cell.isBlink()
- || (cell.isBlink() && cursorBlinkVisible)
- ) {
- gr2.setColor(SwingTerminal.attrToForegroundColor(cell));
- char [] chars = new char[1];
- chars[0] = cell.getChar();
- gr2.drawChars(chars, 0, 1, doubleTextAdjustX,
- (textHeight * 2) - doubleMaxDescent + doubleTextAdjustY);
-
- if (cell.isUnderline() && (line.getDoubleHeight() != 1)) {
- gr2.fillRect(0, textHeight - 2, textWidth, 2);
- }
- }
- gr2.dispose();
-
- // Now save this generated image, using a new key that will not
- // be mutated by invertCell().
- Cell key = new Cell();
- key.setTo(cell);
- if (cell.isBlink() && !cursorBlinkVisible) {
- glyphCacheBlink.put(key, image);
- } else {
- glyphCache.put(key, image);
- }
- }
-
- // Now that we have the double-wide glyph drawn, copy the right
- // pieces of it to the cells.
- Cell left = new Cell();
- Cell right = new Cell();
- left.setTo(cell);
- right.setTo(cell);
- right.setChar(' ');
- BufferedImage leftImage = null;
- BufferedImage rightImage = null;
- switch (line.getDoubleHeight()) {
- case 1:
- // Top half double height
- leftImage = image.getSubimage(0, 0, textWidth, textHeight);
- rightImage = image.getSubimage(textWidth, 0, textWidth, textHeight);
- break;
- case 2:
- // Bottom half double height
- leftImage = image.getSubimage(0, textHeight, textWidth, textHeight);
- rightImage = image.getSubimage(textWidth, textHeight,
- textWidth, textHeight);
- break;
- default:
- // Either single height double-width, or error fallback
- BufferedImage wideImage = new BufferedImage(textWidth * 2,
- textHeight, BufferedImage.TYPE_INT_ARGB);
- Graphics2D grWide = wideImage.createGraphics();
- grWide.drawImage(image, 0, 0, wideImage.getWidth(),
- wideImage.getHeight(), null);
- grWide.dispose();
- leftImage = wideImage.getSubimage(0, 0, textWidth, textHeight);
- rightImage = wideImage.getSubimage(textWidth, 0, textWidth,
- textHeight);
- break;