JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestFontsNEWT00.java
Go to the documentation of this file.
1/**
2 * Copyright 2012 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.opengl.test.junit.graph;
29
30import java.io.IOException;
31
32import org.junit.Assert;
33import org.junit.Test;
34import org.junit.FixMethodOrder;
35import org.junit.runners.MethodSorters;
36
37import com.jogamp.graph.font.Font;
38import com.jogamp.graph.font.FontScale;
39import com.jogamp.math.FloatUtil;
40import com.jogamp.math.geom.AABBox;
41import com.jogamp.opengl.test.junit.util.UITestCase;
42
43
44@FixMethodOrder(MethodSorters.NAME_ASCENDING)
45public class TestFontsNEWT00 extends UITestCase {
46 static boolean mainRun = false;
47
48 static int atoi(final String a) {
49 try {
50 return Integer.parseInt(a);
51 } catch (final Exception ex) { throw new RuntimeException(ex); }
52 }
53
54 public static void main(final String args[]) throws IOException {
55 mainRun = true;
56 final String tstname = TestFontsNEWT00.class.getName();
57 org.junit.runner.JUnitCore.main(tstname);
58 }
59
60 @Test
61 public void test00() throws InterruptedException, IOException {
62 testFontImpl(FontSet01.getSet01());
63 }
64 void testFontImpl(final Font[] fonts) throws InterruptedException, IOException {
65 final float fontSize = 10;
66 final float dpi = 96;
67 for(int i=0; i<fonts.length; i++) {
68 final Font font = fonts[i];
69 System.err.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
70 System.err.println(font.getAllNames(null, "\n"));
71 System.err.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
72 final float pixelSize = FontScale.toPixels(fontSize, dpi);
73 System.err.println(font.getFullFamilyName()+": "+fontSize+"p, "+dpi+"dpi -> "+pixelSize+"px:");
74 System.err.println(font.fullString());
75 testFontGlyph01(font, 'X', pixelSize);
76 testFontGlyph01(font, 'j', pixelSize);
77 testFontGlyph01(font, ' ', pixelSize);
78 testFontGlyph02(font, 'X', 'X');
79 testFontGlyph02(font, 't', '.');
80 testFontGlyph02(font, 'f', 'f');
81 }
82 }
83 void testFontGlyph01(final Font font, final char c, final float pixelSize) {
84 final Font.Glyph glyph = font.getGlyph( c );
85 final int s0 = font.getAdvanceWidthFU( glyph.getID() );
86 final int s1 = glyph.getAdvanceWidthFU();
87
88 final int unitsPerEM = font.getMetrics().getUnitsPerEM();
89
90 final float s0_em = font.getAdvanceWidth( glyph.getID() );
91 final float s1_em = glyph.getAdvanceWidth();
92
93 final float s0_px = s0_em * pixelSize;
94 final float s1_px = s1_em * pixelSize;
95
96 System.err.println(" Char '"+c+"', id "+glyph.getID()+", font-px "+pixelSize+", unitsPerEM "+unitsPerEM+":");
97 System.err.println(" "+glyph);
98 System.err.println(" Advance");
99 System.err.println(" funits "+s0+", "+s1);
100 System.err.println(" em "+s0_em+", "+s1_em);
101 System.err.println(" px "+s0_px+", "+s1_px);
102 System.err.println(" AABBox");
103 System.err.println(" funits "+glyph.getBoundsFU());
104 System.err.println(" em "+glyph.getBounds(new AABBox()));
105
106 Assert.assertEquals(s0, s1);
107
108 Assert.assertEquals((float)s0/(float)unitsPerEM, s0_em, FloatUtil.EPSILON);
109 Assert.assertEquals((float)s1/(float)unitsPerEM, s1_em, FloatUtil.EPSILON);
110 Assert.assertEquals(s0_em, s1_em, FloatUtil.EPSILON);
111
112 Assert.assertEquals(s0_em*pixelSize, s0_px, FloatUtil.EPSILON);
113 Assert.assertEquals(s1_em*pixelSize, s1_px, FloatUtil.EPSILON);
114 Assert.assertEquals(s0_px, s1_px, FloatUtil.EPSILON);
115 }
116 void testFontGlyph02(final Font font, final char left, final char right) {
117 final int glyphid_left = font.getGlyphID(left);
118 final int glyphid_right = font.getGlyphID(right);
119 final Font.Glyph glyph_left = font.getGlyph(glyphid_left);
120
121 final int k_val = glyph_left.getKerningFU(glyphid_right);
122
123 System.err.println(" Font "+font.getFullFamilyName());
124 System.err.println(" Char left['"+left+"', id "+glyphid_left+", kpairs "+glyph_left.getKerningPairCount()+
125 "], right['"+right+"', id "+glyphid_right+"], kerning "+k_val);
126 System.err.println(" "+glyph_left);
127 // System.err.println(" "+glyph_left.fullString());
128 }
129}
Simple static font scale methods for unit conversions.
Definition: FontScale.java:37
static float toPixels(final float points, final float res_dpi)
Converts typical font size in points and screen resolution in dpi (pixels-per-inch) to font size in p...
Definition: FontScale.java:76
Basic Float math utility functions.
Definition: FloatUtil.java:83
static final float EPSILON
Epsilon for floating point {@value}, as once computed via getMachineEpsilon() on an AMD-64 CPU.
Interface wrapper for font implementation.
Definition: Font.java:60
String fullString()
Returns all font details as string.
String getFullFamilyName()
Shall return the family and subfamily name, separated a dash.
StringBuilder getAllNames(final StringBuilder string, final String separator)