mapParams, mapParams.getRequestorDPI(), paintArea, bounds);
paintArea.setBounds(0, 0, (int) (paintArea.width * dpiRatio), (int) (paintArea.height * dpiRatio));
final DistanceUnit mapUnit = getUnit(bounds);
// to calculate the scale the requestor DPI is used , because the paint area is already adjusted
final Scale scale = bounds.getScaleDenominator(paintArea, mapParams.getRequestorDPI());
DistanceUnit scaleUnit = scalebarParams.getUnit();
if (scaleUnit == null) {
scaleUnit = mapUnit;
}
// adjust scalebar width and height to the DPI value
final int maxWidthInPixelAdjusted = (int) (scalebarParams.getSize().width * dpiRatio);
final int maxHeightInPixelAdjusted = (int) (scalebarParams.getSize().height * dpiRatio);
final int maxLengthInPixelAdjusted = (scalebarParams.getOrientation().isHorizontal()) ?
maxWidthInPixelAdjusted : maxHeightInPixelAdjusted;
final double maxIntervalLengthInWorldUnits = DistanceUnit.PX.convertTo(maxLengthInPixelAdjusted, scaleUnit)
* scale.getDenominator() / scalebarParams.intervals;
final double niceIntervalLengthInWorldUnits =
getNearestNiceValue(maxIntervalLengthInWorldUnits, scaleUnit, scalebarParams.lockUnits);
final ScaleBarRenderSettings settings = new ScaleBarRenderSettings();
settings.setParams(scalebarParams);