[cp-patches] FYI: java.util.Locale - fix broken serialization and equals()

2006-08-12 Thread Sven de Marothy
This is a major embarassment. 

2006-08-13  Sven de Marothy  [EMAIL PROTECTED]

* java/util/Locale.java
(hashcode): Is a serialized field, not transient.
(equals): Should NOT compare strings by reference.
(readObject/writeObject): Use the default methods and handle the hash
seperately.


Index: java/util/Locale.java
===
RCS file: /sources/classpath/classpath/java/util/Locale.java,v
retrieving revision 1.33
diff -U3 -r1.33 Locale.java
--- java/util/Locale.java	20 Apr 2006 09:29:27 -	1.33
+++ java/util/Locale.java	13 Aug 2006 00:17:42 -
@@ -192,7 +192,7 @@
*
* @serial should be -1 in serial streams
*/
-  private transient int hashcode;
+  private int hashcode;
 
   /**
* Array storing all available locales.
@@ -917,9 +917,9 @@
   return false;
 Locale l = (Locale) obj;
 
-return (language == l.language
- country == l.country
- variant == l.variant);
+return (language.equals( l.language )
+ country.equals( l.country )
+ variant.equals( l.variant ) );
   }
 
   /**
@@ -935,11 +935,11 @@
   private void writeObject(ObjectOutputStream s)
 throws IOException
   {
-s.writeObject(language);
-s.writeObject(country);
-s.writeObject(variant);
 // Hashcode field is always written as -1.
-s.writeInt(-1);
+int temp = hashcode;
+hashcode = -1;
+s.defaultWriteObject();
+hashcode = temp;
   }
 
   /**
@@ -953,9 +953,7 @@
   private void readObject(ObjectInputStream s)
 throws IOException, ClassNotFoundException
   {
-language = ((String) s.readObject()).intern();
-country = ((String) s.readObject()).intern();
-variant = ((String) s.readObject()).intern();
+s.defaultReadObject();
 // Recompute hashcode.
 hashcode = language.hashCode() ^ country.hashCode() ^ variant.hashCode();
   }


[cp-patches] Re: FYI: java.util.Locale - fix broken serialization and equals()

2006-08-12 Thread Sven de Marothy
Now I get to share in the embarassment, I'd missed the strings are
supposed to be interned.

2006-08-13  Sven de Marothy  [EMAIL PROTECTED]

* java/util/Locale.java
(hashcodeCache): New field.
(hashCode): use the above field instead of the serialized one
(writeObject): Removed method.
(equals): Revert to previous method.

Index: java/util/Locale.java
===
RCS file: /sources/classpath/classpath/java/util/Locale.java,v
retrieving revision 1.34
diff -U3 -r1.34 Locale.java
--- java/util/Locale.java	13 Aug 2006 00:20:11 -	1.34
+++ java/util/Locale.java	13 Aug 2006 01:19:00 -
@@ -188,11 +188,17 @@
   private String variant;
 
   /**
-   * This is the cached hashcode. When writing to stream, we write -1.
+   * This is where the JDK caches its hashcode. This is is only here
+   * for serialization purposes. The actual cache is hashcodeCache
*
* @serial should be -1 in serial streams
*/
-  private int hashcode;
+  private int hashcode = -1;
+
+  /**
+   * This is the cached hashcode. 
+   */
+  private transient int hashcodeCache;
 
   /**
* Array storing all available locales.
@@ -324,7 +330,7 @@
 this.language = language;
 this.country = country;
 this.variant = variant;
-hashcode = language.hashCode() ^ country.hashCode() ^ variant.hashCode();
+hashcodeCache = language.hashCode() ^ country.hashCode() ^ variant.hashCode();
   }
 
   /**
@@ -899,7 +905,7 @@
*/
   public int hashCode()
   {
-return hashcode;
+return hashcodeCache;
   }
 
   /**
@@ -917,29 +923,9 @@
   return false;
 Locale l = (Locale) obj;
 
-return (language.equals( l.language )
- country.equals( l.country )
- variant.equals( l.variant ) );
-  }
-
-  /**
-   * Write the locale to an object stream.
-   *
-   * @param s the stream to write to
-   * @throws IOException if the write fails
-   * @serialData The first three fields are Strings representing language,
-   * country, and variant. The fourth field is a placeholder for 
-   * the cached hashcode, but this is always written as -1, and 
-   * recomputed when reading it back.
-   */
-  private void writeObject(ObjectOutputStream s)
-throws IOException
-  {
-// Hashcode field is always written as -1.
-int temp = hashcode;
-hashcode = -1;
-s.defaultWriteObject();
-hashcode = temp;
+return (language == l.language 
+ country == l.country 
+ variant == l.variant);
   }
 
   /**
@@ -954,7 +940,9 @@
 throws IOException, ClassNotFoundException
   {
 s.defaultReadObject();
-// Recompute hashcode.
-hashcode = language.hashCode() ^ country.hashCode() ^ variant.hashCode();
+language = language.intern();
+country = country.intern();
+variant = variant.intern();
+hashcodeCache = language.hashCode() ^ country.hashCode() ^ variant.hashCode();
   }
 } // class Locale


[cp-patches] FYI: Minor JTree fix

2006-08-09 Thread Sven de Marothy
The default SelectionModel for JTree is DefaultTreeSelectionModel.

2006-08-09  Sven de Marothy  [EMAIL PROTECTED]

* javax/swing/JTree.java
(JTree): Default SelectionModel should be DefaultTreeSelectionModel.
(setSelectionModel): Null parameter should create an EmptySelectionM.


Index: javax/swing/JTree.java
===
RCS file: /sources/classpath/classpath/javax/swing/JTree.java,v
retrieving revision 1.71
diff -U3 -r1.71 JTree.java
--- javax/swing/JTree.java	1 Aug 2006 14:45:46 -	1.71
+++ javax/swing/JTree.java	9 Aug 2006 16:19:41 -
@@ -1509,8 +1509,7 @@
   public JTree(TreeModel model)
   {
 setRootVisible(true);
-setSelectionModel(new EmptySelectionModel());
-selectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
+setSelectionModel( new DefaultTreeSelectionModel() );
 
 // The root node appears expanded by default.
 nodeStates = new Hashtable();
@@ -2050,14 +2049,16 @@
 if (selectionModel == model)
   return;
 
+if( model == null )
+  model = EmptySelectionModel.sharedInstance();
+
 if (selectionModel != null)
   selectionModel.removeTreeSelectionListener(selectionRedirector);
 
 TreeSelectionModel oldValue = selectionModel;
 selectionModel = model;
 
-if (selectionModel != null)
-  selectionModel.addTreeSelectionListener(selectionRedirector);
+selectionModel.addTreeSelectionListener(selectionRedirector);
 
 firePropertyChange(SELECTION_MODEL_PROPERTY, oldValue, model);
 revalidate();


[cp-patches] FYI: Minor BufferedImage completion

2006-08-09 Thread Sven de Marothy
This doesn't make it alright. But it's a step.

2006-08-09  Sven de Marothy  [EMAIL PROTECTED]

* java/awt/image/BufferedImage.java
(BufferedImage): Reimplement predefined-type constructor.
(observers/tileObservers): Field renamed to tileObservers.
(createDefaultIndexedColorModel): New method.


Index: java/awt/image/BufferedImage.java
===
RCS file: /sources/classpath/classpath/java/awt/image/BufferedImage.java,v
retrieving revision 1.17
diff -U3 -r1.17 BufferedImage.java
--- java/awt/image/BufferedImage.java	11 Jul 2006 09:24:41 -	1.17
+++ java/awt/image/BufferedImage.java	9 Aug 2006 18:17:18 -
@@ -79,27 +79,37 @@
   TYPE_BYTE_BINARY= 12,
   TYPE_BYTE_INDEXED   = 13;
   
-  static final int[] bits3 = { 8, 8, 8 };
-  static final int[] bits4 = { 8, 8, 8, 8 };
-  static final int[] bits1byte = { 8 };
-  static final int[] bits1ushort = { 16 };
-  
-  static final int[] masks_int = { 0x00ff,
-   0xff00,
-   0x00ff,
-   DataBuffer.TYPE_INT };
-  static final int[] masks_565 = { 0xf800,
-   0x07e0,
-   0x001f,
-   DataBuffer.TYPE_USHORT};
-  static final int[] masks_555 = { 0x7c00,
-   0x03e0,
-   0x001f,
-   DataBuffer.TYPE_USHORT};
-
-  Vector observers;
+  /**
+   * Vector of TileObservers (or null)
+   */
+  Vector tileObservers;
   
   /**
+   * The image's WritableRaster
+   */
+  WritableRaster raster;
+
+  /**
+   * The associated ColorModel
+   */
+  ColorModel colorModel;
+
+  /**
+   * The image's properties (or null)
+   */
+  Hashtable properties;
+
+  /**
+   * Whether alpha is premultiplied
+   */
+  boolean isPremultiplied;
+
+  /**
+   * The predefined type, if any.
+   */
+  int type;
+
+  /**
* Creates a new codeBufferedImage/code with the specified width, height
* and type.  Valid codetype/code values are:
* 
@@ -130,126 +140,148 @@
*/
   public BufferedImage(int w, int h, int type)
   {
+SampleModel sm = null;
 ColorModel cm = null;
-
-boolean alpha = false;
-boolean premultiplied = false;
-switch (type)
-  {
-  case TYPE_4BYTE_ABGR_PRE:
-  case TYPE_INT_ARGB_PRE:
-	premultiplied = true;
-	// fall through
-  case TYPE_INT_ARGB:
-  case TYPE_4BYTE_ABGR:
-	alpha = true;
-  }
-	
-ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
-switch (type)
+boolean premultiplied = (type == BufferedImage.TYPE_INT_ARGB_PRE || 
+			 type == BufferedImage.TYPE_4BYTE_ABGR_PRE);
+
+switch( type )
   {
-  case TYPE_INT_RGB:
-  case TYPE_INT_ARGB:
-  case TYPE_INT_ARGB_PRE:
-  case TYPE_USHORT_565_RGB:
-  case TYPE_USHORT_555_RGB:
-	int[] masks = null;
-	switch (type)
-	  {
-	  case TYPE_INT_RGB:
-	  case TYPE_INT_ARGB:
-	  case TYPE_INT_ARGB_PRE:
-	masks = masks_int;
-	break;
-	  case TYPE_USHORT_565_RGB:
-	masks = masks_565;
-	break;
-	  case TYPE_USHORT_555_RGB:
-	masks = masks_555;
-	break;
-	  }
-	
-	cm = new DirectColorModel(cs,
-  32, // 32 bits in an int
-  masks[0], // r
-  masks[1], // g
-  masks[2], // b
-  alpha ? 0xff00 : 0,
-  premultiplied,
-  masks[3] // data type
-  );
+  case BufferedImage.TYPE_INT_RGB:
+	sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_INT, 
+	   width, height,
+	   new int[]{ 0x00FF, 
+			  0xFF00, 
+			  0x00FF } ) ;
+	cm = new DirectColorModel( 24, 0xff, 0xff00, 0xff );
 	break;
 	
-  case TYPE_INT_BGR:
-	String msg =
-	  FIXME: Programmer is confused. Why (and how) does a  +
-	  TYPE_INT_BGR image use ComponentColorModel to store  +
-	  8-bit values? Is data type TYPE_INT or TYPE_BYTE. What  +
-	  is the difference between TYPE_INT_BGR and TYPE_3BYTE_BGR?;
-	throw new UnsupportedOperationException(msg);
-	
-  case TYPE_3BYTE_BGR:
-  case TYPE_4BYTE_ABGR:
-  case TYPE_4BYTE_ABGR_PRE:
-  case TYPE_BYTE_GRAY:
-  case TYPE_USHORT_GRAY:
-	int[] bits = null;
-	int dataType = DataBuffer.TYPE_BYTE;
-	switch (type) {
-	case TYPE_3BYTE_BGR:
-	  bits = bits3;
-	  break;
-	case TYPE_4BYTE_ABGR:
-	case TYPE_4BYTE_ABGR_PRE:
-	  bits = bits4;
-	  break;
-case TYPE_BYTE_GRAY:
-  bits = bits1byte;
-  cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
-  break;
-case TYPE_USHORT_GRAY:
-  bits = bits1ushort;
-  cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
-  dataType = DataBuffer.TYPE_USHORT;
-  break;
-	}
-	cm = new ComponentColorModel(cs, bits, alpha, premultiplied,
- alpha ?
- Transparency.TRANSLUCENT:
- Transparency.OPAQUE,
- dataType);
+  case BufferedImage.TYPE_3BYTE_BGR:
+	sm = new PixelInterleavedSampleModel( DataBuffer.TYPE_BYTE,
+	  width, height,
+	  3, width * 3, 
+	  new int[]{ 2, 1, 0 } );
+	cm

[cp-patches] Re: FYI: Minor BufferedImage completion (Part 2)

2006-08-09 Thread Sven de Marothy
Whoops! Last patch was a dud. Here's the fix (commited)

On Wed, 2006-08-09 at 20:20 +0200, Sven de Marothy wrote:
 This doesn't make it alright. But it's a step.
 
 2006-08-09  Sven de Marothy  [EMAIL PROTECTED]
 
   * java/awt/image/BufferedImage.java
   (BufferedImage): Reimplement predefined-type constructor.
   (observers/tileObservers): Field renamed to tileObservers.
   (createDefaultIndexedColorModel): New method.
 

Index: java/awt/image/BufferedImage.java
===
RCS file: /sources/classpath/classpath/java/awt/image/BufferedImage.java,v
retrieving revision 1.18
diff -U3 -r1.18 BufferedImage.java
--- java/awt/image/BufferedImage.java	9 Aug 2006 18:21:14 -	1.18
+++ java/awt/image/BufferedImage.java	9 Aug 2006 18:30:22 -
@@ -138,7 +138,7 @@
* @throws IllegalArgumentException if codetype/code is not one of the
* specified values.
*/
-  public BufferedImage(int w, int h, int type)
+  public BufferedImage(int width, int height, int type)
   {
 SampleModel sm = null;
 ColorModel cm = null;


[cp-patches] Re: RFC: Change GtkToolkit threading

2006-08-08 Thread Sven de Marothy
Commited this.

On Thu, 2006-08-03 at 08:35 +0200, Sven de Marothy wrote:
 This should fix PR #16203, and also make for a general improvement.
 
 In short: The main GTK loop is not started statically in GtkToolkit,
 but rather on creating the first window peer. (as it should be).
 
 In long:
 On destroying the last window peer, we call gtk to end the main
 loop and the thread exits. If a new window is opened, we create
 a new thread object and restart the main gtk loop.
 
 I also moved all the stuff related to this (except native methods) 
 out from GtkToolkit and into a new GtkMainThread class. This should
 help reduce the clutter in the already ugly GtkToolkit class.
 
 It seems to work just fine for me, but being a rather central thing
 I'd like some feedback and testing before committing it.
 (Obviously not intended for the 0.92 release)
 
 /Sven
 
 2006-08-03  Sven de Marothy  [EMAIL PROTECTED]
 
 * gnu/java/awt/peer/gtk/GtkMainThread.java
 New file.
 * gnu/java/awt/peer/gtk/GtkChoicePeer.java
 * gnu/java/awt/peer/gtk/GtkComponentPeer.java
 Replace occurances of GtkToolkit.mainThread to GtkMainThread.mainThread.
 * gnu/java/awt/peer/gtk/GtkToolkit.java
 Minor style fixes; removed unused fields, 
 set fields to private where possible.
 (createDialog, createFrame, createWindow, createEmbeddedWindow): 
 Call GtkMainThread.createWindow().
 * gnu/java/awt/peer/gtk/GtkWindowPeer.java
 (dispose): New method.
 * include/gnu_java_awt_peer_gtk_GtkToolkit.h
 * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c
 (gtkQuit): New native method.





[cp-patches] FYI: Fix font locking

2006-08-06 Thread Sven de Marothy
Here's a commited fix (for the release) for the problem with assert
failures/segfaults while drawing text.

This fix is kind of temporary since I'm doing a big overhaul of all
the font peer code.

2006-08-06  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/CairoGraphics2D.java
(drawGlyphVector): Synchronize against font object when drawing.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c
(nativeDrawGlyphVector): Use pango locking when drawing.
(install_font_peer): Use pango locking when creating the cairo face.


Index: gnu/java/awt/peer/gtk/CairoGraphics2D.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java,v
retrieving revision 1.35
diff -U3 -r1.35 CairoGraphics2D.java
--- gnu/java/awt/peer/gtk/CairoGraphics2D.java	27 Jul 2006 20:59:42 -	1.35
+++ gnu/java/awt/peer/gtk/CairoGraphics2D.java	6 Aug 2006 20:58:04 -
@@ -1458,8 +1458,11 @@
 float[] positions = gv.getGlyphPositions (0, n, null);
 
 setFont (gv.getFont ());
-cairoDrawGlyphVector(nativePointer, (GdkFontPeer)getFont().getPeer(),
- x, y, n, codes, positions);
+	synchronized( this.font ) 
+	  { 
+	cairoDrawGlyphVector(nativePointer, (GdkFontPeer)getFont().getPeer(),
+ x, y, n, codes, positions);
+	  }
   }
 else
   {
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c
===
RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c,v
retrieving revision 1.13
diff -U3 -r1.13 gnu_java_awt_peer_gtk_CairoGraphics2D.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c	26 Jul 2006 22:12:21 -	1.13
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c	6 Aug 2006 20:58:04 -
@@ -315,7 +315,9 @@
   (*env)-ReleaseFloatArrayElements (env, java_positions, native_positions, 0);
   (*env)-ReleaseIntArrayElements (env, java_codes, native_codes, 0);
 
+  pango_fc_font_lock_face( (PangoFcFont *)pfont-font );
   cairo_show_glyphs (gr-cr, glyphs, n);
+  pango_fc_font_unlock_face( (PangoFcFont *)pfont-font );
 
   g_free(glyphs);
 }
@@ -761,18 +763,19 @@
 
   if (pfont-graphics_resource == NULL)
 {
-  face = pango_ft2_font_get_face (pfont-font);
+  face = pango_fc_font_lock_face( (PangoFcFont *)pfont-font );
   g_assert (face != NULL);
 
   ft = cairo_ft_font_face_create_for_ft_face (face, 0);
   g_assert (ft != NULL);
 
   cairo_set_font_face (cr, ft);
-  cairo_font_face_destroy (ft);
+  /*  cairo_font_face_destroy (ft);*/
   cairo_set_font_size (cr,
(pango_font_description_get_size (pfont-desc) /
 (double)PANGO_SCALE));
   ft = cairo_get_font_face (cr);
+  pango_fc_font_unlock_face( (PangoFcFont *)pfont-font );
   pfont-graphics_resource = ft;
 }
   else


Re: [cp-patches] RFC: Change GtkToolkit threading

2006-08-03 Thread Sven de Marothy
On Thu, 2006-08-03 at 13:10 -0400, Thomas Fitzsimmons wrote:

 the three exit conditions are:
 
  * There are no displayable AWT or Swing components.
  * There are no native events in the native event queue.
  * There are no AWT events in java EventQueues.
 
 The first two conditions are satisfied by quitting the GTK main thread (no 
 native events) when there are no windows left (no displayable AWT or Swing 
 components).  I'm wondering if we need a check for the third condition before 
 quitting the GTK main loop.

Right, 1) is what I just implemented. As for 2), calling gtk_main_quit()
doesn't quit immediately but rather Makes the innermost invocation of
the main loop return when it regains control. as the GTK docs say. 
So I'm 95% sure that's to be interpreted as the native queue being empty
at that point.

Condition 3) Is also fulfilled. The EventDispatchThread shuts itself
down as it should, and I'm certain we don't need to check with the GTK
thread. The way I read it, the first two points relate only to the main
GTK thread, and the third point only to the EventDispatchThread. 

So basically when 1) and 2) are satisfied we can shut down the GTK
thread (since the peers are disposed of at that point, the EventQueue
can't call into them and cause new native events). There's no apparent 
reason why we'd need or want to shut them all down at the same time.

Once the GTK thread is shut down the EventQueue empties itself and then
shuts down. It seems to work just fine. I'm attaching a little testcase
that creates and destroys some windows and prints the number of active
threads. As expected we have two; the main GTK thread and the
EventDispatchThread.

Interestingly, the testcase shows that the 1.4 JDK revs up 6 (!)
threads by then. (But 'only' 4 on the 1.5 JDK). I dunno what it's
doing with all those extra threads. Running a botnet? :)

/Sven
import java.awt.*;

public class ThreadTest
{
  public static void main(String[] args)
  {
System.out.println(Thread initially active:+Thread.activeCount());
Frame f = new Frame();
f.setSize(100,100);
f.setVisible(true);
System.out.println(Active after opening window:+Thread.activeCount());
long t = System.currentTimeMillis();
System.out.println(Delaying 5s);
while( (System.currentTimeMillis() - t)  5000 )
  Thread.yield();
System.out.println(Active now:+Thread.activeCount());
System.out.println(Disposing peers.);
f.dispose();
f = null;
t = System.currentTimeMillis();
System.out.println(Active now::+Thread.activeCount());
System.out.println(Waiting 5 s);
while( (System.currentTimeMillis() - t)  5000 )
  Thread.yield();
f = new Frame();
f.setSize(100,100);
System.out.println(Recreating peers.);
f.setVisible(true);
System.out.println(# of active threads now:+Thread.activeCount());
System.out.println(End.);
  }
}


[cp-patches] Re: BigDecimal mauve regressions (FYI: patch)

2006-07-29 Thread Sven de Marothy
On Sat, 2006-07-29 at 16:54 +0200, Mark Wielaard wrote:

