diff options
author | David Schweinsberg <[email protected]> | 2004-12-21 16:55:48 +0000 |
---|---|---|
committer | David Schweinsberg <[email protected]> | 2004-12-21 16:55:48 +0000 |
commit | 6796581b25f967f5e7ba7a32cc72093d968802a4 (patch) | |
tree | 8e04a6f1fa53946a87e3f391e13382ad86174e4d | |
parent | a4b90ff947b7c56ef1bbe290aa0ed423eba5f671 (diff) |
- extended to show character codes
- scaling of font calculated from units-per-em
-rw-r--r-- | src/net/java/dev/typecast/edit/CharacterMap.java | 63 |
1 files changed, 50 insertions, 13 deletions
diff --git a/src/net/java/dev/typecast/edit/CharacterMap.java b/src/net/java/dev/typecast/edit/CharacterMap.java index a583b74..51a7cba 100644 --- a/src/net/java/dev/typecast/edit/CharacterMap.java +++ b/src/net/java/dev/typecast/edit/CharacterMap.java @@ -1,5 +1,5 @@ /* - * $Id: CharacterMap.java,v 1.1 2004-12-21 10:24:35 davidsch Exp $ + * $Id: CharacterMap.java,v 1.2 2004-12-21 16:55:48 davidsch Exp $ * * Typecast - The Font Development Environment * @@ -21,13 +21,19 @@ package net.java.dev.typecast.edit; import java.awt.BorderLayout; +import java.awt.Color; import java.awt.Component; import java.awt.Dimension; +import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Rectangle; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; + import java.awt.geom.AffineTransform; import java.util.ArrayList; @@ -48,18 +54,19 @@ import net.java.dev.typecast.render.GlyphImageFactory; /** * An editor for the character-to-glyph map, as represented in the CmapTable. * @author <a href="mailto:[email protected]">David Schweinsberg</a> - * @version $Id: CharacterMap.java,v 1.1 2004-12-21 10:24:35 davidsch Exp $ + * @version $Id: CharacterMap.java,v 1.2 2004-12-21 16:55:48 davidsch Exp $ */ public class CharacterMap extends JScrollPane { private static final long serialVersionUID = 1L; - private static final int CELL_WIDTH = 40; - private static final int CELL_HEIGHT = 40; + private static final int CELL_WIDTH = 48; + private static final int CELL_HEIGHT = 60; private AbstractListModel _listModel; private OTFont _font; private AffineTransform _tx; + private Font _labelFont = new Font("SansSerif", Font.PLAIN, 10); private class Mapping { @@ -86,7 +93,7 @@ public class CharacterMap extends JScrollPane { _font.getGlyph(_glyphCode), _tx, CELL_WIDTH, - CELL_HEIGHT); + CELL_HEIGHT - 10); } return _glyphImage; } @@ -97,10 +104,28 @@ public class CharacterMap extends JScrollPane { private static final long serialVersionUID = 1L; private Mapping _mapping; - private AffineTransform _imageTx = new AffineTransform(); + private boolean _isSelected; + private AffineTransform _imageTx = + new AffineTransform(1.0, 0.0, 0.0, 1.0, 0.0, 10.0); + /** + * Renders each individual cell + */ protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; + + g2d.setColor(Color.BLACK); + + if (_isSelected) { + g2d.fillRect(0, 0, CELL_WIDTH, 10); + g2d.setColor(Color.WHITE); + } + + // Label this cell with the character code + g2d.setFont(_labelFont); + g2d.drawString(String.format("%04X", _mapping.getCharCode()), 1, 9); + + // Draw the glyph g2d.drawImage(_mapping.getGlyphImage(), _imageTx, null); } @@ -111,6 +136,7 @@ public class CharacterMap extends JScrollPane { boolean isSelected, boolean cellHasFocus) { _mapping = (Mapping) value; + _isSelected = isSelected; setPreferredSize(new Dimension(CELL_WIDTH, CELL_HEIGHT)); return this; } @@ -121,6 +147,7 @@ public class CharacterMap extends JScrollPane { _font = font; + // Set up a list model to wrap the cmap AbstractListModel _listModel = new AbstractListModel() { private static final long serialVersionUID = 1L; @@ -144,24 +171,34 @@ public class CharacterMap extends JScrollPane { return _mappings.size(); } }; - - JList list = new JList(_listModel); + + final JList list = new JList(_listModel); list.setCellRenderer(new CharListCellRenderer()); list.setLayoutOrientation(JList.HORIZONTAL_WRAP); -// setHorizontalScrollBarPolicy( -// ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); list.setVisibleRowCount( _listModel.getSize() / 16 + (_listModel.getSize() % 16 > 0 ? 1 : 0)); -// list.setPreferredSize(new Dimension(400, 400)); setViewportView(list); + // Create a mouse listener so we can listen to double-clicks + MouseListener mouseListener = new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 2) { + int index = list.locationToIndex(e.getPoint()); + } + } + }; + list.addMouseListener(mouseListener); + // int unitsPerEmBy2 = _font.getHeadTable().getUnitsPerEm() / 2; // int translateX = 2 * unitsPerEmBy2; // int translateY = 2 * unitsPerEmBy2; + // How much should we scale the font to fit it into our tint bitmap? + double scaleFactor = 40.0 / _font.getHeadTable().getUnitsPerEm(); + _tx = new AffineTransform(); - _tx.translate(0, CELL_HEIGHT); - _tx.scale(0.02, 0.02); + _tx.translate(2, CELL_HEIGHT - 20); + _tx.scale(scaleFactor, scaleFactor); } } |