2

Does anyone have any pointers where I can find extra information on how to create an opentype wrapper around a CFF font?

Currently I have a parser for CFF files so I can get all sorts of information out of it (cmap, glyph names, widths, names etc etc). Given this information I am unable to create an Opentype (truetype format like) wrapper so I can use the font on Windows using GDI; GDI will not load the Opentype font and the only thing I know is that it fails to load the font.

Does anyone know any additional information, validation applications, example code, get additional information why the font does not load from Windows etc etc?

Note: I am looking for information how to do it, not utilities and/or conversion tools.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ritsaert Hornstra
  • 5,013
  • 1
  • 33
  • 51
  • I've got to ask, where did you find a CFF font file? I've never seen one, and a search came up empty. There's OpenType/CFF but those already have the wrapper. – Mark Ransom Jan 19 '12 at 03:57
  • @Mark: look into PDF files, there usually subsets are embedded. TYou find them also within OTF fonts (naturally). At the moment I am trying to render PDF files to GDI device contexts (screen/printer) and also need to render some CFF embedded fonts. hence the question. The documentation given in the OpenType file format description from Microsoft are not very clear on how to build this wrapper (it's a format record structure description, not a how to). – Ritsaert Hornstra Jan 20 '12 at 08:35
  • The short following question: OpenType font files have CFF table inside. I can simply extract it by the offset address and size in the dictionary table. In PDF file, font resource objects, /FontFile3 stream contents deflated CFF font file. Are that the same CFFs or not? Actually, when I see on the binary, I can see some differences, like FontName in the file is Font-Name, but in the PDF it is FHDH+Font-Name etc. PDF excerpt is shorter, which means for me it is the part of whole CFF of font file. Can I include the whole CFF part of the font file in resource stream of PDF file? – Ruben Kazumov Aug 04 '12 at 18:28
  • @user1543083: There are several changes that can be made to the CFF font file. First: it is the same font file but names are different (due to PDF standard) Subsetting (only leaving the used glyphs) makes the file smaller and is also common practice. – Ritsaert Hornstra Aug 07 '12 at 21:33
  • OK, finally I have got the CFF table of an OTF font. Can you help me to find in which index/dict/place/offset/section etc. I have to digg to find a some *GLYPH WIDTH* parameter value (not average glyph width, not min/max glyph width, just a glyph width of some glyph)? I am trying to find some information about subject in "ISO/IEC STANDARD 14496-22 Open Font Format" and "The Compact Font Format Specification Version 1.0", but nothing found. – Ruben Kazumov Aug 15 '12 at 07:02
  • I know it has been a while, but references to this type of problem are so scarce... I am precisely trying to do exactly the same thing, wrap a PostScript Type 1 font in an OTF, and trying to come up with my own code. *NOT* looking for utilities. – Mitch Match Mar 10 '16 at 12:43

4 Answers4

2

Until now, I found three libraries you could reference:

  1. FreeType: mainly in the cff package. Its main entry is cff\cffload.c. The library is now on GitHub.
  2. FontForge: fontforge\parsettf.c, still on sf.net.
  3. fonttools: fonttools\cffLib.py, on GitHub.
  4. ots tools: cff.cc on Google Code

In parsettf.c, George Williams wrote that "TrueType is a really icky format." ...Now that I understand it better it seems better designed, but the docs remain inconsistent. Sometimes badly so.

IMO, the cff spec is just as bad. Maybe it is better designed. I might eventually look into it to confirm, but it might just be too old to be good.

What old things are good? Parents, math and philosophy :) Anything else must be up-to-date!

Martin
  • 381
  • 4
  • 17
qinxian
  • 367
  • 3
  • 6
  • Thank you for the links. Other peoples source code is probably the best source of information for the CFF file format. Because I expect no other sources of further information this is the best answer up to now. – Ritsaert Hornstra May 15 '12 at 19:46
  • update a new link. IMO, It's hard if just by the so-called opentype spec document. Because I'm doing a render work now, and the spec document and design really strange, at least not best, f.e. the CharString bytecode. – qinxian May 16 '12 at 07:36
  • Sorry for my quick, @Ritsaert. I browse follows, and knonw I focus something wrong. Because all in my head is just the cff (thing:). GDIPP should help. and AGG have samples in demo pages: [link](http://www.antigrain.com/demo/freetype_test.zip) and a LCD demo: [link](http://www.antigrain.com/research/font_rasterization/index.html#toc0014). Agg source freetype and window font wrapper maybe help. But I wonder when windows load otf fails? I use eclipse which text editor just seems call windows#Xoutline function. I do editing only with otf files:) – qinxian May 16 '12 at 07:55
  • Last year(2012/4) I tried the CFF font processing, found the source code about CFF in java, it's wrong. And not used at all. And seems new version FreeType native wrapper return some error data, it's differ from the result reading by AGG. – qinxian Mar 26 '13 at 09:20
  • this is an older post, but I'd like to point out that CFF to TTF is a lossy conversion, and that windows GDI supports opentype-with-cff-block just fine, so a conversion isn't needed when you have a CFF block, you just need to form a valid OpenType wrapper for it. https://pomax.github.io/CFF-glyphlet-fonts touches on (but only the source code really describes) how this wrapper vs. CFF block works. – Mike 'Pomax' Kamermans Jul 25 '14 at 20:28
1

CFF(Compact Font Format) is mainly used for embedded PostScript font in PDF files. And you can also find CFF in OpenType font files which is based on PostScript outlines.

If you got CFF from the embedded font file of a PDF, you can get a PostScript name from the NameIndex of the CFF. You should find the corresponding OpenType File by the PostScript Name.

If you got CFF from a OpenType file, why did you ask this question? :-D

0

I quote this link: Raster, Vector, TrueType, and OpenType Fonts

... the glyphs for a font are stored in a font-resource file. ...

So, Windows loads glyphs from a file with a format that it understands, not a CFF file, and not a structure from memory. If you want to draw CFF files without using a file conversion tool, I think you will need to load the CFF and draw the glyphs by yourself.

To load the CFF and determine the glyph, you can use the FreeType Project. Here is a link here on SO that explain how to build a Win32 DLL from FreeType source: Compiling FreeType to DLL (as opposed to static library)

To draw the glyphs, you can get some inspiration from the gdipp project, which is a replacement of the Windows text renderer, and contains Win32 C/C++ sample code that display glyphs loaded from FreeType.

Community
  • 1
  • 1
Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
  • gdipp is intersting. Will look into that. What I am really after is having a simple CFF -> OTF routine so I can pickup a CFF file, parse it (thats what I have already), construct the other sfnt tables needed for the OTF file; construct it from the loose tables (have that already btw) and load the font as a memory resource. I rather use this route so when the font drawn to a GDI EMF surface I end up with text outs and not bitmap drawing. Naturally this route is the second option if I cannot succeed. – Ritsaert Hornstra Jan 11 '12 at 21:52
0

It appears that the CFF format was made to be embedded directly into an OpenType file. Microsoft has a good overview of OpenType files: http://www.microsoft.com/typography/otspec/otff.htm

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
  • This is exactly what I am after but there are other tables that must be filled: cmap, head, maxp etc (according to the same documenation). Question is: what needs to be filled in this wrapper for Windows GDI to swallow this font; Freetype2 for example works with half filled in fonts just fine but not Windows. And the only error you get is... does not work. – Ritsaert Hornstra Jan 11 '12 at 21:48
  • I award you the bounty because you refer to the spec; although it did not really answered my question it was closest. Thank you for your time. – Ritsaert Hornstra Jan 18 '12 at 14:33