Search code examples
pdffontsjuce

Using CIDFont on pdf generation


all

I'm programing a pdf generation library for a new language not so popular. I have finished some functions, include text output, and image embed, But it support standard 14 fonts only.

I'm adding big character set support to it now, it means I must use other fonts except standard 14 fonts. In my opinion, utf-8 encoded characters can be recognized by pdf correctly, and through a CIDFont CMap, it can find the glyph of the character and paint it.

I looked up some documents about this, and found the best way is embeding the fonts into the pdf document, include the standard 14 fonts.

Because big character set is a very large set, So I think I can use CharSet and CIDSet to parse a subset of it.

The language I used have wrapped JUCE as it's kernel and I can use it to manipulated the font. So I think I can get the font's glyph normally.

But as a cross-platform (desk os and mobile os), JUCE doesn't support more information of the font, for example leading, stemV, ItalicAngle, cap height, etc. even I don't known the type of the font (Type1, TrueType, OpenType or others). So I don't known whether it can be used for pdf generation?

If can't, then I must parse an external type1(ccf?) or ttf(ttc) font file manually? then I embed the big staff (about 2MB )into pdf?

If can, then How to do it? How can I use character glyphs to generate an embed font stream? And use a custom CMap to find them?

Another problem is what encoding I should used? I use utf-8 as string encoding, and I don't known whether it can be used for CIDFont.

The code is located at: a pdf library for 8th.

Thanks.


Solution

  • You will undoubtably need to parse the font yourself, or find a module to do it. Examples of module that doe this in node include fontkit, ttfjs, and opentype. There are far too many details to give a complete answer here, but you should be able to derive an answer from those modules.