JavaPrintingModel2_JunoYoon.PDF

Similar documents
rmi_박준용_final.PDF

MasoJava4_Dongbin.PDF

JMF3_심빈구.PDF

JMF2_심빈구.PDF

fundamentalOfCommandPattern_calmglow_pattern_jstorm_1.0_f…

자바GUI실전프로그래밍2_장대원.PDF

PowerPoint 프레젠테이션

01-OOPConcepts(2).PDF

05-class.key

02 C h a p t e r Java

Orcad Capture 9.x

<4D F736F F F696E74202D20C1A63233C0E520B1D7B7A1C7C820C7C1B7CEB1D7B7A1B9D628B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

PowerPoint 프레젠테이션

12-file.key

Page 2 of 5 아니다 means to not be, and is therefore the opposite of 이다. While English simply turns words like to be or to exist negative by adding not,

Ext JS À¥¾ÖÇø®ÄÉÀ̼ǰ³¹ß-³¹Àå.PDF

Microsoft PowerPoint - 04-UDP Programming.ppt

11 템플릿적용 - Java Program Performance Tuning (김명호기술이사)

자바 프로그래밍

09-interface.key

Modern Javascript

Lab10

신림프로그래머_클린코드.key

07 자바의 다양한 클래스.key

비긴쿡-자바 00앞부속

자바로

Analytics > Log & Crash Search > Unity ios SDK [Deprecated] Log & Crash Unity ios SDK. TOAST SDK. Log & Crash Unity SDK Log & Crash Search. Log & Cras

ch09

1

5장.key

PowerPoint 프레젠테이션

10-Java Applet

Interstage5 SOAP서비스 설정 가이드

Microsoft PowerPoint - java1-lab5-ImageProcessorTestOOP.pptx

example code are examined in this stage The low pressure pressurizer reactor trip module of the Plant Protection System was programmed as subject for

강의10

untitled

step 1-1

Chap12

Eclipse 와 Firefox 를이용한 Javascript 개발 발표자 : 문경대 11 년 10 월 26 일수요일

9장.key

Something that can be seen, touched or otherwise sensed

초보자를 위한 자바 2 21일 완성 - 최신개정판

DIY 챗봇 - LangCon

ilist.add(new Integer(1))과 같이 사용하지 않고 ilist.add(1)과 같이 사용한 것은 자바 5.0에 추가된 기본 자료형과 해당 객체 자료 형과의 오토박싱/언박싱 기능을 사용한 것으로 오토박싱이란 자바 컴파일러가 객체를 요구하는 곳에 기본 자료형

I T C o t e n s P r o v i d e r h t t p : / / w w w. h a n b i t b o o k. c o. k r

프로그램을 학교 등지에서 조금이라도 배운 사람들을 위한 프로그래밍 노트 입니다. 저 역시 그 사람들 중 하나 입니다. 중고등학교 시절 학교 도서관, 새로 생긴 시립 도서관 등을 다니며 책을 보 고 정리하며 어느정도 독학으르 공부하긴 했지만, 자주 안하다 보면 금방 잊어

<4D F736F F D C1A6BEC8BCAD20C0DBBCBAB0FA20C7C1B8AEC1A8C5D7C0CCBCC720B1E2B9FD2E646F63>

MAX+plus II Getting Started - 무작정따라하기

Mobile Service > IAP > Android SDK [ ] IAP SDK TOAST SDK. IAP SDK. Android Studio IDE Android SDK Version (API Level 10). Name Reference V

03장

본문01

DocsPin_Korean.pages

Secure Programming Lecture1 : Introduction

C++-¿Ïº®Çؼ³10Àå

28 THE ASIAN JOURNAL OF TEX [2] ko.tex [5]

Java ~ Java program: main() class class» public static void main(string args[])» First.java (main class ) /* The first simple program */ public class

Polly_with_Serverless_HOL_hyouk

FD¾ØÅÍÇÁ¶óÀÌÁî(Àå¹Ù²Þ)-ÀÛ¾÷Áß

Contents. 1. PMD ㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍ 2. Metrics ㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍ 3. FindBugs ㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍ 4. ㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍㆍ

교육2 ? 그림

Java

Page 2 of 6 Here are the rules for conjugating Whether (or not) and If when using a Descriptive Verb. The only difference here from Action Verbs is wh

11장.key

untitled

Javascript.pages

Remote UI Guide

2009년 국제법평론회 동계학술대회 일정

09권오설_ok.hwp

K&R2 Reference Manual 번역본

Java XPath API (한글)

Spring Boot/JDBC JdbcTemplate/CRUD 예제

10X56_NWG_KOR.indd


