1

For PDF font embedding purposes, I have been tasked with removing glyph outline data for unused glyphs from a CFF OpenType file to reduce its size.

The problem is that unlike TTF, CFF "compresses" into subroutines its glyph outline data and creates dependencies between glyphs and I can't just remove the glyph and its matching char from cmap and outline data.

Since there are several open source CFF libraries like otfcc that can subroutinize a CFF file, I was wondering if there are libraries that can do the opposite and undo subroutinizing.

UPDATE: The library I'm using are otfcc and sfntly. Sfntly doesn't have a CFF parser so I'm extending one, otfcc do have one, but doesn't seem to have a subset option, the source looks more promising though. I also looked at freetype, and whilst it does have CFF loader, doesn't seem to have a subsetter.

I'm currently halfway done porting fontbox for pdfbox from Apache to sfntly. The parser works, but subsetter is still incomplete.

jochen
  • 3,728
  • 2
  • 39
  • 49
legokangpalla
  • 495
  • 5
  • 20
  • Please remove the `c++` tag. –  Feb 28 '17 at 07:13
  • This is a weird thing to do: your tool chain should already be able to do this, so in the interest of not running into an [XY Problem](https://meta.stackexchange.com/a/66378): can you provide more details on how which tools you're already using for going from "source" to "final pdf"? Because depending on the tools used in that chain, it's almost certain there's already a utility or even just runtime flag that achieves this for you. – Mike 'Pomax' Kamermans Apr 02 '17 at 21:25
  • @Mike'Pomax'Kamermans Our application doesn't have a CFF support yet, it just has a TTF subsetter that seems to have been developed in-house with fontbox Apache as a reference. ie) Does not support CFF at all, only thing it can do with a CFF OTF is to embed it in pdf, without subsetting it. – legokangpalla Apr 03 '17 at 00:44
  • It kind of sounds like you're reinventing the wheel, given that things like font forge, fonttools, and the adobe FDK are already free...Just use those for your subsetting. Heck, run the font through TTX with charstring unrolling, prune the glyphs you don't need, run it back through TTX to pack it back up, and then use adobe's own subroutine optimizer if you have to optimize further. Done, with no effort on your part. Some for TTF really, TTX -> remove glyphs -> TTX and you're done, whoever developed your tool literally wasted time on it =/ – Mike 'Pomax' Kamermans Apr 03 '17 at 04:49
  • @Mike'Pomax'Kamermans yeah kind of, but the requirement is that I need to include the feature in our application without adding to distributed files, so I need to port it to C++ and integrate to the project. FontTools actually support CFF subsetting option so you can get the subsetted OTF without needing to convert it to TTX format, but I need to port it anyway. – legokangpalla Apr 03 '17 at 05:11
  • I know, I meant more that all three tools are options here. If you *need* to roll your own (which rather odd - if you already use open source libraries like sfntly then adding TTX to your tool is kind of the far superior option to rolling your own solution) then all I can really say is "good luck". You should have a look at Harfbuzz, Freetype, and maybe even OTS, to see whether any of those help get you most of the way there, but that has turned this question into a "recommend a tool" question, which is off topic for Stackoverflow. – Mike 'Pomax' Kamermans Apr 03 '17 at 15:47

1 Answers1

3

In the end I ended up using AFDKO, I didn't realize it was open source! It have everything from subsetting CFF to using it to make otf font.

legokangpalla
  • 495
  • 5
  • 20