4-Byte Unicode Not Supported in FOP

Q

How to use FOP to support all Unicode characters including 4-byte Unicode characters?

✍: FYIcenter.com

A

If you want to use FOP to support all Unicode characters, you can follow this tutorial:

1. Download a font file that can support all Unicode characters from https://ftp.gnu.org/gnu/unifont/unifont.

2. Selete the latest version in TTF format: unifont-10.0.07.ttf.

3. Build the font definition file:

\local\fop-2.2\fop>java -cp %FOP_PATH%\build\fop.jar;
   %FOP_PATH%\lib\xercesImpl-2.9.1.jar;
   %FOP_PATH%\lib\xalan-2.7.2.jar;
   %FOP_PATH%\lib\avalon-framework-4.3.1.jar;
   %FOP_PATH%\lib\commons-logging-1.0.4.jar;
   %FOP_PATH%\lib\commons-io-1.3.1.jar;
   %FOP_PATH%\lib\serializer-2.7.2.jar;
   %FOP_PATH%\lib\xmlgraphics-commons-2.2.jar 
   org.apache.fop.fonts.apps.TTFReader 
   -d \fyicenter\unifont-10.0.07.ttf \fyicenter\Unicode.xml

4. Create a FOP configuration file,

<?xml version="1.0"?>
<!-- cfg-unicode.xml
     Copyright (c) 2018 FYIcenter.com
-->
<fop version="1.0">
  <renderers>
    <renderer mime="application/pdf">
      <fonts>
        <font metrics-url="\fyicenter\Unicode.xml" kerning="yes" 
          embed-url="\fyicenter\unifont-10.0.07.ttf">
          <font-triplet name="Unicode" style="normal" weight="normal"/>
          <font-triplet name="Unicode" style="normal" weight="bold"/>
          <font-triplet name="Unicode" style="italic" weight="normal"/>
        </font>
      </fonts>
    </renderer>
  </renderers>
</fop>

5. Create a test FO file, unicode-test.fo:

<?xml version="1.0" encoding="utf-8"?>
<!-- unicode-test.fo
     Copyright (c) 2018 FYIcenter.com
-->
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="myPage">
      <fo:region-body margin="1in"/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="myPage">
    <fo:flow flow-name="xsl-region-body" font-family="Unicode">
      <fo:block>1-Byte Unicode &amp;#x41;: &#x41;&#x42;&#x43;</fo:block>
      <fo:block>2-Byte Unicode &amp;#x0278;: &#xFE18;&#xA015;</fo:block>
      <fo:block>4-Byte Unicode &amp;#x1F60B;: &#x1F60B;</fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>

6. Run FOP to generate the PDF output:

>\local\fop-2.2\fop\fop -c \fyicenter\cfg-unicode.xml 
   \fyicenter\unicode-test.fo \fyicenter\unicode-test.pdf

WARNING: Glyph "?" (0xd83d) not available in font "UnifontMedium".
WARNING: Glyph "?" (0xde0b) not available in font "UnifontMedium".
INFO: Rendered page #1.

The two warning messages are actually caused by a single issue. FOP does not support the 4-byte Unicode characters U+1F60B. It first converted the U+1F60B into two characters 0xd83d and 0xde0b, then declared that those two characters are not supported by the Unicode font.

Open the PDF file with Acrobat Reader, you see that 1-byte and 2-byte Unicode characters are generated correctly. But the 4-byte Unicode character is not:
4-Byte Unicode Not Supported in FOP

 

Download and Installing of FOP 2.x

Use Unicode Characters with FOP

Managing Fonts in FOP PDF Output

⇑⇑ FAQ for FOP (Formatting Object Processor)

2018-03-17, 1458🔥, 0💬