harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r442084 - in /incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt: Font.java RenderingHints.java
Date Mon, 11 Sep 2006 03:51:22 GMT
Author: ndbeyer
Date: Sun Sep 10 20:51:22 2006
New Revision: 442084

URL: http://svn.apache.org/viewvc?view=rev&rev=442084
Log:
Uplift code to Java 5 spec.

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java
    incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/RenderingHints.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java?view=diff&rev=442084&r1=442083&r2=442084
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/Font.java
Sun Sep 10 20:51:22 2006
@@ -13,10 +13,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-/**
- * @author Ilya S. Okomin
- * @version $Revision$
- */
+
 package java.awt;
 
 import java.awt.font.FontRenderContext;
@@ -28,6 +25,7 @@
 import java.awt.geom.Rectangle2D;
 import java.io.BufferedInputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -65,6 +63,8 @@
     public static final int HANGING_BASELINE = 2;
 
     public static final int TRUETYPE_FONT = 0;
+    
+    public static final int TYPE1_FONT = 1;
 
     public static final int LAYOUT_LEFT_TO_RIGHT = 0;
 
@@ -125,7 +125,7 @@
 
     }
 
-    public Font(Map<Attribute, Object> attributes) {
+    public Font(Map<? extends Attribute, ?> attributes) {
         Object currAttr;
 
         // Default values are taken from the documentation of the Font class. 
@@ -232,6 +232,14 @@
         FontPeerImpl peer = (FontPeerImpl)this.getPeer();
         return peer.canDisplay(c);
     }
+    
+    public boolean canDisplay(int i) {
+        if (!Character.isValidCodePoint(i)) {
+            throw new IllegalArgumentException();
+        }
+        //TODO implement true code point support 
+        return canDisplay((char)i);
+    }
 
     public int canDisplayUpTo(char[] text, int start, int limit) {
         int st = start;
@@ -478,8 +486,9 @@
 
     }
 
+
     @SuppressWarnings("unchecked")
-    public Font deriveFont(Map<?, ?> attributes) {
+    public Font deriveFont(Map<? extends Attribute, ?> attributes) {
         Attribute[] avalAttributes = this.getAvailableAttributes();
 
         Hashtable<Attribute, Object> derivefRequestedAttributes = (Hashtable<Attribute,
Object>)fRequestedAttributes.clone();
@@ -516,8 +525,8 @@
     }
 
     @SuppressWarnings("unchecked")
-    public Map<Attribute, Object> getAttributes() {
-        return (Map<Attribute, Object>)fRequestedAttributes.clone();
+    public Map<TextAttribute, Object> getAttributes() {
+        return (Map<TextAttribute, Object>)fRequestedAttributes.clone();
     }
 
     public Attribute[] getAvailableAttributes() {
@@ -549,7 +558,7 @@
     }
 
 
-    public static Font getFont(Map<Attribute, Object> attributes) {
+    public static Font getFont(Map<? extends Attribute, ?> attributes) {
         Font fnt = (Font)attributes.get(TextAttribute.FONT);
         if (fnt != null){
             return fnt;
@@ -882,6 +891,16 @@
         return peer.getItalicAngle();
     }
 
+    public static Font createFont(int fontFormat, File fontFile) throws FontFormatException,
+            IOException {
+        InputStream is = new FileInputStream(fontFile);
+        try {
+            return createFont(fontFormat, is);
+        } finally {
+            is.close();
+        }
+    }
+    
     public static Font createFont(int fontFormat, InputStream fontStream)
             throws FontFormatException, IOException {
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/RenderingHints.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/RenderingHints.java?view=diff&rev=442084&r1=442083&r2=442084
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/RenderingHints.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/RenderingHints.java
Sun Sep 10 20:51:22 2006
@@ -29,12 +29,7 @@
  * RenderingHints
  *
  */
-public class RenderingHints implements Map, Cloneable {
-    private final HashMap map = new HashMap();
-
-    /*
-     * Keys and values
-     */
+public class RenderingHints implements Map<Object, Object>, Cloneable {
     public static final Key KEY_ALPHA_INTERPOLATION = new KeyImpl(1);
     public static final Object VALUE_ALPHA_INTERPOLATION_DEFAULT = new KeyValue(KEY_ALPHA_INTERPOLATION);
     public static final Object VALUE_ALPHA_INTERPOLATION_SPEED = new KeyValue(KEY_ALPHA_INTERPOLATION);
@@ -80,18 +75,22 @@
     public static final Object VALUE_TEXT_ANTIALIAS_ON = new KeyValue(KEY_TEXT_ANTIALIASING);
     public static final Object VALUE_TEXT_ANTIALIAS_OFF = new KeyValue(KEY_TEXT_ANTIALIASING);
 
-    public RenderingHints(Map map) {
+    private HashMap<Object, Object> map = new HashMap<Object, Object>();
+    
+    public RenderingHints(Map<Key, ?> map) {
+        super();
         if (map != null) {
             putAll(map);
         }
     }
 
     public RenderingHints(Key key, Object value) {
+        super();
         put(key, value);
     }
 
     public void add(RenderingHints hints) {
-        map.putAll(hints);
+        map.putAll(hints.map);
     }
 
     public Object put(Object key, Object value) {
@@ -110,32 +109,31 @@
         return map.get(key);
     }
 
-    public Set keySet() {
+    public Set<Object> keySet() {
         return map.keySet();
     }
 
-    public Set entrySet() {
+    public Set<Map.Entry<Object, Object>> entrySet() {
         return map.entrySet();
     }
 
-    public void putAll(Map m) {
+    public void putAll(Map<?, ?> m) {
         if (m instanceof RenderingHints) {
-            map.putAll(((RenderingHints)m).map);
-            return;
-        }
-
-        Set entries = m.entrySet();
-
-        Iterator it = entries.iterator();
-        while (it.hasNext()) {
-            Map.Entry entry = (Map.Entry)it.next();
-            Key key = (Key)entry.getKey();
-            Object val = entry.getValue();
-            put(key, val);
+            map.putAll(((RenderingHints) m).map);
+        } else {
+            Set<?> entries = m.entrySet();
+
+            Iterator<?> it = entries.iterator();
+            while (it.hasNext()) {
+                Map.Entry<?, ?> entry = (Map.Entry<?, ?>) it.next();
+                Key key = (Key) entry.getKey();
+                Object val = entry.getValue();
+                put(key, val);
+            }
         }
     }
 
-    public Collection values() {
+    public Collection<Object> values() {
         return map.values();
     }
 
@@ -169,13 +167,13 @@
             return false;
         }
 
-        Map m = (Map)o;
-        Set keys = keySet();
+        Map<?, ?> m = (Map<?, ?>)o;
+        Set<?> keys = keySet();
         if (!keys.equals(m.keySet())) {
             return false;
         }
 
-        Iterator it = keys.iterator();
+        Iterator<?> it = keys.iterator();
         while (it.hasNext()) {
             Key key = (Key)it.next();
             Object v1 = get(key);
@@ -192,9 +190,12 @@
         return map.hashCode();
     }
 
+    @SuppressWarnings("unchecked")
     @Override
     public Object clone() {
-        return new RenderingHints(map);
+        RenderingHints clone = new RenderingHints(null);
+        clone.map = (HashMap<Object, Object>)this.map.clone();
+        return clone;
     }
 
     @Override
@@ -206,7 +207,7 @@
      * Key
      */
     public abstract static class Key {
-        private int key;
+        private final int key;
 
         protected Key(int key) {
             this.key = key;



Mime
View raw message