Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8208666

Missing glyphs from custom made font when rendering on Graphics2D

    XMLWordPrintable

Details

    • 2d
    • b01
    • x86_64
    • windows_10

    Backports

      Description

        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


        Attachments

          1. Test.zip
            16 kB
          2. MISSING_GLYPH_8u181.BMP
            MISSING_GLYPH_8u181.BMP
            2.15 MB
          3. MISSING_GLYPH_7u25.BMP
            MISSING_GLYPH_7u25.BMP
            2.15 MB

          Issue Links

            Activity

              People

                prr Philip Race
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: