From da88b0f2ac0b09082222ce1a387987e8cdd5f21d Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 19 Feb 2023 05:12:04 +0100 Subject: Graph Font.Metrics: Use unchanges sign of (+) ascent, (-) descent and (+) lineGap, document them properly and fix Font.getLineHeightFU() --- .../test/junit/graph/TestTextRendererNEWT00.java | 285 +++++++++++++++++++++ .../test/junit/jogl/demos/es2/av/MovieCube.java | 6 +- 2 files changed, 288 insertions(+), 3 deletions(-) create mode 100644 src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java (limited to 'src/test/com') diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java new file mode 100644 index 000000000..07798e2ee --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT00.java @@ -0,0 +1,285 @@ +/** + * Copyright 2011-2023 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; + +import java.io.File; +import java.io.IOException; +import java.util.Locale; + +import com.jogamp.opengl.GL; +import com.jogamp.opengl.GL2ES2; +import com.jogamp.opengl.GLCapabilities; +import com.jogamp.opengl.GLDrawable; +import com.jogamp.opengl.GLException; +import com.jogamp.opengl.GLProfile; +import com.jogamp.opengl.fixedfunc.GLMatrixFunc; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; + +import com.jogamp.common.util.IOUtil; +import com.jogamp.graph.curve.Region; +import com.jogamp.graph.curve.opengl.RenderState; +import com.jogamp.graph.curve.opengl.GLRegion; +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; +import com.jogamp.opengl.test.junit.util.NEWTGLContext; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.GLReadBufferUtil; +import com.jogamp.opengl.util.PMVMatrix; + + +/** + * TestTextRendererNEWT00 Variant + * - No listener, all straight forward + * - Type Rendering via TextRegionUtil + * - Type Rendering vanilla via GLRegion, GLRegion.addOutlineShape(Font.processString()), .. + */ +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestTextRendererNEWT00 extends UITestCase { + static final boolean DEBUG = false; + static final boolean TRACE = false; + static long duration = 100; // ms + static boolean forceES2 = false; + 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; // in pixel + + @BeforeClass + public static void setup() throws IOException { + if( null == font ) { + font = FontFactory.get(FontFactory.UBUNTU).getDefault(); + } + } + + static int atoi(final String a) { + try { + return Integer.parseInt(a); + } catch (final Exception ex) { throw new RuntimeException(ex); } + } + + public static void main(final String args[]) throws IOException { + mainRun = true; + for(int i=0; i "+full_width_s); + System.err.println("XXX: full_height: "+full_height_o+" / "+txt_box_em.getHeight()+" -> "+full_height_s); + System.err.println("XXX: txt_scale: "+txt_scale); + System.err.println("XXX: txt_box_em "+txt_box_em); + System.err.println("XXX: txt_box_e2 "+txt_box_em2); + once = false; + } + } + 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); + renderString(drawable, gl, renderer, textRenderUtil, "I like JogAmp", 4, -1, -1000, sampleCountIO); + + int c = 0; + renderString(drawable, gl, renderer, textRenderUtil, "GlueGen", c++, -1, -1000, sampleCountIO); + renderString(drawable, gl, renderer, textRenderUtil, "JOAL", c++, -1, -1000, sampleCountIO); + renderString(drawable, gl, renderer, textRenderUtil, "JOGL", c++, -1, -1000, sampleCountIO); + renderString(drawable, gl, renderer, textRenderUtil, "JOCL", c++, -1, -1000, sampleCountIO); + } + gl.glFinish(); + printScreen(renderModes, drawable, gl, false, sampleCount); + drawable.swapBuffers(); + + sleep(); + + // dispose + screenshot.dispose(gl); + renderer.destroy(gl); + + NEWTGLContext.destroyWindow(winctx); + } + private boolean once = true; + + private GLReadBufferUtil screenshot; + int lastRow = -1; + + 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(); + + float dx = 0; + float dy = height; + if(0>row) { + row = lastRow + 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); + pmv.glScalef(fontSize, fontSize, 1.0f); + textRenderUtil.drawString3D(gl, renderer, font, text, null, sampleCount); + + lastRow = row; + } + + private int screenshot_num = 0; + + public void printScreen(final int renderModes, final GLDrawable drawable, final GL gl, final boolean exportAlpha, final int sampleCount) throws GLException, IOException { + final String dir = "./"; + final String objName = getSimpleTestName(".")+"-snap"+screenshot_num; + screenshot_num++; + 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(), + 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/jogl/demos/es2/av/MovieCube.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java index f4b0540fa..21cc6b7ef 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java @@ -203,9 +203,9 @@ public class MovieCube implements GLEventListener { pixelScale = 1.0f / ( pixelSize1 * 20f ); // underlineSize: 'underline' amount of pixel below 0/0 (Note: lineGap is negative) final Font.Metrics metrics = font.getMetrics(); - final float lineGap = pixelSize1 * metrics.getScale( metrics.getLineGapFU() ); - final float descent = pixelSize1 * metrics.getScale( metrics.getDescentFU() ); - underlineSize = descent - lineGap; + final float lineGap = pixelSize1 * metrics.getLineGap(); + final float descent = pixelSize1 * metrics.getDescent(); + underlineSize = lineGap - descent; System.err.println("XXX: dpiH "+dpiH+", fontSize "+fontSize1+", pixelSize "+pixelSize1+", pixelScale "+pixelScale+", fLG "+lineGap+", fDesc "+descent+", underlineSize "+underlineSize); } -- cgit v1.2.3