<commit_before>package org.anddev.andengine.entity.text;

import javax.microedition.khronos.opengles.GL10;
import javax.microedition.khronos.opengles.GL11;

import org.anddev.andengine.entity.HorizontalAlign;
import org.anddev.andengine.entity.primitives.RectangularShape;
import org.anddev.andengine.opengl.GLHelper;
import org.anddev.andengine.opengl.buffer.BaseBuffer;
import org.anddev.andengine.opengl.buffer.BufferObjectManager;
import org.anddev.andengine.opengl.font.Font;
import org.anddev.andengine.opengl.texture.buffer.TextTextureBuffer;
import org.anddev.andengine.opengl.vertex.TextVertexBuffer;
import org.anddev.andengine.util.StringUtils;

/**
 * @author <NAME>
 * @since 10:54:59 - 03.04.2010
 */
public class Text extends RectangularShape {
	// ===========================================================
	// Constants
	// ===========================================================

	// ===========================================================
	// Fields
	// ===========================================================

	protected final int mVertexCount;

	private final TextTextureBuffer mTextTextureBuffer;

	private final String mText;
	private final String[] mLines;
	private final int[] mWidths;

	private final Font mFont;

	private final int mMaximumLineWidth;

	protected final int mCharacterCount;

	// ===========================================================
	// Constructors
	// ===========================================================

	public Text(final float pX, final float pY, final Font pFont, final String pText, final HorizontalAlign pHorizontalAlign) {
		super(pX, pY, 0, 0, new TextVertexBuffer(pText, pHorizontalAlign, GL11.GL_STATIC_DRAW));

		this.mCharacterCount = pText.length() - StringUtils.countOccurences(pText, "\n");
		this.mVertexCount = TextVertexBuffer.VERTICES_PER_CHARACTER * this.mCharacterCount;

		this.mTextTextureBuffer = new TextTextureBuffer(2 * this.mVertexCount * BaseBuffer.BYTES_PER_FLOAT, GL11.GL_STATIC_DRAW);
		BufferObjectManager.loadBufferObject(this.mTextTextureBuffer); // TODO Unload irgendwann oder so...
		this.mFont = pFont;
		this.mText = pText;

		/* Init Metrics. */
		{
			this.mLines = this.mText.split("\n");
			final String[] lines = this.mLines;
			final int lineCount = lines.length;

			this.mWidths = new int[lineCount];
			final int[] widths = this.mWidths;

			int maximumLineWidth = 0;

			for (int i = lineCount - 1; i >= 0; i--) {
				widths[i] = pFont.getStringWidth(lines[i]);
				maximumLineWidth = Math.max(maximumLineWidth, widths[i]);
			}
			this.mMaximumLineWidth = maximumLineWidth;
			<commit_msg>Added Text-Constructor with Default HorizontalAlign.LEFT .<commit_after>package org.anddev.andengine.entity.text;

import javax.microedition.khronos.opengles.GL10;
import javax.microedition.khronos.opengles.GL11;

import org.anddev.andengine.entity.HorizontalAlign;
import org.anddev.andengine.entity.primitives.RectangularShape;
import org.anddev.andengine.opengl.GLHelper;
import org.anddev.andengine.opengl.buffer.BaseBuffer;
import org.anddev.andengine.opengl.buffer.BufferObjectManager;
import org.anddev.andengine.opengl.font.Font;
import org.anddev.andengine.opengl.texture.buffer.TextTextureBuffer;
import org.anddev.andengine.opengl.vertex.TextVertexBuffer;
import org.anddev.andengine.util.StringUtils;

/**
 * @author <NAME>
 * @since 10:54:59 - 03.04.2010
 */
public class Text extends RectangularShape {
	// ===========================================================
	// Constants
	// ===========================================================

	// ===========================================================
	// Fields
	// ===========================================================

	protected final int mVertexCount;

	private final TextTextureBuffer mTextTextureBuffer;

	private final String mText;
	private final String[] mLines;
	private final int[] mWidths;

	private final Font mFont;

	private final int mMaximumLineWidth;

	protected final int mCharacterCount;

	// ===========================================================
	// Constructors
	// ===========================================================

	public Text(final float pX, final float pY, final Font pFont, final String pText) {
		this(pX, pY, pFont, pText, HorizontalAlign.LEFT);
	}

	public Text(final float pX, final float pY, final Font pFont, final String pText, final HorizontalAlign pHorizontalAlign) {
		super(pX, pY, 0, 0, new TextVertexBuffer(pText, pHorizontalAlign, GL11.GL_STATIC_DRAW));

		this.mCharacterCount = pText.length() - StringUtils.countOccurences(pText, "\n");
		this.mVertexCount = TextVertexBuffer.VERTICES_PER_CHARACTER * this.mCharacterCount;

		this.mTextTextureBuffer = new TextTextureBuffer(2 * this.mVertexCount * BaseBuffer.BYTES_PER_FLOAT, GL11.GL_STATIC_DRAW);
		BufferObjectManager.loadBufferObject(this.mTextTextureBuffer); // TODO Unload irgendwann oder so...
		this.mFont = pFont;
		this.mText = pText;

		/* Init Metrics. */
		{
			this.mLines = this.mText.split("\n");
			final String[] lines = this.mLines;
			final int lineCount = lines.length;

			this.mWidths = new int[lineCount];
			final int[] widths = this.mWidths;

			int maximumLineWidth = 0;

			for (int i = lineCount - 1; i >= 0; i--) {
				widths[i] = pFont.getStringWidth(lines[i]);
				maximumLineWidth = Math.max(maximumLineWidth, widths[i]);
			}
			this.mMaximumLineWidth = maximumLineWidth;
			
{'fraction_non_alphanumeric': 0.22707100591715976, 'fraction_numerical': 0.010355029585798817, 'mean_word_length': 5.2676709154113555, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7051002', 'n_tokens_mistral': 1787, 'n_tokens_neox': 1587, 'n_words': 329}