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

OpenTypeFont with CFF is not being rendered using T2KFontScaler

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 7u79
    • Fix Version/s: None
    • Component/s: client-libs
    • Subcomponent:
      2d
    • CPU:
      x86_64
    • OS:
      linux_ubuntu

      Description

      FULL PRODUCT VERSION :


      ADDITIONAL OS VERSION INFORMATION :
      Linux 3.13.0-49-generic #83-Ubuntu SMP Fri Apr 10 20:11:33 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      T2KFontScaler is unable to render glyphs using the OTF fonts located in the following Zip files:

      https://noto-website.storage.googleapis.com/pkgs/NotoSansCJKJP-hinted.zip

      Either nothing or a Tofu is drawn in the image. The same code to render these glyphs would work if a font file is available in TTF format (not using Compact Font Format) with Oracle JDK

      The above scenario works well with all kind of Font files (OTF as well as TTF)
      with Open JDK using "FreetypeFontScaler".

      The problem seems to lie with different implementations in "libfontmanager.so" shipped with the JDKs

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      (1) Application: Convert an SVG Image to PNG Image using batik or alternatively try rendering "幅" to an image using Graphics2D and GlyphVector.

      Here is a sample svg file that can be used. Save the following content into sample.svg:
      ------------------------------------------------------------------------------------------
      <?xml version="1.0" encoding="utf-8"?>
      <svg height="50" width="50" xmlns="http://www.w3.org/2000/svg">
      <rect fill="#000000" height="50" width="50"/>
      <svg height="50" width="50">
      <g fill="#FFFFFF" font-family="Noto Sans JP" font-size="45">
      <g transform="translate(0,45)">
      <g>
      <text x="0">幅</text>
      </g>
      </g>
      </g>
      </svg>
      </svg>
      ------------------------------------------------------------------------------------------

      (3) Very Important: On a system where alternative fonts exist for the desired unicode (here: 幅), the application would work fine picking these alternate fonts. To reproduce the problem, I would recommend using a server distribution of Ubuntu which comes with minimal fonts installed.

      Alternatively, developer should make sure that the right Fonts are being loaded to reproduce the problem.

      I am including the code where application registers these fonts into the GraphicsEnvironment which should be picked for rendering. On Oracle JDK these are not being picked correctly. Rendering however might be fine, if system has an alternate CJK font.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The PNG file generated would contain a rectangular tofu structure and not the expected glyph.
      ACTUAL -
      Expecting the glyph "幅" to be present in the PNG image

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      No Crash is observed

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import org.apache.batik.transcoder.TranscoderInput;
      import org.apache.batik.transcoder.TranscoderOutput;
      import org.apache.batik.transcoder.image.PNGTranscoder;

      import java.awt.*;
      import java.io.File;
      import java.io.FileOutputStream;
      import java.io.IOException;
      import java.io.OutputStream;
      import java.nio.file.Paths;

      public class SvgToPng {

          public static void main(String args[])
              throws Exception {

              String fontFilePath = "/path/to/NotoSansCJKjp-Regular.otf";
              String svgFilePath = "/path/to/sample.svg";
              String pngFilePath = "/path/to/sample.png";

              registerFonts(fontFilePath);
              convertSvgToPng(svgFilePath, pngFilePath);
          }

          private static void registerFonts(String fontFilePath) {

              try {
                  Font font = Font.createFont(Font.TRUETYPE_FONT, new File(fontFilePath));
                  GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
                  e.registerFont(font);
              } catch (IOException eio) {
                  System.out.println("Error registering fonts: " + eio);
              } catch (FontFormatException eff) {
                  System.out.println("Font format exception: " + eff);
              }
          }

          private static void convertSvgToPng(String svgFilePath, String pngFilePath)
              throws Exception {

              String svg_URI_input = Paths.get(svgFilePath).toUri().toURL().toString();
              TranscoderInput input_svg_image = new TranscoderInput(svg_URI_input);

              OutputStream png_ostream = new FileOutputStream(pngFilePath);
              TranscoderOutput output_png_image = new TranscoderOutput(png_ostream);
              PNGTranscoder my_converter = new PNGTranscoder();
              my_converter.transcode(input_svg_image, output_png_image);

              png_ostream.flush();
              png_ostream.close();
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Using Open JDK to resolve the issue

        Attachments

          Activity

            People

            Assignee:
            alexp Alexander Potochkin (Inactive)
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: