gdx-studio

#libgdx#java#desktop

git clone https://git.pyrossh.dev/gdx-studio

An IDE for creating Games using libgdx and Java supported on all platforms Android, iOS, Desktop


src_libs/com/badlogic/gdx/tools/hiero/unicodefont/Glyph.java
a62d533 1
/*******************************************************************************
a62d533 2
 * Copyright 2011 See AUTHORS file.
a62d533 3
 * 
a62d533 4
 * Licensed under the Apache License, Version 2.0 (the "License");
a62d533 5
 * you may not use this file except in compliance with the License.
a62d533 6
 * You may obtain a copy of the License at
a62d533 7
 * 
a62d533 8
 *   http://www.apache.org/licenses/LICENSE-2.0
a62d533 9
 * 
a62d533 10
 * Unless required by applicable law or agreed to in writing, software
a62d533 11
 * distributed under the License is distributed on an "AS IS" BASIS,
a62d533 12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
a62d533 13
 * See the License for the specific language governing permissions and
a62d533 14
 * limitations under the License.
a62d533 15
 ******************************************************************************/
a62d533 16
a62d533 17
package com.badlogic.gdx.tools.hiero.unicodefont;
a62d533 18
a62d533 19
import java.awt.Rectangle;
a62d533 20
import java.awt.Shape;
a62d533 21
import java.awt.font.GlyphMetrics;
a62d533 22
import java.awt.font.GlyphVector;
a62d533 23
a62d533 24
import com.badlogic.gdx.graphics.Texture;
a62d533 25
a62d533 26
/** Represents the glyph in a font for a unicode codepoint.
a62d533 27
 * @author Nathan Sweet */
a62d533 28
public class Glyph {
a62d533 29
	private int codePoint;
a62d533 30
	private short width, height;
a62d533 31
	private short yOffset;
a62d533 32
	private boolean isMissing;
a62d533 33
	private Shape shape;
a62d533 34
	private float u, v, u2, v2;
a62d533 35
	private Texture texture;
a62d533 36
a62d533 37
	Glyph (int codePoint, Rectangle bounds, GlyphVector vector, int index, UnicodeFont unicodeFont) {
a62d533 38
		this.codePoint = codePoint;
a62d533 39
a62d533 40
		GlyphMetrics metrics = vector.getGlyphMetrics(index);
a62d533 41
		int lsb = (int)metrics.getLSB();
a62d533 42
		if (lsb > 0) lsb = 0;
a62d533 43
		int rsb = (int)metrics.getRSB();
a62d533 44
		if (rsb > 0) rsb = 0;
a62d533 45
a62d533 46
		int glyphWidth = bounds.width - lsb - rsb;
a62d533 47
		int glyphHeight = bounds.height;
a62d533 48
		if (glyphWidth > 0 && glyphHeight > 0) {
a62d533 49
			int padTop = unicodeFont.getPaddingTop();
a62d533 50
			int padRight = unicodeFont.getPaddingRight();
a62d533 51
			int padBottom = unicodeFont.getPaddingBottom();
a62d533 52
			int padLeft = unicodeFont.getPaddingLeft();
a62d533 53
			int glyphSpacing = 1; // Needed to prevent filtering problems.
a62d533 54
			width = (short)(glyphWidth + padLeft + padRight + glyphSpacing);
a62d533 55
			height = (short)(glyphHeight + padTop + padBottom + glyphSpacing);
a62d533 56
			yOffset = (short)(unicodeFont.getAscent() + bounds.y - padTop);
a62d533 57
		}
a62d533 58
a62d533 59
		shape = vector.getGlyphOutline(index, -bounds.x + unicodeFont.getPaddingLeft(), -bounds.y + unicodeFont.getPaddingTop());
a62d533 60
a62d533 61
		isMissing = !unicodeFont.getFont().canDisplay((char)codePoint);
a62d533 62
	}
a62d533 63
a62d533 64
	/** The unicode codepoint the glyph represents. */
a62d533 65
	public int getCodePoint () {
a62d533 66
		return codePoint;
a62d533 67
	}
a62d533 68
a62d533 69
	/** Returns true if the font does not have a glyph for this codepoint. */
a62d533 70
	public boolean isMissing () {
a62d533 71
		return isMissing;
a62d533 72
	}
a62d533 73
a62d533 74
	/** The width of the glyph's image. */
a62d533 75
	public int getWidth () {
a62d533 76
		return width;
a62d533 77
	}
a62d533 78
a62d533 79
	/** The height of the glyph's image. */
a62d533 80
	public int getHeight () {
a62d533 81
		return height;
a62d533 82
	}
a62d533 83
a62d533 84
	/** The shape to use to draw this glyph. This is set to null after the glyph is stored in a GlyphPage. */
a62d533 85
	public Shape getShape () {
a62d533 86
		return shape;
a62d533 87
	}
a62d533 88
a62d533 89
	public void setShape (Shape shape) {
a62d533 90
		this.shape = shape;
a62d533 91
	}
a62d533 92
a62d533 93
	public void setTexture (Texture texture, float u, float v, float u2, float v2) {
a62d533 94
		this.texture = texture;
a62d533 95
		this.u = u;
a62d533 96
		this.v = v;
a62d533 97
		this.u2 = u2;
a62d533 98
		this.v2 = v2;
a62d533 99
	}
a62d533 100
a62d533 101
	public Texture getTexture () {
a62d533 102
		return texture;
a62d533 103
	}
a62d533 104
a62d533 105
	public float getU () {
a62d533 106
		return u;
a62d533 107
	}
a62d533 108
a62d533 109
	public float getV () {
a62d533 110
		return v;
a62d533 111
	}
a62d533 112
a62d533 113
	public float getU2 () {
a62d533 114
		return u2;
a62d533 115
	}
a62d533 116
a62d533 117
	public float getV2 () {
a62d533 118
		return v2;
a62d533 119
	}
a62d533 120
a62d533 121
	/** The distance from drawing y location to top of this glyph, causing the glyph to sit on the baseline. */
a62d533 122
	public int getYOffset () {
a62d533 123
		return yOffset;
a62d533 124
	}
a62d533 125
}