int bgcolor = colorScheme.getDefaultBackground().getRGB();
char ch;
LineInfo startLine;
float topWeight;
float bottomWeight;
Lexer lexer = hl.getHighlightingLexer();
IElementType tokenType;
Graphics2D g = (Graphics2D)img.getGraphics();
g.setComposite(CLEAR);
g.fillRect(0, 0, img.getWidth(), img.getHeight());
lexer.start(text);
tokenType = lexer.getTokenType();
int x, y;
while(tokenType != null) {
int start = lexer.getTokenStart();
startLine = getLine(start);
y = startLine.number * config.pixelsPerLine;
color = getColorForElementType(tokenType, hl, colorScheme);
// Pre-loop to count whitespace from start of line.
x = 0;
for (int i = startLine.begin; i < start; i++) {
// Dont count lines inside of folded regions.
if (isFolded(i, folding)) {
continue;
}
if(text.charAt(i) == '\t') {
x += 4;
} else {
x += 1;
}
// Abort if this line is getting to long...
if(x > config.width) break;
}
// Render whole token, make sure multi lines are handled gracefully.
for(int i = start; i < lexer.getTokenEnd(); i++) {
// Don't render folds.
if (isFolded(i, folding)) {
continue;
}
ch = text.charAt(i);
if(ch == '\n') {
x = 0;
y += config.pixelsPerLine;
} else if(ch == '\t') {
x += 4;
} else {
x += 1;
}
topWeight = CharacterWeight.getTopWeight(text.charAt(i));
bottomWeight = CharacterWeight.getBottomWeight(text.charAt(i));
// No point rendering non visible characters.
if(topWeight == 0) continue;
if(0 <= x && x < img.getWidth() && 0 <= y && y + config.pixelsPerLine < img.getHeight()) {
switch(config.pixelsPerLine) {
case 1:
// Cant show whitespace between lines any more. This looks rather ugly...
setPixel(x, y + 1, color, (float) ((topWeight + bottomWeight) / 2.0));
break;
case 2:
// Two lines we make the top line a little lighter to give the illusion of whitespace between lines.
setPixel(x, y, color, topWeight * 0.5f);
setPixel(x, y + 1, color, bottomWeight);
break;
case 3:
// Three lines we make the top nearly empty, and fade the bottom a little too
setPixel(x, y, color, topWeight * 0.3f);
setPixel(x, y + 1, color, (float) ((topWeight + bottomWeight) / 2.0));
setPixel(x, y + 2, color, bottomWeight * 0.7f);
break;
case 4:
// Empty top line, Nice blend for everything else
setPixel(x, y + 1, color, topWeight);
setPixel(x, y + 2, color, (float) ((topWeight + bottomWeight) / 2.0));
setPixel(x, y + 3, color, bottomWeight);
}
}
}
lexer.advance();
tokenType = lexer.getTokenType();
}
}