diff options
Diffstat (limited to 'src/jogl/classes/jogamp/graph')
173 files changed, 6324 insertions, 4643 deletions
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/RegionFactory.java b/src/jogl/classes/jogamp/graph/curve/opengl/RegionFactory.java deleted file mode 100755 index 1f59b5805..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/RegionFactory.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.curve.opengl; - -import com.jogamp.graph.curve.Region; -import com.jogamp.graph.curve.opengl.GLRegion; - -/** RegionFactory to create a Context specific Region implementation. - * - * @see GLRegion - */ -public class RegionFactory { - - /** - * Create a Region using the passed render mode - * - * <p> In case {@link Region#VBAA_RENDERING_BIT} is being requested the default texture unit - * {@link Region#TWO_PASS_DEFAULT_TEXTURE_UNIT} is being used.</p> - * - * @param rs the RenderState to be used - * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#VBAA_RENDERING_BIT} - */ - public static GLRegion create(int renderModes) { - if( 0 != ( Region.VBAA_RENDERING_BIT & renderModes ) ){ - return new VBORegion2PES2(renderModes, Region.TWO_PASS_DEFAULT_TEXTURE_UNIT); - } - else{ - return new VBORegionSPES2(renderModes); - } - } - - /** Create a Single Pass Region using the passed render mode - * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, - * {@link Region#VBAA_RENDERING_BIT} - * @return - */ - public static GLRegion createSinglePass(int renderModes) { - return new VBORegionSPES2(renderModes); - } - - /** Create a Two Pass (VBAA) Region using the passed render mode - * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, - * {@link Region#VBAA_RENDERING_BIT} - * @return - */ - public static GLRegion createTwoPass(int renderModes, int textureUnit) { - return new VBORegion2PES2(renderModes, textureUnit); - } -} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java b/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java deleted file mode 100755 index c34d1cbeb..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java +++ /dev/null @@ -1,93 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.curve.opengl; - -import javax.media.opengl.GL2ES2; -import javax.media.opengl.GLException; - -import jogamp.graph.curve.opengl.shader.AttributeNames; - -import com.jogamp.graph.curve.Region; -import com.jogamp.graph.curve.opengl.GLRegion; -import com.jogamp.graph.curve.opengl.RegionRenderer; -import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.opengl.util.glsl.ShaderCode; -import com.jogamp.opengl.util.glsl.ShaderProgram; -import com.jogamp.opengl.util.glsl.ShaderState; - -public class RegionRendererImpl01 extends RegionRenderer { - public RegionRendererImpl01(RenderState rs, int renderModes) { - super(rs, renderModes); - - } - - @Override - protected String getFragmentShaderName(GL2ES2 gl) { - final String type = Region.isNonUniformWeight(renderModes) ? "02" : "01" ; - final String pass = Region.isVBAA(renderModes) ? "b" : "a" ; - return "curverenderer" + type + pass + getShaderGLVersionSuffix(gl); - } - - protected boolean initShaderProgram(GL2ES2 gl) { - final ShaderState st = rs.getShaderState(); - - ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, RegionRendererImpl01.class, "shader", - "shader/bin", getVertexShaderName(gl), false); - ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, RegionRendererImpl01.class, "shader", - "shader/bin", getFragmentShaderName(gl), false); - - ShaderProgram sp = new ShaderProgram(); - sp.add(rsVp); - sp.add(rsFp); - - sp.init(gl); - st.attachShaderProgram(gl, sp, false); - st.bindAttribLocation(gl, AttributeNames.VERTEX_ATTR_IDX, AttributeNames.VERTEX_ATTR_NAME); - st.bindAttribLocation(gl, AttributeNames.TEXCOORD_ATTR_IDX, AttributeNames.TEXCOORD_ATTR_NAME); - - if(!sp.link(gl, System.err)) { - throw new GLException("RegionRenderer: Couldn't link program: "+sp); - } - st.useProgram(gl, true); - - if(DEBUG) { - System.err.println("RegionRendererImpl01 initialized: " + Thread.currentThread()+" "+st); - } - return true; - } - - @Override - protected void destroyImpl(GL2ES2 gl) { - super.destroyImpl(gl); - } - - @Override - protected void drawImpl(GL2ES2 gl, Region region, float[] position, int[] texSize) { - ((GLRegion)region).draw(gl, rs, vp_width, vp_height, texSize); - } -} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java b/src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java deleted file mode 100644 index 51356ca13..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/RenderStateImpl.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.curve.opengl; - -import java.nio.FloatBuffer; - -import javax.media.opengl.GLUniformData; - -import jogamp.graph.curve.opengl.shader.UniformNames; - -import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.geom.Vertex; -import com.jogamp.opengl.util.PMVMatrix; -import com.jogamp.opengl.util.glsl.ShaderState; - -public class RenderStateImpl extends RenderState { - /** - * weight is equivalent to the - * global off-curve vertex weight. - * TODO: change to per vertex - */ - private final GLUniformData gcu_Weight; - private final GLUniformData gcu_Alpha; - private final GLUniformData gcu_ColorStatic; - - public RenderStateImpl(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory, PMVMatrix pmvMatrix) { - super(st, pointFactory, pmvMatrix); - - gcu_Weight = new GLUniformData(UniformNames.gcu_Weight, 1.0f); - st.ownUniform(gcu_PMVMatrix); - gcu_Alpha = new GLUniformData(UniformNames.gcu_Alpha, 1.0f); - st.ownUniform(gcu_Alpha); - gcu_ColorStatic = new GLUniformData(UniformNames.gcu_ColorStatic, 3, FloatBuffer.allocate(3)); - st.ownUniform(gcu_ColorStatic); -// gcu_Strength = new GLUniformData(UniformNames.gcu_Strength, 3.0f); -// st.ownUniform(gcu_Strength); - } - - public RenderStateImpl(ShaderState st, Vertex.Factory<? extends Vertex> pointFactory) { - this(st, pointFactory, new PMVMatrix()); - } - - public final GLUniformData getWeight() { return gcu_Weight; } - public final GLUniformData getAlpha() { return gcu_Alpha; } - public final GLUniformData getColorStatic() { return gcu_ColorStatic; } - //public final GLUniformData getStrength() { return gcu_Strength; } - - -} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java b/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java deleted file mode 100644 index 158f0240a..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/TextRendererImpl01.java +++ /dev/null @@ -1,95 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.curve.opengl; - -import javax.media.opengl.GL2ES2; -import javax.media.opengl.GLException; - -import jogamp.graph.curve.opengl.shader.AttributeNames; -import jogamp.graph.curve.text.GlyphString; - -import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.curve.opengl.TextRenderer; -import com.jogamp.graph.font.Font; -import com.jogamp.opengl.util.glsl.ShaderCode; -import com.jogamp.opengl.util.glsl.ShaderProgram; -import com.jogamp.opengl.util.glsl.ShaderState; - -public class TextRendererImpl01 extends TextRenderer { - public TextRendererImpl01(RenderState rs, int type) { - super(rs, type); - } - - @Override - protected boolean initShaderProgram(GL2ES2 gl){ - final ShaderState st = rs.getShaderState(); - - ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, TextRendererImpl01.class, "shader", - "shader/bin", getVertexShaderName(gl), false); - ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, TextRendererImpl01.class, "shader", - "shader/bin", getFragmentShaderName(gl), false); - - ShaderProgram sp = new ShaderProgram(); - sp.add(rsVp); - sp.add(rsFp); - - sp.init(gl); - st.attachShaderProgram(gl, sp, false); - st.bindAttribLocation(gl, AttributeNames.VERTEX_ATTR_IDX, AttributeNames.VERTEX_ATTR_NAME); - st.bindAttribLocation(gl, AttributeNames.TEXCOORD_ATTR_IDX, AttributeNames.TEXCOORD_ATTR_NAME); - - if(!sp.link(gl, System.err)) { - throw new GLException("TextRendererImpl01: Couldn't link program: "+sp); - } - st.useProgram(gl, true); - - if(DEBUG) { - System.err.println("TextRendererImpl01 initialized: " + Thread.currentThread()+" "+st); - } - return true; - } - - @Override - protected void destroyImpl(GL2ES2 gl) { - super.destroyImpl(gl); - } - - @Override - public void drawString3D(GL2ES2 gl, Font font, String str, float[] position, int fontSize, int[/*1*/] texSize) { - if(!isInitialized()){ - throw new GLException("TextRendererImpl01: not initialized!"); - } - GlyphString glyphString = getCachedGlyphString(font, str, fontSize); - if(null == glyphString) { - glyphString = createString(gl, font, fontSize, str); - addCachedGlyphString(gl, font, str, fontSize, glyphString); - } - - glyphString.renderString3D(gl, rs, vp_width, vp_height, texSize); - } -} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java deleted file mode 100644 index aabef29b0..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PES2.java +++ /dev/null @@ -1,340 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.curve.opengl; - -import java.nio.FloatBuffer; - -import javax.media.opengl.GL2ES2; -// FIXME: Subsume GL2GL3.GL_DRAW_FRAMEBUFFER -> GL2ES2.GL_DRAW_FRAMEBUFFER ! -import javax.media.opengl.GL; -import javax.media.opengl.GLUniformData; -import javax.media.opengl.fixedfunc.GLMatrixFunc; - -import jogamp.graph.curve.opengl.shader.AttributeNames; -import jogamp.graph.curve.opengl.shader.UniformNames; - -import com.jogamp.common.nio.Buffers; -import com.jogamp.graph.geom.Triangle; -import com.jogamp.graph.geom.Vertex; - -import com.jogamp.graph.curve.opengl.GLRegion; -import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.opengl.FBObject; -import com.jogamp.opengl.FBObject.Attachment; -import com.jogamp.opengl.FBObject.TextureAttachment; -import com.jogamp.opengl.util.GLArrayDataServer; -import com.jogamp.opengl.util.PMVMatrix; -import com.jogamp.opengl.util.glsl.ShaderState; - -public class VBORegion2PES2 extends GLRegion { - private GLArrayDataServer verticeTxtAttr; - private GLArrayDataServer texCoordTxtAttr; - private GLArrayDataServer indicesTxt; - private GLArrayDataServer verticeFboAttr; - private GLArrayDataServer texCoordFboAttr; - private GLArrayDataServer indicesFbo; - - - private FBObject fbo; - private TextureAttachment texA; - private PMVMatrix fboPMVMatrix; - GLUniformData mgl_fboPMVMatrix; - - private int tex_width_c = 0; - private int tex_height_c = 0; - GLUniformData mgl_ActiveTexture; - GLUniformData mgl_TextureSize; // if GLSL < 1.30 - - public VBORegion2PES2(int renderModes, int textureEngine) { - super(renderModes); - fboPMVMatrix = new PMVMatrix(); - mgl_fboPMVMatrix = new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, fboPMVMatrix.glGetPMvMatrixf()); - mgl_ActiveTexture = new GLUniformData(UniformNames.gcu_TextureUnit, textureEngine); - } - - public void update(GL2ES2 gl, RenderState rs) { - if(!isDirty()) { - return; - } - - if(null == indicesFbo) { - final int initialElementCount = 256; - final ShaderState st = rs.getShaderState(); - - indicesFbo = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); - indicesFbo.puts((short) 0); indicesFbo.puts((short) 1); indicesFbo.puts((short) 3); - indicesFbo.puts((short) 1); indicesFbo.puts((short) 2); indicesFbo.puts((short) 3); - indicesFbo.seal(true); - - texCoordFboAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT, - false, initialElementCount, GL.GL_STATIC_DRAW); - st.ownAttribute(texCoordFboAttr, true); - texCoordFboAttr.putf(5); texCoordFboAttr.putf(5); - texCoordFboAttr.putf(5); texCoordFboAttr.putf(6); - texCoordFboAttr.putf(6); texCoordFboAttr.putf(6); - texCoordFboAttr.putf(6); texCoordFboAttr.putf(5); - texCoordFboAttr.seal(true); - - verticeFboAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT, - false, initialElementCount, GL.GL_STATIC_DRAW); - st.ownAttribute(verticeFboAttr, true); - - - indicesTxt = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); - - verticeTxtAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT, - false, initialElementCount, GL.GL_STATIC_DRAW); - st.ownAttribute(verticeTxtAttr, true); - - texCoordTxtAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT, - false, initialElementCount, GL.GL_STATIC_DRAW); - st.ownAttribute(texCoordTxtAttr, true); - - if(DEBUG_INSTANCE) { - System.err.println("VBORegion2PES2 Create: " + this); - } - } - // process triangles - indicesTxt.seal(gl, false); - indicesTxt.rewind(); - for(int i=0; i<triangles.size(); i++) { - final Triangle t = triangles.get(i); - final Vertex[] t_vertices = t.getVertices(); - - if(t_vertices[0].getId() == Integer.MAX_VALUE){ - t_vertices[0].setId(numVertices++); - t_vertices[1].setId(numVertices++); - t_vertices[2].setId(numVertices++); - - vertices.add(t_vertices[0]); - vertices.add(t_vertices[1]); - vertices.add(t_vertices[2]); - - indicesTxt.puts((short) t_vertices[0].getId()); - indicesTxt.puts((short) t_vertices[1].getId()); - indicesTxt.puts((short) t_vertices[2].getId()); - } else { - indicesTxt.puts((short) t_vertices[0].getId()); - indicesTxt.puts((short) t_vertices[1].getId()); - indicesTxt.puts((short) t_vertices[2].getId()); - } - } - indicesTxt.seal(gl, true); - indicesTxt.enableBuffer(gl, false); - - // process vertices and update bbox - box.reset(); - verticeTxtAttr.seal(gl, false); - verticeTxtAttr.rewind(); - texCoordTxtAttr.seal(gl, false); - texCoordTxtAttr.rewind(); - for(int i=0; i<vertices.size(); i++) { - final Vertex v = vertices.get(i); - verticeTxtAttr.putf(v.getX()); - verticeTxtAttr.putf(v.getY()); - verticeTxtAttr.putf(v.getZ()); - box.resize(v.getX(), v.getY(), v.getZ()); - - final float[] tex = v.getTexCoord(); - texCoordTxtAttr.putf(tex[0]); - texCoordTxtAttr.putf(tex[1]); - } - texCoordTxtAttr.seal(gl, true); - texCoordTxtAttr.enableBuffer(gl, false); - verticeTxtAttr.seal(gl, true); - verticeTxtAttr.enableBuffer(gl, false); - - // update all bbox related data - verticeFboAttr.seal(gl, false); - verticeFboAttr.rewind(); - verticeFboAttr.putf(box.getLow()[0]); verticeFboAttr.putf(box.getLow()[1]); verticeFboAttr.putf(box.getLow()[2]); - verticeFboAttr.putf(box.getLow()[0]); verticeFboAttr.putf(box.getHigh()[1]); verticeFboAttr.putf(box.getLow()[2]); - verticeFboAttr.putf(box.getHigh()[0]); verticeFboAttr.putf(box.getHigh()[1]); verticeFboAttr.putf(box.getLow()[2]); - verticeFboAttr.putf(box.getHigh()[0]); verticeFboAttr.putf(box.getLow()[1]); verticeFboAttr.putf(box.getLow()[2]); - verticeFboAttr.seal(gl, true); - verticeFboAttr.enableBuffer(gl, false); - - fboPMVMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION); - fboPMVMatrix.glLoadIdentity(); - fboPMVMatrix.glOrthof(box.getLow()[0], box.getHigh()[0], box.getLow()[1], box.getHigh()[1], -1, 1); - - // push data 2 GPU .. - indicesFbo.seal(gl, true); - indicesFbo.enableBuffer(gl, false); - - setDirty(false); - - // the buffers were disabled, since due to real/fbo switching and other vbo usage - } - - int[] maxTexSize = new int[] { -1 } ; - - protected void drawImpl(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int[/*1*/] texWidth) { - if(vp_width <=0 || vp_height <= 0 || null==texWidth || texWidth[0] <= 0){ - renderRegion(gl); - } else { - if(0 > maxTexSize[0]) { - gl.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, maxTexSize, 0); - } - if(texWidth[0] != tex_width_c) { - if(texWidth[0] > maxTexSize[0]) { - texWidth[0] = maxTexSize[0]; // clip to max - write-back user value! - } - renderRegion2FBO(gl, rs, texWidth); - } - // System.out.println("Scale: " + matrix.glGetMatrixf().get(1+4*3) +" " + matrix.glGetMatrixf().get(2+4*3)); - renderFBO(gl, rs, vp_width, vp_height); - } - } - - private void renderFBO(GL2ES2 gl, RenderState rs, int width, int hight) { - final ShaderState st = rs.getShaderState(); - - gl.glViewport(0, 0, width, hight); - st.uniform(gl, mgl_ActiveTexture); - gl.glActiveTexture(GL.GL_TEXTURE0 + mgl_ActiveTexture.intValue()); - fbo.use(gl, texA); - verticeFboAttr.enableBuffer(gl, true); - texCoordFboAttr.enableBuffer(gl, true); - indicesFbo.enableBuffer(gl, true); - - gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesFbo.getElementCount() * indicesFbo.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); - - verticeFboAttr.enableBuffer(gl, false); - texCoordFboAttr.enableBuffer(gl, false); - indicesFbo.enableBuffer(gl, false); - fbo.unuse(gl); - - // setback: gl.glActiveTexture(currentActiveTextureEngine[0]); - } - - private void renderRegion2FBO(GL2ES2 gl, RenderState rs, int[/*1*/] texWidth) { - final ShaderState st = rs.getShaderState(); - - if(0>=texWidth[0]) { - throw new IllegalArgumentException("texWidth must be greater than 0: "+texWidth[0]); - } - - tex_width_c = texWidth[0]; - tex_height_c = (int) ( ( ( tex_width_c * box.getHeight() ) / box.getWidth() ) + 0.5f ); - - // System.out.println("FBO Size: "+texWidth[0]+" -> "+tex_width_c+"x"+tex_height_c); - // System.out.println("FBO Scale: " + m.glGetMatrixf().get(0) +" " + m.glGetMatrixf().get(5)); - - if(null != fbo && fbo.getWidth() != tex_width_c && fbo.getHeight() != tex_height_c ) { - fbo.reset(gl, tex_width_c, tex_height_c); - } - - if(null == fbo) { - fbo = new FBObject(); - fbo.reset(gl, tex_width_c, tex_height_c); - // FIXME: shall not use bilinear, due to own AA ? However, w/o bilinear result is not smooth - texA = fbo.attachTexture2D(gl, 0, true, GL2ES2.GL_LINEAR, GL2ES2.GL_LINEAR, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE); - // texA = fbo.attachTexture2D(gl, 0, GL2ES2.GL_NEAREST, GL2ES2.GL_NEAREST, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE); - fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24); - } else { - fbo.bind(gl); - } - - //render texture - gl.glViewport(0, 0, tex_width_c, tex_height_c); - st.uniform(gl, mgl_fboPMVMatrix); // use orthogonal matrix - - gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - gl.glClear(GL2ES2.GL_COLOR_BUFFER_BIT | GL2ES2.GL_DEPTH_BUFFER_BIT); - renderRegion(gl); - fbo.unbind(gl); - - st.uniform(gl, rs.getPMVMatrix()); // switch back to real PMV matrix - - // if( !gl.isGL3() ) { - // GLSL < 1.30 - if(null == mgl_TextureSize) { - mgl_TextureSize = new GLUniformData(UniformNames.gcu_TextureSize, 2, Buffers.newDirectFloatBuffer(2)); - } - final FloatBuffer texSize = (FloatBuffer) mgl_TextureSize.getBuffer(); - texSize.put(0, (float)fbo.getWidth()); - texSize.put(1, (float)fbo.getHeight()); - st.uniform(gl, mgl_TextureSize); - //} - } - - private void renderRegion(GL2ES2 gl) { - verticeTxtAttr.enableBuffer(gl, true); - texCoordTxtAttr.enableBuffer(gl, true); - indicesTxt.enableBuffer(gl, true); - - gl.glDrawElements(GL2ES2.GL_TRIANGLES, indicesTxt.getElementCount() * indicesTxt.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); - - verticeTxtAttr.enableBuffer(gl, false); - texCoordTxtAttr.enableBuffer(gl, false); - indicesTxt.enableBuffer(gl, false); - } - - public void destroy(GL2ES2 gl, RenderState rs) { - if(DEBUG_INSTANCE) { - System.err.println("VBORegion2PES2 Destroy: " + this); - } - final ShaderState st = rs.getShaderState(); - if(null != fbo) { - fbo.destroy(gl); - fbo = null; - texA = null; - } - if(null != verticeTxtAttr) { - st.ownAttribute(verticeTxtAttr, false); - verticeTxtAttr.destroy(gl); - verticeTxtAttr = null; - } - if(null != texCoordTxtAttr) { - st.ownAttribute(texCoordTxtAttr, false); - texCoordTxtAttr.destroy(gl); - texCoordTxtAttr = null; - } - if(null != indicesTxt) { - indicesTxt.destroy(gl); - indicesTxt = null; - } - if(null != verticeFboAttr) { - st.ownAttribute(verticeFboAttr, false); - verticeFboAttr.destroy(gl); - verticeFboAttr = null; - } - if(null != texCoordFboAttr) { - st.ownAttribute(texCoordFboAttr, false); - texCoordFboAttr.destroy(gl); - texCoordFboAttr = null; - } - if(null != indicesFbo) { - indicesFbo.destroy(gl); - indicesFbo = null; - } - triangles.clear(); - vertices.clear(); - } -} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java new file mode 100644 index 000000000..fbd40ebdd --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java @@ -0,0 +1,586 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package jogamp.graph.curve.opengl; + +import java.nio.FloatBuffer; + +import javax.media.opengl.GL2ES2; +import javax.media.opengl.GL; +import javax.media.opengl.GLUniformData; + +import jogamp.graph.curve.opengl.shader.AttributeNames; +import jogamp.graph.curve.opengl.shader.UniformNames; + +import com.jogamp.graph.curve.opengl.GLRegion; +import com.jogamp.graph.curve.opengl.RegionRenderer; +import com.jogamp.graph.curve.opengl.RenderState; +import com.jogamp.opengl.FBObject; +import com.jogamp.opengl.FBObject.Attachment; +import com.jogamp.opengl.math.FloatUtil; +import com.jogamp.opengl.math.geom.AABBox; +import com.jogamp.opengl.util.GLArrayDataServer; +import com.jogamp.opengl.util.glsl.ShaderProgram; +import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureCoords; +import com.jogamp.opengl.util.texture.TextureSequence; + +public class VBORegion2PMSAAES2 extends GLRegion { + private static final boolean DEBUG_FBO_1 = false; + private static final boolean DEBUG_FBO_2 = false; + + private final RenderState.ProgramLocal rsLocal; + + // Pass-1: + private GLArrayDataServer gca_VerticesAttr; + private GLArrayDataServer gca_CurveParamsAttr; + private GLArrayDataServer gca_ColorsAttr; + private GLArrayDataServer indicesBuffer; + private final GLUniformData gcu_ColorTexUnit; + private final float[] colorTexBBox; // x0, y0, x1, y1 + private final GLUniformData gcu_ColorTexBBox; + private ShaderProgram spPass1 = null; + + // Pass-2: + private GLArrayDataServer gca_FboVerticesAttr; + private GLArrayDataServer gca_FboTexCoordsAttr; + private GLArrayDataServer indicesFbo; + private final GLUniformData gcu_FboTexUnit; + private final float[] pmvMatrix02 = new float[2*16]; // P + Mv + private final GLUniformData gcu_PMVMatrix02; + private ShaderProgram spPass2 = null; + + private FBObject fbo; + + private int fboWidth = 0; + private int fboHeight = 0; + private boolean fboDirty = true; + + final int[] maxTexSize = new int[] { -1 } ; + + /** + * <p> + * Since multiple {@link Region}s may share one + * {@link ShaderProgram}, the uniform data must always be updated. + * </p> + * + * @param gl + * @param renderer + * @param renderModes + * @param pass1 + * @param quality + * @param sampleCount + */ + public void useShaderProgram(final GL2ES2 gl, final RegionRenderer renderer, final int renderModes, final boolean pass1, final int quality, final int sampleCount) { + final RenderState rs = renderer.getRenderState(); + final boolean updateLocGlobal = renderer.useShaderProgram(gl, renderModes, pass1, quality, sampleCount, colorTexSeq); + final ShaderProgram sp = renderer.getRenderState().getShaderProgram(); + final boolean updateLocLocal; + if( pass1 ) { + updateLocLocal = !sp.equals(spPass1); + spPass1 = sp; + if( DEBUG ) { + System.err.println("XXX changedSP.p1 updateLocation loc "+updateLocLocal+" / glob "+updateLocGlobal); + } + if( updateLocLocal ) { + rs.updateAttributeLoc(gl, true, gca_VerticesAttr, true); + rs.updateAttributeLoc(gl, true, gca_CurveParamsAttr, true); + if( null != gca_ColorsAttr ) { + rs.updateAttributeLoc(gl, true, gca_ColorsAttr, true); + } + } + rsLocal.update(gl, rs, updateLocLocal, renderModes, true, true); + rs.updateUniformLoc(gl, updateLocLocal, gcu_PMVMatrix02, true); + if( null != gcu_ColorTexUnit ) { + rs.updateUniformLoc(gl, updateLocLocal, gcu_ColorTexUnit, true); + rs.updateUniformLoc(gl, updateLocLocal, gcu_ColorTexBBox, true); + } + } else { + updateLocLocal = !sp.equals(spPass2); + spPass2 = sp; + if( DEBUG ) { + System.err.println("XXX changedSP.p2 updateLocation loc "+updateLocLocal+" / glob "+updateLocGlobal); + } + if( updateLocLocal ) { + rs.updateAttributeLoc(gl, true, gca_FboVerticesAttr, true); + rs.updateAttributeLoc(gl, true, gca_FboTexCoordsAttr, true); + } + rsLocal.update(gl, rs, updateLocLocal, renderModes, false, true); + rs.updateUniformDataLoc(gl, updateLocLocal, false /* updateData */, gcu_FboTexUnit, true); // FIXME always update if changing tex-unit + } + } + + public VBORegion2PMSAAES2(final int renderModes, final TextureSequence colorTexSeq, final int pass2TexUnit) { + super(renderModes, colorTexSeq); + + rsLocal = new RenderState.ProgramLocal(); + + final int initialElementCount = 256; + + // Pass 1: + indicesBuffer = GLArrayDataServer.createData(3, GL.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); + + gca_VerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL.GL_FLOAT, + false, initialElementCount, GL.GL_STATIC_DRAW); + + gca_CurveParamsAttr = GLArrayDataServer.createGLSL(AttributeNames.CURVEPARAMS_ATTR_NAME, 3, GL.GL_FLOAT, + false, initialElementCount, GL.GL_STATIC_DRAW); + + if( hasColorChannel() ) { + gca_ColorsAttr = GLArrayDataServer.createGLSL(AttributeNames.COLOR_ATTR_NAME, 4, GL.GL_FLOAT, + false, initialElementCount, GL.GL_STATIC_DRAW); + } else { + gca_ColorsAttr = null; + } + if( hasColorTexture() ) { + gcu_ColorTexUnit = new GLUniformData(UniformNames.gcu_ColorTexUnit, colorTexSeq.getTextureUnit()); + colorTexBBox = new float[4]; + gcu_ColorTexBBox = new GLUniformData(UniformNames.gcu_ColorTexBBox, 4, FloatBuffer.wrap(colorTexBBox)); + } else { + gcu_ColorTexUnit = null; + colorTexBBox = null; + gcu_ColorTexBBox = null; + } + + FloatUtil.makeIdentity(pmvMatrix02, 0); + FloatUtil.makeIdentity(pmvMatrix02, 16); + gcu_PMVMatrix02 = new GLUniformData(UniformNames.gcu_PMVMatrix02, 4, 4, FloatBuffer.wrap(pmvMatrix02)); + + // Pass 2: + gcu_FboTexUnit = new GLUniformData(UniformNames.gcu_FboTexUnit, pass2TexUnit); + + indicesFbo = GLArrayDataServer.createData(3, GL.GL_SHORT, 2, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); + indicesFbo.puts((short) 0); indicesFbo.puts((short) 1); indicesFbo.puts((short) 3); + indicesFbo.puts((short) 1); indicesFbo.puts((short) 2); indicesFbo.puts((short) 3); + indicesFbo.seal(true); + + gca_FboTexCoordsAttr = GLArrayDataServer.createGLSL(AttributeNames.FBO_TEXCOORDS_ATTR_NAME, 2, GL.GL_FLOAT, + false, 4, GL.GL_STATIC_DRAW); + gca_FboTexCoordsAttr.putf(0); gca_FboTexCoordsAttr.putf(0); + gca_FboTexCoordsAttr.putf(0); gca_FboTexCoordsAttr.putf(1); + gca_FboTexCoordsAttr.putf(1); gca_FboTexCoordsAttr.putf(1); + gca_FboTexCoordsAttr.putf(1); gca_FboTexCoordsAttr.putf(0); + gca_FboTexCoordsAttr.seal(true); + + gca_FboVerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.FBO_VERTEX_ATTR_NAME, 3, GL.GL_FLOAT, + false, 4, GL.GL_STATIC_DRAW); + } + + @Override + protected final void clearImpl(final GL2ES2 gl) { + if( null != indicesBuffer ) { + indicesBuffer.seal(gl, false); + indicesBuffer.rewind(); + } + if( null != gca_VerticesAttr ) { + gca_VerticesAttr.seal(gl, false); + gca_VerticesAttr.rewind(); + } + if( null != gca_CurveParamsAttr ) { + gca_CurveParamsAttr.seal(gl, false); + gca_CurveParamsAttr.rewind(); + } + if( null != gca_ColorsAttr ) { + gca_ColorsAttr.seal(gl, false); + gca_ColorsAttr.rewind(); + } + fboDirty = true; + } + + @Override + protected final void pushVertex(final float[] coords, final float[] texParams, final float[] rgba) { + gca_VerticesAttr.putf(coords[0]); + gca_VerticesAttr.putf(coords[1]); + gca_VerticesAttr.putf(coords[2]); + + gca_CurveParamsAttr.putf(texParams[0]); + gca_CurveParamsAttr.putf(texParams[1]); + gca_CurveParamsAttr.putf(texParams[2]); + + if( null != gca_ColorsAttr ) { + if( null != rgba ) { + gca_ColorsAttr.putf(rgba[0]); + gca_ColorsAttr.putf(rgba[1]); + gca_ColorsAttr.putf(rgba[2]); + gca_ColorsAttr.putf(rgba[3]); + } else { + throw new IllegalArgumentException("Null color given for COLOR_CHANNEL rendering mode"); + } + } + } + + @Override + protected final void pushIndex(final int idx) { + indicesBuffer.puts((short)idx); + } + + @Override + protected void updateImpl(final GL2ES2 gl) { + // seal buffers + indicesBuffer.seal(gl, true); + indicesBuffer.enableBuffer(gl, false); + gca_CurveParamsAttr.seal(gl, true); + gca_CurveParamsAttr.enableBuffer(gl, false); + gca_VerticesAttr.seal(gl, true); + gca_VerticesAttr.enableBuffer(gl, false); + if( null != gca_ColorsAttr ) { + gca_ColorsAttr.seal(gl, true); + gca_ColorsAttr.enableBuffer(gl, false); + } + if( null != gcu_ColorTexUnit && colorTexSeq.isTextureAvailable() ) { + final TextureSequence.TextureFrame frame = colorTexSeq.getLastTexture(); + final Texture tex = frame.getTexture(); + final TextureCoords tc = tex.getImageTexCoords(); + final float tcSx = 1f / ( tc.right() - tc.left() ); + colorTexBBox[0] = box.getMinX() * tcSx; + colorTexBBox[2] = box.getMaxX() * tcSx; + if( tex.getMustFlipVertically() ) { + final float tcSy = 1f / ( tc.bottom() - tc.top() ); + colorTexBBox[1] = box.getMaxY() * tcSy; + colorTexBBox[3] = box.getMinY() * tcSy; + } else { + final float tcSy = 1f / ( tc.top() - tc.bottom() ); + colorTexBBox[1] = box.getMinY() * tcSy; + colorTexBBox[3] = box.getMaxY() * tcSy; + } + } + gca_FboVerticesAttr.seal(gl, false); + { + final FloatBuffer fb = (FloatBuffer)gca_FboVerticesAttr.getBuffer(); + fb.put( 2, box.getMinZ()); + fb.put( 5, box.getMinZ()); + fb.put( 8, box.getMinZ()); + fb.put(11, box.getMinZ()); + } + // Pending gca_FboVerticesAttr-seal and fboPMVMatrix-setup, follow fboDirty + + // push data 2 GPU .. + indicesFbo.seal(gl, true); + indicesFbo.enableBuffer(gl, false); + + fboDirty = true; + // the buffers were disabled, since due to real/fbo switching and other vbo usage + } + + private final AABBox drawWinBox = new AABBox(); + private final int[] drawView = new int[] { 0, 0, 0, 0 }; + private final float[] drawVec4Tmp0 = new float[4]; + private final float[] drawVec4Tmp1 = new float[4]; + private final float[] drawVec4Tmp2 = new float[4]; + private final float[] drawMat4PMv = new float[16]; + + private static final int border = 2; // surrounding border, i.e. width += 2*border, height +=2*border + + @Override + protected void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, final int[/*1*/] sampleCount) { + if( 0 >= indicesBuffer.getElementCount() ) { + if(DEBUG_INSTANCE) { + System.err.printf("VBORegion2PMSAAES2.drawImpl: Empty%n"); + } + return; // empty! + } + if( Float.isInfinite(box.getWidth()) || Float.isInfinite(box.getHeight()) ) { + if(DEBUG_INSTANCE) { + System.err.printf("VBORegion2PMSAAES2.drawImpl: Inf %s%n", box); + } + return; // inf + } + final int vpWidth = renderer.getWidth(); + final int vpHeight = renderer.getHeight(); + if(vpWidth <=0 || vpHeight <= 0 || null==sampleCount || sampleCount[0] <= 0){ + renderRegion(gl); + } else { + if(0 > maxTexSize[0]) { + gl.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, maxTexSize, 0); + } + final RenderState rs = renderer.getRenderState(); + final float winWidth, winHeight; + + final float ratioObjWinWidth, ratioObjWinHeight; + final float diffObjWidth, diffObjHeight; + final float diffObjBorderWidth, diffObjBorderHeight; + int targetFboWidth, targetFboHeight; + { + final float diffWinWidth, diffWinHeight; + final int targetWinWidth, targetWinHeight; + + // Calculate perspective pixel width/height for FBO, + // considering the sampleCount. + drawView[2] = vpWidth; + drawView[3] = vpHeight; + + renderer.getMatrix().multPMvMatrixf(drawMat4PMv, 0); + box.mapToWindow(drawWinBox, drawMat4PMv, drawView, true /* useCenterZ */, + drawVec4Tmp0, drawVec4Tmp1, drawVec4Tmp2); + + winWidth = drawWinBox.getWidth(); + winHeight = drawWinBox.getHeight(); + targetWinWidth = (int)Math.ceil(winWidth); + targetWinHeight = (int)Math.ceil(winHeight); + diffWinWidth = targetWinWidth-winWidth; + diffWinHeight = targetWinHeight-winHeight; + + ratioObjWinWidth = box.getWidth() / winWidth; + ratioObjWinHeight= box.getHeight() / winHeight; + diffObjWidth = diffWinWidth * ratioObjWinWidth; + diffObjHeight = diffWinHeight * ratioObjWinHeight; + diffObjBorderWidth = border * ratioObjWinWidth; + diffObjBorderHeight = border * ratioObjWinHeight; + + targetFboWidth = targetWinWidth+2*border; + targetFboHeight = targetWinHeight+2*border; + + if( DEBUG_FBO_2 ) { + final float ratioWinWidth, ratioWinHeight; + ratioWinWidth = winWidth/targetWinWidth; + ratioWinHeight = winHeight/targetWinHeight; + + System.err.printf("XXX.MinMax obj %s%n", box.toString()); + System.err.printf("XXX.MinMax obj d[%.3f, %.3f], r[%f, %f], b[%f, %f]%n", + diffObjWidth, diffObjHeight, ratioObjWinWidth, ratioObjWinWidth, diffObjBorderWidth, diffObjBorderHeight); + System.err.printf("XXX.MinMax win %s%n", drawWinBox.toString()); + System.err.printf("XXX.MinMax view[%d, %d] -> win[%.3f, %.3f], i[%d x %d], d[%.3f, %.3f], r[%f, %f]: FBO i[%d x %d], samples %d%n", + drawView[2], drawView[3], + winWidth, winHeight, targetWinWidth, targetWinHeight, diffWinWidth, + diffWinHeight, ratioWinWidth, ratioWinHeight, + targetFboWidth, targetFboHeight, + sampleCount[0]); + } + } + if( 0 >= targetFboWidth || 0 >= targetFboHeight ) { + // Nothing .. + return; + } + final int deltaFboWidth = Math.abs(targetFboWidth-fboWidth); + final int deltaFboHeight = Math.abs(targetFboHeight-fboHeight); + final boolean hasDelta = 0!=deltaFboWidth || 0!=deltaFboHeight; + if( DEBUG_FBO_2 ) { + System.err.printf("XXX.maxDelta: hasDelta %b: %d / %d, %.3f, %.3f%n", + hasDelta, deltaFboWidth, deltaFboHeight, (float)deltaFboWidth/fboWidth, (float)deltaFboHeight/fboHeight); + System.err.printf("XXX.Scale %d * [%f x %f]: %d x %d%n", + sampleCount[0], winWidth, winHeight, targetFboWidth, targetFboHeight); + } + if( hasDelta || fboDirty || isShapeDirty() || null == fbo || fbo.getNumSamples() != sampleCount[0] ) { + // FIXME: rescale + final float minX = box.getMinX()-diffObjBorderWidth; + final float minY = box.getMinY()-diffObjBorderHeight; + final float maxX = box.getMaxX()+diffObjBorderWidth+diffObjWidth; + final float maxY = box.getMaxY()+diffObjBorderHeight+diffObjHeight; + gca_FboVerticesAttr.seal(false); + { + final FloatBuffer fb = (FloatBuffer)gca_FboVerticesAttr.getBuffer(); + fb.put(0, minX); fb.put( 1, minY); + fb.put(3, minX); fb.put( 4, maxY); + fb.put(6, maxX); fb.put( 7, maxY); + fb.put(9, maxX); fb.put(10, minY); + fb.position(12); + } + gca_FboVerticesAttr.seal(true); + FloatUtil.makeOrtho(pmvMatrix02, 0, true, minX, maxX, minY, maxY, -1, 1); + useShaderProgram(gl, renderer, getRenderModes(), true, getQuality(), sampleCount[0]); + renderRegion2FBO(gl, rs, targetFboWidth, targetFboHeight, vpWidth, vpHeight, sampleCount); + } else if( isStateDirty() ) { + useShaderProgram(gl, renderer, getRenderModes(), true, getQuality(), sampleCount[0]); + renderRegion2FBO(gl, rs, targetFboWidth, targetFboHeight, vpWidth, vpHeight, sampleCount); + } + useShaderProgram(gl, renderer, getRenderModes(), false, getQuality(), sampleCount[0]); + renderFBO(gl, rs, vpWidth, vpHeight, sampleCount[0]); + } + } + + private void renderFBO(final GL2ES2 gl, final RenderState rs, final int width, final int height, final int sampleCount) { + gl.glViewport(0, 0, width, height); + + if( rs.isHintMaskSet(RenderState.BITHINT_BLENDING_ENABLED | RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED) ) { + // RGB is already multiplied w/ alpha via renderRegion2FBO(..) + gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA); + gl.glEnable(GL.GL_DEPTH_TEST); + + } else if( rs.isHintMaskSet(RenderState.BITHINT_BLENDING_ENABLED) ) { + // RGB is already multiplied w/ alpha via renderRegion2FBO(..) + gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA); + } + + gl.glActiveTexture(GL.GL_TEXTURE0 + gcu_FboTexUnit.intValue()); + + fbo.use(gl, fbo.getSamplingSink().getTextureAttachment()); + gca_FboVerticesAttr.enableBuffer(gl, true); + gca_FboTexCoordsAttr.enableBuffer(gl, true); + indicesFbo.bindBuffer(gl, true); // keeps VBO binding + + gl.glDrawElements(GL.GL_TRIANGLES, indicesFbo.getElementCount() * indicesFbo.getComponentCount(), GL.GL_UNSIGNED_SHORT, 0); + + indicesFbo.bindBuffer(gl, false); + gca_FboTexCoordsAttr.enableBuffer(gl, false); + gca_FboVerticesAttr.enableBuffer(gl, false); + fbo.unuse(gl); + + // setback: gl.glActiveTexture(currentActiveTextureEngine[0]); + } + + private void renderRegion2FBO(final GL2ES2 gl, final RenderState rs, final int targetFboWidth, final int targetFboHeight, + final int vpWidth, final int vpHeight, final int[] sampleCount) { + if( 0 >= targetFboWidth || 0 >= targetFboHeight ) { + throw new IllegalArgumentException("fboSize must be greater than 0: "+targetFboWidth+"x"+targetFboHeight); + } + + final boolean blendingEnabled = rs.isHintMaskSet(RenderState.BITHINT_BLENDING_ENABLED); + + if(null == fbo) { + fboWidth = targetFboWidth; + fboHeight = targetFboHeight; + fbo = new FBObject(); + fbo.init(gl, fboWidth, fboHeight, sampleCount[0]); + sampleCount[0] = fbo.getNumSamples(); + fbo.attachColorbuffer(gl, 0, true); + if( !blendingEnabled ) { + // no depth-buffer w/ blending + fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, FBObject.DEFAULT_BITS); + } + final FBObject ssink = new FBObject(); + { + ssink.init(gl, fboWidth, fboHeight, 0); + // FIXME: shall not use bilinear (GL_LINEAR), due to MSAA ??? + // ssink.attachTexture2D(gl, 0, true, GL2ES2.GL_LINEAR, GL2ES2.GL_LINEAR, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE); + ssink.attachTexture2D(gl, 0, true, GL.GL_NEAREST, GL.GL_NEAREST, GL.GL_CLAMP_TO_EDGE, GL.GL_CLAMP_TO_EDGE); + if( !blendingEnabled ) { + // no depth-buffer w/ blending + ssink.attachRenderbuffer(gl, Attachment.Type.DEPTH, FBObject.DEFAULT_BITS); + } + } + fbo.setSamplingSink(ssink); + fbo.resetSamplingSink(gl); // validate + if( DEBUG_FBO_1 ) { + System.err.printf("XXX.createFBO: blending %b, %dx%d%n%s%n", blendingEnabled, fboWidth, fboHeight, fbo.toString()); + } + } else if( targetFboWidth != fboWidth || targetFboHeight != fboHeight || fbo.getNumSamples() != sampleCount[0] ) { + fbo.reset(gl, targetFboWidth, targetFboHeight, sampleCount[0]); + sampleCount[0] = fbo.getNumSamples(); + if( DEBUG_FBO_1 ) { + System.err.printf("XXX.resetFBO: %dx%d -> %dx%d%n%s%n", fboWidth, fboHeight, targetFboWidth, targetFboHeight, fbo ); + } + fboWidth = targetFboWidth; + fboHeight = targetFboHeight; + } + fbo.bind(gl); + + //render texture + gl.glViewport(0, 0, fboWidth, fboHeight); + if( blendingEnabled ) { + gl.glClearColor(0f, 0f, 0f, 0.0f); + gl.glClear(GL.GL_COLOR_BUFFER_BIT); // no depth-buffer w/ blending + // For already pre-multiplied alpha values, use: + // gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA); + + // Multiply RGB w/ Alpha, preserve alpha for renderFBO(..) + gl.glBlendFuncSeparate(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA, GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA); + + if( rs.isHintMaskSet(RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED) ) { + gl.glDisable(GL.GL_DEPTH_TEST); + } + } else { + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + } + + renderRegion(gl); + + fbo.unbind(gl); + fboDirty = false; + } + + private void renderRegion(final GL2ES2 gl) { + gl.glUniform(gcu_PMVMatrix02); + gca_VerticesAttr.enableBuffer(gl, true); + gca_CurveParamsAttr.enableBuffer(gl, true); + if( null != gca_ColorsAttr ) { + gca_ColorsAttr.enableBuffer(gl, true); + } + indicesBuffer.bindBuffer(gl, true); // keeps VBO binding + if( null != gcu_ColorTexUnit && colorTexSeq.isTextureAvailable() ) { + final TextureSequence.TextureFrame frame = colorTexSeq.getNextTexture(gl); + gl.glActiveTexture(GL.GL_TEXTURE0 + colorTexSeq.getTextureUnit()); + final Texture tex = frame.getTexture(); + tex.bind(gl); + tex.enable(gl); // nop on core + gcu_ColorTexUnit.setData(colorTexSeq.getTextureUnit()); + gl.glUniform(gcu_ColorTexUnit); // Always update, since program maybe used by multiple regions + gl.glUniform(gcu_ColorTexBBox); // Always update, since program maybe used by multiple regions + gl.glDrawElements(GL.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL.GL_UNSIGNED_SHORT, 0); + tex.disable(gl); // nop on core + } else { + gl.glDrawElements(GL.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL.GL_UNSIGNED_SHORT, 0); + } + + indicesBuffer.bindBuffer(gl, false); + if( null != gca_ColorsAttr ) { + gca_ColorsAttr.enableBuffer(gl, false); + } + gca_CurveParamsAttr.enableBuffer(gl, false); + gca_VerticesAttr.enableBuffer(gl, false); + } + + @Override + protected void destroyImpl(final GL2ES2 gl) { + if(DEBUG_INSTANCE) { + System.err.println("VBORegion2PES2 Destroy: " + this); + } + if(null != fbo) { + fbo.destroy(gl); + fbo = null; + } + if(null != gca_VerticesAttr) { + gca_VerticesAttr.destroy(gl); + gca_VerticesAttr = null; + } + if(null != gca_CurveParamsAttr) { + gca_CurveParamsAttr.destroy(gl); + gca_CurveParamsAttr = null; + } + if(null != gca_ColorsAttr) { + gca_ColorsAttr.destroy(gl); + gca_ColorsAttr = null; + } + if(null != indicesBuffer) { + indicesBuffer.destroy(gl); + indicesBuffer = null; + } + if(null != gca_FboVerticesAttr) { + gca_FboVerticesAttr.destroy(gl); + gca_FboVerticesAttr = null; + } + if(null != gca_FboTexCoordsAttr) { + gca_FboTexCoordsAttr.destroy(gl); + gca_FboTexCoordsAttr = null; + } + if(null != indicesFbo) { + indicesFbo.destroy(gl); + indicesFbo = null; + } + spPass1 = null; + spPass2 = null; + } +} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java new file mode 100644 index 000000000..8f1de9157 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java @@ -0,0 +1,700 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package jogamp.graph.curve.opengl; + +import java.nio.FloatBuffer; + +import javax.media.opengl.GL2ES2; +import javax.media.opengl.GL; +import javax.media.opengl.GLUniformData; + +import jogamp.graph.curve.opengl.shader.AttributeNames; +import jogamp.graph.curve.opengl.shader.UniformNames; +import jogamp.opengl.Debug; + +import com.jogamp.common.util.PropertyAccess; +import com.jogamp.graph.curve.Region; +import com.jogamp.graph.curve.opengl.GLRegion; +import com.jogamp.graph.curve.opengl.RegionRenderer; +import com.jogamp.graph.curve.opengl.RenderState; +import com.jogamp.opengl.FBObject; +import com.jogamp.opengl.FBObject.Attachment; +import com.jogamp.opengl.FBObject.TextureAttachment; +import com.jogamp.opengl.math.FloatUtil; +import com.jogamp.opengl.math.geom.AABBox; +import com.jogamp.opengl.util.GLArrayDataServer; +import com.jogamp.opengl.util.glsl.ShaderProgram; +import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureCoords; +import com.jogamp.opengl.util.texture.TextureSequence; + +public class VBORegion2PVBAAES2 extends GLRegion { + private static final boolean DEBUG_FBO_1 = false; + private static final boolean DEBUG_FBO_2 = false; + + /** + * Boundary triggering FBO resize if + * <pre> + * fbo[Width|Height] - targetFbo[Width|Height] > RESIZE_BOUNDARY. + * </pre> + * <p> + * Increasing the FBO will add RESIZE_BOUNDARY/2. + * </p> + * <p> + * Reducing FBO resize to gain performance. + * </p> + * <p> + * Defaults to disabled since: + * - not working properly + * - FBO texture rendered > than desired size + * - FBO resize itself should be fast enough ?! + * </p> + */ + private static final int RESIZE_BOUNDARY; + + static { + Debug.initSingleton(); + final String key = "jogl.debug.graph.curve.vbaa.resizeLowerBoundary"; + RESIZE_BOUNDARY = Math.max(0, PropertyAccess.getIntProperty(key, true, 0)); + if( RESIZE_BOUNDARY > 0 ) { + System.err.println("key: "+RESIZE_BOUNDARY); + } + } + + + private final RenderState.ProgramLocal rsLocal; + + // Pass-1: + private GLArrayDataServer gca_VerticesAttr; + private GLArrayDataServer gca_CurveParamsAttr; + private GLArrayDataServer gca_ColorsAttr; + private GLArrayDataServer indicesBuffer; + private final GLUniformData gcu_ColorTexUnit; + private final float[] colorTexBBox; // x0, y0, x1, y1 + private final GLUniformData gcu_ColorTexBBox; + private ShaderProgram spPass1 = null; + + // Pass-2: + private GLArrayDataServer gca_FboVerticesAttr; + private GLArrayDataServer gca_FboTexCoordsAttr; + private GLArrayDataServer indicesFbo; + private final GLUniformData gcu_FboTexUnit; + private final GLUniformData gcu_FboTexSize; + private final float[] pmvMatrix02 = new float[2*16]; // P + Mv + private final GLUniformData gcu_PMVMatrix02; + private ShaderProgram spPass2 = null; + + private FBObject fbo; + private TextureAttachment texA; + + private int fboWidth = 0; + private int fboHeight = 0; + private boolean fboDirty = true; + + final int[] maxTexSize = new int[] { -1 } ; + + /** + * <p> + * Since multiple {@link Region}s may share one + * {@link ShaderProgram}, the uniform data must always be updated. + * </p> + * + * @param gl + * @param renderer + * @param renderModes + * @param pass1 + * @param quality + * @param sampleCount + */ + public void useShaderProgram(final GL2ES2 gl, final RegionRenderer renderer, final int renderModes, final boolean pass1, final int quality, final int sampleCount) { + final RenderState rs = renderer.getRenderState(); + final boolean updateLocGlobal = renderer.useShaderProgram(gl, renderModes, pass1, quality, sampleCount, colorTexSeq); + final ShaderProgram sp = renderer.getRenderState().getShaderProgram(); + final boolean updateLocLocal; + if( pass1 ) { + updateLocLocal = !sp.equals(spPass1); + spPass1 = sp; + if( DEBUG ) { + System.err.println("XXX changedSP.p1 updateLocation loc "+updateLocLocal+" / glob "+updateLocGlobal); + } + if( updateLocLocal ) { + rs.updateAttributeLoc(gl, true, gca_VerticesAttr, true); + rs.updateAttributeLoc(gl, true, gca_CurveParamsAttr, true); + if( null != gca_ColorsAttr ) { + rs.updateAttributeLoc(gl, true, gca_ColorsAttr, true); + } + } + rsLocal.update(gl, rs, updateLocLocal, renderModes, true, true); + rs.updateUniformLoc(gl, updateLocLocal, gcu_PMVMatrix02, true); + if( null != gcu_ColorTexUnit ) { + rs.updateUniformLoc(gl, updateLocLocal, gcu_ColorTexUnit, true); + rs.updateUniformLoc(gl, updateLocLocal, gcu_ColorTexBBox, true); + } + } else { + updateLocLocal = !sp.equals(spPass2); + spPass2 = sp; + if( DEBUG ) { + System.err.println("XXX changedSP.p2 updateLocation loc "+updateLocLocal+" / glob "+updateLocGlobal); + } + if( updateLocLocal ) { + rs.updateAttributeLoc(gl, true, gca_FboVerticesAttr, true); + rs.updateAttributeLoc(gl, true, gca_FboTexCoordsAttr, true); + } + rsLocal.update(gl, rs, updateLocLocal, renderModes, false, true); + rs.updateUniformDataLoc(gl, updateLocLocal, false /* updateData */, gcu_FboTexUnit, true); // FIXME always update if changing tex-unit + rs.updateUniformLoc(gl, updateLocLocal, gcu_FboTexSize, sampleCount > 1); // maybe optimized away for sampleCount <= 1 + } + } + + public VBORegion2PVBAAES2(final int renderModes, final TextureSequence colorTexSeq, final int pass2TexUnit) { + super(renderModes, colorTexSeq); + + rsLocal = new RenderState.ProgramLocal(); + + final int initialElementCount = 256; + + // Pass 1: + indicesBuffer = GLArrayDataServer.createData(3, GL.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); + + gca_VerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL.GL_FLOAT, + false, initialElementCount, GL.GL_STATIC_DRAW); + + gca_CurveParamsAttr = GLArrayDataServer.createGLSL(AttributeNames.CURVEPARAMS_ATTR_NAME, 3, GL.GL_FLOAT, + false, initialElementCount, GL.GL_STATIC_DRAW); + if( hasColorChannel() ) { + gca_ColorsAttr = GLArrayDataServer.createGLSL(AttributeNames.COLOR_ATTR_NAME, 4, GL.GL_FLOAT, + false, initialElementCount, GL.GL_STATIC_DRAW); + } else { + gca_ColorsAttr = null; + } + if( hasColorTexture() ) { + gcu_ColorTexUnit = new GLUniformData(UniformNames.gcu_ColorTexUnit, colorTexSeq.getTextureUnit()); + colorTexBBox = new float[4]; + gcu_ColorTexBBox = new GLUniformData(UniformNames.gcu_ColorTexBBox, 4, FloatBuffer.wrap(colorTexBBox)); + } else { + gcu_ColorTexUnit = null; + colorTexBBox = null; + gcu_ColorTexBBox = null; + } + + FloatUtil.makeIdentity(pmvMatrix02, 0); + FloatUtil.makeIdentity(pmvMatrix02, 16); + gcu_PMVMatrix02 = new GLUniformData(UniformNames.gcu_PMVMatrix02, 4, 4, FloatBuffer.wrap(pmvMatrix02)); + + // Pass 2: + gcu_FboTexUnit = new GLUniformData(UniformNames.gcu_FboTexUnit, pass2TexUnit); + gcu_FboTexSize = new GLUniformData(UniformNames.gcu_FboTexSize, 2, FloatBuffer.wrap(new float[2])); + + indicesFbo = GLArrayDataServer.createData(3, GL.GL_SHORT, 2, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); + indicesFbo.puts((short) 0); indicesFbo.puts((short) 1); indicesFbo.puts((short) 3); + indicesFbo.puts((short) 1); indicesFbo.puts((short) 2); indicesFbo.puts((short) 3); + indicesFbo.seal(true); + + gca_FboTexCoordsAttr = GLArrayDataServer.createGLSL(AttributeNames.FBO_TEXCOORDS_ATTR_NAME, 2, GL.GL_FLOAT, + false, 4, GL.GL_STATIC_DRAW); + gca_FboTexCoordsAttr.putf(0); gca_FboTexCoordsAttr.putf(0); + gca_FboTexCoordsAttr.putf(0); gca_FboTexCoordsAttr.putf(1); + gca_FboTexCoordsAttr.putf(1); gca_FboTexCoordsAttr.putf(1); + gca_FboTexCoordsAttr.putf(1); gca_FboTexCoordsAttr.putf(0); + gca_FboTexCoordsAttr.seal(true); + + gca_FboVerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.FBO_VERTEX_ATTR_NAME, 3, GL.GL_FLOAT, + false, 4, GL.GL_STATIC_DRAW); + } + + @Override + protected final void clearImpl(final GL2ES2 gl) { + if(DEBUG_INSTANCE) { + System.err.println("VBORegion2PES2 Clear: " + this); + // Thread.dumpStack(); + } + if( null != indicesBuffer ) { + indicesBuffer.seal(gl, false); + indicesBuffer.rewind(); + } + if( null != gca_VerticesAttr ) { + gca_VerticesAttr.seal(gl, false); + gca_VerticesAttr.rewind(); + } + if( null != gca_CurveParamsAttr ) { + gca_CurveParamsAttr.seal(gl, false); + gca_CurveParamsAttr.rewind(); + } + if( null != gca_ColorsAttr ) { + gca_ColorsAttr.seal(gl, false); + gca_ColorsAttr.rewind(); + } + fboDirty = true; + } + + @Override + protected final void pushVertex(final float[] coords, final float[] texParams, final float[] rgba) { + gca_VerticesAttr.putf(coords[0]); + gca_VerticesAttr.putf(coords[1]); + gca_VerticesAttr.putf(coords[2]); + + gca_CurveParamsAttr.putf(texParams[0]); + gca_CurveParamsAttr.putf(texParams[1]); + gca_CurveParamsAttr.putf(texParams[2]); + + if( null != gca_ColorsAttr ) { + if( null != rgba ) { + gca_ColorsAttr.putf(rgba[0]); + gca_ColorsAttr.putf(rgba[1]); + gca_ColorsAttr.putf(rgba[2]); + gca_ColorsAttr.putf(rgba[3]); + } else { + throw new IllegalArgumentException("Null color given for COLOR_CHANNEL rendering mode"); + } + } + } + + @Override + protected final void pushIndex(final int idx) { + indicesBuffer.puts((short)idx); + } + + @Override + protected void updateImpl(final GL2ES2 gl) { + // seal buffers + indicesBuffer.seal(gl, true); + indicesBuffer.enableBuffer(gl, false); + gca_CurveParamsAttr.seal(gl, true); + gca_CurveParamsAttr.enableBuffer(gl, false); + gca_VerticesAttr.seal(gl, true); + gca_VerticesAttr.enableBuffer(gl, false); + if( null != gca_ColorsAttr ) { + gca_ColorsAttr.seal(gl, true); + gca_ColorsAttr.enableBuffer(gl, false); + } + if( null != gcu_ColorTexUnit && colorTexSeq.isTextureAvailable() ) { + final TextureSequence.TextureFrame frame = colorTexSeq.getLastTexture(); + final Texture tex = frame.getTexture(); + final TextureCoords tc = tex.getImageTexCoords(); + final float tcSx = 1f / ( tc.right() - tc.left() ); + colorTexBBox[0] = box.getMinX() * tcSx; + colorTexBBox[2] = box.getMaxX() * tcSx; + if( tex.getMustFlipVertically() ) { + final float tcSy = 1f / ( tc.bottom() - tc.top() ); + colorTexBBox[1] = box.getMaxY() * tcSy; + colorTexBBox[3] = box.getMinY() * tcSy; + } else { + final float tcSy = 1f / ( tc.top() - tc.bottom() ); + colorTexBBox[1] = box.getMinY() * tcSy; + colorTexBBox[3] = box.getMaxY() * tcSy; + } + } + gca_FboVerticesAttr.seal(gl, false); + { + final FloatBuffer fb = (FloatBuffer)gca_FboVerticesAttr.getBuffer(); + fb.put( 2, box.getMinZ()); + fb.put( 5, box.getMinZ()); + fb.put( 8, box.getMinZ()); + fb.put(11, box.getMinZ()); + } + // Pending gca_FboVerticesAttr-seal and fboPMVMatrix-setup, follow fboDirty + + // push data 2 GPU .. + indicesFbo.seal(gl, true); + indicesFbo.enableBuffer(gl, false); + + fboDirty = true; + // the buffers were disabled, since due to real/fbo switching and other vbo usage + } + + private final AABBox drawWinBox = new AABBox(); + private final int[] drawView = new int[] { 0, 0, 0, 0 }; + private final float[] drawVec4Tmp0 = new float[4]; + private final float[] drawVec4Tmp1 = new float[4]; + private final float[] drawVec4Tmp2 = new float[4]; + private final float[] drawMat4PMv = new float[16]; + private static final int border = 2; // surrounding border, i.e. width += 2*border, height +=2*border + + @Override + protected void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, final int[/*1*/] sampleCount) { + if( 0 >= indicesBuffer.getElementCount() ) { + if(DEBUG_INSTANCE) { + System.err.printf("VBORegion2PVBAAES2.drawImpl: Empty%n"); + } + return; // empty! + } + if( Float.isInfinite(box.getWidth()) || Float.isInfinite(box.getHeight()) ) { + if(DEBUG_INSTANCE) { + System.err.printf("VBORegion2PVBAAES2.drawImpl: Inf %s%n", box); + } + return; // inf + } + final int vpWidth = renderer.getWidth(); + final int vpHeight = renderer.getHeight(); + if(vpWidth <=0 || vpHeight <= 0 || null==sampleCount || sampleCount[0] <= 0){ + renderRegion(gl); + } else { + if(0 > maxTexSize[0]) { + gl.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, maxTexSize, 0); + } + final RenderState rs = renderer.getRenderState(); + final float winWidth, winHeight; + + final float ratioObjWinWidth, ratioObjWinHeight; + final float diffObjWidth, diffObjHeight; + final float diffObjBorderWidth, diffObjBorderHeight; + int targetFboWidth, targetFboHeight; + { + final float diffWinWidth, diffWinHeight; + final int targetWinWidth, targetWinHeight; + + // Calculate perspective pixel width/height for FBO, + // considering the sampleCount. + drawView[2] = vpWidth; + drawView[3] = vpHeight; + + renderer.getMatrix().multPMvMatrixf(drawMat4PMv, 0); + box.mapToWindow(drawWinBox, drawMat4PMv, drawView, true /* useCenterZ */, + drawVec4Tmp0, drawVec4Tmp1, drawVec4Tmp2); + + winWidth = drawWinBox.getWidth(); + winHeight = drawWinBox.getHeight(); + targetWinWidth = (int)Math.ceil(winWidth); + targetWinHeight = (int)Math.ceil(winHeight); + diffWinWidth = targetWinWidth-winWidth; + diffWinHeight = targetWinHeight-winHeight; + + ratioObjWinWidth = box.getWidth() / winWidth; + ratioObjWinHeight= box.getHeight() / winHeight; + diffObjWidth = diffWinWidth * ratioObjWinWidth; + diffObjHeight = diffWinHeight * ratioObjWinHeight; + diffObjBorderWidth = border * ratioObjWinWidth; + diffObjBorderHeight = border * ratioObjWinHeight; + + targetFboWidth = (targetWinWidth+2*border)*sampleCount[0]; + targetFboHeight = (targetWinHeight+2*border)*sampleCount[0]; + + if( DEBUG_FBO_2 ) { + final float ratioWinWidth, ratioWinHeight; + ratioWinWidth = winWidth/targetWinWidth; + ratioWinHeight = winHeight/targetWinHeight; + final float renderFboWidth, renderFboHeight; + renderFboWidth = (winWidth+2*border)*sampleCount[0]; + renderFboHeight = (winHeight+2*border)*sampleCount[0]; + final float ratioFboWidth, ratioFboHeight; + ratioFboWidth = renderFboWidth/targetFboWidth; + ratioFboHeight = renderFboHeight/targetFboHeight; + final float diffFboWidth, diffFboHeight; + diffFboWidth = targetFboWidth-renderFboWidth; + diffFboHeight = targetFboHeight-renderFboHeight; + + System.err.printf("XXX.MinMax obj %s%n", box.toString()); + System.err.printf("XXX.MinMax obj d[%.3f, %.3f], r[%f, %f], b[%f, %f]%n", + diffObjWidth, diffObjHeight, ratioObjWinWidth, ratioObjWinWidth, diffObjBorderWidth, diffObjBorderHeight); + System.err.printf("XXX.MinMax win %s%n", drawWinBox.toString()); + System.err.printf("XXX.MinMax view[%d, %d] -> win[%.3f, %.3f], i[%d x %d], d[%.3f, %.3f], r[%f, %f]: FBO f[%.3f, %.3f], i[%d x %d], d[%.3f, %.3f], r[%f, %f], samples %d%n", + drawView[2], drawView[3], + winWidth, winHeight, targetWinWidth, targetWinHeight, diffWinWidth, + diffWinHeight, ratioWinWidth, ratioWinHeight, + renderFboWidth, renderFboHeight, targetFboWidth, targetFboHeight, + diffFboWidth, diffFboHeight, ratioFboWidth, ratioFboHeight, + sampleCount[0]); + } + } + if( 0 >= targetFboWidth || 0 >= targetFboHeight ) { + // Nothing .. + return; + } + final int deltaFboWidth = Math.abs(targetFboWidth-fboWidth); + final int deltaFboHeight = Math.abs(targetFboHeight-fboHeight); + final boolean hasDelta = 0!=deltaFboWidth || 0!=deltaFboHeight; + if( DEBUG_FBO_2 ) { + System.err.printf("XXX.maxDelta: hasDelta %b: %d / %d, %.3f, %.3f%n", + hasDelta, deltaFboWidth, deltaFboHeight, (float)deltaFboWidth/fboWidth, (float)deltaFboHeight/fboHeight); + System.err.printf("XXX.Scale %d * [%f x %f]: %d x %d%n", + sampleCount[0], winWidth, winHeight, targetFboWidth, targetFboHeight); + } + if( hasDelta || fboDirty || isShapeDirty() || null == fbo ) { + final int maxLength = Math.max(targetFboWidth, targetFboHeight); + if( maxLength > maxTexSize[0] ) { + if( targetFboWidth > targetFboHeight ) { + sampleCount[0] = (int)Math.floor(maxTexSize[0] / (winWidth+2*border)); + } else { + sampleCount[0] = (int)Math.floor(maxTexSize[0] / (winHeight+2*border)); + } + final float renderFboWidth, renderFboHeight; + renderFboWidth = (winWidth+2*border)*sampleCount[0]; + renderFboHeight = (winWidth+2*border)*sampleCount[0]; + targetFboWidth = (int)Math.ceil(renderFboWidth); + targetFboHeight = (int)Math.ceil(renderFboHeight); + if( DEBUG_FBO_1 ) { + System.err.printf("XXX.Rescale (MAX): win[%.3f, %.3f]: FBO f[%.3f, %.3f], i[%d x %d], msaa %d%n", + winWidth, winHeight, + renderFboWidth, renderFboHeight, targetFboWidth, targetFboHeight, sampleCount[0]); + } + if( sampleCount[0] <= 0 ) { + // Last way out! + renderRegion(gl); + return; + } + } + + final int newFboWidth, newFboHeight, resizeCase; + if( 0 >= RESIZE_BOUNDARY ) { + // Resize w/o optimization + newFboWidth = targetFboWidth; + newFboHeight = targetFboHeight; + resizeCase = 0; + } else { + if( 0 >= fboWidth || 0 >= fboHeight || null == fbo ) { + // Case: New FBO + newFboWidth = targetFboWidth; + newFboHeight = targetFboHeight; + resizeCase = 1; + } else if( targetFboWidth > fboWidth || targetFboHeight > fboHeight ) { + // Case: Inscrease FBO Size, add boundary/2 if avail + newFboWidth = ( targetFboWidth + RESIZE_BOUNDARY/2 < maxTexSize[0] ) ? targetFboWidth + RESIZE_BOUNDARY/2 : targetFboWidth; + newFboHeight = ( targetFboHeight+ RESIZE_BOUNDARY/2 < maxTexSize[0] ) ? targetFboHeight + RESIZE_BOUNDARY/2 : targetFboHeight; + resizeCase = 2; + } else if( targetFboWidth < fboWidth && targetFboHeight < fboHeight && + fboWidth - targetFboWidth < RESIZE_BOUNDARY && + fboHeight - targetFboHeight < RESIZE_BOUNDARY ) { + // Case: Decreased FBO Size Request within boundary + newFboWidth = fboWidth; + newFboHeight = fboHeight; + resizeCase = 3; + } else { + // Case: Decreased-Size-Beyond-Boundary or No-Resize + newFboWidth = targetFboWidth; + newFboHeight = targetFboHeight; + resizeCase = 4; + } + } + final int dResizeWidth = newFboWidth - targetFboWidth; + final int dResizeHeight = newFboHeight - targetFboHeight; + final float diffObjResizeWidth = dResizeWidth*ratioObjWinWidth; + final float diffObjResizeHeight = dResizeHeight*ratioObjWinHeight; + if( DEBUG_FBO_1 ) { + System.err.printf("XXX.resizeFBO: case %d, has %dx%d > target %dx%d, resize: i[%d x %d], f[%.3f x %.3f] -> %dx%d%n", + resizeCase, fboWidth, fboHeight, targetFboWidth, targetFboHeight, + dResizeWidth, dResizeHeight, diffObjResizeWidth, diffObjResizeHeight, + newFboWidth, newFboHeight); + } + + final float minX = box.getMinX()-diffObjBorderWidth; + final float minY = box.getMinY()-diffObjBorderHeight; + final float maxX = box.getMaxX()+diffObjBorderWidth+diffObjWidth+diffObjResizeWidth; + final float maxY = box.getMaxY()+diffObjBorderHeight+diffObjHeight+diffObjResizeHeight; + gca_FboVerticesAttr.seal(false); + { + final FloatBuffer fb = (FloatBuffer)gca_FboVerticesAttr.getBuffer(); + fb.put(0, minX); fb.put( 1, minY); + fb.put(3, minX); fb.put( 4, maxY); + fb.put(6, maxX); fb.put( 7, maxY); + fb.put(9, maxX); fb.put(10, minY); + fb.position(12); + } + gca_FboVerticesAttr.seal(true); + FloatUtil.makeOrtho(pmvMatrix02, 0, true, minX, maxX, minY, maxY, -1, 1); + useShaderProgram(gl, renderer, getRenderModes(), true, getQuality(), sampleCount[0]); + renderRegion2FBO(gl, rs, targetFboWidth, targetFboHeight, newFboWidth, newFboHeight, vpWidth, vpHeight, sampleCount[0]); + } else if( isStateDirty() ) { + useShaderProgram(gl, renderer, getRenderModes(), true, getQuality(), sampleCount[0]); + renderRegion2FBO(gl, rs, targetFboWidth, targetFboHeight, fboWidth, fboHeight, vpWidth, vpHeight, sampleCount[0]); + } + useShaderProgram(gl, renderer, getRenderModes(), false, getQuality(), sampleCount[0]); + renderFBO(gl, rs, targetFboWidth, targetFboHeight, vpWidth, vpHeight, sampleCount[0]); + } + } + + private void renderFBO(final GL2ES2 gl, final RenderState rs, final int targetFboWidth, final int targetFboHeight, + final int vpWidth, final int vpHeight, final int sampleCount) { + gl.glViewport(0, 0, vpWidth, vpHeight); + + if( rs.isHintMaskSet(RenderState.BITHINT_BLENDING_ENABLED) ) { + // RGB is already multiplied w/ alpha via renderRegion2FBO(..) + gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA); + } + + gl.glUniform(gcu_FboTexSize); + + gl.glActiveTexture(GL.GL_TEXTURE0 + gcu_FboTexUnit.intValue()); + + fbo.use(gl, texA); + gca_FboVerticesAttr.enableBuffer(gl, true); + gca_FboTexCoordsAttr.enableBuffer(gl, true); + indicesFbo.bindBuffer(gl, true); // keeps VBO binding + + gl.glDrawElements(GL.GL_TRIANGLES, indicesFbo.getElementCount() * indicesFbo.getComponentCount(), GL.GL_UNSIGNED_SHORT, 0); + + indicesFbo.bindBuffer(gl, false); + gca_FboTexCoordsAttr.enableBuffer(gl, false); + gca_FboVerticesAttr.enableBuffer(gl, false); + fbo.unuse(gl); + + // setback: gl.glActiveTexture(currentActiveTextureEngine[0]); + } + + private void renderRegion2FBO(final GL2ES2 gl, final RenderState rs, + final int targetFboWidth, final int targetFboHeight, final int newFboWidth, final int newFboHeight, + final int vpWidth, final int vpHeight, final int sampleCount) { + if( 0 >= targetFboWidth || 0 >= targetFboHeight ) { + throw new IllegalArgumentException("fboSize must be greater than 0: "+targetFboWidth+"x"+targetFboHeight); + } + + final boolean blendingEnabled = rs.isHintMaskSet(RenderState.BITHINT_BLENDING_ENABLED); + + if(null == fbo) { + fboWidth = newFboWidth; + fboHeight = newFboHeight; + final FloatBuffer fboTexSize = (FloatBuffer) gcu_FboTexSize.getBuffer(); + { + fboTexSize.put(0, fboWidth); + fboTexSize.put(1, fboHeight); + } + fbo = new FBObject(); + fbo.init(gl, fboWidth, fboHeight, 0); + // Shall not use bilinear (GL_LINEAR), due to own VBAA. Result is smooth w/o it now! + // FIXME: FXAA requires bilinear filtering! + // texA = fbo.attachTexture2D(gl, 0, true, GL.GL_LINEAR, GL.GL_LINEAR, GL.GL_CLAMP_TO_EDGE, GL.GL_CLAMP_TO_EDGE); + texA = fbo.attachTexture2D(gl, 0, true, GL.GL_NEAREST, GL.GL_NEAREST, GL.GL_CLAMP_TO_EDGE, GL.GL_CLAMP_TO_EDGE); + if( !blendingEnabled ) { + // no depth-buffer w/ blending + fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, FBObject.DEFAULT_BITS); + } + if( DEBUG_FBO_1 ) { + System.err.printf("XXX.createFBO: %dx%d%n%s%n", fboWidth, fboHeight, fbo.toString()); + } + } else if( newFboWidth != fboWidth || newFboHeight != fboHeight ) { + fbo.reset(gl, newFboWidth, newFboHeight, 0); + fbo.bind(gl); + if( DEBUG_FBO_1 ) { + System.err.printf("XXX.resetFBO: %dx%d -> %dx%d, target %dx%d%n", fboWidth, fboHeight, newFboWidth, newFboHeight, targetFboWidth, targetFboHeight); + } + fboWidth = newFboWidth; + fboHeight = newFboHeight; + final FloatBuffer fboTexSize = (FloatBuffer) gcu_FboTexSize.getBuffer(); + { + fboTexSize.put(0, fboWidth); + fboTexSize.put(1, fboHeight); + } + } else { + fbo.bind(gl); + } + + //render texture + gl.glViewport(0, 0, fboWidth, fboHeight); + if( blendingEnabled ) { + gl.glClearColor(0f, 0f, 0f, 0.0f); + gl.glClear(GL.GL_COLOR_BUFFER_BIT); // no depth-buffer w/ blending + // For already pre-multiplied alpha values, use: + // gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA); + + // Multiply RGB w/ Alpha, preserve alpha for renderFBO(..) + gl.glBlendFuncSeparate(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA, GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA); + } else { + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + } + + renderRegion(gl); + + fbo.unbind(gl); + fboDirty = false; + } + + private void renderRegion(final GL2ES2 gl) { + gl.glUniform(gcu_PMVMatrix02); + + gca_VerticesAttr.enableBuffer(gl, true); + gca_CurveParamsAttr.enableBuffer(gl, true); + if( null != gca_ColorsAttr ) { + gca_ColorsAttr.enableBuffer(gl, true); + } + indicesBuffer.bindBuffer(gl, true); // keeps VBO binding + if( null != gcu_ColorTexUnit && colorTexSeq.isTextureAvailable() ) { + final TextureSequence.TextureFrame frame = colorTexSeq.getNextTexture(gl); + gl.glActiveTexture(GL.GL_TEXTURE0 + colorTexSeq.getTextureUnit()); + final Texture tex = frame.getTexture(); + tex.bind(gl); + tex.enable(gl); // nop on core + gcu_ColorTexUnit.setData(colorTexSeq.getTextureUnit()); + gl.glUniform(gcu_ColorTexUnit); // Always update, since program maybe used by multiple regions + gl.glUniform(gcu_ColorTexBBox); // Always update, since program maybe used by multiple regions + gl.glDrawElements(GL.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL.GL_UNSIGNED_SHORT, 0); + tex.disable(gl); // nop on core + } else { + gl.glDrawElements(GL.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL.GL_UNSIGNED_SHORT, 0); + } + + indicesBuffer.bindBuffer(gl, false); + if( null != gca_ColorsAttr ) { + gca_ColorsAttr.enableBuffer(gl, false); + } + gca_CurveParamsAttr.enableBuffer(gl, false); + gca_VerticesAttr.enableBuffer(gl, false); + } + + @Override + protected void destroyImpl(final GL2ES2 gl) { + if(DEBUG_INSTANCE) { + System.err.println("VBORegion2PES2 Destroy: " + this); + // Thread.dumpStack(); + } + if(null != fbo) { + fbo.destroy(gl); + fbo = null; + texA = null; + } + if(null != gca_VerticesAttr) { + gca_VerticesAttr.destroy(gl); + gca_VerticesAttr = null; + } + if(null != gca_CurveParamsAttr) { + gca_CurveParamsAttr.destroy(gl); + gca_CurveParamsAttr = null; + } + if(null != gca_ColorsAttr) { + gca_ColorsAttr.destroy(gl); + gca_ColorsAttr = null; + } + if(null != indicesBuffer) { + indicesBuffer.destroy(gl); + indicesBuffer = null; + } + + if(null != gca_FboVerticesAttr) { + gca_FboVerticesAttr.destroy(gl); + gca_FboVerticesAttr = null; + } + if(null != gca_FboTexCoordsAttr) { + gca_FboTexCoordsAttr.destroy(gl); + gca_FboTexCoordsAttr = null; + } + if(null != indicesFbo) { + indicesFbo.destroy(gl); + indicesFbo = null; + } + spPass1 = null; + spPass2 = null; + } +} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java index 14ff0380f..46e991866 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java @@ -27,134 +27,258 @@ */ package jogamp.graph.curve.opengl; +import java.nio.FloatBuffer; + import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; +import javax.media.opengl.GLUniformData; import jogamp.graph.curve.opengl.shader.AttributeNames; +import jogamp.graph.curve.opengl.shader.UniformNames; +import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.GLRegion; +import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.geom.Triangle; import com.jogamp.opengl.util.GLArrayDataServer; -import com.jogamp.opengl.util.glsl.ShaderState; +import com.jogamp.opengl.util.glsl.ShaderProgram; +import com.jogamp.opengl.util.texture.Texture; +import com.jogamp.opengl.util.texture.TextureCoords; +import com.jogamp.opengl.util.texture.TextureSequence; public class VBORegionSPES2 extends GLRegion { - private GLArrayDataServer verticeAttr = null; - private GLArrayDataServer texCoordAttr = null; - private GLArrayDataServer indices = null; + private final RenderState.ProgramLocal rsLocal; + + private GLArrayDataServer gca_VerticesAttr = null; + private GLArrayDataServer gca_CurveParamsAttr = null; + private GLArrayDataServer gca_ColorsAttr; + private GLArrayDataServer indicesBuffer = null; + private final GLUniformData gcu_ColorTexUnit; + private final float[] colorTexBBox; // x0, y0, x1, y1 + private final GLUniformData gcu_ColorTexBBox; + private ShaderProgram spPass1 = null; + + public VBORegionSPES2(final int renderModes, final TextureSequence colorTexSeq) { + super(renderModes, colorTexSeq); + + rsLocal = new RenderState.ProgramLocal(); + + final int initialElementCount = 256; + indicesBuffer = GLArrayDataServer.createData(3, GL.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); + + gca_VerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL.GL_FLOAT, + false, initialElementCount, GL.GL_STATIC_DRAW); - protected VBORegionSPES2(int renderModes) { - super(renderModes); + gca_CurveParamsAttr = GLArrayDataServer.createGLSL(AttributeNames.CURVEPARAMS_ATTR_NAME, 3, GL.GL_FLOAT, + false, initialElementCount, GL.GL_STATIC_DRAW); + + if( hasColorChannel() ) { + gca_ColorsAttr = GLArrayDataServer.createGLSL(AttributeNames.COLOR_ATTR_NAME, 4, GL.GL_FLOAT, + false, initialElementCount, GL.GL_STATIC_DRAW); + } else { + gca_ColorsAttr = null; + } + if( hasColorTexture() ) { + gcu_ColorTexUnit = new GLUniformData(UniformNames.gcu_ColorTexUnit, colorTexSeq.getTextureUnit()); + colorTexBBox = new float[4]; + gcu_ColorTexBBox = new GLUniformData(UniformNames.gcu_ColorTexBBox, 4, FloatBuffer.wrap(colorTexBBox)); + } else { + gcu_ColorTexUnit = null; + colorTexBBox = null; + gcu_ColorTexBBox = null; + } } - protected void update(GL2ES2 gl, RenderState rs) { - if(!isDirty()) { - return; + @Override + protected final void clearImpl(final GL2ES2 gl) { + if(DEBUG_INSTANCE) { + System.err.println("VBORegionSPES2 Clear: " + this); + } + if( null != indicesBuffer ) { + indicesBuffer.seal(gl, false); + indicesBuffer.rewind(); + } + if( null != gca_VerticesAttr ) { + gca_VerticesAttr.seal(gl, false); + gca_VerticesAttr.rewind(); } + if( null != gca_CurveParamsAttr ) { + gca_CurveParamsAttr.seal(gl, false); + gca_CurveParamsAttr.rewind(); + } + if( null != gca_ColorsAttr ) { + gca_ColorsAttr.seal(gl, false); + gca_ColorsAttr.rewind(); + } + } - if(null == indices) { - final int initialElementCount = 256; - final ShaderState st = rs.getShaderState(); + @Override + protected final void pushVertex(final float[] coords, final float[] texParams, final float[] rgba) { + gca_VerticesAttr.putf(coords[0]); + gca_VerticesAttr.putf(coords[1]); + gca_VerticesAttr.putf(coords[2]); - indices = GLArrayDataServer.createData(3, GL2ES2.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); + gca_CurveParamsAttr.putf(texParams[0]); + gca_CurveParamsAttr.putf(texParams[1]); + gca_CurveParamsAttr.putf(texParams[2]); - verticeAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL2ES2.GL_FLOAT, - false, initialElementCount, GL.GL_STATIC_DRAW); - st.ownAttribute(verticeAttr, true); + if( null != gca_ColorsAttr ) { + if( null != rgba ) { + gca_ColorsAttr.putf(rgba[0]); + gca_ColorsAttr.putf(rgba[1]); + gca_ColorsAttr.putf(rgba[2]); + gca_ColorsAttr.putf(rgba[3]); + } else { + throw new IllegalArgumentException("Null color given for COLOR_CHANNEL rendering mode"); + } + } + } - texCoordAttr = GLArrayDataServer.createGLSL(AttributeNames.TEXCOORD_ATTR_NAME, 2, GL2ES2.GL_FLOAT, - false, initialElementCount, GL.GL_STATIC_DRAW); - st.ownAttribute(texCoordAttr, true); + @Override + protected final void pushIndex(final int idx) { + indicesBuffer.puts((short)idx); + } - if(DEBUG_INSTANCE) { - System.err.println("VBORegionSPES2 Create: " + this); + @Override + protected void updateImpl(final GL2ES2 gl) { + // seal buffers + gca_VerticesAttr.seal(gl, true); + gca_VerticesAttr.enableBuffer(gl, false); + gca_CurveParamsAttr.seal(gl, true); + gca_CurveParamsAttr.enableBuffer(gl, false); + if( null != gca_ColorsAttr ) { + gca_ColorsAttr.seal(gl, true); + gca_ColorsAttr.enableBuffer(gl, false); + } + if( null != gcu_ColorTexUnit && colorTexSeq.isTextureAvailable() ) { + final TextureSequence.TextureFrame frame = colorTexSeq.getLastTexture(); + final Texture tex = frame.getTexture(); + final TextureCoords tc = tex.getImageTexCoords(); + final float tcSx = 1f / ( tc.right() - tc.left() ); + colorTexBBox[0] = box.getMinX() * tcSx; + colorTexBBox[2] = box.getMaxX() * tcSx; + final float tcSy; + if( tex.getMustFlipVertically() ) { + tcSy = 1f / ( tc.bottom() - tc.top() ); + colorTexBBox[1] = box.getMaxY() * tcSy; + colorTexBBox[3] = box.getMinY() * tcSy; + } else { + tcSy = 1f / ( tc.top() - tc.bottom() ); + colorTexBBox[1] = box.getMinY() * tcSy; + colorTexBBox[3] = box.getMaxY() * tcSy; } } + indicesBuffer.seal(gl, true); + indicesBuffer.enableBuffer(gl, false); + if(DEBUG_INSTANCE) { + System.err.println("VBORegionSPES2 idx "+indicesBuffer); + System.err.println("VBORegionSPES2 ver "+gca_VerticesAttr); + System.err.println("VBORegionSPES2 tex "+gca_CurveParamsAttr); + } + } - // process triangles - indices.seal(gl, false); - indices.rewind(); - for(int i=0; i<triangles.size(); i++) { - final Triangle t = triangles.get(i); - final Vertex[] t_vertices = t.getVertices(); + private static final boolean throwOnError = false; // FIXME + /** + * <p> + * Since multiple {@link Region}s may share one + * {@link ShaderProgram}, the uniform data must always be updated. + * </p> + * + * @param gl + * @param renderer + * @param renderModes + * @param quality + */ + public void useShaderProgram(final GL2ES2 gl, final RegionRenderer renderer, final int renderModes, final int quality) { + final RenderState rs = renderer.getRenderState(); + final boolean updateLocGlobal = renderer.useShaderProgram(gl, renderModes, true, quality, 0, colorTexSeq); + final ShaderProgram sp = renderer.getRenderState().getShaderProgram(); + final boolean updateLocLocal = !sp.equals(spPass1); + spPass1 = sp; + if( DEBUG ) { + System.err.println("XXX changedSP.p1 updateLocation loc "+updateLocLocal+" / glob "+updateLocGlobal); + } + if( updateLocLocal ) { + rs.updateAttributeLoc(gl, true, gca_VerticesAttr, throwOnError); + rs.updateAttributeLoc(gl, true, gca_CurveParamsAttr, throwOnError); + if( null != gca_ColorsAttr ) { + rs.updateAttributeLoc(gl, true, gca_ColorsAttr, throwOnError); + } + } + rsLocal.update(gl, rs, updateLocLocal, renderModes, true, throwOnError); + if( null != gcu_ColorTexUnit ) { + rs.updateUniformLoc(gl, updateLocLocal, gcu_ColorTexUnit, throwOnError); + rs.updateUniformLoc(gl, updateLocLocal, gcu_ColorTexBBox, throwOnError); + } + } - if(t_vertices[0].getId() == Integer.MAX_VALUE){ - t_vertices[0].setId(numVertices++); - t_vertices[1].setId(numVertices++); - t_vertices[2].setId(numVertices++); - vertices.add(t_vertices[0]); - vertices.add(t_vertices[1]); - vertices.add(t_vertices[2]); + @Override + protected void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, final int[/*1*/] sampleCount) { + final int renderModes = getRenderModes(); + useShaderProgram(gl, renderer, renderModes, getQuality()); - indices.puts((short) t_vertices[0].getId()); - indices.puts((short) t_vertices[1].getId()); - indices.puts((short) t_vertices[2].getId()); - } else { - indices.puts((short) t_vertices[0].getId()); - indices.puts((short) t_vertices[1].getId()); - indices.puts((short) t_vertices[2].getId()); + if( 0 >= indicesBuffer.getElementCount() ) { + if(DEBUG_INSTANCE) { + System.err.printf("VBORegionSPES2.drawImpl: Empty%n"); } + return; // empty! } - indices.seal(gl, true); - indices.enableBuffer(gl, false); - - // process vertices and update bbox - box.reset(); - verticeAttr.seal(gl, false); - verticeAttr.rewind(); - texCoordAttr.seal(gl, false); - texCoordAttr.rewind(); - for(int i=0; i<vertices.size(); i++) { - final Vertex v = vertices.get(i); - verticeAttr.putf(v.getX()); - verticeAttr.putf(v.getY()); - verticeAttr.putf(v.getZ()); - box.resize(v.getX(), v.getY(), v.getZ()); - - final float[] tex = v.getTexCoord(); - texCoordAttr.putf(tex[0]); - texCoordAttr.putf(tex[1]); - } - verticeAttr.seal(gl, true); - verticeAttr.enableBuffer(gl, false); - texCoordAttr.seal(gl, true); - texCoordAttr.enableBuffer(gl, false); - - setDirty(false); - } + gca_VerticesAttr.enableBuffer(gl, true); + gca_CurveParamsAttr.enableBuffer(gl, true); + if( null != gca_ColorsAttr ) { + gca_ColorsAttr.enableBuffer(gl, true); + } + indicesBuffer.bindBuffer(gl, true); // keeps VBO binding - protected void drawImpl(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int[/*1*/] texWidth) { - verticeAttr.enableBuffer(gl, true); - texCoordAttr.enableBuffer(gl, true); - indices.enableBuffer(gl, true); + if( renderer.getRenderState().isHintMaskSet(RenderState.BITHINT_BLENDING_ENABLED) ) { + gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); + } - gl.glDrawElements(GL2ES2.GL_TRIANGLES, indices.getElementCount() * indices.getComponentCount(), GL2ES2.GL_UNSIGNED_SHORT, 0); + if( null != gcu_ColorTexUnit && colorTexSeq.isTextureAvailable() ) { + final TextureSequence.TextureFrame frame = colorTexSeq.getNextTexture(gl); + gl.glActiveTexture(GL.GL_TEXTURE0 + colorTexSeq.getTextureUnit()); + final Texture tex = frame.getTexture(); + tex.bind(gl); + tex.enable(gl); // nop on core + gcu_ColorTexUnit.setData(colorTexSeq.getTextureUnit()); + gl.glUniform(gcu_ColorTexUnit); // Always update, since program maybe used by multiple regions + gl.glUniform(gcu_ColorTexBBox); // Always update, since program maybe used by multiple regions + gl.glDrawElements(GL.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL.GL_UNSIGNED_SHORT, 0); + tex.disable(gl); // nop on core + } else { + gl.glDrawElements(GL.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL.GL_UNSIGNED_SHORT, 0); + } - verticeAttr.enableBuffer(gl, false); - texCoordAttr.enableBuffer(gl, false); - indices.enableBuffer(gl, false); - } + indicesBuffer.bindBuffer(gl, false); + if( null != gca_ColorsAttr ) { + gca_ColorsAttr.enableBuffer(gl, false); + } + gca_CurveParamsAttr.enableBuffer(gl, false); + gca_VerticesAttr.enableBuffer(gl, false); + } - public final void destroy(GL2ES2 gl, RenderState rs) { + @Override + protected void destroyImpl(final GL2ES2 gl) { if(DEBUG_INSTANCE) { System.err.println("VBORegionSPES2 Destroy: " + this); - } - final ShaderState st = rs.getShaderState(); - if(null != verticeAttr) { - st.ownAttribute(verticeAttr, false); - verticeAttr.destroy(gl); - verticeAttr = null; - } - if(null != texCoordAttr) { - st.ownAttribute(texCoordAttr, false); - texCoordAttr.destroy(gl); - texCoordAttr = null; - } - if(null != indices) { - indices.destroy(gl); - indices = null; - } - } + } + if(null != gca_VerticesAttr) { + gca_VerticesAttr.destroy(gl); + gca_VerticesAttr = null; + } + if(null != gca_CurveParamsAttr) { + gca_CurveParamsAttr.destroy(gl); + gca_CurveParamsAttr = null; + } + if(null != gca_ColorsAttr) { + gca_ColorsAttr.destroy(gl); + gca_ColorsAttr = null; + } + if(null != indicesBuffer) { + indicesBuffer.destroy(gl); + indicesBuffer = null; + } + spPass1 = null; + } } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/AttributeNames.java b/src/jogl/classes/jogamp/graph/curve/opengl/shader/AttributeNames.java index 8a109c34a..dff536645 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/AttributeNames.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/AttributeNames.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,7 +20,7 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. @@ -28,18 +28,23 @@ package jogamp.graph.curve.opengl.shader; public class AttributeNames { - /** The vertices index in an OGL object + /** + * The vertices index in an OGL object */ - public static final int VERTEX_ATTR_IDX = 0; // FIXME: AMD needs this to be location 0 ? hu ? public static final String VERTEX_ATTR_NAME = "gca_Vertices"; - /** The Texture Coord index in an OGL object + /** + * The Texture Coord index in an OGL object */ - public static final int TEXCOORD_ATTR_IDX = 1; - public static final String TEXCOORD_ATTR_NAME = "gca_TexCoords"; - - /** The color index in an OGL object + public static final String CURVEPARAMS_ATTR_NAME = "gca_CurveParams"; + + /** + * The color index in an OGL object */ - public static final int COLOR_ATTR_IDX = 2; - public static final String COLOR_ATTR_NAME = "gca_Colors"; + public static final String COLOR_ATTR_NAME = "gca_Colors"; + + public static final String FBO_VERTEX_ATTR_NAME = "gca_FboVertices"; + + public static final String FBO_TEXCOORDS_ATTR_NAME = "gca_FboTexCoords"; + } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java b/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java index ab6e0dc6e..7244851ff 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java @@ -1,10 +1,13 @@ package jogamp.graph.curve.opengl.shader; public class UniformNames { - public static final String gcu_PMVMatrix = "gcu_PMVMatrix"; // gcu_PMVMatrix[3]; // P, Mv, and Mvi + public static final String gcu_PMVMatrix01 = "gcu_PMVMatrix01"; // gcu_PMVMatrix[3]; // P, Mv, and Mvi public static final String gcu_ColorStatic = "gcu_ColorStatic"; - public static final String gcu_Alpha = "gcu_Alpha"; public static final String gcu_Weight = "gcu_Weight"; - public static final String gcu_TextureUnit = "gcu_TextureUnit"; - public static final String gcu_TextureSize = "gcu_TextureSize"; + public static final String gcu_ColorTexUnit = "gcu_ColorTexUnit"; + public static final String gcu_ColorTexBBox = "gcu_ColorTexBBox"; + + public static final String gcu_PMVMatrix02 = "gcu_PMVMatrix02"; // gcu_PMVMatrix[3]; // P, Mv, and Mvi + public static final String gcu_FboTexUnit = "gcu_FboTexUnit"; + public static final String gcu_FboTexSize = "gcu_FboTexSize"; } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/attributes.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/attributes.glsl index 108247c9c..b8c68a924 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/attributes.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/attributes.glsl @@ -4,8 +4,27 @@ // attribute vec3 gca_Vertices; attribute vec4 gca_Vertices; -attribute vec2 gca_TexCoords; -//attribute vec4 gca_Colors; + +/** + * CDTriangulator2D.extractBoundaryTriangles(..): + * AA line (exp) : z > 0 + * line : x == 0, y == 0 + * hole or holeLike: 0 > y + * !hole : 0 < y + * + * 0 == gcv_CurveParams.x : vertex-0 of triangle + * 0.5 == gcv_CurveParams.x : vertex-1 of triangle + * 1 == gcv_CurveParams.x : vertex-2 of triangle + */ +attribute vec3 gca_CurveParams; + +attribute vec4 gca_FboVertices; +attribute vec2 gca_FboTexCoords; + +#ifdef USE_COLOR_CHANNEL + attribute vec4 gca_Colors; +#endif + //attribute vec3 gca_Normals; #endif // attributes_glsl diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-es2-merged.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-es2-merged.vp deleted file mode 100644 index 530b24f64..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-es2-merged.vp +++ /dev/null @@ -1,19 +0,0 @@ -//Copyright 2010 JogAmp Community. All rights reserved. - -#ifdef GL_ES - precision lowp float; - precision lowp int; -#endif - -uniform mat4 gcu_PMVMatrix[3]; // P, Mv, and Mvi -varying vec2 gcv_TexCoord; - -attribute vec4 gca_Vertices; -attribute vec2 gca_TexCoords; - - -void main(void) -{ - gl_Position = gcu_PMVMatrix[0] * gcu_PMVMatrix[1] * gca_Vertices; - gcv_TexCoord = gca_TexCoords; -} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-es2.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-es2.vp deleted file mode 100644 index 15ce8cc2b..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-es2.vp +++ /dev/null @@ -1,9 +0,0 @@ -//Copyright 2010 JogAmp Community. All rights reserved. - -#version 100 - -precision mediump float; -precision mediump int; - -#include curverenderer01-xxx.vp - diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-gl2.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-gl2.vp deleted file mode 100644 index 1ac33e8b3..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-gl2.vp +++ /dev/null @@ -1,6 +0,0 @@ -//Copyright 2010 JogAmp Community. All rights reserved. - -#version 110 - -#include curverenderer01-xxx.vp - diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_lineAA.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_lineAA.glsl new file mode 100644 index 000000000..79b3dd6fd --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_lineAA.glsl @@ -0,0 +1,19 @@ + + // if( gcv_CurveParam.x == 10.0 && gcv_CurveParam.y == 10.0 ) { + if( gcv_CurveParam.z > 0.0 ) { + // pass-1: AA Lines + #if 1 + // float dist = sqrt( gcv_CurveParam.x*gcv_CurveParam.x + gcv_CurveParam.y*gcv_CurveParam.y ); // magnitude + float dist = sqrt( gcv_CurveParam.y*gcv_CurveParam.y ); // magnitude + // float a = 1.0 - smoothstep (gcv_CurveParam.y-gcv_CurveParam.z, gcv_CurveParam.y, dist); + float r = gcv_CurveParam.x/3.0; + float wa = gcv_CurveParam.x+r; + float waHalf = wa/2.0; + float a = 1.0 - smoothstep (waHalf-2.0*r, waHalf, dist); + // mgl_FragColor = vec4(gcu_ColorStatic.rgb, gcu_ColorStatic.a * a); + mgl_FragColor = vec4(0, 0, 1.0, gcu_ColorStatic.a * a); + #else + mgl_FragColor = vec4(0, 0, 1.0, 1.0); + #endif + } else + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.glsl new file mode 100644 index 000000000..447242438 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.glsl @@ -0,0 +1,36 @@ + + if( gcv_CurveParam.x == 0.0 && gcv_CurveParam.y == 0.0 ) { + // pass-1: Lines +#if defined(USE_COLOR_TEXTURE) && defined(USE_COLOR_CHANNEL) + mgl_FragColor = gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st) * gcv_Color * gcu_ColorStatic; +#elif defined(USE_COLOR_TEXTURE) + mgl_FragColor = gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st) * gcu_ColorStatic; +#elif defined(USE_COLOR_CHANNEL) + mgl_FragColor = gcv_Color * gcu_ColorStatic; +#else + mgl_FragColor = gcu_ColorStatic; +#endif + } else { + // pass-1: curves + vec2 rtex = vec2( abs(gcv_CurveParam.x), abs(gcv_CurveParam.y) - 0.1 ); + + vec2 dtx = dFdx(rtex); + vec2 dty = dFdy(rtex); + + vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x)); + float position = rtex.y - (rtex.x * (1.0 - rtex.x)); + + float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_CurveParam.y), 0.0, 1.0); +#if defined(USE_COLOR_TEXTURE) && defined(USE_COLOR_CHANNEL) + vec4 t = gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st); + mgl_FragColor = vec4(t.rgb * gcv_Color.rgb * gcu_ColorStatic.rgb, t.a * gcv_Color.a * gcu_ColorStatic.a * a); +#elif defined(USE_COLOR_TEXTURE) + vec4 t = gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st); + mgl_FragColor = vec4(t.rgb * gcu_ColorStatic.rgb, t.a * gcu_ColorStatic.a * a); +#elif defined(USE_COLOR_CHANNEL) + mgl_FragColor = vec4(gcv_Color.rgb * gcu_ColorStatic.rgb, gcv_Color.a * gcu_ColorStatic.a * a); +#else + mgl_FragColor = vec4(gcu_ColorStatic.rgb, gcu_ColorStatic.a * a); +#endif + } + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.orig.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.orig.glsl new file mode 100644 index 000000000..fa2608365 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.orig.glsl @@ -0,0 +1,47 @@ + + vec2 rtex = vec2( abs(gcv_CurveParam.x), abs(gcv_CurveParam.y) ); + + if( gcv_CurveParam.x == 0.0 && gcv_CurveParam.y == 0.0 ) { + // pass-1: Lines +#if defined(USE_COLOR_TEXTURE) && defined(USE_COLOR_CHANNEL) + mgl_FragColor = gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st) * gcv_Color * gcu_ColorStatic; +#elif defined(USE_COLOR_TEXTURE) + mgl_FragColor = gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st) * gcu_ColorStatic; +#elif defined(USE_COLOR_CHANNEL) + mgl_FragColor = gcv_Color * gcu_ColorStatic; +#else + mgl_FragColor = gcu_ColorStatic; +#endif + } else if ( gcv_CurveParam.x > 0.0 && ( rtex.y > 0.0 || rtex.x == 1.0 ) ) { + // pass-1: curves + rtex.y -= 0.1; + + if(rtex.y < 0.0 && gcv_CurveParam.y < 0.0) { + // discard; // freezes NV tegra2 compiler + mgl_FragColor = vec4(0); + } else { + rtex.y = max(rtex.y, 0.0); // always >= 0 + + vec2 dtx = dFdx(rtex); + vec2 dty = dFdy(rtex); + + vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x)); + float position = rtex.y - (rtex.x * (1.0 - rtex.x)); + + float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_CurveParam.y), 0.0, 1.0); +#if defined(USE_COLOR_TEXTURE) && defined(USE_COLOR_CHANNEL) + vec4 t = gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st); + mgl_FragColor = vec4(t.rgb * gcv_Color.rgb * gcu_ColorStatic.rgb, t.a * gcv_Color.a * gcu_ColorStatic.a * a); +#elif defined(USE_COLOR_TEXTURE) + vec4 t = gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st); + mgl_FragColor = vec4(t.rgb * gcu_ColorStatic.rgb, t.a * gcu_ColorStatic.a * a); +#elif defined(USE_COLOR_CHANNEL) + mgl_FragColor = vec4(gcv_Color.rgb * gcu_ColorStatic.rgb, gcv_Color.a * gcu_ColorStatic.a * a); +#else + mgl_FragColor = vec4(gcu_ColorStatic.rgb, gcu_ColorStatic.a * a); +#endif + } + } else { + mgl_FragColor = vec4(0); + } + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_weight.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_weight.glsl new file mode 100644 index 000000000..1620a9532 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_weight.glsl @@ -0,0 +1,32 @@ + + if( gcv_CurveParam.x == 0.0 && gcv_CurveParam.y == 0.0 ) { + // pass-1: Lines +#ifdef USE_COLOR_CHANNEL + mgl_FragColor = gcv_Color * gcu_ColorStatic; +#else + mgl_FragColor = gcu_ColorStatic; +#endif + } else { + // pass-1: curves + vec2 rtex = vec2( abs(gcv_CurveParam.x), abs(gcv_CurveParam.y) - 0.1 ); + + vec2 dtx = dFdx(rtex); + vec2 dty = dFdy(rtex); + + float w = gcu_Weight; + float pd = ((2.0 - (2.0*w))*rtex.x*rtex.x) + 2.0*(w-1.0)*rtex.x + 1.0; + float position = rtex.y - ((w*rtex.x*(1.0 - rtex.x))/pd); + + float aph = 2.0 - 2.0*w; + + float gd = (aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0)*(aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0); + vec2 f = vec2((dtx.y - (w*dtx.x*(1.0 - 2.0*rtex.x))/gd), (dty.y - (w*dty.x*(1.0 - 2.0*rtex.x))/gd)); + + float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_CurveParam.y), 0.0, 1.0); +#ifdef USE_COLOR_CHANNEL + mgl_FragColor = vec4(gcv_Color.rgb * gcu_ColorStatic.rgb, gcv_Color.a * gcu_ColorStatic.a * a); +#else + mgl_FragColor = vec4(gcu_ColorStatic.rgb, gcu_ColorStatic.a * a); +#endif + } + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1.vp new file mode 100644 index 000000000..c6ed4ca58 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1.vp @@ -0,0 +1,33 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#if __VERSION__ >= 130 + #define attribute in + #define varying out +#endif + +#include uniforms.glsl +#include attributes.glsl +#include varyings.glsl + +void main(void) +{ + gl_Position = gcu_PMVMatrix02[0] * gcu_PMVMatrix02[1] * gca_Vertices; +#if 1 + gcv_CurveParam = gca_CurveParams; +#else + if( gcv_CurveParams.x <= -10.0 ) { + // vec4 tc = gcu_PMVMatrix02[0] * gcu_PMVMatrix02[1] * vec4(gca_CurveParams.xy, gca_Vertices.z, 1); + // gcv_CurveParams = vec3(tc.xy, gca_CurveParams.z); + gcv_CurveParam = gca_CurveParams; + } else { + gcv_CurveParam = gca_CurveParams; + } +#endif +#ifdef USE_COLOR_TEXTURE + vec2 dim = vec2(gcu_ColorTexBBox.z - gcu_ColorTexBBox.x, gcu_ColorTexBBox.w - gcu_ColorTexBBox.y); + gcv_ColorTexCoord = vec2(gca_Vertices.x - gcu_ColorTexBBox.x, gca_Vertices.y - gcu_ColorTexBBox.y) / dim; +#endif +#ifdef USE_COLOR_CHANNEL + gcv_Color = gca_Colors; +#endif +} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-msaa.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-msaa.glsl new file mode 100644 index 000000000..1872af67f --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-msaa.glsl @@ -0,0 +1,10 @@ + // Pass-2: Dump Texture + vec4 t = texture2D(gcu_FboTexUnit, gcv_FboTexCoord.st); + #if 0 + if( 0.0 == t.a ) { + discard; // discard freezes NV tegra2 compiler + } + #endif + + mgl_FragColor = t; + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_allprop01.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_allprop01.glsl new file mode 100644 index 000000000..436dd4ed4 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_allprop01.glsl @@ -0,0 +1,113 @@ + // Pass-2: AA on Texture + // Note: gcv_FboTexCoord is in center of sample pixels. + + float sampleCount = gcu_FboTexSize.z; + vec2 psize = 1.0 / gcu_FboTexSize.xy; // pixel size + + // Not only the poles (NW, SW, ..) but the whole edge! + float pixelCount = sampleCount * sampleCount; + + // sampleCount [0, 1, 3, 5, 7] are undefined! + float layerCount = ( sampleCount / 2.0 ); + + // sum of all integer [layerCount .. 1] -> Gauss + float denom = ( layerCount / 2.0 ) * ( layerCount + 1.0 ); + + vec2 texCoord = gcv_FboTexCoord.st; + + vec4 t; + + // Layer-1: SampleCount 2 -> 4x + t = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, -0.5))); // NW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, 0.5))); // SW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, 0.5))); // SE + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, -0.5))); // NE + + t *= (layerCount - 0.0) / ( denom * 4.0 ); // weight layer 1 + + if( sampleCount > 2.0 ) { + // Layer-2: SampleCount 4 -> +12x = 16p + vec4 tn = vec4(0); + tn = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, -1.5))); // NW -> SW Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, -0.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, 0.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, 1.5))); // SW -> SE Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, 1.5))); // + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, 1.5))); // + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, 1.5))); // SE -> NE Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, 0.5))); // + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, -0.5))); // + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, -1.5))); // NE -> NW Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, -1.5))); // + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, -1.5))); // NW - 1 (closed) + + t += tn * (layerCount - 1) / ( denom * 12.0 ); // weight layer 2 + + if( sampleCount > 4.0 ) { + // Layer-3: SampleCount 6 -> +20x = 36p + tn = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, -2.5))); // NW -> SW Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, -1.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, -0.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, 0.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, 1.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, 2.5))); // SW -> SE Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, 2.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, 2.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, 2.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, 2.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, 2.5))); // SE -> NE Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, 1.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, 0.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, -0.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, -1.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, -2.5))); // NE -> NW Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, -2.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, -2.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, -2.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, -2.5))); // NW - 1 (closed) + + t += tn * (layerCount - 2) / ( denom * 20.0 ); // weight layer 3 + + if( sampleCount > 6.0 ) { + // Layer-4: SampleCount 8 -> +28x = 64p + tn = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, -3.5))); // NW -> SW Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, -2.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, -1.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, -0.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, 0.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, 1.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, 2.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, 3.5))); // SW -> SE Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, 3.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, 3.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, 3.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, 3.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, 3.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, 3.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, 3.5))); // SE -> NE Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, 2.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, 1.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, 0.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, -0.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, -1.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, -2.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, -3.5))); // NE -> NW Edge + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, -3.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, -3.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, -3.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, -3.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, -3.5))); + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, -3.5))); // NW - 1 (closed) + + t += tn * (layerCount - 3) / ( denom * 28.0 ); // weight layer 4 + } + } + } + + #if 0 + if(t.w == 0.0){ + discard; // discard freezes NV tegra2 compiler + } + #endif + + mgl_FragColor = t; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_bforce_even.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_bforce_even.glsl new file mode 100644 index 000000000..ba7611a06 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_bforce_even.glsl @@ -0,0 +1,96 @@ + // Pass-2: AA on Texture + // Note: gcv_FboTexCoord is in center of sample pixels. + + // float sample_count = gcu_FboTexSize.z; + vec2 psize = 1.0 / gcu_FboTexSize.xy; // pixel size + + // Not only the poles (NW, SW, ..) but the whole edge! + const float sample_weight = 1.0 / ( sample_count * sample_count ); + + // const vec4 tex_weights = vec4(0.075, 0.06, 0.045, 0.025); + vec2 texCoord = gcv_FboTexCoord.st; + + vec4 t; + + // SampleCount 2 -> 4x + t = texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-0.5, -0.5))*sample_weight; // NW + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-0.5, 0.5))*sample_weight; // SW + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 0.5, 0.5))*sample_weight; // SE + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 0.5, -0.5))*sample_weight; // NE + #if SAMPLE_COUNT > 2 + // SampleCount 4 -> +12x = 16p + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-1.5, -1.5))*sample_weight; // NW -> SW Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-1.5, -0.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-1.5, 0.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-1.5, 1.5))*sample_weight; // SW -> SE Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-0.5, 1.5))*sample_weight; // + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 0.5, 1.5))*sample_weight; // + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 1.5, 1.5))*sample_weight; // SE -> NE Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 1.5, 0.5))*sample_weight; // + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 1.5, -0.5))*sample_weight; // + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 1.5, -1.5))*sample_weight; // NE -> NW Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 0.5, -1.5))*sample_weight; // + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-0.5, -1.5))*sample_weight; // NW - 1 (closed) + + #if SAMPLE_COUNT > 4 + // SampleCount 6 -> +20x = 36p + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-2.5, -2.5))*sample_weight; // NW -> SW Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-2.5, -1.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-2.5, -0.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-2.5, 0.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-2.5, 1.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-2.5, 2.5))*sample_weight; // SW -> SE Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-1.5, 2.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-0.5, 2.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 0.5, 2.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 1.5, 2.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 2.5, 2.5))*sample_weight; // SE -> NE Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 2.5, 1.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 2.5, 0.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 2.5, -0.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 2.5, -1.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 2.5, -2.5))*sample_weight; // NE -> NW Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 1.5, -2.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 0.5, -2.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-0.5, -2.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-1.5, -2.5))*sample_weight; // NW - 1 (closed) + #if SAMPLE_COUNT > 6 + // SampleCount 8 -> +28x = 64p + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-3.5, -3.5))*sample_weight; // NW -> SW Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-3.5, -2.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-3.5, -1.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-3.5, -0.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-3.5, 0.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-3.5, 1.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-3.5, 2.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-3.5, 3.5))*sample_weight; // SW -> SE Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-2.5, 3.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-1.5, 3.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-0.5, 3.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 0.5, 3.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 1.5, 3.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 2.5, 3.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 3.5, 3.5))*sample_weight; // SE -> NE Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 3.5, 2.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 3.5, 1.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 3.5, 0.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 3.5, -0.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 3.5, -1.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 3.5, -2.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 3.5, -3.5))*sample_weight; // NE -> NW Edge + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 2.5, -3.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 1.5, -3.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 0.5, -3.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-0.5, -3.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-1.5, -3.5))*sample_weight; + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-2.5, -3.5))*sample_weight; // NW - 1 (closed) + #endif + #endif + #endif + #if 0 + if(t.w == 0.0){ + discard; // discard freezes NV tegra2 compiler + } + #endif + + mgl_FragColor = t; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_bforce_odd.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_bforce_odd.glsl new file mode 100644 index 000000000..7adf111d5 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_bforce_odd.glsl @@ -0,0 +1,87 @@ + // Pass-2: AA on Texture + // Note: gcv_FboTexCoord is in center of sample pixels. + + // float sample_count = gcu_FboTexSize.z; + vec2 psize = 1.0 / gcu_FboTexSize.xy; // pixel size + + // Not only the poles (NW, SW, ..) but the whole edge! + const float sample_weight = 1.0 / ( sample_count * sample_count ); + + // const vec4 tex_weights = vec4(0.075, 0.06, 0.045, 0.025); + vec2 texCoord = gcv_FboTexCoord.st; + + vec4 t; + + // SampleCount 1 -> 1x (raster 1x1) + t += texture2D(gcu_FboTexUnit, texCoord)*sample_weight; // CENTER + + #if SAMPLE_COUNT > 1 + // SampleCount 3 -> +8x = 9p (raster 3x3) + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-1.0, -1.0))*sample_weight; // top line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 0.0, -1.0))*sample_weight; // top line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 1.0, -1.0))*sample_weight; // top line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-1.0, 0.0))*sample_weight; // Center Left + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 1.0, 0.0))*sample_weight; // Center Right + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-1.0, 1.0))*sample_weight; // bottom line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 0.0, 1.0))*sample_weight; // bottom line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 1.0, 1.0))*sample_weight; // bottom line + + #if SAMPLE_COUNT > 3 + // SampleCount 5 -> +16x = 25p (raster 5x5) + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-2.0, -1.0))*sample_weight; // top line - 1 + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 2.0, -1.0))*sample_weight; // top line - 1 + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-2.0, 0.0))*sample_weight; // Center Left + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 2.0, 0.0))*sample_weight; // Center Right + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-2.0, 1.0))*sample_weight; // bottom line - 1 + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 2.0, 1.0))*sample_weight; // bottom line - 1 + + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-2.0, -2.0))*sample_weight; // top line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-1.0, -2.0))*sample_weight; // top line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 0.0, -2.0))*sample_weight; // top line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 1.0, -2.0))*sample_weight; // top line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 2.0, -2.0))*sample_weight; // top line + + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-2.0, 2.0))*sample_weight; // bottom line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-1.0, 2.0))*sample_weight; // bottom line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 0.0, 2.0))*sample_weight; // bottom line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 1.0, 2.0))*sample_weight; // bottom line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 2.0, 2.0))*sample_weight; // bottom line + + #if SAMPLE_COUNT > 5 + // SampleCount 7 -> +24x = 49p (raster 7x7) + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-3.0, -2.0))*sample_weight; // top line - 1 + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 3.0, -2.0))*sample_weight; // top line - 1 + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-3.0, -1.0))*sample_weight; // top line - 2 + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 3.0, -1.0))*sample_weight; // top line - 2 + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-3.0, 0.0))*sample_weight; // Center Left + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 3.0, 0.0))*sample_weight; // Center Right + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-3.0, 1.0))*sample_weight; // bottom line - 2 + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 3.0, 1.0))*sample_weight; // bottom line - 2 + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-3.0, 2.0))*sample_weight; // bottom line - 1 + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 3.0, 2.0))*sample_weight; // bottom line - 1 + + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-3.0, -3.0))*sample_weight; // top line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-2.0, -3.0))*sample_weight; // top line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-1.0, -3.0))*sample_weight; // top line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 0.0, -3.0))*sample_weight; // top line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 1.0, -3.0))*sample_weight; // top line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 2.0, -3.0))*sample_weight; // top line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 3.0, -3.0))*sample_weight; // top line + + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-3.0, 3.0))*sample_weight; // bottom line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-2.0, 3.0))*sample_weight; // bottom line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2(-1.0, 3.0))*sample_weight; // bottom line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 0.0, 3.0))*sample_weight; // bottom line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 1.0, 3.0))*sample_weight; // bottom line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 2.0, 3.0))*sample_weight; // bottom line + t += texture2D(gcu_FboTexUnit, texCoord + psize*vec2( 3.0, 3.0))*sample_weight; // bottom line + #endif + #endif + #endif + #if 0 + if(t.w == 0.0){ + discard; // discard freezes NV tegra2 compiler + } + #endif + + mgl_FragColor = t; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad.glsl new file mode 100644 index 000000000..3e74fb9a6 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad.glsl @@ -0,0 +1,41 @@ + + // Pass-2: AA on Texture + // Note: gcv_FboTexCoord is in center of sample pixels, origin is bottom left! + + float sampleCount = gcu_FboTexSize.z; + vec2 psize = 1.0 / gcu_FboTexSize.xy; // pixel size + + // Just poles (NW, SW, ..) + float edge1H = sampleCount / 2.0; + float edge1T = sampleCount / 3.0; + float edgeTH = edge1H-edge1T; + + vec2 normFragCoord = gl_FragCoord.xy - vec2(0.5, 0.5); // normalize center 0.5/0.5 -> 0/0 + vec2 modPos = mod(normFragCoord, 2.0); + float orient = mod(modPos.x + modPos.y, 2.0); // mirrored on all odd columns, alternating each row (checker-board pattern) + + vec2 texCoord = gcv_FboTexCoord.st; + vec4 t; + + if( 0.0 == orient ) { + // SWIPE LEFT -> RIGHT + t = GetSample(gcu_FboTexUnit, texCoord, psize, -edge1H, edgeTH, 0.0, 0.0)*0.25; // upper-left [p1] + t += GetSample(gcu_FboTexUnit, texCoord, psize, -edgeTH, -edge1H, 0.0, 0.0)*0.25; // lower-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeTH, edge1H, 0.0, 0.0)*0.25; // upper-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edge1H, -edgeTH, 0.0, 0.0)*0.25; // lower-right [p4] + } else { + t = GetSample(gcu_FboTexUnit, texCoord, psize, -edge1H, -edgeTH, 0.0, 0.0)*0.25; // lower-left [p4] + t += GetSample(gcu_FboTexUnit, texCoord, psize, -edgeTH, edge1H, 0.0, 0.0)*0.25; // upper-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeTH, -edge1H, 0.0, 0.0)*0.25; // lower-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edge1H, edgeTH, 0.0, 0.0)*0.25; // upper-right [p1] + } + + + #if 0 + if(t.w == 0.0){ + discard; // discard freezes NV tegra2 compiler + } + #endif + + mgl_FragColor = t; + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad2.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad2.glsl new file mode 100644 index 000000000..9e31e6bb7 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad2.glsl @@ -0,0 +1,41 @@ + + // Pass-2: AA on Texture + // Note: gcv_FboTexCoord is in center of sample pixels, origin is bottom left! + // + // Same as flipquad - but w/ rgss coordinates + + float sampleCount = gcu_FboTexSize.z; + vec2 psize = 1.0 / gcu_FboTexSize.xy; // pixel size + + vec2 normFragCoord = gl_FragCoord.xy - vec2(0.5, 0.5); // normalize center 0.5/0.5 -> 0/0 + vec2 modPos = mod(normFragCoord, 2.0); + float orient = mod(modPos.x + modPos.y, 2.0); // mirrored on all odd columns, alternating each row (checker-board pattern) + + vec2 texCoord = gcv_FboTexCoord.st; + float edge1Q = ( sampleCount / 2.0 ) - 1.0; + + vec4 t; + +// #define GetSample(texUnit, texCoord, psize, cx, cy, offX, offY) texture2D(texUnit, texCoord + psize * vec2(cx+offX, cy+offY)) + + if( 0.0 == orient ) { + // SWIPE LEFT -> RIGHT + t = GetSample(gcu_FboTexUnit, texCoord, psize, -edge1Q, 0.0, -0.5, 0.5)*0.25; // upper-left [p1] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edge1Q, -0.5, -0.5)*0.25; // lower-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edge1Q, 0.5, 0.5)*0.25; // upper-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edge1Q, 0.0, 0.5, -0.5)*0.25; // lower-right [p4] + } else { + t = GetSample(gcu_FboTexUnit, texCoord, psize, -edge1Q, 0.0, -0.5, -0.5)*0.25; // lower-left [p4] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edge1Q, -0.5, 0.5)*0.25; // upper-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edge1Q, 0.5, -0.5)*0.25; // lower-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edge1Q, 0.0, 0.5, 0.5)*0.25; // upper-right [p1] + } + + #if 0 + if(t.w == 0.0){ + discard; // discard freezes NV tegra2 compiler + } + #endif + + mgl_FragColor = t; + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad3.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad3.glsl new file mode 100644 index 000000000..8cc108bd1 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad3.glsl @@ -0,0 +1,109 @@ + + // Pass-2: AA on Texture + // Note: gcv_FboTexCoord is in center of sample pixels, origin is bottom left! + // + // Same as flipquad - but w/ rgss coordinates + + // float sample_count = gcu_FboTexSize.z; + vec2 psize = 1.0 / gcu_FboTexSize.xy; // pixel size + + vec2 normFragCoord = gl_FragCoord.xy - vec2(0.5, 0.5); // normalize center 0.5/0.5 -> 0/0 + vec2 modPos = mod(normFragCoord, 2.0); + float orient = mod(modPos.x + modPos.y, 2.0); // mirrored on all odd columns, alternating each row (checker-board pattern) + + vec2 texCoord = gcv_FboTexCoord.st; + vec4 t; + +// #define GetSample(texUnit, texCoord, psize, cx, cy, offX, offY) texture2D(texUnit, texCoord + psize * vec2(cx+offX, cy+offY)) + + #if SAMPLE_COUNT == 1 + + t = texture2D(gcu_FboTexUnit, texCoord); + + #elif SAMPLE_COUNT < 4 + + // SampleCount 2 -> 2p + const float weight = 1.0 / 2.0; + const float edge = ( sample_count / 2.0 ) - 1.0; + + t = GetSample(gcu_FboTexUnit, texCoord, psize, -edge, edge, -0.5, 0.5)*weight; // center + t += GetSample(gcu_FboTexUnit, texCoord, psize, edge, -edge, 0.5, -0.5)*weight; // center + + #elif SAMPLE_COUNT < 8 + + // SampleCount 4 -> 4p + const float weight = 1.0 / 4.0; + const float edgeS4_1Q = ( sample_count / 2.0 ) - 1.0; + + if( 0.0 == orient ) { + // SWIPE LEFT -> RIGHT + t = GetSample(gcu_FboTexUnit, texCoord, psize, -edgeS4_1Q, 0.0, -0.5, 0.5)*weight; // upper-left [p1] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edgeS4_1Q, -0.5, -0.5)*weight; // lower-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edgeS4_1Q, 0.5, 0.5)*weight; // upper-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeS4_1Q, 0.0, 0.5, -0.5)*weight; // lower-right [p4] + } else { + t = GetSample(gcu_FboTexUnit, texCoord, psize, -edgeS4_1Q, 0.0, -0.5, -0.5)*weight; // lower-left [p4] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edgeS4_1Q, -0.5, 0.5)*weight; // upper-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edgeS4_1Q, 0.5, -0.5)*weight; // lower-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeS4_1Q, 0.0, 0.5, 0.5)*weight; // upper-right [p1] + } + + #else + + // SampleCount 8 -> 16p + const float weight = 1.0 / 16.0; + const float edgeS4_1Q = 1.0; + + if( 0.0 == orient ) { + // SWIPE LEFT -> RIGHT + t = GetSample(gcu_FboTexUnit, texCoord, psize, -edgeS4_1Q, 0.0, -2.0-0.5, -2.0+0.5)*weight; // upper-left [p1] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edgeS4_1Q, -2.0-0.5, -2.0-0.5)*weight; // lower-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edgeS4_1Q, -2.0-0.5, -2.0-0.5)*weight; // upper-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeS4_1Q, 0.0, -2.0-0.5, -2.0-0.5)*weight; // lower-right [p4] + + t += GetSample(gcu_FboTexUnit, texCoord, psize, -edgeS4_1Q, 0.0, -2.0-0.5, 2.0-0.5)*weight; // lower-left [p4] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edgeS4_1Q, -2.0-0.5, 2.0+0.5)*weight; // upper-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edgeS4_1Q, -2.0+0.5, 2.0-0.5)*weight; // lower-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeS4_1Q, 0.0, -2.0+0.5, 2.0+0.5)*weight; // upper-right [p1] + + t += GetSample(gcu_FboTexUnit, texCoord, psize, -edgeS4_1Q, 0.0, 2.0-0.5, -2.0-0.5)*weight; // lower-left [p4] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edgeS4_1Q, 2.0-0.5, -2.0+0.5)*weight; // upper-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edgeS4_1Q, 2.0+0.5, -2.0-0.5)*weight; // lower-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeS4_1Q, 0.0, 2.0+0.5, -2.0+0.5)*weight; // upper-right [p1] + + t += GetSample(gcu_FboTexUnit, texCoord, psize, -edgeS4_1Q, 0.0, 2.0-0.5, 2.0+0.5)*weight; // upper-left [p1] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edgeS4_1Q, 2.0-0.5, 2.0-0.5)*weight; // lower-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edgeS4_1Q, 2.0-0.5, 2.0-0.5)*weight; // upper-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeS4_1Q, 0.0, 2.0-0.5, 2.0-0.5)*weight; // lower-right [p4] + } else { + t = GetSample(gcu_FboTexUnit, texCoord, psize, -edgeS4_1Q, 0.0, -2.0-0.5, -2.0-0.5)*weight; // lower-left [p4] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edgeS4_1Q, -2.0-0.5, -2.0+0.5)*weight; // upper-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edgeS4_1Q, -2.0+0.5, -2.0-0.5)*weight; // lower-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeS4_1Q, 0.0, -2.0+0.5, -2.0+0.5)*weight; // upper-right [p1] + + t += GetSample(gcu_FboTexUnit, texCoord, psize, -edgeS4_1Q, 0.0, -2.0-0.5, 2.0+0.5)*weight; // upper-left [p1] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edgeS4_1Q, -2.0-0.5, 2.0-0.5)*weight; // lower-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edgeS4_1Q, -2.0-0.5, 2.0-0.5)*weight; // upper-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeS4_1Q, 0.0, -2.0-0.5, 2.0-0.5)*weight; // lower-right [p4] + + t += GetSample(gcu_FboTexUnit, texCoord, psize, -edgeS4_1Q, 0.0, 2.0-0.5, -2.0+0.5)*weight; // upper-left [p1] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edgeS4_1Q, 2.0-0.5, -2.0-0.5)*weight; // lower-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edgeS4_1Q, 2.0-0.5, -2.0-0.5)*weight; // upper-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeS4_1Q, 0.0, 2.0-0.5, -2.0-0.5)*weight; // lower-right [p4] + + t += GetSample(gcu_FboTexUnit, texCoord, psize, -edgeS4_1Q, 0.0, 2.0-0.5, 2.0-0.5)*weight; // lower-left [p4] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edgeS4_1Q, 2.0-0.5, 2.0+0.5)*weight; // upper-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edgeS4_1Q, 2.0+0.5, 2.0-0.5)*weight; // lower-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeS4_1Q, 0.0, 2.0+0.5, 2.0+0.5)*weight; // upper-right [p1] + } + + #endif + + #if 0 + if(t.w == 0.0){ + discard; // discard freezes NV tegra2 compiler + } + #endif + + mgl_FragColor = t; + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_fxaa3.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_fxaa3.glsl new file mode 100644 index 000000000..015dc1b24 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_fxaa3.glsl @@ -0,0 +1,56 @@ + + // Pass-2: AA on Texture + // Note: gcv_FboTexCoord is in center of sample pixels. + + if( gcu_FboTexSize.z < 4.0 ) { + // FXAA-2 + const float FXAA_REDUCE_MIN = (1.0/128.0); + const float FXAA_REDUCE_MUL = (1.0/8.0); + const float FXAA_SPAN_MAX = 8.0; + + float sampleCount = gcu_FboTexSize.z; + + vec2 texCoord = gcv_FboTexCoord.st; + const float poff = 1.0; + vec2 psize = 1.0 / texCoord; // pixel size + + vec3 rgbNW = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-poff, -poff))).rgb; + vec3 rgbSW = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-poff, poff))).rgb; + vec3 rgbSE = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( poff, poff))).rgb; + vec3 rgbNE = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( poff, -poff))).rgb; + vec4 rgbM = texture2D(gcu_FboTexUnit, texCoord); + + const vec3 luma = vec3(0.299, 0.587, 0.114); + float lumaNW = dot(rgbNW, luma); + float lumaNE = dot(rgbNE, luma); + float lumaSW = dot(rgbSW, luma); + float lumaSE = dot(rgbSE, luma); + float lumaM = dot(rgbM.rgb, luma); + float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE))); + float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE))); + vec2 dir; + dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE)); + dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE)); + float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL),FXAA_REDUCE_MIN); + float rcpDirMin = 1.0/(min(abs(dir.x), abs(dir.y)) + dirReduce); + dir = min( vec2( FXAA_SPAN_MAX, FXAA_SPAN_MAX), + max( vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),dir * rcpDirMin) ) * psize; + + + vec3 rgbA = 0.5 * ( texture2D(gcu_FboTexUnit, texCoord + dir * (1.0/3.0 - 0.5)).rgb + + texture2D(gcu_FboTexUnit, texCoord + dir * (2.0/3.0 - 0.5)).rgb ); + vec3 rgbB = rgbA * 0.5 + 0.25 * ( texture2D(gcu_FboTexUnit, texCoord + (dir * - 0.5)).rgb + + texture2D(gcu_FboTexUnit, texCoord + (dir * 0.5)).rgb ); + float lumaB = dot(rgbB, luma); + if((lumaB < lumaMin) || (lumaB > lumaMax)) { + mgl_FragColor.rgb = rgbA; + } else { + mgl_FragColor.rgb = rgbB; + } + mgl_FragColor.a = gcu_Alpha * rgbM.a; // mix(0.0, gcu_Alpha, rgbM.a); // t.a one of [ 0.0, 1.0 ] + } else { + +#include curverenderer01-pass2-vbaa_poles_equalweight.glsl + + } + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_poles_bilin1.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_poles_bilin1.glsl new file mode 100644 index 000000000..d634c1f9b --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_poles_bilin1.glsl @@ -0,0 +1,91 @@ + // Pass-2: AA on Texture + // Note: gcv_FboTexCoord is in center of sample pixels. + + vec2 texCoord = gcv_FboTexCoord.st; + + float sampleCount = gcu_FboTexSize.z; + vec2 tsize = gcu_FboTexSize.xy; // tex size + vec2 psize = 1.0 / gcu_FboTexSize.xy; // pixel size + + // mix(x,y,a): x*(1-a) + y*a + // + // bilinear filtering includes 2 mix: + // + // pix1 = tex[x0][y0] * ( 1 - u_ratio ) + tex[x1][y0] * u_ratio + // pix2 = tex[x0][y1] * ( 1 - u_ratio ) + tex[x1][y1] * u_ratio + // fin = pix1 * ( 1 - v_ratio ) + pix2 * v_ratio + // + // so we can use the build in mix function for these 2 computations ;-) + // + vec2 uv_ratio = fract(texCoord*tsize); // texCoord*tsize - floor(texCoord*tsize); + + // Just poles (NW, SW, ..) + float pixelCount = 2 * sampleCount; + + // sampleCount [0, 1, 3, 5, 7] are undefined! + float layerCount = ( sampleCount / 2.0 ); + + // sum of all integer [layerCount .. 1] -> Gauss + float denom = ( layerCount / 2.0 ) * ( layerCount + 1.0 ); + + vec4 t, p1, p2, p3, p4; + + // Layer-1: SampleCount 2 -> 4x + p1 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, -0.5))); // NW + p2 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, 0.5))); // SW + p3 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, 0.5))); // SE + p4 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, -0.5))); // NE + + p1 = mix( p1, p4, uv_ratio.x); + p2 = mix( p2, p3, uv_ratio.x); + t = mix ( p1, p2, uv_ratio.y ); + + t *= (layerCount - 0.0) / ( denom ); // weight layer 1 + + if( sampleCount > 2.0 ) { + // Layer-2: SampleCount 4 -> +4x = 8p + p1 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, -1.5))); // NW + p2 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, 1.5))); // SW + p3 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, 1.5))); // SE + p4 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, -1.5))); // NE + + p1 = mix( p1, p4, uv_ratio.x); + p2 = mix( p2, p3, uv_ratio.x); + p3 = mix ( p1, p2, uv_ratio.y ); + t += p3 * (layerCount - 1) / ( denom ); // weight layer 2 + + if( sampleCount > 4.0 ) { + // Layer-3: SampleCount 6 -> +4 = 12p + p1 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, -2.5))); // NW + p2 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, 2.5))); // SW + p3 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, 2.5))); // SE + p4 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, -2.5))); // NE + + p1 = mix( p1, p4, uv_ratio.x); + p2 = mix( p2, p3, uv_ratio.x); + p3 = mix ( p1, p2, uv_ratio.y ); + t += p3 * (layerCount - 2) / ( denom ); // weight layer 3 + + if( sampleCount > 6.0 ) { + // Layer-4: SampleCount 8 -> +4 = 16p + p1 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, -3.5))); // NW + p2 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, 3.5))); // SW + p3 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, 3.5))); // SE + p4 = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, -3.5))); // NE + + p1 = mix( p1, p4, uv_ratio.x); + p2 = mix( p2, p3, uv_ratio.x); + p3 = mix ( p1, p2, uv_ratio.y ); + + t += p3 * (layerCount - 3) / ( denom ); // weight layer 4 + } + } + } + + #if 0 + if(t.w == 0.0){ + discard; // discard freezes NV tegra2 compiler + } + #endif + + mgl_FragColor = t; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_polesequal.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_polesequal.glsl new file mode 100644 index 000000000..0e8b6f161 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_polesequal.glsl @@ -0,0 +1,49 @@ + + // Pass-2: AA on Texture + // Note: gcv_FboTexCoord is in center of sample pixels. + + float sampleCount = gcu_FboTexSize.z; + vec2 psize = 1.0 / gcu_FboTexSize.xy; // pixel size + + // Just poles (NW, SW, ..) + float sample_weight = 1 / ( 2 * sampleCount ); + + vec2 texCoord = gcv_FboTexCoord.st; + + vec4 t; + + // SampleCount 2 -> 4x + t = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, -0.5)))*sample_weight; // NW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, 0.5)))*sample_weight; // SW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, 0.5)))*sample_weight; // SE + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, -0.5)))*sample_weight; // NE + if( sampleCount > 2.0 ) { + // SampleCount 4 -> +4 = 8p + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, -1.5)))*sample_weight; // NW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, 1.5)))*sample_weight; // SW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, 1.5)))*sample_weight; // SE + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, -1.5)))*sample_weight; // NE + + if( sampleCount > 4.0 ) { + // SampleCount 6 -> +4 = 12p + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, -2.5)))*sample_weight; // NW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, 2.5)))*sample_weight; // SW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, 2.5)))*sample_weight; // SE + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, -2.5)))*sample_weight; // NE + if( sampleCount > 6.0 ) { + // SampleCount 8 -> +4 = 16p + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, -3.5)))*sample_weight; // NW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, 3.5)))*sample_weight; // SW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, 3.5)))*sample_weight; // SE + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, -3.5)))*sample_weight; // NE + } + } + } + #if 0 + if(t.w == 0.0){ + discard; // discard freezes NV tegra2 compiler + } + #endif + + mgl_FragColor = t; + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_polesprop01.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_polesprop01.glsl new file mode 100644 index 000000000..6c263b9bd --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_polesprop01.glsl @@ -0,0 +1,65 @@ + // Pass-2: AA on Texture + // Note: gcv_FboTexCoord is in center of sample pixels. + + float sampleCount = gcu_FboTexSize.z; + vec2 psize = 1.0 / gcu_FboTexSize.xy; // pixel size + + // Just poles (NW, SW, ..) + float pixelCount = 2 * sampleCount; + + // sampleCount [0, 1, 3, 5, 7] are undefined! + float layerCount = ( sampleCount / 2.0 ); + + // sum of all integer [layerCount .. 1] -> Gauss + float denom = ( layerCount / 2.0 ) * ( layerCount + 1.0 ); + + vec2 texCoord = gcv_FboTexCoord.st; + + vec4 t; + + // Layer-1: SampleCount 2 -> 4x + t = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, -0.5))); // NW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-0.5, 0.5))); // SW + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, 0.5))); // SE + t += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 0.5, -0.5))); // NE + + t *= (layerCount - 0.0) / ( denom * 4.0 ); // weight layer 1 + + if( sampleCount > 2.0 ) { + // Layer-2: SampleCount 4 -> +4x = 8p + vec4 tn = vec4(0); + tn = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, -1.5))); // NW + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-1.5, 1.5))); // SW + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, 1.5))); // SE + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 1.5, -1.5))); // NE + + t += tn * (layerCount - 1) / ( denom * 4.0 ); // weight layer 2 + + if( sampleCount > 4.0 ) { + // Layer-3: SampleCount 6 -> +4 = 12p + tn = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, -2.5))); // NW + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-2.5, 2.5))); // SW + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, 2.5))); // SE + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 2.5, -2.5))); // NE + + t += tn * (layerCount - 2) / ( denom * 4.0 ); // weight layer 3 + + if( sampleCount > 6.0 ) { + // Layer-4: SampleCount 8 -> +4 = 16p + tn = texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, -3.5))); // NW + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2(-3.5, 3.5))); // SW + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, 3.5))); // SE + tn += texture2D(gcu_FboTexUnit, texCoord + psize*(vec2( 3.5, -3.5))); // NE + + t += tn * (layerCount - 3) / ( denom * 4.0 ); // weight layer 4 + } + } + } + + #if 0 + if(t.w == 0.0){ + discard; // discard freezes NV tegra2 compiler + } + #endif + + mgl_FragColor = t; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_quincunx.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_quincunx.glsl new file mode 100644 index 000000000..07a9adf46 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_quincunx.glsl @@ -0,0 +1,28 @@ + + // Pass-2: AA on Texture + // Note: gcv_FboTexCoord is in center of sample pixels, origin is bottom left! + + float sampleCount = gcu_FboTexSize.z; + vec2 psize = 1.0 / gcu_FboTexSize.xy; // pixel size + + // Just poles (NW, SW, ..) + float edgeH = sampleCount / 2.0; + + vec2 texCoord = gcv_FboTexCoord.st; + + vec4 t; + + t = GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, 0.0, 0.0, 0.0)*0.5; // w1 - center + t += GetSample(gcu_FboTexUnit, texCoord, psize, -edgeH, -edgeH, 0.0, 0.0)*0.125; // w2 - sharing + t += GetSample(gcu_FboTexUnit, texCoord, psize, -edgeH, edgeH, 0.0, 0.0)*0.125; // w3 - edges + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeH, -edgeH, 0.0, 0.0)*0.125; // w4 - w/ all pixels + t += GetSample(gcu_FboTexUnit, texCoord, psize, edgeH, edgeH, 0.0, 0.0)*0.125; // w5 + + #if 0 + if(t.w == 0.0){ + discard; // discard freezes NV tegra2 compiler + } + #endif + + mgl_FragColor = t; + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_rgss.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_rgss.glsl new file mode 100644 index 000000000..27a5684a6 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_rgss.glsl @@ -0,0 +1,25 @@ + + // Pass-2: AA on Texture + // Note: gcv_FboTexCoord is in center of sample pixels, origin is bottom left! + + float sampleCount = gcu_FboTexSize.z; + vec2 psize = 1.0 / gcu_FboTexSize.xy; // pixel size + + vec2 texCoord = gcv_FboTexCoord.st; + float edge1Q = ( sampleCount / 2.0 ) - 1.0; + + vec4 t; + // SWIPE LEFT -> RIGHT + t = GetSample(gcu_FboTexUnit, texCoord, psize, -edge1Q, 0.0, -0.5, 0.5)*0.25; // upper-left [p1] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, -edge1Q, -0.5, -0.5)*0.25; // lower-left [p3] + t += GetSample(gcu_FboTexUnit, texCoord, psize, 0.0, edge1Q, 0.5, 0.5)*0.25; // upper-right [p2] + t += GetSample(gcu_FboTexUnit, texCoord, psize, edge1Q, 0.0, 0.5, -0.5)*0.25; // lower-right [p4] + + #if 0 + if(t.w == 0.0){ + discard; // discard freezes NV tegra2 compiler + } + #endif + + mgl_FragColor = t; + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2.vp new file mode 100644 index 000000000..64857c9ce --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2.vp @@ -0,0 +1,17 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#if __VERSION__ >= 130 + #define attribute in + #define varying out +#endif + +#include uniforms.glsl +#include attributes.glsl +#include varyings.glsl + +void main(void) +{ + // gl_Position = gcu_PMVMatrix01[0] * gcu_PMVMatrix01[1] * vec4(gca_FboVertices, 1); + gl_Position = gcu_PMVMatrix01[0] * gcu_PMVMatrix01[1] * gca_FboVertices; + gcv_FboTexCoord = gca_FboTexCoords; +} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-segment-head.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-segment-head.fp new file mode 100644 index 000000000..05407a4e6 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-segment-head.fp @@ -0,0 +1,16 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +// +// 2-pass shader w/o weight +// + +#if __VERSION__ >= 130 + #define varying in + out vec4 mgl_FragColor; + #define texture2D texture +#else + #define mgl_FragColor gl_FragColor +#endif + +#define GetSample(texUnit, texCoord, psize, cx, cy, offX, offY) texture2D(texUnit, texCoord + psize * vec2(cx+offX, cy+offY)) + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-single.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-single.vp new file mode 100644 index 000000000..14210be39 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-single.vp @@ -0,0 +1,33 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#if __VERSION__ >= 130 + #define attribute in + #define varying out +#endif + +#include uniforms.glsl +#include attributes.glsl +#include varyings.glsl + +void main(void) +{ + gl_Position = gcu_PMVMatrix01[0] * gcu_PMVMatrix01[1] * gca_Vertices; +#if 1 + gcv_CurveParam = gca_CurveParams; +#else + if( gcv_CurveParams.x <= -10.0 ) { + // vec4 tc = gcu_PMVMatrix01[0] * gcu_PMVMatrix01[1] * vec4(gca_CurveParams.xy, gca_Vertices.z, 1); + // gcv_CurveParams = vec3(tc.xy, gca_CurveParams.z); + gcv_CurveParam = gca_CurveParams; + } else { + gcv_CurveParam = gca_CurveParams; + } +#endif +#ifdef USE_COLOR_TEXTURE + vec2 dim = vec2(gcu_ColorTexBBox.z - gcu_ColorTexBBox.x, gcu_ColorTexBBox.w - gcu_ColorTexBBox.y); + gcv_ColorTexCoord = vec2(gca_Vertices.x - gcu_ColorTexBBox.x, gca_Vertices.y - gcu_ColorTexBBox.y) / dim; +#endif +#ifdef USE_COLOR_CHANNEL + gcv_Color = gca_Colors; +#endif +} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-xxx.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-xxx.vp deleted file mode 100644 index 64a6835ec..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-xxx.vp +++ /dev/null @@ -1,12 +0,0 @@ -//Copyright 2010 JogAmp Community. All rights reserved. - -#include uniforms.glsl -#include attributes.glsl -#include varyings.glsl - -void main(void) -{ - // gl_Position = gcu_PMVMatrix[0] * gcu_PMVMatrix[1] * vec4(gca_Vertices, 1); - gl_Position = gcu_PMVMatrix[0] * gcu_PMVMatrix[1] * gca_Vertices; - gcv_TexCoord = gca_TexCoords; -} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01a-es2-merged.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01a-es2-merged.fp deleted file mode 100644 index da32df51f..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01a-es2-merged.fp +++ /dev/null @@ -1,52 +0,0 @@ -//Copyright 2010 JogAmp Community. All rights reserved. - -#ifdef GL_ES - precision lowp float; - precision lowp int; -#endif - -uniform mat4 gcu_PMVMatrix[3]; // P, Mv, and Mvi -uniform vec3 gcu_ColorStatic; -uniform float gcu_Alpha; - -varying vec2 gcv_TexCoord; - -const vec3 b_color = vec3(1.0, 1.0, 1.0); - -void main (void) -{ - vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y)); - vec3 c = gcu_ColorStatic; - - float alpha = 0.0; - - if((gcv_TexCoord.x == 0.0) && (gcv_TexCoord.y == 0.0)) { - alpha = gcu_Alpha; - } - else if ((gcv_TexCoord.x > 0.0) && (rtex.y > 0.0 || rtex.x == 1.0)) { - vec2 dtx = dFdx(rtex); - vec2 dty = dFdy(rtex); - - rtex.y -= 0.1; - - if(rtex.y < 0.0) { - rtex.y = 0.0; - } - - vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x)); - float position = rtex.y - (rtex.x * (1.0 - rtex.x)); - float d = position/(length(f)); - - float a = (0.5 - d * sign(gcv_TexCoord.y)); - - if (a >= 1.0) { - alpha = gcu_Alpha; - } else if (a <= 0.0) { - alpha=0.0; - } else { - alpha = gcu_Alpha * a; - } - } - - gl_FragColor = vec4(c, alpha); -} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01a-es2.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01a-es2.fp deleted file mode 100644 index e693891a6..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01a-es2.fp +++ /dev/null @@ -1,13 +0,0 @@ -//Copyright 2010 JogAmp Community. All rights reserved. - -#version 100 - -// we require dFdx/dFdy -// #extension OES_standard_derivatives : require -#extension GL_OES_standard_derivatives : enable - -precision mediump float; -precision mediump int; - -#include curverenderer01a-xxx.fp - diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01a-gl2.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01a-gl2.fp deleted file mode 100644 index d187fea24..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01a-gl2.fp +++ /dev/null @@ -1,6 +0,0 @@ -//Copyright 2010 JogAmp Community. All rights reserved. - -#version 110 - -#include curverenderer01a-xxx.fp - diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01a-xxx.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01a-xxx.fp deleted file mode 100644 index f3a88adef..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01a-xxx.fp +++ /dev/null @@ -1,42 +0,0 @@ -//Copyright 2010 JogAmp Community. All rights reserved. - -// -// 1-pass shader w/o weight -// - -#include uniforms.glsl -#include varyings.glsl - -void main (void) -{ - vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y)); - vec3 c = gcu_ColorStatic.rgb; - - float alpha = 0.0; - - if((gcv_TexCoord.x == 0.0) && (gcv_TexCoord.y == 0.0)) { - alpha = gcu_Alpha; - } - else if ((gcv_TexCoord.x > 0.0) && (rtex.y > 0.0 || rtex.x == 1.0)) { - rtex.y -= 0.1; - - if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) { - // discard; // freezes NV tegra2 compiler - alpha = 0.0; - } else { - rtex.y = max(rtex.y, 0.0); - - vec2 dtx = dFdx(rtex); - vec2 dty = dFdy(rtex); - - vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x)); - float position = rtex.y - (rtex.x * (1.0 - rtex.x)); - - // FIXME: will we ever set gcu_Alpha != 1.0 ? If not, a==alpha! - float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0); - alpha = gcu_Alpha * a; - } - } - - gl_FragColor = vec4(c, alpha); -} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01b-es2.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01b-es2.fp deleted file mode 100644 index 2e709630d..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01b-es2.fp +++ /dev/null @@ -1,14 +0,0 @@ -//Copyright 2010 JogAmp Community. All rights reserved. - -#version 100 - -// we require dFdx/dFdy -// #extension OES_standard_derivatives : require -#extension GL_OES_standard_derivatives : enable - -precision mediump float; -precision mediump int; -precision mediump sampler2D; - -#include curverenderer01b-xxx.fp - diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01b-gl2.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01b-gl2.fp deleted file mode 100644 index 01e08ff30..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01b-gl2.fp +++ /dev/null @@ -1,6 +0,0 @@ -//Copyright 2010 JogAmp Community. All rights reserved. - -#version 110 - -#include curverenderer01b-xxx.fp - diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01b-xxx.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01b-xxx.fp deleted file mode 100644 index 879e41e4c..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01b-xxx.fp +++ /dev/null @@ -1,82 +0,0 @@ -//Copyright 2010 JogAmp Community. All rights reserved. - -// -// 2-pass shader w/o weight -// - -#include uniforms.glsl -#include varyings.glsl - -const vec4 tex_weights = vec4(0.075, 0.06, 0.045, 0.025); - -void main (void) -{ - vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y)); - vec3 c = gcu_ColorStatic.rgb; - - float alpha = 0.0; - float enable = 1.0; - - if((gcv_TexCoord.x == 0.0) && (gcv_TexCoord.y == 0.0)) { - alpha = gcu_Alpha; - } - else if((gcv_TexCoord.x >= 5.0)) { - vec2 dfx = dFdx(gcv_TexCoord); - vec2 dfy = dFdy(gcv_TexCoord); - - vec2 size = 1.0/gcu_TextureSize; - - rtex -= 5.0; - vec4 t = texture2D(gcu_TextureUnit, rtex)* 0.18; - - t += texture2D(gcu_TextureUnit, rtex + size*(vec2(1, 0)))*tex_weights.x; - t += texture2D(gcu_TextureUnit, rtex - size*(vec2(1, 0)))*tex_weights.x; - t += texture2D(gcu_TextureUnit, rtex + size*(vec2(0, 1)))*tex_weights.x; - t += texture2D(gcu_TextureUnit, rtex - size*(vec2(0, 1)))*tex_weights.x; - - t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(1, 0)))*tex_weights.y; - t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(1, 0)))*tex_weights.y; - t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(0, 1)))*tex_weights.y; - t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(0, 1)))*tex_weights.y; - - t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(1, 0)))*tex_weights.z; - t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(1, 0)))*tex_weights.z; - t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(0, 1)))*tex_weights.z; - t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(0, 1)))*tex_weights.z; - - t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(1, 0)))*tex_weights.w; - t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(1, 0)))*tex_weights.w; - t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(0, 1)))*tex_weights.w; - t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(0, 1)))*tex_weights.w; - - /** discard freezes NV tegra2 compiler - if(t.w == 0.0){ - discard; - } */ - - c = t.xyz; - alpha = gcu_Alpha * t.w; - } - else if ((gcv_TexCoord.x > 0.0) && (rtex.y > 0.0 || rtex.x == 1.0)) { - rtex.y -= 0.1; - - if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) { - // discard; // freezes NV tegra2 compiler - alpha = 0.0; - } else { - rtex.y = max(rtex.y, 0.0); - - vec2 dtx = dFdx(rtex); - vec2 dty = dFdy(rtex); - - vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x)); - float position = rtex.y - (rtex.x * (1.0 - rtex.x)); - - // FIXME: will we ever set gcu_Alpha != 1.0 ? If not, a==alpha! - float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0); - alpha = gcu_Alpha * a; - } - } - - gl_FragColor = vec4(c, alpha); -} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02a-es2.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02a-es2.fp deleted file mode 100644 index b52420350..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02a-es2.fp +++ /dev/null @@ -1,14 +0,0 @@ -//Copyright 2010 JogAmp Community. All rights reserved. - -#version 100 - -// we require dFdx/dFdy -// #extension OES_standard_derivatives : require -#extension GL_OES_standard_derivatives : enable - -precision mediump float; -precision mediump int; -precision mediump sampler2D; - -#include curverenderer02a-xxx.fp - diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02a-gl2.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02a-gl2.fp deleted file mode 100644 index 01715daa5..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02a-gl2.fp +++ /dev/null @@ -1,6 +0,0 @@ -//Copyright 2010 JogAmp Community. All rights reserved. - -#version 110 - -#include curverenderer02a-xxx.fp - diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02a-xxx.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02a-xxx.fp deleted file mode 100644 index d31bafb5a..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02a-xxx.fp +++ /dev/null @@ -1,48 +0,0 @@ -//Copyright 2010 JogAmp Community. All rights reserved.
-
-//
-// 1-pass shader w/ weight
-//
-
-#include uniforms.glsl
-#include varyings.glsl
-
-void main (void)
-{
- vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y));
- vec3 c = gcu_ColorStatic.rgb;
-
- float alpha = 0.0;
-
- if((gcv_TexCoord.x == 0.0) && (gcv_TexCoord.y == 0.0)) {
- alpha = gcu_Alpha;
- }
- else if ((gcv_TexCoord.x > 0.0) && (rtex.y > 0.0 || rtex.x == 1.0)) {
- rtex.y -= 0.1;
-
- if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) {
- // discard; // freezes NV tegra2 compiler
- alpha = 0.0;
- } else {
- rtex.y = max(rtex.y, 0.0);
-
- vec2 dtx = dFdx(rtex);
- vec2 dty = dFdy(rtex);
-
- float w = gcu_Weight;
- float pd = ((2.0 - (2.0*w))*rtex.x*rtex.x) + 2.0*(w-1.0)*rtex.x + 1.0;
- float position = rtex.y - ((w*rtex.x*(1.0 - rtex.x))/pd);
-
- float aph = 2.0 - 2.0*w;
-
- float gd = (aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0)*(aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0);
- vec2 f = vec2((dtx.y - (w*dtx.x*(1.0 - 2.0*rtex.x))/gd), (dty.y - (w*dty.x*(1.0 - 2.0*rtex.x))/gd));
-
- // FIXME: will we ever set gcu_Alpha != 1.0 ? If not, a==alpha!
- float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
- alpha = gcu_Alpha * a;
- }
- }
-
- gl_FragColor = vec4(c, alpha);
-}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02b-es2.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02b-es2.fp deleted file mode 100644 index e0486dd7b..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02b-es2.fp +++ /dev/null @@ -1,14 +0,0 @@ -//Copyright 2010 JogAmp Community. All rights reserved. - -#version 100 - -// we require dFdx/dFdy -// #extension OES_standard_derivatives : require -#extension GL_OES_standard_derivatives : enable - -precision mediump float; -precision mediump int; -precision mediump sampler2D; - -#include curverenderer02b-xxx.fp - diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02b-gl2.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02b-gl2.fp deleted file mode 100644 index b1cc72188..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02b-gl2.fp +++ /dev/null @@ -1,6 +0,0 @@ -//Copyright 2010 JogAmp Community. All rights reserved. - -#version 110 - -#include curverenderer02b-xxx.fp - diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02b-xxx.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02b-xxx.fp deleted file mode 100644 index be738498c..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02b-xxx.fp +++ /dev/null @@ -1,88 +0,0 @@ -//Copyright 2010 JogAmp Community. All rights reserved.
-
-//
-// 2-pass shader w/ weight
-//
-
-#include uniforms.glsl
-#include varyings.glsl
-
-const vec4 tex_weights = vec4(0.075, 0.06, 0.045, 0.025);
-
-void main (void)
-{
- vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y));
- vec3 c = gcu_ColorStatic.rgb;
-
- float alpha = 0.0;
-
- if((gcv_TexCoord.x == 0.0) && (gcv_TexCoord.y == 0.0)) {
- alpha = gcu_Alpha;
- }
- else if((gcv_TexCoord.x >= 5.0)) {
- vec2 dfx = dFdx(gcv_TexCoord);
- vec2 dfy = dFdy(gcv_TexCoord);
-
- vec2 size = 1.0/gcu_TextureSize;
-
- rtex -= 5.0;
- vec4 t = texture2D(gcu_TextureUnit, rtex)* 0.18;
-
- t += texture2D(gcu_TextureUnit, rtex + size*(vec2(1, 0)))*tex_weights.x;
- t += texture2D(gcu_TextureUnit, rtex - size*(vec2(1, 0)))*tex_weights.x;
- t += texture2D(gcu_TextureUnit, rtex + size*(vec2(0, 1)))*tex_weights.x;
- t += texture2D(gcu_TextureUnit, rtex - size*(vec2(0, 1)))*tex_weights.x;
-
- t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(1, 0)))*tex_weights.y;
- t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(1, 0)))*tex_weights.y;
- t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(0, 1)))*tex_weights.y;
- t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(0, 1)))*tex_weights.y;
-
- t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(1, 0)))*tex_weights.z;
- t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(1, 0)))*tex_weights.z;
- t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(0, 1)))*tex_weights.z;
- t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(0, 1)))*tex_weights.z;
-
- t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(1, 0)))*tex_weights.w;
- t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(1, 0)))*tex_weights.w;
- t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(0, 1)))*tex_weights.w;
- t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(0, 1)))*tex_weights.w;
-
- /** discard freezes NV tegra2 compiler
- if(t.w == 0.0) {
- discard;
- } */
-
- c = t.xyz;
- alpha = gcu_Alpha * t.w;
- }
- ///////////////////////////////////////////////////////////
- else if ((gcv_TexCoord.x > 0.0) && (rtex.y > 0.0 || rtex.x == 1.0)) {
- rtex.y -= 0.1;
-
- if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) {
- // discard; // freezes NV tegra2 compiler
- alpha = 0.0;
- } else {
- rtex.y = max(rtex.y, 0.0);
-
- vec2 dtx = dFdx(rtex);
- vec2 dty = dFdy(rtex);
-
- float w = gcu_Weight;
- float pd = ((2.0 - (2.0*w))*rtex.x*rtex.x) + 2.0*(w-1.0)*rtex.x + 1.0;
- float position = rtex.y - ((w*rtex.x*(1.0 - rtex.x))/pd);
-
- float aph = 2.0 - 2.0*w;
-
- float gd = (aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0)*(aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0);
- vec2 f = vec2((dtx.y - (w*dtx.x*(1.0 - 2.0*rtex.x))/gd), (dty.y - (w*dty.x*(1.0 - 2.0*rtex.x))/gd));
-
- // FIXME: will we ever set gcu_Alpha != 1.0 ? If not, a==alpha!
- float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0);
- alpha = gcu_Alpha * a;
- }
- }
-
- gl_FragColor = vec4(c, alpha);
-}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl index 5bbd5de14..cd014b732 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl @@ -2,21 +2,20 @@ #ifndef uniforms_glsl #define uniforms_glsl -uniform mat4 gcu_PMVMatrix[3]; // P, Mv, and Mvi -uniform vec3 gcu_ColorStatic; -uniform float gcu_Alpha; +uniform mat4 gcu_PMVMatrix01[3]; // P, Mv, and Mvi +uniform vec4 gcu_ColorStatic; uniform float gcu_Weight; -uniform sampler2D gcu_TextureUnit; -// #if __VERSION__ < 130 -uniform vec2 gcu_TextureSize; -// #endif +#ifdef USE_COLOR_TEXTURE + uniform vec4 gcu_ColorTexBBox; +#endif -// const int MAX_TEXTURE_UNITS = 8; // <= gl_MaxTextureImageUnits -// const int MAX_LIGHTS = 8; -// uniform mat3 gcu_NormalMatrix; // transpose(inverse(ModelView)).3x3 -// uniform int gcu_ColorEnabled; -// uniform int gcu_TexCoordEnabled[MAX_TEXTURE_UNITS]; -// uniform int gcu_CullFace; +uniform mat4 gcu_PMVMatrix02[3]; // P, Mv, and Mvi +uniform sampler2D gcu_FboTexUnit; + +/** + * .x .y : texture-, fbo- or screen-size + */ +uniform vec2 gcu_FboTexSize; #endif // uniforms_glsl diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl index 7a9bc5a07..265ab6915 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl @@ -2,8 +2,17 @@ #ifndef varyings_glsl #define varyings_glsl -//varying vec4 gcv_FrontColor; -varying vec2 gcv_TexCoord; +varying vec3 gcv_CurveParam; + +varying vec2 gcv_FboTexCoord; + +#ifdef USE_COLOR_TEXTURE + varying vec2 gcv_ColorTexCoord; +#endif + +#ifdef USE_COLOR_CHANNEL + varying vec4 gcv_Color; +#endif #endif // varyings_glsl diff --git a/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java b/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java index 10b6d6847..4473d040f 100644 --- a/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java +++ b/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java @@ -29,77 +29,85 @@ package jogamp.graph.curve.tess; import java.util.ArrayList; - +import java.util.List; import com.jogamp.graph.curve.tess.Triangulator; import com.jogamp.graph.geom.Outline; import com.jogamp.graph.geom.Triangle; import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.math.VectorUtil; +import com.jogamp.opengl.math.VectorUtil; import jogamp.opengl.Debug; -/** Constrained Delaunay Triangulation +/** + * Constrained Delaunay Triangulation * implementation of a list of Outlines that define a set of * Closed Regions with optional n holes. - * */ -public class CDTriangulator2D implements Triangulator{ - - protected static final boolean DEBUG = Debug.debug("Triangulation"); - - private float sharpness = 0.5f; - private ArrayList<Loop> loops; - private ArrayList<Vertex> vertices; - - private ArrayList<Triangle> triangles; - private int maxTriID = 0; - - +public class CDTriangulator2D implements Triangulator { + + protected static final boolean DEBUG = Debug.debug("graph.curve.Triangulation"); + + private static final boolean TEST_LINE_AA = Debug.debug("graph.curve.triangulation.LINE_AA"); + private static final boolean TEST_MARK_LINE = Debug.debug("graph.curve.triangulation.MARK_AA"); + private static final boolean TEST_ENABLED = TEST_LINE_AA || TEST_MARK_LINE; + + private final ArrayList<Loop> loops = new ArrayList<Loop>(); + + private int addedVerticeCount; + private int maxTriID; + + /** Constructor for a new Delaunay triangulator */ public CDTriangulator2D() { reset(); } - - /** Reset the triangulation to initial state - * Clearing cached data - */ - public void reset() { + + @Override + public final void reset() { maxTriID = 0; - vertices = new ArrayList<Vertex>(); - triangles = new ArrayList<Triangle>(3); - loops = new ArrayList<Loop>(); + addedVerticeCount = 0; + loops.clear(); + } + + @Override + public final int getAddedVerticeCount() { + return addedVerticeCount; } - - public void addCurve(Outline polyline) { + + + @Override + public final void addCurve(final List<Triangle> sink, final Outline polyline, final float sharpness) { Loop loop = null; - + if(!loops.isEmpty()) { loop = getContainerLoop(polyline); } - + if(loop == null) { - GraphOutline outline = new GraphOutline(polyline); - GraphOutline innerPoly = extractBoundaryTriangles(outline, false); - vertices.addAll(polyline.getVertices()); + final GraphOutline outline = new GraphOutline(polyline); + final GraphOutline innerPoly = extractBoundaryTriangles(sink, outline, false, sharpness); + // vertices.addAll(polyline.getVertices()); loop = new Loop(innerPoly, VectorUtil.Winding.CCW); loops.add(loop); } else { - GraphOutline outline = new GraphOutline(polyline); - GraphOutline innerPoly = extractBoundaryTriangles(outline, true); - vertices.addAll(innerPoly.getVertices()); + final GraphOutline outline = new GraphOutline(polyline); + final GraphOutline innerPoly = extractBoundaryTriangles(sink, outline, true, sharpness); + // vertices.addAll(innerPoly.getVertices()); loop.addConstraintCurve(innerPoly); } } - - public ArrayList<Triangle> generate() { - for(int i=0;i<loops.size();i++) { - Loop loop = loops.get(i); + + @Override + public final void generate(final List<Triangle> sink) { + final int loopsSize = loops.size(); + for(int i=0;i<loopsSize;i++) { + final Loop loop = loops.get(i); int numTries = 0; int size = loop.computeLoopSize(); while(!loop.isSimplex()){ - Triangle tri = null; + final Triangle tri; if(numTries > size){ tri = loop.cut(false); } @@ -112,90 +120,113 @@ public class CDTriangulator2D implements Triangulator{ numTries = 0; size--; tri.setId(maxTriID++); - triangles.add(tri); + sink.add(tri); if(DEBUG){ - System.err.println(tri); + System.err.println("CDTri.gen["+i+"].0: "+tri); } } if(numTries > size*2){ if(DEBUG){ - System.err.println("Triangulation not complete!"); + System.err.println("CDTri.gen["+i+"].X: Triangulation not complete!"); } break; } } - Triangle tri = loop.cut(true); - if(tri != null) - triangles.add(tri); + final Triangle tri = loop.cut(true); + if(tri != null) { + sink.add(tri); + if(DEBUG){ + System.err.println("CDTri.gen["+i+"].1: "+tri); + } + } + } + if( TEST_ENABLED ) { + final float[] tempV2 = new float[2]; + final CDTriangulator2DExpAddOn addOn = new CDTriangulator2DExpAddOn(); + final int sinkSize = sink.size(); + if( TEST_MARK_LINE ) { + for(int i=0; i<sinkSize; i++) { + final Triangle t0 = sink.get(i); + addOn.markLineInTriangle(t0, tempV2); + } + } else if ( TEST_LINE_AA ){ + for(int i=0; i<sinkSize-1; i+=2) { + final Triangle t0 = sink.get(i); + final Triangle t1 = sink.get(i+1); + /* final float[] rect = */ addOn.processLineAA(i, t0, t1, tempV2); + } + } } - return triangles; } - private GraphOutline extractBoundaryTriangles(GraphOutline outline, boolean hole) { - GraphOutline innerOutline = new GraphOutline(); - ArrayList<GraphVertex> outVertices = outline.getGraphPoint(); - int size = outVertices.size(); + private GraphOutline extractBoundaryTriangles(final List<Triangle> sink, final GraphOutline outline, final boolean hole, final float sharpness) { + final GraphOutline innerOutline = new GraphOutline(); + final ArrayList<GraphVertex> outVertices = outline.getGraphPoint(); + final int size = outVertices.size(); for(int i=0; i < size; i++) { - GraphVertex currentVertex = outVertices.get(i); - GraphVertex gv0 = outVertices.get((i+size-1)%size); - GraphVertex gv2 = outVertices.get((i+1)%size); - GraphVertex gv1 = currentVertex; - - if(!currentVertex.getPoint().isOnCurve()) { - Vertex v0 = gv0.getPoint().clone(); - Vertex v2 = gv2.getPoint().clone(); - Vertex v1 = gv1.getPoint().clone(); - + final GraphVertex gv1 = outVertices.get(i); // currentVertex + final GraphVertex gv0 = outVertices.get((i+size-1)%size); // -1 + final GraphVertex gv2 = outVertices.get((i+1)%size); // +1 + + if( !gv1.getPoint().isOnCurve() ) { + final Vertex v0 = gv0.getPoint().clone(); + final Vertex v2 = gv2.getPoint().clone(); + final Vertex v1 = gv1.getPoint().clone(); + addedVerticeCount += 3; + final boolean[] boundaryVertices = { true, true, true }; + gv0.setBoundaryContained(true); gv1.setBoundaryContained(true); gv2.setBoundaryContained(true); - + final Triangle t; final boolean holeLike; if(VectorUtil.ccw(v0,v1,v2)) { holeLike = false; - t = new Triangle(v0, v1, v2); + t = new Triangle(v0, v1, v2, boundaryVertices); } else { holeLike = true; - t = new Triangle(v2, v1, v0); + t = new Triangle(v2, v1, v0, boundaryVertices); } t.setId(maxTriID++); - triangles.add(t); + sink.add(t); if(DEBUG){ System.err.println(t); } if( hole || holeLike ) { - v0.setTexCoord(0, -0.1f); - v2.setTexCoord(1, -0.1f); - v1.setTexCoord(0.5f, -1*sharpness -0.1f); - innerOutline.addVertex(currentVertex); + v0.setTexCoord(0.0f, -0.1f, 0f); + v2.setTexCoord(1.0f, -0.1f, 0f); + v1.setTexCoord(0.5f, -sharpness-0.1f, 0f); + innerOutline.addVertex(gv1); } else { - v0.setTexCoord(0, 0.1f); - v2.setTexCoord(1, 0.1f); - v1.setTexCoord(0.5f, sharpness+0.1f); + v0.setTexCoord(0.0f, 0.1f, 0f); + v2.setTexCoord(1.0f, 0.1f, 0f); + v1.setTexCoord(0.5f, sharpness+0.1f, 0f); } - } - else { - if(!gv2.getPoint().isOnCurve() || !gv0.getPoint().isOnCurve()){ - currentVertex.setBoundaryContained(true); + if(DEBUG) { + System.err.println("CDTri.ebt["+i+"].0: hole "+(hole || holeLike)+" "+gv1+", "+t); + } + } else { + if( !gv2.getPoint().isOnCurve() || !gv0.getPoint().isOnCurve() ) { + gv1.setBoundaryContained(true); + } + innerOutline.addVertex(gv1); + if(DEBUG) { + System.err.println("CDTri.ebt["+i+"].1: "+gv1); } - innerOutline.addVertex(currentVertex); } } return innerOutline; } - - private Loop getContainerLoop(Outline polyline) { - ArrayList<Vertex> vertices = polyline.getVertices(); + + private Loop getContainerLoop(final Outline polyline) { + final ArrayList<Vertex> vertices = polyline.getVertices(); for(int i=0; i < loops.size(); i++) { - Loop loop = loops.get(i); - boolean inside = false; + final Loop loop = loops.get(i); for(int j=0; j < vertices.size(); j++) { - Vertex v = vertices.get(j); - inside |= loop.checkInside(v); - } - if(inside) { - return loop; + if( loop.checkInside( vertices.get(j) ) ) { + return loop; + } } } return null; diff --git a/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2DExpAddOn.java b/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2DExpAddOn.java new file mode 100644 index 000000000..a836e2023 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2DExpAddOn.java @@ -0,0 +1,340 @@ +/** + * Copyright 2014 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package jogamp.graph.curve.tess; + +import com.jogamp.graph.geom.Triangle; +import com.jogamp.graph.geom.Vertex; +import com.jogamp.opengl.math.FloatUtil; +import com.jogamp.opengl.math.VectorUtil; + +/** + * Experimental Add-On .. + * + * Disabled by default + */ +public class CDTriangulator2DExpAddOn { + + private final float[] tempV3a = new float[3]; + private final float[] tempV3b = new float[3]; + + protected final void markLineInTriangle(final Triangle tri1, final float[] tempV2) { + if( !tri1.isOnCurve() || !tri1.isLine() ) { + return; + } + + final boolean[] boundVs = tri1.getVerticesBoundary(); + final Vertex[] triVs = tri1.getVertices(); + final Vertex v0 = triVs[0]; + final Vertex v1 = triVs[1]; + final Vertex v2 = triVs[2]; + + int lineSegCount = 0; + final boolean v0IsLS, v1IsLS, v2IsLS; + if( v0.isOnCurve() && VectorUtil.isVec2Zero(v0.getTexCoord(), 0) && !boundVs[0] ) { + v0IsLS = true; + lineSegCount++; + } else { + v0IsLS = false; + } + if( v1.isOnCurve() && VectorUtil.isVec2Zero(v1.getTexCoord(), 0) && !boundVs[1] ) { + v1IsLS = true; + lineSegCount++; + } else { + v1IsLS = false; + } + if( v2.isOnCurve() && VectorUtil.isVec2Zero(v2.getTexCoord(), 0) && !boundVs[2] ) { + v2IsLS = true; + lineSegCount++; + } else { + v2IsLS = false; + } + if( 2 > lineSegCount ) { + return; + } else { + if(CDTriangulator2D.DEBUG) { + System.err.println("CDTri.markLine.1: "+tri1); + System.err.println("CDTri.markLine.1: count "+lineSegCount+", v0IsLS "+v0IsLS+", v1IsLS "+v1IsLS+", v2IsLS "+v2IsLS); + } + final float texZTag = 2f; + if( true ) { + if( v0IsLS ) { + v0.setTexCoord(0f, 0f, texZTag); + } + if( v1IsLS ) { + v1.setTexCoord(0f, 0f, texZTag); + } + if( v2IsLS ) { + v2.setTexCoord(0f, 0f, texZTag); + } + } else { + if( v0IsLS ) { + final Vertex v = v0.clone(); + v.setTexCoord(0f, 0f, texZTag); + triVs[0] = v; + } + if( v1IsLS ) { + final Vertex v = v1.clone(); + v.setTexCoord(0f, 0f, texZTag); + triVs[1] = v; + } + if( v2IsLS ) { + final Vertex v = v2.clone(); + v.setTexCoord(0f, 0f, texZTag); + triVs[2] = v; + } + } + if ( false ) { + final Vertex vL1, vL2, vL3, vO; + if( 3 == lineSegCount ) { + vL1 = v0; vL2=v1; vL3=v2; vO=null; + } else if( v0IsLS && v1IsLS ) { + vL1 = v0; vL2=v1; vL3=null; vO=v2; + } else if( v0IsLS && v2IsLS ) { + vL1 = v0; vL2=v2; vL3=null; vO=v1; + } else if( v1IsLS && v2IsLS ) { + vL1 = v1; vL2=v2; vL3=null; vO=v0; + } else { + return; // unreachable + } + if( null != vL1 ) { + vL1.setTexCoord(texZTag, 0f, 0f); + } + if( null != vL2 ) { + vL2.setTexCoord(texZTag, 0f, 0f); + } + if( null != vL3 ) { + vL3.setTexCoord(texZTag, 0f, 0f); + } + } + } + } + + /** + * If this and the other triangle compose a rectangle return the + * given <code>tempV2</code> array w/ shortest side first. + * Otherwise return null; + * <p> + * Experimental CODE, enabled only if {@link #TEST_LINE_AA} is set .. WIP + * </p> + * <p> + One test uses method: ROESSLER-2012-OGLES <http://www.cg.tuwien.ac.at/research/publications/2012/ROESSLER-2012-OGLES/> + * </p> + * <p> + * However, we would need to tesselate all lines appropriately, + * i.e. create 2 triangles sharing the middle actual line using thickness+radius. + * + * This test simply used our default font w/ a line thickness of 2 pixels, + * which produced mentioned rectangles. + * This is of course not the case for arbitrary Outline shapes. + * </p> + * @param tri2 + * @param checkThisOnCurve + * @param tempV2 temp float[2] storage + */ + protected final float[] processLineAA(final int i, final Triangle tri1, final Triangle tri2, final float[] tempV2) { + if(CDTriangulator2D.DEBUG){ + System.err.println("CDTri.genP2["+i+"].1: ? t1 "+tri1); + System.err.println("CDTri.genP2["+i+"].1: ? t2 "+tri2); + } + final float[] rect = processLineAAImpl(tri1, tri2, tempV2); + if(CDTriangulator2D.DEBUG){ + if( null != rect ) { + System.err.println("CDTri.genP2["+i+"].1: RECT ["+rect[0]+", "+rect[1]+"]"); + System.err.println("CDTri.genP2["+i+"].1: RECT t1 "+tri1); + System.err.println("CDTri.genP2["+i+"].1: RECT t2 "+tri2); + } else { + System.err.println("CDTri.genP2["+i+"].1: RECT NOPE, t1 "+tri1); + System.err.println("CDTri.genP2["+i+"].1: RECT NOPE, t2 "+tri2); + } + } + return rect; + } + private final float[] processLineAAImpl(final Triangle tri1, final Triangle tri2, final float[] tempV2) { + if( !tri1.isOnCurve() || !tri2.isOnCurve() || !tri1.isLine() || !tri2.isLine() ) { + return null; + } + final float[] rect; + int eqCount = 0; + final int[] commonIdxA = { -1, -1 }; + final int[] commonIdxB = { -1, -1 }; + final Vertex[] verts1 = tri1.getVertices(); + final Vertex[] verts2 = tri2.getVertices(); + float[] coord = verts1[0].getCoord(); + if( VectorUtil.isVec3Equal(coord, 0, verts2[0].getCoord(), 0, FloatUtil.EPSILON) ) { + commonIdxA[eqCount] = 0; + commonIdxB[eqCount] = 0; + eqCount++; + } else if( VectorUtil.isVec3Equal(coord, 0, verts2[1].getCoord(), 0, FloatUtil.EPSILON) ) { + commonIdxA[eqCount] = 0; + commonIdxB[eqCount] = 1; + eqCount++; + } else if( VectorUtil.isVec3Equal(coord, 0, verts2[2].getCoord(), 0, FloatUtil.EPSILON) ) { + commonIdxA[eqCount] = 0; + commonIdxB[eqCount] = 2; + eqCount++; + } + coord = verts1[1].getCoord(); + if( VectorUtil.isVec3Equal(coord, 0, verts2[0].getCoord(), 0, FloatUtil.EPSILON) ) { + commonIdxA[eqCount] = 1; + commonIdxB[eqCount] = 0; + eqCount++; + } else if( VectorUtil.isVec3Equal(coord, 0, verts2[1].getCoord(), 0, FloatUtil.EPSILON) ) { + commonIdxA[eqCount] = 1; + commonIdxB[eqCount] = 1; + eqCount++; + } else if( VectorUtil.isVec3Equal(coord, 0, verts2[2].getCoord(), 0, FloatUtil.EPSILON) ) { + commonIdxA[eqCount] = 1; + commonIdxB[eqCount] = 2; + eqCount++; + } + final int otherIdxA; + if( 2 == eqCount ) { + otherIdxA = 3 - ( commonIdxA[0] + commonIdxA[1] ); + } else { + coord = verts1[2].getCoord(); + if( VectorUtil.isVec3Equal(coord, 0, verts2[0].getCoord(), 0, FloatUtil.EPSILON) ) { + commonIdxA[eqCount] = 2; + commonIdxB[eqCount] = 0; + eqCount++; + } else if( VectorUtil.isVec3Equal(coord, 0, verts2[1].getCoord(), 0, FloatUtil.EPSILON) ) { + commonIdxA[eqCount] = 2; + commonIdxB[eqCount] = 1; + eqCount++; + } else if( VectorUtil.isVec3Equal(coord, 0, verts2[2].getCoord(), 0, FloatUtil.EPSILON) ) { + commonIdxA[eqCount] = 2; + commonIdxB[eqCount] = 2; + eqCount++; + } + if( 2 == eqCount ) { + otherIdxA = 3 - ( commonIdxA[0] + commonIdxA[1] ); + } else { + otherIdxA = -1; + } + } + if( 0 <= otherIdxA && commonIdxB[0] != commonIdxB[1] ) { + final int otherIdxB = 3 - ( commonIdxB[0] + commonIdxB[1] ); + // Reference must be equal, i.e. sharing the actual same vertices! + if( verts1[commonIdxA[0]] != verts2[commonIdxB[0]] || verts1[commonIdxA[1]] != verts2[commonIdxB[1]] ) { + throw new InternalError("XXX: diff shared verts"); // FIXME remove when clear + } + final Vertex vC0A, vC1A, vOA, vOB; + if( false ) { + // Fetch only! + vC0A = verts1[commonIdxA[0]]; + vC1A = verts1[commonIdxA[1]]; + vOA = verts1[otherIdxA]; + vOB = verts2[otherIdxB]; + } else { + // Fetch and clone, write-back to triangles + vC0A = verts1[commonIdxA[0]].clone(); + verts1[commonIdxA[0]] = vC0A; + verts2[commonIdxB[0]] = vC0A; + vC1A = verts1[commonIdxA[1]].clone(); + verts1[commonIdxA[1]] = vC1A; + verts2[commonIdxB[1]] = vC1A; + vOA = verts1[otherIdxA].clone(); + verts1[otherIdxA] = vOA; + vOB = verts2[otherIdxB].clone(); + verts2[otherIdxB] = vOB; + } + + final float texZTag = 2f; + final float[] vOACoords = vOA.getCoord(); + final float dOC0A = VectorUtil.distVec3(vOACoords, vC0A.getCoord()); + final float dOC1A = VectorUtil.distVec3(vOACoords, vC1A.getCoord()); + if( false ) { + final float[] vec3Z = { 0f, 0f, -1f }; + final float[] vecLongSide, vecLineHeight; + if( dOC0A < dOC1A ) { + tempV2[0] = dOC0A; // line width + tempV2[1] = dOC1A; // long side + vecLongSide = VectorUtil.normalizeVec3( VectorUtil.subVec2(tempV3a, vOACoords, vC1A.getCoord()) ); // normal long side vector + vecLineHeight = VectorUtil.crossVec3(tempV3b, vec3Z, tempV3a); // the line-height vector (normal) + vOA.setTexCoord(-1f, -1f, texZTag); + vC1A.setTexCoord(1f, -1f, texZTag); + vOB.setTexCoord(0f, 1f, texZTag); + vC0A.setTexCoord(0f, 1f, texZTag); + } else { + tempV2[0] = dOC1A; // line width + tempV2[1] = dOC0A; // long side + vecLongSide = VectorUtil.normalizeVec3( VectorUtil.subVec2(tempV3a, vOACoords, vC0A.getCoord()) ); // normal long side vector + vecLineHeight = VectorUtil.crossVec3(tempV3b, vec3Z, tempV3a); // the line-height vector (normal) + } + if(CDTriangulator2D.DEBUG){ + System.err.println("RECT.0 : long-side-vec "+vecLongSide[0]+", "+vecLongSide[1]+", "+vecLongSide[2]); + System.err.println("RECT.0 : line-height-vec "+vecLineHeight[0]+", "+vecLineHeight[1]+", "+vecLineHeight[2]); + } + + } else { + /** + * Using method: ROESSLER-2012-OGLES <http://www.cg.tuwien.ac.at/research/publications/2012/ROESSLER-2012-OGLES/> + * + * Arbitrary but consistently pick left/right and set texCoords, FIXME: validate + * + * Testing w/ fixed line-width 1, and radius 1/3. + */ + final float lineWidth; + final Vertex vL1, vL2, vR1, vR2; + if( dOC0A < dOC1A ) { + lineWidth = dOC0A; // line width + tempV2[0] = dOC0A; // line width + tempV2[1] = dOC1A; // long side + // Left: vOA, vC1A + // Right: vOB, vC0A + vL1 = vOA; vL2 = vC1A; + vR1 = vOB; vR2 = vC0A; + } else { + lineWidth = dOC1A; // line width + tempV2[0] = dOC1A; // line width + tempV2[1] = dOC0A; // long side + // Left: vOB, vC1A + // Right: vOA, vC0A + vL1 = vOB; vL2 = vC1A; + vR1 = vOA; vR2 = vC0A; + } + final float r = lineWidth/3f; + final float wa = lineWidth + r; + final float waHalf = wa / 2f; + vL1.setTexCoord(lineWidth, waHalf, texZTag); + vL2.setTexCoord(lineWidth, waHalf, texZTag); + vR1.setTexCoord(lineWidth, -waHalf, texZTag); + vR2.setTexCoord(lineWidth, -waHalf, texZTag); + if(CDTriangulator2D.DEBUG){ + System.err.println("RECT.0 : lineWidth: "+lineWidth+", dim "+dOC0A+" x "+dOC1A+", radius "+r); + System.err.println("RECT Left.0: "+vL1+", "+vL2); + System.err.println("RECT Right.0: "+vR1+", "+vR2); + } + } + rect = tempV2; + } else { + rect = null; + } + return rect; + } +} diff --git a/src/jogl/classes/jogamp/graph/curve/tess/GraphOutline.java b/src/jogl/classes/jogamp/graph/curve/tess/GraphOutline.java index c8251af15..81e6efdad 100644 --- a/src/jogl/classes/jogamp/graph/curve/tess/GraphOutline.java +++ b/src/jogl/classes/jogamp/graph/curve/tess/GraphOutline.java @@ -35,18 +35,18 @@ import com.jogamp.graph.geom.Vertex; public class GraphOutline { final private Outline outline; final private ArrayList<GraphVertex> controlpoints = new ArrayList<GraphVertex>(3); - + public GraphOutline(){ this.outline = new Outline(); } - + /**Create a control polyline of control vertices - * the curve pieces can be identified by onCurve flag + * the curve pieces can be identified by onCurve flag * of each cp the control polyline is open by default */ - public GraphOutline(Outline ol){ + public GraphOutline(final Outline ol){ this.outline = ol; - ArrayList<Vertex> vertices = this.outline.getVertices(); + final ArrayList<Vertex> vertices = this.outline.getVertices(); for(int i = 0; i< vertices.size(); i++){ this.controlpoints.add(new GraphVertex(vertices.get(i))); } @@ -59,14 +59,14 @@ public class GraphOutline { public ArrayList<GraphVertex> getGraphPoint() { return controlpoints; } - + public ArrayList<Vertex> getVertices() { return outline.getVertices(); } - public void addVertex(GraphVertex v) { + public void addVertex(final GraphVertex v) { controlpoints.add(v); outline.addVertex(v.getPoint()); } - + } diff --git a/src/jogl/classes/jogamp/graph/curve/tess/GraphVertex.java b/src/jogl/classes/jogamp/graph/curve/tess/GraphVertex.java index 52d02baa5..391e71011 100644 --- a/src/jogl/classes/jogamp/graph/curve/tess/GraphVertex.java +++ b/src/jogl/classes/jogamp/graph/curve/tess/GraphVertex.java @@ -35,23 +35,23 @@ public class GraphVertex { private Vertex point; private ArrayList<HEdge> edges = null; private boolean boundaryContained = false; - - public GraphVertex(Vertex point) { + + public GraphVertex(final Vertex point) { this.point = point; } public Vertex getPoint() { return point; } - + public float getX(){ return point.getX(); } - + public float getY(){ return point.getY(); } - + public float getZ(){ return point.getZ(); } @@ -59,7 +59,7 @@ public class GraphVertex { return point.getCoord(); } - public void setPoint(Vertex point) { + public void setPoint(final Vertex point) { this.point = point; } @@ -67,17 +67,17 @@ public class GraphVertex { return edges; } - public void setEdges(ArrayList<HEdge> edges) { + public void setEdges(final ArrayList<HEdge> edges) { this.edges = edges; } - - public void addEdge(HEdge edge){ + + public void addEdge(final HEdge edge){ if(edges == null){ edges = new ArrayList<HEdge>(); } edges.add(edge); } - public void removeEdge(HEdge edge){ + public void removeEdge(final HEdge edge){ if(edges == null) return; edges.remove(edge); @@ -85,9 +85,9 @@ public class GraphVertex { edges = null; } } - public HEdge findNextEdge(GraphVertex nextVert){ + public HEdge findNextEdge(final GraphVertex nextVert){ for(int i=0; i<edges.size(); i++) { - HEdge e = edges.get(i); + final HEdge e = edges.get(i); if(e.getNext().getGraphPoint() == nextVert){ return e; } @@ -96,28 +96,32 @@ public class GraphVertex { } public HEdge findBoundEdge(){ for(int i=0; i<edges.size(); i++) { - HEdge e = edges.get(i); + final HEdge e = edges.get(i); if((e.getType() == HEdge.BOUNDARY) || (e.getType() == HEdge.HOLE)){ return e; } } return null; } - public HEdge findPrevEdge(GraphVertex prevVert){ + public HEdge findPrevEdge(final GraphVertex prevVert){ for(int i=0; i<edges.size(); i++) { - HEdge e = edges.get(i); + final HEdge e = edges.get(i); if(e.getPrev().getGraphPoint() == prevVert){ return e; } } return null; } - + public boolean isBoundaryContained() { return boundaryContained; } - public void setBoundaryContained(boolean boundaryContained) { + public void setBoundaryContained(final boolean boundaryContained) { this.boundaryContained = boundaryContained; } + + public String toString() { + return "GraphVertex[contained "+boundaryContained+", "+point+"]"; + } } diff --git a/src/jogl/classes/jogamp/graph/curve/tess/HEdge.java b/src/jogl/classes/jogamp/graph/curve/tess/HEdge.java index 4d29a81f3..4976fd1fc 100644 --- a/src/jogl/classes/jogamp/graph/curve/tess/HEdge.java +++ b/src/jogl/classes/jogamp/graph/curve/tess/HEdge.java @@ -32,23 +32,23 @@ import com.jogamp.graph.geom.Triangle; public class HEdge { - public static int BOUNDARY = 3; - public static int INNER = 1; - public static int HOLE = 2; - + public static final int BOUNDARY = 3; + public static final int INNER = 1; + public static final int HOLE = 2; + private GraphVertex vert; private HEdge prev = null; private HEdge next = null; private HEdge sibling = null; private int type = BOUNDARY; private Triangle triangle = null; - - public HEdge(GraphVertex vert, int type) { + + public HEdge(final GraphVertex vert, final int type) { this.vert = vert; this.type = type; } - public HEdge(GraphVertex vert, HEdge prev, HEdge next, HEdge sibling, int type) { + public HEdge(final GraphVertex vert, final HEdge prev, final HEdge next, final HEdge sibling, final int type) { this.vert = vert; this.prev = prev; this.next = next; @@ -56,7 +56,7 @@ public class HEdge { this.type = type; } - public HEdge(GraphVertex vert, HEdge prev, HEdge next, HEdge sibling, int type, Triangle triangle) { + public HEdge(final GraphVertex vert, final HEdge prev, final HEdge next, final HEdge sibling, final int type, final Triangle triangle) { this.vert = vert; this.prev = prev; this.next = next; @@ -69,7 +69,7 @@ public class HEdge { return vert; } - public void setVert(GraphVertex vert) { + public void setVert(final GraphVertex vert) { this.vert = vert; } @@ -77,7 +77,7 @@ public class HEdge { return prev; } - public void setPrev(HEdge prev) { + public void setPrev(final HEdge prev) { this.prev = prev; } @@ -85,7 +85,7 @@ public class HEdge { return next; } - public void setNext(HEdge next) { + public void setNext(final HEdge next) { this.next = next; } @@ -93,7 +93,7 @@ public class HEdge { return sibling; } - public void setSibling(HEdge sibling) { + public void setSibling(final HEdge sibling) { this.sibling = sibling; } @@ -101,7 +101,7 @@ public class HEdge { return type; } - public void setType(int type) { + public void setType(final int type) { this.type = type; } @@ -109,22 +109,22 @@ public class HEdge { return triangle; } - public void setTriangle(Triangle triangle) { + public void setTriangle(final Triangle triangle) { this.triangle = triangle; } - - public static <T extends Vertex> void connect(HEdge first, HEdge next){ + + public static <T extends Vertex> void connect(final HEdge first, final HEdge next){ first.setNext(next); next.setPrev(first); } - - public static <T extends Vertex> void makeSiblings(HEdge first, HEdge second){ + + public static <T extends Vertex> void makeSiblings(final HEdge first, final HEdge second){ first.setSibling(second); second.setSibling(first); } - + public boolean vertexOnCurveVertex(){ return vert.getPoint().isOnCurve(); } - + } diff --git a/src/jogl/classes/jogamp/graph/curve/tess/Loop.java b/src/jogl/classes/jogamp/graph/curve/tess/Loop.java index b4b796b51..6563219cc 100644 --- a/src/jogl/classes/jogamp/graph/curve/tess/Loop.java +++ b/src/jogl/classes/jogamp/graph/curve/tess/Loop.java @@ -30,17 +30,17 @@ package jogamp.graph.curve.tess; import java.util.ArrayList; -import com.jogamp.graph.geom.AABBox; import com.jogamp.graph.geom.Vertex; import com.jogamp.graph.geom.Triangle; -import com.jogamp.graph.math.VectorUtil; +import com.jogamp.opengl.math.VectorUtil; +import com.jogamp.opengl.math.geom.AABBox; public class Loop { private HEdge root = null; - private AABBox box = new AABBox(); + private final AABBox box = new AABBox(); private GraphOutline initialOutline = null; - public Loop(GraphOutline polyline, VectorUtil.Winding winding){ + public Loop(final GraphOutline polyline, final VectorUtil.Winding winding){ initialOutline = polyline; this.root = initFromPolyline(initialOutline, winding); } @@ -49,27 +49,25 @@ public class Loop { return root; } - public Triangle cut(boolean delaunay){ + public Triangle cut(final boolean delaunay){ if(isSimplex()){ - Triangle t = new Triangle(root.getGraphPoint().getPoint(), root.getNext().getGraphPoint().getPoint(), - root.getNext().getNext().getGraphPoint().getPoint()); - t.setVerticesBoundary(checkVerticesBoundary(root)); - return t; + return new Triangle(root.getGraphPoint().getPoint(), root.getNext().getGraphPoint().getPoint(), + root.getNext().getNext().getGraphPoint().getPoint(), checkVerticesBoundary(root)); } - HEdge prev = root.getPrev(); - HEdge next1 = root.getNext(); + final HEdge prev = root.getPrev(); + final HEdge next1 = root.getNext(); - HEdge next2 = findClosestValidNeighbor(next1.getNext(), delaunay); + final HEdge next2 = findClosestValidNeighbor(next1.getNext(), delaunay); if(next2 == null){ root = root.getNext(); return null; } - GraphVertex v1 = root.getGraphPoint(); - GraphVertex v2 = next1.getGraphPoint(); - GraphVertex v3 = next2.getGraphPoint(); + final GraphVertex v1 = root.getGraphPoint(); + final GraphVertex v2 = next1.getGraphPoint(); + final GraphVertex v3 = next2.getGraphPoint(); - HEdge v3Edge = new HEdge(v3, HEdge.INNER); + final HEdge v3Edge = new HEdge(v3, HEdge.INNER); HEdge.connect(v3Edge, root); HEdge.connect(next1, v3Edge); @@ -83,7 +81,7 @@ public class Loop { HEdge.connect(prev, v3EdgeSib); HEdge.connect(v3EdgeSib, next2); - Triangle t = createTriangle(v1.getPoint(), v2.getPoint(), v3.getPoint(), root); + final Triangle t = createTriangle(v1.getPoint(), v2.getPoint(), v3.getPoint(), root); this.root = next2; return t; } @@ -96,27 +94,27 @@ public class Loop { * from the boundary profile * @param reqWinding requested winding of edges (CCW or CW) */ - private HEdge initFromPolyline(GraphOutline outline, VectorUtil.Winding reqWinding){ - ArrayList<GraphVertex> vertices = outline.getGraphPoint(); + private HEdge initFromPolyline(final GraphOutline outline, final VectorUtil.Winding reqWinding){ + final ArrayList<GraphVertex> vertices = outline.getGraphPoint(); if(vertices.size()<3) { throw new IllegalArgumentException("outline's vertices < 3: " + vertices.size()); } final VectorUtil.Winding hasWinding = VectorUtil.getWinding( - vertices.get(0).getPoint(), + vertices.get(0).getPoint(), vertices.get(1).getPoint(), vertices.get(2).getPoint()); //FIXME: handle case when vertices come inverted - Rami // skips inversion CW -> CCW final boolean invert = hasWinding != reqWinding && reqWinding == VectorUtil.Winding.CW; - + final int max; final int edgeType = reqWinding == VectorUtil.Winding.CCW ? HEdge.BOUNDARY : HEdge.HOLE ; int index; HEdge firstEdge = null; HEdge lastEdge = null; - + if(!invert) { max = vertices.size(); index = 0; @@ -126,10 +124,10 @@ public class Loop { } while(index != max){ - GraphVertex v1 = vertices.get(index); + final GraphVertex v1 = vertices.get(index); box.resize(v1.getX(), v1.getY(), v1.getZ()); - HEdge edge = new HEdge(v1, edgeType); + final HEdge edge = new HEdge(v1, edgeType); v1.addEdge(edge); if(lastEdge != null) { @@ -157,15 +155,15 @@ public class Loop { return firstEdge; } - public void addConstraintCurve(GraphOutline polyline) { + public void addConstraintCurve(final GraphOutline polyline) { // GraphOutline outline = new GraphOutline(polyline); /**needed to generate vertex references.*/ - initFromPolyline(polyline, VectorUtil.Winding.CW); + initFromPolyline(polyline, VectorUtil.Winding.CW); - GraphVertex v3 = locateClosestVertex(polyline); - HEdge v3Edge = v3.findBoundEdge(); - HEdge v3EdgeP = v3Edge.getPrev(); - HEdge crossEdge = new HEdge(root.getGraphPoint(), HEdge.INNER); + final GraphVertex v3 = locateClosestVertex(polyline); + final HEdge v3Edge = v3.findBoundEdge(); + final HEdge v3EdgeP = v3Edge.getPrev(); + final HEdge crossEdge = new HEdge(root.getGraphPoint(), HEdge.INNER); HEdge.connect(root.getPrev(), crossEdge); HEdge.connect(crossEdge, v3Edge); @@ -180,32 +178,32 @@ public class Loop { HEdge.connect(crossEdgeSib, root); } - /** Locates the vertex and update the loops root - * to have (root + vertex) as closest pair - * @param polyline the control polyline + /** Locates the vertex and update the loops root + * to have (root + vertex) as closest pair + * @param polyline the control polyline * to search for closestvertices * @return the vertex that is closest to the newly set root Hedge. */ - private GraphVertex locateClosestVertex(GraphOutline polyline) { + private GraphVertex locateClosestVertex(final GraphOutline polyline) { HEdge closestE = null; GraphVertex closestV = null; float minDistance = Float.MAX_VALUE; boolean inValid = false; - ArrayList<GraphVertex> initVertices = initialOutline.getGraphPoint(); - ArrayList<GraphVertex> vertices = polyline.getGraphPoint(); + final ArrayList<GraphVertex> initVertices = initialOutline.getGraphPoint(); + final ArrayList<GraphVertex> vertices = polyline.getGraphPoint(); for(int i=0; i< initVertices.size()-1; i++){ - GraphVertex v = initVertices.get(i); - GraphVertex nextV = initVertices.get(i+1); + final GraphVertex v = initVertices.get(i); + final GraphVertex nextV = initVertices.get(i+1); for(int pos=0; pos<vertices.size(); pos++) { - GraphVertex cand = vertices.get(pos); - float distance = VectorUtil.computeLength(v.getCoord(), cand.getCoord()); + final GraphVertex cand = vertices.get(pos); + final float distance = VectorUtil.distVec3(v.getCoord(), cand.getCoord()); if(distance < minDistance){ - for (GraphVertex vert:vertices){ + for (final GraphVertex vert:vertices){ if(vert == v || vert == nextV || vert == cand) continue; - inValid = VectorUtil.inCircle(v.getPoint(), nextV.getPoint(), + inValid = VectorUtil.isInCircleVec2(v.getPoint(), nextV.getPoint(), cand.getPoint(), vert.getPoint()); if(inValid){ break; @@ -228,29 +226,29 @@ public class Loop { return closestV; } - private HEdge findClosestValidNeighbor(HEdge edge, boolean delaunay) { - HEdge next = root.getNext(); + private HEdge findClosestValidNeighbor(final HEdge edge, final boolean delaunay) { + final HEdge next = root.getNext(); if(!VectorUtil.ccw(root.getGraphPoint().getPoint(), next.getGraphPoint().getPoint(), edge.getGraphPoint().getPoint())){ return null; } - HEdge candEdge = edge; + final HEdge candEdge = edge; boolean inValid = false; if(delaunay){ - Vertex cand = candEdge.getGraphPoint().getPoint(); + final Vertex cand = candEdge.getGraphPoint().getPoint(); HEdge e = candEdge.getNext(); while (e != candEdge){ - if(e.getGraphPoint() == root.getGraphPoint() - || e.getGraphPoint() == next.getGraphPoint() + if(e.getGraphPoint() == root.getGraphPoint() + || e.getGraphPoint() == next.getGraphPoint() || e.getGraphPoint().getPoint() == cand){ e = e.getNext(); continue; } - inValid = VectorUtil.inCircle(root.getGraphPoint().getPoint(), next.getGraphPoint().getPoint(), - cand, e.getGraphPoint().getPoint()); + inValid = VectorUtil.isInCircleVec2(root.getGraphPoint().getPoint(), next.getGraphPoint().getPoint(), + cand, e.getGraphPoint().getPoint()); if(inValid){ break; } @@ -271,31 +269,25 @@ public class Loop { * @param root and edge of this triangle * @return the triangle iff it satisfies, null otherwise */ - private Triangle createTriangle(Vertex v1, Vertex v2, Vertex v3, HEdge rootT){ - Triangle t = new Triangle(v1, v2, v3); - t.setVerticesBoundary(checkVerticesBoundary(rootT)); - return t; + private Triangle createTriangle(final Vertex v1, final Vertex v2, final Vertex v3, final HEdge rootT){ + return new Triangle(v1, v2, v3, checkVerticesBoundary(rootT)); } - private boolean[] checkVerticesBoundary(HEdge rootT) { - boolean[] boundary = new boolean[3]; - HEdge e1 = rootT; - HEdge e2 = rootT.getNext(); - HEdge e3 = rootT.getNext().getNext(); - - if(e1.getGraphPoint().isBoundaryContained()){ + private boolean[] checkVerticesBoundary(final HEdge rootT) { + final boolean[] boundary = new boolean[3]; + if(rootT.getGraphPoint().isBoundaryContained()){ boundary[0] = true; } - if(e2.getGraphPoint().isBoundaryContained()){ + if(rootT.getNext().getGraphPoint().isBoundaryContained()){ boundary[1] = true; } - if(e3.getGraphPoint().isBoundaryContained()){ + if(rootT.getNext().getNext().getGraphPoint().isBoundaryContained()){ boundary[2] = true; } return boundary; } - public boolean checkInside(Vertex v) { + public boolean checkInside(final Vertex v) { if(!box.contains(v.getX(), v.getY(), v.getZ())){ return false; } @@ -304,22 +296,22 @@ public class Loop { HEdge current = root; HEdge next = root.getNext(); do { - Vertex v2 = current.getGraphPoint().getPoint(); - Vertex v1 = next.getGraphPoint().getPoint(); + final Vertex v2 = current.getGraphPoint().getPoint(); + final Vertex v1 = next.getGraphPoint().getPoint(); if ( ((v1.getY() > v.getY()) != (v2.getY() > v.getY())) && (v.getX() < (v2.getX() - v1.getX()) * (v.getY() - v1.getY()) / (v2.getY() - v1.getY()) + v1.getX()) ){ inside = !inside; } - + current = next; next = current.getNext(); - + } while(current != root); - + return inside; } - + public int computeLoopSize(){ int size = 0; HEdge e = root; diff --git a/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java b/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java deleted file mode 100644 index 578148699..000000000 --- a/src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.curve.text; - -import java.util.ArrayList; - -import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.geom.Triangle; -import com.jogamp.graph.geom.Vertex.Factory; - -import com.jogamp.graph.curve.OutlineShape; -import com.jogamp.graph.math.Quaternion; - -public class GlyphShape { - - private Quaternion quat= null; - private OutlineShape shape = null; - - /** Create a new Glyph shape - * based on Parametric curve control polyline - */ - public GlyphShape(Vertex.Factory<? extends Vertex> factory){ - shape = new OutlineShape(factory); - } - - /** Create a new GlyphShape from a {@link OutlineShape} - * @param factory vertex impl factory {@link Factory} - * @param shape {@link OutlineShape} representation of the Glyph - */ - public GlyphShape(Vertex.Factory<? extends Vertex> factory, OutlineShape shape){ - this(factory); - this.shape = shape; - this.shape.transformOutlines(OutlineShape.VerticesState.QUADRATIC_NURBS); - } - - public final Vertex.Factory<? extends Vertex> vertexFactory() { return shape.vertexFactory(); } - - public OutlineShape getShape() { - return shape; - } - - public int getNumVertices() { - return shape.getVertices().size(); - } - - /** Get the rotational Quaternion attached to this Shape - * @return the Quaternion Object - */ - public Quaternion getQuat() { - return quat; - } - - /** Set the Quaternion that shall defien the rotation - * of this shape. - * @param quat - */ - public void setQuat(Quaternion quat) { - this.quat = quat; - } - - /** Triangluate the glyph shape - * @return ArrayList of triangles which define this shape - */ - public ArrayList<Triangle> triangulate(){ - return shape.triangulate(); - } - - /** Get the list of Vertices of this Object - * @return arrayList of Vertices - */ - public ArrayList<Vertex> getVertices(){ - return shape.getVertices(); - } -} diff --git a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java b/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java deleted file mode 100644 index f86d02f40..000000000 --- a/src/jogl/classes/jogamp/graph/curve/text/GlyphString.java +++ /dev/null @@ -1,213 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.curve.text; - -import java.util.ArrayList; - -import com.jogamp.graph.font.Font; -import com.jogamp.graph.geom.AABBox; -import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.geom.Triangle; -import com.jogamp.graph.geom.Vertex.Factory; -import com.jogamp.graph.geom.opengl.SVertex; - -import javax.media.opengl.GL2ES2; - -import jogamp.graph.curve.opengl.RegionFactory; -import jogamp.graph.font.FontInt; - -import com.jogamp.graph.curve.OutlineShape; -import com.jogamp.graph.curve.Region; -import com.jogamp.graph.curve.opengl.GLRegion; -import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.opengl.util.PMVMatrix; - -public class GlyphString { - /** Static font size for all default font OutlineShape generations via {@link #createString(OutlineShape, Factory, Font, String)}. - * <p>The actual font size shall be accomplished by the GL PMV matrix.</p> - */ - public static final int STATIC_FONT_SIZE = 10; - - private ArrayList<GlyphShape> glyphs = new ArrayList<GlyphShape>(); - private CharSequence str; - private String fontname; - private GLRegion region; - - private SVertex origin = new SVertex(); - - /** - * <p>Uses {@link #STATIC_FONT_SIZE}.</p> - * <p>No caching is performed.</p> - * - * @param shape is not null, add all {@link GlyphShape}'s {@link Outline} to this instance. - * @param vertexFactory vertex impl factory {@link Factory} - * @param font the target {@link Font} - * @param str string text - * @return the created {@link GlyphString} instance - */ - public static GlyphString createString(OutlineShape shape, Factory<? extends Vertex> vertexFactory, Font font, String str) { - return createString(shape, vertexFactory, font, STATIC_FONT_SIZE, str); - } - - /** - * <p>No caching is performed.</p> - * - * @param shape is not null, add all {@link GlyphShape}'s {@link Outline} to this instance. - * @param vertexFactory vertex impl factory {@link Factory} - * @param font the target {@link Font} - * @param fontSize font size - * @param str string text - * @return the created {@link GlyphString} instance - */ - public static GlyphString createString(OutlineShape shape, Factory<? extends Vertex> vertexFactory, Font font, int fontSize, String str) { - ArrayList<OutlineShape> shapes = ((FontInt)font).getOutlineShapes(str, fontSize, vertexFactory); - - GlyphString glyphString = new GlyphString(font.getName(Font.NAME_UNIQUNAME), str); - glyphString.createfromOutlineShapes(vertexFactory, shapes); - if(null != shape) { - for(int i=0; i<glyphString.glyphs.size(); i++) { - shape.addOutlineShape(glyphString.glyphs.get(i).getShape()); - } - } - return glyphString; - } - - /** Create a new GlyphString object - * @param fontname the name of the font that this String is - * associated with - * @param str the string object - */ - public GlyphString(String fontname, CharSequence str){ - this.fontname = fontname; - this.str = str; - } - - public void addGlyphShape(GlyphShape glyph){ - glyphs.add(glyph); - } - - public CharSequence getString(){ - return str; - } - - /**Creates the Curve based Glyphs from a list of {@link OutlineShape} - * @param vertexFactory vertex impl factory {@link Factory} - * @param shapes list of {@link OutlineShape} - */ - public void createfromOutlineShapes(Factory<? extends Vertex> vertexFactory, ArrayList<OutlineShape> shapes) { - final int numGlyps = shapes.size(); - for (int index=0;index<numGlyps;index++){ - if(shapes.get(index) == null){ - continue; - } - GlyphShape glyphShape = new GlyphShape(vertexFactory, shapes.get(index)); - - if(glyphShape.getNumVertices() < 3) { - continue; - } - addGlyphShape(glyphShape); - } - } - - - /** Generate a OGL Region to represent this Object. - * @param gl the current gl object - * @param rs the current attached RenderState - * @param renderModes bit-field of modes, e.g. {@link Region#VARIABLE_CURVE_WEIGHT_BIT}, {@link Region#VBAA_RENDERING_BIT} - */ - public GLRegion createRegion(GL2ES2 gl, int renderModes){ - region = RegionFactory.create(renderModes); - // region.setFlipped(true); - - int numVertices = region.getNumVertices(); - - for(int i=0; i< glyphs.size(); i++) { - final GlyphShape glyph = glyphs.get(i); - ArrayList<Triangle> gtris = glyph.triangulate(); - region.addTriangles(gtris); - - final ArrayList<Vertex> gVertices = glyph.getVertices(); - for(int j=0; j<gVertices.size(); j++) { - final Vertex gVert = gVertices.get(j); - gVert.setId(numVertices++); - region.addVertex(gVert); - } - } - return region; - } - - /** Generate a Hashcode for this object - * @return a string defining the hashcode - */ - public String getTextHashCode(){ - return "" + fontname.hashCode() + str.hashCode(); - } - - /** Render the Object based using the associated Region - * previously generated. - */ - public void renderString3D(GL2ES2 gl) { - region.draw(gl, null, 0, 0, null); - } - /** Render the Object based using the associated Region - * previously generated. - * @param matrix current {@link PMVMatrix}. - * @param rs the RenderState to be used - * @param vp_width current screen width - * @param vp_height current screen height - * @param texWidth desired texture width for multipass-rendering. - * The actual used texture-width is written back when mp rendering is enabled, otherwise the store is untouched. - */ - public void renderString3D(GL2ES2 gl, RenderState rs, int vp_width, int vp_height, int[/*1*/] texWidth) { - region.draw(gl, rs, vp_width, vp_height, texWidth); - } - - /** Get the Origin of this GlyphString - * @return - */ - public Vertex getOrigin() { - return origin; - } - - /** Destroy the associated OGL objects - * @param rs the current attached RenderState - */ - public void destroy(GL2ES2 gl, RenderState rs) { - if(null != gl && null != rs) { - region.destroy(gl, rs); - region = null; - } else if(null != region) { - throw new InternalError("destroy called w/o GL context, but has a region"); - } - glyphs.clear(); - } - - public AABBox getBounds(){ - return region.getBounds(); - } -} diff --git a/src/jogl/classes/jogamp/graph/font/FontConstructor.java b/src/jogl/classes/jogamp/graph/font/FontConstructor.java index b452ae548..2732d07cb 100644 --- a/src/jogl/classes/jogamp/graph/font/FontConstructor.java +++ b/src/jogl/classes/jogamp/graph/font/FontConstructor.java @@ -29,11 +29,19 @@ package jogamp.graph.font; import java.io.File; import java.io.IOException; -import java.net.URLConnection; +import java.io.InputStream; import com.jogamp.graph.font.Font; public interface FontConstructor { - Font create(File file) throws IOException ; - Font create(URLConnection url) throws IOException ; + /** + * @param file The font file + */ + Font create(final File file) throws IOException; + + /** + * @param istream The font input stream + * @param streamLen the length of the font segment in the stream + */ + Font create(final InputStream stream, int streamLen) throws IOException; } diff --git a/src/jogl/classes/jogamp/graph/font/FontInt.java b/src/jogl/classes/jogamp/graph/font/FontInt.java deleted file mode 100644 index 20e1ec028..000000000 --- a/src/jogl/classes/jogamp/graph/font/FontInt.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2011 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -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 { - - public interface GlyphInt extends Font.Glyph { - public Path2D getPath(); // unscaled path - 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/JavaFontLoader.java b/src/jogl/classes/jogamp/graph/font/JavaFontLoader.java index a00e9579c..da651cca9 100644 --- a/src/jogl/classes/jogamp/graph/font/JavaFontLoader.java +++ b/src/jogl/classes/jogamp/graph/font/JavaFontLoader.java @@ -27,8 +27,11 @@ */ package jogamp.graph.font; +import java.io.BufferedInputStream; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.security.AccessController; import java.security.PrivilegedAction; @@ -40,13 +43,16 @@ import com.jogamp.graph.font.FontSet; import com.jogamp.graph.font.FontFactory; public class JavaFontLoader implements FontSet { - - final static FontSet fontLoader = new JavaFontLoader(); + + // FIXME: Add cache size to limit memory usage + private static final IntObjectHashMap fontMap = new IntObjectHashMap(); + + private static final FontSet fontLoader = new JavaFontLoader(); public static FontSet get() { return fontLoader; } - + final static String availableFontFileNames[] = { /* 00 */ "LucidaBrightRegular.ttf", @@ -58,11 +64,12 @@ public class JavaFontLoader implements FontSet { /* 06 */ "LucidaTypewriterRegular.ttf", /* 07 */ "LucidaTypewriterBold.ttf", }; - + final String javaFontPath; - + private JavaFontLoader() { final String javaHome = AccessController.doPrivileged(new PrivilegedAction<String>() { + @Override public String run() { return System.getProperty("java.home"); } @@ -74,26 +81,28 @@ public class JavaFontLoader implements FontSet { } } - // FIXME: Add cache size to limit memory usage - static final IntObjectHashMap fontMap = new IntObjectHashMap(); - - static boolean is(int bits, int bit) { + static boolean is(final int bits, final int bit) { return 0 != ( bits & bit ) ; } - + + @Override public Font getDefault() throws IOException { - return get(FAMILY_REGULAR, 0) ; // Sans Serif Regular + return get(FAMILY_REGULAR, 0) ; // Sans Serif Regular } - - public Font get(int family, int style) throws IOException { + + @Override + public Font get(final int family, final int style) throws IOException { + if(null == javaFontPath) { + throw new GLException("java font path undefined"); + } Font font = (Font)fontMap.get( ( family << 8 ) | style ); if (font != null) { return font; } // 1st process Sans Serif (2 fonts) - if( is(style, STYLE_SERIF) ) { - if( is(style, STYLE_BOLD) ) { + if( is(style, STYLE_SERIF) ) { + if( is(style, STYLE_BOLD) ) { font = abspath(availableFontFileNames[5], family, style); } else { font = abspath(availableFontFileNames[4], family, style); @@ -103,53 +112,74 @@ public class JavaFontLoader implements FontSet { } return font; } - + // Serif Fonts .. switch (family) { case FAMILY_LIGHT: case FAMILY_MEDIUM: case FAMILY_CONDENSED: case FAMILY_REGULAR: - if( is(style, STYLE_BOLD) ) { - if( is(style, STYLE_ITALIC) ) { + if( is(style, STYLE_BOLD) ) { + if( is(style, STYLE_ITALIC) ) { font = abspath(availableFontFileNames[3], family, style); } else { font = abspath(availableFontFileNames[2], family, style); } - } else if( is(style, STYLE_ITALIC) ) { + } else if( is(style, STYLE_ITALIC) ) { font = abspath(availableFontFileNames[1], family, style); } else { font = abspath(availableFontFileNames[0], family, style); } break; - + case FAMILY_MONOSPACED: - if( is(style, STYLE_BOLD) ) { + if( is(style, STYLE_BOLD) ) { font = abspath(availableFontFileNames[7], family, style); } else { font = abspath(availableFontFileNames[6], family, style); } - break; + break; } return font; } - - Font abspath(String fname, int family, int style) throws IOException { - if(null == javaFontPath) { - throw new GLException("java font path undefined"); - } - final String err = "Problem loading font "+fname+", file "+javaFontPath+fname ; - + + Font abspath(final String fname, final int family, final int style) throws IOException { try { - final Font f = FontFactory.get( new File(javaFontPath+fname) ); + final Font f = abspathImpl(javaFontPath+fname, family, style); + if(null != f) { + return f; + } + throw new IOException (String.format("Problem loading font %s, file %s%s", fname, javaFontPath, fname)); + } catch (final IOException ioe) { + throw new IOException(String.format("Problem loading font %s, file %s%s", fname, javaFontPath, fname), ioe); + } + } + private Font abspathImpl(final String fname, final int family, final int style) throws IOException { + final Exception[] privErr = { null }; + final int[] streamLen = { 0 }; + final InputStream stream = AccessController.doPrivileged(new PrivilegedAction<InputStream>() { + @Override + public InputStream run() { + try { + final File file = new File(fname); + streamLen[0] = (int) file.length(); + return new BufferedInputStream(new FileInputStream(file), streamLen[0]); + } catch (final Exception e) { + privErr[0] = e; + return null; + } + } } ); + if( null != privErr[0] ) { + throw new IOException(privErr[0]); + } + if(null != stream) { + final Font f= FontFactory.get ( stream, streamLen[0], true ) ; if(null != f) { fontMap.put( ( family << 8 ) | style, f ); return f; } - throw new IOException (err); - } catch (IOException ioe) { - throw new IOException(err, ioe); } - } + return null; + } } diff --git a/src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java b/src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java index 0772cc47f..bbf022657 100644 --- a/src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java +++ b/src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java @@ -28,29 +28,42 @@ package jogamp.graph.font; import java.io.IOException; -import javax.media.opengl.GLException; +import java.io.InputStream; +import com.jogamp.common.net.Uri; +import com.jogamp.common.os.Platform; import com.jogamp.common.util.IntObjectHashMap; -import com.jogamp.common.util.IOUtil; - +import com.jogamp.common.util.JarUtil; +import com.jogamp.common.util.cache.TempJarCache; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontSet; import com.jogamp.graph.font.FontFactory; -import java.net.URLConnection; + +import java.security.AccessController; +import java.security.PrivilegedAction; public class UbuntuFontLoader implements FontSet { - - final static FontSet fontLoader = new UbuntuFontLoader(); - public static FontSet get() { + // FIXME: Add cache size to limit memory usage + private static final IntObjectHashMap fontMap = new IntObjectHashMap(); + + private static final Uri.Encoded jarSubDir = Uri.Encoded.cast("atomic/"); + private static final Uri.Encoded jarName = Uri.Encoded.cast("jogl-fonts-p0.jar"); + + private static final String relFontPath = "fonts/ubuntu/" ; + private static final String absFontPath = "jogamp/graph/font/fonts/ubuntu/" ; + + private static final FontSet fontLoader = new UbuntuFontLoader(); + + public static final FontSet get() { return fontLoader; } - + final static String availableFontFileNames[] = { /* 00 */ "Ubuntu-R.ttf", // regular /* 01 */ "Ubuntu-RI.ttf", // regular italic - /* 02 */ "Ubuntu-B.ttf", // bold + /* 02 */ "Ubuntu-B.ttf", // bold /* 03 */ "Ubuntu-BI.ttf", // bold italic /* 04 */ "Ubuntu-L.ttf", // light /* 05 */ "Ubuntu-LI.ttf", // light italic @@ -58,24 +71,21 @@ public class UbuntuFontLoader implements FontSet { /* 07 */ "Ubuntu-MI.ttf", // medium italic }; - - final static String relPath = "fonts/ubuntu/" ; - + private UbuntuFontLoader() { } - // FIXME: Add cache size to limit memory usage - static final IntObjectHashMap fontMap = new IntObjectHashMap(); - - static boolean is(int bits, int bit) { + static boolean is(final int bits, final int bit) { return 0 != ( bits & bit ) ; } - + + @Override public Font getDefault() throws IOException { - return get(FAMILY_REGULAR, 0) ; // Sans Serif Regular + return get(FAMILY_REGULAR, 0) ; // Sans Serif Regular } - - public Font get(int family, int style) throws IOException { + + @Override + public Font get(final int family, final int style) throws IOException { Font font = (Font)fontMap.get( ( family << 8 ) | style ); if (font != null) { return font; @@ -97,7 +107,7 @@ public class UbuntuFontLoader implements FontSet { font = abspath(availableFontFileNames[0], family, style); } break; - + case FAMILY_LIGHT: if( is(style, STYLE_ITALIC) ) { font = abspath(availableFontFileNames[5], family, style); @@ -105,34 +115,83 @@ public class UbuntuFontLoader implements FontSet { font = abspath(availableFontFileNames[4], family, style); } break; - + case FAMILY_MEDIUM: if( is(style, STYLE_ITALIC) ) { font = abspath(availableFontFileNames[6], family, style); } else { font = abspath(availableFontFileNames[7], family, style); } - break; + break; } return font; } - - Font abspath(String fname, int family, int style) throws IOException { - final String err = "Problem loading font "+fname+", stream "+relPath+fname; + + private static boolean attemptedJARLoading = false; + private static boolean useTempJARCache = false; + + private synchronized Font abspath(final String fname, final int family, final int style) throws IOException { + if( !attemptedJARLoading ) { + attemptedJARLoading = true; + Platform.initSingleton(); + if( TempJarCache.isInitialized() ) { + try { + final Uri uri = JarUtil.getRelativeOf(UbuntuFontLoader.class, jarSubDir, jarName); + final Exception e0 = AccessController.doPrivileged(new PrivilegedAction<Exception>() { + @Override + public Exception run() { + try { + TempJarCache.addResources(UbuntuFontLoader.class, uri); + useTempJARCache = true; + return null; + } catch (final Exception e) { + return e; + } + } } ); + if( null != e0 ) { + throw e0; + } + } catch(final Exception e1) { + System.err.println("Caught "+e1.getMessage()); + e1.printStackTrace(); + } + } + } + final String path = useTempJARCache ? absFontPath : relFontPath; try { - URLConnection conn = IOUtil.getResource(UbuntuFontLoader.class, relPath+fname); - if(null == conn) { - throw new GLException(err); + final Font f = abspathImpl(path+fname, family, style); + if( null != f ) { + return f; } - final Font f= FontFactory.get ( conn ) ; + throw new IOException(String.format("Problem loading font %s, stream %s%s", fname, path, fname)); + } catch(final Exception e) { + throw new IOException(String.format("Problem loading font %s, stream %s%s", fname, path, fname), e); + } + } + private Font abspathImpl(final String fname, final int family, final int style) throws IOException { + final Exception[] privErr = { null }; + final InputStream stream = AccessController.doPrivileged(new PrivilegedAction<InputStream>() { + @Override + public InputStream run() { + try { + final Uri uri = TempJarCache.getResourceUri(fname); + return null != uri ? uri.toURL().openConnection().getInputStream() : null; + } catch (final Exception e) { + privErr[0] = e; + return null; + } + } } ); + if( null != privErr[0] ) { + throw new IOException(privErr[0]); + } + if(null != stream) { + final Font f= FontFactory.get ( stream, true ) ; if(null != f) { fontMap.put( ( family << 8 ) | style, f ); return f; - } - throw new IOException(err); - } catch(IOException ioe) { - throw new IOException(err, ioe); + } } - } + return null; + } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java index 8e465de99..c48ef99ca 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java @@ -27,9 +27,6 @@ */ package jogamp.graph.font.typecast; -import java.util.ArrayList; - -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; @@ -38,53 +35,52 @@ 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.font.Font.Glyph; -import com.jogamp.graph.geom.AABBox; +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; - - final OTFontCollection fontset; - final OTFont font; - TypecastHMetrics metrics; - final CmapFormat cmapFormat; - int cmapentries; - - // FIXME: Add cache size to limit memory usage ?? - IntObjectHashMap char2Glyph; + private static final Vertex.Factory<SVertex> vertexFactory = SVertex.factory(); + + // private final OTFontCollection fontset; + /* pp */ final OTFont font; + private final CmapFormat cmapFormat; + private final int cmapentries; + private final IntObjectHashMap char2Glyph; + private final TypecastHMetrics metrics; + private final float[] tmpV3 = new float[3]; + // FIXME: Add cache size to limit memory usage ?? - 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, // which is assumed to be the one with the most entries (stupid 'eh?) - CmapTable cmapTable = font.getCmapTable(); - CmapFormat[] _cmapFormatP = { null, null, null, null }; + final CmapTable cmapTable = font.getCmapTable(); + final CmapFormat[] _cmapFormatP = { null, null, null, null }; int platform = -1; int platformLength = -1; int encoding = -1; for(int i=0; i<cmapTable.getNumTables(); i++) { - CmapIndexEntry cmapIdxEntry = cmapTable.getCmapIndexEntry(i); - int pidx = cmapIdxEntry.getPlatformId(); - CmapFormat cf = cmapIdxEntry.getFormat(); + final CmapIndexEntry cmapIdxEntry = cmapTable.getCmapIndexEntry(i); + final int pidx = cmapIdxEntry.getPlatformId(); + final CmapFormat cf = cmapIdxEntry.getFormat(); if(DEBUG) { - System.err.println("CmapFormat["+i+"]: platform " + pidx + + System.err.println("CmapFormat["+i+"]: platform " + pidx + ", encoding "+cmapIdxEntry.getEncodingId() + ": "+cf); } - if( _cmapFormatP[pidx] == null || + if( _cmapFormatP[pidx] == null || _cmapFormatP[pidx].getLength() < cf.getLength() ) { _cmapFormatP[pidx] = cf; if( cf.getLength() > platformLength ) { - platformLength = cf.getLength() ; + platformLength = cf.getLength() ; platform = pidx; encoding = cmapIdxEntry.getEncodingId(); } @@ -93,10 +89,10 @@ class TypecastFont implements FontInt { if(0 <= platform) { cmapFormat = _cmapFormatP[platform]; if(DEBUG) { - System.err.println("Selected CmapFormat: platform " + platform + + System.err.println("Selected CmapFormat: platform " + platform + ", encoding "+encoding + ": "+cmapFormat); } - } else { + } else { CmapFormat _cmapFormat = null; /*if(null == _cmapFormat) { platform = ID.platformMacintosh; @@ -124,58 +120,66 @@ class TypecastFont implements FontInt { } } - 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) { + final 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()); System.err.println("num glyphs: "+font.getNumGlyphs()); System.err.println("num cmap entries: "+cmapentries); System.err.println("num cmap ranges: "+cmapFormat.getRangeCount()); - + for (int i = 0; i < cmapFormat.getRangeCount(); ++i) { - CmapFormat.Range range = cmapFormat.getRange(i); + final CmapFormat.Range range = cmapFormat.getRange(i); for (int j = range.getStartCode(); j <= range.getEndCode(); ++j) { final int code = cmapFormat.mapCharCode(j); if(code < 15) { - System.err.println(" char: " + (int)j + " ( " + (char)j +" ) -> " + code); + System.err.println(" char: " + j + " ( " + (char)j +" ) -> " + code); } } } } char2Glyph = new IntObjectHashMap(cmapentries + cmapentries/4); + metrics = new TypecastHMetrics(this); } - - public StringBuilder getName(StringBuilder sb, int nameIndex) { + + @Override + public StringBuilder getName(final StringBuilder sb, final int nameIndex) { return font.getName(nameIndex, sb); } - public String getName(int nameIndex) { + @Override + public String getName(final int nameIndex) { return getName(null, nameIndex).toString(); } - public StringBuilder getAllNames(StringBuilder sb, String separator) { + @Override + public StringBuilder getAllNames(final StringBuilder sb, final 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; - } + } - public float getAdvanceWidth(int i, float pixelSize) { - return font.getHmtxTable().getAdvanceWidth(i) * metrics.getScale(pixelSize); + @Override + public float getAdvanceWidth(final int glyphID, final float pixelSize) { + return font.getHmtxTable().getAdvanceWidth(glyphID) * metrics.getScale(pixelSize); } - - public Metrics getMetrics() { - if (metrics == null) { - metrics = new TypecastHMetrics(this); - } + + @Override + public final Metrics getMetrics() { return metrics; } - public Glyph getGlyph(char symbol) { - TypecastGlyph result = (TypecastGlyph) char2Glyph.get(symbol); + @Override + public Glyph getGlyph(final char symbol) { + TypecastGlyph result = (TypecastGlyph) char2Glyph.get(symbol); if (null == result) { // final short code = (short) char2Code.get(symbol); short code = (short) cmapFormat.mapCharCode(symbol); @@ -187,7 +191,7 @@ class TypecastFont implements FontInt { default: code = Glyph.ID_UNKNOWN; } } - + jogamp.graph.font.typecast.ot.OTGlyph glyph = font.getGlyph(code); if(null == glyph) { glyph = font.getGlyph(Glyph.ID_UNKNOWN); @@ -195,106 +199,162 @@ class TypecastFont implements FontInt { if(null == glyph) { throw new RuntimeException("Could not retrieve glyph for symbol: <"+symbol+"> "+(int)symbol+" -> glyph id "+code); } - Path2D path = TypecastRenderer.buildPath(glyph); - result = new TypecastGlyph(this, symbol, code, glyph.getBBox(), glyph.getAdvanceWidth(), path); + final OutlineShape shape = TypecastRenderer.buildShape(symbol, glyph, vertexFactory); + result = new TypecastGlyph(this, symbol, code, glyph.getBBox(), glyph.getAdvanceWidth(), shape); if(DEBUG) { - System.err.println("New glyph: " + (int)symbol + " ( " + (char)symbol +" ) -> " + code + ", contours " + glyph.getPointCount() + ": " + path); + System.err.println("New glyph: " + (int)symbol + " ( " + symbol +" ) -> " + code + ", contours " + glyph.getPointCount() + ": " + shape); } - final HdmxTable hdmx = font.getHdmxTable(); + glyph.clearPointData(); + + final HdmxTable hdmx = font.getHdmxTable(); if (null!= result && null != hdmx) { /*if(DEBUG) { System.err.println("hdmx "+hdmx); }*/ for (int i=0; i<hdmx.getNumberOfRecords(); i++) { - final HdmxTable.DeviceRecord dr = hdmx.getRecord(i); + final HdmxTable.DeviceRecord dr = hdmx.getRecord(i); result.addAdvance(dr.getWidth(code), dr.getPixelSize()); /* if(DEBUG) { System.err.println("hdmx advance : pixelsize = "+dr.getWidth(code)+" : "+ dr.getPixelSize()); } */ } - } + } char2Glyph.put(symbol, result); } return result; } - - public ArrayList<OutlineShape> getOutlineShapes(CharSequence string, float pixelSize, Factory<? extends Vertex> vertexFactory) { - AffineTransform transform = new AffineTransform(vertexFactory); - return TypecastRenderer.getOutlineShapes(this, string, pixelSize, transform, vertexFactory); + + @Override + public final float getPixelSize(final float fontSize /* points per inch */, final float resolution) { + return fontSize * resolution / ( 72f /* points per inch */ ); } - public float getStringWidth(CharSequence string, float pixelSize) { + @Override + public float getLineHeight(final float pixelSize) { + final Metrics metrics = getMetrics(); + final float lineGap = metrics.getLineGap(pixelSize) ; // negative value! + final float ascent = metrics.getAscent(pixelSize) ; // negative value! + final float descent = metrics.getDescent(pixelSize) ; // positive value! + final float advanceY = lineGap - descent + ascent; // negative value! + return -advanceY; + } + + @Override + public float getMetricWidth(final CharSequence string, final float pixelSize) { float width = 0; final int len = string.length(); - for (int i=0; i< len; i++) - { - char character = string.charAt(i); + for (int i=0; i< len; i++) { + final char character = string.charAt(i); if (character == '\n') { width = 0; } else { - Glyph glyph = getGlyph(character); + final Glyph glyph = getGlyph(character); width += glyph.getAdvance(pixelSize, false); } } - - return (int)(width + 0.5f); + return (int)(width + 0.5f); } - public float getStringHeight(CharSequence string, float pixelSize) { + @Override + public float getMetricHeight(final CharSequence string, final float pixelSize, final AABBox tmp) { int height = 0; - for (int i=0; i<string.length(); i++) - { - char character = string.charAt(i); - if (character != ' ') - { - Glyph glyph = getGlyph(character); - AABBox bbox = glyph.getBBox(pixelSize); + for (int i=0; i<string.length(); i++) { + final char character = string.charAt(i); + if (character != ' ') { + final Glyph glyph = getGlyph(character); + final AABBox bbox = glyph.getBBox(tmp, pixelSize, tmpV3); height = (int)Math.ceil(Math.max(bbox.getHeight(), height)); } } - return height; + return height; } - public AABBox getStringBounds(CharSequence string, float pixelSize) { + @Override + public AABBox getMetricBounds(final CharSequence string, final float pixelSize) { if (string == null) { return new AABBox(); } - final Metrics metrics = getMetrics(); - final float lineGap = metrics.getLineGap(pixelSize); - final float ascent = metrics.getAscent(pixelSize); - final float descent = metrics.getDescent(pixelSize); - final float advanceY = lineGap - descent + ascent; + 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++) { - char character = string.charAt(i); + for (int i=0; i<charCount; i++) { + final char character = string.charAt(i); if (character == '\n') { totalWidth = Math.max(curLineWidth, totalWidth); curLineWidth = 0; - totalHeight -= advanceY; + totalHeight += lineHeight; continue; } - Glyph glyph = getGlyph(character); + final Glyph glyph = getGlyph(character); curLineWidth += glyph.getAdvance(pixelSize, true); } if (curLineWidth > 0) { - totalHeight -= advanceY; + totalHeight += lineHeight; totalWidth = Math.max(curLineWidth, totalWidth); } - return new AABBox(0, 0, 0, totalWidth, totalHeight,0); + return new AABBox(0, 0, 0, totalWidth, totalHeight,0); + } + @Override + 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 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 ) { + temp1.setTransform(transform); + } else { + temp1.setToIdentity(); + } + temp1.translate(advanceTotal, y, temp2); + temp1.scale(scale, scale, temp2); + tbox.reset(); + + final Font.Glyph glyph = getGlyph(character); + res.resize(temp1.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() { return font.getNumGlyphs(); } - - public boolean isPrintableChar( char c ) { + + @Override + public boolean isPrintableChar( final char c ) { return FontFactory.isPrintableChar(c); } - + + @Override public String toString() { return getFullFamilyName(null).toString(); } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFontConstructor.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFontConstructor.java index 0f762e79c..ef7f38e64 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFontConstructor.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFontConstructor.java @@ -29,62 +29,22 @@ package jogamp.graph.font.typecast; import java.io.File; import java.io.IOException; -import java.net.URLConnection; -import java.security.AccessController; -import java.security.PrivilegedAction; - -import javax.media.opengl.GLException; +import java.io.InputStream; import jogamp.graph.font.FontConstructor; import jogamp.graph.font.typecast.ot.OTFontCollection; -import com.jogamp.common.util.IOUtil; import com.jogamp.graph.font.Font; public class TypecastFontConstructor implements FontConstructor { + @Override public Font create(final File ffile) throws IOException { - Object o = AccessController.doPrivileged(new PrivilegedAction<Object>() { - public Object run() { - OTFontCollection fontset; - try { - fontset = OTFontCollection.create(ffile); - return new TypecastFont(fontset); - } catch (IOException e) { - return e; - } - } - }); - if(o instanceof Font) { - return (Font)o; - } - if(o instanceof IOException) { - throw (IOException)o; - } - throw new InternalError("Unexpected Object: "+o); + return new TypecastFont( OTFontCollection.create(ffile) ); } - - public Font create(final URLConnection fconn) throws IOException { - return AccessController.doPrivileged(new PrivilegedAction<Font>() { - public Font run() { - File tf = null; - int len=0; - Font f = null; - try { - tf = IOUtil.createTempFile( "jogl.font", ".ttf", false, null); - len = IOUtil.copyURLConn2File(fconn, tf); - if(len==0) { - tf.delete(); - throw new GLException("Font of stream "+fconn.getURL()+" was zero bytes"); - } - f = create(tf); - tf.delete(); - } catch (IOException e) { - e.printStackTrace(); - } - return f; - } - }); + + @Override + public Font create(final InputStream istream, final int streamLen) throws IOException { + return new TypecastFont( OTFontCollection.create(istream, streamLen) ); } - } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java index a1f1a3292..97570d605 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java @@ -27,206 +27,185 @@ */ package jogamp.graph.font.typecast; -import java.util.HashMap; - -import jogamp.graph.font.FontInt; -import jogamp.graph.geom.plane.AffineTransform; -import jogamp.graph.geom.plane.Path2D; - +import com.jogamp.common.util.IntIntHashMap; +import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.font.Font; -import com.jogamp.graph.geom.AABBox; +import com.jogamp.opengl.math.geom.AABBox; -public class TypecastGlyph implements FontInt.GlyphInt { - public class Advance +public final class TypecastGlyph implements Font.Glyph { + public static final class Advance { - final Font font; - final float advance; - HashMap<Float, Float> size2advance = new HashMap<Float, Float>(); - - public Advance(Font font, float advance) + private final Font font; + private final float advance; + private final IntIntHashMap size2advanceI = new IntIntHashMap(); + + public Advance(final Font font, final float advance) { this.font = font; this.advance = advance; + size2advanceI.setKeyNotFoundValue(0); } - - public void reset() { - size2advance.clear(); + + public final void reset() { + size2advanceI.clear(); } - - public float getScale(float pixelSize) + + public final Font getFont() { return font; } + + public final float getScale(final float pixelSize) { return this.font.getMetrics().getScale(pixelSize); } - - public void add(float advance, float size) + + public final 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 final float get(final float pixelSize, final boolean useFrationalMetrics) { - 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(pixelSize); + final int aI = size2advanceI.get(sI); + if( 0 != aI ) { + return Float.intBitsToFloat(aI); } - return fo.floatValue(); + final float a; + if ( useFrationalMetrics ) { + a = this.advance * getScale(pixelSize); + } else { + // a = Math.ceil(this.advance * getScale(pixelSize)); + a = Math.round(this.advance * getScale(pixelSize)); // TODO: check whether ceil should be used instead? + } + size2advanceI.put(sI, Float.floatToIntBits(a)); + return a; } - - public String toString() + + @Override + public final String toString() { return "\nAdvance:"+ "\n advance: "+this.advance+ - "\n advances: \n"+size2advance; + "\n advances: \n"+size2advanceI; } } - - public class Metrics + + public static final class Metrics { - AABBox bbox; - Advance advance; - - public Metrics(Font font, AABBox bbox, float advance) + private final AABBox bbox; + private final Advance advance; + + public Metrics(final Font font, final AABBox bbox, final float advance) { this.bbox = bbox; this.advance = new Advance(font, advance); } - - public void reset() { + + public final void reset() { advance.reset(); } - - public float getScale(float pixelSize) + + public final Font getFont() { return advance.getFont(); } + + public final float getScale(final float pixelSize) { return this.advance.getScale(pixelSize); } - - public AABBox getBBox() + + public final AABBox getBBox() { return this.bbox; } - - public void addAdvance(float advance, float size) + + public final void addAdvance(final float advance, final float size) { this.advance.add(advance, size); } - - public float getAdvance(float size, boolean useFrationalMetrics) + + public final float getAdvance(final float pixelSize, final boolean useFrationalMetrics) { - return this.advance.get(size, useFrationalMetrics); + return this.advance.get(pixelSize, useFrationalMetrics); } - - public String toString() + + @Override + public final String toString() { return "\nMetrics:"+ "\n bbox: "+this.bbox+ this.advance; } - } + } public static final short INVALID_ID = (short)((1 << 16) - 1); public static final short MAX_ID = (short)((1 << 16) - 2); - - private final Font font; - - char symbol; - short id; - int advance; - Metrics metrics; - - protected Path2D path; // in EM units - protected Path2D pathSized; - protected float numberSized; - - protected TypecastGlyph(Font font, char symbol) { - this.font = font; - this.symbol = symbol; - } - - protected TypecastGlyph(Font font, - char symbol, short id, AABBox bbox, int advance, Path2D path) { - this.font = font; + + private final char symbol; + private final OutlineShape shape; // in EM units + private final short id; + private final Metrics metrics; + + protected TypecastGlyph(final Font font, final char symbol, final short id, final AABBox bbox, final int advance, final OutlineShape shape) { this.symbol = symbol; - this.advance = advance; - - init(id, bbox, advance); - - this.path = path; - this.pathSized = null; - this.numberSized = 0.0f; - } - - void init(short id, AABBox bbox, int advance) { + this.shape = shape; this.id = id; - this.advance = advance; - this.metrics = new Metrics(this.font, bbox, this.advance); + this.metrics = new Metrics(font, bbox, advance); } - - public void reset(Path2D path) { - this.path = path; - this.metrics.reset(); - } - - public Font getFont() { - return this.font; + + @Override + public final Font getFont() { + return this.metrics.getFont(); } - - public char getSymbol() { + + @Override + public final char getSymbol() { return this.symbol; } - - AABBox getBBoxUnsized() { + + final AABBox getBBoxUnsized() { return this.metrics.getBBox(); } - - public AABBox getBBox() { + + @Override + public final AABBox getBBox() { return this.metrics.getBBox(); } - - public Metrics getMetrics() { + + public final Metrics getMetrics() { return this.metrics; } - - public short getID() { + + @Override + public final short getID() { return this.id; } - - public float getScale(float pixelSize) { + + @Override + public final float getScale(final float pixelSize) { return this.metrics.getScale(pixelSize); } - - public AABBox getBBox(float pixelSize) { - final float size = getScale(pixelSize); - AABBox newBox = getBBox().clone(); - newBox.scale(size); - return newBox; + + @Override + public final AABBox getBBox(final AABBox dest, final float pixelSize, final float[] tmpV3) { + return dest.copy(getBBox()).scale(getScale(pixelSize), tmpV3); } - - protected void addAdvance(float advance, float size) { + + protected final void addAdvance(final float advance, final float size) { this.metrics.addAdvance(advance, size); } - - public float getAdvance(float pixelSize, boolean useFrationalMetrics) { + + @Override + public final float getAdvance(final float pixelSize, final boolean useFrationalMetrics) { return this.metrics.getAdvance(pixelSize, useFrationalMetrics); } - - public Path2D getPath() { - return this.path; + + @Override + public final OutlineShape getShape() { + return this.shape; + } + + @Override + public final int hashCode() { + // 31 * x == (x << 5) - x + final int hash = 31 + getFont().getName(Font.NAME_UNIQUNAME).hashCode(); + return ((hash << 5) - hash) + id; } - - public Path2D getPath(float pixelSize) { - final float size = getScale(pixelSize); - - if (this.numberSized != size) { - this.numberSized = size; - this.pathSized = AffineTransform.getScaleInstance(null, size, size).createTransformedShape(getPath()); - } - return this.pathSized; - } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java index 0dd7a6178..d5e30a500 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java @@ -31,11 +31,11 @@ import jogamp.graph.font.typecast.ot.table.HeadTable; import jogamp.graph.font.typecast.ot.table.HheaTable; import com.jogamp.graph.font.Font.Metrics; -import com.jogamp.graph.geom.AABBox; +import com.jogamp.opengl.math.geom.AABBox; class TypecastHMetrics implements Metrics { private final TypecastFont fontImpl; - + // HeadTable private final HeadTable headTable; private final float unitsPerEM_Inv; @@ -44,41 +44,45 @@ class TypecastHMetrics implements Metrics { private final HheaTable hheaTable; // 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(); + hheaTable = this.fontImpl.font.getHheaTable(); // vheaTable = this.fontImpl.font.getVheaTable(); - unitsPerEM_Inv = 1.0f / ( (float) headTable.getUnitsPerEm() ); - - int maxWidth = headTable.getXMax() - headTable.getXMin(); - int maxHeight = headTable.getYMax() - headTable.getYMin(); - float lowx= headTable.getXMin(); - float lowy = -(headTable.getYMin()+maxHeight); - float highx = lowx + maxWidth; - float highy = lowy + maxHeight; + unitsPerEM_Inv = 1.0f / ( headTable.getUnitsPerEm() ); + + final int maxWidth = headTable.getXMax() - headTable.getXMin(); + final int maxHeight = headTable.getYMax() - headTable.getYMin(); + final float lowx= headTable.getXMin(); + final float lowy = -(headTable.getYMin()+maxHeight); + final float highx = lowx + maxWidth; + final float highy = lowy + maxHeight; bbox = new AABBox(lowx, lowy, 0, highx, highy, 0); // invert } - - public final float getAscent(float pixelSize) { + + @Override + public final float getAscent(final float pixelSize) { return getScale(pixelSize) * -hheaTable.getAscender(); // invert } - public final float getDescent(float pixelSize) { + @Override + public final float getDescent(final float pixelSize) { return getScale(pixelSize) * -hheaTable.getDescender(); // invert } - public final float getLineGap(float pixelSize) { + @Override + public final float getLineGap(final float pixelSize) { return getScale(pixelSize) * -hheaTable.getLineGap(); // invert } - public final float getMaxExtend(float pixelSize) { + @Override + public final float getMaxExtend(final float pixelSize) { return getScale(pixelSize) * hheaTable.getXMaxExtent(); } - public final float getScale(float pixelSize) { + @Override + public final float getScale(final float pixelSize) { return pixelSize * unitsPerEM_Inv; } - public final AABBox getBBox(float pixelSize) { - AABBox res = new AABBox(bbox.getLow(), bbox.getHigh()); - res.scale(getScale(pixelSize)); - return res; + @Override + 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 diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java index f155345aa..f78656b52 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java @@ -27,196 +27,197 @@ */ package jogamp.graph.font.typecast; -import java.util.ArrayList; - -import jogamp.graph.font.FontInt.GlyphInt; import jogamp.graph.font.typecast.ot.OTGlyph; import jogamp.graph.font.typecast.ot.Point; -import jogamp.graph.geom.plane.AffineTransform; -import jogamp.graph.geom.plane.Path2D; -import jogamp.graph.geom.plane.PathIterator; +import jogamp.opengl.Debug; import com.jogamp.graph.curve.OutlineShape; -import com.jogamp.graph.font.Font; -import com.jogamp.graph.font.Font.Glyph; import com.jogamp.graph.geom.Vertex; import com.jogamp.graph.geom.Vertex.Factory; /** - * Factory to build a {@link com.jogamp.graph.geom.Path2D Path2D} from - * {@link jogamp.graph.font.typecast.ot.OTGlyph Glyph}s. + * Factory to build an {@link OutlineShape} from + * {@link jogamp.graph.font.typecast.ot.OTGlyph Glyph}s. + * + * http://www.freetype.org/freetype2/docs/glyphs/glyphs-3.html + * http://walon.org/pub/ttf/ttf_glyphs.htm */ public class TypecastRenderer { + private static final boolean DEBUG = Debug.debug("graph.font.Renderer"); - private static void getPaths(TypecastFont font, - CharSequence string, float pixelSize, AffineTransform transform, Path2D[] p) - { - if (string == null) { - return; - } - Font.Metrics metrics = font.getMetrics(); - float advanceTotal = 0; - float lineGap = metrics.getLineGap(pixelSize) ; - float ascent = metrics.getAscent(pixelSize) ; - float descent = metrics.getDescent(pixelSize) ; - if (transform == null) { - transform = new AffineTransform(); - } - AffineTransform t = new AffineTransform(); - - float advanceY = lineGap - descent + ascent; - float y = 0; - for (int i=0; i<string.length(); i++) - { - p[i] = new Path2D(); - p[i].reset(); - t.setTransform(transform); - char character = string.charAt(i); - 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); - } + private static void addShapeMoveTo(final OutlineShape shape, final Factory<? extends Vertex> vertexFactory, final Point p1) { + if( DEBUG ) { System.err.println("Shape.MoveTo: "+p1); } + shape.closeLastOutline(false); + shape.addEmptyOutline(); + shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, p1.onCurve)); } - - public static ArrayList<OutlineShape> getOutlineShapes(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>(); - final int numGlyps = paths.length; - for (int index=0;index<numGlyps;index++) { - if(paths[index] == null){ - continue; - } - OutlineShape shape = new OutlineShape(vertexFactory); - shapes.add(shape); - PathIterator iterator = paths[index].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 shapes; + private static void addShapeLineTo(final OutlineShape shape, final Factory<? extends Vertex> vertexFactory, final Point p1) { + if( DEBUG ) { System.err.println("Shape.LineTo: "+p1); } + shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, p1.onCurve)); } - private static void addPathVertexToOutline(OutlineShape shape, Factory<? extends Vertex> vertexFactory, float[] coords, int segmentType){ - switch(segmentType) { - case PathIterator.SEG_MOVETO: - shape.closeLastOutline(); - shape.addEmptyOutline(); - shape.addVertex(0, vertexFactory.create(coords, 0, 2, true)); - break; - case PathIterator.SEG_LINETO: - shape.addVertex(0, vertexFactory.create(coords, 0, 2, true)); - break; - case PathIterator.SEG_QUADTO: - shape.addVertex(0, vertexFactory.create(coords, 0, 2, false)); - shape.addVertex(0, vertexFactory.create(coords, 2, 2, true)); - break; - case PathIterator.SEG_CUBICTO: - shape.addVertex(0, vertexFactory.create(coords, 0, 2, false)); - shape.addVertex(0, vertexFactory.create(coords, 2, 2, false)); - shape.addVertex(0, vertexFactory.create(coords, 4, 2, true)); - break; - case PathIterator.SEG_CLOSE: - shape.closeLastOutline(); - break; - default: - throw new IllegalArgumentException("Unhandled Segment Type: "+segmentType); - } + private static void addShapeQuadTo(final OutlineShape shape, final Factory<? extends Vertex> vertexFactory, final Point p1, final Point p2) { + if( DEBUG ) { System.err.println("Shape.QuadTo: "+p1+", "+p2); } + shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, p1.onCurve)); + shape.addVertex(0, vertexFactory.create(p2.x, p2.y, 0, p2.onCurve)); + } + private static void addShapeQuadTo(final OutlineShape shape, final Factory<? extends Vertex> vertexFactory, final Point p1, + final float p2x, final float p2y, final boolean p2OnCurve) { + if( DEBUG ) { System.err.println("Shape.QuadTo: "+p1+", p2 "+p2x+", "+p2y+", onCurve "+p2OnCurve); } + shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, p1.onCurve)); + shape.addVertex(0, vertexFactory.create(p2x, p2y, 0, p2OnCurve)); } - /** - * Build a {@link com.jogamp.graph.geom.Path2D Path2D} from a - * {@link jogamp.graph.font.typecast.ot.OTGlyph Glyph}. This glyph path can then - * be transformed and rendered. - */ - public static Path2D buildPath(OTGlyph glyph) { + private static void addShapeCubicTo(final OutlineShape shape, Factory<? extends Vertex> vertexFactory, Point p1, Point p2, Point p3) { + shape.addVertex(0, vertexFactory.create(p1.x, p1.y, 0, p1.onCurve)); + shape.addVertex(0, vertexFactory.create(p2.x, p2.y, 0, p2.onCurve)); + shape.addVertex(0, vertexFactory.create(p3.x, p3.y, 0, p3.onCurve)); + } */ + + public static OutlineShape buildShape(final char symbol, final OTGlyph glyph, final Factory<? extends Vertex> vertexFactory) { + // + // See Typecast: GlyphPathFactory.addContourToPath(..) + // if (glyph == null) { return null; } - Path2D glyphPath = new Path2D(); + final OutlineShape shape = new OutlineShape(vertexFactory); + buildShapeImpl(shape, symbol, glyph, vertexFactory); + shape.setIsQuadraticNurbs(); + return shape; + } + /** + private static void buildShapeImpl02(final OutlineShape shape, char symbol, OTGlyph glyph, Factory<? extends Vertex> vertexFactory) { // Iterate through all of the points in the glyph. Each time we find a // contour end point, add the point range to the path. - int firstIndex = 0; + int startIndex = 0; int count = 0; for (int i = 0; i < glyph.getPointCount(); i++) { count++; - if (glyph.getPoint(i).endOfContour) { - addContourToPath(glyphPath, glyph, firstIndex, count); - firstIndex = i + 1; + if ( glyph.getPoint(i).endOfContour ) { + for(int j=0; j<count; j++) { + final Point p = glyph.getPoint(startIndex + j); + shape.addVertex(0, vertexFactory.create(p.x, p.y, 0, p.onCurve)); + } + shape.closeLastOutline(false); + startIndex = i + 1; count = 0; } } - return glyphPath; - } + } */ - private static void addContourToPath(Path2D gp, OTGlyph glyph, int startIndex, int count) { - int offset = 0; - while (offset < count) { - Point point = glyph.getPoint(startIndex + offset%count); - Point point_plus1 = glyph.getPoint(startIndex + (offset+1)%count); - Point point_plus2 = glyph.getPoint(startIndex + (offset+2)%count); - if(offset == 0) - { - gp.moveTo(point.x, point.y); - } + private static void buildShapeImpl(final OutlineShape shape, final char symbol, final OTGlyph glyph, final Factory<? extends Vertex> vertexFactory) { + // Iterate through all of the points in the glyph. Each time we find a + // contour end point, add the point range to the path. + int startIndex = 0; + int count = 0; + final int totalPoints = glyph.getPointCount(); + for (int i = 0; i < totalPoints; i++) { + count++; + if ( glyph.getPoint(i).endOfContour ) { + int offset = 0; + while ( offset < count - 1 ) { // require at least +1 point (last one is end-of-contour) + final Point p0 = glyph.getPoint(startIndex + offset%count); + final Point p1 = glyph.getPoint(startIndex + (offset+1)%count); + final Point p2 = glyph.getPoint(startIndex + (offset+2)%count); + final Point p3 = offset+3 < count ? glyph.getPoint(startIndex + offset+3) : null; + if( DEBUG ) { + System.err.println("GlyphShape<"+symbol+">: offset "+offset+" of "+count+"/"+totalPoints+" points"); + final int pMIdx= (offset==0) ? startIndex+count-1 : startIndex+(offset-1)%count; + final Point pM = glyph.getPoint(pMIdx); + final int p0Idx = startIndex + offset%count; + final int p1Idx = startIndex + (offset+1)%count; + final int p2Idx = startIndex + (offset+2)%count; + final int p3Idx = startIndex + (offset+3)%count; + System.err.println("\t pM["+pMIdx+"] "+pM); + System.err.println("\t p0["+p0Idx+"] "+p0); + System.err.println("\t p1["+p1Idx+"] "+p1); + System.err.println("\t p2["+p2Idx+"] "+p2); + System.err.println("\t p3["+p3Idx+"] "+p3); + } + if(offset == 0) { + addShapeMoveTo(shape, vertexFactory, p0); + // gp.moveTo(point.x, point.y); + } - if (point.onCurve) { - if (point_plus1.onCurve) { - // s = new Line2D.Float(point.x, point.y, point_plus1.x, point_plus1.y); - gp.lineTo( point_plus1.x, point_plus1.y ); - offset++; - } else { - if (point_plus2.onCurve) { - // s = new QuadCurve2D.Float( point.x, point.y, point_plus1.x, point_plus1.y, point_plus2.x, point_plus2.y); - gp.quadTo(point_plus1.x, point_plus1.y, point_plus2.x, point_plus2.y); - offset+=2; + if( p0.endOfContour ) { + // Branch-0: EOC ** SHALL NEVER HAPPEN ** + if( DEBUG ) { System.err.println("B0 .. end-of-contour **** EOC"); } + shape.closeLastOutline(false); + break; + } else if (p0.onCurve) { + if (p1.onCurve) { + // Branch-1: point.onCurve && p1.onCurve + if( DEBUG ) { System.err.println("B1 .. line-to p0-p1"); } + + // s = new Line2D.Float(point.x, point.y, p1.x, p1.y); + // gp.lineTo( p1.x, p1.y ); + addShapeLineTo(shape, vertexFactory, p1); + offset++; + } else { + if (p2.onCurve) { + // Branch-2: point.onCurve && !p1.onCurve && p2.onCurve + if( DEBUG ) { System.err.println("B2 .. quad-to p0-p1-p2"); } + + // s = new QuadCurve2D.Float( point.x, point.y, p1.x, p1.y, p2.x, p2.y); + // gp.quadTo(p1.x, p1.y, p2.x, p2.y); + addShapeQuadTo(shape, vertexFactory, p1, p2); + offset+=2; + } else { + if (null != p3 && p3.onCurve) { + // Branch-3: point.onCurve && !p1.onCurve && !p2.onCurve && p3.onCurve + if( DEBUG ) { System.err.println("B3 .. 2-quad p0-p1-p1_2, p1_2-p2-p3 **** 2QUAD"); } + // addShapeCubicTo(shape, vertexFactory, p1, p2, p3); + addShapeQuadTo(shape, vertexFactory, p1, + midValue(p1.x, p2.x), + midValue(p1.y, p2.y), true); + addShapeQuadTo(shape, vertexFactory, p2, p3); + offset+=3; + } else { + // Branch-4: point.onCurve && !p1.onCurve && !p2.onCurve && !p3.onCurve + if( DEBUG ) { System.err.println("B4 .. quad-to p0-p1-p2h **** MID"); } + + // s = new QuadCurve2D.Float(point.x,point.y,p1.x,p1.y, + // midValue(p1.x, p2.x), midValue(p1.y, p2.y)); + // gp.quadTo(p1.x, p1.y, midValue(p1.x, p2.x), midValue(p1.y, p2.y)); + addShapeQuadTo(shape, vertexFactory, p1, + midValue(p1.x, p2.x), + midValue(p1.y, p2.y), true); + offset+=2; // Skip p2 as done in Typecast + } + } + } } else { - // s = new QuadCurve2D.Float(point.x,point.y,point_plus1.x,point_plus1.y, - // midValue(point_plus1.x, point_plus2.x), midValue(point_plus1.y, point_plus2.y)); - gp.quadTo(point_plus1.x, point_plus1.y, midValue(point_plus1.x, point_plus2.x), midValue(point_plus1.y, point_plus2.y)); - offset+=2; + if (!p1.onCurve) { + // Branch-5: !point.onCurve && !p1.onCurve + if( DEBUG ) { System.err.println("B5 .. quad-to pMh-p0-p1h ***** MID"); } + // s = new QuadCurve2D.Float(midValue(pM.x, point.x), midValue(pM.y, point.y), + // point.x, point.y, + // midValue(point.x, p1.x), midValue(point.y, p1.y)); + addShapeQuadTo(shape, vertexFactory, p0, + midValue(p0.x, p1.x), midValue(p0.y, p1.y), true); + offset++; + } else { + // Branch-6: !point.onCurve && p1.onCurve + if( DEBUG ) { System.err.println("B6 .. quad-to pMh-p0-p1"); } + // s = new QuadCurve2D.Float(midValue(pM.x, point.x), midValue(pM.y, point.y), + // point.x, point.y, p1.x, p1.y); + // gp.quadTo(point.x, point.y, p1.x, p1.y); + addShapeQuadTo(shape, vertexFactory, p0, p1); + offset++; + } } } - } else { - if (point_plus1.onCurve) { - // s = new QuadCurve2D.Float(midValue(point_minus1.x, point.x), midValue(point_minus1.y, point.y), - // point.x, point.y, point_plus1.x, point_plus1.y); - //gp.curve3(point_plus1.x, point_plus1.y, point.x, point.y); - gp.quadTo(point.x, point.y, point_plus1.x, point_plus1.y); - offset++; - - } else { - // s = new QuadCurve2D.Float(midValue(point_minus1.x, point.x), midValue(point_minus1.y, point.y), point.x, point.y, - // midValue(point.x, point_plus1.x), midValue(point.y, point_plus1.y)); - //gp.curve3(midValue(point.x, point_plus1.x), midValue(point.y, point_plus1.y), point.x, point.y); - gp.quadTo(point.x, point.y, midValue(point.x, point_plus1.x), midValue(point.y, point_plus1.y)); - offset++; - } + shape.closeLastOutline(false); + startIndex = i + 1; + count = 0; } } } - private static int midValue(int a, int b) { - return a + (b - a)/2; + private static float midValue(final float a, final float b) { + return a + (b - a)/2f; } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/Disassembler.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/Disassembler.java index b5535758d..181f77ee4 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/Disassembler.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/Disassembler.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot; @@ -22,7 +22,7 @@ public class Disassembler { * @param ip The current instruction pointer * @return The new instruction pointer */ - public static int advanceIP(short[] instructions, int ip) { + public static int advanceIP(final short[] instructions, int ip) { // The high word specifies font, cvt, or glyph program int i = ip & 0xffff; @@ -46,8 +46,8 @@ public class Disassembler { return ip; } - public static short getPushCount(short[] instructions, int ip) { - short instr = instructions[ip & 0xffff]; + public static short getPushCount(final short[] instructions, final int ip) { + final short instr = instructions[ip & 0xffff]; if ((Mnemonic.NPUSHB == instr) || (Mnemonic.NPUSHW == instr)) { return instructions[(ip & 0xffff) + 1]; } else if ((Mnemonic.PUSHB == (instr & 0xf8)) || (Mnemonic.PUSHW == (instr & 0xf8))) { @@ -56,11 +56,11 @@ public class Disassembler { return 0; } - public static int[] getPushData(short[] instructions, int ip) { - int count = getPushCount(instructions, ip); - int[] data = new int[count]; - int i = ip & 0xffff; - short instr = instructions[i]; + public static int[] getPushData(final short[] instructions, final int ip) { + final int count = getPushCount(instructions, ip); + final int[] data = new int[count]; + final int i = ip & 0xffff; + final short instr = instructions[i]; if (Mnemonic.NPUSHB == instr) { for (int j = 0; j < count; j++) { data[j] = instructions[i + j + 2]; @@ -81,8 +81,8 @@ public class Disassembler { return data; } - public static String disassemble(short[] instructions, int leadingSpaces) { - StringBuilder sb = new StringBuilder(); + public static String disassemble(final short[] instructions, final int leadingSpaces) { + final StringBuilder sb = new StringBuilder(); int ip = 0; while (ip < instructions.length) { for (int i = 0; i < leadingSpaces; i++) { @@ -91,7 +91,7 @@ public class Disassembler { sb.append(ip).append(": "); sb.append(Mnemonic.getMnemonic(instructions[ip])); if (getPushCount(instructions, ip) > 0) { - int[] data = getPushData(instructions, ip); + final int[] data = getPushData(instructions, ip); for(int j = 0; j < data.length; j++) { if ((instructions[ip] == Mnemonic.PUSHW) || (instructions[ip] == Mnemonic.NPUSHW)) { diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/Fixed.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/Fixed.java index ece0aae4b..14e83814c 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/Fixed.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/Fixed.java @@ -812,7 +812,7 @@ public class Fixed { * @param num Input * @return Output */ - public static int arctan( int num ) { + public static int arctan( final int num ) { return 0; } @@ -822,7 +822,7 @@ public class Fixed { * @param num The 26.6 fixed number in question * @return The resulting square root */ - public static int squareRoot(int num) { + public static int squareRoot(final int num) { int n = num; int divisor = num; int nSquared; @@ -840,13 +840,13 @@ public class Fixed { } return n; } - - public static float floatValue(long fixed) { + + public static float floatValue(final long fixed) { return (fixed >> 16) + (float)(fixed & 0xffff) / 0x10000; } - - public static float roundedFloatValue(long fixed, int decimalPlaces) { - int factor = 10 * decimalPlaces; + + public static float roundedFloatValue(final long fixed, final int decimalPlaces) { + final int factor = 10 * decimalPlaces; return (float)((int)(floatValue(fixed) * factor)) / factor; } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/Mnemonic.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/Mnemonic.java index 6b3dc1f6f..6df892d4d 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/Mnemonic.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/Mnemonic.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot; @@ -143,7 +143,7 @@ public class Mnemonic { * @param opcode The opcode for which the mnemonic is required * @return The mnemonic, with a description */ - public static String getMnemonic(short opcode) { + public static String getMnemonic(final short opcode) { if (opcode >= MIRP) return "MIRP["+((opcode&16)==0?"nrp0,":"srp0,")+((opcode&8)==0?"nmd,":"md,")+((opcode&4)==0?"nrd,":"rd,")+(opcode&3)+"]"; else if (opcode >= MDRP) return "MDRP["+((opcode&16)==0?"nrp0,":"srp0,")+((opcode&8)==0?"nmd,":"md,")+((opcode&4)==0?"nrd,":"rd,")+(opcode&3)+"]"; else if (opcode >= PUSHW) return "PUSHW["+((opcode&7)+1)+"]"; @@ -269,7 +269,7 @@ public class Mnemonic { else return "????"; } - public static String getComment(short opcode) { + public static String getComment(final short opcode) { if (opcode >= MIRP) return "MIRP["+((opcode&16)==0?"nrp0,":"srp0,")+((opcode&8)==0?"nmd,":"md,")+((opcode&4)==0?"nrd,":"rd,")+(opcode&3)+"]\t\tMove Indirect Relative Point"; else if (opcode >= MDRP) return "MDRP["+((opcode&16)==0?"nrp0,":"srp0,")+((opcode&8)==0?"nmd,":"md,")+((opcode&4)==0?"nrd,":"rd,")+(opcode&3)+"]\t\tMove Direct Relative Point"; else if (opcode >= PUSHW) return "PUSHW["+((opcode&7)+1)+"]"; diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/OTFont.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/OTFont.java index 8c14b7302..e83a428ed 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/OTFont.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/OTFont.java @@ -79,7 +79,7 @@ import jogamp.graph.font.typecast.ot.table.VheaTable; */ public class OTFont { - private OTFontCollection _fc; + private final OTFontCollection _fc; private TableDirectory _tableDirectory = null; private Table[] _tables; private Os2Table _os2; @@ -98,17 +98,17 @@ public class OTFont { /** * Constructor */ - public OTFont(OTFontCollection fc) { + public OTFont(final OTFontCollection fc) { _fc = fc; } - public StringBuilder getName(int nameIndex, StringBuilder sb) { + public StringBuilder getName(final int nameIndex, StringBuilder sb) { if(null == sb) { sb = new StringBuilder(); - } + } return _name.getRecordsRecordString(sb, nameIndex); } - - public StringBuilder getAllNames(StringBuilder sb, String separator) { + + public StringBuilder getAllNames(StringBuilder sb, final String separator) { if(null != _name) { if(null == sb) { sb = new StringBuilder(); @@ -117,10 +117,10 @@ public class OTFont { _name.getRecord(i).getRecordString(sb).append(separator); } } - return sb; + return sb; } - - public Table getTable(int tableType) { + + public Table getTable(final int tableType) { for (int i = 0; i < _tables.length; i++) { if ((_tables[i] != null) && (_tables[i].getType() == tableType)) { return _tables[i]; @@ -132,31 +132,31 @@ public class OTFont { public Os2Table getOS2Table() { return _os2; } - + public CmapTable getCmapTable() { return _cmap; } - + public HeadTable getHeadTable() { return _head; } - + public HheaTable getHheaTable() { return _hhea; } - + public HdmxTable getHdmxTable() { return _hdmx; } - + public HmtxTable getHmtxTable() { return _hmtx; } - + public LocaTable getLocaTable() { return _loca; } - + public MaxpTable getMaxpTable() { return _maxp; } @@ -185,9 +185,9 @@ public class OTFont { return _maxp.getNumGlyphs(); } - public OTGlyph getGlyph(int i) { - - final GlyfDescript _glyfDescr = _glyf.getDescription(i); + public OTGlyph getGlyph(final int i) { + + final GlyfDescript _glyfDescr = _glyf.getDescription(i); return (null != _glyfDescr) ? new OTGlyph( _glyfDescr, @@ -195,17 +195,17 @@ public class OTFont { _hmtx.getAdvanceWidth(i)) : null; } - + public TableDirectory getTableDirectory() { return _tableDirectory; } - + private Table readTable( - DataInputStream dis, - int tablesOrigin, - int tag) throws IOException { + final DataInputStream dis, + final int tablesOrigin, + final int tag) throws IOException { dis.reset(); - DirectoryEntry entry = _tableDirectory.getEntryByTag(tag); + final DirectoryEntry entry = _tableDirectory.getEntryByTag(tag); if (entry == null) { return null; } @@ -225,16 +225,16 @@ public class OTFont { * individual font resource data. */ protected void read( - DataInputStream dis, - int directoryOffset, - int tablesOrigin) throws IOException { - + final DataInputStream dis, + final int directoryOffset, + final int tablesOrigin) throws IOException { + // Load the table directory dis.reset(); dis.skip(directoryOffset); _tableDirectory = new TableDirectory(dis); _tables = new Table[_tableDirectory.getNumTables()]; - + // Load some prerequisite tables _head = (HeadTable) readTable(dis, tablesOrigin, Table.head); _hhea = (HheaTable) readTable(dis, tablesOrigin, Table.hhea); @@ -252,10 +252,10 @@ public class OTFont { if (_vhea != null) { _tables[index++] = _vhea; } - + // Load all other tables for (int i = 0; i < _tableDirectory.getNumTables(); i++) { - DirectoryEntry entry = _tableDirectory.getEntry(i); + final DirectoryEntry entry = _tableDirectory.getEntry(i); if (entry.getTag() == Table.head || entry.getTag() == Table.hhea || entry.getTag() == Table.maxp @@ -283,6 +283,7 @@ public class OTFont { _glyf = (GlyfTable) getTable(Table.glyf); } + @Override public String toString() { if (_tableDirectory != null) { return _tableDirectory.toString(); diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/OTFontCollection.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/OTFontCollection.java index 4a041604d..ed07cb30a 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/OTFontCollection.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/OTFontCollection.java @@ -25,6 +25,7 @@ import java.io.BufferedInputStream; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; @@ -48,7 +49,7 @@ public class OTFontCollection { private String _fileName; private TTCHeader _ttcHeader; private OTFont[] _fonts; - private ArrayList<Table> _tables = new ArrayList<Table>(); + private final ArrayList<Table> _tables = new ArrayList<Table>(); private boolean _resourceFork = false; /** Creates new FontCollection */ @@ -58,12 +59,22 @@ public class OTFontCollection { /** * @param file The OpenType font file */ - public static OTFontCollection create(File file) throws IOException { - OTFontCollection fc = new OTFontCollection(); + public static OTFontCollection create(final File file) throws IOException { + final OTFontCollection fc = new OTFontCollection(); fc.read(file); return fc; } + /** + * @param istream The OpenType font input stream + * @param streamLen the length of the OpenType font segment in the stream + */ + public static OTFontCollection create(final InputStream istream, final int streamLen) throws IOException { + final OTFontCollection fc = new OTFontCollection(); + fc.read(istream, streamLen); + return fc; + } + public String getPathName() { return _pathName; } @@ -72,21 +83,21 @@ public class OTFontCollection { return _fileName; } - public OTFont getFont(int i) { + public OTFont getFont(final int i) { return _fonts[i]; } - + public int getFontCount() { return _fonts.length; } - + public TTCHeader getTtcHeader() { return _ttcHeader; } - public Table getTable(DirectoryEntry de) { + public Table getTable(final DirectoryEntry de) { for (int i = 0; i < _tables.size(); i++) { - Table table = _tables.get(i); + final Table table = _tables.get(i); if ((table.getDirectoryEntry().getTag() == de.getTag()) && (table.getDirectoryEntry().getOffset() == de.getOffset())) { return table; @@ -95,7 +106,7 @@ public class OTFontCollection { return null; } - public void addTable(Table table) { + public void addTable(final Table table) { _tables.add(table); } @@ -119,31 +130,59 @@ public class OTFontCollection { } _resourceFork = true; } + final int streamLen = (int) file.length(); + final BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file), streamLen); + try { + readImpl(bis, streamLen); + } finally { + bis.close(); + } + } - DataInputStream dis = new DataInputStream( - new BufferedInputStream( - new FileInputStream(file), (int) file.length())); - dis.mark((int) file.length()); + /** + * @param is The OpenType font stream + * @param streamLen the length of the OpenType font segment in the stream + */ + protected void read(final InputStream is, final int streamLen) throws IOException { + _pathName = ""; + _fileName = ""; + final InputStream bis; + if( is.markSupported() ) { + bis = is; + } else { + bis = new BufferedInputStream(is, streamLen); + } + readImpl(bis, streamLen); + } + /** + * @param is The OpenType font stream, must {@link InputStream#markSupported() support mark}! + */ + private void readImpl(final InputStream bis, final int streamLen) throws IOException { + if( !bis.markSupported() ) { + throw new IllegalArgumentException("stream of type "+bis.getClass().getName()+" doesn't support mark"); + } + bis.mark(streamLen); + final DataInputStream dis = new DataInputStream(bis); if (_resourceFork || _pathName.endsWith(".dfont")) { // This is a Macintosh font suitcase resource - ResourceHeader resourceHeader = new ResourceHeader(dis); + final ResourceHeader resourceHeader = new ResourceHeader(dis); // Seek to the map offset and read the map dis.reset(); dis.skip(resourceHeader.getMapOffset()); - ResourceMap map = new ResourceMap(dis); + final ResourceMap map = new ResourceMap(dis); // Get the 'sfnt' resources - ResourceType resourceType = map.getResourceType("sfnt"); + final ResourceType resourceType = map.getResourceType("sfnt"); // Load the font data _fonts = new OTFont[resourceType.getCount()]; for (int i = 0; i < resourceType.getCount(); i++) { - ResourceReference resourceReference = resourceType.getReference(i); + final ResourceReference resourceReference = resourceType.getReference(i); _fonts[i] = new OTFont(this); - int offset = resourceHeader.getDataOffset() + + final int offset = resourceHeader.getDataOffset() + resourceReference.getDataOffset() + 4; _fonts[i].read(dis, offset, offset); } @@ -165,6 +204,5 @@ public class OTFontCollection { _fonts[0] = new OTFont(this); _fonts[0].read(dis, 0, 0); } - dis.close(); } } 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 5c004246a..8ed450326 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/OTGlyph.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/OTGlyph.java @@ -56,7 +56,7 @@ import jogamp.graph.font.typecast.ot.table.GlyfDescript; import jogamp.graph.font.typecast.ot.table.GlyphDescription; import jogamp.graph.font.typecast.t2.T2Interpreter; -import com.jogamp.graph.geom.AABBox; +import com.jogamp.opengl.math.geom.AABBox; @@ -65,10 +65,10 @@ import com.jogamp.graph.geom.AABBox; * @version $Id: Glyph.java,v 1.3 2007-02-21 12:23:54 davidsch Exp $ * @author <a href="mailto:[email protected]">David Schweinsberg</a>, Sven Gothel */ -public class OTGlyph { +public final class OTGlyph { - protected short _leftSideBearing; - protected int _advanceWidth; + private final short _leftSideBearing; + private final int _advanceWidth; private Point[] _points; AABBox _bbox; @@ -79,7 +79,7 @@ public class OTGlyph { * @param lsb The Left Side Bearing. * @param advance The advance width. */ - public OTGlyph(GlyphDescription gd, short lsb, int advance) { + public OTGlyph(final GlyphDescription gd, final short lsb, final int advance) { _leftSideBearing = lsb; _advanceWidth = advance; describe(gd); @@ -91,47 +91,44 @@ public class OTGlyph { * @param lsb The Left Side Bearing. * @param advance The advance width. */ - public OTGlyph(Charstring cs, short lsb, int advance) { + public OTGlyph(final Charstring cs, final short lsb, final int advance) { _leftSideBearing = lsb; _advanceWidth = advance; if (cs instanceof CharstringType2) { - T2Interpreter t2i = new T2Interpreter(); + final T2Interpreter t2i = new T2Interpreter(); _points = t2i.execute((CharstringType2) cs); } else { //throw unsupported charstring type } } - public AABBox getBBox() { - return _bbox; + public final void clearPointData() { + _points = null; } - - public int getAdvanceWidth() { + + public final AABBox getBBox() { + return _bbox; + } + + public final int getAdvanceWidth() { return _advanceWidth; } - public short getLeftSideBearing() { + public final short getLeftSideBearing() { return _leftSideBearing; } - public Point getPoint(int i) { + public final Point getPoint(final int i) { return _points[i]; } - public int getPointCount() { - return _points.length; - } - - /** - * Resets the glyph to the TrueType table settings - */ - public void reset() { + public final int getPointCount() { + return null != _points ? _points.length : 0; } /** * @param factor a 16.16 fixed value - */ - public void scale(int factor) { + public void scale(final int factor) { for (int i = 0; i < _points.length; i++) { //points[i].x = ( points[i].x * factor ) >> 6; //points[i].y = ( points[i].y * factor ) >> 6; @@ -141,15 +138,16 @@ public class OTGlyph { _leftSideBearing = (short)(( _leftSideBearing * factor) >> 6); _advanceWidth = (_advanceWidth * factor) >> 6; } + */ /** * Set the points of a glyph from the GlyphDescription */ - private void describe(GlyphDescription gd) { + private final void describe(final GlyphDescription gd) { int endPtIndex = 0; _points = new Point[gd.getPointCount() /* + 2 */ ]; for (int i = 0; i < gd.getPointCount(); i++) { - boolean endPt = gd.getEndPtOfContours(endPtIndex) == i; + final boolean endPt = gd.getEndPtOfContours(endPtIndex) == i; if (endPt) { endPtIndex++; } @@ -163,7 +161,7 @@ public class OTGlyph { // Append the origin and advanceWidth points (n & n+1) // _points[gd.getPointCount()] = new Point(0, 0, true, true); // _points[gd.getPointCount()+1] = new Point(_advanceWidth, 0, true, true); - + _bbox = new AABBox(gd.getXMinimum(), gd.getYMinimum(), 0, gd.getXMaximum(), gd.getYMaximum(), 0); } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/Point.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/Point.java index f1a090d68..76b0f90f3 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/Point.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/Point.java @@ -18,12 +18,15 @@ public class Point { public int y = 0; public boolean onCurve = true; public boolean endOfContour = false; - public boolean touched = false; - public Point(int x, int y, boolean onCurve, boolean endOfContour) { + public Point(final int x, final int y, final boolean onCurve, final boolean endOfContour) { this.x = x; this.y = y; this.onCurve = onCurve; this.endOfContour = endOfContour; } + + public String toString() { + return "P["+x+"/"+y+", on "+onCurve+", end "+endOfContour+"]"; + } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceData.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceData.java index 433ff6051..709ff9e91 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceData.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceData.java @@ -30,11 +30,11 @@ import java.io.IOException; */ public class ResourceData { - private byte[] data; - + private final byte[] data; + /** Creates new ResourceData */ - public ResourceData(DataInput di) throws IOException { - int dataLen = di.readInt(); + public ResourceData(final DataInput di) throws IOException { + final int dataLen = di.readInt(); data = new byte[dataLen]; di.readFully(data); } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceFile.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceFile.java index 2ada22c82..767eafb6b 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceFile.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceFile.java @@ -31,16 +31,16 @@ import java.io.RandomAccessFile; */ public class ResourceFile { - private ResourceHeader header; - private ResourceMap map; - + private final ResourceHeader header; + private final ResourceMap map; + /** Creates new Resource */ - public ResourceFile(RandomAccessFile raf) throws IOException { + public ResourceFile(final RandomAccessFile raf) throws IOException { // Read header at the beginning of the file raf.seek(0); header = new ResourceHeader(raf); - + // Seek to the map offset and read the map raf.seek(header.getMapOffset()); map = new ResourceMap(raf); @@ -50,27 +50,27 @@ public class ResourceFile { return map; } - public static void main(String[] args) { + public static void main(final String[] args) { try { //RandomAccessFile raf = new RandomAccessFile("/Library/Fonts/GillSans.dfont", "r"); - + // Tests loading a font from a resource fork on Mac OS X - RandomAccessFile raf = new RandomAccessFile("/Library/Fonts/Georgia/..namedfork/rsrc", "r"); - ResourceFile resource = new ResourceFile(raf); + final RandomAccessFile raf = new RandomAccessFile("/Library/Fonts/Georgia/..namedfork/rsrc", "r"); + final ResourceFile resource = new ResourceFile(raf); for (int i = 0; i < resource.getResourceMap().getResourceTypeCount(); i++) { System.out.println(resource.getResourceMap().getResourceType(i).getTypeAsString()); } - + // Get the first 'sfnt' resource ResourceType type = resource.getResourceMap().getResourceType("sfnt"); ResourceReference reference = type.getReference(0); - + type = resource.getResourceMap().getResourceType("FOND"); for (int i = 0; i < type.getCount(); ++i) { reference = type.getReference(i); System.out.println(reference.getName()); } - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceHeader.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceHeader.java index 8f5224632..dea0b9843 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceHeader.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceHeader.java @@ -30,13 +30,13 @@ import java.io.IOException; */ public class ResourceHeader { - private int dataOffset; - private int mapOffset; - private int dataLen; - private int mapLen; + private final int dataOffset; + private final int mapOffset; + private final int dataLen; + private final int mapLen; /** Creates new ResourceHeader */ - public ResourceHeader(DataInput di) throws IOException { + public ResourceHeader(final DataInput di) throws IOException { dataOffset = di.readInt(); mapOffset = di.readInt(); dataLen = di.readInt(); @@ -46,15 +46,15 @@ public class ResourceHeader { public int getDataOffset() { return dataOffset; } - + public int getMapOffset() { return mapOffset; } - + public int getDataLength() { return dataLen; } - + public int getMapLength() { return mapLen; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceMap.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceMap.java index 96ba06087..781e0adf3 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceMap.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceMap.java @@ -30,42 +30,41 @@ import java.io.IOException; */ public class ResourceMap { - private byte[] headerCopy = new byte[16]; - private int nextResourceMap; - private int fileReferenceNumber; - private int attributes; - private ResourceType[] types; - + private final byte[] headerCopy = new byte[16]; + // private final int nextResourceMap; + // private final int fileReferenceNumber; + // private final int attributes; + private final ResourceType[] types; + /** Creates new ResourceMap */ - public ResourceMap(DataInput di) throws IOException { + public ResourceMap(final DataInput di) throws IOException { di.readFully(headerCopy); - nextResourceMap = di.readInt(); - fileReferenceNumber = di.readUnsignedShort(); - attributes = di.readUnsignedShort(); - int typeOffset = di.readUnsignedShort(); - int nameOffset = di.readUnsignedShort(); - int typeCount = di.readUnsignedShort() + 1; - + /* nextResourceMap = */ di.readInt(); + /* fileReferenceNumber = */ di.readUnsignedShort(); + /* attributes = */ di.readUnsignedShort(); + /* final int typeOffset = */ di.readUnsignedShort(); + /* final int nameOffset = */ di.readUnsignedShort(); + final int typeCount = di.readUnsignedShort() + 1; + // Read types types = new ResourceType[typeCount]; for (int i = 0; i < typeCount; i++) { types[i] = new ResourceType(di); } - + // Read the references for (int i = 0; i < typeCount; i++) { types[i].readRefs(di); } - + // Read the names for (int i = 0; i < typeCount; i++) { types[i].readNames(di); } } - public ResourceType getResourceType(String typeName) { + public ResourceType getResourceType(final String typeName) { for (int i = 0; i < types.length; i++) { - String s = types[i].getTypeAsString(); if (types[i].getTypeAsString().equals(typeName)) { return types[i]; } @@ -73,10 +72,10 @@ public class ResourceMap { return null; } - public ResourceType getResourceType(int i) { + public ResourceType getResourceType(final int i) { return types[i]; } - + public int getResourceTypeCount() { return types.length; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceReference.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceReference.java index fd7ec46b2..f76b85cf4 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceReference.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceReference.java @@ -30,15 +30,15 @@ import java.io.IOException; */ public class ResourceReference { - private int id; - private short nameOffset; - private short attributes; - private int dataOffset; - private int handle; + private final int id; + private final short nameOffset; + private final short attributes; + private final int dataOffset; + private final int handle; private String name; - + /** Creates new ResourceReference */ - protected ResourceReference(DataInput di) throws IOException { + protected ResourceReference(final DataInput di) throws IOException { id = di.readUnsignedShort(); nameOffset = di.readShort(); attributes = (short) di.readUnsignedByte(); @@ -46,10 +46,10 @@ public class ResourceReference { handle = di.readInt(); } - protected void readName(DataInput di) throws IOException { + protected void readName(final DataInput di) throws IOException { if (nameOffset > -1) { - int len = di.readUnsignedByte(); - byte[] buf = new byte[len]; + final int len = di.readUnsignedByte(); + final byte[] buf = new byte[len]; di.readFully(buf); name = new String(buf); } @@ -58,23 +58,23 @@ public class ResourceReference { public int getId() { return id; } - + public short getNameOffset() { return nameOffset; } - + public short getAttributes() { return attributes; } - + public int getDataOffset() { return dataOffset; } - + public int getHandle() { return handle; } - + public String getName() { return name; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceType.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceType.java index 1c7e24c0f..903fe1a48 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceType.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/mac/ResourceType.java @@ -30,26 +30,26 @@ import java.io.IOException; */ public class ResourceType { - private int type; - private int count; - private int offset; - private ResourceReference[] references; - + private final int type; + private final int count; + private final int offset; + private final ResourceReference[] references; + /** Creates new ResourceType */ - protected ResourceType(DataInput di) throws IOException { + protected ResourceType(final DataInput di) throws IOException { type = di.readInt(); count = di.readUnsignedShort() + 1; offset = di.readUnsignedShort(); references = new ResourceReference[count]; } - - protected void readRefs(DataInput di) throws IOException { + + protected void readRefs(final DataInput di) throws IOException { for (int i = 0; i < count; i++) { references[i] = new ResourceReference(di); } } - protected void readNames(DataInput di) throws IOException { + protected void readNames(final DataInput di) throws IOException { for (int i = 0; i < count; i++) { references[i].readName(di); } @@ -58,7 +58,7 @@ public class ResourceType { public int getType() { return type; } - + public String getTypeAsString() { return new StringBuilder() .append((char)((type>>24)&0xff)) @@ -67,16 +67,16 @@ public class ResourceType { .append((char)((type)&0xff)) .toString(); } - + public int getCount() { return count; } - + public int getOffset() { return offset; } - public ResourceReference getReference(int i) { + public ResourceReference getReference(final int i) { return references[i]; } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/BaseTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/BaseTable.java index ed615eb72..002f83e9b 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/BaseTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/BaseTable.java @@ -31,98 +31,104 @@ import java.io.IOException; * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class BaseTable implements Table { - - private abstract class BaseCoord { - public abstract int getBaseCoordFormat(); - - public abstract short getCoordinate(); + abstract class BaseCoord { + + abstract int getBaseCoordFormat(); + + abstract short getCoordinate(); } - - private class BaseCoordFormat1 extends BaseCoord { - private short _coordinate; - - protected BaseCoordFormat1(DataInput di) throws IOException { + class BaseCoordFormat1 extends BaseCoord { + + private final short _coordinate; + + protected BaseCoordFormat1(final DataInput di) throws IOException { _coordinate = di.readShort(); } - public int getBaseCoordFormat() { + @Override + int getBaseCoordFormat() { return 1; } - - public short getCoordinate() { + + @Override + short getCoordinate() { return _coordinate; } - + } - - private class BaseCoordFormat2 extends BaseCoord { - - private short _coordinate; - private int _referenceGlyph; - private int _baseCoordPoint; - - protected BaseCoordFormat2(DataInput di) throws IOException { + + class BaseCoordFormat2 extends BaseCoord { + + private final short _coordinate; + // private final int _referenceGlyph; + // private final int _baseCoordPoint; + + protected BaseCoordFormat2(final DataInput di) throws IOException { _coordinate = di.readShort(); - _referenceGlyph = di.readUnsignedShort(); - _baseCoordPoint = di.readUnsignedShort(); + /* _referenceGlyph = */ di.readUnsignedShort(); + /* _baseCoordPoint = */ di.readUnsignedShort(); } - public int getBaseCoordFormat() { + @Override + int getBaseCoordFormat() { return 2; } - - public short getCoordinate() { + + @Override + short getCoordinate() { return _coordinate; } - + } - - private class BaseCoordFormat3 extends BaseCoord { - private short _coordinate; - private int _deviceTableOffset; - - protected BaseCoordFormat3(DataInput di) throws IOException { + class BaseCoordFormat3 extends BaseCoord { + + private final short _coordinate; + // private final int _deviceTableOffset; + + protected BaseCoordFormat3(final DataInput di) throws IOException { _coordinate = di.readShort(); - _deviceTableOffset = di.readUnsignedShort(); + /* _deviceTableOffset = */ di.readUnsignedShort(); } - public int getBaseCoordFormat() { + @Override + int getBaseCoordFormat() { return 2; } - - public short getCoordinate() { + + @Override + short getCoordinate() { return _coordinate; } - + } - - private class FeatMinMaxRecord { - - private int _tag; - private int _minCoordOffset; - private int _maxCoordOffset; - - protected FeatMinMaxRecord(DataInput di) throws IOException { - _tag = di.readInt(); - _minCoordOffset = di.readUnsignedShort(); - _maxCoordOffset = di.readUnsignedShort(); + + static class FeatMinMaxRecord { + + // private final int _tag; + // private final int _minCoordOffset; + // private final int _maxCoordOffset; + + protected FeatMinMaxRecord(final DataInput di) throws IOException { + /* _tag = */ di.readInt(); + /* _minCoordOffset = */ di.readUnsignedShort(); + /* _maxCoordOffset = */ di.readUnsignedShort(); } } - - private class MinMax { - - private int _minCoordOffset; - private int _maxCoordOffset; - private int _featMinMaxCount; - private FeatMinMaxRecord[] _featMinMaxRecord; - - protected MinMax(int minMaxOffset) throws IOException { - DataInput di = getDataInputForOffset(minMaxOffset); - _minCoordOffset = di.readUnsignedShort(); - _maxCoordOffset = di.readUnsignedShort(); + + class MinMax { + + // private final int _minCoordOffset; + // private final int _maxCoordOffset; + private final int _featMinMaxCount; + private final FeatMinMaxRecord[] _featMinMaxRecord; + + protected MinMax(final int minMaxOffset) throws IOException { + final DataInput di = getDataInputForOffset(minMaxOffset); + /* _minCoordOffset = */ di.readUnsignedShort(); + /* _maxCoordOffset = */ di.readUnsignedShort(); _featMinMaxCount = di.readUnsignedShort(); _featMinMaxRecord = new FeatMinMaxRecord[_featMinMaxCount]; for (int i = 0; i < _featMinMaxCount; ++i) { @@ -130,17 +136,17 @@ public class BaseTable implements Table { } } } - - private class BaseValues { - - private int _defaultIndex; - private int _baseCoordCount; - private int[] _baseCoordOffset; - private BaseCoord[] _baseCoords; - - protected BaseValues(int baseValuesOffset) throws IOException { - DataInput di = getDataInputForOffset(baseValuesOffset); - _defaultIndex = di.readUnsignedShort(); + + class BaseValues { + + // private final int _defaultIndex; + private final int _baseCoordCount; + private final int[] _baseCoordOffset; + private final BaseCoord[] _baseCoords; + + protected BaseValues(final int baseValuesOffset) throws IOException { + final DataInput di = getDataInputForOffset(baseValuesOffset); + /* _defaultIndex = */ di.readUnsignedShort(); _baseCoordCount = di.readUnsignedShort(); _baseCoordOffset = new int[_baseCoordCount]; for (int i = 0; i < _baseCoordCount; ++i) { @@ -148,7 +154,7 @@ public class BaseTable implements Table { } _baseCoords = new BaseCoord[_baseCoordCount]; for (int i = 0; i < _baseCoordCount; ++i) { - int format = di.readUnsignedShort(); + final int format = di.readUnsignedShort(); switch (format) { case 1: _baseCoords[i] = new BaseCoordFormat1(di); @@ -163,39 +169,40 @@ public class BaseTable implements Table { } } } - - private class BaseLangSysRecord { - - private int _baseLangSysTag; - private int _minMaxOffset; - - protected BaseLangSysRecord(DataInput di) throws IOException { - _baseLangSysTag = di.readInt(); + + static class BaseLangSysRecord { + + // private final int _baseLangSysTag; + private final int _minMaxOffset; + + protected BaseLangSysRecord(final DataInput di) throws IOException { + /* _baseLangSysTag = */ di.readInt(); _minMaxOffset = di.readUnsignedShort(); } - public int getBaseLangSysTag() { + /** + int getBaseLangSysTag() { return _baseLangSysTag; - } - - public int getMinMaxOffset() { + } */ + + int getMinMaxOffset() { return _minMaxOffset; } } - - private class BaseScript { - - private int _thisOffset; - private int _baseValuesOffset; - private int _defaultMinMaxOffset; - private int _baseLangSysCount; - private BaseLangSysRecord[] _baseLangSysRecord; + + class BaseScript { + + private final int _thisOffset; + private final int _baseValuesOffset; + private final int _defaultMinMaxOffset; + private final int _baseLangSysCount; + private final BaseLangSysRecord[] _baseLangSysRecord; private BaseValues _baseValues; private MinMax[] _minMax; - - protected BaseScript(int baseScriptOffset) throws IOException { + + protected BaseScript(final int baseScriptOffset) throws IOException { _thisOffset = baseScriptOffset; - DataInput di = getDataInputForOffset(baseScriptOffset); + final DataInput di = getDataInputForOffset(baseScriptOffset); _baseValuesOffset = di.readUnsignedShort(); _defaultMinMaxOffset = di.readUnsignedShort(); _baseLangSysCount = di.readUnsignedShort(); @@ -211,8 +218,9 @@ public class BaseTable implements Table { } } + @Override public String toString() { - StringBuilder sb = new StringBuilder() + final StringBuilder sb = new StringBuilder() .append("\nBaseScript BaseScriptT").append(Integer.toHexString(_thisOffset)) .append("\nBaseValuesT").append(Integer.toHexString(_thisOffset + _baseValuesOffset)) .append("\nMinMaxT").append(Integer.toHexString(_thisOffset + _defaultMinMaxOffset)) @@ -231,36 +239,36 @@ public class BaseTable implements Table { return sb.toString(); } } - - private class BaseScriptRecord { - - private int _baseScriptTag; - private int _baseScriptOffset; - protected BaseScriptRecord(DataInput di) throws IOException { + static class BaseScriptRecord { + + private final int _baseScriptTag; + private final int _baseScriptOffset; + + protected BaseScriptRecord(final DataInput di) throws IOException { _baseScriptTag = di.readInt(); _baseScriptOffset = di.readUnsignedShort(); } - public int getBaseScriptTag() { + int getBaseScriptTag() { return _baseScriptTag; } - - public int getBaseScriptOffset() { + + int getBaseScriptOffset() { return _baseScriptOffset; } } - - private class BaseScriptList { - - private int _thisOffset; - private int _baseScriptCount; - private BaseScriptRecord[] _baseScriptRecord; - private BaseScript[] _baseScripts; - - protected BaseScriptList(int baseScriptListOffset) throws IOException { + + class BaseScriptList { + + private final int _thisOffset; + private final int _baseScriptCount; + private final BaseScriptRecord[] _baseScriptRecord; + private final BaseScript[] _baseScripts; + + protected BaseScriptList(final int baseScriptListOffset) throws IOException { _thisOffset = baseScriptListOffset; - DataInput di = getDataInputForOffset(baseScriptListOffset); + final DataInput di = getDataInputForOffset(baseScriptListOffset); _baseScriptCount = di.readUnsignedShort(); _baseScriptRecord = new BaseScriptRecord[_baseScriptCount]; for (int i = 0; i < _baseScriptCount; ++i) { @@ -273,8 +281,9 @@ public class BaseTable implements Table { } } + @Override public String toString() { - StringBuilder sb = new StringBuilder() + final StringBuilder sb = new StringBuilder() .append("\nBaseScriptList BaseScriptListT").append(Integer.toHexString(_thisOffset)) .append("\n").append(Integer.toHexString(_baseScriptCount)); for (int i = 0; i < _baseScriptCount; ++i) { @@ -288,16 +297,16 @@ public class BaseTable implements Table { return sb.toString(); } } - - private class BaseTagList { - - private int _thisOffset; - private int _baseTagCount; - private int[] _baselineTag; - - protected BaseTagList(int baseTagListOffset) throws IOException { + + class BaseTagList { + + private final int _thisOffset; + private final int _baseTagCount; + private final int[] _baselineTag; + + protected BaseTagList(final int baseTagListOffset) throws IOException { _thisOffset = baseTagListOffset; - DataInput di = getDataInputForOffset(baseTagListOffset); + final DataInput di = getDataInputForOffset(baseTagListOffset); _baseTagCount = di.readUnsignedShort(); _baselineTag = new int[_baseTagCount]; for (int i = 0; i < _baseTagCount; ++i) { @@ -305,8 +314,9 @@ public class BaseTable implements Table { } } + @Override public String toString() { - StringBuilder sb = new StringBuilder() + final StringBuilder sb = new StringBuilder() .append("\nBaseTagList BaseTagListT").append(Integer.toHexString(_thisOffset)) .append("\n").append(Integer.toHexString(_baseTagCount)); for (int i = 0; i < _baseTagCount; ++i) { @@ -315,18 +325,18 @@ public class BaseTable implements Table { return sb.toString(); } } - - private class Axis { - - private int _thisOffset; - private int _baseTagListOffset; - private int _baseScriptListOffset; + + class Axis { + + private final int _thisOffset; + private final int _baseTagListOffset; + private final int _baseScriptListOffset; private BaseTagList _baseTagList; private BaseScriptList _baseScriptList; - protected Axis(int axisOffset) throws IOException { + protected Axis(final int axisOffset) throws IOException { _thisOffset = axisOffset; - DataInput di = getDataInputForOffset(axisOffset); + final DataInput di = getDataInputForOffset(axisOffset); _baseTagListOffset = di.readUnsignedShort(); _baseScriptListOffset = di.readUnsignedShort(); if (_baseTagListOffset != 0) { @@ -338,6 +348,7 @@ public class BaseTable implements Table { } } + @Override public String toString() { return new StringBuilder() .append("\nAxis AxisT").append(Integer.toHexString(_thisOffset)) @@ -348,23 +359,23 @@ public class BaseTable implements Table { .toString(); } } - - private DirectoryEntry _de; - private int _version; - private int _horizAxisOffset; - private int _vertAxisOffset; + + private final DirectoryEntry _de; + private final int _version; + private final int _horizAxisOffset; + private final int _vertAxisOffset; private Axis _horizAxis; private Axis _vertAxis; private byte[] _buf; /** Creates a new instance of BaseTable */ - protected BaseTable(DirectoryEntry de, DataInput di) throws IOException { + protected BaseTable(final DirectoryEntry de, final DataInput di) throws IOException { _de = (DirectoryEntry) de.clone(); // Load entire table into a buffer, and create another input stream _buf = new byte[de.getLength()]; di.readFully(_buf); - DataInput di2 = getDataInputForOffset(0); + final DataInput di2 = getDataInputForOffset(0); _version = di2.readInt(); _horizAxisOffset = di2.readUnsignedShort(); @@ -375,40 +386,42 @@ public class BaseTable implements Table { if (_vertAxisOffset != 0) { _vertAxis = new Axis(_vertAxisOffset); } - + // Let go of the buffer _buf = null; } - - private DataInput getDataInputForOffset(int offset) { + + private DataInput getDataInputForOffset(final int offset) { return new DataInputStream(new ByteArrayInputStream( _buf, offset, _de.getLength() - offset)); } - + // private String valueAsShortHex(int value) { // return String.format("%1$4x", value); // } -// +// // private String valueAsLongHex(int value) { // return String.format("%1$8x", value); // } - - static protected String tagAsString(int tag) { - char[] c = new char[4]; + + static protected String tagAsString(final int tag) { + final char[] c = new char[4]; c[0] = (char)((tag >> 24) & 0xff); c[1] = (char)((tag >> 16) & 0xff); c[2] = (char)((tag >> 8) & 0xff); c[3] = (char)(tag & 0xff); return String.valueOf(c); } - + + @Override public int getType() { return BASE; } + @Override public String toString() { - StringBuilder sb = new StringBuilder() + final StringBuilder sb = new StringBuilder() .append("; 'BASE' Table - Baseline\n;-------------------------------------\n\n") .append("BASEHeader BASEHeaderT").append(Integer.toHexString(0)) .append("\n").append(Integer.toHexString(_version)) @@ -422,13 +435,14 @@ public class BaseTable implements Table { } return sb.toString(); } - + /** * Get a directory entry for this table. This uniquely identifies the * table in collections where there may be more than one instance of a * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return _de; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CffTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CffTable.java index 966f6e17b..d6643f26d 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CffTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CffTable.java @@ -36,27 +36,27 @@ import java.util.Hashtable; * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class CffTable implements Table { - - public class Dict { - - private Dictionary<Integer, Object> _entries = new Hashtable<Integer, Object>(); - private int[] _data; + + public static class Dict { + + private final Dictionary<Integer, Object> _entries = new Hashtable<Integer, Object>(); + private final int[] _data; private int _index; - - protected Dict(int[] data, int offset, int length) { + + protected Dict(final int[] data, final int offset, final int length) { _data = data; _index = offset; while (_index < offset + length) { addKeyAndValueEntry(); } } - - public Object getValue(int key) { + + public Object getValue(final int key) { return _entries.get(key); } - + private boolean addKeyAndValueEntry() { - ArrayList<Object> operands = new ArrayList<Object>(); + final ArrayList<Object> operands = new ArrayList<Object>(); Object operand = null; while (isOperandAtIndex()) { operand = nextOperand(); @@ -74,9 +74,9 @@ public class CffTable implements Table { } return true; } - + private boolean isOperandAtIndex() { - int b0 = _data[_index]; + final int b0 = _data[_index]; if ((32 <= b0 && b0 <= 254) || b0 == 28 || b0 == 29 @@ -87,7 +87,7 @@ public class CffTable implements Table { } private boolean isOperatorAtIndex() { - int b0 = _data[_index]; + final int b0 = _data[_index]; if (0 <= b0 && b0 <= 21) { return true; } @@ -95,44 +95,44 @@ public class CffTable implements Table { } private Object nextOperand() { - int b0 = _data[_index]; + final int b0 = _data[_index]; if (32 <= b0 && b0 <= 246) { - + // 1 byte integer ++_index; - return new Integer(b0 - 139); + return Integer.valueOf(b0 - 139); } else if (247 <= b0 && b0 <= 250) { - + // 2 byte integer - int b1 = _data[_index + 1]; + final int b1 = _data[_index + 1]; _index += 2; - return new Integer((b0 - 247) * 256 + b1 + 108); + return Integer.valueOf((b0 - 247) * 256 + b1 + 108); } else if (251 <= b0 && b0 <= 254) { - + // 2 byte integer - int b1 = _data[_index + 1]; + final int b1 = _data[_index + 1]; _index += 2; - return new Integer(-(b0 - 251) * 256 - b1 - 108); + return Integer.valueOf(-(b0 - 251) * 256 - b1 - 108); } else if (b0 == 28) { - + // 3 byte integer - int b1 = _data[_index + 1]; - int b2 = _data[_index + 2]; + final int b1 = _data[_index + 1]; + final int b2 = _data[_index + 2]; _index += 3; - return new Integer(b1 << 8 | b2); + return Integer.valueOf(b1 << 8 | b2); } else if (b0 == 29) { - + // 5 byte integer - int b1 = _data[_index + 1]; - int b2 = _data[_index + 2]; - int b3 = _data[_index + 3]; - int b4 = _data[_index + 4]; + final int b1 = _data[_index + 1]; + final int b2 = _data[_index + 2]; + final int b3 = _data[_index + 3]; + final int b4 = _data[_index + 4]; _index += 5; - return new Integer(b1 << 24 | b2 << 16 | b3 << 8 | b4); + return Integer.valueOf(b1 << 24 | b2 << 16 | b3 << 8 | b4); } else if (b0 == 30) { - + // Real number - StringBuilder fString = new StringBuilder(); + final StringBuilder fString = new StringBuilder(); int nibble1 = 0; int nibble2 = 0; ++_index; @@ -142,14 +142,14 @@ public class CffTable implements Table { ++_index; fString.append(decodeRealNibble(nibble1)); fString.append(decodeRealNibble(nibble2)); - } - return new Float(fString.toString()); + } + return Float.valueOf(fString.toString()); } else { return null; } } - - private String decodeRealNibble(int nibble) { + + private String decodeRealNibble(final int nibble) { if (nibble < 0xa) { return Integer.toString(nibble); } else if (nibble == 0xa) { @@ -163,12 +163,13 @@ public class CffTable implements Table { } return ""; } - + + @Override public String toString() { - StringBuilder sb = new StringBuilder(); - Enumeration<Integer> keys = _entries.keys(); + final StringBuilder sb = new StringBuilder(); + final Enumeration<Integer> keys = _entries.keys(); while (keys.hasMoreElements()) { - Integer key = keys.nextElement(); + final Integer key = keys.nextElement(); if ((key.intValue() & 0xc00) == 0xc00) { sb.append("12 ").append(key.intValue() & 0xff).append(": "); } else { @@ -179,15 +180,15 @@ public class CffTable implements Table { return sb.toString(); } } - + public class Index { - - private int _count; - private int _offSize; - private int[] _offset; - private int[] _data; - - protected Index(DataInput di) throws IOException { + + private final int _count; + private final int _offSize; + private final int[] _offset; + private final int[] _data; + + protected Index(final DataInput di) throws IOException { _count = di.readUnsignedShort(); _offset = new int[_count + 1]; _offSize = di.readUnsignedByte(); @@ -203,25 +204,26 @@ public class CffTable implements Table { _data[i] = di.readUnsignedByte(); } } - + public int getCount() { return _count; } - - public int getOffset(int index) { + + public int getOffset(final int index) { return _offset[index]; } - + public int getDataLength() { return _offset[_offset.length - 1] - 1; } - + public int[] getData() { return _data; } + @Override public String toString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append("DICT\n"); sb.append("count: ").append(_count).append("\n"); sb.append("offSize: ").append(_offSize).append("\n"); @@ -241,42 +243,43 @@ public class CffTable implements Table { return sb.toString(); } } - + public class TopDictIndex extends Index { - protected TopDictIndex(DataInput di) throws IOException { + protected TopDictIndex(final DataInput di) throws IOException { super(di); } - - public Dict getTopDict(int index) { - int offset = getOffset(index) - 1; - int len = getOffset(index + 1) - offset - 1; + + public Dict getTopDict(final int index) { + final int offset = getOffset(index) - 1; + final int len = getOffset(index + 1) - offset - 1; return new Dict(getData(), offset, len); } + @Override public String toString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); for (int i = 0; i < getCount(); ++i) { sb.append(getTopDict(i).toString()).append("\n"); } return sb.toString(); } } - + public class NameIndex extends Index { - protected NameIndex(DataInput di) throws IOException { + protected NameIndex(final DataInput di) throws IOException { super(di); } - - public String getName(int index) { + + public String getName(final int index) { String name = null; - int offset = getOffset(index) - 1; - int len = getOffset(index + 1) - offset - 1; + final int offset = getOffset(index) - 1; + final int len = getOffset(index + 1) - offset - 1; // Ensure the name hasn't been deleted if (getData()[offset] != 0) { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); for (int i = offset; i < offset + len; ++i) { sb.append((char) getData()[i]); } @@ -286,9 +289,10 @@ public class CffTable implements Table { } return name; } - + + @Override public String toString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); for (int i = 0; i < getCount(); ++i) { sb.append(getName(i)).append("\n"); } @@ -298,10 +302,10 @@ public class CffTable implements Table { public class StringIndex extends Index { - protected StringIndex(DataInput di) throws IOException { + protected StringIndex(final DataInput di) throws IOException { super(di); } - + public String getString(int index) { if (index < CffStandardStrings.standardStrings.length) { return CffStandardStrings.standardStrings[index]; @@ -310,20 +314,21 @@ public class CffTable implements Table { if (index >= getCount()) { return null; } - int offset = getOffset(index) - 1; - int len = getOffset(index + 1) - offset - 1; + final int offset = getOffset(index) - 1; + final int len = getOffset(index + 1) - offset - 1; - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); for (int i = offset; i < offset + len; ++i) { sb.append((char) getData()[i]); } return sb.toString(); } } - + + @Override public String toString() { - int nonStandardBase = CffStandardStrings.standardStrings.length; - StringBuilder sb = new StringBuilder(); + final int nonStandardBase = CffStandardStrings.standardStrings.length; + final StringBuilder sb = new StringBuilder(); for (int i = 0; i < getCount(); ++i) { sb.append(nonStandardBase + i).append(": "); sb.append(getString(nonStandardBase + i)).append("\n"); @@ -331,103 +336,107 @@ public class CffTable implements Table { return sb.toString(); } } - + private class CharsetRange { - + private int _first; private int _left; - + public int getFirst() { return _first; } - protected void setFirst(int first) { + protected void setFirst(final int first) { _first = first; } - + public int getLeft() { return _left; } - protected void setLeft(int left) { + protected void setLeft(final int left) { _left = left; } } private class CharsetRange1 extends CharsetRange { - - protected CharsetRange1(DataInput di) throws IOException { + + protected CharsetRange1(final DataInput di) throws IOException { setFirst(di.readUnsignedShort()); setLeft(di.readUnsignedByte()); } } - + private class CharsetRange2 extends CharsetRange { - - protected CharsetRange2(DataInput di) throws IOException { + + protected CharsetRange2(final DataInput di) throws IOException { setFirst(di.readUnsignedShort()); setLeft(di.readUnsignedShort()); } } - + private abstract class Charset { - + public abstract int getFormat(); - + public abstract int getSID(int gid); } - + private class CharsetFormat0 extends Charset { - - private int[] _glyph; - - protected CharsetFormat0(DataInput di, int glyphCount) throws IOException { + + private final int[] _glyph; + + protected CharsetFormat0(final DataInput di, final int glyphCount) throws IOException { _glyph = new int[glyphCount - 1]; // minus 1 because .notdef is omitted for (int i = 0; i < glyphCount - 1; ++i) { _glyph[i] = di.readUnsignedShort(); } } - + + @Override public int getFormat() { return 0; } - public int getSID(int gid) { + @Override + public int getSID(final int gid) { if (gid == 0) { return 0; } return _glyph[gid - 1]; } } - + private class CharsetFormat1 extends Charset { - - private ArrayList<CharsetRange> _charsetRanges = new ArrayList<CharsetRange>(); - - protected CharsetFormat1(DataInput di, int glyphCount) throws IOException { + + private final ArrayList<CharsetRange> _charsetRanges = new ArrayList<CharsetRange>(); + + protected CharsetFormat1(final DataInput di, final int glyphCount) throws IOException { int glyphsCovered = glyphCount - 1; // minus 1 because .notdef is omitted while (glyphsCovered > 0) { - CharsetRange range = new CharsetRange1(di); + final CharsetRange range = new CharsetRange1(di); _charsetRanges.add(range); glyphsCovered -= range.getLeft() + 1; } } + @Override public int getFormat() { return 1; } - public int getSID(int gid) { + @Override + public int getSID(final int gid) { if (gid == 0) { return 0; } - + // Count through the ranges to find the one of interest int count = 0; - for (CharsetRange range : _charsetRanges) { + for (final CharsetRange range : _charsetRanges) { count += range.getLeft(); if (gid < count) { - int sid = gid - count + range.getFirst(); + final int sid = gid - count + range.getFirst(); return sid; } } @@ -436,32 +445,34 @@ public class CffTable implements Table { } private class CharsetFormat2 extends Charset { - - private ArrayList<CharsetRange> _charsetRanges = new ArrayList<CharsetRange>(); - - protected CharsetFormat2(DataInput di, int glyphCount) throws IOException { + + private final ArrayList<CharsetRange> _charsetRanges = new ArrayList<CharsetRange>(); + + protected CharsetFormat2(final DataInput di, final int glyphCount) throws IOException { int glyphsCovered = glyphCount - 1; // minus 1 because .notdef is omitted while (glyphsCovered > 0) { - CharsetRange range = new CharsetRange2(di); + final CharsetRange range = new CharsetRange2(di); _charsetRanges.add(range); glyphsCovered -= range.getLeft() + 1; } } + @Override public int getFormat() { return 2; } - public int getSID(int gid) { + @Override + public int getSID(final int gid) { if (gid == 0) { return 0; } - + // Count through the ranges to find the one of interest int count = 0; - for (CharsetRange range : _charsetRanges) { + for (final CharsetRange range : _charsetRanges) { if (gid < range.getLeft() + count) { - int sid = gid - count + range.getFirst() - 1; + final int sid = gid - count + range.getFirst() - 1; return sid; } count += range.getLeft(); @@ -469,24 +480,24 @@ public class CffTable implements Table { return 0; } } - - private DirectoryEntry _de; - private int _major; - private int _minor; - private int _hdrSize; - private int _offSize; - private NameIndex _nameIndex; - private TopDictIndex _topDictIndex; - private StringIndex _stringIndex; - private Index _globalSubrIndex; - private Index _charStringsIndexArray[]; - private Charset[] _charsets; - private Charstring[][] _charstringsArray; - - private byte[] _buf; + + private final DirectoryEntry _de; + private final int _major; + private final int _minor; + private final int _hdrSize; + private final int _offSize; + private final NameIndex _nameIndex; + private final TopDictIndex _topDictIndex; + private final StringIndex _stringIndex; + private final Index _globalSubrIndex; + private final Index _charStringsIndexArray[]; + private final Charset[] _charsets; + private final Charstring[][] _charstringsArray; + + private final byte[] _buf; /** Creates a new instance of CffTable */ - protected CffTable(DirectoryEntry de, DataInput di) throws IOException { + protected CffTable(final DirectoryEntry de, final DataInput di) throws IOException { _de = (DirectoryEntry) de.clone(); // Load entire table into a buffer, and create another input stream @@ -499,24 +510,24 @@ public class CffTable implements Table { _minor = di2.readUnsignedByte(); _hdrSize = di2.readUnsignedByte(); _offSize = di2.readUnsignedByte(); - + // Name INDEX di2 = getDataInputForOffset(_hdrSize); _nameIndex = new NameIndex(di2); - + // Top DICT INDEX _topDictIndex = new TopDictIndex(di2); // String INDEX _stringIndex = new StringIndex(di2); - + // Global Subr INDEX _globalSubrIndex = new Index(di2); - + // Encodings go here -- but since this is an OpenType font will this // not always be a CIDFont? In which case there are no encodings // within the CFF data. - + // Load each of the fonts _charStringsIndexArray = new Index[_topDictIndex.getCount()]; _charsets = new Charset[_topDictIndex.getCount()]; @@ -526,15 +537,15 @@ public class CffTable implements Table { // Charstrings INDEX // We load this before Charsets because we may need to know the number // of glyphs - Integer charStringsOffset = (Integer) _topDictIndex.getTopDict(i).getValue(17); + final Integer charStringsOffset = (Integer) _topDictIndex.getTopDict(i).getValue(17); di2 = getDataInputForOffset(charStringsOffset); _charStringsIndexArray[i] = new Index(di2); - int glyphCount = _charStringsIndexArray[i].getCount(); - + final int glyphCount = _charStringsIndexArray[i].getCount(); + // Charsets - Integer charsetOffset = (Integer) _topDictIndex.getTopDict(i).getValue(15); + final Integer charsetOffset = (Integer) _topDictIndex.getTopDict(i).getValue(15); di2 = getDataInputForOffset(charsetOffset); - int format = di2.readUnsignedByte(); + final int format = di2.readUnsignedByte(); switch (format) { case 0: _charsets[i] = new CharsetFormat0(di2, glyphCount); @@ -550,8 +561,8 @@ public class CffTable implements Table { // Create the charstrings _charstringsArray[i] = new Charstring[glyphCount]; for (int j = 0; j < glyphCount; ++j) { - int offset = _charStringsIndexArray[i].getOffset(j) - 1; - int len = _charStringsIndexArray[i].getOffset(j + 1) - offset - 1; + final int offset = _charStringsIndexArray[i].getOffset(j) - 1; + final int len = _charStringsIndexArray[i].getOffset(j + 1) - offset - 1; _charstringsArray[i][j] = new CharstringType2( i, _stringIndex.getString(_charsets[i].getSID(j)), @@ -563,8 +574,8 @@ public class CffTable implements Table { } } } - - private DataInput getDataInputForOffset(int offset) { + + private DataInput getDataInputForOffset(final int offset) { return new DataInputStream(new ByteArrayInputStream( _buf, offset, _de.getLength() - offset)); @@ -573,25 +584,27 @@ public class CffTable implements Table { public NameIndex getNameIndex() { return _nameIndex; } - - public Charset getCharset(int fontIndex) { + + public Charset getCharset(final int fontIndex) { return _charsets[fontIndex]; } - public Charstring getCharstring(int fontIndex, int gid) { + public Charstring getCharstring(final int fontIndex, final int gid) { return _charstringsArray[fontIndex][gid]; } - - public int getCharstringCount(int fontIndex) { + + public int getCharstringCount(final int fontIndex) { return _charstringsArray[fontIndex].length; } + @Override public int getType() { return CFF; } + @Override public String toString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append("'CFF' Table - Compact Font Format\n---------------------------------\n"); sb.append("\nName INDEX\n"); sb.append(_nameIndex.toString()); @@ -607,13 +620,14 @@ public class CffTable implements Table { } return sb.toString(); } - + /** * Get a directory entry for this table. This uniquely identifies the * table in collections where there may be more than one instance of a * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return _de; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Charstring.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Charstring.java index d411d1e00..01e2d4934 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Charstring.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Charstring.java @@ -28,6 +28,6 @@ package jogamp.graph.font.typecast.ot.table; public abstract class Charstring { public abstract int getIndex(); - + public abstract String getName(); } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CharstringType2.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CharstringType2.java index 9c40a0e5e..d96a5848b 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CharstringType2.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CharstringType2.java @@ -28,7 +28,7 @@ import jogamp.graph.font.typecast.ot.table.CffTable; * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class CharstringType2 extends Charstring { - + private static final String[] _oneByteOperators = { "-Reserved-", "hstem", @@ -105,25 +105,25 @@ public class CharstringType2 extends Charstring { "flex1", "-Reserved-" }; - - private int _index; - private String _name; - private int[] _data; - private int _offset; - private int _length; - private CffTable.Index _localSubrIndex; - private CffTable.Index _globalSubrIndex; + + private final int _index; + private final String _name; + private final int[] _data; + private final int _offset; + private final int _length; + private final CffTable.Index _localSubrIndex; + private final CffTable.Index _globalSubrIndex; private int _ip; /** Creates a new instance of CharstringType2 */ protected CharstringType2( - int index, - String name, - int[] data, - int offset, - int length, - CffTable.Index localSubrIndex, - CffTable.Index globalSubrIndex) { + final int index, + final String name, + final int[] data, + final int offset, + final int length, + final CffTable.Index localSubrIndex, + final CffTable.Index globalSubrIndex) { _index = index; _name = name; _data = data; @@ -132,16 +132,18 @@ public class CharstringType2 extends Charstring { _localSubrIndex = localSubrIndex; _globalSubrIndex = globalSubrIndex; } - + + @Override public int getIndex() { return _index; } + @Override public String getName() { return _name; } - - private void disassemble(StringBuilder sb) { + + private void disassemble(final StringBuilder sb) { Number operand = null; while (isOperandAtIndex()) { operand = nextOperand(); @@ -151,7 +153,7 @@ public class CharstringType2 extends Charstring { String mnemonic; if (operator == 12) { operator = nextByte(); - + // Check we're not exceeding the upper limit of our mnemonics if (operator > 38) { operator = 38; @@ -162,13 +164,13 @@ public class CharstringType2 extends Charstring { } sb.append(mnemonic); } - + public void resetIP() { _ip = _offset; } public boolean isOperandAtIndex() { - int b0 = _data[_ip]; + final int b0 = _data[_ip]; if ((32 <= b0 && b0 <= 255) || b0 == 28) { return true; } @@ -176,55 +178,56 @@ public class CharstringType2 extends Charstring { } public Number nextOperand() { - int b0 = _data[_ip]; + final int b0 = _data[_ip]; if (32 <= b0 && b0 <= 246) { // 1 byte integer ++_ip; - return new Integer(b0 - 139); + return Integer.valueOf(b0 - 139); } else if (247 <= b0 && b0 <= 250) { // 2 byte integer - int b1 = _data[_ip + 1]; + final int b1 = _data[_ip + 1]; _ip += 2; - return new Integer((b0 - 247) * 256 + b1 + 108); + return Integer.valueOf((b0 - 247) * 256 + b1 + 108); } else if (251 <= b0 && b0 <= 254) { // 2 byte integer - int b1 = _data[_ip + 1]; + final int b1 = _data[_ip + 1]; _ip += 2; - return new Integer(-(b0 - 251) * 256 - b1 - 108); + return Integer.valueOf(-(b0 - 251) * 256 - b1 - 108); } else if (b0 == 28) { // 3 byte integer - int b1 = _data[_ip + 1]; - int b2 = _data[_ip + 2]; + final int b1 = _data[_ip + 1]; + final int b2 = _data[_ip + 2]; _ip += 3; - return new Integer(b1 << 8 | b2); + return Integer.valueOf(b1 << 8 | b2); } else if (b0 == 255) { // 16-bit signed integer with 16 bits of fraction - int b1 = (byte) _data[_ip + 1]; - int b2 = _data[_ip + 2]; - int b3 = _data[_ip + 3]; - int b4 = _data[_ip + 4]; + final int b1 = (byte) _data[_ip + 1]; + final int b2 = _data[_ip + 2]; + final int b3 = _data[_ip + 3]; + final int b4 = _data[_ip + 4]; _ip += 5; - return new Float((b1 << 8 | b2) + ((b3 << 8 | b4) / 65536.0)); + return Float.valueOf((b1 << 8 | b2) + ((b3 << 8 | b4) / 65536f)); } else { return null; } } - + public int nextByte() { return _data[_ip++]; } - + public boolean moreBytes() { return _ip < _offset + _length; } - + + @Override public String toString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); resetIP(); while (moreBytes()) { disassemble(sb); diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ClassDef.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ClassDef.java index 4c2f3decb..a65bcd525 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ClassDef.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ClassDef.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -20,9 +20,9 @@ public abstract class ClassDef { public abstract int getFormat(); - protected static ClassDef read(RandomAccessFile raf) throws IOException { + protected static ClassDef read(final RandomAccessFile raf) throws IOException { ClassDef c = null; - int format = raf.readUnsignedShort(); + final int format = raf.readUnsignedShort(); if (format == 1) { c = new ClassDefFormat1(raf); } else if (format == 2) { diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ClassDefFormat1.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ClassDefFormat1.java index 0c99ad66a..cbc05393f 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ClassDefFormat1.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ClassDefFormat1.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -18,12 +18,12 @@ import java.io.RandomAccessFile; */ public class ClassDefFormat1 extends ClassDef { - private int startGlyph; - private int glyphCount; - private int[] classValues; + private final int startGlyph; + private final int glyphCount; + private final int[] classValues; /** Creates new ClassDefFormat1 */ - public ClassDefFormat1(RandomAccessFile raf) throws IOException { + public ClassDefFormat1(final RandomAccessFile raf) throws IOException { startGlyph = raf.readUnsignedShort(); glyphCount = raf.readUnsignedShort(); classValues = new int[glyphCount]; @@ -32,6 +32,7 @@ public class ClassDefFormat1 extends ClassDef { } } + @Override public int getFormat() { return 1; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ClassDefFormat2.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ClassDefFormat2.java index 5b7c4d655..99283f026 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ClassDefFormat2.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ClassDefFormat2.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -18,11 +18,11 @@ import java.io.RandomAccessFile; */ public class ClassDefFormat2 extends ClassDef { - private int classRangeCount; - private RangeRecord[] classRangeRecords; + private final int classRangeCount; + private final RangeRecord[] classRangeRecords; /** Creates new ClassDefFormat2 */ - public ClassDefFormat2(RandomAccessFile raf) throws IOException { + public ClassDefFormat2(final RandomAccessFile raf) throws IOException { classRangeCount = raf.readUnsignedShort(); classRangeRecords = new RangeRecord[classRangeCount]; for (int i = 0; i < classRangeCount; i++) { @@ -30,6 +30,7 @@ public class ClassDefFormat2 extends ClassDef { } } + @Override public int getFormat() { return 2; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat.java index 7ce531cd9..602897382 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat.java @@ -58,21 +58,21 @@ import java.io.IOException; * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public abstract class CmapFormat { - - public class Range { - - private int _startCode; - private int _endCode; - - protected Range(int startCode, int endCode) { + + public static class Range { + + private final int _startCode; + private final int _endCode; + + protected Range(final int startCode, final int endCode) { _startCode = startCode; _endCode = endCode; } - + public int getStartCode() { return _startCode; } - + public int getEndCode() { return _endCode; } @@ -82,12 +82,12 @@ public abstract class CmapFormat { protected int _length; protected int _language; - protected CmapFormat(DataInput di) throws IOException { + protected CmapFormat(final DataInput di) throws IOException { _length = di.readUnsignedShort(); _language = di.readUnsignedShort(); } - protected static CmapFormat create(int format, DataInput di) + protected static CmapFormat create(final int format, final DataInput di) throws IOException { switch(format) { case 0: @@ -116,12 +116,13 @@ public abstract class CmapFormat { } public abstract int getRangeCount(); - + public abstract Range getRange(int index) throws ArrayIndexOutOfBoundsException; public abstract int mapCharCode(int charCode); - + + @Override public String toString() { return new StringBuilder() .append("format: ") diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat0.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat0.java index e374f82d2..505e8c942 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat0.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat0.java @@ -61,9 +61,9 @@ import java.io.IOException; */ public class CmapFormat0 extends CmapFormat { - private int[] _glyphIdArray = new int[256]; + private final int[] _glyphIdArray = new int[256]; - protected CmapFormat0(DataInput di) throws IOException { + protected CmapFormat0(final DataInput di) throws IOException { super(di); _format = 0; for (int i = 0; i < 256; i++) { @@ -71,18 +71,21 @@ public class CmapFormat0 extends CmapFormat { } } + @Override public int getRangeCount() { return 1; } - - public Range getRange(int index) throws ArrayIndexOutOfBoundsException { + + @Override + public Range getRange(final int index) throws ArrayIndexOutOfBoundsException { if (index != 0) { throw new ArrayIndexOutOfBoundsException(); } return new Range(0, 255); } - public int mapCharCode(int charCode) { + @Override + public int mapCharCode(final int charCode) { if (0 <= charCode && charCode < 256) { return _glyphIdArray[charCode]; } else { diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat2.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat2.java index 319d8c0d0..743fc93c1 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat2.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat2.java @@ -60,24 +60,24 @@ import java.io.IOException; */ public class CmapFormat2 extends CmapFormat { - private class SubHeader { + static class SubHeader { int _firstCode; int _entryCount; short _idDelta; int _idRangeOffset; int _arrayIndex; } - - private int[] _subHeaderKeys = new int[256]; - private SubHeader[] _subHeaders; - private int[] _glyphIndexArray; - protected CmapFormat2(DataInput di) throws IOException { + private final int[] _subHeaderKeys = new int[256]; + private final SubHeader[] _subHeaders; + private final int[] _glyphIndexArray; + + protected CmapFormat2(final DataInput di) throws IOException { super(di); _format = 2; - + int pos = 6; - + // Read the subheader keys, noting the highest value, as this will // determine the number of subheaders to read. int highest = 0; @@ -86,31 +86,31 @@ public class CmapFormat2 extends CmapFormat { highest = Math.max(highest, _subHeaderKeys[i]); pos += 2; } - int subHeaderCount = highest / 8 + 1; + final int subHeaderCount = highest / 8 + 1; _subHeaders = new SubHeader[subHeaderCount]; - + // Read the subheaders, once again noting the highest glyphIndexArray // index range. - int indexArrayOffset = 8 * subHeaderCount + 518; + final int indexArrayOffset = 8 * subHeaderCount + 518; highest = 0; for (int i = 0; i < _subHeaders.length; ++i) { - SubHeader sh = new SubHeader(); + final SubHeader sh = new SubHeader(); sh._firstCode = di.readUnsignedShort(); sh._entryCount = di.readUnsignedShort(); sh._idDelta = di.readShort(); sh._idRangeOffset = di.readUnsignedShort(); - + // Calculate the offset into the _glyphIndexArray pos += 8; sh._arrayIndex = (pos - 2 + sh._idRangeOffset - indexArrayOffset) / 2; - + // What is the highest range within the glyphIndexArray? highest = Math.max(highest, sh._arrayIndex + sh._entryCount); - + _subHeaders[i] = sh; } - + // Read the glyphIndexArray _glyphIndexArray = new int[highest]; for (int i = 0; i < _glyphIndexArray.length; ++i) { @@ -118,15 +118,17 @@ public class CmapFormat2 extends CmapFormat { } } + @Override public int getRangeCount() { return _subHeaders.length; } - - public Range getRange(int index) throws ArrayIndexOutOfBoundsException { + + @Override + public Range getRange(final int index) throws ArrayIndexOutOfBoundsException { if (index < 0 || index >= _subHeaders.length) { throw new ArrayIndexOutOfBoundsException(); } - + // Find the high-byte (if any) int highByte = 0; if (index != 0) { @@ -137,30 +139,31 @@ public class CmapFormat2 extends CmapFormat { } } } - + return new Range( highByte | _subHeaders[index]._firstCode, highByte | (_subHeaders[index]._firstCode + _subHeaders[index]._entryCount - 1)); } - public int mapCharCode(int charCode) { - + @Override + public int mapCharCode(final int charCode) { + // Get the appropriate subheader int index = 0; - int highByte = charCode >> 8; + final int highByte = charCode >> 8; if (highByte != 0) { index = _subHeaderKeys[highByte] / 8; } - SubHeader sh = _subHeaders[index]; - + final SubHeader sh = _subHeaders[index]; + // Is the charCode out-of-range? - int lowByte = charCode & 0xff; + final int lowByte = charCode & 0xff; if (lowByte < sh._firstCode || lowByte >= (sh._firstCode + sh._entryCount)) { return 0; } - + // Now calculate the glyph index int glyphIndex = _glyphIndexArray[sh._arrayIndex + (lowByte - sh._firstCode)]; diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat4.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat4.java index c09bdc8c3..c8be6c7fb 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat4.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat4.java @@ -59,18 +59,18 @@ import java.io.IOException; */ public class CmapFormat4 extends CmapFormat { - private int _segCountX2; - private int _searchRange; - private int _entrySelector; - private int _rangeShift; - private int[] _endCode; - private int[] _startCode; - private int[] _idDelta; - private int[] _idRangeOffset; - private int[] _glyphIdArray; - private int _segCount; - - protected CmapFormat4(DataInput di) throws IOException { + private final int _segCountX2; + private final int _searchRange; + private final int _entrySelector; + private final int _rangeShift; + private final int[] _endCode; + private final int[] _startCode; + private final int[] _idDelta; + private final int[] _idRangeOffset; + private final int[] _glyphIdArray; + private final int _segCount; + + protected CmapFormat4(final DataInput di) throws IOException { super(di); // 6 _format = 4; _segCountX2 = di.readUnsignedShort(); // +2 (8) @@ -97,12 +97,12 @@ public class CmapFormat4 extends CmapFormat { } // + 2*segCount (8*segCount + 16) // Whatever remains of this header belongs in glyphIdArray - int count = (_length - (8*_segCount + 16)) / 2; + final int count = (_length - (8*_segCount + 16)) / 2; _glyphIdArray = new int[count]; for (int i = 0; i < count; i++) { _glyphIdArray[i] = di.readUnsignedShort(); } // + 2*count (8*segCount + 2*count + 18) - + // Are there any padding bytes we need to consume? // int leftover = length - (8*segCount + 2*count + 18); // if (leftover > 0) { @@ -110,18 +110,21 @@ public class CmapFormat4 extends CmapFormat { // } } + @Override public int getRangeCount() { return _segCount; } - - public Range getRange(int index) throws ArrayIndexOutOfBoundsException { + + @Override + public Range getRange(final int index) throws ArrayIndexOutOfBoundsException { if (index < 0 || index >= _segCount) { throw new ArrayIndexOutOfBoundsException(); } return new Range(_startCode[index], _endCode[index]); } - public int mapCharCode(int charCode) { + @Override + public int mapCharCode(final int charCode) { try { for (int i = 0; i < _segCount; i++) { if (_endCode[i] >= charCode) { @@ -136,12 +139,13 @@ public class CmapFormat4 extends CmapFormat { } } } - } catch (ArrayIndexOutOfBoundsException e) { + } catch (final ArrayIndexOutOfBoundsException e) { System.err.println("error: Array out of bounds - " + e.getMessage()); } return 0; } + @Override public String toString() { return new StringBuilder() .append(super.toString()) @@ -153,13 +157,13 @@ public class CmapFormat4 extends CmapFormat { .append(_entrySelector) .append(", rangeShift: ") .append(_rangeShift) - .append(", endCode: ") - .append(_endCode) - .append(", startCode: ") - .append(_endCode) - .append(", idDelta: ") - .append(_idDelta) - .append(", idRangeOffset: ") - .append(_idRangeOffset).toString(); + .append(", endCodeLen: ") + .append(_endCode.length) + .append(", startCodeLen: ") + .append(_endCode.length) + .append(", idDeltaLen: ") + .append(_idDelta.length) + .append(", idRangeOffsetLen: ") + .append(_idRangeOffset.length).toString(); } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat6.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat6.java index a58531d11..eff3d2fb1 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat6.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat6.java @@ -64,24 +64,27 @@ public class CmapFormat6 extends CmapFormat { private short _entryCount; private short[] _glyphIdArray; - protected CmapFormat6(DataInput di) throws IOException { + protected CmapFormat6(final DataInput di) throws IOException { super(di); _format = 6; - + // HACK: As this is not yet implemented, we need to skip over the bytes // we should be consuming //di.skipBytes(_length - 4); } + @Override public int getRangeCount() { return 0; } - - public Range getRange(int index) throws ArrayIndexOutOfBoundsException { + + @Override + public Range getRange(final int index) throws ArrayIndexOutOfBoundsException { throw new ArrayIndexOutOfBoundsException(); } - public int mapCharCode(int charCode) { + @Override + public int mapCharCode(final int charCode) { return 0; } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormatUnknown.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormatUnknown.java index 83366b593..e9aa1d4e0 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormatUnknown.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormatUnknown.java @@ -30,25 +30,28 @@ import java.io.IOException; * @version $Id: CmapFormatUnknown.java,v 1.1 2004-12-21 10:21:23 davidsch Exp $ */ public class CmapFormatUnknown extends CmapFormat { - + /** Creates a new instance of CmapFormatUnknown */ - protected CmapFormatUnknown(int format, DataInput di) throws IOException { + protected CmapFormatUnknown(final int format, final DataInput di) throws IOException { super(di); _format = format; - + // We don't know how to handle this data, so we'll just skip over it di.skipBytes(_length - 4); } + @Override public int getRangeCount() { return 0; } - - public Range getRange(int index) throws ArrayIndexOutOfBoundsException { + + @Override + public Range getRange(final int index) throws ArrayIndexOutOfBoundsException { throw new ArrayIndexOutOfBoundsException(); } - public int mapCharCode(int charCode) { + @Override + public int mapCharCode(final int charCode) { return 0; } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapIndexEntry.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapIndexEntry.java index 85fdf7225..1f2c80286 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapIndexEntry.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapIndexEntry.java @@ -59,12 +59,12 @@ import java.io.IOException; */ public class CmapIndexEntry implements Comparable { - private int _platformId; - private int _encodingId; - private int _offset; + private final int _platformId; + private final int _encodingId; + private final int _offset; private CmapFormat _format; - protected CmapIndexEntry(DataInput di) throws IOException { + protected CmapIndexEntry(final DataInput di) throws IOException { _platformId = di.readUnsignedShort(); _encodingId = di.readUnsignedShort(); _offset = di.readInt(); @@ -85,11 +85,12 @@ public class CmapIndexEntry implements Comparable { public CmapFormat getFormat() { return _format; } - - public void setFormat(CmapFormat format) { + + public void setFormat(final CmapFormat format) { _format = format; } + @Override public String toString() { return new StringBuilder() .append("platform id: ") @@ -104,8 +105,9 @@ public class CmapIndexEntry implements Comparable { .append(_offset).toString(); } - public int compareTo(java.lang.Object obj) { - CmapIndexEntry entry = (CmapIndexEntry) obj; + @Override + public int compareTo(final java.lang.Object obj) { + final CmapIndexEntry entry = (CmapIndexEntry) obj; if (getOffset() < entry.getOffset()) { return -1; } else if (getOffset() > entry.getOffset()) { diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapTable.java index 0050fdd8e..4623eb5cf 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapTable.java @@ -61,12 +61,12 @@ import java.util.Arrays; */ public class CmapTable implements Table { - private DirectoryEntry _de; - private int _version; - private int _numTables; - private CmapIndexEntry[] _entries; + private final DirectoryEntry _de; + private final int _version; + private final int _numTables; + private final CmapIndexEntry[] _entries; - protected CmapTable(DirectoryEntry de, DataInput di) throws IOException { + protected CmapTable(final DirectoryEntry de, final DataInput di) throws IOException { _de = (DirectoryEntry) de.clone(); _version = di.readUnsignedShort(); _numTables = di.readUnsignedShort(); @@ -94,11 +94,11 @@ public class CmapTable implements Table { } else if (_entries[i].getOffset() > bytesRead) { di.skipBytes(_entries[i].getOffset() - (int) bytesRead); } else if (_entries[i].getOffset() != bytesRead) { - + // Something is amiss throw new IOException(); } - int formatType = di.readUnsignedShort(); + final int formatType = di.readUnsignedShort(); lastFormat = CmapFormat.create(formatType, di); lastOffset = _entries[i].getOffset(); _entries[i].setFormat(lastFormat); @@ -109,16 +109,16 @@ public class CmapTable implements Table { public int getVersion() { return _version; } - + public int getNumTables() { return _numTables; } - - public CmapIndexEntry getCmapIndexEntry(int i) { + + public CmapIndexEntry getCmapIndexEntry(final int i) { return _entries[i]; } - - public CmapFormat getCmapFormat(short platformId, short encodingId) { + + public CmapFormat getCmapFormat(final short platformId, final short encodingId) { // Find the requested format for (int i = 0; i < _numTables; i++) { @@ -130,12 +130,14 @@ public class CmapTable implements Table { return null; } + @Override public int getType() { return cmap; } + @Override public String toString() { - StringBuilder sb = new StringBuilder().append("cmap\n"); + final StringBuilder sb = new StringBuilder().append("cmap\n"); // Get each of the index entries for (int i = 0; i < _numTables; i++) { @@ -148,13 +150,14 @@ public class CmapTable implements Table { // } return sb.toString(); } - + /** * Get a directory entry for this table. This uniquely identifies the * table in collections where there may be more than one instance of a * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return _de; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Coverage.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Coverage.java index e85fadb5e..a6f994f95 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Coverage.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Coverage.java @@ -68,10 +68,10 @@ public abstract class Coverage { * can't be found. */ public abstract int findGlyph(int glyphId); - - protected static Coverage read(DataInput di) throws IOException { + + protected static Coverage read(final DataInput di) throws IOException { Coverage c = null; - int format = di.readUnsignedShort(); + final int format = di.readUnsignedShort(); if (format == 1) { c = new CoverageFormat1(di); } else if (format == 2) { diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CoverageFormat1.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CoverageFormat1.java index 712da54df..3deb60202 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CoverageFormat1.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CoverageFormat1.java @@ -60,11 +60,11 @@ import java.io.IOException; */ public class CoverageFormat1 extends Coverage { - private int _glyphCount; - private int[] _glyphIds; + private final int _glyphCount; + private final int[] _glyphIds; /** Creates new CoverageFormat1 */ - protected CoverageFormat1(DataInput di) throws IOException { + protected CoverageFormat1(final DataInput di) throws IOException { _glyphCount = di.readUnsignedShort(); _glyphIds = new int[_glyphCount]; for (int i = 0; i < _glyphCount; i++) { @@ -72,11 +72,13 @@ public class CoverageFormat1 extends Coverage { } } + @Override public int getFormat() { return 1; } - public int findGlyph(int glyphId) { + @Override + public int findGlyph(final int glyphId) { for (int i = 0; i < _glyphCount; i++) { if (_glyphIds[i] == glyphId) { return i; diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CoverageFormat2.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CoverageFormat2.java index 7196ed595..9397f376d 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CoverageFormat2.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CoverageFormat2.java @@ -60,11 +60,11 @@ import java.io.IOException; */ public class CoverageFormat2 extends Coverage { - private int _rangeCount; - private RangeRecord[] _rangeRecords; + private final int _rangeCount; + private final RangeRecord[] _rangeRecords; /** Creates new CoverageFormat2 */ - protected CoverageFormat2(DataInput di) throws IOException { + protected CoverageFormat2(final DataInput di) throws IOException { _rangeCount = di.readUnsignedShort(); _rangeRecords = new RangeRecord[_rangeCount]; for (int i = 0; i < _rangeCount; i++) { @@ -72,13 +72,15 @@ public class CoverageFormat2 extends Coverage { } } + @Override public int getFormat() { return 2; } - public int findGlyph(int glyphId) { + @Override + public int findGlyph(final int glyphId) { for (int i = 0; i < _rangeCount; i++) { - int n = _rangeRecords[i].getCoverageIndex(glyphId); + final int n = _rangeRecords[i].getCoverageIndex(glyphId); if (n > -1) { return n; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CvtTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CvtTable.java index 963163584..7f62d26ab 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CvtTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CvtTable.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -17,18 +17,19 @@ import java.io.IOException; */ public class CvtTable implements Table { - private DirectoryEntry de; - private short[] values; + private final DirectoryEntry de; + private final short[] values; - protected CvtTable(DirectoryEntry de, DataInput di) throws IOException { + protected CvtTable(final DirectoryEntry de, final DataInput di) throws IOException { this.de = (DirectoryEntry) de.clone(); - int len = de.getLength() / 2; + final int len = de.getLength() / 2; values = new short[len]; for (int i = 0; i < len; i++) { values[i] = di.readShort(); } } + @Override public int getType() { return cvt; } @@ -37,8 +38,9 @@ public class CvtTable implements Table { return values; } + @Override public String toString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append("'cvt ' Table - Control Value Table\n----------------------------------\n"); sb.append("Size = ").append(0).append(" bytes, ").append(values.length).append(" entries\n"); sb.append(" Values\n ------\n"); @@ -47,15 +49,16 @@ public class CvtTable implements Table { } return sb.toString(); } - + /** * Get a directory entry for this table. This uniquely identifies the * table in collections where there may be more than one instance of a * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return de; } - + } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Device.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Device.java index 6b4af6908..a0b10e187 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Device.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Device.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -18,13 +18,13 @@ import java.io.RandomAccessFile; */ public class Device extends Object { - private int startSize; - private int endSize; - private int deltaFormat; - private int[] deltaValues; + private final int startSize; + private final int endSize; + private final int deltaFormat; + private final int[] deltaValues; /** Creates new Device */ - public Device(RandomAccessFile raf) throws IOException { + public Device(final RandomAccessFile raf) throws IOException { startSize = raf.readUnsignedShort(); endSize = raf.readUnsignedShort(); deltaFormat = raf.readUnsignedShort(); diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/DirectoryEntry.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/DirectoryEntry.java index c98f03fe9..54684b8e9 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/DirectoryEntry.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/DirectoryEntry.java @@ -59,22 +59,23 @@ import java.io.IOException; */ public class DirectoryEntry implements Cloneable { - private int _tag; - private int _checksum; - private int _offset; - private int _length; + private final int _tag; + private final int _checksum; + private final int _offset; + private final int _length; - protected DirectoryEntry(DataInput di) throws IOException { + protected DirectoryEntry(final DataInput di) throws IOException { _tag = di.readInt(); _checksum = di.readInt(); _offset = di.readInt(); _length = di.readInt(); } - + + @Override public Object clone() { try { return super.clone(); - } catch (CloneNotSupportedException e) { + } catch (final CloneNotSupportedException e) { return null; } } @@ -103,7 +104,8 @@ public class DirectoryEntry implements Cloneable { .append((char)((_tag)&0xff)) .toString(); } - + + @Override public String toString() { return new StringBuilder() .append("'").append(getTagAsString()) diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/DsigEntry.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/DsigEntry.java index 4b41f451d..ec7b503f1 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/DsigEntry.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/DsigEntry.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -18,12 +18,12 @@ import java.io.DataInput; */ public class DsigEntry { - private int format; - private int length; - private int offset; - + private final int format; + private final int length; + private final int offset; + /** Creates new DsigEntry */ - protected DsigEntry(DataInput di) throws IOException { + protected DsigEntry(final DataInput di) throws IOException { format = di.readInt(); length = di.readInt(); offset = di.readInt(); @@ -32,11 +32,11 @@ public class DsigEntry { public int getFormat() { return format; } - + public int getLength() { return length; } - + public int getOffset() { return offset; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/DsigTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/DsigTable.java index e2784f9e6..f2b1322c0 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/DsigTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/DsigTable.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -18,15 +18,15 @@ import java.io.DataInput; */ public class DsigTable implements Table { - private DirectoryEntry de; - private int version; - private int numSigs; - private int flag; - private DsigEntry[] dsigEntry; - private SignatureBlock[] sigBlocks; + private final DirectoryEntry de; + private final int version; + private final int numSigs; + private final int flag; + private final DsigEntry[] dsigEntry; + private final SignatureBlock[] sigBlocks; /** Creates new DsigTable */ - protected DsigTable(DirectoryEntry de, DataInput di) throws IOException { + protected DsigTable(final DirectoryEntry de, final DataInput di) throws IOException { this.de = (DirectoryEntry) de.clone(); version = di.readInt(); numSigs = di.readUnsignedShort(); @@ -45,22 +45,25 @@ public class DsigTable implements Table { * Get the table type, as a table directory value. * @return The table type */ + @Override public int getType() { return DSIG; } - + /** * Get a directory entry for this table. This uniquely identifies the * table in collections where there may be more than one instance of a * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return de; } - + + @Override public String toString() { - StringBuilder sb = new StringBuilder().append("DSIG\n"); + final StringBuilder sb = new StringBuilder().append("DSIG\n"); for (int i = 0; i < numSigs; i++) { sb.append(sigBlocks[i].toString()); } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Feature.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Feature.java index ee27896a4..c6f912569 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Feature.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Feature.java @@ -60,12 +60,12 @@ import java.io.IOException; */ public class Feature { - private int _featureParams; - private int _lookupCount; - private int[] _lookupListIndex; + private final int _featureParams; + private final int _lookupCount; + private final int[] _lookupListIndex; /** Creates new Feature */ - protected Feature(DataInput di) throws IOException { + protected Feature(final DataInput di) throws IOException { _featureParams = di.readUnsignedShort(); _lookupCount = di.readUnsignedShort(); _lookupListIndex = new int[_lookupCount]; @@ -78,7 +78,7 @@ public class Feature { return _lookupCount; } - public int getLookupListIndex(int i) { + public int getLookupListIndex(final int i) { return _lookupListIndex[i]; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/FeatureList.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/FeatureList.java index 3cfb54a38..933378068 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/FeatureList.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/FeatureList.java @@ -60,17 +60,17 @@ import java.io.IOException; */ public class FeatureList { - private int _featureCount; - private FeatureRecord[] _featureRecords; - private Feature[] _features; + private final int _featureCount; + private final FeatureRecord[] _featureRecords; + private final Feature[] _features; /** Creates new FeatureList */ - public FeatureList(DataInputStream dis, int offset) throws IOException { - + public FeatureList(final DataInputStream dis, final int offset) throws IOException { + // Ensure we're in the right place dis.reset(); dis.skipBytes(offset); - + // Start reading _featureCount = dis.readUnsignedShort(); _featureRecords = new FeatureRecord[_featureCount]; @@ -88,20 +88,20 @@ public class FeatureList { public int getFeatureCount() { return _featureCount; } - - public FeatureRecord getFeatureRecord(int i) { + + public FeatureRecord getFeatureRecord(final int i) { return _featureRecords[i]; } - - public Feature getFeature(int i) { + + public Feature getFeature(final int i) { return _features[i]; } - public Feature findFeature(LangSys langSys, String tag) { + public Feature findFeature(final LangSys langSys, final String tag) { if (tag.length() != 4) { return null; } - int tagVal = ((tag.charAt(0)<<24) + final int tagVal = ((tag.charAt(0)<<24) | (tag.charAt(1)<<16) | (tag.charAt(2)<<8) | tag.charAt(3)); diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/FeatureRecord.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/FeatureRecord.java index eb610814b..06506904f 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/FeatureRecord.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/FeatureRecord.java @@ -60,11 +60,11 @@ import java.io.IOException; */ public class FeatureRecord { - private int _tag; - private int _offset; + private final int _tag; + private final int _offset; /** Creates new FeatureRecord */ - protected FeatureRecord(DataInput di) throws IOException { + protected FeatureRecord(final DataInput di) throws IOException { _tag = di.readInt(); _offset = di.readUnsignedShort(); } @@ -72,7 +72,7 @@ public class FeatureRecord { public int getTag() { return _tag; } - + public int getOffset() { return _offset; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/FpgmTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/FpgmTable.java index 9a6000156..e44acfa02 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/FpgmTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/FpgmTable.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -19,29 +19,32 @@ import jogamp.graph.font.typecast.ot.Disassembler; */ public class FpgmTable extends Program implements Table { - private DirectoryEntry de; + private final DirectoryEntry de; - protected FpgmTable(DirectoryEntry de, DataInput di) throws IOException { + protected FpgmTable(final DirectoryEntry de, final DataInput di) throws IOException { this.de = (DirectoryEntry) de.clone(); readInstructions(di, de.getLength()); } + @Override public int getType() { return fpgm; } + @Override public String toString() { return Disassembler.disassemble(getInstructions(), 0); } - + /** * Get a directory entry for this table. This uniquely identifies the * table in collections where there may be more than one instance of a * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return de; } - + } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GaspRange.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GaspRange.java index 2748406df..cebc51646 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GaspRange.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GaspRange.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -20,18 +20,19 @@ public class GaspRange { public static final int GASP_GRIDFIT = 1; public static final int GASP_DOGRAY = 2; - - private int rangeMaxPPEM; - private int rangeGaspBehavior; - + + private final int rangeMaxPPEM; + private final int rangeGaspBehavior; + /** Creates new GaspRange */ - protected GaspRange(DataInput di) throws IOException { + protected GaspRange(final DataInput di) throws IOException { rangeMaxPPEM = di.readUnsignedShort(); rangeGaspBehavior = di.readUnsignedShort(); } + @Override public String toString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append(" rangeMaxPPEM: ").append(rangeMaxPPEM) .append("\n rangeGaspBehavior: 0x").append(rangeGaspBehavior); if ((rangeGaspBehavior & GASP_GRIDFIT) != 0) { diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GaspTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GaspTable.java index a83db5bff..7bf7f96cc 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GaspTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GaspTable.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -18,13 +18,13 @@ import java.io.IOException; */ public class GaspTable implements Table { - private DirectoryEntry de; - private int version; - private int numRanges; - private GaspRange[] gaspRange; - + private final DirectoryEntry de; + private final int version; + private final int numRanges; + private final GaspRange[] gaspRange; + /** Creates new GaspTable */ - protected GaspTable(DirectoryEntry de, DataInput di) throws IOException { + protected GaspTable(final DirectoryEntry de, final DataInput di) throws IOException { this.de = (DirectoryEntry) de.clone(); version = di.readUnsignedShort(); numRanges = di.readUnsignedShort(); @@ -34,12 +34,14 @@ public class GaspTable implements Table { } } + @Override public int getType() { return gasp; } + @Override public String toString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append("'gasp' Table - Grid-fitting And Scan-conversion Procedure\n---------------------------------------------------------"); sb.append("\n 'gasp' version: ").append(version); sb.append("\n numRanges: ").append(numRanges); @@ -49,15 +51,16 @@ public class GaspTable implements Table { } return sb.toString(); } - + /** * Get a directory entry for this table. This uniquely identifies the * table in collections where there may be more than one instance of a * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return de; } - + } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfCompositeComp.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfCompositeComp.java index e5c86873e..4db4ddcc2 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfCompositeComp.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfCompositeComp.java @@ -69,12 +69,12 @@ public class GlyfCompositeComp { public static final short WE_HAVE_INSTRUCTIONS = 0x0100; public static final short USE_MY_METRICS = 0x0200; - private int _firstIndex; - private int _firstContour; + private final int _firstIndex; + private final int _firstContour; private short _argument1; private short _argument2; - private int _flags; - private int _glyphIndex; + private final int _flags; + private final int _glyphIndex; private double _xscale = 1.0; private double _yscale = 1.0; private double _scale01 = 0.0; @@ -84,7 +84,7 @@ public class GlyfCompositeComp { private int _point1 = 0; private int _point2 = 0; - protected GlyfCompositeComp(int firstIndex, int firstContour, DataInput di) + protected GlyfCompositeComp(final int firstIndex, final int firstContour, final DataInput di) throws IOException { _firstIndex = firstIndex; _firstContour = firstContour; @@ -96,8 +96,8 @@ public class GlyfCompositeComp { _argument1 = di.readShort(); _argument2 = di.readShort(); } else { - _argument1 = (short) di.readByte(); - _argument2 = (short) di.readByte(); + _argument1 = di.readByte(); + _argument2 = di.readByte(); } // Assign the arguments according to the flags @@ -111,7 +111,7 @@ public class GlyfCompositeComp { // Get the scale values (if any) if ((_flags & WE_HAVE_A_SCALE) != 0) { - int i = di.readShort(); + final int i = di.readShort(); _xscale = _yscale = (double) i / (double) 0x4000; } else if ((_flags & WE_HAVE_AN_X_AND_Y_SCALE) != 0) { short i = di.readShort(); @@ -184,8 +184,8 @@ public class GlyfCompositeComp { * @param y The y-coordinate of the point to transform * @return The transformed x-coordinate */ - public int scaleX(int x, int y) { - return (int)((double) x * _xscale + (double) y * _scale10); + public int scaleX(final int x, final int y) { + return (int)(x * _xscale + y * _scale10); } /** @@ -194,7 +194,7 @@ public class GlyfCompositeComp { * @param y The y-coordinate of the point to transform * @return The transformed y-coordinate */ - public int scaleY(int x, int y) { - return (int)((double) x * _scale01 + (double) y * _yscale); + public int scaleY(final int x, final int y) { + return (int)(x * _scale01 + y * _yscale); } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfCompositeDescript.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfCompositeDescript.java index 4cf254198..3879da02a 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfCompositeDescript.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfCompositeDescript.java @@ -65,15 +65,15 @@ import java.util.ArrayList; */ public class GlyfCompositeDescript extends GlyfDescript { - private ArrayList<GlyfCompositeComp> _components = + private final ArrayList<GlyfCompositeComp> _components = new ArrayList<GlyfCompositeComp>(); public GlyfCompositeDescript( - GlyfTable parentTable, - int glyphIndex, - DataInput di) throws IOException { + final GlyfTable parentTable, + final int glyphIndex, + final DataInput di) throws IOException { super(parentTable, glyphIndex, (short) -1, di); - + // Get all of the composite components GlyfCompositeComp comp; int firstIndex = 0; @@ -81,7 +81,7 @@ public class GlyfCompositeDescript extends GlyfDescript { try { do { _components.add(comp = new GlyfCompositeComp(firstIndex, firstContour, di)); - GlyfDescript desc = parentTable.getDescription(comp.getGlyphIndex()); + final GlyfDescript desc = parentTable.getDescription(comp.getGlyphIndex()); if (desc != null) { firstIndex += desc.getPointCount(); firstContour += desc.getContourCount(); @@ -92,38 +92,41 @@ public class GlyfCompositeDescript extends GlyfDescript { if ((comp.getFlags() & GlyfCompositeComp.WE_HAVE_INSTRUCTIONS) != 0) { readInstructions(di, di.readShort()); } - } catch (IOException e) { + } catch (final IOException e) { throw e; // } catch (Exception e) { // int foo = 0; } } - public int getEndPtOfContours(int i) { - GlyfCompositeComp c = getCompositeCompEndPt(i); + @Override + public int getEndPtOfContours(final int i) { + final GlyfCompositeComp c = getCompositeCompEndPt(i); if (c != null) { - GlyphDescription gd = _parentTable.getDescription(c.getGlyphIndex()); + final GlyphDescription gd = _parentTable.getDescription(c.getGlyphIndex()); return gd.getEndPtOfContours(i - c.getFirstContour()) + c.getFirstIndex(); } return 0; } - public byte getFlags(int i) { - GlyfCompositeComp c = getCompositeComp(i); + @Override + public byte getFlags(final int i) { + final GlyfCompositeComp c = getCompositeComp(i); if (c != null) { - GlyphDescription gd = _parentTable.getDescription(c.getGlyphIndex()); + final GlyphDescription gd = _parentTable.getDescription(c.getGlyphIndex()); return gd.getFlags(i - c.getFirstIndex()); } return 0; } - public short getXCoordinate(int i) { - GlyfCompositeComp c = getCompositeComp(i); + @Override + public short getXCoordinate(final int i) { + final GlyfCompositeComp c = getCompositeComp(i); if (c != null) { - GlyphDescription gd = _parentTable.getDescription(c.getGlyphIndex()); - int n = i - c.getFirstIndex(); - int x = gd.getXCoordinate(n); - int y = gd.getYCoordinate(n); + final GlyphDescription gd = _parentTable.getDescription(c.getGlyphIndex()); + final int n = i - c.getFirstIndex(); + final int x = gd.getXCoordinate(n); + final int y = gd.getYCoordinate(n); short x1 = (short) c.scaleX(x, y); x1 += c.getXTranslate(); return x1; @@ -131,13 +134,14 @@ public class GlyfCompositeDescript extends GlyfDescript { return 0; } - public short getYCoordinate(int i) { - GlyfCompositeComp c = getCompositeComp(i); + @Override + public short getYCoordinate(final int i) { + final GlyfCompositeComp c = getCompositeComp(i); if (c != null) { - GlyphDescription gd = _parentTable.getDescription(c.getGlyphIndex()); - int n = i - c.getFirstIndex(); - int x = gd.getXCoordinate(n); - int y = gd.getYCoordinate(n); + final GlyphDescription gd = _parentTable.getDescription(c.getGlyphIndex()); + final int n = i - c.getFirstIndex(); + final int x = gd.getXCoordinate(n); + final int y = gd.getYCoordinate(n); short y1 = (short) c.scaleY(x, y); y1 += c.getYTranslate(); return y1; @@ -145,13 +149,15 @@ public class GlyfCompositeDescript extends GlyfDescript { return 0; } + @Override public boolean isComposite() { return true; } + @Override public int getPointCount() { - GlyfCompositeComp c = _components.get(_components.size()-1); - GlyphDescription gd = _parentTable.getDescription(c.getGlyphIndex()); + final GlyfCompositeComp c = _components.get(_components.size()-1); + final GlyphDescription gd = _parentTable.getDescription(c.getGlyphIndex()); if (gd != null) { return c.getFirstIndex() + gd.getPointCount(); } else { @@ -159,12 +165,14 @@ public class GlyfCompositeDescript extends GlyfDescript { } } + @Override public int getContourCount() { - GlyfCompositeComp c = _components.get(_components.size()-1); - return c.getFirstContour() + _parentTable.getDescription(c.getGlyphIndex()).getContourCount(); + final GlyfCompositeComp c = _components.get(_components.size()-1); + final GlyfDescript d = _parentTable.getDescription(c.getGlyphIndex()); + return c.getFirstContour() + ( null != d ? d.getContourCount() : 0 ); } - public int getComponentIndex(int i) { + public int getComponentIndex(final int i) { return _components.get(i).getFirstIndex(); } @@ -172,15 +180,15 @@ public class GlyfCompositeDescript extends GlyfDescript { return _components.size(); } - public GlyfCompositeComp getComponent(int i) { + public GlyfCompositeComp getComponent(final int i) { return _components.get(i); } - protected GlyfCompositeComp getCompositeComp(int i) { + protected GlyfCompositeComp getCompositeComp(final int i) { GlyfCompositeComp c; for (int n = 0; n < _components.size(); n++) { c = _components.get(n); - GlyphDescription gd = _parentTable.getDescription(c.getGlyphIndex()); + final GlyphDescription gd = _parentTable.getDescription(c.getGlyphIndex()); if (c.getFirstIndex() <= i && i < (c.getFirstIndex() + gd.getPointCount())) { return c; } @@ -188,11 +196,11 @@ public class GlyfCompositeDescript extends GlyfDescript { return null; } - protected GlyfCompositeComp getCompositeCompEndPt(int i) { + protected GlyfCompositeComp getCompositeCompEndPt(final int i) { GlyfCompositeComp c; for (int j = 0; j < _components.size(); j++) { c = _components.get(j); - GlyphDescription gd = _parentTable.getDescription(c.getGlyphIndex()); + final GlyphDescription gd = _parentTable.getDescription(c.getGlyphIndex()); if (c.getFirstContour() <= i && i < (c.getFirstContour() + gd.getContourCount())) { return c; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfDescript.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfDescript.java index a9342a434..3d2154d5a 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfDescript.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfDescript.java @@ -69,17 +69,17 @@ public abstract class GlyfDescript extends Program implements GlyphDescription { protected GlyfTable _parentTable; private int _glyphIndex; - private int _numberOfContours; - private short _xMin; - private short _yMin; - private short _xMax; - private short _yMax; + private final int _numberOfContours; + private final short _xMin; + private final short _yMin; + private final short _xMax; + private final short _yMax; protected GlyfDescript( - GlyfTable parentTable, - int glyphIndex, - short numberOfContours, - DataInput di) throws IOException { + final GlyfTable parentTable, + final int glyphIndex, + final short numberOfContours, + final DataInput di) throws IOException { _parentTable = parentTable; _numberOfContours = numberOfContours; _xMin = di.readShort(); @@ -92,26 +92,32 @@ public abstract class GlyfDescript extends Program implements GlyphDescription { return _numberOfContours; } + @Override public int getGlyphIndex() { return _glyphIndex; } + @Override public short getXMaximum() { return _xMax; } + @Override public short getXMinimum() { return _xMin; } + @Override public short getYMaximum() { return _yMax; } + @Override public short getYMinimum() { return _yMin; } - + + @Override public String toString() { return new StringBuilder() .append(" numberOfContours: ").append(_numberOfContours) diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfSimpleDescript.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfSimpleDescript.java index c11d2d8ff..041c0f04c 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfSimpleDescript.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfSimpleDescript.java @@ -61,19 +61,19 @@ import jogamp.graph.font.typecast.ot.Disassembler; */ public class GlyfSimpleDescript extends GlyfDescript { - private int[] _endPtsOfContours; - private byte[] _flags; - private short[] _xCoordinates; - private short[] _yCoordinates; - private int _count; + private final int[] _endPtsOfContours; + private final byte[] _flags; + private final short[] _xCoordinates; + private final short[] _yCoordinates; + private final int _count; public GlyfSimpleDescript( - GlyfTable parentTable, - int glyphIndex, - short numberOfContours, - DataInput di) throws IOException { + final GlyfTable parentTable, + final int glyphIndex, + final short numberOfContours, + final DataInput di) throws IOException { super(parentTable, glyphIndex, numberOfContours, di); - + // Simple glyph description _endPtsOfContours = new int[numberOfContours]; for (int i = 0; i < numberOfContours; i++) { @@ -86,36 +86,43 @@ public class GlyfSimpleDescript extends GlyfDescript { _xCoordinates = new short[_count]; _yCoordinates = new short[_count]; - int instructionCount = di.readShort(); + final int instructionCount = di.readShort(); readInstructions(di, instructionCount); readFlags(_count, di); readCoords(_count, di); } - public int getEndPtOfContours(int i) { + @Override + public int getEndPtOfContours(final int i) { return _endPtsOfContours[i]; } - public byte getFlags(int i) { + @Override + public byte getFlags(final int i) { return _flags[i]; } - public short getXCoordinate(int i) { + @Override + public short getXCoordinate(final int i) { return _xCoordinates[i]; } - public short getYCoordinate(int i) { + @Override + public short getYCoordinate(final int i) { return _yCoordinates[i]; } + @Override public boolean isComposite() { return false; } + @Override public int getPointCount() { return _count; } + @Override public int getContourCount() { return getNumberOfContours(); } @@ -131,7 +138,7 @@ public class GlyfSimpleDescript extends GlyfDescript { /** * The table is stored as relative values, but we'll store them as absolutes */ - private void readCoords(int count, DataInput di) throws IOException { + private void readCoords(final int count, final DataInput di) throws IOException { short x = 0; short y = 0; for (int i = 0; i < count; i++) { @@ -168,25 +175,26 @@ public class GlyfSimpleDescript extends GlyfDescript { /** * The flags are run-length encoded */ - private void readFlags(int flagCount, DataInput di) throws IOException { + private void readFlags(final int flagCount, final DataInput di) throws IOException { try { for (int index = 0; index < flagCount; index++) { _flags[index] = di.readByte(); if ((_flags[index] & repeat) != 0) { - int repeats = di.readByte(); + final int repeats = di.readByte(); for (int i = 1; i <= repeats; i++) { _flags[index + i] = _flags[index]; } index += repeats; } } - } catch (ArrayIndexOutOfBoundsException e) { + } catch (final ArrayIndexOutOfBoundsException e) { System.out.println("error: array index out of bounds"); } } - + + @Override public String toString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append(super.toString()); sb.append("\n\n EndPoints\n ---------"); for (int i = 0; i < _endPtsOfContours.length; i++) { diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfTable.java index 22fdd8886..6750e9394 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyfTable.java @@ -61,30 +61,30 @@ import java.io.IOException; */ public class GlyfTable implements Table { - private DirectoryEntry _de; - private GlyfDescript[] _descript; + private final DirectoryEntry _de; + private final GlyfDescript[] _descript; protected GlyfTable( - DirectoryEntry de, - DataInput di, - MaxpTable maxp, - LocaTable loca) throws IOException { + final DirectoryEntry de, + final DataInput di, + final MaxpTable maxp, + final LocaTable loca) throws IOException { _de = (DirectoryEntry) de.clone(); _descript = new GlyfDescript[maxp.getNumGlyphs()]; - + // Buffer the whole table so we can randomly access it - byte[] buf = new byte[de.getLength()]; + final byte[] buf = new byte[de.getLength()]; di.readFully(buf); - ByteArrayInputStream bais = new ByteArrayInputStream(buf); - + final ByteArrayInputStream bais = new ByteArrayInputStream(buf); + // Process all the simple glyphs for (int i = 0; i < maxp.getNumGlyphs(); i++) { - int len = loca.getOffset(i + 1) - loca.getOffset(i); + final int len = loca.getOffset(i + 1) - loca.getOffset(i); if (len > 0) { bais.reset(); bais.skip(loca.getOffset(i)); - DataInputStream dis = new DataInputStream(bais); - short numberOfContours = dis.readShort(); + final DataInputStream dis = new DataInputStream(bais); + final short numberOfContours = dis.readShort(); if (numberOfContours >= 0) { _descript[i] = new GlyfSimpleDescript(this, i, numberOfContours, dis); } @@ -95,12 +95,12 @@ public class GlyfTable implements Table { // Now do all the composite glyphs for (int i = 0; i < maxp.getNumGlyphs(); i++) { - int len = loca.getOffset(i + 1) - loca.getOffset(i); + final int len = loca.getOffset(i + 1) - loca.getOffset(i); if (len > 0) { bais.reset(); bais.skip(loca.getOffset(i)); - DataInputStream dis = new DataInputStream(bais); - short numberOfContours = dis.readShort(); + final DataInputStream dis = new DataInputStream(bais); + final short numberOfContours = dis.readShort(); if (numberOfContours < 0) { _descript[i] = new GlyfCompositeDescript(this, i, dis); } @@ -108,7 +108,7 @@ public class GlyfTable implements Table { } } - public GlyfDescript getDescription(int i) { + public GlyfDescript getDescription(final int i) { if (i < _descript.length) { return _descript[i]; } else { @@ -116,16 +116,18 @@ public class GlyfTable implements Table { } } + @Override public int getType() { return glyf; } - + /** * Get a directory entry for this table. This uniquely identifies the * table in collections where there may be more than one instance of a * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return _de; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyphDescription.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyphDescription.java index 106e17917..025778dfc 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyphDescription.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GlyphDescription.java @@ -56,29 +56,29 @@ package jogamp.graph.font.typecast.ot.table; * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public interface GlyphDescription { - + public int getGlyphIndex(); - + public int getEndPtOfContours(int i); - + public byte getFlags(int i); - + public short getXCoordinate(int i); - + public short getYCoordinate(int i); - + public short getXMaximum(); - + public short getXMinimum(); - + public short getYMaximum(); - + public short getYMinimum(); - + public boolean isComposite(); - + public int getPointCount(); - + public int getContourCount(); // public int getComponentIndex(int c); diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GposTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GposTable.java index 91a62362a..ce6f308db 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GposTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GposTable.java @@ -30,25 +30,27 @@ import java.io.IOException; */ public class GposTable implements Table { - private DirectoryEntry _de; + private final DirectoryEntry _de; - protected GposTable(DirectoryEntry de, DataInput di) throws IOException { + protected GposTable(final DirectoryEntry de, final DataInput di) throws IOException { _de = (DirectoryEntry) de.clone(); // GPOS Header - int version = di.readInt(); - int scriptList = di.readInt(); - int featureList = di.readInt(); - int lookupList = di.readInt(); + /* final int version = */ di.readInt(); + /* final int scriptList = */ di.readInt(); + /* final int featureList = */ di.readInt(); + /* final int lookupList = */ di.readInt(); } /** Get the table type, as a table directory value. * @return The table type */ + @Override public int getType() { return GPOS; } - + + @Override public String toString() { return "GPOS"; } @@ -59,8 +61,9 @@ public class GposTable implements Table { * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return _de; } - + } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GsubTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GsubTable.java index c002de374..3147fc8c5 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GsubTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GsubTable.java @@ -62,47 +62,48 @@ import java.io.IOException; */ public class GsubTable implements Table, LookupSubtableFactory { - private DirectoryEntry _de; - private ScriptList _scriptList; - private FeatureList _featureList; - private LookupList _lookupList; - - protected GsubTable(DirectoryEntry de, DataInput di) throws IOException { + private final DirectoryEntry _de; + private final ScriptList _scriptList; + private final FeatureList _featureList; + private final LookupList _lookupList; + + protected GsubTable(final DirectoryEntry de, final DataInput di) throws IOException { _de = (DirectoryEntry) de.clone(); - + // Load into a temporary buffer, and create another input stream - byte[] buf = new byte[de.getLength()]; + final byte[] buf = new byte[de.getLength()]; di.readFully(buf); - DataInputStream dis = new DataInputStream(new ByteArrayInputStream(buf)); + final DataInputStream dis = new DataInputStream(new ByteArrayInputStream(buf)); // GSUB Header - int version = dis.readInt(); - int scriptListOffset = dis.readUnsignedShort(); - int featureListOffset = dis.readUnsignedShort(); - int lookupListOffset = dis.readUnsignedShort(); + /* final int version = */ dis.readInt(); + final int scriptListOffset = dis.readUnsignedShort(); + final int featureListOffset = dis.readUnsignedShort(); + final int lookupListOffset = dis.readUnsignedShort(); // Script List _scriptList = new ScriptList(dis, scriptListOffset); // Feature List _featureList = new FeatureList(dis, featureListOffset); - + // Lookup List _lookupList = new LookupList(dis, lookupListOffset, this); } /** - * 1 - Single - Replace one glyph with one glyph - * 2 - Multiple - Replace one glyph with more than one glyph - * 3 - Alternate - Replace one glyph with one of many glyphs - * 4 - Ligature - Replace multiple glyphs with one glyph - * 5 - Context - Replace one or more glyphs in context + * 1 - Single - Replace one glyph with one glyph + * 2 - Multiple - Replace one glyph with more than one glyph + * 3 - Alternate - Replace one glyph with one of many glyphs + * 4 - Ligature - Replace multiple glyphs with one glyph + * 5 - Context - Replace one or more glyphs in context * 6 - Chaining - Context Replace one or more glyphs in chained context */ + @Override public LookupSubtable read( - int type, - DataInputStream dis, - int offset) throws IOException { + final int type, + final DataInputStream dis, + final int offset) throws IOException { LookupSubtable s = null; switch (type) { case 1: @@ -130,6 +131,7 @@ public class GsubTable implements Table, LookupSubtableFactory { /** Get the table type, as a table directory value. * @return The table type */ + @Override public int getType() { return GSUB; } @@ -146,11 +148,12 @@ public class GsubTable implements Table, LookupSubtableFactory { return _lookupList; } + @Override public String toString() { return "GSUB"; } - public static String lookupTypeAsString(int type) { + public static String lookupTypeAsString(final int type) { switch (type) { case 1: return "Single"; @@ -167,15 +170,16 @@ public class GsubTable implements Table, LookupSubtableFactory { } return "Unknown"; } - + /** * Get a directory entry for this table. This uniquely identifies the * table in collections where there may be more than one instance of a * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return _de; } - + } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/HdmxTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/HdmxTable.java index 5b1fa2020..2bd51c124 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/HdmxTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/HdmxTable.java @@ -30,14 +30,14 @@ import java.io.IOException; * @version $Id: HdmxTable.java,v 1.2 2007-07-26 11:12:30 davidsch Exp $ */ public class HdmxTable implements Table { - - public class DeviceRecord { - - private short _pixelSize; - private short _maxWidth; - private short[] _widths; - - protected DeviceRecord(int numGlyphs, DataInput di) throws IOException { + + public static class DeviceRecord { + + private final short _pixelSize; + private final short _maxWidth; + private final short[] _widths; + + protected DeviceRecord(final int numGlyphs, final DataInput di) throws IOException { _pixelSize = di.readByte(); _maxWidth = di.readByte(); _widths = new short[numGlyphs]; @@ -49,36 +49,36 @@ public class HdmxTable implements Table { public short getPixelSize() { return _pixelSize; } - + public short getMaxWidth() { return _maxWidth; } - + public short[] getWidths() { return _widths; } - public short getWidth(int glyphidx) { + public short getWidth(final int glyphidx) { return _widths[glyphidx]; } - + } - - private DirectoryEntry _de; - private int _version; - private short _numRecords; - private int _sizeDeviceRecords; - private DeviceRecord[] _records; + + private final DirectoryEntry _de; + private final int _version; + private final short _numRecords; + private final int _sizeDeviceRecords; + private final DeviceRecord[] _records; /** Creates a new instance of HdmxTable */ - protected HdmxTable(DirectoryEntry de, DataInput di, MaxpTable maxp) + protected HdmxTable(final DirectoryEntry de, final DataInput di, final MaxpTable maxp) throws IOException { _de = (DirectoryEntry) de.clone(); _version = di.readUnsignedShort(); _numRecords = di.readShort(); _sizeDeviceRecords = di.readInt(); _records = new DeviceRecord[_numRecords]; - + // Read the device records for (int i = 0; i < _numRecords; ++i) { _records[i] = new DeviceRecord(maxp.getNumGlyphs(), di); @@ -88,17 +88,19 @@ public class HdmxTable implements Table { public int getNumberOfRecords() { return _numRecords; } - - public DeviceRecord getRecord(int i) { + + public DeviceRecord getRecord(final int i) { return _records[i]; } - + + @Override public int getType() { return hdmx; } - + + @Override public String toString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append("'hdmx' Table - Horizontal Device Metrics\n----------------------------------------\n"); sb.append("Size = ").append(_de.getLength()).append(" bytes\n") .append("\t'hdmx' version: ").append(_version).append("\n") @@ -124,6 +126,7 @@ public class HdmxTable implements Table { * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return _de; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/HeadTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/HeadTable.java index 9d7fe4251..85158ea3e 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/HeadTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/HeadTable.java @@ -62,26 +62,26 @@ import jogamp.graph.font.typecast.ot.Fixed; */ public class HeadTable implements Table { - private DirectoryEntry _de; - private int _versionNumber; - private int _fontRevision; - private int _checkSumAdjustment; - private int _magicNumber; - private short _flags; - private short _unitsPerEm; - private long _created; - private long _modified; - private short _xMin; - private short _yMin; - private short _xMax; - private short _yMax; - private short _macStyle; - private short _lowestRecPPEM; - private short _fontDirectionHint; - private short _indexToLocFormat; - private short _glyphDataFormat; - - protected HeadTable(DirectoryEntry de, DataInput di) throws IOException { + private final DirectoryEntry _de; + private final int _versionNumber; + private final int _fontRevision; + private final int _checkSumAdjustment; + private final int _magicNumber; + private final short _flags; + private final short _unitsPerEm; + private final long _created; + private final long _modified; + private final short _xMin; + private final short _yMin; + private final short _xMax; + private final short _yMax; + private final short _macStyle; + private final short _lowestRecPPEM; + private final short _fontDirectionHint; + private final short _indexToLocFormat; + private final short _glyphDataFormat; + + protected HeadTable(final DirectoryEntry de, final DataInput di) throws IOException { this._de = (DirectoryEntry) de.clone(); _versionNumber = di.readInt(); _fontRevision = di.readInt(); @@ -142,6 +142,7 @@ public class HeadTable implements Table { return _modified; } + @Override public int getType() { return head; } @@ -170,6 +171,7 @@ public class HeadTable implements Table { return _yMin; } + @Override public String toString() { return new StringBuilder() .append("'head' Table - Font Header\n--------------------------") @@ -192,15 +194,16 @@ public class HeadTable implements Table { .append("\n glyphDataFormat: ").append(_glyphDataFormat) .toString(); } - + /** * Get a directory entry for this table. This uniquely identifies the * table in collections where there may be more than one instance of a * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return _de; } - + } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/HheaTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/HheaTable.java index 20a21e4d9..e67a03777 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/HheaTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/HheaTable.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -19,21 +19,21 @@ import jogamp.graph.font.typecast.ot.Fixed; */ public class HheaTable implements Table { - private DirectoryEntry de; - private int version; - private short ascender; - private short descender; - private short lineGap; - private short advanceWidthMax; - private short minLeftSideBearing; - private short minRightSideBearing; - private short xMaxExtent; - private short caretSlopeRise; - private short caretSlopeRun; - private short metricDataFormat; - private int numberOfHMetrics; - - protected HheaTable(DirectoryEntry de, DataInput di) throws IOException { + private final DirectoryEntry de; + private final int version; + private final short ascender; + private final short descender; + private final short lineGap; + private final short advanceWidthMax; + private final short minLeftSideBearing; + private final short minRightSideBearing; + private final short xMaxExtent; + private final short caretSlopeRise; + private final short caretSlopeRun; + private final short metricDataFormat; + private final int numberOfHMetrics; + + protected HheaTable(final DirectoryEntry de, final DataInput di) throws IOException { this.de = (DirectoryEntry) de.clone(); version = di.readInt(); ascender = di.readShort(); @@ -92,6 +92,7 @@ public class HheaTable implements Table { return numberOfHMetrics; } + @Override public int getType() { return hhea; } @@ -100,6 +101,7 @@ public class HheaTable implements Table { return xMaxExtent; } + @Override public String toString() { return new StringBuilder() .append("'hhea' Table - Horizontal Header\n--------------------------------") @@ -122,15 +124,16 @@ public class HheaTable implements Table { .append("\n numOf_LongHorMetrics: ").append(numberOfHMetrics) .toString(); } - + /** * Get a directory entry for this table. This uniquely identifies the * table in collections where there may be more than one instance of a * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return de; } - + } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/HmtxTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/HmtxTable.java index dacd9e265..3a9672a92 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/HmtxTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/HmtxTable.java @@ -59,15 +59,15 @@ import java.io.IOException; */ public class HmtxTable implements Table { - private DirectoryEntry _de; + private final DirectoryEntry _de; private int[] _hMetrics = null; private short[] _leftSideBearing = null; protected HmtxTable( - DirectoryEntry de, - DataInput di, - HheaTable hhea, - MaxpTable maxp) throws IOException { + final DirectoryEntry de, + final DataInput di, + final HheaTable hhea, + final MaxpTable maxp) throws IOException { _de = (DirectoryEntry) de.clone(); _hMetrics = new int[hhea.getNumberOfHMetrics()]; for (int i = 0; i < hhea.getNumberOfHMetrics(); ++i) { @@ -77,14 +77,14 @@ public class HmtxTable implements Table { | di.readUnsignedByte()<<8 | di.readUnsignedByte(); } - int lsbCount = maxp.getNumGlyphs() - hhea.getNumberOfHMetrics(); + final int lsbCount = maxp.getNumGlyphs() - hhea.getNumberOfHMetrics(); _leftSideBearing = new short[lsbCount]; for (int i = 0; i < lsbCount; ++i) { _leftSideBearing[i] = di.readShort(); } } - public int getAdvanceWidth(int i) { + public int getAdvanceWidth(final int i) { if (_hMetrics == null) { return 0; } @@ -95,7 +95,7 @@ public class HmtxTable implements Table { } } - public short getLeftSideBearing(int i) { + public short getLeftSideBearing(final int i) { if (_hMetrics == null) { return 0; } @@ -106,12 +106,14 @@ public class HmtxTable implements Table { } } + @Override public int getType() { return hmtx; } + @Override public String toString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append("'hmtx' Table - Horizontal Metrics\n---------------------------------\n"); sb.append("Size = ").append(_de.getLength()).append(" bytes, ") .append(_hMetrics.length).append(" entries\n"); @@ -135,6 +137,7 @@ public class HmtxTable implements Table { * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return _de; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ID.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ID.java index 9fd66e728..ad7e4e376 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ID.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ID.java @@ -38,7 +38,7 @@ public abstract class ID { public static final short encodingUnicode11Semantics = 1; public static final short encodingISO10646Semantics = 2; public static final short encodingUnicode20Semantics = 3; - + // Microsoft Encoding IDs // public static final short encodingUndefined = 0; // public static final short encodingUGL = 1; @@ -190,7 +190,7 @@ public abstract class ID { public static final short nameSampleText = 19; public static final short namePostScriptCIDFindfontName = 20; - public static String getPlatformName(short platformId) { + public static String getPlatformName(final short platformId) { switch (platformId) { case platformUnicode: return "Unicode"; case platformMacintosh: return "Macintosh"; @@ -200,10 +200,10 @@ public abstract class ID { } } - public static String getEncodingName(short platformId, short encodingId) { + public static String getEncodingName(final short platformId, final short encodingId) { if (platformId == platformUnicode) { - + // Unicode specific encodings switch (encodingId) { case encodingUnicode10Semantics: return "Unicode 1.0 semantics"; @@ -284,7 +284,7 @@ public abstract class ID { return ""; } - public static String getLanguageName(short platformId, short languageId) { + public static String getLanguageName(final short platformId, final short languageId) { if (platformId == platformMacintosh) { switch (languageId) { @@ -371,7 +371,7 @@ public abstract class ID { return ""; } - public static String getNameName(short nameId) { + public static String getNameName(final short nameId) { switch (nameId) { case nameCopyrightNotice: return "Copyright notice"; case nameFontFamilyName: return "Font Family name"; diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/KernSubtable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/KernSubtable.java index 7a4cccba2..dcf02cb2b 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/KernSubtable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/KernSubtable.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -21,18 +21,18 @@ public abstract class KernSubtable { /** Creates new KernSubtable */ protected KernSubtable() { } - + public abstract int getKerningPairCount(); public abstract KerningPair getKerningPair(int i); - public static KernSubtable read(DataInput di) throws IOException { + public static KernSubtable read(final DataInput di) throws IOException { KernSubtable table = null; - int version = di.readUnsignedShort(); - int length = di.readUnsignedShort(); - int coverage = di.readUnsignedShort(); - int format = coverage >> 8; - + /* final int version = */ di.readUnsignedShort(); + /* final int length = */ di.readUnsignedShort(); + final int coverage = di.readUnsignedShort(); + final int format = coverage >> 8; + switch (format) { case 0: table = new KernSubtableFormat0(di); diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/KernSubtableFormat0.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/KernSubtableFormat0.java index b55bef6d5..2d1acddd5 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/KernSubtableFormat0.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/KernSubtableFormat0.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -17,15 +17,15 @@ import java.io.IOException; * @version $Id: KernSubtableFormat0.java,v 1.1.1.1 2004-12-05 23:14:48 davidsch Exp $ */ public class KernSubtableFormat0 extends KernSubtable { - - private int nPairs; - private int searchRange; - private int entrySelector; - private int rangeShift; - private KerningPair[] kerningPairs; + + private final int nPairs; + private final int searchRange; + private final int entrySelector; + private final int rangeShift; + private final KerningPair[] kerningPairs; /** Creates new KernSubtableFormat0 */ - protected KernSubtableFormat0(DataInput di) throws IOException { + protected KernSubtableFormat0(final DataInput di) throws IOException { nPairs = di.readUnsignedShort(); searchRange = di.readUnsignedShort(); entrySelector = di.readUnsignedShort(); @@ -36,11 +36,13 @@ public class KernSubtableFormat0 extends KernSubtable { } } + @Override public int getKerningPairCount() { return nPairs; } - public KerningPair getKerningPair(int i) { + @Override + public KerningPair getKerningPair(final int i) { return kerningPairs[i]; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/KernSubtableFormat2.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/KernSubtableFormat2.java index 60d584ca6..deb56c96d 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/KernSubtableFormat2.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/KernSubtableFormat2.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -18,24 +18,26 @@ import java.io.IOException; */ public class KernSubtableFormat2 extends KernSubtable { - private int rowWidth; - private int leftClassTable; - private int rightClassTable; - private int array; + private final int rowWidth; + private final int leftClassTable; + private final int rightClassTable; + private final int array; /** Creates new KernSubtableFormat2 */ - protected KernSubtableFormat2(DataInput di) throws IOException { + protected KernSubtableFormat2(final DataInput di) throws IOException { rowWidth = di.readUnsignedShort(); leftClassTable = di.readUnsignedShort(); rightClassTable = di.readUnsignedShort(); array = di.readUnsignedShort(); } + @Override public int getKerningPairCount() { return 0; } - public KerningPair getKerningPair(int i) { + @Override + public KerningPair getKerningPair(final int i) { return null; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/KernTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/KernTable.java index 70aee70d2..6f1d682e1 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/KernTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/KernTable.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -17,14 +17,14 @@ import java.io.IOException; * @version $Id: KernTable.java,v 1.1.1.1 2004-12-05 23:14:48 davidsch Exp $ */ public class KernTable implements Table { - - private DirectoryEntry de; - private int version; - private int nTables; - private KernSubtable[] tables; + + private final DirectoryEntry de; + private final int version; + private final int nTables; + private final KernSubtable[] tables; /** Creates new KernTable */ - protected KernTable(DirectoryEntry de, DataInput di) throws IOException { + protected KernTable(final DirectoryEntry de, final DataInput di) throws IOException { this.de = (DirectoryEntry) de.clone(); version = di.readUnsignedShort(); nTables = di.readUnsignedShort(); @@ -37,14 +37,15 @@ public class KernTable implements Table { public int getSubtableCount() { return nTables; } - - public KernSubtable getSubtable(int i) { + + public KernSubtable getSubtable(final int i) { return tables[i]; } /** Get the table type, as a table directory value. * @return The table type */ + @Override public int getType() { return kern; } @@ -55,8 +56,9 @@ public class KernTable implements Table { * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return de; } - + } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/KerningPair.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/KerningPair.java index ce7cebc97..dd5d0ba06 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/KerningPair.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/KerningPair.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -18,12 +18,12 @@ import java.io.IOException; */ public class KerningPair { - private int left; - private int right; - private short value; + private final int left; + private final int right; + private final short value; /** Creates new KerningPair */ - protected KerningPair(DataInput di) throws IOException { + protected KerningPair(final DataInput di) throws IOException { left = di.readUnsignedShort(); right = di.readUnsignedShort(); value = di.readShort(); diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LangSys.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LangSys.java index 6759208f5..e12d2e2e7 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LangSys.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LangSys.java @@ -60,13 +60,13 @@ import java.io.IOException; */ public class LangSys { - private int _lookupOrder; - private int _reqFeatureIndex; - private int _featureCount; - private int[] _featureIndex; - + private final int _lookupOrder; + private final int _reqFeatureIndex; + private final int _featureCount; + private final int[] _featureIndex; + /** Creates new LangSys */ - protected LangSys(DataInput di) throws IOException { + protected LangSys(final DataInput di) throws IOException { _lookupOrder = di.readUnsignedShort(); _reqFeatureIndex = di.readUnsignedShort(); _featureCount = di.readUnsignedShort(); @@ -75,24 +75,24 @@ public class LangSys { _featureIndex[i] = di.readUnsignedShort(); } } - + public int getLookupOrder() { return _lookupOrder; } - + public int getReqFeatureIndex() { return _reqFeatureIndex; } - + public int getFeatureCount() { return _featureCount; } - - public int getFeatureIndex(int i) { + + public int getFeatureIndex(final int i) { return _featureIndex[i]; } - protected boolean isFeatureIndexed(int n) { + protected boolean isFeatureIndexed(final int n) { for (int i = 0; i < _featureCount; i++) { if (_featureIndex[i] == n) { return true; diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LangSysRecord.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LangSysRecord.java index 9511f66ba..08ea719f3 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LangSysRecord.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LangSysRecord.java @@ -60,11 +60,11 @@ import java.io.IOException; */ public class LangSysRecord { - private int _tag; - private int _offset; - + private final int _tag; + private final int _offset; + /** Creates new LangSysRecord */ - public LangSysRecord(DataInput di) throws IOException { + public LangSysRecord(final DataInput di) throws IOException { _tag = di.readInt(); _offset = di.readUnsignedShort(); } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Ligature.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Ligature.java index d3e2ad5cd..dfd19e7ac 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Ligature.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Ligature.java @@ -60,12 +60,12 @@ import java.io.IOException; */ public class Ligature { - private int _ligGlyph; - private int _compCount; - private int[] _components; + private final int _ligGlyph; + private final int _compCount; + private final int[] _components; /** Creates new Ligature */ - public Ligature(DataInput di) throws IOException { + public Ligature(final DataInput di) throws IOException { _ligGlyph = di.readUnsignedShort(); _compCount = di.readUnsignedShort(); _components = new int[_compCount - 1]; @@ -73,12 +73,12 @@ public class Ligature { _components[i] = di.readUnsignedShort(); } } - + public int getGlyphCount() { return _compCount; } - - public int getGlyphId(int i) { + + public int getGlyphId(final int i) { return (i == 0) ? _ligGlyph : _components[i-1]; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LigatureSet.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LigatureSet.java index e261f3a88..8b7738992 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LigatureSet.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LigatureSet.java @@ -60,12 +60,12 @@ import java.io.IOException; */ public class LigatureSet { - private int _ligatureCount; - private int[] _ligatureOffsets; - private Ligature[] _ligatures; + private final int _ligatureCount; + private final int[] _ligatureOffsets; + private final Ligature[] _ligatures; /** Creates new LigatureSet */ - public LigatureSet(DataInputStream dis, int offset) throws IOException { + public LigatureSet(final DataInputStream dis, final int offset) throws IOException { dis.reset(); dis.skipBytes(offset); _ligatureCount = dis.readUnsignedShort(); diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LigatureSubst.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LigatureSubst.java index c0570cde9..36a44a11e 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LigatureSubst.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LigatureSubst.java @@ -60,10 +60,10 @@ import java.io.IOException; */ public abstract class LigatureSubst extends LookupSubtable { - public static LigatureSubst read(DataInputStream dis, int offset) throws IOException { + public static LigatureSubst read(final DataInputStream dis, final int offset) throws IOException { dis.reset(); dis.skipBytes(offset); - int format = dis.readUnsignedShort(); + final int format = dis.readUnsignedShort(); if (format == 1) { return new LigatureSubstFormat1(dis, offset); } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LigatureSubstFormat1.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LigatureSubstFormat1.java index a0f42662c..02d4479b3 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LigatureSubstFormat1.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LigatureSubstFormat1.java @@ -60,16 +60,16 @@ import java.io.IOException; */ public class LigatureSubstFormat1 extends LigatureSubst { - private int _coverageOffset; - private int _ligSetCount; - private int[] _ligatureSetOffsets; - private Coverage _coverage; - private LigatureSet[] _ligatureSets; + private final int _coverageOffset; + private final int _ligSetCount; + private final int[] _ligatureSetOffsets; + private final Coverage _coverage; + private final LigatureSet[] _ligatureSets; /** Creates new LigatureSubstFormat1 */ protected LigatureSubstFormat1( - DataInputStream dis, - int offset) throws IOException { + final DataInputStream dis, + final int offset) throws IOException { _coverageOffset = dis.readUnsignedShort(); _ligSetCount = dis.readUnsignedShort(); _ligatureSetOffsets = new int[_ligSetCount]; @@ -89,7 +89,8 @@ public class LigatureSubstFormat1 extends LigatureSubst { return 1; } + @Override public String getTypeAsString() { return "LigatureSubstFormat1"; - } + } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LocaTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LocaTable.java index 5eb7c5856..a955ad3e5 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LocaTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LocaTable.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -17,18 +17,18 @@ import java.io.IOException; */ public class LocaTable implements Table { - private DirectoryEntry _de; + private final DirectoryEntry _de; private int[] _offsets = null; private short _factor = 0; protected LocaTable( - DirectoryEntry de, - DataInput di, - HeadTable head, - MaxpTable maxp) throws IOException { + final DirectoryEntry de, + final DataInput di, + final HeadTable head, + final MaxpTable maxp) throws IOException { _de = (DirectoryEntry) de.clone(); _offsets = new int[maxp.getNumGlyphs() + 1]; - boolean shortEntries = head.getIndexToLocFormat() == 0; + final boolean shortEntries = head.getIndexToLocFormat() == 0; if (shortEntries) { _factor = 2; for (int i = 0; i <= maxp.getNumGlyphs(); i++) { @@ -42,19 +42,21 @@ public class LocaTable implements Table { } } - public int getOffset(int i) { + public int getOffset(final int i) { if (_offsets == null) { return 0; } return _offsets[i] * _factor; } + @Override public int getType() { return loca; } + @Override public String toString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append("'loca' Table - Index To Location Table\n--------------------------------------\n") .append("Size = ").append(_de.getLength()).append(" bytes, ") .append(_offsets.length).append(" entries\n"); @@ -64,13 +66,14 @@ public class LocaTable implements Table { } return sb.toString(); } - + /** * Get a directory entry for this table. This uniquely identifies the * table in collections where there may be more than one instance of a * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return _de; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Lookup.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Lookup.java index 2899c24d9..b80ebbee4 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Lookup.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Lookup.java @@ -66,20 +66,20 @@ public class Lookup { public static final int IGNORE_BASE_MARKS = 0x0008; public static final int MARK_ATTACHMENT_TYPE = 0xFF00; - private int _type; - private int _flag; - private int _subTableCount; - private int[] _subTableOffsets; - private LookupSubtable[] _subTables; + private final int _type; + private final int _flag; + private final int _subTableCount; + private final int[] _subTableOffsets; + private final LookupSubtable[] _subTables; /** Creates new Lookup */ - public Lookup(LookupSubtableFactory factory, DataInputStream dis, int offset) + public Lookup(final LookupSubtableFactory factory, final DataInputStream dis, final int offset) throws IOException { // Ensure we're in the right place dis.reset(); dis.skipBytes(offset); - + // Start reading _type = dis.readUnsignedShort(); _flag = dis.readUnsignedShort(); @@ -102,7 +102,7 @@ public class Lookup { return _subTableCount; } - public LookupSubtable getSubtable(int i) { + public LookupSubtable getSubtable(final int i) { return _subTables[i]; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LookupList.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LookupList.java index a3b71b639..6d8ca2a6c 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LookupList.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LookupList.java @@ -60,18 +60,18 @@ import java.io.IOException; */ public class LookupList { - private int _lookupCount; - private int[] _lookupOffsets; - private Lookup[] _lookups; + private final int _lookupCount; + private final int[] _lookupOffsets; + private final Lookup[] _lookups; /** Creates new LookupList */ - public LookupList(DataInputStream dis, int offset, LookupSubtableFactory factory) + public LookupList(final DataInputStream dis, final int offset, final LookupSubtableFactory factory) throws IOException { - + // Ensure we're in the right place dis.reset(); dis.skipBytes(offset); - + // Start reading _lookupCount = dis.readUnsignedShort(); _lookupOffsets = new int[_lookupCount]; @@ -87,18 +87,18 @@ public class LookupList { public int getLookupCount() { return _lookupCount; } - - public int getLookupOffset(int i) { + + public int getLookupOffset(final int i) { return _lookupOffsets[i]; } - - public Lookup getLookup(int i) { + + public Lookup getLookup(final int i) { return _lookups[i]; } - public Lookup getLookup(Feature feature, int index) { + public Lookup getLookup(final Feature feature, final int index) { if (feature.getLookupCount() > index) { - int i = feature.getLookupListIndex(index); + final int i = feature.getLookupListIndex(index); return _lookups[i]; } return null; diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LookupSubtableFactory.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LookupSubtableFactory.java index cb4d28d2c..ca67df7fb 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LookupSubtableFactory.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LookupSubtableFactory.java @@ -47,13 +47,13 @@ Apache Software Foundation, please see <http://www.apache.org/>. */ - + package jogamp.graph.font.typecast.ot.table; import java.io.DataInputStream; import java.io.IOException; -/** +/** * * @author <a href="mailto:[email protected]">David Schweinsberg</a> * @version $Id: LookupSubtableFactory.java,v 1.2 2007-01-24 09:47:46 davidsch Exp $ diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LtshTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LtshTable.java index ace3d38b5..efafe7bb6 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LtshTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LtshTable.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -18,13 +18,13 @@ import java.io.IOException; */ public class LtshTable implements Table { - private DirectoryEntry de; - private int version; - private int numGlyphs; - private int[] yPels; - + private final DirectoryEntry de; + private final int version; + private final int numGlyphs; + private final int[] yPels; + /** Creates new LtshTable */ - protected LtshTable(DirectoryEntry de, DataInput di) throws IOException { + protected LtshTable(final DirectoryEntry de, final DataInput di) throws IOException { this.de = (DirectoryEntry) de.clone(); version = di.readUnsignedShort(); numGlyphs = di.readUnsignedShort(); @@ -38,12 +38,14 @@ public class LtshTable implements Table { * Get the table type, as a table directory value. * @return The table type */ + @Override public int getType() { return LTSH; } - + + @Override public String toString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append("'LTSH' Table - Linear Threshold Table\n-------------------------------------") .append("\n 'LTSH' Version: ").append(version) .append("\n Number of Glyphs: ").append(numGlyphs) @@ -54,15 +56,16 @@ public class LtshTable implements Table { } return sb.toString(); } - + /** * Get a directory entry for this table. This uniquely identifies the * table in collections where there may be more than one instance of a * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return de; } - + } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/MaxpTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/MaxpTable.java index 0e8ec44c7..0e9a6177f 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/MaxpTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/MaxpTable.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -19,8 +19,8 @@ import jogamp.graph.font.typecast.ot.Fixed; */ public class MaxpTable implements Table { - private DirectoryEntry de; - private int versionNumber; + private final DirectoryEntry de; + private final int versionNumber; private int numGlyphs; private int maxPoints; private int maxContours; @@ -36,10 +36,10 @@ public class MaxpTable implements Table { private int maxComponentElements; private int maxComponentDepth; - protected MaxpTable(DirectoryEntry de, DataInput di) throws IOException { + protected MaxpTable(final DirectoryEntry de, final DataInput di) throws IOException { this.de = (DirectoryEntry) de.clone(); versionNumber = di.readInt(); - + // CFF fonts use version 0.5, TrueType fonts use version 1.0 if (versionNumber == 0x00005000) { numGlyphs = di.readUnsignedShort(); @@ -121,12 +121,14 @@ public class MaxpTable implements Table { return numGlyphs; } + @Override public int getType() { return maxp; } + @Override public String toString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append("'maxp' Table - Maximum Profile\n------------------------------") .append("\n 'maxp' version: ").append(Fixed.floatValue(versionNumber)) .append("\n numGlyphs: ").append(numGlyphs); @@ -149,15 +151,16 @@ public class MaxpTable implements Table { } return sb.toString(); } - + /** * Get a directory entry for this table. This uniquely identifies the * table in collections where there may be more than one instance of a * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return de; } - + } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/NameRecord.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/NameRecord.java index 268d6cfca..5ac9ada29 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/NameRecord.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/NameRecord.java @@ -59,15 +59,15 @@ import java.io.IOException; */ public class NameRecord { - private short _platformId; - private short _encodingId; - private short _languageId; - private short _nameId; - private short _stringLength; - private short _stringOffset; + private final short _platformId; + private final short _encodingId; + private final short _languageId; + private final short _nameId; + private final short _stringLength; + private final short _stringOffset; private String _record; - protected NameRecord(DataInput di) throws IOException { + protected NameRecord(final DataInput di) throws IOException { _platformId = di.readShort(); _encodingId = di.readShort(); _languageId = di.readShort(); @@ -75,33 +75,33 @@ public class NameRecord { _stringLength = di.readShort(); _stringOffset = di.readShort(); } - + public short getEncodingId() { return _encodingId; } - + public short getLanguageId() { return _languageId; } - + public short getNameId() { return _nameId; } - + public short getPlatformId() { return _platformId; } - public StringBuilder getRecordString(StringBuilder sb) { + public StringBuilder getRecordString(final StringBuilder sb) { sb.append(_record); return sb; } - protected void loadString(DataInput di) throws IOException { - StringBuilder sb = new StringBuilder(); + protected void loadString(final DataInput di) throws IOException { + final StringBuilder sb = new StringBuilder(); di.skipBytes(_stringOffset); if (_platformId == ID.platformUnicode) { - + // Unicode (big-endian) for (int i = 0; i < _stringLength/2; i++) { sb.append(di.readChar()); @@ -113,13 +113,13 @@ public class NameRecord { sb.append((char) di.readByte()); } } else if (_platformId == ID.platformISO) { - + // ISO encoding, ASCII for (int i = 0; i < _stringLength; i++) { sb.append((char) di.readByte()); } } else if (_platformId == ID.platformMicrosoft) { - + // Microsoft encoding, Unicode char c; for (int i = 0; i < _stringLength/2; i++) { @@ -130,9 +130,10 @@ public class NameRecord { _record = sb.toString(); } + @Override public String toString() { - StringBuilder sb = new StringBuilder(); - + final StringBuilder sb = new StringBuilder(); + sb.append(" Platform ID: ").append(_platformId) .append("\n Specific ID: ").append(_encodingId) .append("\n Language ID: ").append(_languageId) @@ -140,7 +141,7 @@ public class NameRecord { .append("\n Length: ").append(_stringLength) .append("\n Offset: ").append(_stringOffset) .append("\n\n").append(_record); - + return sb.toString(); } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/NameTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/NameTable.java index 6daf2ad60..ba9292a4b 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/NameTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/NameTable.java @@ -63,30 +63,30 @@ import java.io.IOException; * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class NameTable implements Table { - private DirectoryEntry _de; - private short _formatSelector; - private short _numberOfNameRecords; - private short _stringStorageOffset; - private NameRecord[] _records; - - protected NameTable(DirectoryEntry de, DataInput di) throws IOException { + private final DirectoryEntry _de; + private final short _formatSelector; + private final short _numberOfNameRecords; + private final short _stringStorageOffset; + private final NameRecord[] _records; + + protected NameTable(final DirectoryEntry de, final DataInput di) throws IOException { _de = (DirectoryEntry) de.clone(); _formatSelector = di.readShort(); _numberOfNameRecords = di.readShort(); _stringStorageOffset = di.readShort(); _records = new NameRecord[_numberOfNameRecords]; - + // Load the records, which contain the encoding information and string // offsets for (int i = 0; i < _numberOfNameRecords; i++) { _records[i] = new NameRecord(di); } - + // Load the string data into a buffer so the records can copy out the // bits they are interested in - byte[] buffer = new byte[_de.getLength() - _stringStorageOffset]; + final byte[] buffer = new byte[_de.getLength() - _stringStorageOffset]; di.readFully(buffer); - + // Now let the records get their hands on them for (int i = 0; i < _numberOfNameRecords; i++) { _records[i].loadString( @@ -98,15 +98,15 @@ public class NameTable implements Table { return _numberOfNameRecords; } - - public NameRecord getRecord(int i) { + + public NameRecord getRecord(final int i) { if(_numberOfNameRecords > i) { return _records[i]; } return null; } - public StringBuilder getRecordsRecordString(StringBuilder sb, int i) { + public StringBuilder getRecordsRecordString(final StringBuilder sb, final int i) { if(_numberOfNameRecords > i) { _records[i].getRecordString(sb); } else { @@ -115,7 +115,7 @@ public class NameTable implements Table { return sb; } - public StringBuilder getNamedRecordString(StringBuilder sb, short nameId) { + public StringBuilder getNamedRecordString(final StringBuilder sb, final short nameId) { // Search for the first instance of this name ID boolean done = false; for (int i = 0; !done && i < _numberOfNameRecords; i++) { @@ -130,18 +130,20 @@ public class NameTable implements Table { return sb; } + @Override public int getType() { return name; } - + /** * Get a directory entry for this table. This uniquely identifies the * table in collections where there may be more than one instance of a * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return _de; } - + } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Os2Table.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Os2Table.java index f4fa76e81..c91127303 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Os2Table.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Os2Table.java @@ -59,46 +59,46 @@ import java.io.IOException; */ public class Os2Table implements Table { - private DirectoryEntry _de; - private int _version; - private short _xAvgCharWidth; - private int _usWeightClass; - private int _usWidthClass; - private short _fsType; - private short _ySubscriptXSize; - private short _ySubscriptYSize; - private short _ySubscriptXOffset; - private short _ySubscriptYOffset; - private short _ySuperscriptXSize; - private short _ySuperscriptYSize; - private short _ySuperscriptXOffset; - private short _ySuperscriptYOffset; - private short _yStrikeoutSize; - private short _yStrikeoutPosition; - private short _sFamilyClass; - private Panose _panose; - private int _ulUnicodeRange1; - private int _ulUnicodeRange2; - private int _ulUnicodeRange3; - private int _ulUnicodeRange4; - private int _achVendorID; - private short _fsSelection; - private int _usFirstCharIndex; - private int _usLastCharIndex; - private short _sTypoAscender; - private short _sTypoDescender; - private short _sTypoLineGap; - private int _usWinAscent; - private int _usWinDescent; - private int _ulCodePageRange1; - private int _ulCodePageRange2; + private final DirectoryEntry _de; + private final int _version; + private final short _xAvgCharWidth; + private final int _usWeightClass; + private final int _usWidthClass; + private final short _fsType; + private final short _ySubscriptXSize; + private final short _ySubscriptYSize; + private final short _ySubscriptXOffset; + private final short _ySubscriptYOffset; + private final short _ySuperscriptXSize; + private final short _ySuperscriptYSize; + private final short _ySuperscriptXOffset; + private final short _ySuperscriptYOffset; + private final short _yStrikeoutSize; + private final short _yStrikeoutPosition; + private final short _sFamilyClass; + private final Panose _panose; + private final int _ulUnicodeRange1; + private final int _ulUnicodeRange2; + private final int _ulUnicodeRange3; + private final int _ulUnicodeRange4; + private final int _achVendorID; + private final short _fsSelection; + private final int _usFirstCharIndex; + private final int _usLastCharIndex; + private final short _sTypoAscender; + private final short _sTypoDescender; + private final short _sTypoLineGap; + private final int _usWinAscent; + private final int _usWinDescent; + private final int _ulCodePageRange1; + private final int _ulCodePageRange2; private short _sxHeight; private short _sCapHeight; private int _usDefaultChar; private int _usBreakChar; private int _usMaxContext; - protected Os2Table(DirectoryEntry de, DataInput di) throws IOException { + protected Os2Table(final DirectoryEntry de, final DataInput di) throws IOException { this._de = (DirectoryEntry) de.clone(); _version = di.readUnsignedShort(); _xAvgCharWidth = di.readShort(); @@ -116,7 +116,7 @@ public class Os2Table implements Table { _yStrikeoutSize = di.readShort(); _yStrikeoutPosition = di.readShort(); _sFamilyClass = di.readShort(); - byte[] buf = new byte[10]; + final byte[] buf = new byte[10]; di.readFully(buf); _panose = new Panose(buf); _ulUnicodeRange1 = di.readInt(); @@ -134,7 +134,7 @@ public class Os2Table implements Table { _usWinDescent = di.readUnsignedShort(); _ulCodePageRange1 = di.readInt(); _ulCodePageRange2 = di.readInt(); - + // OpenType 1.3 if (_version == 2) { _sxHeight = di.readShort(); @@ -276,27 +276,29 @@ public class Os2Table implements Table { public short getXHeight() { return _sxHeight; } - + public short getCapHeight() { return _sCapHeight; } - + public int getDefaultChar() { return _usDefaultChar; } - + public int getBreakChar() { return _usBreakChar; } - + public int getMaxContext() { return _usMaxContext; } + @Override public int getType() { return OS_2; } + @Override public String toString() { return new StringBuilder() .append("'OS/2' Table - OS/2 and Windows Metrics\n---------------------------------------") @@ -335,7 +337,7 @@ public class Os2Table implements Table { .append("\n CodePage Range 2( Bits 32- 63 ): ").append(Integer.toHexString(_ulCodePageRange2).toUpperCase()) .toString(); } - + private String getVendorIDAsString() { return new StringBuilder() .append((char)((_achVendorID>>24)&0xff)) @@ -344,13 +346,14 @@ public class Os2Table implements Table { .append((char)((_achVendorID)&0xff)) .toString(); } - + /** * Get a directory entry for this table. This uniquely identifies the * table in collections where there may be more than one instance of a * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return _de; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Panose.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Panose.java index 6127140d1..493f43baa 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Panose.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Panose.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -26,7 +26,7 @@ public class Panose { byte bXHeight = 0; /** Creates new Panose */ - public Panose(byte[] panose) { + public Panose(final byte[] panose) { bFamilyType = panose[0]; bSerifStyle = panose[1]; bWeight = panose[2]; @@ -42,11 +42,11 @@ public class Panose { public byte getFamilyType() { return bFamilyType; } - + public byte getSerifStyle() { return bSerifStyle; } - + public byte getWeight() { return bWeight; } @@ -54,33 +54,34 @@ public class Panose { public byte getProportion() { return bProportion; } - + public byte getContrast() { return bContrast; } - + public byte getStrokeVariation() { return bStrokeVariation; } - + public byte getArmStyle() { return bArmStyle; } - + public byte getLetterForm() { return bLetterform; } - + public byte getMidline() { return bMidline; } - + public byte getXHeight() { return bXHeight; } - + + @Override public String toString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append(String.valueOf(bFamilyType)).append(" ") .append(String.valueOf(bSerifStyle)).append(" ") .append(String.valueOf(bWeight)).append(" ") diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/PcltTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/PcltTable.java index f9dcf2ce7..63399cf0e 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/PcltTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/PcltTable.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -18,25 +18,25 @@ import java.io.IOException; */ public class PcltTable implements Table { - private DirectoryEntry de; - private int version; - private long fontNumber; - private int pitch; - private int xHeight; - private int style; - private int typeFamily; - private int capHeight; - private int symbolSet; - private char[] typeface = new char[16]; - private short[] characterComplement = new short[8]; - private char[] fileName = new char[6]; - private short strokeWeight; - private short widthType; - private byte serifStyle; - private byte reserved; + private final DirectoryEntry de; + private final int version; + private final long fontNumber; + private final int pitch; + private final int xHeight; + private final int style; + private final int typeFamily; + private final int capHeight; + private final int symbolSet; + private final char[] typeface = new char[16]; + private final short[] characterComplement = new short[8]; + private final char[] fileName = new char[6]; + private final short strokeWeight; + private final short widthType; + private final byte serifStyle; + private final byte reserved; /** Creates new PcltTable */ - protected PcltTable(DirectoryEntry de, DataInput di) throws IOException { + protected PcltTable(final DirectoryEntry de, final DataInput di) throws IOException { this.de = (DirectoryEntry) de.clone(); version = di.readInt(); fontNumber = di.readInt(); @@ -65,10 +65,12 @@ public class PcltTable implements Table { * Get the table type, as a table directory value. * @return The table type */ + @Override public int getType() { return PCLT; } - + + @Override public String toString() { return new StringBuilder() .append("'PCLT' Table - Printer Command Language Table\n---------------------------------------------") @@ -91,15 +93,16 @@ public class PcltTable implements Table { .append("\n reserved: ").append(reserved) .toString(); } - + /** * Get a directory entry for this table. This uniquely identifies the * table in collections where there may be more than one instance of a * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return de; } - + } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/PostTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/PostTable.java index c913b4c71..f4dd31465 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/PostTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/PostTable.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -284,24 +284,24 @@ public class PostTable implements Table { "" // 257 }; - private DirectoryEntry de; - private int version; - private int italicAngle; - private short underlinePosition; - private short underlineThickness; - private int isFixedPitch; - private int minMemType42; - private int maxMemType42; - private int minMemType1; - private int maxMemType1; - + private final DirectoryEntry de; + private final int version; + private final int italicAngle; + private final short underlinePosition; + private final short underlineThickness; + private final int isFixedPitch; + private final int minMemType42; + private final int maxMemType42; + private final int minMemType1; + private final int maxMemType1; + // v2 private int numGlyphs; private int[] glyphNameIndex; private String[] psGlyphName; /** Creates new PostTable */ - protected PostTable(DirectoryEntry de, DataInput di) throws IOException { + protected PostTable(final DirectoryEntry de, final DataInput di) throws IOException { this.de = (DirectoryEntry) de.clone(); version = di.readInt(); italicAngle = di.readInt(); @@ -312,7 +312,7 @@ public class PostTable implements Table { maxMemType42 = di.readInt(); minMemType1 = di.readInt(); maxMemType1 = di.readInt(); - + if (version == 0x00020000) { numGlyphs = di.readUnsignedShort(); glyphNameIndex = new int[numGlyphs]; @@ -324,14 +324,14 @@ public class PostTable implements Table { h -= 257; psGlyphName = new String[h]; for (int i = 0; i < h; i++) { - int len = di.readUnsignedByte(); - byte[] buf = new byte[len]; + final int len = di.readUnsignedByte(); + final byte[] buf = new byte[len]; di.readFully(buf); psGlyphName[i] = new String(buf); } } - } else if (version == 0x00025000) { - } else if (version == 0x00030000) { + // } else if (version == 0x00025000) { + // } else if (version == 0x00030000) { } } @@ -349,7 +349,7 @@ public class PostTable implements Table { return high; } - public String getGlyphName(int i) { + public String getGlyphName(final int i) { if (version == 0x00020000) { return (glyphNameIndex[i] > 257) ? psGlyphName[glyphNameIndex[i] - 258] @@ -359,23 +359,25 @@ public class PostTable implements Table { } } - private boolean isMacGlyphName(int i) { + private boolean isMacGlyphName(final int i) { if (version == 0x00020000) { return glyphNameIndex[i] <= 257; } else { return false; } } - + /** Get the table type, as a table directory value. * @return The table type */ + @Override public int getType() { return post; } + @Override public String toString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append("'post' Table - PostScript Metrics\n---------------------------------\n") .append("\n 'post' version: ").append(Fixed.floatValue(version)) .append("\n italicAngle: ").append(Fixed.floatValue(italicAngle)) @@ -409,15 +411,16 @@ public class PostTable implements Table { } return sb.toString(); } - + /** * Get a directory entry for this table. This uniquely identifies the * table in collections where there may be more than one instance of a * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return de; } - + } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/PrepTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/PrepTable.java index aac10c539..039789d62 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/PrepTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/PrepTable.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -19,29 +19,32 @@ import jogamp.graph.font.typecast.ot.Disassembler; */ public class PrepTable extends Program implements Table { - private DirectoryEntry de; + private final DirectoryEntry de; - public PrepTable(DirectoryEntry de, DataInput di) throws IOException { + public PrepTable(final DirectoryEntry de, final DataInput di) throws IOException { this.de = (DirectoryEntry) de.clone(); readInstructions(di, de.getLength()); } + @Override public int getType() { return prep; } + @Override public String toString() { return Disassembler.disassemble(getInstructions(), 0); } - + /** * Get a directory entry for this table. This uniquely identifies the * table in collections where there may be more than one instance of a * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return de; } - + } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Program.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Program.java index 28c148c2b..c0d2c1b9d 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Program.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Program.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -23,7 +23,7 @@ public abstract class Program { return instructions; } - protected void readInstructions(DataInput di, int count) throws IOException { + protected void readInstructions(final DataInput di, final int count) throws IOException { instructions = new short[count]; for (int i = 0; i < count; i++) { instructions[i] = (short) di.readUnsignedByte(); diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/RangeRecord.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/RangeRecord.java index 72d703bb4..417779703 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/RangeRecord.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/RangeRecord.java @@ -61,22 +61,22 @@ import java.io.IOException; */ public class RangeRecord { - private int _start; - private int _end; - private int _startCoverageIndex; + private final int _start; + private final int _end; + private final int _startCoverageIndex; /** Creates new RangeRecord */ - public RangeRecord(DataInput di) throws IOException { + public RangeRecord(final DataInput di) throws IOException { _start = di.readUnsignedShort(); _end = di.readUnsignedShort(); _startCoverageIndex = di.readUnsignedShort(); } - public boolean isInRange(int glyphId) { + public boolean isInRange(final int glyphId) { return (_start <= glyphId && glyphId <= _end); } - - public int getCoverageIndex(int glyphId) { + + public int getCoverageIndex(final int glyphId) { if (isInRange(glyphId)) { return _startCoverageIndex + glyphId - _start; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Script.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Script.java index eb534b5dd..8846de5f0 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Script.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Script.java @@ -60,19 +60,19 @@ import java.io.IOException; */ public class Script { - private int _defaultLangSysOffset; - private int _langSysCount; + private final int _defaultLangSysOffset; + private final int _langSysCount; private LangSysRecord[] _langSysRecords; private LangSys _defaultLangSys; private LangSys[] _langSys; - + /** Creates new ScriptTable */ - protected Script(DataInputStream dis, int offset) throws IOException { + protected Script(final DataInputStream dis, final int offset) throws IOException { // Ensure we're in the right place dis.reset(); dis.skipBytes(offset); - + // Start reading _defaultLangSysOffset = dis.readUnsignedShort(); _langSysCount = dis.readUnsignedShort(); @@ -102,8 +102,8 @@ public class Script { public int getLangSysCount() { return _langSysCount; } - - public LangSysRecord getLangSysRecord(int i) { + + public LangSysRecord getLangSysRecord(final int i) { return _langSysRecords[i]; } @@ -111,7 +111,7 @@ public class Script { return _defaultLangSys; } - public LangSys getLangSys(int i) { + public LangSys getLangSys(final int i) { return _langSys[i]; } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ScriptList.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ScriptList.java index 4af62b0ee..1c1be0d2b 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ScriptList.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ScriptList.java @@ -61,16 +61,16 @@ import java.io.IOException; public class ScriptList { private int _scriptCount = 0; - private ScriptRecord[] _scriptRecords; - private Script[] _scripts; - + private final ScriptRecord[] _scriptRecords; + private final Script[] _scripts; + /** Creates new ScriptList */ - protected ScriptList(DataInputStream dis, int offset) throws IOException { - + protected ScriptList(final DataInputStream dis, final int offset) throws IOException { + // Ensure we're in the right place dis.reset(); dis.skipBytes(offset); - + // Start reading _scriptCount = dis.readUnsignedShort(); _scriptRecords = new ScriptRecord[_scriptCount]; @@ -86,20 +86,20 @@ public class ScriptList { public int getScriptCount() { return _scriptCount; } - - public ScriptRecord getScriptRecord(int i) { + + public ScriptRecord getScriptRecord(final int i) { return _scriptRecords[i]; } - - public Script getScript(int i) { + + public Script getScript(final int i) { return _scripts[i]; } - - public Script findScript(String tag) { + + public Script findScript(final String tag) { if (tag.length() != 4) { return null; } - int tagVal = ((tag.charAt(0)<<24) + final int tagVal = ((tag.charAt(0)<<24) | (tag.charAt(1)<<16) | (tag.charAt(2)<<8) | tag.charAt(3)); diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ScriptRecord.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ScriptRecord.java index 5da0608dd..18eefe5a7 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ScriptRecord.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ScriptRecord.java @@ -60,11 +60,11 @@ import java.io.IOException; */ public class ScriptRecord { - private int _tag; - private int _offset; - + private final int _tag; + private final int _offset; + /** Creates new ScriptRecord */ - protected ScriptRecord(DataInput di) throws IOException { + protected ScriptRecord(final DataInput di) throws IOException { _tag = di.readInt(); _offset = di.readUnsignedShort(); } @@ -72,7 +72,7 @@ public class ScriptRecord { public int getTag() { return _tag; } - + public int getOffset() { return _offset; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/SignatureBlock.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/SignatureBlock.java index 5a5de119f..e6841b94c 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/SignatureBlock.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/SignatureBlock.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -18,13 +18,13 @@ import java.io.DataInput; */ public class SignatureBlock { - private int reserved1; - private int reserved2; - private int signatureLen; - private byte[] signature; - + private final int reserved1; + private final int reserved2; + private final int signatureLen; + private final byte[] signature; + /** Creates new SignatureBlock */ - protected SignatureBlock(DataInput di) throws IOException { + protected SignatureBlock(final DataInput di) throws IOException { reserved1 = di.readUnsignedShort(); reserved2 = di.readUnsignedShort(); signatureLen = di.readInt(); @@ -32,8 +32,9 @@ public class SignatureBlock { di.readFully(signature); } + @Override public String toString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); for (int i = 0; i < signatureLen; i += 16) { if (signatureLen - i >= 16) { sb.append(new String(signature, i, 16)).append("\n"); diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/SingleSubst.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/SingleSubst.java index 8c56a740f..c398b4fbb 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/SingleSubst.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/SingleSubst.java @@ -63,12 +63,12 @@ public abstract class SingleSubst extends LookupSubtable { public abstract int getFormat(); public abstract int substitute(int glyphId); - - public static SingleSubst read(DataInputStream dis, int offset) throws IOException { + + public static SingleSubst read(final DataInputStream dis, final int offset) throws IOException { SingleSubst s = null; dis.reset(); dis.skipBytes(offset); - int format = dis.readUnsignedShort(); + final int format = dis.readUnsignedShort(); if (format == 1) { s = new SingleSubstFormat1(dis, offset); } else if (format == 2) { diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/SingleSubstFormat1.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/SingleSubstFormat1.java index 99b85f35c..b2e65dded 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/SingleSubstFormat1.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/SingleSubstFormat1.java @@ -60,12 +60,12 @@ import java.io.IOException; */ public class SingleSubstFormat1 extends SingleSubst { - private int _coverageOffset; - private short _deltaGlyphID; - private Coverage _coverage; + private final int _coverageOffset; + private final short _deltaGlyphID; + private final Coverage _coverage; /** Creates new SingleSubstFormat1 */ - protected SingleSubstFormat1(DataInputStream dis, int offset) throws IOException { + protected SingleSubstFormat1(final DataInputStream dis, final int offset) throws IOException { _coverageOffset = dis.readUnsignedShort(); _deltaGlyphID = dis.readShort(); dis.reset(); @@ -73,18 +73,21 @@ public class SingleSubstFormat1 extends SingleSubst { _coverage = Coverage.read(dis); } + @Override public int getFormat() { return 1; } - public int substitute(int glyphId) { - int i = _coverage.findGlyph(glyphId); + @Override + public int substitute(final int glyphId) { + final int i = _coverage.findGlyph(glyphId); if (i > -1) { return glyphId + _deltaGlyphID; } return glyphId; } - + + @Override public String getTypeAsString() { return "SingleSubstFormat1"; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/SingleSubstFormat2.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/SingleSubstFormat2.java index cd3b6d147..449c14c7a 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/SingleSubstFormat2.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/SingleSubstFormat2.java @@ -60,13 +60,13 @@ import java.io.IOException; */ public class SingleSubstFormat2 extends SingleSubst { - private int _coverageOffset; - private int _glyphCount; - private int[] _substitutes; - private Coverage _coverage; + private final int _coverageOffset; + private final int _glyphCount; + private final int[] _substitutes; + private final Coverage _coverage; /** Creates new SingleSubstFormat2 */ - protected SingleSubstFormat2(DataInputStream dis, int offset) throws IOException { + protected SingleSubstFormat2(final DataInputStream dis, final int offset) throws IOException { _coverageOffset = dis.readUnsignedShort(); _glyphCount = dis.readUnsignedShort(); _substitutes = new int[_glyphCount]; @@ -78,20 +78,23 @@ public class SingleSubstFormat2 extends SingleSubst { _coverage = Coverage.read(dis); } + @Override public int getFormat() { return 2; } - public int substitute(int glyphId) { - int i = _coverage.findGlyph(glyphId); + @Override + public int substitute(final int glyphId) { + final int i = _coverage.findGlyph(glyphId); if (i > -1) { return _substitutes[i]; } return glyphId; } + @Override public String getTypeAsString() { return "SingleSubstFormat2"; - } + } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/TTCHeader.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/TTCHeader.java index b801517f8..a6ec61887 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/TTCHeader.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/TTCHeader.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -17,19 +17,19 @@ import java.io.IOException; * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class TTCHeader { - + public static final int ttcf = 0x74746366; - private int ttcTag; - private int version; - private int directoryCount; - private int[] tableDirectory; + private final int ttcTag; + private final int version; + private final int directoryCount; + private final int[] tableDirectory; private int dsigTag; - private int dsigLength; - private int dsigOffset; + private final int dsigLength; + private final int dsigOffset; /** Creates new TTCHeader */ - public TTCHeader(DataInput di) throws IOException { + public TTCHeader(final DataInput di) throws IOException { ttcTag = di.readInt(); version = di.readInt(); directoryCount = di.readInt(); @@ -47,13 +47,13 @@ public class TTCHeader { public int getDirectoryCount() { return directoryCount; } - - public int getTableDirectory(int i) { + + public int getTableDirectory(final int i) { return tableDirectory[i]; } - public static boolean isTTC(DataInput di) throws IOException { - int ttcTag = di.readInt(); + public static boolean isTTC(final DataInput di) throws IOException { + final int ttcTag = di.readInt(); return ttcTag == ttcf; } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Table.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Table.java index 624f47bef..30fd2f457 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Table.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Table.java @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * - * ------------------------------------------------------------------------- * - * This software is published under the terms of the Apache Software License * - * version 1.1, a copy of which has been included with this distribution in * - * the LICENSE file. * + * ------------------------------------------------------------------------- * + * This software is published under the terms of the Apache Software License * + * version 1.1, a copy of which has been included with this distribution in * + * the LICENSE file. * *****************************************************************************/ package jogamp.graph.font.typecast.ot.table; @@ -51,7 +51,7 @@ public interface Table { public static final int vmtx = 0x766d7478; // Vertical Metrics public static final String notAvailable = "n/a"; - + /** * Get the table type, as a table directory value. * @return The table type @@ -65,5 +65,5 @@ public interface Table { * @return A directory entry */ public DirectoryEntry getDirectoryEntry(); - + } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/TableDirectory.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/TableDirectory.java index bacc26d30..b9448cc72 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/TableDirectory.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/TableDirectory.java @@ -66,9 +66,9 @@ public class TableDirectory { private short _searchRange = 0; private short _entrySelector = 0; private short _rangeShift = 0; - private DirectoryEntry[] _entries; + private final DirectoryEntry[] _entries; - public TableDirectory(DataInput di) throws IOException { + public TableDirectory(final DataInput di) throws IOException { _version = di.readInt(); _numTables = di.readShort(); _searchRange = di.readShort(); @@ -80,11 +80,11 @@ public class TableDirectory { } } - public DirectoryEntry getEntry(int index) { + public DirectoryEntry getEntry(final int index) { return _entries[index]; } - public DirectoryEntry getEntryByTag(int tag) { + public DirectoryEntry getEntryByTag(final int tag) { for (int i = 0; i < _numTables; i++) { if (_entries[i].getTag() == tag) { return _entries[i]; @@ -112,9 +112,10 @@ public class TableDirectory { public int getVersion() { return _version; } - + + @Override public String toString() { - StringBuilder sb = new StringBuilder() + final StringBuilder sb = new StringBuilder() .append("Offset Table\n------ -----") .append("\n sfnt version: ").append(Fixed.floatValue(_version)) .append("\n numTables = ").append(_numTables) diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/TableException.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/TableException.java index 7749ea856..e0433f098 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/TableException.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/TableException.java @@ -26,7 +26,7 @@ package jogamp.graph.font.typecast.ot.table; * @version $Id: TableException.java,v 1.1.1.1 2004-12-05 23:15:00 davidsch Exp $ */ public class TableException extends java.lang.Exception { - + private static final long serialVersionUID = 1L; /** @@ -34,13 +34,13 @@ public class TableException extends java.lang.Exception { */ public TableException() { } - - + + /** * Constructs an instance of <code>TableException</code> with the specified detail message. * @param msg the detail message. */ - public TableException(String msg) { + public TableException(final String msg) { super(msg); } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/TableFactory.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/TableFactory.java index 998ce08e3..d24f3b3ae 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/TableFactory.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/TableFactory.java @@ -47,7 +47,7 @@ Apache Software Foundation, please see <http://www.apache.org/>. */ - + package jogamp.graph.font.typecast.ot.table; import java.io.DataInputStream; @@ -56,7 +56,7 @@ import java.io.IOException; import jogamp.graph.font.typecast.ot.OTFont; import jogamp.graph.font.typecast.ot.OTFontCollection; -/** +/** * * @version $Id: TableFactory.java,v 1.7 2007-02-05 12:39:51 davidsch Exp $ * @author <a href="mailto:[email protected]">David Schweinsberg</a> @@ -64,12 +64,12 @@ import jogamp.graph.font.typecast.ot.OTFontCollection; public class TableFactory { public static Table create( - OTFontCollection fc, - OTFont font, - DirectoryEntry de, - DataInputStream dis) throws IOException { + final OTFontCollection fc, + final OTFont font, + final DirectoryEntry de, + final DataInputStream dis) throws IOException { Table t = null; - + // First, if we have a font collection, look for the table there if (fc != null) { t = fc.getTable(de); @@ -77,7 +77,7 @@ public class TableFactory { return t; } } - + // Create the table switch (de.getTag()) { case Table.BASE: @@ -175,7 +175,7 @@ public class TableFactory { t = new VmtxTable(de, dis, font.getVheaTable(), font.getMaxpTable()); break; } - + // If we have a font collection, add this table to it if ((fc != null) && (t != null)) { fc.addTable(t); diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/VdmxTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/VdmxTable.java index 80579f5cd..679502e84 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/VdmxTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/VdmxTable.java @@ -30,14 +30,14 @@ import java.io.IOException; */ public class VdmxTable implements Table { - private class Ratio { - - private byte _bCharSet; - private byte _xRatio; - private byte _yStartRatio; - private byte _yEndRatio; - - protected Ratio(DataInput di) throws IOException { + static class Ratio { + + private final byte _bCharSet; + private final byte _xRatio; + private final byte _yStartRatio; + private final byte _yEndRatio; + + protected Ratio(final DataInput di) throws IOException { _bCharSet = di.readByte(); _xRatio = di.readByte(); _yStartRatio = di.readByte(); @@ -47,27 +47,27 @@ public class VdmxTable implements Table { public byte getBCharSet() { return _bCharSet; } - + public byte getXRatio() { return _xRatio; } - + public byte getYStartRatio() { return _yStartRatio; } - + public byte getYEndRatio() { return _yEndRatio; } } - - private class VTableRecord { - - private int _yPelHeight; - private short _yMax; - private short _yMin; - - protected VTableRecord(DataInput di) throws IOException { + + static class VTableRecord { + + private final int _yPelHeight; + private final short _yMax; + private final short _yMin; + + protected VTableRecord(final DataInput di) throws IOException { _yPelHeight = di.readUnsignedShort(); _yMax = di.readShort(); _yMin = di.readShort(); @@ -76,24 +76,24 @@ public class VdmxTable implements Table { public int getYPelHeight() { return _yPelHeight; } - + public short getYMax() { return _yMax; } - + public short getYMin() { return _yMin; } } - - private class Group { - - private int _recs; - private int _startsz; - private int _endsz; - private VTableRecord[] _entry; - - protected Group(DataInput di) throws IOException { + + static class Group { + + private final int _recs; + private final int _startsz; + private final int _endsz; + private final VTableRecord[] _entry; + + protected Group(final DataInput di) throws IOException { _recs = di.readUnsignedShort(); _startsz = di.readUnsignedByte(); _endsz = di.readUnsignedByte(); @@ -106,30 +106,30 @@ public class VdmxTable implements Table { public int getRecs() { return _recs; } - + public int getStartSZ() { return _startsz; } - + public int getEndSZ() { return _endsz; } - + public VTableRecord[] getEntry() { return _entry; } } - - private DirectoryEntry _de; - private int _version; - private int _numRecs; - private int _numRatios; - private Ratio[] _ratRange; - private int _offset[]; - private Group[] _groups; - + + private final DirectoryEntry _de; + private final int _version; + private final int _numRecs; + private final int _numRatios; + private final Ratio[] _ratRange; + private final int _offset[]; + private final Group[] _groups; + /** Creates a new instance of VdmxTable */ - protected VdmxTable(DirectoryEntry de, DataInput di) throws IOException { + protected VdmxTable(final DirectoryEntry de, final DataInput di) throws IOException { _de = (DirectoryEntry) de.clone(); _version = di.readUnsignedShort(); _numRecs = di.readUnsignedShort(); @@ -147,13 +147,15 @@ public class VdmxTable implements Table { _groups[i] = new Group(di); } } - + + @Override public int getType() { return VDMX; } - + + @Override public String toString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append("'VDMX' Table - Precomputed Vertical Device Metrics\n") .append("--------------------------------------------------\n") .append(" Version: ").append(_version).append("\n") @@ -170,7 +172,7 @@ public class VdmxTable implements Table { sb.append("\n VDMX Height Record Groups\n") .append(" -------------------------\n"); for (int i = 0; i < _numRecs; ++i) { - Group group = _groups[i]; + final Group group = _groups[i]; sb.append(" ").append(i + 1) .append(". Number of Hgt Records ").append(group.getRecs()).append("\n") .append(" Starting Y Pel Height ").append(group.getStartSZ()).append("\n") @@ -191,6 +193,7 @@ public class VdmxTable implements Table { * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return _de; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/VheaTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/VheaTable.java index 19c91765b..cef7b5297 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/VheaTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/VheaTable.java @@ -32,21 +32,21 @@ import jogamp.graph.font.typecast.ot.Fixed; */ public class VheaTable implements Table { - private DirectoryEntry _de; - private int _version; - private short _ascent; - private short _descent; - private short _lineGap; - private short _advanceHeightMax; - private short _minTopSideBearing; - private short _minBottomSideBearing; - private short _yMaxExtent; - private short _caretSlopeRise; - private short _caretSlopeRun; - private short _metricDataFormat; - private int _numberOfLongVerMetrics; - - protected VheaTable(DirectoryEntry de, DataInput di) throws IOException { + private final DirectoryEntry _de; + private final int _version; + private final short _ascent; + private final short _descent; + private final short _lineGap; + private final short _advanceHeightMax; + private final short _minTopSideBearing; + private final short _minBottomSideBearing; + private final short _yMaxExtent; + private final short _caretSlopeRise; + private final short _caretSlopeRun; + private final short _metricDataFormat; + private final int _numberOfLongVerMetrics; + + protected VheaTable(final DirectoryEntry de, final DataInput di) throws IOException { _de = (DirectoryEntry) de.clone(); _version = di.readInt(); _ascent = di.readShort(); @@ -105,6 +105,7 @@ public class VheaTable implements Table { return _numberOfLongVerMetrics; } + @Override public int getType() { return vhea; } @@ -113,6 +114,7 @@ public class VheaTable implements Table { return _yMaxExtent; } + @Override public String toString() { return new StringBuilder() .append("'vhea' Table - Vertical Header\n------------------------------") @@ -135,13 +137,14 @@ public class VheaTable implements Table { .append("\n numOf_LongVerMetrics: ").append(_numberOfLongVerMetrics) .toString(); } - + /** * Get a directory entry for this table. This uniquely identifies the * table in collections where there may be more than one instance of a * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return _de; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/VmtxTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/VmtxTable.java index 348405380..b76ed7e15 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/VmtxTable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/VmtxTable.java @@ -30,15 +30,15 @@ import java.io.IOException; */ public class VmtxTable implements Table { - private DirectoryEntry _de; + private final DirectoryEntry _de; private int[] _vMetrics = null; private short[] _topSideBearing = null; protected VmtxTable( - DirectoryEntry de, - DataInput di, - VheaTable vhea, - MaxpTable maxp) throws IOException { + final DirectoryEntry de, + final DataInput di, + final VheaTable vhea, + final MaxpTable maxp) throws IOException { _de = (DirectoryEntry) de.clone(); _vMetrics = new int[vhea.getNumberOfLongVerMetrics()]; for (int i = 0; i < vhea.getNumberOfLongVerMetrics(); ++i) { @@ -48,14 +48,14 @@ public class VmtxTable implements Table { | di.readUnsignedByte()<<8 | di.readUnsignedByte(); } - int tsbCount = maxp.getNumGlyphs() - vhea.getNumberOfLongVerMetrics(); + final int tsbCount = maxp.getNumGlyphs() - vhea.getNumberOfLongVerMetrics(); _topSideBearing = new short[tsbCount]; for (int i = 0; i < tsbCount; ++i) { _topSideBearing[i] = di.readShort(); } } - public int getAdvanceHeight(int i) { + public int getAdvanceHeight(final int i) { if (_vMetrics == null) { return 0; } @@ -66,7 +66,7 @@ public class VmtxTable implements Table { } } - public short getTopSideBearing(int i) { + public short getTopSideBearing(final int i) { if (_vMetrics == null) { return 0; } @@ -77,12 +77,14 @@ public class VmtxTable implements Table { } } + @Override public int getType() { return vmtx; } + @Override public String toString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append("'vmtx' Table - Vertical Metrics\n-------------------------------\n"); sb.append("Size = ").append(_de.getLength()).append(" bytes, ") .append(_vMetrics.length).append(" entries\n"); @@ -106,6 +108,7 @@ public class VmtxTable implements Table { * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return _de; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/t2/T2Interpreter.java b/src/jogl/classes/jogamp/graph/font/typecast/t2/T2Interpreter.java index 887f8c34f..80d76a7f8 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/t2/T2Interpreter.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/t2/T2Interpreter.java @@ -34,32 +34,32 @@ import jogamp.graph.font.typecast.ot.table.CharstringType2; * @version $Id: T2Interpreter.java,v 1.2 2007-07-26 11:10:18 davidsch Exp $ */ public class T2Interpreter { - + private static final int ARGUMENT_STACK_LIMIT = 48; private static final int SUBR_STACK_LIMIT = 10; private static final int TRANSIENT_ARRAY_ELEMENT_COUNT = 32; - - private Number[] _argStack = new Number[ARGUMENT_STACK_LIMIT]; + + private final Number[] _argStack = new Number[ARGUMENT_STACK_LIMIT]; private int _argStackIndex = 0; - private int[] _subrStack = new int[SUBR_STACK_LIMIT]; + private final int[] _subrStack = new int[SUBR_STACK_LIMIT]; private int _subrStackIndex = 0; - private Number[] _transientArray = new Number[TRANSIENT_ARRAY_ELEMENT_COUNT]; - + private final Number[] _transientArray = new Number[TRANSIENT_ARRAY_ELEMENT_COUNT]; + private ArrayList<Point> _points; /** Creates a new instance of T2Interpreter */ public T2Interpreter() { } - + /** * Moves the current point to a position at the relative coordinates * (dx1, dy1). */ private void _rmoveto() { - int dy1 = popArg().intValue(); - int dx1 = popArg().intValue(); + final int dy1 = popArg().intValue(); + final int dx1 = popArg().intValue(); clearArg(); - Point lastPoint = getLastPoint(); + final Point lastPoint = getLastPoint(); moveTo(lastPoint.x + dx1, lastPoint.y + dy1); } @@ -67,22 +67,22 @@ public class T2Interpreter { * Moves the current point dx1 units in the horizontal direction. */ private void _hmoveto() { - int dx1 = popArg().intValue(); + final int dx1 = popArg().intValue(); clearArg(); - Point lastPoint = getLastPoint(); + final Point lastPoint = getLastPoint(); moveTo(lastPoint.x + dx1, lastPoint.y); } - + /** * Moves the current point dy1 units in the vertical direction. */ private void _vmoveto() { - int dy1 = popArg().intValue(); + final int dy1 = popArg().intValue(); clearArg(); - Point lastPoint = getLastPoint(); + final Point lastPoint = getLastPoint(); moveTo(lastPoint.x, lastPoint.y + dy1); } - + /** * Appends a line from the current point to a position at the * relative coordinates dxa, dya. Additional rlineto operations are @@ -90,20 +90,20 @@ public class T2Interpreter { * lines is determined from the number of arguments on the stack. */ private void _rlineto() { - int count = getArgCount() / 2; - int[] dx = new int[count]; - int[] dy = new int[count]; + final int count = getArgCount() / 2; + final int[] dx = new int[count]; + final int[] dy = new int[count]; for (int i = 0; i < count; ++i) { dy[count - i - 1] = popArg().intValue(); dx[count - i - 1] = popArg().intValue(); } for (int i = 0; i < count; ++i) { - Point lastPoint = getLastPoint(); + final Point lastPoint = getLastPoint(); lineTo(lastPoint.x + dx[i], lastPoint.y + dy[i]); } clearArg(); } - + /** * Appends a horizontal line of length dx1 to the current point. * With an odd number of arguments, subsequent argument pairs @@ -115,13 +115,13 @@ public class T2Interpreter { * number of arguments on the stack. */ private void _hlineto() { - int count = getArgCount(); - Number[] nums = new Number[count]; + final int count = getArgCount(); + final Number[] nums = new Number[count]; for (int i = 0; i < count; ++i) { nums[count - i - 1] = popArg(); } for (int i = 0; i < count; ++i) { - Point lastPoint = getLastPoint(); + final Point lastPoint = getLastPoint(); if (i % 2 == 0) { lineTo(lastPoint.x + nums[i].intValue(), lastPoint.y); } else { @@ -130,7 +130,7 @@ public class T2Interpreter { } clearArg(); } - + /** * Appends a vertical line of length dy1 to the current point. With * an odd number of arguments, subsequent argument pairs are @@ -142,13 +142,13 @@ public class T2Interpreter { * number of arguments on the stack. */ private void _vlineto() { - int count = getArgCount(); - Number[] nums = new Number[count]; + final int count = getArgCount(); + final Number[] nums = new Number[count]; for (int i = 0; i < count; ++i) { nums[count - i - 1] = popArg(); } for (int i = 0; i < count; ++i) { - Point lastPoint = getLastPoint(); + final Point lastPoint = getLastPoint(); if (i % 2 == 0) { lineTo(lastPoint.x, lastPoint.y + nums[i].intValue()); } else { @@ -157,7 +157,7 @@ public class T2Interpreter { } clearArg(); } - + /** * Appends a Bezier curve, defined by dxa...dyc, to the current * point. For each subsequent set of six arguments, an additional @@ -167,13 +167,13 @@ public class T2Interpreter { * stack. */ private void _rrcurveto() { - int count = getArgCount() / 6; - int[] dxa = new int[count]; - int[] dya = new int[count]; - int[] dxb = new int[count]; - int[] dyb = new int[count]; - int[] dxc = new int[count]; - int[] dyc = new int[count]; + final int count = getArgCount() / 6; + final int[] dxa = new int[count]; + final int[] dya = new int[count]; + final int[] dxb = new int[count]; + final int[] dyb = new int[count]; + final int[] dxc = new int[count]; + final int[] dyc = new int[count]; for (int i = 0; i < count; ++i) { dyc[count - i - 1] = popArg().intValue(); dxc[count - i - 1] = popArg().intValue(); @@ -183,18 +183,18 @@ public class T2Interpreter { dxa[count - i - 1] = popArg().intValue(); } for (int i = 0; i < count; ++i) { - Point lastPoint = getLastPoint(); - int xa = lastPoint.x + dxa[i]; - int ya = lastPoint.y + dya[i]; - int xb = xa + dxb[i]; - int yb = ya + dyb[i]; - int xc = xb + dxc[i]; - int yc = yb + dyc[i]; + final Point lastPoint = getLastPoint(); + final int xa = lastPoint.x + dxa[i]; + final int ya = lastPoint.y + dya[i]; + final int xb = xa + dxb[i]; + final int yb = ya + dyb[i]; + final int xc = xb + dxc[i]; + final int yc = yb + dyc[i]; curveTo(xa, ya, xb, yb, xc, yc); } clearArg(); } - + /** * Appends one or more Bezier curves, as described by the * dxa...dxc set of arguments, to the current point. For each curve, @@ -203,12 +203,12 @@ public class T2Interpreter { * case). Note the argument order for the odd argument case. */ private void _hhcurveto() { - int count = getArgCount() / 4; + final int count = getArgCount() / 4; int dy1 = 0; - int[] dxa = new int[count]; - int[] dxb = new int[count]; - int[] dyb = new int[count]; - int[] dxc = new int[count]; + final int[] dxa = new int[count]; + final int[] dxb = new int[count]; + final int[] dyb = new int[count]; + final int[] dxc = new int[count]; for (int i = 0; i < count; ++i) { dxc[count - i - 1] = popArg().intValue(); dyb[count - i - 1] = popArg().intValue(); @@ -219,18 +219,18 @@ public class T2Interpreter { dy1 = popArg().intValue(); } for (int i = 0; i < count; ++i) { - Point lastPoint = getLastPoint(); - int xa = lastPoint.x + dxa[i]; - int ya = lastPoint.y + (i == 0 ? dy1 : 0); - int xb = xa + dxb[i]; - int yb = ya + dyb[i]; - int xc = xb + dxc[i]; - int yc = yb; + final Point lastPoint = getLastPoint(); + final int xa = lastPoint.x + dxa[i]; + final int ya = lastPoint.y + (i == 0 ? dy1 : 0); + final int xb = xa + dxb[i]; + final int yb = ya + dyb[i]; + final int xc = xb + dxc[i]; + final int yc = yb; curveTo(xa, ya, xb, yb, xc, yc); } clearArg(); } - + /** * Appends one or more Bezier curves to the current point. The * tangent for the first Bezier must be horizontal, and the second @@ -243,15 +243,15 @@ public class T2Interpreter { */ private void _hvcurveto() { if (getArgCount() % 8 <= 1) { - int count = getArgCount() / 8; - int[] dxa = new int[count]; - int[] dxb = new int[count]; - int[] dyb = new int[count]; - int[] dyc = new int[count]; - int[] dyd = new int[count]; - int[] dxe = new int[count]; - int[] dye = new int[count]; - int[] dxf = new int[count]; + final int count = getArgCount() / 8; + final int[] dxa = new int[count]; + final int[] dxb = new int[count]; + final int[] dyb = new int[count]; + final int[] dyc = new int[count]; + final int[] dyd = new int[count]; + final int[] dxe = new int[count]; + final int[] dye = new int[count]; + final int[] dxf = new int[count]; int dyf = 0; if (getArgCount() % 8 == 1) { dyf = popArg().intValue(); @@ -267,32 +267,32 @@ public class T2Interpreter { dxa[count - i - 1] = popArg().intValue(); } for (int i = 0; i < count; ++i) { - Point lastPoint = getLastPoint(); - int xa = lastPoint.x + dxa[i]; - int ya = lastPoint.y; - int xb = xa + dxb[i]; - int yb = ya + dyb[i]; - int xc = xb; - int yc = yb + dyc[i]; - int xd = xc; - int yd = yc + dyd[i]; - int xe = xd + dxe[i]; - int ye = yd + dye[i]; - int xf = xe + dxf[i]; - int yf = ye + dyf; + final Point lastPoint = getLastPoint(); + final int xa = lastPoint.x + dxa[i]; + final int ya = lastPoint.y; + final int xb = xa + dxb[i]; + final int yb = ya + dyb[i]; + final int xc = xb; + final int yc = yb + dyc[i]; + final int xd = xc; + final int yd = yc + dyd[i]; + final int xe = xd + dxe[i]; + final int ye = yd + dye[i]; + final int xf = xe + dxf[i]; + final int yf = ye + dyf; curveTo(xa, ya, xb, yb, xc, yc); curveTo(xd, yd, xe, ye, xf, yf); } } else { - int count = getArgCount() / 8; - int[] dya = new int[count]; - int[] dxb = new int[count]; - int[] dyb = new int[count]; - int[] dxc = new int[count]; - int[] dxd = new int[count]; - int[] dxe = new int[count]; - int[] dye = new int[count]; - int[] dyf = new int[count]; + final int count = getArgCount() / 8; + final int[] dya = new int[count]; + final int[] dxb = new int[count]; + final int[] dyb = new int[count]; + final int[] dxc = new int[count]; + final int[] dxd = new int[count]; + final int[] dxe = new int[count]; + final int[] dye = new int[count]; + final int[] dyf = new int[count]; int dxf = 0; if (getArgCount() % 8 == 1) { dxf = popArg().intValue(); @@ -307,33 +307,43 @@ public class T2Interpreter { dxb[count - i - 1] = popArg().intValue(); dya[count - i - 1] = popArg().intValue(); } - int dy3 = popArg().intValue(); - int dy2 = popArg().intValue(); - int dx2 = popArg().intValue(); - int dx1 = popArg().intValue(); + /** + * Not using the 'popped' arguments, + * hence simply pop them from stack! + * + final int dy3 = popArg().intValue(); + final int dy2 = popArg().intValue(); + final int dx2 = popArg().intValue(); + final int dx1 = popArg().intValue(); + */ + popArg(); + popArg(); + popArg(); + popArg(); + for (int i = 0; i < count; ++i) { - Point lastPoint = getLastPoint(); - int xa = lastPoint.x; - int ya = lastPoint.y + dya[i]; - int xb = xa + dxb[i]; - int yb = ya + dyb[i]; - int xc = xb + dxc[i]; - int yc = yb; - int xd = xc + dxd[i]; - int yd = yc; - int xe = xd + dxe[i]; - int ye = yd + dye[i]; - int xf = xe + dxf; - int yf = ye + dyf[i]; + final Point lastPoint = getLastPoint(); + final int xa = lastPoint.x; + final int ya = lastPoint.y + dya[i]; + final int xb = xa + dxb[i]; + final int yb = ya + dyb[i]; + final int xc = xb + dxc[i]; + final int yc = yb; + final int xd = xc + dxd[i]; + final int yd = yc; + final int xe = xd + dxe[i]; + final int ye = yd + dye[i]; + final int xf = xe + dxf; + final int yf = ye + dyf[i]; curveTo(xa, ya, xb, yb, xc, yc); curveTo(xd, yd, xe, ye, xf, yf); - + // What on earth do we do with dx1, dx2, dy2 and dy3? } } clearArg(); } - + /** * Is equivalent to one rrcurveto for each set of six arguments * dxa...dyc, followed by exactly one rlineto using the dxd, dyd @@ -341,15 +351,15 @@ public class T2Interpreter { * on the argument stack. */ private void _rcurveline() { - int count = (getArgCount() - 2) / 6; - int[] dxa = new int[count]; - int[] dya = new int[count]; - int[] dxb = new int[count]; - int[] dyb = new int[count]; - int[] dxc = new int[count]; - int[] dyc = new int[count]; - int dyd = popArg().intValue(); - int dxd = popArg().intValue(); + final int count = (getArgCount() - 2) / 6; + final int[] dxa = new int[count]; + final int[] dya = new int[count]; + final int[] dxb = new int[count]; + final int[] dyb = new int[count]; + final int[] dxc = new int[count]; + final int[] dyc = new int[count]; + final int dyd = popArg().intValue(); + final int dxd = popArg().intValue(); for (int i = 0; i < count; ++i) { dyc[count - i - 1] = popArg().intValue(); dxc[count - i - 1] = popArg().intValue(); @@ -361,11 +371,11 @@ public class T2Interpreter { int xc = 0; int yc = 0; for (int i = 0; i < count; ++i) { - Point lastPoint = getLastPoint(); - int xa = lastPoint.x + dxa[i]; - int ya = lastPoint.y + dya[i]; - int xb = xa + dxb[i]; - int yb = ya + dyb[i]; + final Point lastPoint = getLastPoint(); + final int xa = lastPoint.x + dxa[i]; + final int ya = lastPoint.y + dya[i]; + final int xb = xa + dxb[i]; + final int yb = ya + dyb[i]; xc = xb + dxc[i]; yc = yb + dyc[i]; curveTo(xa, ya, xb, yb, xc, yc); @@ -373,7 +383,7 @@ public class T2Interpreter { lineTo(xc + dxd, yc + dyd); clearArg(); } - + /** * Is equivalent to one rlineto for each pair of arguments beyond * the six arguments dxb...dyd needed for the one rrcurveto @@ -381,15 +391,15 @@ public class T2Interpreter { * items on the argument stack. */ private void _rlinecurve() { - int count = (getArgCount() - 6) / 2; - int[] dxa = new int[count]; - int[] dya = new int[count]; - int dyd = popArg().intValue(); - int dxd = popArg().intValue(); - int dyc = popArg().intValue(); - int dxc = popArg().intValue(); - int dyb = popArg().intValue(); - int dxb = popArg().intValue(); + final int count = (getArgCount() - 6) / 2; + final int[] dxa = new int[count]; + final int[] dya = new int[count]; + final int dyd = popArg().intValue(); + final int dxd = popArg().intValue(); + final int dyc = popArg().intValue(); + final int dxc = popArg().intValue(); + final int dyb = popArg().intValue(); + final int dxb = popArg().intValue(); for (int i = 0; i < count; ++i) { dya[count - i - 1] = popArg().intValue(); dxa[count - i - 1] = popArg().intValue(); @@ -397,21 +407,21 @@ public class T2Interpreter { int xa = 0; int ya = 0; for (int i = 0; i < count; ++i) { - Point lastPoint = getLastPoint(); + final Point lastPoint = getLastPoint(); xa = lastPoint.x + dxa[i]; ya = lastPoint.y + dya[i]; lineTo(xa, ya); } - int xb = xa + dxb; - int yb = ya + dyb; - int xc = xb + dxc; - int yc = yb + dyc; - int xd = xc + dxd; - int yd = yc + dyd; + final int xb = xa + dxb; + final int yb = ya + dyb; + final int xc = xb + dxc; + final int yc = yb + dyc; + final int xd = xc + dxd; + final int yd = yc + dyd; curveTo(xb, yb, xc, yc, xd, yd); clearArg(); } - + /** * Appends one or more Bezier curves to the current point, where * the first tangent is vertical and the second tangent is horizontal. @@ -420,15 +430,15 @@ public class T2Interpreter { */ private void _vhcurveto() { if (getArgCount() % 8 <= 1) { - int count = getArgCount() / 8; - int[] dya = new int[count]; - int[] dxb = new int[count]; - int[] dyb = new int[count]; - int[] dxc = new int[count]; - int[] dxd = new int[count]; - int[] dxe = new int[count]; - int[] dye = new int[count]; - int[] dyf = new int[count]; + final int count = getArgCount() / 8; + final int[] dya = new int[count]; + final int[] dxb = new int[count]; + final int[] dyb = new int[count]; + final int[] dxc = new int[count]; + final int[] dxd = new int[count]; + final int[] dxe = new int[count]; + final int[] dye = new int[count]; + final int[] dyf = new int[count]; int dxf = 0; if (getArgCount() % 8 == 1) { dxf = popArg().intValue(); @@ -444,28 +454,28 @@ public class T2Interpreter { dya[count - i - 1] = popArg().intValue(); } for (int i = 0; i < count; ++i) { - Point lastPoint = getLastPoint(); - int xa = lastPoint.x; - int ya = lastPoint.y + dya[i]; - int xb = xa + dxb[i]; - int yb = ya + dyb[i]; - int xc = xb + dxc[i]; - int yc = yb; - int xd = xc + dxd[i]; - int yd = yc; - int xe = xd + dxe[i]; - int ye = yd + dye[i]; - int xf = xe + dxf; - int yf = ye + dyf[i]; + final Point lastPoint = getLastPoint(); + final int xa = lastPoint.x; + final int ya = lastPoint.y + dya[i]; + final int xb = xa + dxb[i]; + final int yb = ya + dyb[i]; + final int xc = xb + dxc[i]; + final int yc = yb; + final int xd = xc + dxd[i]; + final int yd = yc; + final int xe = xd + dxe[i]; + final int ye = yd + dye[i]; + final int xf = xe + dxf; + final int yf = ye + dyf[i]; curveTo(xa, ya, xb, yb, xc, yc); curveTo(xd, yd, xe, ye, xf, yf); } } else { - int foo = 0; + final int foo = 0; } clearArg(); } - + /** * Appends one or more curves to the current point. If the argument * count is a multiple of four, the curve starts and ends vertical. If @@ -473,10 +483,10 @@ public class T2Interpreter { * vertical tangent. */ private void _vvcurveto() { - + clearArg(); } - + /** * Causes two Bezier curves, as described by the arguments (as * shown in Figure 2 below), to be rendered as a straight line when @@ -485,10 +495,10 @@ public class T2Interpreter { * pixels. */ private void _flex() { - + clearArg(); } - + /** * Causes the two curves described by the arguments dx1...dx6 to * be rendered as a straight line when the flex depth is less than @@ -496,10 +506,10 @@ public class T2Interpreter { * flex depth is greater than or equal to 0.5 device pixels. */ private void _hflex() { - + clearArg(); } - + /** * Causes the two curves described by the arguments to be * rendered as a straight line when the flex depth is less than 0.5 @@ -507,10 +517,10 @@ public class T2Interpreter { * than or equal to 0.5 device pixels. */ private void _hflex1() { - + clearArg(); } - + /** * Causes the two curves described by the arguments to be * rendered as a straight line when the flex depth is less than 0.5 @@ -518,10 +528,10 @@ public class T2Interpreter { * than or equal to 0.5 device pixels. */ private void _flex1() { - + clearArg(); } - + /** * Finishes a charstring outline definition, and must be the * last operator in a character's outline. @@ -530,81 +540,81 @@ public class T2Interpreter { endContour(); clearArg(); } - + private void _hstem() { - + clearArg(); } - + private void _vstem() { - + clearArg(); } - + private void _hstemhm() { - + clearArg(); } - + private void _vstemhm() { - + clearArg(); } - + private void _hintmask() { - + clearArg(); } - + private void _cntrmask() { - + clearArg(); } - + /** * Returns the absolute value of num. */ private void _abs() { - double num = popArg().doubleValue(); + final double num = popArg().doubleValue(); pushArg(Math.abs(num)); } - + /** * Returns the sum of the two numbers num1 and num2. */ private void _add() { - double num2 = popArg().doubleValue(); - double num1 = popArg().doubleValue(); + final double num2 = popArg().doubleValue(); + final double num1 = popArg().doubleValue(); pushArg(num1 + num2); } - + /** * Returns the result of subtracting num2 from num1. */ private void _sub() { - double num2 = popArg().doubleValue(); - double num1 = popArg().doubleValue(); + final double num2 = popArg().doubleValue(); + final double num1 = popArg().doubleValue(); pushArg(num1 - num2); } - + /** * Returns the quotient of num1 divided by num2. The result is * undefined if overflow occurs and is zero for underflow. */ private void _div() { - double num2 = popArg().doubleValue(); - double num1 = popArg().doubleValue(); + final double num2 = popArg().doubleValue(); + final double num1 = popArg().doubleValue(); pushArg(num1 / num2); } - + /** * Returns the negative of num. */ private void _neg() { - double num = popArg().doubleValue(); + final double num = popArg().doubleValue(); pushArg(-num); } - + /** * Returns a pseudo random number num2 in the range (0,1], that * is, greater than zero and less than or equal to one. @@ -612,43 +622,43 @@ public class T2Interpreter { private void _random() { pushArg(1.0 - Math.random()); } - + /** * Returns the product of num1 and num2. If overflow occurs, the * result is undefined, and zero is returned for underflow. */ private void _mul() { - double num2 = popArg().doubleValue(); - double num1 = popArg().doubleValue(); + final double num2 = popArg().doubleValue(); + final double num1 = popArg().doubleValue(); pushArg(num1 * num2); } - + /** * Returns the square root of num. If num is negative, the result is * undefined. */ private void _sqrt() { - double num = popArg().doubleValue(); + final double num = popArg().doubleValue(); pushArg(Math.sqrt(num)); } - + /** * Removes the top element num from the Type 2 argument stack. */ private void _drop() { popArg(); } - + /** * Exchanges the top two elements on the argument stack. */ private void _exch() { - Number num2 = popArg(); - Number num1 = popArg(); + final Number num2 = popArg(); + final Number num1 = popArg(); pushArg(num2); pushArg(num1); } - + /** * Retrieves the element i from the top of the argument stack and * pushes a copy of that element onto that stack. If i is negative, @@ -656,8 +666,8 @@ public class T2Interpreter { * undefined. */ private void _index() { - int i = popArg().intValue(); - Number[] nums = new Number[i]; + final int i = popArg().intValue(); + final Number[] nums = new Number[i]; for (int j = 0; j < i; ++j) { nums[j] = popArg(); } @@ -666,7 +676,7 @@ public class T2Interpreter { } pushArg(nums[i]); } - + /** * Performs a circular shift of the elements num(Nx1) ... num0 on * the argument stack by the amount J. Positive J indicates upward @@ -675,9 +685,9 @@ public class T2Interpreter { * operation is undefined. */ private void _roll() { - int j = popArg().intValue(); - int n = popArg().intValue(); - Number[] nums = new Number[n]; + final int j = popArg().intValue(); + final int n = popArg().intValue(); + final Number[] nums = new Number[n]; for (int i = 0; i < n; ++i) { nums[i] = popArg(); } @@ -685,25 +695,25 @@ public class T2Interpreter { pushArg(nums[(n + i + j) % n]); } } - + /** * Duplicates the top element on the argument stack. */ private void _dup() { - Number any = popArg(); + final Number any = popArg(); pushArg(any); pushArg(any); } - + /** * Stores val into the transient array at the location given by i. */ private void _put() { - int i = popArg().intValue(); - Number val = popArg(); + final int i = popArg().intValue(); + final Number val = popArg(); _transientArray[i] = val; } - + /** * Retrieves the value stored in the transient array at the location * given by i and pushes the value onto the argument stack. If get @@ -711,61 +721,61 @@ public class T2Interpreter { * charstring, the value returned is undefined. */ private void _get() { - int i = popArg().intValue(); + final int i = popArg().intValue(); pushArg(_transientArray[i]); } - + /** * Puts a 1 on the stack if num1 and num2 are both non-zero, and * puts a 0 on the stack if either argument is zero. */ private void _and() { - double num2 = popArg().doubleValue(); - double num1 = popArg().doubleValue(); + final double num2 = popArg().doubleValue(); + final double num1 = popArg().doubleValue(); pushArg((num1!=0.0) && (num2!=0.0) ? 1 : 0); } - + /** * Puts a 1 on the stack if either num1 or num2 are non-zero, and * puts a 0 on the stack if both arguments are zero. */ private void _or() { - double num2 = popArg().doubleValue(); - double num1 = popArg().doubleValue(); + final double num2 = popArg().doubleValue(); + final double num1 = popArg().doubleValue(); pushArg((num1!=0.0) || (num2!=0.0) ? 1 : 0); } - + /** * Returns a 0 if num1 is non-zero; returns a 1 if num1 is zero. */ private void _not() { - double num1 = popArg().doubleValue(); + final double num1 = popArg().doubleValue(); pushArg((num1!=0.0) ? 0 : 1); } - + /** * Puts a 1 on the stack if num1 equals num2, otherwise a 0 (zero) * is put on the stack. */ private void _eq() { - double num2 = popArg().doubleValue(); - double num1 = popArg().doubleValue(); + final double num2 = popArg().doubleValue(); + final double num1 = popArg().doubleValue(); pushArg(num1 == num2 ? 1 : 0); } - + /** * Leaves the value s1 on the stack if v1 ? v2, or leaves s2 on the * stack if v1 > v2. The value of s1 and s2 is usually the biased * number of a subroutine. */ private void _ifelse() { - double v2 = popArg().doubleValue(); - double v1 = popArg().doubleValue(); - Number s2 = popArg(); - Number s1 = popArg(); + final double v2 = popArg().doubleValue(); + final double v1 = popArg().doubleValue(); + final Number s2 = popArg(); + final Number s1 = popArg(); pushArg(v1 <= v2 ? s1 : s2); } - + /** * Calls a charstring subroutine with index subr# (actually the subr * number plus the subroutine bias number, as described in section @@ -777,26 +787,26 @@ public class T2Interpreter { * Calling an undefined subr (gsubr) has undefined results. */ private void _callsubr() { - + } - + /** * Operates in the same manner as callsubr except that it calls a * global subroutine. */ private void _callgsubr() { - + } - + /** * Returns from either a local or global charstring subroutine, and * continues execution after the corresponding call(g)subr. */ private void _return() { - + } - - public Point[] execute(CharstringType2 cs) { + + public Point[] execute(final CharstringType2 cs) { _points = new ArrayList<Point>(); cs.resetIP(); while (cs.moreBytes()) { @@ -964,7 +974,7 @@ public class T2Interpreter { } } } - Point[] pointArray = new Point[_points.size()]; + final Point[] pointArray = new Point[_points.size()]; _points.toArray(pointArray); return pointArray; } @@ -975,7 +985,7 @@ public class T2Interpreter { private int getArgCount() { return _argStackIndex; } - + /** * Pop a value off the argument stack */ @@ -986,10 +996,10 @@ public class T2Interpreter { /** * Push a value on to the argument stack */ - private void pushArg(Number n) { + private void pushArg(final Number n) { _argStack[_argStackIndex++] = n; } - + /** * Pop a value off the subroutine stack */ @@ -1000,43 +1010,43 @@ public class T2Interpreter { /** * Push a value on to the subroutine stack */ - private void pushSubr(int n) { + private void pushSubr(final int n) { _subrStack[_subrStackIndex++] = n; } - + /** * Clear the argument stack */ private void clearArg() { _argStackIndex = 0; } - + private Point getLastPoint() { - int size = _points.size(); + final int size = _points.size(); if (size > 0) { return _points.get(size - 1); } else { return new Point(0, 0, true, false); } } - - private void moveTo(int x, int y) { + + private void moveTo(final int x, final int y) { endContour(); _points.add(new Point(x, y, true, false)); } - - private void lineTo(int x, int y) { + + private void lineTo(final int x, final int y) { _points.add(new Point(x, y, true, false)); } - - private void curveTo(int cx1, int cy1, int cx2, int cy2, int x, int y) { + + private void curveTo(final int cx1, final int cy1, final int cx2, final int cy2, final int x, final int y) { _points.add(new Point(cx1, cy1, false, false)); _points.add(new Point(cx2, cy2, false, false)); _points.add(new Point(x, y, true, false)); } - + private void endContour() { - Point lastPoint = getLastPoint(); + final Point lastPoint = getLastPoint(); if (lastPoint != null) { lastPoint.endOfContour = true; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/tt/engine/Interpreter.java b/src/jogl/classes/jogamp/graph/font/typecast/tt/engine/Interpreter.java index a659a7003..a7408e381 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/tt/engine/Interpreter.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/tt/engine/Interpreter.java @@ -33,16 +33,16 @@ import jogamp.graph.font.typecast.ot.Point; public class Interpreter { private Parser parser = null; - private GraphicsState gs = new GraphicsState(); - private Point[][] zone = new Point[2][]; + private final GraphicsState gs = new GraphicsState(); + private final Point[][] zone = new Point[2][]; private int[] stack = null; private int[] store = null; - private int[] cvt = new int[256]; + private final int[] cvt = new int[256]; private int[] functionMap = null; private int stackIndex = 0; private boolean inFuncDef = false; - public Interpreter(int stackMax, int storeMax, int funcMax) { + public Interpreter(final int stackMax, final int storeMax, final int funcMax) { zone[0] = new Point[256]; zone[1] = new Point[256]; stack = new int[stackMax]; @@ -54,7 +54,7 @@ public class Interpreter { * ABSolute value */ private void _abs() { - int n = pop(); + final int n = pop(); if (n >= 0) { push(n); } else { @@ -66,8 +66,8 @@ public class Interpreter { * ADD */ private void _add() { - int n1 = pop(); - int n2 = pop(); + final int n1 = pop(); + final int n2 = pop(); push(n2 + n1); } @@ -92,8 +92,8 @@ public class Interpreter { * logical AND */ private void _and() { - int e2 = pop(); - int e1 = pop(); + final int e2 = pop(); + final int e1 = pop(); push(((e1 != 0) && (e2 != 0)) ? 1 : 0); } @@ -108,7 +108,7 @@ public class Interpreter { * CEILING */ private void _ceiling() { - int n = pop(); + final int n = pop(); if (n >= 0) { push((n & 0xffc0) + (((n & 0x3f) != 0) ? 0x40 : 0)); } else { @@ -138,7 +138,7 @@ public class Interpreter { * DELTA exception C1 */ private void _deltac1() { - int n = pop(); + final int n = pop(); for (int i = 0; i < n; i++) { pop(); // pn pop(); // argn @@ -149,7 +149,7 @@ public class Interpreter { * DELTA exception C2 */ private void _deltac2() { - int n = pop(); + final int n = pop(); for (int i = 0; i < n; i++) { pop(); // pn pop(); // argn @@ -160,7 +160,7 @@ public class Interpreter { * DELTA exception C3 */ private void _deltac3() { - int n = pop(); + final int n = pop(); for (int i = 0; i < n; i++) { pop(); // pn pop(); // argn @@ -171,7 +171,7 @@ public class Interpreter { * DELTA exception P1 */ private void _deltap1() { - int n = pop(); + final int n = pop(); for (int i = 0; i < n; i++) { pop(); // pn pop(); // argn @@ -182,7 +182,7 @@ public class Interpreter { * DELTA exception P2 */ private void _deltap2() { - int n = pop(); + final int n = pop(); for (int i = 0; i < n; i++) { pop(); // pn pop(); // argn @@ -193,7 +193,7 @@ public class Interpreter { * DELTA exception P3 */ private void _deltap3() { - int n = pop(); + final int n = pop(); for (int i = 0; i < n; i++) { pop(); // pn pop(); // argn @@ -211,8 +211,8 @@ public class Interpreter { * DIVide */ private void _div() { - int n1 = pop(); - int n2 = pop(); + final int n1 = pop(); + final int n2 = pop(); push((n2 / n1) >> 6); } @@ -220,7 +220,7 @@ public class Interpreter { * DUPlicate top stack element */ private void _dup() { - int n = pop(); + final int n = pop(); push(n); push(n); } @@ -228,7 +228,7 @@ public class Interpreter { /** * ELSE */ - private int _else(int instructionIndex) { + private int _else(final int instructionIndex) { return parser.handleElse(instructionIndex); } @@ -236,8 +236,8 @@ public class Interpreter { * EQual */ private void _eq() { - int e2 = pop(); - int e1 = pop(); + final int e2 = pop(); + final int e1 = pop(); push((e1 == e2) ? 1 : 0); } @@ -249,7 +249,7 @@ public class Interpreter { /** * Function DEFinition */ - private void _fdef(int instructionIndex) { + private void _fdef(final int instructionIndex) { functionMap[pop()] = instructionIndex; inFuncDef = true; } @@ -275,7 +275,7 @@ public class Interpreter { */ private void _flippt() { while(gs.loop-- > 0) { - int index = pop(); + final int index = pop(); zone[gs.zp0][index].onCurve = !zone[gs.zp0][index].onCurve; } gs.loop = 1; @@ -285,8 +285,8 @@ public class Interpreter { * FLIP RanGe OFF */ private void _fliprgoff() { - int end = pop(); - int start = pop(); + final int end = pop(); + final int start = pop(); for (int i = start; i <= end; i++) { zone[1][i].onCurve = false; } @@ -296,8 +296,8 @@ public class Interpreter { * FLIP RanGe ON */ private void _fliprgon() { - int end = pop(); - int start = pop(); + final int end = pop(); + final int start = pop(); for (int i = start; i <= end; i++) { zone[1][i].onCurve = true; } @@ -307,7 +307,7 @@ public class Interpreter { * FLOOR */ private void _floor() { - int n = pop(); + final int n = pop(); if (n >= 0) { push(n & 0xffc0); } else { @@ -315,7 +315,7 @@ public class Interpreter { } } - private void _gc(short param) { + private void _gc(final short param) { pop(); push(0); } @@ -345,8 +345,8 @@ public class Interpreter { * Greater Than */ private void _gt() { - int e2 = pop(); - int e1 = pop(); + final int e2 = pop(); + final int e1 = pop(); push((e1 > e2) ? 1 : 0); } @@ -354,8 +354,8 @@ public class Interpreter { * Greater Than or EQual */ private void _gteq() { - int e2 = pop(); - int e1 = pop(); + final int e2 = pop(); + final int e1 = pop(); push((e1 >= e2) ? 1 : 0); } @@ -370,7 +370,7 @@ public class Interpreter { /** * IF test */ - private int _if(int instructionIndex) { + private int _if(final int instructionIndex) { return parser.handleIf(pop() != 0, instructionIndex); } @@ -425,8 +425,8 @@ public class Interpreter { * will be used in glyph instructions. */ private void _instctrl() { - int s = pop(); - int v = pop(); + final int s = pop(); + final int v = pop(); if (s == 1) { gs.instruction_control |= v; } else if (s == 2) { @@ -446,22 +446,22 @@ public class Interpreter { pop(); } - private void _iup(short param) { + private void _iup(final short param) { } /** * JuMP Relative */ - private int _jmpr(int instructionIndex) { - return instructionIndex += pop() - 1; + private int _jmpr(final int instructionIndex) { + return instructionIndex + ( pop() - 1 ); } /** * Jump Relative On False */ private int _jrof(int instructionIndex) { - boolean test = pop() != 0; - int offset = pop(); + final boolean test = pop() != 0; + final int offset = pop(); if (!test) { instructionIndex += offset - 1; } @@ -472,8 +472,8 @@ public class Interpreter { * Jump Relative On True */ private int _jrot(int instructionIndex) { - boolean test = pop() != 0; - int offset = pop(); + final boolean test = pop() != 0; + final int offset = pop(); if (test) { instructionIndex += offset - 1; } @@ -484,8 +484,8 @@ public class Interpreter { * LOOP and CALL function */ private void _loopcall() { - int index = pop(); - int count = pop(); + /* final int index = */ pop(); + final int count = pop(); for (int i = 0; i < count; i++) { execute(functionMap[i]); } @@ -495,8 +495,8 @@ public class Interpreter { * Less Than */ private void _lt() { - int e2 = pop(); - int e1 = pop(); + final int e2 = pop(); + final int e1 = pop(); push((e1 < e2) ? 1 : 0); } @@ -504,8 +504,8 @@ public class Interpreter { * Less Than or EQual */ private void _lteq() { - int e2 = pop(); - int e1 = pop(); + final int e2 = pop(); + final int e1 = pop(); push((e1 <= e2) ? 1 : 0); } @@ -513,26 +513,26 @@ public class Interpreter { * MAXimum of top two stack elements */ private void _max() { - int n1 = pop(); - int n2 = pop(); + final int n1 = pop(); + final int n2 = pop(); push((n1 > n2) ? n1 : n2); } - private void _md(short param) { + private void _md(final short param) { pop(); pop(); push(0); } - private void _mdap(short param) { + private void _mdap(final short param) { pop(); } - private void _mdrp(short param) { + private void _mdrp(final short param) { pop(); } - private void _miap(short param) { + private void _miap(final short param) { pop(); pop(); } @@ -540,8 +540,8 @@ public class Interpreter { * MINimum of top two stack elements */ private void _min() { - int n1 = pop(); - int n2 = pop(); + final int n1 = pop(); + final int n2 = pop(); push((n1 < n2) ? n1 : n2); } @@ -550,15 +550,15 @@ public class Interpreter { */ private void _mindex() { // Move the indexed element to stackIndex, and shift the others down - int k = pop(); - int e = stack[stackIndex - k]; + final int k = pop(); + final int e = stack[stackIndex - k]; for (int i = stackIndex - k; i < stackIndex - 1; i++) { stack[i] = stack[i+1]; } stack[stackIndex - 1] = e; } - private void _mirp(short param) { + private void _mirp(final short param) { pop(); pop(); } @@ -570,8 +570,8 @@ public class Interpreter { private void _mps() { push(0); } - - private void _msirp(short param) { + + private void _msirp(final short param) { pop(); pop(); } @@ -580,8 +580,8 @@ public class Interpreter { * MULtiply */ private void _mul() { - int n1 = pop(); - int n2 = pop(); + final int n1 = pop(); + final int n2 = pop(); push((n1 * n2) >> 6); } @@ -596,8 +596,8 @@ public class Interpreter { * Not EQual */ private void _neq() { - int e2 = pop(); - int e1 = pop(); + final int e2 = pop(); + final int e1 = pop(); push((e1 != e2) ? 1 : 0); } @@ -608,7 +608,7 @@ public class Interpreter { push((pop() != 0) ? 0 : 1); } - private void _nround(short param) { + private void _nround(final short param) { pop(); push(0); } @@ -622,8 +622,8 @@ public class Interpreter { * logical OR */ private void _or() { - int e2 = pop(); - int e1 = pop(); + final int e2 = pop(); + final int e1 = pop(); push(((e1 != 0) || (e2 != 0)) ? 1 : 0); } @@ -633,7 +633,7 @@ public class Interpreter { * PUSH Bytes * PUSH Words */ - private void _push(int[] data) { + private void _push(final int[] data) { for (int j = 0; j < data.length; j++) { push(data[j]); } @@ -664,15 +664,15 @@ public class Interpreter { * ROLL the top three stack elements */ private void _roll() { - int a = pop(); - int b = pop(); - int c = pop(); + final int a = pop(); + final int b = pop(); + final int c = pop(); push(b); push(a); push(c); } - private void _round(short param) { + private void _round(final short param) { pop(); push(0); } @@ -907,7 +907,7 @@ public class Interpreter { /** * Set Dual Projection_Vector To Line */ - private void _sdpvtl(short param) { + private void _sdpvtl(final short param) { pop(); pop(); } @@ -930,7 +930,7 @@ public class Interpreter { /* * Set Freedom_Vector to Coordinate Axis */ - private void _sfvtca(short param) { + private void _sfvtca(final short param) { if (param == 1) { gs.freedom_vector[0] = 0x4000; gs.freedom_vector[1] = 0x0000; @@ -943,16 +943,16 @@ public class Interpreter { /* * Set Freedom_Vector To Line */ - private void _sfvtl(short param) { + private void _sfvtl(final short param) { pop(); pop(); - if (param == 1) { + // if (param == 1) { gs.freedom_vector[0] = 0x0000; gs.freedom_vector[1] = 0x0000; - } else { - gs.freedom_vector[0] = 0x0000; - gs.freedom_vector[1] = 0x0000; - } + // } else { + // gs.freedom_vector[0] = 0x0000; + // gs.freedom_vector[1] = 0x0000; + //} } /** @@ -963,7 +963,7 @@ public class Interpreter { gs.freedom_vector[1] = gs.projection_vector[1]; } - private void _shc(short param) { + private void _shc(final short param) { pop(); } @@ -972,7 +972,7 @@ public class Interpreter { * * USES: loop */ - private void _shp(short param) { + private void _shp(final short param) { while(gs.loop-- > 0) { pop(); if(param == 0) { @@ -995,7 +995,7 @@ public class Interpreter { gs.loop = 1; } - private void _shz(short param) { + private void _shz(final short param) { pop(); } @@ -1024,7 +1024,7 @@ public class Interpreter { /* * Set Projection_Vector To Coordinate Axis */ - private void _spvtca(short param) { + private void _spvtca(final short param) { if (param == 1) { gs.projection_vector[0] = 0x4000; gs.projection_vector[1] = 0x0000; @@ -1037,21 +1037,26 @@ public class Interpreter { /** * Set Projection_Vector To Line */ - private void _spvtl(short param) { + private void _spvtl(final short param) { + // below block is dead code, reduce to pop() calls. + pop(); + pop(); + /** // We'll get a copy of the line and normalize it - // divide the x- and y-coords by the vector's dot product. - Point p1 = zone[gs.zp2][pop()]; - Point p2 = zone[gs.zp1][pop()]; - int x = p2.x - p1.x; - int y = p2.y - p1.y; - if(param == 1) { - gs.projection_vector[0] = 0x0000; - gs.projection_vector[1] = 0x0000; - } else { + final Point p1 = zone[gs.zp2][pop()]; + final Point p2 = zone[gs.zp1][pop()]; + final int x = p2.x - p1.x; + final int y = p2.y - p1.y; + */ + // if(param == 1) { gs.projection_vector[0] = 0x0000; gs.projection_vector[1] = 0x0000; - } + // } else { + // gs.projection_vector[0] = 0x0000; + // gs.projection_vector[1] = 0x0000; + // } } private void _sround() { @@ -1097,15 +1102,15 @@ public class Interpreter { * SUBtract */ private void _sub() { - int n1 = pop(); - int n2 = pop(); + final int n1 = pop(); + final int n2 = pop(); push(n2 - n1); } /** * Set freedom and projection Vectors To Coordinate Axis */ - private void _svtca(short param) { + private void _svtca(final short param) { if (param == 1) { gs.projection_vector[0] = 0x4000; gs.projection_vector[1] = 0x0000; @@ -1123,8 +1128,8 @@ public class Interpreter { * SWAP the top two elements on the stack */ private void _swap() { - int n1 = pop(); - int n2 = pop(); + final int n1 = pop(); + final int n2 = pop(); push(n1); push(n2); } @@ -1165,7 +1170,7 @@ public class Interpreter { * Write Control Value Table in FUnits */ private void _wcvtf() { - int value = pop(); + final int value = pop(); // Conversion of value goes here cvt[pop()] = value; } @@ -1174,7 +1179,7 @@ public class Interpreter { * Write Control Value Table in Pixel units */ private void _wcvtp() { - int value = pop(); + final int value = pop(); // Conversion of value goes here cvt[pop()] = value; } @@ -1188,9 +1193,9 @@ public class Interpreter { public void execute(int ip) { while (ip < ((ip & 0xffff0000) | parser.getISLength(ip >> 16))) { - short opcode = parser.getOpcode(ip); + final short opcode = parser.getOpcode(ip); if (inFuncDef) { - + // We're within a function definition, so don't execute the code if (opcode == Mnemonic.ENDF) { inFuncDef = false; @@ -1332,7 +1337,7 @@ public class Interpreter { return stack[--stackIndex]; } - private void push(int i) { + private void push(final int i) { stack[stackIndex++] = i; } @@ -1351,7 +1356,7 @@ public class Interpreter { } } - public void setParser(Parser p) { + public void setParser(final Parser p) { parser = p; } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/tt/engine/Parser.java b/src/jogl/classes/jogamp/graph/font/typecast/tt/engine/Parser.java index c5a2b6e87..ff1795a28 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/tt/engine/Parser.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/tt/engine/Parser.java @@ -28,7 +28,7 @@ import jogamp.graph.font.typecast.ot.Mnemonic; */ public class Parser { - private short[][] instructions = new short[3][]; + private final short[][] instructions = new short[3][]; /** * Advance the instruction pointer to the next executable opcode. @@ -41,7 +41,7 @@ public class Parser { public int advanceIP(int ip) { // The high word specifies font, cvt, or glyph program - int prog = ip >> 16; + final int prog = ip >> 16; int i = ip & 0xffff; int dataCount; ip++; @@ -63,16 +63,16 @@ public class Parser { return ip; } - public int getISLength(int prog) { + public int getISLength(final int prog) { return instructions[prog].length; } - public short getOpcode(int ip) { + public short getOpcode(final int ip) { return instructions[ip >> 16][ip & 0xffff]; } - public short getPushCount(int ip) { - short instr = instructions[ip >> 16][ip & 0xffff]; + public short getPushCount(final int ip) { + final short instr = instructions[ip >> 16][ip & 0xffff]; if ((Mnemonic.NPUSHB == instr) || (Mnemonic.NPUSHW == instr)) { return instructions[ip >> 16][(ip & 0xffff) + 1]; } else if ((Mnemonic.PUSHB == (instr & 0xf8)) || (Mnemonic.PUSHW == (instr & 0xf8))) { @@ -81,12 +81,12 @@ public class Parser { return 0; } - public int[] getPushData(int ip) { - int count = getPushCount(ip); - int[] data = new int[count]; - int prog = ip >> 16; - int i = ip & 0xffff; - short instr = instructions[prog][i]; + public int[] getPushData(final int ip) { + final int count = getPushCount(ip); + final int[] data = new int[count]; + final int prog = ip >> 16; + final int i = ip & 0xffff; + final short instr = instructions[prog][i]; if (Mnemonic.NPUSHB == instr) { for (int j = 0; j < count; j++) { data[j] = instructions[prog][i + j + 2]; @@ -114,7 +114,7 @@ public class Parser { return ip; } - public int handleIf(boolean test, int ip) { + public int handleIf(final boolean test, int ip) { if (test == false) { // The TrueType spec says that we merely jump to the *next* ELSE or EIF // instruction in the instruction stream. So therefore no nesting! @@ -130,31 +130,32 @@ public class Parser { /** * This program is run everytime we scale the font */ - public void setCvtProgram(short[] program) { + public void setCvtProgram(final short[] program) { instructions[1] = program; } /** * This program is only run once */ - public void setFontProgram(short[] program) { + public void setFontProgram(final short[] program) { instructions[0] = program; } /** * This program is run everytime we scale the glyph */ - public void setGlyphProgram(short[] program) { + public void setGlyphProgram(final short[] program) { instructions[2] = program; } + @Override public String toString() { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); int ip = 0; while (ip < instructions[0].length) { sb.append(Mnemonic.getMnemonic(getOpcode(ip))); if (getPushCount(ip) > 0) { - int[] data = getPushData(ip); + final int[] data = getPushData(ip); for(int j = 0; j < data.length; j++) sb.append(" ").append(data[j]); } @@ -166,7 +167,7 @@ public class Parser { while (ip < (0x10000 | instructions[1].length)) { sb.append(Mnemonic.getMnemonic(getOpcode(ip))); if(getPushCount(ip) > 0) { - int[] data = getPushData(ip); + final int[] data = getPushData(ip); for (int j = 0; j < data.length; j++) { sb.append(" ").append(data[j]); } @@ -179,7 +180,7 @@ public class Parser { while (ip < (0x20000 | instructions[2].length)) { sb.append(Mnemonic.getMnemonic(getOpcode(ip))); if (getPushCount(ip) > 0) { - int[] data = getPushData(ip); + final int[] data = getPushData(ip); for (int j = 0; j < data.length; j++) { sb.append(" ").append(data[j]); } diff --git a/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java b/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java index fc086ebe4..a9978abe5 100644 --- a/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java +++ b/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java @@ -19,21 +19,16 @@ */ package jogamp.graph.geom.plane; -import java.io.IOException; -import java.io.Serializable; - -import jogamp.graph.math.MathFloat; // import jogamp.opengl.util.HashCode; import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.geom.Vertex.Factory; - -public class AffineTransform implements Cloneable, Serializable { +import com.jogamp.opengl.math.FloatUtil; +import com.jogamp.opengl.math.geom.AABBox; - private static final long serialVersionUID = 1330973210523860834L; +public class AffineTransform implements Cloneable { static final String determinantIsZero = "Determinant is zero"; - + public static final int TYPE_IDENTITY = 0; public static final int TYPE_TRANSLATION = 1; public static final int TYPE_UNIFORM_SCALE = 2; @@ -49,14 +44,12 @@ public class AffineTransform implements Cloneable, Serializable { * The <code>TYPE_UNKNOWN</code> is an initial type value */ static final int TYPE_UNKNOWN = -1; - + /** - * The min value equivalent to zero. If absolute value less then ZERO it considered as zero. + * The min value equivalent to zero. If absolute value less then ZERO it considered as zero. */ static final float ZERO = (float) 1E-10; - - private final Vertex.Factory<? extends Vertex> pointFactory; - + /** * The values of transformation matrix */ @@ -68,26 +61,15 @@ public class AffineTransform implements Cloneable, Serializable { float m12; /** - * The transformation <code>type</code> + * The transformation <code>type</code> */ transient int type; public AffineTransform() { - pointFactory = null; - type = TYPE_IDENTITY; - m00 = m11 = 1.0f; - m10 = m01 = m02 = m12 = 0.0f; - } - - public AffineTransform(Factory<? extends Vertex> factory) { - pointFactory = factory; - type = TYPE_IDENTITY; - m00 = m11 = 1.0f; - m10 = m01 = m02 = m12 = 0.0f; + setToIdentity(); } - public AffineTransform(AffineTransform t) { - this.pointFactory = t.pointFactory; + public AffineTransform(final AffineTransform t) { this.type = t.type; this.m00 = t.m00; this.m10 = t.m10; @@ -97,8 +79,7 @@ public class AffineTransform implements Cloneable, Serializable { this.m12 = t.m12; } - public AffineTransform(Vertex.Factory<? extends Vertex> factory, float m00, float m10, float m01, float m11, float m02, float m12) { - pointFactory = factory; + public AffineTransform(final float m00, final float m10, final float m01, final float m11, final float m02, final float m12) { this.type = TYPE_UNKNOWN; this.m00 = m00; this.m10 = m10; @@ -108,8 +89,7 @@ public class AffineTransform implements Cloneable, Serializable { this.m12 = m12; } - public AffineTransform(Vertex.Factory<? extends Vertex> factory, float[] matrix) { - pointFactory = factory; + public AffineTransform(final float[] matrix) { this.type = TYPE_UNKNOWN; m00 = matrix[0]; m10 = matrix[1]; @@ -123,20 +103,20 @@ public class AffineTransform implements Cloneable, Serializable { /* * Method returns type of affine transformation. - * + * * Transform matrix is * m00 m01 m02 * m10 m11 m12 - * - * According analytic geometry new basis vectors are (m00, m01) and (m10, m11), - * translation vector is (m02, m12). Original basis vectors are (1, 0) and (0, 1). - * Type transformations classification: + * + * According analytic geometry new basis vectors are (m00, m01) and (m10, m11), + * translation vector is (m02, m12). Original basis vectors are (1, 0) and (0, 1). + * Type transformations classification: * TYPE_IDENTITY - new basis equals original one and zero translation - * TYPE_TRANSLATION - translation vector isn't zero + * TYPE_TRANSLATION - translation vector isn't zero * TYPE_UNIFORM_SCALE - vectors length of new basis equals - * TYPE_GENERAL_SCALE - vectors length of new basis doesn't equal + * TYPE_GENERAL_SCALE - vectors length of new basis doesn't equal * TYPE_FLIP - new basis vector orientation differ from original one - * TYPE_QUADRANT_ROTATION - new basis is rotated by 90, 180, 270, or 360 degrees + * TYPE_QUADRANT_ROTATION - new basis is rotated by 90, 180, 270, or 360 degrees * TYPE_GENERAL_ROTATION - new basis is rotated by arbitrary angle * TYPE_GENERAL_TRANSFORM - transformation can't be inversed */ @@ -164,8 +144,8 @@ public class AffineTransform implements Cloneable, Serializable { type |= TYPE_FLIP; } - float dx = m00 * m00 + m10 * m10; - float dy = m01 * m01 + m11 * m11; + final float dx = m00 * m00 + m10 * m10; + final float dy = m01 * m01 + m11 * m11; if (dx != dy) { type |= TYPE_GENERAL_SCALE; } else @@ -185,35 +165,35 @@ public class AffineTransform implements Cloneable, Serializable { return type; } - public float getScaleX() { + public final float getScaleX() { return m00; } - public float getScaleY() { + public final float getScaleY() { return m11; } - public float getShearX() { + public final float getShearX() { return m01; } - public float getShearY() { + public final float getShearY() { return m10; } - public float getTranslateX() { + public final float getTranslateX() { return m02; } - public float getTranslateY() { + public final float getTranslateY() { return m12; } - public boolean isIdentity() { + public final boolean isIdentity() { return getType() == TYPE_IDENTITY; } - public void getMatrix(float[] matrix) { + public final void getMatrix(final float[] matrix) { matrix[0] = m00; matrix[1] = m10; matrix[2] = m01; @@ -224,11 +204,11 @@ public class AffineTransform implements Cloneable, Serializable { } } - public float getDeterminant() { + public final float getDeterminant() { return m00 * m11 - m01 * m10; } - public void setTransform(float m00, float m10, float m01, float m11, float m02, float m12) { + public final AffineTransform setTransform(final float m00, final float m10, final float m01, final float m11, final float m02, final float m12) { this.type = TYPE_UNKNOWN; this.m00 = m00; this.m10 = m10; @@ -236,20 +216,23 @@ public class AffineTransform implements Cloneable, Serializable { this.m11 = m11; this.m02 = m02; this.m12 = m12; + return this; } - public void setTransform(AffineTransform t) { + public final AffineTransform setTransform(final AffineTransform t) { type = t.type; setTransform(t.m00, t.m10, t.m01, t.m11, t.m02, t.m12); + return this; } - public void setToIdentity() { + public final AffineTransform setToIdentity() { type = TYPE_IDENTITY; m00 = m11 = 1.0f; m10 = m01 = m02 = m12 = 0.0f; + return this; } - public void setToTranslation(float mx, float my) { + public final AffineTransform setToTranslation(final float mx, final float my) { m00 = m11 = 1.0f; m01 = m10 = 0.0f; m02 = mx; @@ -259,9 +242,10 @@ public class AffineTransform implements Cloneable, Serializable { } else { type = TYPE_TRANSLATION; } + return this; } - public void setToScale(float scx, float scy) { + public final AffineTransform setToScale(final float scx, final float scy) { m00 = scx; m11 = scy; m10 = m01 = m02 = m12 = 0.0f; @@ -270,9 +254,10 @@ public class AffineTransform implements Cloneable, Serializable { } else { type = TYPE_IDENTITY; } + return this; } - public void setToShear(float shx, float shy) { + public final AffineTransform setToShear(final float shx, final float shy) { m00 = m11 = 1.0f; m02 = m12 = 0.0f; m01 = shx; @@ -282,16 +267,17 @@ public class AffineTransform implements Cloneable, Serializable { } else { type = TYPE_IDENTITY; } + return this; } - public void setToRotation(float angle) { - float sin = MathFloat.sin(angle); - float cos = MathFloat.cos(angle); - if (MathFloat.abs(cos) < ZERO) { + public final AffineTransform setToRotation(final float angle) { + float sin = FloatUtil.sin(angle); + float cos = FloatUtil.cos(angle); + if (FloatUtil.abs(cos) < ZERO) { cos = 0.0f; sin = sin > 0.0f ? 1.0f : -1.0f; } else - if (MathFloat.abs(sin) < ZERO) { + if (FloatUtil.abs(sin) < ZERO) { sin = 0.0f; cos = cos > 0.0f ? 1.0f : -1.0f; } @@ -300,98 +286,108 @@ public class AffineTransform implements Cloneable, Serializable { m10 = sin; m02 = m12 = 0.0f; type = TYPE_UNKNOWN; + return this; } - public void setToRotation(float angle, float px, float py) { + public final AffineTransform setToRotation(final float angle, final float px, final float py) { setToRotation(angle); m02 = px * (1.0f - m00) + py * m10; m12 = py * (1.0f - m00) - px * m10; type = TYPE_UNKNOWN; + return this; } - public static <T extends Vertex> AffineTransform getTranslateInstance(Vertex.Factory<? extends Vertex> factory, float mx, float my) { - AffineTransform t = new AffineTransform(factory); - t.setToTranslation(mx, my); - return t; - } - - public static <T extends Vertex> AffineTransform getScaleInstance(Vertex.Factory<? extends Vertex> factory, float scx, float scY) { - AffineTransform t = new AffineTransform(factory); - t.setToScale(scx, scY); - return t; - } - - public static <T extends Vertex> AffineTransform getShearInstance(Vertex.Factory<? extends Vertex> factory, float shx, float shy) { - AffineTransform t = new AffineTransform(factory); - t.setToShear(shx, shy); - return t; - } - - public static <T extends Vertex> AffineTransform getRotateInstance(Vertex.Factory<? extends Vertex> factory, float angle) { - AffineTransform t = new AffineTransform(factory); - t.setToRotation(angle); - return t; - } - - public static <T extends Vertex> AffineTransform getRotateInstance(Vertex.Factory<? extends Vertex> factory, float angle, float x, float y) { - AffineTransform t = new AffineTransform(factory); - t.setToRotation(angle, x, y); - return t; - } - - public void translate(float mx, float my) { - concatenate(AffineTransform.getTranslateInstance(pointFactory, mx, my)); + public final AffineTransform translate(final float mx, final float my, final AffineTransform tmp) { + return concatenate(tmp.setToTranslation(mx, my)); } - public void scale(float scx, float scy) { - concatenate(AffineTransform.getScaleInstance(pointFactory, scx, scy)); + public final AffineTransform scale(final float scx, final float scy, final AffineTransform tmp) { + return concatenate(tmp.setToScale(scx, scy)); } - public void shear(float shx, float shy) { - concatenate(AffineTransform.getShearInstance(pointFactory, shx, shy)); + public final AffineTransform shear(final float shx, final float shy, final AffineTransform tmp) { + return concatenate(tmp.setToShear(shx, shy)); } - public void rotate(float angle) { - concatenate(AffineTransform.getRotateInstance(pointFactory, angle)); + public final AffineTransform rotate(final float angle, final AffineTransform tmp) { + return concatenate(tmp.setToRotation(angle)); } - public void rotate(float angle, float px, float py) { - concatenate(AffineTransform.getRotateInstance(pointFactory, angle, px, py)); + public final AffineTransform rotate(final float angle, final float px, final float py, final AffineTransform tmp) { + return concatenate(tmp.setToRotation(angle, px, py)); } - /** + /** * Multiply matrix of two AffineTransform objects. - * The first argument's {@link Vertex.Factory} is being used. - * - * @param t1 - the AffineTransform object is a multiplicand - * @param t2 - the AffineTransform object is a multiplier - * @return an AffineTransform object that is a result of t1 multiplied by matrix t2. + * @param tL - the AffineTransform object is a multiplicand (left argument) + * @param tR - the AffineTransform object is a multiplier (right argument) + * + * @return A new AffineTransform object containing the result of [tL] X [tR]. */ - AffineTransform multiply(AffineTransform t1, AffineTransform t2) { - return new AffineTransform(t1.pointFactory, - t1.m00 * t2.m00 + t1.m10 * t2.m01, // m00 - t1.m00 * t2.m10 + t1.m10 * t2.m11, // m01 - t1.m01 * t2.m00 + t1.m11 * t2.m01, // m10 - t1.m01 * t2.m10 + t1.m11 * t2.m11, // m11 - t1.m02 * t2.m00 + t1.m12 * t2.m01 + t2.m02, // m02 - t1.m02 * t2.m10 + t1.m12 * t2.m11 + t2.m12);// m12 - } - - public void concatenate(AffineTransform t) { - setTransform(multiply(t, this)); + public final static AffineTransform multiply(final AffineTransform tL, final AffineTransform tR) { + return new AffineTransform( + tR.m00 * tL.m00 + tR.m10 * tL.m01, // m00 + tR.m00 * tL.m10 + tR.m10 * tL.m11, // m10 + tR.m01 * tL.m00 + tR.m11 * tL.m01, // m01 + tR.m01 * tL.m10 + tR.m11 * tL.m11, // m11 + tR.m02 * tL.m00 + tR.m12 * tL.m01 + tL.m02, // m02 + tR.m02 * tL.m10 + tR.m12 * tL.m11 + tL.m12);// m12 } - public void preConcatenate(AffineTransform t) { - setTransform(multiply(this, t)); + /** + * Concatenates the given matrix to this. + * <p> + * Implementations performs the matrix multiplication: + * <pre> + * [this] = [this] X [tR] + * </pre> + * </p> + * @param tR the right-argument of the matrix multiplication + * @return this transform for chaining + */ + public final AffineTransform concatenate(final AffineTransform tR) { + // setTransform(multiply(this, tR)); + type = TYPE_UNKNOWN; + setTransform( + tR.m00 * m00 + tR.m10 * m01, // m00 + tR.m00 * m10 + tR.m10 * m11, // m10 + tR.m01 * m00 + tR.m11 * m01, // m01 + tR.m01 * m10 + tR.m11 * m11, // m11 + tR.m02 * m00 + tR.m12 * m01 + m02, // m02 + tR.m02 * m10 + tR.m12 * m11 + m12);// m12 + return this; } - public AffineTransform createInverse() throws NoninvertibleTransformException { - float det = getDeterminant(); - if (MathFloat.abs(det) < ZERO) { + /** + * Pre-concatenates the given matrix to this. + * <p> + * Implementations performs the matrix multiplication: + * <pre> + * [this] = [tL] X [this] + * </pre> + * </p> + * @param tL the left-argument of the matrix multiplication + * @return this transform for chaining + */ + public final AffineTransform preConcatenate(final AffineTransform tL) { + // setTransform(multiply(tL, this)); + type = TYPE_UNKNOWN; + setTransform( + m00 * tL.m00 + m10 * tL.m01, // m00 + m00 * tL.m10 + m10 * tL.m11, // m10 + m01 * tL.m00 + m11 * tL.m01, // m01 + m01 * tL.m10 + m11 * tL.m11, // m11 + m02 * tL.m00 + m12 * tL.m01 + tL.m02, // m02 + m02 * tL.m10 + m12 * tL.m11 + tL.m12);// m12 + return this; + } + + public final AffineTransform createInverse() throws NoninvertibleTransformException { + final float det = getDeterminant(); + if (FloatUtil.abs(det) < ZERO) { throw new NoninvertibleTransformException(determinantIsZero); } return new AffineTransform( - this.pointFactory, m11 / det, // m00 -m10 / det, // m10 -m01 / det, // m01 @@ -401,33 +397,67 @@ public class AffineTransform implements Cloneable, Serializable { ); } - public Vertex transform(Vertex src, Vertex dst) { - if (dst == null) { - dst = pointFactory.create(); - } - - float x = src.getX(); - float y = src.getY(); + /** + * + * @param src + * @param dst + * @return dst for chaining + */ + public final AABBox transform(final AABBox src, final AABBox dst) { + final float[] srcLo = src.getLow(); + final float[] srcHi = src.getHigh(); + dst.setSize(srcLo[0] * m00 + srcLo[1] * m01 + m02, srcLo[0] * m10 + srcLo[1] * m11 + m12, srcLo[2], + srcHi[0] * m00 + srcHi[1] * m01 + m02, srcHi[0] * m10 + srcHi[1] * m11 + m12, srcHi[2]); + return dst; + } - dst.setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12, 0f); + /** + * @param src + * @param dst + * @return dst for chaining + */ + public final Vertex transform(final Vertex src, final Vertex dst) { + final float x = src.getX(); + final float y = src.getY(); + dst.setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12, src.getZ()); return dst; } - public void transform(Vertex[] src, int srcOff, Vertex[] dst, int dstOff, int length) { + public final void transform(final Vertex[] src, int srcOff, final Vertex[] dst, int dstOff, int length) { while (--length >= 0) { - Vertex srcPoint = src[srcOff++]; - float x = srcPoint.getX(); - float y = srcPoint.getY(); - Vertex dstPoint = dst[dstOff]; + final Vertex srcPoint = src[srcOff++]; + final Vertex dstPoint = dst[dstOff]; if (dstPoint == null) { throw new IllegalArgumentException("dst["+dstOff+"] is null"); } - dstPoint.setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12, 0f); + final float x = srcPoint.getX(); + final float y = srcPoint.getY(); + dstPoint.setCoord(x * m00 + y * m01 + m02, x * m10 + y * m11 + m12, srcPoint.getZ()); dst[dstOff++] = dstPoint; } } - - public void transform(float[] src, int srcOff, float[] dst, int dstOff, int length) { + + /** + * @param src float[2] source of transformation + * @param dst float[2] destination of transformation, maybe be equal to <code>src</code> + * @return dst for chaining + */ + public final float[] transform(final float[] src, final float[] dst) { + final float x = src[0]; + final float y = src[1]; + dst[0] = x * m00 + y * m01 + m02; + dst[1] = x * m10 + y * m11 + m12; + return dst; + } + + public final void transform(final float[] src, final int srcOff, final float[] dst, final int dstOff) { + final float x = src[srcOff + 0]; + final float y = src[srcOff + 1]; + dst[dstOff + 0] = x * m00 + y * m01 + m02; + dst[dstOff + 1] = x * m10 + y * m11 + m12; + } + + public final void transform(final float[] src, int srcOff, final float[] dst, int dstOff, int length) { int step = 2; if (src == dst && srcOff < dstOff && dstOff < srcOff + length * 2) { srcOff = srcOff + length * 2 - 2; @@ -435,83 +465,87 @@ public class AffineTransform implements Cloneable, Serializable { step = -2; } while (--length >= 0) { - float x = src[srcOff + 0]; - float y = src[srcOff + 1]; + final float x = src[srcOff + 0]; + final float y = src[srcOff + 1]; dst[dstOff + 0] = x * m00 + y * m01 + m02; dst[dstOff + 1] = x * m10 + y * m11 + m12; srcOff += step; dstOff += step; } } - - public Vertex deltaTransform(Vertex src, Vertex dst) { - if (dst == null) { - dst = pointFactory.create(); - } - float x = src.getX(); - float y = src.getY(); - - dst.setCoord(x * m00 + y * m01, x * m10 + y * m11, 0f); + /** + * + * @param src + * @param dst + * @return return dst for chaining + */ + public final Vertex deltaTransform(final Vertex src, final Vertex dst) { + final float x = src.getX(); + final float y = src.getY(); + dst.setCoord(x * m00 + y * m01, x * m10 + y * m11, src.getZ()); return dst; } - public void deltaTransform(float[] src, int srcOff, float[] dst, int dstOff, int length) { + public final void deltaTransform(final float[] src, int srcOff, final float[] dst, int dstOff, int length) { while (--length >= 0) { - float x = src[srcOff++]; - float y = src[srcOff++]; + final float x = src[srcOff++]; + final float y = src[srcOff++]; dst[dstOff++] = x * m00 + y * m01; dst[dstOff++] = x * m10 + y * m11; } } - public Vertex inverseTransform(Vertex src, Vertex dst) throws NoninvertibleTransformException { - float det = getDeterminant(); - if (MathFloat.abs(det) < ZERO) { + /** + * + * @param src + * @param dst + * @return return dst for chaining + * @throws NoninvertibleTransformException + */ + public final Vertex inverseTransform(final Vertex src, final Vertex dst) throws NoninvertibleTransformException { + final float det = getDeterminant(); + if (FloatUtil.abs(det) < ZERO) { throw new NoninvertibleTransformException(determinantIsZero); } - if (dst == null) { - dst = pointFactory.create(); - } - - float x = src.getX() - m02; - float y = src.getY() - m12; - - dst.setCoord((x * m11 - y * m01) / det, (y * m00 - x * m10) / det, 0f); + final float x = src.getX() - m02; + final float y = src.getY() - m12; + dst.setCoord((x * m11 - y * m01) / det, (y * m00 - x * m10) / det, src.getZ()); return dst; } - public void inverseTransform(float[] src, int srcOff, float[] dst, int dstOff, int length) + public final void inverseTransform(final float[] src, int srcOff, final float[] dst, int dstOff, int length) throws NoninvertibleTransformException { - float det = getDeterminant(); - if (MathFloat.abs(det) < ZERO) { - throw new NoninvertibleTransformException(determinantIsZero); + final float det = getDeterminant(); + if (FloatUtil.abs(det) < ZERO) { + throw new NoninvertibleTransformException(determinantIsZero); } while (--length >= 0) { - float x = src[srcOff++] - m02; - float y = src[srcOff++] - m12; + final float x = src[srcOff++] - m02; + final float y = src[srcOff++] - m12; dst[dstOff++] = (x * m11 - y * m01) / det; dst[dstOff++] = (y * m00 - x * m10) / det; } } - public Path2D createTransformedShape(Path2D src) { + public final Path2D createTransformedShape(final Path2D src) { if (src == null) { return null; } - if (src instanceof Path2D) { - return ((Path2D)src).createTransformedShape(this); - } - PathIterator path = src.iterator(this); - Path2D dst = new Path2D(path.getWindingRule()); - dst.append(path, false); - return dst; + return src.createTransformedShape(this); + /** + * If !(src instanceof Path2D): (but here it always is) + final PathIterator path = src.iterator(this); + final Path2D dst = new Path2D(path.getWindingRule()); + dst.append(path, false); + return dst; + */ } @Override - public String toString() { + public final String toString() { return getClass().getName() + "[[" + m00 + ", " + m01 + ", " + m02 + "], [" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ @@ -519,10 +553,10 @@ public class AffineTransform implements Cloneable, Serializable { } @Override - public AffineTransform clone() { + public final AffineTransform clone() { try { return (AffineTransform) super.clone(); - } catch (CloneNotSupportedException e) { + } catch (final CloneNotSupportedException e) { throw new InternalError(); } } @@ -540,12 +574,12 @@ public class AffineTransform implements Cloneable, Serializable { } */ @Override - public boolean equals(Object obj) { + public final boolean equals(final Object obj) { if (obj == this) { return true; } if (obj instanceof AffineTransform) { - AffineTransform t = (AffineTransform)obj; + final AffineTransform t = (AffineTransform)obj; return m00 == t.m00 && m01 == t.m01 && m02 == t.m02 && m10 == t.m10 && @@ -553,28 +587,9 @@ public class AffineTransform implements Cloneable, Serializable { } return false; } - - - /** - * Write AffineTrasform object to the output steam. - * @param stream - the output stream - * @throws IOException - if there are I/O errors while writing to the output strem - */ - private void writeObject(java.io.ObjectOutputStream stream) throws IOException { - stream.defaultWriteObject(); - } - - - /** - * Read AffineTransform object from the input stream - * @param stream - the input steam - * @throws IOException - if there are I/O errors while reading from the input strem - * @throws ClassNotFoundException - if class could not be found - */ - private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException { - stream.defaultReadObject(); - type = TYPE_UNKNOWN; + @Override + public final int hashCode() { + throw new InternalError("hashCode not designed"); } - } diff --git a/src/jogl/classes/jogamp/graph/math/plane/Crossing.java b/src/jogl/classes/jogamp/graph/geom/plane/Crossing.java index 9be5978cc..2ae9d1867 100644 --- a/src/jogl/classes/jogamp/graph/math/plane/Crossing.java +++ b/src/jogl/classes/jogamp/graph/geom/plane/Crossing.java @@ -17,11 +17,10 @@ /** * @author Denis M. Kishenko */ -package jogamp.graph.math.plane; +package jogamp.graph.geom.plane; + +import com.jogamp.opengl.math.FloatUtil; -import jogamp.graph.geom.plane.Path2D; -import jogamp.graph.geom.plane.PathIterator; -import jogamp.graph.math.MathFloat; public class Crossing { @@ -30,17 +29,17 @@ public class Crossing { * Allowable tolerance for bounds comparison */ static final float DELTA = (float) 1E-5; - + /** * If roots have distance less then <code>ROOT_DELTA</code> they are double */ static final float ROOT_DELTA = (float) 1E-10; - + /** * Rectangle cross segment */ public static final int CROSSING = 255; - + /** * Unknown crossing result */ @@ -52,10 +51,10 @@ public class Crossing { * @param res - the roots of the equation * @return a number of roots */ - public static int solveQuad(float eqn[], float res[]) { - float a = eqn[2]; - float b = eqn[1]; - float c = eqn[0]; + public static int solveQuad(final float eqn[], final float res[]) { + final float a = eqn[2]; + final float b = eqn[1]; + final float c = eqn[0]; int rc = 0; if (a == 0.0) { if (b == 0.0) { @@ -68,7 +67,7 @@ public class Crossing { if (d < 0.0) { return 0; } - d = MathFloat.sqrt(d); + d = FloatUtil.sqrt(d); res[rc++] = (- b + d) / (a * 2.0f); // d != 0.0 if (d != 0.0) { @@ -84,32 +83,32 @@ public class Crossing { * @param res - the roots of the equation * @return a number of roots */ - public static int solveCubic(float eqn[], float res[]) { - float d = eqn[3]; + public static int solveCubic(final float eqn[], final float res[]) { + final float d = eqn[3]; if (d == 0) { return solveQuad(eqn, res); } - float a = eqn[2] / d; - float b = eqn[1] / d; - float c = eqn[0] / d; + final float a = eqn[2] / d; + final float b = eqn[1] / d; + final float c = eqn[0] / d; int rc = 0; - float Q = (a * a - 3.0f * b) / 9.0f; - float R = (2.0f * a * a * a - 9.0f * a * b + 27.0f * c) / 54.0f; - float Q3 = Q * Q * Q; - float R2 = R * R; - float n = - a / 3.0f; + final float Q = (a * a - 3.0f * b) / 9.0f; + final float R = (2.0f * a * a * a - 9.0f * a * b + 27.0f * c) / 54.0f; + final float Q3 = Q * Q * Q; + final float R2 = R * R; + final float n = - a / 3.0f; if (R2 < Q3) { - float t = MathFloat.acos(R / MathFloat.sqrt(Q3)) / 3.0f; - float p = 2.0f * MathFloat.PI / 3.0f; - float m = -2.0f * MathFloat.sqrt(Q); - res[rc++] = m * MathFloat.cos(t) + n; - res[rc++] = m * MathFloat.cos(t + p) + n; - res[rc++] = m * MathFloat.cos(t - p) + n; + final float t = FloatUtil.acos(R / FloatUtil.sqrt(Q3)) / 3.0f; + final float p = 2.0f * FloatUtil.PI / 3.0f; + final float m = -2.0f * FloatUtil.sqrt(Q); + res[rc++] = m * FloatUtil.cos(t) + n; + res[rc++] = m * FloatUtil.cos(t + p) + n; + res[rc++] = m * FloatUtil.cos(t - p) + n; } else { // Debug.println("R2 >= Q3 (" + R2 + "/" + Q3 + ")"); - float A = MathFloat.pow(MathFloat.abs(R) + MathFloat.sqrt(R2 - Q3), 1.0f / 3.0f); + float A = FloatUtil.pow(FloatUtil.abs(R) + FloatUtil.sqrt(R2 - Q3), 1.0f / 3.0f); if (R > 0.0) { A = -A; } @@ -117,10 +116,10 @@ public class Crossing { if (-ROOT_DELTA < A && A < ROOT_DELTA) { res[rc++] = n; } else { - float B = Q / A; + final float B = Q / A; res[rc++] = A + B + n; // if (R2 == Q3) { - float delta = R2 - Q3; + final float delta = R2 - Q3; if (-ROOT_DELTA < delta && delta < ROOT_DELTA) { res[rc++] = - (A + B) / 2.0f + n; } @@ -131,12 +130,12 @@ public class Crossing { } /** - * Excludes float roots. Roots are float if they lies enough close with each other. - * @param res - the roots + * Excludes float roots. Roots are float if they lies enough close with each other. + * @param res - the roots * @param rc - the roots count * @return new roots count */ - static int fixRoots(float res[], int rc) { + static int fixRoots(final float res[], final int rc) { int tc = 0; for(int i = 0; i < rc; i++) { out: { @@ -159,7 +158,7 @@ public class Crossing { float ax, ay, bx, by; float Ax, Ay, Bx, By; - public QuadCurve(float x1, float y1, float cx, float cy, float x2, float y2) { + public QuadCurve(final float x1, final float y1, final float cx, final float cy, final float x2, final float y2) { ax = x2 - x1; ay = y2 - y1; bx = cx - x1; @@ -172,11 +171,11 @@ public class Crossing { Ay = ay - By; // Ay = ay - 2.0 * by } - int cross(float res[], int rc, float py1, float py2) { + int cross(final float res[], final int rc, final float py1, final float py2) { int cross = 0; for (int i = 0; i < rc; i++) { - float t = res[i]; + final float t = res[i]; // CURVE-OUTSIDE if (t < -DELTA || t > 1 + DELTA) { @@ -191,16 +190,17 @@ public class Crossing { } // CURVE-END if (t > 1 - DELTA) { + // FIXME: consider using FloatUtil.isEqual(ax, bx, epsilon), ... if (py1 < ay && (ax != bx ? ax - bx : bx) > 0.0) { cross++; } continue; } // CURVE-INSIDE - float ry = t * (t * Ay + By); + final float ry = t * (t * Ay + By); // ry = t * t * Ay + t * By if (ry > py2) { - float rxt = t * Ax + bx; + final float rxt = t * Ax + bx; // rxt = 2.0 * t * Ax + Bx = 2.0 * t * Ax + 2.0 * bx if (rxt > -DELTA && rxt < DELTA) { continue; @@ -212,12 +212,12 @@ public class Crossing { return cross; } - int solvePoint(float res[], float px) { - float eqn[] = {-px, Bx, Ax}; + int solvePoint(final float res[], final float px) { + final float eqn[] = {-px, Bx, Ax}; return solveQuad(eqn, res); } - int solveExtrem(float res[]) { + int solveExtrem(final float res[]) { int rc = 0; if (Ax != 0.0) { res[rc++] = - Bx / (Ax + Ax); @@ -228,11 +228,11 @@ public class Crossing { return rc; } - int addBound(float bound[], int bc, float res[], int rc, float minX, float maxX, boolean changeId, int id) { + int addBound(final float bound[], int bc, final float res[], final int rc, final float minX, final float maxX, final boolean changeId, int id) { for(int i = 0; i < rc; i++) { - float t = res[i]; + final float t = res[i]; if (t > -DELTA && t < 1 + DELTA) { - float rx = t * (t * Ax + Bx); + final float rx = t * (t * Ax + Bx); if (minX <= rx && rx <= maxX) { bound[bc++] = t; bound[bc++] = rx; @@ -258,7 +258,7 @@ public class Crossing { float Ax, Ay, Bx, By, Cx, Cy; float Ax3, Bx2; - public CubicCurve(float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2) { + public CubicCurve(final float x1, final float y1, final float cx1, final float cy1, final float cx2, final float cy2, final float x2, final float y2) { ax = x2 - x1; ay = y2 - y1; bx = cx1 - x1; @@ -278,10 +278,10 @@ public class Crossing { Bx2 = Bx + Bx; } - int cross(float res[], int rc, float py1, float py2) { + int cross(final float res[], final int rc, final float py1, final float py2) { int cross = 0; for (int i = 0; i < rc; i++) { - float t = res[i]; + final float t = res[i]; // CURVE-OUTSIDE if (t < -DELTA || t > 1 + DELTA) { @@ -289,6 +289,7 @@ public class Crossing { } // CURVE-START if (t < DELTA) { + // FIXME: consider using FloatUtil.isZero(bx, epsilon), ... if (py1 < 0.0 && (bx != 0.0 ? bx : (cx != bx ? cx - bx : ax - cx)) < 0.0) { cross--; } @@ -302,7 +303,7 @@ public class Crossing { continue; } // CURVE-INSIDE - float ry = t * (t * (t * Ay + By) + Cy); + final float ry = t * (t * (t * Ay + By) + Cy); // ry = t * t * t * Ay + t * t * By + t * Cy if (ry > py2) { float rxt = t * (t * Ax3 + Bx2) + Cx; @@ -323,26 +324,26 @@ public class Crossing { return cross; } - int solvePoint(float res[], float px) { - float eqn[] = {-px, Cx, Bx, Ax}; + int solvePoint(final float res[], final float px) { + final float eqn[] = {-px, Cx, Bx, Ax}; return solveCubic(eqn, res); } - int solveExtremX(float res[]) { - float eqn[] = {Cx, Bx2, Ax3}; + int solveExtremX(final float res[]) { + final float eqn[] = {Cx, Bx2, Ax3}; return solveQuad(eqn, res); } - int solveExtremY(float res[]) { - float eqn[] = {Cy, By + By, Ay + Ay + Ay}; + int solveExtremY(final float res[]) { + final float eqn[] = {Cy, By + By, Ay + Ay + Ay}; return solveQuad(eqn, res); } - int addBound(float bound[], int bc, float res[], int rc, float minX, float maxX, boolean changeId, int id) { + int addBound(final float bound[], int bc, final float res[], final int rc, final float minX, final float maxX, final boolean changeId, int id) { for(int i = 0; i < rc; i++) { - float t = res[i]; + final float t = res[i]; if (t > -DELTA && t < 1 + DELTA) { - float rx = t * (t * (t * Ax + Bx) + Cx); + final float rx = t * (t * (t * Ax + Bx) + Cx); if (minX <= rx && rx <= maxX) { bound[bc++] = t; bound[bc++] = rx; @@ -362,7 +363,7 @@ public class Crossing { /** * Returns how many times ray from point (x,y) cross line. */ - public static int crossLine(float x1, float y1, float x2, float y2, float x, float y) { + public static int crossLine(final float x1, final float y1, final float x2, final float y2, final float x, final float y) { // LEFT/RIGHT/UP/EMPTY if ((x < x1 && x < x2) || @@ -385,12 +386,12 @@ public class Crossing { // START if (x == x1) { - return x1 < x2 ? 0 : -1; + return x1 < x2 ? 0 : -1; } - + // END if (x == x2) { - return x1 < x2 ? 1 : 0; + return x1 < x2 ? 1 : 0; } // INSIDE-DOWN @@ -400,7 +401,7 @@ public class Crossing { /** * Returns how many times ray from point (x,y) cross quard curve */ - public static int crossQuad(float x1, float y1, float cx, float cy, float x2, float y2, float x, float y) { + public static int crossQuad(final float x1, final float y1, final float cx, final float cy, final float x2, final float y2, final float x, final float y) { // LEFT/RIGHT/UP/EMPTY if ((x < x1 && x < cx && x < x2) || @@ -420,11 +421,11 @@ public class Crossing { } // INSIDE - QuadCurve c = new QuadCurve(x1, y1, cx, cy, x2, y2); - float px = x - x1; - float py = y - y1; - float res[] = new float[3]; - int rc = c.solvePoint(res, px); + final QuadCurve c = new QuadCurve(x1, y1, cx, cy, x2, y2); + final float px = x - x1; + final float py = y - y1; + final float res[] = new float[3]; + final int rc = c.solvePoint(res, px); return c.cross(res, rc, py, py); } @@ -432,7 +433,7 @@ public class Crossing { /** * Returns how many times ray from point (x,y) cross cubic curve */ - public static int crossCubic(float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2, float x, float y) { + public static int crossCubic(final float x1, final float y1, final float cx1, final float cy1, final float cx2, final float cy2, final float x2, final float y2, final float x, final float y) { // LEFT/RIGHT/UP/EMPTY if ((x < x1 && x < cx1 && x < cx2 && x < x2) || @@ -452,18 +453,18 @@ public class Crossing { } // INSIDE - CubicCurve c = new CubicCurve(x1, y1, cx1, cy1, cx2, cy2, x2, y2); - float px = x - x1; - float py = y - y1; - float res[] = new float[3]; - int rc = c.solvePoint(res, px); + final CubicCurve c = new CubicCurve(x1, y1, cx1, cy1, cx2, cy2, x2, y2); + final float px = x - x1; + final float py = y - y1; + final float res[] = new float[3]; + final int rc = c.solvePoint(res, px); return c.cross(res, rc, py, py); } /** * Returns how many times ray from point (x,y) cross path */ - public static int crossPath(PathIterator p, float x, float y) { + public static int crossPath(final PathIterator p, final float x, final float y) { int cross = 0; float mx, my, cx, cy; mx = my = cx = cy = 0.0f; @@ -494,10 +495,10 @@ public class Crossing { } break; default: - throw new IllegalArgumentException("Unhandled Segment Type: "+segmentType); + throw new IllegalArgumentException("Unhandled Segment Type: "+segmentType); } - - // checks if the point (x,y) is the vertex of shape with PathIterator p + + // checks if the point (x,y) is the vertex of shape with PathIterator p if (x == cx && y == cy) { cross = 0; cy = my; @@ -514,7 +515,7 @@ public class Crossing { /** * Returns how many times ray from point (x,y) cross shape */ - public static int crossShape(Path2D s, float x, float y) { + public static int crossShape(final Path2D s, final float x, final float y) { if (!s.getBounds2D().contains(x, y)) { return 0; } @@ -524,14 +525,14 @@ public class Crossing { /** * Returns true if value enough small */ - public static boolean isZero(float val) { + public static boolean isZero(final float val) { return -DELTA < val && val < DELTA; } /** * Sort bound array */ - static void sortBound(float bound[], int bc) { + static void sortBound(final float bound[], final int bc) { for(int i = 0; i < bc - 4; i += 4) { int k = i; for(int j = i + 4; j < bc; j += 4) { @@ -555,11 +556,11 @@ public class Crossing { } } } - + /** - * Returns are bounds intersect or not intersect rectangle + * Returns are bounds intersect or not intersect rectangle */ - static int crossBound(float bound[], int bc, float py1, float py2) { + static int crossBound(final float bound[], final int bc, final float py1, final float py2) { // LEFT/RIGHT if (bc == 0) { @@ -591,7 +592,7 @@ public class Crossing { sortBound(bound, bc); boolean sign = bound[2] > py2; for(int i = 6; i < bc; i += 4) { - boolean sign2 = bound[i] > py2; + final boolean sign2 = bound[i] > py2; if (sign != sign2 && bound[i + 1] != bound[i - 3]) { return CROSSING; } @@ -604,7 +605,7 @@ public class Crossing { /** * Returns how many times rectangle stripe cross line or the are intersect */ - public static int intersectLine(float x1, float y1, float x2, float y2, float rx1, float ry1, float rx2, float ry2) { + public static int intersectLine(final float x1, final float y1, final float x2, final float y2, final float rx1, final float ry1, final float rx2, final float ry2) { // LEFT/RIGHT/UP if ((rx2 < x1 && rx2 < x2) || @@ -632,9 +633,9 @@ public class Crossing { bx1 = x2 < rx1 ? rx1 : x2; bx2 = x1 < rx2 ? x1 : rx2; } - float k = (y2 - y1) / (x2 - x1); - float by1 = k * (bx1 - x1) + y1; - float by2 = k * (bx2 - x1) + y1; + final float k = (y2 - y1) / (x2 - x1); + final float by1 = k * (bx1 - x1) + y1; + final float by2 = k * (bx2 - x1) + y1; // BOUND-UP if (by1 < ry1 && by2 < ry1) { @@ -673,7 +674,7 @@ public class Crossing { /** * Returns how many times rectangle stripe cross quad curve or the are intersect */ - public static int intersectQuad(float x1, float y1, float cx, float cy, float x2, float y2, float rx1, float ry1, float rx2, float ry2) { + public static int intersectQuad(final float x1, final float y1, final float cx, final float cy, final float x2, final float y2, final float rx1, final float ry1, final float rx2, final float ry2) { // LEFT/RIGHT/UP ------------------------------------------------------ if ((rx2 < x1 && rx2 < cx && rx2 < x2) || @@ -692,15 +693,15 @@ public class Crossing { } // INSIDE ------------------------------------------------------------- - QuadCurve c = new QuadCurve(x1, y1, cx, cy, x2, y2); - float px1 = rx1 - x1; - float py1 = ry1 - y1; - float px2 = rx2 - x1; - float py2 = ry2 - y1; - - float res1[] = new float[3]; - float res2[] = new float[3]; - int rc1 = c.solvePoint(res1, px1); + final QuadCurve c = new QuadCurve(x1, y1, cx, cy, x2, y2); + final float px1 = rx1 - x1; + final float py1 = ry1 - y1; + final float px2 = rx2 - x1; + final float py2 = ry2 - y1; + + final float res1[] = new float[3]; + final float res2[] = new float[3]; + final int rc1 = c.solvePoint(res1, px1); int rc2 = c.solvePoint(res2, px2); // INSIDE-LEFT/RIGHT @@ -709,9 +710,9 @@ public class Crossing { } // Build bound -------------------------------------------------------- - float minX = px1 - DELTA; - float maxX = px2 + DELTA; - float bound[] = new float[28]; + final float minX = px1 - DELTA; + final float maxX = px2 + DELTA; + final float bound[] = new float[28]; int bc = 0; // Add roots bc = c.addBound(bound, bc, res1, rc1, minX, maxX, false, 0); @@ -734,7 +735,7 @@ public class Crossing { } // End build bound ---------------------------------------------------- - int cross = crossBound(bound, bc, py1, py2); + final int cross = crossBound(bound, bc, py1, py2); if (cross != UNKNOWN) { return cross; } @@ -744,7 +745,7 @@ public class Crossing { /** * Returns how many times rectangle stripe cross cubic curve or the are intersect */ - public static int intersectCubic(float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2, float rx1, float ry1, float rx2, float ry2) { + public static int intersectCubic(final float x1, final float y1, final float cx1, final float cy1, final float cx2, final float cy2, final float x2, final float y2, final float rx1, final float ry1, final float rx2, final float ry2) { // LEFT/RIGHT/UP if ((rx2 < x1 && rx2 < cx1 && rx2 < cx2 && rx2 < x2) || @@ -763,15 +764,15 @@ public class Crossing { } // INSIDE - CubicCurve c = new CubicCurve(x1, y1, cx1, cy1, cx2, cy2, x2, y2); - float px1 = rx1 - x1; - float py1 = ry1 - y1; - float px2 = rx2 - x1; - float py2 = ry2 - y1; - - float res1[] = new float[3]; - float res2[] = new float[3]; - int rc1 = c.solvePoint(res1, px1); + final CubicCurve c = new CubicCurve(x1, y1, cx1, cy1, cx2, cy2, x2, y2); + final float px1 = rx1 - x1; + final float py1 = ry1 - y1; + final float px2 = rx2 - x1; + final float py2 = ry2 - y1; + + final float res1[] = new float[3]; + final float res2[] = new float[3]; + final int rc1 = c.solvePoint(res1, px1); int rc2 = c.solvePoint(res2, px2); // LEFT/RIGHT @@ -779,11 +780,11 @@ public class Crossing { return 0; } - float minX = px1 - DELTA; - float maxX = px2 + DELTA; + final float minX = px1 - DELTA; + final float maxX = px2 + DELTA; // Build bound -------------------------------------------------------- - float bound[] = new float[40]; + final float bound[] = new float[40]; int bc = 0; // Add roots bc = c.addBound(bound, bc, res1, rc1, minX, maxX, false, 0); @@ -808,7 +809,7 @@ public class Crossing { } // End build bound ---------------------------------------------------- - int cross = crossBound(bound, bc, py1, py2); + final int cross = crossBound(bound, bc, py1, py2); if (cross != UNKNOWN) { return cross; } @@ -818,7 +819,7 @@ public class Crossing { /** * Returns how many times rectangle stripe cross path or the are intersect */ - public static int intersectPath(PathIterator p, float x, float y, float w, float h) { + public static int intersectPath(final PathIterator p, final float x, final float y, final float w, final float h) { int cross = 0; int count; @@ -826,10 +827,10 @@ public class Crossing { mx = my = cx = cy = 0.0f; final float coords[] = new float[6]; - float rx1 = x; - float ry1 = y; - float rx2 = x + w; - float ry2 = y + h; + final float rx1 = x; + final float ry1 = y; + final float rx2 = x + w; + final float ry2 = y + h; while (!p.isDone()) { count = 0; @@ -880,8 +881,8 @@ public class Crossing { /** * Returns how many times rectangle stripe cross shape or the are intersect */ - public static int intersectShape(Path2D s, float x, float y, float w, float h) { - if (!s.getBounds2D().intersects(x, y, w, h)) { + public static int intersectShape(final Path2D s, final float x, final float y, final float w, final float h) { + if (!s.getBounds2D().intersects2DRegion(x, y, w, h)) { return 0; } return intersectPath(s.iterator(null), x, y, w, h); @@ -890,14 +891,14 @@ public class Crossing { /** * Returns true if cross count correspond inside location for non zero path rule */ - public static boolean isInsideNonZero(int cross) { + public static boolean isInsideNonZero(final int cross) { return cross != 0; } /** * Returns true if cross count correspond inside location for even-odd path rule */ - public static boolean isInsideEvenOdd(int cross) { + public static boolean isInsideEvenOdd(final int cross) { return (cross & 1) != 0; } } diff --git a/src/jogl/classes/jogamp/graph/geom/plane/IllegalPathStateException.java b/src/jogl/classes/jogamp/graph/geom/plane/IllegalPathStateException.java index 55211b3f9..2c18e0834 100644 --- a/src/jogl/classes/jogamp/graph/geom/plane/IllegalPathStateException.java +++ b/src/jogl/classes/jogamp/graph/geom/plane/IllegalPathStateException.java @@ -26,7 +26,7 @@ public class IllegalPathStateException extends RuntimeException { public IllegalPathStateException() { } - public IllegalPathStateException(String s) { + public IllegalPathStateException(final String s) { super(s); } diff --git a/src/jogl/classes/jogamp/graph/geom/plane/NoninvertibleTransformException.java b/src/jogl/classes/jogamp/graph/geom/plane/NoninvertibleTransformException.java index 398a03fca..6e49607b7 100644 --- a/src/jogl/classes/jogamp/graph/geom/plane/NoninvertibleTransformException.java +++ b/src/jogl/classes/jogamp/graph/geom/plane/NoninvertibleTransformException.java @@ -23,7 +23,7 @@ public class NoninvertibleTransformException extends java.lang.Exception { private static final long serialVersionUID = 6137225240503990466L; - public NoninvertibleTransformException(String s) { + public NoninvertibleTransformException(final String s) { super(s); } diff --git a/src/jogl/classes/jogamp/graph/geom/plane/Path2D.java b/src/jogl/classes/jogamp/graph/geom/plane/Path2D.java index 8082fe4e1..191b191b5 100644 --- a/src/jogl/classes/jogamp/graph/geom/plane/Path2D.java +++ b/src/jogl/classes/jogamp/graph/geom/plane/Path2D.java @@ -21,11 +21,10 @@ package jogamp.graph.geom.plane; import java.util.NoSuchElementException; -import com.jogamp.graph.geom.AABBox; +import com.jogamp.graph.geom.SVertex; import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.geom.opengl.SVertex; +import com.jogamp.opengl.math.geom.AABBox; -import jogamp.graph.math.plane.Crossing; public final class Path2D implements Cloneable { @@ -34,12 +33,12 @@ public final class Path2D implements Cloneable { static final String invalidWindingRuleValue = "Invalid winding rule value"; static final String iteratorOutOfBounds = "Iterator out of bounds"; - + /** * The buffers size */ private static final int BUFFER_SIZE = 10; - + /** * The buffers capacity */ @@ -49,24 +48,24 @@ public final class Path2D implements Cloneable { * The point's types buffer */ byte[] types; - + /** * The points buffer */ float[] points; - + /** * The point's type buffer size */ int typeSize; - + /** * The points buffer size */ int pointSize; - + /** - * The path rule + * The path rule */ int rule; @@ -81,25 +80,25 @@ public final class Path2D implements Cloneable { 0}; // CLOSE /* - * GeneralPath path iterator + * GeneralPath path iterator */ - class Iterator implements PathIterator { + static class Iterator implements PathIterator { /** * The current cursor position in types buffer */ int typeIndex; - + /** * The current cursor position in points buffer */ int pointIndex; - + /** * The source GeneralPath object */ Path2D p; - + /** * The path iterator transformation */ @@ -109,7 +108,7 @@ public final class Path2D implements Cloneable { * Constructs a new GeneralPath.Iterator for given general path * @param path - the source GeneralPath object */ - Iterator(Path2D path) { + Iterator(final Path2D path) { this(path, null); } @@ -118,29 +117,33 @@ public final class Path2D implements Cloneable { * @param path - the source GeneralPath object * @param at - the AffineTransform object to apply rectangle path */ - Iterator(Path2D path, AffineTransform at) { + Iterator(final Path2D path, final AffineTransform at) { this.p = path; this.t = at; } + @Override public int getWindingRule() { return p.getWindingRule(); } + @Override public boolean isDone() { return typeIndex >= p.typeSize; } + @Override public void next() { typeIndex++; } - public int currentSegment(float[] coords) { + @Override + public int currentSegment(final float[] coords) { if (isDone()) { throw new NoSuchElementException(iteratorOutOfBounds); } - int type = p.types[typeIndex]; - int count = Path2D.pointShift[type]; + final int type = p.types[typeIndex]; + final int count = Path2D.pointShift[type]; System.arraycopy(p.points, pointIndex, coords, 0, count); if (t != null) { t.transform(coords, 0, coords, 0, count / 2); @@ -155,24 +158,24 @@ public final class Path2D implements Cloneable { this(WIND_NON_ZERO, BUFFER_SIZE); } - public Path2D(int rule) { + public Path2D(final int rule) { this(rule, BUFFER_SIZE); } - public Path2D(int rule, int initialCapacity) { + public Path2D(final int rule, final int initialCapacity) { setWindingRule(rule); types = new byte[initialCapacity]; points = new float[initialCapacity * 2]; } - public Path2D(Path2D path) { + public Path2D(final Path2D path) { this(WIND_NON_ZERO, BUFFER_SIZE); - PathIterator p = path.iterator(null); + final PathIterator p = path.iterator(null); setWindingRule(p.getWindingRule()); append(p, false); } - public void setWindingRule(int rule) { + public void setWindingRule(final int rule) { if (rule != WIND_EVEN_ODD && rule != WIND_NON_ZERO) { throw new NoSuchElementException(invalidWindingRuleValue); } @@ -184,26 +187,26 @@ public final class Path2D implements Cloneable { } /** - * Checks points and types buffer size to add pointCount points. If necessary realloc buffers to enlarge size. + * Checks points and types buffer size to add pointCount points. If necessary realloc buffers to enlarge size. * @param pointCount - the point count to be added in buffer */ - void checkBuf(int pointCount, boolean checkMove) { + void checkBuf(final int pointCount, final boolean checkMove) { if (checkMove && typeSize == 0) { throw new IllegalPathStateException("First segment should be SEG_MOVETO type"); } if (typeSize == types.length) { - byte tmp[] = new byte[typeSize + BUFFER_CAPACITY]; + final byte tmp[] = new byte[typeSize + BUFFER_CAPACITY]; System.arraycopy(types, 0, tmp, 0, typeSize); types = tmp; } if (pointSize + pointCount > points.length) { - float tmp[] = new float[pointSize + Math.max(BUFFER_CAPACITY * 2, pointCount)]; + final float tmp[] = new float[pointSize + Math.max(BUFFER_CAPACITY * 2, pointCount)]; System.arraycopy(points, 0, tmp, 0, pointSize); points = tmp; } } - public void moveTo(float x, float y) { + public void moveTo(final float x, final float y) { if (typeSize > 0 && types[typeSize - 1] == PathIterator.SEG_MOVETO) { points[pointSize - 2] = x; points[pointSize - 1] = y; @@ -215,14 +218,14 @@ public final class Path2D implements Cloneable { } } - public void lineTo(float x, float y) { + public void lineTo(final float x, final float y) { checkBuf(2, true); types[typeSize++] = PathIterator.SEG_LINETO; points[pointSize++] = x; points[pointSize++] = y; } - public void quadTo(float x1, float y1, float x2, float y2) { + public void quadTo(final float x1, final float y1, final float x2, final float y2) { checkBuf(4, true); types[typeSize++] = PathIterator.SEG_QUADTO; points[pointSize++] = x1; @@ -231,7 +234,7 @@ public final class Path2D implements Cloneable { points[pointSize++] = y2; } - public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3) { + public void curveTo(final float x1, final float y1, final float x2, final float y2, final float x3, final float y3) { checkBuf(6, true); types[typeSize++] = PathIterator.SEG_CUBICTO; points[pointSize++] = x1; @@ -245,28 +248,29 @@ public final class Path2D implements Cloneable { final public int size() { return typeSize; } - + final public boolean isClosed() { return typeSize > 0 && types[typeSize - 1] == PathIterator.SEG_CLOSE ; } - + public void closePath() { if (!isClosed()) { checkBuf(0, true); types[typeSize++] = PathIterator.SEG_CLOSE; } } - + + @Override public String toString() { return "[size "+size()+", closed "+isClosed()+"]"; } - public void append(Path2D path, boolean connect) { - PathIterator p = path.iterator(null); + public void append(final Path2D path, final boolean connect) { + final PathIterator p = path.iterator(null); append(p, connect); } - public void append(PathIterator path, boolean connect) { + public void append(final PathIterator path, boolean connect) { while (!path.isDone()) { final float coords[] = new float[6]; final int segmentType = path.currentSegment(coords); @@ -296,7 +300,7 @@ public final class Path2D implements Cloneable { closePath(); break; default: - throw new IllegalArgumentException("Unhandled Segment Type: "+segmentType); + throw new IllegalArgumentException("Unhandled Segment Type: "+segmentType); } path.next(); connect = false; @@ -311,7 +315,7 @@ public final class Path2D implements Cloneable { if (types[typeSize - 1] == PathIterator.SEG_CLOSE) { for (int i = typeSize - 2; i > 0; i--) { - int type = types[i]; + final int type = types[i]; if (type == PathIterator.SEG_MOVETO) { break; } @@ -326,12 +330,12 @@ public final class Path2D implements Cloneable { pointSize = 0; } - public void transform(AffineTransform t) { + public void transform(final AffineTransform t) { t.transform(points, 0, points, 0, pointSize / 2); } - public Path2D createTransformedShape(AffineTransform t) { - Path2D p = (Path2D)clone(); + public Path2D createTransformedShape(final AffineTransform t) { + final Path2D p = (Path2D)clone(); if (t != null) { p.transform(t); } @@ -347,8 +351,8 @@ public final class Path2D implements Cloneable { ry1 = ry2 = points[i--]; rx1 = rx2 = points[i--]; while (i > 0) { - float y = points[i--]; - float x = points[i--]; + final float y = points[i--]; + final float x = points[i--]; if (x < rx1) { rx1 = x; } else @@ -367,48 +371,48 @@ public final class Path2D implements Cloneable { } /** - * Checks cross count according to path rule to define is it point inside shape or not. + * Checks cross count according to path rule to define is it point inside shape or not. * @param cross - the point cross count - * @return true if point is inside path, or false otherwise + * @return true if point is inside path, or false otherwise */ - boolean isInside(int cross) { + boolean isInside(final int cross) { if (rule == WIND_NON_ZERO) { return Crossing.isInsideNonZero(cross); } return Crossing.isInsideEvenOdd(cross); } - public boolean contains(float px, float py) { + public boolean contains(final float px, final float py) { return isInside(Crossing.crossShape(this, px, py)); } - public boolean contains(float rx, float ry, float rw, float rh) { - int cross = Crossing.intersectShape(this, rx, ry, rw, rh); + public boolean contains(final float rx, final float ry, final float rw, final float rh) { + final int cross = Crossing.intersectShape(this, rx, ry, rw, rh); return cross != Crossing.CROSSING && isInside(cross); } - public boolean intersects(float rx, float ry, float rw, float rh) { - int cross = Crossing.intersectShape(this, rx, ry, rw, rh); + public boolean intersects(final float rx, final float ry, final float rw, final float rh) { + final int cross = Crossing.intersectShape(this, rx, ry, rw, rh); return cross == Crossing.CROSSING || isInside(cross); } - public boolean contains(Vertex p) { + public boolean contains(final Vertex p) { return contains(p.getX(), p.getY()); } - public boolean contains(AABBox r) { - return contains(r); + public boolean contains(final AABBox r) { + return contains(r.getMinX(), r.getMinY(), r.getWidth(), r.getHeight()); } - public boolean intersects(AABBox r) { + public boolean intersects(final AABBox r) { return intersects(r.getMinX(), r.getMinY(), r.getWidth(), r.getHeight()); } public PathIterator iterator() { - return new Iterator(this); + return new Iterator(this); } - - public PathIterator iterator(AffineTransform t) { + + public PathIterator iterator(final AffineTransform t) { return new Iterator(this, t); } @@ -419,11 +423,11 @@ public final class Path2D implements Cloneable { @Override public Object clone() { try { - Path2D p = (Path2D) super.clone(); + final Path2D p = (Path2D) super.clone(); p.types = types.clone(); p.points = points.clone(); return p; - } catch (CloneNotSupportedException e) { + } catch (final CloneNotSupportedException e) { throw new InternalError(); } } diff --git a/src/jogl/classes/jogamp/graph/math/MathFloat.java b/src/jogl/classes/jogamp/graph/math/MathFloat.java deleted file mode 100644 index 82e7823a6..000000000 --- a/src/jogl/classes/jogamp/graph/math/MathFloat.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright 2011 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package jogamp.graph.math; - -public class MathFloat { - - public static final float E = 2.7182818284590452354f; - - public static final float PI = 3.14159265358979323846f; - - public static float abs(float a) { return (float) java.lang.Math.abs(a); } - public static float pow(float a, float b) { return (float) java.lang.Math.pow(a, b); } - - public static float sin(float a) { return (float) java.lang.Math.sin(a); } - public static float cos(float a) { return (float) java.lang.Math.cos(a); } - public static float acos(float a) { return (float) java.lang.Math.acos(a); } - - public static float sqrt(float a) { return (float) java.lang.Math.sqrt(a); } - -} |