diff options
author | Sven Gothel <[email protected]> | 2023-02-11 19:01:52 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-02-11 19:01:52 +0100 |
commit | aea3a62c0139d1dfc208ede21d3f402d9a66df12 (patch) | |
tree | 3a62f2e40d028eefec3200ea727a2b1202030843 /src/jogl/classes/jogamp/graph/font | |
parent | feb8de27f848b5213423389cf0e19cbd88095682 (diff) |
Update included Typecast library to 2019-09-15 commit 0d55ac0eb4a39a7f8f2a796c7eebd3ea778ba9a7
- Using Typecast's new git repo https://github.com/dcsch/typecast
- Preserved our changes
- Preserved loading fonts and glyph on input stream w/o font data array copies
TODO
- Maintain an original branch in Typecast w/ our changes
to ease updates. Then we merely need to change the package name.
- This also shall help to allow Typecast to use our patches,
if so desired.
Diffstat (limited to 'src/jogl/classes/jogamp/graph/font')
127 files changed, 4651 insertions, 4361 deletions
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/cff/CffFont.java b/src/jogl/classes/jogamp/graph/font/typecast/cff/CffFont.java new file mode 100644 index 000000000..009344730 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/cff/CffFont.java @@ -0,0 +1,130 @@ +/* + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2015 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package jogamp.graph.font.typecast.cff; + +import java.io.DataInput; +import java.io.IOException; +import java.util.List; +import jogamp.graph.font.typecast.ot.table.CffTable; + +/** + * + * @author <a href="mailto:[email protected]">David Schweinsberg</a> + */ +public class CffFont { + + private final CffTable _table; + private final Dict _topDict; + private final Index _charStringsIndex; + private final Dict _privateDict; + private final Index _localSubrIndex; + private final Charset _charset; + private final Charstring[] _charstrings; + + public CffFont( + CffTable table, + int index, + Dict topDict) throws IOException { + _table = table; + _topDict = topDict; + + // Charstrings INDEX + // We load this before Charsets because we may need to know the number + // of glyphs + Integer charStringsOffset = (Integer) _topDict.getValue(17); + DataInput di = _table.getDataInputForOffset(charStringsOffset); + _charStringsIndex = new Index(di); + int glyphCount = _charStringsIndex.getCount(); + + // Private DICT + List<Integer> privateSizeAndOffset = (List<Integer>) _topDict.getValue(18); + di = _table.getDataInputForOffset(privateSizeAndOffset.get(1)); + _privateDict = new Dict(di, privateSizeAndOffset.get(0)); + + // Local Subrs INDEX + Integer localSubrsOffset = (Integer) _privateDict.getValue(19); + if (localSubrsOffset != null) { + di = table.getDataInputForOffset(privateSizeAndOffset.get(1) + localSubrsOffset); + _localSubrIndex = new Index(di); + } else { + _localSubrIndex = null; + //throw new Exception(); + } + + // Charsets + Integer charsetOffset = (Integer) _topDict.getValue(15); + di = table.getDataInputForOffset(charsetOffset); + int format = di.readUnsignedByte(); + switch (format) { + case 0: + _charset = new CharsetFormat0(di, glyphCount); + break; + case 1: + _charset = new CharsetFormat1(di, glyphCount); + break; + case 2: + _charset = new CharsetFormat2(di, glyphCount); + break; + default: + _charset = null; + //throw new Exception(); + } + + // Create the charstrings + _charstrings = new Charstring[glyphCount]; + for (int i = 0; i < glyphCount; ++i) { + int offset = _charStringsIndex.getOffset(i) - 1; + int len = _charStringsIndex.getOffset(i + 1) - offset - 1; + _charstrings[i] = new CharstringType2( + this, + index, + table.getStringIndex().getString(_charset.getSID(i)), + _charStringsIndex.getData(), + offset, + len); + } + } + + public CffTable getTable() { + return _table; + } + + public Index getCharStringsIndex() { + return _charStringsIndex; + } + + public Dict getPrivateDict() { + return _privateDict; + } + + public Index getLocalSubrIndex() { + return _localSubrIndex; + } + + public Charset getCharset() { + return _charset; + } + + public Charstring getCharstring(int gid) { + return _charstrings[gid]; + } + + public int getCharstringCount() { + return _charstrings.length; + } +} diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CffStandardStrings.java b/src/jogl/classes/jogamp/graph/font/typecast/cff/CffStandardStrings.java index bf6bd6a67..49acc27ee 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CffStandardStrings.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/cff/CffStandardStrings.java @@ -1,9 +1,7 @@ /* - * $Id: CffStandardStrings.java,v 1.1 2007-02-05 12:41:52 davidsch Exp $ - * * Typecast - The Font Development Environment * - * Copyright (c) 2004-2007 David Schweinsberg + * Copyright (c) 2004-2015 David Schweinsberg * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,15 +16,14 @@ * limitations under the License. */ -package jogamp.graph.font.typecast.ot.table; +package jogamp.graph.font.typecast.cff; /** * Compact Font Format Standard Strings. As per Appendix A of the Adobe * CFF specification. - * @version $Id: CffStandardStrings.java,v 1.1 2007-02-05 12:41:52 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class CffStandardStrings { +class CffStandardStrings { public static final String[] standardStrings = { ".notdef", diff --git a/src/jogl/classes/jogamp/graph/font/typecast/cff/Charset.java b/src/jogl/classes/jogamp/graph/font/typecast/cff/Charset.java new file mode 100644 index 000000000..b4e65ba3e --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/cff/Charset.java @@ -0,0 +1,33 @@ +/* + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2015 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package jogamp.graph.font.typecast.cff; + +/** + * + * @author dschweinsberg + */ +public abstract class Charset { + + Charset() { + } + + public abstract int getFormat(); + + public abstract int getSID(int gid); + +} diff --git a/src/jogl/classes/jogamp/graph/font/typecast/cff/CharsetFormat0.java b/src/jogl/classes/jogamp/graph/font/typecast/cff/CharsetFormat0.java new file mode 100644 index 000000000..d163a2380 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/cff/CharsetFormat0.java @@ -0,0 +1,51 @@ +/* + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2015 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package jogamp.graph.font.typecast.cff; + +import java.io.DataInput; +import java.io.IOException; + +/** + * + * @author dschweinsberg + */ +public class CharsetFormat0 extends Charset { + + private final int[] _glyph; + + public CharsetFormat0(DataInput di, 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(); + } + } // minus 1 because .notdef is omitted + + @Override + public int getFormat() { + return 0; + } + + @Override + public int getSID(int gid) { + if (gid == 0) { + return 0; + } + return _glyph[gid - 1]; + } + +} diff --git a/src/jogl/classes/jogamp/graph/font/typecast/cff/CharsetFormat1.java b/src/jogl/classes/jogamp/graph/font/typecast/cff/CharsetFormat1.java new file mode 100644 index 000000000..a6cbf050a --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/cff/CharsetFormat1.java @@ -0,0 +1,62 @@ +/* + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2015 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package jogamp.graph.font.typecast.cff; + +import java.io.DataInput; +import java.io.IOException; +import java.util.ArrayList; + +/** + * + * @author dschweinsberg + */ +public class CharsetFormat1 extends Charset { + + private final ArrayList<CharsetRange> _charsetRanges = new ArrayList<>(); + + public CharsetFormat1(DataInput di, int glyphCount) throws IOException { + int glyphsCovered = glyphCount - 1; // minus 1 because .notdef is omitted + while (glyphsCovered > 0) { + CharsetRange range = new CharsetRange1(di); + _charsetRanges.add(range); + glyphsCovered -= range.getLeft() + 1; + } + } + + @Override + public int getFormat() { + return 1; + } + + @Override + public int getSID(int gid) { + if (gid == 0) { + return 0; + } + + // Count through the ranges to find the one of interest + int count = 1; + for (CharsetRange range : _charsetRanges) { + if (gid <= range.getLeft() + count) { + return gid - count + range.getFirst(); + } + count += range.getLeft() + 1; + } + return 0; + } +} diff --git a/src/jogl/classes/jogamp/graph/font/typecast/cff/CharsetFormat2.java b/src/jogl/classes/jogamp/graph/font/typecast/cff/CharsetFormat2.java new file mode 100644 index 000000000..e4d4052e9 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/cff/CharsetFormat2.java @@ -0,0 +1,62 @@ +/* + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2015 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package jogamp.graph.font.typecast.cff; + +import java.io.DataInput; +import java.io.IOException; +import java.util.ArrayList; + +/** + * + * @author dschweinsberg + */ +public class CharsetFormat2 extends Charset { + + private final ArrayList<CharsetRange> _charsetRanges = new ArrayList<>(); + + public CharsetFormat2(DataInput di, int glyphCount) throws IOException { + int glyphsCovered = glyphCount - 1; // minus 1 because .notdef is omitted + while (glyphsCovered > 0) { + CharsetRange range = new CharsetRange2(di); + _charsetRanges.add(range); + glyphsCovered -= range.getLeft() + 1; + } + } + + @Override + public int getFormat() { + return 2; + } + + @Override + public int getSID(int gid) { + if (gid == 0) { + return 0; + } + + // Count through the ranges to find the one of interest + int count = 1; + for (CharsetRange range : _charsetRanges) { + if (gid <= range.getLeft() + count) { + return gid - count + range.getFirst(); + } + count += range.getLeft() + 1; + } + return 0; + } +} diff --git a/src/jogl/classes/jogamp/graph/font/typecast/cff/CharsetRange.java b/src/jogl/classes/jogamp/graph/font/typecast/cff/CharsetRange.java new file mode 100644 index 000000000..c76e2237a --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/cff/CharsetRange.java @@ -0,0 +1,48 @@ +/* + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2015 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package jogamp.graph.font.typecast.cff; + +/** + * + * @author dschweinsberg + */ +class CharsetRange { + + private int _first; + private int _left; + + CharsetRange() { + } + + public final int getFirst() { + return _first; + } + + final void setFirst(int first) { + _first = first; + } + + public final int getLeft() { + return _left; + } + + final void setLeft(int left) { + _left = left; + } + +} diff --git a/src/jogl/classes/jogamp/graph/font/typecast/cff/CharsetRange1.java b/src/jogl/classes/jogamp/graph/font/typecast/cff/CharsetRange1.java new file mode 100644 index 000000000..fc0fd700f --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/cff/CharsetRange1.java @@ -0,0 +1,34 @@ +/* + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2015 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package jogamp.graph.font.typecast.cff; + +import java.io.DataInput; +import java.io.IOException; + +/** + * + * @author dschweinsberg + */ +class CharsetRange1 extends CharsetRange { + + CharsetRange1(DataInput di) throws IOException { + setFirst(di.readUnsignedShort()); + setLeft(di.readUnsignedByte()); + } + +} diff --git a/src/jogl/classes/jogamp/graph/font/typecast/cff/CharsetRange2.java b/src/jogl/classes/jogamp/graph/font/typecast/cff/CharsetRange2.java new file mode 100644 index 000000000..dba3764cc --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/cff/CharsetRange2.java @@ -0,0 +1,34 @@ +/* + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2015 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package jogamp.graph.font.typecast.cff; + +import java.io.DataInput; +import java.io.IOException; + +/** + * + * @author dschweinsberg + */ +class CharsetRange2 extends CharsetRange { + + CharsetRange2(DataInput di) throws IOException { + setFirst(di.readUnsignedShort()); + setLeft(di.readUnsignedShort()); + } + +} diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Charstring.java b/src/jogl/classes/jogamp/graph/font/typecast/cff/Charstring.java index 01e2d4934..ccec144f3 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/Charstring.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/cff/Charstring.java @@ -1,9 +1,7 @@ /* - * $Id: Charstring.java,v 1.2 2007-02-21 12:25:19 davidsch Exp $ - * * Typecast - The Font Development Environment * - * Copyright (c) 2004-2007 David Schweinsberg + * Copyright (c) 2004-2015 David Schweinsberg * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,16 +16,15 @@ * limitations under the License. */ -package jogamp.graph.font.typecast.ot.table; +package jogamp.graph.font.typecast.cff; /** * CFF Charstring - * @version $Id: Charstring.java,v 1.2 2007-02-21 12:25:19 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ 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/cff/CharstringType2.java index d96a5848b..2ba94ea40 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CharstringType2.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/cff/CharstringType2.java @@ -1,9 +1,7 @@ /* - * $Id: CharstringType2.java,v 1.4 2007-07-26 11:13:44 davidsch Exp $ - * * Typecast - The Font Development Environment * - * Copyright (c) 2004-2007 David Schweinsberg + * Copyright (c) 2004-2015 David Schweinsberg * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,17 +16,14 @@ * limitations under the License. */ -package jogamp.graph.font.typecast.ot.table; - -import jogamp.graph.font.typecast.ot.table.CffTable; +package jogamp.graph.font.typecast.cff; /** * CFF Type 2 Charstring - * @version $Id: CharstringType2.java,v 1.4 2007-07-26 11:13:44 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class CharstringType2 extends Charstring { - + private static final String[] _oneByteOperators = { "-Reserved-", "hstem", @@ -105,34 +100,40 @@ public class CharstringType2 extends Charstring { "flex1", "-Reserved-" }; - + + private final CffFont _font; 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( - final int index, - final String name, - final int[] data, - final int offset, - final int length, - final CffTable.Index localSubrIndex, - final CffTable.Index globalSubrIndex) { + + /** Creates a new instance of CharstringType2 + * @param font + * @param index + * @param name + * @param data + * @param offset + * @param length */ + public CharstringType2( + CffFont font, + int index, + String name, + int[] data, + int offset, + int length) { + _font = font; _index = index; _name = name; _data = data; _offset = offset; _length = length; - _localSubrIndex = localSubrIndex; - _globalSubrIndex = globalSubrIndex; } - + + public CffFont getFont() { + return _font; + } + @Override public int getIndex() { return _index; @@ -142,18 +143,18 @@ public class CharstringType2 extends Charstring { public String getName() { return _name; } - - private void disassemble(final StringBuilder sb) { - Number operand = null; - while (isOperandAtIndex()) { - operand = nextOperand(); + + private int disassemble(int ip, StringBuilder sb) { + while (isOperandAtIndex(ip)) { + Number operand = operandAtIndex(ip); sb.append(operand).append(" "); + ip = nextOperandIndex(ip); } - int operator = nextByte(); + int operator = byteAtIndex(ip++); String mnemonic; if (operator == 12) { - operator = nextByte(); - + operator = byteAtIndex(ip++); + // Check we're not exceeding the upper limit of our mnemonics if (operator > 38) { operator = 38; @@ -163,74 +164,95 @@ public class CharstringType2 extends Charstring { mnemonic = _oneByteOperators[operator]; } sb.append(mnemonic); + return ip; } - - public void resetIP() { - _ip = _offset; + + public int getFirstIndex() { + return _offset; } - public boolean isOperandAtIndex() { - final int b0 = _data[_ip]; - if ((32 <= b0 && b0 <= 255) || b0 == 28) { - return true; - } - return false; + public boolean isOperandAtIndex(int ip) { + int b0 = _data[ip]; + return (32 <= b0 && b0 <= 255) || b0 == 28; } - public Number nextOperand() { - final int b0 = _data[_ip]; + public Number operandAtIndex(int ip) { + int b0 = _data[ip]; if (32 <= b0 && b0 <= 246) { // 1 byte integer - ++_ip; - return Integer.valueOf(b0 - 139); + return b0 - 139; } else if (247 <= b0 && b0 <= 250) { // 2 byte integer - final int b1 = _data[_ip + 1]; - _ip += 2; - return Integer.valueOf((b0 - 247) * 256 + b1 + 108); + int b1 = _data[ip + 1]; + return (b0 - 247) * 256 + b1 + 108; } else if (251 <= b0 && b0 <= 254) { // 2 byte integer - final int b1 = _data[_ip + 1]; - _ip += 2; - return Integer.valueOf(-(b0 - 251) * 256 - b1 - 108); + int b1 = _data[ip + 1]; + return -(b0 - 251) * 256 - b1 - 108; } else if (b0 == 28) { // 3 byte integer - final int b1 = _data[_ip + 1]; - final int b2 = _data[_ip + 2]; - _ip += 3; - return Integer.valueOf(b1 << 8 | b2); + int b1 = (byte)_data[ip + 1]; + int b2 = _data[ip + 2]; + return b1 << 8 | b2; } else if (b0 == 255) { // 16-bit signed integer with 16 bits of fraction - 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 Float.valueOf((b1 << 8 | b2) + ((b3 << 8 | b4) / 65536f)); + int b1 = (byte) _data[ip + 1]; + int b2 = _data[ip + 2]; + int b3 = _data[ip + 3]; + int b4 = _data[ip + 4]; + return (float) ((b1 << 8 | b2) + ((b3 << 8 | b4) / 65536.0)); } else { return null; } } - public int nextByte() { - return _data[_ip++]; - } + public int nextOperandIndex(int ip) { + int b0 = _data[ip]; + if (32 <= b0 && b0 <= 246) { - public boolean moreBytes() { - return _ip < _offset + _length; + // 1 byte integer + return ip + 1; + } else if (247 <= b0 && b0 <= 250) { + + // 2 byte integer + return ip + 2; + } else if (251 <= b0 && b0 <= 254) { + + // 2 byte integer + return ip + 2; + } else if (b0 == 28) { + + // 3 byte integer + return ip + 3; + } else if (b0 == 255) { + + return ip + 5; + } else { + return ip; + } + } + + public int byteAtIndex(int ip) { + return _data[ip]; + } + + public boolean moreBytes(int ip) { + return ip < _offset + _length; } @Override public String toString() { - final StringBuilder sb = new StringBuilder(); - resetIP(); - while (moreBytes()) { - disassemble(sb); + StringBuilder sb = new StringBuilder(); + int ip = getFirstIndex(); + while (moreBytes(ip)) { +// sb.append(ip); +// sb.append(": "); + ip = disassemble(ip, sb); sb.append("\n"); } return sb.toString(); diff --git a/src/jogl/classes/jogamp/graph/font/typecast/cff/Dict.java b/src/jogl/classes/jogamp/graph/font/typecast/cff/Dict.java new file mode 100644 index 000000000..610c648ee --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/cff/Dict.java @@ -0,0 +1,165 @@ +/* + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2015 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package jogamp.graph.font.typecast.cff; + +import java.io.DataInput; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +/** + * + * @author dschweinsberg + */ +public class Dict { + + private final Map<Integer, Object> _entries = new HashMap<>(); + private final int[] _data; + private int _index; + + public Dict(int[] data, int offset, int length) { + _data = data; + _index = offset; + while (_index < offset + length) { + addKeyAndValueEntry(); + } + } + + public Dict(DataInput di, int length) throws IOException { + _data = new int[length]; + for (int i = 0; i < length; ++i) { + _data[i] = di.readUnsignedByte(); + } + _index = 0; + while (_index < length) { + addKeyAndValueEntry(); + } + } + + public Object getValue(int key) { + return _entries.get(key); + } + + private void addKeyAndValueEntry() { + ArrayList<Object> operands = new ArrayList<>(); + Object operand = null; + while (isOperandAtIndex()) { + operand = nextOperand(); + operands.add(operand); + } + int operator = _data[_index++]; + if (operator == 12) { + operator <<= 8; + operator |= _data[_index++]; + } + if (operands.size() == 1) { + _entries.put(operator, operand); + } else { + _entries.put(operator, operands); + } + } + + private boolean isOperandAtIndex() { + int b0 = _data[_index]; + return (32 <= b0 && b0 <= 254) || b0 == 28 || b0 == 29 || b0 == 30; + } + + // private boolean isOperatorAtIndex() { + // int b0 = _data[_index]; + // return 0 <= b0 && b0 <= 21; + // } + private Object nextOperand() { + int b0 = _data[_index]; + if (32 <= b0 && b0 <= 246) { + // 1 byte integer + ++_index; + return b0 - 139; + } else if (247 <= b0 && b0 <= 250) { + // 2 byte integer + int b1 = _data[_index + 1]; + _index += 2; + return (b0 - 247) * 256 + b1 + 108; + } else if (251 <= b0 && b0 <= 254) { + // 2 byte integer + int b1 = _data[_index + 1]; + _index += 2; + return -(b0 - 251) * 256 - b1 - 108; + } else if (b0 == 28) { + // 3 byte integer + int b1 = _data[_index + 1]; + int b2 = _data[_index + 2]; + _index += 3; + return 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]; + _index += 5; + return b1 << 24 | b2 << 16 | b3 << 8 | b4; + } else if (b0 == 30) { + // Real number + StringBuilder fString = new StringBuilder(); + int nibble1 = 0; + int nibble2 = 0; + ++_index; + while ((nibble1 != 0xf) && (nibble2 != 0xf)) { + nibble1 = _data[_index] >> 4; + nibble2 = _data[_index] & 0xf; + ++_index; + fString.append(decodeRealNibble(nibble1)); + fString.append(decodeRealNibble(nibble2)); + } + return Float.valueOf(fString.toString()); + } else { + return null; + } + } + + private String decodeRealNibble(int nibble) { + if (nibble < 0xa) { + return Integer.toString(nibble); + } else if (nibble == 0xa) { + return "."; + } else if (nibble == 0xb) { + return "E"; + } else if (nibble == 0xc) { + return "E-"; + } else if (nibble == 0xe) { + return "-"; + } + return ""; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + for (Integer key : _entries.keySet()) { + if ((key & 0xc00) == 0xc00) { + sb.append("12 ").append(key & 0xff).append(": "); + } else { + sb.append(key.toString()).append(": "); + } + sb.append(_entries.get(key).toString()).append("\n"); + } + return sb.toString(); + } + +} diff --git a/src/jogl/classes/jogamp/graph/font/typecast/cff/Index.java b/src/jogl/classes/jogamp/graph/font/typecast/cff/Index.java new file mode 100644 index 000000000..42411a6b3 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/cff/Index.java @@ -0,0 +1,89 @@ +/* + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2015 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package jogamp.graph.font.typecast.cff; + +import java.io.DataInput; +import java.io.IOException; + +/** + * + * @author dschweinsberg + */ +public class Index { + + private final int _count; + private final int _offSize; + private final int[] _offset; + private final int[] _data; + + public Index(DataInput di) throws IOException { + _count = di.readUnsignedShort(); + _offset = new int[_count + 1]; + _offSize = di.readUnsignedByte(); + for (int i = 0; i < _count + 1; ++i) { + int thisOffset = 0; + for (int j = 0; j < _offSize; ++j) { + thisOffset |= di.readUnsignedByte() << ((_offSize - j - 1) * 8); + } + _offset[i] = thisOffset; + } + _data = new int[getDataLength()]; + for (int i = 0; i < getDataLength(); ++i) { + _data[i] = di.readUnsignedByte(); + } + } + + public final int getCount() { + return _count; + } + + public final int getOffset(int index) { + return _offset[index]; + } + + public final int getDataLength() { + return _offset[_offset.length - 1] - 1; + } + + public final int[] getData() { + return _data; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("DICT\n"); + sb.append("count: ").append(_count).append("\n"); + sb.append("offSize: ").append(_offSize).append("\n"); + for (int i = 0; i < _count + 1; ++i) { + sb.append("offset[").append(i).append("]: ").append(_offset[i]).append("\n"); + } + sb.append("data:"); + for (int i = 0; i < _data.length; ++i) { + if (i % 8 == 0) { + sb.append("\n"); + } else { + sb.append(" "); + } + sb.append(_data[i]); + } + sb.append("\n"); + return sb.toString(); + } + +} diff --git a/src/jogl/classes/jogamp/graph/font/typecast/cff/NameIndex.java b/src/jogl/classes/jogamp/graph/font/typecast/cff/NameIndex.java new file mode 100644 index 000000000..824ebc7a6 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/cff/NameIndex.java @@ -0,0 +1,57 @@ +/* + * Copyright 2015 dschweinsberg. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package jogamp.graph.font.typecast.cff; + +import java.io.DataInput; +import java.io.IOException; + +/** + * + * @author dschweinsberg + */ +public class NameIndex extends Index { + + public NameIndex(DataInput di) throws IOException { + super(di); + } + + private String getName(int index) { + String name; + int offset = getOffset(index) - 1; + int len = getOffset(index + 1) - offset - 1; + // Ensure the name hasn't been deleted + if (getData()[offset] != 0) { + StringBuilder sb = new StringBuilder(); + for (int i = offset; i < offset + len; ++i) { + sb.append((char) getData()[i]); + } + name = sb.toString(); + } else { + name = "DELETED NAME"; + } + return name; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < getCount(); ++i) { + sb.append(getName(i)).append("\n"); + } + return sb.toString(); + } + +} diff --git a/src/jogl/classes/jogamp/graph/font/typecast/cff/StringIndex.java b/src/jogl/classes/jogamp/graph/font/typecast/cff/StringIndex.java new file mode 100644 index 000000000..c75a0c47b --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/cff/StringIndex.java @@ -0,0 +1,62 @@ +/* + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2015 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package jogamp.graph.font.typecast.cff; + +import java.io.DataInput; +import java.io.IOException; + +/** + * + * @author dschweinsberg + */ +public class StringIndex extends Index { + + public StringIndex(DataInput di) throws IOException { + super(di); + } + + public String getString(int index) { + if (index < CffStandardStrings.standardStrings.length) { + return CffStandardStrings.standardStrings[index]; + } else { + index -= CffStandardStrings.standardStrings.length; + if (index >= getCount()) { + return null; + } + int offset = getOffset(index) - 1; + int len = getOffset(index + 1) - offset - 1; + 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(); + for (int i = 0; i < getCount(); ++i) { + sb.append(nonStandardBase + i).append(": "); + sb.append(getString(nonStandardBase + i)).append("\n"); + } + return sb.toString(); + } + +} diff --git a/src/jogl/classes/jogamp/graph/font/typecast/t2/T2Interpreter.java b/src/jogl/classes/jogamp/graph/font/typecast/cff/T2Interpreter.java index 80d76a7f8..1f4207393 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/t2/T2Interpreter.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/cff/T2Interpreter.java @@ -1,9 +1,7 @@ /* - * $Id: T2Interpreter.java,v 1.2 2007-07-26 11:10:18 davidsch Exp $ - * * Typecast - The Font Development Environment * - * Copyright (c) 2004-2007 David Schweinsberg + * Copyright (c) 2004-2016 David Schweinsberg * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,48 +16,74 @@ * limitations under the License. */ -package jogamp.graph.font.typecast.t2; +package jogamp.graph.font.typecast.cff; import java.util.ArrayList; - import jogamp.graph.font.typecast.ot.Point; -import jogamp.graph.font.typecast.ot.table.CharstringType2; - - /** * Type 2 Charstring Interpreter. Operator descriptions are quoted from * Adobe's Type 2 Charstring Format document -- 5117.Type2.pdf. - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: T2Interpreter.java,v 1.2 2007-07-26 11:10:18 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class T2Interpreter { + private static final boolean DEBUG = false; + + private static class SubrPair { + final CharstringType2 cs; + final int ip; + SubrPair(CharstringType2 cs, int ip) { + this.cs = cs; + this.ip = ip; + } + } + 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 final Number[] _argStack = new Number[ARGUMENT_STACK_LIMIT]; private int _argStackIndex = 0; - private final int[] _subrStack = new int[SUBR_STACK_LIMIT]; + private final SubrPair[] _subrStack = new SubrPair[SUBR_STACK_LIMIT]; private int _subrStackIndex = 0; private final Number[] _transientArray = new Number[TRANSIENT_ARRAY_ELEMENT_COUNT]; - + + private int _stemCount = 0; + private ArrayList<Integer> _hstems; + private ArrayList<Integer> _vstems; + private ArrayList<Point> _points; + private Index _localSubrIndex; + private Index _globalSubrIndex; + private CharstringType2 _localSubrs; + private CharstringType2 _globalSubrs; + private CharstringType2 _cs; + private int _ip; /** Creates a new instance of T2Interpreter */ public T2Interpreter() { } - + + public Integer[] getHStems() { + Integer[] array = new Integer[_hstems.size()]; + return _hstems.toArray(array); + } + + public Integer[] getVStems() { + Integer[] array = new Integer[_vstems.size()]; + return _vstems.toArray(array); + } + /** * Moves the current point to a position at the relative coordinates * (dx1, dy1). */ private void _rmoveto() { - final int dy1 = popArg().intValue(); - final int dx1 = popArg().intValue(); + int dy1 = popArg().intValue(); + int dx1 = popArg().intValue(); clearArg(); - final Point lastPoint = getLastPoint(); + Point lastPoint = getLastPoint(); moveTo(lastPoint.x + dx1, lastPoint.y + dy1); } @@ -67,22 +91,22 @@ public class T2Interpreter { * Moves the current point dx1 units in the horizontal direction. */ private void _hmoveto() { - final int dx1 = popArg().intValue(); + int dx1 = popArg().intValue(); clearArg(); - final Point lastPoint = getLastPoint(); + Point lastPoint = getLastPoint(); moveTo(lastPoint.x + dx1, lastPoint.y); } - + /** * Moves the current point dy1 units in the vertical direction. */ private void _vmoveto() { - final int dy1 = popArg().intValue(); + int dy1 = popArg().intValue(); clearArg(); - final Point lastPoint = getLastPoint(); + 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 +114,20 @@ public class T2Interpreter { * lines is determined from the number of arguments on the stack. */ private void _rlineto() { - final int count = getArgCount() / 2; - final int[] dx = new int[count]; - final int[] dy = new int[count]; + int count = getArgCount() / 2; + int[] dx = new int[count]; + 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) { - final Point lastPoint = getLastPoint(); + 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 +139,13 @@ public class T2Interpreter { * number of arguments on the stack. */ private void _hlineto() { - final int count = getArgCount(); - final Number[] nums = new Number[count]; + int count = getArgCount(); + Number[] nums = new Number[count]; for (int i = 0; i < count; ++i) { nums[count - i - 1] = popArg(); } for (int i = 0; i < count; ++i) { - final Point lastPoint = getLastPoint(); + Point lastPoint = getLastPoint(); if (i % 2 == 0) { lineTo(lastPoint.x + nums[i].intValue(), lastPoint.y); } else { @@ -130,7 +154,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 +166,13 @@ public class T2Interpreter { * number of arguments on the stack. */ private void _vlineto() { - final int count = getArgCount(); - final Number[] nums = new Number[count]; + int count = getArgCount(); + Number[] nums = new Number[count]; for (int i = 0; i < count; ++i) { nums[count - i - 1] = popArg(); } for (int i = 0; i < count; ++i) { - final Point lastPoint = getLastPoint(); + Point lastPoint = getLastPoint(); if (i % 2 == 0) { lineTo(lastPoint.x, lastPoint.y + nums[i].intValue()); } else { @@ -157,7 +181,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 +191,13 @@ public class T2Interpreter { * stack. */ private void _rrcurveto() { - 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]; + 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]; for (int i = 0; i < count; ++i) { dyc[count - i - 1] = popArg().intValue(); dxc[count - i - 1] = popArg().intValue(); @@ -183,18 +207,18 @@ public class T2Interpreter { dxa[count - i - 1] = popArg().intValue(); } for (int i = 0; i < count; ++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]; + 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]; 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 +227,12 @@ public class T2Interpreter { * case). Note the argument order for the odd argument case. */ private void _hhcurveto() { - final int count = getArgCount() / 4; + int count = getArgCount() / 4; int dy1 = 0; - final int[] dxa = new int[count]; - final int[] dxb = new int[count]; - final int[] dyb = new int[count]; - final int[] dxc = new int[count]; + int[] dxa = new int[count]; + int[] dxb = new int[count]; + int[] dyb = new int[count]; + 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 +243,17 @@ public class T2Interpreter { dy1 = popArg().intValue(); } for (int i = 0; i < count; ++i) { - 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); + 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]; + curveTo(xa, ya, xb, yb, xc, yb); } 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 +266,15 @@ public class T2Interpreter { */ private void _hvcurveto() { if (getArgCount() % 8 <= 1) { - 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 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]; int dyf = 0; if (getArgCount() % 8 == 1) { dyf = popArg().intValue(); @@ -267,34 +290,32 @@ public class T2Interpreter { dxa[count - i - 1] = popArg().intValue(); } for (int i = 0; i < count; ++i) { - 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); + Point lastPoint = getLastPoint(); + int xa = lastPoint.x + dxa[i]; + int ya = lastPoint.y; + int xb = xa + dxb[i]; + int yb = ya + dyb[i]; + int yc = yb + dyc[i]; + int yd = yc + dyd[i]; + int xe = xb + dxe[i]; + int ye = yd + dye[i]; + int xf = xe + dxf[i]; + int yf = ye + (i == count - 1 ? dyf : 0); + curveTo(xa, ya, xb, yb, xb, yc); + curveTo(xb, yd, xe, ye, xf, yf); } } else { - 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 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]; int dxf = 0; - if (getArgCount() % 8 == 1) { + if (getArgCount() % 4 == 1) { dxf = popArg().intValue(); } for (int i = 0; i < count; ++i) { @@ -307,43 +328,39 @@ public class T2Interpreter { dxb[count - i - 1] = popArg().intValue(); dya[count - i - 1] = 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(); + int dy3 = popArg().intValue(); + int dy2 = popArg().intValue(); + int dx2 = popArg().intValue(); + int dx1 = popArg().intValue(); + + Point lastPoint = getLastPoint(); + int x1 = lastPoint.x + dx1; + int y1 = lastPoint.y; + int x2 = x1 + dx2; + int y2 = y1 + dy2; + int x3 = x2 + (count == 0 ? dxf : 0); + int y3 = y2 + dy3; + curveTo(x1, y1, x2, y2, x3, y3); for (int i = 0; i < count; ++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? + 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 xd = xc + dxd[i]; + int xe = xd + dxe[i]; + int ye = yb + dye[i]; + int xf = xe + (i == count - 1 ? dxf : 0); + int yf = ye + dyf[i]; + curveTo(xa, ya, xb, yb, xc, yb); + curveTo(xd, yb, xe, ye, xf, yf); } } clearArg(); } - + /** * Is equivalent to one rrcurveto for each set of six arguments * dxa...dyc, followed by exactly one rlineto using the dxd, dyd @@ -351,15 +368,15 @@ public class T2Interpreter { * on the argument stack. */ private void _rcurveline() { - 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(); + 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(); for (int i = 0; i < count; ++i) { dyc[count - i - 1] = popArg().intValue(); dxc[count - i - 1] = popArg().intValue(); @@ -371,11 +388,11 @@ public class T2Interpreter { int xc = 0; int yc = 0; for (int i = 0; i < count; ++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]; + 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]; xc = xb + dxc[i]; yc = yb + dyc[i]; curveTo(xa, ya, xb, yb, xc, yc); @@ -383,7 +400,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 @@ -391,15 +408,15 @@ public class T2Interpreter { * items on the argument stack. */ private void _rlinecurve() { - 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(); + 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(); for (int i = 0; i < count; ++i) { dya[count - i - 1] = popArg().intValue(); dxa[count - i - 1] = popArg().intValue(); @@ -407,21 +424,21 @@ public class T2Interpreter { int xa = 0; int ya = 0; for (int i = 0; i < count; ++i) { - final Point lastPoint = getLastPoint(); + Point lastPoint = getLastPoint(); xa = lastPoint.x + dxa[i]; ya = lastPoint.y + dya[i]; lineTo(xa, ya); } - 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; + int xb = xa + dxb; + int yb = ya + dyb; + int xc = xb + dxc; + int yc = yb + dyc; + int xd = xc + dxd; + 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. @@ -430,15 +447,15 @@ public class T2Interpreter { */ private void _vhcurveto() { if (getArgCount() % 8 <= 1) { - 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 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]; int dxf = 0; if (getArgCount() % 8 == 1) { dxf = popArg().intValue(); @@ -454,28 +471,77 @@ public class T2Interpreter { dya[count - i - 1] = popArg().intValue(); } for (int i = 0; i < count; ++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); + 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 xd = xc + dxd[i]; + int xe = xd + dxe[i]; + int ye = yb + dye[i]; + int xf = xe + (i == count - 1 ? dxf : 0); + int yf = ye + dyf[i]; + curveTo(xa, ya, xb, yb, xc, yb); + curveTo(xd, yb, xe, ye, xf, yf); } } else { - final int foo = 0; + 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]; + int dyf = 0; + if (getArgCount() % 4 == 1) { + dyf = popArg().intValue(); + } + for (int i = 0; i < count; ++i) { + dxf[count - i - 1] = popArg().intValue(); + dye[count - i - 1] = popArg().intValue(); + dxe[count - i - 1] = popArg().intValue(); + dyd[count - i - 1] = popArg().intValue(); + dyc[count - i - 1] = popArg().intValue(); + dyb[count - i - 1] = popArg().intValue(); + dxb[count - i - 1] = popArg().intValue(); + dxa[count - i - 1] = popArg().intValue(); + } + int dx3 = popArg().intValue(); + int dy2 = popArg().intValue(); + int dx2 = popArg().intValue(); + int dy1 = popArg().intValue(); + + Point lastPoint = getLastPoint(); + int x1 = lastPoint.x; + int y1 = lastPoint.y + dy1; + int x2 = x1 + dx2; + int y2 = y1 + dy2; + int x3 = x2 + dx3; + int y3 = y2 + (count == 0 ? dyf : 0); + curveTo(x1, y1, x2, y2, x3, y3); + + for (int i = 0; i < count; ++i) { + lastPoint = getLastPoint(); + int xa = lastPoint.x + dxa[i]; + int ya = lastPoint.y; + int xb = xa + dxb[i]; + int yb = ya + dyb[i]; + int yc = yb + dyc[i]; + int yd = yc + dyd[i]; + int xe = xb + dxe[i]; + int ye = yd + dye[i]; + int xf = xe + dxf[i]; + int yf = ye + (i == count - 1 ? dyf : 0); + curveTo(xa, ya, xb, yb, xb, yc); + curveTo(xb, yd, xe, ye, xf, yf); + } } 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 @@ -483,22 +549,46 @@ public class T2Interpreter { * vertical tangent. */ private void _vvcurveto() { - + int count = getArgCount() / 4; + int dx1 = 0; + int[] dya = new int[count]; + int[] dxb = new int[count]; + int[] dyb = new int[count]; + int[] dyc = new int[count]; + for (int i = 0; i < count; ++i) { + dyc[count - i - 1] = popArg().intValue(); + dyb[count - i - 1] = popArg().intValue(); + dxb[count - i - 1] = popArg().intValue(); + dya[count - i - 1] = popArg().intValue(); + } + if (getArgCount() == 1) { + dx1 = popArg().intValue(); + } + for (int i = 0; i < count; ++i) { + Point lastPoint = getLastPoint(); + int xa = lastPoint.x + (i == 0 ? dx1 : 0); + int ya = lastPoint.y + dya[i]; + int xb = xa + dxb[i]; + int yb = ya + dyb[i]; + int yc = yb + dyc[i]; + curveTo(xa, ya, xb, yb, xb, yc); + } + clearArg(); } - + /** - * Causes two Bezier curves, as described by the arguments (as + * Causes two Bézier curves, as described by the arguments (as * shown in Figure 2 below), to be rendered as a straight line when * the flex depth is less than fd /100 device pixels, and as curved lines * when the flex depth is greater than or equal to fd/100 device * 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 @@ -506,10 +596,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 @@ -517,10 +607,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 @@ -528,10 +618,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. @@ -539,82 +629,151 @@ public class T2Interpreter { private void _endchar() { endContour(); clearArg(); + while (_subrStackIndex > 0) { + SubrPair sp = popSubr(); + _cs = sp.cs; + _ip = sp.ip; + } } - + + /** + * Specifies one or more horizontal stem hints. This allows multiple pairs + * of numbers, limited by the stack depth, to be used as arguments to a + * single hstem operator. + */ private void _hstem() { + int pairCount = getArgCount() / 2; + for (int i = 0; i < pairCount; ++i) { + _hstems.add(0, popArg().intValue()); + _hstems.add(0, popArg().intValue()); + } - clearArg(); + if (getArgCount() > 0) { + + // This will be the width value + popArg(); + } } - + + /** + * Specifies one or more vertical stem hints between the x coordinates x + * and x+dx, where x is relative to the origin of the coordinate axes. + */ private void _vstem() { + int pairCount = getArgCount() / 2; + for (int i = 0; i < pairCount; ++i) { + _vstems.add(0, popArg().intValue()); + _vstems.add(0, popArg().intValue()); + } - clearArg(); + if (getArgCount() > 0) { + + // This will be the width value + popArg(); + } } - + + /** + * Has the same meaning as hstem, except that it must be used in place + * of hstem if the charstring contains one or more hintmask operators. + */ private void _hstemhm() { + _stemCount += getArgCount() / 2; + int pairCount = getArgCount() / 2; + for (int i = 0; i < pairCount; ++i) { + _hstems.add(0, popArg().intValue()); + _hstems.add(0, popArg().intValue()); + } - clearArg(); + if (getArgCount() > 0) { + + // This will be the width value + popArg(); + } } - + + /** + * Has the same meaning as vstem, except that it must be used in place + * of vstem if the charstring contains one or more hintmask operators. + */ private void _vstemhm() { + _stemCount += getArgCount() / 2; + int pairCount = getArgCount() / 2; + for (int i = 0; i < pairCount; ++i) { + _vstems.add(0, popArg().intValue()); + _vstems.add(0, popArg().intValue()); + } - clearArg(); + if (getArgCount() > 0) { + + // This will be the width value + popArg(); + } } - + + /** + * Specifies which hints are active and which are not active. + */ private void _hintmask() { - + _stemCount += getArgCount() / 2; + _ip += (_stemCount - 1) / 8 + 1; clearArg(); } - + + /** + * Specifies the counter spaces to be controlled, and their + * relative priority. + */ private void _cntrmask() { - + _stemCount += getArgCount() / 2; + _ip += (_stemCount - 1) / 8 + 1; clearArg(); } - + /** * Returns the absolute value of num. */ private void _abs() { - final double num = popArg().doubleValue(); + double num = popArg().doubleValue(); pushArg(Math.abs(num)); } - + /** * Returns the sum of the two numbers num1 and num2. */ private void _add() { - final double num2 = popArg().doubleValue(); - final double num1 = popArg().doubleValue(); + double num2 = popArg().doubleValue(); + double num1 = popArg().doubleValue(); pushArg(num1 + num2); } - + /** * Returns the result of subtracting num2 from num1. */ private void _sub() { - final double num2 = popArg().doubleValue(); - final double num1 = popArg().doubleValue(); + double num2 = popArg().doubleValue(); + 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() { - final double num2 = popArg().doubleValue(); - final double num1 = popArg().doubleValue(); + double num2 = popArg().doubleValue(); + double num1 = popArg().doubleValue(); pushArg(num1 / num2); } - + /** * Returns the negative of num. */ private void _neg() { - final double num = popArg().doubleValue(); + 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. @@ -622,43 +781,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() { - final double num2 = popArg().doubleValue(); - final double num1 = popArg().doubleValue(); + double num2 = popArg().doubleValue(); + double num1 = popArg().doubleValue(); pushArg(num1 * num2); } - + /** * Returns the square root of num. If num is negative, the result is * undefined. */ private void _sqrt() { - final double num = popArg().doubleValue(); + 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() { - final Number num2 = popArg(); - final Number num1 = popArg(); + Number num2 = popArg(); + 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, @@ -666,8 +825,8 @@ public class T2Interpreter { * undefined. */ private void _index() { - final int i = popArg().intValue(); - final Number[] nums = new Number[i]; + int i = popArg().intValue(); + Number[] nums = new Number[i]; for (int j = 0; j < i; ++j) { nums[j] = popArg(); } @@ -676,18 +835,18 @@ public class T2Interpreter { } pushArg(nums[i]); } - + /** - * Performs a circular shift of the elements num(Nx1) ... num0 on + * Performs a circular shift of the elements num(N-1) ... num0 on * the argument stack by the amount J. Positive J indicates upward * motion of the stack; negative J indicates downward motion. * The value N must be a non-negative integer, otherwise the * operation is undefined. */ private void _roll() { - final int j = popArg().intValue(); - final int n = popArg().intValue(); - final Number[] nums = new Number[n]; + int j = popArg().intValue(); + int n = popArg().intValue(); + Number[] nums = new Number[n]; for (int i = 0; i < n; ++i) { nums[i] = popArg(); } @@ -695,25 +854,25 @@ public class T2Interpreter { pushArg(nums[(n + i + j) % n]); } } - + /** * Duplicates the top element on the argument stack. */ private void _dup() { - final Number any = popArg(); + Number any = popArg(); pushArg(any); pushArg(any); } - + /** * Stores val into the transient array at the location given by i. */ private void _put() { - final int i = popArg().intValue(); - final Number val = popArg(); + int i = popArg().intValue(); + 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 @@ -721,61 +880,61 @@ public class T2Interpreter { * charstring, the value returned is undefined. */ private void _get() { - final int i = popArg().intValue(); + 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() { - final double num2 = popArg().doubleValue(); - final double num1 = popArg().doubleValue(); + double num2 = popArg().doubleValue(); + 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() { - final double num2 = popArg().doubleValue(); - final double num1 = popArg().doubleValue(); + double num2 = popArg().doubleValue(); + 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() { - final double num1 = popArg().doubleValue(); + 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() { - final double num2 = popArg().doubleValue(); - final double num1 = popArg().doubleValue(); + double num2 = popArg().doubleValue(); + 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() { - final double v2 = popArg().doubleValue(); - final double v1 = popArg().doubleValue(); - final Number s2 = popArg(); - final Number s1 = popArg(); + double v2 = popArg().doubleValue(); + double v1 = popArg().doubleValue(); + Number s2 = popArg(); + 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 @@ -787,35 +946,85 @@ public class T2Interpreter { * Calling an undefined subr (gsubr) has undefined results. */ private void _callsubr() { - + int bias; + int subrsCount = _localSubrIndex.getCount(); + if (subrsCount < 1240) { + bias = 107; + } else if (subrsCount < 33900) { + bias = 1131; + } else { + bias = 32768; + } + int i = popArg().intValue(); + int offset = _localSubrIndex.getOffset(i + bias) - 1; + pushSubr(new SubrPair(_cs, _ip)); + _cs = _localSubrs; + _ip = offset; } - + /** * Operates in the same manner as callsubr except that it calls a * global subroutine. */ private void _callgsubr() { - + int bias; + int subrsCount = _globalSubrIndex.getCount(); + if (subrsCount < 1240) { + bias = 107; + } else if (subrsCount < 33900) { + bias = 1131; + } else { + bias = 32768; + } + int i = popArg().intValue(); + int offset = _globalSubrIndex.getOffset(i + bias) - 1; + pushSubr(new SubrPair(_cs, _ip)); + _cs = _globalSubrs; + _ip = offset; } - + /** * Returns from either a local or global charstring subroutine, and * continues execution after the corresponding call(g)subr. */ private void _return() { - + SubrPair sp = popSubr(); + _cs = sp.cs; + _ip = sp.ip; } - - public Point[] execute(final CharstringType2 cs) { - _points = new ArrayList<Point>(); - cs.resetIP(); - while (cs.moreBytes()) { - while (cs.isOperandAtIndex()) { - pushArg(cs.nextOperand()); + + public Point[] execute(CharstringType2 cs) { + _localSubrIndex = cs.getFont().getLocalSubrIndex(); + _globalSubrIndex = cs.getFont().getTable().getGlobalSubrIndex(); + _localSubrs = new CharstringType2( + null, + 0, + "Local subrs", + _localSubrIndex.getData(), + _localSubrIndex.getOffset(0) - 1, + _localSubrIndex.getDataLength()); + _globalSubrs = new CharstringType2( + null, + 0, + "Global subrs", + _globalSubrIndex.getData(), + _globalSubrIndex.getOffset(0) - 1, + _globalSubrIndex.getDataLength()); + _cs = cs; + + _hstems = new ArrayList<>(); + _vstems = new ArrayList<>(); + + _points = new ArrayList<>(); + _ip = _cs.getFirstIndex(); + while (_cs.moreBytes(_ip)) { + while (_cs.isOperandAtIndex(_ip)) { + pushArg(_cs.operandAtIndex(_ip)); + _ip = _cs.nextOperandIndex(_ip); } - int operator = cs.nextByte(); + int operator = _cs.byteAtIndex(_ip++); if (operator == 12) { - operator = cs.nextByte(); + operator = _cs.byteAtIndex(_ip++); // Two-byte operators switch (operator) { @@ -974,7 +1183,7 @@ public class T2Interpreter { } } } - final Point[] pointArray = new Point[_points.size()]; + Point[] pointArray = new Point[_points.size()]; _points.toArray(pointArray); return pointArray; } @@ -985,68 +1194,81 @@ public class T2Interpreter { private int getArgCount() { return _argStackIndex; } - + /** * Pop a value off the argument stack */ private Number popArg() { + if (DEBUG) { + System.err.printf( + "T2I: popArg: %s %s%n", + _argStack[_argStackIndex - 1], + java.util.Arrays.copyOfRange(_argStack, 0, _argStackIndex - 1)); + } return _argStack[--_argStackIndex]; } /** * Push a value on to the argument stack */ - private void pushArg(final Number n) { + private void pushArg(Number n) { _argStack[_argStackIndex++] = n; + if (DEBUG) { + System.err.printf( + "T2I: pushArg: %s %s%n", + n, + java.util.Arrays.copyOfRange(_argStack, 0, _argStackIndex - 1)); + } } - + /** * Pop a value off the subroutine stack */ - private int popSubr() { + private SubrPair popSubr() { return _subrStack[--_subrStackIndex]; } /** * Push a value on to the subroutine stack */ - private void pushSubr(final int n) { - _subrStack[_subrStackIndex++] = n; + private void pushSubr(SubrPair sp) { + _subrStack[_subrStackIndex] = sp; + _subrStackIndex++; } - + /** * Clear the argument stack */ private void clearArg() { _argStackIndex = 0; } - + private Point getLastPoint() { - final int size = _points.size(); + int size = _points.size(); if (size > 0) { return _points.get(size - 1); } else { return new Point(0, 0, true, false); } } - - private void moveTo(final int x, final int y) { + + private void moveTo(int x, int y) { endContour(); _points.add(new Point(x, y, true, false)); } - - private void lineTo(final int x, final int y) { + + private void lineTo(int x, int y) { _points.add(new Point(x, y, true, false)); } - - private void curveTo(final int cx1, final int cy1, final int cx2, final int cy2, final int x, final int y) { + + private void curveTo(int cx1, int cy1, int cx2, int cy2, int x, 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() { - final Point lastPoint = getLastPoint(); + Point lastPoint = getLastPoint(); if (lastPoint != null) { lastPoint.endOfContour = true; } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/t2/T2Mnemonic.java b/src/jogl/classes/jogamp/graph/font/typecast/cff/T2Mnemonic.java index 6e7589cb4..5b888f409 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/t2/T2Mnemonic.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/cff/T2Mnemonic.java @@ -1,9 +1,7 @@ /* - * $Id: T2Mnemonic.java,v 1.1 2007-02-21 12:30:48 davidsch Exp $ - * * Typecast - The Font Development Environment * - * Copyright (c) 2004-2007 David Schweinsberg + * Copyright (c) 2004-2015 David Schweinsberg * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,14 +16,13 @@ * limitations under the License. */ -package jogamp.graph.font.typecast.t2; +package jogamp.graph.font.typecast.cff; /** * The Mnemonic representations of the Type 2 charstring instruction set. - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: T2Mnemonic.java,v 1.1 2007-02-21 12:30:48 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class T2Mnemonic { +class T2Mnemonic { /** * One byte operators diff --git a/src/jogl/classes/jogamp/graph/font/typecast/cff/TopDictIndex.java b/src/jogl/classes/jogamp/graph/font/typecast/cff/TopDictIndex.java new file mode 100644 index 000000000..4f6da45fc --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/cff/TopDictIndex.java @@ -0,0 +1,48 @@ +/* + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2015 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package jogamp.graph.font.typecast.cff; + +import java.io.DataInput; +import java.io.IOException; + +/** + * + * @author dschweinsberg + */ +public class TopDictIndex extends Index { + + public TopDictIndex(DataInput di) throws IOException { + super(di); + } + + public Dict getTopDict(int index) { + int offset = getOffset(index) - 1; + int len = getOffset(index + 1) - offset - 1; + return new Dict(getData(), offset, len); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < getCount(); ++i) { + sb.append(getTopDict(i).toString()).append("\n"); + } + return sb.toString(); + } + +} 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 181f77ee4..5bb8e934a 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/Disassembler.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/Disassembler.java @@ -1,16 +1,15 @@ /***************************************************************************** * 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; /** - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: Disassembler.java,v 1.1.1.1 2004-12-05 23:14:25 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class Disassembler { @@ -22,7 +21,7 @@ public class Disassembler { * @param ip The current instruction pointer * @return The new instruction pointer */ - public static int advanceIP(final short[] instructions, int ip) { + private static int advanceIP(short[] instructions, int ip) { // The high word specifies font, cvt, or glyph program int i = ip & 0xffff; @@ -46,8 +45,8 @@ public class Disassembler { return ip; } - public static short getPushCount(final short[] instructions, final int ip) { - final short instr = instructions[ip & 0xffff]; + private static short getPushCount(short[] instructions, int ip) { + 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 +55,11 @@ public class Disassembler { return 0; } - 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]; + private 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]; if (Mnemonic.NPUSHB == instr) { for (int j = 0; j < count; j++) { data[j] = instructions[i + j + 2]; @@ -81,8 +80,8 @@ public class Disassembler { return data; } - public static String disassemble(final short[] instructions, final int leadingSpaces) { - final StringBuilder sb = new StringBuilder(); + public static String disassemble(short[] instructions, int leadingSpaces) { + StringBuilder sb = new StringBuilder(); int ip = 0; while (ip < instructions.length) { for (int i = 0; i < leadingSpaces; i++) { @@ -91,13 +90,13 @@ public class Disassembler { sb.append(ip).append(": "); sb.append(Mnemonic.getMnemonic(instructions[ip])); if (getPushCount(instructions, ip) > 0) { - final int[] data = getPushData(instructions, ip); - for(int j = 0; j < data.length; j++) { + int[] data = getPushData(instructions, ip); + for (int datum : data) { if ((instructions[ip] == Mnemonic.PUSHW) || - (instructions[ip] == Mnemonic.NPUSHW)) { - sb.append(" ").append((short) data[j]); + (instructions[ip] == Mnemonic.NPUSHW)) { + sb.append(" ").append((short) datum); } else { - sb.append(" ").append(data[j]); + sb.append(" ").append(datum); } } } 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 14e83814c..94243cf21 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/Fixed.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/Fixed.java @@ -1,6 +1,4 @@ /* - * $Id: Fixed.java,v 1.1.1.1 2004-12-05 23:14:26 davidsch Exp $ - * * Typecast - The Font Development Environment * * Copyright (c) 2004 David Schweinsberg @@ -22,8 +20,7 @@ package jogamp.graph.font.typecast.ot; /** * Functions for working with signed 16.16 fixed values - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: Fixed.java,v 1.1.1.1 2004-12-05 23:14:26 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class Fixed { @@ -812,17 +809,17 @@ public class Fixed { * @param num Input * @return Output */ - public static int arctan( final int num ) { + public static int arctan( int num ) { return 0; } /** * 26.6 fixed number square root function. - * Simple (brain-dead) divide & conqure algorithm. + * Simple (brain-dead) divide & conquer algorithm. * @param num The 26.6 fixed number in question * @return The resulting square root */ - public static int squareRoot(final int num) { + public static int squareRoot(int num) { int n = num; int divisor = num; int nSquared; @@ -840,13 +837,13 @@ public class Fixed { } return n; } - - public static float floatValue(final long fixed) { + + public static float floatValue(long fixed) { return (fixed >> 16) + (float)(fixed & 0xffff) / 0x10000; } - - public static float roundedFloatValue(final long fixed, final int decimalPlaces) { - final int factor = 10 * decimalPlaces; + + public static float roundedFloatValue(long fixed, int decimalPlaces) { + int factor = 10 * decimalPlaces; return (float)((int)(floatValue(fixed) * factor)) / factor; } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/Glyph.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/Glyph.java new file mode 100644 index 000000000..7b29a6c48 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/Glyph.java @@ -0,0 +1,55 @@ +/* + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2015 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package jogamp.graph.font.typecast.ot; + +import com.jogamp.opengl.math.geom.AABBox; + +/** + * An individual glyph within a font. + * @author <a href="mailto:[email protected]">David Schweinsberg</a> + */ +public abstract class Glyph { + final int _glyph_id; + protected AABBox _bbox; + + public Glyph(final int glyph_id) { + _glyph_id = glyph_id; + } + + /** Return the assigned glyph ID of this instance */ + public final int getGlyphIndex() { return _glyph_id; } + + public abstract void clearPointData(); + + /** Return the AABBox in font-units */ + public final AABBox getBBox() { return _bbox; } + + /** hmtx value */ + public abstract int getAdvanceWidth(); + + /** hmtx value */ + public abstract short getLeftSideBearing(); + + public abstract Point getPoint(int i); + + public abstract int getPointCount(); + + @Override + public abstract String toString(); +} 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 6df892d4d..b5ba8e271 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/Mnemonic.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/Mnemonic.java @@ -1,17 +1,16 @@ /***************************************************************************** * 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; /** * The Mnemonic representations of the TrueType instruction set. - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: Mnemonic.java,v 1.1.1.1 2004-12-05 23:14:30 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class Mnemonic { @@ -72,9 +71,9 @@ public class Mnemonic { public static final short RS = 0x43; public static final short WCVTP = 0x44; public static final short RCVT = 0x45; - public static final short GC = 0x46; // [a] + public static final short GC = 0x46; // [a] public static final short SCFS = 0x48; - public static final short MD = 0x49; // [a] + public static final short MD = 0x49; // [a] public static final short MPPEM = 0x4B; public static final short MPS = 0x4C; public static final short FLIPON = 0x4D; @@ -143,7 +142,7 @@ public class Mnemonic { * @param opcode The opcode for which the mnemonic is required * @return The mnemonic, with a description */ - public static String getMnemonic(final short opcode) { + public static String getMnemonic(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 +268,7 @@ public class Mnemonic { else return "????"; } - public static String getComment(final short opcode) { + public static String getComment(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 344aeb1bb..9c7c0da0f 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/OTFont.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/OTFont.java @@ -1,62 +1,29 @@ /* - - ============================================================================ - 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 - - 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 <http://www.apache.org/>. - -*/ + * Typecast + * + * Copyright © 2004-2019 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package jogamp.graph.font.typecast.ot; +import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.IOException; import jogamp.graph.font.typecast.ot.table.CmapTable; -import jogamp.graph.font.typecast.ot.table.DirectoryEntry; -import jogamp.graph.font.typecast.ot.table.GlyfDescript; -import jogamp.graph.font.typecast.ot.table.GlyfTable; +import jogamp.graph.font.typecast.ot.table.GsubTable; import jogamp.graph.font.typecast.ot.table.HdmxTable; import jogamp.graph.font.typecast.ot.table.HeadTable; import jogamp.graph.font.typecast.ot.table.HheaTable; @@ -64,71 +31,70 @@ import jogamp.graph.font.typecast.ot.table.HmtxTable; import jogamp.graph.font.typecast.ot.table.KernTable; import jogamp.graph.font.typecast.ot.table.LocaTable; import jogamp.graph.font.typecast.ot.table.MaxpTable; +import jogamp.graph.font.typecast.ot.table.NameRecord; import jogamp.graph.font.typecast.ot.table.NameTable; import jogamp.graph.font.typecast.ot.table.Os2Table; import jogamp.graph.font.typecast.ot.table.PostTable; import jogamp.graph.font.typecast.ot.table.Table; import jogamp.graph.font.typecast.ot.table.TableDirectory; -import jogamp.graph.font.typecast.ot.table.TableFactory; import jogamp.graph.font.typecast.ot.table.VheaTable; /** * The TrueType font. - * @version $Id: OTFont.java,v 1.6 2007-01-31 01:49:18 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a>, Sven Gothel + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class OTFont { - - private final OTFontCollection _fc; - private TableDirectory _tableDirectory = null; - private Table[] _tables; - private Os2Table _os2; - private CmapTable _cmap; - private GlyfTable _glyf; - private HeadTable _head; - private HheaTable _hhea; - private HdmxTable _hdmx; - private HmtxTable _hmtx; - private LocaTable _loca; - private MaxpTable _maxp; - private NameTable _name; - private PostTable _post; - private VheaTable _vhea; - private KernTable _kern; - - /** - * Constructor - */ - public OTFont(final OTFontCollection fc) { - _fc = fc; - } - public StringBuilder getName(final int nameIndex, StringBuilder sb) { - if(null == sb) { - sb = new StringBuilder(); +public abstract class OTFont { + + private final Os2Table _os2; + private final CmapTable _cmap; + private final HeadTable _head; + private final HheaTable _hhea; + private final HmtxTable _hmtx; + private final MaxpTable _maxp; + private final NameTable _name; + private final PostTable _post; + private final VheaTable _vhea; + private final GsubTable _gsub; + + OTFont(final DataInputStream dis, TableDirectory tableDirectory, final int tablesOrigin) throws IOException { + // Load some prerequisite tables + // (These are tables that are referenced by other tables, so we need to load + // them first) + seekTable(tableDirectory, dis, tablesOrigin, Table.head); + _head = new HeadTable(dis); + + // 'hhea' is required by 'hmtx' + seekTable(tableDirectory, dis, tablesOrigin, Table.hhea); + _hhea = new HheaTable(dis); + + // 'maxp' is required by 'glyf', 'hmtx', 'loca', and 'vmtx' + seekTable(tableDirectory, dis, tablesOrigin, Table.maxp); + _maxp = new MaxpTable(dis); + + // 'vhea' is required by 'vmtx' + int length = seekTable(tableDirectory, dis, tablesOrigin, Table.vhea); + if (length > 0) { + _vhea = new VheaTable(dis); + } else { + _vhea = null; } - return _name.getRecordsRecordString(sb, nameIndex); - } - public StringBuilder getAllNames(StringBuilder sb, final String separator) { - if(null != _name) { - if(null == sb) { - sb = new StringBuilder(); - } - for(int i=0; i<_name.getNumberOfNameRecords(); i++) { - _name.getRecord(i).getRecordString(sb).append(separator); - } - } - return sb; - } + // 'post' is required by 'glyf' + seekTable(tableDirectory, dis, tablesOrigin, Table.post); + _post = new PostTable(dis); - 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]; - } - } - return null; + // Load all the other required tables + seekTable(tableDirectory, dis, tablesOrigin, Table.cmap); + _cmap = new CmapTable(dis); + length = seekTable(tableDirectory, dis, tablesOrigin, Table.hmtx); + _hmtx = new HmtxTable(dis, length, _hhea, _maxp); + length = seekTable(tableDirectory, dis, tablesOrigin, Table.name); + _name = new NameTable(dis, length); + seekTable(tableDirectory, dis, tablesOrigin, Table.OS_2); + _os2 = new Os2Table(dis); + + _gsub = null; // FIXME: delete? } public Os2Table getOS2Table() { @@ -147,18 +113,10 @@ public class OTFont { return _hhea; } - public HdmxTable getHdmxTable() { - return _hdmx; - } - public HmtxTable getHmtxTable() { return _hmtx; } - public LocaTable getLocaTable() { - return _loca; - } - public MaxpTable getMaxpTable() { return _maxp; } @@ -175,8 +133,8 @@ public class OTFont { return _vhea; } - public KernTable getKernTable() { - return _kern; + public GsubTable getGsubTable() { + return _gsub; } public int getAscent() { @@ -191,112 +149,43 @@ public class OTFont { return _maxp.getNumGlyphs(); } - public OTGlyph getGlyph(final 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; - } + public abstract Glyph getGlyph(int i); - private Table readTable( + int seekTable( + final TableDirectory tableDirectory, final DataInputStream dis, final int tablesOrigin, final int tag) throws IOException { dis.reset(); - final DirectoryEntry entry = _tableDirectory.getEntryByTag(tag); + final TableDirectory.Entry entry = tableDirectory.getEntryByTag(tag); if (entry == null) { - return null; + return 0; } dis.skip(tablesOrigin + entry.getOffset()); - return TableFactory.create(_fc, this, entry, dis); + return entry.getLength(); } - /** - * @param dis OpenType/TrueType font file data. - * @param directoryOffset The Table Directory offset within the file. For a - * regular TTF/OTF file this will be zero, but for a TTC (Font Collection) - * the offset is retrieved from the TTC header. For a Mac font resource, - * offset is retrieved from the resource headers. - * @param tablesOrigin The point the table offsets are calculated from. - * Once again, in a regular TTF file, this will be zero. In a TTC is is - * also zero, but within a Mac resource, it is the beggining of the - * individual font resource data. - */ - protected void read( - 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); - _maxp = (MaxpTable) readTable(dis, tablesOrigin, Table.maxp); - _loca = (LocaTable) readTable(dis, tablesOrigin, Table.loca); - _vhea = (VheaTable) readTable(dis, tablesOrigin, Table.vhea); - - int index = 0; - _tables[index++] = _head; - _tables[index++] = _hhea; - _tables[index++] = _maxp; - if (_loca != null) { - _tables[index++] = _loca; - } - if (_vhea != null) { - _tables[index++] = _vhea; - } + public String getName(final int nameIndex) { + return _name.getRecordsRecordString(nameIndex); + } - // Load all other tables - for (int i = 0; i < _tableDirectory.getNumTables(); i++) { - final DirectoryEntry entry = _tableDirectory.getEntry(i); - if (entry.getTag() == Table.head - || entry.getTag() == Table.hhea - || entry.getTag() == Table.maxp - || entry.getTag() == Table.loca - || entry.getTag() == Table.vhea) { - continue; + public StringBuilder getAllNames(StringBuilder sb, final String separator) { + if(null != _name) { + if(null == sb) { + sb = new StringBuilder(); + } + for(int i=0; i<_name.getNumberOfNameRecords(); i++) { + final NameRecord nr = _name.getRecord(i); + if( null != nr ) { + sb.append( nr.getRecordString() ).append(separator); + } } - dis.reset(); - dis.skip(tablesOrigin + entry.getOffset()); - _tables[index] = TableFactory.create(_fc, this, entry, dis); - ++index; } - - // 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); - _post = (PostTable) getTable(Table.post); - - // If this is a TrueType outline, then we'll have at least the - // 'glyf' table (along with the 'loca' table) - _glyf = (GlyfTable) getTable(Table.glyf); - - _kern = (KernTable) getTable(Table.kern); + return sb; } - + @Override public String toString() { - if (_tableDirectory != null) { - return _tableDirectory.toString(); - } else { - return "Empty font"; - } + return _head.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 ed07cb30a..269542019 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/OTFontCollection.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/OTFontCollection.java @@ -1,9 +1,7 @@ /* - * $Id: OTFontCollection.java,v 1.6 2010-08-10 11:38:11 davidsch Exp $ + * Typecast * - * Typecast - The Font Development Environment - * - * Copyright (c) 2004 David Schweinsberg + * Copyright © 2004-2019 David Schweinsberg * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,61 +18,31 @@ package jogamp.graph.font.typecast.ot; -import java.io.File; import java.io.BufferedInputStream; import java.io.DataInputStream; +import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; - -import java.util.ArrayList; - import jogamp.graph.font.typecast.ot.mac.ResourceHeader; import jogamp.graph.font.typecast.ot.mac.ResourceMap; import jogamp.graph.font.typecast.ot.mac.ResourceReference; import jogamp.graph.font.typecast.ot.mac.ResourceType; -import jogamp.graph.font.typecast.ot.table.DirectoryEntry; import jogamp.graph.font.typecast.ot.table.TTCHeader; -import jogamp.graph.font.typecast.ot.table.Table; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: OTFontCollection.java,v 1.6 2010-08-10 11:38:11 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class OTFontCollection { - + private final boolean DEBUG = false; + private TTCHeader _ttcHeader; + private TTFont[] _fonts; private String _pathName; private String _fileName; - private TTCHeader _ttcHeader; - private OTFont[] _fonts; - private final ArrayList<Table> _tables = new ArrayList<Table>(); private boolean _resourceFork = false; - /** Creates new FontCollection */ - protected OTFontCollection() { - } - - /** - * @param file The OpenType font file - */ - 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; } @@ -83,7 +51,7 @@ public class OTFontCollection { return _fileName; } - public OTFont getFont(final int i) { + public TTFont getFont(final int i) { return _fonts[i]; } @@ -95,19 +63,19 @@ public class OTFontCollection { return _ttcHeader; } - public Table getTable(final DirectoryEntry de) { - for (int i = 0; i < _tables.size(); i++) { - final Table table = _tables.get(i); - if ((table.getDirectoryEntry().getTag() == de.getTag()) && - (table.getDirectoryEntry().getOffset() == de.getOffset())) { - return table; - } - } - return null; + /** + * @param file The OpenType font file + */ + public OTFontCollection(final File file) throws IOException { + read(file); } - public void addTable(final Table table) { - _tables.add(table); + /** + * @param istream The OpenType font input stream + * @param streamLen the length of the OpenType font segment in the stream + */ + public OTFontCollection(final InputStream istream, final int streamLen) throws IOException { + read(istream, streamLen); } /** @@ -126,10 +94,11 @@ public class OTFontCollection { if (file.length() == 0) { file = new File(file, "..namedfork/rsrc"); if (!file.exists()) { - throw new IOException(); + throw new IOException("File <"+file.getName()+"> doesn't exist."); } _resourceFork = true; } + final int streamLen = (int) file.length(); final BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file), streamLen); try { @@ -164,6 +133,7 @@ public class OTFontCollection { } bis.mark(streamLen); final DataInputStream dis = new DataInputStream(bis); + if (_resourceFork || _pathName.endsWith(".dfont")) { // This is a Macintosh font suitcase resource @@ -174,17 +144,29 @@ public class OTFontCollection { dis.skip(resourceHeader.getMapOffset()); final ResourceMap map = new ResourceMap(dis); + if( DEBUG ) { + // Dump some info about the font suitcase + for (int i = 0; i < map.getResourceTypeCount(); ++i) { + System.err.println(map.getResourceType(i).getTypeAsString()); + } + + final ResourceType type = map.getResourceType("FOND"); + for (int i = 0; i < type.getCount(); ++i) { + final ResourceReference reference = type.getReference(i); + System.err.println(reference.getName()); + } + } + // Get the 'sfnt' resources final ResourceType resourceType = map.getResourceType("sfnt"); // Load the font data - _fonts = new OTFont[resourceType.getCount()]; + _fonts = new TTFont[resourceType.getCount()]; for (int i = 0; i < resourceType.getCount(); i++) { final ResourceReference resourceReference = resourceType.getReference(i); - _fonts[i] = new OTFont(this); final int offset = resourceHeader.getDataOffset() + - resourceReference.getDataOffset() + 4; - _fonts[i].read(dis, offset, offset); + resourceReference.getDataOffset() + 4; + _fonts[i] = TTFont.read(dis, offset, offset); } } else if (TTCHeader.isTTC(dis)) { @@ -192,17 +174,18 @@ public class OTFontCollection { // This is a TrueType font collection dis.reset(); _ttcHeader = new TTCHeader(dis); - _fonts = new OTFont[_ttcHeader.getDirectoryCount()]; + _fonts = new TTFont[_ttcHeader.getDirectoryCount()]; for (int i = 0; i < _ttcHeader.getDirectoryCount(); i++) { - _fonts[i] = new OTFont(this); - _fonts[i].read(dis, _ttcHeader.getTableDirectory(i), 0); + _fonts[i] = TTFont.read(dis, _ttcHeader.getTableDirectory(i), 0); } } else { // This is a standalone font file - _fonts = new OTFont[1]; - _fonts[0] = new OTFont(this); - _fonts[0].read(dis, 0, 0); + _fonts = new TTFont[1]; + _fonts[0] = TTFont.read(dis, 0, 0); + + // TODO T2Fonts } + 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 deleted file mode 100644 index 6ed5f8f3a..000000000 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/OTGlyph.java +++ /dev/null @@ -1,185 +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 - - 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 <http://www.apache.org/>. - -*/ - -package jogamp.graph.font.typecast.ot; - -import jogamp.graph.font.typecast.ot.table.Charstring; -import jogamp.graph.font.typecast.ot.table.CharstringType2; -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.opengl.math.geom.AABBox; - - - -/** - * An individual glyph within a font. - * @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 final class OTGlyph { - - private final int _glyphIndex; - private final short _leftSideBearing; - private final 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 (hmtx). - * @param advance The advance width (hmtx). - */ - public OTGlyph(final GlyphDescription gd, final short lsb, final int advance) { - _glyphIndex = gd.getGlyphIndex(); - _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(final int glyphID, final Charstring cs, final short lsb, final int advance) { - _glyphIndex = glyphID; - _leftSideBearing = lsb; - _advanceWidth = advance; - if (cs instanceof CharstringType2) { - final T2Interpreter t2i = new T2Interpreter(); - _points = t2i.execute((CharstringType2) cs); - } else { - //throw unsupported charstring type - } - } - - public int getGlyphIndex() { - return _glyphIndex; - } - - public final void clearPointData() { - _points = null; - } - - public final AABBox getBBox() { - return _bbox; - } - - /** hmtx value */ - public final int getAdvanceWidth() { - return _advanceWidth; - } - - /** hmtx value */ - public final short getLeftSideBearing() { - return _leftSideBearing; - } - - public final Point getPoint(final int i) { - return _points[i]; - } - - public final int getPointCount() { - return null != _points ? _points.length : 0; - } - - /** - * @param factor a 16.16 fixed value - 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; - _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 final void describe(final GlyphDescription gd) { - int endPtIndex = 0; - _points = new Point[gd.getPointCount() /* + 2 */ ]; - for (int i = 0; i < gd.getPointCount(); i++) { - final 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); - } - - @Override - public String toString() { - return new StringBuilder() - .append("OTGlyph id ").append(_glyphIndex).append(", points ").append(_points.length) - .append(", advance ").append(getAdvanceWidth()) - .append(", ").append(_bbox) - .toString(); - } -} 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 76b0f90f3..5f06ed1d6 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/Point.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/Point.java @@ -9,17 +9,17 @@ package jogamp.graph.font.typecast.ot; /** - * @version $Id: Point.java,v 1.1.1.1 2004-12-05 23:14:31 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class Point { - public int x = 0; - public int y = 0; - public boolean onCurve = true; - public boolean endOfContour = false; + public int x; + public int y; + public boolean onCurve; + public boolean endOfContour; + // public boolean touched = false; - public Point(final int x, final int y, final boolean onCurve, final boolean endOfContour) { + public Point(int x, int y, boolean onCurve, boolean endOfContour) { this.x = x; this.y = y; this.onCurve = onCurve; diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/T2Glyph.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/T2Glyph.java new file mode 100644 index 000000000..9df937121 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/T2Glyph.java @@ -0,0 +1,106 @@ +/* + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2016 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package jogamp.graph.font.typecast.ot; + +import com.jogamp.opengl.math.geom.AABBox; + +import jogamp.graph.font.typecast.cff.CharstringType2; +import jogamp.graph.font.typecast.cff.T2Interpreter; + +/** + * An individual Type 2 Charstring glyph within a font. + * @author <a href="mailto:[email protected]">David Schweinsberg</a> + */ +public class T2Glyph extends Glyph { + private final short _leftSideBearing; + private final int _advanceWidth; + private Point[] _points; + private Integer[] _hstems; + private Integer[] _vstems; + + /** + * Construct a Glyph from a PostScript outline described by a Charstring. + * @param glyph_id the assigned glyph_id of this instance + * @param cs The CharstringType2 describing the glyph. + * @param lsb The Left Side Bearing. + * @param advance The advance width. + */ + public T2Glyph( + final int glyph_id, + CharstringType2 cs, + short lsb, + int advance) { + super( glyph_id ); + _leftSideBearing = lsb; + _advanceWidth = advance; + T2Interpreter t2i = new T2Interpreter(); + _points = t2i.execute(cs); + _hstems = t2i.getHStems(); + _vstems = t2i.getVStems(); + { + AABBox bbox = new AABBox(); + for (Point p : _points) { + bbox.resize(p.x, p.y, 0); + } + _bbox = bbox; + } + } + + public final void clearPointData() { + _points = null; + _hstems = null; + _vstems = null; + } + + @Override + public int getAdvanceWidth() { + return _advanceWidth; + } + + @Override + public short getLeftSideBearing() { + return _leftSideBearing; + } + + @Override + public Point getPoint(int i) { + return _points[i]; + } + + @Override + public int getPointCount() { + return _points.length; + } + + public Integer[] getHStems() { + return _hstems; + } + + public Integer[] getVStems() { + return _vstems; + } + + @Override + public String toString() { + return new StringBuilder() + .append("T2Glyph id ").append(_glyph_id).append(", points ").append(_points.length) + .append(", advance ").append(getAdvanceWidth()) + .append(", ").append(_bbox) + .toString(); + } +} diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/TTFont.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/TTFont.java new file mode 100644 index 000000000..3e0de88ef --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/TTFont.java @@ -0,0 +1,117 @@ +/* + * Typecast + * + * Copyright © 2004-2019 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package jogamp.graph.font.typecast.ot; + +import jogamp.graph.font.typecast.ot.table.*; + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; + +public class TTFont extends OTFont { + + private final GlyfTable _glyf; + private GaspTable _gasp; + private KernTable _kern; + private HdmxTable _hdmx; + private VdmxTable _vdmx; + + /** + * Constructor method + * @param dis + * @param directoryOffset + * @param tablesOrigin + * @return + * @throws IOException + */ + public static TTFont read(final DataInputStream dis, final int directoryOffset, final int tablesOrigin) throws IOException { + // Load the table directory + dis.reset(); + dis.skip(directoryOffset); + final TableDirectory tableDirectory = new TableDirectory(dis); + return new TTFont(dis, tableDirectory, tablesOrigin); + } + + private TTFont(final DataInputStream dis, final TableDirectory tableDirectory, final int tablesOrigin) throws IOException { + super(dis, tableDirectory, tablesOrigin); + + // 'loca' is required by 'glyf' + int length = seekTable(tableDirectory, dis, tablesOrigin, Table.loca); + final LocaTable loca = new LocaTable(dis, length, this.getHeadTable(), this.getMaxpTable()); + + // If this is a TrueType outline, then we'll have at least the + // 'glyf' table (along with the 'loca' table) + length = seekTable(tableDirectory, dis, tablesOrigin, Table.glyf); + _glyf = new GlyfTable(dis, length, this.getMaxpTable(), loca); + + length = seekTable(tableDirectory, dis, tablesOrigin, Table.gasp); + if (length > 0) { + _gasp = new GaspTable(dis); + } + + length = seekTable(tableDirectory, dis, tablesOrigin, Table.kern); + if (length > 0) { + _kern = new KernTable(dis); + } + + length = seekTable(tableDirectory, dis, tablesOrigin, Table.hdmx); + if (length > 0) { + _hdmx = new HdmxTable(dis, length, this.getMaxpTable()); + } + + length = seekTable(tableDirectory, dis, tablesOrigin, Table.VDMX); + if (length > 0) { + _vdmx = new VdmxTable(dis); + } + } + + public GlyfTable getGlyfTable() { + return _glyf; + } + + public GaspTable getGaspTable() { + return _gasp; + } + + public KernTable getKernTable() { + return _kern; + } + + public HdmxTable getHdmxTable() { + return _hdmx; + } + + public VdmxTable getVdmxTable() { + return _vdmx; + } + + @Override + public Glyph getGlyph(final int i) { + final GlyfDescript glyfDescr = _glyf.getDescription(i); + if( null != glyfDescr ) { + return new TTGlyph( + glyfDescr, + getHmtxTable().getLeftSideBearing(i), + getHmtxTable().getAdvanceWidth(i)); + } else { + return null; + } + } + +} diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/TTGlyph.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/TTGlyph.java new file mode 100644 index 000000000..5e0f83a33 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/TTGlyph.java @@ -0,0 +1,127 @@ +/* + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2015 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package jogamp.graph.font.typecast.ot; + +import com.jogamp.opengl.math.geom.AABBox; + +import jogamp.graph.font.typecast.ot.table.GlyfDescript; +import jogamp.graph.font.typecast.ot.table.GlyphDescription; + +/** + * An individual TrueType glyph within a font. + * @author <a href="mailto:[email protected]">David Schweinsberg</a> + */ +public class TTGlyph extends Glyph { + + private short _leftSideBearing; + private int _advanceWidth; + private Point[] _points; + + /** + * Construct a Glyph from a TrueType outline described by + * a GlyphDescription. + * @param gd The glyph description of the glyph. + * @param lsb The Left Side Bearing. + * @param advance The advance width. + */ + public TTGlyph(GlyphDescription gd, short lsb, int advance) { + super( gd.getGlyphIndex() ); + _leftSideBearing = lsb; + _advanceWidth = advance; + describe(gd); + } + + public final void clearPointData() { + _points = null; + } + + @Override + public int getAdvanceWidth() { + return _advanceWidth; + } + + @Override + public short getLeftSideBearing() { + return _leftSideBearing; + } + + @Override + public Point getPoint(int i) { + return _points[i]; + } + + @Override + 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 (Point _point : _points) { + //points[i].x = ( points[i].x * factor ) >> 6; + //points[i].y = ( points[i].y * factor ) >> 6; + _point.x = ((_point.x << 10) * factor) >> 26; + _point.y = ((_point.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; + int pointCount = gd != null ? gd.getPointCount() : 0; + _points = new Point[pointCount /* + 2 */]; + for (int i = 0; i < pointCount; 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[pointCount] = new Point(0, 0, true, true); + // _points[pointCount+1] = new Point(_advanceWidth, 0, true, true); + + _bbox = new AABBox(gd.getXMinimum(), gd.getYMinimum(), 0, gd.getXMaximum(), gd.getYMaximum(), 0); + } + + @Override + public String toString() { + return new StringBuilder() + .append("TTGlyph id ").append(_glyph_id).append(", points ").append(_points.length) + .append(", advance ").append(getAdvanceWidth()) + .append(", ").append(_bbox) + .toString(); + } +} 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 709ff9e91..80cf920ee 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 @@ -1,6 +1,4 @@ /* - * $Id: ResourceData.java,v 1.1.1.1 2004-12-05 23:14:31 davidsch Exp $ - * * Typecast - The Font Development Environment * * Copyright (c) 2004 David Schweinsberg @@ -25,16 +23,15 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ResourceData.java,v 1.1.1.1 2004-12-05 23:14:31 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class ResourceData { - - private final byte[] data; +class ResourceData { + private byte[] data; + /** Creates new ResourceData */ - public ResourceData(final DataInput di) throws IOException { - final int dataLen = di.readInt(); + public ResourceData(DataInput di) throws IOException { + 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 767eafb6b..480d116d2 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 @@ -1,6 +1,4 @@ /* - * $Id: ResourceFile.java,v 1.2 2007-01-29 04:01:53 davidsch Exp $ - * * Typecast - The Font Development Environment * * Copyright (c) 2004 David Schweinsberg @@ -26,51 +24,50 @@ import java.io.RandomAccessFile; /** * Mac resource loading test. * TODO: incorporate this into the test suite. - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ResourceFile.java,v 1.2 2007-01-29 04:01:53 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class ResourceFile { - - private final ResourceHeader header; - private final ResourceMap map; +class ResourceFile { + private ResourceHeader header; + private ResourceMap map; + /** Creates new Resource */ - public ResourceFile(final RandomAccessFile raf) throws IOException { + private ResourceFile(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); } - public ResourceMap getResourceMap() { + private ResourceMap getResourceMap() { return map; } - public static void main(final String[] args) { + public static void main(String[] args) { try { //RandomAccessFile raf = new RandomAccessFile("/Library/Fonts/GillSans.dfont", "r"); - + // Tests loading a font from a resource fork on Mac OS X - final RandomAccessFile raf = new RandomAccessFile("/Library/Fonts/Georgia/..namedfork/rsrc", "r"); - final ResourceFile resource = new ResourceFile(raf); + RandomAccessFile raf = new RandomAccessFile("/Library/Fonts/Georgia/..namedfork/rsrc", "r"); + 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 (final Exception e) { + } catch (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 dea0b9843..21046ce1e 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 @@ -1,6 +1,4 @@ /* - * $Id: ResourceHeader.java,v 1.1.1.1 2004-12-05 23:14:32 davidsch Exp $ - * * Typecast - The Font Development Environment * * Copyright (c) 2004 David Schweinsberg @@ -25,18 +23,17 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ResourceHeader.java,v 1.1.1.1 2004-12-05 23:14:32 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class ResourceHeader { - private final int dataOffset; - private final int mapOffset; - private final int dataLen; - private final int mapLen; + private int dataOffset; + private int mapOffset; + private int dataLen; + private int mapLen; /** Creates new ResourceHeader */ - public ResourceHeader(final DataInput di) throws IOException { + public ResourceHeader(DataInput di) throws IOException { dataOffset = di.readInt(); mapOffset = di.readInt(); dataLen = di.readInt(); @@ -46,15 +43,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 781e0adf3..e792c4e25 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 @@ -1,6 +1,4 @@ /* - * $Id: ResourceMap.java,v 1.1.1.1 2004-12-05 23:14:32 davidsch Exp $ - * * Typecast - The Font Development Environment * * Copyright (c) 2004 David Schweinsberg @@ -25,57 +23,61 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ResourceMap.java,v 1.1.1.1 2004-12-05 23:14:32 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class ResourceMap { private final byte[] headerCopy = new byte[16]; - // private final int nextResourceMap; - // private final int fileReferenceNumber; - // private final int attributes; - private final ResourceType[] types; - + @SuppressWarnings("unused") + private int nextResourceMap; + @SuppressWarnings("unused") + private int fileReferenceNumber; + @SuppressWarnings("unused") + private int attributes; + private ResourceType[] types; + /** Creates new ResourceMap */ - public ResourceMap(final DataInput di) throws IOException { + @SuppressWarnings("unused") + public ResourceMap(DataInput di) throws IOException { di.readFully(headerCopy); - /* 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; - + nextResourceMap = di.readInt(); + fileReferenceNumber = di.readUnsignedShort(); + attributes = di.readUnsignedShort(); + int typeOffset = di.readUnsignedShort(); + int nameOffset = di.readUnsignedShort(); + 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(final String typeName) { - for (int i = 0; i < types.length; i++) { - if (types[i].getTypeAsString().equals(typeName)) { - return types[i]; + public ResourceType getResourceType(String typeName) { + for (ResourceType type : types) { + String s = type.getTypeAsString(); + if (type.getTypeAsString().equals(typeName)) { + return type; } } return null; } - public ResourceType getResourceType(final int i) { + public ResourceType getResourceType(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 f76b85cf4..5f3bc8f93 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 @@ -1,6 +1,4 @@ /* - * $Id: ResourceReference.java,v 1.1.1.1 2004-12-05 23:14:32 davidsch Exp $ - * * Typecast - The Font Development Environment * * Copyright (c) 2004 David Schweinsberg @@ -25,20 +23,19 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ResourceReference.java,v 1.1.1.1 2004-12-05 23:14:32 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class ResourceReference { - private final int id; - private final short nameOffset; - private final short attributes; - private final int dataOffset; - private final int handle; + private int id; + private short nameOffset; + private short attributes; + private int dataOffset; + private int handle; private String name; - + /** Creates new ResourceReference */ - protected ResourceReference(final DataInput di) throws IOException { + ResourceReference(DataInput di) throws IOException { id = di.readUnsignedShort(); nameOffset = di.readShort(); attributes = (short) di.readUnsignedByte(); @@ -46,10 +43,10 @@ public class ResourceReference { handle = di.readInt(); } - protected void readName(final DataInput di) throws IOException { + void readName(DataInput di) throws IOException { if (nameOffset > -1) { - final int len = di.readUnsignedByte(); - final byte[] buf = new byte[len]; + int len = di.readUnsignedByte(); + byte[] buf = new byte[len]; di.readFully(buf); name = new String(buf); } @@ -58,23 +55,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 903fe1a48..2ff274484 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 @@ -1,6 +1,4 @@ /* - * $Id: ResourceType.java,v 1.1.1.1 2004-12-05 23:14:33 davidsch Exp $ - * * Typecast - The Font Development Environment * * Copyright (c) 2004 David Schweinsberg @@ -25,31 +23,30 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ResourceType.java,v 1.1.1.1 2004-12-05 23:14:33 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class ResourceType { - private final int type; - private final int count; - private final int offset; - private final ResourceReference[] references; - + private int type; + private int count; + private int offset; + private ResourceReference[] references; + /** Creates new ResourceType */ - protected ResourceType(final DataInput di) throws IOException { + ResourceType(DataInput di) throws IOException { type = di.readInt(); count = di.readUnsignedShort() + 1; offset = di.readUnsignedShort(); references = new ResourceReference[count]; } - - protected void readRefs(final DataInput di) throws IOException { + + void readRefs(DataInput di) throws IOException { for (int i = 0; i < count; i++) { references[i] = new ResourceReference(di); } } - protected void readNames(final DataInput di) throws IOException { + void readNames(DataInput di) throws IOException { for (int i = 0; i < count; i++) { references[i].readName(di); } @@ -58,25 +55,23 @@ public class ResourceType { public int getType() { return type; } - + public String getTypeAsString() { - return new StringBuilder() - .append((char)((type>>24)&0xff)) - .append((char)((type>>16)&0xff)) - .append((char)((type>>8)&0xff)) - .append((char)((type)&0xff)) - .toString(); + return String.valueOf((char) ((type >> 24) & 0xff)) + + (char) ((type >> 16) & 0xff) + + (char) ((type >> 8) & 0xff) + + (char) ((type) & 0xff); } - + public int getCount() { return count; } - + public int getOffset() { return offset; } - public ResourceReference getReference(final int i) { + public ResourceReference getReference(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 002f83e9b..51f64494d 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 @@ -1,6 +1,4 @@ /* - * $Id: BaseTable.java,v 1.3 2007-02-08 04:31:31 davidsch Exp $ - * * Typecast - The Font Development Environment * * Copyright (c) 2004-2007 David Schweinsberg @@ -27,108 +25,101 @@ import java.io.IOException; /** * Baseline Table - * @version $Id: BaseTable.java,v 1.3 2007-02-08 04:31:31 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class BaseTable implements Table { + + private abstract static class BaseCoord { - abstract class BaseCoord { - - abstract int getBaseCoordFormat(); - - abstract short getCoordinate(); + public abstract int getBaseCoordFormat(); + + public abstract short getCoordinate(); } + + private static class BaseCoordFormat1 extends BaseCoord { - class BaseCoordFormat1 extends BaseCoord { - - private final short _coordinate; - - protected BaseCoordFormat1(final DataInput di) throws IOException { + private short _coordinate; + + BaseCoordFormat1(DataInput di) throws IOException { _coordinate = di.readShort(); } - @Override - int getBaseCoordFormat() { + public int getBaseCoordFormat() { return 1; } - - @Override - short getCoordinate() { + + public short getCoordinate() { return _coordinate; } - + } - - class BaseCoordFormat2 extends BaseCoord { - - private final short _coordinate; - // private final int _referenceGlyph; - // private final int _baseCoordPoint; - - protected BaseCoordFormat2(final DataInput di) throws IOException { + + private static class BaseCoordFormat2 extends BaseCoord { + + private short _coordinate; + private int _referenceGlyph; + private int _baseCoordPoint; + + BaseCoordFormat2(DataInput di) throws IOException { _coordinate = di.readShort(); - /* _referenceGlyph = */ di.readUnsignedShort(); - /* _baseCoordPoint = */ di.readUnsignedShort(); + _referenceGlyph = di.readUnsignedShort(); + _baseCoordPoint = di.readUnsignedShort(); } - @Override - int getBaseCoordFormat() { + public int getBaseCoordFormat() { return 2; } - - @Override - short getCoordinate() { + + public short getCoordinate() { return _coordinate; } - + } + + private static class BaseCoordFormat3 extends BaseCoord { - class BaseCoordFormat3 extends BaseCoord { - - private final short _coordinate; - // private final int _deviceTableOffset; - - protected BaseCoordFormat3(final DataInput di) throws IOException { + private short _coordinate; + private int _deviceTableOffset; + + BaseCoordFormat3(DataInput di) throws IOException { _coordinate = di.readShort(); - /* _deviceTableOffset = */ di.readUnsignedShort(); + _deviceTableOffset = di.readUnsignedShort(); } - @Override - int getBaseCoordFormat() { + public int getBaseCoordFormat() { return 2; } - - @Override - short getCoordinate() { + + public short getCoordinate() { return _coordinate; } - + } - - 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 static class FeatMinMaxRecord { + + private int _tag; + private int _minCoordOffset; + private int _maxCoordOffset; + + FeatMinMaxRecord(DataInput di) throws IOException { + _tag = di.readInt(); + _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(); + + private class MinMax { + + private int _minCoordOffset; + private int _maxCoordOffset; + private int _featMinMaxCount; + private FeatMinMaxRecord[] _featMinMaxRecord; + + MinMax(int minMaxOffset) throws IOException { + DataInput di = getDataInputForOffset(minMaxOffset); + _minCoordOffset = di.readUnsignedShort(); + _maxCoordOffset = di.readUnsignedShort(); _featMinMaxCount = di.readUnsignedShort(); _featMinMaxRecord = new FeatMinMaxRecord[_featMinMaxCount]; for (int i = 0; i < _featMinMaxCount; ++i) { @@ -136,17 +127,17 @@ public class BaseTable implements Table { } } } - - 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(); + + private class BaseValues { + + private int _defaultIndex; + private int _baseCoordCount; + private int[] _baseCoordOffset; + private BaseCoord[] _baseCoords; + + BaseValues(int baseValuesOffset) throws IOException { + DataInput di = getDataInputForOffset(baseValuesOffset); + _defaultIndex = di.readUnsignedShort(); _baseCoordCount = di.readUnsignedShort(); _baseCoordOffset = new int[_baseCoordCount]; for (int i = 0; i < _baseCoordCount; ++i) { @@ -154,7 +145,7 @@ public class BaseTable implements Table { } _baseCoords = new BaseCoord[_baseCoordCount]; for (int i = 0; i < _baseCoordCount; ++i) { - final int format = di.readUnsignedShort(); + int format = di.readUnsignedShort(); switch (format) { case 1: _baseCoords[i] = new BaseCoordFormat1(di); @@ -169,40 +160,39 @@ public class BaseTable implements Table { } } } - - static class BaseLangSysRecord { - - // private final int _baseLangSysTag; - private final int _minMaxOffset; - - protected BaseLangSysRecord(final DataInput di) throws IOException { - /* _baseLangSysTag = */ di.readInt(); + + private static class BaseLangSysRecord { + + private int _baseLangSysTag; + private int _minMaxOffset; + + BaseLangSysRecord(DataInput di) throws IOException { + _baseLangSysTag = di.readInt(); _minMaxOffset = di.readUnsignedShort(); } - /** - int getBaseLangSysTag() { + public int getBaseLangSysTag() { return _baseLangSysTag; - } */ - + } + int getMinMaxOffset() { return _minMaxOffset; } } - - class BaseScript { - + + private class BaseScript { + private final int _thisOffset; - private final int _baseValuesOffset; - private final int _defaultMinMaxOffset; - private final int _baseLangSysCount; - private final BaseLangSysRecord[] _baseLangSysRecord; + private int _baseValuesOffset; + private int _defaultMinMaxOffset; + private int _baseLangSysCount; + private BaseLangSysRecord[] _baseLangSysRecord; private BaseValues _baseValues; private MinMax[] _minMax; - - protected BaseScript(final int baseScriptOffset) throws IOException { + + BaseScript(int baseScriptOffset) throws IOException { _thisOffset = baseScriptOffset; - final DataInput di = getDataInputForOffset(baseScriptOffset); + DataInput di = getDataInputForOffset(baseScriptOffset); _baseValuesOffset = di.readUnsignedShort(); _defaultMinMaxOffset = di.readUnsignedShort(); _baseLangSysCount = di.readUnsignedShort(); @@ -218,9 +208,8 @@ public class BaseTable implements Table { } } - @Override public String toString() { - final StringBuilder sb = new StringBuilder() + 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)) @@ -239,13 +228,13 @@ public class BaseTable implements Table { return sb.toString(); } } + + private static class BaseScriptRecord { + + private int _baseScriptTag; + private int _baseScriptOffset; - static class BaseScriptRecord { - - private final int _baseScriptTag; - private final int _baseScriptOffset; - - protected BaseScriptRecord(final DataInput di) throws IOException { + BaseScriptRecord(DataInput di) throws IOException { _baseScriptTag = di.readInt(); _baseScriptOffset = di.readUnsignedShort(); } @@ -253,22 +242,22 @@ public class BaseTable implements Table { int getBaseScriptTag() { return _baseScriptTag; } - + int getBaseScriptOffset() { return _baseScriptOffset; } } - - class BaseScriptList { - + + private 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 { + private int _baseScriptCount; + private BaseScriptRecord[] _baseScriptRecord; + private BaseScript[] _baseScripts; + + BaseScriptList(int baseScriptListOffset) throws IOException { _thisOffset = baseScriptListOffset; - final DataInput di = getDataInputForOffset(baseScriptListOffset); + DataInput di = getDataInputForOffset(baseScriptListOffset); _baseScriptCount = di.readUnsignedShort(); _baseScriptRecord = new BaseScriptRecord[_baseScriptCount]; for (int i = 0; i < _baseScriptCount; ++i) { @@ -281,9 +270,8 @@ public class BaseTable implements Table { } } - @Override public String toString() { - final StringBuilder sb = new StringBuilder() + StringBuilder sb = new StringBuilder() .append("\nBaseScriptList BaseScriptListT").append(Integer.toHexString(_thisOffset)) .append("\n").append(Integer.toHexString(_baseScriptCount)); for (int i = 0; i < _baseScriptCount; ++i) { @@ -297,16 +285,16 @@ public class BaseTable implements Table { return sb.toString(); } } - - class BaseTagList { - + + private class BaseTagList { + private final int _thisOffset; - private final int _baseTagCount; - private final int[] _baselineTag; - - protected BaseTagList(final int baseTagListOffset) throws IOException { + private int _baseTagCount; + private int[] _baselineTag; + + BaseTagList(int baseTagListOffset) throws IOException { _thisOffset = baseTagListOffset; - final DataInput di = getDataInputForOffset(baseTagListOffset); + DataInput di = getDataInputForOffset(baseTagListOffset); _baseTagCount = di.readUnsignedShort(); _baselineTag = new int[_baseTagCount]; for (int i = 0; i < _baseTagCount; ++i) { @@ -314,9 +302,8 @@ public class BaseTable implements Table { } } - @Override public String toString() { - final StringBuilder sb = new StringBuilder() + StringBuilder sb = new StringBuilder() .append("\nBaseTagList BaseTagListT").append(Integer.toHexString(_thisOffset)) .append("\n").append(Integer.toHexString(_baseTagCount)); for (int i = 0; i < _baseTagCount; ++i) { @@ -325,18 +312,18 @@ public class BaseTable implements Table { return sb.toString(); } } - - class Axis { - + + private class Axis { + private final int _thisOffset; - private final int _baseTagListOffset; - private final int _baseScriptListOffset; + private int _baseTagListOffset; + private int _baseScriptListOffset; private BaseTagList _baseTagList; private BaseScriptList _baseScriptList; - protected Axis(final int axisOffset) throws IOException { + Axis(int axisOffset) throws IOException { _thisOffset = axisOffset; - final DataInput di = getDataInputForOffset(axisOffset); + DataInput di = getDataInputForOffset(axisOffset); _baseTagListOffset = di.readUnsignedShort(); _baseScriptListOffset = di.readUnsignedShort(); if (_baseTagListOffset != 0) { @@ -348,34 +335,29 @@ public class BaseTable implements Table { } } - @Override public String toString() { - return new StringBuilder() - .append("\nAxis AxisT").append(Integer.toHexString(_thisOffset)) - .append("\nBaseTagListT").append(Integer.toHexString(_thisOffset + _baseTagListOffset)) - .append("\nBaseScriptListT").append(Integer.toHexString(_thisOffset + _baseScriptListOffset)) - .append("\n").append(_baseTagList) - .append("\n").append(_baseScriptList) - .toString(); + return "\nAxis AxisT" + Integer.toHexString(_thisOffset) + + "\nBaseTagListT" + Integer.toHexString(_thisOffset + _baseTagListOffset) + + "\nBaseScriptListT" + Integer.toHexString(_thisOffset + _baseScriptListOffset) + + "\n" + _baseTagList + + "\n" + _baseScriptList; } } - - private final DirectoryEntry _de; - private final int _version; - private final int _horizAxisOffset; - private final int _vertAxisOffset; + + private int _version; + private int _horizAxisOffset; + private int _vertAxisOffset; private Axis _horizAxis; private Axis _vertAxis; private byte[] _buf; /** Creates a new instance of BaseTable */ - protected BaseTable(final DirectoryEntry de, final DataInput di) throws IOException { - _de = (DirectoryEntry) de.clone(); + protected BaseTable(DataInput di, int length) throws IOException { // Load entire table into a buffer, and create another input stream - _buf = new byte[de.getLength()]; + _buf = new byte[length]; di.readFully(_buf); - final DataInput di2 = getDataInputForOffset(0); + DataInput di2 = getDataInputForOffset(0); _version = di2.readInt(); _horizAxisOffset = di2.readUnsignedShort(); @@ -386,42 +368,36 @@ public class BaseTable implements Table { if (_vertAxisOffset != 0) { _vertAxis = new Axis(_vertAxisOffset); } - + // Let go of the buffer _buf = null; } - - private DataInput getDataInputForOffset(final int offset) { + + private DataInput getDataInputForOffset(int offset) { return new DataInputStream(new ByteArrayInputStream( _buf, offset, - _de.getLength() - offset)); + _buf.length - 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(final int tag) { - final char[] c = new char[4]; + + private static String tagAsString(int tag) { + 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() { - final StringBuilder sb = new StringBuilder() + StringBuilder sb = new StringBuilder() .append("; 'BASE' Table - Baseline\n;-------------------------------------\n\n") .append("BASEHeader BASEHeaderT").append(Integer.toHexString(0)) .append("\n").append(Integer.toHexString(_version)) @@ -436,14 +412,4 @@ 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 d6643f26d..5bb14c73d 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 @@ -1,9 +1,7 @@ /* - * $Id: CffTable.java,v 1.4 2007-07-26 11:15:06 davidsch Exp $ - * * Typecast - The Font Development Environment * - * Copyright (c) 2004-2007 David Schweinsberg + * Copyright (c) 2004-2015 David Schweinsberg * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,464 +22,18 @@ import java.io.ByteArrayInputStream; import java.io.DataInput; import java.io.DataInputStream; import java.io.IOException; - -import java.util.ArrayList; -import java.util.Dictionary; -import java.util.Enumeration; -import java.util.Hashtable; +import jogamp.graph.font.typecast.cff.CffFont; +import jogamp.graph.font.typecast.cff.Index; +import jogamp.graph.font.typecast.cff.NameIndex; +import jogamp.graph.font.typecast.cff.StringIndex; +import jogamp.graph.font.typecast.cff.TopDictIndex; /** * Compact Font Format Table - * @version $Id: CffTable.java,v 1.4 2007-07-26 11:15:06 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class CffTable implements Table { - - public static class Dict { - - private final Dictionary<Integer, Object> _entries = new Hashtable<Integer, Object>(); - private final int[] _data; - private int _index; - - protected Dict(final int[] data, final int offset, final int length) { - _data = data; - _index = offset; - while (_index < offset + length) { - addKeyAndValueEntry(); - } - } - - public Object getValue(final int key) { - return _entries.get(key); - } - - private boolean addKeyAndValueEntry() { - final ArrayList<Object> operands = new ArrayList<Object>(); - Object operand = null; - while (isOperandAtIndex()) { - operand = nextOperand(); - operands.add(operand); - } - int operator = _data[_index++]; - if (operator == 12) { - operator <<= 8; - operator |= _data[_index++]; - } - if (operands.size() == 1) { - _entries.put(operator, operand); - } else { - _entries.put(operator, operands); - } - return true; - } - - private boolean isOperandAtIndex() { - final int b0 = _data[_index]; - if ((32 <= b0 && b0 <= 254) - || b0 == 28 - || b0 == 29 - || b0 == 30) { - return true; - } - return false; - } - - private boolean isOperatorAtIndex() { - final int b0 = _data[_index]; - if (0 <= b0 && b0 <= 21) { - return true; - } - return false; - } - - private Object nextOperand() { - final int b0 = _data[_index]; - if (32 <= b0 && b0 <= 246) { - - // 1 byte integer - ++_index; - return Integer.valueOf(b0 - 139); - } else if (247 <= b0 && b0 <= 250) { - - // 2 byte integer - final int b1 = _data[_index + 1]; - _index += 2; - return Integer.valueOf((b0 - 247) * 256 + b1 + 108); - } else if (251 <= b0 && b0 <= 254) { - - // 2 byte integer - final int b1 = _data[_index + 1]; - _index += 2; - return Integer.valueOf(-(b0 - 251) * 256 - b1 - 108); - } else if (b0 == 28) { - - // 3 byte integer - final int b1 = _data[_index + 1]; - final int b2 = _data[_index + 2]; - _index += 3; - return Integer.valueOf(b1 << 8 | b2); - } else if (b0 == 29) { - - // 5 byte integer - 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 Integer.valueOf(b1 << 24 | b2 << 16 | b3 << 8 | b4); - } else if (b0 == 30) { - - // Real number - final StringBuilder fString = new StringBuilder(); - int nibble1 = 0; - int nibble2 = 0; - ++_index; - while ((nibble1 != 0xf) && (nibble2 != 0xf)) { - nibble1 = _data[_index] >> 4; - nibble2 = _data[_index] & 0xf; - ++_index; - fString.append(decodeRealNibble(nibble1)); - fString.append(decodeRealNibble(nibble2)); - } - return Float.valueOf(fString.toString()); - } else { - return null; - } - } - - private String decodeRealNibble(final int nibble) { - if (nibble < 0xa) { - return Integer.toString(nibble); - } else if (nibble == 0xa) { - return "."; - } else if (nibble == 0xb) { - return "E"; - } else if (nibble == 0xc) { - return "E-"; - } else if (nibble == 0xe) { - return "-"; - } - return ""; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - final Enumeration<Integer> keys = _entries.keys(); - while (keys.hasMoreElements()) { - final Integer key = keys.nextElement(); - if ((key.intValue() & 0xc00) == 0xc00) { - sb.append("12 ").append(key.intValue() & 0xff).append(": "); - } else { - sb.append(key.toString()).append(": "); - } - sb.append(_entries.get(key).toString()).append("\n"); - } - return sb.toString(); - } - } - - public class Index { - - 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(); - for (int i = 0; i < _count + 1; ++i) { - int thisOffset = 0; - for (int j = 0; j < _offSize; ++j) { - thisOffset |= di.readUnsignedByte() << ((_offSize - j - 1) * 8); - } - _offset[i] = thisOffset; - } - _data = new int[getDataLength()]; - for (int i = 0; i < getDataLength(); ++i) { - _data[i] = di.readUnsignedByte(); - } - } - - public int getCount() { - return _count; - } - - 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() { - final StringBuilder sb = new StringBuilder(); - sb.append("DICT\n"); - sb.append("count: ").append(_count).append("\n"); - sb.append("offSize: ").append(_offSize).append("\n"); - for (int i = 0; i < _count + 1; ++i) { - sb.append("offset[").append(i).append("]: ").append(_offset[i]).append("\n"); - } - sb.append("data:"); - for (int i = 0; i < _data.length; ++i) { - if (i % 8 == 0) { - sb.append("\n"); - } else { - sb.append(" "); - } - sb.append(_data[i]); - } - sb.append("\n"); - return sb.toString(); - } - } - - public class TopDictIndex extends Index { - - protected TopDictIndex(final DataInput di) throws IOException { - super(di); - } - - 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() { - 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(final DataInput di) throws IOException { - super(di); - } - - public String getName(final int index) { - String name = null; - 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) { - final StringBuilder sb = new StringBuilder(); - for (int i = offset; i < offset + len; ++i) { - sb.append((char) getData()[i]); - } - name = sb.toString(); - } else { - name = "DELETED NAME"; - } - return name; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - for (int i = 0; i < getCount(); ++i) { - sb.append(getName(i)).append("\n"); - } - return sb.toString(); - } - } - - public class StringIndex extends Index { - - protected StringIndex(final DataInput di) throws IOException { - super(di); - } - - public String getString(int index) { - if (index < CffStandardStrings.standardStrings.length) { - return CffStandardStrings.standardStrings[index]; - } else { - index -= CffStandardStrings.standardStrings.length; - if (index >= getCount()) { - return null; - } - final int offset = getOffset(index) - 1; - final int len = getOffset(index + 1) - offset - 1; - - 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() { - 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"); - } - return sb.toString(); - } - } - - private class CharsetRange { - - private int _first; - private int _left; - - public int getFirst() { - return _first; - } - - protected void setFirst(final int first) { - _first = first; - } - - public int getLeft() { - return _left; - } - - protected void setLeft(final int left) { - _left = left; - } - } - - private class CharsetRange1 extends CharsetRange { - - protected CharsetRange1(final DataInput di) throws IOException { - setFirst(di.readUnsignedShort()); - setLeft(di.readUnsignedByte()); - } - } - - private class CharsetRange2 extends CharsetRange { - - 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 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; - } - - @Override - public int getSID(final int gid) { - if (gid == 0) { - return 0; - } - return _glyph[gid - 1]; - } - } - - private class CharsetFormat1 extends Charset { - - 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) { - final CharsetRange range = new CharsetRange1(di); - _charsetRanges.add(range); - glyphsCovered -= range.getLeft() + 1; - } - } - - @Override - public int getFormat() { - return 1; - } - - @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 (final CharsetRange range : _charsetRanges) { - count += range.getLeft(); - if (gid < count) { - final int sid = gid - count + range.getFirst(); - return sid; - } - } - return 0; - } - } - - private class CharsetFormat2 extends Charset { - - 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) { - final CharsetRange range = new CharsetRange2(di); - _charsetRanges.add(range); - glyphsCovered -= range.getLeft() + 1; - } - } - - @Override - public int getFormat() { - return 2; - } - - @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 (final CharsetRange range : _charsetRanges) { - if (gid < range.getLeft() + count) { - final int sid = gid - count + range.getFirst() - 1; - return sid; - } - count += range.getLeft(); - } - return 0; - } - } - - private final DirectoryEntry _de; + private final int _major; private final int _minor; private final int _hdrSize; @@ -490,18 +42,18 @@ public class CffTable implements Table { 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 CffFont[] _fonts; private final byte[] _buf; - /** Creates a new instance of CffTable */ - protected CffTable(final DirectoryEntry de, final DataInput di) throws IOException { - _de = (DirectoryEntry) de.clone(); + /** Creates a new instance of CffTable + * @param di + * @param length + * @throws java.io.IOException */ + protected CffTable(DataInput di, int length) throws IOException { // Load entire table into a buffer, and create another input stream - _buf = new byte[de.getLength()]; + _buf = new byte[length]; di.readFully(_buf); DataInput di2 = getDataInputForOffset(0); @@ -510,101 +62,66 @@ 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); + + // TESTING +// Charstring gscs = new CharstringType2( +// null, +// 0, +// "Global subrs", +// _globalSubrIndex.getData(), +// _globalSubrIndex.getOffset(0) - 1, +// _globalSubrIndex.getDataLength()); +// System.out.println(gscs.toString()); // 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()]; - _charstringsArray = new Charstring[_topDictIndex.getCount()][]; + _fonts = new CffFont[_topDictIndex.getCount()]; for (int i = 0; i < _topDictIndex.getCount(); ++i) { - - // Charstrings INDEX - // We load this before Charsets because we may need to know the number - // of glyphs - final Integer charStringsOffset = (Integer) _topDictIndex.getTopDict(i).getValue(17); - di2 = getDataInputForOffset(charStringsOffset); - _charStringsIndexArray[i] = new Index(di2); - final int glyphCount = _charStringsIndexArray[i].getCount(); - - // Charsets - final Integer charsetOffset = (Integer) _topDictIndex.getTopDict(i).getValue(15); - di2 = getDataInputForOffset(charsetOffset); - final int format = di2.readUnsignedByte(); - switch (format) { - case 0: - _charsets[i] = new CharsetFormat0(di2, glyphCount); - break; - case 1: - _charsets[i] = new CharsetFormat1(di2, glyphCount); - break; - case 2: - _charsets[i] = new CharsetFormat2(di2, glyphCount); - break; - } - - // Create the charstrings - _charstringsArray[i] = new Charstring[glyphCount]; - for (int j = 0; j < glyphCount; ++j) { - 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)), - _charStringsIndexArray[i].getData(), - offset, - len, - null, - null); - } + _fonts[i] = new CffFont(this, i, _topDictIndex.getTopDict(i)); } } - - private DataInput getDataInputForOffset(final int offset) { + + public final DataInput getDataInputForOffset(int offset) { return new DataInputStream(new ByteArrayInputStream( _buf, offset, - _de.getLength() - offset)); + _buf.length - offset)); } public NameIndex getNameIndex() { return _nameIndex; } - public Charset getCharset(final int fontIndex) { - return _charsets[fontIndex]; - } - - public Charstring getCharstring(final int fontIndex, final int gid) { - return _charstringsArray[fontIndex][gid]; + public StringIndex getStringIndex() { + return _stringIndex; } - - public int getCharstringCount(final int fontIndex) { - return _charstringsArray[fontIndex].length; + + public Index getGlobalSubrIndex() { + return _globalSubrIndex; } - @Override - public int getType() { - return CFF; + public CffFont getFont(int fontIndex) { + return _fonts[fontIndex]; } @Override public String toString() { - final StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(); sb.append("'CFF' Table - Compact Font Format\n---------------------------------\n"); sb.append("\nName INDEX\n"); sb.append(_nameIndex.toString()); @@ -614,21 +131,11 @@ public class CffTable implements Table { sb.append(_stringIndex.toString()); sb.append("\nGlobal Subr INDEX\n"); sb.append(_globalSubrIndex.toString()); - for (int i = 0; i < _charStringsIndexArray.length; ++i) { + for (int i = 0; i < _fonts.length; ++i) { sb.append("\nCharStrings INDEX ").append(i).append("\n"); - sb.append(_charStringsIndexArray[i].toString()); + sb.append(_fonts[i].getCharStringsIndex().toString()); } 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/ClassDef.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ClassDef.java index a65bcd525..f06d08b27 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; @@ -13,16 +13,15 @@ import java.io.RandomAccessFile; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ClassDef.java,v 1.1.1.1 2004-12-05 23:14:33 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public abstract class ClassDef { public abstract int getFormat(); - protected static ClassDef read(final RandomAccessFile raf) throws IOException { + protected static ClassDef read(RandomAccessFile raf) throws IOException { ClassDef c = null; - final int format = raf.readUnsignedShort(); + 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 cbc05393f..f67e1e7f0 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; @@ -13,17 +13,16 @@ import java.io.RandomAccessFile; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ClassDefFormat1.java,v 1.1.1.1 2004-12-05 23:14:33 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class ClassDefFormat1 extends ClassDef { - private final int startGlyph; - private final int glyphCount; - private final int[] classValues; + private int startGlyph; + private int glyphCount; + private int[] classValues; /** Creates new ClassDefFormat1 */ - public ClassDefFormat1(final RandomAccessFile raf) throws IOException { + public ClassDefFormat1(RandomAccessFile raf) throws IOException { startGlyph = raf.readUnsignedShort(); glyphCount = raf.readUnsignedShort(); classValues = new int[glyphCount]; @@ -32,7 +31,6 @@ 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 99283f026..8411db5fe 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; @@ -13,16 +13,15 @@ import java.io.RandomAccessFile; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ClassDefFormat2.java,v 1.1.1.1 2004-12-05 23:14:33 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class ClassDefFormat2 extends ClassDef { - private final int classRangeCount; - private final RangeRecord[] classRangeRecords; + private int classRangeCount; + private RangeRecord[] classRangeRecords; /** Creates new ClassDefFormat2 */ - public ClassDefFormat2(final RandomAccessFile raf) throws IOException { + public ClassDefFormat2(RandomAccessFile raf) throws IOException { classRangeCount = raf.readUnsignedShort(); classRangeRecords = new RangeRecord[classRangeCount]; for (int i = 0; i < classRangeCount; i++) { @@ -30,7 +29,6 @@ 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 602897382..1d4bb48bd 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 @@ -1,52 +1,21 @@ /* + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2016 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ - ============================================================================ - 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 - - 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 <http://www.apache.org/>. - -*/ package jogamp.graph.font.typecast.ot.table; @@ -54,40 +23,30 @@ import java.io.DataInput; import java.io.IOException; /** - * @version $Id: CmapFormat.java,v 1.3 2004-12-21 16:56:35 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public abstract class CmapFormat { - + public static class Range { - + private final int _startCode; private final int _endCode; - - protected Range(final int startCode, final int endCode) { + + Range(int startCode, int endCode) { _startCode = startCode; _endCode = endCode; } - + public int getStartCode() { return _startCode; } - + public int getEndCode() { return _endCode; } } - protected int _format; - protected int _length; - protected int _language; - - protected CmapFormat(final DataInput di) throws IOException { - _length = di.readUnsignedShort(); - _language = di.readUnsignedShort(); - } - - protected static CmapFormat create(final int format, final DataInput di) + static CmapFormat create(int format, DataInput di) throws IOException { switch(format) { case 0: @@ -98,38 +57,33 @@ public abstract class CmapFormat { return new CmapFormat4(di); case 6: return new CmapFormat6(di); + case 12: + return new CmapFormat12(di); default: return new CmapFormatUnknown(format, di); } } - public int getFormat() { - return _format; - } + protected abstract int getFormat(); - public int getLength() { - return _length; - } + public abstract int getLength(); - public int getLanguage() { - return _language; - } + protected abstract int getLanguage(); 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: ") - .append(_format) - .append(", length: ") - .append(_length) - .append(", language: ") - .append(_language).toString(); + return "format: " + + getFormat() + + ", length: " + + getLength() + + ", language: " + + getLanguage(); } } 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 505e8c942..ed3d6cd6c 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 @@ -1,52 +1,21 @@ /* + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2016 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ - ============================================================================ - 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 - - 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 <http://www.apache.org/>. - -*/ package jogamp.graph.font.typecast.ot.table; @@ -56,28 +25,44 @@ import java.io.IOException; /** * Simple Macintosh cmap table, mapping only the ASCII character set to glyphs. * - * @version $Id: CmapFormat0.java,v 1.2 2004-12-21 10:22:55 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class CmapFormat0 extends CmapFormat { + private final int _length; + private final int _language; private final int[] _glyphIdArray = new int[256]; - protected CmapFormat0(final DataInput di) throws IOException { - super(di); - _format = 0; + CmapFormat0(DataInput di) throws IOException { + _length = di.readUnsignedShort(); + _language = di.readUnsignedShort(); for (int i = 0; i < 256; i++) { _glyphIdArray[i] = di.readUnsignedByte(); } } @Override + public int getFormat() { + return 0; + } + + @Override + public int getLength() { + return _length; + } + + @Override + public int getLanguage() { + return _language; + } + + @Override public int getRangeCount() { return 1; } - + @Override - public Range getRange(final int index) throws ArrayIndexOutOfBoundsException { + public Range getRange(int index) throws ArrayIndexOutOfBoundsException { if (index != 0) { throw new ArrayIndexOutOfBoundsException(); } @@ -85,7 +70,7 @@ public class CmapFormat0 extends CmapFormat { } @Override - public int mapCharCode(final int charCode) { + public int mapCharCode(int charCode) { if (0 <= charCode && charCode < 256) { return _glyphIdArray[charCode]; } else { diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat12.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat12.java new file mode 100644 index 000000000..530470cae --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CmapFormat12.java @@ -0,0 +1,103 @@ +/* + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2016 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package jogamp.graph.font.typecast.ot.table; + +import java.io.DataInput; +import java.io.IOException; + +/** + * + * @author <a href="mailto:[email protected]">David Schweinsberg</a> + */ +public class CmapFormat12 extends CmapFormat { + + private final int _length; + private final int _language; + private final int _nGroups; + private final int[] _startCharCode; + private final int[] _endCharCode; + private final int[] _startGlyphId; + + CmapFormat12(DataInput di) throws IOException { + di.readUnsignedShort(); // reserved + _length = di.readInt(); + _language = di.readInt(); + _nGroups = di.readInt(); + _startCharCode = new int[_nGroups]; + _endCharCode = new int[_nGroups]; + _startGlyphId = new int[_nGroups]; + for (int i = 0; i < _nGroups; ++i) { + _startCharCode[i] = di.readInt(); + _endCharCode[i] = di.readInt(); + _startGlyphId[i] = di.readInt(); + } + } + + @Override + public int getFormat() { + return 12; + } + + @Override + public int getLength() { + return _length; + } + + @Override + public int getLanguage() { + return _language; + } + + @Override + public int getRangeCount() { + return _nGroups; + } + + @Override + public Range getRange(int index) throws ArrayIndexOutOfBoundsException { + if (index < 0 || index >= _nGroups) { + throw new ArrayIndexOutOfBoundsException(); + } + return new Range(_startCharCode[index], _endCharCode[index]); + } + + @Override + public int mapCharCode(int charCode) { + try { + for (int i = 0; i < _nGroups; i++) { + if (_endCharCode[i] >= charCode) { + if (_startCharCode[i] <= charCode) { + return charCode - _startCharCode[i] + _startGlyphId[i]; + } else { + break; + } + } + } + } catch (ArrayIndexOutOfBoundsException e) { + System.err.println("error: Array out of bounds - " + e.getMessage()); + } + return 0; + } + + @Override + public String toString() { + return super.toString() + + ", nGroups: " + + _nGroups; + } +} 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 743fc93c1..41fbbb88a 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 @@ -1,52 +1,21 @@ /* + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2016 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ - ============================================================================ - 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 - - 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 <http://www.apache.org/>. - -*/ package jogamp.graph.font.typecast.ot.table; @@ -55,29 +24,30 @@ import java.io.IOException; /** * High-byte mapping through table cmap format. - * @version $Id: CmapFormat2.java,v 1.3 2004-12-21 16:56:54 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class CmapFormat2 extends CmapFormat { - static class SubHeader { + private static class SubHeader { int _firstCode; int _entryCount; short _idDelta; int _idRangeOffset; int _arrayIndex; } - + + private final int _length; + private final int _language; 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; - + CmapFormat2(DataInput di) throws IOException { + _length = di.readUnsignedShort(); + _language = di.readUnsignedShort(); + 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 +56,31 @@ public class CmapFormat2 extends CmapFormat { highest = Math.max(highest, _subHeaderKeys[i]); pos += 2; } - final int subHeaderCount = highest / 8 + 1; + int subHeaderCount = highest / 8 + 1; _subHeaders = new SubHeader[subHeaderCount]; - + // Read the subheaders, once again noting the highest glyphIndexArray // index range. - final int indexArrayOffset = 8 * subHeaderCount + 518; + int indexArrayOffset = 8 * subHeaderCount + 518; highest = 0; for (int i = 0; i < _subHeaders.length; ++i) { - final SubHeader sh = new SubHeader(); + 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) { @@ -119,16 +89,31 @@ public class CmapFormat2 extends CmapFormat { } @Override + public int getFormat() { + return 2; + } + + @Override + public int getLength() { + return _length; + } + + @Override + public int getLanguage() { + return _language; + } + + @Override public int getRangeCount() { return _subHeaders.length; } - + @Override - public Range getRange(final int index) throws ArrayIndexOutOfBoundsException { + public Range getRange(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) { @@ -139,31 +124,31 @@ public class CmapFormat2 extends CmapFormat { } } } - + return new Range( highByte | _subHeaders[index]._firstCode, highByte | (_subHeaders[index]._firstCode + - _subHeaders[index]._entryCount - 1)); + _subHeaders[index]._entryCount - 1)); } @Override - public int mapCharCode(final int charCode) { - + public int mapCharCode(int charCode) { + // Get the appropriate subheader int index = 0; - final int highByte = charCode >> 8; + int highByte = charCode >> 8; if (highByte != 0) { index = _subHeaderKeys[highByte] / 8; } - final SubHeader sh = _subHeaders[index]; - + SubHeader sh = _subHeaders[index]; + // Is the charCode out-of-range? - final int lowByte = charCode & 0xff; + 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 c8be6c7fb..a371b5d6a 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 @@ -1,64 +1,35 @@ /* + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2016 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ - ============================================================================ - 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 - - 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 <http://www.apache.org/>. - -*/ package jogamp.graph.font.typecast.ot.table; import java.io.DataInput; import java.io.IOException; +import java.util.Arrays; /** - * @version $Id: CmapFormat4.java,v 1.3 2004-12-21 16:57:23 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class CmapFormat4 extends CmapFormat { + private final int _length; + private final int _language; private final int _segCountX2; private final int _searchRange; private final int _entrySelector; @@ -70,9 +41,9 @@ public class CmapFormat4 extends CmapFormat { private final int[] _glyphIdArray; private final int _segCount; - protected CmapFormat4(final DataInput di) throws IOException { - super(di); // 6 - _format = 4; + CmapFormat4(DataInput di) throws IOException { + _length = di.readUnsignedShort(); + _language = di.readUnsignedShort(); _segCountX2 = di.readUnsignedShort(); // +2 (8) _segCount = _segCountX2 / 2; _endCode = new int[_segCount]; @@ -97,12 +68,12 @@ public class CmapFormat4 extends CmapFormat { } // + 2*segCount (8*segCount + 16) // Whatever remains of this header belongs in glyphIdArray - final int count = (_length - (8*_segCount + 16)) / 2; + 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) { @@ -111,12 +82,27 @@ public class CmapFormat4 extends CmapFormat { } @Override + public int getFormat() { + return 4; + } + + @Override + public int getLength() { + return _length; + } + + @Override + public int getLanguage() { + return _language; + } + + @Override public int getRangeCount() { return _segCount; } - + @Override - public Range getRange(final int index) throws ArrayIndexOutOfBoundsException { + public Range getRange(int index) throws ArrayIndexOutOfBoundsException { if (index < 0 || index >= _segCount) { throw new ArrayIndexOutOfBoundsException(); } @@ -124,7 +110,7 @@ public class CmapFormat4 extends CmapFormat { } @Override - public int mapCharCode(final int charCode) { + public int mapCharCode(int charCode) { try { for (int i = 0; i < _segCount; i++) { if (_endCode[i] >= charCode) { @@ -139,7 +125,7 @@ public class CmapFormat4 extends CmapFormat { } } } - } catch (final ArrayIndexOutOfBoundsException e) { + } catch (ArrayIndexOutOfBoundsException e) { System.err.println("error: Array out of bounds - " + e.getMessage()); } return 0; @@ -147,23 +133,22 @@ public class CmapFormat4 extends CmapFormat { @Override public String toString() { - return new StringBuilder() - .append(super.toString()) - .append(", segCountX2: ") - .append(_segCountX2) - .append(", searchRange: ") - .append(_searchRange) - .append(", entrySelector: ") - .append(_entrySelector) - .append(", rangeShift: ") - .append(_rangeShift) - .append(", endCodeLen: ") - .append(_endCode.length) - .append(", startCodeLen: ") - .append(_endCode.length) - .append(", idDeltaLen: ") - .append(_idDelta.length) - .append(", idRangeOffsetLen: ") - .append(_idRangeOffset.length).toString(); + return super.toString() + + ", segCountX2: " + + _segCountX2 + + ", searchRange: " + + _searchRange + + ", entrySelector: " + + _entrySelector + + ", rangeShift: " + + _rangeShift + + ", endCode: " + + Arrays.toString(_endCode) + + ", startCode: " + + Arrays.toString(_endCode) + + ", idDelta: " + + Arrays.toString(_idDelta) + + ", idRangeOffset: " + + Arrays.toString(_idRangeOffset); } } 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 eff3d2fb1..80039aac0 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 @@ -1,52 +1,20 @@ /* - - ============================================================================ - 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 - - 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 <http://www.apache.org/>. - -*/ + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2016 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package jogamp.graph.font.typecast.ot.table; @@ -54,37 +22,62 @@ import java.io.DataInput; import java.io.IOException; /** - * TODO: To be implemented - * @version $Id: CmapFormat6.java,v 1.2 2004-12-21 10:22:56 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * Format 6: Trimmed table mapping + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class CmapFormat6 extends CmapFormat { - private short _firstCode; - private short _entryCount; - private short[] _glyphIdArray; + private final int _length; + private final int _language; + private final int _firstCode; + private final int _entryCount; + private final int[] _glyphIdArray; + + CmapFormat6(DataInput di) throws IOException { + _length = di.readUnsignedShort(); + _language = di.readUnsignedShort(); + _firstCode = di.readUnsignedShort(); + _entryCount = di.readUnsignedShort(); + _glyphIdArray = new int[_entryCount]; + for (int i = 0; i < _entryCount; i++) { + _glyphIdArray[i] = di.readUnsignedShort(); + } + } + + @Override + public int getFormat() { + return 6; + } - protected CmapFormat6(final DataInput di) throws IOException { - super(di); - _format = 6; + @Override + public int getLength() { + return _length; + } - // 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 getLanguage() { + return _language; } @Override public int getRangeCount() { - return 0; + return 1; } - + @Override - public Range getRange(final int index) throws ArrayIndexOutOfBoundsException { - throw new ArrayIndexOutOfBoundsException(); + public Range getRange(int index) throws ArrayIndexOutOfBoundsException { + if (index != 0) { + throw new ArrayIndexOutOfBoundsException(); + } + return new Range(_firstCode, _entryCount); } @Override - public int mapCharCode(final int charCode) { - return 0; + public int mapCharCode(int charCode) { + if (_firstCode <= charCode && charCode < _firstCode + _entryCount) { + return _glyphIdArray[charCode - _firstCode]; + } else { + 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 e9aa1d4e0..c09d66c01 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 @@ -1,9 +1,7 @@ /* - * $Id: CmapFormatUnknown.java,v 1.1 2004-12-21 10:21:23 davidsch Exp $ - * * Typecast - The Font Development Environment * - * Copyright (c) 2004 David Schweinsberg + * Copyright (c) 2004-2016 David Schweinsberg * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,32 +24,63 @@ import java.io.IOException; /** * When we encounter a cmap format we don't understand, we can use this class * to hold the bare minimum information about it. - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: CmapFormatUnknown.java,v 1.1 2004-12-21 10:21:23 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class CmapFormatUnknown extends CmapFormat { - - /** Creates a new instance of CmapFormatUnknown */ - protected CmapFormatUnknown(final int format, final DataInput di) throws IOException { - super(di); + + private final int _format; + private final int _length; + private final int _language; + + /** Creates a new instance of CmapFormatUnknown + * @param format + * @param di + * @throws java.io.IOException */ + CmapFormatUnknown(int format, DataInput di) throws IOException { _format = format; + if (_format < 8) { + _length = di.readUnsignedShort(); + _language = di.readUnsignedShort(); + + // We don't know how to handle this data, so we'll just skip over it + di.skipBytes(_length - 6); + } else { + di.readUnsignedShort(); // reserved + _length = di.readInt(); + _language = di.readInt(); + + // We don't know how to handle this data, so we'll just skip over it + di.skipBytes(_length - 12); + } + } + + @Override + public int getFormat() { + return _format; + } + + @Override + public int getLength() { + return _length; + } - // We don't know how to handle this data, so we'll just skip over it - di.skipBytes(_length - 4); + @Override + public int getLanguage() { + return _language; } @Override public int getRangeCount() { return 0; } - + @Override - public Range getRange(final int index) throws ArrayIndexOutOfBoundsException { + public Range getRange(int index) throws ArrayIndexOutOfBoundsException { throw new ArrayIndexOutOfBoundsException(); } @Override - public int mapCharCode(final int charCode) { + public int mapCharCode(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 1f2c80286..102ea2f71 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 @@ -54,17 +54,16 @@ import java.io.DataInput; import java.io.IOException; /** - * @version $Id: CmapIndexEntry.java,v 1.2 2004-12-21 10:22:56 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class CmapIndexEntry implements Comparable { +public class CmapIndexEntry implements Comparable<CmapIndexEntry> { - private final int _platformId; - private final int _encodingId; - private final int _offset; + private int _platformId; + private int _encodingId; + private int _offset; private CmapFormat _format; - protected CmapIndexEntry(final DataInput di) throws IOException { + CmapIndexEntry(DataInput di) throws IOException { _platformId = di.readUnsignedShort(); _encodingId = di.readUnsignedShort(); _offset = di.readInt(); @@ -85,35 +84,27 @@ public class CmapIndexEntry implements Comparable { public CmapFormat getFormat() { return _format; } - - public void setFormat(final CmapFormat format) { + + public void setFormat(CmapFormat format) { _format = format; } @Override public String toString() { - return new StringBuilder() - .append("platform id: ") - .append(_platformId) - .append(" (") - .append(ID.getPlatformName((short) _platformId)) - .append("), encoding id: ") - .append(_encodingId) - .append(" (") - .append(ID.getEncodingName((short) _platformId, (short) _encodingId)) - .append("), offset: ") - .append(_offset).toString(); + return "platform id: " + + _platformId + + " (" + + ID.getPlatformName((short) _platformId) + + "), encoding id: " + + _encodingId + + " (" + + ID.getEncodingName((short) _platformId, (short) _encodingId) + + "), offset: " + + _offset; } @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()) { - return 1; - } else { - return 0; - } + public int compareTo(CmapIndexEntry entry) { + return Integer.compare(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 4623eb5cf..dd5e9bc02 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 @@ -56,18 +56,15 @@ import java.io.IOException; import java.util.Arrays; /** - * @version $Id: CmapTable.java,v 1.3 2004-12-21 10:22:56 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class CmapTable implements Table { - private final DirectoryEntry _de; - private final int _version; - private final int _numTables; - private final CmapIndexEntry[] _entries; + private int _version; + private int _numTables; + private CmapIndexEntry[] _entries; - protected CmapTable(final DirectoryEntry de, final DataInput di) throws IOException { - _de = (DirectoryEntry) de.clone(); + public CmapTable(DataInput di) throws IOException { _version = di.readUnsignedShort(); _numTables = di.readUnsignedShort(); long bytesRead = 4; @@ -94,11 +91,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(); } - final int formatType = di.readUnsignedShort(); + int formatType = di.readUnsignedShort(); lastFormat = CmapFormat.create(formatType, di); lastOffset = _entries[i].getOffset(); _entries[i].setFormat(lastFormat); @@ -109,16 +106,16 @@ public class CmapTable implements Table { public int getVersion() { return _version; } - + public int getNumTables() { return _numTables; } - - public CmapIndexEntry getCmapIndexEntry(final int i) { + + public CmapIndexEntry getCmapIndexEntry(int i) { return _entries[i]; } - - public CmapFormat getCmapFormat(final short platformId, final short encodingId) { + + public CmapFormat getCmapFormat(short platformId, short encodingId) { // Find the requested format for (int i = 0; i < _numTables; i++) { @@ -131,13 +128,8 @@ public class CmapTable implements Table { } @Override - public int getType() { - return cmap; - } - - @Override public String toString() { - final StringBuilder sb = new StringBuilder().append("cmap\n"); + StringBuilder sb = new StringBuilder().append("cmap\n"); // Get each of the index entries for (int i = 0; i < _numTables; i++) { @@ -151,14 +143,4 @@ 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/ColrTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ColrTable.java new file mode 100644 index 000000000..13d4f2c6b --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ColrTable.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package jogamp.graph.font.typecast.ot.table; + +import java.io.DataInput; +import java.io.IOException; + +/** + * @author <a href="mailto:[email protected]">David Schweinsberg</a> + */ +class ColrTable implements Table { + + static class BaseGlyphRecord { + + private final int _gid; + private final int _firstLayerIndex; + private final int _numLayers; + + BaseGlyphRecord(DataInput di) throws IOException { + _gid = di.readUnsignedShort(); + _firstLayerIndex = di.readUnsignedShort(); + _numLayers = di.readUnsignedShort(); + } + + int getGid() { + return _gid; + } + + int getFirstLayerIndex() { + return _firstLayerIndex; + } + + int getNumLayers() { + return _numLayers; + } + } + + static class LayerRecord { + + private final int _gid; + private final int _paletteIndex; + + LayerRecord(DataInput di) throws IOException { + _gid = di.readUnsignedShort(); + _paletteIndex = di.readUnsignedShort(); + } + + int getGid() { + return _gid; + } + + int getPaletteIndex() { + return _paletteIndex; + } + } + + private final int _version; + private final int _numBaseGlyphRecords; + private final int _offsetBaseGlyphRecord; + private final int _offsetLayerRecord; + private final int _numLayerRecords; + private final BaseGlyphRecord[] _baseGlyphRecords; + private final LayerRecord[] _layerRecords; + + protected ColrTable(DataInput di) throws IOException { + _version = di.readUnsignedShort(); + _numBaseGlyphRecords = di.readUnsignedShort(); + _offsetBaseGlyphRecord = di.readInt(); + _offsetLayerRecord = di.readInt(); + _numLayerRecords = di.readUnsignedShort(); + + int byteCount = 14; + if (_offsetBaseGlyphRecord > byteCount) { + di.skipBytes(byteCount - _offsetBaseGlyphRecord); + } + + _baseGlyphRecords = new BaseGlyphRecord[_numBaseGlyphRecords]; + for (int i = 0; i < _numBaseGlyphRecords; ++i) { + _baseGlyphRecords[i] = new BaseGlyphRecord(di); + byteCount += 6; + } + + if (_offsetLayerRecord > byteCount) { + di.skipBytes(byteCount - _offsetLayerRecord); + } + + _layerRecords = new LayerRecord[_numLayerRecords]; + for (int i = 0; i < _numLayerRecords; ++i) { + _layerRecords[i] = new LayerRecord(di); + } + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("'COLR' Table\n------------\nBase Glyph Records\n"); + for (BaseGlyphRecord record : _baseGlyphRecords) { + sb.append(String.format("%d : %d, %d\n", record.getGid(), + record.getFirstLayerIndex(), record.getNumLayers())); + } + sb.append("\nLayer Records\n"); + for (LayerRecord record : _layerRecords) { + sb.append(String.format("%d : %d\n", record.getGid(), + record.getPaletteIndex())); + } + return sb.toString(); + } + +} 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 a6f994f95..a5aed00ba 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 @@ -55,8 +55,7 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: Coverage.java,v 1.3 2007-01-24 09:43:30 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public abstract class Coverage { @@ -68,10 +67,12 @@ public abstract class Coverage { * can't be found. */ public abstract int findGlyph(int glyphId); - - protected static Coverage read(final DataInput di) throws IOException { + + public abstract int[] getGlyphIds(); + + static Coverage read(DataInput di) throws IOException { Coverage c = null; - final int format = di.readUnsignedShort(); + 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 3deb60202..9cdfc2283 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 @@ -55,8 +55,7 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: CoverageFormat1.java,v 1.2 2007-01-24 09:43:30 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class CoverageFormat1 extends Coverage { @@ -64,7 +63,7 @@ public class CoverageFormat1 extends Coverage { private final int[] _glyphIds; /** Creates new CoverageFormat1 */ - protected CoverageFormat1(final DataInput di) throws IOException { + CoverageFormat1(DataInput di) throws IOException { _glyphCount = di.readUnsignedShort(); _glyphIds = new int[_glyphCount]; for (int i = 0; i < _glyphCount; i++) { @@ -78,7 +77,7 @@ public class CoverageFormat1 extends Coverage { } @Override - public int findGlyph(final int glyphId) { + public int findGlyph(int glyphId) { for (int i = 0; i < _glyphCount; i++) { if (_glyphIds[i] == glyphId) { return i; @@ -87,4 +86,8 @@ public class CoverageFormat1 extends Coverage { return -1; } + @Override + public int[] getGlyphIds() { + return _glyphIds; + } } 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 9397f376d..5bab93cb8 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 @@ -52,11 +52,12 @@ package jogamp.graph.font.typecast.ot.table; import java.io.DataInput; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: CoverageFormat2.java,v 1.2 2007-01-24 09:43:30 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class CoverageFormat2 extends Coverage { @@ -64,7 +65,7 @@ public class CoverageFormat2 extends Coverage { private final RangeRecord[] _rangeRecords; /** Creates new CoverageFormat2 */ - protected CoverageFormat2(final DataInput di) throws IOException { + CoverageFormat2(DataInput di) throws IOException { _rangeCount = di.readUnsignedShort(); _rangeRecords = new RangeRecord[_rangeCount]; for (int i = 0; i < _rangeCount; i++) { @@ -78,9 +79,9 @@ public class CoverageFormat2 extends Coverage { } @Override - public int findGlyph(final int glyphId) { + public int findGlyph(int glyphId) { for (int i = 0; i < _rangeCount; i++) { - final int n = _rangeRecords[i].getCoverageIndex(glyphId); + int n = _rangeRecords[i].getCoverageIndex(glyphId); if (n > -1) { return n; } @@ -88,4 +89,14 @@ public class CoverageFormat2 extends Coverage { return -1; } + @Override + public int[] getGlyphIds() { + List<Integer> ids = new ArrayList<>(); + for (RangeRecord record : _rangeRecords) { + for (int i = record.getStart(); i < record.getEnd(); ++i) { + ids.add(i); + } + } + return ids.stream().mapToInt(i->i).toArray(); + } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CpalTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CpalTable.java new file mode 100644 index 000000000..f8122c730 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/CpalTable.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package jogamp.graph.font.typecast.ot.table; + +import java.io.DataInput; +import java.io.IOException; + +/** + * @author <a href="mailto:[email protected]">David Schweinsberg</a> + */ +class CpalTable implements Table { + + static class ColorRecord { + + private final short _blue; + private final short _green; + private final short _red; + private final short _alpha; + + ColorRecord(DataInput di) throws IOException { + _blue = (short) di.readUnsignedByte(); + _green = (short) di.readUnsignedByte(); + _red = (short) di.readUnsignedByte(); + _alpha = (short) di.readUnsignedByte(); + } + + short getBlue() { + return _blue; + } + + short getGreen() { + return _green; + } + + short getRed() { + return _red; + } + + short getAlpha() { + return _alpha; + } + } + + private final int _version; + private final int _numPalettesEntries; + private final int _numPalette; + private final int _numColorRecords; + private final int _offsetFirstColorRecord; + private final int[] _colorRecordIndices; + private final int _offsetPaletteTypeArray; + private final int _offsetPaletteLabelArray; + private final int _offsetPaletteEntryLabelArray; + private final ColorRecord[] _colorRecords; + + protected CpalTable(DataInput di) throws IOException { + _version = di.readUnsignedShort(); + _numPalettesEntries = di.readUnsignedShort(); + _numPalette = di.readUnsignedShort(); + _numColorRecords = di.readUnsignedShort(); + _offsetFirstColorRecord = di.readInt(); + + int byteCount = 12; + _colorRecordIndices = new int[_numPalette]; + for (int i = 0; i < _numPalette; ++i) { + _colorRecordIndices[i] = di.readUnsignedShort(); + byteCount += 2; + } + if (_version == 1) { + _offsetPaletteTypeArray = di.readInt(); + _offsetPaletteLabelArray = di.readInt(); + _offsetPaletteEntryLabelArray = di.readInt(); + byteCount += 12; + } else { + _offsetPaletteTypeArray = -1; + _offsetPaletteLabelArray = -1; + _offsetPaletteEntryLabelArray = -1; + } + + if (_offsetFirstColorRecord > byteCount) { + di.skipBytes(byteCount - _offsetFirstColorRecord); + } + + _colorRecords = new ColorRecord[_numColorRecords]; + for (int i = 0; i < _numColorRecords; ++i) { + _colorRecords[i] = new ColorRecord(di); + } + + if (_version == 1) { + // TODO find some sample version 1 content + } + } + + public int getNumPalettesEntries() { + return _numPalettesEntries; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("'CPAL' Table\n------------\nColor Record Indices\n"); + int i = 0; + for (int index : _colorRecordIndices) { + sb.append(String.format("%d: %d\n", i++, index)); + } + sb.append("\nColor Records\n"); + i = 0; + for (ColorRecord record : _colorRecords) { + sb.append(String.format("%d: B: %3d, G: %3d, R: %3d, A: %3d\n", + i++, record.getBlue(), record.getGreen(), record.getRed(), + record.getAlpha())); + } + return sb.toString(); + } + +} 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 7f62d26ab..24139da22 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; @@ -12,35 +12,26 @@ import java.io.DataInput; import java.io.IOException; /** - * @version $Id: CvtTable.java,v 1.1.1.1 2004-12-05 23:14:36 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class CvtTable implements Table { +class CvtTable implements Table { - private final DirectoryEntry de; private final short[] values; - protected CvtTable(final DirectoryEntry de, final DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); - final int len = de.getLength() / 2; + protected CvtTable(DataInput di, int length) throws IOException { + int len = length / 2; values = new short[len]; for (int i = 0; i < len; i++) { values[i] = di.readShort(); } } - @Override - public int getType() { - return cvt; - } - public short[] getValues() { return values; } - @Override public String toString() { - final StringBuilder sb = new StringBuilder(); + 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"); @@ -50,15 +41,4 @@ 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 a0b10e187..510c43816 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; @@ -13,18 +13,17 @@ import java.io.RandomAccessFile; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: Device.java,v 1.1.1.1 2004-12-05 23:14:37 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class Device extends Object { +class Device { - private final int startSize; - private final int endSize; - private final int deltaFormat; - private final int[] deltaValues; + private int startSize; + private int endSize; + private int deltaFormat; + private int[] deltaValues; /** Creates new Device */ - public Device(final RandomAccessFile raf) throws IOException { + public Device(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 deleted file mode 100644 index 54684b8e9..000000000 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/DirectoryEntry.java +++ /dev/null @@ -1,117 +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 - - 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 <http://www.apache.org/>. - -*/ - -package jogamp.graph.font.typecast.ot.table; - -import java.io.DataInput; -import java.io.IOException; - -/** - * @version $Id: DirectoryEntry.java,v 1.2 2004-12-09 23:46:21 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class DirectoryEntry implements Cloneable { - - private final int _tag; - private final int _checksum; - private final int _offset; - private final int _length; - - 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 (final CloneNotSupportedException e) { - return null; - } - } - - public int getChecksum() { - return _checksum; - } - - public int getLength() { - return _length; - } - - public int getOffset() { - return _offset; - } - - public int getTag() { - return _tag; - } - - public String getTagAsString() { - return new StringBuilder() - .append((char)((_tag>>24)&0xff)) - .append((char)((_tag>>16)&0xff)) - .append((char)((_tag>>8)&0xff)) - .append((char)((_tag)&0xff)) - .toString(); - } - - @Override - public String toString() { - return new StringBuilder() - .append("'").append(getTagAsString()) - .append("' - chksm = 0x").append(Integer.toHexString(_checksum)) - .append(", off = 0x").append(Integer.toHexString(_offset)) - .append(", len = ").append(_length) - .toString(); - } -} 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 ec7b503f1..66e9474a9 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; @@ -13,17 +13,16 @@ import java.io.DataInput; /** * - * @version $Id: DsigEntry.java,v 1.1.1.1 2004-12-05 23:14:37 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class DsigEntry { - - private final int format; - private final int length; - private final int offset; +class DsigEntry { + private int format; + private int length; + private int offset; + /** Creates new DsigEntry */ - protected DsigEntry(final DataInput di) throws IOException { + DsigEntry(DataInput di) throws IOException { format = di.readInt(); length = di.readInt(); offset = di.readInt(); @@ -32,11 +31,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 f2b1322c0..c10e007f0 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; @@ -13,21 +13,18 @@ import java.io.DataInput; /** * - * @version $Id: DsigTable.java,v 1.1.1.1 2004-12-05 23:14:37 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class DsigTable implements Table { +class DsigTable implements Table { - private final DirectoryEntry de; - private final int version; - private final int numSigs; - private final int flag; - private final DsigEntry[] dsigEntry; - private final SignatureBlock[] sigBlocks; + private int version; + private int numSigs; + private int flag; + private DsigEntry[] dsigEntry; + private SignatureBlock[] sigBlocks; /** Creates new DsigTable */ - protected DsigTable(final DirectoryEntry de, final DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); + protected DsigTable(DataInput di) throws IOException { version = di.readInt(); numSigs = di.readUnsignedShort(); flag = di.readUnsignedShort(); @@ -41,29 +38,8 @@ 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() { - final StringBuilder sb = new StringBuilder().append("DSIG\n"); + 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 c6f912569..ce9d65115 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 @@ -55,17 +55,16 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: Feature.java,v 1.2 2007-01-24 09:47:46 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class Feature { - private final int _featureParams; - private final int _lookupCount; - private final int[] _lookupListIndex; + private int _featureParams; + private int _lookupCount; + private int[] _lookupListIndex; /** Creates new Feature */ - protected Feature(final DataInput di) throws IOException { + Feature(DataInput di) throws IOException { _featureParams = di.readUnsignedShort(); _lookupCount = di.readUnsignedShort(); _lookupListIndex = new int[_lookupCount]; @@ -78,7 +77,7 @@ public class Feature { return _lookupCount; } - public int getLookupListIndex(final int i) { + public int getLookupListIndex(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 933378068..cc67a85a5 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 @@ -55,22 +55,21 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: FeatureList.java,v 1.3 2007-01-24 09:54:44 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class FeatureList { - private final int _featureCount; - private final FeatureRecord[] _featureRecords; - private final Feature[] _features; + private int _featureCount; + private FeatureRecord[] _featureRecords; + private Feature[] _features; /** Creates new FeatureList */ - public FeatureList(final DataInputStream dis, final int offset) throws IOException { - + public FeatureList(DataInputStream dis, 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 +87,20 @@ public class FeatureList { public int getFeatureCount() { return _featureCount; } - - public FeatureRecord getFeatureRecord(final int i) { + + public FeatureRecord getFeatureRecord(int i) { return _featureRecords[i]; } - - public Feature getFeature(final int i) { + + public Feature getFeature(int i) { return _features[i]; } - public Feature findFeature(final LangSys langSys, final String tag) { + public Feature findFeature(LangSys langSys, String tag) { if (tag.length() != 4) { return null; } - final int tagVal = ((tag.charAt(0)<<24) + 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 06506904f..120c1da17 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 @@ -55,16 +55,15 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: FeatureRecord.java,v 1.2 2007-01-24 09:47:48 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class FeatureRecord { - private final int _tag; - private final int _offset; + private int _tag; + private int _offset; /** Creates new FeatureRecord */ - protected FeatureRecord(final DataInput di) throws IOException { + FeatureRecord(DataInput di) throws IOException { _tag = di.readInt(); _offset = di.readUnsignedShort(); } @@ -72,17 +71,15 @@ public class FeatureRecord { public int getTag() { return _tag; } - + public int getOffset() { return _offset; } public String getTagAsString() { - return new StringBuilder() - .append((char)((_tag>>24)&0xff)) - .append((char)((_tag>>16)&0xff)) - .append((char)((_tag>>8)&0xff)) - .append((char)((_tag)&0xff)) - .toString(); + return String.valueOf((char) ((_tag >> 24) & 0xff)) + + (char) ((_tag >> 16) & 0xff) + + (char) ((_tag >> 8) & 0xff) + + (char) ((_tag) & 0xff); } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/FeatureTags.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/FeatureTags.java index a5584a207..cf0ed7e80 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/FeatureTags.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/FeatureTags.java @@ -53,11 +53,10 @@ package jogamp.graph.font.typecast.ot.table; /** * Definition of Feature tags * - * @version $Id: FeatureTags.java,v 1.2 2007-01-24 09:47:48 davidsch Exp $ * @author <a href="mailto:[email protected]">Vincent Hardy</a> */ public interface FeatureTags { - public static final String FEATURE_TAG_INIT = "init"; - public static final String FEATURE_TAG_MEDI = "medi"; - public static final String FEATURE_TAG_FINA = "fina"; + String FEATURE_TAG_INIT = "init"; + String FEATURE_TAG_MEDI = "medi"; + String FEATURE_TAG_FINA = "fina"; } 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 e44acfa02..49e26ebbb 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,50 +1,28 @@ /***************************************************************************** * 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; import java.io.DataInput; import java.io.IOException; - import jogamp.graph.font.typecast.ot.Disassembler; /** - * @version $Id: FpgmTable.java,v 1.1.1.1 2004-12-05 23:14:38 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class FpgmTable extends Program implements Table { - - private final DirectoryEntry de; - - protected FpgmTable(final DirectoryEntry de, final DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); - readInstructions(di, de.getLength()); - } +class FpgmTable extends Program implements Table { - @Override - public int getType() { - return fpgm; + protected FpgmTable(DataInput di, int length) throws IOException { + readInstructions(di, length); } - @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 cebc51646..52c03dfb9 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; @@ -13,26 +13,24 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: GaspRange.java,v 1.1.1.1 2004-12-05 23:14:38 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class GaspRange { - - public static final int GASP_GRIDFIT = 1; - public static final int GASP_DOGRAY = 2; - - private final int rangeMaxPPEM; - private final int rangeGaspBehavior; +class GaspRange { + private static final int GASP_GRIDFIT = 1; + private static final int GASP_DOGRAY = 2; + + private int rangeMaxPPEM; + private int rangeGaspBehavior; + /** Creates new GaspRange */ - protected GaspRange(final DataInput di) throws IOException { + GaspRange(DataInput di) throws IOException { rangeMaxPPEM = di.readUnsignedShort(); rangeGaspBehavior = di.readUnsignedShort(); } - @Override public String toString() { - final StringBuilder sb = new StringBuilder(); + 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 7bf7f96cc..c52e4b61c 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; @@ -13,19 +13,16 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: GaspTable.java,v 1.1.1.1 2004-12-05 23:14:39 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class GaspTable implements Table { - private final DirectoryEntry de; - private final int version; - private final int numRanges; - private final GaspRange[] gaspRange; - + private int version; + private int numRanges; + private GaspRange[] gaspRange; + /** Creates new GaspTable */ - protected GaspTable(final DirectoryEntry de, final DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); + public GaspTable(DataInput di) throws IOException { version = di.readUnsignedShort(); numRanges = di.readUnsignedShort(); gaspRange = new GaspRange[numRanges]; @@ -34,14 +31,8 @@ public class GaspTable implements Table { } } - @Override - public int getType() { - return gasp; - } - - @Override public String toString() { - final StringBuilder sb = new StringBuilder(); + 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); @@ -52,15 +43,4 @@ 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/GdefTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GdefTable.java new file mode 100644 index 000000000..fdc4701f0 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GdefTable.java @@ -0,0 +1,15 @@ + +package jogamp.graph.font.typecast.ot.table; + +import java.io.DataInput; +import java.io.IOException; + +/** + * @author <a href="mailto:[email protected]">David Schweinsberg</a> + */ +class GdefTable implements Table { + + protected GdefTable(DataInput di) throws IOException { + } + +} 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 4db4ddcc2..93b7ad1f0 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 @@ -54,18 +54,17 @@ import java.io.DataInput; import java.io.IOException; /** - * @version $Id: GlyfCompositeComp.java,v 1.3 2010-08-10 11:41:55 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class GlyfCompositeComp { - public static final short ARG_1_AND_2_ARE_WORDS = 0x0001; - public static final short ARGS_ARE_XY_VALUES = 0x0002; + private static final short ARG_1_AND_2_ARE_WORDS = 0x0001; + private static final short ARGS_ARE_XY_VALUES = 0x0002; public static final short ROUND_XY_TO_GRID = 0x0004; - public static final short WE_HAVE_A_SCALE = 0x0008; + private static final short WE_HAVE_A_SCALE = 0x0008; public static final short MORE_COMPONENTS = 0x0020; - public static final short WE_HAVE_AN_X_AND_Y_SCALE = 0x0040; - public static final short WE_HAVE_A_TWO_BY_TWO = 0x0080; + private static final short WE_HAVE_AN_X_AND_Y_SCALE = 0x0040; + private static final short WE_HAVE_A_TWO_BY_TWO = 0x0080; public static final short WE_HAVE_INSTRUCTIONS = 0x0100; public static final short USE_MY_METRICS = 0x0200; @@ -73,8 +72,8 @@ public class GlyfCompositeComp { private final int _firstContour; private short _argument1; private short _argument2; - private final int _flags; - private final int _glyphIndex; + private int _flags; + private int _glyphIndex; private double _xscale = 1.0; private double _yscale = 1.0; private double _scale01 = 0.0; @@ -84,7 +83,7 @@ public class GlyfCompositeComp { private int _point1 = 0; private int _point2 = 0; - protected GlyfCompositeComp(final int firstIndex, final int firstContour, final DataInput di) + GlyfCompositeComp(int firstIndex, int firstContour, DataInput di) throws IOException { _firstIndex = firstIndex; _firstContour = firstContour; @@ -111,7 +110,7 @@ public class GlyfCompositeComp { // Get the scale values (if any) if ((_flags & WE_HAVE_A_SCALE) != 0) { - final int i = di.readShort(); + 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 +183,8 @@ public class GlyfCompositeComp { * @param y The y-coordinate of the point to transform * @return The transformed x-coordinate */ - public int scaleX(final int x, final int y) { - return (int)(x * _xscale + y * _scale10); + public int scaleX(int x, int y) { + return (int)((double) x * _xscale + (double) y * _scale10); } /** @@ -194,7 +193,7 @@ public class GlyfCompositeComp { * @param y The y-coordinate of the point to transform * @return The transformed y-coordinate */ - public int scaleY(final int x, final int y) { - return (int)(x * _scale01 + y * _yscale); + public int scaleY(int x, int y) { + return (int)((double) x * _scale01 + (double) 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 3879da02a..f9d639033 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 @@ -60,13 +60,11 @@ import java.util.ArrayList; * or more simple glyphs, usually with some sort of transformation applied to * each. * - * @version $Id: GlyfCompositeDescript.java,v 1.5 2007-01-25 08:43:18 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class GlyfCompositeDescript extends GlyfDescript { - private final ArrayList<GlyfCompositeComp> _components = - new ArrayList<GlyfCompositeComp>(); + private final ArrayList<GlyfCompositeComp> _components = new ArrayList<>(); public GlyfCompositeDescript( final GlyfTable parentTable, @@ -184,10 +182,10 @@ public class GlyfCompositeDescript extends GlyfDescript { return _components.get(i); } - protected GlyfCompositeComp getCompositeComp(final int i) { + private GlyfCompositeComp getCompositeComp(final int i) { GlyfCompositeComp c; - for (int n = 0; n < _components.size(); n++) { - c = _components.get(n); + for (final GlyfCompositeComp component : _components) { + c = component; final GlyphDescription gd = _parentTable.getDescription(c.getGlyphIndex()); if (c.getFirstIndex() <= i && i < (c.getFirstIndex() + gd.getPointCount())) { return c; @@ -196,10 +194,10 @@ public class GlyfCompositeDescript extends GlyfDescript { return null; } - protected GlyfCompositeComp getCompositeCompEndPt(final int i) { + private GlyfCompositeComp getCompositeCompEndPt(final int i) { GlyfCompositeComp c; - for (int j = 0; j < _components.size(); j++) { - c = _components.get(j); + for (final GlyfCompositeComp component : _components) { + c = component; 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 3d2154d5a..2a8deaeeb 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 @@ -54,32 +54,31 @@ import java.io.DataInput; import java.io.IOException; /** - * @version $Id: GlyfDescript.java,v 1.3 2007-01-24 09:47:48 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public abstract class GlyfDescript extends Program implements GlyphDescription { // flags public static final byte onCurve = 0x01; - public static final byte xShortVector = 0x02; - public static final byte yShortVector = 0x04; - public static final byte repeat = 0x08; - public static final byte xDual = 0x10; - public static final byte yDual = 0x20; + static final byte xShortVector = 0x02; + static final byte yShortVector = 0x04; + static final byte repeat = 0x08; + static final byte xDual = 0x10; + static final byte yDual = 0x20; - protected GlyfTable _parentTable; + final GlyfTable _parentTable; private int _glyphIndex; private final int _numberOfContours; - private final short _xMin; - private final short _yMin; - private final short _xMax; - private final short _yMax; - - protected GlyfDescript( - final GlyfTable parentTable, - final int glyphIndex, - final short numberOfContours, - final DataInput di) throws IOException { + private short _xMin; + private short _yMin; + private short _xMax; + private short _yMax; + + GlyfDescript( + GlyfTable parentTable, + int glyphIndex, + short numberOfContours, + DataInput di) throws IOException { _parentTable = parentTable; _numberOfContours = numberOfContours; _xMin = di.readShort(); @@ -88,43 +87,35 @@ public abstract class GlyfDescript extends Program implements GlyphDescription { _yMax = di.readShort(); } - public int getNumberOfContours() { + int getNumberOfContours() { 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) - .append("\n xMin: ").append(_xMin) - .append("\n yMin: ").append(_yMin) - .append("\n xMax: ").append(_xMax) - .append("\n yMax: ").append(_yMax) - .toString(); + return " numberOfContours: " + _numberOfContours + + "\n xMin: " + _xMin + + "\n yMin: " + _yMin + + "\n xMax: " + _xMax + + "\n yMax: " + _yMax; } } 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 041c0f04c..406c64f45 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 @@ -52,28 +52,26 @@ package jogamp.graph.font.typecast.ot.table; import java.io.DataInput; import java.io.IOException; - import jogamp.graph.font.typecast.ot.Disassembler; /** - * @version $Id: GlyfSimpleDescript.java,v 1.3 2007-01-24 09:47:47 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class GlyfSimpleDescript extends GlyfDescript { - private final int[] _endPtsOfContours; - private final byte[] _flags; - private final short[] _xCoordinates; - private final short[] _yCoordinates; - private final int _count; + private int[] _endPtsOfContours; + private byte[] _flags; + private short[] _xCoordinates; + private short[] _yCoordinates; + private int _count; public GlyfSimpleDescript( - final GlyfTable parentTable, - final int glyphIndex, - final short numberOfContours, - final DataInput di) throws IOException { + GlyfTable parentTable, + int glyphIndex, + short numberOfContours, + DataInput di) throws IOException { super(parentTable, glyphIndex, numberOfContours, di); - + // Simple glyph description _endPtsOfContours = new int[numberOfContours]; for (int i = 0; i < numberOfContours; i++) { @@ -86,43 +84,36 @@ public class GlyfSimpleDescript extends GlyfDescript { _xCoordinates = new short[_count]; _yCoordinates = new short[_count]; - final int instructionCount = di.readShort(); + int instructionCount = di.readShort(); readInstructions(di, instructionCount); readFlags(_count, di); readCoords(_count, di); } - @Override - public int getEndPtOfContours(final int i) { + public int getEndPtOfContours(int i) { return _endPtsOfContours[i]; } - @Override - public byte getFlags(final int i) { + public byte getFlags(int i) { return _flags[i]; } - @Override - public short getXCoordinate(final int i) { + public short getXCoordinate(int i) { return _xCoordinates[i]; } - @Override - public short getYCoordinate(final int i) { + public short getYCoordinate(int i) { return _yCoordinates[i]; } - @Override public boolean isComposite() { return false; } - @Override public int getPointCount() { return _count; } - @Override public int getContourCount() { return getNumberOfContours(); } @@ -138,7 +129,7 @@ public class GlyfSimpleDescript extends GlyfDescript { /** * The table is stored as relative values, but we'll store them as absolutes */ - private void readCoords(final int count, final DataInput di) throws IOException { + private void readCoords(int count, DataInput di) throws IOException { short x = 0; short y = 0; for (int i = 0; i < count; i++) { @@ -175,26 +166,25 @@ public class GlyfSimpleDescript extends GlyfDescript { /** * The flags are run-length encoded */ - private void readFlags(final int flagCount, final DataInput di) throws IOException { + private void readFlags(int flagCount, DataInput di) throws IOException { try { for (int index = 0; index < flagCount; index++) { _flags[index] = di.readByte(); if ((_flags[index] & repeat) != 0) { - final int repeats = di.readByte(); + int repeats = di.readByte(); for (int i = 1; i <= repeats; i++) { _flags[index + i] = _flags[index]; } index += repeats; } } - } catch (final ArrayIndexOutOfBoundsException e) { + } catch (ArrayIndexOutOfBoundsException e) { System.out.println("error: array index out of bounds"); } } - - @Override + public String toString() { - final StringBuilder sb = new StringBuilder(); + 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 6750e9394..ad59f95cd 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 @@ -56,35 +56,32 @@ import java.io.DataInputStream; import java.io.IOException; /** - * @version $Id: GlyfTable.java,v 1.6 2010-08-10 11:46:30 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class GlyfTable implements Table { - private final DirectoryEntry _de; private final GlyfDescript[] _descript; - protected GlyfTable( - final DirectoryEntry de, - final DataInput di, - final MaxpTable maxp, - final LocaTable loca) throws IOException { - _de = (DirectoryEntry) de.clone(); + public GlyfTable( + DataInput di, + int length, + MaxpTable maxp, + LocaTable loca) throws IOException { _descript = new GlyfDescript[maxp.getNumGlyphs()]; - + // Buffer the whole table so we can randomly access it - final byte[] buf = new byte[de.getLength()]; + byte[] buf = new byte[length]; di.readFully(buf); - final ByteArrayInputStream bais = new ByteArrayInputStream(buf); - + ByteArrayInputStream bais = new ByteArrayInputStream(buf); + // Process all the simple glyphs for (int i = 0; i < maxp.getNumGlyphs(); i++) { - final int len = loca.getOffset(i + 1) - loca.getOffset(i); + int len = loca.getOffset(i + 1) - loca.getOffset(i); if (len > 0) { bais.reset(); bais.skip(loca.getOffset(i)); - final DataInputStream dis = new DataInputStream(bais); - final short numberOfContours = dis.readShort(); + DataInputStream dis = new DataInputStream(bais); + short numberOfContours = dis.readShort(); if (numberOfContours >= 0) { _descript[i] = new GlyfSimpleDescript(this, i, numberOfContours, dis); } @@ -95,12 +92,12 @@ public class GlyfTable implements Table { // Now do all the composite glyphs for (int i = 0; i < maxp.getNumGlyphs(); i++) { - final int len = loca.getOffset(i + 1) - loca.getOffset(i); + int len = loca.getOffset(i + 1) - loca.getOffset(i); if (len > 0) { bais.reset(); bais.skip(loca.getOffset(i)); - final DataInputStream dis = new DataInputStream(bais); - final short numberOfContours = dis.readShort(); + DataInputStream dis = new DataInputStream(bais); + short numberOfContours = dis.readShort(); if (numberOfContours < 0) { _descript[i] = new GlyfCompositeDescript(this, i, dis); } @@ -108,7 +105,7 @@ public class GlyfTable implements Table { } } - public GlyfDescript getDescription(final int i) { + public GlyfDescript getDescription(int i) { if (i < _descript.length) { return _descript[i]; } else { @@ -116,19 +113,4 @@ 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 025778dfc..59b85637d 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 @@ -52,34 +52,33 @@ package jogamp.graph.font.typecast.ot.table; /** * Specifies access to glyph description classes, simple and composite. - * @version $Id: GlyphDescription.java,v 1.3 2007-01-24 09:47:45 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @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(); + + int getGlyphIndex(); + + int getEndPtOfContours(int i); + + byte getFlags(int i); + + short getXCoordinate(int i); + + short getYCoordinate(int i); + + short getXMaximum(); + + short getXMinimum(); + + short getYMaximum(); + + short getYMinimum(); + + boolean isComposite(); + + int getPointCount(); + + int getContourCount(); // public int getComponentIndex(int c); // public int getComponentCount(); 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 ce6f308db..1919a83f7 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 @@ -1,6 +1,4 @@ /* - * $Id: GposTable.java,v 1.2 2007-01-24 09:47:47 davidsch Exp $ - * * Typecast - The Font Development Environment * * Copyright (c) 2004 David Schweinsberg @@ -25,45 +23,21 @@ import java.io.IOException; /** * TODO: To be implemented - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: GposTable.java,v 1.2 2007-01-24 09:47:47 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class GposTable implements Table { - - private final DirectoryEntry _de; +class GposTable implements Table { - protected GposTable(final DirectoryEntry de, final DataInput di) throws IOException { - _de = (DirectoryEntry) de.clone(); + protected GposTable(DataInput di) throws IOException { // GPOS Header - /* 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; + int version = di.readInt(); + int scriptList = di.readInt(); + int featureList = di.readInt(); + int lookupList = di.readInt(); } - @Override public String toString() { return "GPOS"; } - /** - * 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/GsubTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/GsubTable.java index 3147fc8c5..ca625a52f 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 @@ -57,53 +57,49 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: GsubTable.java,v 1.3 2007-01-24 09:47:46 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class GsubTable implements Table, LookupSubtableFactory { - 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(); + private ScriptList _scriptList; + private FeatureList _featureList; + private LookupList _lookupList; + + protected GsubTable(DataInput di, int length) throws IOException { // Load into a temporary buffer, and create another input stream - final byte[] buf = new byte[de.getLength()]; + byte[] buf = new byte[length]; di.readFully(buf); - final DataInputStream dis = new DataInputStream(new ByteArrayInputStream(buf)); + DataInputStream dis = new DataInputStream(new ByteArrayInputStream(buf)); // GSUB Header - /* final int version = */ dis.readInt(); - final int scriptListOffset = dis.readUnsignedShort(); - final int featureListOffset = dis.readUnsignedShort(); - final int lookupListOffset = dis.readUnsignedShort(); + int version = dis.readInt(); + int scriptListOffset = dis.readUnsignedShort(); + int featureListOffset = dis.readUnsignedShort(); + 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( - final int type, - final DataInputStream dis, - final int offset) throws IOException { + int type, + DataInputStream dis, + int offset) throws IOException { LookupSubtable s = null; switch (type) { case 1: @@ -128,14 +124,6 @@ public class GsubTable implements Table, LookupSubtableFactory { return s; } - /** Get the table type, as a table directory value. - * @return The table type - */ - @Override - public int getType() { - return GSUB; - } - public ScriptList getScriptList() { return _scriptList; } @@ -148,12 +136,11 @@ public class GsubTable implements Table, LookupSubtableFactory { return _lookupList; } - @Override public String toString() { return "GSUB"; } - public static String lookupTypeAsString(final int type) { + public static String lookupTypeAsString(int type) { switch (type) { case 1: return "Single"; @@ -171,15 +158,4 @@ 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 2bd51c124..34578a8de 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 @@ -1,6 +1,4 @@ /* - * $Id: HdmxTable.java,v 1.2 2007-07-26 11:12:30 davidsch Exp $ - * * Typecast - The Font Development Environment * * Copyright (c) 2004-2007 David Schweinsberg @@ -26,18 +24,16 @@ import java.io.IOException; /** * The Horizontal Device Metrics table for TrueType outlines. This stores * integer advance widths scaled to specific pixel sizes. - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: HdmxTable.java,v 1.2 2007-07-26 11:12:30 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class HdmxTable implements Table { 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 { + DeviceRecord(final int numGlyphs, final DataInput di) throws IOException { _pixelSize = di.readByte(); _maxWidth = di.readByte(); _widths = new short[numGlyphs]; @@ -61,19 +57,16 @@ public class HdmxTable implements Table { public short getWidth(final int glyphidx) { return _widths[glyphidx]; } - } - private final DirectoryEntry _de; private final int _version; private final short _numRecords; private final int _sizeDeviceRecords; private final DeviceRecord[] _records; + private final int _length; /** Creates a new instance of HdmxTable */ - protected HdmxTable(final DirectoryEntry de, final DataInput di, final MaxpTable maxp) - throws IOException { - _de = (DirectoryEntry) de.clone(); + public HdmxTable(final DataInput di, final int length, final MaxpTable maxp) throws IOException { _version = di.readUnsignedShort(); _numRecords = di.readShort(); _sizeDeviceRecords = di.readInt(); @@ -83,6 +76,7 @@ public class HdmxTable implements Table { for (int i = 0; i < _numRecords; ++i) { _records[i] = new DeviceRecord(maxp.getNumGlyphs(), di); } + _length = length; } public int getNumberOfRecords() { @@ -94,15 +88,10 @@ public class HdmxTable implements Table { } @Override - public int getType() { - return hdmx; - } - - @Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("'hdmx' Table - Horizontal Device Metrics\n----------------------------------------\n"); - sb.append("Size = ").append(_de.getLength()).append(" bytes\n") + sb.append("Size = ").append(_length).append(" bytes\n") .append("\t'hdmx' version: ").append(_version).append("\n") .append("\t# device records: ").append(_numRecords).append("\n") .append("\tRecord length: ").append(_sizeDeviceRecords).append("\n"); @@ -120,14 +109,4 @@ public class HdmxTable 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/HeadTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/HeadTable.java index 7d00479df..e5a5f5201 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 @@ -55,14 +55,11 @@ import java.io.IOException; import jogamp.graph.font.typecast.ot.Fixed; - /** - * @version $Id: HeadTable.java,v 1.2 2004-12-21 10:23:20 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class HeadTable implements Table { - private final DirectoryEntry _de; private final int _versionNumber; private final int _fontRevision; private final int _checkSumAdjustment; @@ -81,8 +78,7 @@ public class HeadTable implements Table { private final short _indexToLocFormat; private final short _glyphDataFormat; - protected HeadTable(final DirectoryEntry de, final DataInput di) throws IOException { - this._de = (DirectoryEntry) de.clone(); + public HeadTable(final DataInput di) throws IOException { _versionNumber = di.readInt(); _fontRevision = di.readInt(); _checkSumAdjustment = di.readInt(); @@ -142,7 +138,6 @@ public class HeadTable implements Table { return _modified; } - @Override public int getType() { return head; } @@ -173,37 +168,24 @@ public class HeadTable implements Table { @Override public String toString() { - return new StringBuilder() - .append("'head' Table - Font Header\n--------------------------") - .append("\n 'head' version: ").append(Fixed.floatValue(_versionNumber)) - .append("\n fontRevision: ").append(Fixed.roundedFloatValue(_fontRevision, 8)) - .append("\n checkSumAdjustment: 0x").append(Integer.toHexString(_checkSumAdjustment).toUpperCase()) - .append("\n magicNumber: 0x").append(Integer.toHexString(_magicNumber).toUpperCase()) - .append("\n flags: 0x").append(Integer.toHexString(_flags).toUpperCase()) - .append("\n unitsPerEm: ").append(_unitsPerEm) - .append("\n created: ").append(_created) - .append("\n modified: ").append(_modified) - .append("\n xMin: ").append(_xMin) - .append("\n yMin: ").append(_yMin) - .append("\n xMax: ").append(_xMax) - .append("\n yMax: ").append(_yMax) - .append("\n macStyle bits: ").append(Integer.toHexString(_macStyle).toUpperCase()) - .append("\n lowestRecPPEM: ").append(_lowestRecPPEM) - .append("\n fontDirectionHint: ").append(_fontDirectionHint) - .append("\n indexToLocFormat: ").append(_indexToLocFormat) - .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; + return "'head' Table - Font Header\n--------------------------" + + "\n 'head' version: " + Fixed.floatValue(_versionNumber) + + "\n fontRevision: " + Fixed.roundedFloatValue(_fontRevision, 8) + + "\n checkSumAdjustment: 0x" + Integer.toHexString(_checkSumAdjustment).toUpperCase() + + "\n magicNumber: 0x" + Integer.toHexString(_magicNumber).toUpperCase() + + "\n flags: 0x" + Integer.toHexString(_flags).toUpperCase() + + "\n unitsPerEm: " + _unitsPerEm + + "\n created: " + _created + + "\n modified: " + _modified + + "\n xMin: " + _xMin + + "\n yMin: " + _yMin + + "\n xMax: " + _xMax + + "\n yMax: " + _yMax + + "\n macStyle bits: " + Integer.toHexString(_macStyle).toUpperCase() + + "\n lowestRecPPEM: " + _lowestRecPPEM + + "\n fontDirectionHint: " + _fontDirectionHint + + "\n indexToLocFormat: " + _indexToLocFormat + + "\n glyphDataFormat: " + _glyphDataFormat; } } 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 e67a03777..333b36f56 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,40 +1,36 @@ /***************************************************************************** * 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; import java.io.DataInput; import java.io.IOException; - import jogamp.graph.font.typecast.ot.Fixed; /** - * @version $Id: HheaTable.java,v 1.2 2010-08-10 11:44:02 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class HheaTable implements Table { - 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(); + 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; + + public HheaTable(DataInput di) throws IOException { version = di.readInt(); ascender = di.readShort(); descender = di.readShort(); @@ -92,48 +88,29 @@ public class HheaTable implements Table { return numberOfHMetrics; } - @Override - public int getType() { - return hhea; - } - public short getXMaxExtent() { return xMaxExtent; } - @Override public String toString() { - return new StringBuilder() - .append("'hhea' Table - Horizontal Header\n--------------------------------") - .append("\n 'hhea' version: ").append(Fixed.floatValue(version)) - .append("\n yAscender: ").append(ascender) - .append("\n yDescender: ").append(descender) - .append("\n yLineGap: ").append(lineGap) - .append("\n advanceWidthMax: ").append(advanceWidthMax) - .append("\n minLeftSideBearing: ").append(minLeftSideBearing) - .append("\n minRightSideBearing: ").append(minRightSideBearing) - .append("\n xMaxExtent: ").append(xMaxExtent) - .append("\n horizCaretSlopeNum: ").append(caretSlopeRise) - .append("\n horizCaretSlopeDenom: ").append(caretSlopeRun) - .append("\n reserved0: 0") - .append("\n reserved1: 0") - .append("\n reserved2: 0") - .append("\n reserved3: 0") - .append("\n reserved4: 0") - .append("\n metricDataFormat: ").append(metricDataFormat) - .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; + return "'hhea' Table - Horizontal Header\n--------------------------------" + + "\n 'hhea' version: " + Fixed.floatValue(version) + + "\n yAscender: " + ascender + + "\n yDescender: " + descender + + "\n yLineGap: " + lineGap + + "\n advanceWidthMax: " + advanceWidthMax + + "\n minLeftSideBearing: " + minLeftSideBearing + + "\n minRightSideBearing: " + minRightSideBearing + + "\n xMaxExtent: " + xMaxExtent + + "\n horizCaretSlopeNum: " + caretSlopeRise + + "\n horizCaretSlopeDenom: " + caretSlopeRun + + "\n reserved0: 0" + + "\n reserved1: 0" + + "\n reserved2: 0" + + "\n reserved3: 0" + + "\n reserved4: 0" + + "\n metricDataFormat: " + metricDataFormat + + "\n numOf_LongHorMetrics: " + numberOfHMetrics; } } 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 3a9672a92..090eca65c 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 @@ -54,21 +54,19 @@ import java.io.DataInput; import java.io.IOException; /** - * @version $Id: HmtxTable.java,v 1.5 2007-07-26 11:11:48 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class HmtxTable implements Table { - private final DirectoryEntry _de; - private int[] _hMetrics = null; - private short[] _leftSideBearing = null; + private int[] _hMetrics; + private short[] _leftSideBearing; + private int _length; - protected HmtxTable( - final DirectoryEntry de, - final DataInput di, - final HheaTable hhea, - final MaxpTable maxp) throws IOException { - _de = (DirectoryEntry) de.clone(); + public HmtxTable( + DataInput di, + int length, + HheaTable hhea, + MaxpTable maxp) throws IOException { _hMetrics = new int[hhea.getNumberOfHMetrics()]; for (int i = 0; i < hhea.getNumberOfHMetrics(); ++i) { _hMetrics[i] = @@ -77,14 +75,15 @@ public class HmtxTable implements Table { | di.readUnsignedByte()<<8 | di.readUnsignedByte(); } - final int lsbCount = maxp.getNumGlyphs() - hhea.getNumberOfHMetrics(); + int lsbCount = maxp.getNumGlyphs() - hhea.getNumberOfHMetrics(); _leftSideBearing = new short[lsbCount]; for (int i = 0; i < lsbCount; ++i) { _leftSideBearing[i] = di.readShort(); } + _length = length; } - public int getAdvanceWidth(final int i) { + public int getAdvanceWidth(int i) { if (_hMetrics == null) { return 0; } @@ -95,7 +94,7 @@ public class HmtxTable implements Table { } } - public short getLeftSideBearing(final int i) { + public short getLeftSideBearing(int i) { if (_hMetrics == null) { return 0; } @@ -106,16 +105,10 @@ public class HmtxTable implements Table { } } - @Override - public int getType() { - return hmtx; - } - - @Override public String toString() { - final StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(); sb.append("'hmtx' Table - Horizontal Metrics\n---------------------------------\n"); - sb.append("Size = ").append(_de.getLength()).append(" bytes, ") + sb.append("Size = ").append(_length).append(" bytes, ") .append(_hMetrics.length).append(" entries\n"); for (int i = 0; i < _hMetrics.length; i++) { sb.append(" ").append(i) @@ -131,14 +124,4 @@ public class HmtxTable 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/ID.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ID.java index ad7e4e376..e3aa6523c 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 @@ -1,9 +1,7 @@ /* - * $Id: ID.java,v 1.1.1.1 2004-12-05 23:14:47 davidsch Exp $ - * * Typecast - The Font Development Environment * - * Copyright (c) 2004 David Schweinsberg + * Copyright (c) 2004-2016 David Schweinsberg * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +20,7 @@ package jogamp.graph.font.typecast.ot.table; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ID.java,v 1.1.1.1 2004-12-05 23:14:47 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public abstract class ID { @@ -34,163 +31,166 @@ public abstract class ID { public static final short platformMicrosoft = 3; // Unicode Encoding IDs - public static final short encodingUnicode10Semantics = 0; - public static final short encodingUnicode11Semantics = 1; - public static final short encodingISO10646Semantics = 2; - public static final short encodingUnicode20Semantics = 3; - + private static final short encodingUnicode10Semantics = 0; + private static final short encodingUnicode11Semantics = 1; + private static final short encodingISO10646Semantics = 2; + private static final short encodingUnicode20SemanticsBMPOnly = 3; + private static final short encodingUnicode20Semantics = 4; + private static final short encodingUnicodeVariationSequences = 5; + private static final short encodingFullUnicodeCoverage = 6; + // Microsoft Encoding IDs // public static final short encodingUndefined = 0; // public static final short encodingUGL = 1; public static final short encodingSymbol = 0; public static final short encodingUnicode = 1; - public static final short encodingShiftJIS = 2; - public static final short encodingPRC = 3; - public static final short encodingBig5 = 4; - public static final short encodingWansung = 5; - public static final short encodingJohab = 6; - public static final short encodingUCS4 = 10; + private static final short encodingShiftJIS = 2; + private static final short encodingPRC = 3; + private static final short encodingBig5 = 4; + private static final short encodingWansung = 5; + private static final short encodingJohab = 6; + private static final short encodingUCS4 = 10; // Macintosh Encoding IDs public static final short encodingRoman = 0; - public static final short encodingJapanese = 1; - public static final short encodingChinese = 2; - public static final short encodingKorean = 3; - public static final short encodingArabic = 4; - public static final short encodingHebrew = 5; - public static final short encodingGreek = 6; - public static final short encodingRussian = 7; - public static final short encodingRSymbol = 8; - public static final short encodingDevanagari = 9; - public static final short encodingGurmukhi = 10; - public static final short encodingGujarati = 11; - public static final short encodingOriya = 12; - public static final short encodingBengali = 13; - public static final short encodingTamil = 14; - public static final short encodingTelugu = 15; - public static final short encodingKannada = 16; - public static final short encodingMalayalam = 17; - public static final short encodingSinhalese = 18; - public static final short encodingBurmese = 19; - public static final short encodingKhmer = 20; - public static final short encodingThai = 21; - public static final short encodingLaotian = 22; - public static final short encodingGeorgian = 23; - public static final short encodingArmenian = 24; - public static final short encodingMaldivian = 25; - public static final short encodingTibetan = 26; - public static final short encodingMongolian = 27; - public static final short encodingGeez = 28; - public static final short encodingSlavic = 29; - public static final short encodingVietnamese = 30; - public static final short encodingSindhi = 31; - public static final short encodingUninterp = 32; + private static final short encodingJapanese = 1; + private static final short encodingChinese = 2; + private static final short encodingKorean = 3; + private static final short encodingArabic = 4; + private static final short encodingHebrew = 5; + private static final short encodingGreek = 6; + private static final short encodingRussian = 7; + private static final short encodingRSymbol = 8; + private static final short encodingDevanagari = 9; + private static final short encodingGurmukhi = 10; + private static final short encodingGujarati = 11; + private static final short encodingOriya = 12; + private static final short encodingBengali = 13; + private static final short encodingTamil = 14; + private static final short encodingTelugu = 15; + private static final short encodingKannada = 16; + private static final short encodingMalayalam = 17; + private static final short encodingSinhalese = 18; + private static final short encodingBurmese = 19; + private static final short encodingKhmer = 20; + private static final short encodingThai = 21; + private static final short encodingLaotian = 22; + private static final short encodingGeorgian = 23; + private static final short encodingArmenian = 24; + private static final short encodingMaldivian = 25; + private static final short encodingTibetan = 26; + private static final short encodingMongolian = 27; + private static final short encodingGeez = 28; + private static final short encodingSlavic = 29; + private static final short encodingVietnamese = 30; + private static final short encodingSindhi = 31; + private static final short encodingUninterp = 32; // ISO Encoding IDs - public static final short encodingASCII = 0; - public static final short encodingISO10646 = 1; - public static final short encodingISO8859_1 = 2; + private static final short encodingASCII = 0; + private static final short encodingISO10646 = 1; + private static final short encodingISO8859_1 = 2; // Microsoft Language IDs - public static final short languageSQI = 0x041c; - public static final short languageEUQ = 0x042d; - public static final short languageBEL = 0x0423; - public static final short languageBGR = 0x0402; - public static final short languageCAT = 0x0403; - public static final short languageSHL = 0x041a; - public static final short languageCSY = 0x0405; - public static final short languageDAN = 0x0406; - public static final short languageNLD = 0x0413; - public static final short languageNLB = 0x0813; - public static final short languageENU = 0x0409; - public static final short languageENG = 0x0809; - public static final short languageENA = 0x0c09; - public static final short languageENC = 0x1009; - public static final short languageENZ = 0x1409; - public static final short languageENI = 0x1809; - public static final short languageETI = 0x0425; - public static final short languageFIN = 0x040b; - public static final short languageFRA = 0x040c; - public static final short languageFRB = 0x080c; - public static final short languageFRC = 0x0c0c; - public static final short languageFRS = 0x100c; - public static final short languageFRL = 0x140c; - public static final short languageDEU = 0x0407; - public static final short languageDES = 0x0807; - public static final short languageDEA = 0x0c07; - public static final short languageDEL = 0x1007; - public static final short languageDEC = 0x1407; - public static final short languageELL = 0x0408; - public static final short languageHUN = 0x040e; - public static final short languageISL = 0x040f; - public static final short languageITA = 0x0410; - public static final short languageITS = 0x0810; - public static final short languageLVI = 0x0426; - public static final short languageLTH = 0x0427; - public static final short languageNOR = 0x0414; - public static final short languageNON = 0x0814; - public static final short languagePLK = 0x0415; - public static final short languagePTB = 0x0416; - public static final short languagePTG = 0x0816; - public static final short languageROM = 0x0418; - public static final short languageRUS = 0x0419; - public static final short languageSKY = 0x041b; - public static final short languageSLV = 0x0424; - public static final short languageESP = 0x040a; - public static final short languageESM = 0x080a; - public static final short languageESN = 0x0c0a; - public static final short languageSVE = 0x041d; - public static final short languageTRK = 0x041f; - public static final short languageUKR = 0x0422; + private static final short languageSQI = 0x041c; + private static final short languageEUQ = 0x042d; + private static final short languageBEL = 0x0423; + private static final short languageBGR = 0x0402; + private static final short languageCAT = 0x0403; + private static final short languageSHL = 0x041a; + private static final short languageCSY = 0x0405; + private static final short languageDAN = 0x0406; + private static final short languageNLD = 0x0413; + private static final short languageNLB = 0x0813; + private static final short languageENU = 0x0409; + private static final short languageENG = 0x0809; + private static final short languageENA = 0x0c09; + private static final short languageENC = 0x1009; + private static final short languageENZ = 0x1409; + private static final short languageENI = 0x1809; + private static final short languageETI = 0x0425; + private static final short languageFIN = 0x040b; + private static final short languageFRA = 0x040c; + private static final short languageFRB = 0x080c; + private static final short languageFRC = 0x0c0c; + private static final short languageFRS = 0x100c; + private static final short languageFRL = 0x140c; + private static final short languageDEU = 0x0407; + private static final short languageDES = 0x0807; + private static final short languageDEA = 0x0c07; + private static final short languageDEL = 0x1007; + private static final short languageDEC = 0x1407; + private static final short languageELL = 0x0408; + private static final short languageHUN = 0x040e; + private static final short languageISL = 0x040f; + private static final short languageITA = 0x0410; + private static final short languageITS = 0x0810; + private static final short languageLVI = 0x0426; + private static final short languageLTH = 0x0427; + private static final short languageNOR = 0x0414; + private static final short languageNON = 0x0814; + private static final short languagePLK = 0x0415; + private static final short languagePTB = 0x0416; + private static final short languagePTG = 0x0816; + private static final short languageROM = 0x0418; + private static final short languageRUS = 0x0419; + private static final short languageSKY = 0x041b; + private static final short languageSLV = 0x0424; + private static final short languageESP = 0x040a; + private static final short languageESM = 0x080a; + private static final short languageESN = 0x0c0a; + private static final short languageSVE = 0x041d; + private static final short languageTRK = 0x041f; + private static final short languageUKR = 0x0422; // Macintosh Language IDs - public static final short languageEnglish = 0; - public static final short languageFrench = 1; - public static final short languageGerman = 2; - public static final short languageItalian = 3; - public static final short languageDutch = 4; - public static final short languageSwedish = 5; - public static final short languageSpanish = 6; - public static final short languageDanish = 7; - public static final short languagePortuguese = 8; - public static final short languageNorwegian = 9; - public static final short languageHebrew = 10; - public static final short languageJapanese = 11; - public static final short languageArabic = 12; - public static final short languageFinnish = 13; - public static final short languageGreek = 14; - public static final short languageIcelandic = 15; - public static final short languageMaltese = 16; - public static final short languageTurkish = 17; - public static final short languageYugoslavian = 18; - public static final short languageChinese = 19; - public static final short languageUrdu = 20; - public static final short languageHindi = 21; - public static final short languageThai = 22; + private static final short languageEnglish = 0; + private static final short languageFrench = 1; + private static final short languageGerman = 2; + private static final short languageItalian = 3; + private static final short languageDutch = 4; + private static final short languageSwedish = 5; + private static final short languageSpanish = 6; + private static final short languageDanish = 7; + private static final short languagePortuguese = 8; + private static final short languageNorwegian = 9; + private static final short languageHebrew = 10; + private static final short languageJapanese = 11; + private static final short languageArabic = 12; + private static final short languageFinnish = 13; + private static final short languageGreek = 14; + private static final short languageIcelandic = 15; + private static final short languageMaltese = 16; + private static final short languageTurkish = 17; + private static final short languageYugoslavian = 18; + private static final short languageChinese = 19; + private static final short languageUrdu = 20; + private static final short languageHindi = 21; + private static final short languageThai = 22; // Name IDs - public static final short nameCopyrightNotice = 0; + private static final short nameCopyrightNotice = 0; public static final short nameFontFamilyName = 1; - public static final short nameFontSubfamilyName = 2; - public static final short nameUniqueFontIdentifier = 3; - public static final short nameFullFontName = 4; - public static final short nameVersionString = 5; - public static final short namePostscriptName = 6; - public static final short nameTrademark = 7; - public static final short nameManufacturerName = 8; - public static final short nameDesigner = 9; - public static final short nameDescription = 10; - public static final short nameURLVendor = 11; - public static final short nameURLDesigner = 12; - public static final short nameLicenseDescription = 13; - public static final short nameLicenseInfoURL = 14; - public static final short namePreferredFamily = 16; - public static final short namePreferredSubfamily = 17; - public static final short nameCompatibleFull = 18; - public static final short nameSampleText = 19; - public static final short namePostScriptCIDFindfontName = 20; + private static final short nameFontSubfamilyName = 2; + private static final short nameUniqueFontIdentifier = 3; + private static final short nameFullFontName = 4; + private static final short nameVersionString = 5; + private static final short namePostscriptName = 6; + private static final short nameTrademark = 7; + private static final short nameManufacturerName = 8; + private static final short nameDesigner = 9; + private static final short nameDescription = 10; + private static final short nameURLVendor = 11; + private static final short nameURLDesigner = 12; + private static final short nameLicenseDescription = 13; + private static final short nameLicenseInfoURL = 14; + private static final short namePreferredFamily = 16; + private static final short namePreferredSubfamily = 17; + private static final short nameCompatibleFull = 18; + private static final short nameSampleText = 19; + private static final short namePostScriptCIDFindfontName = 20; - public static String getPlatformName(final short platformId) { + public static String getPlatformName(short platformId) { switch (platformId) { case platformUnicode: return "Unicode"; case platformMacintosh: return "Macintosh"; @@ -200,17 +200,20 @@ public abstract class ID { } } - public static String getEncodingName(final short platformId, final short encodingId) { + public static String getEncodingName(short platformId, short encodingId) { if (platformId == platformUnicode) { - + // Unicode specific encodings switch (encodingId) { - case encodingUnicode10Semantics: return "Unicode 1.0 semantics"; - case encodingUnicode11Semantics: return "Unicode 1.1 semantics"; - case encodingISO10646Semantics: return "ISO 10646:1993 semantics"; - case encodingUnicode20Semantics: return "Unicode 2.0 and onwards semantics"; - default: return ""; + case encodingUnicode10Semantics: return "Unicode 1.0 semantics"; + case encodingUnicode11Semantics: return "Unicode 1.1 semantics"; + case encodingISO10646Semantics: return "ISO 10646:1993 semantics"; + case encodingUnicode20SemanticsBMPOnly: return "Unicode 2.0 and onwards semantics (BMP only)"; + case encodingUnicode20Semantics: return "Unicode 2.0 and onwards semantics (non-BMP allowed)"; + case encodingUnicodeVariationSequences: return "Unicode Variation Sequences"; + case encodingFullUnicodeCoverage: return "Full Unicode coverage"; + default: return ""; } } else if (platformId == platformMacintosh) { @@ -284,7 +287,7 @@ public abstract class ID { return ""; } - public static String getLanguageName(final short platformId, final short languageId) { + public static String getLanguageName(short platformId, short languageId) { if (platformId == platformMacintosh) { switch (languageId) { @@ -371,7 +374,7 @@ public abstract class ID { return ""; } - public static String getNameName(final short nameId) { + public static String getNameName(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 1cc328ad2..816b9fc74 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 @@ -11,12 +11,9 @@ package jogamp.graph.font.typecast.ot.table; import java.io.DataInput; import java.io.IOException; -import jogamp.graph.font.typecast.ot.Fixed; - /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: KernSubtable.java,v 1.1.1.1 2004-12-05 23:14:47 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public abstract class KernSubtable { private final int version; @@ -24,7 +21,7 @@ public abstract class KernSubtable { private final int coverage; /** Creates new KernSubtable */ - protected KernSubtable(final int version, final int length, final int coverage) { + KernSubtable(final int version, final int length, final int coverage) { this.version = version; this.length = length; this.coverage = coverage; @@ -50,7 +47,19 @@ public abstract class KernSubtable { public abstract int getKerningPairCount(); public abstract KerningPair getKerningPair(int i); + + public abstract void clearKerningPairs(); + public short getKerningValue(final int left_glyphid, final int right_glyphid) { + for (int i = 0; i < getKerningPairCount(); i++) { + final KerningPair kpair = getKerningPair(i); + if( kpair.getLeft() == left_glyphid && kpair.getRight() == right_glyphid ) { + return kpair.getValue(); + } + } + return 0; + } + public static KernSubtable read(final DataInput di) throws IOException { KernSubtable table = null; final int version = di.readUnsignedShort(); 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 360aa94f7..6c882451e 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 @@ -13,19 +13,18 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: KernSubtableFormat0.java,v 1.1.1.1 2004-12-05 23:14:48 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class KernSubtableFormat0 extends KernSubtable { - private final int nPairs; + private int nPairs; private final int searchRange; private final int entrySelector; private final int rangeShift; - private final KerningPair[] kerningPairs; + private KerningPair[] kerningPairs; /** Creates new KernSubtableFormat0 */ - protected KernSubtableFormat0(final int version, final int length, final int coverage, final DataInput di) throws IOException { + KernSubtableFormat0(final int version, final int length, final int coverage, final DataInput di) throws IOException { super(version, length, coverage); nPairs = di.readUnsignedShort(); searchRange = di.readUnsignedShort(); @@ -38,6 +37,12 @@ public class KernSubtableFormat0 extends KernSubtable { } @Override + public void clearKerningPairs() { + nPairs = 0; + kerningPairs = null; + } + + @Override public int getKerningPairCount() { return nPairs; } 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 79b8abc1b..393ff9731 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 @@ -13,14 +13,17 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: KernSubtableFormat2.java,v 1.1.1.1 2004-12-05 23:14:48 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class KernSubtableFormat2 extends KernSubtable { + @SuppressWarnings("unused") private final int rowWidth; + @SuppressWarnings("unused") private final int leftClassTable; + @SuppressWarnings("unused") private final int rightClassTable; + @SuppressWarnings("unused") private final int array; /** Creates new KernSubtableFormat2 */ @@ -33,6 +36,10 @@ public class KernSubtableFormat2 extends KernSubtable { } @Override + public void clearKerningPairs() { + } + + @Override public int getKerningPairCount() { return 0; } 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 bb29ceb89..4d9abe241 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 @@ -12,23 +12,18 @@ import java.io.DataInput; import java.io.IOException; /** - * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6kern.html - * https://learn.microsoft.com/en-us/typography/opentype/spec/kern * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: KernTable.java,v 1.1.1.1 2004-12-05 23:14:48 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class KernTable implements Table { - private final DirectoryEntry de; private final int version; private final int nTables; private final KernSubtable[] tables; private final KernSubtableFormat0 table0; /** Creates new KernTable */ - protected KernTable(final DirectoryEntry de, final DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); + public KernTable(final DataInput di) throws IOException { version = di.readUnsignedShort(); nTables = di.readUnsignedShort(); tables = new KernSubtable[nTables]; @@ -54,25 +49,6 @@ public class KernTable implements Table { return table0; } - /** Get the table type, as a table directory value. - * @return The table type - */ - @Override - public int getType() { - return kern; - } - - /** - * 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() { final StringBuilder sb = new StringBuilder(); 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 84c5c2872..b0af5c953 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 @@ -13,8 +13,7 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: KerningPair.java,v 1.1.1.1 2004-12-05 23:14:47 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class KerningPair { @@ -23,7 +22,7 @@ public class KerningPair { private final short value; // sint16 in FUnits /** Creates new KerningPair */ - protected KerningPair(final DataInput di) throws IOException { + 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 e12d2e2e7..fa51c4f83 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 @@ -55,18 +55,17 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: LangSys.java,v 1.2 2007-01-24 09:47:47 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class LangSys { - private final int _lookupOrder; - private final int _reqFeatureIndex; - private final int _featureCount; - private final int[] _featureIndex; - + private int _lookupOrder; + private int _reqFeatureIndex; + private int _featureCount; + private int[] _featureIndex; + /** Creates new LangSys */ - protected LangSys(final DataInput di) throws IOException { + LangSys(DataInput di) throws IOException { _lookupOrder = di.readUnsignedShort(); _reqFeatureIndex = di.readUnsignedShort(); _featureCount = di.readUnsignedShort(); @@ -75,24 +74,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(final int i) { + + public int getFeatureIndex(int i) { return _featureIndex[i]; } - protected boolean isFeatureIndexed(final int n) { + boolean isFeatureIndexed(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 08ea719f3..d8c01c555 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 @@ -55,16 +55,15 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: LangSysRecord.java,v 1.2 2007-01-24 09:47:48 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class LangSysRecord { - private final int _tag; - private final int _offset; - + private int _tag; + private int _offset; + /** Creates new LangSysRecord */ - public LangSysRecord(final DataInput di) throws IOException { + public LangSysRecord(DataInput di) throws IOException { _tag = di.readInt(); _offset = di.readUnsignedShort(); } @@ -78,11 +77,9 @@ public class LangSysRecord { } public String getTagAsString() { - return new StringBuilder() - .append((char)((_tag>>24)&0xff)) - .append((char)((_tag>>16)&0xff)) - .append((char)((_tag>>8)&0xff)) - .append((char)((_tag)&0xff)) - .toString(); + return String.valueOf((char) ((_tag >> 24) & 0xff)) + + (char) ((_tag >> 16) & 0xff) + + (char) ((_tag >> 8) & 0xff) + + (char) ((_tag) & 0xff); } } 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 dfd19e7ac..d993407c8 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 @@ -55,17 +55,16 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: Ligature.java,v 1.2 2007-01-24 09:47:48 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class Ligature { +class Ligature { - private final int _ligGlyph; - private final int _compCount; - private final int[] _components; + private int _ligGlyph; + private int _compCount; + private int[] _components; /** Creates new Ligature */ - public Ligature(final DataInput di) throws IOException { + public Ligature(DataInput di) throws IOException { _ligGlyph = di.readUnsignedShort(); _compCount = di.readUnsignedShort(); _components = new int[_compCount - 1]; @@ -73,12 +72,12 @@ public class Ligature { _components[i] = di.readUnsignedShort(); } } - + public int getGlyphCount() { return _compCount; } - - public int getGlyphId(final int i) { + + public int getGlyphId(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 8b7738992..9ce8a2092 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 @@ -55,17 +55,16 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: LigatureSet.java,v 1.2 2007-01-24 09:47:46 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class LigatureSet { +class LigatureSet { - private final int _ligatureCount; - private final int[] _ligatureOffsets; - private final Ligature[] _ligatures; + private int _ligatureCount; + private int[] _ligatureOffsets; + private Ligature[] _ligatures; /** Creates new LigatureSet */ - public LigatureSet(final DataInputStream dis, final int offset) throws IOException { + public LigatureSet(DataInputStream dis, 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 36a44a11e..af28a774c 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 @@ -55,15 +55,14 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: LigatureSubst.java,v 1.2 2007-01-24 09:47:48 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public abstract class LigatureSubst extends LookupSubtable { - public static LigatureSubst read(final DataInputStream dis, final int offset) throws IOException { + public static LigatureSubst read(DataInputStream dis, int offset) throws IOException { dis.reset(); dis.skipBytes(offset); - final int format = dis.readUnsignedShort(); + 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 02d4479b3..775746b28 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 @@ -55,21 +55,20 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: LigatureSubstFormat1.java,v 1.2 2007-01-24 09:47:47 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class LigatureSubstFormat1 extends LigatureSubst { - private final int _coverageOffset; - private final int _ligSetCount; - private final int[] _ligatureSetOffsets; - private final Coverage _coverage; - private final LigatureSet[] _ligatureSets; + private int _coverageOffset; + private int _ligSetCount; + private int[] _ligatureSetOffsets; + private Coverage _coverage; + private LigatureSet[] _ligatureSets; /** Creates new LigatureSubstFormat1 */ - protected LigatureSubstFormat1( - final DataInputStream dis, - final int offset) throws IOException { + LigatureSubstFormat1( + DataInputStream dis, + int offset) throws IOException { _coverageOffset = dis.readUnsignedShort(); _ligSetCount = dis.readUnsignedShort(); _ligatureSetOffsets = new int[_ligSetCount]; @@ -89,8 +88,7 @@ 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 a955ad3e5..0d0c115b8 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; @@ -12,23 +12,21 @@ import java.io.DataInput; import java.io.IOException; /** - * @version $Id: LocaTable.java,v 1.4 2010-08-10 11:45:43 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class LocaTable implements Table { - private final DirectoryEntry _de; - private int[] _offsets = null; - private short _factor = 0; + private int[] _offsets; + private short _factor; + private int _length; - protected LocaTable( - final DirectoryEntry de, - final DataInput di, - final HeadTable head, - final MaxpTable maxp) throws IOException { - _de = (DirectoryEntry) de.clone(); + public LocaTable( + DataInput di, + int length, + HeadTable head, + MaxpTable maxp) throws IOException { _offsets = new int[maxp.getNumGlyphs() + 1]; - final boolean shortEntries = head.getIndexToLocFormat() == 0; + boolean shortEntries = head.getIndexToLocFormat() == 0; if (shortEntries) { _factor = 2; for (int i = 0; i <= maxp.getNumGlyphs(); i++) { @@ -40,9 +38,21 @@ public class LocaTable implements Table { _offsets[i] = di.readInt(); } } + + // Check the validity of the offsets + int lastOffset = 0; + int index = 0; + for (int offset : _offsets) { + if (offset < lastOffset) { + System.err.printf("LocaTable: Offset at index %d is bad (%d < %d)%n", index, offset, lastOffset); + } + lastOffset = offset; + ++index; + } + _length = length; } - public int getOffset(final int i) { + public int getOffset(int i) { if (_offsets == null) { return 0; } @@ -50,15 +60,10 @@ public class LocaTable implements Table { } @Override - public int getType() { - return loca; - } - - @Override public String toString() { - final StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(); sb.append("'loca' Table - Index To Location Table\n--------------------------------------\n") - .append("Size = ").append(_de.getLength()).append(" bytes, ") + .append("Size = ").append(_length).append(" bytes, ") .append(_offsets.length).append(" entries\n"); for (int i = 0; i < _offsets.length; i++) { sb.append(" Idx ").append(i) @@ -66,15 +71,5 @@ 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 b80ebbee4..2deffb504 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 @@ -55,8 +55,7 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: Lookup.java,v 1.2 2007-01-24 09:47:47 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class Lookup { @@ -66,20 +65,20 @@ public class Lookup { public static final int IGNORE_BASE_MARKS = 0x0008; public static final int MARK_ATTACHMENT_TYPE = 0xFF00; - private final int _type; - private final int _flag; - private final int _subTableCount; - private final int[] _subTableOffsets; - private final LookupSubtable[] _subTables; + private int _type; + private int _flag; + private int _subTableCount; + private int[] _subTableOffsets; + private LookupSubtable[] _subTables; /** Creates new Lookup */ - public Lookup(final LookupSubtableFactory factory, final DataInputStream dis, final int offset) + public Lookup(LookupSubtableFactory factory, DataInputStream dis, 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 +101,7 @@ public class Lookup { return _subTableCount; } - public LookupSubtable getSubtable(final int i) { + public LookupSubtable getSubtable(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 6d8ca2a6c..6bae19bf4 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 @@ -55,23 +55,22 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: LookupList.java,v 1.2 2007-01-24 09:47:47 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class LookupList { - private final int _lookupCount; - private final int[] _lookupOffsets; - private final Lookup[] _lookups; + private int _lookupCount; + private int[] _lookupOffsets; + private Lookup[] _lookups; /** Creates new LookupList */ - public LookupList(final DataInputStream dis, final int offset, final LookupSubtableFactory factory) + public LookupList(DataInputStream dis, int offset, 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 +86,18 @@ public class LookupList { public int getLookupCount() { return _lookupCount; } - - public int getLookupOffset(final int i) { + + public int getLookupOffset(int i) { return _lookupOffsets[i]; } - - public Lookup getLookup(final int i) { + + public Lookup getLookup(int i) { return _lookups[i]; } - public Lookup getLookup(final Feature feature, final int index) { + public Lookup getLookup(Feature feature, int index) { if (feature.getLookupCount() > index) { - final int i = feature.getLookupListIndex(index); + int i = feature.getLookupListIndex(index); return _lookups[i]; } return null; diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LookupSubtable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LookupSubtable.java index 1d19038f3..075821092 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LookupSubtable.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/LookupSubtable.java @@ -52,8 +52,7 @@ package jogamp.graph.font.typecast.ot.table; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: LookupSubtable.java,v 1.2 2007-01-24 09:47:45 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public abstract class LookupSubtable { public abstract String getTypeAsString(); 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 ca67df7fb..3ba377831 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,18 +47,17 @@ 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 $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public interface LookupSubtableFactory { - public LookupSubtable read(int type, DataInputStream dis, int offset) +interface LookupSubtableFactory { + LookupSubtable read(int type, DataInputStream dis, int offset) throws IOException; } 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 efafe7bb6..588e5d7e6 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; @@ -13,19 +13,16 @@ import java.io.IOException; /** * - * @version $Id: LtshTable.java,v 1.1.1.1 2004-12-05 23:14:51 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class LtshTable implements Table { - - private final DirectoryEntry de; - private final int version; - private final int numGlyphs; - private final int[] yPels; +class LtshTable implements Table { + private int version; + private int numGlyphs; + private int[] yPels; + /** Creates new LtshTable */ - protected LtshTable(final DirectoryEntry de, final DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); + protected LtshTable(DataInput di) throws IOException { version = di.readUnsignedShort(); numGlyphs = di.readUnsignedShort(); yPels = new int[numGlyphs]; @@ -34,18 +31,8 @@ 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() { - final StringBuilder sb = new StringBuilder(); + 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) @@ -57,15 +44,4 @@ 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 0e9a6177f..19521726e 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,26 +1,23 @@ /***************************************************************************** * 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; import java.io.DataInput; import java.io.IOException; - import jogamp.graph.font.typecast.ot.Fixed; /** - * @version $Id: MaxpTable.java,v 1.1.1.1 2004-12-05 23:14:52 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class MaxpTable implements Table { - private final DirectoryEntry de; - private final int versionNumber; + private int versionNumber; private int numGlyphs; private int maxPoints; private int maxContours; @@ -36,10 +33,9 @@ public class MaxpTable implements Table { private int maxComponentElements; private int maxComponentDepth; - protected MaxpTable(final DirectoryEntry de, final DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); + public MaxpTable(DataInput di) throws IOException { versionNumber = di.readInt(); - + // CFF fonts use version 0.5, TrueType fonts use version 1.0 if (versionNumber == 0x00005000) { numGlyphs = di.readUnsignedShort(); @@ -121,14 +117,8 @@ public class MaxpTable implements Table { return numGlyphs; } - @Override - public int getType() { - return maxp; - } - - @Override public String toString() { - final StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(); sb.append("'maxp' Table - Maximum Profile\n------------------------------") .append("\n 'maxp' version: ").append(Fixed.floatValue(versionNumber)) .append("\n numGlyphs: ").append(numGlyphs); @@ -152,15 +142,4 @@ 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 5ac9ada29..ebb70433d 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 @@ -54,20 +54,19 @@ import java.io.DataInput; import java.io.IOException; /** - * @version $Id: NameRecord.java,v 1.2 2004-12-09 23:47:23 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class NameRecord { - 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 short _platformId; + private short _encodingId; + private short _languageId; + private short _nameId; + private short _stringLength; + private short _stringOffset; private String _record; - protected NameRecord(final DataInput di) throws IOException { + NameRecord(DataInput di) throws IOException { _platformId = di.readShort(); _encodingId = di.readShort(); _languageId = di.readShort(); @@ -75,33 +74,32 @@ 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(final StringBuilder sb) { - sb.append(_record); - return sb; + public String getRecordString() { + return _record; } - protected void loadString(final DataInput di) throws IOException { - final StringBuilder sb = new StringBuilder(); + void loadString(DataInput di) throws IOException { + 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 +111,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,18 +128,15 @@ public class NameRecord { _record = sb.toString(); } - @Override public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append(" Platform ID: ").append(_platformId) - .append("\n Specific ID: ").append(_encodingId) - .append("\n Language ID: ").append(_languageId) - .append("\n Name ID: ").append(_nameId) - .append("\n Length: ").append(_stringLength) - .append("\n Offset: ").append(_stringOffset) - .append("\n\n").append(_record); - - return sb.toString(); + String sb = " Platform ID: " + _platformId + + "\n Specific ID: " + _encodingId + + "\n Language ID: " + _languageId + + "\n Name ID: " + _nameId + + "\n Length: " + _stringLength + + "\n Offset: " + _stringOffset + + "\n\n" + _record; + return sb; } } 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 ba9292a4b..e04f89e1e 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 @@ -59,34 +59,33 @@ import java.io.IOException; * The naming table allows multilingual strings to be associated with the * OpenType font file. These strings can represent copyright notices, font * names, family names, style names, and so on. - * @version $Id: NameTable.java,v 1.2 2004-12-09 23:47:23 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class NameTable implements Table { - 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(); + + @SuppressWarnings("unused") + private short _formatSelector; + private short _numberOfNameRecords; + private short _stringStorageOffset; + private NameRecord[] _records; + + public NameTable(DataInput di, int length) throws IOException { _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 - final byte[] buffer = new byte[_de.getLength() - _stringStorageOffset]; + byte[] buffer = new byte[length - _stringStorageOffset]; di.readFully(buffer); - + // Now let the records get their hands on them for (int i = 0; i < _numberOfNameRecords; i++) { _records[i].loadString( @@ -106,44 +105,23 @@ public class NameTable implements Table { return null; } - public StringBuilder getRecordsRecordString(final StringBuilder sb, final int i) { + public String getRecordsRecordString(final int i) { if(_numberOfNameRecords > i) { - _records[i].getRecordString(sb); + return _records[i].getRecordString(); } else { - sb.append(Table.notAvailable); + return Table.notAvailable; } - return sb; } - - public StringBuilder getNamedRecordString(final StringBuilder sb, final short nameId) { + + /** Return a named record string */ + public String getRecordString(short nameId) { // Search for the first instance of this name ID - boolean done = false; - for (int i = 0; !done && i < _numberOfNameRecords; i++) { + for (int i = 0; i < _numberOfNameRecords; i++) { if (_records[i].getNameId() == nameId) { - _records[i].getRecordString(sb); - done = true; + return _records[i].getRecordString(); } } - if(!done) { - sb.append(Table.notAvailable); - } - 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; + return ""; } } 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 c91127303..f88a78d24 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 @@ -54,52 +54,49 @@ import java.io.DataInput; import java.io.IOException; /** - * @version $Id: Os2Table.java,v 1.2 2004-12-09 23:46:21 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class Os2Table implements Table { - 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 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 short _sxHeight; private short _sCapHeight; private int _usDefaultChar; private int _usBreakChar; private int _usMaxContext; - protected Os2Table(final DirectoryEntry de, final DataInput di) throws IOException { - this._de = (DirectoryEntry) de.clone(); + public Os2Table(DataInput di) throws IOException { _version = di.readUnsignedShort(); _xAvgCharWidth = di.readShort(); _usWeightClass = di.readUnsignedShort(); @@ -116,7 +113,7 @@ public class Os2Table implements Table { _yStrikeoutSize = di.readShort(); _yStrikeoutPosition = di.readShort(); _sFamilyClass = di.readShort(); - final byte[] buf = new byte[10]; + byte[] buf = new byte[10]; di.readFully(buf); _panose = new Panose(buf); _ulUnicodeRange1 = di.readInt(); @@ -134,7 +131,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,85 +273,65 @@ 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---------------------------------------") - .append("\n 'OS/2' version: ").append(_version) - .append("\n xAvgCharWidth: ").append(_xAvgCharWidth) - .append("\n usWeightClass: ").append(_usWeightClass) - .append("\n usWidthClass: ").append(_usWidthClass) - .append("\n fsType: 0x").append(Integer.toHexString(_fsType).toUpperCase()) - .append("\n ySubscriptXSize: ").append(_ySubscriptXSize) - .append("\n ySubscriptYSize: ").append(_ySubscriptYSize) - .append("\n ySubscriptXOffset: ").append(_ySubscriptXOffset) - .append("\n ySubscriptYOffset: ").append(_ySubscriptYOffset) - .append("\n ySuperscriptXSize: ").append(_ySuperscriptXSize) - .append("\n ySuperscriptYSize: ").append(_ySuperscriptYSize) - .append("\n ySuperscriptXOffset: ").append(_ySuperscriptXOffset) - .append("\n ySuperscriptYOffset: ").append(_ySuperscriptYOffset) - .append("\n yStrikeoutSize: ").append(_yStrikeoutSize) - .append("\n yStrikeoutPosition: ").append(_yStrikeoutPosition) - .append("\n sFamilyClass: ").append(_sFamilyClass>>8) - .append(" subclass = ").append(_sFamilyClass&0xff) - .append("\n PANOSE: ").append(_panose.toString()) - .append("\n Unicode Range 1( Bits 0 - 31 ): ").append(Integer.toHexString(_ulUnicodeRange1).toUpperCase()) - .append("\n Unicode Range 2( Bits 32- 63 ): ").append(Integer.toHexString(_ulUnicodeRange2).toUpperCase()) - .append("\n Unicode Range 3( Bits 64- 95 ): ").append(Integer.toHexString(_ulUnicodeRange3).toUpperCase()) - .append("\n Unicode Range 4( Bits 96-127 ): ").append(Integer.toHexString(_ulUnicodeRange4).toUpperCase()) - .append("\n achVendID: '").append(getVendorIDAsString()) - .append("'\n fsSelection: 0x").append(Integer.toHexString(_fsSelection).toUpperCase()) - .append("\n usFirstCharIndex: 0x").append(Integer.toHexString(_usFirstCharIndex).toUpperCase()) - .append("\n usLastCharIndex: 0x").append(Integer.toHexString(_usLastCharIndex).toUpperCase()) - .append("\n sTypoAscender: ").append(_sTypoAscender) - .append("\n sTypoDescender: ").append(_sTypoDescender) - .append("\n sTypoLineGap: ").append(_sTypoLineGap) - .append("\n usWinAscent: ").append(_usWinAscent) - .append("\n usWinDescent: ").append(_usWinDescent) - .append("\n CodePage Range 1( Bits 0 - 31 ): ").append(Integer.toHexString(_ulCodePageRange1).toUpperCase()) - .append("\n CodePage Range 2( Bits 32- 63 ): ").append(Integer.toHexString(_ulCodePageRange2).toUpperCase()) - .toString(); - } - + return "'OS/2' Table - OS/2 and Windows Metrics\n---------------------------------------" + + "\n 'OS/2' version: " + _version + + "\n xAvgCharWidth: " + _xAvgCharWidth + + "\n usWeightClass: " + _usWeightClass + + "\n usWidthClass: " + _usWidthClass + + "\n fsType: 0x" + Integer.toHexString(_fsType).toUpperCase() + + "\n ySubscriptXSize: " + _ySubscriptXSize + + "\n ySubscriptYSize: " + _ySubscriptYSize + + "\n ySubscriptXOffset: " + _ySubscriptXOffset + + "\n ySubscriptYOffset: " + _ySubscriptYOffset + + "\n ySuperscriptXSize: " + _ySuperscriptXSize + + "\n ySuperscriptYSize: " + _ySuperscriptYSize + + "\n ySuperscriptXOffset: " + _ySuperscriptXOffset + + "\n ySuperscriptYOffset: " + _ySuperscriptYOffset + + "\n yStrikeoutSize: " + _yStrikeoutSize + + "\n yStrikeoutPosition: " + _yStrikeoutPosition + + "\n sFamilyClass: " + (_sFamilyClass >> 8) + + " subclass = " + (_sFamilyClass & 0xff) + + "\n PANOSE: " + _panose.toString() + + "\n Unicode Range 1( Bits 0 - 31 ): " + Integer.toHexString(_ulUnicodeRange1).toUpperCase() + + "\n Unicode Range 2( Bits 32- 63 ): " + Integer.toHexString(_ulUnicodeRange2).toUpperCase() + + "\n Unicode Range 3( Bits 64- 95 ): " + Integer.toHexString(_ulUnicodeRange3).toUpperCase() + + "\n Unicode Range 4( Bits 96-127 ): " + Integer.toHexString(_ulUnicodeRange4).toUpperCase() + + "\n achVendID: '" + getVendorIDAsString() + + "'\n fsSelection: 0x" + Integer.toHexString(_fsSelection).toUpperCase() + + "\n usFirstCharIndex: 0x" + Integer.toHexString(_usFirstCharIndex).toUpperCase() + + "\n usLastCharIndex: 0x" + Integer.toHexString(_usLastCharIndex).toUpperCase() + + "\n sTypoAscender: " + _sTypoAscender + + "\n sTypoDescender: " + _sTypoDescender + + "\n sTypoLineGap: " + _sTypoLineGap + + "\n usWinAscent: " + _usWinAscent + + "\n usWinDescent: " + _usWinDescent + + "\n CodePage Range 1( Bits 0 - 31 ): " + Integer.toHexString(_ulCodePageRange1).toUpperCase() + + "\n CodePage Range 2( Bits 32- 63 ): " + Integer.toHexString(_ulCodePageRange2).toUpperCase(); + } + private String getVendorIDAsString() { - return new StringBuilder() - .append((char)((_achVendorID>>24)&0xff)) - .append((char)((_achVendorID>>16)&0xff)) - .append((char)((_achVendorID>>8)&0xff)) - .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; + return String.valueOf((char) ((_achVendorID >> 24) & 0xff)) + + (char) ((_achVendorID >> 16) & 0xff) + + (char) ((_achVendorID >> 8) & 0xff) + + (char) ((_achVendorID) & 0xff); } + } 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 493f43baa..13f4503e9 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,32 +1,31 @@ /***************************************************************************** * 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; /** - * @version $Id: Panose.java,v 1.1.1.1 2004-12-05 23:14:54 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class Panose { - byte bFamilyType = 0; - byte bSerifStyle = 0; - byte bWeight = 0; - byte bProportion = 0; - byte bContrast = 0; - byte bStrokeVariation = 0; - byte bArmStyle = 0; - byte bLetterform = 0; - byte bMidline = 0; - byte bXHeight = 0; + private byte bFamilyType; + private byte bSerifStyle; + private byte bWeight; + private byte bProportion; + private byte bContrast; + private byte bStrokeVariation; + private byte bArmStyle; + private byte bLetterform; + private byte bMidline; + private byte bXHeight; /** Creates new Panose */ - public Panose(final byte[] panose) { + public Panose(byte[] panose) { bFamilyType = panose[0]; bSerifStyle = panose[1]; bWeight = panose[2]; @@ -42,11 +41,11 @@ public class Panose { public byte getFamilyType() { return bFamilyType; } - + public byte getSerifStyle() { return bSerifStyle; } - + public byte getWeight() { return bWeight; } @@ -54,44 +53,42 @@ 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() { - final StringBuilder sb = new StringBuilder(); - sb.append(String.valueOf(bFamilyType)).append(" ") - .append(String.valueOf(bSerifStyle)).append(" ") - .append(String.valueOf(bWeight)).append(" ") - .append(String.valueOf(bProportion)).append(" ") - .append(String.valueOf(bContrast)).append(" ") - .append(String.valueOf(bStrokeVariation)).append(" ") - .append(String.valueOf(bArmStyle)).append(" ") - .append(String.valueOf(bLetterform)).append(" ") - .append(String.valueOf(bMidline)).append(" ") - .append(String.valueOf(bXHeight)); - return sb.toString(); + String sb = String.valueOf(bFamilyType) + " " + + String.valueOf(bSerifStyle) + " " + + String.valueOf(bWeight) + " " + + String.valueOf(bProportion) + " " + + String.valueOf(bContrast) + " " + + String.valueOf(bStrokeVariation) + " " + + String.valueOf(bArmStyle) + " " + + String.valueOf(bLetterform) + " " + + String.valueOf(bMidline) + " " + + String.valueOf(bXHeight); + return sb; } } 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 63399cf0e..47c633d26 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; @@ -13,31 +13,28 @@ import java.io.IOException; /** * - * @version $Id: PcltTable.java,v 1.1.1.1 2004-12-05 23:14:54 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class PcltTable implements Table { +class PcltTable implements Table { - 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 int version; + private long fontNumber; + private int pitch; + private int xHeight; + private int style; + private int typeFamily; + private int capHeight; + private 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; + private short strokeWeight; + private short widthType; + private byte serifStyle; + private byte reserved; /** Creates new PcltTable */ - protected PcltTable(final DirectoryEntry de, final DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); + protected PcltTable(DataInput di) throws IOException { version = di.readInt(); fontNumber = di.readInt(); pitch = di.readUnsignedShort(); @@ -61,48 +58,25 @@ public class PcltTable implements Table { reserved = di.readByte(); } - /** - * 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---------------------------------------------") - .append("\n version: 0x").append(Integer.toHexString(version).toUpperCase()) - .append("\n fontNumber: ").append(fontNumber).append(" (0x").append(Long.toHexString(fontNumber).toUpperCase()) - .append(")\n pitch: ").append(pitch) - .append("\n xHeight: ").append(xHeight) - .append("\n style: 0x").append(style) - .append("\n typeFamily: 0x").append(typeFamily>>12) - .append(" ").append(typeFamily & 0xfff) - .append("\n capHeight: ").append(capHeight) - .append("\n symbolSet: ").append(symbolSet) - .append("\n typeFace: ").append(new String(typeface)) - .append("\n characterComplement 0x") - .append(Integer.toHexString(characterComplement[0]).toUpperCase()) - .append("\n fileName: ").append(new String(fileName)) - .append("\n strokeWeight: ").append(strokeWeight) - .append("\n widthType: ").append(widthType) - .append("\n serifStyle: ").append(serifStyle) - .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; + return "'PCLT' Table - Printer Command Language Table\n---------------------------------------------" + + "\n version: 0x" + Integer.toHexString(version).toUpperCase() + + "\n fontNumber: " + fontNumber + " (0x" + Long.toHexString(fontNumber).toUpperCase() + + ")\n pitch: " + pitch + + "\n xHeight: " + xHeight + + "\n style: 0x" + style + + "\n typeFamily: 0x" + (typeFamily >> 12) + + " " + (typeFamily & 0xfff) + + "\n capHeight: " + capHeight + + "\n symbolSet: " + symbolSet + + "\n typeFace: " + new String(typeface) + + "\n characterComplement 0x" + + Integer.toHexString(characterComplement[0]).toUpperCase() + + "\n fileName: " + new String(fileName) + + "\n strokeWeight: " + strokeWeight + + "\n widthType: " + widthType + + "\n serifStyle: " + serifStyle + + "\n reserved: " + reserved; } } 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 f4dd31465..3226b9d0a 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,28 +1,23 @@ /***************************************************************************** * 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; import java.io.DataInput; import java.io.IOException; - import jogamp.graph.font.typecast.ot.Fixed; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: PostTable.java,v 1.1.1.1 2004-12-05 23:14:56 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class PostTable implements Table { - /** - * TODO: Mac Glyph names for 210 & 257 - */ private static final String[] macGlyphName = { ".notdef", // 0 "null", // 1 @@ -175,15 +170,15 @@ public class PostTable implements Table { "lessequal", // 148 "greaterequal", // 149 "yen", // 150 - "mu", // 151 + "mu", // 151 "partialdiff", // 152 "summation", // 153 "product", // 154 - "pi", // 155 + "pi", // 155 "integral'", // 156 "ordfeminine", // 157 "ordmasculine", // 158 - "Omega", // 159 + "Omega", // 159 "ae", // 160 "oslash", // 161 "questiondown", // 162 @@ -234,7 +229,7 @@ public class PostTable implements Table { "Igrave", // 207 "Oacute", // 208 "Ocircumflex", // 209 - "", // 210 + "apple", // 210 "Ograve", // 211 "Uacute", // 212 "Ucircumflex", // 213 @@ -281,28 +276,26 @@ public class PostTable implements Table { "cacute", // 254 "Ccaron", // 255 "ccaron", // 256 - "" // 257 + "dcroat" // 257 }; - 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; - + 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; + // v2 private int numGlyphs; private int[] glyphNameIndex; private String[] psGlyphName; /** Creates new PostTable */ - protected PostTable(final DirectoryEntry de, final DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); + public PostTable(DataInput di) throws IOException { version = di.readInt(); italicAngle = di.readInt(); underlinePosition = di.readShort(); @@ -312,7 +305,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 +317,14 @@ public class PostTable implements Table { h -= 257; psGlyphName = new String[h]; for (int i = 0; i < h; i++) { - final int len = di.readUnsignedByte(); - final byte[] buf = new byte[len]; + int len = di.readUnsignedByte(); + 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 +342,7 @@ public class PostTable implements Table { return high; } - public String getGlyphName(final int i) { + public String getGlyphName(int i) { if (version == 0x00020000) { return (glyphNameIndex[i] > 257) ? psGlyphName[glyphNameIndex[i] - 258] @@ -359,25 +352,16 @@ public class PostTable implements Table { } } - private boolean isMacGlyphName(final int i) { + private boolean isMacGlyphName(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() { - final StringBuilder sb = new StringBuilder(); + 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)) @@ -411,16 +395,5 @@ 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 039789d62..1bd38bd85 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,50 +1,28 @@ /***************************************************************************** * 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; import java.io.DataInput; import java.io.IOException; - import jogamp.graph.font.typecast.ot.Disassembler; /** - * @version $Id: PrepTable.java,v 1.1.1.1 2004-12-05 23:14:57 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class PrepTable extends Program implements Table { - - private final DirectoryEntry de; - - public PrepTable(final DirectoryEntry de, final DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); - readInstructions(di, de.getLength()); - } +class PrepTable extends Program implements Table { - @Override - public int getType() { - return prep; + public PrepTable(DataInput di, int length) throws IOException { + readInstructions(di, length); } - @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 c0d2c1b9d..a210b6ffd 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; @@ -12,18 +12,17 @@ import java.io.DataInput; import java.io.IOException; /** - * @version $Id: Program.java,v 1.1.1.1 2004-12-05 23:14:57 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public abstract class Program { +abstract class Program { private short[] instructions; - public short[] getInstructions() { + short[] getInstructions() { return instructions; } - protected void readInstructions(final DataInput di, final int count) throws IOException { + void readInstructions(DataInput di, 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 417779703..cde656a63 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 @@ -56,32 +56,42 @@ import java.io.IOException; /** * Coverage Index (GlyphID) = StartCoverageIndex + GlyphID - Start GlyphID * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: RangeRecord.java,v 1.2 2007-01-24 09:47:47 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class RangeRecord { +class RangeRecord { private final int _start; private final int _end; private final int _startCoverageIndex; /** Creates new RangeRecord */ - public RangeRecord(final DataInput di) throws IOException { + public RangeRecord(DataInput di) throws IOException { _start = di.readUnsignedShort(); _end = di.readUnsignedShort(); _startCoverageIndex = di.readUnsignedShort(); } - public boolean isInRange(final int glyphId) { - return (_start <= glyphId && glyphId <= _end); + public int getStart() { + return _start; + } + + public int getEnd() { + return _end; + } + + public int getStartCoverageIndex() { + return _startCoverageIndex; } - public int getCoverageIndex(final int glyphId) { + private boolean isInRange(int glyphId) { + return (_start <= glyphId && glyphId <= _end); + } + + public int getCoverageIndex(int glyphId) { if (isInRange(glyphId)) { return _startCoverageIndex + glyphId - _start; } return -1; } - } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/SbixTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/SbixTable.java new file mode 100644 index 000000000..687bd4eb4 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/SbixTable.java @@ -0,0 +1,151 @@ +/* + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2016 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package jogamp.graph.font.typecast.ot.table; + +import java.io.ByteArrayInputStream; +import java.io.DataInput; +import java.io.DataInputStream; +import java.io.IOException; + +/** + * This table provides access to bitmap data in a standard graphics format + * (such as PNG, JPEG, TIFF). + * @author <a href="mailto:[email protected]">David Schweinsberg</a> + */ +public class SbixTable implements Table { + + private static final boolean DEBUG = false; + + public static class GlyphDataRecord { + private final short _originOffsetX; + private final short _originOffsetY; + private final int _graphicType; + private final byte[] _data; + + private static final int PNG = 0x706E6720; + + GlyphDataRecord(DataInput di, int dataLength) throws IOException { + _originOffsetX = di.readShort(); + _originOffsetY = di.readShort(); + _graphicType = di.readInt(); + + // Check the graphicType is valid + if (_graphicType != PNG) { + System.err.printf("SbixTable: Invalid graphicType: %d%n", _graphicType); + _data = null; + return; + } + + _data = new byte[dataLength]; + try { + di.readFully(_data); + } catch (IOException e) { + System.err.println("SbixTable: Reading too much data: "+e.getMessage()); + } + } + + public int getGraphicType() { + return _graphicType; + } + + public byte[] getData() { + return _data; + } + } + + public static class Strike { + private final int _ppem; + private final int _resolution; + private final long[] _glyphDataOffset; + private final GlyphDataRecord[] _glyphDataRecord; + + Strike(ByteArrayInputStream bais, int numGlyphs) throws IOException { + DataInput di = new DataInputStream(bais); + _ppem = di.readUnsignedShort(); + _resolution = di.readUnsignedShort(); + _glyphDataOffset = new long[numGlyphs + 1]; + for (int i = 0; i < numGlyphs + 1; ++i) { + _glyphDataOffset[i] = di.readInt(); + } + + _glyphDataRecord = new GlyphDataRecord[numGlyphs]; + for (int i = 0; i < numGlyphs; ++i) { + int dataLength = (int)(_glyphDataOffset[i + 1] - _glyphDataOffset[i]); + if (dataLength == 0) + continue; + bais.reset(); + if( DEBUG ) { + System.err.printf("SbixTable: Skip: %d%n", _glyphDataOffset[i]); + } + bais.skip(_glyphDataOffset[i]); + _glyphDataRecord[i] = new GlyphDataRecord(new DataInputStream(bais), dataLength); + } + if( DEBUG ) { + System.err.printf("SbixTable: Loaded Strike: ppem = %d, resolution = %d%n", _ppem, _resolution); + } + } + + public GlyphDataRecord[] getGlyphDataRecords() { + return _glyphDataRecord; + } + + @Override + public String toString() { + return String.format("ppem: %d, resolution: %d", _ppem, _resolution); + } + } + + private final int _version; + private final int _flags; + private final int _numStrikes; + private final int[] _strikeOffset; + private final Strike[] _strikes; + + private SbixTable(DataInput di, int length, MaxpTable maxp) throws IOException { + + // Load entire table into a buffer, and create another input stream + byte[] buf = new byte[length]; + di.readFully(buf); + DataInput di2 = new DataInputStream(getByteArrayInputStreamForOffset(buf, 0)); + + _version = di2.readUnsignedShort(); + _flags = di2.readUnsignedShort(); + _numStrikes = di2.readInt(); + _strikeOffset = new int[_numStrikes]; + for (int i = 0; i < _numStrikes; ++i) { + _strikeOffset[i] = di2.readInt(); + } + + _strikes = new Strike[_numStrikes]; + for (int i = 0; i < _numStrikes; ++i) { + ByteArrayInputStream bais = getByteArrayInputStreamForOffset(buf, _strikeOffset[i]); + _strikes[i] = new Strike(bais, maxp.getNumGlyphs()); + } + } + + private ByteArrayInputStream getByteArrayInputStreamForOffset(byte[] buf, int offset) { + return new ByteArrayInputStream( + buf, offset, + buf.length - offset); + } + + public Strike[] getStrikes() { + return _strikes; + } + +} 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 8846de5f0..5de6af283 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 @@ -55,24 +55,23 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: Script.java,v 1.2 2007-01-24 09:47:47 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class Script { - private final int _defaultLangSysOffset; - private final int _langSysCount; + private int _defaultLangSysOffset; + private int _langSysCount; private LangSysRecord[] _langSysRecords; private LangSys _defaultLangSys; private LangSys[] _langSys; - + /** Creates new ScriptTable */ - protected Script(final DataInputStream dis, final int offset) throws IOException { + Script(DataInputStream dis, 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 +101,8 @@ public class Script { public int getLangSysCount() { return _langSysCount; } - - public LangSysRecord getLangSysRecord(final int i) { + + public LangSysRecord getLangSysRecord(int i) { return _langSysRecords[i]; } @@ -111,7 +110,7 @@ public class Script { return _defaultLangSys; } - public LangSys getLangSys(final int i) { + public LangSys getLangSys(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 1c1be0d2b..3f26ea09e 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 @@ -55,22 +55,21 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ScriptList.java,v 1.3 2007-01-24 09:54:44 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class ScriptList { - private int _scriptCount = 0; - private final ScriptRecord[] _scriptRecords; - private final Script[] _scripts; - + private int _scriptCount; + private ScriptRecord[] _scriptRecords; + private Script[] _scripts; + /** Creates new ScriptList */ - protected ScriptList(final DataInputStream dis, final int offset) throws IOException { - + ScriptList(DataInputStream dis, 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 +85,20 @@ public class ScriptList { public int getScriptCount() { return _scriptCount; } - - public ScriptRecord getScriptRecord(final int i) { + + public ScriptRecord getScriptRecord(int i) { return _scriptRecords[i]; } - - public Script getScript(final int i) { + + public Script getScript(int i) { return _scripts[i]; } - - public Script findScript(final String tag) { + + public Script findScript(String tag) { if (tag.length() != 4) { return null; } - final int tagVal = ((tag.charAt(0)<<24) + 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 18eefe5a7..a8439e111 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 @@ -55,16 +55,15 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: ScriptRecord.java,v 1.2 2007-01-24 09:47:46 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class ScriptRecord { - private final int _tag; - private final int _offset; - + private int _tag; + private int _offset; + /** Creates new ScriptRecord */ - protected ScriptRecord(final DataInput di) throws IOException { + ScriptRecord(DataInput di) throws IOException { _tag = di.readInt(); _offset = di.readUnsignedShort(); } @@ -72,17 +71,15 @@ public class ScriptRecord { public int getTag() { return _tag; } - + public int getOffset() { return _offset; } public String getTagAsString() { - return new StringBuilder() - .append((char)((_tag>>24)&0xff)) - .append((char)((_tag>>16)&0xff)) - .append((char)((_tag>>8)&0xff)) - .append((char)((_tag)&0xff)) - .toString(); + return String.valueOf((char) ((_tag >> 24) & 0xff)) + + (char) ((_tag >> 16) & 0xff) + + (char) ((_tag >> 8) & 0xff) + + (char) ((_tag) & 0xff); } } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ScriptTags.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ScriptTags.java index a5e196e83..bb248922d 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ScriptTags.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/ScriptTags.java @@ -53,9 +53,8 @@ package jogamp.graph.font.typecast.ot.table; /** * Definition of Script tags * - * @version $Id: ScriptTags.java,v 1.2 2007-01-24 09:47:46 davidsch Exp $ * @author <a href="mailto:[email protected]">Vincent Hardy</a> */ public interface ScriptTags { - public static final String SCRIPT_TAG_ARAB = "arab"; + String SCRIPT_TAG_ARAB = "arab"; } 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 e6841b94c..d5d06e253 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; @@ -13,18 +13,17 @@ import java.io.DataInput; /** * - * @version $Id: SignatureBlock.java,v 1.1.1.1 2004-12-05 23:14:58 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class SignatureBlock { - - private final int reserved1; - private final int reserved2; - private final int signatureLen; - private final byte[] signature; +class SignatureBlock { + private int reserved1; + private int reserved2; + private int signatureLen; + private byte[] signature; + /** Creates new SignatureBlock */ - protected SignatureBlock(final DataInput di) throws IOException { + SignatureBlock(DataInput di) throws IOException { reserved1 = di.readUnsignedShort(); reserved2 = di.readUnsignedShort(); signatureLen = di.readInt(); @@ -32,9 +31,8 @@ public class SignatureBlock { di.readFully(signature); } - @Override public String toString() { - final StringBuilder sb = new StringBuilder(); + 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 c398b4fbb..b4c68adba 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 @@ -55,20 +55,19 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: SingleSubst.java,v 1.2 2007-01-24 09:47:46 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public abstract class SingleSubst extends LookupSubtable { public abstract int getFormat(); public abstract int substitute(int glyphId); - - public static SingleSubst read(final DataInputStream dis, final int offset) throws IOException { + + public static SingleSubst read(DataInputStream dis, int offset) throws IOException { SingleSubst s = null; dis.reset(); dis.skipBytes(offset); - final int format = dis.readUnsignedShort(); + 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 b2e65dded..0ef7573b7 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 @@ -55,17 +55,16 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: SingleSubstFormat1.java,v 1.2 2007-01-24 09:47:45 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class SingleSubstFormat1 extends SingleSubst { - private final int _coverageOffset; - private final short _deltaGlyphID; - private final Coverage _coverage; + private int _coverageOffset; + private short _deltaGlyphID; + private Coverage _coverage; /** Creates new SingleSubstFormat1 */ - protected SingleSubstFormat1(final DataInputStream dis, final int offset) throws IOException { + SingleSubstFormat1(DataInputStream dis, int offset) throws IOException { _coverageOffset = dis.readUnsignedShort(); _deltaGlyphID = dis.readShort(); dis.reset(); @@ -73,21 +72,18 @@ public class SingleSubstFormat1 extends SingleSubst { _coverage = Coverage.read(dis); } - @Override public int getFormat() { return 1; } - @Override - public int substitute(final int glyphId) { - final int i = _coverage.findGlyph(glyphId); + public int substitute(int glyphId) { + 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 449c14c7a..d66e246f8 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 @@ -55,8 +55,7 @@ import java.io.IOException; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: SingleSubstFormat2.java,v 1.2 2007-01-24 09:47:48 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class SingleSubstFormat2 extends SingleSubst { @@ -66,7 +65,7 @@ public class SingleSubstFormat2 extends SingleSubst { private final Coverage _coverage; /** Creates new SingleSubstFormat2 */ - protected SingleSubstFormat2(final DataInputStream dis, final int offset) throws IOException { + SingleSubstFormat2(DataInputStream dis, int offset) throws IOException { _coverageOffset = dis.readUnsignedShort(); _glyphCount = dis.readUnsignedShort(); _substitutes = new int[_glyphCount]; @@ -84,8 +83,8 @@ public class SingleSubstFormat2 extends SingleSubst { } @Override - public int substitute(final int glyphId) { - final int i = _coverage.findGlyph(glyphId); + public int substitute(int glyphId) { + int i = _coverage.findGlyph(glyphId); if (i > -1) { return _substitutes[i]; } @@ -95,6 +94,18 @@ public class SingleSubstFormat2 extends SingleSubst { @Override public String getTypeAsString() { return "SingleSubstFormat2"; - } -} + } + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + int[] glyphIds = _coverage.getGlyphIds(); + for (int glyphId : glyphIds) { + int i = _coverage.findGlyph(glyphId); + if (i > -1) { + sb.append(String.format("%d = %d\n", glyphId, _substitutes[i])); + } + } + return sb.toString(); + } +} 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 a6ec61887..63d5bd00e 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; @@ -13,23 +13,22 @@ import java.io.IOException; /** * - * @version $Id: TTCHeader.java,v 1.1.1.1 2004-12-05 23:15:01 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class TTCHeader { + + private static final int ttcf = 0x74746366; - public static final int ttcf = 0x74746366; - - private final int ttcTag; - private final int version; - private final int directoryCount; - private final int[] tableDirectory; + private int ttcTag; + private int version; + private int directoryCount; + private int[] tableDirectory; private int dsigTag; - private final int dsigLength; - private final int dsigOffset; + private int dsigLength; + private int dsigOffset; /** Creates new TTCHeader */ - public TTCHeader(final DataInput di) throws IOException { + public TTCHeader(DataInput di) throws IOException { ttcTag = di.readInt(); version = di.readInt(); directoryCount = di.readInt(); @@ -47,13 +46,13 @@ public class TTCHeader { public int getDirectoryCount() { return directoryCount; } - - public int getTableDirectory(final int i) { + + public int getTableDirectory(int i) { return tableDirectory[i]; } - public static boolean isTTC(final DataInput di) throws IOException { - final int ttcTag = di.readInt(); + public static boolean isTTC(DataInput di) throws IOException { + 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 30fd2f457..bf0d1c6f5 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,22 +1,32 @@ -/***************************************************************************** - * 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. * - *****************************************************************************/ - +/* + * Typecast - The Font Development Environment + * + * Copyright (c) 2004-2016 David Schweinsberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package jogamp.graph.font.typecast.ot.table; /** - * @version $Id: Table.java,v 1.1.1.1 2004-12-05 23:14:59 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public interface Table { // Table constants public static final int BASE = 0x42415345; // Baseline data [OpenType] public static final int CFF = 0x43464620; // PostScript font program (compact font format) [PostScript] + public static final int COLR = 0x434f4c52; // Color Table + public static final int CPAL = 0x4350414c; // Color Palette Table public static final int DSIG = 0x44534947; // Digital signature public static final int EBDT = 0x45424454; // Embedded bitmap data public static final int EBLC = 0x45424c43; // Embedded bitmap location data @@ -47,23 +57,10 @@ public interface Table { public static final int name = 0x6e616d65; // naming table [r] public static final int prep = 0x70726570; // CVT Program public static final int post = 0x706f7374; // PostScript information [r] + public static final int sbix = 0x73626978; // Extended Bitmaps public static final int vhea = 0x76686561; // Vertical Metrics header 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 - */ - public int getType(); - - /** - * 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 - */ - 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 b9448cc72..63931286e 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 @@ -52,21 +52,65 @@ package jogamp.graph.font.typecast.ot.table; import java.io.DataInput; import java.io.IOException; - import jogamp.graph.font.typecast.ot.Fixed; /** - * @version $Id: TableDirectory.java,v 1.2 2004-12-09 23:46:21 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class TableDirectory { - private int _version = 0; - private short _numTables = 0; - private short _searchRange = 0; - private short _entrySelector = 0; - private short _rangeShift = 0; - private final DirectoryEntry[] _entries; + public static class Entry { + + private final int _tag; + private final int _checksum; + private final int _offset; + private final int _length; + + Entry(final DataInput di) throws IOException { + _tag = di.readInt(); + _checksum = di.readInt(); + _offset = di.readInt(); + _length = di.readInt(); + } + + public int getChecksum() { + return _checksum; + } + + public int getLength() { + return _length; + } + + public int getOffset() { + return _offset; + } + + int getTag() { + return _tag; + } + + String getTagAsString() { + return String.valueOf((char) ((_tag >> 24) & 0xff)) + + (char) ((_tag >> 16) & 0xff) + + (char) ((_tag >> 8) & 0xff) + + (char) ((_tag) & 0xff); + } + + @Override + public String toString() { + return "'" + getTagAsString() + + "' - chksm = 0x" + Integer.toHexString(_checksum) + + ", off = 0x" + Integer.toHexString(_offset) + + ", len = " + _length; + } + } + + private final int _version; + private final short _numTables; + private final short _searchRange; + private final short _entrySelector; + private final short _rangeShift; + private final Entry[] _entries; public TableDirectory(final DataInput di) throws IOException { _version = di.readInt(); @@ -74,17 +118,17 @@ public class TableDirectory { _searchRange = di.readShort(); _entrySelector = di.readShort(); _rangeShift = di.readShort(); - _entries = new DirectoryEntry[_numTables]; + _entries = new Entry[_numTables]; for (int i = 0; i < _numTables; i++) { - _entries[i] = new DirectoryEntry(di); + _entries[i] = new Entry(di); } } - public DirectoryEntry getEntry(final int index) { + public Entry getEntry(final int index) { return _entries[index]; } - public DirectoryEntry getEntryByTag(final int tag) { + public Entry getEntryByTag(final int tag) { for (int i = 0; i < _numTables; i++) { if (_entries[i].getTag() == tag) { return _entries[i]; 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 e0433f098..461a30a54 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 @@ -1,6 +1,4 @@ /* - * $Id: TableException.java,v 1.1.1.1 2004-12-05 23:15:00 davidsch Exp $ - * * Typecast - The Font Development Environment * * Copyright (c) 2004 David Schweinsberg @@ -22,11 +20,10 @@ package jogamp.graph.font.typecast.ot.table; /** * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: TableException.java,v 1.1.1.1 2004-12-05 23:15:00 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class TableException extends java.lang.Exception { - + private static final long serialVersionUID = 1L; /** @@ -34,13 +31,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(final String msg) { + public TableException(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 deleted file mode 100644 index d24f3b3ae..000000000 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/table/TableFactory.java +++ /dev/null @@ -1,185 +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 - - 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 <http://www.apache.org/>. - -*/ - -package jogamp.graph.font.typecast.ot.table; - -import java.io.DataInputStream; -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> - */ -public class TableFactory { - - public static Table create( - 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); - if (t != null) { - return t; - } - } - - // Create the table - switch (de.getTag()) { - case Table.BASE: - t = new BaseTable(de, dis); - break; - case Table.CFF: - t = new CffTable(de, dis); - break; - case Table.DSIG: - t = new DsigTable(de, dis); - break; - case Table.EBDT: - break; - case Table.EBLC: - break; - case Table.EBSC: - break; - case Table.GDEF: - break; - case Table.GPOS: - t = new GposTable(de, dis); - break; - case Table.GSUB: - t = new GsubTable(de, dis); - break; - case Table.JSTF: - break; - case Table.LTSH: - t = new LtshTable(de, dis); - break; - case Table.MMFX: - break; - case Table.MMSD: - break; - case Table.OS_2: - t = new Os2Table(de, dis); - break; - case Table.PCLT: - t = new PcltTable(de, dis); - break; - case Table.VDMX: - t = new VdmxTable(de, dis); - break; - case Table.cmap: - t = new CmapTable(de, dis); - break; - case Table.cvt: - t = new CvtTable(de, dis); - break; - case Table.fpgm: - t = new FpgmTable(de, dis); - break; - case Table.fvar: - break; - case Table.gasp: - t = new GaspTable(de, dis); - break; - case Table.glyf: - t = new GlyfTable(de, dis, font.getMaxpTable(), font.getLocaTable()); - break; - case Table.hdmx: - t = new HdmxTable(de, dis, font.getMaxpTable()); - break; - case Table.head: - t = new HeadTable(de, dis); - break; - case Table.hhea: - t = new HheaTable(de, dis); - break; - case Table.hmtx: - t = new HmtxTable(de, dis, font.getHheaTable(), font.getMaxpTable()); - break; - case Table.kern: - t = new KernTable(de, dis); - break; - case Table.loca: - t = new LocaTable(de, dis, font.getHeadTable(), font.getMaxpTable()); - break; - case Table.maxp: - t = new MaxpTable(de, dis); - break; - case Table.name: - t = new NameTable(de, dis); - break; - case Table.prep: - t = new PrepTable(de, dis); - break; - case Table.post: - t = new PostTable(de, dis); - break; - case Table.vhea: - t = new VheaTable(de, dis); - break; - case Table.vmtx: - 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); - } - return 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 679502e84..ac1b8ecf9 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 @@ -1,6 +1,4 @@ /* - * $Id: VdmxTable.java,v 1.1 2007-01-30 05:25:35 davidsch Exp $ - * * Typecast - The Font Development Environment * * Copyright (c) 2004-2007 David Schweinsberg @@ -25,75 +23,74 @@ import java.io.IOException; /** * The Vertical Device Metrics table for TrueType outlines. - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: VdmxTable.java,v 1.1 2007-01-30 05:25:35 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class VdmxTable implements Table { - 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 { + private static class Ratio { + + private byte _bCharSet; + private byte _xRatio; + private byte _yStartRatio; + private byte _yEndRatio; + + Ratio(DataInput di) throws IOException { _bCharSet = di.readByte(); _xRatio = di.readByte(); _yStartRatio = di.readByte(); _yEndRatio = di.readByte(); } - public byte getBCharSet() { + byte getBCharSet() { return _bCharSet; } - - public byte getXRatio() { + + byte getXRatio() { return _xRatio; } - - public byte getYStartRatio() { + + byte getYStartRatio() { return _yStartRatio; } - - public byte getYEndRatio() { + + byte getYEndRatio() { return _yEndRatio; } } - - static class VTableRecord { - - private final int _yPelHeight; - private final short _yMax; - private final short _yMin; - - protected VTableRecord(final DataInput di) throws IOException { + + private static class VTableRecord { + + private int _yPelHeight; + private short _yMax; + private short _yMin; + + VTableRecord(DataInput di) throws IOException { _yPelHeight = di.readUnsignedShort(); _yMax = di.readShort(); _yMin = di.readShort(); } - public int getYPelHeight() { + int getYPelHeight() { return _yPelHeight; } - - public short getYMax() { + + short getYMax() { return _yMax; } - - public short getYMin() { + + short getYMin() { return _yMin; } } - - 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 { + + private static class Group { + + private int _recs; + private int _startsz; + private int _endsz; + private VTableRecord[] _entry; + + Group(DataInput di) throws IOException { _recs = di.readUnsignedShort(); _startsz = di.readUnsignedByte(); _endsz = di.readUnsignedByte(); @@ -103,34 +100,32 @@ public class VdmxTable implements Table { } } - public int getRecs() { + int getRecs() { return _recs; } - - public int getStartSZ() { + + int getStartSZ() { return _startsz; } - - public int getEndSZ() { + + int getEndSZ() { return _endsz; } - - public VTableRecord[] getEntry() { + + VTableRecord[] getEntry() { return _entry; } } - - 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; - + + private int _version; + private int _numRecs; + private int _numRatios; + private Ratio[] _ratRange; + private int[] _offset; + private Group[] _groups; + /** Creates a new instance of VdmxTable */ - protected VdmxTable(final DirectoryEntry de, final DataInput di) throws IOException { - _de = (DirectoryEntry) de.clone(); + public VdmxTable(DataInput di) throws IOException { _version = di.readUnsignedShort(); _numRecs = di.readUnsignedShort(); _numRatios = di.readUnsignedShort(); @@ -147,15 +142,9 @@ public class VdmxTable implements Table { _groups[i] = new Group(di); } } - - @Override - public int getType() { - return VDMX; - } - - @Override + public String toString() { - final StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(); sb.append("'VDMX' Table - Precomputed Vertical Device Metrics\n") .append("--------------------------------------------------\n") .append(" Version: ").append(_version).append("\n") @@ -172,7 +161,7 @@ public class VdmxTable implements Table { sb.append("\n VDMX Height Record Groups\n") .append(" -------------------------\n"); for (int i = 0; i < _numRecs; ++i) { - final Group group = _groups[i]; + 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") @@ -187,14 +176,4 @@ public class VdmxTable 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/VheaTable.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/table/VheaTable.java index cef7b5297..57c4aa914 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 @@ -1,6 +1,4 @@ /* - * $Id: VheaTable.java,v 1.1 2007-01-31 01:17:40 davidsch Exp $ - * * Typecast - The Font Development Environment * * Copyright (c) 2004-2007 David Schweinsberg @@ -22,32 +20,28 @@ package jogamp.graph.font.typecast.ot.table; import java.io.DataInput; import java.io.IOException; - import jogamp.graph.font.typecast.ot.Fixed; /** * Vertical Header Table - * @version $Id: VheaTable.java,v 1.1 2007-01-31 01:17:40 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class VheaTable implements Table { - 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(); + 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; + + public VheaTable(DataInput di) throws IOException { _version = di.readInt(); _ascent = di.readShort(); _descent = di.readShort(); @@ -105,47 +99,29 @@ public class VheaTable implements Table { return _numberOfLongVerMetrics; } - @Override - public int getType() { - return vhea; - } - public short getYMaxExtent() { return _yMaxExtent; } - @Override public String toString() { - return new StringBuilder() - .append("'vhea' Table - Vertical Header\n------------------------------") - .append("\n 'vhea' version: ").append(Fixed.floatValue(_version)) - .append("\n xAscender: ").append(_ascent) - .append("\n xDescender: ").append(_descent) - .append("\n xLineGap: ").append(_lineGap) - .append("\n advanceHeightMax: ").append(_advanceHeightMax) - .append("\n minTopSideBearing: ").append(_minTopSideBearing) - .append("\n minBottomSideBearing: ").append(_minBottomSideBearing) - .append("\n yMaxExtent: ").append(_yMaxExtent) - .append("\n horizCaretSlopeNum: ").append(_caretSlopeRise) - .append("\n horizCaretSlopeDenom: ").append(_caretSlopeRun) - .append("\n reserved0: 0") - .append("\n reserved1: 0") - .append("\n reserved2: 0") - .append("\n reserved3: 0") - .append("\n reserved4: 0") - .append("\n metricDataFormat: ").append(_metricDataFormat) - .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; + return "'vhea' Table - Vertical Header\n------------------------------" + + "\n 'vhea' version: " + Fixed.floatValue(_version) + + "\n xAscender: " + _ascent + + "\n xDescender: " + _descent + + "\n xLineGap: " + _lineGap + + "\n advanceHeightMax: " + _advanceHeightMax + + "\n minTopSideBearing: " + _minTopSideBearing + + "\n minBottomSideBearing: " + _minBottomSideBearing + + "\n yMaxExtent: " + _yMaxExtent + + "\n horizCaretSlopeNum: " + _caretSlopeRise + + "\n horizCaretSlopeDenom: " + _caretSlopeRun + + "\n reserved0: 0" + + "\n reserved1: 0" + + "\n reserved2: 0" + + "\n reserved3: 0" + + "\n reserved4: 0" + + "\n metricDataFormat: " + _metricDataFormat + + "\n numOf_LongVerMetrics: " + _numberOfLongVerMetrics; } + } 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 b76ed7e15..6ceaa73ad 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 @@ -1,6 +1,4 @@ /* - * $Id: VmtxTable.java,v 1.1 2007-01-31 01:18:04 davidsch Exp $ - * * Typecast - The Font Development Environment * * Copyright (c) 2004-2007 David Schweinsberg @@ -25,21 +23,17 @@ import java.io.IOException; /** * Vertical Metrics Table - * @version $Id: VmtxTable.java,v 1.1 2007-01-31 01:18:04 davidsch Exp $ - * @author <a href="mailto:[email protected]">David Schweinsberg</a> + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class VmtxTable implements Table { +class VmtxTable implements Table { - private final DirectoryEntry _de; - private int[] _vMetrics = null; - private short[] _topSideBearing = null; + private int[] _vMetrics; + private short[] _topSideBearing; protected VmtxTable( - final DirectoryEntry de, - final DataInput di, - final VheaTable vhea, - final MaxpTable maxp) throws IOException { - _de = (DirectoryEntry) de.clone(); + DataInput di, + VheaTable vhea, + MaxpTable maxp) throws IOException { _vMetrics = new int[vhea.getNumberOfLongVerMetrics()]; for (int i = 0; i < vhea.getNumberOfLongVerMetrics(); ++i) { _vMetrics[i] = @@ -48,14 +42,14 @@ public class VmtxTable implements Table { | di.readUnsignedByte()<<8 | di.readUnsignedByte(); } - final int tsbCount = maxp.getNumGlyphs() - vhea.getNumberOfLongVerMetrics(); + int tsbCount = maxp.getNumGlyphs() - vhea.getNumberOfLongVerMetrics(); _topSideBearing = new short[tsbCount]; for (int i = 0; i < tsbCount; ++i) { _topSideBearing[i] = di.readShort(); } } - public int getAdvanceHeight(final int i) { + private int getAdvanceHeight(int i) { if (_vMetrics == null) { return 0; } @@ -66,7 +60,7 @@ public class VmtxTable implements Table { } } - public short getTopSideBearing(final int i) { + private short getTopSideBearing(int i) { if (_vMetrics == null) { return 0; } @@ -77,17 +71,11 @@ public class VmtxTable implements Table { } } - @Override - public int getType() { - return vmtx; - } - - @Override public String toString() { - final StringBuilder sb = new StringBuilder(); + 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"); +// sb.append("Size = ").append(_de.getLength()).append(" bytes, ") + sb.append(_vMetrics.length).append(" entries\n"); for (int i = 0; i < _vMetrics.length; i++) { sb.append(" ").append(i) .append(". advHeight: ").append(getAdvanceHeight(i)) @@ -102,14 +90,4 @@ public class VmtxTable 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/tt/engine/GraphicsState.java b/src/jogl/classes/jogamp/graph/font/typecast/tt/engine/GraphicsState.java index b8605ac69..41a1cd2b4 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/tt/engine/GraphicsState.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/tt/engine/GraphicsState.java @@ -1,6 +1,4 @@ /* - * $Id: GraphicsState.java,v 1.1.1.1 2004-12-05 23:15:01 davidsch Exp $ - * * Typecast - The Font Development Environment * * Copyright (c) 2004 David Schweinsberg @@ -22,8 +20,7 @@ package jogamp.graph.font.typecast.tt.engine; /** * Maintains the graphics state whilst interpreting hinting instructions. - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: GraphicsState.java,v 1.1.1.1 2004-12-05 23:15:01 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ class GraphicsState { 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 a7408e381..2685ba046 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 @@ -1,6 +1,4 @@ /* - * $Id: Interpreter.java,v 1.1.1.1 2004-12-05 23:15:05 davidsch Exp $ - * * Typecast - The Font Development Environment * * Copyright (c) 2004 David Schweinsberg @@ -27,22 +25,21 @@ import jogamp.graph.font.typecast.ot.Point; * The interpreter shall remain ignorant of the table structure - the table * data will be extracted by supporting classes, whether it be the Parser * or some other. - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: Interpreter.java,v 1.1.1.1 2004-12-05 23:15:05 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class Interpreter { +class Interpreter { private Parser parser = null; private final GraphicsState gs = new GraphicsState(); private final Point[][] zone = new Point[2][]; - private int[] stack = null; - private int[] store = null; + private int[] stack; + private int[] store; private final int[] cvt = new int[256]; - private int[] functionMap = null; + private int[] functionMap; private int stackIndex = 0; private boolean inFuncDef = false; - public Interpreter(final int stackMax, final int storeMax, final int funcMax) { + public Interpreter(int stackMax, int storeMax, int funcMax) { zone[0] = new Point[256]; zone[1] = new Point[256]; stack = new int[stackMax]; @@ -54,7 +51,7 @@ public class Interpreter { * ABSolute value */ private void _abs() { - final int n = pop(); + int n = pop(); if (n >= 0) { push(n); } else { @@ -66,8 +63,8 @@ public class Interpreter { * ADD */ private void _add() { - final int n1 = pop(); - final int n2 = pop(); + int n1 = pop(); + int n2 = pop(); push(n2 + n1); } @@ -92,8 +89,8 @@ public class Interpreter { * logical AND */ private void _and() { - final int e2 = pop(); - final int e1 = pop(); + int e2 = pop(); + int e1 = pop(); push(((e1 != 0) && (e2 != 0)) ? 1 : 0); } @@ -108,7 +105,7 @@ public class Interpreter { * CEILING */ private void _ceiling() { - final int n = pop(); + int n = pop(); if (n >= 0) { push((n & 0xffc0) + (((n & 0x3f) != 0) ? 0x40 : 0)); } else { @@ -138,10 +135,10 @@ public class Interpreter { * DELTA exception C1 */ private void _deltac1() { - final int n = pop(); + int n = pop(); for (int i = 0; i < n; i++) { - pop(); // pn - pop(); // argn + pop(); // pn + pop(); // argn } } @@ -149,10 +146,10 @@ public class Interpreter { * DELTA exception C2 */ private void _deltac2() { - final int n = pop(); + int n = pop(); for (int i = 0; i < n; i++) { - pop(); // pn - pop(); // argn + pop(); // pn + pop(); // argn } } @@ -160,10 +157,10 @@ public class Interpreter { * DELTA exception C3 */ private void _deltac3() { - final int n = pop(); + int n = pop(); for (int i = 0; i < n; i++) { - pop(); // pn - pop(); // argn + pop(); // pn + pop(); // argn } } @@ -171,10 +168,10 @@ public class Interpreter { * DELTA exception P1 */ private void _deltap1() { - final int n = pop(); + int n = pop(); for (int i = 0; i < n; i++) { - pop(); // pn - pop(); // argn + pop(); // pn + pop(); // argn } } @@ -182,10 +179,10 @@ public class Interpreter { * DELTA exception P2 */ private void _deltap2() { - final int n = pop(); + int n = pop(); for (int i = 0; i < n; i++) { - pop(); // pn - pop(); // argn + pop(); // pn + pop(); // argn } } @@ -193,10 +190,10 @@ public class Interpreter { * DELTA exception P3 */ private void _deltap3() { - final int n = pop(); + int n = pop(); for (int i = 0; i < n; i++) { - pop(); // pn - pop(); // argn + pop(); // pn + pop(); // argn } } @@ -211,8 +208,8 @@ public class Interpreter { * DIVide */ private void _div() { - final int n1 = pop(); - final int n2 = pop(); + int n1 = pop(); + int n2 = pop(); push((n2 / n1) >> 6); } @@ -220,7 +217,7 @@ public class Interpreter { * DUPlicate top stack element */ private void _dup() { - final int n = pop(); + int n = pop(); push(n); push(n); } @@ -228,7 +225,7 @@ public class Interpreter { /** * ELSE */ - private int _else(final int instructionIndex) { + private int _else(int instructionIndex) { return parser.handleElse(instructionIndex); } @@ -236,8 +233,8 @@ public class Interpreter { * EQual */ private void _eq() { - final int e2 = pop(); - final int e1 = pop(); + int e2 = pop(); + int e1 = pop(); push((e1 == e2) ? 1 : 0); } @@ -249,7 +246,7 @@ public class Interpreter { /** * Function DEFinition */ - private void _fdef(final int instructionIndex) { + private void _fdef(int instructionIndex) { functionMap[pop()] = instructionIndex; inFuncDef = true; } @@ -275,7 +272,7 @@ public class Interpreter { */ private void _flippt() { while(gs.loop-- > 0) { - final int index = pop(); + int index = pop(); zone[gs.zp0][index].onCurve = !zone[gs.zp0][index].onCurve; } gs.loop = 1; @@ -285,8 +282,8 @@ public class Interpreter { * FLIP RanGe OFF */ private void _fliprgoff() { - final int end = pop(); - final int start = pop(); + int end = pop(); + int start = pop(); for (int i = start; i <= end; i++) { zone[1][i].onCurve = false; } @@ -296,8 +293,8 @@ public class Interpreter { * FLIP RanGe ON */ private void _fliprgon() { - final int end = pop(); - final int start = pop(); + int end = pop(); + int start = pop(); for (int i = start; i <= end; i++) { zone[1][i].onCurve = true; } @@ -307,7 +304,7 @@ public class Interpreter { * FLOOR */ private void _floor() { - final int n = pop(); + int n = pop(); if (n >= 0) { push(n & 0xffc0); } else { @@ -315,7 +312,7 @@ public class Interpreter { } } - private void _gc(final short param) { + private void _gc(short param) { pop(); push(0); } @@ -345,8 +342,8 @@ public class Interpreter { * Greater Than */ private void _gt() { - final int e2 = pop(); - final int e1 = pop(); + int e2 = pop(); + int e1 = pop(); push((e1 > e2) ? 1 : 0); } @@ -354,8 +351,8 @@ public class Interpreter { * Greater Than or EQual */ private void _gteq() { - final int e2 = pop(); - final int e1 = pop(); + int e2 = pop(); + int e1 = pop(); push((e1 >= e2) ? 1 : 0); } @@ -370,7 +367,7 @@ public class Interpreter { /** * IF test */ - private int _if(final int instructionIndex) { + private int _if(int instructionIndex) { return parser.handleIf(pop() != 0, instructionIndex); } @@ -407,12 +404,12 @@ public class Interpreter { * to inhibit grid-fitting when a glyph is being rotated or stretched, use the * following sequence on the preprogram: * - * PUSHB[000] 6 ; ask GETINFO to check for stretching or rotation - * GETINFO[] ; will push TRUE if glyph is stretched or rotated - * IF[] ; tests value at top of stack - * PUSHB[000] 1 ; value for INSTCTRL - * PUSHB[000] 1 ; selector for INSTCTRL - * INSTRCTRL[] ; based on selector and value will turn grid-fitting off + * PUSHB[000] 6 ; ask GETINFO to check for stretching or rotation + * GETINFO[] ; will push TRUE if glyph is stretched or rotated + * IF[] ; tests value at top of stack + * PUSHB[000] 1 ; value for INSTCTRL + * PUSHB[000] 1 ; selector for INSTCTRL + * INSTRCTRL[] ; based on selector and value will turn grid-fitting off * EIF[] * * Selector flag 2 is used to establish that any parameters set in the CVT program @@ -425,8 +422,8 @@ public class Interpreter { * will be used in glyph instructions. */ private void _instctrl() { - final int s = pop(); - final int v = pop(); + int s = pop(); + int v = pop(); if (s == 1) { gs.instruction_control |= v; } else if (s == 2) { @@ -446,22 +443,23 @@ public class Interpreter { pop(); } - private void _iup(final short param) { + private void _iup(short param) { } /** * JuMP Relative */ - private int _jmpr(final int instructionIndex) { - return instructionIndex + ( pop() - 1 ); + private int _jmpr(int instructionIndex) { + instructionIndex += pop() - 1; + return instructionIndex; } /** * Jump Relative On False */ private int _jrof(int instructionIndex) { - final boolean test = pop() != 0; - final int offset = pop(); + boolean test = pop() != 0; + int offset = pop(); if (!test) { instructionIndex += offset - 1; } @@ -472,8 +470,8 @@ public class Interpreter { * Jump Relative On True */ private int _jrot(int instructionIndex) { - final boolean test = pop() != 0; - final int offset = pop(); + boolean test = pop() != 0; + int offset = pop(); if (test) { instructionIndex += offset - 1; } @@ -484,8 +482,8 @@ public class Interpreter { * LOOP and CALL function */ private void _loopcall() { - /* final int index = */ pop(); - final int count = pop(); + int index = pop(); + int count = pop(); for (int i = 0; i < count; i++) { execute(functionMap[i]); } @@ -495,8 +493,8 @@ public class Interpreter { * Less Than */ private void _lt() { - final int e2 = pop(); - final int e1 = pop(); + int e2 = pop(); + int e1 = pop(); push((e1 < e2) ? 1 : 0); } @@ -504,8 +502,8 @@ public class Interpreter { * Less Than or EQual */ private void _lteq() { - final int e2 = pop(); - final int e1 = pop(); + int e2 = pop(); + int e1 = pop(); push((e1 <= e2) ? 1 : 0); } @@ -513,26 +511,26 @@ public class Interpreter { * MAXimum of top two stack elements */ private void _max() { - final int n1 = pop(); - final int n2 = pop(); - push((n1 > n2) ? n1 : n2); + int n1 = pop(); + int n2 = pop(); + push(Math.max(n1, n2)); } - private void _md(final short param) { + private void _md(short param) { pop(); pop(); push(0); } - private void _mdap(final short param) { + private void _mdap(short param) { pop(); } - private void _mdrp(final short param) { + private void _mdrp(short param) { pop(); } - private void _miap(final short param) { + private void _miap(short param) { pop(); pop(); } @@ -540,9 +538,9 @@ public class Interpreter { * MINimum of top two stack elements */ private void _min() { - final int n1 = pop(); - final int n2 = pop(); - push((n1 < n2) ? n1 : n2); + int n1 = pop(); + int n2 = pop(); + push(Math.min(n1, n2)); } /** @@ -550,15 +548,15 @@ public class Interpreter { */ private void _mindex() { // Move the indexed element to stackIndex, and shift the others down - final int k = pop(); - final int e = stack[stackIndex - k]; + int k = pop(); + 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(final short param) { + private void _mirp(short param) { pop(); pop(); } @@ -570,8 +568,8 @@ public class Interpreter { private void _mps() { push(0); } - - private void _msirp(final short param) { + + private void _msirp(short param) { pop(); pop(); } @@ -580,8 +578,8 @@ public class Interpreter { * MULtiply */ private void _mul() { - final int n1 = pop(); - final int n2 = pop(); + int n1 = pop(); + int n2 = pop(); push((n1 * n2) >> 6); } @@ -596,8 +594,8 @@ public class Interpreter { * Not EQual */ private void _neq() { - final int e2 = pop(); - final int e1 = pop(); + int e2 = pop(); + int e1 = pop(); push((e1 != e2) ? 1 : 0); } @@ -608,7 +606,7 @@ public class Interpreter { push((pop() != 0) ? 0 : 1); } - private void _nround(final short param) { + private void _nround(short param) { pop(); push(0); } @@ -622,8 +620,8 @@ public class Interpreter { * logical OR */ private void _or() { - final int e2 = pop(); - final int e1 = pop(); + int e2 = pop(); + int e1 = pop(); push(((e1 != 0) || (e2 != 0)) ? 1 : 0); } @@ -633,9 +631,9 @@ public class Interpreter { * PUSH Bytes * PUSH Words */ - private void _push(final int[] data) { - for (int j = 0; j < data.length; j++) { - push(data[j]); + private void _push(int[] data) { + for (int datum : data) { + push(datum); } } @@ -664,15 +662,15 @@ public class Interpreter { * ROLL the top three stack elements */ private void _roll() { - final int a = pop(); - final int b = pop(); - final int c = pop(); + int a = pop(); + int b = pop(); + int c = pop(); push(b); push(a); push(c); } - private void _round(final short param) { + private void _round(short param) { pop(); push(0); } @@ -907,7 +905,7 @@ public class Interpreter { /** * Set Dual Projection_Vector To Line */ - private void _sdpvtl(final short param) { + private void _sdpvtl(short param) { pop(); pop(); } @@ -923,14 +921,14 @@ public class Interpreter { * Set Freedom_Vector From Stack */ private void _sfvfs() { - gs.freedom_vector[1] = pop(); // y - gs.freedom_vector[0] = pop(); // x + gs.freedom_vector[1] = pop(); // y + gs.freedom_vector[0] = pop(); // x } /* * Set Freedom_Vector to Coordinate Axis */ - private void _sfvtca(final short param) { + private void _sfvtca(short param) { if (param == 1) { gs.freedom_vector[0] = 0x4000; gs.freedom_vector[1] = 0x0000; @@ -943,16 +941,16 @@ public class Interpreter { /* * Set Freedom_Vector To Line */ - private void _sfvtl(final short param) { + private void _sfvtl(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 +961,7 @@ public class Interpreter { gs.freedom_vector[1] = gs.projection_vector[1]; } - private void _shc(final short param) { + private void _shc(short param) { pop(); } @@ -972,7 +970,7 @@ public class Interpreter { * * USES: loop */ - private void _shp(final short param) { + private void _shp(short param) { while(gs.loop-- > 0) { pop(); if(param == 0) { @@ -988,14 +986,14 @@ public class Interpreter { * USES: loop */ private void _shpix() { - pop(); // amount + pop(); // amount while (gs.loop-- > 0) { - pop(); // p + pop(); // p } gs.loop = 1; } - private void _shz(final short param) { + private void _shz(short param) { pop(); } @@ -1017,14 +1015,14 @@ public class Interpreter { * Set Projection_Vector From Stack */ private void _spvfs() { - gs.projection_vector[1] = pop(); // y - gs.projection_vector[0] = pop(); // x + gs.projection_vector[1] = pop(); // y + gs.projection_vector[0] = pop(); // x } /* * Set Projection_Vector To Coordinate Axis */ - private void _spvtca(final short param) { + private void _spvtca(short param) { if (param == 1) { gs.projection_vector[0] = 0x4000; gs.projection_vector[1] = 0x0000; @@ -1037,26 +1035,21 @@ public class Interpreter { /** * Set Projection_Vector To Line */ - private void _spvtl(final short param) { + private void _spvtl(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. - 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) { + 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 { - // gs.projection_vector[0] = 0x0000; - // gs.projection_vector[1] = 0x0000; - // } + } else { + gs.projection_vector[0] = 0x0000; + gs.projection_vector[1] = 0x0000; + } } private void _sround() { @@ -1102,15 +1095,15 @@ public class Interpreter { * SUBtract */ private void _sub() { - final int n1 = pop(); - final int n2 = pop(); + int n1 = pop(); + int n2 = pop(); push(n2 - n1); } /** * Set freedom and projection Vectors To Coordinate Axis */ - private void _svtca(final short param) { + private void _svtca(short param) { if (param == 1) { gs.projection_vector[0] = 0x4000; gs.projection_vector[1] = 0x0000; @@ -1128,8 +1121,8 @@ public class Interpreter { * SWAP the top two elements on the stack */ private void _swap() { - final int n1 = pop(); - final int n2 = pop(); + int n1 = pop(); + int n2 = pop(); push(n1); push(n2); } @@ -1170,7 +1163,7 @@ public class Interpreter { * Write Control Value Table in FUnits */ private void _wcvtf() { - final int value = pop(); + int value = pop(); // Conversion of value goes here cvt[pop()] = value; } @@ -1179,7 +1172,7 @@ public class Interpreter { * Write Control Value Table in Pixel units */ private void _wcvtp() { - final int value = pop(); + int value = pop(); // Conversion of value goes here cvt[pop()] = value; } @@ -1191,11 +1184,11 @@ public class Interpreter { store[pop()] = pop(); } - public void execute(int ip) { + private void execute(int ip) { while (ip < ((ip & 0xffff0000) | parser.getISLength(ip >> 16))) { - final short opcode = parser.getOpcode(ip); + 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; @@ -1337,7 +1330,7 @@ public class Interpreter { return stack[--stackIndex]; } - private void push(final int i) { + private void push(int i) { stack[stackIndex++] = i; } @@ -1356,7 +1349,7 @@ public class Interpreter { } } - public void setParser(final Parser p) { + public void setParser(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 ff1795a28..062276527 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 @@ -1,6 +1,4 @@ /* - * $Id: Parser.java,v 1.1.1.1 2004-12-05 23:15:06 davidsch Exp $ - * * Typecast - The Font Development Environment * * Copyright (c) 2004 David Schweinsberg @@ -23,10 +21,9 @@ package jogamp.graph.font.typecast.tt.engine; import jogamp.graph.font.typecast.ot.Mnemonic; /** - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: Parser.java,v 1.1.1.1 2004-12-05 23:15:06 davidsch Exp $ + * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class Parser { +class Parser { private final short[][] instructions = new short[3][]; @@ -41,7 +38,7 @@ public class Parser { public int advanceIP(int ip) { // The high word specifies font, cvt, or glyph program - final int prog = ip >> 16; + int prog = ip >> 16; int i = ip & 0xffff; int dataCount; ip++; @@ -63,16 +60,16 @@ public class Parser { return ip; } - public int getISLength(final int prog) { + public int getISLength(int prog) { return instructions[prog].length; } - public short getOpcode(final int ip) { + public short getOpcode(int ip) { return instructions[ip >> 16][ip & 0xffff]; } - public short getPushCount(final int ip) { - final short instr = instructions[ip >> 16][ip & 0xffff]; + private short getPushCount(int ip) { + 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 +78,12 @@ public class Parser { return 0; } - 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]; + 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]; if (Mnemonic.NPUSHB == instr) { for (int j = 0; j < count; j++) { data[j] = instructions[prog][i + j + 2]; @@ -114,8 +111,8 @@ public class Parser { return ip; } - public int handleIf(final boolean test, int ip) { - if (test == false) { + public int handleIf(boolean test, int ip) { + if (!test) { // The TrueType spec says that we merely jump to the *next* ELSE or EIF // instruction in the instruction stream. So therefore no nesting! // Looking at actual code, IF-ELSE-EIF can be nested! @@ -130,34 +127,32 @@ public class Parser { /** * This program is run everytime we scale the font */ - public void setCvtProgram(final short[] program) { + public void setCvtProgram(short[] program) { instructions[1] = program; } /** * This program is only run once */ - public void setFontProgram(final short[] program) { + public void setFontProgram(short[] program) { instructions[0] = program; } /** * This program is run everytime we scale the glyph */ - public void setGlyphProgram(final short[] program) { + public void setGlyphProgram(short[] program) { instructions[2] = program; } - @Override public String toString() { - final StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(); int ip = 0; while (ip < instructions[0].length) { sb.append(Mnemonic.getMnemonic(getOpcode(ip))); if (getPushCount(ip) > 0) { - final int[] data = getPushData(ip); - for(int j = 0; j < data.length; j++) - sb.append(" ").append(data[j]); + int[] data = getPushData(ip); + for (int datum : data) sb.append(" ").append(datum); } sb.append("\n"); ip = advanceIP(ip); @@ -167,9 +162,9 @@ public class Parser { while (ip < (0x10000 | instructions[1].length)) { sb.append(Mnemonic.getMnemonic(getOpcode(ip))); if(getPushCount(ip) > 0) { - final int[] data = getPushData(ip); - for (int j = 0; j < data.length; j++) { - sb.append(" ").append(data[j]); + int[] data = getPushData(ip); + for (int datum : data) { + sb.append(" ").append(datum); } } sb.append("\n"); @@ -180,9 +175,9 @@ public class Parser { while (ip < (0x20000 | instructions[2].length)) { sb.append(Mnemonic.getMnemonic(getOpcode(ip))); if (getPushCount(ip) > 0) { - final int[] data = getPushData(ip); - for (int j = 0; j < data.length; j++) { - sb.append(" ").append(data[j]); + int[] data = getPushData(ip); + for (int datum : data) { + sb.append(" ").append(datum); } } sb.append("\n"); |