 Did you also happen to look at the DiagBigDecimal test? It passed with
 0.91, but current CVS (with or without you patch) gives the following
 failures:
..[snip list of 22 failures]..

Yes. I didn't investigate those further because the 1.5 JRE fails
the same set of tests (+4 more). The 1.4 JRE fails only 3 of them.

So these tests need a bit of looking into, but I'm pretty sure
that like the construct() failure, it's due to the change in toString()
behaviour, and not any real bugs.

/Sven




[cp-patches] BigDecimal mauve regressions (FYI: patch)

2006-07-28 Thread Sven de Marothy
I commited this:

2006-07-27  Sven de Marothy  

* java/math/BigDecimal.java
Adjust copyright date.
(divide(BigDecimal): Implement.
(precision): Reimplement.
(numDigitsInBigInteger, numDigitsInLong): Removed.
(toString): Get exponent from string length, 
fix negative values with exponential form.
(toEngineeringString): Same as for toString. 
(setScale): Throw ArithmeticException if scale  0.

This fixes all the BigDecimal regressions, with
the exception of one in BigDecimal.construct,
which isn't a regression, just that the string
representation returned from toString() changed
in this case from 1000 to 1E+3, which is also
what the 1.5 JRE returns (but not 1.4). Either
value is still allowed by the spec, so it's more
a case of a too rigid test.

We need a lot more tests for this, in particular for
the new 1.5 methods.

The setScale() regression may not be one, as the 1.5 JRE no longer
throws ArithmeticException with a negative scale here, despite
the 1.5 docs still saying that it does. (1.4 and earlier do
throw the exception). I'm thinking this is a Sun regression in
1.5. But if it's still around in 1.6. we should probably change.

/Sven

Index: java/math/BigDecimal.java
===
RCS file: /sources/classpath/classpath/java/math/BigDecimal.java,v
retrieving revision 1.23
diff -U3 -r1.23 BigDecimal.java
--- java/math/BigDecimal.java	7 Jun 2006 19:01:07 -	1.23
+++ java/math/BigDecimal.java	28 Jul 2006 08:28:35 -
@@ -1,5 +1,5 @@
 /* java.math.BigDecimal -- Arbitrary precision decimals.
-   Copyright (C) 1999, 2000, 2001, 2003, 2005 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2000, 2001, 2003, 2005, 2006 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -266,8 +266,10 @@
 long mantissa = bits  mantMask;
 long exponent = (bits  mantissaBits)  expMask;
 boolean denormal = exponent == 0;
+
 // Correct the exponent for the bias.
 exponent -= denormal ? 1022 : 1023;
+
 // Now correct the exponent to account for the bits to the right
 // of the decimal.
 exponent -= mantissaBits;
@@ -748,6 +750,19 @@
   }
   
   /**
+   * Performs division, if the resulting quotient requires rounding
+   * (has a nonterminating decimal expansion), 
+   * an ArithmeticException is thrown. 
+   * #see divide(BigDecimal, int, int)
+   * @since 1.5
+   */
+  public BigDecimal divide(BigDecimal divisor)
+throws ArithmeticException, IllegalArgumentException 
+  {
+return divide(divisor, scale, ROUND_UNNECESSARY);
+  }
+
+  /**
* Returns a BigDecimal whose value is the remainder in the quotient
* this / val.  This is obtained by 
* subtract(divideToIntegralValue(val).multiply(val)).  
@@ -760,7 +775,7 @@
   {
 return subtract(divideToIntegralValue(val).multiply(val));
   }
-  
+
   /**
* Returns a BigDecimal array, the first element of which is the integer part
* of this / val, and the second element of which is the remainder of 
@@ -994,84 +1009,13 @@
   {
 if (precision == 0)
   {
-if (intVal.compareTo(BigInteger.TEN.pow(18)) == 1)
-  precision = numDigitsInBigInteger(intVal);
-else
-  precision = numDigitsInLong(intVal.longValue());
-  }
+	String s = intVal.toString();
+	precision = s.length() - (( s.charAt(0) == '-' ) ? 1 : 0);
+  }
 return precision;
   }
   
   /**
-   * This method is used to determine the precision of BigIntegers with 19 or
-   * more digits.
-   * @param b the BigInteger
-   * @return the number of digits in codeb/code
-   */
-  int numDigitsInBigInteger(BigInteger b)
-  {
-int i = 19;
-BigInteger comp = BigInteger.TEN.pow(i);
-while (b.compareTo(comp) = 0)  
-  comp = BigInteger.TEN.pow(++i);
-  
-return i;
-  }
-
-  /**
-   * This method determines the number of digits in the long value l. 
-   * @param l1 the long value
-   * @return the number of digits in l
-   */
-  private static int numDigitsInLong(long l1)
-  {
-long l = l1 = 0 ? l1 : -l1; 
-// We divide up the range in a binary fashion, this first if
-// takes care of numbers with 1 to 9 digits.
-if (l  10L)
-{
-  // This if is for numbers with 1 to 5 digits.
-  if (l  10L)
-{
-  if (l  100L)
-return (l  10L) ? 1 : 2;
-  if (l  1L)
-return (l  1000L) ? 3 : 4;
-  return 5;
-}
-  // Here we handle numbers with 6 to 9 digits.
-  if (l  1000L)
-return (l  100L) ? 6 : 7;
-  return (l  1L) ? 8 : 9;
-}
-// If we are at this point that means we didn't enter the loop for
-// numbers with 1 to 9 digits, so our number has 10 to 19 digits. 
-// This first if handles numbers with 10 to 14 digits.
-if (l  100L)
-  {
-// This handles numbers with 10 to 12 digits.
-if (l  1L)
-  {
-if (l

[cp-patches] FYI: Fix nanotime

2006-07-26 Thread Sven de Marothy
Fixes nanotime and also implements currentTimeMillis on top of it 
instead of vice-versa. The ref impl therefore now returns with
microsecond precision.

2006-07-26  Sven de Marothy  [EMAIL PROTECTED]

* include/java_lang_VMSystem.h
* vm/reference/java/lang/VMSystem.java
* native/jni/java-lang/java_lang_VMSystem.c
(nanoTime, currentTimeMillis): Switch the former to native code and
the latter to java.


Index: include/java_lang_VMSystem.h
===
RCS file: /sources/classpath/classpath/include/java_lang_VMSystem.h,v
retrieving revision 1.8
diff -U3 -r1.8 java_lang_VMSystem.h
--- include/java_lang_VMSystem.h	3 May 2006 20:22:55 -	1.8
+++ include/java_lang_VMSystem.h	26 Jul 2006 19:36:33 -
@@ -15,7 +15,7 @@
 JNIEXPORT void JNICALL Java_java_lang_VMSystem_setIn (JNIEnv *env, jclass, jobject);
 JNIEXPORT void JNICALL Java_java_lang_VMSystem_setOut (JNIEnv *env, jclass, jobject);
 JNIEXPORT void JNICALL Java_java_lang_VMSystem_setErr (JNIEnv *env, jclass, jobject);
-JNIEXPORT jlong JNICALL Java_java_lang_VMSystem_currentTimeMillis (JNIEnv *env, jclass);
+JNIEXPORT jlong JNICALL Java_java_lang_VMSystem_nanoTime (JNIEnv *env, jclass);
 JNIEXPORT jobject JNICALL Java_java_lang_VMSystem_environ (JNIEnv *env, jclass);
 JNIEXPORT jstring JNICALL Java_java_lang_VMSystem_getenv (JNIEnv *env, jclass, jstring);
 
Index: native/jni/java-lang/java_lang_VMSystem.c
===
RCS file: /sources/classpath/classpath/native/jni/java-lang/java_lang_VMSystem.c,v
retrieving revision 1.14
diff -U3 -r1.14 java_lang_VMSystem.c
--- native/jni/java-lang/java_lang_VMSystem.c	22 Apr 2006 21:52:18 -	1.14
+++ native/jni/java-lang/java_lang_VMSystem.c	26 Jul 2006 19:36:34 -
@@ -113,11 +113,11 @@
 
 /*
  * Class: java_lang_VMSystem
- * Method:currentTimeMillis
+ * Method:nanoTime
  * Signature: ()J
  */
 JNIEXPORT jlong JNICALL
-Java_java_lang_VMSystem_currentTimeMillis
+Java_java_lang_VMSystem_nanoTime
   (JNIEnv * env __attribute__ ((__unused__)),
jclass thisClass __attribute__ ((__unused__)))
 {
@@ -129,8 +129,9 @@
 (*env)-FatalError (env, gettimeofday call failed.);
 
   result = (jlong) tp.tv_sec;
-  result *= 1000;
-  result += (tp.tv_usec / 1000);
+  result *= (jlong)100L;
+  result += (jlong)tp.tv_usec;
+  result *= (jlong)1000;
 
   return result;
 }
Index: vm/reference/java/lang/VMSystem.java
===
RCS file: /sources/classpath/classpath/vm/reference/java/lang/VMSystem.java,v
retrieving revision 1.16
diff -U3 -r1.16 VMSystem.java
--- vm/reference/java/lang/VMSystem.java	22 Apr 2006 21:52:18 -	1.16
+++ vm/reference/java/lang/VMSystem.java	26 Jul 2006 19:36:35 -
@@ -135,7 +135,10 @@
* @return the current time
* @see java.util.Date
*/
-   public static native long currentTimeMillis();
+   public static long currentTimeMillis()
+   {
+ return nanoTime() / 100L;
+   }
 
   /**
* p
@@ -162,10 +165,7 @@
* @return the time of a system timer in nanoseconds.
* @since 1.5 
*/
-   public static long nanoTime()
-   {
- return currentTimeMillis() * 1000;
-   }
+  public static native long nanoTime();
 
   /**
* Returns a list of 'name=value' pairs representing the current environment


[cp-patches] FYI: GeneralPath doc fix.

2006-07-26 Thread Sven de Marothy
2006-07-26  Sven de Marothy  [EMAIL PROTECTED]

* java/awt/geom/GeneralPath.java: Fix severe typo.


Index: java/awt/geom/GeneralPath.java
===
RCS file: /sources/classpath/classpath/java/awt/geom/GeneralPath.java,v
retrieving revision 1.16
diff -U3 -r1.16 GeneralPath.java
--- java/awt/geom/GeneralPath.java	15 Jun 2006 18:18:51 -	1.16
+++ java/awt/geom/GeneralPath.java	26 Jul 2006 20:27:59 -
@@ -65,8 +65,8 @@
  * #x2019;up#x2019;
  * direction, one in the #x2019;down#x2019; direction) Point bB/b in 
  * the image is inside (one intersection #x2019;down#x2019;)
- * Point bC/b in the image is outside (two intersections 
- * #x2019;down#x2019;)
+ * Point bC/b in the image is inside (two intersections in the 
+ * #x2019;down#x2019; direction)
  *
  * @see Line2D
  * @see CubicCurve2D


[cp-patches] FYI: Minor Font, GtkVolatileImage stuff

2006-07-25 Thread Sven de Marothy
Just some random minor fixes from my tree.

2006-07-25  Sven de Marothy  [EMAIL PROTECTED]

* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c
(init): Default to the actual depth in the worst case.

* java/awt/Font.java
(createFont(int, File)): New method.


Index: java/awt/Font.java
===
RCS file: /sources/classpath/classpath/java/awt/Font.java,v
retrieving revision 1.36
diff -U3 -r1.36 Font.java
--- java/awt/Font.java	16 Jun 2006 16:10:22 -	1.36
+++ java/awt/Font.java	25 Jul 2006 17:51:21 -
@@ -48,6 +48,8 @@
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
 import java.awt.peer.FontPeer;
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.ObjectInputStream;
@@ -583,6 +585,34 @@
   }
 
   /**
+   * Creates a new font from a File object.
+   *
+   * @see #layoutGlyphVector(FontRenderContext, char[], int, int, int)
+   *
+   * @param fontFormat - Integer code indicating the format the font data is
+   * in.Currently this can only be [EMAIL PROTECTED] #TRUETYPE_FONT}.
+   * @param file - a [EMAIL PROTECTED] File} from which font data will be read.
+   *
+   * @return A new [EMAIL PROTECTED] Font} of the format indicated.
+   *
+   * @throws IllegalArgumentException if codefontType/code is not
+   * recognized.
+   * @throws NullPointerException if codefile/code is codenull/code.
+   * @throws FontFormatException if data in the file is invalid or cannot be read..
+   * @throws SecurityException if the caller has no read permission for the file.
+   * @throws IOException if the file cannot be read
+   *
+   * @since 1.5
+   */
+  public static Font createFont (int fontFormat, File file)
+throws FontFormatException, IOException
+  {
+if( file == null )
+  throw new NullPointerException(Null file argument);
+return tk().createFont(fontFormat, new FileInputStream( file ));
+  }
+
+  /**
* Maps characters to glyphs in a one-to-one relationship, returning a new
* [EMAIL PROTECTED] GlyphVector} with a mapped glyph for each input character. This
* sort of mapping is often sufficient for some scripts such as Roman, but
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c
===
RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c,v
retrieving revision 1.5
diff -U3 -r1.5 gnu_java_awt_peer_gtk_GtkVolatileImage.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c	10 Jun 2006 14:16:09 -	1.5
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c	25 Jul 2006 17:51:23 -
@@ -73,7 +73,8 @@
   pixmap = gdk_pixmap_new( widget-window, width, height, -1 );
 }
   else
-pixmap = gdk_pixmap_new( NULL, width, height, 16 );
+pixmap = gdk_pixmap_new( NULL, width, height, 
+			 gdk_rgb_get_visual()-depth );
 
   gdk_threads_leave();
 


Re: [cp-patches] RFC: java.awt.color.ICC_Profile missing constants added

2006-07-20 Thread Sven de Marothy
On Wed, 2006-07-19 at 19:38 +0200, Carsten Neumann wrote:
   Hi,
 
 this adds the missing fields pointed out by JAPI (classpath vs. jdk-1.5).
 
 Please comment/commit.
 

Yeah, please don't. :) These new fields are for ICC v4.0.0 profiles,
which our CMS doesn't support yet, so adding them wouldn't actually
update the class to 1.5. However, (somewhat coincidentally) I just got
started working on the ICC v4 support. So it'll be fixed soon enough.

/Sven




Re: [cp-patches] FYI: Inet6Address updated to 1.5

2006-07-19 Thread Sven de Marothy
On Tue, 2006-07-18 at 09:53 -0600, Tom Tromey wrote:
  Sven == Sven de Marothy [EMAIL PROTECTED] writes:
 
 Sven + * @status Updated to 1.5. Serialization compatibility is tested.
 
 According to JAPI it looks as though we're still missing a couple
 methods: getScopeId and getScopedInterface.

Ah right. :) I'd implemented this and accidentally deleted it and had to
do it all again. I must've forgotten them the second time around. 

No problem, it's a trivial fix.

/Sven




Re: [cp-patches] FYI: Inet6Address updated to 1.5 (patch)

2006-07-19 Thread Sven de Marothy
Here are the two remaining methods.

2006-07-19  Sven de Marothy  [EMAIL PROTECTED]

* java/net/Inet6Address.java:
(getScopedId, getScopedInterface): New methods.

On Wed, 2006-07-19 at 15:40 +0200, Sven de Marothy wrote:
 On Tue, 2006-07-18 at 09:53 -0600, Tom Tromey wrote:
   Sven == Sven de Marothy [EMAIL PROTECTED] writes:
  
  Sven + * @status Updated to 1.5. Serialization compatibility is tested.
  
  According to JAPI it looks as though we're still missing a couple
  methods: getScopeId and getScopedInterface.
 
 Ah right. :) I'd implemented this and accidentally deleted it and had to
 do it all again. I must've forgotten them the second time around. 
 
 No problem, it's a trivial fix.
 
 /Sven
 
 
-- 
Sven de Marothy [EMAIL PROTECTED]
Index: java/net/Inet6Address.java
===
RCS file: /sources/classpath/classpath/java/net/Inet6Address.java,v
retrieving revision 1.12
diff -U3 -r1.12 Inet6Address.java
--- java/net/Inet6Address.java	18 Jul 2006 02:58:14 -	1.12
+++ java/net/Inet6Address.java	19 Jul 2006 16:19:44 -
@@ -242,6 +242,7 @@
* Creates a scoped Inet6Address where the scope has an integer id.
*
* @throws UnkownHostException if the address is an invalid number of bytes.
+   * @since 1.5
*/  
   public static Inet6Address getByAddress(String host, byte[] addr, 
 	  int scopeId)
@@ -261,6 +262,7 @@
* NetworkInterface.
*
* @throws UnkownHostException if the address is an invalid number of bytes.
+   * @since 1.5
*/  
   public static Inet6Address getByAddress(String host, byte[] addr, 
 	  NetworkInterface nif)
@@ -276,6 +278,36 @@
   }
 
   /**
+   * Returns the codeNetworkInterface/code of the address scope
+   * if it is a scoped address and the scope is given in the form of a
+   * NetworkInterface. 
+   * (I.e. the address was created using  the 
+   * getByAddress(String, byte[], NetworkInterface) method)
+   * Otherwise this method returns codenull/code.
+   * @since 1.5
+   */
+  public NetworkInterface getScopedInterface()
+  {
+return nif;
+  }
+
+  /**
+   * Returns the scope ID of the address scope if it is a scoped adress using
+   * an integer to identify the scope.
+   *
+   * Otherwise this method returns 0.
+   * @since 1.5
+   */
+  public int getScopeId()
+  {
+// check scope_id_set because some JDK-serialized objects seem to have
+// scope_id set to a nonzero value even when scope_id_set == false
+if( scope_id_set )
+  return scope_id; 
+return 0;
+  }
+
+  /**
* Returns the IP address string in textual presentation
*/
   public String getHostAddress()


Re: [cp-patches] FYI: Using the custom DTD for the Swing HTML parser.

2006-07-17 Thread Sven de Marothy
This patch breaks the build. For me, at least. I tried from a fresh tree
and that didn't work. It did compile minus this patch.

/Sven

On Sun, 2006-07-16 at 16:54 +0200, Audrius Meskauskas wrote:
 Fixing the 28392, I have concluded that HTMLEditorKit is getting more 
 and more unnecessarily complicated functionality, and that the 
 suggestions of Roman and others (discussed in Brussels) to have the 
 custom DTD model for our Swing are probably correct. This patch 
 introduces the HTML_401Swing.java which is derived from HTML_401F.java 
 and allows us to define additional rules exclusively for the parser of 
 the HTMLDocument. It will not affect any applications that use the 
 parser directly, creating the instance of the ParserDelegator.
 
 The custom DTD model generates the implied P tags for the top level 
 document body text that is not in a paragraph. It also generates P tags 
 for the top level tags like I, B, U, A, FONT and so on, because, if not 
 wrapped into paragraph at the top body level, they cause the same 
 problems. The tags are not generated when they are not necessary and are 
 closed where they end is supposed from the context. The DTD model can be 
 extended to work about more our HTML rendering problems.
 
 The implied paragraph handling in HTMLDocument is no longer needed as is 
 removed.
 
 2006-07-16  Audrius Meskauskas  [EMAIL PROTECTED]
 
   PR 28392
 * examples/gnu/classpath/examples/swing/HtmlDemo.java:
 Removed heading p tag from the parsing example.
 * gnu/javax/swing/text/html/parser/HTML_401F.java:
 (createHtmlContentModel): Explained.
 (defineElements): Call getBodyElements to get the body
 elements. (getBodyElements): New method. (model):
 Made protected from private.
 * gnu/javax/swing/text/html/parser/htmlValidator.java
 (openTag): Mind that current content model may be null.
 (tagIsValidForContext): If the tag is PCDATA, and it is not
 valid for context, but the paragraph (P) is valid for context,
 suggest to insert the P tag here.
 * javax/swing/text/html/HTMLDocument.java (HTMLReader.addContent,
 HTMLReader.blockOpen, HTMLReader.blockClose): Do not handle
 implied P tags here.
 * javax/swing/text/html/HTMLEditorKit.java (getParser):
 Get the custom parser, using  DTD.
 * javax/swing/text/html/parser/ParserDelegator.java:
 Removed the obsolete note that HTMLEditorKit does not exist.
 * gnu/javax/swing/text/html/parser/GnuParserDelegator.java,
 gnu/javax/swing/text/html/parser/HTML_401Swing.java: New files.
-- 
Sven de Marothy [EMAIL PROTECTED]




Re: [cp-patches] FYI: Using the custom DTD for the Swing HTML parser.

2006-07-17 Thread Sven de Marothy
Oh I forgot, this is with the options I usually use:
--with-jikes --disable-plugin 

/Sven

On Mon, 2006-07-17 at 12:59 +0200, Sven de Marothy wrote:
 This patch breaks the build. For me, at least. I tried from a fresh tree
 and that didn't work. It did compile minus this patch.
 
 /Sven





[cp-patches] FYI: Inet6Address updated to 1.5

2006-07-17 Thread Sven de Marothy

2006-07-18  Sven de Marothy  [EMAIL PROTECTED]

* java/net/Inet6Address.java:
Add 1.5 serialized fields.
(getByAddress): New methods.
(readObject, writeObject): New methods. 
(equals): Reimplement.


Index: java/net/Inet6Address.java
===
RCS file: /sources/classpath/classpath/java/net/Inet6Address.java,v
retrieving revision 1.11
diff -U3 -r1.11 Inet6Address.java
--- java/net/Inet6Address.java	2 Jul 2005 20:32:39 -	1.11
+++ java/net/Inet6Address.java	18 Jul 2006 02:55:16 -
@@ -39,13 +39,16 @@
 package java.net;
 
 import java.util.Arrays;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.IOException;
 
 /*
  * Written using on-line Java Platform 1.4 API Specification and
  * RFC 1884 (http://www.ietf.org/rfc/rfc1884.txt)
  * 
  * @author Michael Koch
- * @status Believed complete and correct.
+ * @status Updated to 1.5. Serialization compatibility is tested.
  */
 public final class Inet6Address extends InetAddress
 {
@@ -57,6 +60,39 @@
   byte[] ipaddress;
 
   /**
+   * The scope ID, if any. 
+   * @since 1.5
+   * @serial 
+   */
+  private int scope_id;
+
+  /**
+   * The scope ID, if any. 
+   * @since 1.5
+   * @serial 
+   */
+  private boolean scope_id_set;
+
+  /**
+   * Whether ifname is set or not.
+   * @since 1.5
+   * @serial 
+   */
+  private boolean scope_ifname_set;
+
+  /**
+   * Name of the network interface, used only by the serialization methods
+   * @since 1.5
+   * @serial 
+   */
+  private String ifname;
+
+  /**
+   * Scope network interface, or codenull/code.
+   */
+  private transient NetworkInterface nif; 
+
+  /**
* Create an Inet6Address object
*
* @param addr The IP address
@@ -67,6 +103,10 @@
 super(addr, host);
 // Super constructor clones the addr.  Get a reference to the clone.
 this.ipaddress = this.addr;
+ifname = null;
+scope_ifname_set = scope_id_set = false;
+scope_id = 0;
+nif = null;
   }
 
   /**
@@ -199,6 +239,43 @@
   }
 
   /**
+   * Creates a scoped Inet6Address where the scope has an integer id.
+   *
+   * @throws UnkownHostException if the address is an invalid number of bytes.
+   */  
+  public static Inet6Address getByAddress(String host, byte[] addr, 
+	  int scopeId)
+throws UnknownHostException
+  {
+if( addr.length != 16 )
+  throw new UnknownHostException(Illegal address length:  + addr.length
+ +  bytes.);
+Inet6Address ip = new Inet6Address( addr, host );
+ip.scope_id = scopeId;
+ip.scope_id_set = true;
+return ip;
+  }
+
+  /**
+   * Creates a scoped Inet6Address where the scope is a given
+   * NetworkInterface.
+   *
+   * @throws UnkownHostException if the address is an invalid number of bytes.
+   */  
+  public static Inet6Address getByAddress(String host, byte[] addr, 
+	  NetworkInterface nif)
+throws UnknownHostException
+  {
+if( addr.length != 16 )
+  throw new UnknownHostException(Illegal address length:  + addr.length
+ +  bytes.);
+Inet6Address ip = new Inet6Address( addr, host );
+ip.nif = nif;
+
+return ip;
+  }
+
+  /**
* Returns the IP address string in textual presentation
*/
   public String getHostAddress()
@@ -214,12 +291,17 @@
 
 	sbuf.append(Integer.toHexString(x));
   }
+if( nif != null )
+  sbuf.append( % + nif.getName() );
+else if( scope_id_set )
+  sbuf.append( % + scope_id );
 
 return sbuf.toString();
   }
 
   /**
* Returns a hashcode for this IP address
+   * (The hashcode is independent of scope)
*/
   public int hashCode()
   {
@@ -234,10 +316,23 @@
 if (! (obj instanceof Inet6Address))
   return false;
 
-// this.ipaddress is never set in this class except to
-// the value of the super class' addr.  The super classes
-// equals(Object) will do the compare.
-return super.equals(obj);
+Inet6Address ip = (Inet6Address)obj;
+if (ipaddress.length != ip.ipaddress.length)
+  return false;
+
+for (int i = 0; i  ip.ipaddress.length; i++)
+  if (ipaddress[i] != ip.ipaddress[i])
+	return false;
+
+if( ip.nif != null  nif != null )
+  return nif.equals( ip.nif );
+if( ip.nif != nif )
+  return false;
+if( ip.scope_id_set != scope_id_set )
+  return false;
+if( scope_id_set )
+  return (scope_id == ip.scope_id);
+return true;
   }
 
   /**
@@ -258,4 +353,38 @@
 
 return true;
   }
+
+  /**
+   * Required for 1.5-compatible serialization.
+   * @since 1.5
+   */
+  private void readObject(ObjectInputStream s)
+throws IOException, ClassNotFoundException
+  {  
+s.defaultReadObject();
+try
+  {
+	if( scope_ifname_set )
+	  nif = NetworkInterface.getByName( ifname );
+  }
+catch( SocketException se )
+  {
+	// FIXME: Ignore this? or throw an IOException?
+  }
+  }
+
+  /**
+   * Required for 1.5-compatible

Re: [cp-patches] FYI: Some AWT 1.5 stuff

2006-07-15 Thread Sven de Marothy
Whoops, forgot to attach the new files. Here they are.

On Sat, 2006-07-15 at 09:56 +0200, Sven de Marothy wrote:
 This implements some of the new 1.5 stuff for AWT.
 - changes to Image (accelerationPriority)
 - always-on-top Window (and GTK peer support)
 - MouseInfo and PointerInfo classes and the necessary
 peers and Toolkit changes.
 - GTK implementation of MouseInfoPeer.
 
 (Note that the getMouseInfoPeer method is not abstract
 in Toolkit and is allowed to throw UnsupportedOpException,
 so I made that the default. Toolkit implementations should
 obviously overload this if possible. That means you, Roman ;))
 
 /Sven
 
 2006-07-15  Sven de Marothy  [EMAIL PROTECTED]
 
   * gnu/java/awt/peer/gtk/GtkMouseInfoPeer.java,
   * java/awt/MouseInfo.java,
   * java/awt/PointerInfo.java,
   * java/awt/peer/MouseInfoPeer.java:
   New files.
 
   * java/awt/Image.java
   (accelerationPriority): New field.
   (setAccelerationPriority, getAccelerationPriority): New methods..
 
   * include/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.h,
   * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c,
   * gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java:
   (getMouseCoordinates): New method.
 
   * gnu/java/awt/peer/gtk/GtkFramePeer.java
   (updateAlwaysOnTop): Remove stub overload.
 
   * gnu/java/awt/ClasspathToolkit.java,
   * gnu/java/awt/peer/gtk/GtkToolkit.java,
   * include/gnu_java_awt_peer_gtk_GtkToolkit.h,
   * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c:
   (getMouseInfoPeer): New method.
   (getMouseNumberOfButtons): New method.
   
   * gnu/java/awt/peer/gtk/GtkWindowPeer.java
   * include/gnu_java_awt_peer_gtk_GtkWindowPeer.h
   * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c
   (gtkWindowSetAlwaysOnTop): New method.
   (updateAlwaysOnTop): Implement.
 
   * java/awt/Toolkit.java,
   (getMouseInfoPeer): New method.
 
   * java/awt/Window.java
   (alwaysOnTop): New field.
   (isAlwaysOnTop, setAlwaysOnTop): New methods.
 
   * java/awt/peer/WindowPeer.java: Doc fix.
 
 
-- 
Sven de Marothy [EMAIL PROTECTED]
/* GtkToolkit.java -- Implements an AWT Toolkit using GTK for peers
   Copyright (C) 2006
   Free Software Foundation, Inc.

This file is part of GNU Classpath.

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */

package gnu.java.awt.peer.gtk;

import java.awt.Point;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Window;
import java.awt.peer.MouseInfoPeer;

/**
 * The MouseInfoPeer is so small, I'm including it here.
 */
public class GtkMouseInfoPeer implements MouseInfoPeer
{
  private static GdkGraphicsEnvironment gde = new GdkGraphicsEnvironment();
  
  public int fillPointWithCoords(Point p)
  {
int[] coords = gde.getMouseCoordinates();
  p.x = coords[1]; 
  p.y = coords[2];
  return coords[0];
  }
  
  public boolean isWindowUnderMouse(Window w)
  {
int[] coords = gde.getMouseCoordinates();
GraphicsDevice[] gds = gde.getScreenDevices();

// Check if the screen  of the Window and the cursor match
if( gds[ coords[0] ] != w.getGraphicsConfiguration().getDevice() )
  return false;

// Return the bounds-check.
Point p = w.getLocationOnScreen();
return (coords[1] = p.x  coords[1]  p.x + w.getWidth() 
	coords[2] = p.y

Re: [cp-patches] [RFA] JVMTI (ATTN:contains offer for free beer)

2006-07-15 Thread Sven de Marothy
On Sat, 2006-07-15 at 10:26 -0700, Keith Seitz wrote:
 With no further comments, I have committed this patch.
 
 Thank you for taking a look at it, Tom!
 
 Keith

Yay! Great job Keith!

First VM to implement JVMTI now gets a beer from me!

/Sven




[cp-patches] FYI: Databuffer fixlet

2006-07-14 Thread Sven de Marothy
2006-07-14  Sven de Marothy  [EMAIL PROTECTED]

* java/awt/image/DataBuffer.java
(DataBuffer): Call constructors in the correct order,


Index: java/awt/image/DataBuffer.java
===
RCS file: /sources/classpath/classpath/java/awt/image/DataBuffer.java,v
retrieving revision 1.6
diff -U3 -r1.6 DataBuffer.java
--- java/awt/image/DataBuffer.java	2 Jul 2005 20:32:30 -	1.6
+++ java/awt/image/DataBuffer.java	14 Jul 2006 22:40:23 -
@@ -114,8 +114,7 @@
*/
   protected DataBuffer(int dataType, int size)
   {
-this.dataType = dataType;
-this.size = size;
+this(dataType, size, 1);
   }
 
   /**
@@ -132,9 +131,7 @@
* @param numBanks the number of data banks.
*/
   protected DataBuffer(int dataType, int size, int numBanks) {
-this(dataType, size);
-banks = numBanks;
-offsets = new int[numBanks];
+this(dataType, size, numBanks, 0);
   }
 
   /**
@@ -153,11 +150,14 @@
* @param offset the offset to the first element for all banks.
*/
   protected DataBuffer(int dataType, int size, int numBanks, int offset) {
-this(dataType, size, numBanks);
-
-java.util.Arrays.fill(offsets, offset);  
-
+banks = numBanks;
+this.dataType = dataType;
+this.size = size;
 this.offset = offset;
+
+offsets = new int[ numBanks ];
+for(int i = 0; i  numBanks; i++ )
+  offsets[i] = offset;
   }
 
   /**
@@ -179,10 +179,11 @@
* codenumBanks != offsets.length/code.
*/
   protected DataBuffer(int dataType, int size, int numBanks, int[] offsets) {
-this(dataType, size);
 if (numBanks != offsets.length) 
   throw new ArrayIndexOutOfBoundsException();
-
+
+this.dataType = dataType;
+this.size = size;
 banks = numBanks;
 this.offsets = offsets;
 


[cp-patches] RFC: Some JFileChooser fixes

2006-07-14 Thread Sven de Marothy
This fixes some bugs:
-Default mode is FILES_ONLY.
-FILES_ONLY mode doesn't mean show only files it means allow only
files to be selected. 
-Hitting enter or return doesn't cancel renaming of files.
-File-name textbox is not set to directory names when in FILES_ONLY,
(but you can still traverse them, requiring a new field for the selected
directory)

And completes BasicDirectoryModel, which I think is all right now.

Some remaining bugs:
- Changing to list view and back screws things up (the table header is
still there, for instance)
- Scrolling size is wrong.
- Sometimes you can select empty entries.

Let me know if there are any regressions.

/Sven

2006-07-14  Sven de Marothy  [EMAIL PROTECTED]

* javax/swing/JFileChooser.java
Change default selection mode to FILES_ONLY.
* javax/swing/plaf/basic/BasicDirectoryModel.java
Document, fix selection mode filtering.
(renameFile): Implement
* javax/swing/plaf/basic/BasicFileChooserUI.java
(selectedDir): New field to handle selected directories,
disallow selecting of directories in FILES_ONLY mode.
* javax/swing/plaf/metal/MetalFileChooserUI.java:
(EditingActionListener.actionPerformed):
Stop editing on all actions (e.g. return-key press)


Index: javax/swing/JFileChooser.java
===
RCS file: /sources/classpath/classpath/javax/swing/JFileChooser.java,v
retrieving revision 1.34
diff -U3 -r1.34 JFileChooser.java
--- javax/swing/JFileChooser.java	12 Jul 2006 21:22:22 -	1.34
+++ javax/swing/JFileChooser.java	14 Jul 2006 23:35:37 -
@@ -353,7 +353,7 @@
* The file selection mode.
* @see #setFileSelectionMode(int) 
*/
-  private int fileSelectionMode = FILES_AND_DIRECTORIES;
+  private int fileSelectionMode = FILES_ONLY;
 
   /** 
* The file view.
Index: javax/swing/plaf/basic/BasicDirectoryModel.java
===
RCS file: /sources/classpath/classpath/javax/swing/plaf/basic/BasicDirectoryModel.java,v
retrieving revision 1.3
diff -U3 -r1.3 BasicDirectoryModel.java
--- javax/swing/plaf/basic/BasicDirectoryModel.java	1 Jun 2006 05:17:02 -	1.3
+++ javax/swing/plaf/basic/BasicDirectoryModel.java	14 Jul 2006 23:35:37 -
@@ -1,5 +1,5 @@
 /* BasicDirectoryModel.java --
-   Copyright (C) 2005  Free Software Foundation, Inc.
+   Copyright (C) 2005, 2006  Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -51,24 +51,29 @@
 
 
 /**
- * DOCUMENT ME!
+ * Implements an AbstractListModel for directories where the source
+ * of the files is a JFileChooser object. 
+ *
+ * This class is used for sorting and ordering the file list in
+ * a JFileChooser LF object.
  */
 public class BasicDirectoryModel extends AbstractListModel
   implements PropertyChangeListener
 {
-  /** DOCUMENT ME! */
+  /** The list of files itself */
   private Vector contents;
 
-  /** DOCUMENT ME! */
+  /** The number of directories in the list */
   private int directories;
 
-  /** DOCUMENT ME! */
+  /** The listing mode of the associated JFileChooser,
+  either FILES_ONLY, DIRECTORIES_ONLY or FILES_AND_DIRECTORIES */
   private int listingMode;
 
-  /** DOCUMENT ME! */
+  /** The JFileCooser associated with this model */
   private JFileChooser filechooser;
 
-  /** DOCUMENT ME! */
+  /** A Comparator class/object for sorting the file list. */
   private Comparator comparator = new Comparator()
 {
   public int compare(Object o1, Object o2)
@@ -91,14 +96,15 @@
 filechooser.addPropertyChangeListener(this);
 listingMode = filechooser.getFileSelectionMode();
 contents = new Vector();
+validateFileCache();
   }
 
   /**
-   * DOCUMENT ME!
+   * Returns whether a given (File) object is included in the list.
*
-   * @param o DOCUMENT ME!
+   * @param o - The file object to test.
*
-   * @return DOCUMENT ME!
+   * @return codetrue/code if the list contains the given object.
*/
   public boolean contains(Object o)
   {
@@ -106,7 +112,7 @@
   }
 
   /**
-   * DOCUMENT ME!
+   * Fires a content change event. 
*/
   public void fireContentsChanged()
   {
@@ -114,9 +120,10 @@
   }
 
   /**
-   * DOCUMENT ME!
+   * Returns a Vector of (java.io.File) objects containing
+   * the directories in this list.
*
-   * @return DOCUMENT ME!
+   * @return a Vector
*/
   public Vector getDirectories()
   {
@@ -127,26 +134,24 @@
   }
 
   /**
-   * DOCUMENT ME!
+   * Returns the (java.io.File) object at 
+   * an index in the list.
*
-   * @param index DOCUMENT ME!
-   *
-   * @return DOCUMENT ME!
+   * @param index The list index
+   * @return a File object
*/
   public Object getElementAt(int index)
   {
 if (index  getSize() - 1)
   return null;
-if (listingMode == JFileChooser.FILES_ONLY)
-  return contents.get(directories + index);
-else
-  return contents.elementAt(index);
+return

Re: [cp-patches] RFC: java.lang.StrictMath#cbrt implemented

2006-07-13 Thread Sven de Marothy
On Thu, 2006-07-13 at 19:46 +0200, Carsten Neumann wrote:
   Hi,
 
 the attached patch implements java.lang.StrictMath#cbrt, but I'm
 actually quite ashamed to post it: I'm not very knowledgeable about
 floating point arithmetic, so I just followed the implementation in
 fdlibm (www.netlib.org/fdlibm). Unfortunately this library does some
 weird manipulations of the bits of a double, which I simply mimicked in
 java.

That's probably okay though. Actually it's probably a lot better coding
practice to do it in Java than in C since Java at least has a strictly
defined idea of what a double is.

(A bigger problem with some VMs (*cough* GCJ) is that the internal
representation of a double isn't right. E.g. the might use the
processors extended 80-bit doubles *cough* instead of IEEE 64-bit ones)

One question though.. would it make sense to use longs instead of
int[2] for the 'word' stuff? You could use the Double.doubleFromRawLong
method to convert back to double then.

/Sven




[cp-patches] FYI: GIFImageReader cleaning

2006-07-13 Thread Sven de Marothy
2006-07-12  Sven de Marothy  [EMAIL PROTECTED]

* gnu/javax/imageio/gif/GIFImageReader.java
(read): Remove old debugging trace.


Index: gnu/javax/imageio/gif/GIFImageReader.java
===
RCS file: /sources/classpath/classpath/gnu/javax/imageio/gif/GIFImageReader.java,v
retrieving revision 1.1
diff -U3 -r1.1 GIFImageReader.java
--- gnu/javax/imageio/gif/GIFImageReader.java	26 Jun 2006 16:06:30 -	1.1
+++ gnu/javax/imageio/gif/GIFImageReader.java	13 Jul 2006 21:41:11 -
@@ -231,9 +231,6 @@
 	  new int[] {0xFF});
 	break;
   }
-byte[] bits = f.getRawImage();
-for(int i = 0; i  5; i++)
-  System.out.println(Bits +i+:+bits[i]);
 DataBuffer db = new DataBufferByte(f.getRawImage(), width * height, 0);
 WritableRaster raster = Raster.createWritableRaster(sm, db, null);
 


Re: [cp-patches] RFA: java2d ellipse optimization

2006-07-12 Thread Sven de Marothy
On Wed, 2006-07-12 at 14:34 -0400, Francis Kung wrote:
 Hi,
 
 Attached is a patch to optimize ellipse drawing in java2d.  I'm seeing a
 ~25% speed boost from it on both draw and fill.
 
 Also, ignore my earlier patch re alpha composite; I realised that it
 doesn't work with gradients/textures, and am working on a better patch.
 
 Francis

Looks fine to me!

/Sven




[cp-patches] Re: FYI: AU reader fixlet

2006-07-11 Thread Sven de Marothy
On Tue, 2006-07-11 at 19:47 +0200, Sven de Marothy wrote:
 Whoops, forgot I'd renamed the extension from .au to .as for debugging
 purposes. (So I could test it against the JDK without conflicting with
 its existing AU Reader) This changes it back.

(as being a mild curse in Swedish, meaning carcass) 

/Sven




[cp-patches] FYI: ImageIO GIF decoder plugin

2006-06-26 Thread Sven de Marothy
2006-06-26  Sven de Marothy  [EMAIL PROTECTED]

* gnu/javax/imageio/gif/GIFFile.java
* gnu/javax/imageio/gif/GIFImageReader.java
* gnu/javax/imageio/gif/GIFImageSpi.java
* gnu/javax/imageio/gif/GIFStream.java
New files.
* javax/imageio/spi/IIORegistry.java: Load new GIF decoder plugin.


Index: javax/imageio/spi/IIORegistry.java
===
RCS file: /sources/classpath/classpath/javax/imageio/spi/IIORegistry.java,v
retrieving revision 1.8
diff -U3 -r1.8 IIORegistry.java
--- javax/imageio/spi/IIORegistry.java	2 Sep 2005 09:15:22 -	1.8
+++ javax/imageio/spi/IIORegistry.java	26 Jun 2006 15:53:49 -
@@ -45,6 +45,7 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import gnu.javax.imageio.gif.GIFImageReaderSpi;
 
 public final class IIORegistry extends ServiceRegistry
 {
@@ -81,7 +82,7 @@
 super(defaultCategories.iterator());
 
 // XXX: Register built-in Spis here.
-
+registerServiceProvider(new GIFImageReaderSpi()); // Register GIF decoder
 Toolkit toolkit = Toolkit.getDefaultToolkit();
 if (toolkit instanceof ClasspathToolkit)
   ((ClasspathToolkit)toolkit).registerImageIOSpis(this);
/* GIFFile.java -- GIF decoder
   Copyright (C) 2006  Free Software Foundation, Inc.

This file is part of GNU Classpath.

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */

package gnu.javax.imageio.gif;

import java.io.IOException;
import java.io.InputStream;
import java.util.Vector;

/**
 * GIFFile - reads a GIF file.
 * 
 * This class only does the bare minimum work, and returns the data in raw
 * formats (described below). The class is J2ME compatible, and hopefully
 * we can keep it that way without any significant overhead.
 *
 * @author Sven de Marothy. 
 */
public class GIFFile 
{
  // NETSCAPE2.0 - identifier
  private final static byte[] nsBlock = new byte[]
  {0x4e, 0x45, 0x54, 0x53, 0x43, 0x41, 0x50, 0x45, 0x32, 0x2e, 0x30 };

  /**
   * Block identifiers
   */
  private final static int EXTENSION = 0x21;
  private final static int LOCAL = 0x2C;
  private final static int TERMINATOR = 0x3B;

  /**
   * Extension block types
   */
  private final static int EXTENSION_COMMENT = 254;
  private final static int EXTENSION_GCONTROL = 249; 
  private final static int EXTENSION_APPLICATION = 255;

  /**
   * Undraw commands for animation.
   */
  private final static int UNDRAW_OVERWRITE = 1;
  private final static int UNDRAW_RESTORE_BACKGROUND = 2;
  private final static int UNDRAW_RESTORE_PREVIOUS = 3; 

  /**
   * Image position and dimensions (images may be partial)
   */
  private int x, y, width, height;

  /**
   * Global dimensions
   */
  private int globalWidth, globalHeight;

  /**
   * Background color index.
   */
  private byte bgIndex;

  /**
   * Number of colors
   */
  private int nColors;

  /**
   * Global palette, if any
   */
  private byte[] globalPalette;

  /**
   * Any
   */
  private boolean hasGlobalColorMap;

  /**
   * Local palette, if any (used if available)
   */
  private byte[] localPalette;

  /**
   * Interlaced GIF or not?
   */
  private boolean interlaced;

  /**
   * Has transparency?
   */
  private boolean hasTransparency;
  
  /**
   * Undraw mode (animations)
   */
  private int undraw;

  /**
   * Transparent index;
   */
  private int transparentIndex

[cp-patches] FYI: More font stuff

2006-06-17 Thread Sven de Marothy
2006-06-18  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
(FreetypeGlyphVector, clone): Implement cloning.
(getGlyphLogicalBounds): Bounds should be offset to the glyph 
position.
* java/awt/font/TextMeasurer.java: Implement.
* java/awt/font/LineBreakMeasurer.java: 
Reimplement to use TextMeasurer.
* java/awt/font/TextLayout.java
New constructors.
(getBlackboxBounds, getLogicalHighlightShape): Reimplement.
(getText, getFont): New private static methods.
(setCharIndices): New method.
* java/text/AttributedString.java
(AttributedString): Fix constructor to stop at end point.

Index: gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
===
RCS file: 
/sources/classpath/classpath/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java,v
retrieving revision 1.6
diff -U3 -r1.6 FreetypeGlyphVector.java
--- gnu/java/awt/peer/gtk/FreetypeGlyphVector.java  11 Jun 2006 08:29:57 
-  1.6
+++ gnu/java/awt/peer/gtk/FreetypeGlyphVector.java  18 Jun 2006 00:47:35 
-
@@ -137,6 +137,35 @@
   }
 
   /**
+   * Cloning constructor
+   */  
+  private FreetypeGlyphVector( FreetypeGlyphVector gv )
+  {
+font = gv.font;
+peer = gv.peer;
+frc = gv.frc;
+s = gv.s;
+nGlyphs = gv.nGlyphs;
+logicalBounds = gv.logicalBounds.getBounds2D();
+
+if( gv.metricsCache != null )
+  {
+   metricsCache = new GlyphMetrics[ nGlyphs ];
+   System.arraycopy(gv.metricsCache, 0, metricsCache, 0, nGlyphs);
+  }
+
+glyphCodes = new int[ nGlyphs ];
+glyphPositions = new float[ nGlyphs ];
+glyphTransforms = new AffineTransform[ nGlyphs ];
+for(int i = 0; i  nGlyphs; i++ )
+  {
+   glyphTransforms[ i ] = new AffineTransform( gv.glyphTransforms[ i ] );
+   glyphCodes[i] = gv.glyphCodes[ i ];
+   glyphPositions[i] = gv.glyphPositions[ i ];
+  }
+  }
+
+  /**
* Create the array of glyph codes.
*/
   private void getGlyphs()
@@ -172,6 +201,12 @@
 
   private native GeneralPath getGlyphOutlineNative(int glyphIndex);
 
+
+  public Object clone()
+  {
+return new FreetypeGlyphVector( this );
+  }
+
   /**
* Duh, compares two instances.
*/
@@ -260,8 +295,11 @@
 if( gm == null )
   return null; 
 Rectangle2D r = gm.getBounds2D();
-return new Rectangle2D.Double( r.getX() - gm.getLSB(), r.getY(),
-  gm.getAdvanceX(), r.getHeight() );
+Point2D p = getGlyphPosition( glyphIndex );
+return new Rectangle2D.Double( p.getX() + r.getX() - gm.getLSB(), 
+  p.getY() + r.getY(),
+  gm.getAdvanceX(), 
+  r.getHeight() );
   }
 
   /*
@@ -385,8 +423,6 @@
 for( int i = 1; i  nGlyphs; i++ )
   {
Rectangle2D r2 = (Rectangle2D)getGlyphLogicalBounds( i );
-   Point2D p = getGlyphPosition( i );
-   r2.setRect( p.getX(), p.getY(), r2.getWidth(), r2.getHeight() );
rect = rect.createUnion( r2 );
   }
 
Index: java/awt/font/LineBreakMeasurer.java
===
RCS file: /sources/classpath/classpath/java/awt/font/LineBreakMeasurer.java,v
retrieving revision 1.4
diff -U3 -r1.4 LineBreakMeasurer.java
--- java/awt/font/LineBreakMeasurer.java13 Jun 2006 00:14:27 -  
1.4
+++ java/awt/font/LineBreakMeasurer.java18 Jun 2006 00:47:36 -
@@ -41,57 +41,41 @@
 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 text;
   private int position;
-  private FontRenderContext frc;
-  private TextLayout totalLayout;
+  private TextMeasurer tm; 
   private int numChars;
 
   public LineBreakMeasurer(AttributedCharacterIterator text, 
   BreakIterator breakIter, FontRenderContext frc)
   {
-this.text = text;
-this.frc = frc;
-position = 0;
-totalLayout = new TextLayout(text, frc);
-numChars = totalLayout.getCharacterCount();
+this( text, frc );
   }
 
   public LineBreakMeasurer(AttributedCharacterIterator text, 
   FontRenderContext frc)
   {
 this.text = text;
-this.frc = frc;
 position = 0;
-totalLayout = new TextLayout(text, frc);
-numChars = totalLayout.getCharacterCount();
+numChars = text.getEndIndex();
+tm = new TextMeasurer( text, frc );
   }
 
   public void deleteChar(AttributedCharacterIterator newParagraph, 
 int deletePos)
   {
-totalLayout = new TextLayout(newParagraph, frc);
-if( deletePos  0 || deletePos  totalLayout.getCharacterCount

Re: [cp-patches] FYI: CairoGraphics2D speedup

2006-06-14 Thread Sven de Marothy
On Wed, 14 Jun 2006, Mark Wielaard wrote:

 Nice, but unfortunately that doesn't work for ComponentGraphics which
 manipulate the X state. In that case we need locking before drawing. We
 used to get that for free since ComponentGraphics overrides draw(Shape)
 and fill(Shape). So we need to override these three new public methods
 so we do correct locking again.

Correct.
 
 Unfortunately I am unable to say how much speed loss this gives because
 without this patch the benchmark program kept crashing on me. With this
 it runs reliable though.

Zero speed loss compared to before. You're not doing any less work.
 
 We might want to think a bit more about how we do this locking since the
 current way means we do three separate JNI calls and a little extra
 bookkeeping in ComponentGraphics to account for the gdk lock not being
 reentrant. It is probably much more efficient if we had some
 needs_drawing_lock flag inside CairoGraphics itself that subclasses
 could set if needed.

Absolutely not. Never. No way. I refactored the drawing classes precisely
to get away from bullshit like this. CairoGraphics draws to a generic 
Cairo context. Most Cairo context do not require any kind of locking. 
That's the whole idea of why things are done the way they are. 

Trust me, the existing code is a lot more thought through than your idea.
What you're proposing here is going to first introduce a gdk dependency in 
CairoGraphics, which I do not want at all. 

Second, it will slow down all the other drawing contexts by performing an 
unncessary check for whether to do locking.

Third, you're not going to gain much speed regardless, because the 
overhead of making two extra JNI calls is negligable compared to the time 
required to release and get the locks, and in comparison to the fact that 
all those drawing operations have to go through Xlib (and possible 
client-server communication), which is why they need locks to begin with.

This short-sighted thinking is what made the Graphics2D code such a mess
in the first place. It's cleaned up now, and let's not go back there.

-Sven



Re: [cp-patches] RFA: CairoGraphics2D.java fixlet

2006-06-14 Thread Sven de Marothy
On Wed, 14 Jun 2006, David Gilbert wrote:

 I'm requesting approval for this patch, just in case I'm missing something
 important.
 
 As I understand the getPathIterator(AffineTransform) method defined in the
 Shape interface, if you want the path returned without transformation, you can
 pass in null for the AffineTransform.  So it is wasteful to create a new
 identity transform as we seem to be doing here.
 

Seems sane to me.

-Sven



[cp-patches] FYI: CairoSurface fix

2006-06-13 Thread Sven de Marothy
Whoops! Two wrongs make a right, CairoSurface was allocating 4x too much
memory due to an inconsistent row stride parameter.

2006-06-13  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/CairoSurface.java
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c
(create): Use stride in ints.


Index: gnu/java/awt/peer/gtk/CairoSurface.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/CairoSurface.java,v
retrieving revision 1.9
diff -U3 -r1.9 CairoSurface.java
--- gnu/java/awt/peer/gtk/CairoSurface.java	12 Jun 2006 10:32:44 -	1.9
+++ gnu/java/awt/peer/gtk/CairoSurface.java	13 Jun 2006 15:56:39 -
@@ -88,7 +88,7 @@
   /**
* Allocates and clears the buffer and creates the cairo surface.
* @param width, height - the image size
-   * @param stride - the buffer row stride.
+   * @param stride - the buffer row stride. (in ints)
*/
   private native void create(int width, int height, int stride);
 
@@ -146,7 +146,7 @@
* The format will be ARGB32 with premultiplied alpha and native bit 
* and word ordering.
*/
-  CairoSurface(int width, int height)
+  public CairoSurface(int width, int height)
   {
 super(DataBuffer.TYPE_INT, width * height);
 
@@ -156,7 +156,7 @@
 this.width = width;
 this.height = height;
 
-create(width, height, width * 4);
+create(width, height, width);
 
 if(surfacePointer == 0 || bufferPointer == 0)
   throw new Error(Could not allocate bitmap.);
@@ -176,7 +176,7 @@
 width = image.width;
 height = image.height;
 
-create(width, height, width * 4);
+create(width, height, width);
 
 if(surfacePointer == 0 || bufferPointer == 0)
   throw new Error(Could not allocate bitmap.);
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c
===
RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c,v
retrieving revision 1.19
diff -U3 -r1.19 gnu_java_awt_peer_gtk_CairoSurface.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c	12 Jun 2006 10:32:44 -	1.19
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c	13 Jun 2006 15:56:40 -
@@ -64,7 +64,7 @@
   setNativeObject(env, obj, data, BUFFER);
 
   surface = cairo_image_surface_create_for_data
-(data, CAIRO_FORMAT_ARGB32, width, height, stride);
+(data, CAIRO_FORMAT_ARGB32, width, height, stride * 4);
 
   setNativeObject(env, obj, surface, SURFACE);
 }


[cp-patches] FYI: Implement lineBreakMeasurer

2006-06-12 Thread Sven de Marothy
Here's LineBreakMeasurer. The rest of you can't quite use it yet because
the CVS TextLayout isn't up to snuff. So you'll just have to take my
word for it. :) 

2006-06-12  Sven de Marothy  [EMAIL PROTECTED]

* java/awt/font/LineBreakMeasurer.java): Implement.


Index: java/awt/font/LineBreakMeasurer.java
===
RCS file: /sources/classpath/classpath/java/awt/font/LineBreakMeasurer.java,v
retrieving revision 1.3
diff -U3 -r1.3 LineBreakMeasurer.java
--- java/awt/font/LineBreakMeasurer.java	22 Mar 2006 19:15:24 -	1.3
+++ java/awt/font/LineBreakMeasurer.java	13 Jun 2006 00:12:13 -
@@ -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 codeLineBreakMeasurer/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 codeLineBreakMeasurer/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,
-  int deletePos)
-throws NotImplementedException
+  public void deleteChar(AttributedCharacterIterator newParagraph, 
+			 int deletePos)
   {
-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,
-boolean requireNextWord)
-throws NotImplementedException
+  public int nextOffset(float wrappingWidth)
   {
-throw new Error (not implemented);
+return nextOffset( wrappingWidth, numChars, false );
   }
 
-  public int nextOffset (float wrappingWidth)
-throws NotImplementedException
+  public int nextOffset(float wrappingWidth, int offsetLimit, 
+			boolean requireNextWord)
   {
-throw new Error (not implemented);
+Shape s = totalLayout.getBlackBoxBounds( position, offsetLimit );
+double remainingLength = s.getBounds2D().getWidth();
+
+int

[cp-patches] FYI: Faster drawString.

2006-06-11 Thread Sven de Marothy
All in all, this makes drawString() about 3 times as fast.

2006-06-11  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
(setupGlyphMetrics): New method. Add glyphmetrics caching.
(getOutline): Operate on the shape directly.
* gnu/java/awt/peer/gtk/GdkFontPeer.java
(getGlyphMetrics,putGlyphMetrics): Add GlyphMetrics caching.
* include/gnu_java_awt_peer_gtk_FreetypeGlyphVector.h
(getGlyph renamed getGlyphs)
* java/awt/geom/AffineTransform.java
(getTranslateInstance): Set fields directly.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c
(getGlyphs): Get all glyph codes at once.


Index: gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java,v
retrieving revision 1.5
diff -U3 -r1.5 FreetypeGlyphVector.java
--- gnu/java/awt/peer/gtk/FreetypeGlyphVector.java	11 Jun 2006 03:09:03 -	1.5
+++ gnu/java/awt/peer/gtk/FreetypeGlyphVector.java	11 Jun 2006 08:23:21 -
@@ -84,11 +84,7 @@
*/
   private AffineTransform[] glyphTransforms;
 
-  /**
-   * Keep track of which glyphs are whitespace, since we don't have
-   * reporting from the peers yet. TextLayout needs this for justification.
-   */
-  private boolean[] whiteSpace;
+  private GlyphMetrics[] metricsCache;
 
   /**
* Create a glyphvector from a given (Freetype) font and a String.
@@ -147,21 +143,25 @@
   {
 nGlyphs = s.codePointCount( 0, s.length() );
 glyphCodes = new int[ nGlyphs ];
+int[] codePoints = new int[ nGlyphs ];
 int stringIndex = 0;
+
 for(int i = 0; i  nGlyphs; i++)
   {
-	glyphCodes[i] = getGlyph( s.codePointAt(stringIndex) );
+	codePoints[i] = s.codePointAt( stringIndex );
 	// UTF32 surrogate handling
-	if( s.codePointAt( stringIndex ) != (int)s.charAt( stringIndex ) )
+	if( codePoints[i] != (int)s.charAt( stringIndex ) )
 	  stringIndex ++;
 	stringIndex ++;
   }
+
+   glyphCodes = getGlyphs( codePoints );
   }
 
   /**
* Returns the glyph code within the font for a given character
*/
-  public native int getGlyph(int codepoint);
+  public native int[] getGlyphs(int[] codepoints);
 
   /**
* Returns the kerning of a glyph pair
@@ -209,14 +209,12 @@
 logicalBounds = null; // invalidate caches.
 glyphPositions = null;
 
-whiteSpace = new boolean[ nGlyphs ]; 
 glyphTransforms = new AffineTransform[ nGlyphs ]; 
 double x = 0;
+
 for(int i = 0; i  nGlyphs; i++)
   {
-	whiteSpace[i] = Character.isWhitespace( glyphCodes[ i ] );
 	GlyphMetrics gm = getGlyphMetrics( i );
-	Rectangle2D r = gm.getBounds2D();
 	glyphTransforms[ i ] = AffineTransform.getTranslateInstance(x, 0);
 	x += gm.getAdvanceX();
 	if( i  0 )
@@ -266,22 +264,48 @@
    gm.getAdvanceX(), r.getHeight() );
   }
 
+  /*
+   * FIXME: Not all glyph types are supported.
+   * (The JDK doesn't really seem to do so either)
+   */
+  public void setupGlyphMetrics()
+  {
+metricsCache = new GlyphMetrics[ nGlyphs ];
+
+for(int i = 0; i  nGlyphs; i++)
+  {
+	GlyphMetrics gm = (GlyphMetrics)
+	  peer.getGlyphMetrics( glyphCodes[ i ] );
+	if( gm == null )
+	  {
+	double[] val = getMetricsNative( glyphCodes[ i ] );
+	if( val == null )
+	  gm = null;
+	else
+	  {
+		gm = new GlyphMetrics( true, 
+   (float)val[1], 
+   (float)val[2], 
+   new Rectangle2D.Double
+   ( val[3], val[4], 
+	 val[5], val[6] ),
+   GlyphMetrics.STANDARD );
+		peer.putGlyphMetrics( glyphCodes[ i ], gm );
+	  }
+	  }
+	metricsCache[ i ] = gm;
+  }
+  }
+
   /**
* Returns the metrics of a single glyph.
-   * FIXME: Not all glyph types are supported.
*/
   public GlyphMetrics getGlyphMetrics(int glyphIndex)
   {
-double[] val = getMetricsNative( glyphCodes[ glyphIndex ] );
-if( val == null )
-  return null;
-byte type = whiteSpace[ glyphIndex ] ? 
-  GlyphMetrics.WHITESPACE : GlyphMetrics.STANDARD;
-
-return new GlyphMetrics( true, (float)val[1], (float)val[2], 
-			 new Rectangle2D.Double( val[3], val[4], 
-		 val[5], val[6] ),
-			 type );
+if( metricsCache == null )
+  setupGlyphMetrics();
+
+return metricsCache[ glyphIndex ];
   }
 
   /**
@@ -406,7 +430,9 @@
   public Shape getOutline(float x, float y)
   {
 AffineTransform tx = AffineTransform.getTranslateInstance( x, y );
-return tx.createTransformedShape( getOutline() );
+GeneralPath gp = (GeneralPath)getOutline();
+gp.transform( tx );
+return gp;
   }
 
   /**
Index: gnu/java/awt/peer/gtk/GdkFontPeer.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/GdkFontPeer.java,v
retrieving revision 1.17
diff -U3 -r1.17 GdkFontPeer.java
--- gnu/java/awt/peer

Re: [cp-patches] FYI: VolatileImage backbuffer for Swing

2006-06-10 Thread Sven de Marothy
On Sat, 2006-06-10 at 10:11 +0200, Roman Kennke wrote:
 Hi again,
 
 Am Samstag, den 10.06.2006, 10:02 +0200 schrieb Roman Kennke:
  This enables the use of VolatileImages as backbuffer for Swing. This
  effectively solves the performance problems brought by the Java2D
  rewrite.
 
 Well, actually this seemed to be wishful thinking. Comparison in the
 FillRect demo shows that painting is comparable for the 'standard'
 benchmark, and even slower on VolatileImage with both checkboxes checked
 (on my machine ~1000ms for VI vs ~500ms for BI). I guess we need to fix
 the VolatileImage impl.

Forget about the fillRect demo. It's a terrible benchmark. The values it
gives do not actually provide any meaningful measure of drawing speed.

/Sven




[cp-patches] Re: RFC: deadlock with Componet/CairoGraphics.drawImage()

2006-06-10 Thread Sven de Marothy
On Sat, 2006-06-10 at 23:17 +0200, Mark Wielaard wrote:
 Hi,
 
 I was seeing deadlocks in some cases with ComponentGraphics.drawImage().
 ComponentGraphics takes the gdk lock and then calls super.drawImage().
 But in some cases when the image isn't a BufferedImage CairoGraphics
 would recurse into drawImage() again. And since the gdk lock isn't
 reentrant that would cause a deadlock. There was a second problem if the
 image was the error image, in that case it wouldn't have a ImageProducer
 and later on in CairoGraphics.drawImage() an Exception would be thrown.
 In that case the gdk lock would never be released. To prevent against
 such situations this patch also moves all operations that have to
 operate with the gdk lock held into a try-finally block to make sure the
 lock is always released.

Looks OK. But on a seperate but related note, could we move that error
image stuff to a seperate dummy class instead though? 

/Sven




[cp-patches] FYI: TextLayout fixlet and some GlyphVector caches.

2006-06-10 Thread Sven de Marothy
2006-06-11  Sven de Marothy  [EMAIL PROTECTED]

* java/awt/font/TextLayout.java
(getLogicalHighlightShape): Add check.
* gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
(getLogicalBounds, getGlyphPositions): Cache bounds, positions.


Index: gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java,v
retrieving revision 1.4
diff -U3 -r1.4 FreetypeGlyphVector.java
--- gnu/java/awt/peer/gtk/FreetypeGlyphVector.java	9 Jun 2006 20:23:55 -	1.4
+++ gnu/java/awt/peer/gtk/FreetypeGlyphVector.java	11 Jun 2006 03:03:04 -
@@ -56,6 +56,9 @@
   private Font font;
   private GdkFontPeer peer; // ATTN: Accessed from native code.
 
+  private Rectangle2D logicalBounds;
+
+  private float[] glyphPositions;
   /**
* The string represented by this GlyphVector.
*/
@@ -203,6 +206,9 @@
*/
   public void performDefaultLayout()
   {
+logicalBounds = null; // invalidate caches.
+glyphPositions = null;
+
 whiteSpace = new boolean[ nGlyphs ]; 
 glyphTransforms = new AffineTransform[ nGlyphs ]; 
 double x = 0;
@@ -303,6 +309,9 @@
   public float[] getGlyphPositions(int beginGlyphIndex, int numEntries, 
    float[] positionReturn)
   {
+if( glyphPositions != null )
+  return glyphPositions;
+
 float[] rval;
 
 if( positionReturn == null )
@@ -317,6 +326,7 @@
 	rval[i * 2 + 1] = (float)p.getY();
   }
 
+glyphPositions = rval;
 return rval;
   }
 
@@ -344,6 +354,8 @@
   {
 if( nGlyphs == 0 )
   return new Rectangle2D.Double(0, 0, 0, 0);
+if( logicalBounds != null )
+  return logicalBounds;
 
 Rectangle2D rect = (Rectangle2D)getGlyphLogicalBounds( 0 );
 for( int i = 1; i  nGlyphs; i++ )
@@ -354,6 +366,7 @@
 	rect = rect.createUnion( r2 );
   }
 
+logicalBounds = rect;
 return rect;
   }
 
@@ -413,6 +426,8 @@
 // FIXME: Scaling, etc.?
 glyphTransforms[ glyphIndex ].setToTranslation( newPos.getX(), 
 		newPos.getY() );
+logicalBounds = null;
+glyphPositions = null;
   }
 
   /**
@@ -421,5 +436,7 @@
   public void setGlyphTransform(int glyphIndex, AffineTransform newTX)
   {
 glyphTransforms[ glyphIndex ].setTransform( newTX );
+logicalBounds = null;
+glyphPositions = null;
   }
 }
Index: java/awt/font/TextLayout.java
===
RCS file: /sources/classpath/classpath/java/awt/font/TextLayout.java,v
retrieving revision 1.9
diff -U3 -r1.9 TextLayout.java
--- java/awt/font/TextLayout.java	9 Jun 2006 20:48:02 -	1.9
+++ java/awt/font/TextLayout.java	11 Jun 2006 03:03:06 -
@@ -391,11 +391,12 @@
 double advance = 0;
 
 // go to first run
-while( runIndices[i + 1][1]  firstEndpoint ) 
-  {
-	advance += runs[i].getLogicalBounds().getWidth();
-	i++;
-  }
+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 )


[cp-patches] FYI: TextLayout patch Bidi fix

2006-06-09 Thread Sven de Marothy
Hey all, this is my initial implementation of TextLayout, deprecating
the whole old TextLayoutPeer stuff.

Work's still needed (no hit testing yet), but it's mostly there.
/Sven

2006-06-08  Sven de Marothy  [EMAIL PROTECTED]

* java/text/Bidi.java: Treat WS as neutral for rules N1  N2.
* gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
New constructor for bidirectionality.
(getGlyphMetrics): Return whitespace glyphs.
(getLogicalBounds): Offset rectangles to correct positions.
* gnu/java/awt/peer/gtk/GdkFontPeer.java
(getBaselineFor): Default to ROMAN_BASELINE.
(GdkFontLineMetrics): Guess some values for underline and 
strikethrough.
(layoutGlyphVector): Use bidirectionality.
* java/awt/font/TextLayout.java: Implement, mostly.


Index: ChangeLog
===
RCS file: /sources/classpath/classpath/ChangeLog,v
retrieving revision 1.7743
diff -U3 -r1.7743 ChangeLog
--- ChangeLog	9 Jun 2006 17:02:31 -	1.7743
+++ ChangeLog	9 Jun 2006 20:20:03 -
@@ -1,3 +1,17 @@
+2006-06-08  Sven de Marothy  [EMAIL PROTECTED]
+
+	* java/text/Bidi.java: Treat WS as neutral for rules N1  N2.
+	* gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
+	New constructor for bidirectionality.
+	(getGlyphMetrics): Return whitespace glyphs.
+	(getLogicalBounds): Offset rectangles to correct positions.
+	* gnu/java/awt/peer/gtk/GdkFontPeer.java
+	(getBaselineFor): Default to ROMAN_BASELINE.
+	(GdkFontLineMetrics): Guess some values for underline and 
+	strikethrough.
+	(layoutGlyphVector): Use bidirectionality.
+	* java/awt/font/TextLayout.java: Implement, mostly.
+	
 2006-06-09  Anthony Green  [EMAIL PROTECTED]
 
 	PR classpath/27888:
Index: gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java,v
retrieving revision 1.3
diff -U3 -r1.3 FreetypeGlyphVector.java
--- gnu/java/awt/peer/gtk/FreetypeGlyphVector.java	7 Jun 2006 23:48:05 -	1.3
+++ gnu/java/awt/peer/gtk/FreetypeGlyphVector.java	9 Jun 2006 20:20:08 -
@@ -82,10 +82,25 @@
   private AffineTransform[] glyphTransforms;
 
   /**
+   * Keep track of which glyphs are whitespace, since we don't have
+   * reporting from the peers yet. TextLayout needs this for justification.
+   */
+  private boolean[] whiteSpace;
+
+  /**
* Create a glyphvector from a given (Freetype) font and a String.
*/
   public FreetypeGlyphVector(Font f, String s, FontRenderContext frc)
   {
+this(f, s, frc, Font.LAYOUT_LEFT_TO_RIGHT);
+  }
+
+  /**
+   * Create a glyphvector from a given (Freetype) font and a String.
+   */
+  public FreetypeGlyphVector(Font f, String s, FontRenderContext frc,
+			 int flags)
+  {
 this.s = s;
 this.font = f;
 this.frc = frc;
@@ -94,6 +109,14 @@
 peer = (GdkFontPeer)font.getPeer();
 
 getGlyphs();
+if( flags == Font.LAYOUT_RIGHT_TO_LEFT )
+  {
+	// reverse the glyph ordering.
+	int[] temp = new int[ nGlyphs ];
+	for(int i = 0; i  nGlyphs; i++)
+	  temp[ i ] = glyphCodes[ nGlyphs - i - 1];
+	glyphCodes = temp;
+  }
 performDefaultLayout();
   }
 
@@ -180,10 +203,12 @@
*/
   public void performDefaultLayout()
   {
+whiteSpace = new boolean[ nGlyphs ]; 
 glyphTransforms = new AffineTransform[ nGlyphs ]; 
 double x = 0;
 for(int i = 0; i  nGlyphs; i++)
   {
+	whiteSpace[i] = Character.isWhitespace( glyphCodes[ i ] );
 	GlyphMetrics gm = getGlyphMetrics( i );
 	Rectangle2D r = gm.getBounds2D();
 	glyphTransforms[ i ] = AffineTransform.getTranslateInstance(x, 0);
@@ -237,17 +262,20 @@
 
   /**
* Returns the metrics of a single glyph.
+   * FIXME: Not all glyph types are supported.
*/
   public GlyphMetrics getGlyphMetrics(int glyphIndex)
   {
 double[] val = getMetricsNative( glyphCodes[ glyphIndex ] );
 if( val == null )
   return null;
+byte type = whiteSpace[ glyphIndex ] ? 
+  GlyphMetrics.WHITESPACE : GlyphMetrics.STANDARD;
 
 return new GlyphMetrics( true, (float)val[1], (float)val[2], 
 			 new Rectangle2D.Double( val[3], val[4], 
 		 val[5], val[6] ),
-			 GlyphMetrics.STANDARD );
+			 type );
   }
 
   /**
@@ -319,7 +347,12 @@
 
 Rectangle2D rect = (Rectangle2D)getGlyphLogicalBounds( 0 );
 for( int i = 1; i  nGlyphs; i++ )
-  rect = rect.createUnion( (Rectangle2D)getGlyphLogicalBounds( i ) );
+  {
+	Rectangle2D r2 = (Rectangle2D)getGlyphLogicalBounds( i );
+	Point2D p = getGlyphPosition( i );
+	r2.setRect( p.getX(), p.getY(), r2.getWidth(), r2.getHeight() );
+	rect = rect.createUnion( r2 );
+  }
 
 return rect;
   }
Index: gnu/java/awt/peer/gtk/GdkFontPeer.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/GdkFontPeer.java,v
retrieving revision 1.15

[cp-patches] FYI: CairoGraphics2D.drawString implemented on TextLayout

2006-06-09 Thread Sven de Marothy
2006-06-08  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/CairoGraphics2D.java
(drawString): Use TextLayout instead of GlyphVector.


Index: gnu/java/awt/peer/gtk/CairoGraphics2D.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java,v
retrieving revision 1.16
diff -U3 -r1.16 CairoGraphics2D.java
--- gnu/java/awt/peer/gtk/CairoGraphics2D.java	9 Jun 2006 16:04:20 -	1.16
+++ gnu/java/awt/peer/gtk/CairoGraphics2D.java	9 Jun 2006 20:36:47 -
@@ -63,6 +63,7 @@
 import java.awt.Toolkit;
 import java.awt.font.FontRenderContext;
 import java.awt.font.GlyphVector;
+import java.awt.font.TextLayout;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Arc2D;
 import java.awt.geom.Area;
@@ -1271,8 +1272,8 @@
   {
 if (str == null || str.length() == 0)
   return;
-
-drawGlyphVector(getFont().createGlyphVector(null, str), x, y);
+(new TextLayout( str, getFont(), getFontRenderContext() )).
+  draw(this, x, y);
   }
 
   public void drawString(String str, int x, int y)


[cp-patches] FYI: Fix locking in componentgraphics.

2006-06-09 Thread Sven de Marothy
2006-06-09  Sven de Marothy  [EMAIL PROTECTED]

* native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c
(Java_gnu_java_awt_peer_gtk_ComponentGraphics_disposeSurface):
Use GTK locks while disposing (Xlib) surface.


Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c
===
RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c,v
retrieving revision 1.14
diff -U3 -r1.14 gnu_java_awt_peer_gtk_ComponentGraphics.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c	7 Jun 2006 09:40:54 -	1.14
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c	9 Jun 2006 22:03:53 -
@@ -186,7 +186,11 @@
 
   surface = cairo_get_target (gr-cr);
   if (surface != NULL)
-cairo_surface_destroy (surface);
+{
+  gdk_threads_enter();
+  cairo_surface_destroy (surface);
+  gdk_threads_leave();
+}
 }
 
 JNIEXPORT jlong JNICALL 


[cp-patches] Re: FYI: GlyphVector reimplementation

2006-06-07 Thread Sven de Marothy
Finally,

2006-06-05  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/GdkGlyphVector: Removed file.






[cp-patches] FYI: GlyphVector reimplementation

2006-06-07 Thread Sven de Marothy
2006-06-05  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
* include/gnu_java_awt_peer_gtk_FreetypeGlyphVector.h
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c
New files.

* gnu/java/awt/peer/gtk/GdkFontPeer.java
(getGlyphVector): Removed native method.
(createGlyphVector, getStringBounds): Use new GV class.

* include/Makefile.am
* native/jni/gtk-peer/Makefile.am
Add new files.

* include/gnu_java_awt_peer_gtk_GdkFontPeer.h
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c
(getGlyphVector): Removed native method.


? gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
? include/gnu_java_awt_peer_gtk_FreetypeGlyphVector.h
? native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c
Index: gnu/java/awt/peer/gtk/GdkFontPeer.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/GdkFontPeer.java,v
retrieving revision 1.14
diff -U3 -r1.14 GdkFontPeer.java
--- gnu/java/awt/peer/gtk/GdkFontPeer.java	30 May 2006 22:36:32 -	1.14
+++ gnu/java/awt/peer/gtk/GdkFontPeer.java	7 Jun 2006 13:45:10 -
@@ -47,8 +47,10 @@
 import java.awt.Toolkit;
 import java.awt.font.FontRenderContext;
 import java.awt.font.GlyphVector;
+import java.awt.font.GlyphMetrics;
 import java.awt.font.LineMetrics;
 import java.awt.geom.Rectangle2D;
+import java.awt.geom.Point2D;
 import java.text.CharacterIterator;
 import java.text.StringCharacterIterator;
 import java.util.Locale;
@@ -234,23 +236,18 @@
 return -1;
   }
   
-  private native GdkGlyphVector getGlyphVector(String txt, 
-   Font f, 
-   FontRenderContext ctx);
-
   public GlyphVector createGlyphVector (Font font, 
 FontRenderContext ctx, 
 CharacterIterator i)
   {
-return getGlyphVector(buildString (i), font, ctx);
+return new FreetypeGlyphVector(font, buildString (i), ctx);
   }
 
   public GlyphVector createGlyphVector (Font font, 
 FontRenderContext ctx, 
 int[] glyphCodes)
   {
-return null;
-//return new GdkGlyphVector (font, this, ctx, glyphCodes);
+return new FreetypeGlyphVector(font, glyphCodes, ctx);
   }
 
   public byte getBaselineFor (Font font, char c)
@@ -338,7 +335,9 @@
   public Rectangle2D getStringBounds (Font font, CharacterIterator ci, 
   int begin, int limit, FontRenderContext frc)
   {
-GdkGlyphVector gv = getGlyphVector(buildString (ci, begin, limit), font, frc);
+GlyphVector gv = new FreetypeGlyphVector( font, 
+	  buildString(ci, begin, limit),
+	  frc);
 return gv.getVisualBounds();
   }
 
@@ -373,5 +372,4 @@
 // the metrics cache.
 return Toolkit.getDefaultToolkit().getFontMetrics (font);
   }
-
 }
Index: include/Makefile.am
===
RCS file: /sources/classpath/classpath/include/Makefile.am,v
retrieving revision 1.63
diff -U3 -r1.63 Makefile.am
--- include/Makefile.am	6 Jun 2006 10:04:15 -	1.63
+++ include/Makefile.am	7 Jun 2006 13:45:11 -
@@ -41,6 +41,7 @@
 $(top_srcdir)/include/gnu_java_awt_peer_gtk_CairoGraphics2D.h \
 $(top_srcdir)/include/gnu_java_awt_peer_gtk_ComponentGraphics.h \
 $(top_srcdir)/include/gnu_java_awt_peer_gtk_ComponentGraphicsCopy.h \
+$(top_srcdir)/include/gnu_java_awt_peer_gtk_FreetypeGlyphVector.h \
 $(top_srcdir)/include/gnu_java_awt_peer_gtk_GdkFontPeer.h \
 $(top_srcdir)/include/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.h \
 $(top_srcdir)/include/gnu_java_awt_peer_gtk_GdkPixbufDecoder.h \
Index: include/gnu_java_awt_peer_gtk_GdkFontPeer.h
===
RCS file: /sources/classpath/classpath/include/gnu_java_awt_peer_gtk_GdkFontPeer.h,v
retrieving revision 1.8
diff -U3 -r1.8 gnu_java_awt_peer_gtk_GdkFontPeer.h
--- include/gnu_java_awt_peer_gtk_GdkFontPeer.h	29 May 2006 16:14:59 -	1.8
+++ include/gnu_java_awt_peer_gtk_GdkFontPeer.h	7 Jun 2006 13:45:11 -
@@ -18,7 +18,6 @@
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkFontPeer_getTextMetrics (JNIEnv *env, jobject, jstring, jdoubleArray);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkFontPeer_releasePeerGraphicsResource (JNIEnv *env, jobject);
 JNIEXPORT jbyteArray JNICALL Java_gnu_java_awt_peer_gtk_GdkFontPeer_getTrueTypeTable (JNIEnv *env, jobject, jbyte, jbyte, jbyte, jbyte);
-JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_gtk_GdkFontPeer_getGlyphVector (JNIEnv *env, jobject, jstring, jobject, jobject);
 
 #ifdef __cplusplus
 }
Index: native/jni/gtk-peer/Makefile.am

Re: [cp-patches] FYI: GlyphVector reimplementation

2006-06-07 Thread Sven de Marothy
On Wed, 2006-06-07 at 16:45 +0200, Roman Kennke wrote:
 You don't loose much words except for the ChangeLog entries, eh? ;-)
 
 It would be helpful to add some descriptive text too, so others can get
 up to what you did. Otherwise we wouldn't need this ML and could depend
 on commit-classpath for commit messages and changelog entries.

Okay, okay! :) I reimplemented GlyphVector properly, now it actually
does the layouting that GV is supposed to do, and works with FreeType
directly (albeit getting the FT data structures through Pango, as of
yet).

Previously the implementation worked by letting pango lay the stuff out
and then getting the glyphs and their respective positions from there. 

So, now that we have a proper and seemingly functional GlyphVector we
can implement TextLayout on top of that, the way it's supposed to be.

So the next step in the grand plan is to kill the
ClasspathTextLayoutPeer and related stuff, stub the TextLayout impl and
implement it properly.

/Sven




[cp-patches] FYI: Glyphvector kerning.

2006-06-07 Thread Sven de Marothy
2006-06-08  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
(defaultLayout): Do kerning.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c
(getKerning): Correct class name, removed unused variable.


Index: gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java,v
retrieving revision 1.2
diff -U3 -r1.2 FreetypeGlyphVector.java
--- gnu/java/awt/peer/gtk/FreetypeGlyphVector.java	7 Jun 2006 15:22:50 -	1.2
+++ gnu/java/awt/peer/gtk/FreetypeGlyphVector.java	7 Jun 2006 23:45:33 -
@@ -188,6 +188,11 @@
 	Rectangle2D r = gm.getBounds2D();
 	glyphTransforms[ i ] = AffineTransform.getTranslateInstance(x, 0);
 	x += gm.getAdvanceX();
+	if( i  0 )
+	  {
+	Point2D p = getKerning( glyphCodes[ i - 1 ], glyphCodes[ i ] );
+	x += p.getX();
+	  }
   }
   }
 
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c
===
RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c,v
retrieving revision 1.1
diff -U3 -r1.1 gnu_java_awt_peer_gtk_FreetypeGlyphVector.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c	7 Jun 2006 13:54:32 -	1.1
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c	7 Jun 2006 23:45:34 -
@@ -115,7 +115,6 @@
   font = getFont(env, obj);
   ft_face = pango_fc_font_lock_face( font );
   g_assert (ft_face != NULL);
-
   FT_Get_Kerning( ft_face, rightGlyph, leftGlyph, FT_KERNING_DEFAULT, kern );
 
   pango_fc_font_unlock_face( font );
@@ -123,7 +122,7 @@
   values[0].d = (jdouble)kern.x/64.0;
   values[1].d = (jdouble)kern.y/64.0;
 
-  cls = (*env)-FindClass (env, java/awt/geom/Point2D.Double);
+  cls = (*env)-FindClass (env, java/awt/geom/Point2D$Double);
   method = (*env)-GetMethodID (env, cls, init, (DD)V);
   return (*env)-NewObjectA(env, cls, method, values);
 }
@@ -136,7 +135,6 @@
   jdouble *values;
   jdoubleArray retArray = NULL;
   PangoFcFont *font;
-  FT_BBox acbox;
 
   font = getFont(env, obj);
   ft_face = pango_fc_font_lock_face( font );


[cp-patches] Stub TextLayout

2006-06-07 Thread Sven de Marothy
Time to remove this unnecessary peer interface and replace the stub peer
with a stubbed actual impl. Yay! This makes our JAPI scores more honest.

Ok?

/Sven

2006-06-08  Sven de Marothy  [EMAIL PROTECTED]

* java/awt/font/TextLayout: Replace methods with stubs.
* gnu/java/awt/peer/gtk/GtkToolkit.java:
( getClasspathTextLayoutPeer ): Remove method.
Index: gnu/java/awt/ClasspathToolkit.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/ClasspathToolkit.java,v
retrieving revision 1.19
diff -U3 -r1.19 ClasspathToolkit.java
--- gnu/java/awt/ClasspathToolkit.java	2 Sep 2005 09:15:22 -	1.19
+++ gnu/java/awt/ClasspathToolkit.java	8 Jun 2006 00:51:46 -
@@ -41,7 +41,6 @@
 import gnu.java.awt.EmbeddedWindow;
 import gnu.java.awt.peer.ClasspathFontPeer;
 import gnu.java.awt.peer.EmbeddedWindowPeer;
-import gnu.java.awt.peer.ClasspathTextLayoutPeer;
 import gnu.java.security.action.SetAccessibleAction;
 
 import java.awt.AWTException;
@@ -120,10 +119,6 @@
*/
   public abstract ClasspathFontPeer getClasspathFontPeer (String name, Map attrs); 
 
-  public abstract ClasspathTextLayoutPeer 
-  getClasspathTextLayoutPeer (AttributedString str, FontRenderContext frc); 
-
-
   /** 
* Creates a [EMAIL PROTECTED] Font}, in a platform-specific manner.
* 
Index: gnu/java/awt/peer/gtk/GtkToolkit.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/GtkToolkit.java,v
retrieving revision 1.87
diff -U3 -r1.87 GtkToolkit.java
--- gnu/java/awt/peer/gtk/GtkToolkit.java	5 Jun 2006 13:47:04 -	1.87
+++ gnu/java/awt/peer/gtk/GtkToolkit.java	8 Jun 2006 00:51:46 -
@@ -42,7 +42,6 @@
 import gnu.classpath.Configuration;
 import gnu.java.awt.EmbeddedWindow;
 import gnu.java.awt.peer.ClasspathFontPeer;
-import gnu.java.awt.peer.ClasspathTextLayoutPeer;
 import gnu.java.awt.peer.EmbeddedWindowPeer;
 
 import java.awt.*;
@@ -528,12 +527,6 @@
   }
   }
 
-  public ClasspathTextLayoutPeer getClasspathTextLayoutPeer (AttributedString str, 
- FontRenderContext frc)
-  {
-return new GdkTextLayout(str, frc);
-  }
-
   protected EventQueue getSystemEventQueueImpl() 
   {
 synchronized (GtkToolkit.class)
Index: java/awt/font/TextLayout.java
===
RCS file: /sources/classpath/classpath/java/awt/font/TextLayout.java,v
retrieving revision 1.7
diff -U3 -r1.7 TextLayout.java
--- java/awt/font/TextLayout.java	2 Jul 2005 20:32:29 -	1.7
+++ java/awt/font/TextLayout.java	8 Jun 2006 00:51:46 -
@@ -39,7 +39,6 @@
 package java.awt.font;
 
 import gnu.java.awt.ClasspathToolkit;
-import gnu.java.awt.peer.ClasspathTextLayoutPeer;
 
 import java.awt.Font;
 import java.awt.Graphics2D;
@@ -57,276 +56,287 @@
 public final class TextLayout implements Cloneable
 {
   public static final CaretPolicy DEFAULT_CARET_POLICY = new CaretPolicy ();
-  ClasspathTextLayoutPeer peer;
-
-  public static class CaretPolicy
-  {
-public CaretPolicy ()
-{
-  // Do nothing here.
-}
-
-public TextHitInfo getStrongCaret (TextHitInfo hit1, TextHitInfo hit2,
-   TextLayout layout)
-{
-  return layout.peer.getStrongCaret(hit1, hit2);
-}
-  }
 
   public TextLayout (AttributedCharacterIterator text, FontRenderContext frc)
-  {
-AttributedString as = new AttributedString (text);
-ClasspathToolkit tk = (ClasspathToolkit)(Toolkit.getDefaultToolkit ());
-peer = tk.getClasspathTextLayoutPeer(as, frc);
+throws NotImplementedException
+  {
+throw new Error (not implemented);
   }
 
   public TextLayout (String string, Font font, FontRenderContext frc) 
+throws NotImplementedException
   {
-AttributedString as = new AttributedString (string);
-as.addAttribute (TextAttribute.FONT, font);
-ClasspathToolkit tk = (ClasspathToolkit)(Toolkit.getDefaultToolkit ());
-peer = tk.getClasspathTextLayoutPeer(as, frc);
+throw new Error (not implemented);
   }
 
   public TextLayout (String string, Map attributes, FontRenderContext frc)  
+throws NotImplementedException
   {
-AttributedString as = new AttributedString (string, attributes);
-ClasspathToolkit tk = (ClasspathToolkit)(Toolkit.getDefaultToolkit ());
-peer = tk.getClasspathTextLayoutPeer(as, frc);
+throw new Error (not implemented);
   }
 
   protected Object clone ()
+throws NotImplementedException
   {
-try
-  {
-TextLayout tl = (TextLayout) super.clone ();
-tl.peer = (ClasspathTextLayoutPeer) this.peer.clone();
-return tl;
-  }
-catch (CloneNotSupportedException e)
-  {
-// This should never occur
-throw new InternalError ();
-  }
+throw new Error (not implemented);
   }
 
 
   public void draw (Graphics2D g2

[cp-patches] Re: RFC: Cairo memory leak fixes

2006-06-06 Thread Sven de Marothy
On Tue, 2006-06-06 at 17:40 +0200, Mark Wielaard wrote:
 Hi,
 
 This fixes some memory leaks found by Norman when trying niffler with
 the new Cairo code. With this I am able to run the slideshow without
 running out of memory.

Looks good to me. I know I left some leaks here and there. So cleaning
them up just means less work for me to do. Yay. :)

/Sven




Re: [cp-patches] FYI: GdkScreenGraphicsDevice and friends implemented

2006-06-06 Thread Sven de Marothy
On Tue, 2006-06-06 at 12:02 +0200, Robert Schuster wrote:
 Hi,
 this patch implements the GdkScreenGraphicsDevice and related classes.

Great! Now we can fill in the missing puzzle piece for VolatileImage,
which is the GraphicsEnvironment constructor. It should probably take a
GdkScreenGraphicsDevice as a parameter.

The reason for this is that VolatileImage wraps an X pixmap both in our
impl and in the JDK (says Sun's docs), and to create a pixmap you need
to know the native screen parameters. Which can be recieved either from
an existing widget (GtkComponentPeer constructor -implemented.) or from
a GdkScreen (not implemented). 

So you should all understand now why the createVolatileImage methods
happen to be in GraphicsConfiguration and Component. :)

/Sven




[cp-patches] FYI: Volatileimage changes

2006-06-05 Thread Sven de Marothy
2006-06-05  Sven de Marothy  [EMAIL PROTECTED]

* include/gnu_java_awt_peer_gtk_ComponentGraphics.h
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c
* gnu/java/awt/peer/gtk/ComponentGraphics.java
(initFromVolatile): New method.
* gnu/java/awt/peer/gtk/GtkVolatileImage.java
* gnu/java/awt/peer/gtk/VolatileImageGraphics.java
Reimplement.
* include/gnu_java_awt_peer_gtk_GtkVolatileImage.h
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c
(copyArea, drawVolatileImage): New methods.


Index: gnu/java/awt/peer/gtk/ComponentGraphics.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java,v
retrieving revision 1.9
diff -U3 -r1.9 ComponentGraphics.java
--- gnu/java/awt/peer/gtk/ComponentGraphics.java	5 Jun 2006 03:39:14 -	1.9
+++ gnu/java/awt/peer/gtk/ComponentGraphics.java	6 Jun 2006 02:13:44 -
@@ -46,6 +46,7 @@
 import java.awt.Image;
 import java.awt.Rectangle;
 import java.awt.Shape;
+import java.awt.Point;
 import java.awt.font.FontRenderContext;
 import java.awt.font.GlyphVector;
 import java.awt.geom.AffineTransform;
@@ -64,8 +65,12 @@
 public class ComponentGraphics extends CairoGraphics2D
 {
   private GtkComponentPeer component;
-  private long cairo_t;
+  protected long cairo_t;
 
+  ComponentGraphics()
+  {
+  }
+  
   private ComponentGraphics(GtkComponentPeer component)
   {
 this.component = component;
@@ -94,6 +99,11 @@
   private native long initState(GtkComponentPeer component);
 
   /**
+   * Creates a cairo_t for a volatile image
+   */
+  protected native long initFromVolatile( long pixmapPtr, int width, int height);
+
+  /**
* Grab lock
*/
   private native void start_gdk_drawing();
@@ -194,8 +204,7 @@
   {
 if( img instanceof GtkVolatileImage )
   {
-	((GtkVolatileImage)img).validate( null );
-	drawVolatile( component, img, x, y-20 ,
+	drawVolatile( component, img, x, y - 20,
 		  ((GtkVolatileImage)img).width, 
 		  ((GtkVolatileImage)img).height );
 	return true;
@@ -208,8 +217,7 @@
   {
 if( img instanceof GtkVolatileImage )
   {
-	((GtkVolatileImage)img).validate( null );
-	drawVolatile( component, img, x, y-20, 
+	drawVolatile( component, img, x, y - 20, 
 		  width, height );
 	return true;
   }  
Index: gnu/java/awt/peer/gtk/GtkVolatileImage.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/GtkVolatileImage.java,v
retrieving revision 1.5
diff -U3 -r1.5 GtkVolatileImage.java
--- gnu/java/awt/peer/gtk/GtkVolatileImage.java	4 Jun 2006 19:44:39 -	1.5
+++ gnu/java/awt/peer/gtk/GtkVolatileImage.java	6 Jun 2006 02:13:44 -
@@ -53,23 +53,18 @@
   /**
* Don't touch, accessed from native code.
*/
-  private long nativePointer;
-
-  /**
-   * Offscreen image we draw to.
-   */
-  CairoSurface offScreen;
-
-  private boolean needsUpdate = false;
+  long nativePointer;
 
   native long init(GtkComponentPeer component, int width, int height);
 
   native void destroy();
 
   native int[] getPixels();
-  
-  native void update(GtkImage image);
 
+  native void copyArea( int x, int y, int w, int h, int dx, int dy );
+
+  native void drawVolatile( long ptr, int x, int y, int w, int h );
+  
   public GtkVolatileImage(GtkComponentPeer component, 
 			  int width, int height, ImageCapabilities caps)
   {
@@ -77,7 +72,6 @@
 this.height = height;
 this.caps = caps;
 nativePointer = init( component, width, height );
-offScreen = new CairoSurface( width, height );
   }
 
   public GtkVolatileImage(int width, int height, ImageCapabilities caps)
@@ -100,11 +94,6 @@
 destroy();
   }
 
-  void invalidate()
-  {
-needsUpdate = true;
-  }
-
   public BufferedImage getSnapshot()
   {
 CairoSurface cs = new CairoSurface( width, height );
@@ -119,24 +108,17 @@
 
   public Graphics2D createGraphics()
   {
-invalidate();
-return offScreen.getGraphics();
+return new VolatileImageGraphics( this );
   }
 
   public int validate(GraphicsConfiguration gc)
   {
-if( needsUpdate )
-  {
-	update( offScreen.getGtkImage() );
-	needsUpdate = false;
-	return VolatileImage.IMAGE_RESTORED;
-  }
 return VolatileImage.IMAGE_OK;
   }
 
   public boolean contentsLost()
   {
-return needsUpdate;
+return false;
   }
 
   public ImageCapabilities getCapabilities()
Index: gnu/java/awt/peer/gtk/VolatileImageGraphics.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/VolatileImageGraphics.java,v
retrieving revision 1.1
diff -U3 -r1.1 VolatileImageGraphics.java
--- gnu/java/awt/peer/gtk/VolatileImageGraphics.java	3 Jun 2006 22:41:41 -	1.1
+++ gnu/java/awt/peer/gtk/VolatileImageGraphics.java	6 Jun 2006 02:13:44 -
@@ -58,72

[cp-patches] FYI: VolatileImage fixes

2006-06-04 Thread Sven de Marothy
2006-06-04  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/CairoSurface.java
(getFlippedBuffer): New method.
(getGtkImage): Renamed method.
* gnu/java/awt/peer/gtk/ComponentGraphicsCopy.java
* gnu/java/awt/peer/gtk/GtkVolatileImage.java
Renamed getSharedImage to getGtkImage.
* include/gnu_java_awt_peer_gtk_CairoSurface.h
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c
(getFlippedBuffer): New method
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c
Avoid window casts.


Index: gnu/java/awt/peer/gtk/CairoSurface.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/CairoSurface.java,v
retrieving revision 1.5
diff -U3 -r1.5 CairoSurface.java
--- gnu/java/awt/peer/gtk/CairoSurface.java	1 Jun 2006 13:57:39 -	1.5
+++ gnu/java/awt/peer/gtk/CairoSurface.java	4 Jun 2006 19:39:50 -
@@ -123,6 +123,8 @@
*/
   native void setPixels(int[] pixels);
 
+  native long getFlippedBuffer(int size);
+
   /**
* Create a cairo_surface_t with specified width and height.
* The format will be ARGB32 with premultiplied alpha and native bit 
@@ -197,11 +199,11 @@
   }
 
   /**
-   * Return a GtkImage which shares its data with this Cairo surface.
+   * Return a GtkImage from this Cairo surface.
*/
-  public GtkImage getSharedGtkImage()
+  public GtkImage getGtkImage()
   {
-return new GtkImage( width, height, bufferPointer );
+return new GtkImage( width, height, getFlippedBuffer( width * height ));
   }
 
   /**
Index: gnu/java/awt/peer/gtk/ComponentGraphicsCopy.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/ComponentGraphicsCopy.java,v
retrieving revision 1.1
diff -U3 -r1.1 ComponentGraphicsCopy.java
--- gnu/java/awt/peer/gtk/ComponentGraphicsCopy.java	30 May 2006 04:21:53 -	1.1
+++ gnu/java/awt/peer/gtk/ComponentGraphicsCopy.java	4 Jun 2006 19:39:50 -
@@ -83,7 +83,7 @@
 this.component = component;
 this.width = width;
 this.height = height;
-gtkimage = surface.getSharedGtkImage();
+gtkimage = surface.getGtkImage();
 getPixbuf( component, gtkimage );
   }
 
Index: gnu/java/awt/peer/gtk/GtkVolatileImage.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/GtkVolatileImage.java,v
retrieving revision 1.4
diff -U3 -r1.4 GtkVolatileImage.java
--- gnu/java/awt/peer/gtk/GtkVolatileImage.java	3 Jun 2006 22:41:41 -	1.4
+++ gnu/java/awt/peer/gtk/GtkVolatileImage.java	4 Jun 2006 19:39:50 -
@@ -127,7 +127,7 @@
   {
 if( needsUpdate )
   {
-	update( offScreen.getSharedGtkImage() );
+	update( offScreen.getGtkImage() );
 	needsUpdate = false;
 	return VolatileImage.IMAGE_RESTORED;
   }
Index: include/gnu_java_awt_peer_gtk_CairoSurface.h
===
RCS file: /sources/classpath/classpath/include/gnu_java_awt_peer_gtk_CairoSurface.h,v
retrieving revision 1.1
diff -U3 -r1.1 gnu_java_awt_peer_gtk_CairoSurface.h
--- include/gnu_java_awt_peer_gtk_CairoSurface.h	29 May 2006 16:14:59 -	1.1
+++ include/gnu_java_awt_peer_gtk_CairoSurface.h	4 Jun 2006 19:39:50 -
@@ -18,6 +18,7 @@
 JNIEXPORT jintArray JNICALL Java_gnu_java_awt_peer_gtk_CairoSurface_getPixels (JNIEnv *env, jobject, jint);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoSurface_setPixels (JNIEnv *env, jobject, jintArray);
 JNIEXPORT jlong JNICALL Java_gnu_java_awt_peer_gtk_CairoSurface_newCairoContext (JNIEnv *env, jobject);
+JNIEXPORT jlong JNICALL Java_gnu_java_awt_peer_gtk_CairoSurface_getFlippedBuffer (JNIEnv *env, jobject, jint);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoSurface_copyAreaNative (JNIEnv *env, jobject, jint, jint, jint, jint, jint, jint, jint);
 
 #ifdef __cplusplus
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c
===
RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c,v
retrieving revision 1.14
diff -U3 -r1.14 gnu_java_awt_peer_gtk_CairoSurface.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c	3 Jun 2006 05:21:05 -	1.14
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c	4 Jun 2006 19:39:55 -
@@ -208,6 +208,29 @@
  (*env)-ReleaseDoubleArrayElements (env, java_matrix, native_matrix, 0);
 }
 
+JNIEXPORT jlong JNICALL 
+Java_gnu_java_awt_peer_gtk_CairoSurface_getFlippedBuffer 
+(JNIEnv *env, jobject obj, jint size)
+{
+  jint *dst;
+  jint *src = (jint *)getNativeObject(env, obj, BUFFER);
+  int i;
+  int t;
+
+  g_assert( src != NULL );
+  dst = g_malloc( size * sizeof( jint ) );
+
+  for(i = 0; i  size; i++ )
+{
+  t = (src[i]  0xFF)  16;
+  dst[i] = (src[i

[cp-patches] FYI: ComponentGraphics clip fix

2006-06-04 Thread Sven de Marothy
2006-06-05  Sven de Marothy  [EMAIL PROTECTED]

*  gnu/java/awt/peer/gtk/ComponentGraphics.java
(ComponentGraphics): Use 0,0 as clip origin.


Index: gnu/java/awt/peer/gtk/ComponentGraphics.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java,v
retrieving revision 1.8
diff -U3 -r1.8 ComponentGraphics.java
--- gnu/java/awt/peer/gtk/ComponentGraphics.java	3 Jun 2006 22:41:41 -	1.8
+++ gnu/java/awt/peer/gtk/ComponentGraphics.java	5 Jun 2006 03:36:45 -
@@ -71,8 +71,9 @@
 this.component = component;
 cairo_t = initState(component);
 setup( cairo_t );
+Rectangle bounds = component.awtComponent.getBounds();
+setClip( new Rectangle( 0, 0, bounds.width, bounds.height) );
 setBackground(component.awtComponent.getBackground());
-setClip(component.awtComponent.getBounds());
 setColor(component.awtComponent.getForeground());
   }
 
@@ -81,8 +82,9 @@
 component = cg.component;
 cairo_t = initState(component);
 copy( cg, cairo_t );
+Rectangle bounds = component.awtComponent.getBounds();
+setClip( new Rectangle( 0, 0, bounds.width, bounds.height) );
 setBackground(component.awtComponent.getBackground());
-setClip(component.awtComponent.getBounds());
 setColor(component.awtComponent.getForeground());
   }
 


[cp-patches] FYI: Clipping fixes

2006-06-03 Thread Sven de Marothy
This seems to make the clipping less buggy. I'm still not sure about it.
Anyone care to write some tests to figure out how setClip() is different
from clip()?

2006-06-02  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/CairoGraphics2D.java
(cairoPreserveClip, cairoResetClip): New methods.
(setClip, clip): Reimplement.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c
* include/gnu_java_awt_peer_gtk_CairoGraphics2D.h
(cairoPreserveClip, cairoResetClip): New methods.


Index: gnu/java/awt/peer/gtk/CairoGraphics2D.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java,v
retrieving revision 1.13
diff -U3 -r1.13 CairoGraphics2D.java
--- gnu/java/awt/peer/gtk/CairoGraphics2D.java	2 Jun 2006 22:57:31 -	1.13
+++ gnu/java/awt/peer/gtk/CairoGraphics2D.java	3 Jun 2006 22:44:25 -
@@ -410,6 +410,16 @@
*/
   private native void cairoClip();
 
+  /** 
+   * Save clip
+   */
+  private native void cairoPreserveClip();
+
+  /** 
+   * Save clip
+   */
+  private native void cairoResetClip();
+
   /**
* Set interpolation types
*/
@@ -518,32 +528,10 @@
 
   public void clip(Shape s)
   {
-// update it
-if (clip == null || s == null)
-  clip = s;
-else if (s instanceof Rectangle2D  clip instanceof Rectangle2D)
-  {
-	Rectangle2D r = (Rectangle2D) s;
-	Rectangle2D curr = (Rectangle2D) clip;
-	clip = curr.createIntersection(r);
-  }
-else
-  throw new UnsupportedOperationException();
+if( s == null )
+  setClip( originalClip );
 
-// draw it
-if (clip != null)
-  {
-	cairoNewPath();
-	if (clip instanceof Rectangle2D)
-	  {
-	Rectangle2D r = (Rectangle2D) clip;
-	cairoRectangle(r.getX(), r.getY(), r.getWidth(), r.getHeight());
-	  }
-	else
-	  walkPath(clip.getPathIterator(null), false);
-
-	cairoClip();
-  }
+setClip(s);
   }
 
   public Paint getPaint()
@@ -706,17 +694,18 @@
 
   public void setClip(int x, int y, int width, int height)
   {
-setClip(new Rectangle2D.Double((double) x, (double) y, (double) width,
-   (double) height));
+if( width  0 || height  0 )
+  return;
+
+setClip(new Rectangle2D.Double(x, y, width, height));
   }
 
   public void setClip(Shape s)
   {
-clip = s;
-
-// The first time the clip is set, save it as the original clip to reset to on
-// s == null. We can rely on this being non-null because the constructor in 
-// subclasses is expected to set the initial clip properly.
+// The first time the clip is set, save it as the original clip 
+// to reset to on s == null. We can rely on this being non-null 
+// because the constructor in subclasses is expected to set the 
+// initial clip properly.
 if( firstClip )
   {
 	originalClip = s;
@@ -725,6 +714,10 @@
 
 if (s == null)
   clip = originalClip;
+else
+  clip = s;
+
+cairoResetClip();
 
 cairoNewPath();
 if (clip instanceof Rectangle2D)
@@ -735,7 +728,6 @@
 else
   walkPath(clip.getPathIterator(null), false);
 
-// cairoClosePath ();
 cairoClip();
   }
 
Index: include/gnu_java_awt_peer_gtk_CairoGraphics2D.h
===
RCS file: /sources/classpath/classpath/include/gnu_java_awt_peer_gtk_CairoGraphics2D.h,v
retrieving revision 1.1
diff -U3 -r1.1 gnu_java_awt_peer_gtk_CairoGraphics2D.h
--- include/gnu_java_awt_peer_gtk_CairoGraphics2D.h	29 May 2006 16:14:59 -	1.1
+++ include/gnu_java_awt_peer_gtk_CairoGraphics2D.h	3 Jun 2006 22:44:25 -
@@ -34,6 +34,8 @@
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoStroke (JNIEnv *env, jobject);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoFill (JNIEnv *env, jobject);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoClip (JNIEnv *env, jobject);
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoResetClip (JNIEnv *env, jobject);
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoPreserveClip (JNIEnv *env, jobject);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoSurfaceSetFilter (JNIEnv *env, jobject, jint);
 
 #ifdef __cplusplus
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c
===
RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c,v
retrieving revision 1.5
diff -U3 -r1.5 gnu_java_awt_peer_gtk_CairoGraphics2D.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c	31 May 2006 23:25:13 -	1.5
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c	3 Jun 2006 22:44:26 -
@@ -590,11 +590,30 @@
 Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoClip 
(JNIEnv *env

[cp-patches] FYI: Partial volatileimage impl.

2006-06-03 Thread Sven de Marothy
2006-06-02  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/VolatileImageGraphics.java
* include/gnu_java_awt_peer_gtk_GtkVolatileImage.h
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c
New files.
* gnu/java/awt/peer/gtk/ComponentGraphics.java
(drawImage): Overloads for VolatileImage drawing.
(drawVolatile): New method.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c
* include/gnu_java_awt_peer_gtk_ComponentGraphics.h
(drawVolatile): New method.
* gnu/java/awt/peer/gtk/GtkVolatileImage.java
Unstub implementation.
* include/Makefile.am
* native/jni/gtk-peer/Makefile.am
Add new files.
* native/jni/gtk-peer/gtkpeer.h
New prototype.


? gnu/java/awt/peer/gtk/VolatileImageGraphics.java
? include/gnu_java_awt_peer_gtk_GtkVolatileImage.h
? native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c
Index: gnu/java/awt/peer/gtk/ComponentGraphics.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java,v
retrieving revision 1.7
diff -U3 -r1.7 ComponentGraphics.java
--- gnu/java/awt/peer/gtk/ComponentGraphics.java	2 Jun 2006 22:57:31 -	1.7
+++ gnu/java/awt/peer/gtk/ComponentGraphics.java	3 Jun 2006 22:33:23 -
@@ -110,6 +110,10 @@
   private native void copyAreaNative(GtkComponentPeer component, int x, int y, 
  int width, int height, int dx, int dy);
 
+  private native void drawVolatile(GtkComponentPeer component,
+   Image vimg, int x, int y, 
+   int width, int height);
+
   /**
* Returns a Graphics2D object for a component, either an instance of this 
* class (if xrender is supported), or a context which copies.
@@ -183,4 +187,32 @@
 super.drawGlyphVector(gv, x, y);
 end_gdk_drawing();
   }
+  
+  public boolean drawImage(Image img, int x, int y, ImageObserver observer)
+  {
+if( img instanceof GtkVolatileImage )
+  {
+	((GtkVolatileImage)img).validate( null );
+	drawVolatile( component, img, x, y-20 ,
+		  ((GtkVolatileImage)img).width, 
+		  ((GtkVolatileImage)img).height );
+	return true;
+  }  
+return super.drawImage( img, x, y, observer );
+  }
+  
+  public boolean drawImage(Image img, int x, int y, int width, int height,
+   ImageObserver observer)
+  {
+if( img instanceof GtkVolatileImage )
+  {
+	((GtkVolatileImage)img).validate( null );
+	drawVolatile( component, img, x, y-20, 
+		  width, height );
+	return true;
+  }  
+return super.drawImage( img, x, y, width, height, observer );
+  }
+
 }
+
Index: gnu/java/awt/peer/gtk/GtkVolatileImage.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/GtkVolatileImage.java,v
retrieving revision 1.3
diff -U3 -r1.3 GtkVolatileImage.java
--- gnu/java/awt/peer/gtk/GtkVolatileImage.java	2 Jul 2005 20:32:12 -	1.3
+++ gnu/java/awt/peer/gtk/GtkVolatileImage.java	3 Jun 2006 22:33:23 -
@@ -1,4 +1,4 @@
-/* GtkVolatileImage.java -- a hardware-accelerated image buffer
+/* GtkVolatileImage.java -- wraps an X pixmap
Copyright (C) 2005  Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
@@ -38,6 +38,7 @@
 package gnu.java.awt.peer.gtk;
 
 import java.awt.ImageCapabilities;
+import java.awt.Graphics;
 import java.awt.Graphics2D;
 import java.awt.GraphicsConfiguration;
 import java.awt.image.BufferedImage;
@@ -46,54 +47,96 @@
 
 public class GtkVolatileImage extends VolatileImage
 {
-  private int width;
-  private int height;
+  int width, height;
   private ImageCapabilities caps;
 
-  public GtkVolatileImage(int width, int height)
-  {
-this(width, height, null);
-  }
+  /**
+   * Don't touch, accessed from native code.
+   */
+  private long nativePointer;
 
-  public GtkVolatileImage(int width, int height, ImageCapabilities caps)
+  /**
+   * Offscreen image we draw to.
+   */
+  CairoSurface offScreen;
+
+  private boolean needsUpdate = false;
+
+  native long init(GtkComponentPeer component, int width, int height);
+
+  native void destroy();
+
+  native int[] getPixels();
+  
+  native void update(GtkImage image);
+
+  public GtkVolatileImage(GtkComponentPeer component, 
+			  int width, int height, ImageCapabilities caps)
   {
 this.width = width;
 this.height = height;
 this.caps = caps;
+nativePointer = init( component, width, height );
+offScreen = new CairoSurface( width, height );
   }
 
-  // FIXME: should return a buffered image snapshot of the accelerated
-  // visual
-  public BufferedImage getSnapshot()
+  public GtkVolatileImage(int width, int height, ImageCapabilities caps)
   {
-return null;
+this(null, width, height, caps);
   }
 
-  public int getWidth()
+  public GtkVolatileImage(int width, int height

Re: [cp-patches] FYI: Partial volatileimage impl.

2006-06-03 Thread Sven de Marothy
Check out this demo of VolatileImage.

It doesn't really work on the JDK, though. It's pretty much tailored to
our impl. It also shows off a bug in the impl. (inverted pixel colors
due to me not bothering to convert from Cairo to GTK pixel format)

Still works though, and shows good performance.

/Sven
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

public class ImageBenchmark extends Panel 
  implements MouseMotionListener, ActionListener {
  public static long totalTime;
  public static int totalDraws;
  static Label l;

  Image img;
  VolatileImage vimg;
  int x, y;
  boolean whichImage = false;

  public ImageBenchmark( String imagefile ) 
  {
x = 50;
y = 0;
img = Toolkit.getDefaultToolkit().createImage( imagefile );
addMouseMotionListener(this);
  }

  public void actionPerformed(ActionEvent e)
  {
whichImage = !whichImage;
ImageBenchmark.totalTime = 0;
ImageBenchmark.totalDraws = 0;
  }

  public void mouseDragged(MouseEvent e)
  {
  }

  public void mouseMoved(MouseEvent e)
  {
x = e.getX();
y = e.getY();
repaint();
  }

  public void paint(Graphics g) 
  {
setBackground(Color.white);
if( img == null )
  return;

if( img != null  vimg == null )
  {
	vimg = createVolatileImage(img.getWidth(null), img.getHeight(null));
	Graphics g2 = vimg.getGraphics();
	g2.drawImage(img, 0, 0, this);
  }

long t = System.currentTimeMillis();
g.drawImage( (whichImage ? vimg : img ), x, y, this);
long t2 = (System.currentTimeMillis() - t);
ImageBenchmark.totalTime += t2;
ImageBenchmark.totalDraws++;
double speed = 
  ((double)ImageBenchmark.totalTime/(double)ImageBenchmark.totalDraws);
ImageBenchmark.l.setText(Average speed: +speed+ in last:+t2);
  }

  public static void main(String[] args) 
  {
if( args.length  1 )
  {
	System.out.println(Need an image filename.);
	System.exit(0);
  }

Frame f = new Frame(Image drawing);
f.addWindowListener(new WindowAdapter() {
	public void windowClosing(WindowEvent e) 
	{
	  System.out.println(Total time:+ImageBenchmark.totalTime);
	  System.out.println(Total draws:+ImageBenchmark.totalDraws);
	  System.exit(0);
	}
  });

ImageBenchmark ib = new ImageBenchmark(args[0]);
Button b = new Button(Swap);
b.addActionListener(ib);
l = new Label(Speed:);
f.add(l, BorderLayout.NORTH);
f.add(ib, BorderLayout.CENTER);
f.add(b, BorderLayout.SOUTH);
f.setSize(new Dimension(500, 500));
f.setVisible(true);
  }
}



[cp-patches] FYI: clipping copyarea and flush.

2006-06-02 Thread Sven de Marothy
2006-06-01  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/BufferedImageGraphics.java
* gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c
(nativeCopyArea): Change stride parameter to use # of ints.
* gnu/java/awt/peer/gtk/ComponentGraphics.java
(ComponentGraphics): Set background, clip.
* gnu/java/awt/peer/gtk/CairoGraphics2D.java
(Cairographics2D): Don't set clip.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c
Add flush.


Index: gnu/java/awt/peer/gtk/BufferedImageGraphics.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/BufferedImageGraphics.java,v
retrieving revision 1.5
diff -U3 -r1.5 BufferedImageGraphics.java
--- gnu/java/awt/peer/gtk/BufferedImageGraphics.java	1 Jun 2006 07:43:14 -	1.5
+++ gnu/java/awt/peer/gtk/BufferedImageGraphics.java	2 Jun 2006 16:17:45 -
@@ -231,7 +231,7 @@
 if( y + dy + height = surface.height ) // bottom
   height = surface.height - dy - y;
 
-surface.copyAreaNative(x, y, width, height, dx, dy, surface.width * 4);
+surface.copyAreaNative(x, y, width, height, dx, dy, surface.width);
 updateBufferedImage(x + dx, y + dy, width, height);
   }
 
Index: gnu/java/awt/peer/gtk/CairoGraphics2D.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java,v
retrieving revision 1.11
diff -U3 -r1.11 CairoGraphics2D.java
--- gnu/java/awt/peer/gtk/CairoGraphics2D.java	1 Jun 2006 17:50:58 -	1.11
+++ gnu/java/awt/peer/gtk/CairoGraphics2D.java	2 Jun 2006 16:17:45 -
@@ -257,7 +257,6 @@
 setPaint(paint);
 setStroke(stroke);
 setTransform(transform);
-setClip(clip);
   }
 
   /**
Index: gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java,v
retrieving revision 1.2
diff -U3 -r1.2 CairoSurfaceGraphics.java
--- gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java	30 May 2006 04:21:53 -	1.2
+++ gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java	2 Jun 2006 16:17:45 -
@@ -115,6 +115,6 @@
 if( y + dy + height = surface.height ) // bottom
   height = surface.height - dy - y;
 
-surface.copyAreaNative(x, y, width, height, dx, dy, surface.width * 4);
+surface.copyAreaNative(x, y, width, height, dx, dy, surface.width);
   }
 }
Index: gnu/java/awt/peer/gtk/ComponentGraphics.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java,v
retrieving revision 1.5
diff -U3 -r1.5 ComponentGraphics.java
--- gnu/java/awt/peer/gtk/ComponentGraphics.java	31 May 2006 00:04:30 -	1.5
+++ gnu/java/awt/peer/gtk/ComponentGraphics.java	2 Jun 2006 16:17:45 -
@@ -80,6 +80,9 @@
 component = cg.component;
 cairo_t = initState(component);
 copy( cg, cairo_t );
+setBackground(component.awtComponent.getBackground());
+setClip(component.awtComponent.getBounds());
+setColor(component.awtComponent.getForeground());
   }
 
   /**
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c
===
RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c,v
retrieving revision 1.11
diff -U3 -r1.11 gnu_java_awt_peer_gtk_CairoSurface.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c	1 Jun 2006 04:26:40 -	1.11
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c	2 Jun 2006 16:17:47 -
@@ -223,17 +223,17 @@
   jint *pixeldata = (jint *)getNativeObject(env, obj, BUFFER);
   g_assert( pixeldata != NULL );
 
-  temp = g_malloc( w * 4 );
+  temp = g_malloc( w * sizeof( jint ) );
   g_assert( temp != NULL );
 
-  srcOffset = x + y * (stride  2);
-  dstOffset = (x + dx) + (y + dy) * (stride  2);
+  srcOffset = x + y * stride;
+  dstOffset = (x + dx) + (y + dy) * stride;
   for( row = 0; row  h; row++)
 {
-  memcpy( temp, pixeldata + srcOffset, w * 4 );
-  memcpy( pixeldata + dstOffset, temp, w * 4 );
-  srcOffset += (stride  2);
-  dstOffset += (stride  2);
+  memcpy( temp, pixeldata + srcOffset, w * sizeof(jint) );
+  memcpy( pixeldata + dstOffset, temp, w * sizeof(jint) );
+  srcOffset += stride;
+  dstOffset += stride;
 }
 
   g_free( temp );
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c
===
RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c,v
retrieving revision 1.8
diff -U3 -r1.8 gnu_java_awt_peer_gtk_ComponentGraphics.c
--- native/jni/gtk-peer

[cp-patches] FYI: CairoSurface.setPixels

2006-06-02 Thread Sven de Marothy
I also added checks to CairoSurface.setPixels. Avoid segfaults.
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c
===
RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c,v
retrieving revision 1.11
diff -U3 -r1.11 gnu_java_awt_peer_gtk_CairoSurface.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c	1 Jun 2006 04:26:40 -	1.11
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c	2 Jun 2006 18:27:18 -
@@ -145,12 +145,29 @@
 {
   jint *pixeldata, *jpixdata;
   int size;
+  int width, height;
+  jclass cls;
+  jfieldID field;
+
+  if( jpixels == NULL )
+return;
+
+  cls = (*env)-GetObjectClass (env, obj);
+  field = (*env)-GetFieldID (env, cls, width, I);
+  g_assert (field != 0);
+  width = (*env)-GetIntField (env, obj, field);
+
+  field = (*env)-GetFieldID (env, cls, height, I);
+  g_assert (field != 0);
+  height = (*env)-GetIntField (env, obj, field);
 
   pixeldata = (jint *)getNativeObject(env, obj, BUFFER);
   g_assert(pixeldata != NULL);
-
+  
   jpixdata = (*env)-GetIntArrayElements (env, jpixels, NULL);
   size = (*env)-GetArrayLength( env, jpixels );
+  if( size  width * height ) size = width * height; // stop overflows.
+  
   memcpy (pixeldata, jpixdata, size * sizeof( jint ));
 
   (*env)-ReleaseIntArrayElements (env, jpixels, jpixdata, 0);
@@ -223,17 +240,17 @@
   jint *pixeldata = (jint *)getNativeObject(env, obj, BUFFER);
   g_assert( pixeldata != NULL );
 
-  temp = g_malloc( w * 4 );
+  temp = g_malloc( w * sizeof( jint ) );
   g_assert( temp != NULL );
 
-  srcOffset = x + y * (stride  2);
-  dstOffset = (x + dx) + (y + dy) * (stride  2);
+  srcOffset = x + y * stride;
+  dstOffset = (x + dx) + (y + dy) * stride;
   for( row = 0; row  h; row++)
 {
-  memcpy( temp, pixeldata + srcOffset, w * 4 );
-  memcpy( pixeldata + dstOffset, temp, w * 4 );
-  srcOffset += (stride  2);
-  dstOffset += (stride  2);
+  memcpy( temp, pixeldata + srcOffset, w * sizeof(jint) );
+  memcpy( pixeldata + dstOffset, temp, w * sizeof(jint) );
+  srcOffset += stride;
+  dstOffset += stride;
 }
 
   g_free( temp );


[cp-patches] FYI: CopyArea fix

2006-06-02 Thread Sven de Marothy
This fixes some bugs with copyArea, including the one that caused
JScrollpanes not to work.

2006-06-02  Sven de Marothy  [EMAIL PROTECTED]

PR 27879 
* gnu/java/awt/peer/gtk/CairoGraphics2D.java
(copyArea): Implement.
(copyAreaImpl, getRealBounds): New methods.
* gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java
* gnu/java/awt/peer/gtk/ComponentGraphics.java
* gnu/java/awt/peer/gtk/BufferedImageGraphics.java
(copyAreaImpl, getRealBounds): Implement.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c
(nativeCopyArea): Reimplement.  


Index: gnu/java/awt/peer/gtk/BufferedImageGraphics.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/BufferedImageGraphics.java,v
retrieving revision 1.6
diff -U3 -r1.6 BufferedImageGraphics.java
--- gnu/java/awt/peer/gtk/BufferedImageGraphics.java	2 Jun 2006 18:29:13 -	1.6
+++ gnu/java/awt/peer/gtk/BufferedImageGraphics.java	2 Jun 2006 22:49:13 -
@@ -48,6 +48,7 @@
 import java.awt.Shape;
 import java.awt.font.GlyphVector;
 import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;
 import java.awt.image.DataBuffer;
 import java.awt.image.DataBufferInt;
@@ -204,35 +205,14 @@
   {
 return null;
   }
+
+  protected Rectangle2D getRealBounds()
+  {
+return new Rectangle2D.Double(0.0, 0.0, imageWidth, imageHeight);
+  }
   
-  public void copyArea(int x, int y, int width, int height, int dx, int dy)
+  public void copyAreaImpl(int x, int y, int width, int height, int dx, int dy)
   {
-// Return if outside the surface
-if( x + dx  surface.width || y + dy  surface.height )
-  return;
-
-if( x + dx + width  0 || y + dy + height  0 )
-  return;
-
-// Clip edges if necessary 
-if( x + dx  0 ) // left
-  {
-	width = x + dx + width;
-	x = -dx;
-  }
-
-if( y + dy  0 ) // top
-  {
-	height = y + dy + height;
-	y = -dy;
-  }
-
-if( x + dx + width = surface.width ) // right
-  width = surface.width - dx - x;
-
-if( y + dy + height = surface.height ) // bottom
-  height = surface.height - dy - y;
-
 surface.copyAreaNative(x, y, width, height, dx, dy, surface.width);
 updateBufferedImage(x + dx, y + dy, width, height);
   }
Index: gnu/java/awt/peer/gtk/CairoGraphics2D.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java,v
retrieving revision 1.12
diff -U3 -r1.12 CairoGraphics2D.java
--- gnu/java/awt/peer/gtk/CairoGraphics2D.java	2 Jun 2006 18:29:13 -	1.12
+++ gnu/java/awt/peer/gtk/CairoGraphics2D.java	2 Jun 2006 22:49:15 -
@@ -292,7 +292,11 @@
 
   public abstract GraphicsConfiguration getDeviceConfiguration();
 
-  public abstract void copyArea(int x, int y, int width, int height, int dx, int dy);
+  protected abstract void copyAreaImpl(int x, int y, 
+   int width, int height, int dx, int dy);
+
+
+  protected abstract Rectangle2D getRealBounds();
 
   // Native Methods 
 
@@ -909,6 +913,60 @@
 fill(new RoundRectangle2D.Double(x, y, width, height, arcWidth, arcHeight));
   }
 
+  /**
+   * CopyArea - performs clipping to the native surface as a convenience 
+   * (requires getRealBounds). Then calls copyAreaImpl.
+   */
+  public void copyArea(int ox, int oy, int owidth, int oheight, 
+		   int odx, int ody)
+  {
+Point2D pos = transform.transform(new Point2D.Double(ox, oy),
+  (Point2D) null);
+Point2D dim = transform.transform(new Point2D.Double(ox + owidth, 
+			 oy + oheight),
+  (Point2D) null);
+Point2D p2 = transform.transform(new Point2D.Double(ox + odx, oy + ody),
+ (Point2D) null);
+int x = (int)pos.getX();
+int y = (int)pos.getY();
+int width = (int)(dim.getX() - pos.getX());
+int height = (int)(dim.getY() - pos.getY());
+int dx = (int)(p2.getX() - pos.getX());
+int dy = (int)(p2.getY() - pos.getY());
+
+Rectangle2D r = getRealBounds();
+
+if( width  0 || height  0 )
+  return;
+// Return if outside the surface
+if( x + dx  r.getWidth() || y + dy  r.getHeight() )
+  return;
+
+if( x + dx + width  r.getX() || y + dy + height  r.getY() )
+  return;
+
+// Clip edges if necessary 
+if( x + dx  r.getX() ) // left
+  {
+	width = x + dx + width;
+	x = (int)r.getX() - dx;
+  }
+
+if( y + dy  r.getY() ) // top
+  {
+	height = y + dy + height;
+	y = (int)r.getY() - dy;
+  }
+
+if( x + dx + width = r.getWidth() ) // right
+  width = (int)r.getWidth() - dx - x;
+
+if( y + dy + height = r.getHeight() ) // bottom
+  height = (int)r.getHeight() - dy - y;
+
+copyAreaImpl(x, y, width, height, dx, dy);
+  }
+
   / RENDERING HINTS

[cp-patches] FYI: GdkTextLayout improvements

2006-06-01 Thread Sven de Marothy
2006-06-01  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/CairoGraphics2D.java
(drawImage): Check for zero size.
* gnu/java/awt/peer/gtk/GdkTextLayout.java:
(setFont): Declare new native method.
(GdkTextLayout): Read some attributes.
* include/gnu_java_awt_peer_gtk_GdkTextLayout.h
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkTextLayout.c
(setFont): New native method.


Index: gnu/java/awt/peer/gtk/CairoGraphics2D.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java,v
retrieving revision 1.8
diff -U3 -r1.8 CairoGraphics2D.java
--- gnu/java/awt/peer/gtk/CairoGraphics2D.java	1 Jun 2006 05:05:57 -	1.8
+++ gnu/java/awt/peer/gtk/CairoGraphics2D.java	1 Jun 2006 10:47:33 -
@@ -1122,6 +1122,8 @@
   {
 double scaleX = width / (double) img.getWidth(observer);
 double scaleY = height / (double) img.getHeight(observer);
+if( scaleX == 0 || scaleY == 0 )
+  return true;
 
 return drawImage(img, new AffineTransform(scaleX, 0f, 0f, scaleY, x, y),
  bgcolor, observer);
Index: gnu/java/awt/peer/gtk/GdkTextLayout.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/GdkTextLayout.java,v
retrieving revision 1.8
diff -U3 -r1.8 GdkTextLayout.java
--- gnu/java/awt/peer/gtk/GdkTextLayout.java	30 May 2006 22:36:32 -	1.8
+++ gnu/java/awt/peer/gtk/GdkTextLayout.java	1 Jun 2006 10:47:33 -
@@ -75,6 +75,7 @@
 initStaticState ();
   }
   private native void setText(String str);
+  private native void setFont(GdkFontPeer font);
   private native void getExtents(double[] inkExtents,
  double[] logExtents);
   private native void indexToPos(int idx, double[] pos);
@@ -104,6 +105,15 @@
 initState();
 attributedString = str;
 fontRenderContext = frc;
+AttributedCharacterIterator aci = str.getIterator();
+char[] chars = new char[aci.getEndIndex() - aci.getBeginIndex()];
+for(int i = aci.getBeginIndex(); i  aci.getEndIndex(); i++)
+  chars[i] = aci.setIndex(i);
+setText(new String(chars));
+
+Object fnt = aci.getAttribute(TextAttribute.FONT);
+if (fnt != null  fnt instanceof Font) 	 
+  setFont( (GdkFontPeer) ((Font)fnt).getPeer() );
   }
 
   protected class CharacterIteratorProxy 
Index: include/gnu_java_awt_peer_gtk_GdkTextLayout.h
===
RCS file: /sources/classpath/classpath/include/gnu_java_awt_peer_gtk_GdkTextLayout.h,v
retrieving revision 1.5
diff -U3 -r1.5 gnu_java_awt_peer_gtk_GdkTextLayout.h
--- include/gnu_java_awt_peer_gtk_GdkTextLayout.h	29 May 2006 16:14:59 -	1.5
+++ include/gnu_java_awt_peer_gtk_GdkTextLayout.h	1 Jun 2006 10:47:34 -
@@ -11,6 +11,7 @@
 #endif
 
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkTextLayout_setText (JNIEnv *env, jobject, jstring);
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkTextLayout_setFont (JNIEnv *env, jobject, jobject);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkTextLayout_getExtents (JNIEnv *env, jobject, jdoubleArray, jdoubleArray);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkTextLayout_indexToPos (JNIEnv *env, jobject, jint, jdoubleArray);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkTextLayout_initState (JNIEnv *env, jobject);
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkTextLayout.c
===
RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkTextLayout.c,v
retrieving revision 1.13
diff -U3 -r1.13 gnu_java_awt_peer_gtk_GdkTextLayout.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkTextLayout.c	31 May 2006 23:00:22 -	1.13
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkTextLayout.c	1 Jun 2006 10:47:34 -
@@ -97,8 +97,6 @@
   gchar *str = NULL;
   gint len = 0;
 
-  gdk_threads_enter ();
-
   g_assert(self != NULL);
   g_assert(text != NULL);
 
@@ -110,13 +108,37 @@
   str = (gchar *)(*env)-GetStringUTFChars (env, text, NULL);
   g_assert (str != NULL);
 
-  pango_layout_set_text (tl-pango_layout, text, len);
+  gdk_threads_enter ();
+
+  pango_layout_set_text (tl-pango_layout, str, len);
 
   (*env)-ReleaseStringUTFChars (env, text, str);
 
   gdk_threads_leave ();  
 }
 
+JNIEXPORT void JNICALL 
+Java_gnu_java_awt_peer_gtk_GdkTextLayout_setFont (JNIEnv *env, jobject obj, jobject font)
+{
+  struct textlayout *tl;
+  struct peerfont *pf;
+
+  g_assert(obj != NULL);
+  g_assert(font != NULL);
+
+  tl = (struct textlayout *)NSA_GET_TEXT_LAYOUT_PTR (env, obj);
+  g_assert(tl != NULL);
+  g_assert(tl-pango_layout != NULL);
+  pf = (struct peerfont *)NSA_GET_FONT_PTR (env, font);
+  g_assert(pf != NULL);
+  
+  gdk_threads_enter ();
+
+  pango_layout_set_font_description(tl

[cp-patches] FYI: PR27854/DataBuffers

2006-06-01 Thread Sven de Marothy
Our old code couldn't handle custom DataBuffer implementations.
Fixes that (PR27854), and also some bugs in our custom implementation
(CairoSurface).

2006-06-01  Sven de Marothy  [EMAIL PROTECTED]

PR 27854
* gnu/java/awt/Buffers.java (getData): Reimplement.
* gnu/java/awt/peer/gtk/CairoSurface.java
(getElem, setElem): Call native methods.


Index: gnu/java/awt/Buffers.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/Buffers.java,v
retrieving revision 1.5
diff -U3 -r1.5 Buffers.java
--- gnu/java/awt/Buffers.java	2 Jul 2005 20:32:10 -	1.5
+++ gnu/java/awt/Buffers.java	1 Jun 2006 13:52:14 -
@@ -144,25 +144,7 @@
*/
   public static Object getData(DataBuffer buffer)
   {
-if (buffer instanceof DataBufferByte)
-  return ((DataBufferByte) buffer).getData();
-
-if (buffer instanceof DataBufferShort)
-  return ((DataBufferShort) buffer).getData();
-
-if (buffer instanceof DataBufferUShort)
-  return ((DataBufferUShort) buffer).getData();
-
-if (buffer instanceof DataBufferInt)
-  return ((DataBufferInt) buffer).getData();
-
-if (buffer instanceof DataBufferFloat)
-  return ((DataBufferFloat) buffer).getData();
-
-if (buffer instanceof DataBufferDouble)
-  return ((DataBufferDouble) buffer).getData();
-
-throw new ClassCastException(Unknown data buffer type);
+return getData(buffer, 0, null, 0, buffer.getSize());
   }
 
 
@@ -172,46 +154,46 @@
* given destination array is null.
*/
   public static Object getData(DataBuffer src, int srcOffset,
-			   Object dest,  int destOffset,
+			   Object dest,  int dstOffset,
 			   int length)
   {
 Object from;
-if (src instanceof DataBufferByte)
-  {
-	from = ((DataBufferByte) src).getData();
-	if (dest == null) dest = new byte[length+destOffset];
-  }
-else if (src instanceof DataBufferShort)
-  {
-	from = ((DataBufferShort) src).getData();
-	if (dest == null) dest = new short[length+destOffset];
-  }
-else if (src instanceof DataBufferUShort)
-  {
-	from = ((DataBufferUShort) src).getData();
-	if (dest == null) dest = new short[length+destOffset];
-  }
-else if (src instanceof DataBufferInt)
-  {
-	from = ((DataBufferInt) src).getData();
-	if (dest == null) dest = new int[length+destOffset];
-  }
-else if (src instanceof DataBufferFloat)
-  {
-	from = ((DataBufferFloat) src).getData();
-	if (dest == null) dest = new float[length+destOffset];
-  }
-else if (src instanceof DataBufferDouble)
-  {
-	from = ((DataBufferDouble) src).getData();
-	if (dest == null) dest = new double[length+destOffset];
-  }
-else
+switch(src.getDataType())
   {
+  case DataBuffer.TYPE_BYTE:
+	if (dest == null) dest = new byte[length+dstOffset];
+	for(int i = 0; i  length; i++)
+	  ((byte[])dest)[i + dstOffset] = (byte)src.getElem(i + srcOffset);
+	break;
+
+  case DataBuffer.TYPE_DOUBLE:
+	if (dest == null) dest = new double[length+dstOffset];
+	for(int i = 0; i  length; i++)
+	  ((double[])dest)[i + dstOffset] = src.getElemDouble(i + srcOffset);
+	break;
+
+  case DataBuffer.TYPE_FLOAT:
+	if (dest == null) dest = new float[length+dstOffset];
+	for(int i = 0; i  length; i++)
+	  ((float[])dest)[i + dstOffset] = src.getElemFloat(i + srcOffset);
+	break;
+
+  case DataBuffer.TYPE_INT:
+	if (dest == null) dest = new int[length+dstOffset];
+	for(int i = 0; i  length; i++)
+	  ((int[])dest)[i + dstOffset] = src.getElem(i + srcOffset);
+	break;
+
+  case DataBuffer.TYPE_SHORT:
+  case DataBuffer.TYPE_USHORT:
+	if (dest == null) dest = new short[length+dstOffset];
+	for(int i = 0; i  length; i++)
+	  ((short[])dest)[i + dstOffset] = (short)src.getElem(i + srcOffset);
+	break;
+
+  case DataBuffer.TYPE_UNDEFINED:
 	throw new ClassCastException(Unknown data buffer type);
   }
-
-System.arraycopy(from, srcOffset, dest, destOffset, length);
 return dest;
   }
   
Index: gnu/java/awt/peer/gtk/CairoSurface.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/CairoSurface.java,v
retrieving revision 1.4
diff -U3 -r1.4 CairoSurface.java
--- gnu/java/awt/peer/gtk/CairoSurface.java	31 May 2006 00:38:08 -	1.4
+++ gnu/java/awt/peer/gtk/CairoSurface.java	1 Jun 2006 13:52:15 -
@@ -239,9 +239,9 @@
*/
   public int getElem(int bank, int i)
   {
-if(bank != 0 || i = 0 || i = width*height)
-  throw new IndexOutOfBoundsException();
-return getElem(i);
+if(bank != 0 || i  0 || i = width*height)
+  throw new IndexOutOfBoundsException(i+ size: +width*height);
+return nativeGetElem(i);
   }
   
   /**
@@ -249,9 +249,9 @@
*/
   public void setElem(int bank, int i, int val)
   {
-if(bank != 0 || i = 0 || i = width*height)
-  throw new IndexOutOfBoundsException

[cp-patches] FYI: Trivial Texturepaint fix

2006-06-01 Thread Sven de Marothy
We needed the texture one pixel larger to not have lines between the
tiles.

2006-06-01  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/CairoGraphics2D.java:
(setPaint): Scale +1 pixel larger.


Index: gnu/java/awt/peer/gtk/CairoGraphics2D.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java,v
retrieving revision 1.9
diff -U3 -r1.9 CairoGraphics2D.java
--- gnu/java/awt/peer/gtk/CairoGraphics2D.java	1 Jun 2006 10:51:17 -	1.9
+++ gnu/java/awt/peer/gtk/CairoGraphics2D.java	1 Jun 2006 14:00:34 -
@@ -572,8 +572,8 @@
 	int width = (int) tp.getAnchorRect().getWidth();
 	int height = (int) tp.getAnchorRect().getHeight();
 
-	double scaleX = width / (double) img.getWidth();
-	double scaleY = width / (double) img.getHeight();
+	double scaleX = (width+1) / (double) img.getWidth();
+	double scaleY = (height+1) / (double) img.getHeight();
 
 	AffineTransform at = new AffineTransform(scaleX, 0, 0, scaleY, 0, 0);
 	AffineTransformOp op = new AffineTransformOp(at, getRenderingHints());


Re: [cp-patches] [patch] qt-peer - fixes SEGFAULT on awt Demo

2006-06-01 Thread Sven de Marothy
On Thu, 2006-06-01 at 11:13 +0200, Boris Dušek wrote:
 On Monday 29 May 2006 11:39, Boris Dušek wrote:
  Hi,
 
  this patch fixes a SEGFAULT of gnu.classpath.examples.awt.Demo when using
  qt-peer as AWT toolkit. Not sure why it did not work before, but I have
  cleaned up the code a bit and it works now.
 
  Regards,
  Boris Dusek
 
 Hi, if there are no objections, could someone please commit this?
 Regards, Boris Dusek

Commited.
2006-06-01  Sven de Marothy  [EMAIL PROTECTED]

Patch submitted by Boris Dusek.
* native/jni/qt-peer/qtmenupeer.cpp
Fix segfault






[cp-patches] FYI: Color fix.

2006-06-01 Thread Sven de Marothy
This is needed or the pattern won't change on switching from
a texture or gradient fill to solid color.

2006-06-01  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/CairoGraphics2D.java:
(setColor): Update the cairo paint.


Index: gnu/java/awt/peer/gtk/CairoGraphics2D.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java,v
retrieving revision 1.10
diff -U3 -r1.10 CairoGraphics2D.java
--- gnu/java/awt/peer/gtk/CairoGraphics2D.java	1 Jun 2006 14:02:52 -	1.10
+++ gnu/java/awt/peer/gtk/CairoGraphics2D.java	1 Jun 2006 17:49:02 -
@@ -639,12 +639,9 @@
 if (c == null)
   c = Color.BLACK;
 
-if (! c.equals(fg))
-  {
-fg = c;
-paint = c;
-updateColor();
-  }
+fg = c;
+paint = c;
+updateColor();
   }
   
   /**


[cp-patches] FYI: OutofBounds in BufferedImageGraphics

2006-05-31 Thread Sven de Marothy
2006-05-30  Sven de Marothy  [EMAIL PROTECTED]

Should fix PR 27835
* gnu/java/awt/peer/gtk/BufferedImageGraphics.java
(updateBufferedImage): Keep within image bounds.


Index: gnu/java/awt/peer/gtk/BufferedImageGraphics.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/BufferedImageGraphics.java,v
retrieving revision 1.1
diff -U3 -r1.1 BufferedImageGraphics.java
--- gnu/java/awt/peer/gtk/BufferedImageGraphics.java	29 May 2006 16:14:59 -	1.1
+++ gnu/java/awt/peer/gtk/BufferedImageGraphics.java	31 May 2006 20:50:34 -
@@ -119,7 +119,16 @@
   private void updateBufferedImage(int x, int y, int width, int height)
   {
 int[] pixels = surface.getPixels(imageWidth * imageHeight * 4);
-
+if( x  imageWidth || y  imageHeight )
+  return;
+// Clip edges.
+if( x  0 ){ width = width + x; x = 0; }
+if( y  0 ){ height = height + y; y = 0; }
+if( x + width  imageWidth ) 
+  width = imageWidth - x;
+if( y + height  imageHeight ) 
+  height = imageHeight - y;
+
 int index = 0;
 for (int j = y; j  y + height; ++j)
   for (int i = x; i  x + width; ++i)


[cp-patches] FYI: Reimplement gradients.

2006-05-31 Thread Sven de Marothy
They work now. And in less code too.

2006-06-01  Sven de Marothy  [EMAIL PROTECTED]

* native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c
(setGradient): Reimplement.


Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c
===
RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c,v
retrieving revision 1.4
diff -U3 -r1.4 gnu_java_awt_peer_gtk_CairoGraphics2D.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c	31 May 2006 23:00:22 -	1.4
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c	31 May 2006 23:22:04 -
@@ -140,106 +140,27 @@
jboolean cyclic)
 {
   struct cairographics2d *gr = NULL;
-  cairo_surface_t *surf = NULL;
-  cairo_t *cr2 = NULL;
-  cairo_matrix_t mat;
+  cairo_pattern_t* pattern;
+  cairo_extend_t extend;
 
   gr = getPointer (env, obj);
-  g_assert (gr != NULL);
-
-  if (cyclic == JNI_TRUE)
-surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 3, 2);
-  else
-surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 2, 2);  
-  g_assert (surf != NULL);
-
-  cr2 = cairo_create (surf);
-  
-  cairo_identity_matrix (cr2);
+  g_assert( gr != NULL );
 
-  cairo_set_source_rgba (cr2, r1 / 255.0, g1 / 255.0, b1 / 255.0, a1 / 255.0);
-  cairo_rectangle (cr2, 0, 0, 1, 2);
-  cairo_fill (cr2);
-
-  cairo_set_source_rgba (cr2, r2 / 255.0, g2 / 255.0, b2 / 255.0, a2 / 255.0);
-  cairo_rectangle (cr2, 1, 0, 1, 2);
-  cairo_fill (cr2);
+  pattern = cairo_pattern_create_linear(x1, y1, x2, y2);
+  g_assert( pattern != NULL );
 
-  if (cyclic == JNI_TRUE)
-{
-  cairo_set_source_rgba (cr2, r1 / 255.0, g1 / 255.0, b1 / 255.0, a1 / 255.0);
-  cairo_rectangle (cr2, 2, 0, 1, 2);
-  cairo_fill (cr2);
-}
-
-  cairo_matrix_init_identity (mat);
+  cairo_pattern_add_color_stop_rgba(pattern, 0.0, r1 / 255.0, g1 / 255.0, 
+b1 / 255.0, a1 / 255.0);
 
-  /* 
- consider the vector [x2 - x1, y2 - y1] = [p,q]
+  cairo_pattern_add_color_stop_rgba(pattern, 1.0, r2 / 255.0, g2 / 255.0, 
+b2 / 255.0, a2 / 255.0);
 
- this is a line in space starting at an 'origin' x1, y1.
-
- it can also be thought of as a transformed unit vector in either the
- x or y directions. we have just *drawn* our gradient as a unit vector
- (well, a 2-3x unit vector) in the x dimension. so what we want to know
- is which transformation turns our existing unit vector into [p,q].
-
- which means solving for M in 
- 
- [p,q] = M[1,0]
-
- [p,q] = |a b| [1,0]
- |c d|  
-
- [p,q] = [a,c], with b = d = 0.
-
- what does this mean? it means that our gradient is 1-dimensional; as
- you move through the x axis of our 2 or 3 pixel gradient from logical
- x positions 0 to 1, the transformation of your x coordinate under the
- matrix M causes you to accumulate both x and y values in fill
- space. the y value of a gradient coordinate is ignored, since the
- gradient is one dimensional. which is correct.
-
- unfortunately we want the opposite transformation, it seems, because of
- the way cairo is going to use this transformation. I'm a bit confused by
- that, but it seems to work right, so we take reciprocals of values and
- negate offsets. oh well.
- 
-   */
-  {
-double a = (x2 - x1 == 0.) ? 0. : ((cyclic ? 3.0 : 2.0) / (x2 - x1));
-double c = (y2 - y1 == 0.) ? 0. : (1. / (y2 - y1));
-double dx = (x1 == 0.) ? 0. : 1. / x1;
-double dy = (y1 == 0.) ? 0. : 1. / y1;
-cairo_pattern_t *p;
-
-cairo_matrix_init (mat,
-   a, 0.,
-   c, 0.,
-   dx, dy);
-
-p = cairo_pattern_create_for_surface (surf);
-cairo_pattern_set_matrix (p, mat);
-cairo_pattern_set_filter (p, CAIRO_FILTER_BILINEAR);
-  }
+  extend = (cyclic == JNI_TRUE) ? CAIRO_EXTEND_REFLECT : CAIRO_EXTEND_NONE;
 
-  /* FIXME: repeating gradients (not to mention hold gradients) don't seem to work. */
-  /*   cairo_surface_set_repeat (surf, cyclic ? 1 : 0); */
+  cairo_pattern_set_extend( pattern, extend );
 
-  if (gr-pattern)
-cairo_pattern_destroy (gr-pattern);
-  
-  if (gr-pattern_surface)
-cairo_surface_destroy (gr-pattern_surface);
-
-  if (gr-pattern_pixels)
-g_free (gr-pattern_pixels);
-  
-  gr-pattern_pixels = NULL;  
-  gr-pattern_surface = surf;  
-  gr-pattern = cairo_pattern_create_for_surface(surf);
-
-  cairo_set_source (gr-cr, gr-pattern);
+  gr-pattern = pattern;
+  cairo_set_source(gr-cr, gr-pattern);
 }
 
 JNIEXPORT void JNICALL


[cp-patches] FYI: Minor image fixes

2006-05-31 Thread Sven de Marothy
2006-06-01  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/BufferedImageGraphics.java
(updateBufferedImage): Simplify.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c
(getPixels): Don't swap.


Index: gnu/java/awt/peer/gtk/BufferedImageGraphics.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/BufferedImageGraphics.java,v
retrieving revision 1.2
diff -U3 -r1.2 BufferedImageGraphics.java
--- gnu/java/awt/peer/gtk/BufferedImageGraphics.java	31 May 2006 20:52:48 -	1.2
+++ gnu/java/awt/peer/gtk/BufferedImageGraphics.java	1 Jun 2006 00:50:00 -
@@ -117,8 +117,9 @@
* Update a rectangle of the bufferedImage. This can be improved upon a lot.
*/
   private void updateBufferedImage(int x, int y, int width, int height)
-  {
+  {  
 int[] pixels = surface.getPixels(imageWidth * imageHeight * 4);
+
 if( x  imageWidth || y  imageHeight )
   return;
 // Clip edges.
@@ -128,11 +129,8 @@
   width = imageWidth - x;
 if( y + height  imageHeight ) 
   height = imageHeight - y;
-
-int index = 0;
-for (int j = y; j  y + height; ++j)
-  for (int i = x; i  x + width; ++i)
-	image.setRGB(i, j, pixels[ i + j*imageWidth ]);
+
+image.setRGB(x, y, width, height, pixels, x + y * imageWidth, imageWidth);
   }
 
   /**
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c
===
RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c,v
retrieving revision 1.8
diff -U3 -r1.8 gnu_java_awt_peer_gtk_CairoSurface.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c	31 May 2006 23:09:55 -	1.8
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c	1 Jun 2006 00:50:05 -
@@ -125,10 +125,6 @@
   jint *pixeldata, *jpixdata;
   jintArray jpixels;
 
-#ifndef WORDS_BIGENDIAN
-  int i;
-#endif
-
   pixeldata = (jint *)getNativeObject(env, obj, BUFFER);
   g_assert(pixeldata != NULL);
 
@@ -136,14 +132,6 @@
   jpixdata = (*env)-GetIntArrayElements (env, jpixels, NULL);
   memcpy (jpixdata, pixeldata, size);
 
-#ifndef WORDS_BIGENDIAN
-  /* convert pixels from 0xBBGGRRAA to 0xAARRGGBB */
-  for (i = 0; i  size; ++i)
-{
-  jpixdata[i] = SWAPU32 ((unsigned)jpixdata[i]);
-}
-#endif
-
   (*env)-ReleaseIntArrayElements (env, jpixels, jpixdata, 0);
   return jpixels;
 }


[cp-patches] FYI: Improve BufferedImageGraphics stuff

2006-05-31 Thread Sven de Marothy
2006-06-01  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/BufferedImageGraphics.java
(BufferedImageGraphics): Cache surfaces.
(updateBufferedImage): Copy directly for certain color models.
* gnu/java/awt/peer/gtk/CairoGraphics2D.java
(drawImage): Reimplement.


Index: gnu/java/awt/peer/gtk/BufferedImageGraphics.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/BufferedImageGraphics.java,v
retrieving revision 1.3
diff -U3 -r1.3 BufferedImageGraphics.java
--- gnu/java/awt/peer/gtk/BufferedImageGraphics.java	1 Jun 2006 00:57:18 -	1.3
+++ gnu/java/awt/peer/gtk/BufferedImageGraphics.java	1 Jun 2006 04:44:29 -
@@ -50,8 +50,12 @@
 import java.awt.geom.AffineTransform;
 import java.awt.image.BufferedImage;
 import java.awt.image.DataBuffer;
+import java.awt.image.DataBufferInt;
+import java.awt.image.ColorModel;
+import java.awt.image.DirectColorModel;
 import java.awt.image.RenderedImage;
 import java.awt.image.ImageObserver;
+import java.util.WeakHashMap;
 
 /**
  * Implementation of Graphics2D on a Cairo surface.
@@ -74,20 +78,55 @@
   /**
* The cairo surface that we actually draw on.
*/
-  private CairoSurface surface;
+  CairoSurface surface;
+
+  /**
+   * Cache BufferedImageGraphics instances.
+   */
+  static WeakHashMap bufferedImages = new WeakHashMap();
 
   /**
* Its corresponding cairo_t.
*/
   private long cairo_t;
-  
+
+  /**
+   * Colormodels we recognize for fast copying.
+   */  
+  static ColorModel rgb32 = new DirectColorModel(32, 0xFF, 0xFF00, 0xFF);
+  static ColorModel argb32 = new DirectColorModel(32, 0xFF, 0xFF00, 0xFF,
+		  0xFF00);
+  private boolean hasFastCM;
+  private boolean hasAlpha;
+
+
   public BufferedImageGraphics(BufferedImage bi)
   {
 this.image = bi;
 imageWidth = bi.getWidth();
 imageHeight = bi.getHeight();
+if(bi.getColorModel().equals(rgb32))
+  {
+	hasFastCM = true;
+	hasAlpha = false;
+  }
+else if(bi.getColorModel().equals(argb32))
+  {
+	hasFastCM = true;
+	hasAlpha = false;
+  }
+else
+  hasFastCM = false;
+
+// Cache surfaces.
+if( bufferedImages.get( bi ) != null )
+  surface = (CairoSurface)bufferedImages.get( bi );
+else
+  {
+	surface = new CairoSurface( imageWidth, imageHeight );
+	bufferedImages.put(bi, surface);
+  }
 
-surface = new CairoSurface( imageWidth, imageHeight );
 cairo_t = surface.newCairoContext();
 
 DataBuffer db = bi.getRaster().getDataBuffer();
@@ -97,18 +136,30 @@
 if(db instanceof CairoSurface)
   pixels = ((CairoSurface)db).getPixels(imageWidth * imageHeight * 4);
 else
-  pixels = CairoGraphics2D.findSimpleIntegerArray (image.getColorModel(),
-		   image.getData());
+  {
+	if( hasFastCM )
+	  {
+	pixels = ((DataBufferInt)db).getData();
+	if( !hasAlpha )
+	  for(int i = 0; i  pixels.length; i++)
+		pixels[i] |= 0xFF00;
+	  }
+	else
+	  pixels = CairoGraphics2D.findSimpleIntegerArray
+	(image.getColorModel(),image.getData());
+  }
 surface.setPixels( pixels );
 
 setup( cairo_t );
 setClip(0, 0, imageWidth, imageHeight);
   }
   
-  private BufferedImageGraphics(BufferedImageGraphics copyFrom)
+  BufferedImageGraphics(BufferedImageGraphics copyFrom)
   {
-
+surface = copyFrom.surface;
 cairo_t = surface.newCairoContext();
+imageWidth = copyFrom.imageWidth;
+imageHeight = copyFrom.imageHeight;
 copy( copyFrom, cairo_t );
 setClip(0, 0, surface.width, surface.height);
   }
@@ -118,7 +169,7 @@
*/
   private void updateBufferedImage(int x, int y, int width, int height)
   {  
-int[] pixels = surface.getPixels(imageWidth * imageHeight * 4);
+int[] pixels = surface.getPixels(imageWidth * imageHeight);
 
 if( x  imageWidth || y  imageHeight )
   return;
@@ -130,6 +181,13 @@
 if( y + height  imageHeight ) 
   height = imageHeight - y;
 
+if( hasFastCM )
+  {
+	System.arraycopy(pixels, y * imageWidth, 
+			 ((DataBufferInt)image.getRaster().getDataBuffer()).
+			 getData(), y * imageWidth, height * imageWidth);
+	return;
+  }
 image.setRGB(x, y, width, height, pixels, x + y * imageWidth, imageWidth);
   }
 
@@ -138,7 +196,7 @@
*/  
   public Graphics create()
   {
-return new BufferedImageGraphics( this );
+return new BufferedImageGraphics(this);
   }
   
   public GraphicsConfiguration getDeviceConfiguration()
@@ -148,7 +206,34 @@
   
   public void copyArea(int x, int y, int width, int height, int dx, int dy)
   {
-// FIXME
+// Return if outside the surface
+if( x + dx  surface.width || y + dy  surface.height )
+  return;
+
+if( x + dx + width  0 || y + dy + height  0 )
+  return;
+
+// Clip edges if necessary 
+if( x + dx  0 ) // left
+  {
+	width = x + dx + width;
+	x = -dx;
+  }
+
+if( y + dy  0

[cp-patches] FYI: Eliminate use of GdkPixbufDecoder

2006-05-30 Thread Sven de Marothy
This elimates the uses of GdkPixbufDecoder. Now Cairo-backed
BufferedImages are created via GtkImage.


2006-05-30  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/CairoGraphics2D.java
(drawImage): Use Toolkit to convert to BufferedImage.
* gnu/java/awt/peer/gtk/CairoSurface.java
(CairoSurface(GtkImage)): New Constructor.
(getBufferedImage): New method.
* gnu/java/awt/peer/gtk/ComponentGraphics.java
Don't fill background - FIXME.
* gnu/java/awt/peer/gtk/GdkPixbufDecoder.java:
Remove unused methods.
* gnu/java/awt/peer/gtk/GtkImage.java:
(pixbuflock): New field. Methods change to use this lock.
* gnu/java/awt/peer/gtk/GtkToolkit.java
(createImage): Use Cairo-backed surfaces via GtkImage instead of 
GtkPixbufDecoder.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c
(setPixels): Correct length in bytes.


Index: gnu/java/awt/peer/gtk/CairoGraphics2D.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java,v
retrieving revision 1.3
diff -U3 -r1.3 CairoGraphics2D.java
--- gnu/java/awt/peer/gtk/CairoGraphics2D.java	30 May 2006 11:53:42 -	1.3
+++ gnu/java/awt/peer/gtk/CairoGraphics2D.java	30 May 2006 21:36:33 -
@@ -1025,8 +1025,8 @@
 			  invertedXform, bgcolor);
 	  }
 	else
-	  return this.drawImage(GdkPixbufDecoder.createBufferedImage(img
- .getSource()),
+	  return this.drawImage(Toolkit.getDefaultToolkit().
+createImage(img.getSource()),
 xform, bgcolor, obs);
   }
 catch (NoninvertibleTransformException e)
Index: gnu/java/awt/peer/gtk/CairoSurface.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/CairoSurface.java,v
retrieving revision 1.2
diff -U3 -r1.2 CairoSurface.java
--- gnu/java/awt/peer/gtk/CairoSurface.java	30 May 2006 04:21:53 -	1.2
+++ gnu/java/awt/peer/gtk/CairoSurface.java	30 May 2006 21:36:33 -
@@ -145,6 +145,39 @@
   }
 
   /**
+   * Create a cairo_surface_t from a GtkImage instance.
+   * (data is copied, not shared)
+   */
+  CairoSurface(GtkImage image)
+  {
+super(DataBuffer.TYPE_INT, image.width * image.height);
+
+if(image.width = 0 || image.height = 0)
+  throw new IllegalArgumentException(Image must be at least 1x1 pixels.);
+
+width = image.width;
+height = image.height;
+
+create(width, height, width * 4);
+
+if(surfacePointer == 0 || bufferPointer == 0)
+  throw new Error(Could not allocate bitmap.);
+
+// Copy the pixel data from the GtkImage.
+int[] data = image.getPixels();
+
+// Swap ordering, since Gtk is weird.
+for(int i = 0; i  data.length; i++ )
+  {
+	int temp = (data[i]  0x00FF)  16;
+	data[i] = (data[i]  0xFF00) | ((data[i]  0x00FF)  16);
+	data[i] = (data[i]  0xFF00) | temp;
+  }
+
+setPixels( data );
+  }
+
+  /**
* Dispose of the native data.
*/
   public void dispose()
@@ -166,8 +199,25 @@
*/
   public static BufferedImage getBufferedImage(int width, int height)
   {
+return getBufferedImage(new CairoSurface(width, height));
+  }
+
+  /**
+   * Returns a BufferedImage backed by a Cairo surface, 
+   * created from a GtkImage.
+   */
+  public static BufferedImage getBufferedImage(GtkImage image)
+  {
+return getBufferedImage(new CairoSurface(image));
+  }
+
+  /**
+   * Returns a BufferedImage backed by a Cairo surface.
+   */
+  public static BufferedImage getBufferedImage(CairoSurface surface)
+  {
 WritableRaster raster = Raster.createPackedRaster
-  (new CairoSurface(width, height), width, height, width, 
+  (surface, surface.width, surface.height, surface.width, 
new int[]{ 0x00FF, 0xFF00, 0x00FF, 0xFF00 },
new Point(0,0));
 
Index: gnu/java/awt/peer/gtk/ComponentGraphics.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java,v
retrieving revision 1.3
diff -U3 -r1.3 ComponentGraphics.java
--- gnu/java/awt/peer/gtk/ComponentGraphics.java	30 May 2006 19:16:56 -	1.3
+++ gnu/java/awt/peer/gtk/ComponentGraphics.java	30 May 2006 21:36:33 -
@@ -72,8 +72,8 @@
 setup( cairo_t );
 setBackground(component.awtComponent.getBackground());
 setClip(component.awtComponent.getBounds());
-setColor( new Color( 255, 255, 255, 255 ) );
-fill(component.awtComponent.getBounds());
+// setColor( new Color( 255, 255, 255, 255 ) );
+// fill(component.awtComponent.getBounds());
 setColor(component.awtComponent.getForeground());
   }
 
Index: gnu/java/awt/peer/gtk/GdkPixbufDecoder.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk

[cp-patches] FYI: Fix transparency issue

2006-05-30 Thread Sven de Marothy
This fixes one of the regressions - transparent Images.

2006-05-30  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/CairoSurface.java:
(CairoSurface): Convert pixels properly.
* gnu/java/awt/peer/gtk/ComponentGraphics.java
Remove commented-out lines.


Index: gnu/java/awt/peer/gtk/CairoSurface.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/CairoSurface.java,v
retrieving revision 1.3
diff -U3 -r1.3 CairoSurface.java
--- gnu/java/awt/peer/gtk/CairoSurface.java	30 May 2006 21:42:56 -	1.3
+++ gnu/java/awt/peer/gtk/CairoSurface.java	30 May 2006 23:59:45 -
@@ -166,12 +166,22 @@
 // Copy the pixel data from the GtkImage.
 int[] data = image.getPixels();
 
-// Swap ordering, since Gtk is weird.
+// Swap ordering from GdkPixbuf to Cairo
 for(int i = 0; i  data.length; i++ )
   {
-	int temp = (data[i]  0x00FF)  16;
-	data[i] = (data[i]  0xFF00) | ((data[i]  0x00FF)  16);
-	data[i] = (data[i]  0xFF00) | temp;
+	int alpha = (data[i]  0xFF00)  24;
+	if( alpha == 0 ) // I do not know why we need this, but it works.
+	  data[i] = 0;
+	else
+	  {
+	int r = (((data[i]  0x00FF)  16) );
+	int g = (((data[i]  0xFF00)  8) );
+	int b = ((data[i]  0x00FF) );
+	data[i] = (( alpha  24 )  0xFF00) 
+	  | (( b  16 )  0x00FF)
+	  | (( g  8 )   0xFF00)
+	  | ( r   0x00FF);
+	  }
   }
 
 setPixels( data );
Index: gnu/java/awt/peer/gtk/ComponentGraphics.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java,v
retrieving revision 1.4
diff -U3 -r1.4 ComponentGraphics.java
--- gnu/java/awt/peer/gtk/ComponentGraphics.java	30 May 2006 21:42:56 -	1.4
+++ gnu/java/awt/peer/gtk/ComponentGraphics.java	30 May 2006 23:59:45 -
@@ -72,8 +72,6 @@
 setup( cairo_t );
 setBackground(component.awtComponent.getBackground());
 setClip(component.awtComponent.getBounds());
-// setColor( new Color( 255, 255, 255, 255 ) );
-// fill(component.awtComponent.getBounds());
 setColor(component.awtComponent.getForeground());
   }
 


[cp-patches] FYI: drawImage clipping

2006-05-30 Thread Sven de Marothy
Fix another regression.

2006-05-30  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/CairoGraphics2D.java
(drawImage): Clip scaled image to dest rectangle.


===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java	2006/05/31 00:04:30	1.6
+++ classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java	2006/05/31 03:32:26	1.7
@@ -1092,8 +1092,6 @@
 if (img == null)
   return false;
 
-Image subImage;
-
 int sourceWidth = sx2 - sx1;
 int sourceHeight = sy2 - sy1;
 
@@ -1107,26 +1105,27 @@
 double scaleX = destWidth / (double) sourceWidth;
 double scaleY = destHeight / (double) sourceHeight;
 
-// Get the subimage of the source enclosed in the 
-// rectangle specified by sx1, sy1, sx2, sy2
-	
-if (img instanceof BufferedImage)
-  {
-	BufferedImage b = (BufferedImage) img;
-	subImage = b.getSubimage(sx1, sy1, sx2, sy2);
-  }
+// FIXME: Avoid using an AT if possible here - it's at least twice as slow.
+
+Shape oldClip = getClip();
+int cx, cy, cw, ch;
+if( dx1  dx2 ) 
+  { cx = dx1; cw = dx2 - dx1; }
 else
-  {
-	CropImageFilter filter = new CropImageFilter(sx1, sx2, sx2, sy2);
-	FilteredImageSource src = new FilteredImageSource(img.getSource(),
-	  filter);
-
-	subImage = Toolkit.getDefaultToolkit().createImage(src);
-  }
+  { cx = dx2; cw = dx1 - dx2; }
+if( dy1  dy2 ) 
+  { cy = dy1; ch = dy2 - dy1; }
+else
+  { cy = dy2; ch = dy1 - dy2; }
+
+setClip( cx, cy, cw, ch );
 
-// FIXME: Avoid using an AT if possible here - it's at least twice as slow.
-return drawImage(subImage,
- new AffineTransform(scaleX, 0, 0, scaleY, dx1, dy1),
- bgcolor, observer);
+AffineTransform tx = new AffineTransform();
+tx.translate( dx1 - sx1*scaleX, dy1 - sy1*scaleY );
+tx.scale( scaleX, scaleY );
+
+boolean retval = drawImage(img, tx, bgcolor, observer);
+setClip( oldClip );
+return retval;
   }
 
   public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2,

Re: [cp-patches] [rfc] add check for Xrender for recent and future functionality.

2006-05-29 Thread Sven de Marothy
On Sun, 2006-05-28 at 20:07 -0400, Thomas Fitzsimmons wrote:
 Can you add to the GdkGraphics2D NEWS entry to mention the new XRENDER 
 dependency?  Please commit,

Well, we shouldn't really have an Xrender dependency. There's a check
there in the code for a reason. So we'll need some #ifdefs in the code
to sort this out.

/Sven




Re: [cp-patches] FYI: Return early in GdkGraphics2D.setColor

2006-05-29 Thread Sven de Marothy
On Mon, 2006-05-29 at 09:23 +0200, Audrius Meskauskas wrote:
 This patch forces to return early if the color being set is the same as 
 the current color. It improves the paint performance test result from 78 
 till 66.

Actually that screws up the copying constructor
GdkGraphics2d(GdkGraphics2d c) which explicitly calls setColor(fg) for
updating Cairo's internal state to the current color.

These patches are a bit moot though because the pending Graphics2D patch
removes the class altogether. 

/Sven




[cp-patches] Commited giant Java2D patch.

2006-05-29 Thread Sven de Marothy
Commited. With the attached patch to the previous version of
cairographics2d.c, the gtk locking was causing trouble.

2006-05-29  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/BufferedImageGraphics.java
* gnu/java/awt/peer/gtk/CairoGraphics2D.java
* gnu/java/awt/peer/gtk/CairoSurface.java
* gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java
* gnu/java/awt/peer/gtk/ComponentGraphics.java
* include/gnu_java_awt_peer_gtk_CairoGraphics2D.h
* include/gnu_java_awt_peer_gtk_CairoSurface.h
* include/gnu_java_awt_peer_gtk_ComponentGraphics.h
* native/jni/gtk-peer/cairographics2d.h
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c
New files.

* gnu/java/awt/peer/gtk/GdkGraphics2D.java
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c
* include/gnu_java_awt_peer_gtk_GdkGraphics2D.h
Removed

* include/gnu_java_awt_peer_gtk_GdkFontPeer.h
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c
* gnu/java/awt/peer/gtk/GdkFontPeer.java
(releasePeerGraphicsResource): Moved to Font peer class.

* gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java
(createGraphics): Use new context classes.

* gnu/java/awt/peer/gtk/GdkPixbufDecoder.java:
Use native BufferedImages where possible.

* gnu/java/awt/peer/gtk/GdkTextLayout.java
* include/gnu_java_awt_peer_gtk_GdkTextLayout.h
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkTextLayout.c
Move GdkGraphics2D.drawGdkTextLayout to the GdkTextLayout class,
renamed to cairoDrawGdkTextLayout.

* gnu/java/awt/peer/gtk/GtkComponentPeer.java
(getGraphics): Use ComponentGraphics context.
(createImage): Use native BufferedImage.

* gnu/java/awt/peer/gtk/GtkImage.java:
* include/gnu_java_awt_peer_gtk_GtkImage.h
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c
Remove pixmap support. (GtkImage(int, int) constructor, getGraphics)
Remove drawing methods.

* gnu/java/awt/print/JavaPrinterGraphics.java:
Use CairoSurface instead of GtkImage.

* include/Makefile.am
* native/jni/gtk-peer/Makefile.am
Update for new files.

* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkClipboard.c
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c
Remove superfluous GtkImage code for GdkPixmaps. 

* native/jni/gtk-peer/gtkpeer.h
Remove graphics2d structure.


-- 
Sven de Marothy [EMAIL PROTECTED]
--- gnu_java_awt_peer_gtk_CairoGraphics2D.c	2006-05-29 18:35:02.0 +0200
+++ classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c	2006-05-29 12:17:25.0 +0200
@@ -364,8 +364,6 @@
   float *native_positions;
   jint i = 0;
 
-  gdk_threads_enter ();
-
   g_assert (obj != NULL);
   g_assert (java_codes != NULL);
   g_assert (java_positions != NULL);
@@ -397,8 +395,6 @@
   cairo_show_glyphs (gr-cr, glyphs, n);
 
   g_free(glyphs);
-
-  gdk_threads_leave ();  
 }
 
 


[cp-patches] FYI: CairoSurface.c

2006-05-29 Thread Sven de Marothy
Fix a compiler warning

2006-05-29  Sven de Marothy  [EMAIL PROTECTED]

* native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c
(setPixels): Remove superfluous return statement.   


Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c
===
RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c,v
retrieving revision 1.1
diff -U3 -r1.1 gnu_java_awt_peer_gtk_CairoSurface.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c	29 May 2006 16:14:59 -	1.1
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c	29 May 2006 17:37:41 -
@@ -169,7 +169,6 @@
 #endif
 
   (*env)-ReleaseIntArrayElements (env, jpixels, jpixdata, 0);
-  return jpixels;
 }
 
 JNIEXPORT void JNICALL


[cp-patches] FYI: More Graphics2D stuff

2006-05-29 Thread Sven de Marothy
This implements the missing graphics context, and fixes a few small
things here and there.

2006-05-30  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/ComponentGraphicsCopy.java
* include/gnu_java_awt_peer_gtk_ComponentGraphicsCopy.h
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphicsCopy.c
New files.
* include/Makefile.am
* native/jni/gtk-peer/Makefile.am
Add new files.
* gnu/java/awt/peer/gtk/CairoSurface.java
(getSharedGtkImage): New method.
* gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c
Fix copyArea.
* gnu/java/awt/peer/gtk/ComponentGraphics.java
Support a non-xrender context.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c
Plug memory leak.
* gnu/java/awt/peer/gtk/GtkImage.java
* include/gnu_java_awt_peer_gtk_GtkImage.h
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c
(initFromBuffer): New method.   
* native/jni/gtk-peer/gtkpeer.h: 
Remove declarations of previouslyremoved methods.


/* ComponentGraphicsCopy.java
   Copyright (C) 2006 Free Software Foundation, Inc.

This file is part of GNU Classpath.

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */


package gnu.java.awt.peer.gtk;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.awt.image.RenderedImage;
import java.awt.image.ImageObserver;

/**
 * Implementation of Graphics2D for Components for servers which 
 * do not have xrender.
 *
 * A mirrored GtkImage of the component is stored in memory
 * and copied back. Yay.
 */
public class ComponentGraphicsCopy extends CairoSurfaceGraphics
{
  private GtkComponentPeer component;

  /**
   * GtkImage sharing its data buffer with this Cairo surface.
   */
  private GtkImage gtkimage;
  
  private int width, height;

  native void getPixbuf( GtkComponentPeer component, GtkImage image );

  native void copyPixbuf( GtkComponentPeer component, GtkImage image, 
			  int x, int y, int w, int h );

  public ComponentGraphicsCopy(int width, int height, 
			   GtkComponentPeer component)
  { 
super( new CairoSurface( width, height ) );
this.component = component;
this.width = width;
this.height = height;
gtkimage = surface.getSharedGtkImage();
getPixbuf( component, gtkimage );
  }

  /**
   * Overloaded methods that do actual drawing need to enter the gdk threads 
   * and also do certain things before and after.
   */
  public void draw(Shape s)
  {
super.draw(s);
Rectangle r = s.getBounds();
copyPixbuf(component, gtkimage, r.x, r.y, r.width, r.height);
  }

  public void fill(Shape s)
  {
super.fill(s);
Rectangle r = s.getBounds();
copyPixbuf(component, gtkimage, r.x, r.y, r.width, r.height);
  }

  public void drawRenderedImage(RenderedImage image, AffineTransform xform)
  {
super.drawRenderedImage(image, xform);
copyPixbuf(component, gtkimage, 0, 0, width, height);
  }

  protected boolean drawImage(Image img

Re: [cp-patches] [rfc] add check for Xrender for recent and future functionality.

2006-05-29 Thread Sven de Marothy
Sorting out the Xrender crap:
1) There's now a non-Xrender graphics context

2) There already is checking for Xrender in place through
XRenderQueryExtension. If that requires the xrender library then that is
no new problem. The code that calls that has been in Classpath FOR
ALMOST THREE YEARS.

So please stop telling *me* about this. I didn't add any dependencies
that were not there already. No, I don't know how to fix it. 

/Sven




Re: [cp-patches] [patch] qtpeers, silence some warnings with gcc-4.2

2006-05-26 Thread Sven de Marothy
On Fri, 2006-05-26 at 15:23 -0600, Tom Tromey wrote:
  Andreas == Andreas Tobler [EMAIL PROTECTED] writes:
 
 Andreas classpath/native/jni/qt-peer/eventmethods.h:111: warning: deprecated
 Andreas conversion from string constant to 'char*''
 
 Andreas There are quite a lot of them. And they pop up in gcc-head.
 
 Andreas Ok to commit?
 
 I think it is ok.  However, let's wait a couple days in case Sven
 wants to respond; this is all his code.

Looks fine by me, thanks.

/Sven




Re: [cp-patches] Patch: FYI: implement guessContentTypeFromStream

2006-05-25 Thread Sven de Marothy
On Thu, 2006-05-25 at 11:39 -0600, Tom Tromey wrote:
 I'm submitting this for comment before checking it in.
 
 This implements URLConnection.guessContentTypeFromStream.  It adds a
 new VMURLConnection class to which the method defers.  The reference
 implementation of this VM class uses 'libmagic' to guess the content
 type; libmagic is part of the 'file' package on Linux systems and
 presents a nice, simple API to this functionality.
 

Looks good to me. I don't really have any concerns about libmagic. It's
included with all Linux distos I know of (even if isn't in LSB), all BSD
distros I know of and even OS X. 

So short of having no external dependency at all, this is probably as
good as it can get.

/Sven




[cp-patches] FYI: DragGestureRecognizer

2006-05-24 Thread Sven de Marothy
I implemented these two missing methods.

2006-05-24  Sven de Marothy  [EMAIL PROTECTED]

* java/awt/dnd/DragGestureRecognizer.java
(resetRecognizer): Implement.
(fireDragGestureRecognized): Implement.


Index: java/awt/dnd/DragGestureRecognizer.java
===
RCS file: /sources/classpath/classpath/java/awt/dnd/DragGestureRecognizer.java,v
retrieving revision 1.4
diff -U3 -r1.4 DragGestureRecognizer.java
--- java/awt/dnd/DragGestureRecognizer.java	22 Mar 2006 19:15:24 -	1.4
+++ java/awt/dnd/DragGestureRecognizer.java	24 May 2006 19:32:27 -
@@ -1,5 +1,5 @@
 /* DragGestureRecognizer.java --
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002,2006 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -130,7 +130,7 @@
   public void resetRecognizer()
 throws NotImplementedException
   {
-throw new Error(not implemented);
+events = new ArrayList();
   }
 
   /**
@@ -154,10 +154,15 @@
 dragGestureListener = null;
   }
 
+  /**
+   * Fires a codeDragGestureEvent/code to the DragGestureListener
+   * associated with this object, if there is one.
+   */
   protected void fireDragGestureRecognized(int dragAction, Point p)
-throws NotImplementedException
   {
-throw new Error(not implemented);
+if(dragGestureListener != null)
+  dragGestureListener.dragGestureRecognized
+	(new DragGestureEvent(this, dragAction, p, events));
   }
 
   protected void appendEvent(InputEvent e)


Re: [cp-patches] RFC: GdkScreenGraphicsDevice et all implementation - preview patch

2006-05-23 Thread Sven de Marothy
On Mon, 2006-05-22 at 22:53 +0200, Robert Schuster wrote:

 The way its done now is pretty simple and there is much room for enhancement.
 However I want to have some feedback on the current state because I am new to
 Gdk/Gtk+ and Xlib/XRandR programming and had to work myself into the goodness 
 of
 Classpath' Magical NSA API ... ;)

I'm not sure we should use the NSA stuff for new code. I personally
don't think it's a very good solution. It obfuscates where the actual
data is at behind an undocumented and unintuitive set of macros. It also
makes it harder to see what native data structures the java classes map
to. It's one of the things that makes understanding and working on the
Gtk peers more difficult. The Pointer/Pointer32/Pointer64 classes also
do their job in contributing. 

Storing the native pointer as a simple long field works just fine on any
platform. I don't see the point of not Keeping It Simple.

/Sven




[cp-patches] Re: RFC: GDK backend for AbstractGraphics2D

2006-05-21 Thread Sven de Marothy
Hey,
Here's a patch which might be of use..

I created a GtkImage.getBufferedImage() method which returns a
BufferedImage backed by the GtkImage. (Only works for the pixbuf
GtkImages at the moment though, so it's not terribly useful.)

Attached is a small demo too. Works on my machine.

/Sven


Index: gnu/java/awt/Buffers.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/Buffers.java,v
retrieving revision 1.5
diff -U3 -r1.5 Buffers.java
--- gnu/java/awt/Buffers.java	2 Jul 2005 20:32:10 -	1.5
+++ gnu/java/awt/Buffers.java	21 May 2006 07:12:56 -
@@ -208,7 +208,10 @@
   }
 else
   {
-	throw new ClassCastException(Unknown data buffer type);
+	if( dest == null ) dest = new int[length + destOffset];
+	for(int i = 0; i  length; i++)
+	  ((int[])dest)[destOffset + i] = src.getElem(0, srcOffset + i);
+	return dest;
   }
 
 System.arraycopy(from, srcOffset, dest, destOffset, length);
Index: gnu/java/awt/peer/gtk/GtkImage.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/GtkImage.java,v
retrieving revision 1.28
diff -U3 -r1.28 GtkImage.java
--- gnu/java/awt/peer/gtk/GtkImage.java	6 May 2006 21:10:11 -	1.28
+++ gnu/java/awt/peer/gtk/GtkImage.java	21 May 2006 07:12:56 -
@@ -41,12 +41,15 @@
 import java.awt.Graphics;
 import java.awt.Color;
 import java.awt.Image;
+import java.awt.Point;
 import java.awt.image.ColorModel;
+import java.awt.image.DataBuffer;
 import java.awt.image.DirectColorModel;
 import java.awt.image.MemoryImageSource;
 import java.awt.image.ImageConsumer;
 import java.awt.image.ImageObserver;
 import java.awt.image.ImageProducer;
+import java.awt.image.*;
 import java.io.File;
 import java.io.IOException;
 import java.util.Hashtable;
@@ -116,9 +119,9 @@
* The 32-bit AABBGGRR format the GDK uses.
*/
   static ColorModel nativeModel = new DirectColorModel(32, 
-		   0x00FF,
-		   0xFF00,
 		   0x00FF,
+		   0xFF00,
+		   0x00FF,
 		   0xFF00);
 
   /**
@@ -669,4 +672,52 @@
   }
 return false;
   }
+
+
+  public BufferedImage getBufferedImage()
+  {
+if(offScreen)
+  throw new IllegalArgumentException(Pixbuf only);
+
+WritableRaster raster = Raster.createPackedRaster
+  (new NativeDataBuffer(this), width, height,
+   width, new int[]{ 0x00FF, 0xFF00, 0x00FF, 0xFF00 },
+   new Point(0,0));
+
+return new BufferedImage(nativeModel, raster, false, new Hashtable());
+  }
+
+  /**
+   * Provides access to pixel data - PIXBUF ONLY.
+   */
+  private native int getElem(int i);
+
+  /**
+   * Provides access to pixel data - PIXBUF ONLY.
+   */
+  private native void setElem(int i, int val);
+
+  /**
+   * Provides access to pixel data - PIXBUF ONLY.
+   */
+  public class NativeDataBuffer extends DataBuffer
+  {
+private GtkImage image;
+
+public NativeDataBuffer(GtkImage image)
+{
+  super(DataBuffer.TYPE_INT, image.width * image.height);
+  this.image = image;
+}
+
+public int getElem(int bank, int i)
+{
+  return image.getElem(i);
+}
+
+public void setElem(int bank, int i, int val)
+{
+  image.setElem(i, val);
+}
+  }
 }
Index: include/gnu_java_awt_peer_gtk_GtkImage.h
===
RCS file: /sources/classpath/classpath/include/gnu_java_awt_peer_gtk_GtkImage.h,v
retrieving revision 1.6
diff -U3 -r1.6 gnu_java_awt_peer_gtk_GtkImage.h
--- include/gnu_java_awt_peer_gtk_GtkImage.h	30 Apr 2006 10:37:36 -	1.6
+++ include/gnu_java_awt_peer_gtk_GtkImage.h	21 May 2006 07:12:57 -
@@ -20,6 +20,8 @@
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkImage_drawPixelsScaled (JNIEnv *env, jobject, jobject, jint, jint, jint, jint, jint, jint, jint, jboolean);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkImage_drawPixelsScaledFlipped (JNIEnv *env, jobject, jobject, jint, jint, jint, jboolean, jboolean, jint, jint, jint, jint, jint, jint, jint, jint, jboolean);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkImage_createFromPixbuf (JNIEnv *env, jobject);
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_gtk_GtkImage_getElem(JNIEnv *env, jobject, jint);
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkImage_setElem(JNIEnv *env, jobject, jint, jint);
 
 #ifdef __cplusplus
 }
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c
===
RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c,v
retrieving revision 1.19
diff -U3 -r1.19 gnu_java_awt_peer_gtk_GtkImage.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c	13 May 2006 15:05:12 -	1.19
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c	21 May 2006 07:12:57 -
@@ -505,6 +505,62 @@
   

[cp-patches] FYI: CharBuffer.wrap() bounds check

2006-05-21 Thread Sven de Marothy
charAt() already throws ArrayIndexOutOfBounds for us, 
and the (end  (length() - start)) check was wrong.

2006-05-22  Sven de Marothy  [EMAIL PROTECTED]

* java/nio/CharBuffer.java
(wrap): Fix bounds checking.

Index: java/nio/CharBuffer.java
===
RCS file: /sources/classpath/classpath/java/nio/CharBuffer.java,v
retrieving revision 1.25
diff -U3 -r1.25 CharBuffer.java
--- java/nio/CharBuffer.java	2 Jul 2005 20:32:39 -	1.25
+++ java/nio/CharBuffer.java	22 May 2006 00:12:44 -
@@ -107,14 +107,12 @@
   {
 // FIXME: implement better handling of java.lang.String.
 // Probably share data with String via reflection.
-	  
-if ((start  0)
-|| (start  seq.length())
-|| (end  start)
-|| (end  (seq.length() - start)))
-  throw new IndexOutOfBoundsException();
-
+	 
 int len = end - start;
+
+if( len  0 )
+  throw new IndexOutOfBoundsException();
+
 char[] buffer = new char[len];
 
 for (int i = 0; i  len; i++)


[cp-patches] FYI: Graphics2D for printing

2006-05-20 Thread Sven de Marothy
Here's an initial Graphics2D implementation for printing. Still doesn't 
handle copyArea and composites, but since it's still a lot better than
the other PrinterGraphics impl, I'm making this one the default now.

2006-05-20  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/print/JavaPrinterJob.java 
(print): Use PostScriptGraphics2D.
* gnu/java/awt/print/PostScriptGraphics2D.java: New file.


Index: gnu/java/awt/print/JavaPrinterJob.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/print/JavaPrinterJob.java,v
retrieving revision 1.3
diff -U3 -r1.3 JavaPrinterJob.java
--- gnu/java/awt/print/JavaPrinterJob.java	15 May 2006 01:54:19 -	1.3
+++ gnu/java/awt/print/JavaPrinterJob.java	20 May 2006 07:55:16 -
@@ -260,7 +260,7 @@
 if( printable == null  pageable == null ) // nothing to print?
   return;
 
-JavaPrinterGraphics pg = new JavaPrinterGraphics( this );
+PostScriptGraphics2D pg = new PostScriptGraphics2D( this );
 SpooledDocument doc = pg.spoolPostScript( printable, pageFormat, 
 	  pageable );
 
/* PostScriptGraphics2D.java -- AWT printer rendering class.
   Copyright (C) 2006  Free Software Foundation, Inc.

This file is part of GNU Classpath.

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */

package gnu.java.awt.print;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Paint;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.AffineTransform;
import java.awt.geom.Arc2D;
import java.awt.geom.Ellipse2D;
import java.awt.geom.RoundRectangle2D;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.font.TextLayout;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.renderable.RenderableImage;
import java.awt.image.RenderedImage;
import java.awt.image.ImageObserver;
import java.awt.image.PixelGrabber;
import java.awt.print.PageFormat;
import java.awt.print.Pageable;
import java.awt.print.Paper;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterGraphics;
import java.awt.print.PrinterJob;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.text.AttributedCharacterIterator;
import java.util.Map;

/**
 * Class PostScriptGraphics2D - Class that implements the Graphics2D object,
 * writing the output to a PostScript or EPS file
 *
 * @author Sven de Marothy
 *
 */
class PostScriptGraphics2D extends Graphics2D
{
  /**
   * The associated printer job.
   */
  private PrinterJob printerJob;

  /**
   * Output file.
   */
  private PrintWriter out;

  // Graphics data
  private AffineTransform currentTransform = new AffineTransform();
  private AffineTransform pageTransform;
  private RenderingHints renderingHints;
  private Paint

[cp-patches] FYI: Font.getNumGlyphs()

2006-05-20 Thread Sven de Marothy
2006-05-20  Sven de Marothy  [EMAIL PROTECTED]

* java/awt/Font.java (getNumGlyphs): Call correct peer method.


Index: java/awt/Font.java
===
RCS file: /sources/classpath/classpath/java/awt/Font.java,v
retrieving revision 1.33
diff -U3 -r1.33 Font.java
--- java/awt/Font.java	3 Oct 2005 00:13:52 -	1.33
+++ java/awt/Font.java	20 May 2006 12:49:24 -
@@ -1013,7 +1013,7 @@
*/
   public int getNumGlyphs()
   {
-return peer.getMissingGlyphCode(this);
+return peer.getNumGlyphs(this);
   }
 
   /**


[cp-patches] Font work - build help needed.

2006-05-20 Thread Sven de Marothy
Hello all,
This patch implements several missing GdkFontPeer methods, and provides
a native method to give access to TrueType tables straight from the java
side.

This requires the freetype2 libraries, which isn't much of a dependency
problem. But when building I found myself needing to stick a -lfreetype
in there, so I need someone to help config the build scripts for this.

/Sven
Index: gnu/java/awt/peer/gtk/GdkFontPeer.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/GdkFontPeer.java,v
retrieving revision 1.9
diff -U3 -r1.9 GdkFontPeer.java
--- gnu/java/awt/peer/gtk/GdkFontPeer.java	19 Mar 2006 23:02:42 -	1.9
+++ gnu/java/awt/peer/gtk/GdkFontPeer.java	20 May 2006 12:49:23 -
@@ -53,6 +53,8 @@
 import java.util.Locale;
 import java.util.Map;
 import java.util.ResourceBundle;
+import java.nio.ByteBuffer;
+import java.io.UnsupportedEncodingException;
 
 public class GdkFontPeer extends ClasspathFontPeer
 {
@@ -156,9 +158,58 @@
 return null;
   }
 
+  /**
+   * Returns the bytes belonging to a TrueType/OpenType table,
+   * Parameters n,a,m,e identify the 4-byte ASCII tag of the table.
+   *
+   * Returns null if the font is not TT, the table is nonexistant, 
+   * or if some other unexpected error occured.
+   *
+   */
+  private native byte[] getTrueTypeTable(byte n, byte a, byte m, byte e);
+
+  /**
+   * Returns the PostScript name of the font, defaults to the familyName if 
+   * a PS name could not be retrieved.
+   */
   public String getPostScriptName(Font font)
   {
-return this.familyName;
+byte[] bits = getTrueTypeTable((byte)'n', (byte) 'a', 
+   (byte) 'm', (byte) 'e');
+try 
+  {
+	if(bits == null)
+	  return this.familyName;
+	String s = parsePSName(bits);
+	if( s == null )
+	  return this.familyName;
+	return s;
+  } 
+catch(UnsupportedEncodingException e)
+  {
+	return this.familyName;
+  }
+  }
+
+  private String parsePSName(byte[] bits) throws UnsupportedEncodingException
+  {
+ByteBuffer buf = ByteBuffer.wrap( bits );
+int count = buf.getShort(2);
+int stringOffset = buf.getShort(4);
+
+for(int i = 0; i  count; i++)
+  if(buf.getShort(12 + 12 * i) == 6)
+	{
+	  int length = buf.getShort(14 + 12 * i);
+	  int offset = buf.getShort(16 + 12 * i);
+	  // Check if it's ASCII or Unicode
+	  if(bits[stringOffset + offset] == 0)
+	return new String(bits, stringOffset + offset, length, UTF-16BE);
+	  else
+	return new String(bits, stringOffset + offset, length, ASCII);
+	}
+
+return null;
   }
 
   public boolean canDisplay (Font font, char c)
@@ -265,7 +316,13 @@
 
   public int getNumGlyphs (Font font)
   {
-throw new UnsupportedOperationException ();
+byte[] data = getTrueTypeTable((byte)'m', (byte) 'a', 
+   (byte)'x', (byte) 'p');
+if( data == null )
+  return -1;
+
+ByteBuffer buf = ByteBuffer.wrap( data );   
+return buf.getShort(4);
   }
 
   public Rectangle2D getStringBounds (Font font, CharacterIterator ci, 
Index: include/gnu_java_awt_peer_gtk_GdkFontPeer.h
===
RCS file: /sources/classpath/classpath/include/gnu_java_awt_peer_gtk_GdkFontPeer.h,v
retrieving revision 1.5
diff -U3 -r1.5 gnu_java_awt_peer_gtk_GdkFontPeer.h
--- include/gnu_java_awt_peer_gtk_GdkFontPeer.h	30 Apr 2006 10:37:36 -	1.5
+++ include/gnu_java_awt_peer_gtk_GdkFontPeer.h	20 May 2006 12:49:24 -
@@ -17,6 +17,7 @@
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkFontPeer_getFontMetrics (JNIEnv *env, jobject, jdoubleArray);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkFontPeer_getTextMetrics (JNIEnv *env, jobject, jstring, jdoubleArray);
 JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_gtk_GdkFontPeer_getGlyphVector (JNIEnv *env, jobject, jstring, jobject, jobject);
+JNIEXPORT jbyteArray JNICALL Java_gnu_java_awt_peer_gtk_GdkFontPeer_getTrueTypeTable (JNIEnv *env, jobject, jbyte, jbyte, jbyte, jbyte);
 
 #ifdef __cplusplus
 }
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c
===
RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c,v
retrieving revision 1.15
diff -U3 -r1.15 gnu_java_awt_peer_gtk_GdkFontPeer.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c	3 Apr 2006 10:00:05 -	1.15
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c	20 May 2006 12:49:24 -
@@ -35,6 +35,13 @@
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */
 
+#include pango/pango.h
+#include pango/pangoft2.h
+#include pango/pangofc-font.h
+#include freetype/ftglyph.h
+#include freetype/ftoutln.h
+#include freetype/fttypes.h
+#include freetype/tttables.h
 #include gdkfont.h
 #include gnu_java_awt_peer_gtk_GdkFontPeer.h
 
@@ -465,3 +472,64 @@
 }
 
 
+JNIEXPORT jbyteArray 

[cp-patches] Re: RFC: GDK backend for AbstractGraphics2D

2006-05-20 Thread Sven de Marothy
Hey,
I'm not sure I quite support this yet, since it does mean losing some
existing functionality. (For instance, drawing a dashed line)
(Not that I don't hate the Cairo peer mess as much as anyone else..)

What I think I'd really prefer for the time being would be to keep the
Cairo Graphics2D around a bit longer and just bump GtkGraphics up
to Graphics2D-using-AbstractGraphics2D. 

Would that be OK?

/Sven

On Sat, 2006-05-20 at 05:43 -0400, Thomas Fitzsimmons wrote:
 Hi,
 
 This is a work-in-progress patch to provide a GDK backend for 
 AbstractGraphics2D and also to ready the codebase for further Java2D 
 development.
 
 It turned out that making a GDK backend was (almost) as simple as 
 moving GdkGraphics under AbstractGraphics2D in the inheritance 
 hierarchy.  Graphics-using applications will see little change in 
 performance/correctness with this patch, since GdkGraphics overrides all 
 of AbstractGraphics2D's Graphics methods.
 
 I also removed all mention of GdkGraphics2D and Cairo.  If it turns out 
 that we can accelerate AbstractGraphics2D with Cairo methods, then all 
 we'll need to do is bump the GTK release requirement to 2.8 (which 
 brings in Cairo headers and libraries by default), and move any code we 
 need from GdkGraphics2D into Graphics.  For now, I wanted to eliminate 
 the complexity of --enable-gtk-cairo and 
 -Dgnu.java.awt.peer.gtk.Graphics while we experiment with 
 AbstractGraphics2D.
 
 As you can see by commenting out GdkGraphics.fillRect (which causes 
 AbstractGraphics2D's fillRect to be activated), pixel colors are all 
 wrong.  I haven't investigated why yet.
 
 Comments?  If people don't consider this too drastic, I'll finish it off 
 and commit it this week.
 
 Tom




Re: [cp-patches] Font work - build help needed.

2006-05-20 Thread Sven de Marothy
 Hi Sven,
 
 The patch builds fine here without any build changes.  FreeType is
 already checked for in configure.ac and included in the Makefile.am of
 the GTK+ peers, so in theory, it should be working.  What platform did
 you run into this problem on?  Presumably, FreeType is being found by
 configure?

Ok good. That's what I thought should be the case too, but it wasn't
working on my machine. I think I know what the problem is though.
(A nasty proprietary program I have installed which uses FT1, so in 
certain shells FT1 is in the LD_LIBRARY_PATH, which probably screws
things up)

I'll check it in then. (Unless somone has a problem with it)

/Sven




[cp-patches] Re: Font work - build help needed.

2006-05-20 Thread Sven de Marothy
Commited the aforementioned patch.

2006-05-20  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/GdkFontPeer.java
(getTrueTypeTable): New native method.
(getPostScriptName): Reimplement.
(parsePSName): New method.
(getNumGlyphs): Implement.
* include/gnu_java_awt_peer_gtk_GdkFontPeer.h: New native method.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c
(Java_gnu_java_awt_peer_gtk_GdkFontPeer_getTrueTypeTable):
New function. File is now explicitly dependent on FT2.


Index: gnu/java/awt/peer/gtk/GdkFontPeer.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/GdkFontPeer.java,v
retrieving revision 1.9
diff -U3 -r1.9 GdkFontPeer.java
--- gnu/java/awt/peer/gtk/GdkFontPeer.java	19 Mar 2006 23:02:42 -	1.9
+++ gnu/java/awt/peer/gtk/GdkFontPeer.java	20 May 2006 12:49:23 -
@@ -53,6 +53,8 @@
 import java.util.Locale;
 import java.util.Map;
 import java.util.ResourceBundle;
+import java.nio.ByteBuffer;
+import java.io.UnsupportedEncodingException;
 
 public class GdkFontPeer extends ClasspathFontPeer
 {
@@ -156,9 +158,58 @@
 return null;
   }
 
+  /**
+   * Returns the bytes belonging to a TrueType/OpenType table,
+   * Parameters n,a,m,e identify the 4-byte ASCII tag of the table.
+   *
+   * Returns null if the font is not TT, the table is nonexistant, 
+   * or if some other unexpected error occured.
+   *
+   */
+  private native byte[] getTrueTypeTable(byte n, byte a, byte m, byte e);
+
+  /**
+   * Returns the PostScript name of the font, defaults to the familyName if 
+   * a PS name could not be retrieved.
+   */
   public String getPostScriptName(Font font)
   {
-return this.familyName;
+byte[] bits = getTrueTypeTable((byte)'n', (byte) 'a', 
+   (byte) 'm', (byte) 'e');
+try 
+  {
+	if(bits == null)
+	  return this.familyName;
+	String s = parsePSName(bits);
+	if( s == null )
+	  return this.familyName;
+	return s;
+  } 
+catch(UnsupportedEncodingException e)
+  {
+	return this.familyName;
+  }
+  }
+
+  private String parsePSName(byte[] bits) throws UnsupportedEncodingException
+  {
+ByteBuffer buf = ByteBuffer.wrap( bits );
+int count = buf.getShort(2);
+int stringOffset = buf.getShort(4);
+
+for(int i = 0; i  count; i++)
+  if(buf.getShort(12 + 12 * i) == 6)
+	{
+	  int length = buf.getShort(14 + 12 * i);
+	  int offset = buf.getShort(16 + 12 * i);
+	  // Check if it's ASCII or Unicode
+	  if(bits[stringOffset + offset] == 0)
+	return new String(bits, stringOffset + offset, length, UTF-16BE);
+	  else
+	return new String(bits, stringOffset + offset, length, ASCII);
+	}
+
+return null;
   }
 
   public boolean canDisplay (Font font, char c)
@@ -265,7 +316,13 @@
 
   public int getNumGlyphs (Font font)
   {
-throw new UnsupportedOperationException ();
+byte[] data = getTrueTypeTable((byte)'m', (byte) 'a', 
+   (byte)'x', (byte) 'p');
+if( data == null )
+  return -1;
+
+ByteBuffer buf = ByteBuffer.wrap( data );   
+return buf.getShort(4);
   }
 
   public Rectangle2D getStringBounds (Font font, CharacterIterator ci, 
Index: include/gnu_java_awt_peer_gtk_GdkFontPeer.h
===
RCS file: /sources/classpath/classpath/include/gnu_java_awt_peer_gtk_GdkFontPeer.h,v
retrieving revision 1.5
diff -U3 -r1.5 gnu_java_awt_peer_gtk_GdkFontPeer.h
--- include/gnu_java_awt_peer_gtk_GdkFontPeer.h	30 Apr 2006 10:37:36 -	1.5
+++ include/gnu_java_awt_peer_gtk_GdkFontPeer.h	20 May 2006 12:49:24 -
@@ -17,6 +17,7 @@
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkFontPeer_getFontMetrics (JNIEnv *env, jobject, jdoubleArray);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkFontPeer_getTextMetrics (JNIEnv *env, jobject, jstring, jdoubleArray);
 JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_gtk_GdkFontPeer_getGlyphVector (JNIEnv *env, jobject, jstring, jobject, jobject);
+JNIEXPORT jbyteArray JNICALL Java_gnu_java_awt_peer_gtk_GdkFontPeer_getTrueTypeTable (JNIEnv *env, jobject, jbyte, jbyte, jbyte, jbyte);
 
 #ifdef __cplusplus
 }
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c
===
RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c,v
retrieving revision 1.15
diff -U3 -r1.15 gnu_java_awt_peer_gtk_GdkFontPeer.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c	3 Apr 2006 10:00:05 -	1.15
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c	20 May 2006 12:49:24 -
@@ -35,6 +35,13 @@
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */
 
+#include pango/pango.h
+#include pango/pangoft2.h
+#include pango/pangofc-font.h
+#include freetype/ftglyph.h
+#include freetype

[cp-patches] FYI: MinimalHTMLWriter

2006-05-19 Thread Sven de Marothy
Hey, implemented this. 
It still doesn't work well due to remaining bugs in AbstractWriter,
StyledDocument, etc. But it works fine on the JDK.

2006-05-20  Sven de Marothy  [EMAIL PROTECTED]

* javax/swing/text/html/MinimalHTMLWriter.java: New file


/* MinimalHTMLWriter.java -- 
   Copyright (C) 2006 Free Software Foundation, Inc.

This file is part of GNU Classpath.

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */

package javax.swing.text.html;

import javax.swing.text.AttributeSet;
import javax.swing.text.AbstractWriter;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.Element;
import javax.swing.text.ElementIterator;
import javax.swing.text.StyleConstants;
import javax.swing.text.Style;
import javax.swing.text.StyledDocument;
import java.io.Writer;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Stack;
import java.awt.Color;

/**
 * MinimalHTMLWriter,
 * A minimal AbstractWriter implementation for HTML.
 *
 * @author Sven de Marothy
 */
public class MinimalHTMLWriter extends AbstractWriter 
{
  private StyledDocument doc;
  private Stack tagStack;
  private boolean inFontTag = false;

  /**
   * Constructs a MinimalHTMLWriter.
   * @param w - a Writer, for output.
   * @param doc - the document
   */
  public MinimalHTMLWriter(Writer w, StyledDocument doc)
  {
super(w, doc);
this.doc = doc;
tagStack = new Stack();
  }

  /**
   * Constructs a MinimalHTMLWriter.
   * @param w - a Writer, for output.
   * @param doc - the document
   * @param pos - start position
   * @param len - length
   */
  public MinimalHTMLWriter(Writer w, StyledDocument doc, int pos, int len)
  {
super(w, doc, pos, len);
this.doc = doc;
tagStack = new Stack();
  }

  /**
   * Starts a span tag.
   */
  protected void startFontTag(String style) throws IOException
  {
if( inFontTag() )
  endOpenTags();
writeStartTag(span style=\+style+\);
inFontTag = true;
  }

  /**
   * Returns whether the writer is within two span tags.
   */
  protected boolean inFontTag()
  {
return inFontTag;
  }

  /**
   * Ends a span tag.
   */
  protected void endFontTag() throws IOException
  {
writeEndTag(/span);
inFontTag = false;
  }

  /**
   * Write the entire HTML document.
   */
  public synchronized void write() throws IOException, BadLocationException
  {
writeStartTag(html);
writeHeader();
writeBody();
writeEndTag(/html);
  }

  /**
   * Write a start tag and increment the indent.
   */
  protected void writeStartTag(String tag) throws IOException
  {
indent();
write(tag+NEWLINE);
incrIndent();
  }

  /**
   * Write an ending tag and decrement the indent.
   */
  protected void writeEndTag(String endTag) throws IOException
  {
decrIndent();
indent();
write(endTag+NEWLINE);
  }

  /**
   * Write the HTML header.
   */
  protected void writeHeader() throws IOException 
  {
writeStartTag(head);
writeStartTag(style);
writeStartTag(!--);
writeStyles();
writeEndTag(--);
writeEndTag(/style);
writeEndTag(/head);
  }

  /**
   * Write a paragraph start tag.
   */
  protected void writeStartParagraph(Element elem) throws IOException
  {  
indent();
write(p class=default+NEWLINE); // FIXME: Class value = ?
incrIndent();
  }

  /**
   * Write a paragraph end tag

[cp-patches] FYI: Parenthesis added

2006-05-15 Thread Sven de Marothy
2006-05-15  Sven de Marothy  [EMAIL PROTECTED]

* native/target/generic/target_generic_network.h: 
Add a pair of parenthesis.


-- 
Sven de Marothy [EMAIL PROTECTED]
Index: native/target/generic/target_generic_network.h
===
RCS file: /sources/classpath/classpath/native/target/generic/target_generic_network.h,v
retrieving revision 1.22
diff -U3 -r1.22 target_generic_network.h
--- native/target/generic/target_generic_network.h	12 May 2006 20:59:31 -	1.22
+++ native/target/generic/target_generic_network.h	15 May 2006 23:19:46 -
@@ -682,8 +682,8 @@
   \
   __value.tv_sec = flag / 1000; \
   __value.tv_usec = (flag % 1000) * 1000; \
-  result = ( setsockopt(socketDescriptor, SOL_SOCKET, SO_SNDTIMEO, __value, sizeof(__value)) | \
-		setsockopt(socketDescriptor, SOL_SOCKET, SO_RCVTIMEO, __value, sizeof(__value)) == 0) ? TARGET_NATIVE_OK : TARGET_NATIVE_ERROR; \
+  result = ( (setsockopt(socketDescriptor, SOL_SOCKET, SO_SNDTIMEO, __value, sizeof(__value)) | \
+		  setsockopt(socketDescriptor, SOL_SOCKET, SO_RCVTIMEO, __value, sizeof(__value))) == 0) ? TARGET_NATIVE_OK : TARGET_NATIVE_ERROR; \
 } while (0)
 #endif
 


Re: [cp-patches] FYI: Socket timeout impl and fix

2006-05-14 Thread Sven de Marothy
On Sun, 2006-05-14 at 00:17 -0700, Casey Marshall wrote:
 On May 12, 2006, at 2:06 PM, Sven de Marothy wrote:
 
  This adds the 1.5 timeout methods in URLConnection and implements them
  for HttUrlConnection (and HttpsUrlConnection).
 
  It also fixes a long-standing bug in the native-target-layer aicas
  thingie. SO_TIMEOUT timeout was being used as a socket option, when  
  it's
  the name of the Java socket option. The POSIX constants are  
  SO_SNDTIMEO
  and SO_RCVTIMEO. So timeouts actually work now.
  (I could say something nasty here about preprocessor macros.. )
 
 
 This introduces a warning, and thus doesn't compile with -Werror, and  
 generally doesn't look right (should the operator be `||' and not  
 `|'? Otherwise, you aren't short-circuiting the second call to  
 `setsockopt' if the first fails). Removing the warning just means  
 putting parentheses around the `|' operation.

No, '|' is what was intended. My intent is that it should fail if either
call returns a nonzero (error) result.

I should add a parenthesis though.

/Sven




Re: [cp-patches] FYI: Socket timeout impl and fix

2006-05-14 Thread Sven de Marothy
On Sun, 2006-05-14 at 12:45 -0700, Casey Marshall wrote:

 Yeah, I figured out what you were doing when going to sleep last  
 night ;-)
 
 But still, wouldn't an  be better for that?

if( callA() == 0  callB() == 0 )
 result = value1;
else
 result = value2;

Versus:

result = ((callA() | callB()) == 0) ? value1 : value2;

See? Shorter code! ;)

-- 
Sven de Marothy [EMAIL PROTECTED]




[cp-patches] FYI: More AWT printing

2006-05-14 Thread Sven de Marothy
This implements cancellable jobs, proper support for Pageable and also
reverse landscape. Whatever people want that for.

It's still slow of course.

/Sven

2006-05-15  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/print/JavaPrinterGraphics.java:
Sweeping changes I can't be bothered to document in detail.
* gnu/java/awt/print/JavaPrinterJob.java
(getPageAttributes): New method.
(setPageable,cancel,isCancelled): Implement.


Index: gnu/java/awt/print/JavaPrinterGraphics.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/print/JavaPrinterGraphics.java,v
retrieving revision 1.3
diff -U3 -r1.3 JavaPrinterGraphics.java
--- gnu/java/awt/print/JavaPrinterGraphics.java	13 May 2006 17:06:38 -	1.3
+++ gnu/java/awt/print/JavaPrinterGraphics.java	15 May 2006 01:35:09 -
@@ -37,6 +37,7 @@
 
 package gnu.java.awt.print;
 
+import java.awt.print.Pageable;
 import java.awt.print.PrinterGraphics;
 import java.awt.print.Printable;
 import java.awt.print.PrinterJob;
@@ -85,11 +86,6 @@
   private PrinterJob printerJob;
 
   /**
-   * The paper format.
-   */
-  PageFormat pageFormat;
-  
-  /**
* Rendering resolution
*/
   private static final double DPI = 72.0;
@@ -104,66 +100,96 @@
*/
   private Image image;
 
-  public JavaPrinterGraphics( PrinterJob printerJob, PageFormat pageFormat )
+  public JavaPrinterGraphics( PrinterJob printerJob )
   {
 this.printerJob = printerJob;
-this.pageFormat = pageFormat;
-
-// Create a really big image and draw to that.
-xSize = (int)(DPI*pageFormat.getWidth()/72.0);
-ySize = (int)(DPI*pageFormat.getHeight()/72.0);
-
-// FIXME: This should at least be BufferedImage. Fix once we have a working B.I.
-// Graphics2D should also be supported of course.
-image = new GtkImage(xSize, ySize);
-
-initImage();
   }
 
   /**
-   * The only method worthy of mention here.
+   * Spool a document to PostScript.
+   * If Pageable is non-null, it will print that, otherwise it will use
+   * the supplied printable and pageFormat.
*/
-  public SpooledDocument spoolPostScript(Printable p)
+  public SpooledDocument spoolPostScript(Printable printable, 
+	 PageFormat pageFormat,
+	 Pageable pageable)
 throws PrinterException
-   {
- try 
-   {
-	 // spool to a temporary file
-	 File temp = File.createTempFile(cpspool, .ps);
-	 temp.deleteOnExit();
-
-	 PrintWriter out = new PrintWriter
-	   (new BufferedWriter
+  {
+try 
+  {
+	// spool to a temporary file
+	File temp = File.createTempFile(cpspool, .ps);
+	temp.deleteOnExit();
+	
+	PrintWriter out = new PrintWriter
+	  (new BufferedWriter
 	(new OutputStreamWriter
 	 (new FileOutputStream(temp), ISO8859_1), 100));
 
-	 writePSHeader(out);
-	 int status;
-	 int index = 0;
-	 while(p.print(this, pageFormat, index++) == Printable.PAGE_EXISTS)
-	   {
-	 g.dispose();
-	 g = null;
-	 writePage( out );
-	 initImage();
-	   }
-
+	writePSHeader(out);
+	
+	if(pageable != null)
+	  {
+	for(int index = 0; index  pageable.getNumberOfPages(); index++)
+	  spoolPage(out, pageable.getPrintable(index),
+			pageable.getPageFormat(index), index);
+	  }
+	else
+	  {
+	int index = 0;
+	while(spoolPage(out, printable, pageFormat, index++) ==
+		  Printable.PAGE_EXISTS);
+	  }
 	 out.println(%%Trailer);
-	 out.println(grestore % restore original stuff);
 	 out.println(%%EOF);
 	 out.close();
 	 return new SpooledDocument( temp );
} 
- catch (IOException e) 
-   {
-	 PrinterException pe = new PrinterException();
-	 pe.initCause(e);
-	 throw pe;
-   }
-   }
+catch (IOException e) 
+  {
+	PrinterException pe = new PrinterException();
+	pe.initCause(e);
+	throw pe;
+  }
+  }
 
-  private void initImage()
+  /**
+   * Spools a single page, returns NO_SUCH_PAGE unsuccessful,
+   * PAGE_EXISTS if it was.
+   */
+  public int spoolPage(PrintWriter out,
+		   Printable printable, 
+		   PageFormat pageFormat, 
+		   int index) throws IOException, PrinterException
+  {
+initImage( pageFormat );
+if(printable.print(this, pageFormat, index) == Printable.NO_SUCH_PAGE)
+  return Printable.NO_SUCH_PAGE;
+g.dispose();
+g = null;
+writePage( out, pageFormat );
+return Printable.PAGE_EXISTS;
+  }
+  
+  private void initImage(PageFormat pageFormat)
   {
+// Create a really big image and draw to that.
+xSize = (int)(DPI*pageFormat.getWidth()/72.0);
+ySize = (int)(DPI*pageFormat.getHeight()/72.0);
+
+// Swap X and Y sizes if it's a Landscape page.
+if( pageFormat.getOrientation() != PageFormat.PORTRAIT )
+  {
+	int t = xSize;
+	xSize = ySize;
+	ySize = t;
+  }
+
+// FIXME: This should at least be BufferedImage. 
+// Fix once we have a working B.I.
+// Graphics2D should also be supported of course.
+image = new GtkImage(xSize, ySize

Re: [cp-patches] Patch: FYI: minor printing fix

2006-05-14 Thread Sven de Marothy
On Sun, 2006-05-14 at 19:50 -0600, Tom Tromey wrote:
 I updated before preparing a different patch, and eclipse complained
 about JavaPrinterJob.  This fixes the assignment, which, previously,
 did nothing.  It also cleans up the imports.
 
 Tom
 

Ah, whoops. Thanks :)

/Sven




Re: [cp-patches] FYI: Socket timeout impl and fix

2006-05-13 Thread Sven de Marothy
On Sat, 2006-05-13 at 13:54 +0200, Robert Schuster wrote:
 Hi,
 could you test whether Socket.setSoTimeout() really sets the send and receive
 timeout?
 

I did, and it seems to work fine for me (A difference in 3 minutes and
1 second timeout when you're setting it to 1 second is quite
noticable). 

Note that from what I read though, not all socket implementations
necessarily support this stuff.

/Sven




[cp-patches] Re: FYI: Implement java.awt.print (demo)

2006-05-13 Thread Sven de Marothy

Here's a little working demo program.

/Sven
import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;

public class Draw extends Frame implements ActionListener, Printable
{
  public Draw()
  {
setLayout(new BorderLayout());
Button b = new Button(Print);
add(b, BorderLayout.SOUTH);
b.addActionListener(this);
setSize(300,300);
setVisible(true);
  }
  
  public void actionPerformed(ActionEvent e)
  {
printMe();
  }

  public void printMe()
  {
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(this);
if (printJob.printDialog())
  try {
	printJob.print();
  } catch(PrinterException pe) {
	System.out.println(Error printing:  + pe);
  }
  }

  public void paint(Graphics g)
  {
g.setColor(Color.yellow);
g.fillOval(50, 50, 200, 200);
g.setColor(Color.black);
g.fillOval(75,100, 25, 25);
g.fillOval(200,100, 25, 25);
g.fillArc(90, 150, 125, 75, 0, -180);
  }


  public int print(Graphics g, PageFormat pageFormat, int pageIndex)
  {
if (pageIndex  0) 
  return NO_SUCH_PAGE;
else
  {
	paint(g);
	return PAGE_EXISTS;
  }
  }

  public static void main(String[] args)
  {
new Draw();
  }


}


Re: [cp-patches] FYI: Socket timeout impl and fix

2006-05-13 Thread Sven de Marothy
On Sat, 2006-05-13 at 16:58 +0200, Michael Koch wrote:

 AFAIK Linux is the only one. If we want to stay portable we need to use
 select() and wait for the time of the timeout. In libgcj its already
 handled this way. Thats the safest.

Actually, I don't think we need to stay portable though. 
The JDK docs say: Some non-standard implmentation of this method may
ignore the specified timeout.

So.. Presumably, Solaris supports it too. But we don't need to though.

Anyway, this is still better than before when it didn't work at all :)

/Sven




[cp-patches] FYI: Implement java.awt.print

2006-05-13 Thread Sven de Marothy
So, here's a first implementation, thanks to Wolfgang's work. ATM it's
fairly stupid, printing to an image and printing that (have patience if
you think it's slow). But it's a big step up from nothing!

2006-05-13  Sven de Marothy  [EMAIL PROTECTED]

* gnu/javax/print/ipp/IppRequest.java (send): Set a timeout.
* java/awt/print/PrinterJob.java 
(getPrinterJob): Return a JavaPrinterJob
(setPrintService,getPrintService): Implement.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c:
(getPixels): Gtk_threads_enter required.
* gnu/java/awt/print/JavaPrinterGraphics.java
* gnu/java/awt/print/JavaPrinterJob.java
* gnu/java/awt/print/SpooledDocumet.java: 
New files.

Index: gnu/javax/print/ipp/IppRequest.java
===
RCS file: /sources/classpath/classpath/gnu/javax/print/ipp/IppRequest.java,v
retrieving revision 1.1
diff -U3 -r1.1 IppRequest.java
--- gnu/javax/print/ipp/IppRequest.java	13 Mar 2006 18:56:15 -	1.1
+++ gnu/javax/print/ipp/IppRequest.java	13 May 2006 14:57:03 -
@@ -119,6 +119,11 @@
 {
 
   /**
+   * The printer-poll timeout. 
+   */
+  private static final int timeout = 1000;
+
+  /**
* Helper class used to write the attributes of a request
* into the supplied data output stream in the correct way.
* 
@@ -838,7 +843,12 @@
  
 out.flush();
 stream.flush();  
-
+  
+// Set the connection timeout, for if the printer is offline.
+// FIXME: The print services polling should probably be done in its
+// own thread.
+connection.setConnectTimeout( timeout );
+
 int responseCode = responseCode = connection.getResponseCode();
 
 if (responseCode == HttpURLConnection.HTTP_OK)
Index: java/awt/print/PrinterJob.java
===
RCS file: /sources/classpath/classpath/java/awt/print/PrinterJob.java,v
retrieving revision 1.16
diff -U3 -r1.16 PrinterJob.java
--- java/awt/print/PrinterJob.java	10 May 2006 21:12:41 -	1.16
+++ java/awt/print/PrinterJob.java	13 May 2006 14:57:03 -
@@ -38,8 +38,9 @@
 
 package java.awt.print;
 
-import java.awt.HeadlessException;
+import gnu.java.awt.print.JavaPrinterJob;
 
+import java.awt.HeadlessException;
 import javax.print.PrintService;
 import javax.print.PrintServiceLookup;
 import javax.print.DocFlavor;
@@ -63,8 +64,7 @@
*/
   public static PrinterJob getPrinterJob()
   {
-// FIXME: Need to fix this to load a default implementation instance.
-return new NoPrinterJob();
+return new JavaPrinterJob();
   }
 
   /**
@@ -283,7 +283,7 @@
*/
   public PrintService getPrintService()
   {
-return null;
+return printer;
   }
 
   /**
@@ -298,13 +298,19 @@
   public void setPrintService(PrintService service)
 throws PrinterException
   {
-throw new PrinterException();
+printer = service;
   }
 }
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c
===
RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c,v
retrieving revision 1.18
diff -U3 -r1.18 gnu_java_awt_peer_gtk_GtkImage.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c	20 Mar 2006 14:42:37 -	1.18
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c	13 May 2006 14:57:04 -
@@ -154,6 +154,8 @@
   jint *result_array_iter, *dst;
   int i,j;
 
+  gdk_threads_enter ();
+
   pixbuf = cp_gtk_image_get_pixbuf (env, obj);
   width =  gdk_pixbuf_get_width (pixbuf);
   height = gdk_pixbuf_get_height (pixbuf);
@@ -195,6 +197,7 @@
 
   (*env)-ReleaseIntArrayElements (env, result_array, result_array_iter, 0);
 
+  gdk_threads_leave ();
   return result_array;
 }
 
@@ -527,6 +530,7 @@
 
   /* Get a pixmap */
   pixmap = (GdkPixmap *)getData (env, obj);
+
   pixbuf = gdk_pixbuf_get_from_drawable (NULL,
 	 pixmap,
 	 gdk_drawable_get_colormap( pixmap ),


/* JavaPrinterGraphics.java -- AWT printer rendering class.
   Copyright (C) 2006  Free Software Foundation, Inc.

This file is part of GNU Classpath.

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus

[cp-patches] FYI: improve JavaPrinterGraphics

2006-05-13 Thread Sven de Marothy
2006-05-13  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/print/JavaPrinterGraphics.java
(colorTripleHex): Reimplement better.


-- 
Sven de Marothy [EMAIL PROTECTED]
Index: gnu/java/awt/print/JavaPrinterGraphics.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/print/JavaPrinterGraphics.java,v
retrieving revision 1.1
diff -U3 -r1.1 JavaPrinterGraphics.java
--- gnu/java/awt/print/JavaPrinterGraphics.java	13 May 2006 15:05:12 -	1.1
+++ gnu/java/awt/print/JavaPrinterGraphics.java	13 May 2006 16:24:37 -
@@ -224,7 +224,7 @@
 int n = 0;
 for (int j = 0; j  ySize; j++) {
   for (int i = 0; i  xSize; i++) {
-	out.print( colorTripleHex(new Color(pixels[j * xSize + i])) );
+	out.print( colorTripleHex(pixels[j * xSize + i]) );
 	if(((++n)%11) == 0) out.println();
   }
 }
@@ -238,13 +238,16 @@
   /**
* Get a nonsperated hex RGB triple, e.g. FF = white 
*/
-  private String colorTripleHex(Color c){
+  private String colorTripleHex(int num){
 String s = ;
 
 try {
-  s = Integer.toString( ( c.getRed()  0xFF ) + 0x100, 16).substring(1)
-	+ Integer.toString( ( c.getGreen()  0xFF ) + 0x100, 16).substring(1)
-	+ Integer.toString( ( c.getBlue()  0xFF ) + 0x100, 16).substring(1);
+  s = Integer.toHexString( ( num  0x00FF ) );
+  if( s.length()  6 )
+	{
+	  s = 00+s;
+	  return s.substring(s.length()-6);
+	}
 } catch (Exception e){
   s = FF;
 }


[cp-patches] FYI2: improve JavaPrinterGraphics

2006-05-13 Thread Sven de Marothy

2006-05-13  Sven de Marothy  [EMAIL PROTECTED]

* gnu/java/awt/print/JavaPrinterGraphics.java
(spoolPostScript): Use a faster writer.





Index: gnu/java/awt/print/JavaPrinterGraphics.java
===
RCS file: /sources/classpath/classpath/gnu/java/awt/print/JavaPrinterGraphics.java,v
retrieving revision 1.2
diff -U3 -r1.2 JavaPrinterGraphics.java
--- gnu/java/awt/print/JavaPrinterGraphics.java	13 May 2006 16:28:19 -	1.2
+++ gnu/java/awt/print/JavaPrinterGraphics.java	13 May 2006 17:05:25 -
@@ -60,6 +60,8 @@
 import java.io.Writer;
 import java.io.PrintWriter;
 import java.io.FileWriter;
+import java.io.OutputStreamWriter;
+import java.io.FileOutputStream;
 import java.io.BufferedWriter;
 
 import gnu.java.awt.peer.gtk.GtkImage;
@@ -129,8 +131,12 @@
 	 // spool to a temporary file
 	 File temp = File.createTempFile(cpspool, .ps);
 	 temp.deleteOnExit();
-	 
-	 PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(temp)));
+
+	 PrintWriter out = new PrintWriter
+	   (new BufferedWriter
+	(new OutputStreamWriter
+	 (new FileOutputStream(temp), ISO8859_1), 100));
+
 	 writePSHeader(out);
 	 int status;
 	 int index = 0;


[cp-patches] RFC: HTML hack

2006-05-12 Thread Sven de Marothy
Hi all. 

I did some work on the HTML stuff after getting annoyed with JLabels
with HTML. 

This is somewhat of a hack, which I don't really think is done the right
way or in the right place. But in any case, it makes most of the font
attributes work, which is nice and useful.

Screenshot attached, too. :) Anyone against this as a simple temporary
solution?

2006-05-12  Sven de Marothy  [EMAIL PROTECTED]

* javax/swing/text/html/HTMLDocument.java
(CharacterAction.start): Translate tag to StyleAttribute.
(pushCharacterStyle): Push copy of attributes onto stack.
* gnu/javax/swing/text/html/CharacterAttributeTranslator.java:
New file

Index: javax/swing/text/html/HTMLDocument.java
===
RCS file: /sources/classpath/classpath/javax/swing/text/html/HTMLDocument.java,v
retrieving revision 1.28
diff -U3 -r1.28 HTMLDocument.java
--- javax/swing/text/html/HTMLDocument.java	23 Mar 2006 00:30:14 -	1.28
+++ javax/swing/text/html/HTMLDocument.java	12 May 2006 12:57:33 -
@@ -40,12 +40,13 @@
 
 import gnu.classpath.NotImplementedException;
 
+import gnu.javax.swing.text.html.CharacterAttributeTranslator;
+import java.lang.NumberFormatException;
 import java.io.IOException;
 import java.net.URL;
 import java.util.HashMap;
 import java.util.Stack;
 import java.util.Vector;
-
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.UndoableEditEvent;
 import javax.swing.text.AbstractDocument;
@@ -646,12 +647,16 @@
   {
 // Put the old attribute set on the stack.
 pushCharacterStyle();
-
-// And create the new one by adding the attributes in codea/code.
-if (a != null)
-  charAttr.addAttribute(t, a.copyAttributes());  
+
+	// Translate tag.. return if succesful.
+	if(CharacterAttributeTranslator.translateTag(charAttr, t, a))
+	  return;
+
+// Just add the attributes in codea/code.
+ 	if (a != null)
+ 	  charAttr.addAttribute(t, a.copyAttributes());  
   }
-  
+
   /**
* Called when an end tag is seen for one of the types of tags associated
* with this Action.
@@ -1131,7 +1136,7 @@
  */
 protected void pushCharacterStyle()
 {
-  charAttrStack.push(charAttr);
+  charAttrStack.push(charAttr.copyAttributes());
 }
 
 /**
/* CharacterAttributeTranslator.java -- 
   Copyright (C) 2006  Free Software Foundation, Inc.

This file is part of GNU Classpath.

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */

package gnu.javax.swing.text.html;

import java.awt.Color;
import java.util.HashMap;
import javax.swing.text.AbstractDocument;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.Element;
import javax.swing.text.ElementIterator;
import javax.swing.text.GapContent;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.html.HTML.Tag;

/**
 * This is a small utility class to translate HTML character attributes to
 * Swing StyleConstants
 */
public class CharacterAttributeTranslator
{
  private static final HashMap colorMap = new HashMap();
  static 
  {
colorMap.put(aqua , #00);
colorMap.put(blue , #FF);
colorMap.put(black

[cp-patches] Re: RFC: HTML hack

2006-05-12 Thread Sven de Marothy
Oh, and one more thing: This exposes what seems to be a few bugs in
BoxView, one of which is that it goes very very slowly due to excessive
recursion. 

This seems to alleviate the problem, although I don't think it's a real
fix either:
   public float getMinimumSpan(int axis)
   {
-updateRequirements(axis);
+//updateRequirements(axis);
 return requirements[axis].minimum;
   }

The other bug is that the text baseline moves down after every tag. Very
weird behaviour. 

/Sven

On Fri, 2006-05-12 at 17:36 +0200, Sven de Marothy wrote:
 Hi all. 
 
 I did some work on the HTML stuff after getting annoyed with JLabels
 with HTML. 
 
 This is somewhat of a hack, which I don't really think is done the right
 way or in the right place. But in any case, it makes most of the font
 attributes work, which is nice and useful.
 
 Screenshot attached, too. :) Anyone against this as a simple temporary
 solution?
 
 2006-05-12  Sven de Marothy  [EMAIL PROTECTED]
 
   * javax/swing/text/html/HTMLDocument.java
   (CharacterAction.start): Translate tag to StyleAttribute.
   (pushCharacterStyle): Push copy of attributes onto stack.
   * gnu/javax/swing/text/html/CharacterAttributeTranslator.java:
   New file
 
-- 
Sven de Marothy [EMAIL PROTECTED]




  1   2   >