aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--resources/logback.xml2
-rw-r--r--src/net/java/dev/typecast/ot/table/SbixTable.java141
-rw-r--r--src/net/java/dev/typecast/ot/table/Table.java26
-rw-r--r--src/net/java/dev/typecast/ot/table/TableFactory.java70
4 files changed, 179 insertions, 60 deletions
diff --git a/resources/logback.xml b/resources/logback.xml
index e29aa69..7e9514b 100644
--- a/resources/logback.xml
+++ b/resources/logback.xml
@@ -6,7 +6,7 @@
</encoder>
</appender>
- <root level="debug">
+ <root level="trace">
<appender-ref ref="STDOUT" />
</root>
</configuration>
diff --git a/src/net/java/dev/typecast/ot/table/SbixTable.java b/src/net/java/dev/typecast/ot/table/SbixTable.java
new file mode 100644
index 0000000..50e0355
--- /dev/null
+++ b/src/net/java/dev/typecast/ot/table/SbixTable.java
@@ -0,0 +1,141 @@
+/*
+ * 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.ByteArrayInputStream;
+import java.io.DataInput;
+import java.io.DataInputStream;
+import java.io.IOException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 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 class GlyphDataRecord {
+ private final short _originOffsetX;
+ private final short _originOffsetY;
+ private final int _graphicType;
+ private final byte[] _data;
+
+ private static final int PNG = 0x706E6720;
+
+ protected GlyphDataRecord(DataInput di, int dataLength) throws IOException {
+ _originOffsetX = di.readShort();
+ _originOffsetY = di.readShort();
+ _graphicType = di.readInt();
+
+ // Check the graphicType is valid
+ if (_graphicType != PNG) {
+ logger.error("Invalid graphicType: {}", _graphicType);
+ _data = null;
+ return;
+ }
+
+ _data = new byte[dataLength];
+ try {
+ di.readFully(_data);
+ } catch (IOException e) {
+ logger.error("Reading too much data");
+ }
+ }
+ }
+
+ private class Strike {
+ private final int _ppem;
+ private final int _resolution;
+ private final long[] _glyphDataOffset;
+ private final GlyphDataRecord[] _glyphDataRecord;
+
+ protected 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();
+ logger.trace("Skip: {}", _glyphDataOffset[i]);
+ bais.skip(_glyphDataOffset[i]);
+ _glyphDataRecord[i] = new GlyphDataRecord(new DataInputStream(bais), dataLength);
+ }
+ logger.debug("Loaded Strike: ppem = {}, resolution = {}", _ppem, _resolution);
+ }
+ }
+
+ private final DirectoryEntry _de;
+ private final int _version;
+ private final int _flags;
+ private final int _numStrikes;
+ private final int[] _strikeOffset;
+ private final Strike[] _strikes;
+
+ private final byte[] _buf;
+
+ static final Logger logger = LoggerFactory.getLogger(SbixTable.class);
+
+ protected SbixTable(DirectoryEntry de, DataInput di, MaxpTable maxp) throws IOException {
+ _de = (DirectoryEntry) de.clone();
+
+ // Load entire table into a buffer, and create another input stream
+ _buf = new byte[de.getLength()];
+ di.readFully(_buf);
+ DataInput di2 = new DataInputStream(getByteArrayInputStreamForOffset(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(_strikeOffset[i]);
+ _strikes[i] = new Strike(bais, maxp.getNumGlyphs());
+ }
+ }
+
+ private ByteArrayInputStream getByteArrayInputStreamForOffset(int offset) {
+ return new ByteArrayInputStream(
+ _buf, offset,
+ _de.getLength() - offset);
+ }
+
+ @Override
+ public int getType() {
+ return sbix;
+ }
+
+ @Override
+ public DirectoryEntry getDirectoryEntry() {
+ return _de;
+ }
+}
diff --git a/src/net/java/dev/typecast/ot/table/Table.java b/src/net/java/dev/typecast/ot/table/Table.java
index 1fcb352..0145b9f 100644
--- a/src/net/java/dev/typecast/ot/table/Table.java
+++ b/src/net/java/dev/typecast/ot/table/Table.java
@@ -1,11 +1,20 @@
-/*****************************************************************************
- * 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 net.java.dev.typecast.ot.table;
/**
@@ -46,6 +55,7 @@ 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
diff --git a/src/net/java/dev/typecast/ot/table/TableFactory.java b/src/net/java/dev/typecast/ot/table/TableFactory.java
index 7dea497..91a2e33 100644
--- a/src/net/java/dev/typecast/ot/table/TableFactory.java
+++ b/src/net/java/dev/typecast/ot/table/TableFactory.java
@@ -1,64 +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 - 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.DataInputStream;
-import java.io.InputStream;
import java.io.IOException;
import net.java.dev.typecast.ot.OTFont;
import net.java.dev.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 {
@@ -168,6 +133,9 @@ public class TableFactory {
case Table.post:
t = new PostTable(de, dis);
break;
+ case Table.sbix:
+ t = new SbixTable(de, dis, font.getMaxpTable());
+ break;
case Table.vhea:
t = new VheaTable(de, dis);
break;