[Poppler-bugs] [Bug 81748] FreeText annotation ignores font

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Tue Aug 7 07:40:17 UTC 2018


https://bugs.freedesktop.org/show_bug.cgi?id=81748

--- Comment #16 from Tobias Deiminger <haxtibal at posteo.de> ---
(In reply to Dileep Sankhla from comment #14)
> This patch is generated as per my experiment in Poppler and is a workaround
> for the Base 14/standard fonts.

Thanks Dileep. The patch has several problems, but it's good you sent it, it
helps narrowing down a solution.

> It gets rid of the "Invalid_font" tags and
> generates meaningful font tags.

Tags have to be unique in the AcroForm->DR->Font dictionary. Your patch can't
ensure this, because you did no lookup to DR. There might already be a "/DejSe"
tag existing, coming from another PDF tool for another font. We must not
overwrite that tag.

Your patch may even collide with its own tags, because for example
QFont("Liberation Mono,12,-1,5,50,0,0,0,0,0,Regular") and QFont("Liberation
Mono,12,-1,5,75,1,0,0,0,0,Bold Italic") both become "LiberMo", but they're
different fonts.

We often see PDF docs where font tags are counted like this, F1, F2, F3,... or
R1, R2, R3... I believe that's a reasonable scheme. No need to make the tag
sound like the name, but just use the next free number to make it unique.

> Secondly, the font name as per the Base 14
> font names is exactly generated from the QFont and the font name is set in
> the font dictionary inside createAnnotDrawFont.

No, your generated names are neither Base14 nor PostScript names, but quite
arbitrary. Your new method createFontTagandName() generates font names and tags
from QFonts with results like this:
QFont("DejaVu Serif,12,-1,5,50,0,0,0,0,0,Book") => Tag="DejSe",
Name="DejaVu-Book"
QFont("FreeSans,12,-1,5,63,0,0,0,0,0,Bold") => Tag="Free", Name="FreeSans-Bold"
QFont("Liberation Mono,12,-1,5,50,0,0,0,0,0,Regular") => Tag="LiberMo",
Name="Liberation"
QFont("Liberation Mono,12,-1,5,75,1,0,0,0,0,Bold Italic") => Tag="LiberMo",
Name="Liberation-BoldItalic"

That generated names really don't refer to Base14 fonts. In the standard,
there's a list of exactly 14 Type1 base fonts:
[Times-Roman, Helvetica, Courier, Symbol, Times-Bold, Helvetica-Bold,
Courier-Bold, ZapfDingbats, Times-Italic, Helvetica-Oblique, Courier-Oblique,
Times-BoldItalic, Helvetica-BoldOblique, Courier-BoldOblique]
That's it. None of DejaVu-Book, FreeSans-Bold, Liberation,
Liberation-BoldItalic is listed here, so they're not Base14 fonts.

The names are also not PostScript names. You can check for PostScript name like

$ fc-scan --format "%{postscriptname}\n"
/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf 
DejaVuSerif

So the PostScript name for QFont("DejaVu Serif,12,-1,5,50,0,0,0,0,0,Book")
would have been "DejaVuSerif", not "DejaVu-Book".

We can use non-Base14 fonts, it's just harder to set them up. It's important to
use the real PostScript name then, and to provide encoding and a font
descriptor. And, for platform independence, non-Base14 font programs should be
embedded into the PDF. Embedding is optional: If font is not embedded, a reader
will do font substitution with available system fonts by available metrics.

I think we should start by querying fontconfig in poppler to get font type and
PostScript name, and then write it to SubType and BaseName. In a second step,
we should try to get the encoding right and to setup a font descriptor. I guess
most readers have heuristics to cope without a font descriptor, but standard
says it's required. If we managed that too, we can finally research for font
embedding.

> The default is set to
> "Helvetica". What this patch can do is when the Okular program is in the
> memory, you can try different base-14 fonts for the typewriter annotation
> but if you save the PDF doc and then quit it, the fonts will be set to
> "Helvetica".

I've not looked into that yet. Eventually we should generate a DA that's the
same in memory and on disk.

> Imho this experimental patch can be extended and modified to write the font
> dictionary for the base 14 fonts in the document and to generate freetext
> appearance based on the DA and DR entries and the font dict. The second
> follows the embedded fonts.

Yes, both needs to be done.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/poppler-bugs/attachments/20180807/0ea5d7bd/attachment-0001.html>


More information about the Poppler-bugs mailing list