8283664: Remove jtreg tag manual=yesno for java/awt/print/PrinterJob/PrintTextTest.java

Reviewed-by: honkar, aivanov, aturbanov
This commit is contained in:
Daniel Gredler 2024-11-07 20:19:50 +00:00
parent 2c7bea1cb2
commit 84c99fb91f
2 changed files with 341 additions and 436 deletions

View File

@ -806,6 +806,7 @@ java/awt/image/VolatileImage/VolatileImageConfigurationTest.java 8171069 macosx-
java/awt/Modal/InvisibleParentTest/InvisibleParentTest.java 8172245 linux-all java/awt/Modal/InvisibleParentTest/InvisibleParentTest.java 8172245 linux-all
java/awt/Frame/FrameStateTest/FrameStateTest.java 8203920 macosx-all,linux-all java/awt/Frame/FrameStateTest/FrameStateTest.java 8203920 macosx-all,linux-all
java/awt/print/PrinterJob/ScaledText/ScaledText.java 8231226 macosx-all java/awt/print/PrinterJob/ScaledText/ScaledText.java 8231226 macosx-all
java/awt/print/PrinterJob/PrintTextTest.java 8148334 generic-all
java/awt/font/TextLayout/TestJustification.java 8250791 macosx-all java/awt/font/TextLayout/TestJustification.java 8250791 macosx-all
java/awt/TrayIcon/DragEventSource/DragEventSource.java 8252242 macosx-all java/awt/TrayIcon/DragEventSource/DragEventSource.java 8252242 macosx-all
java/awt/FileDialog/DefaultFocusOwner/DefaultFocusOwner.java 7187728 macosx-all,linux-all java/awt/FileDialog/DefaultFocusOwner/DefaultFocusOwner.java 7187728 macosx-all,linux-all

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -21,193 +21,207 @@
* questions. * questions.
*/ */
/** /*
* @test * @test
* @bug 6425068 7157659 8132890 * @bug 6425068 7157659 8132890
* @key printer * @key printer
* @summary Confirm that text prints where we expect to the length we expect. * @summary Confirm that text prints where we expect to the length we expect.
* @run main/manual=yesno PrintTextTest * @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual PrintTextTest
*/ */
import java.awt.*; import java.awt.BorderLayout;
import java.awt.event.*; import java.awt.Color;
import java.text.*; import java.awt.Component;
import java.util.*; import java.awt.Dimension;
import java.awt.font.*; import java.awt.Font;
import java.awt.geom.*; import java.awt.FontMetrics;
import java.awt.print.*; import java.awt.Graphics;
import javax.swing.*; import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.RenderingHints;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.font.TextLayout;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.print.Book;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.text.AttributedCharacterIterator;
import java.text.AttributedString;
import java.util.HashMap;
public class PrintTextTest extends Component implements Printable { import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
static int preferredSize; public class PrintTextTest {
Font textFont;
AffineTransform gxTx;
String page;
boolean useFM;
public static void main(String args[]) { static final String INSTRUCTIONS = """
String[] instructions = This tests that printed text renders similarly to on-screen under a variety
{ of APIs and graphics and font transforms.
"This tests that printed text renders similarly to on-screen", 1. Print to your preferred printer.
"under a variety of APIs and graphics and font transforms", 2. Collect the output.
"Print to your preferred printer. Collect the output.", 3. Refer to the onscreen buttons to cycle through the on-screen content.
"Refer to the onscreen buttons to cycle through the on-screen", 4. For each page, confirm that the printed content corresponds to the
"content", on-screen rendering for that *same* page. Some cases may look odd but
"For each page, confirm that the printed content corresponds to", its intentional. Verify it looks the same on screen and on the printer.
"the on-screen rendering for that *same* page.", Note that text does not scale linearly from screen to printer so some
"Some cases may look odd but its intentional. Verify", differences are normal and not a bug.
"it looks the same on screen and on the printer.", The easiest way to spot real problems is to check that any underlines are
"Note that text does not scale linearly from screen to printer", the same length as the underlined text and that any rotations are the same
"so some differences are normal and not a bug.", in each case.
"The easiest way to spot real problems is to check that", Note that each on-screen page is printed in both portrait and landscape mode.
"any underlines are the same length as the underlined text", So for example, Page 1/Portrait, and Page 1/Landscape when rotated to view
"and that any rotations are the same in each case.", properly, should both match Page 1 on screen.
"Note that each on-screen page is printed in both portrait", """;
"and landscape mode",
"So for example, Page 1/Portrait, and Page 1/Landscape when",
"rotated to view properly, should both match Page 1 on screen.",
};
Sysout.createDialogWithInstructions(instructions);
public static void main(String[] args) throws Exception {
PrinterJob pjob = PrinterJob.getPrinterJob(); PrinterJob pjob = PrinterJob.getPrinterJob();
PageFormat portrait = pjob.defaultPage(); PageFormat portrait = pjob.defaultPage();
portrait.setOrientation(PageFormat.PORTRAIT); portrait.setOrientation(PageFormat.PORTRAIT);
preferredSize = (int)portrait.getImageableWidth(); int preferredSize = (int) portrait.getImageableWidth();
PageFormat landscape = pjob.defaultPage(); PageFormat landscape = pjob.defaultPage();
landscape.setOrientation(PageFormat.LANDSCAPE); landscape.setOrientation(PageFormat.LANDSCAPE);
Book book = new Book(); Book book = new Book();
JTabbedPane p = new JTabbedPane(); JTabbedPane pane = new JTabbedPane();
int page = 1; int page = 1;
Font font = new Font("Dialog", Font.PLAIN, 18); Font font = new Font(Font.DIALOG, Font.PLAIN, 18);
String name = "Page " + new Integer(page++); String name = "Page " + page++;
PrintTextTest ptt = new PrintTextTest(name, font, null, false); PrintText pt = new PrintText(name, font, null, false, preferredSize);
p.add(name, ptt); pane.addTab(name, pt);
book.append(ptt, portrait); book.append(pt, portrait);
book.append(ptt, landscape); book.append(pt, landscape);
font = new Font("Dialog", Font.PLAIN, 18); font = new Font(Font.DIALOG, Font.PLAIN, 18);
name = "Page " + new Integer(page++); name = "Page " + page++;
ptt = new PrintTextTest(name, font, null, true); pt = new PrintText(name, font, null, true, preferredSize);
p.add(name, ptt); pane.addTab(name, pt);
book.append(ptt, portrait); book.append(pt, portrait);
book.append(ptt, landscape); book.append(pt, landscape);
font = getPhysicalFont(); font = getPhysicalFont();
name = "Page " + new Integer(page++); name = "Page " + page++;
ptt = new PrintTextTest(name, font, null, false); pt = new PrintText(name, font, null, false, preferredSize);
p.add(name, ptt); pane.addTab(name, pt);
book.append(ptt, portrait); book.append(pt, portrait);
book.append(ptt, landscape); book.append(pt, landscape);
font = getPhysicalFont(); font = getPhysicalFont();
AffineTransform rotTx = AffineTransform.getRotateInstance(0.15); AffineTransform rotTx = AffineTransform.getRotateInstance(0.15);
rotTx.translate(60,0); rotTx.translate(60, 0);
name = "Page " + new Integer(page++); name = "Page " + page++;
ptt = new PrintTextTest(name, font, rotTx, false); pt = new PrintText(name, font, rotTx, false, preferredSize);
p.add(name, ptt); pane.addTab(name, pt);
book.append(ptt, portrait); book.append(pt, portrait);
book.append(ptt, landscape); book.append(pt, landscape);
font = new Font("Dialog", Font.PLAIN, 18); font = new Font(Font.DIALOG, Font.PLAIN, 18);
AffineTransform scaleTx = AffineTransform.getScaleInstance(1.25, 1.25); AffineTransform scaleTx = AffineTransform.getScaleInstance(1.25, 1.25);
name = "Page " + new Integer(page++); name = "Page " + page++;
ptt = new PrintTextTest(name, font, scaleTx, false); pt = new PrintText(name, font, scaleTx, false, preferredSize);
p.add(name, ptt); pane.addTab(name, pt);
book.append(ptt, portrait); book.append(pt, portrait);
book.append(ptt, landscape); book.append(pt, landscape);
font = new Font("Dialog", Font.PLAIN, 18); font = new Font(Font.DIALOG, Font.PLAIN, 18);
scaleTx = AffineTransform.getScaleInstance(-1.25, 1.25); scaleTx = AffineTransform.getScaleInstance(-1.25, 1.25);
scaleTx.translate(-preferredSize/1.25, 0); scaleTx.translate(-preferredSize / 1.25, 0);
name = "Page " + new Integer(page++); name = "Page " + page++;
ptt = new PrintTextTest(name, font, scaleTx, false); pt = new PrintText(name, font, scaleTx, false, preferredSize);
p.add(name, ptt); pane.addTab(name, pt);
book.append(ptt, portrait); book.append(pt, portrait);
book.append(ptt, landscape); book.append(pt, landscape);
font = new Font("Dialog", Font.PLAIN, 18); font = new Font(Font.DIALOG, Font.PLAIN, 18);
scaleTx = AffineTransform.getScaleInstance(1.25, -1.25); scaleTx = AffineTransform.getScaleInstance(1.25, -1.25);
scaleTx.translate(0, -preferredSize/1.25); scaleTx.translate(0, -preferredSize / 1.25);
name = "Page " + new Integer(page++); name = "Page " + page++;
ptt = new PrintTextTest(name, font, scaleTx, false); pt = new PrintText(name, font, scaleTx, false, preferredSize);
p.add(name, ptt); pane.addTab(name, pt);
book.append(ptt, portrait); book.append(pt, portrait);
book.append(ptt, landscape); book.append(pt, landscape);
font = font.deriveFont(rotTx); font = font.deriveFont(rotTx);
name = "Page " + new Integer(page++); name = "Page " + page++;
ptt = new PrintTextTest(name, font, null, false); pt = new PrintText(name, font, null, false, preferredSize);
p.add(ptt, BorderLayout.CENTER); pane.addTab(name, pt);
p.add(name, ptt); book.append(pt, portrait);
book.append(ptt, portrait); book.append(pt, landscape);
book.append(ptt, landscape);
font = new Font("Monospaced", Font.PLAIN, 12); font = new Font(Font.MONOSPACED, Font.PLAIN, 12);
name = "Page " + new Integer(page++); name = "Page " + page++;
ptt = new PrintTextTest(name, font, null, false); pt = new PrintText(name, font, null, false, preferredSize);
p.add(ptt, BorderLayout.CENTER); pane.addTab(name, pt);
p.add(name, ptt); book.append(pt, portrait);
book.append(ptt, portrait); book.append(pt, landscape);
book.append(ptt, landscape);
Font xfont = font.deriveFont(AffineTransform.getScaleInstance(1.5, 1)); Font xfont = font.deriveFont(AffineTransform.getScaleInstance(1.5, 1));
name = "Page " + new Integer(page++); name = "Page " + page++;
ptt = new PrintTextTest(name, xfont, null, false); pt = new PrintText(name, xfont, null, false, preferredSize);
p.add(ptt, BorderLayout.CENTER); pane.addTab(name, pt);
p.add(name, ptt); book.append(pt, portrait);
book.append(ptt, portrait); book.append(pt, landscape);
book.append(ptt, landscape);
Font yfont = font.deriveFont(AffineTransform.getScaleInstance(1, 1.5)); Font yfont = font.deriveFont(AffineTransform.getScaleInstance(1, 1.5));
name = "Page " + new Integer(page++); name = "Page " + page++;
ptt = new PrintTextTest(name, yfont, null, false); pt = new PrintText(name, yfont, null, false, preferredSize);
p.add(ptt, BorderLayout.CENTER); pane.addTab(name, pt);
p.add(name, ptt); book.append(pt, portrait);
book.append(ptt, portrait); book.append(pt, landscape);
book.append(ptt, landscape);
if (System.getProperty("os.name").startsWith("Windows")) { if (System.getProperty("os.name").startsWith("Windows")) {
font = new Font("MS Gothic", Font.PLAIN, 12); font = new Font("MS Gothic", Font.PLAIN, 12);
name = "Page " + new Integer(page++); name = "Page " + page++;
ptt = new PrintJAText(name, font, null, true); pt = new PrintJapaneseText(name, font, null, true, preferredSize);
p.add(ptt, BorderLayout.CENTER); pane.addTab(name, pt);
p.add(name, ptt); book.append(pt, portrait);
book.append(ptt, portrait); book.append(pt, landscape);
book.append(ptt, landscape);
font = new Font("MS Gothic", Font.PLAIN, 12); font = new Font("MS Gothic", Font.PLAIN, 12);
name = "Page " + new Integer(page++); name = "Page " + page++;
rotTx = AffineTransform.getRotateInstance(0.15); rotTx = AffineTransform.getRotateInstance(0.15);
ptt = new PrintJAText(name, font, rotTx, true); pt = new PrintJapaneseText(name, font, rotTx, true, preferredSize);
p.add(ptt, BorderLayout.CENTER); pane.addTab(name, pt);
p.add(name, ptt); book.append(pt, portrait);
book.append(ptt, portrait); book.append(pt, landscape);
book.append(ptt, landscape);
} }
pjob.setPageable(book); pjob.setPageable(book);
JFrame f = new JFrame(); JButton printButton = new JButton("Print");
f.add(BorderLayout.CENTER, p); printButton.addActionListener(event -> {
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
f.pack();
f.show();
try { try {
if (pjob.printDialog()) { if (pjob.printDialog()) {
pjob.print(); pjob.print();
} }
} catch (PrinterException e) { } catch (PrinterException e) {
throw new RuntimeException(e.getMessage()); throw new RuntimeException(e.getMessage(), e);
} }
});
JFrame f = new JFrame("PrintTextTest");
f.add(BorderLayout.CENTER, pane);
f.add(BorderLayout.SOUTH, printButton);
f.pack();
PassFailJFrame.builder()
.title("PrintTextTest")
.instructions(INSTRUCTIONS)
.testTimeOut(10)
.columns(60)
.testUI(f)
.build()
.awaitAndCheck();
} }
// The test needs a physical font that supports Latin. // The test needs a physical font that supports Latin.
@ -221,13 +235,13 @@ public class PrintTextTest extends Component implements Printable {
String[] names = ge.getAvailableFontFamilyNames(); String[] names = ge.getAvailableFontFamilyNames();
for (String n : names) { for (String n : names) {
switch (n.toLowerCase()) { switch (n) {
case "dialog": case Font.DIALOG:
case "dialoginput": case Font.DIALOG_INPUT:
case "serif": case Font.SERIF:
case "sansserif": case Font.SANS_SERIF:
case "monospaced": case Font.MONOSPACED:
break; continue;
default: default:
Font f = new Font(n, Font.PLAIN, 18); Font f = new Font(n, Font.PLAIN, 18);
if (f.canDisplayUpTo("AZaz09") == -1) { if (f.canDisplayUpTo("AZaz09") == -1) {
@ -240,20 +254,28 @@ public class PrintTextTest extends Component implements Printable {
return physicalFont; return physicalFont;
} }
public PrintTextTest(String page, Font font, AffineTransform gxTx, private static class PrintText extends Component implements Printable {
boolean fm) {
protected final Font textFont;
protected final AffineTransform gxTx;
protected final String page;
protected final boolean useFM;
protected final int preferredSize;
public PrintText(String page, Font font, AffineTransform gxTx, boolean fm, int size) {
this.page = page; this.page = page;
textFont = font; this.textFont = font;
this.gxTx = gxTx; this.gxTx = gxTx;
this.useFM = fm; this.useFM = fm;
setBackground(Color.white); this.preferredSize = size;
setBackground(Color.WHITE);
} }
public static AttributedCharacterIterator getIterator(String s) { private static AttributedCharacterIterator getIterator(String s) {
return new AttributedString(s).getIterator(); return new AttributedString(s).getIterator();
} }
static String orient(PageFormat pf) { private static String orient(PageFormat pf) {
if (pf.getOrientation() == PageFormat.PORTRAIT) { if (pf.getOrientation() == PageFormat.PORTRAIT) {
return "Portrait"; return "Portrait";
} else { } else {
@ -261,31 +283,32 @@ public class PrintTextTest extends Component implements Printable {
} }
} }
@Override
public int print(Graphics g, PageFormat pf, int pageIndex) { public int print(Graphics g, PageFormat pf, int pageIndex) {
Graphics2D g2d = (Graphics2D) g;
Graphics2D g2d = (Graphics2D)g;
g2d.translate(pf.getImageableX(), pf.getImageableY()); g2d.translate(pf.getImageableX(), pf.getImageableY());
g.drawString(page+" "+orient(pf),50,20); g.drawString(page + " " + orient(pf), 50, 20);
g.translate(0, 25); g.translate(0, 25);
paint(g); paint(g);
return PAGE_EXISTS; return PAGE_EXISTS;
} }
@Override
public Dimension getMinimumSize() { public Dimension getMinimumSize() {
return getPreferredSize(); return getPreferredSize();
} }
@Override
public Dimension getPreferredSize() { public Dimension getPreferredSize() {
return new Dimension(preferredSize, preferredSize); return new Dimension(preferredSize, preferredSize);
} }
@Override
public void paint(Graphics g) { public void paint(Graphics g) {
/* fill with white before any transformation is applied */ g.setColor(Color.WHITE);
g.setColor(Color.white);
g.fillRect(0, 0, getSize().width, getSize().height); g.fillRect(0, 0, getSize().width, getSize().height);
Graphics2D g2d = (Graphics2D) g; Graphics2D g2d = (Graphics2D) g;
if (gxTx != null) { if (gxTx != null) {
g2d.transform(gxTx); g2d.transform(gxTx);
@ -300,13 +323,13 @@ public class PrintTextTest extends Component implements Printable {
String s; String s;
int LS = 30; int LS = 30;
int ix=10, iy=LS+10; int ix = 10, iy = LS + 10;
g.setColor(Color.black); g.setColor(Color.BLACK);
s = "drawString(String str, int x, int y)"; s = "drawString(String str, int x, int y)";
g.drawString(s, ix, iy); g.drawString(s, ix, iy);
if (!textFont.isTransformed()) { if (!textFont.isTransformed()) {
g.drawLine(ix, iy+1, ix+fm.stringWidth(s), iy+1); g.drawLine(ix, iy + 1, ix + fm.stringWidth(s), iy + 1);
} }
iy += LS; iy += LS;
@ -317,12 +340,12 @@ public class PrintTextTest extends Component implements Printable {
s = "\tdrawChars(\t\r\nchar[], int off, int len, int x, int y\t)"; s = "\tdrawChars(\t\r\nchar[], int off, int len, int x, int y\t)";
g.drawChars(s.toCharArray(), 0, s.length(), ix, iy); g.drawChars(s.toCharArray(), 0, s.length(), ix, iy);
if (!textFont.isTransformed()) { if (!textFont.isTransformed()) {
g.drawLine(ix, iy+1, ix+fm.stringWidth(s), iy+1); g.drawLine(ix, iy + 1, ix + fm.stringWidth(s), iy + 1);
} }
iy += LS; iy += LS;
s = "drawBytes(byte[], int off, int len, int x, int y)"; s = "drawBytes(byte[], int off, int len, int x, int y)";
byte data[] = new byte[s.length()]; byte[] data = new byte[s.length()];
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
data[i] = (byte) s.charAt(i); data[i] = (byte) s.charAt(i);
} }
@ -335,11 +358,11 @@ public class PrintTextTest extends Component implements Printable {
s = "drawString(String s, float x, float y)"; s = "drawString(String s, float x, float y)";
g2d.drawString(s, (float) ix, (float) iy); g2d.drawString(s, (float) ix, (float) iy);
if (!textFont.isTransformed()) { if (!textFont.isTransformed()) {
g.drawLine(ix, iy+1, ix+fm.stringWidth(s), iy+1); g.drawLine(ix, iy + 1, ix + fm.stringWidth(s), iy + 1);
} }
iy += LS; iy += LS;
s = "drawString(AttributedCharacterIterator iterator, "+ s = "drawString(AttributedCharacterIterator iterator, " +
"float x, float y)"; "float x, float y)";
g2d.drawString(getIterator(s), (float) ix, (float) iy); g2d.drawString(getIterator(s), (float) ix, (float) iy);
@ -349,7 +372,7 @@ public class PrintTextTest extends Component implements Printable {
g2d.drawGlyphVector(gv, ix, iy); g2d.drawGlyphVector(gv, ix, iy);
Point2D adv = gv.getGlyphPosition(gv.getNumGlyphs()); Point2D adv = gv.getGlyphPosition(gv.getNumGlyphs());
if (!textFont.isTransformed()) { if (!textFont.isTransformed()) {
g.drawLine(ix, iy+1, ix+(int)adv.getX(), iy+1); g.drawLine(ix, iy + 1, ix + (int) adv.getX(), iy + 1);
} }
iy += LS; iy += LS;
@ -358,33 +381,33 @@ public class PrintTextTest extends Component implements Printable {
gv = f.createGlyphVector(frc, s); gv = f.createGlyphVector(frc, s);
int ng = gv.getNumGlyphs(); int ng = gv.getNumGlyphs();
adv = gv.getGlyphPosition(ng); adv = gv.getGlyphPosition(ng);
for (int i=0; i<ng; i++) { for (int i = 0; i < ng; i++) {
Point2D gp = gv.getGlyphPosition(i); Point2D gp = gv.getGlyphPosition(i);
double gx = gp.getX(); double gx = gp.getX();
double gy = gp.getY(); double gy = gp.getY();
if (i % 2 == 0) { if (i % 2 == 0) {
gy+=5; gy += 5;
} else { } else {
gy-=5; gy -= 5;
} }
gp.setLocation(gx, gy); gp.setLocation(gx, gy);
gv.setGlyphPosition(i, gp); gv.setGlyphPosition(i, gp);
} }
g2d.drawGlyphVector(gv, ix, iy); g2d.drawGlyphVector(gv, ix, iy);
if (!textFont.isTransformed()) { if (!textFont.isTransformed()) {
g.drawLine(ix, iy+1, ix+(int)adv.getX(), iy+1); g.drawLine(ix, iy + 1, ix + (int) adv.getX(), iy + 1);
} }
iy +=LS; iy += LS;
s = "drawString: \u0924\u094d\u0930 \u0915\u0948\u0930\u0947 End."; s = "drawString: \u0924\u094d\u0930 \u0915\u0948\u0930\u0947 End.";
g.drawString(s, ix, iy); g.drawString(s, ix, iy);
if (!textFont.isTransformed()) { if (!textFont.isTransformed()) {
g.drawLine(ix, iy+1, ix+fm.stringWidth(s), iy+1); g.drawLine(ix, iy + 1, ix + fm.stringWidth(s), iy + 1);
} }
iy += LS; iy += LS;
s = "TextLayout 1: \u0924\u094d\u0930 \u0915\u0948\u0930\u0947 End."; s = "TextLayout 1: \u0924\u094d\u0930 \u0915\u0948\u0930\u0947 End.";
TextLayout tl = new TextLayout(s, new HashMap(), frc); TextLayout tl = new TextLayout(s, new HashMap<>(), frc);
tl.draw(g2d, ix, iy); tl.draw(g2d, ix, iy);
iy += LS; iy += LS;
@ -392,28 +415,24 @@ public class PrintTextTest extends Component implements Printable {
tl = new TextLayout(s, f, frc); tl = new TextLayout(s, f, frc);
tl.draw(g2d, ix, iy); tl.draw(g2d, ix, iy);
} }
} }
class PrintJAText extends PrintTextTest { private static class PrintJapaneseText extends PrintText {
public PrintJapaneseText(String page, Font font, AffineTransform gxTx, boolean fm, int size) {
public PrintJAText(String page, Font font, AffineTransform gxTx, super(page, font, gxTx, fm, size);
boolean fm) {
super(page, font, gxTx, fm);
} }
private static final String TEXT = private static final String TEXT =
"\u3042\u3044\u3046\u3048\u304a\u30a4\u30ed\u30cf" + "\u3042\u3044\u3046\u3048\u304a\u30a4\u30ed\u30cf" +
"\u30cb\u30db\u30d8\u30c8\u4e00\u4e01\u4e02\u4e05\uff08"; "\u30cb\u30db\u30d8\u30c8\u4e00\u4e01\u4e02\u4e05\uff08";
@Override
public void paint(Graphics g) { public void paint(Graphics g) {
/* fill with white before any transformation is applied */ g.setColor(Color.WHITE);
g.setColor(Color.white);
g.fillRect(0, 0, getSize().width, getSize().height); g.fillRect(0, 0, getSize().width, getSize().height);
Graphics2D g2d = (Graphics2D) g; Graphics2D g2d = (Graphics2D) g;
if (gxTx != null) { if (gxTx != null) {
g2d.transform(gxTx); g2d.transform(gxTx);
@ -424,135 +443,20 @@ class PrintJAText extends PrintTextTest {
} }
String text = TEXT + TEXT + TEXT; String text = TEXT + TEXT + TEXT;
g.setColor(Color.black); g.setColor(Color.BLACK);
int y = 20; int y = 20;
float origSize = 7f; float origSize = 7f;
for (int i=0;i<11;i++) { for (int i = 0; i < 11; i++) {
float size = origSize+(i*0.1f); float size = origSize + (i * 0.1f);
g2d.translate(0, size+6); g2d.translate(0, size + 6);
Font f = textFont.deriveFont(size); Font f = textFont.deriveFont(size);
g2d.setFont(f); g2d.setFont(f);
FontMetrics fontMetrics = g2d.getFontMetrics(); FontMetrics fontMetrics = g2d.getFontMetrics();
int stringWidth = fontMetrics.stringWidth(text); int stringWidth = fontMetrics.stringWidth(text);
g.drawLine(0, y+1, stringWidth, y+1); g.drawLine(0, y + 1, stringWidth, y + 1);
g.drawString(text, 0, y); g.drawString(text, 0, y);
y +=10; y += 10;
}
} }
} }
} }
class Sysout
{
private static TestDialog dialog;
public static void createDialogWithInstructions( String[] instructions )
{
dialog = new TestDialog( new Frame(), "Instructions" );
dialog.printInstructions( instructions );
dialog.show();
println( "Any messages for the tester will display here." );
}
public static void createDialog( )
{
dialog = new TestDialog( new Frame(), "Instructions" );
String[] defInstr = { "Instructions will appear here. ", "" } ;
dialog.printInstructions( defInstr );
dialog.show();
println( "Any messages for the tester will display here." );
}
public static void printInstructions( String[] instructions )
{
dialog.printInstructions( instructions );
}
public static void println( String messageIn )
{
dialog.displayMessage( messageIn );
}
}// Sysout class
/**
This is part of the standard test machinery. It provides a place for the
test instructions to be displayed, and a place for interactive messages
to the user to be displayed.
To have the test instructions displayed, see Sysout.
To have a message to the user be displayed, see Sysout.
Do not call anything in this dialog directly.
*/
class TestDialog extends Dialog
{
TextArea instructionsText;
TextArea messageText;
int maxStringLength = 80;
//DO NOT call this directly, go through Sysout
public TestDialog( Frame frame, String name )
{
super( frame, name );
int scrollBoth = TextArea.SCROLLBARS_BOTH;
instructionsText = new TextArea( "", 20, maxStringLength, scrollBoth );
add( "North", instructionsText );
messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
add("South", messageText);
pack();
show();
}// TestDialog()
//DO NOT call this directly, go through Sysout
public void printInstructions( String[] instructions )
{
//Clear out any current instructions
instructionsText.setText( "" );
//Go down array of instruction strings
String printStr, remainingStr;
for( int i=0; i < instructions.length; i++ )
{
//chop up each into pieces maxSringLength long
remainingStr = instructions[ i ];
while( remainingStr.length() > 0 )
{
//if longer than max then chop off first max chars to print
if( remainingStr.length() >= maxStringLength )
{
//Try to chop on a word boundary
int posOfSpace = remainingStr.
lastIndexOf( ' ', maxStringLength - 1 );
if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
printStr = remainingStr.substring( 0, posOfSpace + 1 );
remainingStr = remainingStr.substring( posOfSpace + 1 );
}
//else just print
else
{
printStr = remainingStr;
remainingStr = "";
}
instructionsText.append( printStr + "\n" );
}// while
}// for
}//printInstructions()
//DO NOT call this directly, go through Sysout
public void displayMessage( String messageIn )
{
messageText.append( messageIn + "\n" );
}
}// TestDialog class