summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes')
-rw-r--r--src/jogl/classes/com/jogamp/graph/font/Font.java19
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java119
2 files changed, 50 insertions, 88 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/font/Font.java b/src/jogl/classes/com/jogamp/graph/font/Font.java
index 541cec8dc..a2fcfb23a 100644
--- a/src/jogl/classes/com/jogamp/graph/font/Font.java
+++ b/src/jogl/classes/com/jogamp/graph/font/Font.java
@@ -166,8 +166,6 @@ public interface Font {
// http://scripts.sil.org/cms/scripts/page.php?item_id=IWS-Chapter08#ba57949e
public static final int ID_UNKNOWN = 0;
- Font getFont();
-
/** Return this glyph's ID */
int getID();
@@ -175,16 +173,6 @@ public interface Font {
String getName();
/**
- * Return fractional font em-size [0..1], i.e. funits divided by {@link #getUnitsPerEM()}, i.e.
- * <pre>
- * return funits / head.unitsPerEM;
- * </pre>
- * @param funits smallest font unit, where {@link #getUnitsPerEM()} square covers whole glyph
- * @return fractional font em-size [0..1]
- */
- float getScale(final int funits);
-
- /**
* Return the AABBox in font-units, borrowing internal instance.
*/
AABBox getBBoxFU();
@@ -215,8 +203,15 @@ public interface Font {
/** Return advance in font em-size [0..1], sourced from `hmtx` table. */
float getAdvance();
+ /** Return leftSideBearings in font units, sourced from `hmtx` table. */
+ int getLeftSideBearingsFU();
+
+ /** Return leftSideBearings in font em-size [0..1], sourced from `hmtx` table. */
+ float getLeftSideBearings();
+
/** True if kerning values are horizontal, otherwise vertical */
boolean isKerningHorizontal();
+
/** True if kerning values are perpendicular to text flow, otherwise along with flow */
boolean isKerningCrossstream();
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java
index 15f617553..f097b1225 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java
@@ -37,46 +37,6 @@ import jogamp.graph.font.typecast.ot.table.PostTable;
public final class TypecastGlyph implements Font.Glyph {
- public static final class Metrics
- {
- private final TypecastFont font;
- private final AABBox bbox; // in font-units
- private final int advance; // in font-units
-
- /**
- *
- * @param font
- * @param bbox in font-units
- * @param advance hmtx value in font-units
- */
- public Metrics(final TypecastFont font, final AABBox bbox, final int advance)
- {
- this.font = font;
- this.bbox = bbox;
- this.advance = advance;
- }
-
- public final TypecastFont getFont() { return font; }
-
- public final int getUnitsPerEM() { return font.getMetrics().getUnitsPerEM(); }
-
- public final float getScale(final int funits) { return font.getMetrics().getScale(funits); }
-
- /** in font-units */
- public final AABBox getBBoxFU() { return this.bbox; }
-
- /** Return advance in font units, sourced from `hmtx` table. */
- public final int getAdvanceFU() { return this.advance; }
-
- @Override
- public final String toString()
- {
- return "\nMetrics:"+
- "\n bbox: "+this.bbox+
- "\n advance: "+this.advance;
- }
- }
-
public static final short INVALID_ID = (short)((1 << 16) - 1);
public static final short MAX_ID = (short)((1 << 16) - 2);
@@ -106,25 +66,36 @@ public final class TypecastGlyph implements Font.Glyph {
private final int id;
private final String name;
+
+ private final TypecastFont font;
+ private final AABBox bbox; // in font-units
+ private final int advance; // in font-units
+ private final int leftSideBearings; // in font-units
+
private final int[/*right_glyphid*/][/*value*/] kerning;
private final boolean kerning_horizontal;
private final boolean kerning_crossstream;
private final OutlineShape shape; // in EM units
- private final Metrics metrics;
/**
*
* @param font
- * @param name
+ * @param name from `post` table
* @param id
* @param bbox in font-units
* @param advance from hmtx in font-units
+ * @param leftSideBearings from hmtx in font-units
* @param shape
*/
- protected TypecastGlyph(final TypecastFont font, final int id, final String name, final AABBox bbox, final int advance,
+ protected TypecastGlyph(final TypecastFont font, final int id, final String name,
+ final AABBox bbox, final int advance, final int leftSideBearings,
final KernSubtable kernSub, final OutlineShape shape) {
this.id = id;
this.name = name;
+ this.font = font;
+ this.bbox = bbox;
+ this.advance = advance;
+ this.leftSideBearings = leftSideBearings;
if( null != kernSub && kernSub.areKerningValues() ) {
int pair_sz = 64;
int pair_idx = 0;
@@ -152,59 +123,42 @@ public final class TypecastGlyph implements Font.Glyph {
this.kerning_crossstream = true;
}
this.shape = shape;
- this.metrics = new Metrics(font, bbox, advance);
}
@Override
- public final Font getFont() {
- return this.metrics.getFont();
- }
-
- public final Metrics getMetrics() {
- return this.metrics;
- }
+ public final int getID() { return id; }
@Override
- public final int getID() {
- return this.id;
- }
+ public final String getName() { return name; }
@Override
- public final String getName() {
- return this.name;
- }
+ public final AABBox getBBoxFU() { return bbox; }
@Override
- public final float getScale(final int funits) {
- return this.metrics.getScale(funits);
- }
+ public final AABBox getBBoxFU(final AABBox dest) { return dest.copy(bbox); }
@Override
- public final AABBox getBBoxFU() {
- return metrics.getBBoxFU();
+ public final AABBox getBBox(final AABBox dest, final float[] tmpV3) {
+ return dest.copy(bbox).scale2(1.0f/font.getMetrics().getUnitsPerEM(), tmpV3);
}
@Override
- public final AABBox getBBoxFU(final AABBox dest) {
- return dest.copy(metrics.getBBoxFU());
+ public final AABBox getBBox() {
+ final AABBox dest = new AABBox();
+ return dest.copy(bbox).scale2(1.0f/font.getMetrics().getUnitsPerEM(), new float[2]);
}
@Override
- public final AABBox getBBox(final AABBox dest, final float[] tmpV3) {
- return dest.copy(metrics.getBBoxFU()).scale2(1.0f/metrics.getUnitsPerEM(), tmpV3);
- }
+ public final int getAdvanceFU() { return advance; }
@Override
- public final AABBox getBBox() {
- final AABBox dest = new AABBox();
- return dest.copy(metrics.getBBoxFU()).scale2(1.0f/metrics.getUnitsPerEM(), new float[2]);
- }
+ public float getAdvance() { return font.getMetrics().getScale( advance ); }
@Override
- public final int getAdvanceFU() { return metrics.getAdvanceFU(); }
+ public final int getLeftSideBearingsFU() { return leftSideBearings; }
@Override
- public float getAdvance() { return getScale( getAdvanceFU() ); }
+ public final float getLeftSideBearings() { return font.getMetrics().getScale( leftSideBearings ); }
@Override
public final boolean isKerningHorizontal() { return kerning_horizontal; }
@@ -236,7 +190,7 @@ public final class TypecastGlyph implements Font.Glyph {
@Override
public final float getKerning(final int right_glyphid) {
- return getScale( getKerningFU(right_glyphid) );
+ return font.getMetrics().getScale( getKerningFU(right_glyphid) );
}
@Override
@@ -247,15 +201,27 @@ public final class TypecastGlyph implements Font.Glyph {
@Override
public final int hashCode() {
// 31 * x == (x << 5) - x
- final int hash = 31 + getFont().getName(Font.NAME_UNIQUNAME).hashCode();
+ final int hash = 31 + font.getName(Font.NAME_UNIQUNAME).hashCode();
return ((hash << 5) - hash) + id;
}
@Override
+ public final boolean equals(final Object o) {
+ if( this == o ) { return true; }
+ if( o instanceof TypecastGlyph ) {
+ final TypecastGlyph og = (TypecastGlyph)o;
+ return og.font.getName(Font.NAME_UNIQUNAME).equals(font.getName(Font.NAME_UNIQUNAME)) &&
+ og.id == id;
+ }
+ return false;
+ }
+
+ @Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("Glyph[id ").append(id).append(" '").append(name).append("'")
.append(", advance ").append(getAdvanceFU())
+ .append(", leftSideBearings ").append(getLeftSideBearingsFU())
.append(", kerning[size ").append(kerning.length).append(", horiz ").append(this.isKerningHorizontal()).append(", cross ").append(this.isKerningCrossstream()).append("]")
.append(", shape ").append(null != shape).append("]");
return sb.toString();
@@ -263,11 +229,12 @@ public final class TypecastGlyph implements Font.Glyph {
@Override
public String fullString() {
- final PostTable post = metrics.getFont().getPostTable();
+ final PostTable post = font.getPostTable();
final String glyph_name = null != post ? post.getGlyphName(id) : "n/a";
final StringBuilder sb = new StringBuilder();
sb.append("Glyph id ").append(id).append(" '").append(glyph_name).append("'")
.append(", advance ").append(getAdvanceFU())
+ .append(", leftSideBearings ").append(getLeftSideBearingsFU())
.append(", ").append(getBBoxFU());
sb.append("\n Kerning: size ").append(kerning.length).append(", horiz ").append(this.isKerningHorizontal()).append(", cross ").append(this.isKerningCrossstream());