Java Code Examples for org.andengine.opengl.font.IFont#getLineHeight()
The following examples show how to use
org.andengine.opengl.font.IFont#getLineHeight() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Text.java From tilt-game-android with MIT License | 5 votes |
/** * @param pText * @throws OutOfCharactersException leaves this {@link Text} object in an undefined state, until {@link #setText(CharSequence)} is called again and no {@link OutOfCharactersException} is thrown. */ public void setText(final CharSequence pText) throws OutOfCharactersException { this.mText = pText; final IFont font = this.mFont; this.mLines.clear(); this.mLineWidths.clear(); if (this.mTextOptions.mAutoWrap == AutoWrap.NONE) { this.mLines = FontUtils.splitLines(this.mText, this.mLines); // TODO Add whitespace-trimming. } else { this.mLines = FontUtils.splitLines(this.mFont, this.mText, this.mLines, this.mTextOptions.mAutoWrap, this.mTextOptions.mAutoWrapWidth); } final int lineCount = this.mLines.size(); float maximumLineWidth = 0; for (int i = 0; i < lineCount; i++) { final float lineWidth = FontUtils.measureText(font, this.mLines.get(i)); maximumLineWidth = Math.max(maximumLineWidth, lineWidth); this.mLineWidths.add(lineWidth); } this.mLineWidthMaximum = maximumLineWidth; if (this.mTextOptions.mAutoWrap == AutoWrap.NONE) { this.mLineAlignmentWidth = this.mLineWidthMaximum; } else { this.mLineAlignmentWidth = this.mTextOptions.mAutoWrapWidth; } final float width = this.mLineAlignmentWidth; final float height = lineCount * font.getLineHeight() + (lineCount - 1) * this.mTextOptions.mLeading; this.setSize(width, height); }
Example 2
Source File: HighPerformanceTextVertexBufferObject.java From tilt-game-android with MIT License | 4 votes |
@Override public void onUpdateVertices(final Text pText) { final float[] bufferData = this.mBufferData; final IFont font = pText.getFont(); final HorizontalAlign horizontalAlign = pText.getHorizontalAlign(); final ArrayList<CharSequence> lines = pText.getLines(); final float lineHeight = font.getLineHeight(); final IFloatList lineWidths = pText.getLineWidths(); final float leading = pText.getLeading(); final float ascent = font.getAscent(); final float lineAlignmentWidth = pText.getLineAlignmentWidth(); int charactersToDraw = 0; int bufferDataOffset = 0; final int lineCount = lines.size(); for (int row = 0; row < lineCount; row++) { final CharSequence line = lines.get(row); float xBase; switch (horizontalAlign) { case RIGHT: xBase = lineAlignmentWidth - lineWidths.get(row); break; case CENTER: xBase = (lineAlignmentWidth - lineWidths.get(row)) * 0.5f; break; case LEFT: default: xBase = 0; } final float yBase = (lineCount - row) * lineHeight + ((lineCount - row - 1) * leading) + ascent; final int lineLength = line.length(); Letter previousLetter = null; for (int i = 0; i < lineLength; i++) { final Letter letter = font.getLetter(line.charAt(i)); if (previousLetter != null) { xBase += previousLetter.getKerning(letter.mCharacter); } if (!letter.isWhitespace()) { final float x = xBase + letter.mOffsetX; final float y = yBase - letter.mOffsetY; final float x2 = x + letter.mWidth; final float y2 = y - letter.mHeight; final float u = letter.mU; final float v = letter.mV; final float u2 = letter.mU2; final float v2 = letter.mV2; bufferData[bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x; bufferData[bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y2; bufferData[bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u; bufferData[bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v2; bufferData[bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x; bufferData[bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y; bufferData[bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u; bufferData[bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v; bufferData[bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x2; bufferData[bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y2; bufferData[bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u2; bufferData[bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v2; bufferData[bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x2; bufferData[bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y2; bufferData[bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u2; bufferData[bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v2; bufferData[bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x; bufferData[bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y; bufferData[bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u; bufferData[bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v; bufferData[bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x2; bufferData[bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y; bufferData[bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u2; bufferData[bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v; bufferDataOffset += Text.LETTER_SIZE; charactersToDraw++; } xBase += letter.mAdvance; previousLetter = letter; } } pText.setCharactersToDraw(charactersToDraw); this.setDirtyOnHardware(); }
Example 3
Source File: LowMemoryTextVertexBufferObject.java From tilt-game-android with MIT License | 4 votes |
@Override public void onUpdateVertices(final Text pText) { final FloatBuffer bufferData = this.mFloatBuffer; final IFont font = pText.getFont(); final HorizontalAlign horizontalAlign = pText.getHorizontalAlign(); final ArrayList<CharSequence> lines = pText.getLines(); final float lineHeight = font.getLineHeight(); final IFloatList lineWidths = pText.getLineWidths(); final float leading = pText.getLeading(); final float ascent = font.getAscent(); final float lineAlignmentWidth = pText.getLineAlignmentWidth(); int charactersToDraw = 0; int bufferDataOffset = 0; final int lineCount = lines.size(); for (int row = 0; row < lineCount; row++) { final CharSequence line = lines.get(row); float xBase; switch (horizontalAlign) { case RIGHT: xBase = lineAlignmentWidth - lineWidths.get(row); break; case CENTER: xBase = (lineAlignmentWidth - lineWidths.get(row)) * 0.5f; break; case LEFT: default: xBase = 0; } final float yBase = (lineCount - row) * lineHeight + ((lineCount - row - 1) * leading) + ascent; final int lineLength = line.length(); Letter previousLetter = null; for (int i = 0; i < lineLength; i++) { final Letter letter = font.getLetter(line.charAt(i)); if (previousLetter != null) { xBase += previousLetter.getKerning(letter.mCharacter); } if (!letter.isWhitespace()) { final float x = xBase + letter.mOffsetX; final float y = yBase - letter.mOffsetY; final float x2 = x + letter.mWidth; final float y2 = y - letter.mHeight; final float u = letter.mU; final float v = letter.mV; final float u2 = letter.mU2; final float v2 = letter.mV2; bufferData.put(bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X, x); bufferData.put(bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y, y2); bufferData.put(bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U, u); bufferData.put(bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V, v2); bufferData.put(bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X, x); bufferData.put(bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y, y); bufferData.put(bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U, u); bufferData.put(bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V, v); bufferData.put(bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X, x2); bufferData.put(bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y, y2); bufferData.put(bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U, u2); bufferData.put(bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V, v2); bufferData.put(bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X, x2); bufferData.put(bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y, y2); bufferData.put(bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U, u2); bufferData.put(bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V, v2); bufferData.put(bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X, x); bufferData.put(bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y, y); bufferData.put(bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U, u); bufferData.put(bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V, v); bufferData.put(bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X, x2); bufferData.put(bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y, y); bufferData.put(bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U, u2); bufferData.put(bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V, v); bufferDataOffset += Text.LETTER_SIZE; charactersToDraw++; } xBase += letter.mAdvance; previousLetter = letter; } } pText.setCharactersToDraw(charactersToDraw); this.setDirtyOnHardware(); }
Example 4
Source File: HighPerformanceTextVertexBufferObject.java From 30-android-libraries-in-30-days with Apache License 2.0 | 4 votes |
@Override public void onUpdateVertices(final Text pText) { final float[] bufferData = this.mBufferData; // TODO Optimize with field access? final IFont font = pText.getFont(); final ArrayList<CharSequence> lines = pText.getLines(); final float lineHeight = font.getLineHeight(); final IFloatList lineWidths = pText.getLineWidths(); final float lineAlignmentWidth = pText.getLineAlignmentWidth(); int charactersToDraw = 0; int bufferDataOffset = 0; final int lineCount = lines.size(); for (int row = 0; row < lineCount; row++) { final CharSequence line = lines.get(row); float xBase; switch(pText.getHorizontalAlign()) { case RIGHT: xBase = lineAlignmentWidth - lineWidths.get(row); break; case CENTER: xBase = (lineAlignmentWidth - lineWidths.get(row)) * 0.5f; break; case LEFT: default: xBase = 0; } final float yBase = row * (lineHeight + pText.getLeading()); final int lineLength = line.length(); Letter previousLetter = null; for(int i = 0; i < lineLength; i++) { final Letter letter = font.getLetter(line.charAt(i)); if(previousLetter != null) { xBase += previousLetter.getKerning(letter.mCharacter); } if(!letter.isWhitespace()) { final float x = xBase + letter.mOffsetX; final float y = yBase + letter.mOffsetY; final float y2 = y + letter.mHeight; final float x2 = x + letter.mWidth; final float u = letter.mU; final float v = letter.mV; final float u2 = letter.mU2; final float v2 = letter.mV2; bufferData[bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x; bufferData[bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y; bufferData[bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u; bufferData[bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v; bufferData[bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x; bufferData[bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y2; bufferData[bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u; bufferData[bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v2; bufferData[bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x2; bufferData[bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y2; bufferData[bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u2; bufferData[bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v2; bufferData[bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x2; bufferData[bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y2; bufferData[bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u2; bufferData[bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v2; bufferData[bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x2; bufferData[bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y; bufferData[bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u2; bufferData[bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v; bufferData[bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X] = x; bufferData[bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y] = y; bufferData[bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U] = u; bufferData[bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V] = v; bufferDataOffset += Text.LETTER_SIZE; charactersToDraw++; } xBase += letter.mAdvance; previousLetter = letter; } } pText.setCharactersToDraw(charactersToDraw); this.setDirtyOnHardware(); }
Example 5
Source File: LowMemoryTextVertexBufferObject.java From 30-android-libraries-in-30-days with Apache License 2.0 | 4 votes |
@Override public void onUpdateVertices(final Text pText) { final FloatBuffer bufferData = this.mFloatBuffer; // TODO Optimize with field access? final IFont font = pText.getFont(); final ArrayList<CharSequence> lines = pText.getLines(); final float lineHeight = font.getLineHeight(); final IFloatList lineWidths = pText.getLineWidths(); final float lineAlignmentWidth = pText.getLineAlignmentWidth(); int charactersToDraw = 0; int bufferDataOffset = 0; final int lineCount = lines.size(); for (int i = 0; i < lineCount; i++) { final CharSequence line = lines.get(i); float xBase; switch(pText.getHorizontalAlign()) { case RIGHT: xBase = lineAlignmentWidth - lineWidths.get(i); break; case CENTER: xBase = (lineAlignmentWidth - lineWidths.get(i)) * 0.5f; break; case LEFT: default: xBase = 0; } final float yBase = i * (lineHeight + pText.getLeading()); final int lineLength = line.length(); Letter previousLetter = null; for(int j = 0; j < lineLength; j++) { final Letter letter = font.getLetter(line.charAt(j)); if(previousLetter != null) { xBase += previousLetter.getKerning(letter.mCharacter); } if(!letter.isWhitespace()) { final float x = xBase + letter.mOffsetX; final float y = yBase + letter.mOffsetY; final float y2 = y + letter.mHeight; final float x2 = x + letter.mWidth; final float u = letter.mU; final float v = letter.mV; final float u2 = letter.mU2; final float v2 = letter.mV2; bufferData.put(bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X, x); bufferData.put(bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y, y); bufferData.put(bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U, u); bufferData.put(bufferDataOffset + 0 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V, v); bufferData.put(bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X, x); bufferData.put(bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y, y2); bufferData.put(bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U, u); bufferData.put(bufferDataOffset + 1 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V, v2); bufferData.put(bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X, x2); bufferData.put(bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y, y2); bufferData.put(bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U, u2); bufferData.put(bufferDataOffset + 2 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V, v2); bufferData.put(bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X, x2); bufferData.put(bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y, y2); bufferData.put(bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U, u2); bufferData.put(bufferDataOffset + 3 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V, v2); bufferData.put(bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X, x2); bufferData.put(bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y, y); bufferData.put(bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U, u2); bufferData.put(bufferDataOffset + 4 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V, v); bufferData.put(bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_X, x); bufferData.put(bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.VERTEX_INDEX_Y, y); bufferData.put(bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_U, u); bufferData.put(bufferDataOffset + 5 * Text.VERTEX_SIZE + Text.TEXTURECOORDINATES_INDEX_V, v); bufferDataOffset += Text.LETTER_SIZE; charactersToDraw++; } xBase += letter.mAdvance; previousLetter = letter; } } pText.setCharactersToDraw(charactersToDraw); this.setDirtyOnHardware(); }
Example 6
Source File: Text.java From 30-android-libraries-in-30-days with Apache License 2.0 | 4 votes |
/** * @param pText * @throws OutOfCharactersException leaves this {@link Text} object in an undefined state, until {@link Text#setText(CharSequence)} is called again and no {@link OutOfCharactersException} is thrown. */ public void setText(final CharSequence pText) throws OutOfCharactersException { this.mText = pText; final IFont font = this.mFont; this.mLines.clear(); this.mLineWidths.clear(); if(this.mTextOptions.mAutoWrap == AutoWrap.NONE) { this.mLines = FontUtils.splitLines(this.mText, this.mLines); // TODO Add whitespace-trimming. } else { this.mLines = FontUtils.splitLines(this.mFont, this.mText, this.mLines, this.mTextOptions.mAutoWrap, this.mTextOptions.mAutoWrapWidth); } final int lineCount = this.mLines.size(); float maximumLineWidth = 0; for (int i = 0; i < lineCount; i++) { final float lineWidth = FontUtils.measureText(font, this.mLines.get(i)); maximumLineWidth = Math.max(maximumLineWidth, lineWidth); this.mLineWidths.add(lineWidth); } this.mLineWidthMaximum = maximumLineWidth; if(this.mTextOptions.mAutoWrap == AutoWrap.NONE) { this.mLineAlignmentWidth = this.mLineWidthMaximum; } else { this.mLineAlignmentWidth = this.mTextOptions.mAutoWrapWidth; } super.mWidth = this.mLineAlignmentWidth; super.mHeight = lineCount * font.getLineHeight() + (lineCount - 1) * this.mTextOptions.mLeading; this.mRotationCenterX = super.mWidth * 0.5f; this.mRotationCenterY = super.mHeight * 0.5f; this.mScaleCenterX = this.mRotationCenterX; this.mScaleCenterY = this.mRotationCenterY; this.onUpdateVertices(); }