diff options
author | smallsql <smallsql> | 2011-07-17 21:45:55 +0400 |
---|---|---|
committer | smallsql <smallsql> | 2011-07-17 21:45:55 +0400 |
commit | 9ad9befcb629e7f99391eb1b6734bf6a1b64ea45 (patch) | |
tree | 22470ec5947f574be6b9fdbf05a404fb6ab18297 /openjdk/sun | |
parent | b64ac018a5cafcb7560f8644fea9443c2db6609f (diff) |
findFont2D must return a CompositeFont for font "dialog" in Java 7.
Diffstat (limited to 'openjdk/sun')
-rw-r--r-- | openjdk/sun/font/CompositeFont.java | 111 | ||||
-rw-r--r-- | openjdk/sun/font/SunFontManager.java | 76 |
2 files changed, 166 insertions, 21 deletions
diff --git a/openjdk/sun/font/CompositeFont.java b/openjdk/sun/font/CompositeFont.java index 466a25cd..232c4387 100644 --- a/openjdk/sun/font/CompositeFont.java +++ b/openjdk/sun/font/CompositeFont.java @@ -23,6 +23,10 @@ */ package sun.font; +import java.awt.font.FontRenderContext; +import java.awt.geom.AffineTransform; +import java.util.Locale; + import cli.System.Drawing.Font; import ikvm.internal.NotYetImplementedError; @@ -31,23 +35,20 @@ import ikvm.internal.NotYetImplementedError; * */ public class CompositeFont extends Font2D{ + + private final Font2D delegate; + public CompositeFont(PhysicalFont physicalFont, CompositeFont dialog2d) { - throw new NotYetImplementedError(); + delegate = physicalFont; } - @Override - public int getStyle(){ - throw new NotYetImplementedError(); - } - - @Override - public Font createNetFont(java.awt.Font font){ - throw new NotYetImplementedError(); - } + public CompositeFont(Font2D font2d){ + delegate = font2d; + } public int getNumSlots() { - throw new NotYetImplementedError(); + throw new NotYetImplementedError(); } public PhysicalFont getSlotFont(int slot) { @@ -57,4 +58,92 @@ public class CompositeFont extends Font2D{ public boolean isStdComposite() { throw new NotYetImplementedError(); } + + @Override + public int getStyle(){ + return delegate.getStyle(); + } + + @Override + public Font createNetFont(java.awt.Font font){ + return delegate.createNetFont(font); + } + + public FontStrike getStrike(java.awt.Font font, AffineTransform devTx, + int aa, int fm) { + return delegate.getStrike(font, devTx, aa, fm); + } + + public FontStrike getStrike(java.awt.Font font, FontRenderContext frc) { + return delegate.getStrike(font, frc); + } + + public void removeFromCache(FontStrikeDesc desc) { + delegate.removeFromCache(desc); + } + + public void getFontMetrics(java.awt.Font font, AffineTransform identityTx, + Object antiAliasingHint, Object fractionalMetricsHint, + float[] metrics) { + delegate.getFontMetrics(font, identityTx, antiAliasingHint, + fractionalMetricsHint, metrics); + } + + public void getStyleMetrics(float pointSize, float[] metrics, int offset) { + delegate.getStyleMetrics(pointSize, metrics, offset); + } + + public void getFontMetrics(java.awt.Font font, FontRenderContext frc, + float[] metrics) { + delegate.getFontMetrics(font, frc, metrics); + } + + public boolean useAAForPtSize(int ptsize) { + return delegate.useAAForPtSize(ptsize); + } + + public boolean hasSupplementaryChars() { + return delegate.hasSupplementaryChars(); + } + + public String getPostscriptName() { + return delegate.getPostscriptName(); + } + + public String getFontName(Locale l) { + return delegate.getFontName(l); + } + + public String getFamilyName(Locale l) { + return delegate.getFamilyName(l); + } + + public int getNumGlyphs() { + return delegate.getNumGlyphs(); + } + + public int charToGlyph(int wchar) { + return delegate.charToGlyph(wchar); + } + + public int getMissingGlyphCode() { + return delegate.getMissingGlyphCode(); + } + + public boolean canDisplay(char c) { + return delegate.canDisplay(c); + } + + public boolean canDisplay(int cp) { + return delegate.canDisplay(cp); + } + + public byte getBaselineFor(char c) { + return delegate.getBaselineFor(c); + } + + public float getItalicAngle(java.awt.Font font, AffineTransform at, + Object aaHint, Object fmHint) { + return delegate.getItalicAngle(font, at, aaHint, fmHint); + } } diff --git a/openjdk/sun/font/SunFontManager.java b/openjdk/sun/font/SunFontManager.java index 00d8c880..131784a8 100644 --- a/openjdk/sun/font/SunFontManager.java +++ b/openjdk/sun/font/SunFontManager.java @@ -49,10 +49,11 @@ import java.util.Vector; import java.util.concurrent.ConcurrentHashMap; import javax.swing.plaf.FontUIResource; - +import sun.awt.AppContext; import sun.awt.FontConfiguration; - -import cli.System.Drawing.FontFamily; +import sun.awt.SunToolkit; +import sun.java2d.FontSupport; +import sun.util.logging.PlatformLogger; /** * The base implementation of the {@link FontManager} interface. It implements @@ -198,14 +199,69 @@ public class SunFontManager implements FontManager { public Font2D findFont2D(String name, int style, int fallback) { String lowerCaseName = name.toLowerCase(Locale.ENGLISH); String mapName = lowerCaseName + dotStyleStr(style); - Font2D font2D = fontNameCache.get(mapName); + Font2D font; + + /* If preferLocaleFonts() or preferProportionalFonts() has been + * called we may be using an alternate set of composite fonts in this + * app context. The presence of a pre-built name map indicates whether + * this is so, and gives access to the alternate composite for the + * name. + */ + if (_usingPerAppContextComposites) { + ConcurrentHashMap<String, Font2D> altNameCache = + (ConcurrentHashMap<String, Font2D>) + AppContext.getAppContext().get(CompositeFont.class); + if (altNameCache != null) { + font = (Font2D)altNameCache.get(mapName); + } else { + font = null; + } + } else { + font = fontNameCache.get(mapName); + } + if (font != null) { + return font; + } + + if (FontUtilities.isLogging()) { + FontUtilities.getLogger().info("Search for font: " + name); + } + + // The check below is just so that the bitmap fonts being set by + // AWT and Swing thru the desktop properties do not trigger the + // the load fonts case. The two bitmap fonts are now mapped to + // appropriate equivalents for serif and sansserif. + // Note that the cost of this comparison is only for the first + // call until the map is filled. + if (FontUtilities.isWindows) { + if (lowerCaseName.equals("ms sans serif")) { + name = "sansserif"; + } else if (lowerCaseName.equals("ms serif")) { + name = "serif"; + } + } + + /* This isn't intended to support a client passing in the + * string default, but if a client passes in null for the name + * the java.awt.Font class internally substitutes this name. + * So we need to recognise it here to prevent a loadFonts + * on the unrecognised name. The only potential problem with + * this is it would hide any real font called "default"! + * But that seems like a potential problem we can ignore for now. + */ + if (lowerCaseName.equals("default")) { + lowerCaseName = name = "dialog"; + } - if(font2D != null){ - return font2D; + font = new PhysicalFont(name,style); + + switch (lowerCaseName){ + case "dialog": + font = new CompositeFont(font); //dialog must a CompositeFont, else there are ClassCastExceptions + break; } - font2D = new PhysicalFont(name,style); - fontNameCache.put(mapName, font2D); - return font2D; + fontNameCache.put(mapName, font); + return font; } /* @@ -381,7 +437,7 @@ public class SunFontManager implements FontManager { * the style * @return a Font2D */ - public static Font2D createFont2D( FontFamily family, int style ) { + public static Font2D createFont2D( cli.System.Drawing.FontFamily family, int style ) { return new PhysicalFont( family, style ); } } |