Get the maximum width and height of the labels.

@param settings Parameters for rendering the scalebar.
434009
@VisibleForTesting
    protected static Dimension getMaxLabelSize(final ScaleBarRenderSettings settings) {
        float maxLabelHeight = 0.0f;
        float maxLabelWidth = 0.0f;
        for (final Label label: settings.getLabels()) {
            maxLabelHeight = Math.max(maxLabelHeight, label.getHeight());
            maxLabelWidth = Math.max(maxLabelWidth, label.getWidth());
        }
        return new Dimension((int) Math.ceil(maxLabelWidth), (int) Math.ceil(maxLabelHeight));
    }
974832
function(){
			// First we need the width of the yLabels, assuming the xLabels aren't rotated

			// To do that we need the base line at the top and base of the chart, assuming there is no x label rotation
			this.startPoint = (this.display) ? this.fontSize : 0;
			this.endPoint = (this.display) ? this.height - (this.fontSize * 1.5) - 5 : this.height; // -5 to pad labels

			// Apply padding settings to the start and end point.
			this.startPoint += this.padding;
			this.endPoint -= this.padding;

			// Cache the starting height, so can determine if we need to recalculate the scale yAxis
			var cachedHeight = this.endPoint - this.startPoint,
				cachedYLabelWidth;

			// Build the current yLabels so we have an idea of what size they'll be to start
			/*
			 *	This sets what is returned from calculateScaleRange as static properties of this class:
			 *
				this.steps;
				this.stepValue;
				this.min;
				this.max;
			 *
			 */
			this.calculateYRange(cachedHeight);

			// With these properties set we can now build the array of yLabels
			// and also the width of the largest yLabel
			this.buildYLabels();

			this.calculateXLabelRotation();

			while((cachedHeight > this.endPoint - this.startPoint)){
				cachedHeight = this.endPoint - this.startPoint;
				cachedYLabelWidth = this.yLabelWidth;

				this.calculateYRange(cachedHeight);
				this.buildYLabels();

				// Only go through the xLabel loop again if the yLabel width has changed
				if (cachedYLabelWidth < this.yLabelWidth){
					this.calculateXLabelRotation();
				}
			}

		}
1287663
function getBoxWidth(labelOpts, fontSize) {
	return labelOpts.usePointStyle && labelOpts.boxWidth > fontSize ?
		fontSize :
		labelOpts.boxWidth;
}
17961
private static int getScaleFactor(ImageMetadata metadata, int maxPixels) {
        int scale = 1;
        int scaledW = metadata.getW();
        int scaledH = metadata.getH();
        while (scaledW * scaledH > maxPixels) {
            scale *= 2;
            scaledH /= 2;
            scaledW /= 2;
        }
        return scale;
    }
1068735
public void setMapSize(int mapWidth, int mapHeight) {
		super.setMapSize(mapWidth, mapHeight);
		if (null == unitType) {
			throw new IllegalStateException("Please initialize scale bar before using");
		}
		backGround.getBounds().setX(getUpperLeftCorner().getX());
		backGround.getBounds().setY(getUpperLeftCorner().getY());
		bottomLine.getBounds().setX(getUpperLeftCorner().getX() + HORIZONTAL_PADDING);
		bottomLine.getBounds().setY(getUpperLeftCorner().getY() + VERTICAL_PADDING + MARKER_HEIGHT);
		leftMarker.getBounds().setX(getUpperLeftCorner().getX() + HORIZONTAL_PADDING);
		leftMarker.getBounds().setY(getUpperLeftCorner().getY() + VERTICAL_PADDING);
		rightMarker.getBounds().setY(getUpperLeftCorner().getY() + VERTICAL_PADDING);
		distance.setPosition(new Coordinate(getUpperLeftCorner().getX() + HORIZONTAL_PADDING + 6,
				getUpperLeftCorner().getY() + VERTICAL_PADDING));
	}
22105
private void resize() {
        width  = getWidth() - getInsets().getLeft() - getInsets().getRight();
        height = getHeight() - getInsets().getTop() - getInsets().getBottom();
        size   = parentWidth < parentHeight ? parentWidth : parentHeight;

        if (ASPECT_RATIO * width > height) {
            width = 1 / (ASPECT_RATIO / height);
        } else if (1 / (ASPECT_RATIO / height) > width) {
            height = ASPECT_RATIO * width;
        }

        if (width > 0 && height > 0) {
            stepSize = (parentWidth - size * 0.15) / maxValue;

            pane.setMaxSize(parentWidth, height * 0.12);
            pane.setPrefSize(parentWidth, height * 0.12);

            nameText.setFont(Fonts.latoRegular(size * 0.06));
            nameText.setX(size * 0.05);
            nameText.setY(0);

            valueText.setFont(Fonts.latoRegular(size * 0.06));
            valueText.setX((parentWidth - size * 0.05) - valueText.getLayoutBounds().getWidth());
            valueText.setY(0);

            barBackground.setX(size * 0.075);
            barBackground.setY(size * 0.10333333);
            barBackground.setWidth(parentWidth - size * 0.15);
            barBackground.setHeight(size * 0.01);

            bar.setX(size * 0.075);
            bar.setY(size * 0.09666667);
            bar.setWidth(clamp(0, (parentWidth - size * 0.15), getValue() * stepSize));
            bar.setHeight(size * 0.02333333);

            redraw();
        }
    }
