summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp/graph/font
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-04-02 19:25:16 +0200
committerSven Gothel <[email protected]>2014-04-02 19:25:16 +0200
commitabc833631e0ab30a06c7aff47a39a551544fd735 (patch)
tree1d6e5a94d2149d7b2635de5b5eccb330bc41cd2c /src/jogl/classes/jogamp/graph/font
parente8a5a1cbb988670ca206ab1ac633e19a91bfa478 (diff)
Bug 801: Reduce temp. object creation, i.e. GC load
Diffstat (limited to 'src/jogl/classes/jogamp/graph/font')
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java22
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java67
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java18
3 files changed, 51 insertions, 56 deletions
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
index cd48cd8d6..5fb61387a 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
@@ -38,10 +38,8 @@ import jogamp.graph.geom.plane.AffineTransform;
import com.jogamp.common.util.IntObjectHashMap;
import com.jogamp.graph.curve.OutlineShape;
-import com.jogamp.graph.curve.Region;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;
-import com.jogamp.graph.font.Font.Glyph;
import com.jogamp.graph.geom.SVertex;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.opengl.math.geom.AABBox;
@@ -251,7 +249,7 @@ class TypecastFont implements Font {
if (character == '\n') {
width = 0;
} else {
- Glyph glyph = getGlyph(character);
+ final Glyph glyph = getGlyph(character);
width += glyph.getAdvance(pixelSize, false);
}
}
@@ -259,14 +257,14 @@ class TypecastFont implements Font {
}
@Override
- public float getMetricHeight(CharSequence string, float pixelSize) {
+ public float getMetricHeight(CharSequence string, float pixelSize, final AABBox tmp) {
int height = 0;
for (int i=0; i<string.length(); i++) {
final char character = string.charAt(i);
if (character != ' ') {
final Glyph glyph = getGlyph(character);
- AABBox bbox = glyph.getBBox(pixelSize, tmpV3);
+ final AABBox bbox = glyph.getBBox(tmp, pixelSize, tmpV3);
height = (int)Math.ceil(Math.max(bbox.getHeight(), height));
}
}
@@ -301,14 +299,14 @@ class TypecastFont implements Font {
return new AABBox(0, 0, 0, totalWidth, totalHeight,0);
}
@Override
- public AABBox getPointsBounds(final AffineTransform transform, CharSequence string, float pixelSize) {
+ public AABBox getPointsBounds(final AffineTransform transform, final CharSequence string, final float pixelSize,
+ final AffineTransform temp1, final AffineTransform temp2) {
if (string == null) {
return new AABBox();
}
final int charCount = string.length();
final float lineHeight = getLineHeight(pixelSize);
final float scale = getMetrics().getScale(pixelSize);
- final AffineTransform t = null != transform ? new AffineTransform(transform) : new AffineTransform();
final AABBox tbox = new AABBox();
final AABBox res = new AABBox();
@@ -325,16 +323,16 @@ class TypecastFont implements Font {
} else {
// reset transform
if( null != transform ) {
- t.setTransform(transform);
+ temp1.setTransform(transform);
} else {
- t.setToIdentity();
+ temp1.setToIdentity();
}
- t.translate(advanceTotal, y);
- t.scale(scale, scale);
+ temp1.translate(advanceTotal, y, temp2);
+ temp1.scale(scale, scale, temp2);
tbox.reset();
final Font.Glyph glyph = getGlyph(character);
- res.resize(t.transform(glyph.getBBox(), tbox));
+ res.resize(temp1.transform(glyph.getBBox(), tbox));
final OutlineShape glyphShape = glyph.getShape();
if( null == glyphShape ) {
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java
index b0e283278..2246b4a3c 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java
@@ -27,8 +27,7 @@
*/
package jogamp.graph.font.typecast;
-import java.util.HashMap;
-
+import com.jogamp.common.util.IntIntHashMap;
import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.font.Font;
import com.jogamp.opengl.math.geom.AABBox;
@@ -38,42 +37,45 @@ public class TypecastGlyph implements Font.Glyph {
{
private final Font font;
private final float advance;
- HashMap<Float, Float> size2advance = new HashMap<Float, Float>();
+ private final IntIntHashMap size2advanceI = new IntIntHashMap();
- public Advance(Font font, float advance)
+ public Advance(final Font font, final float advance)
{
this.font = font;
this.advance = advance;
+ size2advanceI.setKeyNotFoundValue(0);
}
public void reset() {
- size2advance.clear();
+ size2advanceI.clear();
}
- public float getScale(float pixelSize)
+ public float getScale(final float pixelSize)
{
return this.font.getMetrics().getScale(pixelSize);
}
- public void add(float advance, float size)
+ public void add(final float advance, final float size)
{
- size2advance.put(size, advance);
+ size2advanceI.put(Float.floatToIntBits(size), Float.floatToIntBits(advance));
}
- public float get(float size, boolean useFrationalMetrics)
+ public float get(final float size, final boolean useFrationalMetrics)
{
- final Float fo = size2advance.get(size);
- if(null == fo) {
- float value = (this.advance * getScale(size));
- if (useFrationalMetrics == false) {
- //value = (float)Math.ceil(value);
- // value = (int)value;
- value = (int) ( value + 0.5f ) ; // TODO: check
- }
- size2advance.put(size, value);
- return value;
+ final int sI = Float.floatToIntBits(size);
+ final int aI = size2advanceI.get(sI);
+ if( 0 != aI ) {
+ return Float.intBitsToFloat(aI);
+ }
+ final float a;
+ if ( useFrationalMetrics ) {
+ a = this.advance * getScale(size);
+ } else {
+ // a = Math.ceil(this.advance * getScale(size));
+ a = Math.round(this.advance * getScale(size)); // TODO: check whether ceil should be used instead?
}
- return fo.floatValue();
+ size2advanceI.put(sI, Float.floatToIntBits(a));
+ return a;
}
@Override
@@ -81,7 +83,7 @@ public class TypecastGlyph implements Font.Glyph {
{
return "\nAdvance:"+
"\n advance: "+this.advance+
- "\n advances: \n"+size2advance;
+ "\n advances: \n"+size2advanceI;
}
}
@@ -90,7 +92,7 @@ public class TypecastGlyph implements Font.Glyph {
private final AABBox bbox;
private final Advance advance;
- public Metrics(Font font, AABBox bbox, float advance)
+ public Metrics(final Font font, final AABBox bbox, final float advance)
{
this.bbox = bbox;
this.advance = new Advance(font, advance);
@@ -100,7 +102,7 @@ public class TypecastGlyph implements Font.Glyph {
advance.reset();
}
- public float getScale(float pixelSize)
+ public float getScale(final float pixelSize)
{
return this.advance.getScale(pixelSize);
}
@@ -110,12 +112,12 @@ public class TypecastGlyph implements Font.Glyph {
return this.bbox;
}
- public void addAdvance(float advance, float size)
+ public void addAdvance(final float advance, final float size)
{
this.advance.add(advance, size);
}
- public float getAdvance(float size, boolean useFrationalMetrics)
+ public float getAdvance(final float size, final boolean useFrationalMetrics)
{
return this.advance.get(size, useFrationalMetrics);
}
@@ -139,7 +141,7 @@ public class TypecastGlyph implements Font.Glyph {
private final int advance;
private final Metrics metrics;
- protected TypecastGlyph(Font font, char symbol, short id, AABBox bbox, int advance, OutlineShape shape) {
+ protected TypecastGlyph(final Font font, final char symbol, final short id, final AABBox bbox, final int advance, final OutlineShape shape) {
this.font = font;
this.symbol = symbol;
this.shape = shape;
@@ -183,24 +185,21 @@ public class TypecastGlyph implements Font.Glyph {
}
@Override
- public final float getScale(float pixelSize) {
+ public final float getScale(final float pixelSize) {
return this.metrics.getScale(pixelSize);
}
@Override
- public final AABBox getBBox(float pixelSize, float[] tmpV3) {
- final float size = getScale(pixelSize);
- AABBox newBox = getBBox().clone();
- newBox.scale(size, tmpV3);
- return newBox;
+ public final AABBox getBBox(final AABBox dest, final float pixelSize, final float[] tmpV3) {
+ return dest.copy(getBBox()).scale(getScale(pixelSize), tmpV3);
}
- protected final void addAdvance(float advance, float size) {
+ protected final void addAdvance(final float advance, final float size) {
this.metrics.addAdvance(advance, size);
}
@Override
- public final float getAdvance(float pixelSize, boolean useFrationalMetrics) {
+ public final float getAdvance(final float pixelSize, final boolean useFrationalMetrics) {
return this.metrics.getAdvance(pixelSize, useFrationalMetrics);
}
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java
index 4064e6463..be8ab8f69 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java
@@ -45,7 +45,7 @@ class TypecastHMetrics implements Metrics {
// VheaTable (for horizontal fonts)
// private final VheaTable vheaTable;
- public TypecastHMetrics(TypecastFont fontImpl) {
+ public TypecastHMetrics(final TypecastFont fontImpl) {
this.fontImpl = fontImpl;
headTable = this.fontImpl.font.getHeadTable();
hheaTable = this.fontImpl.font.getHheaTable();
@@ -62,29 +62,27 @@ class TypecastHMetrics implements Metrics {
}
@Override
- public final float getAscent(float pixelSize) {
+ public final float getAscent(final float pixelSize) {
return getScale(pixelSize) * -hheaTable.getAscender(); // invert
}
@Override
- public final float getDescent(float pixelSize) {
+ public final float getDescent(final float pixelSize) {
return getScale(pixelSize) * -hheaTable.getDescender(); // invert
}
@Override
- public final float getLineGap(float pixelSize) {
+ public final float getLineGap(final float pixelSize) {
return getScale(pixelSize) * -hheaTable.getLineGap(); // invert
}
@Override
- public final float getMaxExtend(float pixelSize) {
+ public final float getMaxExtend(final float pixelSize) {
return getScale(pixelSize) * hheaTable.getXMaxExtent();
}
@Override
- public final float getScale(float pixelSize) {
+ public final float getScale(final float pixelSize) {
return pixelSize * unitsPerEM_Inv;
}
@Override
- public final AABBox getBBox(float pixelSize, float[] tmpV3) {
- AABBox res = new AABBox(bbox.getLow(), bbox.getHigh());
- res.scale(getScale(pixelSize), tmpV3);
- return res;
+ public final AABBox getBBox(final AABBox dest, final float pixelSize, final float[] tmpV3) {
+ return dest.setSize(bbox.getLow(), bbox.getHigh()).scale(getScale(pixelSize), tmpV3);
}
} \ No newline at end of file