VZ94-한글매뉴얼

Connection 8 22 UniSQLConnection / / 9 3 UniSQL OID SET

교육자료

04장

untitled

2015 경제ㆍ재정수첩


T100MD+

( )부록

PowerPoint 프레젠테이션

歯Writing_Enterprise_Applications_2_JunoYoon.PDF

Microsoft Word - P02.doc

Contents Contents 2 1 Abstract 3 2 Infer Checkers Eradicate Infer....

Microsoft PowerPoint - 14주차 강의자료

8장.그래픽 프로그래밍

CD-RW_Advanced.PDF

쉽게 풀어쓴 C 프로그래밍

uFOCS

Solaris Express Developer Edition

CAD 화면상에 동그란 원형 도형이 생성되었습니다. 화면상에 나타난 원형은 반지름 500인 도형입니다. 하지만 반지름이 500이라는 것은 작도자만 알고 있는 사실입니다. 반지름이 500이라는 것을 클라이언트와 작업자들에게 알려주기 위 해서는 반드시 치수가 필요하겠죠?

chap10.PDF

03-JAVA Syntax(2).PDF

歯9장.PDF


4. #include <stdio.h> #include <stdlib.h> int main() { functiona(); } void functiona() { printf("hihi\n"); } warning: conflicting types for functiona

DioPen 6.0 사용 설명서

Transcription:

<JSTORM> 2 JSTORM http://wwwjstormpekr

2 Issued by: < > Revision: <10> <2000/12/21> Document Information Document title: 2 Document file name: Revision number: <10> Issued by: Issue Date: <2000/12/21> Status: JavaPrintingModel2_JunoYoondoc < > junoyoon@orgionet final Audience Abstract Content Information 5 2 Java Printing API Reference Printing in Java, Part 2 (http://wwwjavaworldcom/javaworld/jw-10-2000/jw-1020-print_phtml) Benchmark information by Jean-Pierre Dubé JSTORM <2/35>

2 Issued by: < > Revision: <10> <2000/12/21> Table of Contents 2 4 4 Pageable Books 7, 16 18 19 20 21 TextLayout 22 TextLayout 24 31 34 35 JSTORM <3/35>

2 Issued by: < > Revision: <10> <2000/12/21> 1 1 Printable Pageable 2 Book 2 2D API Sun Java 13 Windows 2000 Linux 1 Printable Pageable Printable Printable Printable Pageable Book 1 Printable 1 2 /** 3 * Class: Example1 <p> 4 * JSTORM <4/35>

2 Issued by: < > Revision: <10> <2000/12/21> 5 * @author Jean-Pierre Dube <jpdube@videotronca> 6 * @version 10 7 * @since 10 8 * @see Printable 9 */ 10 11 import javaawt*; 12 import javaawtgeom*; 13 import javaawtprint*; 14 15 16 public class Example1 implements Printable { 17 18 // Private 19 private final double INCH = 72; 20 21 22 23 /** 24 * Constructor: Example1 <p> 25 * 26 */ 27 public Example1 () { 28 29 //--- printerjob 30 PrinterJob printjob = PrinterJobgetPrinterJob (); 31 32 //--- Example1 Printable 33 //--- Printable this 34 printjobsetprintable (this); 35 36 //--- 37 //--- 38 //--- 39 if (printjobprintdialog()) { 40 try { 41 printjobprint(); 42 } catch (Exception PrintException) { 43 PrintExceptionprintStackTrace(); 44 } 45 } 46 47 } JSTORM <5/35>

2 Issued by: < > Revision: <10> <2000/12/21> 48 49 50 /** 51 * Method: print <p> 52 * 53 * 54 * 1/2 * 1/2 55 * 56 * 57 * @param g a value of type Graphics 58 * @param pageformat a value of type PageFormat 59 * @param page a value of type int 60 * @return a value of type int 61 */ 62 public int print (Graphics g, PageFormat pageformat, int page) { 63 64 int i; 65 Graphics2D g2d; 66 Line2DDouble line = new Line2DDouble (); 67 68 // 69 if (page == 0) { 70 71 //--- graphic2d 72 g2d = (Graphics2D) g; 73 g2dsetcolor (Colorblack); 74 75 //--- (0,0) 76 g2dtranslate(pageformatgetimageablex(), pageformatgetimageabley()); 77 78 //--- 79 for (i = 0; i < pageformatgetwidth (); i += INCH / 2) { 80 linesetline (i, 0, i, pageformatgetheight ()); 81 g2ddraw (line); 82 } 83 84 //--- 85 for (i = 0; i < pageformatgetheight (); i += INCH / 2) { 86 linesetline (0, i, pageformatgetwidth (), i); 87 g2ddraw (line); 88 } 89 JSTORM <6/35>

2 Issued by: < > Revision: <10> <2000/12/21> 90 return (PAGE_EXISTS); 91 } 92 else 93 return (NO_SUCH_PAGE); 94 } 95 96 } //Example1 1 1/2 * 1/2 12 12 API Printable PrinterJob,,, Printable print() Graphics PAGE_EXIT NO_SUCH_PAGE Pageable Books Printable Printable Pageable Book 1 Book Book (painter) Pageable Book 1 2 /** 3 * Class: Example2 <p> 4 * 5 * Print in Java series for the JavaWorld magazine 6 * JSTORM <7/35>