1092876
private static float getAutofitTextSize(CharSequence text, TextPaint paint,
            float targetWidth, int maxLines, float low, float high, float precision,
            DisplayMetrics displayMetrics) {
        float mid = (low + high) / 2.0f;
        int lineCount = 1;
        StaticLayout layout = null;

        paint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, mid,
                displayMetrics));

        if (maxLines != 1) {
            layout = new StaticLayout(text, paint, (int)targetWidth, Layout.Alignment.ALIGN_NORMAL,
                    1.0f, 0.0f, true);
            lineCount = layout.getLineCount();
        }

        if (SPEW) Log.d(TAG, "low=" + low + " high=" + high + " mid=" + mid +
                " target=" + targetWidth + " maxLines=" + maxLines + " lineCount=" + lineCount);

        if (lineCount > maxLines) {
            // For the case that `text` has more newline characters than `maxLines`.
            if ((high - low) < precision) {
                return low;
            }
            return getAutofitTextSize(text, paint, targetWidth, maxLines, low, mid, precision,
                    displayMetrics);
        }
        else if (lineCount < maxLines) {
            return getAutofitTextSize(text, paint, targetWidth, maxLines, mid, high, precision,
                    displayMetrics);
        }
        else {
            float maxLineWidth = 0;
            if (maxLines == 1) {
                maxLineWidth = paint.measureText(text, 0, text.length());
            } else {
                for (int i = 0; i < lineCount; i++) {
                    if (layout.getLineWidth(i) > maxLineWidth) {
                        maxLineWidth = layout.getLineWidth(i);
                    }
                }
            }

            if ((high - low) < precision) {
                return low;
            } else if (maxLineWidth > targetWidth) {
                return getAutofitTextSize(text, paint, targetWidth, maxLines, low, mid, precision,
                        displayMetrics);
            } else if (maxLineWidth < targetWidth) {
                return getAutofitTextSize(text, paint, targetWidth, maxLines, mid, high, precision,
                        displayMetrics);
            } else {
                return mid;
            }
        }
    }
962301
public static double getMaxLength(double[] widths, double[] heights) {
		double maxWidth = getMaxLength(widths);
		double maxHeight = getMaxLength(heights);
		double maxLength = Math.min(maxWidth, maxHeight);
		return maxLength;
	}
337148
def max_layout_dimensions(dimensions):
    
    min_ = max([d.min for d in dimensions if d.min is not None])
    max_ = max([d.max for d in dimensions if d.max is not None])
    preferred = max([d.preferred for d in dimensions])

    return LayoutDimension(min=min_, max=max_, preferred=preferred)
30300
public synchronized void scaleTextSize(float scaleFactor, byte zoomLevel) {
        if (!textScales.containsKey(zoomLevel) || scaleFactor != textScales.get(zoomLevel)) {
            for (int i = 0, n = this.rulesList.size(); i < n; ++i) {
                Rule rule = this.rulesList.get(i);
                if (rule.zoomMin <= zoomLevel && rule.zoomMax >= zoomLevel) {
                    rule.scaleTextSize(scaleFactor * this.baseTextSize, zoomLevel);
                }
            }
            textScales.put(zoomLevel, scaleFactor);
        }
    }
163576
@Override protected void resizeDynamicText() {
        double maxWidth = unitText.isVisible() ? size * 0.725 : size * 0.9;
        double fontSize = size * 0.24;
        valueText.setFont(Fonts.latoRegular(fontSize));
        if (valueText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(valueText, maxWidth, fontSize); }

        percentageUnitText.relocate(percentageText.getLayoutBounds().getMaxX() + size * 0.075, height - size * 0.25);
    }
816982
@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));
    }
1153219
private List<Integer> getColumnMaxWidths() {
    int numCols = data.get(0).size();
    int[] widths = new int[numCols];

    if (this.labels != null) {
      for (int i=0; i<numCols; i++) {
        widths[i] = this.labels.get(i).length();
      }
    }

    for (List<String> row : this.data) {
      for (int i=0;i<row.size(); i++) {
        if (row.get(i) == null) {
          widths[i] = Math.max(widths[i], 4);
        } else {
          widths[i] = Math.max(widths[i], row.get(i).length());
        }
      }
    }

    return Ints.asList(widths);
  }
