From 5b627f588b1bb0e4cef57ffe1f9cd5efdf0f9e42 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 25 Mar 2011 02:37:14 +0100 Subject: Minor changes, OTGlyph: remove redundant/errorneous add-on points (origin, advanced). --- src/net/java/dev/typecast/ot/Glyph.java | 159 ---------------------------- src/net/java/dev/typecast/ot/OTFont.java | 23 ++-- src/net/java/dev/typecast/ot/OTGlyph.java | 168 ++++++++++++++++++++++++++++++ 3 files changed, 184 insertions(+), 166 deletions(-) delete mode 100644 src/net/java/dev/typecast/ot/Glyph.java create mode 100644 src/net/java/dev/typecast/ot/OTGlyph.java (limited to 'src/net/java/dev') diff --git a/src/net/java/dev/typecast/ot/Glyph.java b/src/net/java/dev/typecast/ot/Glyph.java deleted file mode 100644 index a59d62684..000000000 --- a/src/net/java/dev/typecast/ot/Glyph.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, 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. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Batik" and "Apache Software Foundation" must not be - used to endorse or promote products derived from this software without - prior written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, 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. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation. For more information on the - Apache Software Foundation, please see . - -*/ - -package net.java.dev.typecast.ot; - -import net.java.dev.typecast.ot.table.GlyphDescription; -import net.java.dev.typecast.ot.table.GlyfDescript; -import net.java.dev.typecast.ot.table.Charstring; -import net.java.dev.typecast.ot.table.CharstringType2; - -import net.java.dev.typecast.t2.T2Interpreter; - -/** - * An individual glyph within a font. - * @version $Id: Glyph.java,v 1.3 2007-02-21 12:23:54 davidsch Exp $ - * @author David Schweinsberg - */ -public class Glyph { - - protected short _leftSideBearing; - protected int _advanceWidth; - private Point[] _points; - - /** - * Construct a Glyph from a TrueType outline described by - * a GlyphDescription. - * @param cs The Charstring describing the glyph. - * @param lsb The Left Side Bearing. - * @param advance The advance width. - */ - public Glyph(GlyphDescription gd, short lsb, int advance) { - _leftSideBearing = lsb; - _advanceWidth = advance; - describe(gd); - } - - /** - * Construct a Glyph from a PostScript outline described by a Charstring. - * @param cs The Charstring describing the glyph. - * @param lsb The Left Side Bearing. - * @param advance The advance width. - */ - public Glyph(Charstring cs, short lsb, int advance) { - _leftSideBearing = lsb; - _advanceWidth = advance; - if (cs instanceof CharstringType2) { - T2Interpreter t2i = new T2Interpreter(); - _points = t2i.execute((CharstringType2) cs); - } else { - //throw unsupported charstring type - } - } - - public int getAdvanceWidth() { - return _advanceWidth; - } - - public short getLeftSideBearing() { - return _leftSideBearing; - } - - public Point getPoint(int i) { - return _points[i]; - } - - public int getPointCount() { - return _points.length; - } - - /** - * Resets the glyph to the TrueType table settings - */ - public void reset() { - } - - /** - * @param factor a 16.16 fixed value - */ - public void scale(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; - _points[i].x = ((_points[i].x<<10) * factor) >> 26; - _points[i].y = ((_points[i].y<<10) * factor) >> 26; - } - _leftSideBearing = (short)(( _leftSideBearing * factor) >> 6); - _advanceWidth = (_advanceWidth * factor) >> 6; - } - - /** - * Set the points of a glyph from the GlyphDescription - */ - private void describe(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; - if (endPt) { - endPtIndex++; - } - _points[i] = new Point( - gd.getXCoordinate(i), - gd.getYCoordinate(i), - (gd.getFlags(i) & GlyfDescript.onCurve) != 0, - endPt); - } - - // 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); - } -} diff --git a/src/net/java/dev/typecast/ot/OTFont.java b/src/net/java/dev/typecast/ot/OTFont.java index d23228483..e58fc3794 100644 --- a/src/net/java/dev/typecast/ot/OTFont.java +++ b/src/net/java/dev/typecast/ot/OTFont.java @@ -54,7 +54,8 @@ import java.io.DataInputStream; import java.io.IOException; import net.java.dev.typecast.ot.table.DirectoryEntry; -import net.java.dev.typecast.ot.table.TTCHeader; +import net.java.dev.typecast.ot.table.GlyfDescript; +import net.java.dev.typecast.ot.table.HdmxTable; import net.java.dev.typecast.ot.table.TableDirectory; import net.java.dev.typecast.ot.table.Table; import net.java.dev.typecast.ot.table.Os2Table; @@ -73,7 +74,7 @@ import net.java.dev.typecast.ot.table.TableFactory; /** * The TrueType font. * @version $Id: OTFont.java,v 1.6 2007-01-31 01:49:18 davidsch Exp $ - * @author David Schweinsberg + * @author David Schweinsberg, Sven Gothel */ public class OTFont { @@ -85,6 +86,7 @@ public class OTFont { private GlyfTable _glyf; private HeadTable _head; private HheaTable _hhea; + private HdmxTable _hdmx; private HmtxTable _hmtx; private LocaTable _loca; private MaxpTable _maxp; @@ -124,6 +126,10 @@ public class OTFont { return _hhea; } + public HdmxTable getHdmxTable() { + return _hdmx; + } + public HmtxTable getHmtxTable() { return _hmtx; } @@ -160,15 +166,17 @@ public class OTFont { return _maxp.getNumGlyphs(); } - public Glyph getGlyph(int i) { - return (_glyf.getDescription(i) != null) - ? new Glyph( - _glyf.getDescription(i), + public OTGlyph getGlyph(int i) { + + final GlyfDescript _glyfDescr = _glyf.getDescription(i); + return (null != _glyfDescr) + ? new OTGlyph( + _glyfDescr, _hmtx.getLeftSideBearing(i), _hmtx.getAdvanceWidth(i)) : null; } - + public TableDirectory getTableDirectory() { return _tableDirectory; } @@ -245,6 +253,7 @@ public class OTFont { // Get references to commonly used tables (these happen to be all the // required tables) _cmap = (CmapTable) getTable(Table.cmap); + _hdmx = (HdmxTable) getTable(Table.hdmx); _hmtx = (HmtxTable) getTable(Table.hmtx); _name = (NameTable) getTable(Table.name); _os2 = (Os2Table) getTable(Table.OS_2); diff --git a/src/net/java/dev/typecast/ot/OTGlyph.java b/src/net/java/dev/typecast/ot/OTGlyph.java new file mode 100644 index 000000000..958dd2280 --- /dev/null +++ b/src/net/java/dev/typecast/ot/OTGlyph.java @@ -0,0 +1,168 @@ +/* + + ============================================================================ + The Apache Software License, Version 1.1 + ============================================================================ + + Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without modifica- + tion, 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. + + 3. The end-user documentation included with the redistribution, if any, must + include the following acknowledgment: "This product includes software + developed by the Apache Software Foundation (http://www.apache.org/)." + Alternately, this acknowledgment may appear in the software itself, if + and wherever such third-party acknowledgments normally appear. + + 4. The names "Batik" and "Apache Software Foundation" must not be + used to endorse or promote products derived from this software without + prior written permission. For written permission, please contact + apache@apache.org. + + 5. Products derived from this software may not be called "Apache", nor may + "Apache" appear in their name, without prior written permission of the + Apache Software Foundation. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE + APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + DING, 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. + + This software consists of voluntary contributions made by many individuals + on behalf of the Apache Software Foundation. For more information on the + Apache Software Foundation, please see . + +*/ + +package net.java.dev.typecast.ot; + +import com.jogamp.graph.geom.AABBox; + +import net.java.dev.typecast.ot.table.GlyphDescription; +import net.java.dev.typecast.ot.table.GlyfDescript; +import net.java.dev.typecast.ot.table.Charstring; +import net.java.dev.typecast.ot.table.CharstringType2; + +import net.java.dev.typecast.t2.T2Interpreter; + +/** + * An individual glyph within a font. + * @version $Id: Glyph.java,v 1.3 2007-02-21 12:23:54 davidsch Exp $ + * @author David Schweinsberg, Sven Gothel + */ +public class OTGlyph { + + protected short _leftSideBearing; + protected int _advanceWidth; + private Point[] _points; + AABBox _bbox; + + /** + * Construct a Glyph from a TrueType outline described by + * a GlyphDescription. + * @param cs The Charstring describing the glyph. + * @param lsb The Left Side Bearing. + * @param advance The advance width. + */ + public OTGlyph(GlyphDescription gd, short lsb, int advance) { + _leftSideBearing = lsb; + _advanceWidth = advance; + describe(gd); + } + + /** + * Construct a Glyph from a PostScript outline described by a Charstring. + * @param cs The Charstring describing the glyph. + * @param lsb The Left Side Bearing. + * @param advance The advance width. + */ + public OTGlyph(Charstring cs, short lsb, int advance) { + _leftSideBearing = lsb; + _advanceWidth = advance; + if (cs instanceof CharstringType2) { + T2Interpreter t2i = new T2Interpreter(); + _points = t2i.execute((CharstringType2) cs); + } else { + //throw unsupported charstring type + } + } + + public AABBox getBBox() { + return _bbox; + } + + public int getAdvanceWidth() { + return _advanceWidth; + } + + public short getLeftSideBearing() { + return _leftSideBearing; + } + + public Point getPoint(int i) { + return _points[i]; + } + + public int getPointCount() { + return _points.length; + } + + /** + * Resets the glyph to the TrueType table settings + */ + public void reset() { + } + + /** + * @param factor a 16.16 fixed value + */ + public void scale(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; + _points[i].x = ((_points[i].x<<10) * factor) >> 26; + _points[i].y = ((_points[i].y<<10) * factor) >> 26; + } + _leftSideBearing = (short)(( _leftSideBearing * factor) >> 6); + _advanceWidth = (_advanceWidth * factor) >> 6; + } + + /** + * Set the points of a glyph from the GlyphDescription + */ + private void describe(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; + if (endPt) { + endPtIndex++; + } + _points[i] = new Point( + gd.getXCoordinate(i), + gd.getYCoordinate(i), + (gd.getFlags(i) & GlyfDescript.onCurve) != 0, + endPt); + } + + // 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); + } +} -- cgit v1.2.3