summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java47
-rw-r--r--src/jogl/classes/com/jogamp/graph/font/Font.java126
-rw-r--r--src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java21
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java149
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java113
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java26
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java73
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestFontsNEWT00.java7
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java22
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java10
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java45
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWTBugXXXX.java10
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java8
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo.java4
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java32
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java4
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java8
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label0.java14
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/LabelButton.java29
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java107
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListener01.java (renamed from src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java)86
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java12
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java5
23 files changed, 353 insertions, 605 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java
index a4ba4bf52..4af40bf1c 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java
@@ -42,7 +42,10 @@ import com.jogamp.graph.geom.Vertex.Factory;
import com.jogamp.graph.geom.plane.AffineTransform;
/**
- * Text {@link GLRegion} Utility Class
+ * Text Type Rendering Utility Class adding the {@link Font.Glyph}s {@link OutlineShape} to a {@link GLRegion}.
+ * <p>
+ * {@link OutlineShape}s are all produced in font em-size [0..1].
+ * </p>
*/
public class TextRegionUtil {
@@ -55,6 +58,9 @@ public class TextRegionUtil {
public static interface ShapeVisitor {
/**
* Visiting the given {@link OutlineShape} with it's corresponding {@link AffineTransform}.
+ * <p>
+ * The shape is in font em-size [0..1].
+ * </p>
* @param shape may be used as is, otherwise a copy shall be made if intended to be modified.
* @param t may be used immediately as is, otherwise a copy shall be made if stored.
*/
@@ -74,14 +80,16 @@ public class TextRegionUtil {
/**
* Visit each {@link Font.Glyph}'s {@link OutlineShape} with the given {@link ShapeVisitor}
- * additionally passing the progressed {@link AffineTransform} in font-units.
- * The latter reflects the given font metric in font-units and hence character position.
+ * additionally passing the progressed {@link AffineTransform}.
+ * <p>
+ * The produced shapes are in font em-size [0..1], but can be adjusted with the given transform, progressed and passed to the visitor.
+ * </p>
* @param visitor
* @param transform optional given transform
* @param font the target {@link Font}
* @param str string text
- * @param temp1 temporary AffineTransform storage, mandatory, will be passed to {@link ShapeVisitor#visit(OutlineShape, AffineTransform)} and can be modified.
- * @param temp2 temporary AffineTransform storage, mandatory, can be re-used in {@link ShapeVisitor#visit(OutlineShape, AffineTransform)} by user code.
+ * @param temp1 temporary AffineTransform storage, mandatory
+ * @param temp2 temporary AffineTransform storage, mandatory
*/
public static void processString(final ShapeVisitor visitor, final AffineTransform transform,
final Font font, final CharSequence str,
@@ -89,10 +97,10 @@ public class TextRegionUtil {
final int charCount = str.length();
// region.setFlipped(true);
- final int lineHeight = font.getLineHeightFU();
+ final float lineHeight = font.getLineHeight();
- int y = 0;
- int advanceTotal = 0;
+ float y = 0;
+ float advanceTotal = 0;
Font.Glyph left_glyph = null;
for(int i=0; i< charCount; i++) {
@@ -102,7 +110,7 @@ public class TextRegionUtil {
advanceTotal = 0;
left_glyph = null;
} else if (character == ' ') {
- advanceTotal += font.getAdvanceWidthFU(Glyph.ID_SPACE);
+ advanceTotal += font.getAdvanceWidth(Glyph.ID_SPACE);
left_glyph = null;
} else {
// reset transform
@@ -115,24 +123,23 @@ public class TextRegionUtil {
final OutlineShape glyphShape = glyph.getShape();
if( null == glyphShape ) {
left_glyph = null;
- temp1.translate(advanceTotal, y, temp2);
continue;
}
if( null != left_glyph ) {
- advanceTotal += left_glyph.getKerningFU(glyph.getID());
+ advanceTotal += left_glyph.getKerning(glyph.getID());
}
temp1.translate(advanceTotal, y, temp2);
visitor.visit(glyphShape, temp1);
- advanceTotal += glyph.getAdvanceFU();
+ advanceTotal += glyph.getAdvance();
left_glyph = glyph;
}
}
}
/**
- * Add the string in 3D space w.r.t. the font using font-units at the end of the {@link GLRegion}.
+ * Add the string in 3D space w.r.t. the font in font em-size [0..1] at the end of the {@link GLRegion}.
* <p>
- * The resulting GLRegion should be scaled by the chosen pixelSize of the font divided by the font's unitsPerEM.
+ * The shapes added to the GLRegion are in font em-size [0..1].
* </p>
* @param region the {@link GLRegion} sink
* @param vertexFactory vertex impl factory {@link Factory}
@@ -154,9 +161,9 @@ public class TextRegionUtil {
}
/**
- * Render the string in 3D space w.r.t. the font using font-units at the end of an internally cached {@link GLRegion}.
+ * Render the string in 3D space w.r.t. the font int font em-size [0..1] at the end of an internally cached {@link GLRegion}.
* <p>
- * The resulting GLRegion should be scaled by the chosen pixelSize of the font divided by the font's unitsPerEM.
+ * The shapes added to the GLRegion are in font em-size [0..1].
* </p>
* <p>
* Cached {@link GLRegion}s will be destroyed w/ {@link #clear(GL2ES2)} or to free memory.
@@ -187,9 +194,9 @@ public class TextRegionUtil {
}
/**
- * Render the string in 3D space w.r.t. the font using font-units at the end of an internally temporary {@link GLRegion}.
+ * Render the string in 3D space w.r.t. the font in font em-size [0..1] at the end of an internally temporary {@link GLRegion}.
* <p>
- * The resulting GLRegion should be scaled by the chosen pixelSize of the font divided by the font's unitsPerEM.
+ * The shapes added to the GLRegion are in font em-size [0..1].
* </p>
* <p>
* In case of a multisampling region renderer, i.e. {@link Region#VBAA_RENDERING_BIT}, recreating the {@link GLRegion}
@@ -222,10 +229,10 @@ public class TextRegionUtil {
}
/**
- * Render the string in 3D space w.r.t. the font using font-units at the end of the given {@link GLRegion},
+ * Render the string in 3D space w.r.t. the font in font em-size [0..1] at the end of the given {@link GLRegion},
* which will {@link GLRegion#clear(GL2ES2) cleared} beforehand.
* <p>
- * The resulting GLRegion should be scaled by the chosen pixelSize of the font divided by the font's unitsPerEM.
+ * The shapes added to the GLRegion are in font em-size [0..1].
* </p>
* @param gl the current GL state
* @param font {@link Font} to be used
diff --git a/src/jogl/classes/com/jogamp/graph/font/Font.java b/src/jogl/classes/com/jogamp/graph/font/Font.java
index 5c63227b3..2d26b1a85 100644
--- a/src/jogl/classes/com/jogamp/graph/font/Font.java
+++ b/src/jogl/classes/com/jogamp/graph/font/Font.java
@@ -86,20 +86,40 @@ public interface Font {
int getAscentFU();
/**
+ * @return ascent in font em-size [0..1]
+ */
+ float getAscent();
+
+ /**
* @return descent in font-units to be divided by {@link #getUnitsPerEM()}
*/
int getDescentFU();
/**
+ * @return descend in font em-size [0..1]
+ */
+ float getDescent();
+
+ /**
* @return line-gap in font-units to be divided by {@link #getUnitsPerEM()}
*/
int getLineGapFU();
/**
+ * @return line-gap in font em-size [0..1]
+ */
+ float getLineGap();
+
+ /**
* @return max-extend in font-units to be divided by {@link #getUnitsPerEM()}
*/
int getMaxExtendFU();
+ /**
+ * @return max-extend in font em-size [0..1]
+ */
+ float getMaxExtend();
+
/** Returns the font's units per EM from the 'head' table. One em square covers one glyph. */
int getUnitsPerEM();
@@ -117,15 +137,13 @@ public interface Font {
* @param dest AABBox instance set to this metrics boundary in font-units
* @return the given and set AABBox 'dest' in font units
*/
- AABBox getBBox(final AABBox dest);
+ AABBox getBBoxFU(final AABBox dest);
/**
- * @param dest AABBox instance set to this metrics boundary w/ given pixelSize
- * @param pixelSize pixel-size of font, for resolution correct pixel-size use {@link FontScale#toPixels(float, float)}
- * @param tmpV3 caller provided temporary 3-component vector
- * @return the given and set AABBox 'dest' in pixel size
+ * @param dest AABBox instance set to this metrics boundary in font em-size [0..1]
+ * @return the given and set AABBox 'dest' in font units
*/
- AABBox getBBox(final AABBox dest, final float pixelSize, final float[] tmpV3);
+ AABBox getBBox(final AABBox dest, final float[] tmpV3);
}
/**
@@ -159,12 +177,9 @@ public interface Font {
float getScale(final int funits);
/**
- * @param dest AABBox instance set to this metrics boundary w/ given pixelSize
- * @param pixelSize pixel-size of font, for resolution correct pixel-size use {@link FontScale#toPixels(float, float)}
- * @param tmpV3 caller provided temporary 3-component vector
- * @return the given and set AABBox 'dest' in pixel size
+ * Return the AABBox in font-units to be divided by unitsPerEM
*/
- AABBox getBBox(final AABBox dest, final float pixelSize, float[] tmpV3);
+ AABBox getBBoxFU();
/**
* Return the AABBox in font-units to be divided by unitsPerEM
@@ -174,9 +189,11 @@ public interface Font {
AABBox getBBoxFU(final AABBox dest);
/**
- * Return the AABBox in font-units to be divided by unitsPerEM
+ * @param dest AABBox instance set to this metrics boundary in font em-size [0..1]
+ * @param tmpV3 caller provided temporary 3-component vector
+ * @return the given and set AABBox 'dest' in font em-size [0..1]
*/
- AABBox getBBoxFU();
+ AABBox getBBox(final AABBox dest, float[] tmpV3);
/** Return advance in font units to be divided by unitsPerEM */
int getAdvanceFU();
@@ -184,12 +201,6 @@ public interface Font {
/** Return advance in font em-size [0..1] */
float getAdvance();
- /**
- * @param pixelSize pixel-size of font, for resolution correct pixel-size use {@link FontScale#toPixels(float, float)}
- * @return pixel size of advance
- */
- float getAdvance(final float pixelSize);
-
/** True if kerning values are horizontal, otherwise vertical */
boolean isKerningHorizontal();
/** True if kerning values are perpendicular to text flow, otherwise along with flow */
@@ -226,7 +237,6 @@ public interface Font {
String fullString();
}
-
String getName(final int nameIndex);
/** Shall return the family and subfamily name, separated a dash.
@@ -237,12 +247,10 @@ public interface Font {
StringBuilder getAllNames(final StringBuilder string, final String separator);
/**
- *
+ * Return advance-width of given glyphID in font-units to be divided by unitsPerEM
* @param glyphID
- * @param pixelSize pixel-size of font, for resolution correct pixel-size use {@link FontScale#toPixels(float, float)}
- * @return pixel size of advance width
*/
- float getAdvanceWidth(final int glyphID, final float pixelSize);
+ int getAdvanceWidthFU(final int glyphID);
/**
* Return advance-width of given glyphID in font em-size [0..1]
@@ -250,12 +258,6 @@ public interface Font {
*/
float getAdvanceWidth(final int glyphID);
- /**
- * Return advance-width of given glyphID in font-units to be divided by unitsPerEM
- * @param glyphID
- */
- int getAdvanceWidthFU(final int glyphID);
-
Metrics getMetrics();
int getGlyphID(final char symbol);
@@ -265,79 +267,49 @@ public interface Font {
int getNumGlyphs();
/**
- *
- * @param pixelSize pixel-size of font, for resolution correct pixel-size use {@link FontScale#toPixels(float, float)}
- * @return pixel size of line height
+ * Return line height in font-units to be divided by unitsPerEM
*/
- float getLineHeight(final float pixelSize);
+ int getLineHeightFU();
/**
* Return line height in font em-size [0..1]
*/
float getLineHeight();
- /**
- * Return line height in font-units to be divided by unitsPerEM
- */
- int getLineHeightFU();
-
- /**
- *
- * @param string
- * @param pixelSize pixel-size of font, for resolution correct pixel-size use {@link FontScale#toPixels(float, float)}
- * @return pixel size of metric width
- */
- float getMetricWidth(final CharSequence string, final float pixelSize);
+ /** Return metric-width in font-units */
+ int getMetricWidthFU(final CharSequence string);
/** Return metric-width in font em-size */
float getMetricWidth(final CharSequence string);
- /** Return metric-width in font-units */
- int getMetricWidthFU(final CharSequence string);
-
- /**
- *
- * @param string
- * @param pixelSize pixel-size of font, for resolution correct pixel-size use {@link FontScale#toPixels(float, float)}
- * @return pixel size of metric height
- */
- float getMetricHeight(final CharSequence string, final float pixelSize);
+ /** Return metric-height in font-units */
+ int getMetricHeightFU(final CharSequence string);
/** Return metric-height in font em-size */
float getMetricHeight(final CharSequence string);
- /** Return metric-height in font-units */
- int getMetricHeightFU(final CharSequence string);
-
- /**
- * Return the <i>layout</i> bounding box as computed by each glyph's metrics.
- * The result is not pixel correct, but reflects layout specific metrics.
- * <p>
- * See {@link #getPointsBounds(AffineTransform, CharSequence, float, AffineTransform, AffineTransform)} for pixel correct results.
- * </p>
- * @param string string text
- * @param pixelSize pixel-size of font, for resolution correct pixel-size use {@link FontScale#toPixels(float, float)}
- */
- AABBox getMetricBounds(final CharSequence string, final float pixelSize);
+ /** Return layout metric-bounds in font-units, see {@link #getMetricBounds(CharSequence, float)} */
+ AABBox getMetricBoundsFU(final CharSequence string);
/** Return layout metric-bounds in font em-size, see {@link #getMetricBounds(CharSequence, float)} */
AABBox getMetricBounds(final CharSequence string);
- /** Return layout metric-bounds in font-units, see {@link #getMetricBounds(CharSequence, float)} */
- AABBox getMetricBoundsFU(final CharSequence string);
-
/**
- * Return the bounding box by taking each glyph's point-based bounding box into account.
+ * Return the bounding box by taking each glyph's font-unit sized bounding box into account.
* @param transform optional given transform
* @param string string text
- * @param pixelSize pixel-size of font, for resolution correct pixel-size use {@link FontScale#toPixels(float, float)}
+ * @return the bounding box of the given string in font-units [0..1]
*/
- AABBox getPointsBounds(final AffineTransform transform, final CharSequence string, final float pixelSize);
+ AABBox getPointsBoundsFU(final AffineTransform transform, final CharSequence string);
+ /**
+ * Return the bounding box by taking each glyph's font em-sized bounding box into account.
+ * @param transform optional given transform
+ * @param string string text
+ * @return the bounding box of the given string in font em-size [0..1]
+ */
AABBox getPointsBounds(final AffineTransform transform, final CharSequence string);
- AABBox getPointsBoundsFU(final AffineTransform transform, final CharSequence string);
-
boolean isPrintableChar(final char c);
/** Shall return {@link #getFullFamilyName()} */
diff --git a/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java b/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java
index d54142e38..234b2121b 100644
--- a/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java
+++ b/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java
@@ -582,7 +582,10 @@ public class AABBox {
}
/**
- * Scale this AABBox by a constant
+ * Scale this AABBox by a constant around fixed center
+ * <p>
+ * high and low is recomputed by scaling its distance to fixed center.
+ * </p>
* @param size a constant float value
* @param tmpV3 caller provided temporary 3-component vector
* @return this AABBox for chaining
@@ -605,6 +608,22 @@ public class AABBox {
}
/**
+ * Scale this AABBox by a constant, recomputing center
+ * <p>
+ * high and low is scaled and center recomputed.
+ * </p>
+ * @param size a constant float value
+ * @param tmpV3 caller provided temporary 3-component vector
+ * @return this AABBox for chaining
+ */
+ public final AABBox scale2(final float size, final float[] tmpV3) {
+ VectorUtil.scaleVec3(high, high, size); // in-place scale
+ VectorUtil.scaleVec3(low, low, size); // in-place scale
+ computeCenter();
+ return this;
+ }
+
+ /**
* Translate this AABBox by a float[3] vector
* @param t the float[3] translation vector
* @return this AABBox for chaining
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
index 146bc0380..382d35a73 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
@@ -32,7 +32,6 @@ import jogamp.graph.font.typecast.ot.TTFont;
import jogamp.graph.font.typecast.ot.table.CmapFormat;
import jogamp.graph.font.typecast.ot.table.CmapIndexEntry;
import jogamp.graph.font.typecast.ot.table.CmapTable;
-import jogamp.graph.font.typecast.ot.table.HdmxTable;
import jogamp.graph.font.typecast.ot.table.ID;
import jogamp.graph.font.typecast.ot.table.KernSubtable;
import jogamp.graph.font.typecast.ot.table.KernSubtableFormat0;
@@ -50,7 +49,6 @@ import com.jogamp.graph.geom.plane.AffineTransform;
import com.jogamp.opengl.math.geom.AABBox;
class TypecastFont implements Font {
- static final boolean USE_PRESCALED_ADVANCE = false;
static final boolean DEBUG = false;
private static final Vertex.Factory<SVertex> vertexFactory = SVertex.factory();
@@ -167,10 +165,6 @@ class TypecastFont implements Font {
}
@Override
- public float getAdvanceWidth(final int glyphID, final float pixelSize) {
- return pixelSize * metrics.getScale( font.getHmtxTable().getAdvanceWidth(glyphID) );
- }
- @Override
public float getAdvanceWidth(final int glyphID) {
return metrics.getScale( font.getHmtxTable().getAdvanceWidth(glyphID) );
}
@@ -230,7 +224,7 @@ class TypecastFont implements Font {
if(null == glyph) {
throw new RuntimeException("Could not retrieve glyph for symbol: <"+symbol+"> "+(int)symbol+" -> glyph id "+glyph_id);
}
- final OutlineShape shape = TypecastRenderer.buildShape(symbol, glyph, vertexFactory);
+ final OutlineShape shape = TypecastRenderer.buildShape(metrics.getUnitsPerEM(), symbol, glyph, vertexFactory);
KernSubtable kernSub = null;
{
final KernTable kern = font.getKernTable();
@@ -248,33 +242,12 @@ class TypecastFont implements Font {
}
glyph.clearPointData();
- if( TypecastFont.USE_PRESCALED_ADVANCE ) {
- final HdmxTable hdmx = font.getHdmxTable();
- if (null!= result && null != hdmx) {
- /*if(DEBUG) {
- System.err.println("hdmx "+hdmx);
- }*/
- for (int i=0; i<hdmx.getNumberOfRecords(); i++)
- {
- final HdmxTable.DeviceRecord dr = hdmx.getRecord(i);
- if(DEBUG) {
- System.err.println("hdmx advance : pixelsize "+dr.getPixelSize()+" -> advance "+dr.getWidth(glyph_id));
- }
- result.addAdvance(dr.getPixelSize(), dr.getWidth(glyph_id));
- }
- }
- }
char2Glyph.put(symbol, result);
}
return result;
}
@Override
- public float getLineHeight(final float pixelSize) {
- return pixelSize * metrics.getScale( getLineHeightFU() );
- }
-
- @Override
public float getLineHeight() {
return metrics.getScale( getLineHeightFU() );
}
@@ -290,26 +263,6 @@ class TypecastFont implements Font {
}
@Override
- public float getMetricWidth(final CharSequence string, final float pixelSize) {
- if( !TypecastFont.USE_PRESCALED_ADVANCE ) {
- return pixelSize * getMetricWidth(string);
- } else {
- float width = 0;
- final int len = string.length();
- for (int i=0; i< len; i++) {
- final char character = string.charAt(i);
- if (character == '\n') {
- width = 0;
- } else {
- final Glyph glyph = getGlyph(character);
- width += glyph.getAdvance(pixelSize); // uses pixelSize mapping, different than glyph.getAdvanceFU()
- }
- }
- return width;
- }
- }
-
- @Override
public float getMetricWidth(final CharSequence string) {
return metrics.getScale( getMetricWidthFU(string) );
}
@@ -331,11 +284,6 @@ class TypecastFont implements Font {
}
@Override
- public float getMetricHeight(final CharSequence string, final float pixelSize) {
- return pixelSize * getMetricHeight(string);
- }
-
- @Override
public float getMetricHeight(final CharSequence string) {
return metrics.getScale( getMetricHeightFU(string) );
}
@@ -355,40 +303,8 @@ class TypecastFont implements Font {
}
@Override
- public AABBox getMetricBounds(final CharSequence string, final float pixelSize) {
- if( !TypecastFont.USE_PRESCALED_ADVANCE ) {
- return getMetricBoundsFU(string).scale(pixelSize/metrics.getUnitsPerEM(), new float[3]);
- } else {
- if (string == null) {
- return new AABBox();
- }
- final int charCount = string.length();
- final float lineHeight = getLineHeight(pixelSize);
- float totalHeight = 0;
- float totalWidth = 0;
- float curLineWidth = 0;
- for (int i=0; i<charCount; i++) {
- final char character = string.charAt(i);
- if (character == '\n') {
- totalWidth = Math.max(curLineWidth, totalWidth);
- curLineWidth = 0;
- totalHeight += lineHeight;
- continue;
- }
- final Glyph glyph = getGlyph(character);
- curLineWidth += glyph.getAdvance(pixelSize); // uses pixelSize mapping, different than glyph.getAdvanceFU()
- }
- if (curLineWidth > 0) {
- totalHeight += lineHeight;
- totalWidth = Math.max(curLineWidth, totalWidth);
- }
- return new AABBox(0, 0, 0, totalWidth, totalHeight,0);
- }
- }
-
- @Override
public AABBox getMetricBounds(final CharSequence string) {
- return getMetricBoundsFU(string).scale(1.0f/metrics.getUnitsPerEM(), new float[3]);
+ return getMetricBoundsFU(string).scale2(1.0f/metrics.getUnitsPerEM(), new float[3]);
}
@Override
@@ -419,62 +335,6 @@ class TypecastFont implements Font {
}
@Override
- public AABBox getPointsBounds(final AffineTransform transform, final CharSequence string, final float pixelSize) {
- if( !TypecastFont.USE_PRESCALED_ADVANCE ) {
- return getPointsBoundsFU(transform, string).scale(pixelSize/metrics.getUnitsPerEM(), new float[3]);
- } else {
- if (string == null) {
- return new AABBox();
- }
- final AffineTransform temp1 = new AffineTransform();
- final AffineTransform temp2 = new AffineTransform();
- final float pixelSize2 = pixelSize / metrics.getUnitsPerEM();
- final int charCount = string.length();
- final float lineHeight = getLineHeight(pixelSize);
- final AABBox tbox = new AABBox();
- final AABBox res = new AABBox();
-
- float y = 0;
- float advanceTotal = 0;
-
- for(int i=0; i< charCount; i++) {
- final char character = string.charAt(i);
- if( '\n' == character ) {
- y -= lineHeight;
- advanceTotal = 0;
- } else if (character == ' ') {
- advanceTotal += getAdvanceWidth(Glyph.ID_SPACE, pixelSize);
- } else {
- // reset transform
- if( null != transform ) {
- temp1.setTransform(transform);
- } else {
- temp1.setToIdentity();
- }
- temp1.translate(advanceTotal, y, temp2);
- temp1.scale(pixelSize2, pixelSize2, temp2);
- tbox.reset();
-
- final Font.Glyph glyph = getGlyph(character);
- res.resize(temp1.transform(glyph.getBBoxFU(), tbox));
-
- final OutlineShape glyphShape = glyph.getShape();
- if( null == glyphShape ) {
- continue;
- }
- advanceTotal += glyph.getAdvance(pixelSize);
- }
- }
- return res;
- }
- }
-
- @Override
- public AABBox getPointsBounds(final AffineTransform transform, final CharSequence string) {
- return getPointsBoundsFU(transform, string).scale(1.0f/metrics.getUnitsPerEM(), new float[3]);
- }
-
- @Override
public AABBox getPointsBoundsFU(final AffineTransform transform, final CharSequence string) {
if (string == null) {
return new AABBox();
@@ -520,6 +380,11 @@ class TypecastFont implements Font {
}
@Override
+ public AABBox getPointsBounds(final AffineTransform transform, final CharSequence string) {
+ return getPointsBoundsFU(transform, string).scale2(1.0f/metrics.getUnitsPerEM(), new float[3]);
+ }
+
+ @Override
final public int getNumGlyphs() {
return font.getNumGlyphs();
}
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java
index b5876758f..e6a655661 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java
@@ -27,7 +27,6 @@
*/
package jogamp.graph.font.typecast;
-import com.jogamp.common.util.IntIntHashMap;
import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.font.Font;
import com.jogamp.opengl.math.geom.AABBox;
@@ -38,76 +37,11 @@ import jogamp.graph.font.typecast.ot.table.PostTable;
public final class TypecastGlyph implements Font.Glyph {
- /** Scaled hmtx value */
- public static final class Advance
- {
- private final Font font;
- private final int advance; // in font-units
- private final IntIntHashMap size2advanceI;
-
- public Advance(final Font font, final int advance)
- {
- this.font = font;
- this.advance = advance;
- if( TypecastFont.USE_PRESCALED_ADVANCE ) {
- size2advanceI = new IntIntHashMap();
- size2advanceI.setKeyNotFoundValue(0);
- } else {
- size2advanceI = null;
- }
- }
-
- public final void reset() {
- if( TypecastFont.USE_PRESCALED_ADVANCE ) {
- size2advanceI.clear();
- }
- }
-
- public final Font getFont() { return font; }
-
- public final int getUnitsPerEM() { return this.font.getMetrics().getUnitsPerEM(); }
-
- public final float getScale(final int funits)
- {
- return this.font.getMetrics().getScale(funits);
- }
-
- public final void add(final float pixelSize, final float advance)
- {
- if( TypecastFont.USE_PRESCALED_ADVANCE ) {
- size2advanceI.put(Float.floatToIntBits(pixelSize), Float.floatToIntBits(advance));
- }
- }
-
- public final float get(final float pixelSize)
- {
- if( !TypecastFont.USE_PRESCALED_ADVANCE ) {
- return pixelSize * font.getMetrics().getScale( advance );
- } else {
- final int sI = Float.floatToIntBits( (float) Math.ceil( pixelSize ) );
- final int aI = size2advanceI.get(sI);
- if( 0 != aI ) {
- return Float.intBitsToFloat(aI);
- }
- return pixelSize * font.getMetrics().getScale( advance );
- }
- }
-
- @Override
- public final String toString()
- {
- return "\nAdvance:"+
- "\n advance: "+this.advance+
- "\n advances: \n"+size2advanceI;
- }
- }
-
public static final class Metrics
{
private final TypecastFont font;
private final AABBox bbox; // in font-units
private final int advance; // in font-units
- private final Advance advance2;
/**
*
@@ -120,17 +54,6 @@ public final class TypecastGlyph implements Font.Glyph {
this.font = font;
this.bbox = bbox;
this.advance = advance;
- if( TypecastFont.USE_PRESCALED_ADVANCE ) {
- this.advance2 = new Advance(font, advance);
- } else {
- this.advance2 = null;
- }
- }
-
- public final void reset() {
- if( TypecastFont.USE_PRESCALED_ADVANCE ) {
- advance2.reset();
- }
}
public final TypecastFont getFont() { return font; }
@@ -145,27 +68,12 @@ public final class TypecastGlyph implements Font.Glyph {
/** Return advance in font units to be divided by unitsPerEM */
public final int getAdvanceFU() { return this.advance; }
- public final void addAdvance(final float pixelSize, final float advance) {
- if( TypecastFont.USE_PRESCALED_ADVANCE ) {
- this.advance2.add(pixelSize, advance);
- }
- }
-
- public final float getAdvance(final float pixelSize) {
- if( TypecastFont.USE_PRESCALED_ADVANCE ) {
- return this.advance2.get(pixelSize);
- } else {
- return pixelSize * font.getMetrics().getScale( advance );
- }
- }
-
@Override
public final String toString()
{
return "\nMetrics:"+
"\n bbox: "+this.bbox+
- "\n advance: "+this.advance+
- "\n advance2: "+this.advance2;
+ "\n advance: "+this.advance;
}
}
@@ -272,8 +180,8 @@ public final class TypecastGlyph implements Font.Glyph {
}
@Override
- public final AABBox getBBox(final AABBox dest, final float pixelSize, final float[] tmpV3) {
- return dest.copy(metrics.getBBoxFU()).scale(pixelSize/metrics.getUnitsPerEM(), tmpV3);
+ public final AABBox getBBoxFU() {
+ return metrics.getBBoxFU();
}
@Override
@@ -282,8 +190,8 @@ public final class TypecastGlyph implements Font.Glyph {
}
@Override
- public final AABBox getBBoxFU() {
- return metrics.getBBoxFU();
+ public final AABBox getBBox(final AABBox dest, final float[] tmpV3) {
+ return dest.copy(metrics.getBBoxFU()).scale2(1.0f/metrics.getUnitsPerEM(), tmpV3);
}
@Override
@@ -292,17 +200,6 @@ public final class TypecastGlyph implements Font.Glyph {
@Override
public float getAdvance() { return getScale( getAdvanceFU() ); }
- protected final void addAdvance(final float pixelSize, final float advance) {
- if( TypecastFont.USE_PRESCALED_ADVANCE ) {
- this.metrics.addAdvance(pixelSize, advance);
- }
- }
-
- @Override
- public final float getAdvance(final float pixelSize) {
- return metrics.getAdvance(pixelSize);
- }
-
@Override
public final boolean isKerningHorizontal() { return kerning_horizontal; }
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java
index 705246822..274114e4a 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java
@@ -69,21 +69,41 @@ final class TypecastHMetrics implements Metrics {
}
@Override
+ public float getAscent() {
+ return getScale( getAscentFU() );
+ }
+
+ @Override
public int getDescentFU() {
return -hheaTable.getDescender(); // inverted
}
@Override
+ public float getDescent() {
+ return getScale( getDescentFU() );
+ }
+
+ @Override
public int getLineGapFU() {
return -hheaTable.getLineGap(); // inverted
}
@Override
+ public float getLineGap() {
+ return getScale( getLineGapFU() );
+ }
+
+ @Override
public int getMaxExtendFU() {
return hheaTable.getXMaxExtent();
}
@Override
+ public float getMaxExtend() {
+ return getScale( getMaxExtendFU() );
+ }
+
+ @Override
public final int getUnitsPerEM() {
return unitsPerEM;
}
@@ -94,12 +114,12 @@ final class TypecastHMetrics implements Metrics {
}
@Override
- public final AABBox getBBox(final AABBox dest) {
+ public final AABBox getBBoxFU(final AABBox dest) {
return dest.copy(bbox);
}
@Override
- public final AABBox getBBox(final AABBox dest, final float pixelSize, final float[] tmpV3) {
- return dest.setSize(bbox.getLow(), bbox.getHigh()).scale(pixelSize*unitsPerEM_inv, tmpV3);
+ public AABBox getBBox(final AABBox dest, final float[] tmpV3) {
+ return dest.setSize(bbox.getLow(), bbox.getHigh()).scale2(unitsPerEM_inv, tmpV3);
}
}
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java
index 472e3e58e..60319d842 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java
@@ -47,70 +47,49 @@ import com.jogamp.graph.geom.Vertex.Factory;
public class TypecastRenderer {
private static final boolean DEBUG = Debug.debug("graph.font.Renderer");
- private static void addShapeMoveTo(final OutlineShape shape, final Point p1) {
+ private static void addShapeMoveTo(final float unitsPerEM, final OutlineShape shape, final Point p1) {
if( DEBUG ) { System.err.println("Shape.MoveTo: "+p1); }
shape.closeLastOutline(false);
shape.addEmptyOutline();
- shape.addVertex(0, p1.x, p1.y, p1.onCurve);
+ shape.addVertex(0, p1.x/unitsPerEM, p1.y/unitsPerEM, p1.onCurve);
}
- private static void addShapeLineTo(final OutlineShape shape, final Point p1) {
+ private static void addShapeLineTo(final float unitsPerEM, final OutlineShape shape, final Point p1) {
if( DEBUG ) { System.err.println("Shape.LineTo: "+p1); }
- shape.addVertex(0, p1.x, p1.y, p1.onCurve);
+ shape.addVertex(0, p1.x/unitsPerEM, p1.y/unitsPerEM, p1.onCurve);
}
- private static void addShapeQuadTo(final OutlineShape shape, final Point p1, final Point p2) {
+ private static void addShapeQuadTo(final float unitsPerEM, final OutlineShape shape, final Point p1, final Point p2) {
if( DEBUG ) { System.err.println("Shape.QuadTo: "+p1+", "+p2); }
- shape.addVertex(0, p1.x, p1.y, p1.onCurve);
- shape.addVertex(0, p2.x, p2.y, p2.onCurve);
+ shape.addVertex(0, p1.x/unitsPerEM, p1.y/unitsPerEM, p1.onCurve);
+ shape.addVertex(0, p2.x/unitsPerEM, p2.y/unitsPerEM, p2.onCurve);
}
- private static void addShapeQuadTo(final OutlineShape shape, final Point p1, final float p2x,
- final float p2y, final boolean p2OnCurve) {
+ private static void addShapeQuadTo(final float unitsPerEM, final OutlineShape shape, final Point p1,
+ final float p2x, final float p2y, final boolean p2OnCurve) {
if( DEBUG ) { System.err.println("Shape.QuadTo: "+p1+", p2 "+p2x+", "+p2y+", onCurve "+p2OnCurve); }
- shape.addVertex(0, p1.x, p1.y, p1.onCurve);
- shape.addVertex(0, p2x, p2y, p2OnCurve);
+ shape.addVertex(0, p1.x/unitsPerEM, p1.y/unitsPerEM, p1.onCurve);
+ shape.addVertex(0, p2x/unitsPerEM, p2y/unitsPerEM, p2OnCurve);
}
/**
- private static void addShapeCubicTo(final OutlineShape shape, Factory<? extends Vertex> vertexFactory, Point p1, Point p2, Point p3) {
- shape.addVertex(0, p1.x, p1.y, p1.onCurve);
- shape.addVertex(0, p2.x, p2.y, p2.onCurve);
- shape.addVertex(0, p3.x, p3.y, p3.onCurve);
+ private static void addShapeCubicTo(final float unitsPerEM, final OutlineShape shape, Factory<? extends Vertex> vertexFactory, Point p1, Point p2, Point p3) {
+ shape.addVertex(0, p1.x/unitsPerEM, p1.y/unitsPerEM, p1.onCurve);
+ shape.addVertex(0, p2.x/unitsPerEM, p2.y/unitsPerEM, p2.onCurve);
+ shape.addVertex(0, p3.x/unitsPerEM, p3.y/unitsPerEM, p3.onCurve);
} */
- public static OutlineShape buildShape(final char symbol, final jogamp.graph.font.typecast.ot.Glyph glyph, final Factory<? extends Vertex> vertexFactory) {
+ public static OutlineShape buildShape(final int unitsPerEM, final char symbol, final jogamp.graph.font.typecast.ot.Glyph glyph, final Factory<? extends Vertex> vertexFactory) {
//
// See Typecast: GlyphPathFactory.addContourToPath(..)
//
-
if (glyph == null) {
return null;
}
final OutlineShape shape = new OutlineShape(vertexFactory);
- buildShapeImpl(shape, symbol, glyph);
+ buildShapeImpl(unitsPerEM, shape, symbol, glyph);
shape.setIsQuadraticNurbs();
return shape;
}
- /**
- private static void buildShapeImpl02(final OutlineShape shape, char symbol, OTGlyph glyph, Factory<? extends Vertex> vertexFactory) {
- // Iterate through all of the points in the glyph. Each time we find a
- // contour end point, add the point range to the path.
- int startIndex = 0;
- int count = 0;
- for (int i = 0; i < glyph.getPointCount(); i++) {
- count++;
- if ( glyph.getPoint(i).endOfContour ) {
- for(int j=0; j<count; j++) {
- final Point p = glyph.getPoint(startIndex + j);
- shape.addVertex(0, vertexFactory.create(p.x, p.y, 0, p.onCurve));
- }
- shape.closeLastOutline(false);
- startIndex = i + 1;
- count = 0;
- }
- }
- } */
-
- private static void buildShapeImpl(final OutlineShape shape, final char symbol, final jogamp.graph.font.typecast.ot.Glyph glyph) {
+ private static void buildShapeImpl(final float unitsPerEM, final OutlineShape shape, final char symbol, final jogamp.graph.font.typecast.ot.Glyph glyph) {
// Iterate through all of the points in the glyph. Each time we find a
// contour end point, add the point range to the path.
int startIndex = 0;
@@ -140,7 +119,7 @@ public class TypecastRenderer {
System.err.println("\t p3["+p3Idx+"] "+p3);
}
if(offset == 0) {
- addShapeMoveTo(shape, p0);
+ addShapeMoveTo(unitsPerEM, shape, p0);
// gp.moveTo(point.x, point.y);
}
@@ -156,7 +135,7 @@ public class TypecastRenderer {
// s = new Line2D.Float(point.x, point.y, p1.x, p1.y);
// gp.lineTo( p1.x, p1.y );
- addShapeLineTo(shape, p1);
+ addShapeLineTo(unitsPerEM, shape, p1);
offset++;
} else {
if (p2.onCurve) {
@@ -165,17 +144,17 @@ public class TypecastRenderer {
// s = new QuadCurve2D.Float( point.x, point.y, p1.x, p1.y, p2.x, p2.y);
// gp.quadTo(p1.x, p1.y, p2.x, p2.y);
- addShapeQuadTo(shape, p1, p2);
+ addShapeQuadTo(unitsPerEM, shape, p1, p2);
offset+=2;
} else {
if (null != p3 && p3.onCurve) {
// Branch-3: point.onCurve && !p1.onCurve && !p2.onCurve && p3.onCurve
if( DEBUG ) { System.err.println("B3 .. 2-quad p0-p1-p1_2, p1_2-p2-p3 **** 2QUAD"); }
// addShapeCubicTo(shape, vertexFactory, p1, p2, p3);
- addShapeQuadTo(shape, p1, midValue(p1.x, p2.x),
+ addShapeQuadTo(unitsPerEM, shape, p1, midValue(p1.x, p2.x),
midValue(p1.y, p2.y),
true);
- addShapeQuadTo(shape, p2, p3);
+ addShapeQuadTo(unitsPerEM, shape, p2, p3);
offset+=3;
} else {
// Branch-4: point.onCurve && !p1.onCurve && !p2.onCurve && !p3.onCurve
@@ -184,7 +163,7 @@ public class TypecastRenderer {
// s = new QuadCurve2D.Float(point.x,point.y,p1.x,p1.y,
// midValue(p1.x, p2.x), midValue(p1.y, p2.y));
// gp.quadTo(p1.x, p1.y, midValue(p1.x, p2.x), midValue(p1.y, p2.y));
- addShapeQuadTo(shape, p1, midValue(p1.x, p2.x),
+ addShapeQuadTo(unitsPerEM, shape, p1, midValue(p1.x, p2.x),
midValue(p1.y, p2.y),
true);
offset+=2; // Skip p2 as done in Typecast
@@ -198,7 +177,7 @@ public class TypecastRenderer {
// s = new QuadCurve2D.Float(midValue(pM.x, point.x), midValue(pM.y, point.y),
// point.x, point.y,
// midValue(point.x, p1.x), midValue(point.y, p1.y));
- addShapeQuadTo(shape, p0, midValue(p0.x, p1.x),
+ addShapeQuadTo(unitsPerEM, shape, p0, midValue(p0.x, p1.x),
midValue(p0.y, p1.y), true);
offset++;
} else {
@@ -207,7 +186,7 @@ public class TypecastRenderer {
// s = new QuadCurve2D.Float(midValue(pM.x, point.x), midValue(pM.y, point.y),
// point.x, point.y, p1.x, p1.y);
// gp.quadTo(point.x, point.y, p1.x, p1.y);
- addShapeQuadTo(shape, p0, p1);
+ addShapeQuadTo(unitsPerEM, shape, p0, p1);
offset++;
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestFontsNEWT00.java b/src/test/com/jogamp/opengl/test/junit/graph/TestFontsNEWT00.java
index 8a2284b67..be654d345 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TestFontsNEWT00.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TestFontsNEWT00.java
@@ -91,8 +91,8 @@ public class TestFontsNEWT00 extends UITestCase {
final float s0_em = font.getAdvanceWidth(glyphID);
final float s1_em = glyph.getAdvance();
- final float s0_px = font.getAdvanceWidth(glyphID, pixelSize);
- final float s1_px = glyph.getAdvance(pixelSize);
+ final float s0_px = s0_em * pixelSize;
+ final float s1_px = s1_em * pixelSize;
System.err.println(" Char '"+c+"', id "+glyphID+", font-px "+pixelSize+", unitsPerEM "+unitsPerEM+":");
System.err.println(" "+glyph);
@@ -102,7 +102,7 @@ public class TestFontsNEWT00 extends UITestCase {
System.err.println(" px "+s0_px+", "+s1_px);
System.err.println(" AABBox");
System.err.println(" funits "+glyph.getBBoxFU());
- System.err.println(" px "+glyph.getBBox(new AABBox(), pixelSize, new float[3]));
+ System.err.println(" em "+glyph.getBBox(new AABBox(), new float[3]));
Assert.assertEquals(s0, s1);
@@ -118,7 +118,6 @@ public class TestFontsNEWT00 extends UITestCase {
final int glyphid_left = font.getGlyphID(left);
final int glyphid_right = font.getGlyphID(right);
final Font.Glyph glyph_left = font.getGlyph(left);
- final Font.Glyph glyph_right = font.getGlyph(right);
final int k_val = glyph_left.getKerningFU(glyphid_right);
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java
index c5fe0b903..5db5c09ea 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java
@@ -287,7 +287,7 @@ public class TestTextRendererNEWT00 extends UITestCase {
final float fontSizeMin, fontSizeMax;
private long t0;
float fontSizeAnim, fontSizeDelta;
- float dpiH;
+ float dpiV, ppmmV;
TextRendererGLEL(final RenderState rs, final int renderModes, final int sampleCount) {
super(renderModes, new int[] { sampleCount });
@@ -340,7 +340,8 @@ public class TestTextRendererNEWT00 extends UITestCase {
final Window win = (Window)drawable.getUpstreamWidget();
final float[] pixelsPerMM = win.getPixelsPerMM(new float[2]);
final float[] dotsPerInch = FontScale.ppmmToPPI(pixelsPerMM, new float[2]);
- dpiH = dotsPerInch[1];
+ dpiV = dotsPerInch[1];
+ ppmmV = pixelsPerMM[1];
System.err.println(getFontInfo());
System.err.println("fontSize "+fontSizeFixed+", dotsPerMM "+pixelsPerMM[0]+"x"+pixelsPerMM[1]+", dpi "+dotsPerInch[0]+"x"+dotsPerInch[1]+", pixelSize "+FontScale.toPixels(fontSizeFixed, dotsPerInch[1] /* dpi display */));
}
@@ -358,7 +359,7 @@ public class TestTextRendererNEWT00 extends UITestCase {
final String modeS = Region.getRenderModeString(renderModes);
final String bname = String.format((Locale)null, "%s-msaa%02d-fontsz%02.1f-%03dx%03d-%s%04d", objName,
drawable.getChosenGLCapabilities().getNumSamples(),
- TestTextRendererNEWT00.fontSizeFixed, drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), modeS, vbaaSampleCount[0]);
+ fontSizeFixed, drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), modeS, vbaaSampleCount[0]);
final String filename = dir + bname +".png";
if(screenshot.readPixels(drawable.getGL(), false)) {
screenshot.write(new File(filename));
@@ -366,11 +367,12 @@ public class TestTextRendererNEWT00 extends UITestCase {
}
String getFontInfo() {
- final float unitsPerEM = font.getMetrics().getUnitsPerEM();
- return String.format("Font %s%n %s%nunitsPerEM %f (upem)",
- font.getFullFamilyName(),
- font.getName(Font.NAME_UNIQUNAME),
- unitsPerEM);
+ final float pixelSize = FontScale.toPixels(fontSizeFixed, dpiV);
+ final float mmSize = pixelSize / ppmmV;
+ final int unitsPerEM = font.getMetrics().getUnitsPerEM();
+ return String.format("Resolution dpiV %.2f, %.2f px/mm%nFont %s, unitsPerEM %d, size %.2f pt %.2f px %2f mm%n",
+ dpiV, ppmmV,
+ font.getFullFamilyName(),unitsPerEM, fontSizeFixed, pixelSize, mmSize);
}
@Override
@@ -395,8 +397,8 @@ public class TestTextRendererNEWT00 extends UITestCase {
fontSizeDelta *= -1f;
}
- final float pixelSize = FontScale.toPixels(fontSizeFixed, dpiH);
- final float pixelSizeAnim = FontScale.toPixels(fontSizeAnim, dpiH);
+ final float pixelSize = FontScale.toPixels(fontSizeFixed, dpiV);
+ final float pixelSizeAnim = FontScale.toPixels(fontSizeAnim, dpiV);
final String modeS = Region.getRenderModeString(renderModes);
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java
index 6211409f7..8826275b1 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java
@@ -61,6 +61,8 @@ public class TestTextRendererNEWT01 extends UITestCase {
static final boolean DEBUG = false;
static final boolean TRACE = false;
static long duration = 100; // ms
+ static int win_width = 1024;
+ static int win_height = 640;
static int atoi(final String a) {
try {
@@ -73,6 +75,12 @@ public class TestTextRendererNEWT01 extends UITestCase {
if(args[i].equals("-time")) {
i++;
duration = atoi(args[i]);
+ } else if(args[i].equals("-width")) {
+ i++;
+ win_width = atoi(args[i]);
+ } else if(args[i].equals("-height")) {
+ i++;
+ win_height = atoi(args[i]);
}
}
final String tstname = TestTextRendererNEWT01.class.getName();
@@ -118,7 +126,7 @@ public class TestTextRendererNEWT01 extends UITestCase {
caps.setAlphaBits(4);
System.err.println("Requested: "+caps);
- final GLWindow window = createWindow("text-vbaa1-msaa0", caps, 1024, 640);
+ final GLWindow window = createWindow("text-vbaa1-msaa0", caps, win_width, win_height);
window.display();
System.err.println("Chosen: "+window.getChosenGLCapabilities());
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java
index cdd2bc750..5cabe546d 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT10.java
@@ -52,6 +52,7 @@ import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.curve.opengl.TextRegionUtil;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;
+import com.jogamp.graph.font.FontScale;
import com.jogamp.graph.geom.SVertex;
import com.jogamp.opengl.math.geom.AABBox;
import com.jogamp.opengl.test.junit.util.MiscUtils;
@@ -70,9 +71,11 @@ public class TestTextRendererNEWT10 extends UITestCase {
static boolean forceGL3 = false;
static boolean mainRun = false;
static boolean useMSAA = true;
+ static int win_width = 1024;
+ static int win_height = 640;
static Font font;
- static float fontSize = 24;
+ static float fontSize = 24; // in pixel
static String customStr = null;
@BeforeClass
@@ -95,6 +98,12 @@ public class TestTextRendererNEWT10 extends UITestCase {
if(args[i].equals("-time")) {
i++;
duration = atoi(args[i]);
+ } else if(args[i].equals("-width")) {
+ i++;
+ win_width = atoi(args[i]);
+ } else if(args[i].equals("-height")) {
+ i++;
+ win_height = atoi(args[i]);
} else if(args[i].equals("-noMSAA")) {
useMSAA = false;
} else if(args[i].equals("-es2")) {
@@ -157,7 +166,7 @@ public class TestTextRendererNEWT10 extends UITestCase {
System.err.println("Requested: "+caps);
System.err.println("Requested: "+Region.getRenderModeString(renderModes));
- final NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow(caps, 800, 400, true);
+ final NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow(caps, win_width, win_height, true);
final GLDrawable drawable = winctx.context.getGLDrawable();
final GL2ES2 gl = winctx.context.getGL().getGL2ES2();
@@ -186,7 +195,17 @@ public class TestTextRendererNEWT10 extends UITestCase {
// display
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
if( null == customStr ) {
- renderString(drawable, gl, renderer, textRenderUtil, "012345678901234567890123456789", 0, 0, -1000, sampleCountIO);
+ {
+ final float[] pixelsPerMM = winctx.window.getPixelsPerMM(new float[2]);
+ final float[] dpi = FontScale.ppmmToPPI(pixelsPerMM, new float[2]);
+ final float mmSize = fontSize / pixelsPerMM[1];
+ final int unitsPerEM = font.getMetrics().getUnitsPerEM();
+ String txt = String.format("Resolution dpiV %.2f, %.2f px/mm", dpi[1], pixelsPerMM[1]);
+ renderString(drawable, gl, renderer, textRenderUtil, txt, 0, 0, -1000, sampleCountIO);
+ txt = String.format("Font %s, unitsPerEM %d, size %.2f px %2f mm", font.getFullFamilyName(), unitsPerEM, fontSize, mmSize);
+ renderString(drawable, gl, renderer, textRenderUtil, txt, 0, -1, -1000, sampleCountIO);
+ }
+ renderString(drawable, gl, renderer, textRenderUtil, "012345678901234567890123456789", 0, -1, -1000, sampleCountIO);
renderString(drawable, gl, renderer, textRenderUtil, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, -1, -1000, sampleCountIO);
renderString(drawable, gl, renderer, textRenderUtil, "Hello World", 0, -1, -1000, sampleCountIO);
renderString(drawable, gl, renderer, textRenderUtil, "4567890123456", 4, -1, -1000,sampleCountIO);
@@ -200,8 +219,9 @@ public class TestTextRendererNEWT10 extends UITestCase {
} else {
renderString(drawable, gl, renderer, textRenderUtil, customStr, 0, 0, -1000, sampleCountIO);
}
- drawable.swapBuffers();
+ gl.glFinish();
printScreen(renderModes, drawable, gl, false, sampleCount);
+ drawable.swapBuffers();
sleep();
@@ -218,23 +238,20 @@ public class TestTextRendererNEWT10 extends UITestCase {
void renderString(final GLDrawable drawable, final GL2ES2 gl, final RegionRenderer renderer, final TextRegionUtil textRenderUtil, final String text, final int column, int row, final int z0, final int[] sampleCount) {
final int height = drawable.getSurfaceHeight();
- int dx = 0;
- int dy = height;
+ float dx = 0;
+ float dy = height;
if(0>row) {
row = lastRow + 1;
}
- final AABBox textBox = font.getMetricBounds(text, fontSize);
- dx += font.getAdvanceWidth('X', fontSize) * column;
- dy -= (int)textBox.getHeight() * ( row + 1 );
+ final AABBox textBox = font.getMetricBounds(text); // em-size
+ dx += fontSize * font.getAdvanceWidth('X') * column;
+ dy -= fontSize * textBox.getHeight() * ( row + 1 );
final PMVMatrix pmv = renderer.getMatrix();
pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
pmv.glLoadIdentity();
pmv.glTranslatef(dx, dy, z0);
- {
- final float sxy = fontSize / font.getMetrics().getUnitsPerEM();
- pmv.glScalef(sxy, sxy, 1.0f);
- }
+ pmv.glScalef(fontSize, fontSize, 1.0f);
textRenderUtil.drawString3D(gl, renderer, font, text, null, sampleCount);
lastRow = row;
@@ -249,7 +266,7 @@ public class TestTextRendererNEWT10 extends UITestCase {
final String modeS = Region.getRenderModeString(renderModes);
final String bname = String.format((Locale)null, "%s-msaa%02d-fontsz%02.1f-%03dx%03d-%s%04d", objName,
drawable.getChosenGLCapabilities().getNumSamples(),
- TestTextRendererNEWT10.fontSize, drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), modeS, sampleCount);
+ fontSize, drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), modeS, sampleCount);
final String filename = dir + bname +".png";
if(screenshot.readPixels(gl, false)) {
screenshot.write(new File(filename));
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWTBugXXXX.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWTBugXXXX.java
index 2c7967dd1..445d233d6 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWTBugXXXX.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWTBugXXXX.java
@@ -188,14 +188,14 @@ public class TestTextRendererNEWTBugXXXX extends UITestCase {
void renderString(final GLDrawable drawable, final GL2ES2 gl, final RegionRenderer renderer, final Font font, final TextRegionUtil textRenderUtil, final String text, final int column, int row, final int z0, final int[] sampleCount) {
final int height = drawable.getSurfaceHeight();
- int dx = 0;
- int dy = height;
+ float dx = 0;
+ float dy = height;
if(0>row) {
row = lastRow + 1;
}
- final AABBox textBox = font.getMetricBounds(text, fontSize);
- dx += font.getAdvanceWidth('X', fontSize) * column;
- dy -= (int)textBox.getHeight() * ( row + 1 );
+ final AABBox textBox = font.getMetricBounds(text);
+ dx += fontSize * font.getAdvanceWidth('X') * column;
+ dy -= fontSize * textBox.getHeight() * ( row + 1 );
final PMVMatrix pmv = renderer.getMatrix();
pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java b/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java
index 866a522ac..6bc120cde 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java
@@ -249,10 +249,11 @@ public abstract class TextRendererGLELBase implements GLEventListener {
final int height = drawable.getSurfaceHeight();
dy = height-ty;
}
+ final float sxy = pixelScale * pixelSize;
final int newLineCount = TextRegionUtil.getCharCount(text, '\n');
- final float lineHeight = font.getLineHeight(pixelSize);
- dx += pixelScale * font.getAdvanceWidth('X', pixelSize) * column;
- dy -= pixelScale * lineHeight * ( row + 1 );
+ final float lineHeight = font.getLineHeight();
+ dx += sxy * font.getAdvanceWidth('X') * column;
+ dy -= sxy * lineHeight * ( row + 1 );
final PMVMatrix pmvMatrix = rs.getMatrix();
pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
@@ -262,7 +263,6 @@ public abstract class TextRendererGLELBase implements GLEventListener {
pmvMatrix.glLoadIdentity();
}
pmvMatrix.glTranslatef(dx, dy, tz);
- final float sxy = ( pixelScale * pixelSize ) / font.getMetrics().getUnitsPerEM();
if( flipVerticalInGLOrientation && drawable.isGLOriented() ) {
pmvMatrix.glScalef(sxy, -1f*sxy, 1.0f);
} else {
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo.java
index 401450fdb..ade84b3a3 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo.java
@@ -139,10 +139,10 @@ public class GPUTextNewtDemo {
final float[] sDPI = FontScale.perMMToPerInch( window.getPixelsPerMM(new float[2]) );
final float font_ptpi = 12f;
final float font_ppi = FontScale.toPixels(font_ptpi, sDPI[1]);
- final AABBox fontNameBox = font.getMetricBounds(GPUTextRendererListenerBase01.textX1, font_ppi);
+ final AABBox fontNameBox = font.getMetricBounds(GPUTextRendererListenerBase01.textX1);
System.err.println("GPU Text Newt Demo: "+font.fullString());
System.err.println("GPU Text Newt Demo: screen-dpi: "+sDPI[0]+"x"+sDPI[1]+", font "+font_ptpi+" pt, "+font_ppi+" pixel");
- System.err.println("GPU Text Newt Demo: textX2: "+fontNameBox+" pixel");
+ System.err.println("GPU Text Newt Demo: textX2: "+fontNameBox+" em, "+fontNameBox.scale(font_ppi, new float[3])+" px");
// window.setSurfaceSize((int)(fontNameBox.getWidth()*1.1f), (int)(fontNameBox.getHeight()*2f));
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java
index 5ae940da7..abf7151d0 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java
@@ -192,9 +192,10 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
headtext = textXLast;
}
if(resize && null != headtext) {
- headbox = font.getMetricBounds(headtext, FontScale.toPixels(fontSizeHead, dpiV));
+ headbox = font.getMetricBounds(headtext);
if( headtext != text_help ) {
- upsizeWindowSurface(upstream_window, true, (int)(headbox.getWidth()*1.1f), (int)(headbox.getHeight()*2f));
+ final float pxSz = FontScale.toPixels(fontSizeHead, dpiV);
+ upsizeWindowSurface(upstream_window, true, (int)(headbox.getWidth()*pxSz*1.1f), (int)(headbox.getHeight()*pxSz*2f));
}
}
}
@@ -230,7 +231,7 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
} else {
System.err.println("Using vertical default DPI of "+dpiV+", "+ppmmV+" pixel/mm");
}
- fontNameBox = font.getMetricBounds(fontName, FontScale.toPixels(fontSizeFName, dpiV));
+ fontNameBox = font.getMetricBounds(fontName);
setHeadBox(headType, true);
}
@@ -322,7 +323,7 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
// bottom, half line up
pmv.glTranslatef(nearPlaneX0, nearPlaneY0+(nearPlaneS * pixelSizeFPS / 2f), nearPlaneZ0);
{
- final float sxy = ( nearPlaneS * pixelSizeFPS ) / font.getMetrics().getUnitsPerEM();
+ final float sxy = nearPlaneS * pixelSizeFPS;
pmv.glScalef(sxy, sxy, 1.0f);
}
// No cache, keep region alive!
@@ -330,21 +331,21 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
textRegionUtil.tempT2);
}
- float dx = width-fontNameBox.getWidth()-font.getAdvanceWidth(Glyph.ID_SPACE, pixelSizeFName);
- float dy = height-fontNameBox.getHeight();
+ float dx = width - ( fontNameBox.getWidth() - font.getAdvanceWidth(Glyph.ID_SPACE) ) * pixelSizeFName;
+ float dy = height - fontNameBox.getHeight() * pixelSizeFName;
pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
pmv.glLoadIdentity();
pmv.glTranslatef(nearPlaneX0+(dx*nearPlaneSx), nearPlaneY0+(dy*nearPlaneSy), nearPlaneZ0);
{
- final float sxy = ( nearPlaneS * pixelSizeFName ) / font.getMetrics().getUnitsPerEM();
+ final float sxy = nearPlaneS * pixelSizeFName;
pmv.glScalef(sxy, sxy, 1.0f);
}
// System.err.printf("FontN: [%f %f] -> [%f %f]%n", dx, dy, nearPlaneX0+(dx*nearPlaneSx), nearPlaneY0+(dy*nearPlaneSy));
textRegionUtil.drawString3D(gl, renderer, font, fontName, null, getSampleCount());
dx = 10f;
- dy += -fontNameBox.getHeight() - 10f;
+ dy += -fontNameBox.getHeight() * pixelSizeFName - 10f;
if(null != headtext) {
pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
@@ -352,14 +353,14 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
// System.err.printf("Head: [%f %f] -> [%f %f]%n", dx, dy, nearPlaneX0+(dx*nearPlaneSx), nearPlaneY0+(dy*nearPlaneSy));
pmv.glTranslatef(nearPlaneX0+(dx*nearPlaneSx), nearPlaneY0+(dy*nearPlaneSy), nearPlaneZ0);
{
- final float sxy = ( nearPlaneS * pixelSizeHead ) / font.getMetrics().getUnitsPerEM();
+ final float sxy = nearPlaneS * pixelSizeHead;
pmv.glScalef(sxy, sxy, 1.0f);
}
// pmv.glTranslatef(x0, y1, z0);
textRegionUtil.drawString3D(gl, renderer, font, headtext, null, getSampleCount());
}
- dy += -headbox.getHeight() - font.getLineHeight(pixelSizeCenter);
+ dy += ( -headbox.getHeight() - font.getLineHeight() ) * pixelSizeCenter;
pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
pmv.glLoadIdentity();
@@ -368,7 +369,7 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
pmv.glTranslatef(getXTran(), getYTran(), getZTran());
pmv.glRotatef(getAngle(), 0, 1, 0);
{
- final float sxy = ( nearPlaneS * pixelSizeCenter ) / font.getMetrics().getUnitsPerEM();
+ final float sxy = nearPlaneS * pixelSizeCenter;
pmv.glScalef(sxy, sxy, 1.0f);
}
rs.setColorStatic(0.9f, 0.0f, 0.0f, 1.0f);
@@ -406,7 +407,7 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
public void fontHeadIncr(final int v) {
fontSizeHead = Math.abs((fontSizeHead + v) % fontSizeModulo) ;
if(null != headtext) {
- headbox = font.getMetricBounds(headtext, FontScale.toPixels(fontSizeHead, dpiV));
+ headbox = font.getMetricBounds(headtext);
}
}
@@ -418,7 +419,7 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
fontSet = set;
font = _font;
fontName = font.getFullFamilyName();
- fontNameBox = font.getMetricBounds(fontName, FontScale.toPixels(fontSizeFName, dpiV));
+ fontNameBox = font.getMetricBounds(fontName);
return true;
}
} catch (final IOException ex) {
@@ -434,7 +435,7 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
fontSet = set;
font = _font;
fontName = font.getFullFamilyName()+" (head "+fontSizeHead+"pt)";
- fontNameBox = font.getMetricBounds(fontName, FontScale.toPixels(fontSizeFName, dpiV));
+ fontNameBox = font.getMetricBounds(fontName);
return true;
}
} catch (final IOException ex) {
@@ -448,7 +449,8 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB
void dumpMatrix(final boolean bbox) {
System.err.println("Matrix: " + getXTran() + "/" + getYTran() + " x"+getZTran() + " @"+getAngle() +" fontSize "+fontSizeCenter);
if(bbox) {
- System.err.println("bbox: "+font.getMetricBounds(text2, nearPlaneS * FontScale.toPixels(fontSizeCenter, dpiV)));
+ System.err.println("bbox em: "+font.getMetricBounds(text2));
+ System.err.println("bbox px: "+font.getMetricBounds(text2).scale(nearPlaneS * FontScale.toPixels(fontSizeCenter, dpiV), new float[3]));
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java
index e92f18995..1a74264cd 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java
@@ -80,9 +80,9 @@ public class GPUUISceneGLListener0A implements GLEventListener {
private final float buttonXSizePVP = 0.105f;
private final float fontSizePt = 10f;
/** Proportional Font Size to Window Height for Main Text, per-vertical-pixels [PVP] */
- private final float fontSizeFixedPVP = 0.046f;
+ private final float fontSizeFixedPVP = 0.03f;
/** Proportional Font Size to Window Height for FPS Status Line, per-vertical-pixels [PVP] */
- private final float fontSizeFpsPVP = 0.038f;
+ private final float fontSizeFpsPVP = 0.03f;
private float dpiH = 96;
/**
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java
index f7e6e3de9..eb86aba81 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java
@@ -71,7 +71,7 @@ public class Label extends UIShape {
}
public float getLineHeight() {
- return font.getLineHeight(pixelSize);
+ return pixelSize * font.getLineHeight();
}
public void setPixelSize(final float pixelSize) {
@@ -102,13 +102,11 @@ public class Label extends UIShape {
@Override
protected void addShapeToRegion(final GL2ES2 gl, final RegionRenderer renderer) {
- final AffineTransform t_sxy = new AffineTransform(); // FIXME ?
- final float sxy = pixelSize / font.getMetrics().getUnitsPerEM();
- t_sxy.setToScale(sxy, sxy);
+ final AffineTransform t_sxy = new AffineTransform();
+ t_sxy.setToScale(pixelSize, pixelSize);
TextRegionUtil.processString(shapeVisitor, t_sxy, font, text, tempT1, tempT2);
final float[] ctr = box.getCenter();
setRotationOrigin( ctr[0], ctr[1], ctr[2]);
- // scale(sxy, sxy, 1f);
}
@Override
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label0.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label0.java
index 6641ce8b4..c43714b31 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label0.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label0.java
@@ -77,25 +77,21 @@ public class Label0 {
private final TextRegionUtil.ShapeVisitor shapeVisitor = new TextRegionUtil.ShapeVisitor() {
@Override
public void visit(final OutlineShape shape, final AffineTransform t) {
- final AffineTransform t1 = t.preConcatenate(tLeft);
- region.addOutlineShape(shape, t1, rgbaColor);
- box.resize(shape.getBounds(), t1, tmpV3);
+ region.addOutlineShape(shape, t, rgbaColor);
+ box.resize(shape.getBounds(), t, tmpV3);
}
};
private Region region;
- private AffineTransform tLeft;
public final AABBox addShapeToRegion(final float pixelSize, final Region region, final AffineTransform tLeft) {
box.reset();
this.region = region;
- this.tLeft = tLeft;
- final AffineTransform t_sxy = new AffineTransform(); // FIXME ?
- final float sxy = pixelSize / font.getMetrics().getUnitsPerEM();
- t_sxy.setToScale(sxy, sxy);
+ final AffineTransform t_sxy = new AffineTransform(tLeft);
+ final AffineTransform tmp = new AffineTransform();
+ t_sxy.scale(pixelSize, pixelSize, tmp);
TextRegionUtil.processString(shapeVisitor, t_sxy, font, text, tempT1, tempT2);
this.region = null;
- this.tLeft = null;
return box;
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/LabelButton.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/LabelButton.java
index 39eab26e2..db1ec239a 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/LabelButton.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/LabelButton.java
@@ -94,28 +94,31 @@ public class LabelButton extends RoundButton {
final float lPixelSize0 = 10f;
final float lw = width * ( 1f - spacingX ) ;
final float lh = height * ( 1f - spacingY ) ;
- final AABBox lbox0 = label.font.getMetricBounds(label.text, lPixelSize0);
- final float lsx = lw / lbox0.getWidth();
- final float lsy = lh / lbox0.getHeight();
- final float lPixelSize1 = lsx < lsy ? lPixelSize0 * lsx : lPixelSize0 * lsy;
+ final AABBox lbox0_em = label.font.getMetricBounds(label.text);
+ final float lsx = lw / lbox0_em.getWidth();
+ final float lsy = lh / lbox0_em.getHeight();
+ final float lPixelSize1 = lsx < lsy ? lsx : lsy;
if( DRAW_DEBUG_BOX ) {
- System.err.println("RIButton: spacing "+spacingX+", "+spacingY);
- System.err.println("RIButton: bbox "+box);
- System.err.println("RIButton: lbox "+lbox0+", "+label.text);
- System.err.println("RIButton: net-text "+lw+" x "+lh);
- System.err.println("RIButton: lsx "+lsx+", lsy "+lsy+": pixelSize "+lPixelSize0+" -> "+lPixelSize1);
+ final AABBox lbox0_px = new AABBox(lbox0_em).scale2(lPixelSize0, new float[3]);
+ System.err.println("RIButton: dim "+width+" x "+height+", spacing "+spacingX+", "+spacingY);
+ System.err.println("RIButton: net-text "+lw+" x "+lh+" px");
+ System.err.println("RIButton: shape "+box+" px");
+ System.err.println("RIButton: text "+lbox0_em+" em, "+label.text);
+ System.err.println("RIButton: text "+lbox0_px+" px, "+label.text);
+ System.err.println("RIButton: lscale "+lsx+" x "+lsy+": pixelSize "+lPixelSize0+" -> "+lPixelSize1);
}
- // Setting pixelSize based on actual text-box size
- final AABBox lbox1 = label.font.getPointsBounds(null, label.text, lPixelSize1);
+ // Setting left-corner transform using text-box in font em-size [0..1]
+ final AABBox lbox1_s = label.font.getPointsBounds(null, label.text).scale2(lPixelSize1, new float[3]);
// Center text .. (share same center w/ button)
- final float[] lctr = lbox1.getCenter();
+ final float[] lctr = lbox1_s.getCenter();
final float[] ctr = box.getCenter();
final float[] ltx = new float[] { ctr[0] - lctr[0], ctr[1] - lctr[1], 0f };
final AABBox lbox2 = label.addShapeToRegion(lPixelSize1, region, tempT1.setToTranslation(ltx[0], ltx[1]));
if( DRAW_DEBUG_BOX ) {
- System.err.printf("RIButton.0: lbox1 %s%n", lbox1);
+ System.err.printf("RIButton.0: tleft %f / %f, %f / %f%n", ltx[0], ltx[1], ltx[0] * lPixelSize1, ltx[1] * lPixelSize1);
+ System.err.printf("RIButton.0: lbox1 %s scaled%n", lbox1_s);
System.err.printf("RIButton.0: lbox2 %s%n", lbox2);
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java
deleted file mode 100644
index 12f9793dc..000000000
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIGLListener01.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/**
- * Copyright 2010 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification, are
- * permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those of the
- * authors and should not be interpreted as representing official policies, either expressed
- * or implied, of JogAmp Community.
- */
-
-package com.jogamp.opengl.test.junit.graph.demos.ui;
-
-import java.io.IOException;
-
-import com.jogamp.opengl.GL;
-import com.jogamp.opengl.GL2ES2;
-import com.jogamp.opengl.GLAutoDrawable;
-import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
-
-import com.jogamp.graph.curve.opengl.RegionRenderer;
-import com.jogamp.graph.curve.opengl.RenderState;
-import com.jogamp.graph.font.Font;
-import com.jogamp.graph.font.FontFactory;
-import com.jogamp.graph.geom.SVertex;
-import com.jogamp.opengl.test.junit.graph.demos.MSAATool;
-import com.jogamp.opengl.util.PMVMatrix;
-
-public class UIGLListener01 extends UIListenerBase01 {
-
- public UIGLListener01 (final int renderModes, final RenderState rs, final boolean debug, final boolean trace) {
- super(renderModes, RegionRenderer.create(rs, RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable), debug, trace);
- setMatrix(-20, 00, 0f, -50);
- try {
- final Font font = FontFactory.get(FontFactory.UBUNTU).getDefault();
- button = new LabelButton(SVertex.factory(), 0, font, "Click me!", 4f, 3f);
- button.translate(2,1,0);
- /** Button defaults !
- button.setLabelColor(1.0f,1.0f,1.0f);
- button.setButtonColor(0.6f,0.6f,0.6f);
- button.setCorner(1.0f);
- button.setSpacing(2.0f);
- */
- System.err.println(button);
- } catch (final IOException ex) {
- System.err.println("Caught: "+ex.getMessage());
- ex.printStackTrace();
- }
- }
-
- @Override
- public void init(final GLAutoDrawable drawable) {
- super.init(drawable);
-
- final GL2ES2 gl = drawable.getGL().getGL2ES2();
-
- gl.setSwapInterval(1);
- gl.glEnable(GL.GL_DEPTH_TEST);
- gl.glEnable(GL.GL_POLYGON_OFFSET_FILL);
-
- MSAATool.dump(drawable);
- }
-
- @Override
- public void display(final GLAutoDrawable drawable) {
- final GL2ES2 gl = drawable.getGL().getGL2ES2();
-
- gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
- gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
-
- final int[] sampleCount = { 4 };
- final float[] translate = button.getTranslate();
-
- final RegionRenderer regionRenderer = getRegionRenderer();
- final PMVMatrix pmv = regionRenderer.getMatrix();
- pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
- pmv.glLoadIdentity();
- pmv.glTranslatef(getXTran(), getYTran(), getZoom());
- pmv.glRotatef(getAngle(), 0, 1, 0);
- pmv.glTranslatef(translate[0], translate[1], 0);
- button.drawShape(gl, regionRenderer, sampleCount);
- }
-
- @Override
- public void dispose(final GLAutoDrawable drawable) {
- final GL2ES2 gl = drawable.getGL().getGL2ES2();
- button.destroy(gl, getRegionRenderer());
- super.dispose(drawable);
- }
-}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListener01.java
index ab5bfb926..f18491a2a 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListenerBase01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIListener01.java
@@ -41,15 +41,21 @@ import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLException;
import com.jogamp.opengl.GLPipelineFactory;
import com.jogamp.opengl.GLRunnable;
-
+import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
+import com.jogamp.opengl.test.junit.graph.demos.MSAATool;
import com.jogamp.graph.curve.Region;
import com.jogamp.graph.curve.opengl.RegionRenderer;
+import com.jogamp.graph.curve.opengl.RenderState;
+import com.jogamp.graph.font.Font;
+import com.jogamp.graph.font.FontFactory;
+import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.KeyListener;
import com.jogamp.newt.event.MouseEvent;
import com.jogamp.newt.event.MouseListener;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.util.GLReadBufferUtil;
+import com.jogamp.opengl.util.PMVMatrix;
/**
*
@@ -61,7 +67,7 @@ import com.jogamp.opengl.util.GLReadBufferUtil;
* - v: toggle v-sync
* - s: screenshot
*/
-public abstract class UIListenerBase01 implements GLEventListener {
+public class UIListener01 implements GLEventListener {
private final GLReadBufferUtil screenshot;
private final int renderModes;
private final RegionRenderer rRenderer;
@@ -84,12 +90,29 @@ public abstract class UIListenerBase01 implements GLEventListener {
boolean ignoreInput = false;
- public UIListenerBase01(final int renderModes, final RegionRenderer rRenderer, final boolean debug, final boolean trace) {
+ public UIListener01(final int renderModes, final RenderState rs, final boolean debug, final boolean trace) {
this.renderModes = renderModes;
- this.rRenderer = rRenderer;
+ this.rRenderer = RegionRenderer.create(rs, RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
this.debug = debug;
this.trace = trace;
this.screenshot = new GLReadBufferUtil(false, false);
+
+ setMatrix(-4, -2, 0f, -10);
+ try {
+ final Font font = FontFactory.get(FontFactory.UBUNTU).getDefault();
+ button = new LabelButton(SVertex.factory(), 0, font, "Click me!", 4f, 2f);
+ button.translate(2,1,0);
+ /** Button defaults !
+ button.setLabelColor(1.0f,1.0f,1.0f);
+ button.setButtonColor(0.6f,0.6f,0.6f);
+ button.setCorner(1.0f);
+ button.setSpacing(2.0f);
+ */
+ System.err.println(button);
+ } catch (final IOException ex) {
+ System.err.println("Caught: "+ex.getMessage());
+ ex.printStackTrace();
+ }
}
public final RegionRenderer getRegionRenderer() { return rRenderer; }
@@ -106,6 +129,7 @@ public abstract class UIListenerBase01 implements GLEventListener {
this.zoom = zoom;
}
+ @Override
public void init(final GLAutoDrawable drawable) {
autoDrawable = drawable;
GL2ES2 gl = drawable.getGL().getGL2ES2();
@@ -117,8 +141,14 @@ public abstract class UIListenerBase01 implements GLEventListener {
}
gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
getRegionRenderer().init(gl, renderModes);
+
+ gl.setSwapInterval(1);
+ gl.glEnable(GL.GL_DEPTH_TEST);
+ gl.glEnable(GL.GL_POLYGON_OFFSET_FILL);
+ MSAATool.dump(drawable);
}
+ @Override
public void reshape(final GLAutoDrawable drawable, final int xstart, final int ystart, final int width, final int height) {
final GL2ES2 gl = drawable.getGL().getGL2ES2();
@@ -127,9 +157,32 @@ public abstract class UIListenerBase01 implements GLEventListener {
dumpMatrix();
}
+ @Override
+ public void display(final GLAutoDrawable drawable) {
+ final GL2ES2 gl = drawable.getGL().getGL2ES2();
+
+ gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+
+ final int[] sampleCount = { 4 };
+ final float[] translate = button.getTranslate();
+
+ final RegionRenderer regionRenderer = getRegionRenderer();
+ final PMVMatrix pmv = regionRenderer.getMatrix();
+ pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
+ pmv.glLoadIdentity();
+ pmv.glTranslatef(getXTran(), getYTran(), getZoom());
+ pmv.glRotatef(getAngle(), 0, 1, 0);
+ pmv.glTranslatef(translate[0], translate[1], 0);
+ button.drawShape(gl, regionRenderer, sampleCount);
+ }
+
+ @Override
public void dispose(final GLAutoDrawable drawable) {
- autoDrawable = null;
final GL2ES2 gl = drawable.getGL().getGL2ES2();
+ button.destroy(gl, getRegionRenderer());
+
+ autoDrawable = null;
screenshot.dispose(gl);
rRenderer.destroy(gl);
}
@@ -200,36 +253,44 @@ public abstract class UIListenerBase01 implements GLEventListener {
public class MouseAction implements MouseListener{
+ @Override
public void mouseClicked(final MouseEvent e) {
}
+ @Override
public void mouseEntered(final MouseEvent e) {
}
+ @Override
public void mouseExited(final MouseEvent e) {
}
+ @Override
public void mousePressed(final MouseEvent e) {
button.setLabelColor(0.8f,0.8f,0.8f);
button.setColor(0.1f, 0.1f, 0.1f, 1.0f);
}
+ @Override
public void mouseReleased(final MouseEvent e) {
button.setLabelColor(1.0f,1.0f,1.0f);
button.setColor(0.6f,0.6f,0.6f, 1.0f);
}
+ @Override
public void mouseMoved(final MouseEvent e) {
// TODO Auto-generated method stub
}
+ @Override
public void mouseDragged(final MouseEvent e) {
// TODO Auto-generated method stub
}
+ @Override
public void mouseWheelMoved(final MouseEvent e) {
// TODO Auto-generated method stub
@@ -238,28 +299,29 @@ public abstract class UIListenerBase01 implements GLEventListener {
}
public class KeyAction implements KeyListener {
+ @Override
public void keyPressed(final KeyEvent arg0) {
if(ignoreInput) {
return;
}
if(arg0.getKeyCode() == KeyEvent.VK_1){
- zoom(10);
+ zoom(2);
}
else if(arg0.getKeyCode() == KeyEvent.VK_2){
- zoom(-10);
+ zoom(-2);
}
else if(arg0.getKeyCode() == KeyEvent.VK_UP){
- move(0, -1);
+ move(0, 1);
}
else if(arg0.getKeyCode() == KeyEvent.VK_DOWN){
- move(0, 1);
+ move(0, -1);
}
else if(arg0.getKeyCode() == KeyEvent.VK_LEFT){
- move(1, 0);
+ move(-1, 0);
}
else if(arg0.getKeyCode() == KeyEvent.VK_RIGHT){
- move(-1, 0);
+ move(1, 0);
}
else if(arg0.getKeyCode() == KeyEvent.VK_4){
button.setSpacing(button.getSpacingX()-0.01f, button.getSpacingY()-0.005f);
@@ -316,6 +378,7 @@ public abstract class UIListenerBase01 implements GLEventListener {
rotate(-1);
if(null != autoDrawable) {
autoDrawable.invoke(false, new GLRunnable() {
+ @Override
public boolean run(final GLAutoDrawable drawable) {
try {
final String type = Region.getRenderModeString(renderModes);
@@ -332,6 +395,7 @@ public abstract class UIListenerBase01 implements GLEventListener {
}
}
}
+ @Override
public void keyReleased(final KeyEvent arg0) {}
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java
index 88dc1615f..d211a9b80 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java
@@ -30,7 +30,7 @@ package com.jogamp.opengl.test.junit.graph.demos.ui;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLProfile;
-
+import com.jogamp.common.util.InterruptSource;
import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.graph.geom.SVertex;
import com.jogamp.newt.event.KeyAdapter;
@@ -64,7 +64,7 @@ public class UINewtDemo01 {
window.setSize(800, 400);
window.setTitle("GPU UI Newt Demo 01");
final RenderState rs = RenderState.createRenderState(SVertex.factory());
- final UIGLListener01 uiGLListener = new UIGLListener01 (0, rs, DEBUG, TRACE);
+ final UIListener01 uiGLListener = new UIListener01 (0, rs, DEBUG, TRACE);
uiGLListener.attachInputListenerTo(window);
window.addGLEventListener(uiGLListener);
window.setVisible(true);
@@ -74,13 +74,19 @@ public class UINewtDemo01 {
animator.add(window);
window.addKeyListener(new KeyAdapter() {
+ @Override
public void keyPressed(final KeyEvent arg0) {
if(arg0.getKeyCode() == KeyEvent.VK_F4) {
- window.destroy();
+ new InterruptSource.Thread() {
+ @Override
+ public void run() {
+ window.destroy();
+ } }.start();
}
}
});
window.addWindowListener(new WindowAdapter() {
+ @Override
public void windowDestroyed(final WindowEvent e) {
animator.stop();
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java
index 716712d22..4976c78e8 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java
@@ -48,7 +48,7 @@ import com.jogamp.opengl.math.Quaternion;
import com.jogamp.opengl.math.geom.AABBox;
public abstract class UIShape {
- public static final boolean DRAW_DEBUG_BOX = false;
+ public static final boolean DRAW_DEBUG_BOX = true;
protected static final int DIRTY_SHAPE = 1 << 0 ;
protected static final int DIRTY_STATE = 1 << 1 ;
@@ -280,7 +280,7 @@ public abstract class UIShape {
region.clear(gl);
}
addShapeToRegion(gl, renderer);
- if( DRAW_DEBUG_BOX ) {
+ if( false && DRAW_DEBUG_BOX ) {
region.clear(gl);
final OutlineShape shape = new OutlineShape(renderer.getRenderState().getVertexFactory());
shape.setSharpness(shapesSharpness);
@@ -436,6 +436,7 @@ public abstract class UIShape {
this.objPos = objPos;
}
+ @Override
public String toString() {
return "EventDetails[winPos ["+glWinX+", "+glWinY+"], objPos ["+objPos[0]+", "+objPos[1]+", "+objPos[2]+"], "+shape+"]";
}