2 Issued by: < > Revision: <10> <2000/12/21> 7 * @author Jean-Pierre Dube <jpdube@videotronca> 8 * @version 10 9 * @since 10 10 */ 11 12 import javaawt*; 13 import javaawtfont*; 14 import javaawtgeom*; 15 import javaawtprint*; 16 17 18 public class Example2 { 19 20 //--- Private 21 private final static int POINTS_PER_INCH = 72; 22 23 24 /** 25 * Constructor: Example2 <p> 26 * 27 */ 28 public Example2 () { 29 30 //--- PrinterJob 31 PrinterJob printjob = PrinterJobgetPrinterJob (); 32 33 //--- (page) book 34 Book book = new Book (); 35 36 //--- Job 37 bookappend (new IntroPage (), printjobdefaultpage ()); 38 39 //--- (document) 40 PageFormat documentpageformat = new PageFormat (); 41 documentpageformatsetorientation (PageFormatLANDSCAPE); 42 bookappend (new Document (), documentpageformat); 43 44 //--- printjob Pageable Book 45 printjobsetpageable (book); 46 47 //--- print 48 //--- cancel 49 //--- JSTORM <8/35>

2 Issued by: < > Revision: <10> <2000/12/21> 50 if (printjobprintdialog()) { 51 try { 52 printjobprint(); 53 } catch (Exception PrintException) { 54 PrintExceptionprintStackTrace(); 55 } 56 } 57 } 58 59 60 /** 61 * Class: IntroPage <p> 62 * 63 * Printable 64 * (cover page) (painter) <p> 65 * 66 * @author Jean-Pierre Dube <jpdube@videotronca> 67 * @version 10 68 * @since 10 69 * @see Printable 70 */ 71 private class IntroPage implements Printable { 72 73 74 /** 75 * Method: print <p> 76 * 77 * @param g a value of type Graphics 78 * @param pageformat a value of type PageFormat 79 * @param page a value of type int 80 * @return a value of type int 81 */ 82 public int print (Graphics g, PageFormat pageformat, int page) { 83 84 //--- Graphics2D 85 Graphics2D g2d = (Graphics2D) g; 86 87 //--- (0, 0) ( ) 88 g2dtranslate (pageformatgetimageablex (), pageformatgetimageabley ()); 89 90 //--- 91 g2dsetpaint (Colorblack); JSTORM <9/35>

2 Issued by: < > Revision: <10> <2000/12/21> 92 93 //--- 94 Rectangle2DDouble border = new Rectangle2DDouble (0, 95 0, 96 pageformatgetimageablewidth (), 97 pageformatgetimageableheight ()); 98 g2ddraw (border); 99 100 //--- 101 String titletext = "Printing in Java Part 2"; 102 Font titlefont = new Font ("helvetica", FontBOLD, 36); 103 g2dsetfont (titlefont); 104 105 //--- 106 FontMetrics fontmetrics = g2dgetfontmetrics (); 107 double titlex = (pageformatgetimageablewidth () / 2) - (fontmetricsstringwidth (titletext) / 2); 108 double titley = 3 * POINTS_PER_INCH; 109 g2ddrawstring (titletext, (int) titlex, (int) titley); 110 111 return (PAGE_EXISTS); 112 } 113 } 114 115 116 117 /** 118 * Class: Document <p> 119 * 120 * document <p> 121 * 122 * 123 * @author Jean-Pierre Dube <jpdube@videotronca> 124 * @version 10 125 * @since 10 126 * @see Printable 127 */ 128 private class Document implements Printable { 129 130 131 /** 132 * Method: print <p> 133 * JSTORM <10/35>

2 Issued by: < > Revision: <10> <2000/12/21> 134 * @param g a value of type Graphics 135 * @param pageformat a value of type PageFormat 136 * @param page a value of type int 137 * @return a value of type int 138 */ 139 public int print (Graphics g, PageFormat pageformat, int page) { 140 141 142 //--- Graphics2D 143 Graphics2D g2d = (Graphics2D) g; 144 145 //--- (0, 0) ( ) 146 g2dtranslate (pageformatgetimageablex (), pageformatgetimageabley ()); 147 148 //--- 149 g2dsetpaint (Colorblack); 150 151 //--- 12 152 g2dsetstroke (new BasicStroke (12)); 153 Rectangle2DDouble border = new Rectangle2DDouble (0, 154 0, 155 pageformatgetimageablewidth (), 156 pageformatgetimageableheight ()); 157 158 g2ddraw (border); 159 160 //--- 1 161 g2ddrawstring ("This the content page", POINTS_PER_INCH, POINTS_PER_INCH); 162 163 //--- Validate 164 return (PAGE_EXISTS); 165 166 } 167 } 168 169 } // Example2 (cover) (document) 2 2 1 1 JSTORM <11/35>

2 Issued by: < > Revision: <10> <2000/12/21> 1 2 3 /** 4 * Class: Example3 <p> 5 * 6 * @author Jean-Pierre Dube <jpdube@videotronca> 7 * @version 10 8 * @since 10 9 */ 10 11 import javaawt*; 12 import javaawtfont*; 13 import javaawtgeom*; 14 import javaawtprint*; 15 16 17 public class Example3 { 18 19 //--- Private 20 private final static int POINTS_PER_INCH = 72; 21 22 23 /** 24 * Constructor: Example3 <p> 25 * 26 */ 27 public Example3 () { 28 29 //--- PrinterJob 30 PrinterJob printjob = PrinterJobgetPrinterJob (); 31 32 //--- Book 33 Book book = new Book (); 34 35 //--- printjob 36 bookappend (new IntroPage (), printjobdefaultpage ()); 37 38 //--- document 39 PageFormat documentpageformat = new PageFormat (); 40 documentpageformatsetorientation (PageFormatLANDSCAPE); 41 bookappend (new Document (), documentpageformat); JSTORM <12/35>

2 Issued by: < > Revision: <10> <2000/12/21> 42 43 //--- painter 44 bookappend (new Document (), documentpageformat); 45 46 //--- printjob Pageable Book 47 printjobsetpageable (book); 48 49 //--- 50 //--- cancel 51 //--- 52 if (printjobprintdialog()) { 53 try { 54 printjobprint(); 55 } catch (Exception PrintException) { 56 PrintExceptionprintStackTrace(); 57 } 58 } 59 60 } 61 62 /** 63 * Class: IntroPage <p> 64 * 65 * Printable 66 * <p> 67 * 68 * @author Jean-Pierre Dube <jpdube@videotronca> 69 * @version 10 70 * @since 10 71 * @see Printable 72 */ 73 private class IntroPage implements Printable { 74 75 76 /** 77 * Method: print <p> 78 * 79 * @param g a value of type Graphics 80 * @param pageformat a value of type PageFormat 81 * @param page a value of type int 82 * @return a value of type int 83 */ 84 public int print (Graphics g, PageFormat pageformat, int page) { JSTORM <13/35>

2 Issued by: < > Revision: <10> <2000/12/21> 85 86 //--- Graphics2D 87 Graphics2D g2d = (Graphics2D) g; 88 89 //--- ( ) (0,0) 90 g2dtranslate (pageformatgetimageablex (), pageformatgetimageabley ()); 91 92 //--- 93 g2dsetpaint (Colorblack); 94 95 //--- 96 Rectangle2DDouble border = new Rectangle2DDouble (0, 97 0, 98 pageformatgetimageablewidth (), 99 pageformatgetimageableheight ()); 100 g2ddraw (border); 101 102 //--- 103 String titletext = "Printing in Java Part 2"; 104 Font titlefont = new Font ("helvetica", FontBOLD, 36); 105 g2dsetfont (titlefont); 106 107 //--- 108 FontMetrics fontmetrics = g2dgetfontmetrics (); 109 double titlex = (pageformatgetimageablewidth () / 2) - (fontmetricsstringwidth (titletext) / 2); 110 double titley = 3 * POINTS_PER_INCH; 111 g2ddrawstring (titletext, (int) titlex, (int) titley); 112 113 return (PAGE_EXISTS); 114 } 115 } 116 117 118 119 /** 120 * Class: Document <p> 121 * 122 * document <p> 123 * 124 * 125 * @author Jean-Pierre Dube <jpdube@videotronca> JSTORM <14/35>

2 Issued by: < > Revision: <10> <2000/12/21> 126 * @version 10 127 * @since 10 128 * @see Printable 129 */ 130 private class Document implements Printable { 131 132 133 /** 134 * Method: print <p> 135 * 136 * @param g a value of type Graphics 137 * @param pageformat a value of type PageFormat 138 * @param page a value of type int 139 * @return a value of type int 140 */ 141 public int print (Graphics g, PageFormat pageformat, int page) { 142 143 144 //--- Graphics2D 145 Graphics2D g2d = (Graphics2D) g; 146 147 //--- ( ) (0, 0) 148 g2dtranslate (pageformatgetimageablex (), pageformatgetimageabley ()); 149 150 //--- 151 g2dsetpaint (Colorblack); 152 153 //--- 12 154 g2dsetstroke (new BasicStroke (12)); 155 Rectangle2DDouble border = new Rectangle2DDouble (0, 156 0, 157 pageformatgetimageablewidth (), 158 pageformatgetimageableheight ()); 159 160 g2ddraw (border); 161 162 163 //--- 1 164 if (page == 1) { 165 //--- 1 166 g2ddrawstring ("This the content page of page: " + page, POINTS_PER_INCH, POINTS_PER_INCH); JSTORM <15/35>

2 Issued by: < > Revision: <10> <2000/12/21> 167 return (PAGE_EXISTS); 168 } 169 170 //--- 2 171 else if (page == 2) { 172 //--- 1 173 g2ddrawstring ("This the content of the second page: " + page, POINTS_PER_INCH, POINTS_PER_INCH); 174 return (PAGE_EXISTS); 175 } 176 177 178 //--- Validate 179 return (NO_SUCH_PAGE); 180 181 } 182 } 183 184 } // Example3 3 44 164 171 if API API 2, 12 (print job) OS 1 JSTORM <16/35>

2 Issued by: < > Revision: <10> <2000/12/21> if (printjobprintdialog()) { try { printjobprint(); } catch (Exception PrintException) { PrintExceptionprintStackTrace(); } } PrinterJob printdialog Boolean Print printdialog() true cancel false printdialog() Boolean (interact) PrinterJob page 2 JSTORM <17/35>

2 Issued by: < > Revision: <10> <2000/12/21>,,, PageForamt PageFormat documentpageformat = new PageFormat (); documentpageformat = printjobpagedialog (documentpageformat); bookappend (new Document (), documentpageformat); OK pagedialog() PageFormat (clone) Cancel PageFormat JSTORM <18/35>

2 Issued by: < > Revision: <10> <2000/12/21> CR/LF 2 CR/LF 3 baseline ascend baseline baseline descend leading 2 height ascend leading descend string advance Arial text Lucida text baseline y text x 4 JSTORM <19/35>

2 Issued by: < > Revision: <10> <2000/12/21> 2 Serif Times New Roman serif ABCD Sans serif Arial sans serif (monospaced) (proportional) monospaced monospaced proportional proportional Apple Lisa (WORA) (font family) 8 : Serif, Sans Serif, Dialog, Dialog Input, Lucida Sans, Lucida Sans Typewriter, Lucida Bright Monospace WORA JDK jre/lib/fontproperties Serif JSTORM <20/35>

2 Issued by: < > Revision: <10> <2000/12/21> fontproperties = Serif Times New Roman Arial, Courier, Times Roman Lucida Arial Arial Bold, Arial Italic Arial Regular Arial java -Djavaawtfonts=[fonts directory] Type1( ) javaawtfonts jar API Class FontMetrix Class abstract (Abstract) GraphicsgetFontMetrics descend, ascend, leading, advance FontMetric (Rule) Class (Rule) JSTORM <21/35>

2 Issued by: < > Revision: <10> <2000/12/21> JDK (proportional) TexLayout LineBreakMeasurer TextLayout TextLayout TextLayout TextLayout LineBreakMeasurer LineBreakMeasurer (wrap) (break) LineBreakMeasurer FontRenderContext FontRenderContext (targeted device), TextLayout AttributedString This is a Bold attribute AttributedString, GraphicsdrawString() JSTORM <22/35>

2 Issued by: < > Revision: <10> <2000/12/21> Font normalfont = new Font ("serif", FontPLAIN, 12); Font boldfont = new Font ("serif", FontBOLD, 12); g2setfont (normalfont); g2drawstring ("This is a "); g2setfont (boldfont); g2drawstring ("bold "); g2setfont (normalfont); g2drawstring ("attribute", 72, 72);? Attributed String AttributedString String Attribute attribute AttributedString AttributedString attributedstring = new AttributedString ("This is a Bold attribute"); attributedstringaddattribute (TextAttributeWEIGHT, TextAttributeWEIGHT_BOLD, 11, 14); g2drawstring (attributestringgetiterator (), 72, 72); Bold addattribute() TextAttributeWEIGHT weight TextAttributeWEIGHT t WEIGHT_DEMIBOLD, WEIGHT_DEMILIGHT, WEIGHT_EXTRA_LIGHT, WEIGHT_EXTRABOLD, WEIGHT_HEAVY, WEIGHT_LIGHT, WEIGHT_MEDIUM, WEIGHT_REGULAR, WEIGHT_SEMIBOLD WEIGHT_ULTRABOLD, 5 Attribute dstring JSTORM <23/35>

2 Issued by: < > Revision: <10> <2000/12/21> TextLayout TextLayout Example4 TextLayout List 4 75 TextLayout 162 235 118 /** 119 * Class: Document <p> 120 * 121 * (document) <p> 122 * 123 * 124 * @author Jean-Pierre Dube <jpdube@videotronca> 125 * @version 10 126 * @since 10 127 * @see Printable 128 */ 129 private class Document implements Printable { 130 131 132 /** 133 * Method: print <p> 134 * 135 * @param g a value of type Graphics 136 * @param pageformat a value of type PageFormat 137 * @param page a value of type int 138 * @return a value of type int 139 */ 140 public int print (Graphics g, PageFormat pageformat, int page) { 141 142 143 //--- Graphics2D 144 Graphics2D g2d = (Graphics2D) g; 145 146 //--- 147 g2dtranslate (pageformatgetimageablex (), pageformatgetimageabley ()); 148 149 //--- JSTORM <24/35>

2 Issued by: < > Revision: <10> <2000/12/21> 150 g2dsetpaint (Colorblack); 151 152 //--- 12 153 g2dsetstroke (new BasicStroke (4)); 154 Rectangle2DDouble border = new Rectangle2DDouble (0, 155 0, 156 pageformatgetimageablewidth (), 157 pageformatgetimageableheight ()); 158 159 g2ddraw (border); 160 161 162 //--- 163 String text = new String (); 164 text += "Manipulating raw fonts would be too complicated to render paragraphs of "; 165 text += "text Trying to write an algorithm to fully justify text using "; 166 text += "proportional fonts is not trivial Adding support for international "; 167 text += "characters adds to the complexity That's why we will use the "; 168 text += "TextLayout and the LineBreakMeasurer class to "; 169 text += "render text The TextLayout class offers a lot of "; 170 text += "functionality to render high quality text This class is capable of "; 171 text += "rendering bidirectional text such as Japanese text where the alignment "; 172 text += "is from right to left instead of the North American style which is left "; 173 text += "to right The TextLayout class offers some additional "; 174 text += "functionalities that we will not use in the course of this "; 175 text += "series Features such as text input, caret positioning and hit "; 176 text += "testing will not be of much use when printing documents, but it's good "; 177 text += "to know that this functionality exists "; 178 179 text += "The TextLayout class will be used to layout "; 180 text += "paragraphs The TextLayout class does not work alone To "; 181 text += "layout text within a specified width it needs the help of the "; 182 text += "LineBreakMeasurer class This class will wrap a string of "; 183 text += "text to fit a predefined width Since it's a multi-lingual class, it "; 184 text += "knows exactly where to break a line of text according to the rules "; 185 text += "of the language Then again the LineBreakMeasurer does "; 186 text += "not work alone It needs information from the "; JSTORM <25/35>

2 Issued by: < > Revision: <10> <2000/12/21> 187 text += "FontRenderContext class This class' main function is to "; 188 text += "return accurate font metrics To measure text effectively, this class "; 189 text += "needs to know the rendering hints for the targeted device and the font "; 190 text += "type being used "; 191 192 193 //--- TextLayout point 194 Point2DDouble pen = new Point2DDouble (025 * POINTS_PER_INCH, 025 * POINTS_PER_INCH); 195 196 //--- TextLayout 197 double width = 75 * POINTS_PER_INCH; 198 199 200 //--- attributed string LineBreakMesurer 201 //--- Iterator attributed string 202 // 203 AttributedString paragraphtext = new AttributedString (text); 204 205 //--- 206 paragraphtextaddattribute (TextAttributeFONT, new Font ("serif", FontPLAIN, 12)); 207 208 //--- LineBreakMeasurer TextLayout 209 //--- FontRendereContext 210 //--- 2 true 211 //--- usefractionalmetrics true 212 LineBreakMeasurer linebreaker = new LineBreakMeasurer (paragraphtextgetiterator(), 213 new FontRenderContext (null, true, true)); 214 215 //--- TextLayout 216 TextLayout layout; 217 218 //--- LineBreakMeasurer width 219 //--- TextLayout 220 while ((layout = linebreakernextlayout ((float) width))!= null) { 221 222 //--- Y ascend font ascending 223 //--- (0, 0) 1 JSTORM <26/35>

2 Issued by: < > Revision: <10> <2000/12/21> 224 peny += layoutgetascent (); 225 226 //--- 227 layoutdraw (g2d, (float) penx, (float) peny); 228 229 //--- y descent leading 230 231 peny += layoutgetdescent () + layoutgetleading (); 232 } 233 234 //--- page Validate 235 return (PAGE_EXISTS); 236 } 237 } 238 239 } // Example4 4 AttributedString addattribute() AttributedString iterator FontRenderContext 2 LineBreakMeasurer LineBreakMeasurer TextLaout y=0 baseline descend leading 1 Listing 5 Example5 120 /** 121 * Class: Document <p> 122 * 123 * (document) 124 * 125 * <p> 126 * 127 * 128 * @author Jean-Pierre Dube <jpdube@videotronca> 129 * @version 10 JSTORM <27/35>

2 Issued by: < > Revision: <10> <2000/12/21> 130 * @since 10 131 * @see Printable 132 */ 133 private class Document implements Printable { 134 135 136 /** 137 * Method: print <p> 138 * 139 * @param g a value of type Graphics 140 * @param pageformat a value of type PageFormat 141 * @param page a value of type int 142 * @return a value of type int 143 */ 144 public int print (Graphics g, PageFormat pageformat, int page) { 145 146 147 //--- Graphics2D 148 Graphics2D g2d = (Graphics2D) g; 149 150 //--- ( ) 0,0 151 g2dtranslate (pageformatgetimageablex (), pageformatgetimageabley ()); 152 153 //--- 154 g2dsetpaint (Colorblack); 155 156 //--- 12 157 g2dsetstroke (new BasicStroke (4)); 158 Rectangle2DDouble border = new Rectangle2DDouble (0, 159 0, 160 pageformatgetimageablewidth (), 161 pageformatgetimageableheight ()); 162 163 g2ddraw (border); 164 165 166 //--- 167 String text = new String (); 168 text += "Manipulating raw fonts would be too complicated to render paragraphs of "; 169 text += "text Trying to write an algorithm to fully justify text using "; 170 text += "proportional fonts is not trivial Adding support for international JSTORM <28/35>

2 Issued by: < > Revision: <10> <2000/12/21> "; 171 text += "characters adds to the complexity That's why we will use the "; 172 text += "TextLayout and the LineBreakMeasurer class to "; 173 text += "render text The TextLayout class offers a lot of "; 174 text += "functionality to render high quality text This class is capable of "; 175 text += "rendering bidirectional text such as Japanese text where the alignment "; 176 text += "is from right to left instead of the North American style which is left "; 177 text += "to right The TextLayout class offers some additional "; 178 text += "functionalities that we will not use in the course of this "; 179 text += "series Features such as text input, caret positioning and hit "; 180 text += "testing will not be of much use when printing documents, but it's good "; 181 text += "to know that this functionality exists "; 182 183 text += "The TextLayout class will be used to layout "; 184 text += "paragraphs The TextLayout class does not work alone To "; 185 text += "layout text within a specified width it needs the help of the "; 186 text += "LineBreakMeasurer class This class will wrap a string of "; 187 text += "text to fit a predefined width Since it's a multi-lingual class, it "; 188 text += "knows exactly where to break a line of text according to the rules "; 189 text += "of the language Then again the LineBreakMeasurer does "; 190 text += "not work alone It needs information from the "; 191 text += "FontRenderContext class This class' main function is to "; 192 text += "return accurate font metrics To measure text effectively, this class "; 193 text += "needs to know the rendering hints for the targeted device and the font "; 194 text += "type being used "; 195 196 197 //--- TextLayout point 198 Point2DDouble pen = new Point2DDouble (025 * POINTS_PER_INCH, 025 * POINTS_PER_INCH); 199 200 //--- TextLayout 201 double width = 8 * POINTS_PER_INCH; 202 203 204 //--- attributed LineBreakMeasurer 205 //--- Iterator attributed string JSTORM <29/35>

2 Issued by: < > Revision: <10> <2000/12/21> 206 //--- 207 AttributedString paragraphtext = new AttributedString (text); 208 209 //--- 210 paragraphtextaddattribute (TextAttributeFONT, new Font ("serif", FontPLAIN, 12)); 211 212 //--- TextLayout text LineBreakMeasurer 213 //--- FontContext 214 //--- true antialised 4 215 //--- usefractionalmetrics true 216 LineBreakMeasurer linebreaker = new LineBreakMeasurer (paragraphtextgetiterator(), 217 new FontRenderContext (null, true, true)); 218 219 //--- TextLayouts 220 TextLayout layout; 221 TextLayout justifylayout; 222 223 //--- Vector 224 Vector lines = new Vector (); 225 226 //--- LineBreakMeasurer Vector 227 while ((layout = linebreakernextlayout ((float) width))!= null) { 228 linesadd (layout); 229 230 } 231 232 //--- 233 for (int i = 0; i < linessize (); i++) { 234 235 //--- 236 layout = (TextLayout) linesget (i); 237 238 //--- 239 //--- 240 if (i!= linessize () - 1) 241 justifylayout = layoutgetjustifiedlayout ((float) width); 242 else 243 justifylayout = layout; 244 245 //--- Y ascend ascend (0,0) 246 //--- 1 JSTORM <30/35>

2 Issued by: < > Revision: <10> <2000/12/21> 247 peny += justifylayoutgetascent (); 248 249 //--- 250 justifylayoutdraw (g2d, (float) penx, (float) peny); 251 252 //--- descend leading 253 //--- 254 peny += justifylayoutgetdescent () + justifylayoutgetleading (); 255 256 } 257 258 //--- validation 259 return (PAGE_EXISTS); 260 } 261 } 262 263 } // Example5 5 219 259 TextLayout LineBreakMeasurer Vector for getj ustifiedlayout() Image Graphics2DdrawImage() 165 198 120 /** 121 * Class: Document <p> 122 * 123 * 124 * <p> JSTORM <31/35>

2 Issued by: < > Revision: <10> <2000/12/21> 125 * 126 * 127 * @author Jean-Pierre Dube <jpdube@videotronca> 128 * @version 10 129 * @since 10 130 * @see Printable 131 */ 132 private class Document extends Component implements Printable { 133 134 135 /** 136 * Method: print <p> 137 * 138 * @param g a value of type Graphics 139 * @param pageformat a value of type PageFormat 140 * @param page a value of type int 141 * @return a value of type int 142 */ 143 public int print (Graphics g, PageFormat pageformat, int page) { 144 145 146 //--- Graphics2D 147 Graphics2D g2d = (Graphics2D) g; 148 149 //--- ( ) (0,0) 150 g2dtranslate (pageformatgetimageablex (), pageformatgetimageabley ()); 151 152 //--- 153 g2dsetpaint (Colorblack); 154 155 //--- 12 156 g2dsetstroke (new BasicStroke (4)); 157 Rectangle2DDouble border = new Rectangle2DDouble (0, 158 0, 159 pageformatgetimageablewidth (), 160 pageformatgetimageableheight ()); 161 162 g2ddraw (border); 163 164 165 //--- Media Tracker URL 166 MediaTracker mt = new MediaTracker (this); JSTORM <32/35>

2 Issued by: < > Revision: <10> <2000/12/21> 167 URL imageurl = null; 168 169 //--- URL 170 //--- NOTE: 171 //--- NOTE: JPEG, GIF, PNG 173 174 imageurl = new URL ("file:///c:/softdev/java/articles/javaworld/printing/part_2/ss2jpg"); 175 } 176 catch (MalformedURLException me) { 177 meprintstacktrace (); 178 } 179 180 //--- 181 Image image = ToolkitgetDefaultToolkit()getImage (imageurl); 182 mtaddimage (image, 0); 183 try { 184 mtwaitforid (0); 185 } 186 catch (InterruptedException e) { 187 } 188 189 //--- 190 g2ddrawimage (image, 191 (int) (025 * POINTS_PER_INCH), 192 (int) (025 * POINTS_PER_INCH), 193 (int) (85 * POINTS_PER_INCH), 194 (int) (6 * POINTS_PER_INCH), 195 this); 196 197 //--- Validate 198 return (PAGE_EXISTS); 199 } 200 } 201 202 } // Example6 3 URL MediaTracker GIF, JPEG PNG Advance Imaging API Graphics2D drawimage() JSTORM <33/35>

2 Issued by: < > Revision: <10> <2000/12/21> drawimage() 6 Image ImageObserver Document Component Component ImageObserver 3 JavaSoft Advanced Imaging API WORA OS SuSe Linux 64 Sun Java 13 Windows 2000 HP 5L OS, Windows Linux SuSe APS HP 5L 600 dpi 300 dpi 600 dpi Linux, 6 7 JSTORM <34/35>

2 Issued by: < > Revision: <10> <2000/12/21> OS X Max OS 2 API (?) API,,, API 3 3 ~ JSTORM <35/35>