private void init(String currentText) {

		if (displaySize.width <= 0) {
			return;
		}

		// create the attributed string needed by the LineBreakMeasurer, setting the font over all
		// of the text
		AttributedString as = new AttributedString(currentText);
		int length = currentText.length();
		Font font = g2d.getFont();
		as.addAttribute(TextAttribute.FONT, font, 0, length);

		// create the LineBreakMeasuerer we will use to split the text at the given width, using the
		// rendering environment to get accurate size information
		AttributedCharacterIterator paragraph = as.getIterator();
		FontRenderContext frc = g2d.getFontRenderContext();
		LineBreakMeasurer measurer = new LineBreakMeasurer(paragraph, frc);
		measurer.setPosition(paragraph.getBeginIndex());

		int totalHeight = 0;
		int largestWidth = 0;
		int position = 0;
		while ((position = measurer.getPosition()) < paragraph.getEndIndex()) {

			TextShaperLine line = createLine(currentText, measurer);

			// Look ahead to see if the new row we created will fit within the height restrictions.
			// If not, we must clip the text and do this work again.
			float rowHeight = line.getHeight();
			totalHeight += rowHeight;
			if (totalHeight > displaySize.height) {

				// Truncate the original text and try again with the smaller text that we now know 
				// will fit, adding an ellipsis.
				int lineCount = lines.size();
				lines.clear();

				if (lineCount == 0) {
					return; // no room for a single line of text
				}

				// clip the text of the and recalculate
				int end = position;
				int newEnd = end - 3; // 3 for '...' 
				clippedText = currentText.substring(0, newEnd) + "...";

				init(clippedText);
				return;
			}

			lines.add(line);

			largestWidth = Math.max(largestWidth, (int) line.getWidth());

		}

		textSize = new Dimension(largestWidth, totalHeight);
	}
Creates a text shaper with the given text, display size and graphics context.
@param text the text
@param displaySize the size
@param g2d the graphics
Ghidra/Framework/Docking/src/main/java/docking/util/TextShaper.java