diff -r 354decadfe6c javafx-font/src/com/sun/javafx/font/directwrite/DWFontFile.java --- a/javafx-font/src/com/sun/javafx/font/directwrite/DWFontFile.java Tue Jun 25 09:52:01 2013 -0700 +++ b/javafx-font/src/com/sun/javafx/font/directwrite/DWFontFile.java Tue Jun 25 16:57:04 2013 -0700 @@ -43,29 +43,53 @@ super(name, filename, fIndex, register, embedded, copy, tracked); fontFace = createFontFace(); + if (PrismFontFactory.debugFonts) { + if (fontFace == null) { + System.err.println("Failed to create IDWriteFontFace for " + this); + } + } + if (!isRegistered()) { disposer = new DWDisposer(fontFace); Disposer.addRecord(this, disposer); } } + private IDWriteFontFace createEmbeddedFontFace() { + IDWriteFactory factory = DWFactory.getDWriteFactory(); + IDWriteFontFile fontFile = factory.CreateFontFileReference(getFileName()); + boolean[] isSupportedFontType = new boolean[1]; + int[] fontFileType = new int[1]; + int[] fontFaceType = new int[1]; + int[] numberOfFaces = new int[1]; + int hr = fontFile.Analyze(isSupportedFontType, fontFileType, fontFaceType, numberOfFaces); + IDWriteFontFace face = null; + if (hr == OS.S_OK && isSupportedFontType[0]) { + int faceIndex = getFontIndex(); + int simulation = OS.DWRITE_FONT_SIMULATIONS_NONE; + face = factory.CreateFontFace(fontFaceType[0], 1, fontFile, faceIndex, simulation); + } + fontFile.Release(); + return face; + } + private IDWriteFontFace createFontFace() { if (isEmbeddedFont()) { - /* Note: The font path has already been verified at this point. */ - IDWriteFactory factory = DWFactory.getDWriteFactory(); - IDWriteFontFile fontFile = factory.CreateFontFileReference(getFileName()); - boolean[] isSupportedFontType = new boolean[1]; - int[] fontFileType = new int[1]; - int[] fontFaceType = new int[1]; - int[] numberOfFaces = new int[1]; - fontFile.Analyze(isSupportedFontType, fontFileType, fontFaceType, numberOfFaces); - IDWriteFontFace face = factory.CreateFontFace(fontFaceType[0], 1, fontFile, 0, OS.DWRITE_FONT_SIMULATIONS_NONE); - fontFile.Release(); - return face; + return createEmbeddedFontFace(); } + IDWriteFontCollection collection = DWFactory.getFontCollection(); int index = collection.FindFamilyName(getFamilyName()); - if (index == -1) return null; + if (index == -1) { + /* This can happen when the family name reported by GDI does not + * match family name in DirectWrite. For example, GDI reports + * 'Arial Black' as family name while DirectWrite represents the + * same font using family equals to 'Arial' and style equals to + * DWRITE_FONT_WEIGHT_BLACK. The fix to try to create the font + * using the font file. + */ + return createEmbeddedFontFace(); + } IDWriteFontFamily family = collection.GetFontFamily(index); int weight = isBold() ? OS.DWRITE_FONT_WEIGHT_BOLD :