Skip to content

Commit

Permalink
Bug 801: Graph TextRenderer Cleanup Part-2: Remove Path2D from Glyph/…
Browse files Browse the repository at this point in the history
…Typecast* ; Misc Cleanup

Commit c362122 introduced
create an OutlineShape per Glyph from it's data w/o going through Path2D.

Misc Cleanup: Remove unused code/fields, use private/final where possible.
  • Loading branch information
sgothel committed Feb 27, 2014
1 parent 80a0ddd commit 073ac5a
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 401 deletions.
37 changes: 0 additions & 37 deletions src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderUtil.java
Expand Up @@ -144,43 +144,6 @@ public static GLRegion createRegion(final int renderModes, final Factory<? exten
return region;
}

private static GLRegion createRegion2(final int renderModes, final Factory<? extends Vertex> vertexFactory,
final Font font, final CharSequence str, final int pixelSize) {
final List<OutlineShape> shapesIn = font.getOutlineShapes(null, str, pixelSize, vertexFactory);
final ArrayList<OutlineShape> shapesOut = new ArrayList<OutlineShape>();
final int numGlyps = shapesIn.size();
for (int index=0;index<numGlyps;index++){
if(shapesIn.get(index) == null){
continue;
}
final OutlineShape glyphShape = shapesIn.get(index);

if(glyphShape.getVertices().size() < 3) {
continue;
}
shapesOut.add(glyphShape);
}

final GLRegion region = Region.create(renderModes);
// region.setFlipped(true);
int numVertices = region.getNumVertices();

for(int i=0; i< shapesOut.size(); i++) {
final OutlineShape shape = shapesOut.get(i);
ArrayList<Triangle> gtris = shape.getTriangles(OutlineShape.VerticesState.QUADRATIC_NURBS);
region.addTriangles(gtris, null, 0);

final ArrayList<Vertex> gVertices = shape.getVertices();
for(int j=0; j<gVertices.size(); j++) {
final Vertex gVert = gVertices.get(j);
gVert.setId(numVertices++);
region.addVertex(gVert, null);
}
}
return region;
}


/**
* Render the String in 3D space wrt to the font provided at the position provided
* the outlines will be generated, if not yet generated
Expand Down
17 changes: 2 additions & 15 deletions src/jogl/classes/com/jogamp/graph/font/Font.java
Expand Up @@ -27,11 +27,7 @@
*/
package com.jogamp.graph.font;

import java.util.List;

import com.jogamp.graph.curve.OutlineShape;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.geom.Vertex.Factory;
import com.jogamp.opengl.math.geom.AABBox;

/**
Expand Down Expand Up @@ -88,6 +84,7 @@ public interface Glyph {
public Font getFont();
public char getSymbol();
public short getID();
public AABBox getBBox();
public float getScale(float pixelSize);
public AABBox getBBox(float pixelSize);
public float getAdvance(float pixelSize, boolean useFrationalMetrics);
Expand Down Expand Up @@ -117,17 +114,7 @@ public interface Glyph {

public boolean isPrintableChar( char c );

/**
* @deprecated Remove altogether - use {@link #getOutlineShape(Glyph, Factory)
* @param shapes optional storage of OutlineShapes passed by user, new shapes are appended
* @param string source of the created OutlineShapes
* @param pixelSize
* @param vertexFactory factory for vertices
* @return List of OutlineShapes, one OutlineShape per character
*/
public List<OutlineShape> getOutlineShapes(List<OutlineShape> shapes, CharSequence string, float pixelSize, Factory<? extends Vertex> vertexFactory);

/** Shall return {@link #getFullFamilyName()} */
@Override
public String toString();
}
}
44 changes: 0 additions & 44 deletions src/jogl/classes/jogamp/graph/font/FontInt.java

This file was deleted.

54 changes: 20 additions & 34 deletions src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
Expand Up @@ -27,42 +27,36 @@
*/
package jogamp.graph.font.typecast;

import java.util.List;

import jogamp.graph.font.FontInt;
import jogamp.graph.font.typecast.ot.OTFont;
import jogamp.graph.font.typecast.ot.OTFontCollection;
import jogamp.graph.font.typecast.ot.table.CmapFormat;
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 jogamp.graph.geom.plane.Path2D;

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.geom.SVertex;
import com.jogamp.graph.geom.Vertex;
import com.jogamp.graph.geom.Vertex.Factory;
import com.jogamp.opengl.math.geom.AABBox;

