public void flush() {

		if (textInfos.isEmpty()) {
			return;
		}

		sortDataAndAssignRows();

		// render the text into a string
		int lastRow = 0;
		int currentX = 0; //The x coordinate of the end of the last string
		for (TextInfo info : textInfos) {
			// insert newlines as appropriate
			for (int i = lastRow; i < info.row; i++) {
				buffer.append('\n');
			}

			// if we started a new row, reset the x position
			if (lastRow != info.row) {
				currentX = 0;
			}
			lastRow = info.row;

			// insert spaces to account for distance past last field in row
			FontMetrics metrics = info.fontMetrics;
			int spaceWidth = metrics.charWidth(' ');

			if (spaceWidth == 0) {
				// some environments report 0 for some fonts
				spaceWidth = 4;
			}

			float spaceBetween = info.point.x - currentX;
			int fillSpaces = Math.round(spaceBetween / spaceWidth);

			// account for the case where there's a very small amount of space between fields
			if (fillSpaces == 0 && info.point.x > currentX) {
				fillSpaces = 1;
			}

			for (int i = 0; i < fillSpaces; i++) {
				buffer.append(' ');
			}

			int stringWidth = metrics.stringWidth(info.text);
			currentX = info.point.x + stringWidth;

			// append the text
			buffer.append(info.text);
		}

		buffer.append('\n');
		textInfos.clear();
	}
Format text into a string for rendering.
Ghidra/Framework/Generic/src/main/java/generic/text/TextLayoutGraphics.java