Use baseline instead of centerline in PlotRenderer

If the text extent height of a to be rendered plot line is odd, then the
SWTPlotRenderer cannot calculate the correct Y position for drawing the
label and draws the label with a 1 pixel offset. SWT text drawing uses
the baseline as Y coordinate. Due to the given centerline API in the
AbstractPlotRenderer the overall calculation of the baseline for SWT is
effectively (height / 2) * 2, thereby rounding all odd heights downward
to the next even number.

This change pushes the division by 2 from the caller into the
implementations of drawText. A corresponding change will be pushed in
the egit repository.

Bug: 450813
Change-Id: I66f4e71873bb8e6f936fde573bbe4c35fe23a022
Signed-off-by: Michael Keppler <michael.keppler@gmx.de>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Michael Keppler 2014-11-28 21:21:59 +01:00 committed by Matthias Sohn
parent 147e24a7b2
commit 1a72143780
2 changed files with 5 additions and 5 deletions

View File

@ -123,7 +123,7 @@ protected void drawBoundaryDot(final int x, final int y, final int w,
@Override
protected void drawText(final String msg, final int x, final int y) {
final int texth = g.getFontMetrics().getHeight();
final int y0 = y - texth/2 + (cell.getHeight() - texth)/2;
final int y0 = (y - texth) / 2 + (cell.getHeight() - texth) / 2;
g.setColor(cell.getForeground());
g.drawString(msg, x, y0 + texth - g.getFontMetrics().getDescent());
}

View File

@ -174,7 +174,7 @@ protected void paintCommit(final PlotCommit<TLane> commit, final int h) {
}
final String msg = commit.getShortMessage();
drawText(msg, textx + dotSize, h / 2);
drawText(msg, textx + dotSize, h);
}
/**
@ -276,9 +276,9 @@ protected abstract void drawLine(TColor color, int x1, int y1, int x2,
* first pixel from the left that the text can be drawn at.
* Character data must not appear before this position.
* @param y
* pixel coordinate of the centerline of the text.
* Implementations must adjust this coordinate to account for the
* way their implementation handles font rendering.
* pixel coordinate of the baseline of the text. Implementations
* must adjust this coordinate to account for the way their
* implementation handles font rendering.
*/
protected abstract void drawText(String msg, int x, int y);