135823
private void measureComponents() {
    // TODO This would be a good place to check that all settings have sensible values or throw
    // illegal state exception.

    // TODO Put this somewhere so it only gets created once.
    BufferedImage chartImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
    Graphics2D tempGraphics = chartImage.createGraphics();

    // Calculate title dimensions.
    if (title != null) {
      tempGraphics.setFont(titleFont);
      FontMetrics metrics = tempGraphics.getFontMetrics();
      titleSize = new Dimension(metrics.stringWidth(title), metrics.getHeight());
      titleAscent = metrics.getAscent();
    }
    else {
      titleSize = new Dimension(0, 0);
    }

    // Calculate x-axis label dimensions.
    if (xAxisLabel != null) {
      tempGraphics.setFont(axisLabelsFont);
      FontMetrics metrics = tempGraphics.getFontMetrics();
      xAxisLabelSize = new Dimension(metrics.stringWidth(xAxisLabel), metrics.getHeight());
      xAxisLabelDescent = metrics.getDescent();
    }
    else {
      xAxisLabelSize = new Dimension(0, 0);
    }

    // Calculate y-axis label dimensions.
    if (yAxisLabel != null) {
      tempGraphics.setFont(axisLabelsFont);
      FontMetrics metrics = tempGraphics.getFontMetrics();
      yAxisLabelSize = new Dimension(metrics.stringWidth(yAxisLabel), metrics.getHeight());
      yAxisLabelAscent = metrics.getAscent();
    }
    else {
      yAxisLabelSize = new Dimension(0, 0);
    }

    // Calculate x-axis value dimensions.
    if (showXAxisValues) {
      tempGraphics.setFont(axisValuesFont);
      FontMetrics metrics = tempGraphics.getFontMetrics();
      xAxisValuesHeight = metrics.getHeight();
      xAxisValuesWidthMax = 0;
      for (Object o : xValues) {
        int w = metrics.stringWidth(o.toString());
        if (w > xAxisValuesWidthMax) {
          xAxisValuesWidthMax = w;
        }
      }
    }
    else {
      xAxisValuesHeight = 0;
    }

    // Calculate y-axis value dimensions.
    if (showYAxisValues) {
      tempGraphics.setFont(axisValuesFont);
      FontMetrics metrics = tempGraphics.getFontMetrics();
      yAxisValuesHeight = metrics.getHeight();
      yAxisValuesAscent = metrics.getAscent();
      yAxisValuesWidthMax = 0;
      for (Object o : yValues) {
        int w = metrics.stringWidth(o.toString());
        if (w > yAxisValuesWidthMax) {
          yAxisValuesWidthMax = w;
        }
      }
    }
    else {
      yAxisValuesHeight = 0;
    }

    // Calculate heatmap dimensions.
    int heatMapWidth = (zValues[0].length * cellSize.width);
    int heatMapHeight = (zValues.length * cellSize.height);
    heatMapSize = new Dimension(heatMapWidth, heatMapHeight);

    int yValuesHorizontalSize = 0;
    if (yValuesHorizontal) {
      yValuesHorizontalSize = yAxisValuesWidthMax;
    }
    else {
      yValuesHorizontalSize = yAxisValuesHeight;
    }

    int xValuesVerticalSize = 0;
    if (xValuesHorizontal) {
      xValuesVerticalSize = xAxisValuesHeight;
    }
    else {
      xValuesVerticalSize = xAxisValuesWidthMax;
    }

    // Calculate chart dimensions.
    int chartWidth = heatMapWidth + (2 * margin) + yAxisLabelSize.height + yValuesHorizontalSize
        + axisThickness;
    int chartHeight = heatMapHeight + (2 * margin) + xAxisLabelSize.height + xValuesVerticalSize
        + titleSize.height + axisThickness;
    chartSize = new Dimension(chartWidth, chartHeight);
  }
1256687
@Override protected void resizeDynamicText() {
        double maxWidth = unitText.isManaged() ? width - size * 0.275 : width - size * 0.1;
        double fontSize = size * 0.24;
        valueText.setFont(Fonts.latoRegular(fontSize));
        if (valueText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(valueText, maxWidth, fontSize); }

        fontSize = size * 0.1;
        unitText.setFont(Fonts.latoRegular(fontSize));
        if (unitText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(unitText, maxWidth, fontSize); }

        thresholdText.setFill(sectionsVisible ? Color.TRANSPARENT : tile.getBackgroundColor());
        if (!sectionsVisible) {
            fontSize = size * 0.08;
            thresholdText.setFont(Fonts.latoRegular(fontSize));
            thresholdText.setTextOrigin(VPos.CENTER);
            if (thresholdText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(thresholdText, maxWidth, fontSize); }
            thresholdText.setX((width - thresholdText.getLayoutBounds().getWidth()) * 0.5);
            thresholdText.setY(thresholdRect.getLayoutBounds().getMinY() + thresholdRect.getHeight() * 0.5);
        }
    }
1170923
def _zoom_labels(self, zoom):
        """"""

        labelfont = self.grid.GetLabelFont()
        default_fontsize = get_default_font().GetPointSize()
        labelfont.SetPointSize(max(1, int(round(default_fontsize * zoom))))
        self.grid.SetLabelFont(labelfont)
125596
public static int getDisplayWidth(@NonNull final Context context) {
        Condition.INSTANCE.ensureNotNull(context, "The context may not be null");
        return context.getResources().getDisplayMetrics().widthPixels;
    }