⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 int.html

📁 JSP中文介绍,对于菜鸟有用
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD>  <TITLE>2D Text Tutorial Lesson 4: Foreign Language Support</TITLE>  <META NAME="AUTHOR" CONTENT="Monica Pawlan of the JDC">  <META NAME="CREATED" CONTENT="09/15/98">  <META NAME="OWNER" CONTENT="Editorial/JDC">  <META NAME="revision" CONTENT="@(#)int.src	1.10 11/10/99  JDC">  <META NAME="TOPIC" CONTENT="tutorial, graphics, media, JDK 1.2, text, API">    <STYLE TYPE="text/css">    <!--     CODE {font-family: Courier, Monospace;          font-size: 12pt}    PRE {font-family: Courier, Monospace;         font-size: 11pt}      -->  </STYLE></HEAD><!-- Start Body Insert--><BODY BGCOLOR="#ffffff"><!-- End Body Insert--><!-- Start PageTop Insert --><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="100%">  <TR ALIGN="CENTER" VALIGN="TOP">    <TD WIDTH="157" ALIGN="LEFT">    <IMG SRC="/images/pixel.gif" HEIGHT="40" WIDTH="40" ALT="">    <A HREF="http://java.sun.com/index.html"><IMG SRC="/images/javalogo52x88.gif" WIDTH="52" HEIGHT="88" ALT="Java Technology Home Page" BORDER="0"></A>    <BR>    <IMG SRC="/images/pixel.gif" WIDTH="157" HEIGHT="1" ALT=""></TD>    <TD>    <FORM NAME="seek1" METHOD="GET" ACTION="http://search.java.sun.com/query.html">    <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%">      <TR>        <TD ALIGN="RIGHT">        <IMG SRC="/images/stripelt.gif" WIDTH="6" HEIGHT="14" ALT=""></TD>                <TD WIDTH="100%">                <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%">          <TR>            <TD BGCOLOR="#CC9966" WIDTH="100%">            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>          </TR>                    <TR>            <TD>            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>          </TR>                    <TR>            <TD BGCOLOR="#CC9966">            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>          </TR>                    <TR>            <TD>            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>          </TR>                    <TR>            <TD BGCOLOR="#CC9966">            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>          </TR>                    <TR>            <TD>            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>          </TR>                    <TR>            <TD BGCOLOR="#CC9966">            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>          </TR>        </TABLE>        </TD>                <TD ALIGN="LEFT">        <IMG SRC="/images/stripert.gif" WIDTH="6" HEIGHT="14" ALT=""></TD>        <TD>                <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">          <TR>            <TD VALIGN="CENTER">            <A HREF="http://java.sun.com/a-z/index.html"><IMG SRC="/images/azindex.gif" BORDER="0" WIDTH="72" HEIGHT="11" ALT="A-Z Index"></A></TD>                          <TD VALIGN="CENTER">            <FONT FACE="Helvetica" SIZE="1">            <INPUT TYPE="text" SIZE="15" MAXLENGTH="128" NAME=qt></FONT></TD>                        <TD VALIGN="CENTER">            <INPUT TYPE="image" SRC="/images/search.button.gif"               value="search" BORDER="0" WIDTH="55" HEIGHT="14" ALT="Search"></TD>          </TR>        </TABLE>        </TD>      </TR>    </TABLE>    </FORM>    <P>    <TABLE BORDER="0" WIDTH="100%" CELLPADDING="0" CELLSPACING="0">      <TR VALIGN="TOP">        <TD WIDTH="100%"><IMG SRC="/images/chiclet.row.gif" WIDTH="55"           HEIGHT="18" ALT=""></TD>                  <TD ROWSPAN="4" ALIGN="RIGHT" WIDTH="152">        <A HREF="/developer/index.html"><IMG SRC="/images/developer.connection.header.gif" BORDER="0" HEIGHT="42" WIDTH="319" ALT="Java Developer Connection(SM)"></A></TD>      </TR>            <TR VALIGN="TOP">        <TD BGCOLOR="#FFFFFF" HEIGHT="1" WIDTH="100%">        <IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD>      </TR>            <TR VALIGN="TOP">        <TD BGCOLOR="#CC9966" HEIGHT="1" WIDTH="100%">        <IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD>      </TR>            <TR VALIGN="TOP">        <TD><A HREF="/developer/onlineTraining/"><IMG SRC="/images/online-training.gif" ALT="Online Training" BORDER=0></A></TD>      </TR>    </TABLE>    </TD>  </TR></TABLE><!-- End PageTop Insert --><!-- Start NavBar Insert --><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="3" BGCOLOR="#FFFFFF" WIDTH="157" ALIGN="LEFT"><!-- tab categories --><TR><TD><A HREF="http://java.sun.com/products/"><IMG SRC="/images/side.tab.products.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Downloads, APIs, Documentation"></A></TD></TR><TR><TD><A HREF="/developer/index.html"><IMG SRC="/images/side.tab.developer.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Java Developer Connection"></A></TD></TR><TR><TD><A HREF="/developer/infodocs/index.shtml"><IMG SRC="/images/side.tab.docs.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Tutorials, Tech Articles, Training"></A></TD></TR><TR><TD><A HREF="/developer/support/index.html"><IMG SRC="/images/side.tab.support.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Online Support"></A></TD></TR><TR><TD><A HREF="/developer/community/index.html"><IMG SRC="/images/side.tab.community.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Community Discussion"></A></TD></TR><TR><TD><A HREF="http://java.sun.com/industry/"><IMG SRC="/images/side.tab.news.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="News &amp; Events from Everywhere"></A></TD></TR><TR><TD><A HREF="http://java.sun.com/solutions"><IMG SRC="/images/side.tab.solutions.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Products from Everywhere"></A></TD></TR><TR><TD><A HREF="http://java.sun.com/casestudies"><IMG SRC="/images/side.tab.case.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="How Java Technology is Used Worldwide"></A></TD></TR><TR><TD>&nbsp;</TD></TR><!-- End NavBar Insert --><!-- START SUB-NAV --><TR>  <TD><!-- INSERT SUB-NAV INFO -->  </TD></TR><!-- END SUB-NAV --></TABLE><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0"><TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><!-- Template Version 2.0 --><!-- ================== --><!-- Start Main Content --><!-- ================== --><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0"><TR><TD><FONT FACE="Verdana, Arial, Helvetica, sans-serif">  <DIV ALIGN="RIGHT">  <FONT SIZE="-1"><A HREF="/developer/onlineTraining/index.html">Training Index</A></FONT>  <H2>2D Text Tutorial<BR>  <FONT SIZE="3">Lesson 4: Foreign Language Support</FONT></H2>  <H4><EM>By Monica Pawlan</EM></H4>    <FONT SIZE="-1">[<A HREF="more.html">&lt;&lt;BACK</A>] [<A HREF="index.html#TOC">CONTENTS</A>] [<A HREF="other.html">NEXT&gt;&gt;</A>]</FONT></DIV>  <P>The<A HREF="http://java.sun.com/products/jdk/1.2/docs/api/index.html"><CODE>java.awt.font.TextLayout</CODE></A> object lets you draw styled text in any language or script supported by <A HREF="http://www.unicode.org/unicode/standard/standard.html">The Unicode Standard</A>--a global character coding system for handling diverse modern, classical, and historical languages.When drawing text, the direction the text is read must be taken into account so all words in the the string display correctly. A <CODE>TextLayout</CODE> object maintains the direction of the text and correctly draws it no matter if the string runs left-to-right, right-to-left, or both (bidirectional). <P>Arabic and Hebrew are bidirectional because their text runsright-to-left and their numbers run left-to-right. Also, anystring with embedded text that runs in the opposite directionfrom the main text (English with embedded Arabic text, for example), is bidirectional.<P>Bidirectional text presents interesting problems for correctly positioning carets, accurately locating selections, and correctlydisplaying multiple lines. Also bidirectional and right-to-lefttext present similar problems for moving the caret in the correct direction in response to right and left arrow key presses. <P>This lesson describes these issues and demonstrates how a<CODE>TextLayout</CODE> object takes care of them. See the <A HREF="http://www.ibm.com/java/education/international-text/index.html">International Text in JDK 1.2</A> paper for more details on theinformation presented in this lesson. <UL><LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="#about">About the Examples</A></FONT><LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="#insert">Inserting Text</A> </FONT>	<UL>	<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="#character">Character Hit, Side, and Language</A></FONT>	<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="#position">Caret Positioning</A></FONT>	<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="#testing">Hit Detection</A></FONT>	</UL><LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="#highlighting">Selection Highlighting</A></FONT><LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="#moving">Moving the Caret</A></FONT><LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="#multi">Multiline text</A></FONT><LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="exercises.html#four">Exercises</A></FONT></UL><A NAME="about"></A><H3>About the Examples</H3>The following examples support foreign language text with the <CODE>-text</CODE> option. Valid <CODE>-text</CODE> values arehebrew, english, mixed, arabic, longenglish, and longhebrew.<UL><LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="./Code/DrawSample.java">DrawSample.java</A></FONT><LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="./Code/HitTestSample.java">HitTestSample.java</A></FONT><LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="./Code/SelectionSample.java">SelectionSample.java</A></FONT><LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="./Code/ArrowKeySample.java">ArrowKeySample.java</A></FONT><LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif"><A HREF="./Code/LineBreakSample.java">LineBreakSample.java</A></FONT></UL>To see the foreign language text, you need a unicode font like Bitstream Cyberbit on your system. You also need to setyour <CODE>JAVA_FONTS</CODE> variable to point to the directorywhere the font is stored.For example, with a unicode font set up on your system,you can start the DrawSample application as follows to see a text string in Hebrew:<P><BLOCKQUOTE><PRE>java DrawSample -text hebrew</PRE><IMG SRC="./Art/Hebrew.gif"></BLOCKQUOTE>The <A HREF="./Code/SampleUtils.java"><CODE>SampleUtils.java</CODE></A> source code providestext in various languages and other things used by the example applications.<A NAME="insert"></A><H3>Inserting Text</H3>In editable text, a caret displays where the end user clicks toindicate the insertion point where the end user will enter text. When the insertion point falls between right-to-left text likeArabic and left-to-right text like English, the same character location in the source text (shown on top) maps to two insertion points on the display (shown on the bottom). One location is the insertion point for English text and the other location is the insertion point for Arabic text. In the figure, character location 8 in the source text maps to the space after the word <I>is</I> or the first character in the right-to-left Arabic text in the displayed text.  <P><BLOCKQUOTE><HR><STRONG>Note</STRONG>:The Arabic text is in bold capitalized English to help peoplewho do not read Arabic understand the point better.<HR></BLOCKQUOTE><P><IMG SRC="./Art/image28.gif"><P>The <CODE>TextLayout</CODE> object ensures the inserted text appears in the correct location on the display based on which character was hit, the side onwhich the characer was hit, and the language the end user enters.<P>The next two figures display the same text, which consists of mainly right-to-left text with two left-to-right words (Hello and Arabic) embedded.  When the end user clicks on the <I>o</I> in <I>Hello</I> or on the space after the <I>o</I>, dual carets display. <P>Dual carets consist of a strong and weak caret, and in the figures, the strong caret is red and the weak caret is black. The carets represent boundaries between glyphs for selection highlighting, hit testing, and moving the caret with arrow keys. The <CODE>TextLayout</CODE> objectdraws dual carets because the end user clicked on a directionalboundary where right-to-left text meets left-to-right text. If theend user had clicked on a non-directional boundary, the<CODE>TextLayout</CODE> object would have drawn a single caret atthat location.<BLOCKQUOTE><HR><STRONG><FONT COLOR=NAVY>Note</FONT></STRONG>: If you do not want to usedual carets, you can extend the <CODE>TextLayout.CaretPolicy</CODE> class to use something other than  dual carets to mark directionalboundaries.<HR></BLOCKQUOTE><A NAME="character"></A><H3>Character Hit, Side, and Language</H3>A click on the <I>o</I> on the side of the <I>o</I> towards the Hebrew records that the end user clicked after the <I>o</I>, which ispart of the English. This positions the weak (black) caret next tothe <I>o</I> and the strong caret (red) in front of the <I>H</I>. If the end user enters English, it appears after the<I>o</I>, and if the end user enters Hebrew, it appears before the<I>H</I>. <P><BLOCKQUOTE><IMG SRC="./Art/HTMixed2.gif"></BLOCKQUOTE><P>A click on the space to the right of the <I>o</I> records that the enduser clicked the space, which is part of the Hebrew. This positionsthe strong (red) caret next to the <I>o</I> and the weak caret (black)in front of the <I>H</I>. If the end user types English,it appears before the <I>H</I>, and if the end user types Hebrew,it appears after the <I>o</I>.<P><BLOCKQUOTE><IMG SRC="./Art/HTMixed.gif"></BLOCKQUOTE><P><BLOCKQUOTE><HR><STRONG><FONT COLOR=NAVY>Note</FONT></STRONG>:The insertion offset is the nearest one in the text. If it is off oneend of the line, the offset at that end is returned.<HR></BLOCKQUOTE><P><A NAME="position"></A><H3>Caret Positioning</H3>You might be wondering why the caret positions do not include the spaces

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -