Fix drawing lines with tabs

Fixes #3975
This commit is contained in:
Jakub Valtar
2016-04-17 12:58:38 +02:00
parent 205b73bf89
commit 1cd8bd7b07
2 changed files with 19 additions and 14 deletions
@@ -20,6 +20,7 @@ import javax.swing.JComponent;
import processing.app.Preferences;
import processing.app.syntax.im.CompositionTextPainter;
import processing.app.ui.Editor;
/**
@@ -670,14 +671,18 @@ public class TextAreaPainter extends JComponent implements TabExpander {
// gfx.setFont(defaultFont);
// gfx.setColor(defaultColor);
int x0 = x - textArea.getHorizontalOffset();
y += fm.getHeight();
// doesn't respect fixed width like it should
// x = Utilities.drawTabbedText(currentLine, x, y, gfx, this, 0);
// int w = fm.charWidth(' ');
for (int i = 0; i < currentLine.count; i++) {
gfx.drawChars(currentLine.array, currentLine.offset+i, 1, x, y);
x = currentLine.array[currentLine.offset + i] == '\t' ? (int)nextTabStop(x, i) :
x = currentLine.array[currentLine.offset + i] == '\t' ?
x0 + (int)nextTabStop(x - x0, i) :
x + fm.charWidth(currentLine.array[currentLine.offset+i]);
textArea.offsetToX(line, currentLine.offset + i);
}
// Draw characters via input method.
@@ -745,6 +750,8 @@ public class TextAreaPainter extends JComponent implements TabExpander {
// Font defaultFont = gfx.getFont();
// Color defaultColor = gfx.getColor();
int x0 = x - textArea.getHorizontalOffset();
// for (byte id = tokens.id; id != Token.END; tokens = tokens.next) {
for (;;) {
byte id = tokens.id;
@@ -772,8 +779,9 @@ public class TextAreaPainter extends JComponent implements TabExpander {
// int w = fm.charWidth(' ');
for (int i = 0; i < line.count; i++) {
gfx.drawChars(line.array, line.offset+i, 1, x, y);
x = line.array[line.offset + i] == '\t' ? (int)nextTabStop(x, i) :
x + fm.charWidth(line.array[line.offset+i]);
x = line.array[line.offset + i] == '\t' ?
x0 + (int)nextTabStop(x - x0, i) :
x + fm.charWidth(line.array[line.offset+i]);
}
//x += fm.charsWidth(line.array, line.offset, line.count);
//x += fm.charWidth(' ') * line.count;
@@ -389,20 +389,17 @@ public class JavaTextAreaPainter extends TextAreaPainter
return;
}
// Take care of offsets
int aw = fm.stringWidth(trimRight(badCode)) + textArea.getHorizontalOffset();
// to the left of line + text
// width
int rw = fm.stringWidth(badCode.trim()); // real width
int x1 = fm.stringWidth(goodCode) + (aw - rw);
int y1 = y + fm.getHeight() - 2, x2 = x1 + rw;
int trimmedLength = badCode.trim().length();
int rightTrimmedLength = trimRight(badCode).length();
int leftTrimLength = rightTrimmedLength - trimmedLength;
int x1 = textArea.offsetToX(line, goodCode.length() + leftTrimLength);
int x2 = textArea.offsetToX(line, goodCode.length() + rightTrimmedLength);
int y1 = y + fm.getHeight() - 2;
if (line != problem.getLineNumber()) {
x1 = 0; // on the following lines, wiggle extends to the left border
x1 = Editor.LEFT_GUTTER; // on the following lines, wiggle extends to the left border
}
// Adding offsets for the gutter
x1 += Editor.LEFT_GUTTER;
x2 += Editor.LEFT_GUTTER;
gfx.setColor(errorUnderlineColor);
if (marker.getType() == LineMarker.WARNING) {