aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp/graph/font
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-04-01 16:31:05 +0200
committerSven Gothel <[email protected]>2014-04-01 16:31:05 +0200
commitb935d5248aef79e2386a284b32f5888348a382d6 (patch)
tree6b661210ee531968fcf7d5c75ded4ed58bd3b0fc /src/jogl/classes/jogamp/graph/font
parent07d1c5a272e528d130daf37b9aa7077aac8d748e (diff)
Bug 801: WIP 1/2 - Add color attribute; Switch Shader instead of branching in shader; Update attributes and uniforms manually, drop ShaderState;
- ShaderCode - add int insertShaderSource(int shaderIdx, int position, Class<?> context, String path) - insertShaderSource(..): pos==-1 -> append code - VectorUtil - add isVec3InTriangle3(..., float epsilon) - add testSeg2SegIntersection(..., float epsilon) - add testTri2SegIntersection(..., float epsilon) - AffineTransform: Return result for chaining - Font - Add pixel precise 'getPointsBounds(final AffineTransform transform, CharSequence string, float pixelSize)' - Rename getString*() -> getMetric*() - OTGlyph: Release _points field, no more used - - Graph Triangulation - Count additional vertices in: Triangulator, CDTriangulator2D - OutlineShape: - Allow skipping of 'transformOutlines2Quadratic', i.e. allow tagging OutlineShape to be quadratic_nurbs via 'setIsQuadraticNurbs()' - Clarify cleanup ot outlines in same method 'cleanupOutlines()' - Count additional vertices .. - Graph Shader: - Start splitting and segmenting shader code for: - pass1 / pass2 - features, i.e. sampleCont, color-channel, ..
Diffstat (limited to 'src/jogl/classes/jogamp/graph/font')
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java60
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java2
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/ot/OTGlyph.java12
3 files changed, 61 insertions, 13 deletions
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
index a75c5e02c..cd48cd8d6 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
@@ -34,11 +34,14 @@ import jogamp.graph.font.typecast.ot.table.CmapIndexEntry;
import jogamp.graph.font.typecast.ot.table.CmapTable;
import jogamp.graph.font.typecast.ot.table.HdmxTable;
import jogamp.graph.font.typecast.ot.table.ID;
+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;
@@ -203,6 +206,8 @@ class TypecastFont implements Font {
if(DEBUG) {
System.err.println("New glyph: " + (int)symbol + " ( " + symbol +" ) -> " + code + ", contours " + glyph.getPointCount() + ": " + shape);
}
+ glyph.clearPointData();
+
final HdmxTable hdmx = font.getHdmxTable();
if (null!= result && null != hdmx) {
/*if(DEBUG) {
@@ -238,7 +243,7 @@ class TypecastFont implements Font {
}
@Override
- public float getStringWidth(CharSequence string, float pixelSize) {
+ public float getMetricWidth(CharSequence string, float pixelSize) {
float width = 0;
final int len = string.length();
for (int i=0; i< len; i++) {
@@ -254,7 +259,7 @@ class TypecastFont implements Font {
}
@Override
- public float getStringHeight(CharSequence string, float pixelSize) {
+ public float getMetricHeight(CharSequence string, float pixelSize) {
int height = 0;
for (int i=0; i<string.length(); i++) {
@@ -269,16 +274,16 @@ class TypecastFont implements Font {
}
@Override
- public AABBox getStringBounds(CharSequence string, float pixelSize) {
+ public AABBox getMetricBounds(CharSequence string, float pixelSize) {
if (string == null) {
return new AABBox();
}
+ final int charCount = string.length();
final float lineHeight = getLineHeight(pixelSize);
-
float totalHeight = 0;
float totalWidth = 0;
float curLineWidth = 0;
- for (int i=0; i<string.length(); i++) {
+ for (int i=0; i<charCount; i++) {
char character = string.charAt(i);
if (character == '\n') {
totalWidth = Math.max(curLineWidth, totalWidth);
@@ -295,6 +300,51 @@ class TypecastFont implements Font {
}
return new AABBox(0, 0, 0, totalWidth, totalHeight,0);
}
+ @Override
+ public AABBox getPointsBounds(final AffineTransform transform, CharSequence string, float pixelSize) {
+ 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();
+
+ float y = 0;
+ float advanceTotal = 0;
+
+ for(int i=0; i< charCount; i++) {
+ final char character = string.charAt(i);
+ if( '\n' == character ) {
+ y -= lineHeight;
+ advanceTotal = 0;
+ } else if (character == ' ') {
+ advanceTotal += getAdvanceWidth(Glyph.ID_SPACE, pixelSize);
+ } else {
+ // reset transform
+ if( null != transform ) {
+ t.setTransform(transform);
+ } else {
+ t.setToIdentity();
+ }
+ t.translate(advanceTotal, y);
+ t.scale(scale, scale);
+ tbox.reset();
+
+ final Font.Glyph glyph = getGlyph(character);
+ res.resize(t.transform(glyph.getBBox(), tbox));
+
+ final OutlineShape glyphShape = glyph.getShape();
+ if( null == glyphShape ) {
+ continue;
+ }
+ advanceTotal += glyph.getAdvance(pixelSize, true);
+ }
+ }
+ return res;
+ }
@Override
final public int getNumGlyphs() {
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java
index c540f7ddb..b6e9925d4 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java
@@ -84,7 +84,7 @@ public class TypecastRenderer {
final OutlineShape shape = new OutlineShape(vertexFactory);
buildShapeImpl(shape, symbol, glyph, vertexFactory);
- shape.closeLastOutline(false);
+ shape.setIsQuadraticNurbs();
return shape;
}
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/OTGlyph.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/OTGlyph.java
index e0d652bd4..270507fec 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/ot/OTGlyph.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/OTGlyph.java
@@ -102,6 +102,10 @@ public class OTGlyph {
}
}
+ public void clearPointData() {
+ _points = null;
+ }
+
public AABBox getBBox() {
return _bbox;
}
@@ -119,13 +123,7 @@ public class OTGlyph {
}
public int getPointCount() {
- return _points.length;
- }
-
- /**
- * Resets the glyph to the TrueType table settings
- */
- public void reset() {
+ return null != _points ? _points.length : 0;
}
/**