public static @Nullable AffineTransform alignTxToInt(@NotNull Graphics2D g, @Nullable Point2D offset, boolean alignX, boolean alignY, RoundingMode rm) {
    try {
      AffineTransform tx = g.getTransform();
      if (isFractionalScale(tx) && (tx.getType() & AffineTransform.TYPE_MASK_ROTATION) == 0) {
        double scaleX = tx.getScaleX();
        double scaleY = tx.getScaleY();
        AffineTransform alignedTx = new AffineTransform();
        double trX = tx.getTranslateX();
        double trY = tx.getTranslateY();
        if (alignX) {
          double offX = trX + (offset != null ? offset.getX() * scaleX : 0);
          trX += rm.round(offX) - offX;
        }
        if (alignY) {
          double offY = trY + (offset != null ? offset.getY() * scaleY : 0);
          trY += rm.round(offY) - offY;
        }
        alignedTx.translate(trX, trY);
        alignedTx.scale(scaleX, scaleY);
        assert tx.getShearX() == 0 && tx.getShearY() == 0; // the shear is ignored
        g.setTransform(alignedTx);
        return tx;
      }
    }
    catch (Exception e) {
      Logger.getInstance(PaintUtil.class).error(e);
    }
    return null;
  }
public static @Nullable AffineTransform alignTxToInt(@NotNull Graphics2D g, @Nullable Point2D offset, boolean alignX, boolean alignY, RoundingMode rm)