]> source.dussan.org Git - jgit.git/commitdiff
Use baseline instead of centerline in PlotRenderer 03/37303/2
authorMichael Keppler <michael.keppler@gmx.de>
Fri, 28 Nov 2014 20:21:59 +0000 (21:21 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Sat, 29 Nov 2014 00:30:13 +0000 (01:30 +0100)
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>
org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AWTPlotRenderer.java
org.eclipse.jgit/src/org/eclipse/jgit/revplot/AbstractPlotRenderer.java

index 25d9f97ced120f8b226d2a1ba8c88737326389ce..c1168f17f3a2cf4d763dcdbaf8b757f320915814 100644 (file)
@@ -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());
        }
index 6ba0dfed03ff22217cd65077a6bcffdd7ac8fbb1..f88b819d4d4ac947adb818dc8057a7e4d510ed3f 100644 (file)
@@ -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);