Пример #1
0
 protected Font getFontToDisplay(char c, TextStyle style) {
   boolean bold = style.hasOption(TextStyle.Option.BOLD);
   boolean italic = style.hasOption(TextStyle.Option.ITALIC);
   // workaround to fix Swing bad rendering of bold special chars on Linux
   if (bold && mySettingsProvider.DECCompatibilityMode() && CharacterSets.isDecBoxChar(c)) {
     return myNormalFont;
   }
   return bold ? (italic ? myBoldItalicFont : myBoldFont) : (italic ? myItalicFont : myNormalFont);
 }
Пример #2
0
  /**
   * Draw every char in separate terminal cell to guaranty equal width for different lines.
   * Nevertheless to improve kerning we draw word characters as one block for monospaced fonts.
   */
  private void drawChars(int x, int y, CharBuffer buf, TextStyle style, Graphics2D gfx) {
    final int blockLen = 1;
    int offset = 0;
    int drawCharsOffset = 0;

    // workaround to fix Swing bad rendering of bold special chars on Linux
    // TODO required for italic?
    CharBuffer renderingBuffer;
    if (mySettingsProvider.DECCompatibilityMode() && style.hasOption(TextStyle.Option.BOLD)) {
      renderingBuffer = CharUtils.heavyDecCompatibleBuffer(buf);
    } else {
      renderingBuffer = buf;
    }

    while (offset + blockLen <= buf.length()) {
      if (renderingBuffer.getBuf()[buf.getStart() + offset] == CharUtils.DWC) {
        offset += blockLen;
        drawCharsOffset += blockLen;
        continue; // dont' draw second part(fake one) of double width character
      }

      Font font = getFontToDisplay(buf.charAt(offset + blockLen - 1), style);
      //      while (myMonospaced && (offset + blockLen < buf.getLength()) &&
      // isWordCharacter(buf.charAt(offset + blockLen - 1))
      //              && (font == getFontToDisplay(buf.charAt(offset + blockLen - 1), style))) {
      //        blockLen++;
      //      }
      gfx.setFont(font);

      int descent = gfx.getFontMetrics(font).getDescent();
      int baseLine = (y + 1) * myCharSize.height - descent;
      int xCoord = (x + drawCharsOffset) * myCharSize.width;
      int textLength =
          CharUtils.getTextLengthDoubleWidthAware(
              buf.getBuf(),
              buf.getStart() + offset,
              blockLen,
              mySettingsProvider.ambiguousCharsAreDoubleWidth());

      int yCoord = y * myCharSize.height;

      gfx.setClip(
          xCoord,
          yCoord,
          Math.min(textLength * myCharSize.width, getWidth() - xCoord),
          Math.min(myCharSize.height, getHeight() - yCoord));

      gfx.setColor(getPalette().getColor(myStyleState.getForeground(style.getForegroundForRun())));

      gfx.drawChars(renderingBuffer.getBuf(), buf.getStart() + offset, blockLen, xCoord, baseLine);

      drawCharsOffset += blockLen;
      offset += blockLen;
    }
    gfx.setClip(null);
  }
Пример #3
0
 private TextStyle getInversedStyle(TextStyle style) {
   TextStyle selectionStyle;
   selectionStyle = style.clone();
   selectionStyle.setOption(Option.INVERSE, !selectionStyle.hasOption(Option.INVERSE));
   if (selectionStyle.getForeground() == null) {
     selectionStyle.setForeground(myStyleState.getForeground());
   }
   if (selectionStyle.getBackground() == null) {
     selectionStyle.setBackground(myStyleState.getBackground());
   }
   return selectionStyle;
 }
Пример #4
0
 private TextStyle getSelectionStyle(TextStyle style) {
   TextStyle selectionStyle = style.clone();
   if (mySettingsProvider.useInverseSelectionColor()) {
     selectionStyle = getInversedStyle(style);
   } else {
     TextStyle mySelectionStyle = mySettingsProvider.getSelectionColor();
     selectionStyle.setBackground(mySelectionStyle.getBackground());
     selectionStyle.setForeground(mySelectionStyle.getForeground());
   }
   return selectionStyle;
 }
Пример #5
0
  private void drawCharacters(int x, int y, TextStyle style, CharBuffer buf, Graphics2D gfx) {
    int xCoord = x * myCharSize.width;
    int yCoord = y * myCharSize.height;

    if (xCoord < 0 || xCoord > getWidth() || yCoord < 0 || yCoord > getHeight()) {
      return;
    }

    gfx.setColor(getPalette().getColor(myStyleState.getBackground(style.getBackgroundForRun())));
    int textLength =
        CharUtils.getTextLengthDoubleWidthAware(
            buf.getBuf(),
            buf.getStart(),
            buf.length(),
            mySettingsProvider.ambiguousCharsAreDoubleWidth());

    gfx.fillRect(
        xCoord,
        yCoord,
        Math.min(textLength * myCharSize.width, getWidth() - xCoord),
        Math.min(myCharSize.height, getHeight() - yCoord));

    if (buf.isNul()) {
      return; // nothing more to do
    }

    drawChars(x, y, buf, style, gfx);

    gfx.setColor(getPalette().getColor(myStyleState.getForeground(style.getForegroundForRun())));

    int baseLine = (y + 1) * myCharSize.height - myDescent;

    if (style.hasOption(TextStyle.Option.UNDERLINED)) {
      gfx.drawLine(xCoord, baseLine + 1, (x + textLength) * myCharSize.width, baseLine + 1);
    }
  }
Пример #6
0
    public void drawCursor(char c, Graphics2D gfx, TextStyle style) {
      TerminalCursorState state = computeCursorState();

      // hidden: do nothing
      if (state == TerminalCursorState.HIDDEN) {
        return;
      } else {
        final int x = getCoordX();
        final int y = getCoordY();
        if (y >= 0 && y < myTermSize.height) {
          if (state == TerminalCursorState.SHOWING) {
            TextStyle styleToDraw = getInversedStyle(style);
            drawCharacters(x, y, styleToDraw, new CharBuffer(c, 1), gfx);
          } else if (state == TerminalCursorState.NO_FOCUS) {
            int xCoord = x * myCharSize.width;
            int yCoord = y * myCharSize.height;
            gfx.setColor(
                getPalette().getColor(myStyleState.getForeground(style.getForegroundForRun())));
            gfx.drawRect(xCoord, yCoord, myCharSize.width - 1, myCharSize.height - 1);
          }
        }
      }
    }