diff options
4 files changed, 15 insertions, 35 deletions
diff --git a/src/demos/com/jogamp/opengl/demos/graph/TextRendererGLELBase.java b/src/demos/com/jogamp/opengl/demos/graph/TextRendererGLELBase.java index 09a4546c6..d220114ab 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/TextRendererGLELBase.java +++ b/src/demos/com/jogamp/opengl/demos/graph/TextRendererGLELBase.java @@ -32,6 +32,7 @@ import java.io.IOException; import com.jogamp.opengl.GL2ES2; import com.jogamp.opengl.GLAutoDrawable; import com.jogamp.opengl.GLEventListener; +import com.jogamp.common.util.StringUtil; import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.GLRegion; import com.jogamp.graph.curve.opengl.RenderState; @@ -187,14 +188,14 @@ public abstract class TextRendererGLELBase implements GLEventListener { * @param cacheRegion */ public void renderString(final GLAutoDrawable drawable, - final Font font, final float pixelSize, final String text, + final Font font, final float pixelSize, final CharSequence text, final int column, final float tx, final float ty, final float tz, final boolean cacheRegion) { final int row = lastRow + 1; renderStringImpl(drawable, font, pixelSize, text, column, row, tx, ty, tz, cacheRegion, null); } public void renderString(final GLAutoDrawable drawable, - final Font font, final float pixelSize, final String text, + final Font font, final float pixelSize, final CharSequence text, final int column, final float tx, final float ty, final float tz, final GLRegion region) { final int row = lastRow + 1; renderStringImpl(drawable, font, pixelSize, text, column, row, tx, ty, tz, false, region); @@ -214,21 +215,21 @@ public abstract class TextRendererGLELBase implements GLEventListener { * @param cacheRegion */ public void renderString(final GLAutoDrawable drawable, - final Font font, final float pixelSize, final String text, + final Font font, final float pixelSize, final CharSequence text, final int column, final int row, final float tx, final float ty, final float tz, final boolean cacheRegion) { renderStringImpl(drawable, font, pixelSize, text, column, row, tx, ty, tz, cacheRegion, null); } public void renderString(final GLAutoDrawable drawable, - final Font font, final float pixelSize, final String text, + final Font font, final float pixelSize, final CharSequence text, final int column, final int row, final float tx, final float ty, final float tz, final GLRegion region) { renderStringImpl(drawable, font, pixelSize, text, column, row, tx, ty, tz, false, region); } private void renderStringImpl(final GLAutoDrawable drawable, - final Font font, final float pixelSize, final String text, + final Font font, final float pixelSize, final CharSequence text, final int column, final int row, final float tx, final float ty, final float tz, final boolean cacheRegion, final GLRegion region) { if( null != renderer ) { @@ -244,7 +245,7 @@ public abstract class TextRendererGLELBase implements GLEventListener { dy = height-ty; } final float sxy = pixelScale * pixelSize; - final int newLineCount = TextRegionUtil.getCharCount(text, '\n'); + final int newLineCount = StringUtil.getLineCount(text); final float lineHeight = font.getLineHeight(); dx += sxy * font.getAdvanceWidth( font.getGlyphID( 'X' ) ) * column; dy -= sxy * lineHeight * ( row + 1 ); @@ -278,9 +279,9 @@ public abstract class TextRendererGLELBase implements GLEventListener { } } public void renderRegion(final GLAutoDrawable drawable, - final Font font, final float pixelSize, - final int column, final int row, - final float tx, final float ty, final float tz, final GLRegion region) { + final Font font, final float pixelSize, + final int column, final int row, + final float tx, final float ty, final float tz, final GLRegion region) { if( null != renderer ) { final GL2ES2 gl = drawable.getGL().getGL2ES2(); 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 5d60e2686..b538d1546 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java @@ -55,17 +55,6 @@ public class TextRegionUtil { this.renderModes = renderModes; } - public static int getCharCount(final String s, final char c) { - final int sz = s.length(); - int count = 0; - for(int i=0; i<sz; i++) { - if( s.charAt(i) == c ) { - count++; - } - } - return count; - } - /** * Add the string in 3D space w.r.t. the font in font em-size [0..1] at the end of the {@link GLRegion} * while passing the progressed {@link AffineTransform}. diff --git a/src/jogl/classes/com/jogamp/opengl/util/av/SubTextEvent.java b/src/jogl/classes/com/jogamp/opengl/util/av/SubTextEvent.java index 622c5d29a..be8219634 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/av/SubTextEvent.java +++ b/src/jogl/classes/com/jogamp/opengl/util/av/SubTextEvent.java @@ -30,6 +30,7 @@ package com.jogamp.opengl.util.av; import java.time.format.DateTimeParseException; import com.jogamp.common.av.PTS; +import com.jogamp.common.util.StringUtil; /** * Text Event Line including ASS/SAA of {@link SubtitleEvent} @@ -215,19 +216,7 @@ public class SubTextEvent extends SubtitleEvent { this.name = name; this.effect = effect; this.text = text.replace("\\N", "\n"); - { - final int len = this.text.length(); - int lc = 1; - for(int i=0; len > i; ) { - final int j = this.text.indexOf("\n", i); - if( 0 > j ) { - break; - } - ++lc; - i = j + 1; - } - this.lines = lc; - } + this.lines = StringUtil.getLineCount(this.text); } @Override 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 a248dd810..6b5e09877 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/TextRendererGLELBase.java @@ -32,6 +32,7 @@ import java.io.IOException; import com.jogamp.opengl.GL2ES2; import com.jogamp.opengl.GLAutoDrawable; import com.jogamp.opengl.GLEventListener; +import com.jogamp.common.util.StringUtil; import com.jogamp.graph.curve.opengl.GLRegion; import com.jogamp.graph.curve.opengl.RenderState; import com.jogamp.graph.curve.opengl.RegionRenderer; @@ -222,7 +223,7 @@ public abstract class TextRendererGLELBase implements GLEventListener { } private void renderStringImpl(final GLAutoDrawable drawable, - final Font font, final float pixelSize, final String text, + final Font font, final float pixelSize, final CharSequence text, final int column, final int row, final float tx, final float ty, final float tz, final boolean cacheRegion, final GLRegion region) { if( null != renderer ) { @@ -238,7 +239,7 @@ public abstract class TextRendererGLELBase implements GLEventListener { dy = height-ty; } final float sxy = pixelScale * pixelSize; - final int newLineCount = TextRegionUtil.getCharCount(text, '\n'); + final int newLineCount = StringUtil.getLineCount(text); final float lineHeight = font.getLineHeight(); dx += sxy * font.getAdvanceWidth( font.getGlyphID( 'X' ) ) * column; dy -= sxy * lineHeight * ( row + 1 ); |