diff options
author | Sven Gothel <[email protected]> | 2014-02-23 06:11:11 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-02-23 06:11:11 +0100 |
commit | f51933f0ebe9ae030c26c066e59a728ce08b8559 (patch) | |
tree | 6723e2343b80a487dba73d51609e2d8fee120b1a /src/jogl/classes/jogamp/graph/font | |
parent | b68794ae48cf2f133abd9d822f08207cf3404c17 (diff) |
Bug 801: Graph TextRenderer Cleanup Part-1a (unclean)
Remark: This commit is unclean and requires 'Part-1b' due to
merging this commit after more than 2 years!
Graph:
- Use List<OutlineShape> instead of array
allowing more flexible memory managment.
- GLRegion -> Region promotion:
- Region create(List<OutlineShape> outlineShapes, int renderModes)
- Region create(OutlineShape outlineShape, int renderModes)
- Region additions
- void addOutlineShape(OutlineShape shape)
- void addOutlineShapes(List<OutlineShape> shapes)
- RegionRenderer
- draw(..) remove 'position', redundant
-
- Deprecate 'TextRenderer' and 'GlyphString'
Use Region.create(Font.getOutlineShapes(...)) + RegionRenderer instead.
- FontInt -> Font promotion (make public)
- getOutlineShape and getOutlineShapes
- Font.Glyph additions
- 'getID(), hashCode()'
- 'float getScale(float pixelSize)'
- GlyphShape
- Add reference to Glyph allowing GlyphString
to access the font metrics for translation and scaling
- Experimental pre-scale/translation in GlyphString
using default font size and it's metrics
Diffstat (limited to 'src/jogl/classes/jogamp/graph/font')
4 files changed, 62 insertions, 24 deletions
diff --git a/src/jogl/classes/jogamp/graph/font/FontInt.java b/src/jogl/classes/jogamp/graph/font/FontInt.java index 20e1ec028..7528a692b 100644 --- a/src/jogl/classes/jogamp/graph/font/FontInt.java +++ b/src/jogl/classes/jogamp/graph/font/FontInt.java @@ -27,14 +27,9 @@ */ package jogamp.graph.font; -import java.util.ArrayList; - import jogamp.graph.geom.plane.Path2D; -import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.font.Font; -import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.geom.Vertex.Factory; public interface FontInt extends Font { @@ -43,5 +38,4 @@ public interface FontInt extends Font { public Path2D getPath(float pixelSize); } - public ArrayList<OutlineShape> getOutlineShapes(CharSequence string, float pixelSize, Factory<? extends Vertex> vertexFactory); } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java index 8e465de99..2d13ae32d 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java @@ -27,7 +27,7 @@ */ package jogamp.graph.font.typecast; -import java.util.ArrayList; +import java.util.List; import jogamp.graph.font.FontInt; import jogamp.graph.font.typecast.ot.OTFont; @@ -44,7 +44,6 @@ import com.jogamp.common.util.IntObjectHashMap; import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; -import com.jogamp.graph.font.Font.Glyph; import com.jogamp.graph.geom.AABBox; import com.jogamp.graph.geom.Vertex; import com.jogamp.graph.geom.Vertex.Factory; @@ -148,25 +147,31 @@ class TypecastFont implements FontInt { char2Glyph = new IntObjectHashMap(cmapentries + cmapentries/4); } + @Override public StringBuilder getName(StringBuilder sb, int nameIndex) { return font.getName(nameIndex, sb); } + @Override public String getName(int nameIndex) { return getName(null, nameIndex).toString(); } + @Override public StringBuilder getAllNames(StringBuilder sb, String separator) { return font.getAllNames(sb, separator); } + @Override public StringBuilder getFullFamilyName(StringBuilder sb) { sb = getName(sb, Font.NAME_FAMILY).append("-"); getName(sb, Font.NAME_SUBFAMILY); return sb; } + @Override public float getAdvanceWidth(int i, float pixelSize) { return font.getHmtxTable().getAdvanceWidth(i) * metrics.getScale(pixelSize); } + @Override public Metrics getMetrics() { if (metrics == null) { metrics = new TypecastHMetrics(this); @@ -174,6 +179,7 @@ class TypecastFont implements FontInt { return metrics; } + @Override public Glyph getGlyph(char symbol) { TypecastGlyph result = (TypecastGlyph) char2Glyph.get(symbol); if (null == result) { @@ -218,12 +224,19 @@ class TypecastFont implements FontInt { } return result; } - - public ArrayList<OutlineShape> getOutlineShapes(CharSequence string, float pixelSize, Factory<? extends Vertex> vertexFactory) { + + @Override + public OutlineShape getOutlineShape(Glyph glyph, Factory<? extends Vertex> vertexFactory) { + return TypecastRenderer.getOutlineShape(this, glyph, vertexFactory); + } + + @Override + public List<OutlineShape> getOutlineShapes(List<OutlineShape> shapes, CharSequence string, float pixelSize, Factory<? extends Vertex> vertexFactory) { AffineTransform transform = new AffineTransform(vertexFactory); - return TypecastRenderer.getOutlineShapes(this, string, pixelSize, transform, vertexFactory); + return TypecastRenderer.getOutlineShapes(shapes, this, string, pixelSize, transform, vertexFactory); } + @Override public float getStringWidth(CharSequence string, float pixelSize) { float width = 0; final int len = string.length(); @@ -241,6 +254,7 @@ class TypecastFont implements FontInt { return (int)(width + 0.5f); } + @Override public float getStringHeight(CharSequence string, float pixelSize) { int height = 0; @@ -257,6 +271,7 @@ class TypecastFont implements FontInt { return height; } + @Override public AABBox getStringBounds(CharSequence string, float pixelSize) { if (string == null) { return new AABBox(); @@ -287,14 +302,17 @@ class TypecastFont implements FontInt { return new AABBox(0, 0, 0, totalWidth, totalHeight,0); } + @Override final public int getNumGlyphs() { return font.getNumGlyphs(); } + @Override public boolean isPrintableChar( char c ) { return FontFactory.isPrintableChar(c); } + @Override public String toString() { return getFullFamilyName(null).toString(); } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java index a1f1a3292..cdaa2df7e 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java @@ -228,5 +228,11 @@ public class TypecastGlyph implements FontInt.GlyphInt { this.pathSized = AffineTransform.getScaleInstance(null, size, size).createTransformedShape(getPath()); } return this.pathSized; + } + + public int hashCode() { + // 31 * x == (x << 5) - x + int hash = 31 + font.getName(Font.NAME_UNIQUNAME).hashCode(); + return ((hash << 5) - hash) + id; } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java index f155345aa..d62f19cb7 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java @@ -28,6 +28,7 @@ package jogamp.graph.font.typecast; import java.util.ArrayList; +import java.util.List; import jogamp.graph.font.FontInt.GlyphInt; import jogamp.graph.font.typecast.ot.OTGlyph; @@ -64,9 +65,10 @@ public class TypecastRenderer { } AffineTransform t = new AffineTransform(); + final int len = string.length(); float advanceY = lineGap - descent + ascent; float y = 0; - for (int i=0; i<string.length(); i++) + for (int i=0; i<len; i++) { p[i] = new Path2D(); p[i].reset(); @@ -75,26 +77,44 @@ public class TypecastRenderer { if (character == '\n') { y += advanceY; advanceTotal = 0; - continue; } else if (character == ' ') { advanceTotal += font.getAdvanceWidth(Glyph.ID_SPACE, pixelSize); - continue; - } - Glyph glyph = font.getGlyph(character); - Path2D gp = ((GlyphInt)glyph).getPath(); - float scale = metrics.getScale(pixelSize); - t.translate(advanceTotal, y); - t.scale(scale, scale); - p[i].append(gp.iterator(t), false); - advanceTotal += glyph.getAdvance(pixelSize, true); + } else { + final Glyph glyph = font.getGlyph(character); + final Path2D gp = ((GlyphInt)glyph).getPath(); + final float scale = metrics.getScale(pixelSize); + t.translate(advanceTotal, y); + t.scale(scale, scale); + p[i].append(gp.iterator(t), false); + advanceTotal += glyph.getAdvance(pixelSize, true); + } } } - public static ArrayList<OutlineShape> getOutlineShapes(TypecastFont font, CharSequence string, float pixelSize, AffineTransform transform, Factory<? extends Vertex> vertexFactory) { + public static OutlineShape getOutlineShape(TypecastFont font, Glyph glyph, Factory<? extends Vertex> vertexFactory) { + Path2D path = ((GlyphInt)glyph).getPath(); + AffineTransform transform = new AffineTransform(vertexFactory); + OutlineShape shape = new OutlineShape(vertexFactory); + + PathIterator iterator = path.iterator(transform); + if(null != iterator){ + while(!iterator.isDone()){ + float[] coords = new float[6]; + int segmentType = iterator.currentSegment(coords); + addPathVertexToOutline(shape, vertexFactory, coords, segmentType); + iterator.next(); + } + } + return shape; + } + + public static List<OutlineShape> getOutlineShapes(List<OutlineShape> shapes, TypecastFont font, CharSequence string, float pixelSize, AffineTransform transform, Factory<? extends Vertex> vertexFactory) { Path2D[] paths = new Path2D[string.length()]; getPaths(font, string, pixelSize, transform, paths); - ArrayList<OutlineShape> shapes = new ArrayList<OutlineShape>(); + if(null == shapes) { + shapes = new ArrayList<OutlineShape>(); + } final int numGlyps = paths.length; for (int index=0;index<numGlyps;index++) { if(paths[index] == null){ |