Search code examples
pdflib

pdflib - Is there a way to tell if a font supports Chinese


When I used Arial Black to write text, I found it didn't work in Chinese, so I wondered if there was a way to determine whether a font would support Chinese or not


Solution

  • A general note about fonts:

    not all font contains all glyphs. So it's expected that you can not use a single font for the whole Unicode range. You should first find the font that meets your visual requirements and contains the glyphs. Many font families have several specifications for the different Unicode ranges. You should first find the font that meets your visual requirements and contains the glyphs. Many font families have several variants for the different Unicode ranges. It is best to contact your font vendor to get the right font file. Or you can use free but very complete font families, such as Noto.

    Of course you can check the glyph availability in a font with PDFlib. This is demonstrated in the PDFlib cookbook topic glyph availability:

    gid = (int) p.info_font(font, "glyphid", "unicode=" + t.character);
    

    Based on this, you can determine if a font contains the glyphs you need. Please see also the PDFlib 9.3.0 Tutorial, chapter 6.6.2 "Font-specific Encoding, Unicode, and Glyph Name Queries" for details.

    Also related to your question, you might check the technique of fallback fonts for chaining multiple fonts to get a larger set of glyphs. Please see PDFlib 9.3.0 Tutorial, chapter 6.4.6 "Fallback Fonts", as well the included starter sample starter_fallback, which is also available in the PDFlib cookbook.

    I have try 'int error_font = p.load_font("Arial Black","", "replacementchar=error");

    as soon an exception occurs, you can not longer use the PDFlib Object. Please see PDFlib 9.3.0 Tutorial, chapter 3.1.1 "Exception Handling" for details on this important topic. You find the PDFlib 9.3.0 Tutorial within all PDFlib Download package within the "doc" directory, as well on the PDFlib 9.3 Download page as separate link.