Browse Source

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>
stable-3.6
Michael Keppler 10 years ago committed by Matthias Sohn
parent
commit
1a72143780
  1. 2
      org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AWTPlotRenderer.java
  2. 8
      org.eclipse.jgit/src/org/eclipse/jgit/revplot/AbstractPlotRenderer.java

2
org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AWTPlotRenderer.java

@ -123,7 +123,7 @@ final class AWTPlotRenderer extends AbstractPlotRenderer<SwingLane, Color>
@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());
}

8
org.eclipse.jgit/src/org/eclipse/jgit/revplot/AbstractPlotRenderer.java

@ -174,7 +174,7 @@ public abstract class AbstractPlotRenderer<TLane extends PlotLane, TColor> {
}
final String msg = commit.getShortMessage();
drawText(msg, textx + dotSize, h / 2);
drawText(msg, textx + dotSize, h);
}
/**
@ -276,9 +276,9 @@ public abstract class AbstractPlotRenderer<TLane extends PlotLane, TColor> {
* 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);

Loading…
Cancel
Save