harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r440748 [9/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
Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/datatransfer/linux/LinuxSelection.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/datatransfer/linux/LinuxSelection.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/datatransfer/linux/LinuxSelection.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/datatransfer/linux/LinuxSelection.java Wed Sep  6 09:06:15 2006
@@ -19,51 +19,16 @@
  */
 package org.apache.harmony.awt.datatransfer.linux;
 
-import java.awt.EventQueue;
-import java.awt.datatransfer.ClipboardOwner;
-import java.awt.datatransfer.DataFlavor;
-import java.awt.datatransfer.FlavorListener;
-import java.awt.datatransfer.Transferable;
-import java.awt.datatransfer.UnsupportedFlavorException;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-
-import org.apache.harmony.awt.ComponentInternals;
 import org.apache.harmony.awt.ContextStorage;
-import org.apache.harmony.awt.PeriodicTimer;
-import org.apache.harmony.awt.RelativeTimer;
-import org.apache.harmony.awt.datatransfer.ClipboardEntry;
-import org.apache.harmony.awt.datatransfer.FlavorInfo;
 import org.apache.harmony.awt.datatransfer.NativeClipboard;
-import org.apache.harmony.awt.datatransfer.SystemTransferable;
-import org.apache.harmony.awt.nativebridge.linux.X11;
-import org.apache.harmony.awt.nativebridge.linux.X11Defs;
-import org.apache.harmony.awt.wtk.linux.LinuxEventDecoder;
+import org.apache.harmony.awt.nativebridge.linux.X11.XEvent;
+import org.apache.harmony.awt.wtk.linux.LinuxEventQueue;
 import org.apache.harmony.awt.wtk.linux.LinuxWindowFactory;
-import org.apache.harmony.misc.accessors.AccessorFactory;
-import org.apache.harmony.misc.accessors.ArrayAccessor;
-import org.apache.harmony.misc.accessors.LockedArray;
-import org.apache.harmony.misc.accessors.MemoryAccessor;
-
-public final class LinuxSelection
-        extends NativeClipboard implements LinuxWindowFactory.Preprocessor
-{
 
-    private static final ArrayAccessor memArrAccess = AccessorFactory.getArrayAccessor();
-    private static final MemoryAccessor memAccess = AccessorFactory.getMemoryAccessor();
-    private static final int POINTER_SIZE = memAccess.getPointerSize();
-    private static final X11 x11 = X11.getInstance();
+public final class LinuxSelection extends NativeClipboard 
+        implements LinuxEventQueue.Preprocessor {
 
-    private static final int MAX_TARGETS_NUM = 50;
-    private static final int INT_SIZE = 4;
-    private static final int EXAMENATION_PERIOD = 1000;
-
-    private final ComponentInternals toolkit;
     private final LinuxWindowFactory factory;
-    private final long display;
 
     private final long xaSelection;
     private final long xaTargets;
@@ -72,30 +37,10 @@
     private final long xaUTF8;
     private final long xaSTRING;
 
-    private final Owner owner;
-    private final Requestor requestor;
-    private final RelativeTimer examinationTimer;
-
-    private final Runnable dataRequestor = new Runnable() {
-        public void run() {
-            flavorInfo.rawData = requestor.requestData(flavorInfo.format);
-        }
-    };
-    private final Runnable targetsRequestor = new Runnable() {
-        public void run() {
-            availableFormats = requestor.requestTargets();
-        }
-    };
-
-    private FlavorInfo flavorInfo;
-    private LinkedList availableFormats;
-
     public LinuxSelection(String selection) {
         super("System");
 
-        toolkit = ComponentInternals.getComponentInternals();
-        factory = (LinuxWindowFactory) ContextStorage.getNativeEventQueue();
-        display = factory.getDisplay();
+        factory = (LinuxWindowFactory)ContextStorage.getWindowFactory();
 
         xaSelection = factory.internAtom(selection);
         xaTargets = factory.internAtom("TARGETS");
@@ -103,568 +48,10 @@
         xaText = factory.internAtom("TEXT");
         xaUTF8 = factory.internAtom("UTF8_STRING");
         xaSTRING = factory.internAtom("STRING");
-
-        owner = new Owner();
-        requestor = new Requestor();
-        flavorInfo = null;
-        availableFormats = null;
-
-        factory.addPreprocessor(this);
-        examinationTimer = new PeriodicTimer(EXAMENATION_PERIOD, new Runnable() {
-            public void run() {
-                EventQueue.invokeLater(new Runnable() {
-                    public void run() {
-                        updateClipboardFlavors();
-                    }
-                });
-            }
-        });
-
-        updateClipboardFlavors();
-    }
-
-    public void addFlavorListener(FlavorListener listener) {
-        awtSynchronizer.lock();
-        try {
-            super.addFlavorListener(listener);
-            if (getFlavorListeners().length == 1) {
-                examinationTimer.start();
-            }
-        } finally {
-            awtSynchronizer.unlock();
-        }
-    }
-
-    public void removeFlavorListener(FlavorListener listener) {
-        awtSynchronizer.lock();
-        try {
-            super.removeFlavorListener(listener);
-            if (getFlavorListeners().length == 0) {
-                examinationTimer.stop();
-            }
-        } finally {
-            awtSynchronizer.unlock();
-        }
-    }
-
-    public DataFlavor[] getAvailableDataFlavors() {
-        awtSynchronizer.lock();
-        try {
-            if (!owner.isOwner) {
-                updateClipboardFlavorsImpl();
-            }
-
-            return super.getAvailableDataFlavors();
-        } finally {
-            awtSynchronizer.unlock();
-        }
-    }
-
-    public boolean isDataFlavorAvailable(DataFlavor flavor) {
-        awtSynchronizer.lock();
-        try {
-            if (!owner.isOwner) {
-                updateClipboardFlavorsImpl();
-            }
-
-            return super.isDataFlavorAvailable(flavor);
-        } finally {
-            awtSynchronizer.unlock();
-        }
     }
 
-    public void setContents(Transferable contents, ClipboardOwner owner) {
-        awtSynchronizer.lock();
-        try {
-            super.setContents(contents, owner);
-
-            if (!this.owner.acquire()) {
-                throw new IllegalStateException("Can't acquire clipboard.");
-            }
-        } finally {
-            awtSynchronizer.unlock();
-        }
-    }
-
-    public Transferable getContents(Object requestor) {
-        awtSynchronizer.lock();
-        try {
-            if (owner.isOwner) {
-                return super.getContents(requestor);
-            } else {
-                SystemTransferable transferable = updateClipboardFlavorsImpl();
-
-                if (transferable.flavors.isEmpty()) {
-                    return super.getContents(requestor);
-                }
-
-                HashSet requestedFormats = new HashSet();
-                HashMap dataMap = new HashMap();
-
-                for (Iterator i = transferable.flavors.iterator(); i.hasNext(); ) {
-                    flavorInfo = (FlavorInfo) transferable.infoMap.get(i.next());
-                    Long format = new Long(flavorInfo.format);
-
-                    if (requestedFormats.contains(format)) {
-                        flavorInfo.rawData = (byte[]) dataMap.get(format);
-                    } else {
-                        requestedFormats.add(format);
-                        if (!runOnDispatchThread(dataRequestor)) {
-                            flavorInfo.rawData = null;
-                        }
-                        dataMap.put(format, flavorInfo.rawData);
-                    }
-                }
-
-                return transferable;
-            }
-        } finally {
-            awtSynchronizer.unlock();
-        }
-    }
-
-    public Object getData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
-        awtSynchronizer.lock();
-        try {
-            if (owner.isOwner) {
-                return super.getData(flavor);
-            } else {
-                flavorInfo = (FlavorInfo) updateClipboardFlavorsImpl().infoMap.get(flavor);
-
-                if (flavorInfo == null) {
-                    throw new UnsupportedFlavorException(flavor);
-                }
-
-                if (!runOnDispatchThread(dataRequestor) || (flavorInfo.rawData == null)) {
-                    throw new IOException("Can't read data.");
-                }
-
-                flavorInfo.data = translationManager.translateNative2Java(flavor, flavorInfo);
-
-                if (flavorInfo.data != null) {
-                    return flavorInfo.data;
-                }
-                throw new RuntimeException(
-                        "Data translation failed. Can't find proper clipboard translator.");
-            }
-        } finally {
-            awtSynchronizer.unlock();
-        }
-    }
-
-    private boolean runOnDispatchThread(Runnable runnable) {
-        if (EventQueue.isDispatchThread()) {
-            runnable.run();
-        } else {
-            try {
-                toolkit.unsafeInvokeAndWait(runnable);
-            } catch (Exception e) {
-                return false;
-            }
-        }
-
-        return true;
-    }
-
-    private void updateClipboardFlavors() {
-        awtSynchronizer.lock();
-        try {
-            if (!owner.isOwner) {
-                updateClipboardFlavorsImpl();
-            }
-        } finally {
-            awtSynchronizer.unlock();
-        }
-    }
-
-    private SystemTransferable updateClipboardFlavorsImpl() {
-        SystemTransferable transferable;
-
-        availableFormats = null;
-        runOnDispatchThread(targetsRequestor);
-        transferable = translationManager.createTransferableStub(availableFormats);
-        super.setContents(transferable, null);
-
-        return transferable;
-    }
-
-    public boolean preprocess(X11.XEvent event) {
-        awtSynchronizer.lock();
-        try {
-            int type = event.get_type();
-
-            switch (type) {
-            case X11Defs.SelectionRequest:
-                return owner.processRequest(event.get_xselectionrequest());
-            case X11Defs.SelectionClear:
-                return owner.processClear(event.get_xselectionclear());
-            case X11Defs.SelectionNotify:
-                // Just ignore. Can get here only when notification timeout expired. Too late.
-                return true;
-            default:
-                return false;
-            }
-        } finally {
-            awtSynchronizer.unlock();
-        }
-    }
-
-    private class Requestor {
-
-        private X11.XEvent event = x11.createXEvent(false);
-
-        byte[] requestData(long target) {
-            if (convert(target)) {
-                return readData(target);
-            } else {
-                return null;
-            }
-        }
-
-        LinkedList requestTargets() {
-            if (convert(xaTargets)) {
-                return readTargets();
-            } else {
-                return null;
-            }
-        }
-
-        private boolean convert(long target) {
-            long timeout = System.currentTimeMillis() + OPS_TIMEOUT;
-
-            x11.XDeleteProperty(display, javaWindow, target);
-            x11.XConvertSelection(display, xaSelection, target,
-                    target, javaWindow, X11Defs.CurrentTime);
-
-            while (true) {
-                if (System.currentTimeMillis() > timeout) {
-                    return false;
-                }
-
-                if (x11.XCheckTypedEvent(display, X11Defs.SelectionNotify, event)
-                        == X11Defs.TRUE) {
-                X11.XSelectionRequestEvent sre = event.get_xselectionrequest();
-                    if ((sre.get_selection() == xaSelection)
-                            && (sre.get_requestor() == javaWindow)
-                            && (sre.get_target() == target)) {
-                        return (sre.get_property() != X11Defs.None);
-                    }
-
-                    return false;
-                }
-            }
-        }
-
-        private byte[] readData(long target) {
-            PropertyParams params = new PropertyParams();
-            long dataPtr;
-            int entrySize;
-            byte[] data;
-
-            int res = x11.XGetWindowProperty(display, javaWindow, target, 0, Integer.MAX_VALUE,
-                    X11Defs.AnyPropertyType, X11Defs.False, params.typePtr, params.formatPtr,
-                    params.itemsNumPtr, params.bytesLeftPtr, params.dataPtrPtr);
-
-            if ((res != X11Defs.Success) || (memAccess.getPointer(params.itemsNumPtr) == 0)) {
-                return null;
-            }
-
-            dataPtr = memAccess.getPointer(params.dataPtrPtr);
-            entrySize = memAccess.getInt(params.formatPtr) / 8;
-            if (entrySize == 4) {
-                entrySize = memAccess.getPointerSize();
-            }
-            data = new byte[entrySize * (int) memAccess.getPointer(params.itemsNumPtr)];
-
-            try {
-                LockedArray locked = memArrAccess.lockArrayShort(data);
-
-                memAccess.memcpy(locked.getAddress(), dataPtr, data.length);
-
-                x11.XDeleteProperty(display, javaWindow, target);
-                locked.release();
-
-                return data;
-            } finally {
-                x11.XFree(dataPtr);
-                params.free();
-            }
-        }
-
-        private LinkedList readTargets() {
-            PropertyParams params = new PropertyParams();
-            long dataPtr;
-            long itemsNum;
-
-            int res = x11.XGetWindowProperty(display, javaWindow, xaTargets, 0, MAX_TARGETS_NUM,
-                    X11Defs.AnyPropertyType, X11Defs.False, params.typePtr, params.formatPtr,
-                    params.itemsNumPtr, params.bytesLeftPtr, params.dataPtrPtr);
-            dataPtr = memAccess.getPointer(params.dataPtrPtr);
-            itemsNum = memAccess.getPointer(params.itemsNumPtr);
-
-            try {
-                if ((res != X11Defs.Success) || (memAccess.getInt(params.formatPtr) != 32)
-                        || (memAccess.getPointer(params.bytesLeftPtr) != 0))
-                {
-                    return null;
-                }
-
-                LinkedList formats = new LinkedList();
-
-                for (long addr = dataPtr + ((int) itemsNum - 1) * POINTER_SIZE;
-                        addr >= dataPtr; addr -= POINTER_SIZE)
-                {
-                    formats.addFirst(new Long(memAccess.getPointer(addr)));
-                }
-                x11.XDeleteProperty(display, javaWindow, xaTargets);
-
-                return formats;
-            } finally {
-                x11.XFree(dataPtr);
-                params.free();
-            }
-        }
-
-    }
-
-    private class Owner {
-
-        private long owningTime = 0;
-        private boolean isOwner = false;
-        private HashMap entriesMap = null;
-
-        boolean acquire() {
-            long curTime = System.currentTimeMillis();
-            long timeout = curTime + OPS_TIMEOUT;
-
-            owningTime = curTime - LinuxEventDecoder.getUTCOffset();
-            do {
-                x11.XSetSelectionOwner(display, xaSelection, javaWindow, owningTime);
-                if (x11.XGetSelectionOwner(display, xaSelection) == javaWindow) {
-                    break;
-                }
-                if (System.currentTimeMillis() > timeout) {
-                    return false;
-                }
-                Thread.yield();
-            } while (true);
-            initFields();
-
-            return true;
-        }
-
-        boolean processClear(X11.XSelectionClearEvent event) {
-            if (event.get_selection() != xaSelection) {
-                return false;
-            }
-
-            isOwner = false;
-            updateClipboardFlavorsImpl();
-
-            // Must return false. Otherwise can wait for OwnershipLost forever
-            return false;
-        }
-
-        boolean processRequest(X11.XSelectionRequestEvent event) {
-            long requestor = event.get_requestor();
-            long target = event.get_target();
-            long property = event.get_property();
-            long time = event.get_time();
-            boolean err = false;
-
-            if ((event.get_selection() != xaSelection) || (requestor == X11Defs.None)) {
-                return false;
-            }
-
-            if (isOwner && ((time == X11Defs.CurrentTime) || (time >= owningTime))) {
-                if (target == xaMultiple) {
-                    err = (property == X11Defs.None);
-                    err = (err || !copyMultiple(requestor, property));
-                } else {
-                    if (target == xaText) {
-                        long text = findTextAtom();
-
-                        if (text == X11Defs.None) {
-                            err = true;
-                        } else {
-                            target = property = text;
-                        }
-                    } else if (property == X11Defs.None) {
-                        property = target;
-                    }
-                    err = (err || !copyData(requestor, property, target));
-                }
-            }
-
-            x11.XSendEvent(display, requestor, X11Defs.FALSE, X11Defs.None,
-                    createNotifyEvent(event, err ? X11Defs.None : property));
-
-            return true;
-        }
-
-        private long findTextAtom() {
-            if (entriesMap.containsKey(new Long(xaSTRING))) {
-                return xaSTRING;
-            } else if (entriesMap.containsKey(new Long(xaUTF8))) {
-                return xaUTF8;
-            } else {
-                return X11Defs.None;
-            }
-        }
-
-        private void initFields() {
-            LinkedList entries = translationManager.translateJava2Native(contents);
-            byte[] targets = new byte[POINTER_SIZE * (entries.size() + 3)];
-            LockedArray lockedTargets = memArrAccess.lockArrayShort(targets);
-            long addr = lockedTargets.getAddress();
-            boolean text = false;
-
-            isOwner = true;
-            entriesMap = new HashMap();
-
-            memAccess.setPointer(addr, xaMultiple);
-            addr += POINTER_SIZE;
-            memAccess.setPointer(addr, xaTargets);
-
-            for (Iterator i = entries.iterator(); i.hasNext(); ) {
-                ClipboardEntry entry = (ClipboardEntry) i.next();
-
-                text = (text || (entry.format == xaSTRING) || (entry.format == xaUTF8));
-                entriesMap.put(new Long(entry.format), entry);
-                addr += POINTER_SIZE;
-                memAccess.setPointer(addr, entry.format);
-            }
-            if (text) {
-                addr += POINTER_SIZE;
-                memAccess.setPointer(addr, xaText);
-                entriesMap.put(new Long(xaTargets), new ClipboardEntry(xaTargets, targets));
-            } else {
-                int length = targets.length - POINTER_SIZE;
-                byte[] shortTargets = new byte[length];
-
-                System.arraycopy(targets, 0, shortTargets, 0, length);
-                entriesMap.put(new Long(xaTargets), new ClipboardEntry(xaTargets, shortTargets));
-            }
-            lockedTargets.release();
-
-        }
-
-        private boolean copyMultiple(long requestor, long property) {
-            PropertyParams params = new PropertyParams();
-            long itemsNum;
-            long dataPtr;
-
-            int res = x11.XGetWindowProperty(display, requestor, property, 0, MAX_TARGETS_NUM * 2,
-                    X11Defs.AnyPropertyType, X11Defs.False, params.typePtr, params.formatPtr,
-                    params.itemsNumPtr, params.bytesLeftPtr, params.dataPtrPtr);
-            dataPtr = memAccess.getPointer(params.dataPtrPtr);
-            itemsNum = memAccess.getPointer(params.itemsNumPtr);
-
-            try {
-                if ((res != X11Defs.Success) || (memAccess.getInt(params.formatPtr) != 32)
-                        || ((itemsNum % 2) != 0)
-                        || (memAccess.getPointer(params.bytesLeftPtr) != 0))
-                {
-                    return false;
-                }
-
-                if (!copyMultiplePairs(requestor, dataPtr, itemsNum)) {
-                    x11.XChangeProperty(display, requestor, property,
-                            memAccess.getLong(params.typePtr), 32, X11Defs.PropModeReplace,
-                            dataPtr, (int) itemsNum);
-                }
-
-                return true;
-            } finally {
-                x11.XFree(dataPtr);
-                params.free();
-            }
-        }
-
-        private boolean copyMultiplePairs(long requestor, long dataPtr, long itemsNum) {
-            boolean noErrs = true;
-
-            for (long pair = dataPtr + ((itemsNum - 2) * POINTER_SIZE);
-                    pair >= dataPtr; pair -= 2 * POINTER_SIZE)
-            {
-                long target = memAccess.getLong(pair);
-                long propertyAddr = pair + POINTER_SIZE;
-                long property = memAccess.getLong(propertyAddr);
-                boolean err = false;
-
-                if (property == xaText) {
-                    long text = findTextAtom();
-
-                    if (text == X11Defs.None) {
-                        err = true;
-                    } else {
-                        target = property = text;
-                    }
-                }
-                err = (err || !copyData(requestor, property, target));
-
-                if (err) {
-                    noErrs = false;
-                    memAccess.setLong(propertyAddr, X11Defs.None);
-                }
-            }
-
-            return noErrs;
-        }
-
-        private boolean copyData(long requestor, long property, long target) {
-            ClipboardEntry entry = (ClipboardEntry) entriesMap.get(new Long(target));
-
-            if (entry == null) {
-                return false;
-            }
-
-            LockedArray locked = memArrAccess.lockArrayShort(entry.data);
-            boolean format32 = (target == xaTargets);
-
-            try {
-                return (x11.XChangeProperty(display, requestor, property, target,
-                        (format32 ? 32 : 8), X11Defs.PropModeReplace, locked.getAddress(),
-                        (format32 ? entry.data.length / POINTER_SIZE: entry.data.length))
-                        != X11Defs.BadAlloc);
-            } finally {
-                locked.release();
-            }
-        }
-
-        private X11.XEvent createNotifyEvent(
-                X11.XSelectionRequestEvent request, long property) {
-            X11.XEvent retEvent = x11.createXEvent(false);
-            X11.XSelectionEvent se = retEvent.get_xselection();
-
-            se.set_type(X11Defs.SelectionNotify);
-            se.set_selection(request.get_selection());
-            se.set_target(request.get_target());
-            se.set_requestor(request.get_requestor());
-            se.set_time(request.get_time());
-            se.set_property(property);
-
-            return retEvent;
-        }
-
-    }
-
-    private class PropertyParams {
-
-        long typePtr = memAccess.malloc(POINTER_SIZE);
-        long formatPtr = memAccess.malloc(INT_SIZE);
-        long bytesLeftPtr = memAccess.malloc(POINTER_SIZE);
-        long itemsNumPtr = memAccess.malloc(POINTER_SIZE);
-        long dataPtrPtr = memAccess.malloc(POINTER_SIZE);
-
-        void free() {
-            memAccess.free(typePtr);
-            memAccess.free(formatPtr);
-            memAccess.free(itemsNumPtr);
-            memAccess.free(bytesLeftPtr);
-            memAccess.free(dataPtrPtr);
-        }
-
+    public boolean preprocess(XEvent event) {
+        return false;
     }
 
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/font/LinuxFont.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/font/LinuxFont.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/font/LinuxFont.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/font/LinuxFont.java Wed Sep  6 09:06:15 2006
@@ -43,14 +43,6 @@
  */
 public class LinuxFont extends FontPeerImpl {
 
-    // pitch value of this font
-    private int fPitch;
-
-    // available pitch constants
-    private static final int PITCH_DONTCARE = 0;
-    private static final int PITCH_MONO = 1;
-    private static final int PITCH_PROPORTIONAL = 2;
-
     // Pairs of [begin, end],[..].. unicode ranges values 
     private int[] fontUnicodeRanges;
     
@@ -63,86 +55,21 @@
     // X11 screen value
     private int screen = 0;
     
-    // font style name of this font peer
-    private String fontStyle;
-
-    public LinuxFont(Font font, boolean isLogical, String familyName, String faceName, String fontStyle) {
+    public LinuxFont(String fontName, int fontStyle, int fontSize) {
         /*
          * Workaround : to initialize awt platform-dependent fields and libraries.
          */
         Toolkit.getDefaultToolkit();
 
-        this.name = font.getName();
-        this.size = font.getSize();
-        this.style = font.getStyle();
-
-        this.display = ((LinuxWindowFactory)ContextStorage.getWindowFactory()).getDisplay();
-        this.screen = ((LinuxWindowFactory)ContextStorage.getWindowFactory()).getScreen();
-
-        String family = familyName;
-        this.fontFamilyName = familyName;
-        this.faceName = faceName;
-        this.fontStyle = fontStyle;
-
-        if (isLogical){
-            this.psName = familyName;
-            int index = FontManager.getLogicalIndex(familyName.toLowerCase());
-            this.setPitch(index);
-            
-            /* Xft chooses Luxi Sans font with fixed width parameter as monospaced 
-             * font. At first we check if Courier font is on the system, if it is
-             * we create this font as monospaced, otherwise we create XFT font with
-             * XFT_MONO spacing.
-             */
-            if (index == MONOSPACED){
-                if (CommonGraphics2DFactory.inst.getFontManager().isFamilyExist("Courier")){
-                    family = "Courier";
-                }
-            }
-
-        }
-
-        pFont = LinuxNativeFont.initializeFont(this, family, style, size, fontStyle);
-
-        initLinuxFont();
-    }
-
-    public LinuxFont(LinuxFontProperty lfp, int size) {
-        /*
-         * Workaround : to initialize awt platform-dependent fields and libraries.
-         */
-        Toolkit.getDefaultToolkit();
-
-        this.name = lfp.getName();
-        this.size = size;
-        this.style = lfp.getStyle();
-
+        this.name = fontName;
+        this.size = fontSize;
+        this.style = fontStyle;
+        
         this.display = ((LinuxWindowFactory)ContextStorage.getWindowFactory()).getDisplay();
         this.screen = ((LinuxWindowFactory)ContextStorage.getWindowFactory()).getScreen();
 
-        pFont = LinuxNativeFont.initializeFontFromFP(this, lfp.getXLFD(), size);
-        if (pFont == 0){
-            int index = FontManager.getLogicalIndex(lfp.getLogicalName().toLowerCase());
-            this.setPitch(index);
-
-            this.fontFamilyName = FontManager.LOGICAL_FONT_FAMILIES[index];
-            this.faceName       = FontManager.LOGICAL_FONT_NAMES[index];
-            this.psName         = FontManager.LOGICAL_FONT_NAMES[index];
-
-            String family = FontManager.LOGICAL_FONT_FAMILIES[index];
-
-            /* Xft chooses Luxi Sans font with fixed width parameter as monospaced 
-             * font. At first we check if Courier font is on the system, if it is
-             * we create this font as monospaced, otherwise we create XFT font with
-             * XFT_MONO spacing.
-             */
-            if ((index == MONOSPACED) &&
-                    CommonGraphics2DFactory.inst.getFontManager().isFamilyExist("Courier")){
-                family = "Courier";
-            }
+        pFont = LinuxNativeFont.initializeFont(this, name, style, size, null);
 
-            pFont = LinuxNativeFont.initializeFont(this, family, style, size, fontStyle);
-        }
         initLinuxFont();
     }
 
@@ -151,9 +78,11 @@
      * font metrics, italic angle etc. 
      */
     public void initLinuxFont(){
-        this.numGlyphs = LinuxNativeFont.getNumGlyphsNative(pFont);
-        this.italicAngle = LinuxNativeFont.getItalicAngleNative(pFont, this.fontType);
-
+        if (pFont != 0){
+                this.numGlyphs = LinuxNativeFont.getNumGlyphsNative(pFont);
+                this.italicAngle = LinuxNativeFont.getItalicAngleNative(pFont, this.fontType);
+        }
+        
         this.nlm = new LinuxLineMetrics(this, null, " ");
 
         this.ascent = nlm.getLogicalAscent();
@@ -170,7 +99,8 @@
 
         this.maxCharBounds = new Rectangle2D.Float(0, -nlm.getAscent(), nlm.getMaxCharWidth(), this.height);
 
-        addGlyphs((char) 0x20, (char) 0x7E);
+//        addGlyphs((char) 0x20, (char) 0x7E);
+
     }
 
 
@@ -184,6 +114,10 @@
 
     public LineMetrics getLineMetrics(String str, FontRenderContext frc, AffineTransform at) {
         //TODO: frc isn't used now
+        
+        // Initialize baseline offsets
+        nlm.getBaselineOffsets();
+        
         LineMetricsImpl lm = (LineMetricsImpl)(this.nlm.clone());
         lm.setNumChars(str.length());
 
@@ -195,8 +129,8 @@
     }
 
     public String getPSName() {
-        if (psName == null){
-            psName = LinuxNativeFont.getFontPSNameNative(this.getFontHandle());
+        if ((pFont != 0) && (psName == null)){
+                psName = LinuxNativeFont.getFontPSNameNative(pFont);
         }
         return psName;
     }
@@ -211,8 +145,7 @@
     }
 
     public String getFontName(Locale l) {
-        // TODO: implement localized font name
-        if (this.fontType == FontManager.FONT_TYPE_T1){
+        if ((pFont == 0) || (this.fontType == FontManager.FONT_TYPE_T1)){
             return this.name;
         }
 
@@ -252,8 +185,9 @@
                 glyphs.put(key, new LinuxGlyph(defaultChar, defaultChar));
                 result = (Glyph) glyphs.get(key);
             } else {
-                glyphs.put(key, new LinuxGlyph(this.pFont,
-                    this.getSize(), defaultChar, LinuxNativeFont.getGlyphCodeNative(this.pFont, defaultChar, this.display)));
+                    int code = LinuxNativeFont.getGlyphCodeNative(this.pFont, defaultChar, this.display);
+                    glyphs.put(key, new LinuxGlyph(this.pFont,
+                            this.getSize(), defaultChar, code));
                 result = (Glyph) glyphs.get(key);
             }
         }
@@ -267,13 +201,16 @@
      */
     public void dispose(){
         String tempDirName;
-        LinuxNativeFont.pFontFree(this.pFont,this.display);
-        
-        if (this.isCreatedFromStream()) {
-            File fontFile = new File(this.getTempFontFileName());
-            tempDirName = fontFile.getParent();
-            fontFile.delete();
-            LinuxNativeFont.RemoveFontResource(tempDirName);
+        if (pFont != 0){
+            LinuxNativeFont.pFontFree(pFont, display);
+            pFont = 0;
+
+            if (isCreatedFromStream()) {
+                File fontFile = new File(getTempFontFileName());
+                tempDirName = fontFile.getParent();
+                fontFile.delete();
+                LinuxNativeFont.RemoveFontResource(tempDirName);
+            }
         }
     }
 
@@ -284,7 +221,7 @@
      * @return true if glyph of the specified character exists in this
      * LinuxFont or this character is escape sequence character.
      */
-   public boolean addGlyph(char uChar) {
+    public boolean addGlyph(char uChar) {
         boolean result = false;
         boolean isEscape = false;
 
@@ -296,7 +233,6 @@
                             this.getSize(), uChar, glyphCode));
                 result = true;
         }
-
         return result;
     }
 
@@ -333,9 +269,9 @@
                     return false;
                 }
             }
-        }
-*/
-        return (LinuxNativeFont.getGlyphCodeNative(this.getFontHandle(), uIndex, display) != 0xFFFF);
+        }*/
+        int code = LinuxNativeFont.getGlyphCodeNative(this.getFontHandle(), uIndex, display);
+        return (code != 0xFFFF);
     }
 
     /**
@@ -350,38 +286,6 @@
     }
 
     /**
-     * Returns Physical font name in case of predefined in Java logical names
-     * If there is no matches - the return value is the string parameter without 
-     * changes, in this case GDI chooses font that match to Font parent object 
-     * parameters.
-     * 
-     * @param logFontNameIndex index of the logical font family name
-     */
-    private void setPitch(int logFontNameIndex){
-        switch (logFontNameIndex){
-            case DIALOG:
-            case SANSSERIF:
-            case SERIF:
-                this.fPitch = PITCH_PROPORTIONAL;
-                break;
-            case DIALOGINPUT:
-            case MONOSPACED:
-                this.fPitch = PITCH_MONO;
-                break;
-            default:
-                this.fPitch = PITCH_DONTCARE;
-        }
-
-    }
-    
-    /**
-     * Returns pitch of this font peer. 
-     */
-    public int getPitch(){
-        return this.fPitch;
-    }
-
-    /**
      * Return Font object if it was successfully embedded in System
      */
     public static Font embedFont(String absolutePath){
@@ -389,7 +293,7 @@
     }
 
     public String getFontName(){
-        if (faceName == null){
+        if ((pFont != 0) && (faceName == null)){
             if (this.fontType == FontManager.FONT_TYPE_T1){
                 faceName = getFamily();
             } else {
@@ -400,9 +304,30 @@
     }
 
     public String getFamily() {
-        if (fontFamilyName == null){
+        if ((pFont != 0) && (fontFamilyName == null)){
             fontFamilyName = LinuxNativeFont.getFamilyNative(pFont);
         }
         return fontFamilyName;
+    }
+    
+    /**
+     * Returns initiated FontExtraMetrics instance of this WindowsFont.
+     */
+    public FontExtraMetrics getExtraMetrics(){
+        if (extraMetrix == null){
+            float[] metrics = LinuxNativeFont.getExtraMetricsNative(pFont, size, fontType);
+            if (metrics == null){
+                return null;
+            }
+                
+            //!! for Type1 fonts 'x' char width used as average char width
+            if (fontType == FontManager.FONT_TYPE_T1){
+                metrics[0] = this.charWidth('x');
+            }
+            
+            extraMetrix = new FontExtraMetrics(metrics);
+        }
+        
+        return extraMetrix;
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/font/LinuxFontManager.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/font/LinuxFontManager.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/font/LinuxFontManager.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/font/LinuxFontManager.java Wed Sep  6 09:06:15 2006
@@ -26,7 +26,6 @@
 import java.util.Properties;
 import java.util.Vector;
 
-import org.apache.harmony.awt.gl.font.CompositeFont;
 import org.apache.harmony.awt.gl.font.FontManager;
 import org.apache.harmony.awt.gl.font.FontProperty;
 
@@ -72,54 +71,6 @@
     }
 
     /**
-     * Creates and returns logical font peer. 
-     * 
-     * @param logicalName logical font family name
-     * @param font specified Font object
-     * @return In case of non-null fontproperties for the specified logical 
-     * name CompositeFont object is returned, otherwise LinuxFont object is 
-     * returned.
-     */
-    private FontPeer CreateLogicalFont(String logicalName, Font font){
-        FontProperty[] fps = getFontProperties(logicalName.toLowerCase() + "." + font.getStyle());
-        if (fps != null){
-            return new CompositeFont(font, fps, logicalName);
-        }
-        return new LinuxFont(font, true, logicalName, logicalName, null);
-    }
-
-    public FontPeer createFont(Font font){
-        String fontName = font.getName();
-        if (isFontLogical(font)){
-            return CreateLogicalFont(fontName, font);
-        }
-
-        String fontStyle = null;
-        String family = null;
-        String face = null;
-
-        int faceIndex = getFaceIndex(fontName);
-        // Check if name parameter is face name
-        if (faceIndex != -1){
-            fontStyle = LinuxNativeFont.getFontStyle(faceIndex);
-            family = LinuxNativeFont.getFamily(faceIndex);
-            face = fontName;
-        } else
-            // Check if name parameter is family name
-            if(isFamilyExist(fontName)){
-                family = fontName;
-            } else {
-                return CreateLogicalFont(FontManager.LOGICAL_FONT_NAMES[3], font);  // "dialog"
-            }
-        return new LinuxFont(font, false, family, face, fontStyle);
-    }
-
-    public FontPeer createFont(FontProperty fp, int size){
-        LinuxFontProperty lfp = (LinuxFontProperty)fp;
-        return new LinuxFont(lfp, size);
-    }
-
-    /**
      * Initializes fProperties array field for the current system configuration font
      * property file.
      * 
@@ -289,6 +240,33 @@
             fonts[i] = new Font(faces[i], Font.PLAIN, 1);
         }
         return fonts;
+    }
+
+    public FontPeer createPhysicalFontPeer(String name, int style, int size) {
+        LinuxFont peer;
+        int familyIndex = getFamilyIndex(name);
+        if (familyIndex != -1){
+            // !! we use family names from the list with cached families because 
+            // they are differ from the family names in xlfd structure, in xlfd 
+            // family names mostly in lower case.
+            peer = new LinuxFont(getFamily(familyIndex), style, size);
+            peer.setFamily(getFamily(familyIndex));
+            return peer;
+        }
+        int faceIndex = getFaceIndex(name); 
+        if (faceIndex != -1){
+            style |= LinuxNativeFont.getFontStyle(faceIndex);
+            name = LinuxNativeFont.getFamilyFromFaceIndex(faceIndex);
+
+            peer = new LinuxFont(name, style, size);
+            return peer;
+        }
+        
+        return null;
+    }
+
+    public FontPeer createDefaultFont(int style, int size) {
+        return new LinuxFont(DEFAULT_NAME, style, size);
     }
 
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/font/LinuxGlyph.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/font/LinuxGlyph.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/font/LinuxGlyph.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/font/LinuxGlyph.java Wed Sep  6 09:06:15 2006
@@ -61,32 +61,41 @@
      * Constructor
      */
     public LinuxGlyph(long pFnt, int fntSize, char c, int glyphIndex) {
-        int[] pxlMetrics;
+        // FIXME: all code related to the precise metrics array 
+        // commented out because we have the same results as pxl metrics
 
+        int[] pxlMetrics = new int[6];
+//        float[] metrics = new float[6]; 
+        
         this.pFont = pFnt;
         this.fontSize = fntSize;
         long display = ((LinuxWindowFactory)ContextStorage.getWindowFactory()).getDisplay();
-
         switch (c){
         case '\t':
         case '\r':
         case '\n':
-            pxlMetrics = new int[6];
             break;
         default:
             pxlMetrics = LinuxNativeFont.getGlyphPxlInfoNative(display, this.pFont, c);
+            if (pxlMetrics == null){
+                pxlMetrics = new int[6];
+            }
+/*            metrics = LinuxNativeFont.getGlyphInfoNative(this.pFont, c, fntSize);
+            if (metrics == null){
+                metrics = new float[6];
+            }
+*/ 
             break;
 
-    }
-//      LinuxNativeFont.getGlyphInfoNative(this.pFont, c, fntSize);
+        }
 
-/*      FIXME: The same results as pxl metrics
-        metrics = LinuxNativeFont.getGlyphInfoNative(this.pFont, c, fntSize);
+/*        metrics = LinuxNativeFont.getGlyphInfoNative(this.pFont, c, fntSize);
 
         Rectangle2D.Float rect  = new Rectangle2D.Float(metrics[0],
                                                         -metrics[1],
                                                         metrics[4],
                                                         metrics[5]);
+        this.glPointMetrics = new GlyphMetrics((float)Math.ceil(metrics[2]), rect, (byte)1);
         this.glMetrics = new GlyphMetrics((float)Math.ceil(metrics[2]), rect, (byte)1);
 */
         this.glCode = glyphIndex;
@@ -96,6 +105,7 @@
                                                         -pxlMetrics[1],
                                                         pxlMetrics[4],
                                                         pxlMetrics[5]);
+
         this.glPointMetrics = new GlyphMetrics(pxlMetrics[2], rct, (byte)1);
         this.glMetrics = new GlyphMetrics((float)Math.ceil(pxlMetrics[2]), rct, (byte)0);
 
@@ -137,22 +147,22 @@
         }
 
         if (this.bitmap == null){
-            getFTBitmap();
+            initFTBitmap();
         }
 
         return this.bitmap;
     }
 
-
     /**
-     * Returns array of bytes, representing image of this glyph from native code.
+     * Returns cached GlyphBitmap object representing bitmap data of this glyph.
+     * If cached value is null - bitmap data is to be obtained from native code.
+     * @return GlyphBitmap data object
      */
-    public LinuxNativeFontWrapper.GlyphBitmap getFTBitmap(){
+    public LinuxNativeFontWrapper.GlyphBitmap initFTBitmap(){
         if (this.gBmp == null){
             long ptr = LinuxNativeFont.NativeInitGlyphBitmap(this.pFont, this.glChar);
-            if (ptr != 0)
+            if (ptr != 0){
                 this.gBmp = lnfw.createGlyphBitmap(ptr);
-
                 Xft.FT_Bitmap ft_bitmap = gBmp.get_bitmap();
                 Int8Pointer buffer = ft_bitmap.get_buffer();
                 this.bmp_left = gBmp.get_left();
@@ -161,9 +171,11 @@
                 this.bmp_rows = ft_bitmap.get_rows();
                 this.bmp_width = ft_bitmap.get_width();
                 int bufSize = bmp_pitch * bmp_rows; // size of buffer
-
+                
                 bitmap = new byte[bufSize];
                 buffer.get(bitmap, 0, bufSize);
+                LinuxNativeFont.NativeFreeGlyphBitmap(ptr);
+            }
         }
 
         return this.gBmp;
@@ -204,57 +216,59 @@
 
         return this.image;
     }
-
+    
     public Shape initOutline(char c){
-        if ((this.getWidth()==0) || (this.getHeight()==0)){
-            return new GeneralPath();
+       GeneralPath gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
+       if ((this.getWidth()==0) || (this.getHeight()==0)){
+            return gp;
         }
 
-        GeneralPath gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
         Shape shape = null;
         long ptr;
 
         ptr = LinuxNativeFont.getGlyphOutline(this.pFont, c);
         if (ptr == 0){
-            return null;
+            return gp;
         }
 
         Xft.FT_Outline outline = xft.createFT_Outline(ptr);
 
-        int n_contours = outline.get_n_contours(); /* number of contours in the glyph */
-        Xft.FT_Vector pPoints = outline.get_points(); /* array of outline points */
+        int n_contours = outline.get_n_contours(); // number of contours in the glyph
+        if (n_contours == 0){
+            LinuxNativeFont.freeGlyphOutline(ptr);
+            return gp;
+        }
+        Xft.FT_Vector pPoints = outline.get_points(); // array of outline points
+
         long pPointsPtr = pPoints.lock();
         pPoints.unlock();
-
-        Int16Pointer pContours = outline.get_contours(); /* array of contour end points */
-        Int8Pointer pTags = outline.get_tags(); /* an array of point tags */
-
-        int index = 0;  /* current point's index */
-        int tag;        /* current tag */
+        
+        int size = outline.get_n_points();
+        float points[] = LinuxNativeFont.getPointsFromFTVector(pPointsPtr, size);
+
+        Int16Pointer pContours = outline.get_contours(); // array of contour end points 
+        Int8Pointer pTags = outline.get_tags(); // an array of point tags
+        int index = 0;  // current point's index 
+        int tag;        // current tag 
         float x_start;
         float y_start;
         float x_finish;
         float y_finish;
         for (int i=0; i < n_contours; i++){
-
             short end = pContours.get(i);// index of the last point
-            Xft.FT_Vector point;
 
             // get start position
-            point = xft.createFT_Vector(pPointsPtr + index * (Xft.FT_Vector.sizeof));
-            x_start = (float)((int)point.get_x() + 32)/64;
-            y_start = (float)(-(int)point.get_y() + 32)/64;
-//          System.out.println("AddPoint [" + x_start + "," + y_start + "]");
-
+            x_start = points[index*2];
+            y_start = points[index*2 + 1];
+            
             // get finish position
-            point = xft.createFT_Vector(pPointsPtr + (end - 1) * Xft.FT_Vector.sizeof);
-            x_finish = (float)((int)point.get_x() + 32)/64;
-            y_finish = (float)(-(int)point.get_y() + 32)/64;
+            x_finish = points[end*2];
+            y_finish = points[end*2 + 1];
 
             tag = pTags.get(index);// tag of the current point
 
             if (tag == LinuxNativeFontWrapper.FT_CURVE_TAG_CONIC){
-                tag = pTags.get(end - 1);// tag of the last point
+                tag = pTags.get(end);// tag of the last point
                 if ((tag & LinuxNativeFontWrapper.FT_CURVE_TAG_ON)==0){
                     x_start = x_finish;
                     y_start = y_finish;
@@ -277,25 +291,22 @@
                 tag = pTags.get(index);// tag of the current point
                 switch((tag & 3)){
                     case(LinuxNativeFontWrapper.FT_CURVE_TAG_ON):
-                        point = xft.createFT_Vector(pPointsPtr + index*Xft.FT_Vector.sizeof);
-                        float x = (float)((int)point.get_x() + 32)/64;
-                        float y = (float)(-(int)point.get_y() + 32)/64;
+                        float x = points[index*2];
+                        float y = points[index*2 + 1];
                         gp.lineTo(x, y);
 //                      System.out.println("AddPoint [" + x + "," + y + "]");
                         break;
                     case(LinuxNativeFontWrapper.FT_CURVE_TAG_CONIC):
-                        point = xft.createFT_Vector(pPointsPtr + index*Xft.FT_Vector.sizeof);
-                        float x1 = (float)((int)point.get_x() + 32)/64;
-                        float y1 = (float)(-(int)point.get_y() + 32)/64;
+                        float x1 = points[index*2];
+                        float y1 = points[index*2 + 1];
 
                         float x2;
                         float y2;
                         while (index < end){
                             index++;
                             tag = pTags.get(index);// tag of the current point
-                            point = xft.createFT_Vector(pPointsPtr + index*Xft.FT_Vector.sizeof);
-                            x2 = (float)((int)point.get_x() + 32)/64;
-                            y2 = (float)(-(int)point.get_y() + 32)/64;
+                            x2 = points[index*2];
+                            y2 = points[index*2 + 1];
                             if ((tag & LinuxNativeFontWrapper.FT_CURVE_TAG_ON) != 0){
                                 gp.quadTo(x1, y1, x2, y2);
 //                              System.out.println("AddQSpline 1[" + x1 + "," + y1 + "][" + x2 + "," + y2 + "]");
@@ -313,21 +324,17 @@
                         }
                         break;
                     case(LinuxNativeFontWrapper.FT_CURVE_TAG_CUBIC):
-                        point = xft.createFT_Vector(pPointsPtr + index*Xft.FT_Vector.sizeof);
-                        x1 = (float)((int)point.get_x()+ 32)/64;
-                        y1 = (float)(-(int)point.get_y()+ 32)/64;
-                        point = xft.createFT_Vector(pPointsPtr + index*Xft.FT_Vector.sizeof);
+                        x1 = points[index*2];
+                        y1 = points[index*2 + 1];
                         index++;
+                        x2 = points[index*2];
+                        y2 = points[index*2 + 1];
 
-                        x2 = (float)((int)point.get_x()+ 32)/64;
-                        y2 = (float)(-(int)point.get_y()+ 32)/64;
-
-                        index ++;
+                        if (index < end){
+                            index ++;
 
-                        if (index <= end){
-                            point = xft.createFT_Vector(pPointsPtr + index * Xft.FT_Vector.sizeof);
-                            float x3 = (float)((int)point.get_x()+ 32)/64;
-                            float y3 = (float)(-(int)point.get_y()+ 32)/64;
+                            float x3 = points[index*2];
+                            float y3 = points[index*2 + 1];
                             gp.curveTo(x1, y1, x2, y2, x3, y3);
 //                          System.out.println("AddCSpline 1[" + x1 + "," + y1 + "][" + x2 + "," + y2 + "][" + x3 + "," + y3 + "]");
                         } else {
@@ -336,7 +343,8 @@
                         }
                         break;
                     default:
-                        return null;
+                        LinuxNativeFont.freeGlyphOutline(ptr);
+                        return new GeneralPath(GeneralPath.WIND_EVEN_ODD);
                 }
 
             }
@@ -345,6 +353,7 @@
         }
 
         shape = gp;
+        LinuxNativeFont.freeGlyphOutline(ptr);
         return shape;
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/font/LinuxLineMetrics.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/font/LinuxLineMetrics.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/font/LinuxLineMetrics.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/font/LinuxLineMetrics.java Wed Sep  6 09:06:15 2006
@@ -21,7 +21,6 @@
 
 import java.awt.font.FontRenderContext;
 
-import org.apache.harmony.awt.gl.font.FontManager;
 import org.apache.harmony.awt.gl.font.LineMetricsImpl;
 
 /**
@@ -32,7 +31,7 @@
     
     // LinuxFont corresponding to this LineMetrics object
     private LinuxFont font = null;
-    
+
     /**
      * Constructor
      */
@@ -42,6 +41,10 @@
         // TODO : FontRenderContext isn't used now
         float[] metrics = LinuxNativeFont.getNativeLineMetrics(fnt.getFontHandle(), fnt.getSize(), false, false, fnt.fontType);
 
+        if (metrics == null){
+            metrics = new float[17];
+        }
+        
         font = fnt;
         numChars = str.length();
         baseLineIndex = 0;
@@ -95,8 +98,29 @@
     public float[] getBaselineOffsets() {
         // TODO: implement baseline offsets for TrueType fonts
         if (baselineOffsets == null){
-            baseLineIndex = 0;
-            baselineOffsets = new float[]{0, (-ascent+descent)/2, -ascent};
+            float[] baselineData = null;
+
+            // Temporary workaround:
+            // Commented out native data initialization, since it can 
+            // cause failures with opening files in multithreaded applications.
+            //
+            // TODO: support work with truetype data in multithreaded
+            // applications.
+
+            // If font TrueType data is taken from BASE table
+//            if ((this.font.getFontHandle() != 0) && (font.getFontType() == FontManager.FONT_TYPE_TT)){
+//                baselineData = LinuxNativeFont.getBaselineOffsetsNative(font.getFontHandle(), font.getSize(), ascent, descent, units_per_EM);
+//            }
+//
+//            if (baselineData == null){
+                baseLineIndex = 0;
+                baselineOffsets = new float[]{0, (-ascent+descent)/2, -ascent};
+//            } else {
+//                baseLineIndex = (int)baselineData[3];
+//                baselineOffsets = new float[3];
+//                System.arraycopy(baselineData, 0, baselineOffsets, 0, 3);
+//            }
+
         }
 
         return baselineOffsets;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/font/LinuxNativeFont.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/font/LinuxNativeFont.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/font/LinuxNativeFont.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/font/LinuxNativeFont.java Wed Sep  6 09:06:15 2006
@@ -31,17 +31,16 @@
  */
 public class LinuxNativeFont {
     
-    
     public static final int FC_SLANT_ROMAN = 0;
     public static final int FC_SLANT_ITALIC = 100;
     public static final int FC_SLANT_OBLIQUE = 110;
     public static final int FC_WEIGHT_MEDIUM = 100;
-    
+
     /**
      * Returns array of Strings that represents list of all font families names
      * available on the system.  
      */
-    public static native String[] getFontFamiliesNames();
+    public synchronized static native String[] getFontFamiliesNames();
 
     /**
      * Returns true if the new font was added to the system, false otherwise.
@@ -50,8 +49,8 @@
      *   
      * @param absolutePath absolute path to the font.
      */
-    public static native boolean embedFontNative(String absolutePath);
-    
+    public synchronized static native boolean embedFontNative(String absolutePath);
+
     /**
      * Initiailzes native Xft font object from specified parameters and returns 
      * font handle, also sets font type to the font peer parameter. 
@@ -63,27 +62,16 @@
      * @param size size of the font
      * @param styleName style name of the font
      */
-    public static native long initializeFont(LinuxFont linFont, String family, int style, int size, String styleName);
-
-    /**
-     * Initializes native Xft font object from xlfd string and returns font handle,  
-     * also sets font type to the font peer parameter. If font 
-     * that is described by the given xlfd doesn't exist onto a system returned value
-     * is null. NullPointerException is thrown if there are errors in native code. 
-     * 
-     * @param linFont LinuxFont instanse
-     * @param xlfd String representing font in xlfd format
-     * @param size size of the font
-     */
-    public static native long initializeFontFromFP(LinuxFont linFont, String xlfd, int size);
+    public synchronized static native long initializeFont(LinuxFont linFont, String family, int style, int size, String styleName);
 
     /** 
      * Returns number of glyphs in specified XftFont if success. 
      * 
      * @param hndFont XftFont handle
      */
-    public static native int getNumGlyphsNative(long hndFont);
-    
+
+    public synchronized static native int getNumGlyphsNative(long hndFont);
+
     /**
      * Returns true, if XftFont object can display specified char.
      * 
@@ -93,21 +81,21 @@
     // !! Instead of this method getGlyphCode can be used
     // TODO: implement method and find out if this method faster than getGlyphCode 
     // usage 
-    public static native boolean canDisplayCharNative(long hndFont, char c);
+    public synchronized static native boolean canDisplayCharNative(long hndFont, char c);
 
     /**
      * Returns family name of the XftFont object.
      * 
      * @param hndFont XftFont handle
      */
-    public static native String getFamilyNative(long hndFont);
-    
+    public synchronized static native String getFamilyNative(long hndFont);
+
     /**
      * Returns face name of the XftFont object.
      * 
      * @param hndFont XftFont handle
      */
-    public static native String getFontNameNative(long hndFont);
+    public synchronized static native String getFontNameNative(long hndFont);
 
     /**
      * Returns XftFont's postscript name.
@@ -116,7 +104,7 @@
      * 
      * @param fnt XftFont handle
      */
-    public static native String getFontPSNameNative(long fnt);
+    public synchronized static native String getFontPSNameNative(long fnt);
 
     /**
      * Disposing XftFont object.
@@ -124,7 +112,7 @@
      * @param hndFont XftFont handle
      * @param display Display handle
      */
-    public static native void pFontFree(long hndFont, long display);
+    public synchronized static native void pFontFree(long hndFont, long display);
 
     /**
      * Returns tangent of Italic angle of given Font.
@@ -133,13 +121,13 @@
      * @param hndFont XftFont handle
      * @param fontType type of the font
      */
-    public static native float getItalicAngleNative(long hndFont, int fontType);
-    
+    public synchronized static native float getItalicAngleNative(long hndFont, int fontType);
+
     /** 
      * Returns an array of available system fonts names.
      * In case of errors in native code NullPointerException is thrown.
      */
-    public static native String[] getFonts();
+    public synchronized static native String[] getFonts();
 
     /**
      * Returns array of values of font metrics corresponding to the given XftFont 
@@ -151,7 +139,7 @@
      * @param usesFractionalMetrics true if results calculated using fractional metrics
      * @param fontType type of the specified font
      */
-    public static native float[] getNativeLineMetrics(long hFont, int fontSize,
+    public synchronized static native float[] getNativeLineMetrics(long hFont, int fontSize,
             boolean isAntialiased, boolean usesFractionalMetrics, int fontType);
 
     /** 
@@ -162,7 +150,7 @@
      * @param pFnt XftFont handle
      * @param c specified char
      */
-    public static native float[] getGlyphInfoNative(long pFnt, char c,
+    public synchronized static native float[] getGlyphInfoNative(long pFnt, char c,
             int fontSize);
 
     /** 
@@ -172,8 +160,8 @@
      * @param pFnt XftFont handle
      * @param c specified char
      */
-    public static native int[] getGlyphPxlInfoNative(long display, long pFnt, char c);
-    
+    public synchronized static native int[] getGlyphPxlInfoNative(long display, long pFnt, char c);
+
     /**
      * Returns glyphs code corresponding to the characters in String specified, null 
      * is returned if failure. NullPointerException is thrown in case of Display 
@@ -184,8 +172,8 @@
      * @param display Display handle
      */
     // TODO: implement native call
-    public static native int[] getGlyphCodesNative(long fnt, String str, int len);
-    
+    public synchronized static native int[] getGlyphCodesNative(long fnt, String str, int len);
+
     /**
      * Returns glyph code corresponding to the specified character, null is 
      * returned if failure. NullPointerException is thrown in case of Display is null.
@@ -194,8 +182,8 @@
      * @param uChar specified char
      * @param display Display handle
      */
-    public static native int getGlyphCodeNative(long fnt, char uChar, long display);
-    
+    public synchronized static native int getGlyphCodeNative(long fnt, char uChar, long display);
+
     /**
      * Updates specified folder where temporary font created from InputStream stored.
      * This method used in LinuxFont dispose method, it re-caches ~/.fonts
@@ -204,20 +192,7 @@
      * @param tempFontFileName directory that is being re-cached name.
      * @return not null value if succcess, 0 otherwise
      */
-    public static native int RemoveFontResource(String tempFontFileName);
-    
-    /**
-     * Returns byte array that represents bitmap
-     * of the character specified. 
-     * ( Better to use NativeInitGlyphBitmap method to get
-     * bitmap of the glyph. This method is to be deleted in the nearest future.)
-     * 
-     * @param fnt XftFont handle
-     * @param chr specified char
-     */
-    // TODO: avoid use of this method in font classes due to incomplete returned 
-    // bitmap information
-    public static native byte[] NativeInitGlyphImage(long fnt, char uChar);
+    public synchronized static native int RemoveFontResource(String tempFontFileName);
 
     /**
      * Draws text on XftDraw with specified parameters using Xft library.
@@ -232,17 +207,52 @@
      * @param len length of the array of chars
      * @param xcolor XColor handle, the color of the text
      */
-    public static native void drawStringNative(long xftDraw, long display, long colormap, long font, int x, int y, char[] chars, int len, long xcolor);
+    public synchronized static native void drawStringNative(long xftDraw, long display, long colormap, long font, int x, int y, char[] chars, int len, long xcolor);
     
 // FreeType routines
+    
     /**
-     * Returns pointer to FreeType FT_Bitmap that represents bitmap
-     * of the character specified or 0 if failures in native code.
+     * Returns pointer to GlyphBitmap structure that represents bitmap
+     * with parameters of the character specified or 0 if failures 
+     * in native code.
      * 
      * @param fnt XftFont handle
      * @param chr specified char
      */
-    public static native long NativeInitGlyphBitmap(long fnt, char chr);
+    public synchronized static native long NativeInitGlyphBitmap(long fnt, char chr);
+    
+    /**
+     * Disposes memory block that is used by FreeType FT_Bitmap structure
+     * by pointer specified.
+     * 
+     * @param ptr specified pointer to the memory block
+     */    
+    public synchronized static native void NativeFreeGlyphBitmap(long bitmap);
+
+    /**
+     * Returns pointer to the FreeType FT_Outline structure. 
+     * 
+     * @param pFont XFT font handle
+     * @param c specified character
+     */
+    public synchronized static native long getGlyphOutline(long pFont, char c);
+    
+    /**
+     * Disposes memory block that is used by FreeType FT_Outline structure
+     * by pointer specified.
+     * 
+     * @param ptr specified pointer to the memory block
+     */
+    public synchronized static native void freeGlyphOutline(long ptr);
+
+    /**
+     * Returns an array of pairs of coordinates [x1, y1, x2, y2...] from 
+     * FreeType FT_Vector structure.  
+     * 
+     * @param ft_vector pointer to the memory block with FT_Vector structure
+     * @param size number of elements in FT_Vector structure
+     */
+    public synchronized static native float[] getPointsFromFTVector(long ft_vector, int size);
 
 // Xft routines
     
@@ -253,13 +263,13 @@
      * @param drawable Drawable handle
      * @param visual Visual handle
      */
-    public static native long createXftDrawNative(long display, long drawable, long visual);
+    public synchronized static native long createXftDrawNative(long display, long drawable, long visual);
 
     /**
      * Destroys XftDraw object.
      * @param xftDraw XftDraw handle 
      */
-    public static native void freeXftDrawNative(long xftDraw);
+    public synchronized static native void freeXftDrawNative(long xftDraw);
 
     /**
      * Set new subwindow mode to XftDraw object
@@ -268,7 +278,7 @@
      * @param mode new mode
      */
     public static native void xftDrawSetSubwindowModeNative(long xftDraw, int mode);
-    
+
     /**
      * Sets clipping rectangles in Xft drawable to the specified clipping rectangles. 
      * 
@@ -283,15 +293,29 @@
     public static native boolean XftDrawSetClipRectangles(long xftDraw, int xOrigin,
             int yOrigin, long rects, int n);
 
+//  public static native boolean isCharExists(char chr);
+
     /**
-     * Returns pointer to the FreeType FT_Outline structure. 
+     * Returns an array of extrametrics of the font:<p>
+     *  elem[0] - the average width of characters in the font (Type1 - 0.0f)<p>
+     *  elem[1] - horizontal size for subscripts (Type1 - 0.7f * fontHeight)<p> 
+     *  elem[2] - vertical size for subscripts (Type1 - 0.65f * fontHeight)<p> 
+     *  elem[3] - horizontal offset for subscripts (Type1 - 0.0f)<p>
+     *  elem[4] - vertical offset value for subscripts(Type1 - 0.15f * fontHeight)<p>
+     *  elem[5] - horizontal size for superscripts (Type1 - 0.7f * fontHeight)<p>
+     *  elem[6] - vertical size for superscripts (Type1 - 0.65f * fontHeight)<p>
+     *  elem[7] - horizontal offset for superscripts (Type1 - 0.0f)<p> 
+     *  elem[8] - vertical offset for superscripts (Type1 - 0.45f * fontHeight)<p> 
+     * For TrueType fonts metrics are taken from OS2 table, for Type1 fonts
+     * metrics are calculated using coefficients (read FontExtraMetrics comments).
+     * OS2 table can be found at http://www.freetype.org/freetype2/docs/reference/ft2-truetype_tables.html#TT_OS2
      * 
-     * @param pFont XFT font handle
-     * @param c specified character
+     * @param hFont XFT font handle
+     * @param fontSize font size
+     * @param fontType type of the font
      */
-    public static native long getGlyphOutline(long pFont, char c);
+    public synchronized static native float[] getExtraMetricsNative(long hFont, int fontSize, int fontType);
 
-//  public static native boolean isCharExists(char chr);
 
     /**
      * Initializes LCID table
@@ -510,8 +534,8 @@
      * List of font style names of system fonts supported by a system 
      * corresponding to faces indexing.
      */
-    public static String[] styles;
-
+    public static String[] styleNames;
+    
     /**
      * List of family indexes in families array corresponding to the faces 
      * indexing.
@@ -519,6 +543,12 @@
     public static int[] famIndices;
 
     /**
+     * List of font styles of system fonts supported by a system 
+     * corresponding to faces indexing.
+     */
+    public static int[] fontStyles;
+
+    /**
      * The number of different fonts installed onto the system.
      */
     public static int facesCount;
@@ -529,11 +559,12 @@
     public static Vector fams = new Vector();
 
     /**
-     * Returns font family name of the font with face having specified index.
+     * Returns family name that corresponds to the face with specified 
+     * face index.
      * 
-     * @param faceIndex specified index of the face in faces array
+     * @param faceIndex index of the face in faces array
      */
-    public static String getFamily(int faceIndex){
+    public static String getFamilyFromFaceIndex(int faceIndex){
         return (String)fams.get(famIndices[faceIndex]);
     }
 
@@ -542,8 +573,17 @@
      * 
      * @param faceIndex specified index of the face in faces array
      */
-    public static String getFontStyle(int faceIndex){
-        return styles[faceIndex];
+    public static String getFontStyleName(int faceIndex){
+        return styleNames[faceIndex];
+    }
+
+    /**
+     * Returns font style of the font with face having specified index.
+     * 
+     * @param faceIndex specified index of the face in faces array
+     */
+    public static int getFontStyle(int faceIndex){
+        return fontStyles[faceIndex];
     }
 
     /**
@@ -555,45 +595,53 @@
             initFaces();
         return faces;
     }
-    
+
     /**
-     * Initializes famIndices, styles and faces arrays according to the 
-     * font information available on the system. 
+     * Initializes famIndices, styles, style names and faces arrays 
+     * according to the font information available on the system. 
      */
     public static void initFaces(){
         if (facesCount == 0){
             String[] fontNames = getFonts();
             facesCount = fontNames.length;
             faces = new String[facesCount];
-            styles = new String[facesCount];
+            styleNames = new String[facesCount];
             famIndices = new int[facesCount];
+            fontStyles = new int[facesCount];
 
             for (int i =0; i < facesCount; i++){
                 initFace(i, fontNames[i]);
             }
         }
     }
-    
+
     /**
      * Initializes specified elements with index specified of famIndices, styles and 
      * faces arrays according to the given faceString. faceString has format 
-     * "family name"-"style name".
+     * "family name"-"style name"-style.
      * 
      * @param index index of element to identify
-     * @param faceString String defining family name and style in special format
+     * @param faceString String defining family name, style name and style in 
+     * special format
      */
     public static void initFace(int index, String faceString){
         String delim = "-";
         int pos;
-
         if (faceString == null) {
             return;
         }
-        pos = faceString.lastIndexOf(delim);
 
-        styles[index] = faceString.substring(pos+1);
+        String str = faceString;
+        pos = str.lastIndexOf(delim);
 
-        String family = faceString.substring(0, pos);
+        // get style value
+        int style = Integer.parseInt(str.substring(pos+1));
+        str = str.substring(0, pos);
+
+        pos = str.lastIndexOf(delim);
+
+        // get family name
+        String family = str.substring(0, pos);
         int famIndex = fams.indexOf(family);
         if(famIndex == -1){
             fams.add(family);
@@ -601,7 +649,11 @@
         }
         famIndices[index] = famIndex;
 
-        faces[index] = family + " " + styles[index];
+        styleNames[index] = str.substring(pos+1);
+        
+        fontStyles[index] = style;
+
+        faces[index] = family + " " + styleNames[index];
     }
 
     /** Returns the list of system font families names. */
@@ -615,7 +667,7 @@
         }
         return names;
     }
-    
+
     /**
      * Returns an array of instanses of 1 pt. sized plain Font objects
      * corresponding to fonts supported by a system. 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/linux/DrawableTextRenderer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/linux/DrawableTextRenderer.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/linux/DrawableTextRenderer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/linux/DrawableTextRenderer.java Wed Sep  6 09:06:15 2006
@@ -98,6 +98,7 @@
         LinuxFont peer = (LinuxFont)g.getFont().getPeer();
 
         X11.XColor xcolor = getXColor(g.getColor());
+        long xcolorPtr = xcolor.lock();
 
         /*
          * Work around for escape-subsequences.
@@ -127,9 +128,9 @@
         if (inChars.length != 0 ){
             LinuxNativeFont.drawStringNative(xg2d.xftDraw, display, colormap, 
                     peer.getFontHandle(), (int)Math.round(x), (int)Math.round(y), 
-                    outChars, j, xcolor.lock());
-            xcolor.unlock();
+                    outChars, j, xcolorPtr);
         }
+        xcolor.unlock();
 
     }
 
@@ -151,7 +152,8 @@
         long colormap = x11.XDefaultColormap(display, screen);
 
         X11.XColor xcolor = getXColor(g.getColor());
-
+        long xcolorPtr = xcolor.lock();
+        
         CompositeFont wcf = (CompositeFont)(g.getFont().getPeer());
         long font = 0;
         int xOffset = (int)Math.round(x);    // X offset to draw
@@ -174,8 +176,7 @@
                 chars = sChars.toCharArray();
                 LinuxNativeFont.drawStringNative(xg2d.xftDraw, display, 
                         colormap, font, xOffset, yOffset, chars, 
-                        sChars.length(), xcolor.lock());
-                xcolor.unlock();
+                        sChars.length(), xcolorPtr);
 
                 xOffset += offs;
                 offs = 0;
@@ -190,9 +191,9 @@
         if (chars.length != 0){
             LinuxNativeFont.drawStringNative(xg2d.xftDraw, display, colormap, 
                     font, xOffset, yOffset, chars, sChars.length(), 
-                    xcolor.lock());
-            xcolor.unlock();
+                    xcolorPtr);
         }
+        xcolor.unlock();
 
     }
 
@@ -233,6 +234,7 @@
         LinuxFont peer = (LinuxFont)glyphVector.getFont().getPeer();
 
         X11.XColor xcolor = getXColor(g.getColor());
+        long xcolorPtr = xcolor.lock();
 
         for (int i = 0; i < glyphVector.getNumGlyphs(); i++) {
 
@@ -249,9 +251,9 @@
 
             LinuxNativeFont.drawStringNative(xg2d.xftDraw, display, colormap, 
                     peer.getFontHandle(), xBaseLine, yBaseLine, chars, 1, 
-                    xcolor.lock());
-            xcolor.unlock();
+                    xcolorPtr);
         }
+        xcolor.unlock();
 
     }
 
@@ -273,6 +275,7 @@
         long colormap = x11.XDefaultColormap(display, screen);
 
         X11.XColor xcolor = getXColor(g.getColor());
+        long xcolorPtr = xcolor.lock();
 
         for (int i = 0; i < glyphVector.getNumGlyphs(); i++) {
 
@@ -289,9 +292,9 @@
 
             LinuxNativeFont.drawStringNative(xg2d.xftDraw, display, colormap, 
                     gl.getPFont(), xBaseLine, yBaseLine, chars, 1, 
-                    xcolor.lock());
-            xcolor.unlock();
+                    xcolorPtr);
         }
+        xcolor.unlock();
 
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/linux/LinuxGraphics2DFactory.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/linux/LinuxGraphics2DFactory.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/linux/LinuxGraphics2DFactory.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/linux/LinuxGraphics2DFactory.java Wed Sep  6 09:06:15 2006
@@ -25,6 +25,7 @@
 
 import org.apache.harmony.awt.gl.CommonGraphics2DFactory;
 import org.apache.harmony.awt.gl.MultiRectArea;
+import org.apache.harmony.awt.gl.opengl.OGLGraphics2D;
 import org.apache.harmony.awt.gl.font.FontManager;
 import org.apache.harmony.awt.gl.font.LinuxFont;
 import org.apache.harmony.awt.gl.font.LinuxFontManager;
@@ -42,11 +43,19 @@
         inst = new LinuxGraphics2DFactory();
     }
     public Graphics2D getGraphics2D(NativeWindow nw, int tx, int ty, MultiRectArea clip) {
-        return new XGraphics2D(nw, tx, ty, clip);
+        String opengl = System.getProperty("java2d.opengl");
+        boolean useOpenGL = opengl != null && opengl.equals("true");
+        return useOpenGL ?
+                (Graphics2D) new OGLGraphics2D(nw, tx, ty, clip) :
+                new XGraphics2D(nw, tx, ty, clip);
     }
 
     public Graphics2D getGraphics2D(NativeWindow nw, int tx, int ty, int width, int height) {
-        return new XGraphics2D(nw, tx, ty, width, height);
+        String opengl = System.getProperty("java2d.opengl");
+        boolean useOpenGL = opengl != null && opengl.equals("true");
+        return useOpenGL ?
+                (Graphics2D) new OGLGraphics2D(nw, tx, ty, width, height) :
+                new XGraphics2D(nw, tx, ty, width, height);
     }
 
     public GraphicsEnvironment createGraphicsEnvironment(WindowFactory wf) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/linux/XGraphicsConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/linux/XGraphicsConfiguration.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/linux/XGraphicsConfiguration.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/linux/XGraphicsConfiguration.java Wed Sep  6 09:06:15 2006
@@ -22,19 +22,20 @@
 
 package org.apache.harmony.awt.gl.linux;
 
-import org.apache.harmony.awt.nativebridge.Int8Pointer;
-import org.apache.harmony.awt.nativebridge.NativeBridge;
+import org.apache.harmony.awt.nativebridge.*;
 import org.apache.harmony.awt.nativebridge.linux.X11;
 import org.apache.harmony.awt.nativebridge.linux.X11Defs;
 
 import java.awt.*;
-import java.awt.color.ColorSpace;
 import java.awt.image.*;
 import java.awt.geom.AffineTransform;
 
 
 public class XGraphicsConfiguration extends GraphicsConfiguration {
-    private static final X11 x11 = X11.getInstance();
+    // X11 atom, required for getting the default colormap
+    private static final long XA_RGB_DEFAULT_MAP = 27;
+
+    protected static final X11 x11 = X11.getInstance();
 
     XGraphicsDevice dev;
     X11.XVisualInfo info;
@@ -45,7 +46,82 @@
     XGraphicsConfiguration(XGraphicsDevice dev, X11.XVisualInfo info) {
         this.dev = dev;
         this.info = info;
-        xcolormap = x11.XDefaultColormap(dev.display, dev.screen);
+        xcolormap = obtainRGBColorMap();
+    }
+
+    public long getXColormap() {
+        return xcolormap;
+    }
+
+    public int getDepth() {
+        return info.get_depth();
+    }
+
+    public X11.Visual getVisual() {
+        return info.get_visual();
+    }
+
+    private long obtainRGBColorMap() {
+        X11.Visual defVisual = x11.createVisual(x11.XDefaultVisual(dev.display, dev.screen));
+        if (info.get_visualid() == defVisual.get_visualid()) {
+            return x11.XDefaultColormap(dev.display, dev.screen);
+        }
+
+        X11.Visual vis = info.get_visual();
+        long rootWindow = x11.XRootWindow(dev.display, dev.screen);
+
+        int status = x11.XmuLookupStandardColormap(
+                dev.display, dev.screen,
+                info.get_visualid(),
+                info.get_depth(),
+                               XA_RGB_DEFAULT_MAP,
+                               X11Defs.False,
+                X11Defs.True
+        );
+
+        if (status == 1) {
+            Int32Pointer nCmaps = NativeBridge.getInstance().createInt32Pointer(1, true);
+            PointerPointer stdCmaps = NativeBridge.getInstance().createPointerPointer(1, true);
+
+            status = x11.XGetRGBColormaps(
+                    dev.display,
+                    rootWindow,
+                    stdCmaps,
+                                   nCmaps,
+                    XA_RGB_DEFAULT_MAP
+            );
+
+            int numCmaps = nCmaps.get(0);
+            VoidPointer ptr = stdCmaps.get(0);
+            nCmaps.free();
+            stdCmaps.free();
+
+            if (status == 1) {
+                for (int i = 0; i < numCmaps; i++) {
+
+                    X11.XStandardColormap stdCmap = x11.createXStandardColormap(
+                            ptr.byteBase.getElementPointer(i*X11.XStandardColormap.sizeof)
+                    );
+
+                    if (stdCmap.get_visualid() == info.get_visualid()) {
+                        long cmap = stdCmap.get_colormap();
+                        x11.XFree(ptr);
+                        return cmap;
+                    }
+                }
+
+                x11.XFree(ptr);
+            }
+        }
+
+        long cmap = x11.XCreateColormap(
+                dev.display,
+                rootWindow,
+                vis.lock(),
+                X11Defs.AllocNone
+        );
+        vis.unlock();
+        return cmap;
     }
 
     public GraphicsDevice getDevice() {
@@ -95,6 +171,9 @@
                     );
                     break;
                 case X11Defs.StaticGray:
+                    // looks like native colormap differs from the colors given
+                    // by the gray ICC profile
+                    /*
                     // This should be enough
                     cm = new ComponentColorModel(
                             ColorSpace.getInstance(ColorSpace.CS_GRAY),
@@ -105,6 +184,7 @@
                             DataBuffer.TYPE_BYTE
                     );
                     break;
+                    */
                 case X11Defs.PseudoColor:
                 case X11Defs.GrayScale:
                 case X11Defs.StaticColor: {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/linux/XGraphicsDevice.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/linux/XGraphicsDevice.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/linux/XGraphicsDevice.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/linux/XGraphicsDevice.java Wed Sep  6 09:06:15 2006
@@ -23,6 +23,7 @@
 package org.apache.harmony.awt.gl.linux;
 
 import java.awt.*;
+import java.lang.reflect.InvocationTargetException;
 
 import org.apache.harmony.awt.gl.GLGraphicsDevice;
 import org.apache.harmony.awt.gl.Utils;
@@ -30,6 +31,7 @@
 import org.apache.harmony.awt.nativebridge.NativeBridge;
 import org.apache.harmony.awt.nativebridge.linux.X11;
 import org.apache.harmony.awt.nativebridge.linux.X11Defs;
+import org.apache.harmony.awt.ContextStorage;
 
 public class XGraphicsDevice extends GLGraphicsDevice {
     private static final X11 x11 = X11.getInstance();
@@ -63,17 +65,39 @@
 
         return xscreen;
     }
-    /*
-    private final X11.Display getXdisplay() {
-        if (xdisplay == null)
-            xdisplay = x11.new Display(display);
 
-        return xdisplay;
-    }
-    */
     private final XGraphicsConfiguration[] getConfigs() {
-        if (configs == null)
-            createConfigs();
+        if (configs == null) {
+            //createConfigs();
+
+            if (true || EventQueue.isDispatchThread()) {
+                createConfigs();
+            } else {
+                boolean wasAWTLocked = false;
+                try {
+                    // XXX - todo - This is a hack actually, should be discussed further
+                    try {
+                        ContextStorage.getSynchronizer().storeStateAndFree();
+                        wasAWTLocked = true;
+                    } catch (RuntimeException e) {}
+
+                    try {
+                        EventQueue.invokeAndWait(
+                                new Runnable() {
+                                    public void run () { createConfigs(); }
+                                }
+                        );
+                    } catch (InterruptedException e) {
+                        e.printStackTrace();
+                    } catch (InvocationTargetException e) {
+                        e.printStackTrace();
+                    }
+                } finally {
+                    if (wasAWTLocked)
+                        ContextStorage.getSynchronizer().lockAndRestoreState();
+                }
+            }
+        }
 
         return configs;
     }
@@ -106,15 +130,32 @@
         // Allocate array for configurations
         configs = new XGraphicsConfiguration[numVisualInfos];
 
+        String opengl = System.getProperty("java2d.opengl");
+        boolean useOpenGL = opengl != null && opengl.equals("true");
+
         for (int i=0; i<numVisualInfos; i++) {
             X11.XVisualInfo info = x11.createXVisualInfo(
                     infosPtr.getElementPointer(i*infosPtr.size())
             );
-            configs[i] = new XGraphicsConfiguration(this, info);
+            configs[i] = //useOpenGL ?
+//                    new GLXGraphicsConfiguration(this, info) :
+                    new XGraphicsConfiguration(this, info);
 
             if (info.get_visualid() == defVisId)
                 defaultConfigIdx = i;
         }
+
+/*        if (useOpenGL) {
+            //defVisId = 36;
+            defVisId = GLXGraphicsConfiguration.GlxConfigsRec.getBestGLXVisualId(display, screen);
+            for (int i=0; i<numVisualInfos; i++) {
+                if (configs[i].info.get_visualid() == defVisId) {
+                    defaultConfigIdx = i;
+                    break;
+                }
+            }
+        }
+*/        
     }
 
     public int getType() {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/linux/XSurface.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/linux/XSurface.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/linux/XSurface.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/linux/org/apache/harmony/awt/gl/linux/XSurface.java Wed Sep  6 09:06:15 2006
@@ -61,7 +61,24 @@
     }
 
     void setRoi(Rectangle2D roi) {
-        this.roi = roi;
+        if (roi.getX() < 0 || roi.getY() < 0) {
+            double x = roi.getX();
+            double y = roi.getY();
+            double width = roi.getWidth();
+            double height = (int) roi.getHeight();
+            if (x < 0) {
+                width += x;
+                x = 0;
+            }
+            if (y < 0) {
+                height += y;
+                y = 0;
+            }
+
+            this.roi = new Rectangle2D.Double(x, y, width, height);
+        } else {
+            this.roi = roi;
+        }
     }
 
     public ColorModel getColorModel() {



Mime
View raw message