JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestFontScale01NOUI.java
Go to the documentation of this file.
1/**
2 * Copyright 2014-2023 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 com.jogamp.graph.font.FontScale;
31import com.jogamp.junit.util.JunitTracer;
32import com.jogamp.math.FloatUtil;
33
34import org.junit.Assert;
35import org.junit.Test;
36import org.junit.FixMethodOrder;
37import org.junit.runners.MethodSorters;
38
39@FixMethodOrder(MethodSorters.NAME_ASCENDING)
40public class TestFontScale01NOUI extends JunitTracer {
41
42 @Test
43 public void test01() {
44 Assert.assertEquals(10f/72f, FontScale.ptToInch(10), FloatUtil.EPSILON); // pt -> inch
45 Assert.assertEquals(10f/72f * 25.4f, FontScale.ptToMM(10), FloatUtil.EPSILON); // pt -> mm
46 Assert.assertEquals(0.138888f, FontScale.ptToInch(10), 0.000001f); // pt -> inch
47 Assert.assertEquals(3.527778f, FontScale.ptToMM(10), 0.000001f); // pt -> mm
48
49 Assert.assertEquals(5f, FontScale.ppiToPPMM(new float[] { 127f, 127f })[0], FloatUtil.EPSILON); // dpi -> pixel/mm
50 Assert.assertEquals(127f, FontScale.ppmmToPPI(new float[] { 5f, 5f })[0], FloatUtil.EPSILON); // pixel/mm -> dpi
51
52 System.err.println("10pt @ 128 dpi -> pixels "+FontScale.toPixels(10 /* pt */, 127f /* dpi */));
53 System.err.println("10pt @ 5 ppmm -> pixels "+FontScale.toPixels2(10 /* pt */, 5f /* ppmm */));
54 Assert.assertEquals(17.638889f, FontScale.toPixels(10 /* pt */, 127f /* dpi */), 0.000001f);
55 Assert.assertEquals(17.638889f, FontScale.toPixels2(10 /* pt */, 5f /* ppmm */), 0.000001f);
56 }
57
58 public static void main(final String args[]) {
59 org.junit.runner.JUnitCore.main(TestFontScale01NOUI.class.getName());
60 }
61}
Simple static font scale methods for unit conversions.
Definition: FontScale.java:37
static float[] ppmmToPPI(final float[] ppmm)
Converts [1/mm] to [1/inch] in place.
Definition: FontScale.java:105
static float[] ppiToPPMM(final float[] ppi)
Converts [1/inch] to [1/mm] in place.
Definition: FontScale.java:128
static float ptToInch(final float points)
Converts the the given points size to inch, dividing by 72 points per inch.
Definition: FontScale.java:45
static float ptToMM(final float points)
Converts the the given points size to mm, dividing by 72 * 25.4 points per inch.
Definition: FontScale.java:58
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
static float toPixels2(final float points, final float res_ppmm)
Converts typical font size in points and screen resolution in pixels (pixels-per-mm) to font size in ...
Definition: FontScale.java:96
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.