This improves the hinting demo by adding options to show a grid, as well as the original and hinted glyphs.
2007-05-08 Roman Kennke <[EMAIL PROTECTED]>
* examples/gnu/classpath/examples/awt/HintingDemo.java
Add support for showing the original vs the hinted glyphs plus
a grid.
/Roman
--
aicas Allerton Interworks Computer Automated Systems GmbH
Haid-und-Neu-Straße 18 * D-76131 Karlsruhe * Germany
http://www.aicas.com * Tel: +49-721-663 968-0
USt-Id: DE216375633, Handelsregister HRB 109481, AG Karlsruhe
Geschäftsführer: Dr. James J. Hunt
Index: examples/gnu/classpath/examples/awt/HintingDemo.java
===================================================================
RCS file: /cvsroot/classpath/classpath/examples/gnu/classpath/examples/awt/HintingDemo.java,v
retrieving revision 1.1
diff -u -1 -5 -r1.1 HintingDemo.java
--- examples/gnu/classpath/examples/awt/HintingDemo.java 16 Dec 2006 20:53:10 -0000 1.1
+++ examples/gnu/classpath/examples/awt/HintingDemo.java 8 May 2007 12:40:32 -0000
@@ -8,67 +8,81 @@
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA. */
package gnu.classpath.examples.awt;
-import gnu.java.awt.font.*;
-import gnu.java.awt.font.opentype.*;
-
-import java.awt.*;
+import gnu.java.awt.font.FontDelegate;
+import gnu.java.awt.font.GNUGlyphVector;
+import gnu.java.awt.font.opentype.OpenTypeFontFactory;
+
+import java.awt.BasicStroke;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.GridLayout;
+import java.awt.Insets;
+import java.awt.RenderingHints;
+import java.awt.Shape;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.awt.font.*;
-import java.io.*;
-import java.nio.*;
-import java.nio.channels.*;
-import java.text.*;
+import java.awt.font.FontRenderContext;
+import java.io.File;
+import java.io.RandomAccessFile;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+import java.text.StringCharacterIterator;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class HintingDemo extends JFrame {
FontDelegate font;
GNUGlyphVector glyph;
GlyphPreview glyphPreview;
HintPanel hintPanel;
StringViewer stringViewer;
Chooser chooser;
char character;
Options options;
boolean antiAlias;
+ boolean showGrid;
+ boolean showOriginal;
+ boolean showHinted;
int flags;
class StringViewer extends JPanel
implements ActionListener
{
JTextField input;
GNUGlyphVector gv;
Viewer viewer;
StringViewer()
{
setLayout(new GridLayout(0, 1));
setBorder(new TitledBorder("Use this field to render complete strings"));
input = new JTextField();
input.addActionListener(this);
add(input);
@@ -121,48 +135,59 @@
class HintPanel extends JPanel
{
HintPanel()
{
setBorder(new TitledBorder("Detailed glyph view"));
}
protected void paintComponent(Graphics g)
{
if (glyph != null && g instanceof Graphics2D)
{
Graphics2D g2d = (Graphics2D) g.create();
Insets i = getInsets();
g2d.clearRect(i.left, i.top, getWidth() - i.left - i.right,
getHeight() - i.top - i.bottom);
- g2d.setColor(Color.GRAY);
- for (int x = 20; x < getWidth(); x += 20)
- {
- g2d.drawLine(x, i.top, x, getHeight() - i.top - i.bottom);
- }
- for (int y = 20; y < getHeight(); y += 20)
+ if (showGrid)
{
- g2d.drawLine(i.left, y, getWidth() - i.left - i.right, y);
+ g2d.setColor(Color.GRAY);
+ for (int x = 20; x < getWidth(); x += 20)
+ {
+ g2d.drawLine(x, i.top, x, getHeight() - i.top - i.bottom);
+ }
+ for (int y = 20; y < getHeight(); y += 20)
+ {
+ g2d.drawLine(i.left, y, getWidth() - i.left - i.right, y);
+ }
}
- g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_OFF);
+// g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+// RenderingHints.VALUE_ANTIALIAS_ON);
g2d.translate(40, 300);
g2d.scale(20., 20.);
- g2d.setStroke(new BasicStroke((float) (1/20.)));
- g2d.setColor(Color.RED);
- g2d.draw(glyph.getOutline(0, 0, flags & ~FontDelegate.FLAG_FITTED));
- g2d.setColor(Color.GREEN);
- g2d.draw(glyph.getOutline(0, 0, flags | FontDelegate.FLAG_FITTED));
+ g2d.setStroke(new BasicStroke((float) (1/10.)));
+ if (showOriginal)
+ {
+ g2d.setColor(Color.RED);
+ g2d.draw(glyph.getOutline(0, 0,
+ flags & ~FontDelegate.FLAG_FITTED));
+ }
+ if (showHinted)
+ {
+ g2d.setColor(Color.RED);
+ g2d.draw(glyph.getOutline(0, 0,
+ flags | FontDelegate.FLAG_FITTED));
+ }
}
}
}
class GlyphPreview extends JPanel
{
protected void paintComponent(Graphics g)
{
if (glyph != null && g instanceof Graphics2D)
{
Graphics2D g2d = (Graphics2D) g;
if (antiAlias)
{
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
@@ -174,31 +199,31 @@
RenderingHints.VALUE_ANTIALIAS_OFF);
}
g2d.clearRect(0, 0, getWidth(), getHeight());
g2d.setColor(Color.BLACK);
Shape outline = glyph.getOutline(0, 0,
flags | FontDelegate.FLAG_FITTED);
g2d.translate(20, outline.getBounds2D().getHeight() + 2);
g2d.fill(outline);
}
}
}
HintingDemo()
{
- File file = new File("/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType/DejaVuSerif.ttf");
+ File file = new File("/usr/share/fonts/truetype/freefont/FreeSans.ttf");
loadFont(file);
setLayout(new BorderLayout());
chooser = new Chooser();
add(chooser, BorderLayout.NORTH);
hintPanel = new HintPanel();
character = 'A';
add(hintPanel);
options = new Options();
add(options, BorderLayout.EAST);
stringViewer = new StringViewer();
add(stringViewer, BorderLayout.SOUTH);
refresh();
@@ -232,69 +257,87 @@
{
if (chooser != null)
chooser.refresh();
if (glyphPreview != null)
glyphPreview.repaint();
if (hintPanel != null)
hintPanel.repaint();
if (stringViewer != null)
stringViewer.refresh();
}
class Options extends JPanel
implements ActionListener
{
JCheckBox antiAliasOpt;
+ JCheckBox showGridOpt;
+ JCheckBox showOriginalOpt;
+ JCheckBox showHintedOpt;
JCheckBox hintHorizontalOpt;
JCheckBox hintVerticalOpt;
JCheckBox hintEdgeOpt;
JCheckBox hintStrongOpt;
JCheckBox hintWeakOpt;
Options()
{
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
setBorder(new TitledBorder("Hinting options"));
antiAliasOpt = new JCheckBox("Antialias");
antiAliasOpt.setSelected(true);
antiAliasOpt.addActionListener(this);
add(antiAliasOpt);
+ showGridOpt = new JCheckBox("Show grid");
+ showGridOpt.setSelected(true);
+ showGridOpt.addActionListener(this);
+ add(showGridOpt);
+ showOriginalOpt = new JCheckBox("Show original");
+ showOriginalOpt.setSelected(true);
+ showOriginalOpt.addActionListener(this);
+ add(showOriginalOpt);
+ showHintedOpt = new JCheckBox("Show hinted");
+ showHintedOpt.setSelected(true);
+ showHintedOpt.addActionListener(this);
+ add(showHintedOpt);
hintHorizontalOpt = new JCheckBox("Hint horizontal");
hintHorizontalOpt.setSelected(true);
hintHorizontalOpt.addActionListener(this);
add(hintHorizontalOpt);
hintVerticalOpt = new JCheckBox("Hint vertical");
hintVerticalOpt.setSelected(true);
hintVerticalOpt.addActionListener(this);
add(hintVerticalOpt);
hintEdgeOpt = new JCheckBox("Hint edge points");
hintEdgeOpt.setSelected(true);
hintEdgeOpt.addActionListener(this);
add(hintEdgeOpt);
hintStrongOpt = new JCheckBox("Hint strong points");
hintStrongOpt.setSelected(true);
hintStrongOpt.addActionListener(this);
add(hintStrongOpt);
hintWeakOpt = new JCheckBox("Hint weak points");
hintWeakOpt.setSelected(true);
hintWeakOpt.addActionListener(this);
add(hintWeakOpt);
sync();
}
void sync()
{
antiAlias = antiAliasOpt.isSelected();
+ showGrid = showGridOpt.isSelected();
+ showOriginal = showOriginalOpt.isSelected();
+ showHinted = showHintedOpt.isSelected();
if (hintHorizontalOpt.isSelected())
flags &= ~FontDelegate.FLAG_NO_HINT_HORIZONTAL;
else
flags |= FontDelegate.FLAG_NO_HINT_HORIZONTAL;
if (hintVerticalOpt.isSelected())
flags &= ~FontDelegate.FLAG_NO_HINT_VERTICAL;
else
flags |= FontDelegate.FLAG_NO_HINT_VERTICAL;
if (hintEdgeOpt.isSelected())
flags &= ~FontDelegate.FLAG_NO_HINT_EDGE_POINTS;
else
flags |= FontDelegate.FLAG_NO_HINT_EDGE_POINTS;
if (hintStrongOpt.isSelected())
flags &= ~FontDelegate.FLAG_NO_HINT_STRONG_POINTS;
else
signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
