Documentation
¶
Overview ¶
CJK demonstrates PDF generation with Chinese, Japanese, and Korean text.
It exercises CJK-aware line breaking: ideographs, kana, and hangul characters break at character boundaries, while kinsoku shori rules keep opening punctuation grouped with the following character and closing punctuation grouped with the preceding character. Font embedding uses CIDFont Type0 with Identity-H encoding and ToUnicode mapping for copy/paste, so extracted text round-trips cleanly.
Required fonts (the example exits with a message if none resolve). SC-specific variants come first because the example body is in Simplified Chinese; pan-CJK collections (NotoSansCJK-Regular.ttc, msgothic.ttc) are accepted as fallbacks but their default face is JP and the rendered glyphs lean Japanese:
macOS /Library/Fonts/Arial Unicode.ttf
/System/Library/Fonts/STHeiti Light.ttc
/System/Library/Fonts/Hiragino Sans GB.ttc
/System/Library/Fonts/PingFang.ttc
Linux /usr/share/fonts/opentype/noto/NotoSansSC-Regular.otf (SC-specific)
/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc (SC-specific)
/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc (pan-CJK fallback)
Windows C:\Windows\Fonts\simsun.ttc (SC-native)
C:\Windows\Fonts\msyh.ttc (SC-native)
C:\Windows\Fonts\msgothic.ttc (JP fallback)
Programmatic callers who load a TTC directly (without going through @font-face url()) can pick a non-default face by language using font.ParseFontForLanguage("zh-CN", data) instead of font.ParseFont(data); see the font package documentation.
Usage:
go run ./examples/cjk