Bug 692943 - Allow the use of system fonts with custom callbacks.
Summary: Allow the use of system fonts with custom callbacks.
Status: RESOLVED FIXED
Alias: None
Product: MuPDF
Classification: Unclassified
Component: mupdf (show other bugs)
Version: unspecified
Hardware: PC Linux
: P4 normal
Assignee: MuPDF bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-22 18:52 UTC by Ronni Egeriis Persson
Modified: 2014-04-17 08:20 UTC (History)
5 users (show)

See Also:
Customer:
Word Size: ---


Attachments
PNG output from pdfdraw (164.50 KB, image/png)
2012-03-22 18:52 UTC, Ronni Egeriis Persson
Details
PDF input to pdfdraw (118.09 KB, application/pdf)
2012-03-22 18:52 UTC, Ronni Egeriis Persson
Details
test2.pdf (30.30 KB, application/pdf)
2012-04-05 11:55 UTC, Robin Watts
Details
acrobat without arial.ttf (19.95 KB, image/png)
2012-04-20 12:02 UTC, Tor Andersson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ronni Egeriis Persson 2012-03-22 18:52:05 UTC
Created attachment 8443 [details]
PNG output from pdfdraw

Please find attached PDF and PNG. This is the only case in which I've experience this issue, however it is a bit odd case.

To replicate the bug, convert PDF to PNG with the following command. I've also tried updating to the latest commit to your master branch in git.
Comment 1 Ronni Egeriis Persson 2012-03-22 18:52:33 UTC
Created attachment 8444 [details]
PDF input to pdfdraw
Comment 2 Ronni Egeriis Persson 2012-03-22 18:54:27 UTC
Forgot the command:

mupdfdraw -o %d.png -r 144 doc.pdf
Comment 3 Robin Watts 2012-04-05 11:55:53 UTC
Created attachment 8503 [details]
test2.pdf

Simplified file, showing a single char that mupdf gets wrong, but gs and acrobat get right.
Comment 4 Chris Liddell (chrisl) 2012-04-05 17:12:45 UTC
The problem is the job uses the non-embedded CIDFont Arial,Bold which, being a "well known name", MuPDF is substituting ("through" Helvetica) with the NimbusSanL-Bold font.

Using a font as a substitute for a CIDFont doesn't work (in Ghostscript it would produce an error).

If I nobble the CIDFont loading so it uses DroidSansFallback (instead of NimbusSanL-Bold) as the substitute in the cut down job, I get the correct glyph out.

So, I think mupdf's CIDFont loading needs to be revised so it doesn't do the "well known name" lookup (and only does it for fonts).
Comment 5 Chris Liddell (chrisl) 2012-04-05 17:14:32 UTC
Oh, and to OP:

This type of problem is *exactly* why the PDF *strongly* recommends always embedding CIDFonts - if the font were embedded, the job would work fine.
Comment 6 Tor Andersson 2012-04-19 08:58:13 UTC
(In reply to comment #4)
> If I nobble the CIDFont loading so it uses DroidSansFallback (instead of
> NimbusSanL-Bold) as the substitute in the cut down job, I get the correct glyph
> out.
> 
> So, I think mupdf's CIDFont loading needs to be revised so it doesn't do the
> "well known name" lookup (and only does it for fonts).

I tried the same, and we only get the correct glyphs out for the 7-bit ascii characters.
All extended latin characters are still wrong. Ghostscript shows the same problem.
The issue is that we don't have arial.ttf and the file is constructed to use direct
glyph indexing (an Identity-H encoding).

If a font uses the Identity-H encoding it MUST be embedded for it to work portably.
Comment 7 Ronni Egeriis Persson 2012-04-20 09:11:49 UTC
If Adobe Reader, Preview and other software can interpret the file correctly, so should MuPDF be able to. This is rather critical for my usage of this software. Is it really impossible to do some kind of workaround to make the document readable at least?
Comment 8 Tor Andersson 2012-04-20 12:02:42 UTC
Created attachment 8536 [details]
acrobat without arial.ttf

See attachment for how Acrobat renders the file when arial.ttf is not available. It also fails miserably.

We don't have a license to ship arial.ttf; and for portability reasons we don't use system fonts in MuPDF.
Comment 9 Ronni Egeriis Persson 2012-04-20 12:14:23 UTC
I see! Could it be a workaround to have arial.ttf available in the system or is there any other failsafe way of working around this issue?
Comment 10 zeniko 2012-04-22 10:26:29 UTC
Ronni: In case you're compiling for Windows, one work-around would be to use the MuPDF from http://code.google.com/p/sumatrapdf/source/browse/trunk#trunk%2Fmupdf which is able to load arial.ttf from the system's Fonts directory.
Comment 11 Tor Andersson 2012-05-01 09:39:56 UTC
TODO: Add hooks / callbacks to Fitz font context to allow system fonts to be loaded if clients provide a function for it.
Comment 12 Ronni Egeriis Persson 2012-05-01 10:50:03 UTC
I am compiling on Linux; Ubuntu 10.04LTS
Comment 13 ojab 2013-03-24 07:23:01 UTC
I have similar issue with file http://ojab.ru/mupdf.pdf (not attaching due to personal info in it) and mupdf from git (commit 8a11586f923bf202083e37a98f7f1140dc1a8cdb).

There is also many warnings in console like:
>warning: freetype load glyph (gid 621): invalid argument
>warning: ... repeated 2 times ...
>warning: cannot render glyph
>warning: freetype load glyph (gid 651): invalid argument
>warning: ... repeated 2 times ...
>warning: cannot render glyph

Is it the same bug or I should file another one?
Comment 14 Tor Andersson 2014-04-17 08:20:04 UTC
There is a function fz_install_load_system_font_funcs that you can use
to load system fonts via callbacks.