Search in sources :

Example 1 with LineIterator

use of com.intellij.openapi.editor.ex.LineIterator in project intellij-community by JetBrains.

the class TextPainter method drawText.

private void drawText(Graphics2D g, Rectangle2D clip) {
    float lineHeight = getLineHeight(g);
    HighlighterIterator hIterator = myHighlighter.createIterator(myOffset);
    if (hIterator.atEnd()) {
        myOffset = mySegmentEnd;
        return;
    }
    LineIterator lIterator = myDocument.createLineIterator();
    lIterator.start(myOffset);
    if (lIterator.atEnd()) {
        myOffset = mySegmentEnd;
        return;
    }
    TextAttributes attributes = hIterator.getTextAttributes();
    Color currentColor = attributes.getForegroundColor();
    Color backColor = attributes.getBackgroundColor();
    Color underscoredColor = attributes.getEffectColor();
    Font currentFont = getFont(attributes.getFontType());
    setForegroundColor(g, currentColor);
    setFont(g, currentFont);
    g.translate(clip.getX(), 0);
    Point2D position = new Point2D.Double(0, clip.getY());
    double lineY = position.getY();
    if (myPerformActualDrawing) {
        getMethodSeparator(lIterator.getLineNumber());
    }
    char[] text = myDocument.getCharsSequence().toString().toCharArray();
    while (!hIterator.atEnd() && !lIterator.atEnd()) {
        int hEnd = hIterator.getEnd();
        int lEnd = lIterator.getEnd();
        int lStart = lIterator.getStart();
        if (hEnd >= lEnd) {
            if (!drawString(g, text, lEnd - lIterator.getSeparatorLength(), myOffset == lStart, position, clip, backColor, underscoredColor)) {
                drawLineNumber(g, 0, lineY);
                break;
            }
            drawLineNumber(g, 0, lineY);
            lIterator.advance();
            myLineNumber++;
            position.setLocation(0, position.getY() + lineHeight);
            lineY = position.getY();
            myOffset = lEnd;
            if (myPerformActualDrawing) {
                LineMarkerInfo marker = getMethodSeparator(lIterator.getLineNumber());
                if (marker != null) {
                    Color save = g.getColor();
                    setForegroundColor(g, marker.separatorColor);
                    UIUtil.drawLine(g, 0, (int) lineY, (int) clip.getWidth(), (int) lineY);
                    setForegroundColor(g, save);
                }
            }
            if (position.getY() > clip.getY() + clip.getHeight() - lineHeight) {
                break;
            }
        } else {
            if (hEnd > lEnd - lIterator.getSeparatorLength()) {
                if (!drawString(g, text, lEnd - lIterator.getSeparatorLength(), myOffset == lStart, position, clip, backColor, underscoredColor)) {
                    drawLineNumber(g, 0, lineY);
                    break;
                }
            } else {
                if (!drawString(g, text, hEnd, myOffset == lStart, position, clip, backColor, underscoredColor)) {
                    drawLineNumber(g, 0, lineY);
                    break;
                }
            }
            hIterator.advance();
            attributes = hIterator.getTextAttributes();
            Color color = attributes.getForegroundColor();
            if (color == null) {
                color = Color.black;
            }
            if (color != currentColor) {
                setForegroundColor(g, color);
                currentColor = color;
            }
            backColor = attributes.getBackgroundColor();
            underscoredColor = attributes.getEffectColor();
            Font font = getFont(attributes.getFontType());
            if (font != currentFont) {
                setFont(g, font);
                currentFont = font;
            }
            myOffset = hEnd;
        }
    }
    g.translate(-clip.getX(), 0);
}
Also used : LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) Point2D(java.awt.geom.Point2D) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) LineIterator(com.intellij.openapi.editor.ex.LineIterator) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator)

Aggregations

LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)1 LineIterator (com.intellij.openapi.editor.ex.LineIterator)1 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)1 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)1 Point2D (java.awt.geom.Point2D)1