[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[commit-cp] classpath ChangeLog java/awt/font/LineBreakMeas...
From: |
Sven de Marothy |
Subject: |
[commit-cp] classpath ChangeLog java/awt/font/LineBreakMeas... |
Date: |
Tue, 13 Jun 2006 00:14:27 +0000 |
CVSROOT: /sources/classpath
Module name: classpath
Changes by: Sven de Marothy <smarothy> 06/06/13 00:14:27
Modified files:
. : ChangeLog
java/awt/font : LineBreakMeasurer.java
Log message:
2006-06-12 Sven de Marothy <address@hidden>
* java/awt/font/LineBreakMeasurer.java): Implement.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/classpath/ChangeLog?cvsroot=classpath&r1=1.7791&r2=1.7792
http://cvs.savannah.gnu.org/viewcvs/classpath/java/awt/font/LineBreakMeasurer.java?cvsroot=classpath&r1=1.3&r2=1.4
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/classpath/classpath/ChangeLog,v
retrieving revision 1.7791
retrieving revision 1.7792
diff -u -b -r1.7791 -r1.7792
--- ChangeLog 12 Jun 2006 21:29:38 -0000 1.7791
+++ ChangeLog 13 Jun 2006 00:14:26 -0000 1.7792
@@ -1,3 +1,7 @@
+2006-06-12 Sven de Marothy <address@hidden>
+
+ * java/awt/font/LineBreakMeasurer.java): Implement.
+
2006-06-12 Keith Seitz <address@hidden>
From Kyle Galloway <address@hidden>:
Index: java/awt/font/LineBreakMeasurer.java
===================================================================
RCS file: /sources/classpath/classpath/java/awt/font/LineBreakMeasurer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- java/awt/font/LineBreakMeasurer.java 22 Mar 2006 19:15:24 -0000
1.3
+++ java/awt/font/LineBreakMeasurer.java 13 Jun 2006 00:14:27 -0000
1.4
@@ -1,5 +1,5 @@
/* LineBreakMeasurer.java
- Copyright (C) 2003 Free Software Foundation, Inc.
+ Copyright (C) 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,84 +38,161 @@
package java.awt.font;
-import gnu.classpath.NotImplementedException;
-
import java.text.AttributedCharacterIterator;
+import java.text.AttributedString;
import java.text.BreakIterator;
+import java.awt.font.TextLayout;
+import java.awt.font.FontRenderContext;
+import java.awt.Shape;
public final class LineBreakMeasurer
{
- private AttributedCharacterIterator ci;
+ private AttributedCharacterIterator text;
+ private int position;
private FontRenderContext frc;
- private BreakIterator bi;
+ private TextLayout totalLayout;
+ private int numChars;
- /**
- * Constructs a <code>LineBreakMeasurer</code> object.
- */
- public LineBreakMeasurer (AttributedCharacterIterator text,
- FontRenderContext frc)
+ public LineBreakMeasurer(AttributedCharacterIterator text,
+ BreakIterator breakIter, FontRenderContext frc)
{
- this (text, null, frc);
+ this.text = text;
+ this.frc = frc;
+ position = 0;
+ totalLayout = new TextLayout(text, frc);
+ numChars = totalLayout.getCharacterCount();
}
- /**
- * Constructs a <code>LineBreakMeasurer</code> object.
- */
- public LineBreakMeasurer (AttributedCharacterIterator text,
- BreakIterator breakIter, FontRenderContext frc)
+ public LineBreakMeasurer(AttributedCharacterIterator text,
+ FontRenderContext frc)
{
- this.ci = text;
- this.bi = breakIter;
+ this.text = text;
this.frc = frc;
+ position = 0;
+ totalLayout = new TextLayout(text, frc);
+ numChars = totalLayout.getCharacterCount();
}
- public void deleteChar (AttributedCharacterIterator newParagraph,
+ public void deleteChar(AttributedCharacterIterator newParagraph,
int deletePos)
- throws NotImplementedException
{
- throw new Error ("not implemented");
+ totalLayout = new TextLayout(newParagraph, frc);
+ if( deletePos < 0 || deletePos > totalLayout.getCharacterCount() )
+ throw new NullPointerException("Invalid deletePos:"+deletePos);
+ numChars = totalLayout.getCharacterCount();
+ text = newParagraph;
+ position = 0;
}
- public int getPosition ()
+ public void insertChar(AttributedCharacterIterator newParagraph,
+ int insertPos)
{
- return ci.getIndex ();
+ totalLayout = new TextLayout(newParagraph, frc);
+ if( insertPos < 0 || insertPos > totalLayout.getCharacterCount() )
+ throw new NullPointerException("Invalid insertPos:"+insertPos);
+ numChars = totalLayout.getCharacterCount();
+ text = newParagraph;
+ position = 0;
}
- public void insertChar (AttributedCharacterIterator newParagraph,
- int insertPos)
- throws NotImplementedException
+ public TextLayout nextLayout(float wrappingWidth)
{
- throw new Error ("not implemented");
+ return nextLayout( wrappingWidth, numChars, false );
}
- public TextLayout nextLayout (float wrappingWidth)
- throws NotImplementedException
+ public TextLayout nextLayout(float wrappingWidth, int offsetLimit,
+ boolean requireNextWord)
{
- throw new Error ("not implemented");
+ int next = nextOffset( wrappingWidth, offsetLimit, requireNextWord );
+ AttributedCharacterIterator aci = (new AttributedString( text,
+ position, next )
+ ).getIterator();
+ position = next;
+ return new TextLayout( aci, frc );
}
- public TextLayout nextLayout (float wrappingWidth, int offsetLimit,
+ public int nextOffset(float wrappingWidth)
+ {
+ return nextOffset( wrappingWidth, numChars, false );
+ }
+
+ public int nextOffset(float wrappingWidth, int offsetLimit,
boolean requireNextWord)
- throws NotImplementedException
{
- throw new Error ("not implemented");
+ Shape s = totalLayout.getBlackBoxBounds( position, offsetLimit );
+ double remainingLength = s.getBounds2D().getWidth();
+
+ int guessOffset = (int)( ( (double)wrappingWidth / (double)remainingLength)
+ * ( (double)numChars - (double)position ) );
+ guessOffset += position;
+ if( guessOffset > offsetLimit )
+ guessOffset = offsetLimit;
+
+ s = totalLayout.getBlackBoxBounds( position, guessOffset );
+ double guessLength = s.getBounds2D().getWidth();
+
+ boolean makeSmaller = ( guessLength > wrappingWidth );
+ int inc = makeSmaller ? -1 : 1;
+ boolean keepGoing = true;
+
+ do
+ {
+ guessOffset = guessOffset + inc;
+ if( guessOffset <= position || guessOffset > offsetLimit )
+ {
+ keepGoing = false;
+ }
+ else
+ {
+ s = totalLayout.getBlackBoxBounds( position, guessOffset );
+ guessLength = s.getBounds2D().getWidth();
+ if( makeSmaller && ( guessLength <= wrappingWidth) )
+ keepGoing = false;
+ if( !makeSmaller && ( guessLength >= wrappingWidth) )
+ keepGoing = false;
+ }
}
+ while( keepGoing );
- public int nextOffset (float wrappingWidth)
- throws NotImplementedException
+ if( !makeSmaller )
+ guessOffset--;
+
+ if( guessOffset >= offsetLimit )
+ return offsetLimit;
+
+ text.setIndex( guessOffset );
+ if( !requireNextWord )
+ {
+ char c = text.previous();
+ while( !Character.isWhitespace( c ) && c != '-' &&
+ guessOffset > position )
+ {
+ guessOffset--;
+ c = text.previous();
+ }
+ }
+ else
{
- throw new Error ("not implemented");
+ char c = text.next();
+ while( !Character.isWhitespace( c ) && c != '-' &&
+ guessOffset < offsetLimit )
+ {
+ guessOffset++;
+ c = text.next();
+ }
}
- public int nextOffset (float wrappingWidth, int offsetLimit,
- boolean requireNextWord)
- throws NotImplementedException
+ return guessOffset;
+ }
+
+ public void setPosition(int newPosition)
{
- throw new Error ("not implemented");
+ position = newPosition;
}
- public void setPosition (int newPosition)
+ public int getPosition()
{
- ci.setIndex (newPosition);
+ return position;
}
}
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [commit-cp] classpath ChangeLog java/awt/font/LineBreakMeas...,
Sven de Marothy <=