com.badlogic.gdx.graphics.g2d.BitmapFont.Glyph Java Examples

The following examples show how to use com.badlogic.gdx.graphics.g2d.BitmapFont.Glyph. 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: GlyphUtils.java    From typing-label with MIT License 6 votes vote down vote up
/** Copies all contents from the first glyph to the second one. */
static void clone(Glyph from, TypingGlyph to) {
    to.id = from.id;
    to.srcX = from.srcX;
    to.srcY = from.srcY;
    to.width = from.width;
    to.height = from.height;
    to.u = from.u;
    to.v = from.v;
    to.u2 = from.u2;
    to.v2 = from.v2;
    to.xoffset = from.xoffset;
    to.yoffset = from.yoffset;
    to.xadvance = from.xadvance;
    to.kerning = from.kerning; // Keep the same instance, there's no reason to deep clone it
    to.fixedWidth = from.fixedWidth;

    to.run = null;
    to.internalIndex = -1;
    to.color = null;
}
 
Example #2
Source File: FreeTypeFontGenerator.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
public void getGlyphs (GlyphRun run, CharSequence str, int start, int end, Glyph lastGlyph) {
	if (packer != null) packer.setPackToTexture(true); // All glyphs added after this are packed directly to the texture.
	super.getGlyphs(run, str, start, end, lastGlyph);
	if (dirty) {
		dirty = false;
		packer.updateTextureRegions(regions, parameter.minFilter, parameter.magFilter, parameter.genMipMaps);
	}
}
 
Example #3
Source File: GlyphUtils.java    From typing-label with MIT License 4 votes vote down vote up
/**
 * Returns a glyph from this pool and clones it from the given one. The glyph may be new (from {@link
 * Pool#newObject()}) or reused (previously {@link Pool#free(Object) freed}).
 */
static Glyph obtainClone(Glyph from) {
    TypingGlyph glyph = pool.obtain();
    clone(from, glyph);
    return glyph;
}
 
Example #4
Source File: TypingLabel.java    From typing-label with MIT License 4 votes vote down vote up
/** Adds cached glyphs to the active BitmapFontCache as the char index progresses. */
private void addMissingGlyphs() {
    // Add additional glyphs to layout array, if any
    int glyphLeft = glyphCharIndex - cachedGlyphCharIndex;
    if(glyphLeft < 1) return;

    // Get runs
    GlyphLayout layout = super.getGlyphLayout();
    Array<GlyphRun> runs = layout.runs;

    // Iterate through GlyphRuns to find the next glyph spot
    int glyphCount = 0;
    for(int runIndex = 0; runIndex < glyphRunCapacities.size; runIndex++) {
        int runCapacity = glyphRunCapacities.get(runIndex);
        if((glyphCount + runCapacity) < cachedGlyphCharIndex) {
            glyphCount += runCapacity;
            continue;
        }

        // Get run and increase glyphCount up to its current size
        Array<Glyph> glyphs = runs.get(runIndex).glyphs;
        glyphCount += glyphs.size;

        // Next glyphs go here
        while(glyphLeft > 0) {

            // Skip run if this one is full
            int runSize = glyphs.size;
            if(runCapacity == runSize) {
                break;
            }

            // Put new glyph to this run
            cachedGlyphCharIndex++;
            TypingGlyph glyph = glyphCache.get(cachedGlyphCharIndex);
            glyphs.add(glyph);

            // Cache glyph's vertex index
            glyph.internalIndex = glyphCount;

            // Advance glyph count
            glyphCount++;
            glyphLeft--;
        }
    }
}
 
Example #5
Source File: FreeTypeFontGenerator.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
/** Returns null if glyph was not found. If there is nothing to render, for example with various space characters, then bitmap
 * is null. */
public GlyphAndBitmap generateGlyphAndBitmap (int c, int size, boolean flip) {
	setPixelSizes(0, size);

	SizeMetrics fontMetrics = face.getSize().getMetrics();
	int baseline = FreeType.toInt(fontMetrics.getAscender());

	// Check if character exists in this font.
	// 0 means 'undefined character code'
	if (face.getCharIndex(c) == 0) {
		return null;
	}

	// Try to load character
	if (!loadChar(c)) {
		throw new GdxRuntimeException("Unable to load character!");
	}

	GlyphSlot slot = face.getGlyph();

	// Try to render to bitmap
	Bitmap bitmap;
	if (bitmapped) {
		bitmap = slot.getBitmap();
	} else if (!slot.renderGlyph(FreeType.FT_RENDER_MODE_NORMAL)) {
		bitmap = null;
	} else {
		bitmap = slot.getBitmap();
	}

	GlyphMetrics metrics = slot.getMetrics();

	Glyph glyph = new Glyph();
	if (bitmap != null) {
		glyph.width = bitmap.getWidth();
		glyph.height = bitmap.getRows();
	} else {
		glyph.width = 0;
		glyph.height = 0;
	}
	glyph.xoffset = slot.getBitmapLeft();
	glyph.yoffset = flip ? -slot.getBitmapTop() + baseline : -(glyph.height - slot.getBitmapTop()) - baseline;
	glyph.xadvance = FreeType.toInt(metrics.getHoriAdvance());
	glyph.srcX = 0;
	glyph.srcY = 0;
	glyph.id = c;

	GlyphAndBitmap result = new GlyphAndBitmap();
	result.glyph = glyph;
	result.bitmap = bitmap;
	return result;
}