JDK-6609143 : wasn't able to create type 1 font under windows
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_2003
  • CPU: x86
  • Submitted: 2007-09-25
  • Updated: 2020-04-07
  • Resolved: 2020-04-07
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
jsdk 6.02

ADDITIONAL OS VERSION INFORMATION :
windows 2003

A DESCRIPTION OF THE PROBLEM :
use Font.createFont(int type, File fontFile) to create a type 1 Font.
it couldn't generate the glyph with the give font file.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run under windows

__________ source code ___________

Font javaFont=Font.createFont(Font.TYPE1_FONT,new File("cour.pfa"));
            javaFont=javaFont.deriveFont(Font.BOLD,20);
            BufferedImage bi=new BufferedImage(600, 400, BufferedImage.TYPE_INT_RGB);
            Graphics2D g2 = (Graphics2D) bi.getGraphics();
            g2.setColor(Color.WHITE);
            g2.setFont(javaFont);
            g2.drawString("test string", 100,100);
            ImageIO.write(bi, "png", new File("new.png"));

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
a PNG image with white text -- test string on it
ACTUAL -
a blank PNG image with nothing on it

ERROR MESSAGES/STACK TRACES THAT OCCUR :
no error message

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
__________ source code ___________

Font javaFont=Font.createFont(Font.TYPE1_FONT,new File("cour.pfa"));
            javaFont=javaFont.deriveFont(Font.BOLD,20);
            BufferedImage bi=new BufferedImage(600, 400, BufferedImage.TYPE_INT_RGB);
            Graphics2D g2 = (Graphics2D) bi.getGraphics();
            g2.setColor(Color.WHITE);
            g2.setFont(javaFont);
            g2.drawString("test string", 100,100);
            ImageIO.write(bi, "png", new File("new.png"));


the cour.pfa:


---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Couldn't find a workaround. it looks like the createFont is platform dependent.

currently, we have to try to convert Type 1 Font to true type and tolerate the information lost

Comments
No longer using t2k
07-04-2020

EVALUATION Looking more into this it seems we can not and should not replace font with backup font. However we have to deregister it. Exception in 7 was thrown because NullFontScaler reports 0 as number of glyphs available but it should return 1 to reserve space for missing glyph. Changes necessary to deregister font are: 1) trigger tsi_Assert if Type1 scaler was not created 2) invalidate scalers and throw exceptions from FontScaler constructors if native scaler was not constructed successfully (need to do this for both T2K and Freetype)
28-11-2007

EVALUATION T2K fails to process this particular font file because lines are terminated with \r\n instead of \n and it does not expect while trying to decode CMAP. This can be easily fixed. But this bug report also highlights 2 other issues: 1) being unable to parse CMAP font T2K should report on malformed font and it should gets replaced by fallback font. Because output image is blank this does not seem to happen and we need to investigate why. Perhaps Type1 error handling needs improvements. 2) Exception observed for JDK7 should not happen even if we detect problems in runtime. Perhaps this is something overlooked during OpenJDK-related code refactoring. I'll look into this further.
28-11-2007

EVALUATION Problem is reproducible with 6u1 but requires special version of cour.pfa file. Perhaps font is malformed or just special. Need further investigation. Note that with jdk7 b20 test fails with following exception: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at sun.font.FileFontStrike.setCachedGlyphPtr(FileFontStrike.java:374) at sun.font.FileFontStrike.setCachedGlyphPtr(FileFontStrike.java:425) at sun.font.FileFontStrike.getGlyphImagePtrs(FileFontStrike.java:305) at sun.font.GlyphList.mapChars(GlyphList.java:272) at sun.font.GlyphList.setFromString(GlyphList.java:244) at sun.java2d.pipe.GlyphListPipe.drawString(GlyphListPipe.java:71) at sun.java2d.pipe.ValidatePipe.drawString(ValidatePipe.java:165) at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2814) at CreateType1.main(CreateType1.java:17)
26-09-2007

EVALUATION Problem is not reproducible. Asked submitter for additional details.
26-09-2007