textlayout.html

来自「API資料大全」· HTML 代码 · 共 1,381 行 · 第 1/5 页

HTML
1,381
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc on Thu Apr 27 23:33:35 PDT 2000 --><TITLE>Java 2 Platform SE v1.3: Class  TextLayout</TITLE><LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style"></HEAD><BODY BGCOLOR="white"><!-- ========== START OF NAVBAR ========== --><A NAME="navbar_top"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0"><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">  <TR ALIGN="center" VALIGN="top">  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="class-use/TextLayout.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>  </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><b>Java<sup><font size=-2>TM</font></sup>&nbsp;2&nbsp;Platform<br>Std.&nbsp;Ed. v1.3</b></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">&nbsp;<A HREF="../../../java/awt/font/TextHitInfo.html"><B>PREV CLASS</B></A>&nbsp;&nbsp;<A HREF="../../../java/awt/font/TextLayout.CaretPolicy.html"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">  <A HREF="../../../index.html" TARGET="_top"><B>FRAMES</B></A>  &nbsp;&nbsp;<A HREF="TextLayout.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">  SUMMARY: &nbsp;<A HREF="#inner_class_summary">INNER</A>&nbsp;|&nbsp;<A HREF="#field_summary">FIELD</A>&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: &nbsp;<A HREF="#field_detail">FIELD</A>&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><!-- =========== END OF NAVBAR =========== --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">java.awt.font</FONT><BR>Class  TextLayout</H2><PRE><A HREF="../../../java/lang/Object.html">java.lang.Object</A>  |  +--<B>java.awt.font.TextLayout</B></PRE><DL><DT><B>All Implemented Interfaces:</B> <DD><A HREF="../../../java/lang/Cloneable.html">Cloneable</A></DD></DL><HR><DL><DT>public final class <B>TextLayout</B><DT>extends <A HREF="../../../java/lang/Object.html">Object</A><DT>implements <A HREF="../../../java/lang/Cloneable.html">Cloneable</A></DL><P><code>TextLayout</code> is an immutable graphical representation of styled  character data. <p> It provides the following capabilities: <ul> <li>implicit bidirectional analysis and reordering, <li>cursor positioning and movement, including split cursors for mixed directional text, <li>highlighting, including both logical and visual highlighting for mixed directional text, <li>multiple baselines (roman, hanging, and centered), <li>hit testing, <li>justification, <li>default font substitution, <li>metric information such as ascent, descent, and advance, and <li>rendering </ul> <p> A <code>TextLayout</code> object can be rendered using  its <code>draw</code> method. <p> <code>TextLayout</code> can be constructed either directly or through  the use of a <A HREF="../../../java/awt/font/LineBreakMeasurer.html"><CODE>LineBreakMeasurer</CODE></A>.  When constructed directly, the  source text represents a single paragraph.  <code>LineBreakMeasurer</code> allows styled text to be broken into lines that fit within a particular  width.  See the <code>LineBreakMeasurer</code> documentation for more information. <p> <code>TextLayout</code> construction logically proceeds as follows: <ul> <li>paragraph attributes are extracted and examined, <li>text is analyzed for bidirectional reordering, and reordering information is computed if needed, <li>text is segmented into style runs <li>fonts are chosen for style runs, first by using a font if the attribute <A HREF="../../../java/awt/font/TextAttribute.html#FONT"><CODE>TextAttribute.FONT</CODE></A> is present, otherwise by computing a default font using the attributes that have been defined <li>if text is on multiple baselines, the runs or subruns are further broken into subruns sharing a common baseline, <li>glyphvectors are generated for each run using the chosen font, <li>final bidirectional reordering is performed on the glyphvectors </ul> <p> All graphical information returned from a <code>TextLayout</code>  object's methods is relative to the origin of the  <code>TextLayout</code>, which is the intersection of the <code>TextLayout</code> object's baseline with its left edge.  Also,  coordinates passed into a <code>TextLayout</code> object's methods  are assumed to be relative to the <code>TextLayout</code> object's origin.  Clients usually need to translate between a  <code>TextLayout</code> object's coordinate system and the coordinate system in another object (such as a  <A HREF="../../../java/awt/Graphics.html"><CODE>Graphics</CODE></A> object). <p> <code>TextLayout</code> objects are constructed from styled text,  but they do not retain a reference to their source text.  Thus,  changes in the text previously used to generate a <code>TextLayout</code> do not affect the <code>TextLayout</code>. <p> Three methods on a <code>TextLayout</code> object  (<code>getNextRightHit</code>, <code>getNextLeftHit</code>, and  <code>hitTestChar</code>) return instances of <A HREF="../../../java/awt/font/TextHitInfo.html"><CODE>TextHitInfo</CODE></A>.   The offsets contained in these <code>TextHitInfo</code> objects are relative to the start of the <code>TextLayout</code>, <b>not</b>  to the text used to create the <code>TextLayout</code>.  Similarly,  <code>TextLayout</code> methods that accept <code>TextHitInfo</code> instances as parameters expect the <code>TextHitInfo</code> object's  offsets to be relative to the <code>TextLayout</code>, not to any  underlying text storage model. <p> <strong>Examples</strong>:<p> Constructing and drawing a <code>TextLayout</code> and its bounding  rectangle: <blockquote><pre>   Graphics2D g = ...;   Point2D loc = ...;   Font font = Font.getFont("Helvetica-bold-italic");   FontRenderContext frc = g.getFontRenderContext();   TextLayout layout = new TextLayout("This is a string", font, frc);   layout.draw(g, loc.getX(), loc.getY());   Rectangle2D bounds = layout.getBounds();   bounds.setRect(bounds.getX()+loc.getX(),                  bounds.getY()+loc.getY(),                  bounds.getWidth(),                  bounds.getHeight())   g.draw(bounds); </pre> </blockquote> <p> Hit-testing a <code>TextLayout</code> (determining which character is at a particular graphical location): <blockquote><pre>   Point2D click = ...;   TextHitInfo hit = layout.hitTestChar(                         (float) (click.getX() - loc.getX()),                         (float) (click.getY() - loc.getY())); </pre> </blockquote> <p> Responding to a right-arrow key press: <blockquoute><pre>   int insertionIndex = ...;   TextHitInfo next = layout.getNextRightHit(insertionIndex);   if (next != null) {       // translate graphics to origin of layout on screen       g.translate(loc.getX(), loc.getY());       Shape[] carets = layout.getCaretShapes(next.getInsertionIndex());       g.draw(carets[0]);       if (carets[1] != null) {           g.draw(carets[1]);       }   } </pre></blockquote> <p> Drawing a selection range corresponding to a substring in the source text. The selected area may not be visually contiguous: <blockquoute><pre>   // selStart, selLimit should be relative to the layout,   // not to the source text   int selStart = ..., selLimit = ...;   Color selectionColor = ...;   Shape selection = layout.getLogicalHighlightShape(selStart, selLimit);   // selection may consist of disjoint areas   // graphics is assumed to be tranlated to origin of layout   g.setColor(selectionColor);   g.fill(selection); </pre></blockquote> <p> Drawing a visually contiguous selection range.  The selection range may correspond to more than one substring in the source text.  The ranges of the corresponding source text substrings can be obtained with <code>getLogicalRangesForVisualSelection()</code>: <blockquoute><pre>   TextHitInfo selStart = ..., selLimit = ...;   Shape selection = layout.getVisualHighlightShape(selStart, selLimit);   g.setColor(selectionColor);   g.fill(selection);   int[] ranges = getLogicalRangesForVisualSelection(selStart, selLimit);   // ranges[0], ranges[1] is the first selection range,   // ranges[2], ranges[3] is the second selection range, etc. </pre></blockquote> <p><P><DL><DT><B>See Also: </B><DD><A HREF="../../../java/awt/font/LineBreakMeasurer.html"><CODE>LineBreakMeasurer</CODE></A>, <A HREF="../../../java/awt/font/TextAttribute.html"><CODE>TextAttribute</CODE></A>, <A HREF="../../../java/awt/font/TextHitInfo.html"><CODE>TextHitInfo</CODE></A></DL><HR><P><!-- ======== INNER CLASS SUMMARY ======== --><A NAME="inner_class_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Inner Class Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static&nbsp;class</CODE></FONT></TD><TD><CODE><B><A HREF="../../../java/awt/font/TextLayout.CaretPolicy.html">TextLayout.CaretPolicy</A></B></CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Defines a policy for determining the strong caret location.</TD></TR></TABLE>&nbsp;<!-- =========== FIELD SUMMARY =========== --><A NAME="field_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Field Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static&nbsp;<A HREF="../../../java/awt/font/TextLayout.CaretPolicy.html">TextLayout.CaretPolicy</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../../java/awt/font/TextLayout.html#DEFAULT_CARET_POLICY">DEFAULT_CARET_POLICY</A></B></CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;This <code>CaretPolicy</code> is used when a policy is not specified  by the client.</TD></TR></TABLE>&nbsp;<!-- ======== CONSTRUCTOR SUMMARY ======== --><A NAME="constructor_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Constructor Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../../../java/awt/font/TextLayout.html#TextLayout(java.text.AttributedCharacterIterator, java.awt.font.FontRenderContext)">TextLayout</A></B>(<A HREF="../../../java/text/AttributedCharacterIterator.html">AttributedCharacterIterator</A>&nbsp;text,           <A HREF="../../../java/awt/font/FontRenderContext.html">FontRenderContext</A>&nbsp;frc)</CODE><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Constructs a <code>TextLayout</code> from an iterator over styled text.</TD></TR>

⌨️ 快捷键说明

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