-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Embedding exotic fonts into PDF #6
Comments
I'm a little unclear on the issue as it seems there may be three separate issued that have been conflated here. First off, there is no such font family as "Dialog"; it is what is known as a "logical font" that gets mapped to a real font internally. Generally it is assigned to the system's default Sans Serif font. AWT decided to protect programmers against common issues with missing fonts; especially if they write on one platform and don't or can't test on other OS's. The available standard PDF font families in OrsonPDF are: Helvetica, Times, and Courier. You have probably also seen that the DefaultFontMapper class maps some other common font families to these four. "DialogInput" is mapped to Times, and Dialog is mapped to Helvetica. Anything not found in this list goes to Courier, as you noted. You could either do your own implementation of the FontMapper interface, or even extend DefaultFontMapper just to add some other mappings and/or make the "mapToBaseFont()" function more sophisticated or switch its default. The findOrCreateFontReference() in the Pages class seems to be the main gateway to adding and mapping fonts for a current PDF Document, but I don't see it invoked internally in the OrsonPDF library, so I guess it's something you'd add in your own code before you start writing content to the PDGGraphics2D instance. The Pages constructor initially assigns to the Default Font Mapper, and I'm not seeing any direct access to the stored fonts or the cached font map, or a way to switch the Font Mapper in use, so I think the only way currently to build a font dictionary is to invoke findOrCreateFontReference() on your Pages object, repeatedly for the font families you expect will show up during the PDFGraphics2D rendering. My impression is that otherwise, you simply have an available Default Font Mapper that isn't getting used and just a default font map vs. an expanded font dictionary. So this might be why the Dialog logical font isn't getting mapped properly. Once I have an Eclipse Maven project set up for this library (I'm looking at individual files in a text editor at the moment), I may find that there are ways to override the default mappings. Certainly the API design supports it, but I'm simply not seeing available function calls to hook it into an actual PDF output workflow. |
It's a limitation of OrsonPDF that it doesn't support font embedding / subsetting, it just maps fonts to the standard PDF fonts, or gives the option to render fonts as vectors (results in larger output but any font supported in Java2D can be rendered). The original goal of the library was to support export of charts (JFreeChart and Orson Charts) to PDF, so for that purpose rendering fonts as vectors is generally acceptable. It would be great to extend the font support though - I just never had the time/expertise required to do it. |
For as long as I remain unemployed, I do have the time, and a good baseline for the required expertise. I need to wrap up my EPS library first, and my core graphics and gui libraries, and also have a few minor tweaks to post for jFreeSVG and OrsonPDF, but I've just finished two hours of deep diving into the architecture of OrsonPDF and am familiar enough with different approaches to PDF generation that I think I have a good idea about how to embed and/or subset fonts in OrsonPDF. I may even have time this week to give this a go. Just as a reminder, which revision of PDF are we aiming for? I think 1.4 is the support level for OsronPDF; the spec may be beyond 1.7 by now but that was the most recent one that I found for download last week. My recollection is that application support for more recent versions of PDF can be iffy and that it may not be wise to be TOO current as it may limit what end users can do with the resulting documents. |
Being able to embed fonts and use those fonts' supported Unicode characters would be wonderful. The only downside I've encountered with OrsonPDF is having to render glyphs to vectors. If you need older versions of the PDF spec, they're available here |
The 1.4 spec is the one I used previously, but I'm not familiar yet with differences in the later editions. I don't mind to move to a later version. |
Hello,
I have an issue with fonts. Generally I use Dialog font but also some system fonts that are not default Java fonts but this library seems to support only default fonts (12 of 14 in fact). Exotic fonts are replaced by Courier, that is not good for me.
There is a way to embed them automatically ?
In code, The Pages.findOrCreateFontReference() method and its call to FontMApper.mapToBaseFont() seems to be the origin of font selection but I don't know how PDF format works.
Best regards,
The text was updated successfully, but these errors were encountered: