diff options
author | smallsql <smallsql> | 2011-07-17 19:24:13 +0400 |
---|---|---|
committer | smallsql <smallsql> | 2011-07-17 19:24:13 +0400 |
commit | b64ac018a5cafcb7560f8644fea9443c2db6609f (patch) | |
tree | 2a2683c8edf86dd168165fbdf14a9fb4e242c8e0 /openjdk/sun | |
parent | 9bdf625e6e0b7c0976f325f4af99d370de980977 (diff) |
port findFont2D from FontManager to SunFontManager
Diffstat (limited to 'openjdk/sun')
-rw-r--r-- | openjdk/sun/font/Font2D.java | 2 | ||||
-rw-r--r-- | openjdk/sun/font/SunFontManager.java | 32 |
2 files changed, 31 insertions, 3 deletions
diff --git a/openjdk/sun/font/Font2D.java b/openjdk/sun/font/Font2D.java index 37a311ae..7fc9eda0 100644 --- a/openjdk/sun/font/Font2D.java +++ b/openjdk/sun/font/Font2D.java @@ -37,7 +37,7 @@ import sun.awt.SunHints; */ public abstract class Font2D{ - public Font2DHandle handle; + public Font2DHandle handle = new Font2DHandle(this); /* SunGraphics2D has font, tx, aa and fm. From this info * can get a Strike object from the cache, creating it if necessary. diff --git a/openjdk/sun/font/SunFontManager.java b/openjdk/sun/font/SunFontManager.java index cf74a22b..00d8c880 100644 --- a/openjdk/sun/font/SunFontManager.java +++ b/openjdk/sun/font/SunFontManager.java @@ -165,11 +165,30 @@ public class SunFontManager implements FontManager { return handle; } CompositeFont compFont = new CompositeFont(physicalFont, dialog2D); - Font2DHandle newHandle = new Font2DHandle(compFont); + Font2DHandle newHandle = compFont.handle; return newHandle; } /* + * return String representation of style prepended with "." + * This is useful for performance to avoid unnecessary string operations. + */ + private static String dotStyleStr(int num) { + switch(num){ + case Font.BOLD: + return ".bold"; + case Font.ITALIC: + return ".italic"; + case Font.ITALIC | Font.BOLD: + return ".bolditalic"; + default: + return ".plain"; + } + } + + private ConcurrentHashMap<String, Font2D> fontNameCache = + new ConcurrentHashMap<String, Font2D>(); + /* * The client supplies a name and a style. * The name could be a family name, or a full name. * A font may exist with the specified style, or it may @@ -177,7 +196,16 @@ public class SunFontManager implements FontManager { * may be able to emulate the required style. */ public Font2D findFont2D(String name, int style, int fallback) { - throw new NotYetImplementedError(); + String lowerCaseName = name.toLowerCase(Locale.ENGLISH); + String mapName = lowerCaseName + dotStyleStr(style); + Font2D font2D = fontNameCache.get(mapName); + + if(font2D != null){ + return font2D; + } + font2D = new PhysicalFont(name,style); + fontNameCache.put(mapName, font2D); + return font2D; } /* |