diff options
author | David Schweinsberg <[email protected]> | 2016-01-20 23:14:41 +1100 |
---|---|---|
committer | David Schweinsberg <[email protected]> | 2016-01-20 23:14:41 +1100 |
commit | 6ea36086f23e6b412637c29733e08d605e24b2d1 (patch) | |
tree | 2b3014b04b83c34303975c55a4360a85db876b7c | |
parent | ba9a762fe8bf5dd28a44b56d1b9b4e91d52d10cf (diff) |
Added the beginnings of cmap format 12, for issues #1 & #7.
8 files changed, 201 insertions, 34 deletions
diff --git a/src/net/java/dev/typecast/ot/table/CmapFormat.java b/src/net/java/dev/typecast/ot/table/CmapFormat.java index bb2d82e..5a2cef6 100644 --- a/src/net/java/dev/typecast/ot/table/CmapFormat.java +++ b/src/net/java/dev/typecast/ot/table/CmapFormat.java @@ -46,15 +46,6 @@ public abstract class CmapFormat { } } - protected int _format; - protected int _length; - protected int _language; - - protected CmapFormat(DataInput di) throws IOException { - _length = di.readUnsignedShort(); - _language = di.readUnsignedShort(); - } - protected static CmapFormat create(int format, DataInput di) throws IOException { switch(format) { @@ -66,22 +57,18 @@ 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; - } + public abstract int getFormat(); - public int getLength() { - return _length; - } + public abstract int getLength(); - public int getLanguage() { - return _language; - } + public abstract int getLanguage(); public abstract int getRangeCount(); @@ -92,12 +79,12 @@ public abstract class CmapFormat { @Override public String toString() { - return new StringBuffer() + return new StringBuilder() .append("format: ") - .append(_format) + .append(getFormat()) .append(", length: ") - .append(_length) + .append(getLength()) .append(", language: ") - .append(_language).toString(); + .append(getLanguage()).toString(); } } diff --git a/src/net/java/dev/typecast/ot/table/CmapFormat0.java b/src/net/java/dev/typecast/ot/table/CmapFormat0.java index 04f1189..329a650 100644 --- a/src/net/java/dev/typecast/ot/table/CmapFormat0.java +++ b/src/net/java/dev/typecast/ot/table/CmapFormat0.java @@ -29,17 +29,34 @@ import java.io.IOException; */ public class CmapFormat0 extends CmapFormat { + private final int _length; + private final int _language; private final int[] _glyphIdArray = new int[256]; protected CmapFormat0(DataInput di) throws IOException { - super(di); - _format = 0; + _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; } diff --git a/src/net/java/dev/typecast/ot/table/CmapFormat12.java b/src/net/java/dev/typecast/ot/table/CmapFormat12.java new file mode 100644 index 0000000..6593043 --- /dev/null +++ b/src/net/java/dev/typecast/ot/table/CmapFormat12.java @@ -0,0 +1,81 @@ +/* + * 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 net.java.dev.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; + + protected 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() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public Range getRange(int index) throws ArrayIndexOutOfBoundsException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public int mapCharCode(int charCode) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + +} diff --git a/src/net/java/dev/typecast/ot/table/CmapFormat2.java b/src/net/java/dev/typecast/ot/table/CmapFormat2.java index 23ab390..cff572e 100644 --- a/src/net/java/dev/typecast/ot/table/CmapFormat2.java +++ b/src/net/java/dev/typecast/ot/table/CmapFormat2.java @@ -36,13 +36,15 @@ public class CmapFormat2 extends CmapFormat { 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(DataInput di) throws IOException { - super(di); - _format = 2; + _length = di.readUnsignedShort(); + _language = di.readUnsignedShort(); int pos = 6; @@ -87,6 +89,21 @@ 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; } diff --git a/src/net/java/dev/typecast/ot/table/CmapFormat4.java b/src/net/java/dev/typecast/ot/table/CmapFormat4.java index 16855e2..a7225ff 100644 --- a/src/net/java/dev/typecast/ot/table/CmapFormat4.java +++ b/src/net/java/dev/typecast/ot/table/CmapFormat4.java @@ -27,6 +27,8 @@ import java.io.IOException; */ 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; @@ -39,8 +41,8 @@ public class CmapFormat4 extends CmapFormat { private final int _segCount; protected CmapFormat4(DataInput di) throws IOException { - super(di); // 6 - _format = 4; + _length = di.readUnsignedShort(); + _language = di.readUnsignedShort(); _segCountX2 = di.readUnsignedShort(); // +2 (8) _segCount = _segCountX2 / 2; _endCode = new int[_segCount]; @@ -79,6 +81,21 @@ 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; } diff --git a/src/net/java/dev/typecast/ot/table/CmapFormat6.java b/src/net/java/dev/typecast/ot/table/CmapFormat6.java index a956a6c..af93e0a 100644 --- a/src/net/java/dev/typecast/ot/table/CmapFormat6.java +++ b/src/net/java/dev/typecast/ot/table/CmapFormat6.java @@ -27,13 +27,15 @@ import java.io.IOException; */ public class CmapFormat6 extends CmapFormat { + private final int _length; + private final int _language; private final int _firstCode; private final int _entryCount; private final int[] _glyphIdArray; protected CmapFormat6(DataInput di) throws IOException { - super(di); - _format = 6; + _length = di.readUnsignedShort(); + _language = di.readUnsignedShort(); _firstCode = di.readUnsignedShort(); _entryCount = di.readUnsignedShort(); _glyphIdArray = new int[_entryCount]; @@ -43,6 +45,21 @@ public class CmapFormat6 extends CmapFormat { } @Override + public int getFormat() { + return 6; + } + + @Override + public int getLength() { + return _length; + } + + @Override + public int getLanguage() { + return _language; + } + + @Override public int getRangeCount() { return 1; } diff --git a/src/net/java/dev/typecast/ot/table/CmapFormatUnknown.java b/src/net/java/dev/typecast/ot/table/CmapFormatUnknown.java index 2d59e9e..fe1fef3 100644 --- a/src/net/java/dev/typecast/ot/table/CmapFormatUnknown.java +++ b/src/net/java/dev/typecast/ot/table/CmapFormatUnknown.java @@ -28,16 +28,45 @@ import java.io.IOException; */ public class CmapFormatUnknown extends CmapFormat { + 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 */ protected CmapFormatUnknown(int format, DataInput di) throws IOException { - super(di); _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); + // 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; + } + + @Override + public int getLanguage() { + return _language; } @Override diff --git a/src/net/java/dev/typecast/ot/table/CmapTable.java b/src/net/java/dev/typecast/ot/table/CmapTable.java index 9dd93ee..868222e 100644 --- a/src/net/java/dev/typecast/ot/table/CmapTable.java +++ b/src/net/java/dev/typecast/ot/table/CmapTable.java @@ -56,7 +56,6 @@ 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> */ public class CmapTable implements Table { @@ -130,10 +129,12 @@ public class CmapTable implements Table { return null; } + @Override public int getType() { return cmap; } + @Override public String toString() { StringBuffer sb = new StringBuffer().append("cmap\n"); @@ -155,6 +156,7 @@ public class CmapTable implements Table { * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return _de; } |