summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/graph
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-02-13 07:01:54 +0100
committerSven Gothel <[email protected]>2023-02-13 07:01:54 +0100
commit6d2009d33495a01ae3b59a4be6004c1a5e7007ad (patch)
tree1294462baa6b0ef3a2389e7fe6f4d878a0e8d4c1 /src/jogl/classes/com/jogamp/graph
parent93c51380f34c3eb203f46df52fed49a8a967510e (diff)
Graph Type Rendering: Drop pixelSize and use font em-size [0..1] throughout system.
- All pixelSize metrics methods are dropped in Font* - TypecastGlyph.Advance dropped, i.e. dropping prescales glyph advance based on pixelSize - TextRegionUtil produces OutlineShape in font em-size [0..1] added to GLRegion - Adjusted demos
Diffstat (limited to 'src/jogl/classes/com/jogamp/graph')
-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
2 files changed, 76 insertions, 97 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()} */