class TypecastFont implements FontInt {
class TypecastFont implements Font {
static final boolean DEBUG = false;
private static final Vertex.Factory<SVertex> vertexFactory = SVertex.factory();

final OTFontCollection fontset;
final OTFont font;
TypecastHMetrics metrics;
final CmapFormat cmapFormat;
int cmapentries;
// private final OTFontCollection fontset;
/* pp */ final OTFont font;
private final CmapFormat cmapFormat;
private final int cmapentries;
private final IntObjectHashMap char2Glyph;
private final TypecastHMetrics metrics;
// FIXME: Add cache size to limit memory usage ??
IntObjectHashMap char2Glyph;

public TypecastFont(OTFontCollection fontset) {
this.fontset = fontset;
public TypecastFont(final OTFontCollection fontset) {
// this.fontset = fontset;
this.font = fontset.getFont(0);

// FIXME: Generic attempt to find the best CmapTable,
Expand Down Expand Up @@ -124,10 +118,13 @@ public TypecastFont(OTFontCollection fontset) {
}
}

cmapentries = 0;
for (int i = 0; i < cmapFormat.getRangeCount(); ++i) {
CmapFormat.Range range = cmapFormat.getRange(i);
cmapentries += range.getEndCode() - range.getStartCode() + 1; // end included
{
int _cmapentries = 0;
for (int i = 0; i < cmapFormat.getRangeCount(); ++i) {
CmapFormat.Range range = cmapFormat.getRange(i);
_cmapentries += range.getEndCode() - range.getStartCode() + 1; // end included
}
cmapentries = _cmapentries;
}
if(DEBUG) {
System.err.println("font direction hint: "+font.getHeadTable().getFontDirectionHint());
Expand All @@ -146,6 +143,7 @@ public TypecastFont(OTFontCollection fontset) {
}
}
char2Glyph = new IntObjectHashMap(cmapentries + cmapentries/4);
metrics = new TypecastHMetrics(this);
}

@Override
Expand Down Expand Up @@ -173,10 +171,7 @@ public float getAdvanceWidth(int i, float pixelSize) {
}

@Override
public Metrics getMetrics() {
if (metrics == null) {
metrics = new TypecastHMetrics(this);
}
public final Metrics getMetrics() {
return metrics;
}

Expand All @@ -203,11 +198,9 @@ public Glyph getGlyph(char symbol) {
throw new RuntimeException("Could not retrieve glyph for symbol: <"+symbol+"> "+(int)symbol+" -> glyph id "+code);
}
final OutlineShape shape = TypecastRenderer.buildShape(glyph, vertexFactory);
// FIXME: Remove Path2D
final Path2D path = TypecastRenderer.buildPath(glyph);
result = new TypecastGlyph(this, symbol, code, glyph.getBBox(), glyph.getAdvanceWidth(), path, shape);
result = new TypecastGlyph(this, symbol, code, glyph.getBBox(), glyph.getAdvanceWidth(), shape);
if(DEBUG) {
System.err.println("New glyph: " + (int)symbol + " ( " + symbol +" ) -> " + code + ", contours " + glyph.getPointCount() + ": " + path);
System.err.println("New glyph: " + (int)symbol + " ( " + symbol +" ) -> " + code + ", contours " + glyph.getPointCount() + ": " + shape);
}
final HdmxTable hdmx = font.getHdmxTable();
if (null!= result && null != hdmx) {
Expand All @@ -228,13 +221,6 @@ public Glyph getGlyph(char symbol) {
return result;
}

// FIXME: Remove altogether
@Override
public List<OutlineShape> getOutlineShapes(List<OutlineShape> shapes, CharSequence string, float pixelSize, Factory<? extends Vertex> vertexFactory) {
AffineTransform transform = new AffineTransform(vertexFactory);
return TypecastRenderer.getOutlineShapes(shapes, this, string, pixelSize, transform, vertexFactory);
}

@Override
public float getStringWidth(CharSequence string, float pixelSize) {
float width = 0;
Expand Down

0 comments on commit 073ac5a

Please sign in to comment.