A couple more additions for the X peers.
2006-07-18 Roman Kennke <[EMAIL PROTECTED]>
* gnu/java/awt/peer/x/XFontPeer.java
(encodeFont): Be more flexible with font sizes.
(validSize): New helper method.
* gnu/java/awt/peer/x/XGraphics.java
(drawImage(Image,int,int,int,int,int,int,int,int,ImageObserver)):
Implemented.
(drawImage(Image,int,int,int,int,int,int,int,int,Color,ImageObserver)):
Implemented.
* gnu/java/awt/peer/x/XImage.java
(properties): New field.
(getProperty): Implemented.
* resource/gnu/java/awt/peer/x/fonts.properties:
Added copyright header. Fixed font size field.
/Roman
Index: resource/gnu/java/awt/peer/x/fonts.properties
===================================================================
RCS file: /cvsroot/classpath/classpath/resource/gnu/java/awt/peer/x/fonts.properties,v
retrieving revision 1.1
diff -u -1 -2 -r1.1 fonts.properties
--- resource/gnu/java/awt/peer/x/fonts.properties 18 Jul 2006 13:41:08 -0000 1.1
+++ resource/gnu/java/awt/peer/x/fonts.properties 18 Jul 2006 18:16:18 -0000
@@ -1,25 +1,61 @@
+# fonts.properties
+# 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.
-serif.plain=-adobe-times-medium-r-normal--%d-*-*-*-p-*-iso8859-1
-serif.bold=-adobe-times-bold-r-normal--%d-*-*-*-p-*-iso8859-1
-serif.italic=-adobe-times-medium-o-normal--%d-*-*-*-p-*-iso8859-1
-serif.bolditalic=-adobe-times-bold-o-normal--%d-*-*-*-p-*-iso8859-1
+serif.plain=-adobe-times-medium-r-normal--*-%d-75-*-p-*-iso8859-1
+serif.bold=-adobe-times-bold-r-normal--*-%d-75-*-p-*-iso8859-1
+serif.italic=-adobe-times-medium-o-normal--*-%d-75-*-p-*-iso8859-1
+serif.bolditalic=-adobe-times-bold-o-normal--*-%d-75-*-p-*-iso8859-1
-sansserif.plain=-adobe-helvetica-medium-r-normal--%d-*-*-*-p-*-iso8859-1
-sansserif.bold=-adobe-helvetica-bold-r-normal--%d-*-*-*-p-*-iso8859-1
-sansserif.italic=-adobe-helvetica-medium-o-normal--%d-*-*-*-p-*-iso8859-1
-sansserif.bolditalic=-adobe-helvetica-bold-o-normal--%d-*-*-*-p-*-iso8859-1
+sansserif.plain=-adobe-helvetica-medium-r-normal--*-%d-75-*-p-*-iso8859-1
+sansserif.bold=-adobe-helvetica-bold-r-normal--*-%d-75-*-p-*-iso8859-1
+sansserif.italic=-adobe-helvetica-medium-o-normal--*-%d-75-*-p-*-iso8859-1
+sansserif.bolditalic=-adobe-helvetica-bold-o-normal--*-%d-75-*-p-*-iso8859-1
-monospaced.plain=-adobe-courier-medium-r-normal--%d-*-*-*-p-*-iso8859-1
-monospaced.bold=-adobe-courier-bold-r-normal--%d-*-*-*-p-*-iso8859-1
-monospaced.italic=-adobe-courier-medium-o-normal--%d-*-*-*-p-*-iso8859-1
-monospaced.bolditalic=-adobe-courier-bold-o-normal--%d-*-*-*-p-*-iso8859-1
+monospaced.plain=-adobe-courier-medium-r-normal--*-%d-75-*-p-*-iso8859-1
+monospaced.bold=-adobe-courier-bold-r-normal--*-%d-75-*-p-*-iso8859-1
+monospaced.italic=-adobe-courier-medium-o-normal--*-%d-75-*-p-*-iso8859-1
+monospaced.bolditalic=-adobe-courier-bold-o-normal--*-%d-75-*-p-*-iso8859-1
-dialog.plain=-adobe-helvetica-medium-r-normal--%d-*-*-*-p-*-iso8859-1
-dialog.bold=-adobe-helvetica-bold-r-normal--%d-*-*-*-p-*-iso8859-1
-dialog.italic=-adobe-helvetica-medium-o-normal--%d-*-*-*-p-*-iso8859-1
-dialog.bolditalic=-adobe-helvetica-bold-o-normal--%d-*-*-*-p-*-iso8859-1
+dialog.plain=-adobe-helvetica-medium-r-normal--*-%d-75-*-p-*-iso8859-1
+dialog.bold=-adobe-helvetica-bold-r-normal--*-%d-75-*-p-*-iso8859-1
+dialog.italic=-adobe-helvetica-medium-o-normal--*-%d-75-*-p-*-iso8859-1
+dialog.bolditalic=-adobe-helvetica-bold-o-normal--*-%d-75-*-p-*-iso8859-1
-dialoginput.plain=-adobe-helvetica-medium-r-normal--%d-*-*-*-p-*-iso8859-1
-dialoginput.bold=-adobe-helvetica-bold-r-normal--%d-*-*-*-p-*-iso8859-1
-dialoginput.italic=-adobe-helvetica-medium-o-normal--%d-*-*-*-p-*-iso8859-1
-dialoginput.bolditalic=-adobe-helvetica-bold-o-normal--%d-*-*-*-p-*-iso8859-1
+dialoginput.plain=-adobe-helvetica-medium-r-normal--*-%d-75-*-p-*-iso8859-1
+dialoginput.bold=-adobe-helvetica-bold-r-normal--*-%d-75-*-p-*-iso8859-1
+dialoginput.italic=-adobe-helvetica-medium-o-normal--*-%d-75-*-p-*-iso8859-1
+dialoginput.bolditalic=-adobe-helvetica-bold-o-normal--*-%d-75-*-p-*-iso8859-1
Index: gnu/java/awt/peer/x/XFontPeer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/x/XFontPeer.java,v
retrieving revision 1.1
diff -u -1 -2 -r1.1 XFontPeer.java
--- gnu/java/awt/peer/x/XFontPeer.java 29 Jun 2006 15:15:56 -0000 1.1
+++ gnu/java/awt/peer/x/XFontPeer.java 18 Jul 2006 18:16:18 -0000
@@ -685,25 +685,26 @@
key.append("italic");
break;
case (Font.BOLD | Font.ITALIC):
key.append("bolditalic");
break;
case Font.PLAIN:
default:
key.append("plain");
}
String protoType = fontProperties.getProperty(key.toString());
- return protoType.replaceFirst("%d", String.valueOf(size));
+ int s = validSize(size);
+ return protoType.replaceFirst("%d", String.valueOf(s * 10));
}
/**
* Checks the specified font name for a valid font name. If the font name
* is not known, then this returns 'sansserif' as fallback.
*
* @param name the font name to check
*
* @return a valid font name
*/
static String validName(String name)
{
@@ -715,24 +716,49 @@
|| name.equalsIgnoreCase("dialoginput"))
{
retVal = name.toLowerCase();
}
else
{
retVal = "sansserif";
}
return retVal;
}
/**
+ * Translates an arbitrary point size to a size that is typically available
+ * on an X server. These are the sizes 8, 10, 12, 14, 18 and 24.
+ *
+ * @param size the queried size
+ * @return the real available size
+ */
+ private static final int validSize(int size)
+ {
+ int val;
+ if (size <= 9)
+ val = 8;
+ else if (size <= 11)
+ val = 10;
+ else if (size <= 13)
+ val = 12;
+ else if (size <= 17)
+ val = 14;
+ else if (size <= 23)
+ val = 18;
+ else
+ val = 24;
+ return val;
+ }
+
+ /**
* Returns the X Font reference. This lazily loads the font when first
* requested.
*
* @return the X Font reference
*/
gnu.x11.Font getXFont()
{
if (xfont == null)
{
init(name, style, size);
}
return xfont;
Index: gnu/java/awt/peer/x/XGraphics.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/x/XGraphics.java,v
retrieving revision 1.3
diff -u -1 -2 -r1.3 XGraphics.java
--- gnu/java/awt/peer/x/XGraphics.java 18 Jul 2006 10:23:20 -0000 1.3
+++ gnu/java/awt/peer/x/XGraphics.java 18 Jul 2006 18:16:18 -0000
@@ -37,46 +37,33 @@
package gnu.java.awt.peer.x;
import gnu.x11.Colormap;
import gnu.x11.Drawable;
import gnu.x11.GC;
import gnu.x11.Pixmap;
import gnu.x11.Point;
import java.awt.AWTError;
import java.awt.Color;
-import java.awt.Composite;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
-import java.awt.GraphicsConfiguration;
import java.awt.Image;
-import java.awt.Paint;
import java.awt.Rectangle;
-import java.awt.RenderingHints;
import java.awt.Shape;
-import java.awt.Stroke;
import java.awt.Toolkit;
-import java.awt.RenderingHints.Key;
-import java.awt.font.FontRenderContext;
-import java.awt.font.GlyphVector;
-import java.awt.geom.AffineTransform;
-import java.awt.image.BufferedImage;
-import java.awt.image.BufferedImageOp;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
-import java.awt.image.RenderedImage;
-import java.awt.image.renderable.RenderableImage;
import java.text.AttributedCharacterIterator;
import java.util.HashMap;
public class XGraphics
extends Graphics
implements Cloneable
{
/**
* The X Drawable to draw on.
*/
private Drawable xdrawable;
@@ -568,34 +555,59 @@
public boolean drawImage(Image image, int x, int y, int width, int height,
Color bgcolor, ImageObserver observer)
{
// FIXME: Implement this.
throw new UnsupportedOperationException("Not yet implemented");
}
public boolean drawImage(Image image, int dx1, int dy1, int dx2, int dy2,
int sx1, int sy1, int sx2, int sy2,
ImageObserver observer)
{
- // FIXME: Implement this.
- throw new UnsupportedOperationException("Not yet implemented");
+ return drawImage(image, dx1, dy1, dx2, dy2, sx1, sx2, sy1, sy2, null,
+ observer);
}
public boolean drawImage(Image image, int dx1, int dy1, int dx2, int dy2,
int sx1, int sy1, int sx2, int sy2, Color bgcolor,
ImageObserver observer)
{
- // FIXME: Implement this.
- throw new UnsupportedOperationException("Not yet implemented");
+
+ // FIXME: What to do with bgcolor?
+
+ // Scale the image.
+ int sw = image.getWidth(observer);
+ int sh = image.getHeight(observer);
+ double scaleX = Math.abs(dx2 - dx1) / (double) Math.abs(sx2 - sx1);
+ double scaleY = Math.abs(dy2 - dy1) / (double) Math.abs(sy2 - sy1);
+ Image scaled = image.getScaledInstance((int) (scaleX * sw),
+ (int) (scaleY * sh),
+ Image.SCALE_FAST);
+
+ // Scaled source coordinates.
+ int sx1s = (int) (scaleX * Math.min(sx1, sx2));
+ int sx2s = (int) (scaleX * Math.max(sx1, sx2));
+
+ // Temporarily clip to the target rectangle.
+ Rectangle old = clip;
+ clipRect(dx1, dy1, dx2 - dx1, dy2 - dy1);
+
+ // Draw scaled image.
+ boolean res = drawImage(scaled, dx1 - sx1s, dy1 - sx2s, observer);
+
+ // Reset clip.
+ setClip(old);
+
+ return res;
}
/**
* Frees any resources associated with this object.
*/
public void dispose()
{
xdrawable.display.flush();
if (! disposed)
{
xgc.free();
disposed = true;
Index: gnu/java/awt/peer/x/XImage.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/x/XImage.java,v
retrieving revision 1.2
diff -u -1 -2 -r1.2 XImage.java
--- gnu/java/awt/peer/x/XImage.java 17 Jul 2006 08:30:37 -0000 1.2
+++ gnu/java/awt/peer/x/XImage.java 18 Jul 2006 18:16:18 -0000
@@ -36,31 +36,34 @@
exception statement from your version. */
package gnu.java.awt.peer.x;
import gnu.x11.Pixmap;
import java.awt.Graphics;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
+import java.util.Hashtable;
public class XImage
extends Image
{
Pixmap pixmap;
+ private Hashtable properties;
+
XImage(int w, int h)
{
GraphicsEnvironment env =
GraphicsEnvironment.getLocalGraphicsEnvironment();
XGraphicsDevice dev = (XGraphicsDevice) env.getDefaultScreenDevice();
pixmap = new Pixmap(dev.getDisplay(), w, h);
}
public int getWidth(ImageObserver observer)
{
return pixmap.width;
}
@@ -80,26 +83,28 @@
* Creates an XGraphics for drawing on this XImage.
*
* @return an XGraphics for drawing on this XImage
*/
public Graphics getGraphics()
{
XGraphics g = new XGraphics(pixmap);
return g;
}
public Object getProperty(String name, ImageObserver observer)
{
- // TODO: Implement this.
- throw new UnsupportedOperationException("Not yet implemented.");
+ Object val = null;
+ if (properties != null)
+ val = properties.get(val);
+ return val;
}
public void flush()
{
// TODO: Implement this.
throw new UnsupportedOperationException("Not yet implemented.");
}
protected void finalize()
{
pixmap.free();
}