harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r440748 [4/25] - in /incubator/harmony/enhanced/classlib/trunk/modules: accessibility/src/main/java/javax/accessibility/ awt/ awt/make/ awt/src/main/java/common/java/awt/ awt/src/main/java/common/java/awt/datatransfer/ awt/src/main/java/com...
Date Wed, 06 Sep 2006 16:06:30 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DragSourceEventProxy.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DragSourceEventProxy.java?view=auto&rev=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DragSourceEventProxy.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/DragSourceEventProxy.java Wed Sep  6 09:06:15 2006
@@ -0,0 +1,104 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Pavel Dolgov
+ * @version $Revision$
+ */
+package org.apache.harmony.awt.datatransfer;
+
+import java.awt.Point;
+import java.awt.dnd.DragSourceContext;
+import java.awt.dnd.DragSourceDragEvent;
+import java.awt.dnd.DragSourceDropEvent;
+import java.awt.dnd.DragSourceEvent;
+
+/**
+ * Dispatches DragSource events on event dispatch thread 
+ * in conjunction with {@link java.awt.EventQueue#invokeLater(Runnable)}
+ */
+public class DragSourceEventProxy implements Runnable {
+    public static final int DRAG_ENTER = 1;
+    public static final int DRAG_OVER = 2;
+    public static final int DRAG_ACTION_CHANGED = 3;
+    public static final int DRAG_MOUSE_MOVED = 4;
+    public static final int DRAG_EXIT = 5;
+    public static final int DRAG_DROP_END = 6;
+    
+    private final DragSourceContext context;
+    
+    private final int type;
+    private final int userAction;
+    private final int targetActions;
+    private final int x;
+    private final int y;
+    private final int modifiers;
+    private final boolean success;
+    
+    public DragSourceEventProxy(DragSourceContext context, 
+            int type, int userAction, int targetActions,
+            Point location, int modifiers) {
+        this.context = context;
+        this.type = type;
+        this.userAction = userAction;
+        this.targetActions = targetActions;
+        this.x = location.x;
+        this.y = location.y;
+        this.modifiers = modifiers;
+        this.success = false;
+    }
+    
+    public DragSourceEventProxy(DragSourceContext context,
+            int type, int userAction, boolean success,
+            Point location, int modifiers) {
+        this.context = context;
+        this.type = type;
+        this.userAction = userAction;
+        this.targetActions = userAction;
+        this.x = location.x;
+        this.y = location.y;
+        this.modifiers = modifiers;
+        this.success = success;
+    }
+    
+    public void run() {
+        switch (type) {
+        case DRAG_ENTER:
+            context.dragEnter(newDragSourceDragEvent());
+            break;
+        case DRAG_OVER:
+            context.dragOver(newDragSourceDragEvent());
+            break;
+        case DRAG_ACTION_CHANGED:
+            context.dropActionChanged(newDragSourceDragEvent());
+            break;
+        case DRAG_MOUSE_MOVED:
+            context.dragMouseMoved(newDragSourceDragEvent());
+            break;
+        case DRAG_EXIT:
+            context.dragExit(new DragSourceEvent(context, x, y));
+            break;
+        case DRAG_DROP_END:
+            context.dragExit(new DragSourceDropEvent(
+                    context, userAction, success, x, y));
+            break;
+        }
+    }
+    
+    private DragSourceDragEvent newDragSourceDragEvent() {
+        return new DragSourceDragEvent(
+                context, userAction, targetActions, modifiers, x, y);
+    }
+}
\ No newline at end of file

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/NativeClipboard.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/NativeClipboard.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/NativeClipboard.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/NativeClipboard.java Wed Sep  6 09:06:15 2006
@@ -21,31 +21,20 @@
 
 import java.awt.datatransfer.Clipboard;
 
