Generic Font for Chinese Characters

This section provides a tutorial example on using XSL-FO generic font for Chinese characters. Apache FOP AWT output works. But PDF output failed, because the mapped font Helvetica does not support Chinese characters.

In previous tutorials, we learned that XSL-FO supports generic font families to allow XSL processors to map them to specific font families. We also learned that not all font families can support all characters in all languages.

In this tutorial, let's if XSL processors are smart to map generic fonts to appropriate specific fonts.

Here is my tutorial example, Generic-Font-for-Chinese-Characters.fo, that uses generic font "sans-serif" for some Chinese characters:

<?xml version="1.0" encoding="utf-8"?>
<!-- Generic-Font-for-Chinese-Characters.fo
 - Copyright (c) 2016, HerongYang.com, All Rights Reserved.
-->
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
 <fo:layout-master-set>
  <fo:simple-page-master master-name="page" 
   margin="0.1in" page-height="4.4in" page-width="3.4in">
   <fo:region-body region-name="body"/>
  </fo:simple-page-master>
 </fo:layout-master-set>
 <fo:page-sequence master-reference="page">
  <fo:flow flow-name="body" font-size="10pt">
<fo:block margin-top="6pt">English letters:
 <fo:inline background-color="#ffddff" 
  font-family="sans-serif" font-weight="bold">
The tangram is a dissection puzzle consisting of seven flat shapes, 
called tans, which are put together to form shapes.
 </fo:inline>
</fo:block>
<fo:block margin-top="6pt">Chinese characters:
 <fo:inline background-color="#ffddff" 
  font-family="sans-serif" font-weight="bold">
七巧板是一種智力游戏,顧名思義,七巧板是由七塊板組成的。由於等積變換,
所以這七塊板可拼成許多圖形(千種以上)。  
 </fo:inline>
</fo:block>
  </fo:flow>
 </fo:page-sequence>
</fo:root>

If you process this example XSL-FO document with Apache FOP tool on AWT screen, you will see Chinese characters are nicely formatted:

Generic Font for Chinese - FOP AWT Output

But if you process this example XSL-FO document with Apache FOP tool to generate a PDF file, you will get warnings:

C:\herong>\fop\fop -fo Generic-Font-for-Chinese-Characters.fo
   -pdf Generic-Font-for-Chinese-Characters_fop.pdf
   
... org.apache.fop.events.LoggingEventListener processEvent
WARNING: Glyph "?" (0x4e03) not available in font "Helvetica-Bold".
WARNING: Glyph "?" (0x5de7) not available in font "Helvetica-Bold".
WARNING: Glyph "?" (0x677f) not available in font "Helvetica-Bold".
...

And here is how the PDF page look like:

Generic Font for Chinese - FOP PDF Output

Conclusions:

Last update: 2016.

Table of Contents

 About This XSL-FO Tutorial Book

 Introduction of XSL-FO

 Apache™ FOP (Formatting Objects Processor)

 RenderX XEP as an XSL-FO Tool

 Introduction of Area Model

 XSL-FO Document Basics and Examples

 Page Layout Masters

 Block-Level Formatting Objects

 Inline-Level Formatting Objects

 Including Graphics in XSL-FO document

 Table of Rows and Columns

 List, Item, Label, and Body

 Floating Blocks - "float" and "footnote"

 Hyperlinks, Table of Contents and Indexes

 Headers and Footers using "static-content"

Font Attributes and Font Families

 What Is a Font?

 Font Attributes and Generic Fonts

 Adobe PDF Base-14 Fonts

Generic Font for Chinese Characters

 Apache FOP Font Configurations

 RenderX XEP Font Configurations

 References

 PDF Printing Version