configure: Regenerate.
2006-06-13 Thomas Fitzsimmons <fitzsim@redhat.com> * configure: Regenerate. * Makefile.in: Regenerate. * configure.ac (--enable-plugin): New option. (ac_configure_args): Add --enable-tool-wrappers. (ac_configure_args): Add --disable-plugin unless --enable-plugin was specified. * gcj/Makefile.in: Regenerate. * sources.am (gnu_java_net_source_files): Add classpath/gnu/java/net/IndexListParser.java. (property_files): Remove classpath/resource/gnu/classpath/tools/jarsigner/MessageBundle.properties, classpath/resource/gnu/classpath/tools/keytool/MessageBundle.properties. Add classpath/resource/gnu/classpath/tools/appletviewer/MessagesBundle.properties, classpath/resource/gnu/classpath/tools/appletviewer/MessagesBundle_de.properties, classpath/resource/gnu/classpath/tools/getopt/Messages.properties, classpath/resource/gnu/classpath/tools/jar/messages.properties, classpath/resource/gnu/classpath/tools/jarsigner/messages.properties, classpath/resource/gnu/classpath/tools/keytool/messages.properties, classpath/resource/gnu/classpath/tools/native2ascii/messages.properties, classpath/resource/gnu/classpath/tools/serialver/messages.properties. * classpath/Makefile.in: Regenerate. * classpath/native/jni/gtk-peer/cairographics2d.h, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkTextLayout.c: Merge from GNU Classpath. * classpath/native/Makefile.in: Regenerate. * classpath/native/jawt/Makefile.in: Regenerate. * classpath/native/jawt/Makefile.am: Install libjawt.so in GCJ's versioned library directory. * classpath/native/Makefile.am: Add plugin directory if --enable-plugin was specified. * classpath/native/plugin/Makefile.in: Regenerate. * classpath/native/plugin/Makefile.am: Install libgcjwebplugin.so in GCJ's versioned library directory. * classpath/resource/gnu/classpath/tools/native2ascii/messages.properties: New file. * classpath/resource/gnu/classpath/tools/getopt/Messages.properties: Likewise. * classpath/resource/gnu/classpath/tools/jarsigner/messages.properties: Likewise. * classpath/resource/gnu/classpath/tools/jarsigner/MessageBundle.properties: Remove file. * classpath/resource/gnu/classpath/tools/keytool/messages.properties: New file. * classpath/resource/gnu/classpath/tools/keytool/MessageBundle.properties: Remove file. * classpath/resource/gnu/classpath/tools/appletviewer/MessagesBundle_de.properties: New file. * classpath/resource/gnu/classpath/tools/appletviewer/MessagesBundle.properties: Likewise. * classpath/resource/gnu/classpath/tools/jar/messages.properties: Likewise. * classpath/resource/gnu/classpath/tools/serialver/messages.properties: Likewise. * classpath/gnu/java/net/IndexListParser.java: Likewise. * classpath/gnu/java/awt/peer/gtk/VolatileImageGraphics.java, classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java, classpath/gnu/java/awt/peer/gtk/CairoSurface.java, classpath/gnu/java/awt/peer/gtk/GdkFontPeer.java, classpath/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java, classpath/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java, classpath/gnu/java/awt/peer/gtk/GdkTextLayout.java, classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java, classpath/gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java, classpath/gnu/java/awt/peer/gtk/GtkVolatileImage.java, classpath/gnu/java/awt/font/opentype/truetype/VirtualMachine.java, classpath/gnu/java/awt/java2d/PolyEdge.java, classpath/gnu/java/awt/java2d/AbstractGraphics2D.java: Merge from GNU Classpath. * classpath/tools/toolwrapper.c: Replace tools.zip reference with libgcj-tools-4.2.0.jar. * classpath/tools/Makefile.in: Regenerate. * classpath/tools/Makefile.am: Rename tools.zip to libgcj-tools-4.2.0.jar. Install libgcj-tools-4.2.0.jar in $(datadir)/java. * classpath/javax/swing/JTabbedPane.java, classpath/javax/swing/text/DefaultStyledDocument.java, classpath/javax/swing/text/html/HTMLDocument.java, classpath/javax/swing/text/GapContent.java, classpath/javax/swing/JComponent.java, classpath/javax/swing/RepaintManager.java, classpath/javax/swing/plaf/basic/BasicComboBoxRenderer.java, classpath/javax/swing/plaf/basic/BasicScrollBarUI.java, classpath/javax/swing/plaf/basic/BasicTabbedPaneUI.java, classpath/javax/swing/plaf/basic/BasicScrollPaneUI.java, classpath/javax/swing/plaf/basic/BasicLookAndFeel.java, classpath/javax/swing/plaf/metal/MetalButtonUI.java, classpath/java/text/Bidi.java, classpath/java/awt/image/BufferedImage.java, classpath/java/awt/datatransfer/DataFlavor.java, classpath/java/awt/geom/AffineTransform.java, classpath/java/awt/dnd/DropTargetDropEvent.java, classpath/java/awt/dnd/DropTargetContext.java, classpath/java/awt/font/TextLayout.java, classpath/include/gnu_java_awt_peer_gtk_ComponentGraphics.h, classpath/include/gnu_java_awt_peer_gtk_CairoGraphics2D.h, classpath/include/gnu_java_awt_peer_gtk_FreetypeGlyphVector.h, classpath/include/gnu_java_awt_peer_gtk_GdkTextLayout.h, classpath/include/gnu_java_awt_peer_gtk_GtkVolatileImage.h, classpath/include/gnu_java_awt_peer_gtk_CairoSurface.h: Merge from GNU Classpath. * classpath/include/gnu_java_awt_peer_gtk_GdkGraphics.h, classpath/include/gnu_java_awt_peer_gtk_GdkGraphics2D.h, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c, classpath/native/jni/gtk-peer/gtkcairopeer.h, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c: Remove files. * classpath/Makefile.am (SUBDIRS, DIST_SUBDIRS): Include tools directory. * include/Makefile.in: Regenerate. * testsuite/Makefile.in: Regenerate. From-SVN: r114633
This commit is contained in:
parent
e3d437c056
commit
648e8d6dd3
102 changed files with 3933 additions and 4458 deletions
|
@ -1,5 +1,5 @@
|
|||
/* TextLayout.java --
|
||||
Copyright (C) 2003, 2004 Free Software Foundation, Inc.
|
||||
Copyright (C) 2006 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
|
@ -38,8 +38,7 @@ exception statement from your version. */
|
|||
|
||||
package java.awt.font;
|
||||
|
||||
import gnu.java.awt.ClasspathToolkit;
|
||||
import gnu.java.awt.peer.ClasspathTextLayoutPeer;
|
||||
import gnu.classpath.NotImplementedException;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
|
@ -47,116 +46,269 @@ import java.awt.Shape;
|
|||
import java.awt.Toolkit;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.text.AttributedCharacterIterator;
|
||||
import java.text.AttributedString;
|
||||
import java.text.Bidi;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Michael Koch
|
||||
* @author Sven de Marothy
|
||||
*/
|
||||
public final class TextLayout implements Cloneable
|
||||
{
|
||||
public static final CaretPolicy DEFAULT_CARET_POLICY = new CaretPolicy ();
|
||||
ClasspathTextLayoutPeer peer;
|
||||
private GlyphVector[] runs;
|
||||
private Font font;
|
||||
private FontRenderContext frc;
|
||||
private String string;
|
||||
private Rectangle2D boundsCache;
|
||||
private LineMetrics lm;
|
||||
|
||||
public static class CaretPolicy
|
||||
{
|
||||
public CaretPolicy ()
|
||||
{
|
||||
// Do nothing here.
|
||||
}
|
||||
/**
|
||||
* Start and end character indices of the runs.
|
||||
* First index is the run number, second is 0 or 1 for the starting
|
||||
* and ending character index of the run, respectively.
|
||||
*/
|
||||
private int[][] runIndices;
|
||||
|
||||
public TextHitInfo getStrongCaret (TextHitInfo hit1, TextHitInfo hit2,
|
||||
TextLayout layout)
|
||||
{
|
||||
return layout.peer.getStrongCaret(hit1, hit2);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Base directionality, determined from the first char.
|
||||
*/
|
||||
private boolean leftToRight;
|
||||
|
||||
public TextLayout (AttributedCharacterIterator text, FontRenderContext frc)
|
||||
{
|
||||
AttributedString as = new AttributedString (text);
|
||||
ClasspathToolkit tk = (ClasspathToolkit)(Toolkit.getDefaultToolkit ());
|
||||
peer = tk.getClasspathTextLayoutPeer(as, frc);
|
||||
}
|
||||
/**
|
||||
* Whether this layout contains whitespace or not.
|
||||
*/
|
||||
private boolean hasWhitespace = false;
|
||||
|
||||
/**
|
||||
* The default caret policy.
|
||||
*/
|
||||
static TextLayout.CaretPolicy DEFAULT_CARET_POLICY = new CaretPolicy();
|
||||
|
||||
/**
|
||||
* Constructs a TextLayout.
|
||||
*/
|
||||
public TextLayout (String string, Font font, FontRenderContext frc)
|
||||
{
|
||||
AttributedString as = new AttributedString (string);
|
||||
as.addAttribute (TextAttribute.FONT, font);
|
||||
ClasspathToolkit tk = (ClasspathToolkit)(Toolkit.getDefaultToolkit ());
|
||||
peer = tk.getClasspathTextLayoutPeer(as, frc);
|
||||
this.font = font;
|
||||
this.frc = frc;
|
||||
this.string = string;
|
||||
lm = font.getLineMetrics(string, frc);
|
||||
|
||||
// Get base direction and whitespace info
|
||||
getStringProperties();
|
||||
|
||||
if( Bidi.requiresBidi( string.toCharArray(), 0, string.length() ) )
|
||||
{
|
||||
Bidi bidi = new Bidi( string, leftToRight ?
|
||||
Bidi.DIRECTION_LEFT_TO_RIGHT :
|
||||
Bidi.DIRECTION_RIGHT_TO_LEFT );
|
||||
int rc = bidi.getRunCount();
|
||||
byte[] table = new byte[ rc ];
|
||||
for(int i = 0; i < table.length; i++)
|
||||
table[i] = (byte)bidi.getRunLevel(i);
|
||||
|
||||
runs = new GlyphVector[ rc ];
|
||||
runIndices = new int[rc][2];
|
||||
for(int i = 0; i < runs.length; i++)
|
||||
{
|
||||
runIndices[i][0] = bidi.getRunStart( i );
|
||||
runIndices[i][1] = bidi.getRunLimit( i );
|
||||
if( runIndices[i][0] != runIndices[i][1] ) // no empty runs.
|
||||
{
|
||||
runs[i] = font.layoutGlyphVector
|
||||
( frc, string.toCharArray(),
|
||||
runIndices[i][0], runIndices[i][1],
|
||||
((table[i] & 1) == 0) ? Font.LAYOUT_LEFT_TO_RIGHT :
|
||||
Font.LAYOUT_RIGHT_TO_LEFT );
|
||||
}
|
||||
}
|
||||
Bidi.reorderVisually( table, 0, runs, 0, runs.length );
|
||||
}
|
||||
else
|
||||
{
|
||||
runs = new GlyphVector[ 1 ];
|
||||
runIndices = new int[1][2];
|
||||
runIndices[0][0] = 0;
|
||||
runIndices[0][1] = string.length();
|
||||
runs[ 0 ] = font.layoutGlyphVector( frc, string.toCharArray(),
|
||||
0, string.length(),
|
||||
leftToRight ?
|
||||
Font.LAYOUT_LEFT_TO_RIGHT :
|
||||
Font.LAYOUT_RIGHT_TO_LEFT );
|
||||
}
|
||||
}
|
||||
|
||||
public TextLayout (String string, Map attributes, FontRenderContext frc)
|
||||
{
|
||||
AttributedString as = new AttributedString (string, attributes);
|
||||
ClasspathToolkit tk = (ClasspathToolkit)(Toolkit.getDefaultToolkit ());
|
||||
peer = tk.getClasspathTextLayoutPeer(as, frc);
|
||||
this( string, new Font( attributes ), frc );
|
||||
}
|
||||
|
||||
public TextLayout (AttributedCharacterIterator text, FontRenderContext frc)
|
||||
throws NotImplementedException
|
||||
{
|
||||
throw new Error ("not implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan the character run for the first strongly directional character,
|
||||
* which in turn defines the base directionality of the whole layout.
|
||||
*/
|
||||
private void getStringProperties()
|
||||
{
|
||||
boolean gotDirection = false;
|
||||
int i = 0;
|
||||
|
||||
leftToRight = true;
|
||||
while( i < string.length() && !gotDirection )
|
||||
switch( Character.getDirectionality( string.charAt( i++ ) ) )
|
||||
{
|
||||
case Character.DIRECTIONALITY_LEFT_TO_RIGHT:
|
||||
case Character.DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING:
|
||||
case Character.DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE:
|
||||
gotDirection = true;
|
||||
break;
|
||||
|
||||
case Character.DIRECTIONALITY_RIGHT_TO_LEFT:
|
||||
case Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC:
|
||||
case Character.DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING:
|
||||
case Character.DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE:
|
||||
leftToRight = false;
|
||||
gotDirection = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// Determine if there's whitespace in the thing.
|
||||
// Ignore trailing chars.
|
||||
i = string.length() - 1;
|
||||
hasWhitespace = false;
|
||||
while( i >= 0 && Character.isWhitespace( string.charAt(i) ) )
|
||||
i--;
|
||||
// Check the remaining chars
|
||||
while( i >= 0 )
|
||||
if( Character.isWhitespace( string.charAt(i--) ) )
|
||||
hasWhitespace = true;
|
||||
}
|
||||
|
||||
protected Object clone ()
|
||||
{
|
||||
try
|
||||
{
|
||||
TextLayout tl = (TextLayout) super.clone ();
|
||||
tl.peer = (ClasspathTextLayoutPeer) this.peer.clone();
|
||||
return tl;
|
||||
}
|
||||
catch (CloneNotSupportedException e)
|
||||
{
|
||||
// This should never occur
|
||||
throw new InternalError ();
|
||||
}
|
||||
return new TextLayout( string, font, frc );
|
||||
}
|
||||
|
||||
|
||||
public void draw (Graphics2D g2, float x, float y)
|
||||
{
|
||||
peer.draw(g2, x, y);
|
||||
{
|
||||
for(int i = 0; i < runs.length; i++)
|
||||
{
|
||||
g2.drawGlyphVector(runs[i], x, y);
|
||||
Rectangle2D r = runs[i].getLogicalBounds();
|
||||
x += r.getWidth();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean equals (Object obj)
|
||||
{
|
||||
if (! (obj instanceof TextLayout))
|
||||
if( !( obj instanceof TextLayout) )
|
||||
return false;
|
||||
|
||||
return equals ((TextLayout) obj);
|
||||
return equals( (TextLayout) obj );
|
||||
}
|
||||
|
||||
public boolean equals (TextLayout tl)
|
||||
{
|
||||
return this.peer.equals(tl.peer);
|
||||
if( runs.length != tl.runs.length )
|
||||
return false;
|
||||
// Compare all glyph vectors.
|
||||
for( int i = 0; i < runs.length; i++ )
|
||||
if( !runs[i].equals( tl.runs[i] ) )
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public float getAdvance ()
|
||||
{
|
||||
return peer.getAdvance();
|
||||
float totalAdvance = 0f;
|
||||
for(int i = 0; i < runs.length; i++)
|
||||
totalAdvance += runs[i].getLogicalBounds().getWidth();
|
||||
return totalAdvance;
|
||||
}
|
||||
|
||||
public float getAscent ()
|
||||
{
|
||||
return peer.getAscent();
|
||||
return lm.getAscent();
|
||||
}
|
||||
|
||||
public byte getBaseline ()
|
||||
{
|
||||
return peer.getBaseline();
|
||||
return (byte)lm.getBaselineIndex();
|
||||
}
|
||||
|
||||
public float[] getBaselineOffsets ()
|
||||
{
|
||||
return peer.getBaselineOffsets();
|
||||
return lm.getBaselineOffsets();
|
||||
}
|
||||
|
||||
public Shape getBlackBoxBounds (int firstEndpoint, int secondEndpoint)
|
||||
{
|
||||
return peer.getBlackBoxBounds(firstEndpoint, secondEndpoint);
|
||||
if( firstEndpoint < 0 || secondEndpoint > getCharacterCount() )
|
||||
return new Rectangle2D.Float();
|
||||
|
||||
GeneralPath gp = new GeneralPath();
|
||||
int i = 0; // run index
|
||||
double advance = 0;
|
||||
|
||||
// go to first run
|
||||
while( runIndices[i + 1][1] < firstEndpoint )
|
||||
{
|
||||
advance += runs[i].getLogicalBounds().getWidth();
|
||||
i++;
|
||||
}
|
||||
|
||||
int j = 0; // index into the run.
|
||||
if( runIndices[i][1] - runIndices[i][0] > 1 )
|
||||
{
|
||||
while( runs[i].getGlyphCharIndex( j + 1 ) <
|
||||
(firstEndpoint - runIndices[i][0] ) )j++;
|
||||
}
|
||||
|
||||
gp.append(runs[i].getGlyphVisualBounds( j ), false);
|
||||
boolean keepGoing = true;;
|
||||
|
||||
do
|
||||
{
|
||||
while( j < runs[i].getNumGlyphs() &&
|
||||
runs[i].getGlyphCharIndex( j ) + runIndices[i][0] <
|
||||
secondEndpoint )
|
||||
{
|
||||
Rectangle2D r2 = (runs[i].getGlyphVisualBounds( j )).
|
||||
getBounds2D();
|
||||
Point2D p = runs[i].getGlyphPosition( j );
|
||||
r2.setRect( advance + p.getX(), r2.getY(),
|
||||
r2.getWidth(), r2.getHeight() );
|
||||
gp.append(r2, false);
|
||||
j++;
|
||||
}
|
||||
|
||||
if( j >= runs[i].getNumGlyphs() )
|
||||
{
|
||||
advance += runs[i].getLogicalBounds().getWidth();
|
||||
i++;
|
||||
j = 0;
|
||||
}
|
||||
else
|
||||
keepGoing = false;
|
||||
}
|
||||
while( keepGoing );
|
||||
|
||||
return gp;
|
||||
}
|
||||
|
||||
public Rectangle2D getBounds()
|
||||
{
|
||||
return peer.getBounds();
|
||||
if( boundsCache == null )
|
||||
boundsCache = getOutline(new AffineTransform()).getBounds();
|
||||
return boundsCache;
|
||||
}
|
||||
|
||||
public float[] getCaretInfo (TextHitInfo hit)
|
||||
|
@ -165,144 +317,274 @@ public final class TextLayout implements Cloneable
|
|||
}
|
||||
|
||||
public float[] getCaretInfo (TextHitInfo hit, Rectangle2D bounds)
|
||||
throws NotImplementedException
|
||||
{
|
||||
return peer.getCaretInfo(hit, bounds);
|
||||
throw new Error ("not implemented");
|
||||
}
|
||||
|
||||
public Shape getCaretShape (TextHitInfo hit)
|
||||
{
|
||||
return getCaretShape(hit, getBounds());
|
||||
return getCaretShape( hit, getBounds() );
|
||||
}
|
||||
|
||||
public Shape getCaretShape (TextHitInfo hit, Rectangle2D bounds)
|
||||
throws NotImplementedException
|
||||
{
|
||||
return peer.getCaretShape(hit, bounds);
|
||||
throw new Error ("not implemented");
|
||||
}
|
||||
|
||||
public Shape[] getCaretShapes (int offset)
|
||||
{
|
||||
return getCaretShapes(offset, getBounds());
|
||||
return getCaretShapes( offset, getBounds() );
|
||||
}
|
||||
|
||||
public Shape[] getCaretShapes (int offset, Rectangle2D bounds)
|
||||
throws NotImplementedException
|
||||
{
|
||||
return getCaretShapes(offset, getBounds(), DEFAULT_CARET_POLICY);
|
||||
}
|
||||
|
||||
public Shape[] getCaretShapes (int offset, Rectangle2D bounds,
|
||||
TextLayout.CaretPolicy policy)
|
||||
{
|
||||
return peer.getCaretShapes(offset, bounds, policy);
|
||||
throw new Error ("not implemented");
|
||||
}
|
||||
|
||||
public int getCharacterCount ()
|
||||
{
|
||||
return peer.getCharacterCount();
|
||||
return string.length();
|
||||
}
|
||||
|
||||
public byte getCharacterLevel (int index)
|
||||
throws NotImplementedException
|
||||
{
|
||||
return peer.getCharacterLevel(index);
|
||||
throw new Error ("not implemented");
|
||||
}
|
||||
|
||||
public float getDescent ()
|
||||
{
|
||||
return peer.getDescent();
|
||||
return lm.getDescent();
|
||||
}
|
||||
|
||||
public TextLayout getJustifiedLayout (float justificationWidth)
|
||||
{
|
||||
return peer.getJustifiedLayout(justificationWidth);
|
||||
TextLayout newLayout = (TextLayout)clone();
|
||||
|
||||
if( hasWhitespace )
|
||||
newLayout.handleJustify( justificationWidth );
|
||||
|
||||
return newLayout;
|
||||
}
|
||||
|
||||
public float getLeading ()
|
||||
{
|
||||
return peer.getLeading();
|
||||
return lm.getLeading();
|
||||
}
|
||||
|
||||
public Shape getLogicalHighlightShape (int firstEndpoint, int secondEndpoint)
|
||||
{
|
||||
return getLogicalHighlightShape (firstEndpoint, secondEndpoint, getBounds());
|
||||
return getLogicalHighlightShape( firstEndpoint, secondEndpoint,
|
||||
getBounds() );
|
||||
}
|
||||
|
||||
public Shape getLogicalHighlightShape (int firstEndpoint, int secondEndpoint,
|
||||
Rectangle2D bounds)
|
||||
{
|
||||
return peer.getLogicalHighlightShape(firstEndpoint, secondEndpoint, bounds);
|
||||
if( firstEndpoint < 0 || secondEndpoint > getCharacterCount() )
|
||||
return new Rectangle2D.Float();
|
||||
|
||||
int i = 0; // run index
|
||||
double advance = 0;
|
||||
|
||||
// go to first run
|
||||
if( i > 0 )
|
||||
while( runIndices[i + 1][1] < firstEndpoint )
|
||||
{
|
||||
advance += runs[i].getLogicalBounds().getWidth();
|
||||
i++;
|
||||
}
|
||||
|
||||
int j = 0; // index into the run.
|
||||
if( runIndices[i][1] - runIndices[i][0] > 1 )
|
||||
{
|
||||
while( runs[i].getGlyphCharIndex( j + 1 ) <
|
||||
(firstEndpoint - runIndices[i][0] ) )j++;
|
||||
}
|
||||
|
||||
Rectangle2D r = (runs[i].getGlyphLogicalBounds( j )).getBounds2D();
|
||||
boolean keepGoing = true;;
|
||||
|
||||
do
|
||||
{
|
||||
while( j < runs[i].getNumGlyphs() &&
|
||||
runs[i].getGlyphCharIndex( j ) + runIndices[i][0] <
|
||||
secondEndpoint )
|
||||
{
|
||||
Rectangle2D r2 = (runs[i].getGlyphLogicalBounds( j )).
|
||||
getBounds2D();
|
||||
Point2D p = runs[i].getGlyphPosition( j );
|
||||
r2.setRect( advance + p.getX(), r2.getY(),
|
||||
r2.getWidth(), r2.getHeight() );
|
||||
r = r.createUnion( r2 );
|
||||
j++;
|
||||
}
|
||||
|
||||
if( j >= runs[i].getNumGlyphs() )
|
||||
{
|
||||
advance += runs[i].getLogicalBounds().getWidth();
|
||||
i++;
|
||||
j = 0;
|
||||
}
|
||||
else
|
||||
keepGoing = false;
|
||||
}
|
||||
while( keepGoing );
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
public int[] getLogicalRangesForVisualSelection (TextHitInfo firstEndpoint,
|
||||
TextHitInfo secondEndpoint)
|
||||
throws NotImplementedException
|
||||
{
|
||||
return peer.getLogicalRangesForVisualSelection(firstEndpoint, secondEndpoint);
|
||||
throw new Error ("not implemented");
|
||||
}
|
||||
|
||||
public TextHitInfo getNextLeftHit (int offset)
|
||||
throws NotImplementedException
|
||||
{
|
||||
return getNextLeftHit(offset, DEFAULT_CARET_POLICY);
|
||||
}
|
||||
|
||||
public TextHitInfo getNextLeftHit (int offset, TextLayout.CaretPolicy policy)
|
||||
{
|
||||
return peer.getNextLeftHit(offset, policy);
|
||||
throw new Error ("not implemented");
|
||||
}
|
||||
|
||||
public TextHitInfo getNextLeftHit (TextHitInfo hit)
|
||||
throws NotImplementedException
|
||||
{
|
||||
return getNextLeftHit(hit.getCharIndex());
|
||||
throw new Error ("not implemented");
|
||||
}
|
||||
|
||||
public TextHitInfo getNextRightHit (int offset)
|
||||
throws NotImplementedException
|
||||
{
|
||||
return getNextRightHit(offset, DEFAULT_CARET_POLICY);
|
||||
}
|
||||
|
||||
public TextHitInfo getNextRightHit (int offset, TextLayout.CaretPolicy policy)
|
||||
{
|
||||
return peer.getNextRightHit(offset, policy);
|
||||
throw new Error ("not implemented");
|
||||
}
|
||||
|
||||
public TextHitInfo getNextRightHit (TextHitInfo hit)
|
||||
throws NotImplementedException
|
||||
{
|
||||
return getNextRightHit(hit.getCharIndex());
|
||||
throw new Error ("not implemented");
|
||||
}
|
||||
|
||||
public Shape getOutline (AffineTransform tx)
|
||||
{
|
||||
return peer.getOutline(tx);
|
||||
float x = 0f;
|
||||
GeneralPath gp = new GeneralPath();
|
||||
for(int i = 0; i < runs.length; i++)
|
||||
{
|
||||
gp.append( runs[i].getOutline( x, 0f ), false );
|
||||
Rectangle2D r = runs[i].getLogicalBounds();
|
||||
x += r.getWidth();
|
||||
}
|
||||
if( tx != null )
|
||||
gp.transform( tx );
|
||||
return gp;
|
||||
}
|
||||
|
||||
public float getVisibleAdvance ()
|
||||
{
|
||||
return peer.getVisibleAdvance();
|
||||
float totalAdvance = 0f;
|
||||
|
||||
if( runs.length <= 0 )
|
||||
return 0f;
|
||||
|
||||
// No trailing whitespace
|
||||
if( !Character.isWhitespace( string.charAt( string.length() -1 ) ) )
|
||||
return getAdvance();
|
||||
|
||||
// Get length of all runs up to the last
|
||||
for(int i = 0; i < runs.length - 1; i++)
|
||||
totalAdvance += runs[i].getLogicalBounds().getWidth();
|
||||
|
||||
int lastRun = runIndices[ runs.length - 1 ][0];
|
||||
int j = string.length() - 1;
|
||||
while( j >= lastRun && Character.isWhitespace( string.charAt( j ) ) ) j--;
|
||||
|
||||
if( j < lastRun )
|
||||
return totalAdvance; // entire last run is whitespace
|
||||
|
||||
int lastNonWSChar = j - lastRun;
|
||||
j = 0;
|
||||
while( runs[ runs.length - 1 ].getGlyphCharIndex( j )
|
||||
<= lastNonWSChar )
|
||||
{
|
||||
totalAdvance += runs[ runs.length - 1 ].getGlyphLogicalBounds( j ).
|
||||
getBounds2D().getWidth();
|
||||
j ++;
|
||||
}
|
||||
|
||||
return totalAdvance;
|
||||
}
|
||||
|
||||
public Shape getVisualHighlightShape (TextHitInfo firstEndpoint,
|
||||
TextHitInfo secondEndpoint)
|
||||
{
|
||||
return getVisualHighlightShape(firstEndpoint, secondEndpoint, getBounds());
|
||||
return getVisualHighlightShape( firstEndpoint, secondEndpoint,
|
||||
getBounds() );
|
||||
}
|
||||
|
||||
public Shape getVisualHighlightShape (TextHitInfo firstEndpoint,
|
||||
TextHitInfo secondEndpoint,
|
||||
Rectangle2D bounds)
|
||||
throws NotImplementedException
|
||||
{
|
||||
return peer.getVisualHighlightShape(firstEndpoint, secondEndpoint, bounds);
|
||||
throw new Error ("not implemented");
|
||||
}
|
||||
|
||||
public TextHitInfo getVisualOtherHit (TextHitInfo hit)
|
||||
throws NotImplementedException
|
||||
{
|
||||
return peer.getVisualOtherHit(hit);
|
||||
throw new Error ("not implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a protected method of a <code>final</code> class, meaning
|
||||
* it exists only to taunt you.
|
||||
*/
|
||||
protected void handleJustify (float justificationWidth)
|
||||
{
|
||||
peer.handleJustify(justificationWidth);
|
||||
}
|
||||
// We assume that the text has non-trailing whitespace.
|
||||
// First get the change in width to insert into the whitespaces.
|
||||
double deltaW = justificationWidth - getVisibleAdvance();
|
||||
int nglyphs = 0; // # of whitespace chars
|
||||
|
||||
public int hashCode ()
|
||||
{
|
||||
return peer.hashCode();
|
||||
// determine last non-whitespace char.
|
||||
int lastNWS = string.length() - 1;
|
||||
while( Character.isWhitespace( string.charAt( lastNWS ) ) ) lastNWS--;
|
||||
|
||||
// locations of the glyphs.
|
||||
int[] wsglyphs = new int[string.length() * 10];
|
||||
for(int run = 0; run < runs.length; run++ )
|
||||
for(int i = 0; i < runs[run].getNumGlyphs(); i++ )
|
||||
{
|
||||
int cindex = runIndices[run][0] + runs[run].getGlyphCharIndex( i );
|
||||
if( Character.isWhitespace( string.charAt( cindex ) ) )
|
||||
// && cindex < lastNWS )
|
||||
{
|
||||
wsglyphs[ nglyphs * 2 ] = run;
|
||||
wsglyphs[ nglyphs * 2 + 1] = i;
|
||||
nglyphs++;
|
||||
}
|
||||
}
|
||||
|
||||
deltaW = deltaW / nglyphs; // Change in width per whitespace glyph
|
||||
double w = 0;
|
||||
int cws = 0;
|
||||
// Shift all characters
|
||||
for(int run = 0; run < runs.length; run++ )
|
||||
for(int i = 0; i < runs[ run ].getNumGlyphs(); i++ )
|
||||
{
|
||||
if( wsglyphs[ cws * 2 ] == run && wsglyphs[ cws * 2 + 1 ] == i )
|
||||
{
|
||||
cws++; // update 'current whitespace'
|
||||
w += deltaW; // increment the shift
|
||||
}
|
||||
Point2D p = runs[ run ].getGlyphPosition( i );
|
||||
p.setLocation( p.getX() + w, p.getY() );
|
||||
runs[ run ].setGlyphPosition( i, p );
|
||||
}
|
||||
}
|
||||
|
||||
public TextHitInfo hitTestChar (float x, float y)
|
||||
|
@ -312,21 +594,48 @@ public final class TextLayout implements Cloneable
|
|||
|
||||
public TextHitInfo hitTestChar (float x, float y, Rectangle2D bounds)
|
||||
{
|
||||
return peer.hitTestChar(x, y, bounds);
|
||||
return hitTestChar( x, y, getBounds() );
|
||||
}
|
||||
|
||||
public boolean isLeftToRight ()
|
||||
{
|
||||
return peer.isLeftToRight();
|
||||
return leftToRight;
|
||||
}
|
||||
|
||||
public boolean isVertical ()
|
||||
{
|
||||
return peer.isVertical();
|
||||
return false; // FIXME: How do you create a vertical layout?
|
||||
}
|
||||
|
||||
public int hashCode ()
|
||||
throws NotImplementedException
|
||||
{
|
||||
throw new Error ("not implemented");
|
||||
}
|
||||
|
||||
public String toString ()
|
||||
{
|
||||
return peer.toString();
|
||||
return "TextLayout [string:"+string+", Font:"+font+" Rendercontext:"+
|
||||
frc+"]";
|
||||
}
|
||||
|
||||
/**
|
||||
* Inner class describing a caret policy
|
||||
*/
|
||||
public static class CaretPolicy
|
||||
{
|
||||
public CaretPolicy()
|
||||
{
|
||||
}
|
||||
|
||||
public TextHitInfo getStrongCaret(TextHitInfo hit1,
|
||||
TextHitInfo hit2,
|
||||
TextLayout layout)
|
||||
throws NotImplementedException
|
||||
{
|
||||
throw new Error ("not implemented");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue