28package com.jogamp.opengl.test.junit.graph;
30import java.io.IOException;
32import org.junit.Assert;
34import org.junit.FixMethodOrder;
35import org.junit.runners.MethodSorters;
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;
44@FixMethodOrder(MethodSorters.NAME_ASCENDING)
46 static boolean mainRun =
false;
48 static int atoi(
final String a) {
50 return Integer.parseInt(a);
51 }
catch (
final Exception ex) {
throw new RuntimeException(ex); }
54 public static void main(
final String args[])
throws IOException {
57 org.junit.runner.JUnitCore.
main(tstname);
61 public void test00() throws InterruptedException, IOException {
64 void testFontImpl(
final Font[] fonts)
throws InterruptedException, IOException {
65 final float fontSize = 10;
67 for(
int i=0; i<fonts.length; i++) {
68 final Font font = fonts[i];
69 System.err.println(
"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
71 System.err.println(
"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
73 System.err.println(font.
getFullFamilyName()+
": "+fontSize+
"p, "+dpi+
"dpi -> "+pixelSize+
"px:");
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');
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();
88 final int unitsPerEM = font.getMetrics().getUnitsPerEM();
90 final float s0_em = font.getAdvanceWidth( glyph.getID() );
91 final float s1_em = glyph.getAdvanceWidth();
93 final float s0_px = s0_em * pixelSize;
94 final float s1_px = s1_em * pixelSize;
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()));
106 Assert.assertEquals(s0, s1);
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);
121 final int k_val = glyph_left.getKerningFU(glyphid_right);
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);
Simple static font scale methods for unit conversions.
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...
Basic Float math utility functions.
static final float EPSILON
Epsilon for floating point {@value}, as once computed via getMachineEpsilon() on an AMD-64 CPU.
static void main(final String args[])
Interface wrapper for font implementation.
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)