code: @VisibleForTesting
      protected static Dimension getSize(
              final ScalebarAttributeValues scalebarParams,
              final ScaleBarRenderSettings settings, final Dimension maxLabelSize) {
          final float width;
          final float height;
          if (scalebarParams.getOrientation().isHorizontal()) {
              width = 2 * settings.getPadding()
                      + settings.getIntervalLengthInPixels() * scalebarParams.intervals
                      + settings.getLeftLabelMargin() + settings.getRightLabelMargin();
              height = 2 * settings.getPadding()
                      + settings.getBarSize() + settings.getLabelDistance()
                      + Label.getRotatedHeight(maxLabelSize, scalebarParams.getLabelRotation());
          } else {
              width = 2 * settings.getPadding()
                      + settings.getLabelDistance() + settings.getBarSize()
                      + Label.getRotatedWidth(maxLabelSize, scalebarParams.getLabelRotation());
              height = 2 * settings.getPadding()
                      + settings.getTopLabelMargin()
                      + settings.getIntervalLengthInPixels() * scalebarParams.intervals
                      + settings.getBottomLabelMargin();
          }
          return new Dimension((int) Math.ceil(width), (int) Math.ceil(height));
      }
docs: Get the size of the painting area required to draw the scalebar with labels.
  
  @param scalebarParams Parameters for the scalebar.
  @param settings Parameters for rendering the scalebar.
  @param maxLabelSize The max. size of the labels.