diff options
Diffstat (limited to 'src')
7 files changed, 90 insertions, 35 deletions
diff --git a/src/demos/com/jogamp/opengl/demos/graph/GPUTextNewtDemo.java b/src/demos/com/jogamp/opengl/demos/graph/GPUTextNewtDemo.java index 3f60ef8a2..bbdf4bfbb 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/GPUTextNewtDemo.java +++ b/src/demos/com/jogamp/opengl/demos/graph/GPUTextNewtDemo.java @@ -72,20 +72,20 @@ public class GPUTextNewtDemo { int width = 800, height = 400; int x = 10, y = 10; if( 0 != args.length ) { - SceneMSAASamples = 0; - GraphMSAASamples = 0; - GraphVBAASamples = 0; - for(int i=0; i<args.length; i++) { if(args[i].equals("-smsaa")) { i++; SceneMSAASamples = MiscUtils.atoi(args[i], SceneMSAASamples); + GraphMSAASamples = 0; + GraphVBAASamples = 0; } else if(args[i].equals("-gmsaa")) { i++; + SceneMSAASamples = 0; GraphMSAASamples = MiscUtils.atoi(args[i], GraphMSAASamples); GraphVBAASamples = 0; } else if(args[i].equals("-gvbaa")) { i++; + SceneMSAASamples = 0; GraphMSAASamples = 0; GraphVBAASamples = MiscUtils.atoi(args[i], GraphVBAASamples); } else if(args[i].equals("-width")) { diff --git a/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/Label.java b/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/Label.java index e55526fd7..17ea3ad4e 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/Label.java +++ b/src/graphui/classes/com/jogamp/graph/ui/gl/shapes/Label.java @@ -34,6 +34,7 @@ import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.curve.opengl.GLRegion; import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.graph.font.Font; +import com.jogamp.graph.font.Font.Glyph; import com.jogamp.graph.geom.plane.AffineTransform; import com.jogamp.graph.ui.gl.Shape; @@ -159,9 +160,13 @@ public class Label extends Shape { return GLRegion.create(glp, getRenderModes(), null, font, text); } - private final OutlineShape.Visitor shapeVisitor = new OutlineShape.Visitor() { + private final Font.GlyphVisitor glyphVisitor = new Font.GlyphVisitor() { @Override - public void visit(final OutlineShape shape, final AffineTransform t) { + public void visit(final Glyph glyph, final AffineTransform t) { + if( glyph.isWhiteSpace() ) { + return; + } + final OutlineShape shape = glyph.getShape(); shape.setSharpness(oshapeSharpness); try { region.addOutlineShape(shape, t, rgbaColor); @@ -178,7 +183,7 @@ public class Label extends Shape { @Override protected void addShapeToRegion() { tempT1.setToScale(fontScale, fontScale); - final AABBox fbox = font.processString(shapeVisitor, tempT1, text, tempT2, tempT3); + final AABBox fbox = font.processString(glyphVisitor, tempT1, text, tempT2, tempT3); final float[] ctr = fbox.getCenter(); setRotationOrigin( ctr[0], ctr[1], ctr[2]); box.copy(fbox); diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java index aca5fca52..aa756582a 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java @@ -150,10 +150,10 @@ public abstract class GLRegion extends Region { region = new VBORegionSPES2(glp, renderModes, colorTexSeq, 0, 0);
}
final int[] vertIndexCount = { 0, 0 };
- final OutlineShape.Visitor2 visitor = new OutlineShape.Visitor2() {
+ final Font.GlyphVisitor2 visitor = new Font.GlyphVisitor2() {
@Override
- public final void visit(final OutlineShape shape) {
- region.countOutlineShape(shape, vertIndexCount);
+ public final void visit(final Font.Glyph glyph) {
+ region.countOutlineShape(glyph.getShape(), vertIndexCount);
} };
font.processString(visitor, str);
region.setBufferCapacity(vertIndexCount[0], vertIndexCount[1]);
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 de9ff5636..35b6d5028 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java @@ -37,6 +37,7 @@ import com.jogamp.opengl.math.geom.AABBox; import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.curve.Region; import com.jogamp.graph.font.Font; +import com.jogamp.graph.font.Font.Glyph; import com.jogamp.graph.geom.plane.AffineTransform; /** @@ -106,11 +107,15 @@ public class TextRegionUtil { public static AABBox addStringToRegion(final Region region, final Font font, final AffineTransform transform, final CharSequence str, final float[] rgbaColor, final AffineTransform temp1, final AffineTransform temp2) { - final OutlineShape.Visitor visitor = new OutlineShape.Visitor() { + final Font.GlyphVisitor visitor = new Font.GlyphVisitor() { @Override - public final void visit(final OutlineShape shape, final AffineTransform t) { - region.addOutlineShape(shape, t, region.hasColorChannel() ? rgbaColor : null); - } }; + public void visit(final Glyph glyph, final AffineTransform t) { + if( glyph.isWhiteSpace() ) { + return; + } + region.addOutlineShape(glyph.getShape(), t, region.hasColorChannel() ? rgbaColor : null); + } + }; return font.processString(visitor, transform, str, temp1, temp2); } @@ -128,10 +133,10 @@ public class TextRegionUtil { * @see #drawString3D(GL2ES2, GLRegion, RegionRenderer, Font, CharSequence, float[], int[], AffineTransform, AffineTransform) */ public static void countStringRegion(final Region region, final Font font, final CharSequence str, final int[/*2*/] vertIndexCount) { - final OutlineShape.Visitor2 visitor = new OutlineShape.Visitor2() { + final Font.GlyphVisitor2 visitor = new Font.GlyphVisitor2() { @Override - public final void visit(final OutlineShape shape) { - region.countOutlineShape(shape, vertIndexCount); + public final void visit(final Font.Glyph glyph) { + region.countOutlineShape(glyph.getShape(), vertIndexCount); } }; font.processString(visitor, str); } diff --git a/src/jogl/classes/com/jogamp/graph/font/Font.java b/src/jogl/classes/com/jogamp/graph/font/Font.java index 1b5452a45..2a75a203f 100644 --- a/src/jogl/classes/com/jogamp/graph/font/Font.java +++ b/src/jogl/classes/com/jogamp/graph/font/Font.java @@ -172,6 +172,9 @@ public interface Font { /** Return the glyph's name, source from `post` table */ String getName(); + /** Return true if the underlying {@link #getShape()} is a whitespace, otherwise false. */ + boolean isWhiteSpace(); + /** * Return the AABBox in font-units, borrowing internal instance. */ @@ -246,6 +249,30 @@ public interface Font { String fullString(); } + /** + * General purpose {@link Font.Glyph} visitor. + */ + public static interface GlyphVisitor { + /** + * Visiting the given {@link Font.Glyph} having an {@link OutlineShape} with it's corresponding {@link AffineTransform}. + * @param glyph {@link Font.Glyph} which contains an {@link OutlineShape} via {@link Font.Glyph#getShape()}. + * @param t may be used immediately as is, otherwise a copy shall be made if stored. + */ + public void visit(final Glyph glyph, final AffineTransform t); + } + + /** + * Constrained {@link Font.Glyph} visitor w/o {@link AffineTransform}. + */ + public static interface GlyphVisitor2 { + /** + * Visiting the given {@link Font.Glyph} having an {@link OutlineShape}. + * @param glyph {@link Font.Glyph} which contains an {@link OutlineShape} via {@link Font.Glyph#getShape()}. + */ + public void visit(final Glyph glyph); + } + + String getName(final int nameIndex); /** Shall return the family and subfamily name, separated a dash. @@ -417,39 +444,41 @@ public interface Font { boolean isPrintableChar(final char c); /** - * Try using {@link #processString(com.jogamp.graph.curve.OutlineShape.Visitor, AffineTransform, CharSequence, AffineTransform, AffineTransform)} + * Try using {@link #processString(GlyphVisitor, AffineTransform, CharSequence, AffineTransform, AffineTransform)} * to reuse {@link AffineTransform} instances. + * @see #processString(GlyphVisitor, AffineTransform, CharSequence, AffineTransform, AffineTransform) */ - AABBox processString(final OutlineShape.Visitor visitor, final AffineTransform transform, + AABBox processString(final Font.GlyphVisitor visitor, final AffineTransform transform, final CharSequence string); /** - * Visit each {@link Glyph}'s {@link OutlineShape} of the string with the {@link OutlineShape.Visitor} + * Visit each {@link Glyph} and perhaps its {@link OutlineShape} of the string with the {@link Font.GlyphVisitor} * while passing the progressed {@link AffineTransform}. * <p> * The processed 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 handling each glyph's outline shape in font em-size [0..1] and the given {@link AffineTransform} - * @param transform optional given transform + * @param visitor handling each {@link Font.Glyph} and perhaps its {@link OutlineShape} in font em-size [0..1] and the given {@link AffineTransform} + * @param transform optional given transform for size and position * @param font the target {@link Font} * @param string string text * @param temp1 temporary AffineTransform storage, mandatory * @param temp2 temporary AffineTransform storage, mandatory * @return the bounding box of the given string by taking each glyph's font em-sized [0..1] {@link OutlineShape} into account. + * @see #processString(GlyphVisitor, AffineTransform, CharSequence) */ - AABBox processString(final OutlineShape.Visitor visitor, final AffineTransform transform, + AABBox processString(final Font.GlyphVisitor visitor, final AffineTransform transform, final CharSequence string, final AffineTransform temp1, final AffineTransform temp2); /** - * Visit each {@link Glyph}'s {@link OutlineShape} of the string with the constrained {@link OutlineShape.Visitor2}. + * Visit each {@link Glyph} and perhaps its {@link OutlineShape} of the string with the constrained {@link Font.GlyphVisitor2}. * <p> * The processed shapes are in font em-size [0..1]. * </p> - * @param visitor handling each glyph's outline shape in font em-size [0..1] + * @param visitor handling each {@link Font.Glyph} and perhaps its {@link OutlineShape} in font em-size [0..1] * @param string string text */ - void processString(final OutlineShape.Visitor2 visitor, final CharSequence string); + void processString(final Font.GlyphVisitor2 visitor, final CharSequence string); /** Returns {@link #getFullFamilyName()} */ @Override diff --git a/src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java b/src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java index 8b3b9dbf1..7aba7fa73 100644 --- a/src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java +++ b/src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java @@ -2129,6 +2129,16 @@ public final class FloatUtil { /** The value PI^2. */ public final static float SQUARED_PI = PI * PI; + /** Converts arc-degree to radians */ + public static float adegToRad(final float arc_degree) { + return arc_degree * PI / 180.0f; + } + + /** Converts radians to arc-degree */ + public static float radToADeg(final float rad) { + return rad * 180.0f / PI; + } + /** * Epsilon for floating point {@value}, as once computed via {@link #getMachineEpsilon()} on an AMD-64 CPU. * <p> diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java index ca27b9164..188d8d688 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java @@ -330,6 +330,10 @@ class TypecastFont implements Font { advanceTotal += glyph.getAdvanceFU(); left_glyph = null; // break kerning continue; + } else if( glyph.isWhiteSpace() ) { // covers 'space' and all non-contour symbols + advanceTotal += glyph.getAdvance(); + left_glyph = null; // break kerning + continue; } if( null != left_glyph ) { advanceTotal += left_glyph.getKerningFU(glyph_id); @@ -353,22 +357,22 @@ class TypecastFont implements Font { if (null == string || 0 == string.length() ) { return new AABBox(); } - final OutlineShape.Visitor visitor = new OutlineShape.Visitor() { + final Font.GlyphVisitor visitor = new Font.GlyphVisitor() { @Override - public final void visit(final OutlineShape shape, final AffineTransform t) { + public final void visit(final Font.Glyph shape, final AffineTransform t) { // nop } }; return processString(visitor, transform, string); } @Override - public AABBox processString(final OutlineShape.Visitor visitor, final AffineTransform transform, + public AABBox processString(final Font.GlyphVisitor visitor, final AffineTransform transform, final CharSequence string) { return processString(visitor, transform, string, new AffineTransform(), new AffineTransform()); } @Override - public AABBox processString(final OutlineShape.Visitor visitor, final AffineTransform transform, + public AABBox processString(final Font.GlyphVisitor visitor, final AffineTransform transform, final CharSequence string, final AffineTransform temp1, final AffineTransform temp2) { if (null == string || 0 == string.length() ) { @@ -407,13 +411,15 @@ class TypecastFont implements Font { advanceTotal += glyph.getAdvance(); left_glyph = null; // break kerning continue; + } else if( glyph.isWhiteSpace() ) { // covers 'space' and all non-contour symbols + left_glyph = null; // break kerning } if( null != left_glyph ) { advanceTotal += left_glyph.getKerning(glyph_id); } temp1.translate(advanceTotal, y, temp2); res.resize(temp1.transform(glyphShape.getBounds(), temp_box)); - visitor.visit(glyphShape, temp1); + visitor.visit(glyph, temp1); advanceTotal += glyph.getAdvance(); left_glyph = glyph; } @@ -422,7 +428,7 @@ class TypecastFont implements Font { } @Override - public void processString(final OutlineShape.Visitor2 visitor, final CharSequence string) { + public void processString(final Font.GlyphVisitor2 visitor, final CharSequence string) { if (null == string || 0 == string.length() ) { return; } @@ -431,9 +437,9 @@ class TypecastFont implements Font { for(int i=0; i< charCount; i++) { final char character = string.charAt(i); if( '\n' != character ) { - final OutlineShape glyphShape = getGlyph(getGlyphID(character)).getShape(); - if( null != glyphShape ) { // also covers 'space' and all non-contour symbols - visitor.visit(glyphShape); + final Glyph glyph = getGlyph(getGlyphID(character)); + if( null != glyph.getShape() ) { // also covers 'space' and all non-contour symbols + visitor.visit(glyph); } } } |