-
Bug
-
Resolution: Fixed
-
P3
-
7u13, 7u40, 8, 9
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8227001 | 8u221 | Philip Race | P3 | Resolved | Fixed | master |
JDK-8226211 | 8u212 | Philip Race | P3 | Closed | Fixed | b34 |
JDK-8229682 | emb-8u231 | Philip Race | P3 | Resolved | Fixed | b01 |
ADDITIONAL SYSTEM INFORMATION :
Windows 10 + JRE 1.8.0.144. Reproducible on latest Java 10 as well.
Red Hat 6.8 + JRE 1.8.0.144 is also affected.
A DESCRIPTION OF THE PROBLEM :
We are using custom made fonts and most of the time TTF version of fonts do not render some glyphs with Java, no matter what version. I can provide a font file on demand, and also screenshots of incorrect images with rendered text. Glyphs are inside font file indeed, well rendered used other software like MS Word. What is interesting that rendered image retain boundaries of missed glyph but no actual symbol graphics is rendered. GlyphVector of particular missed font keystroke is empty.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the provided code snippet, obtaining font file on request preliminary.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Image with text contains all glyphs in provided char sequence.
ACTUAL -
Generated image with text won't contain some glyphs.
---------- BEGIN SOURCE ----------
import java.awt.Color;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.Graphics2D;
import java.awt.font.TextAttribute;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import javax.imageio.ImageIO;
public class MissedGlyphs {
private static final int FONT_SIZE = 50;
public static void main(String[] args) throws IOException {
BufferedImage result = new BufferedImage(1500,500,BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = result.createGraphics();
File initialFile = new File(new File("C:\\"), "font.ttf");
InputStream targetStream = new FileInputStream(initialFile);
Font font = null;
try {
Font sourceFont = Font.createFont(Font.TRUETYPE_FONT, targetStream);
Map<TextAttribute, Object> attributes = (Map<TextAttribute, Object>) sourceFont.getAttributes();
attributes.put(TextAttribute.SIZE, FONT_SIZE);
font = sourceFont.deriveFont(attributes);
graphics.setFont(font);
} catch (FontFormatException e) {
e.printStackTrace();
}
graphics.setColor(Color.WHITE);
graphics.drawString("ABCDEF", 10, 100);
graphics.drawString("GHIJK", 10, 200);
graphics.dispose();
ImageIO.write(result,"BMP",new File(new File("C:\\"), "MISSING_GLYPH.BMP"));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Sometimes using OTF version of the same font fixes issue, but only on Linux OS. In addition, OpenJDK renders everything without any issues, but actual image view is a bit different than Oracle JDK provides.
FREQUENCY : always
Windows 10 + JRE 1.8.0.144. Reproducible on latest Java 10 as well.
Red Hat 6.8 + JRE 1.8.0.144 is also affected.
A DESCRIPTION OF THE PROBLEM :
We are using custom made fonts and most of the time TTF version of fonts do not render some glyphs with Java, no matter what version. I can provide a font file on demand, and also screenshots of incorrect images with rendered text. Glyphs are inside font file indeed, well rendered used other software like MS Word. What is interesting that rendered image retain boundaries of missed glyph but no actual symbol graphics is rendered. GlyphVector of particular missed font keystroke is empty.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the provided code snippet, obtaining font file on request preliminary.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Image with text contains all glyphs in provided char sequence.
ACTUAL -
Generated image with text won't contain some glyphs.
---------- BEGIN SOURCE ----------
import java.awt.Color;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.Graphics2D;
import java.awt.font.TextAttribute;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import javax.imageio.ImageIO;
public class MissedGlyphs {
private static final int FONT_SIZE = 50;
public static void main(String[] args) throws IOException {
BufferedImage result = new BufferedImage(1500,500,BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = result.createGraphics();
File initialFile = new File(new File("C:\\"), "font.ttf");
InputStream targetStream = new FileInputStream(initialFile);
Font font = null;
try {
Font sourceFont = Font.createFont(Font.TRUETYPE_FONT, targetStream);
Map<TextAttribute, Object> attributes = (Map<TextAttribute, Object>) sourceFont.getAttributes();
attributes.put(TextAttribute.SIZE, FONT_SIZE);
font = sourceFont.deriveFont(attributes);
graphics.setFont(font);
} catch (FontFormatException e) {
e.printStackTrace();
}
graphics.setColor(Color.WHITE);
graphics.drawString("ABCDEF", 10, 100);
graphics.drawString("GHIJK", 10, 200);
graphics.dispose();
ImageIO.write(result,"BMP",new File(new File("C:\\"), "MISSING_GLYPH.BMP"));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Sometimes using OTF version of the same font fixes issue, but only on Linux OS. In addition, OpenJDK renders everything without any issues, but actual image view is a bit different than Oracle JDK provides.
FREQUENCY : always
- backported by
-
JDK-8227001 Missing glyphs from custom made font when rendering on Graphics2D
- Resolved
-
JDK-8229682 Missing glyphs from custom made font when rendering on Graphics2D
- Resolved
-
JDK-8226211 Missing glyphs from custom made font when rendering on Graphics2D
- Closed