Created
October 30, 2013 09:30
-
-
Save RaffaeleSgarro/7229649 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ArtifactsWhenUsingDialogFont { | |
| public static void main(String... args) throws Exception { | |
| PrinterJob job = PrinterJob.getPrinterJob(); | |
| job.setPrintService(PrintServiceLookup.lookupDefaultPrintService()); | |
| job.setPrintable(new Printable(){ | |
| @Override | |
| public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException { | |
| graphics.translate( (int) pageFormat.getImageableX(), (int) pageFormat.getImageableY() ); | |
| final String target = "OOOOOOOOOO\u2014MMMMMMMMM\u2014IIIIIIIIII\u2014"; | |
| printLine(graphics, target, "Arial"); | |
| printLine(graphics, target, "Times New Roman"); | |
| printLine(graphics, target, "Dialog"); | |
| return pageIndex == 0 ? PAGE_EXISTS : NO_SUCH_PAGE; | |
| } | |
| private int lineCounter = 0; | |
| private void printLine(Graphics graphics, String text, String fontName) { | |
| graphics.setFont(new Font(fontName, Font.PLAIN, 20)); | |
| graphics.drawString(text, 20, 20 * ++lineCounter); | |
| } | |
| }); | |
| job.print(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment