diff options
author | David Schweinsberg <[email protected]> | 2016-01-28 20:49:59 +1100 |
---|---|---|
committer | David Schweinsberg <[email protected]> | 2016-01-28 20:49:59 +1100 |
commit | 477e12b8d36e9200347a0a4f54e22d91d369893e (patch) | |
tree | 126d17415efb66271b914846e9fd483ce06e6616 /src | |
parent | cfcd0a8f26410216217832d006aa5217301af63f (diff) |
Displays bitmaps within the 'sbix' table (#7)
Diffstat (limited to 'src')
7 files changed, 152 insertions, 38 deletions
diff --git a/src/net/java/dev/typecast/app/editor/BitmapPanel.java b/src/net/java/dev/typecast/app/editor/BitmapPanel.java new file mode 100644 index 0000000..bd2a927 --- /dev/null +++ b/src/net/java/dev/typecast/app/editor/BitmapPanel.java @@ -0,0 +1,63 @@ +/* + * 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.app.editor; + +import java.awt.Graphics; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import javax.imageio.ImageIO; +import javax.swing.JPanel; +import net.java.dev.typecast.app.framework.EditorView; +import net.java.dev.typecast.ot.OTFont; +import net.java.dev.typecast.ot.table.SbixTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A basic bitmap view. + * @author <a href="mailto:[email protected]">David Schweinsberg</a> + */ +public final class BitmapPanel extends JPanel implements EditorView { + + private BufferedImage _image; + + private static final long serialVersionUID = 1L; + + static final Logger logger = LoggerFactory.getLogger(BitmapPanel.class); + + public BitmapPanel() { + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + g.drawImage(_image, 0, 0, this); + } + + @Override + public void setModel(OTFont font, Object obj) { + SbixTable.GlyphDataRecord gdr = (SbixTable.GlyphDataRecord) obj; + ByteArrayInputStream input = new ByteArrayInputStream(gdr.getData()); + try { + _image = ImageIO.read(input); + } catch (IOException e) { + logger.error("Unable to load image data: " + e.toString()); + } + } +} diff --git a/src/net/java/dev/typecast/app/editor/DumpPanel.java b/src/net/java/dev/typecast/app/editor/DumpPanel.java index c12a5bf..b9ac77e 100644 --- a/src/net/java/dev/typecast/app/editor/DumpPanel.java +++ b/src/net/java/dev/typecast/app/editor/DumpPanel.java @@ -1,9 +1,7 @@ /* - * $Id: DumpPanel.java,v 1.2 2007-01-25 08:39:24 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,29 +20,24 @@ package net.java.dev.typecast.app.editor; import java.awt.BorderLayout; import java.awt.Font; - import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; - import net.java.dev.typecast.app.framework.EditorView; - import net.java.dev.typecast.ot.OTFont; /** * A simple view of an object's "toString()" output. * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: DumpPanel.java,v 1.2 2007-01-25 08:39:24 davidsch Exp $ */ public class DumpPanel extends JPanel implements EditorView { private static final long serialVersionUID = 1L; - private JTextArea _dumpTextArea; + private final JTextArea _dumpTextArea; /** Creates a new instance of DumpPanel */ public DumpPanel() { - setName("Dump"); setLayout(new BorderLayout()); _dumpTextArea = new JTextArea(); _dumpTextArea.setEditable(false); @@ -56,6 +49,7 @@ public class DumpPanel extends JPanel implements EditorView { BorderLayout.CENTER); } + @Override public void setModel(OTFont font, Object obj) { _dumpTextArea.setText(obj.toString()); } diff --git a/src/net/java/dev/typecast/app/editor/Main.java b/src/net/java/dev/typecast/app/editor/Main.java index 91a17a0..7f79bb6 100644 --- a/src/net/java/dev/typecast/app/editor/Main.java +++ b/src/net/java/dev/typecast/app/editor/Main.java @@ -402,9 +402,18 @@ public class Main { _tabbedPane.add(cm); } + // Bitmaps + if (obj instanceof net.java.dev.typecast.ot.table.SbixTable.GlyphDataRecord) { + BitmapPanel bitmapPanel = new BitmapPanel(); + bitmapPanel.setName("Bitmap"); + bitmapPanel.setModel(_selectedFont, obj); + _tabbedPane.add(bitmapPanel); + } + // All selections get a "dump" pane if (obj != null) { DumpPanel textPane = new DumpPanel(); + textPane.setName("Dump"); textPane.setModel(_selectedFont, obj); _tabbedPane.add(textPane); } diff --git a/src/net/java/dev/typecast/app/editor/TableTreeBuilder.java b/src/net/java/dev/typecast/app/editor/TableTreeBuilder.java index 0764466..732b95e 100644 --- a/src/net/java/dev/typecast/app/editor/TableTreeBuilder.java +++ b/src/net/java/dev/typecast/app/editor/TableTreeBuilder.java @@ -1,7 +1,7 @@ /* * Typecast - The Font Development Environment * - * Copyright (c) 2004-2015 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. @@ -42,6 +42,7 @@ import net.java.dev.typecast.ot.table.LookupSubtable; import net.java.dev.typecast.ot.table.NameRecord; import net.java.dev.typecast.ot.table.NameTable; import net.java.dev.typecast.ot.table.PostTable; +import net.java.dev.typecast.ot.table.SbixTable; import net.java.dev.typecast.ot.table.Script; import net.java.dev.typecast.ot.table.Table; @@ -246,19 +247,53 @@ public class TableTreeBuilder { } } + private static void addSbixStrike(OTFont font, TableTreeNode parent, SbixTable.Strike strike) { + int i = 0; + for (SbixTable.GlyphDataRecord gdr : strike.getGlyphDataRecords()) { + TableTreeNode n = new TableTreeNode( + String.valueOf(i), + gdr, + i++); + parent.add(n); + } + } + + private static void addSbixTable(OTFont font, TableTreeNode parent, SbixTable sbix) { + int i = 0; + for (SbixTable.Strike strike : sbix.getStrikes()) { + TableTreeNode n = new TableTreeNode( + strike.toString(), + strike, + i++); + parent.add(n); + addSbixStrike(font, n, strike); + } + } + private static void addTableDirectoryEntry(OTFont font, TableTreeNode parent, DirectoryEntry de) { TableTreeNode node = createNode(de.getTagAsString(), font.getTable(de.getTag())); parent.add(node); - if (de.getTag() == Table.name) { - addNameTable(node, (NameTable) font.getTable(Table.name)); - } else if (de.getTag() == Table.cmap) { - addCmapTable(node, (CmapTable) font.getTable(Table.cmap)); - } else if (de.getTag() == Table.glyf) { - addGlyfTable(font, node, (GlyfTable) font.getTable(Table.glyf)); - } else if (de.getTag() == Table.CFF) { - addCffTable(font, node, (CffTable) font.getTable(Table.CFF)); - } else if (de.getTag() == Table.GSUB) { - addGsubTable(node, (GsubTable) font.getTable(Table.GSUB)); + switch (de.getTag()) { + case Table.name: + addNameTable(node, (NameTable) font.getTable(Table.name)); + break; + case Table.cmap: + addCmapTable(node, (CmapTable) font.getTable(Table.cmap)); + break; + case Table.glyf: + addGlyfTable(font, node, (GlyfTable) font.getTable(Table.glyf)); + break; + case Table.CFF: + addCffTable(font, node, (CffTable) font.getTable(Table.CFF)); + break; + case Table.GSUB: + addGsubTable(node, (GsubTable) font.getTable(Table.GSUB)); + break; + case Table.sbix: + addSbixTable(font, node, (SbixTable) font.getTable(Table.sbix)); + break; + default: + break; } } diff --git a/src/net/java/dev/typecast/app/editor/TableTreeNode.java b/src/net/java/dev/typecast/app/editor/TableTreeNode.java index 5583fd0..7718eef 100644 --- a/src/net/java/dev/typecast/app/editor/TableTreeNode.java +++ b/src/net/java/dev/typecast/app/editor/TableTreeNode.java @@ -1,9 +1,7 @@ /* - * $Id: TableTreeNode.java,v 1.1 2007-01-24 09:36:58 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. @@ -23,7 +21,6 @@ package net.java.dev.typecast.app.editor; /** * * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: TableTreeNode.java,v 1.1 2007-01-24 09:36:58 davidsch Exp $ */ public class TableTreeNode extends javax.swing.tree.DefaultMutableTreeNode { diff --git a/src/net/java/dev/typecast/app/framework/EditorView.java b/src/net/java/dev/typecast/app/framework/EditorView.java index 973096f..f97e982 100644 --- a/src/net/java/dev/typecast/app/framework/EditorView.java +++ b/src/net/java/dev/typecast/app/framework/EditorView.java @@ -1,9 +1,7 @@ /* - * $Id: EditorView.java,v 1.1 2007-01-24 09:37:57 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. @@ -25,7 +23,6 @@ import net.java.dev.typecast.ot.OTFont; /** * The standard interface for all Typecast editor "view" components. * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: EditorView.java,v 1.1 2007-01-24 09:37:57 davidsch Exp $ */ public interface EditorView { public void setModel(OTFont font, Object obj); diff --git a/src/net/java/dev/typecast/ot/table/SbixTable.java b/src/net/java/dev/typecast/ot/table/SbixTable.java index 50e0355..3d9f5f8 100644 --- a/src/net/java/dev/typecast/ot/table/SbixTable.java +++ b/src/net/java/dev/typecast/ot/table/SbixTable.java @@ -31,7 +31,7 @@ import org.slf4j.LoggerFactory; */ public class SbixTable implements Table { - private class GlyphDataRecord { + public class GlyphDataRecord { private final short _originOffsetX; private final short _originOffsetY; private final int _graphicType; @@ -58,9 +58,17 @@ public class SbixTable implements Table { logger.error("Reading too much data"); } } + + public int getGraphicType() { + return _graphicType; + } + + public byte[] getData() { + return _data; + } } - private class Strike { + public class Strike { private final int _ppem; private final int _resolution; private final long[] _glyphDataOffset; @@ -87,6 +95,15 @@ public class SbixTable implements Table { } logger.debug("Loaded Strike: ppem = {}, resolution = {}", _ppem, _resolution); } + + public GlyphDataRecord[] getGlyphDataRecords() { + return _glyphDataRecord; + } + + @Override + public String toString() { + return String.format("ppem: %d, resolution: %d", _ppem, _resolution); + } } private final DirectoryEntry _de; @@ -96,17 +113,15 @@ public class SbixTable implements Table { 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)); + byte[] buf = new byte[de.getLength()]; + di.readFully(buf); + DataInput di2 = new DataInputStream(getByteArrayInputStreamForOffset(buf, 0)); _version = di2.readUnsignedShort(); _flags = di2.readUnsignedShort(); @@ -118,16 +133,20 @@ public class SbixTable implements Table { _strikes = new Strike[_numStrikes]; for (int i = 0; i < _numStrikes; ++i) { - ByteArrayInputStream bais = getByteArrayInputStreamForOffset(_strikeOffset[i]); + ByteArrayInputStream bais = getByteArrayInputStreamForOffset(buf, _strikeOffset[i]); _strikes[i] = new Strike(bais, maxp.getNumGlyphs()); } } - private ByteArrayInputStream getByteArrayInputStreamForOffset(int offset) { + private ByteArrayInputStream getByteArrayInputStreamForOffset(byte[] buf, int offset) { return new ByteArrayInputStream( - _buf, offset, + buf, offset, _de.getLength() - offset); } + + public Strike[] getStrikes() { + return _strikes; + } @Override public int getType() { |