From 1a721437808cbf7ae0bcdd1b2e060a69aaf2a16b Mon Sep 17 00:00:00 2001 From: Michael Keppler Date: Fri, 28 Nov 2014 21:21:59 +0100 Subject: [PATCH] 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 Signed-off-by: Matthias Sohn --- .../src/org/eclipse/jgit/awtui/AWTPlotRenderer.java | 2 +- .../org/eclipse/jgit/revplot/AbstractPlotRenderer.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AWTPlotRenderer.java b/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AWTPlotRenderer.java index 25d9f97ce..c1168f17f 100644 --- a/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AWTPlotRenderer.java +++ b/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AWTPlotRenderer.java @@ -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()); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revplot/AbstractPlotRenderer.java b/org.eclipse.jgit/src/org/eclipse/jgit/revplot/AbstractPlotRenderer.java index 6ba0dfed0..f88b819d4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revplot/AbstractPlotRenderer.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revplot/AbstractPlotRenderer.java @@ -174,7 +174,7 @@ protected void paintCommit(final PlotCommit 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);