-import org.apache.harmony.awt.ContextStorage;
-import org.apache.harmony.awt.wtk.Synchronizer;
-
 
 /**
- * Native clipboard class. Base class for concrete native clipboards.
+ * Base class for platrorm-specific clipboards.
  */
 public abstract class NativeClipboard extends Clipboard {
 
     protected static final int OPS_TIMEOUT = 10000;     // ms
 
-    protected final Synchronizer awtSynchronizer;
-    protected final long javaWindow;
-    protected final NativeTranslationManager translationManager;
-
     /**
      * Creates native clipboard object.
      * @param name - clipboard name.
      */
     public NativeClipboard(String name) {
         super(name);
-
-        translationManager = DTK.getContextInstance().getTranslationManager();
-        awtSynchronizer = ContextStorage.getSynchronizer();
-        javaWindow = ContextStorage.getNativeEventQueue().getJavaWindow();
     }
 
     /**

Added: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/RawBitmap.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/RawBitmap.java?view=auto&rev=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/RawBitmap.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/RawBitmap.java Wed Sep  6 09:06:15 2006
@@ -0,0 +1,68 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Pavel Dolgov
+ * @version $Revision$
+ */
+package org.apache.harmony.awt.datatransfer;
+
+/**
+ * RawBitmap
+ */
+public final class RawBitmap {
+
+    public final int width;
+    public final int height;
+    public final int stride;
+    public final int bits;
+    public final int rMask;
+    public final int gMask;
+    public final int bMask;
+    
+    /**
+     * Array representing bitmap data.
+     * Depending on bit count per pixel, it could be
+     * int[] (32 bits) or short[] (15 or 16 bits) or byte[] (8 or 24 bits) 
+     */
+    public final Object buffer;
+    
+    public RawBitmap(int w, int h, int stride, int bits, 
+            int rMask, int gMask, int bMask, Object buffer) {
+        this.width = w;
+        this.height = h;
+        this.stride = stride;
+        this.bits = bits;
+        this.rMask = rMask;
+        this.gMask = gMask;
+        this.bMask = bMask;
+        this.buffer = buffer;
+    }
+    
+    public RawBitmap(int header[], Object buffer) {
+        this.width = header[0];
+        this.height = header[1];
+        this.stride = header[2];
+        this.bits = header[3];
+        this.rMask = header[4];
+        this.gMask = header[5];
+        this.bMask = header[6];
+        this.buffer = buffer;
+    }
+    
+    public int[] getHeader() {
+        return new int[] { width, height, stride, bits, rMask, gMask, bMask }; 
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/TextFlavor.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/TextFlavor.java?view=auto&rev=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/TextFlavor.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/datatransfer/TextFlavor.java Wed Sep  6 09:06:15 2006
@@ -0,0 +1,67 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/** 
+ * @author Pavel Dolgov
+ * @version $Revision$
+ */
+package org.apache.harmony.awt.datatransfer;
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.SystemFlavorMap;
+import java.io.InputStream;
+import java.io.Reader;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+
+/**
+ * TextFlavor
+ */
+public class TextFlavor {
+
+    public static final Class[] unicodeTextClasses = { 
+            String.class, Reader.class, CharBuffer.class, char[].class };
+
+    public static final Class[] charsetTextClasses = { 
+            InputStream.class, ByteBuffer.class, byte[].class };
+    
+    public static void addUnicodeClasses(SystemFlavorMap fm,
+                                         String nat,
+                                         String subType) {
+        for (int i = 0; i < unicodeTextClasses.length; i++) {
+            String type = "text/" + subType;
+            String params = ";class=\"" + 
+                    unicodeTextClasses[i].getName() + "\"";
+            DataFlavor f = new DataFlavor(type + params, type);
+            fm.addFlavorForUnencodedNative(nat, f);
+            fm.addUnencodedNativeForFlavor(f, nat);
+        }
+    }
+
+    public static void addCharsetClasses(SystemFlavorMap fm, 
+                                         String nat,
+                                         String subType, 
+                                         String charset) {
+        for (int i = 0; i < charsetTextClasses.length; i++) {
+            String type = "text/" + subType;
+            String params = ";class=\"" + 
+                    charsetTextClasses[i].getName() + "\"" + 
+                    ";charset=\"" + charset + "\"";
+            DataFlavor f = new DataFlavor(type + params, type);
+            fm.addFlavorForUnencodedNative(nat, f);
+            fm.addUnencodedNativeForFlavor(f, nat);
+        }
+    }
+}
\ No newline at end of file

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/AwtImageBackdoorAccessor.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/AwtImageBackdoorAccessor.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/AwtImageBackdoorAccessor.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/AwtImageBackdoorAccessor.java Wed Sep  6 09:06:15 2006
@@ -26,12 +26,14 @@
 import java.awt.Image;
 import java.awt.image.DataBuffer;
 import java.awt.image.IndexColorModel;
+import org.apache.harmony.awt.gl.image.DataBufferListener;
 
 /**
  * This class give an opportunity to get access to private data of 
  * some java.awt.image classes 
  * Implementation of this class placed in java.awt.image package
  */
+
 public abstract class AwtImageBackdoorAccessor {
 
     static protected AwtImageBackdoorAccessor inst;
@@ -50,4 +52,9 @@
     public abstract short[] getDataUShort(DataBuffer db);
     public abstract double[] getDataDouble(DataBuffer db);
     public abstract float[] getDataFloat(DataBuffer db);
+    public abstract void releaseData(DataBuffer db);
+    
+    public abstract void addDataBufferListener(DataBuffer db, DataBufferListener listener);
+    public abstract void removeDataBufferListener(DataBuffer db);
+    public abstract void validate(DataBuffer db);
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/CommonGraphics2D.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/CommonGraphics2D.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/CommonGraphics2D.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/CommonGraphics2D.java Wed Sep  6 09:06:15 2006
@@ -59,6 +59,7 @@
 import org.apache.harmony.awt.gl.Surface;
 import org.apache.harmony.awt.gl.image.OffscreenImage;
 import org.apache.harmony.awt.gl.render.Blitter;
+import org.apache.harmony.awt.gl.render.JavaArcRasterizer;
 import org.apache.harmony.awt.gl.render.JavaLineRasterizer;
 import org.apache.harmony.awt.gl.render.JavaShapeRasterizer;
 import org.apache.harmony.awt.gl.render.JavaTextRenderer;
@@ -273,6 +274,15 @@
     }
 
     public void drawArc(int x, int y, int width, int height, int sa, int ea) {
+        if (stroke instanceof BasicStroke && ((BasicStroke)stroke).getLineWidth() <= 1 &&
+                ((BasicStroke)stroke).getDashArray() == null && 
+                (transform.isIdentity() || transform.getType() == AffineTransform.TYPE_TRANSLATION)) {
+            Point p = new Point(x, y);
+            transform.transform(p, p);
+            MultiRectArea mra = JavaArcRasterizer.rasterize(x, y, width, height, sa, ea, clip);
+            fillMultiRectArea(mra);
+            return;
+        }
         draw(new Arc2D.Float(x, y, width, height, sa, ea, Arc2D.OPEN));
     }
 
@@ -488,6 +498,15 @@
     }
 
     public void drawOval(int x, int y, int width, int height) {
+        if (stroke instanceof BasicStroke && ((BasicStroke)stroke).getLineWidth() <= 1 &&
+                ((BasicStroke)stroke).getDashArray() == null && 
+                (transform.isIdentity() || transform.getType() == AffineTransform.TYPE_TRANSLATION)) {
+            Point p = new Point(x, y);
+            transform.transform(p, p);
+            MultiRectArea mra = JavaArcRasterizer.rasterize(x, y, width, height, 0, 360, clip);
+            fillMultiRectArea(mra);
+            return;
+        }
         draw(new Ellipse2D.Float(x, y, width, height));
     }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/CommonGraphics2DFactory.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/CommonGraphics2DFactory.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/CommonGraphics2DFactory.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/CommonGraphics2DFactory.java Wed Sep  6 09:06:15 2006
@@ -63,52 +63,10 @@
 
         return fm;
     }
-    
-    /**
-     * Returns native dependent FontPeer object applicable to the specified font.
-     * 
-     * @param font specified Font
-     * @return FontPeer object
-     */
-    public FontPeer createFontPeer(Font font) {
-        StringBuffer init = new StringBuffer();
-        init.append(font.getName());
-        init.append(font.getStyle());
-        init.append(font.getSize());
-        return getFontManager().setFont(init.toString(), font);
-    }
+    // Font methods
 
-    /**
-     * Manages resources of the FontPeer corresponding to the specified font.
-     * If there is no other Font objects that links on the applicaple FontPeer than
-     * this font peer is to be disposed, otherwise links counter in the FontPeer 
-     * object is decreased by one. 
-     * 
-     * @param font specified Font
-     */
-    public void freeFontPeer(Font font) {
-        StringBuffer init = new StringBuffer();
-        init.append(font.getName());
-        init.append(font.getStyle());
-        init.append(font.getSize());
-        getFontManager().deleteFont(init.toString());
-    }
-
-    /**
-     * Returns native dependent FontPeer object applicable to the specified 
-     * FontProperty object and size of the font. 
-     * !! This constructor mostly used for LinuxFont creation where font 
-     * families names in font properties lowercased. 
-     * 
-     * @param font specified Font
-     * @return FontPeer object
-     */
-    public FontPeer createFontPeer(FontProperty fp, int size){
-        StringBuffer init = new StringBuffer();
-        init.append(fp.getName());
-        init.append(fp.getStyle());
-        init.append(size);
-        return getFontManager().setFont(init.toString(), fp, size);
+    public FontPeer getFontPeer(Font font) {
+        return getFontManager().getFontPeer(font.getName(), font.getStyle(), font.getSize());
     }
     
     /**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/ImageSurface.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/ImageSurface.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/ImageSurface.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/ImageSurface.java Wed Sep  6 09:06:15 2006
@@ -36,13 +36,14 @@
 import java.awt.image.WritableRaster;
 
 import org.apache.harmony.awt.gl.color.LUTColorConverter;
+import org.apache.harmony.awt.gl.image.DataBufferListener;
 
 
 /**
  * This class represent Surface for differnt types of Images (BufferedImage, 
  * OffscreenImage and so on) 
  */
-public class ImageSurface extends Surface {
+public class ImageSurface extends Surface implements DataBufferListener {
 
     boolean nativeDrawable = true;
     int surfaceType;
@@ -50,6 +51,12 @@
     ColorModel cm;
     WritableRaster raster;
     Object data;
+    
+    boolean needToRefresh = true;
+    boolean dataTaken = false;
+    
+    private long cachedDataPtr;       // Pointer for cached Image Data
+    private boolean alphaPre;         // Cached Image Data alpha premultiplied 
 
     public ImageSurface(ColorModel cm, WritableRaster raster){
         this(cm, raster, Surface.getType(cm, raster));
@@ -63,6 +70,8 @@
         this.raster = raster;
         surfaceType = type;
 
+        data = AwtImageBackdoorAccessor.getInstance().
+        getData(raster.getDataBuffer());
         ColorSpace cs = cm.getColorSpace();
         transparency = cm.getTransparency();
         width = raster.getWidth();
@@ -85,7 +94,6 @@
         if(type == BufferedImage.TYPE_CUSTOM){
             nativeDrawable = false;
         }
-        if(nativeDrawable) createSufaceStructure();
     }
 
     public ColorModel getColorModel() {
@@ -97,6 +105,9 @@
     }
 
     public long getSurfaceDataPtr() {
+        if(surfaceDataPtr == 0L && nativeDrawable){
+            createSufaceStructure();
+        }
         return surfaceDataPtr;
     }
 
@@ -116,39 +127,43 @@
      * Creates native Surface structure which used for native blitting
      */
     private void createSufaceStructure(){
+        int cmType = 0;
+        int numComponents = cm.getNumComponents();
+        boolean hasAlpha = cm.hasAlpha();
+        boolean isAlphaPre = cm.isAlphaPremultiplied();
+        int transparency = cm.getTransparency();
+        int bits[] = cm.getComponentSize();
+        int pixelStride = cm.getPixelSize();
+        int masks[] = null;
+        int colorMap[] = null;
+        int colorMapSize = 0;
+        int transpPixel = -1;
+        boolean isGrayPallete = false;
         SampleModel sm = raster.getSampleModel();
+        int smType = 0;
         int dataType = sm.getDataType();
-        data = AwtImageBackdoorAccessor.getInstance().
-        getData(raster.getDataBuffer());
+        int scanlineStride = 0;
+        int bankIndeces[] = null;
+        int bandOffsets[] = null;
+        int offset = raster.getDataBuffer().getOffset();
 
         if(cm instanceof DirectColorModel){
+            cmType = DCM;
             DirectColorModel dcm = (DirectColorModel) cm;
-            int redMask = dcm.getRedMask();
-            int greenMask = dcm.getGreenMask();
-            int blueMask = dcm.getBlueMask();
-            int alphaMask = dcm.getAlphaMask();
-            SinglePixelPackedSampleModel sppsm =
-                (SinglePixelPackedSampleModel) sm;
-            int scanlineStride = sppsm.getScanlineStride();
-            boolean isAlphaPre = dcm.isAlphaPremultiplied();
-
-            surfaceDataPtr = createStructDCM(surfaceType, dataType,
-                    csType, redMask, greenMask, blueMask, alphaMask,
-                    cm.getPixelSize(), scanlineStride, raster.getWidth(),
-                    raster.getHeight(), dcm.getTransparency(), isAlphaPre);
+            masks = dcm.getMasks();
+            smType = SPPSM;
+            SinglePixelPackedSampleModel sppsm = (SinglePixelPackedSampleModel) sm;
+            scanlineStride = sppsm.getScanlineStride();
 
         }else if(cm instanceof IndexColorModel){
+            cmType = ICM;
             IndexColorModel icm = (IndexColorModel) cm;
-            int mapSize = icm.getMapSize();
-            int colorMap[] = new int[mapSize];
+            colorMapSize = icm.getMapSize();
+            colorMap = new int[colorMapSize];
             icm.getRGBs(colorMap);
-            int pixelStride = icm.getPixelSize();
-            int trans = icm.getTransparentPixel();
-            int transparency = icm.getTransparency();
-            boolean isGrayPallete = Surface.isGrayPallete(icm);
+            transpPixel = icm.getTransparentPixel();
+            isGrayPallete = Surface.isGrayPallete(icm);
 
-            int smType;
-            int scanlineStride;
             if(sm instanceof MultiPixelPackedSampleModel){
                 smType = MPPSM;
                 MultiPixelPackedSampleModel mppsm =
@@ -163,23 +178,9 @@
                 throw new IllegalArgumentException("The raster is" +
                 " incompatible with this ColorModel");
             }
-            surfaceDataPtr = createStructICM(surfaceType, dataType,
-                    pixelStride, scanlineStride, width, height,
-                    mapSize, colorMap, isGrayPallete, transparency,
-                    trans, smType);
 
         }else if(cm instanceof ComponentColorModel){
-            ComponentColorModel ccm = (ComponentColorModel) cm;
-            int transparency = ccm.getTransparency();
-            boolean isAlphaPre = ccm.isAlphaPremultiplied();
-            int numComponents = ccm.getNumComponents();
-            int bits[] = ccm.getComponentSize();
-
-            int smType;
-            int scanlineStride;
-            int bankIndeces[];
-            int bandOffsets[];
-
+            cmType = CCM;
             if(sm instanceof ComponentSampleModel){
                 ComponentSampleModel csm = (ComponentSampleModel) sm;
                 scanlineStride = csm.getScanlineStride();
@@ -196,39 +197,49 @@
                 throw new IllegalArgumentException("The raster is" +
                 " incompatible with this ColorModel");
             }
-            surfaceDataPtr = createStructCCM(surfaceType, dataType,
-                    csType, numComponents, cm.getPixelSize(), scanlineStride,
-                    width, height, bits, bankIndeces, bandOffsets,
-                    transparency, isAlphaPre);
+
         }else{
             surfaceDataPtr = 0L;
+            return;
         }
+        surfaceDataPtr = createSurfStruct(surfaceType, width, height, cmType, csType, smType, dataType,
+                numComponents, pixelStride, scanlineStride, bits, masks, colorMapSize,
+                colorMap, transpPixel, isGrayPallete, bankIndeces, bandOffsets,
+                offset, hasAlpha, isAlphaPre, transparency);
     }
 
     public void dispose() {
-        dispose(surfaceDataPtr);
-        surfaceDataPtr = 0L;
+        if(surfaceDataPtr != 0L){
+            dispose(surfaceDataPtr);
+            surfaceDataPtr = 0L;
+        }
+    }
+    
+    public long getCachedData(boolean alphaPre){
+        if(nativeDrawable){
+            if(cachedDataPtr == 0L || needToRefresh || this.alphaPre != alphaPre){
+                cachedDataPtr = updateCache(getSurfaceDataPtr(), data, alphaPre);
+                this.alphaPre = alphaPre;
+                validate(); 
+            }
+        }
+        return cachedDataPtr;
     }
 
-    private native long createStructDCM(int surfaceType, int dataType,
-            int csType, int redMask, int greenMask, int blueMask,
-            int alphaMask, int pixelStride, int scanlineStride, int width, int height,
-            int transparancy, boolean isAlphaPre);
-
-    private native long createStructICM(int surfaceType, int dataType,
-            int pixelStride, int scanlineStride, int width, int height,
-            int mapSize, int colorMap[], boolean isGrayPallete, int transparency,
-            int trans, int smType);
-
-    private native long createStructCCM(int surfaceType, int dataType,
-            int csType, int numComponents, int pixelStride, int scanlineStride,
-            int width, int height, int bits[], int bankIndeces[], int bandOffsets[],
-            int transparency, boolean isAlphaPre);
+    private native long createSurfStruct(int surfaceType, int width, int height, 
+            int cmType, int csType, int smType, int dataType,
+            int numComponents, int pixelStride, int scanlineStride,
+            int bits[], int masks[], int colorMapSize, int colorMap[],
+            int transpPixel, boolean isGrayPalette, int bankIndeces[], 
+            int bandOffsets[], int offset, boolean hasAlpha, boolean isAlphaPre,
+            int transparency);
 
     private native void dispose(long structPtr);
 
     private native void setImageSize(long structPtr, int width, int height);
 
+    private native long updateCache(long structPtr, Object data, boolean alphaPre);
+    
     /**
      * Supposes that new raster is compatible with an old one
      * @param r
@@ -236,7 +247,9 @@
     public void setRaster(WritableRaster r) {
         raster = r;
         data = AwtImageBackdoorAccessor.getInstance().getData(r.getDataBuffer());
-        setImageSize(surfaceDataPtr, r.getWidth(), r.getHeight());
+        if (surfaceDataPtr != 0) {
+            setImageSize(surfaceDataPtr, r.getWidth(), r.getHeight());
+        }
         this.width = r.getWidth();
         this.height = r.getHeight();
     }
@@ -252,5 +265,41 @@
 
     public Surface getImageSurface() {
         return this;
+    }
+
+    public void dataChanged() {
+        needToRefresh = true;
+        clearValidCaches();
+    }
+
+    public void dataTaken() {
+        dataTaken = true;
+        needToRefresh = true;
+        clearValidCaches();
+    }
+    
+    public void dataReleased(){
+        dataTaken = false;
+        needToRefresh = true;
+        clearValidCaches();
+    }
+    
+    public void invalidate(){
+        needToRefresh = true;
+        clearValidCaches();
+    }
+    
+    public void validate(){
+        if(!needToRefresh) return;
+        if(!dataTaken){
+            needToRefresh = false;
+            AwtImageBackdoorAccessor ba = AwtImageBackdoorAccessor.getInstance();
+            ba.validate(raster.getDataBuffer());
+        }
+        
+    }
+    
+    public boolean invalidated(){
+        return needToRefresh;
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/MultiRectArea.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/MultiRectArea.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/MultiRectArea.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/MultiRectArea.java Wed Sep  6 09:06:15 2006
@@ -35,6 +35,8 @@
      */
     private static final boolean CHECK = false;
 
+    boolean sorted = true;
+    
     /**
      * Rectangle buffer
      */
@@ -351,6 +353,11 @@
         rect = MultiRectAreaOp.createBuf(0);
     }
 
+    public MultiRectArea(boolean sorted) {
+       this();
+       this.sorted = sorted;
+    }
+    
     /**
      * Constructs a new MultiRectArea as a copy of another one 
      */
@@ -465,7 +472,7 @@
      */
     static MultiRectArea check(MultiRectArea mra, String msg) {
         if (CHECK && mra != null) {
-            if (MultiRectArea.checkValidation(mra.getRectangles()) != -1) {
+            if (MultiRectArea.checkValidation(mra.getRectangles(), mra.sorted) != -1) {
                 new RuntimeException("Invalid MultiRectArea in method " + msg);
             }
         }
@@ -475,7 +482,7 @@
     /**
      * Checks validation of MultiRectArea object
      */
-    public static int checkValidation(Rectangle[] r) {
+    public static int checkValidation(Rectangle[] r, boolean sorted) {
 
         // Check width and height
         for(int i = 0; i < r.length; i++) {
@@ -485,14 +492,16 @@
         }
 
         // Check order
-        for(int i = 1; i < r.length; i++) {
-            if (r[i - 1].y > r[i].y) {
-                return i;
-            }
-            if (r[i - 1].y == r[i].y) {
-                if (r[i - 1].x > r[i].x) {
+        if (sorted) {
+            for(int i = 1; i < r.length; i++) {
+                if (r[i - 1].y > r[i].y) {
                     return i;
                 }
+                if (r[i - 1].y == r[i].y) {
+                    if (r[i - 1].x > r[i].x) {
+                        return i;
+                    }
+                }
             }
         }
 
@@ -671,8 +680,10 @@
         int y1 = rect[2];
         int x2 = rect[3];
         int y2 = rect[4];
+        
         for(int i = 5; i < rect[0]; i += 4) {
             int rx1 = rect[i + 0];
+            int ry1 = rect[i + 1];
             int rx2 = rect[i + 2];
             int ry2 = rect[i + 3];
             if (rx1 < x1) {
@@ -681,10 +692,14 @@
             if (rx2 > x2) {
                 x2 = rx2;
             }
+            if (ry1 < y1) {
+                y1 = ry1;
+            }
             if (ry2 > y2) {
                 y2 = ry2;
             }
         }
+        
         return bounds = new Rectangle(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
     }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/MultiRectAreaOp.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/MultiRectAreaOp.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/MultiRectAreaOp.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/MultiRectAreaOp.java Wed Sep  6 09:06:15 2006
@@ -356,7 +356,9 @@
 
             MultiRectArea.RectCash dst = new MultiRectArea.RectCash();
 
-            if (src1.getRectCount() <= MAX_SIMPLE || src2.getRectCount() <= MAX_SIMPLE) {
+            if (!src1.sorted || !src2.sorted || 
+               src1.getRectCount() <= MAX_SIMPLE || src2.getRectCount() <= MAX_SIMPLE) 
+            {
                 dst.setRect(simpleIntersect(src1, src2), false);
             } else {
                 Rectangle bounds1 = src1.getBounds();
@@ -535,7 +537,9 @@
 
             dst = new MultiRectArea.RectCash();
 
-            if (src1.getRectCount() <= MAX_SIMPLE || src2.getRectCount() <= MAX_SIMPLE) {
+            if (!src1.sorted || !src2.sorted ||
+               src1.getRectCount() <= MAX_SIMPLE || src2.getRectCount() <= MAX_SIMPLE) 
+            {
                 simpleUnion(src1, src2, dst);
             } else {
                 Rectangle bounds1 = src1.getBounds();
@@ -808,8 +812,9 @@
 
             MultiRectArea.RectCash dst = new MultiRectArea.RectCash();
 
-            if (src1.getRectCount() <= MAX_SIMPLE || src2.getRectCount() <= MAX_SIMPLE) {
-
+            if (!src1.sorted || !src2.sorted ||
+               src1.getRectCount() <= MAX_SIMPLE || src2.getRectCount() <= MAX_SIMPLE) 
+            {
                 simpleSubtract(src1, src2, dst);
             } else {
                 Rectangle bounds1 = src1.getBounds();

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/Surface.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/Surface.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/Surface.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/Surface.java Wed Sep  6 09:06:15 2006
@@ -34,6 +34,7 @@
 import java.awt.image.MultiPixelPackedSampleModel;
 import java.awt.image.SampleModel;
 import java.awt.image.WritableRaster;
+import java.util.ArrayList;
 
 import org.apache.harmony.awt.gl.color.LUTColorConverter;
 
@@ -50,6 +51,11 @@
     public static final int Linear_RGB_CS = 2;
     public static final int Linear_Gray_CS = 3;
     public static final int Custom_CS = 0;
+    
+    // Color Model Types
+    public static final int DCM = 1;  // Direct Color Model
+    public static final int ICM = 2;  // Index Color Model
+    public static final int CCM = 3;  // Component Color Model
 
     // Sample Model Types
     public static final int SPPSM = 1;  // Single Pixel Packed Sample Model
@@ -84,6 +90,14 @@
     protected int width;
     protected int height;
 
+    /**
+     * This list contains caches with the data of this surface that are valid at the moment.
+     * Surface should clear this list when its data is updated.
+     * Caches may check if they are still valid using isCacheValid method.
+     * When cache gets data from the surface, it should call addValidCache method of the surface.
+     */
+    private ArrayList validCaches = new ArrayList();
+
     public abstract ColorModel getColorModel();
     public abstract WritableRaster getRaster();
     public abstract int getSurfaceType(); // Syrface type. It is equal 
@@ -108,6 +122,18 @@
         return surfaceDataPtr;
     }
 
+    public final boolean isCaheValid(Object cache) {
+        return validCaches.contains(cache);
+    }
+
+    public final void addValidCache(Object cache) {
+        validCaches.add(cache);
+    }
+
+    protected final void clearValidCaches() {
+        validCaches.clear();
+    }
+
     /**
      * Returns could or coldn't the Surface be blit by Native blitter 
      * @return - true if the Surface could be blit by Native blitter, 
@@ -136,6 +162,14 @@
     public Object getData(){
         return null;
     }
+    
+    public boolean invalidated(){
+        return true;
+    }
+    
+    public void validate(){}
+    
+    public void invalidate(){}
 
     /**
      * Computation type of BufferedImage or Surface

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/TextRenderer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/TextRenderer.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/TextRenderer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/TextRenderer.java Wed Sep  6 09:06:15 2006
@@ -33,7 +33,7 @@
      * @param y start Y position to draw
      */
     public abstract void drawString(Graphics2D g, String str, float x, float y);
-    
+
     /**
      * Draws string on specified Graphics at desired position.
      * 
@@ -41,11 +41,11 @@
      * @param str String object to draw
      * @param x start X position to draw
      * @param y start Y position to draw
-     */
+     */    
     public void drawString(Graphics2D g, String str, int x, int y){
         drawString(g, str, (float)x, (float)y);
     }
-    
+
     /**
      * Draws GlyphVector on specified Graphics at desired position.
      * 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/CommonGlyphVector.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/CommonGlyphVector.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/CommonGlyphVector.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/CommonGlyphVector.java Wed Sep  6 09:06:15 2006
@@ -50,6 +50,7 @@
     float[] defaultPositions;
 
     // array of logical positions of glyphs in GlyphVector
+
     float[] logicalPositions;
 
     // array of visual (real) positions of glyphs in GlyphVector
@@ -60,7 +61,7 @@
 
     // layout flags mask
     protected int layoutFlags = 0;
-    
+
     // array of cached glyph outlines 
     protected Shape[] gvShapes;
 
@@ -203,7 +204,7 @@
     /**
      * Returnes the pixel bounds of this GlyphVector rendered at the 
      * specified x,y location with the given FontRenderContext.
-     * 
+     *  
      * @param frc a FontRenderContext that is used
      * @param x specified x coordinate value
      * @param y specified y coordinate value
@@ -459,7 +460,7 @@
     /**
      * Returnes the pixel bounds of the specified glyph within GlyphVector 
      * rendered at the specified x,y location.
-     * 
+     *  
      * @param glyphIndex index of the glyph
      * @param frc a FontRenderContext that is used
      * @param x specified x coordinate value
@@ -859,7 +860,7 @@
     }
 
     /**
-     * Clear desired flags in layout flags describing the state.
+     * Clear desired flags in layout flags describing the state. 
      * 
      * @param clearFlags flags mask to clear 
      */

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/CompositeFont.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/CompositeFont.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/CompositeFont.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/CompositeFont.java Wed Sep  6 09:06:15 2006
@@ -19,28 +19,23 @@
  */
 package org.apache.harmony.awt.gl.font;
 
-import java.awt.Font;
 import java.awt.font.FontRenderContext;
 import java.awt.font.LineMetrics;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
 
-import org.apache.harmony.awt.gl.CommonGraphics2DFactory;
 import org.apache.harmony.awt.gl.font.FontPeerImpl;
 import org.apache.harmony.awt.gl.font.FontProperty;
 
 /**
-  * CompositeFont class is the implementation of logical font classes. 
-  * Every logical font consists of several physical fonts that described 
-  * in font.properties file according to the face name of this logical font.
-  */
+ * CompositeFont class is the implementation of logical font classes. 
+ * Every logical font consists of several physical fonts that described 
+ * in font.properties file according to the face name of this logical font.
+ */
 public class CompositeFont extends FontPeerImpl{
     
     // a number of physical fonts that CompositeFont consist of 
     int numFonts;
-    
-    // font name
-    String name;
 
     // font family name
     String family;
@@ -48,20 +43,13 @@
     // font face name
     String face;
 
-    // font postscript name
-    String psName;
-
-    // font style
-    int style;
-
-    // font size
-    float size;
+    String[] fontNames;
     
     // an array of font properties applicable to this CompositeFont
     FontProperty[] fontProperties;
     
     // an array of font peers applicable to this CompositeFont
-    public FontPeerImpl[] physicalFonts;
+    public FontPeerImpl[] fPhysicalFonts;
     
     // missing glyph code field
     int missingGlyphCode = -1;
@@ -72,35 +60,33 @@
     // cached num glyphs parameter of this font that is the sum of num glyphs of 
     // font peers composing this font
     int cachedNumGlyphs = -1;
-    
     /**
      * Creates CompositeFont object that is corresponding to the specified logical 
      * family name.
      * 
-     * @param font Font object CompositeFont is to be created from
+     * @param familyName logical family name CompositeFont is to be created from
+     * @param faceName logical face name CompositeFont is to be created from
+     * @param _style style of the CompositeFont to be created
+     * @param _size size of the CompositeFont to be created 
      * @param fProperties an array of FontProperties describing physical fonts - 
      * parts of logical font
-     * @param familyName family name of the logical font
+     * @param physFonts an array of physical font peers related to the CompositeFont
+     * to be created
      */
-    public CompositeFont(Font font, FontProperty[] fProperties, String familyName){
-        this.size = font.getSize();
-        this.name = font.getName();
+    public CompositeFont(String familyName, String faceName, int _style, int _size, FontProperty[] fProperties, FontPeerImpl[] physFonts){
+        this.size = _size;
+        this.name = faceName;
         this.family = familyName;
-        this.style = font.getStyle();
-        this.face = family.concat(".").concat(FontManager.STYLE_NAMES[style]);
-        this.psName = family.toLowerCase().concat(".").concat(FontManager.STYLE_NAMES[style]);
+        this.style = _style;
+        this.face = faceName;
+        this.psName = faceName;
         this.fontProperties = fProperties;// !! Supposed that fProperties parameter != null
-        this.numFonts = fontProperties.length;
-        physicalFonts = new FontPeerImpl[numFonts];
-        for (int i = 0; i < numFonts; i++){
-            FontProperty fp = fontProperties[i];
-            physicalFonts[i] = (FontPeerImpl)CommonGraphics2DFactory.inst.getFontManager().createFont(fp, (int)size);
-        }
-
+        fPhysicalFonts = physFonts;
+        numFonts = fPhysicalFonts.length; 
         setDefaultLineMetrics("", null);
         this.uniformLM = false;
     }
-    
+
     /**
      * Returns the index of the FontPeer in array of physical fonts that is applicable 
      * for the given character. This font has to have the highest priority among fonts
@@ -116,7 +102,7 @@
             if (fontProperties[i].isCharExcluded(chr)){
                 continue;
             }
-            if (physicalFonts[i].canDisplay(chr)){
+            if (fPhysicalFonts[i].canDisplay(chr)){
                 return i;
             }
         }
@@ -135,12 +121,12 @@
      * @return index of the font from the array of physical fonts that will be used 
      * during processing of the specified character. 
      */
-    public int getCharFontIndex(char chr, int defaultValue){
+     public int getCharFontIndex(char chr, int defaultValue){
         for (int i = 0; i < numFonts; i++){
             if (fontProperties[i].isCharExcluded(chr)){
                 continue;
             }
-            if (physicalFonts[i].canDisplay(chr)){
+            if (fPhysicalFonts[i].canDisplay(chr)){
                 return i;
             }
         }
@@ -157,14 +143,14 @@
     public boolean canDisplay(char chr){
         return (getCharFontIndex(chr) != -1);
     }
-    
+
     /**
      * Returns logical ascent (in pixels)
      */
     public int getAscent(){
         return nlm.getLogicalAscent();
     }
-    
+
     /**
      * Returns LineMetrics instance scaled according to the specified transform.  
      * 
@@ -172,7 +158,7 @@
      * @param frc specified FontRenderContext 
      * @param at specified AffineTransform
      */
-    public LineMetrics getLineMetrics(String str, FontRenderContext frc , AffineTransform at){
+     public LineMetrics getLineMetrics(String str, FontRenderContext frc , AffineTransform at){
         LineMetricsImpl lm = (LineMetricsImpl)(this.nlm.clone());
         lm.setNumChars(str.length());
 
@@ -205,8 +191,8 @@
      * @param frc specified FontRenderContext 
      */
     private void setDefaultLineMetrics(String str, FontRenderContext frc){
-        LineMetrics lm = physicalFonts[0].getLineMetrics(str, frc, null);
-        float maxCharWidth = (float)physicalFonts[0].getMaxCharBounds(frc).getWidth();
+        LineMetrics lm = fPhysicalFonts[0].getLineMetrics(str, frc, null);
+        float maxCharWidth = (float)fPhysicalFonts[0].getMaxCharBounds(frc).getWidth();
 
         if (numFonts == 1) {
             this.nlm = (LineMetricsImpl)lm;
@@ -229,7 +215,7 @@
         float maxDescent = lm.getDescent(); // Descent of the font
 
         for (int i = 1; i < numFonts; i++){
-            lm = physicalFonts[i].getLineMetrics(str, frc, null);
+            lm = fPhysicalFonts[i].getLineMetrics(str, frc, null);
             if (maxUnderlineThickness < lm.getUnderlineThickness()){
                 maxUnderlineThickness = lm.getUnderlineThickness();
             }
@@ -258,7 +244,7 @@
                 maxDescent = lm.getDescent();
             }
 
-            float width = (float)physicalFonts[i].getMaxCharBounds(frc).getWidth();
+            float width = (float)fPhysicalFonts[i].getMaxCharBounds(frc).getWidth();
             if(maxCharWidth < width){
                 maxCharWidth = width;
             }
@@ -297,7 +283,7 @@
             this.cachedNumGlyphs = 0;
 
             for (int i = 0; i < numFonts; i++){
-                this.cachedNumGlyphs += physicalFonts[i].getNumGlyphs();
+                this.cachedNumGlyphs += fPhysicalFonts[i].getNumGlyphs();
             }
         }
 
@@ -309,7 +295,7 @@
      */
     public float getItalicAngle(){
         // !! only first physical font used to get this value
-        return physicalFonts[0].getItalicAngle();
+        return fPhysicalFonts[0].getItalicAngle();
     }
 
     /**
@@ -347,22 +333,35 @@
      */
     public Rectangle2D getMaxCharBounds(FontRenderContext frc){
 
-        Rectangle2D rect2D = physicalFonts[0].getMaxCharBounds(frc);
-
+        Rectangle2D rect2D = fPhysicalFonts[0].getMaxCharBounds(frc);
+        float minY = (float)rect2D.getY();
+        float maxWidth = (float)rect2D.getWidth();
+        float maxHeight = (float)rect2D.getHeight();
         if (numFonts == 1){
             return rect2D;
         }
 
         for (int i = 1; i < numFonts; i++){
-            if (physicalFonts[i] != null){
-                Rectangle2D currRect2D = physicalFonts[i].getMaxCharBounds(frc);
-                float minY = (float)(rect2D.getY() < currRect2D.getY()? rect2D.getY() : currRect2D.getY());
-                float maxWidth = (float)(rect2D.getWidth() > currRect2D.getWidth()? rect2D.getWidth() : currRect2D.getWidth());
-                float maxHeight = (float)(rect2D.getHeight() > currRect2D.getHeight()? rect2D.getHeight() : currRect2D.getHeight());
-                rect2D = new Rectangle2D.Float(0, minY, maxWidth, maxHeight);
+            if (fPhysicalFonts[i] != null){
+                rect2D = fPhysicalFonts[i].getMaxCharBounds(frc);
+                float y = (float)rect2D.getY();
+                float mWidth = (float)rect2D.getWidth();
+                float mHeight = (float)rect2D.getHeight();
+                if (y < minY){
+                    minY = y;
+                }
+                if (mWidth > maxWidth){
+                    maxHeight = mWidth;
+                }
+                
+                if (mHeight > maxHeight){
+                    maxHeight = mHeight;
+                }
             }
         }
 
+        rect2D = new Rectangle2D.Float(0, minY, maxWidth, maxHeight);
+
         return rect2D;
     }
 
@@ -392,7 +391,7 @@
      */
     public int getMissingGlyphCode(){
         // !! only first physical font used to get this value
-        return physicalFonts[0].getMissingGlyphCode();
+        return fPhysicalFonts[0].getMissingGlyphCode();
     }
 
     /**
@@ -405,19 +404,14 @@
             if (fontProperties[i].isCharExcluded(ch)){
                     continue;
             }
-            if (physicalFonts[i].canDisplay(ch)){
-                return physicalFonts[i].getGlyph(ch);
+            
+            /* Control symbols considered to be supported by the font peer */
+            if ((ch < 0x20) || fPhysicalFonts[i].canDisplay(ch)){
+                return fPhysicalFonts[i].getGlyph(ch);
             }
         }
         return getDefaultGlyph();
     }
-    
-    /**
-     * Disposes resources. 
-     */
-    public void dispose(){
-        if (true) throw new RuntimeException("Method is not implemented");
-    }
 
     /**
      * Returns width of the char with specified index.
@@ -425,9 +419,7 @@
      * @param ind specified index of the character 
      */
     public int charWidth(int ind){
-        if (true) throw new RuntimeException("Method is not implemented");
-        return 0;
-
+        return charWidth((char)ind);
     }
 
     /**
@@ -439,7 +431,7 @@
         Glyph gl = this.getGlyph(c);
         return (int)gl.getGlyphPointMetrics().getAdvanceX();
     }
-    
+
     /**
      * Returns debug information about this class.
      */
@@ -455,7 +447,23 @@
      */
     public Glyph getDefaultGlyph(){
         // !! only first physical font used to get this value
-        return physicalFonts[0].getDefaultGlyph();
+        return fPhysicalFonts[0].getDefaultGlyph();
+    }
+    
+    /**
+     * Returns FontExtraMetrics object with extra metrics
+     * related to this CompositeFont.
+     */
+    public FontExtraMetrics getExtraMetrics(){
+        // Returns FontExtraMetrics instanse of the first physical 
+        // Font from the array of fonts.
+        return fPhysicalFonts[0].getExtraMetrics();
     }
 
+    /**
+     * Disposes CompositeFont object's resources.
+     */
+    public void dispose() {
+        // Nothing to dispose
+    }
 }

Added: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/FontExtraMetrics.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/FontExtraMetrics.java?view=auto&rev=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/FontExtraMetrics.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/FontExtraMetrics.java Wed Sep  6 09:06:15 2006
@@ -0,0 +1,144 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+ * @author Ilya S. Okomin
+ * @version $Revision$
+ * 
+ */
+package org.apache.harmony.awt.gl.font;
+
+/**
+ * Extra font metrics: sub/superscripts sizes, offsets, average char width.
+ */
+public class FontExtraMetrics {
+    
+    /* !! Subscript/superscript metrics are undefined for Type1. As a possible 
+     * solution we can use values for Type1, that are proportionate to TrueType
+     * ones:
+     *  SubscriptSizeX == 0.7 * fontSize
+     *  SubscriptSizeY == 0.65 * fontSize
+     *  SubscriptOffsetX == 0;
+     *  SubscriptOffsetY == 0.15 * fontSize;
+     *  SuperscriptSizeX == 0.7 * fontSize
+     *  SuperscriptSizeY == 0.65 * fontSize
+     *  SuperscriptOffsetX == 0;
+     *  SuperscriptOffsetY == 0.45 * fontSize
+     *  
+     */
+    
+    /*
+     * The average width of characters in the font.
+     */
+    private float lAverageCharWidth;
+    
+    /*
+     * Horizontal size for subscripts.
+     */
+    private float lSubscriptSizeX;
+
+    /*
+     * Vertical size for subscripts.
+     */
+    private float lSubscriptSizeY; 
+    
+    /*
+     * Horizontal offset for subscripts, the offset from the character origin 
+     * to the origin of the subscript character.
+     */
+    private float lSubscriptOffsetX; 
+
+    /*
+     * Vertical offset for subscripts, the offset from the character origin 
+     * to the origin of the subscript character.
+     */
+    private float lSubscriptOffsetY;
+    
+    /*
+     * Horizontal size for superscripts.
+     */
+    private float lSuperscriptSizeX; 
+
+    /*
+     * Vertical size for superscripts.
+     */
+    private float lSuperscriptSizeY;
+    
+    /*
+     * Horizontal offset for superscripts, the offset from the character 
+     * base line to the base line of the superscript character.
+     */
+    private float lSuperscriptOffsetX;
+
+    /*
+     * Vertical offset for superscripts, the offset from the character 
+     * base line to the base line of the superscript character.
+     */
+    private float lSuperscriptOffsetY;
+    
+    public FontExtraMetrics(){
+        // default constructor
+    }
+
+    public FontExtraMetrics(float[] metrics){
+        lAverageCharWidth = metrics[0];
+        lSubscriptSizeX = metrics[1];
+        lSubscriptSizeY = metrics[2];
+        lSubscriptOffsetX = metrics[3];
+        lSubscriptOffsetY = metrics[4];
+        lSuperscriptSizeX = metrics[5];
+        lSuperscriptSizeY = metrics[6];
+        lSuperscriptOffsetX = metrics[7];
+        lSuperscriptOffsetY = metrics[8];
+    }
+
+    public float getAverageCharWidth(){
+        return lAverageCharWidth;
+    }
+    
+    public float getSubscriptSizeX(){
+        return lSubscriptSizeX;
+    }
+
+    public float getSubscriptSizeY(){
+        return lSubscriptSizeY;
+    }
+
+    public float getSubscriptOffsetX(){
+        return lSubscriptOffsetX;
+    }
+
+    public float getSubscriptOffsetY(){
+        return lSubscriptOffsetY;
+    }
+
+    public float getSuperscriptSizeX(){
+        return lSuperscriptSizeX;
+    }
+
+    public float getSuperscriptSizeY(){
+        return lSuperscriptSizeY;
+    }
+
+    public float getSuperscriptOffsetX(){
+        return lSuperscriptOffsetX;
+    }
+
+    public float getSuperscriptOffsetY(){
+        return lSuperscriptOffsetY;
+    }
+    
+    
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/FontManager.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/FontManager.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/FontManager.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/FontManager.java Wed Sep  6 09:06:15 2006
@@ -24,6 +24,9 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Locale;
@@ -40,6 +43,9 @@
      */
     public String[] allFamilies;
 
+    public static final String DEFAULT_NAME = "Default"; /* Default font name */
+    public static final String DIALOG_NAME = "Dialog";  /* Dialog font name */
+
     /**
      * Set of constants applicable to the TrueType 'name' table.
      */
@@ -47,7 +53,7 @@
     public static final byte  FONT_NAME_ID  = 4;        /* Full font name identifier    */
     public static final byte  POSTSCRIPT_NAME_ID = 6;   /* PostScript name identifier   */
     public static final short ENGLISH_LANGID = 0x0409;  /* English (United States)language identifier   */
-    
+
     /**
      * Set of constants describing font type.
      */
@@ -55,6 +61,14 @@
     public static final byte  FONT_TYPE_T1  = 2;        /* Type1 type    (DEVICE_FONTTYPE)      */
     public static final byte  FONT_TYPE_UNDEF  = 0;     /* Undefined type                       */
 
+    // logical family types (indices in FontManager.LOGICAL_FONT_NAMES)
+    static final int DIALOG = 3;        // FF_SWISS
+    static final int SANSSERIF = 1;     // FF_SWISS
+    static final int DIALOGINPUT = 4;   // FF_MODERN
+    static final int MONOSPACED = 2;    // FF_MODERN
+    static final int SERIF = 0;         // FF_ROMAN
+
+
     /**
      * FontProperty related constants. 
      */
@@ -75,17 +89,32 @@
     public static final String FONT_FILE_NAME = "filename.PlatformFontName";
 
     /**
-     * Available font names.
+     * Available logical font families names.
+     */
+    public static final String[] LOGICAL_FONT_FAMILIES = {
+            "Serif", "SansSerif", "Monospaced", "Dialog", "DialogInput"
+    };
+
+    /**
+     * Available logical font names.
      */
     public static final String[] LOGICAL_FONT_NAMES = {
-            "serif", "sansserif", "monospaced", "dialog", "dialoginput"
+            "serif", "serif.plain", "serif.bold", "serif.italic", "serif.bolditalic",
+            "sansserif", "sansserif.plain", "sansserif.bold", "sansserif.italic", "sansserif.bolditalic",
+            "monospaced", "monospaced.plain", "monospaced.bold", "monospaced.italic", "monospaced.bolditalic",
+            "dialog", "dialog.plain", "dialog.bold", "dialog.italic", "dialog.bolditalic",
+            "dialoginput", "dialoginput.plain", "dialoginput.bold", "dialoginput.italic", "dialoginput.bolditalic"
     };
-    
+
     /**
-     * Available font families names.
+     * Available logical font face names.
      */
-    public static final String[] LOGICAL_FONT_FAMILIES = {
-            "Serif", "SansSerif", "Monospaced", "Dialog", "DialogInput"
+    public static final String[] LOGICAL_FONT_FACES = {
+            "Serif", "Serif.plain", "Serif.bold", "Serif.italic", "Serif.bolditalic",
+            "Sansserif", "Sansserif.plain", "Sansserif.bold", "Sansserif.italic", "Sansserif.bolditalic",
+            "Monospaced", "Monospaced.plain", "Monospaced.bold", "Monospaced.italic", "Monospaced.bolditalic",
+            "Dialog", "Dialog.plain", "Dialog.bold", "Dialog.italic", "Dialog.bolditalic",
+            "Dialoginput", "Dialoginput.plain", "Dialoginput.bold", "Dialoginput.italic", "Dialoginput.bolditalic"
     };
 
     /**
@@ -95,29 +124,29 @@
     public static final String[] STYLE_NAMES = {
             "plain", "bold", "italic", "bolditalic"
     };
-    
+
     /**
-     * Logical font names table where font names used as the key
-     * and the value is the index of this name.
+     * Logical font styles names table where font styles names used 
+     * as the key and the value is the index of this style name.
      */
-    private static Hashtable keys = new Hashtable(5);
-    
+    private static Hashtable style_keys = new Hashtable(4);
+
     /**
-     * Initialize keys table.
+     * Initialize font styles keys table.
      */
     static {
-        for (int i = 0; i < LOGICAL_FONT_NAMES.length; i++){
-            keys.put(LOGICAL_FONT_NAMES[i], new Integer(i));
+        for (int i = 0; i < STYLE_NAMES.length; i++){
+            style_keys.put(STYLE_NAMES[i], new Integer(i));
         }
     }
-    
+
     /**
-     * Returns index in the LOGICAL_FONT_NAMES array of the logical name specified.
+     * Return font style from the logical style name.
      * 
-     * @param lName specified logical font name
+     * @param lName style name of the logical face
      */
-    public static int getLogicalIndex(String lName){
-        Integer value = (Integer) keys.get(lName);
+    public static int getLogicalStyle(String lName){
+        Integer value = (Integer) style_keys.get(lName);
         return value != null ? value.intValue(): -1;
     }
 
@@ -161,6 +190,10 @@
             "/lib/font.properties"
     };
 
+    /**
+     * Table with all available font properties corresponding
+     * to the current system configuration.
+     */
     public Hashtable fProperties = new Hashtable();
 
     public FontManager(){
@@ -172,8 +205,9 @@
         DisposeNativeHook shutdownHook = new DisposeNativeHook();
         Runtime.getRuntime().addShutdownHook(shutdownHook);
     }
+
     /**
-     * 
+     * Maximum number of unreferensed font peers to keep.
      */
     public static final int EMPTY_FONTS_CAPACITY = 10;
 
@@ -185,13 +219,14 @@
     /**
      * Hash table that contains FontPeers instances.
      */
-    public Hashtable fonts = new Hashtable();
 
+    public Hashtable fontsTable = new Hashtable();
+    
     /**
-     * Vector of keys objects for the fonts Hashtable,
-     * that have no references to Java font objects.
+     * ReferenceQueue for HashMapReference objects to check
+     * if they were collected by garbage collector. 
      */
-    public Vector unrefs = new Vector();
+    public ReferenceQueue queue = new ReferenceQueue();
 
     /**
      * Singleton instance
@@ -209,127 +244,253 @@
     }
 
     /**
-     * Returns platform-dependent Font peer from the specified Font.
-     * 
-     * @param font the specified Font object
-     * @return platform dependent FontPeer implementation created from Font
-     */
-    public abstract FontPeer createFont(Font font);
-
-    /**
-     * Creates platform-dependent Font peer from the specified FontProperty
-     *  and size.
-     * 
-     * @param fp the specified FontProperty object
-     * @param size the point size of the Font
-     * 
-     * @return platform dependent FontPeer implementation with specified  
-     * FontProperty and size parameters
-     */
-    public abstract FontPeer createFont(FontProperty fp, int size);
-
-    /**
      * Returns platform-dependent Font peer created from the specified 
-     * FontProperty and size from the table with cached FontPeers instanses.
+     * Font object from the table with cached FontPeers instanses.
      * 
      * Note, this method checks whether FontPeer with specified parameters 
      * exists in the table with cached FontPeers' instanses. If there is no needed 
-     * instanse - it is created and cached. Required FontPeer instanse 
-     * fetched from the table with cached FontPeers' instanses.  
+     * instanse - it is created and cached.
+     * 
+     * @param fontName name of the font 
+     * @param _fontStyle style of the font 
+     * @param size font size
      * 
-     * @param fontID string that uniquily describes font 
-     * (fontname+fontstyle+fontsize)
-     * @param fp the specified FontProperty object
-     * @param size the point size of the Font
      * @return platform dependent FontPeer implementation created from 
-     * FontProperty and size parameters
+     * the specified parameters
      */
-    public FontPeer setFont(String fontID, FontProperty fp, int size){
-        if (!fonts.containsKey(fontID)){
-            FontPeer peer = createFont(fp, size);
-            fonts.put(fontID, peer);
+    public FontPeer getFontPeer(String fontName, int _fontStyle, int size) {
+        
+        updateFontsTable();
+        
+        FontPeer peer = null;
+        String key; 
+        String name;
+        int fontStyle = _fontStyle;
+        
+        int logicalIndex = getLogicalFaceIndex(fontName);
+        
+        if (logicalIndex != -1){
+            name = getLogicalFaceFromFont(fontStyle, logicalIndex);
+            fontStyle = getStyleFromLogicalFace(name);
+            key = name.concat(String.valueOf(size));
+        } else {
+            name = fontName;
+            key = name.concat(String.valueOf(fontStyle)).
+                    concat(String.valueOf(size));
+        }
+        
+        Reference hmr   = (Reference)fontsTable.get(key);
+        if (hmr != null) {
+            peer = (FontPeer)hmr.get();
+        }
+
+        if (peer == null) {
+            peer = createFontPeer(name, fontStyle, size, logicalIndex);
+            if (peer == null){
+                peer = getFontPeer(DIALOG_NAME, fontStyle, size);
+            }
+            fontsTable.put(key, new HashMapReference(key, peer, queue));
         }
-        return (FontPeer)fonts.get(fontID);
 
+        return peer;
     }
-
+    
     /**
-     * Returns platform-dependent Font peer created from the specified 
-     * Font object from the table with cached FontPeers instanses.
+     * Returns instanse of font peer (logical or physical) according to the 
+     * specified parameters.
      * 
-     * Note, this method checks whether FontPeer with specified parameters 
-     * exists in the table with cached FontPeers' instanses. If there is no needed 
-     * instanse - it is created and cached. Required FontPeer instanse 
-     * fetched from the table with cached FontPeers' instanses. 
-     * @param fontStr string that uniquily describes font 
-     * (fontname+fontstyle+fontsize)
-     * @param font specified Font
-     *
-     * @return platform dependent FontPeer implementation created from 
-     * the specified Font object
-     */
-    public FontPeer setFont(String fontStr, Font font) {
-        if (!fonts.containsKey(fontStr)){
-            FontPeer peer = createFont(font);
-            fonts.put(fontStr, peer);
+     * @param name font face name
+     * @param style style of the font
+     * @param size size of the font
+     * @param logicalIndex index of the logical face name in LOGICAL_FONT_FACES 
+     * array or -1 if desired font peer is not logical.
+     */
+    private FontPeer createFontPeer(String name, int style, int size, int logicalIndex){
+        FontPeer peer;
+        if (logicalIndex != -1){
+            peer = createLogicalFontPeer(name, style, size);
+        }else {
+            peer = createPhysicalFontPeer(name, style, size);
         }
-        return (FontPeer)fonts.get(fontStr);
-    }
+        
+        return peer;
+    } 
+    
+    /**
+     * Returns family name for logical face names as a parameter.
+     * 
+     * @param faceName logical font face name
+     */
+    public String getFamilyFromLogicalFace(String faceName){
+        int pos = faceName.indexOf(".");
+        if (pos == -1){
+            return faceName;
+        }
+            
+        return faceName.substring(0, pos);
+    }
+            
+    /**
+     * Returns new logical font peer for the parameters specified using font 
+     * properties.
+     * 
+     * @param faceName face name of the logical font 
+     * @param style style of the font 
+     * @param size font size
+     * 
+     */
+    private FontPeer createLogicalFontPeer(String faceName, int style, int size){
+        String family = getFamilyFromLogicalFace(faceName);
+        FontProperty[] fps = getFontProperties(family.toLowerCase() + "." + style);
+        if (fps != null){
+            int numFonts = fps.length;
+            FontPeerImpl[] physicalFonts = new FontPeerImpl[numFonts];
+            for (int i = 0; i < numFonts; i++){
+                FontProperty fp = fps[i];
+                
+                String name = fp.getName();
+                int fpStyle = fp.getStyle();
+                String key = name.concat(String.valueOf(fpStyle)).
+                    concat(String.valueOf(size));
+                
+                Reference hmr   = (Reference)fontsTable.get(key);
+                if (hmr != null) {
+                    physicalFonts[i] = (FontPeerImpl)hmr.get();
+                }
+
+                if (physicalFonts[i] == null){
+                    physicalFonts[i] = (FontPeerImpl)createPhysicalFontPeer(name, fpStyle, size);
+                    fontsTable.put(key, new HashMapReference(key, physicalFonts[i], queue));
+                }
 
+                if (physicalFonts[i] == null){
+                    physicalFonts[i] = (FontPeerImpl)getDefaultFont(style, size);
+                }
+            }
+            return new CompositeFont(family, faceName, style, size, fps, physicalFonts); 
+        }
+        
+        // if there is no property for this logical font - default font is to be
+        // created
+        FontPeerImpl peer = (FontPeerImpl)getDefaultFont(style, size);
+        
+        return peer;
+    } 
 
     /**
-     * Returns font peer instance corresponding to the specified 
-     * font string id.
-     * 
-     * If number of Font references after inrcrement in FontPeer
-     * object is equal to 1 it means, that FontPeer was in list of
-     * fonts that have no references to Font objects. For this
-     * reason, this FontPeer can be deleted from unrefs list.
+     * Returns new physical font peer for the parameters specified using font properties
+     * This method must be overridden by subclasses implementations.
+     *  
+     * @param faceName face name or family name of the font 
+     * @param style style of the font 
+     * @param size font size
      * 
-     * @param fontStr specified font string id
      */
-    public FontPeer getFont(String fontStr){
-        FontPeerImpl peer = (FontPeerImpl)fonts.get(fontStr);
+    public abstract FontPeer createPhysicalFontPeer(String name, int style, int size);
+    
+    /**
+     * Returns default font peer class with "Default" name that is usually 
+     * used when font with specified font names and style doesn't exsist 
+     * on a system. 
+     * 
+     * @param style style of the font
+     * @param size size of the font
+     */
+    public FontPeer getDefaultFont(int style, int size){
+        updateFontsTable();
+        
+        FontPeer peer = null;
+        String key = DEFAULT_NAME.concat(String.valueOf(style)).
+                    concat(String.valueOf(size));
+        
+        Reference hmr   = (Reference)fontsTable.get(key);
+        if (hmr != null) {
+            peer = (FontPeer)hmr.get();
+        }
+
+        if (peer == null) {
+            peer = createDefaultFont(style, size);
+            
+            ((FontPeerImpl)peer).setFamily(DEFAULT_NAME);
+            ((FontPeerImpl)peer).setPSName(DEFAULT_NAME);
+            ((FontPeerImpl)peer).setFontName(DEFAULT_NAME);
 
-        if (peer != null){
-            int numRef = peer.addRef();
-            if (numRef == 1)
-                unrefs.remove(fontStr);
+            fontsTable.put(key, new HashMapReference(key, peer, queue));
         }
+
         return peer;
     }
-
+    
     /**
-     * Moves font with specified font string id to the unreferenced font 
-     * objects list.
      * 
-     * If number of Font references after decrement in FontPeer
-     * object is equal to 0 it means, that FontPeer has 
-     * no references to Font objects. For this
-     * reason, this FontPeer must be added to the first
-     * position in unrefs list. If the number of emelemnts in list
-     * is equals to it's size - the last element must be deleted, as
-     * the low-activity object.
-     * 
-     * @param fontStr specified font string id
-     */
-    public void deleteFont(String fontStr){
-        FontPeerImpl peer = (FontPeerImpl)fonts.get(fontStr);
-        if (peer != null){
-            int numRef = peer.removeRef();
-            if (numRef == 0){
-                if (unrefs.size() == EMPTY_FONTS_CAPACITY){
-                    Object obj = unrefs.remove(EMPTY_FONTS_CAPACITY - 1);
-                    FontPeerImpl delPeer = (FontPeerImpl)fonts.remove(obj);
-
-                    delPeer.dispose();
-                }
-                unrefs.add(0, peer);
-            }
+     * Returns new default font peer with "Default" name for the parameters 
+     * specified. This method must be overridden by subclasses implementations.
+     *  
+     * @param style style of the font
+     * @param size size of the font
+     */
+    public abstract FontPeer createDefaultFont(int style, int size);
+    
+    /**
+     * Returns face name of the logical font, which is the result
+     * of specified font style and face style union.   
+     * 
+     * @param fontStyle specified style of the font
+     * @param logicalIndex index of the specified face from the 
+     * LOGICAL_FONT_FACES array
+     * @return resulting face name
+     */
+    public String getLogicalFaceFromFont(int fontStyle, int logicalIndex){
+        int style = 0;
+        String name = LOGICAL_FONT_FACES[logicalIndex];
+        int pos = name.indexOf(".");
+        
+        if (pos == -1){
+            return createLogicalFace(name, fontStyle);
+        }
+        
+        String styleName = name.substring(pos+1);
+        name = name.substring(0, pos);
+        
+        // appending font style to the face style
+        style = fontStyle | getLogicalStyle(styleName);
+        
+        return createLogicalFace(name, style);
+    }
+    
+    /**
+     * Function returns style value from logical face name.
+     *  
+     * @param name face name
+     * @return font style
+     */
+    public int getStyleFromLogicalFace(String name){
+        int style;
+        int pos = name.indexOf(".");
+        
+        if (pos == -1){
+            return Font.PLAIN;
         }
+        
+        String styleName = name.substring(pos+1);
+        
+        style = getLogicalStyle(styleName);
+        
+        return style;
     }
 
     /**
+     * Returns logical face name corresponding to the logical
+     * family name and style of the font.
+     * 
+     * @param family font family
+     * @param styleIndex index of the style name from the STYLE_NAMES array 
+     */
+    public String createLogicalFace(String family, int styleIndex){
+        return family + "." + STYLE_NAMES[styleIndex];
+    }
+    
+    /**
      * Return language Id from LCID hash corresponding to the specified locale
      * 
      * @param l specified locale
@@ -356,15 +517,20 @@
         public void run() {
             try{
                 /* Disposing native font peer's resources */
-                Enumeration kEnum = fonts.keys();
+                Enumeration kEnum = fontsTable.keys();
 
                 while(kEnum.hasMoreElements()){
                     Object key = kEnum.nextElement();
-                    FontPeerImpl delPeer = (FontPeerImpl)fonts.remove(key);
-                    delPeer.dispose();
+                    HashMapReference hmr = (HashMapReference)fontsTable.remove(key);
+                    FontPeerImpl delPeer = (FontPeerImpl)hmr.get();
+                    
+                    if ((delPeer != null) && (delPeer.getClass() != CompositeFont.class)){
+                        // there's nothing to dispose in CompositeFont objects
+                        delPeer.dispose();
+                    }
                 }
             } catch (Throwable t){
-
+                throw new RuntimeException(t);
             }
         }
       }
@@ -504,19 +670,26 @@
     }
 
     /**
-     * Returns an array of FontProperties from the properties set
-     * with the specified font property name.
-     * 
+     * Returns an array of FontProperties from the properties file
+     * with the specified property name "logical face.style". E.g. 
+     * "dialog.2" corresponds to the font family Dialog with bold style. 
+     *
      * @param fpName key of the font properties in the properties set
      */
     public FontProperty[] getFontProperties(String fpName){
         Vector props = (Vector)fProperties.get(fpName);
-
+        
         if (props == null){
             return null;
         }
 
-        FontProperty[] fps = new FontProperty[props.size()];
+        int size =  props.size();
+        
+        if (size == 0){
+            return null;
+        }
+
+        FontProperty[] fps = new FontProperty[size];
         for (int i=0; i < fps.length; i++){
             fps[i] = (FontProperty)props.elementAt(i);
         }
@@ -524,18 +697,18 @@
     }
 
     /**
-     * Returns true if specified font is logical.
+     * Returns index of the font name in array of font names or -1 if 
+     * this font is not logical.
      * 
-     * @param font the specified font object
+     * @param fontName specified font name
      */
-    public static boolean isFontLogical(Font font){
-        String name = font.getName();
+    public static int getLogicalFaceIndex(String fontName){
         for (int i=0; i<LOGICAL_FONT_NAMES.length; i++ ){
-            if (LOGICAL_FONT_NAMES[i].equalsIgnoreCase(name)){
-                return true;
+            if (LOGICAL_FONT_NAMES[i].equalsIgnoreCase(fontName)){
+                return i;
             }
         }
-        return false;
+        return -1;
     }
 
     /**
@@ -545,40 +718,95 @@
      * @param familyName the specified font family name
      */
     public boolean isFamilyExist(String familyName){
+        return (getFamilyIndex(familyName) != -1);
+    }
+
+    /**
+     * Returns index of family name from the array of family names available in 
+     * this GraphicsEnvironment or -1 if no family name was found.
+     * 
+     * @param familyName specified font family name 
+     */
+    public int getFamilyIndex(String familyName){
         for (int i=0; i<allFamilies.length; i++ ){
             if (familyName.equalsIgnoreCase(allFamilies[i])){
-                return true;
+                return i;
             }
         }
-        return false;
+        return -1;
     }
 
     /**
+     * Returns family with index specified from the array of family names available in 
+     * this GraphicsEnvironment.
+     * 
+     * @param index index of the family in families names array 
+     */
+    public String getFamily(int index){
+        return allFamilies[index];
+    }
+    /**
      * Returns index of face name from the array of face names available in 
      * this GraphicsEnvironment or -1 if no face name was found. Default return 
      * value is -1, method must be overridden by FontManager implementation.
      * 
-     * @param faceName specified face name
+     * @param faceName font face name which index is to be searched
      */
     public int getFaceIndex(String faceName){
         return -1;
     }
 
+    public abstract String[] getAllFamilies();
+
+    public abstract Font[] getAllFonts();
+    
     /**
-     * Returns correct logical family name from the specified font name.
-     * 
-     * @param fontName specified font name 
+     * Class contains SoftReference instance that can be stored in the 
+     * Hashtable by means of key field corresponding to it.
      */
-    public static String getLogicalFamilyName(String fontName){
-        for (int i=0; i<LOGICAL_FONT_NAMES.length; i++ ){
-            if (LOGICAL_FONT_NAMES[i].equalsIgnoreCase(fontName)){
-                return LOGICAL_FONT_FAMILIES[i];
-            }
+    private class HashMapReference extends SoftReference {
+        
+        /**
+         * The key for Hashtable.
+         */
+        private final Object key;
+
+        /**
+         * Creates a new soft reference with the key specified and 
+         * adding this reference in the reference queue specified.
+         *
+         * @param key the key in Hashtable
+         * @param value object that corresponds to the key
+         * @param queue reference queue where reference is to be added 
+         */
+        public HashMapReference(final Object key, final Object value,
+                              final ReferenceQueue queue) {
+            super(value, queue);
+            this.key = key;
+        }
+
+        /**
+         * Returns the key that corresponds to the SoftReference instance 
+         *
+         * @return the key in Hashtable with cached references
+         */
+        public Object getKey() {
+            return key;
         }
-        return null;
     }
 
-    public abstract String[] getAllFamilies();
+    /**
+     * Removes keys from the Hashtable with font peers which corresponding 
+     * HashMapReference objects were garbage collected.
+     */
+    private void updateFontsTable() {
+        HashMapReference r;
+        while ((r = (HashMapReference)queue.poll()) != null) {
+            Object obj = fontsTable.remove(r.getKey());
+            
+        }
+    }
 
-    public abstract Font[] getAllFonts();
 }
+
+

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/FontMetricsImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/FontMetricsImpl.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/FontMetricsImpl.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/font/FontMetricsImpl.java Wed Sep  6 09:06:15 2006
@@ -30,7 +30,7 @@
 public class FontMetricsImpl extends FontMetrics  {
 
     private static final long serialVersionUID = 844695615201925138L;
-    
+
     // ascent of the font
     private int ascent;
     
@@ -216,7 +216,7 @@
     
     /**
      * Returns FontPeer implementation of the Font describing this 
-     * FontMetricsImpl object.
+     * FontMetricsImpl object. 
      *  
      * @return a FontPeer object, that is the platform dependent FontPeer 
      * implementation for the Font describing this FontMetricsImpl object.



Mime
View raw message