import java.awt.geom.*; static void drawTextAlongLine(Graphics2D g, S text, int x1, int y1, int x2, int y2, int shift) { if (y2 == y1 && x2 == x1) ++x2; new AffineTransform tx; double angle = Math.atan2(y2-y1, x2-x1); bool above = abs(angle) <= pi()/2; if (!above) angle -= pi(); tx.translate((x1+x2)/2.0, (y1+y2)/2.0); tx.rotate(angle); AffineTransform old = g.getTransform(); g.setTransform(tx); FontMetrics fm = g.getFontMetrics(); g.drawString(text, -fm.stringWidth(text)/2.0f, shift+fm.getLeading()+fm.getMaxAscent()); g.setTransform(old); }