Bug 91829 - Glyph size/appearance errors
Summary: Glyph size/appearance errors
Status: RESOLVED WORKSFORME
Alias: None
Product: freetype
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: All Linux (All)
: medium normal
Assignee: Werner Lemberg
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-08-31 20:23 UTC by Jethro Beekman
Modified: 2016-07-04 18:47 UTC (History)
3 users (show)

See Also:
i915 platform:
i915 features:


Attachments
Compile with gcc -I/usr/include/freetype2 -I/usr/include/cairo cairo_xlib_simple.c -lcairo -lX11 -lfreetype (3.45 KB, text/plain)
2015-08-31 20:23 UTC, Jethro Beekman
Details
Font file that exhibits the rendering error (1.52 KB, application/x-font-ttf)
2015-08-31 20:24 UTC, Jethro Beekman
Details
Incorrect render #1 (25.22 KB, image/png)
2015-08-31 20:25 UTC, Jethro Beekman
Details
Incorrect render #2 (21.99 KB, image/png)
2015-08-31 20:29 UTC, Jethro Beekman
Details
Correct render #1 (16.45 KB, image/png)
2015-08-31 20:30 UTC, Jethro Beekman
Details
Correct render #2 (18.41 KB, image/png)
2015-08-31 20:37 UTC, Jethro Beekman
Details
updated cairo-based test case (3.73 KB, text/plain)
2015-09-01 12:17 UTC, Behdad Esfahbod
Details

Description Jethro Beekman 2015-08-31 20:23:33 UTC
Created attachment 118021 [details]
Compile with gcc -I/usr/include/freetype2 -I/usr/include/cairo cairo_xlib_simple.c  -lcairo -lX11 -lfreetype

Certain fonts/sizes get rendered incorrectly on certain distributions of Linux. This mostly happens when rendering PDFs that were generated using LaTeX in a browser using pdf.js.

I have extracted and attached the font from a PDF file with a rendering error (as converted to OpenType using pdf.js). I have attached a small test program that demonstrates the error using that font.

Distributions that seem to be affected:
* Most versions of Ubuntu/Debian
* Arch Linux with infinality-patched freetype/fontconfig/cairo

This seems to be a long-standing bug across many versions of various software.
Firefox bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=1200077
pdf.js bug report: https://github.com/mozilla/pdf.js/issues/2594

In the next few comments I will attach screenshots of renderings including version information.
Comment 1 Jethro Beekman 2015-08-31 20:24:11 UTC
Created attachment 118022 [details]
Font file that exhibits the rendering error
Comment 2 Jethro Beekman 2015-08-31 20:25:52 UTC
Created attachment 118023 [details]
Incorrect render #1

Example of an incorrect rendering.

Ubuntu 14.04
Cairo version 1.13.0~20140204-0ubuntu1.1
Freetype version 2.5.2-1ubuntu2.4
Comment 3 Jethro Beekman 2015-08-31 20:29:17 UTC
Created attachment 118024 [details]
Incorrect render #2

Example of an incorrect rendering. This screenshot was taken with the X server on Ubuntu 14.04 and client on Red Hat 5.11, X forwarding over SSH.

Red Hat 5.11
Freetype 2.2.1-32.el5_9.1
Cairo 1.2.4-5.el5
Comment 4 Jethro Beekman 2015-08-31 20:30:02 UTC
Created attachment 118025 [details]
Correct render #1

This is an example of a correct rendering. This screenshot was taken over NX.

Red Hat 5.11
Freetype 2.2.1-32.el5_9.1
Cairo 1.2.4-5.el5
Comment 5 Jethro Beekman 2015-08-31 20:31:50 UTC
I should mention the bug remains on Ubuntu when tested with vanilla Freetype 2.6 and Cairo 1.14.2.
Comment 6 Jethro Beekman 2015-08-31 20:37:14 UTC
Created attachment 118026 [details]
Correct render #2

Example of a correct rendering. This was created using the Image surface.

Ubuntu 14.04
Cairo version 1.13.0~20140204-0ubuntu1.1
Freetype version 2.5.2-1ubuntu2.4
Comment 7 Jethro Beekman 2015-08-31 20:40:04 UTC
Clarification on the attachements:

Attachment #118021 [details] is named cairo_xlib_simple.c
Attachment #118022 [details] is an OTF file named cmex10.otf
Attachment #118025 [details] is a PNG file
Comment 8 Behdad Esfahbod 2015-09-01 11:34:56 UTC
Test case crashes for me.   Will take a look later.
Comment 9 Behdad Esfahbod 2015-09-01 11:37:05 UTC
Ok, doesn't crash anymore, but all I see is a black window.
Comment 10 Behdad Esfahbod 2015-09-01 11:38:35 UTC
Ok I can reproduce after adding cairo_surface_flush().
Comment 11 Behdad Esfahbod 2015-09-01 12:16:38 UTC
This is a FreeType autohinter issue.  The font in question has a root-sign at letter 's'.  Bug only exists if hinting-mode=slight is chosen.  That invokes autohinter in vertical direction only.  If you try other hinting modes (NONE, MEDIUM, FULL) bug doesn't appear.
Comment 12 Behdad Esfahbod 2015-09-01 12:17:18 UTC
Can be reproduced using ftview.  Press 'f' to force autohinting on, then arrow-key up/down and see how the shape jumps drastically at some point sizes...
Comment 13 Behdad Esfahbod 2015-09-01 12:17:52 UTC
Created attachment 118032 [details]
updated cairo-based test case
Comment 14 Werner Lemberg 2015-09-01 13:07:09 UTC
It's a font *and* PDF engine bug.

The font contains a cmap that maps position `r' (not `s', BTW) to a glyph called `.notdef'.  Since the auto-hinter accesses a font not by glyph names but by a Unicode mapping (either a real one or a synthesized), it believes that glyph `r' is present, which accidentally is one of the glyphs used for deriving blue zones of the latin script.  This fact makes the auto-hinter proceed, which fails miserably.

Two important rules.

(1) Font cmaps must not lie to the auto-hinter!

(2) In general, don't use the auto-hinter for rendering sub-setted fonts!  As this example shows, such fonts are often buggy since the character to glyph mappings are extremely simplified, making it impossible for the auto-hinter to derive sensible global glyph information.
Comment 15 Behdad Esfahbod 2015-09-01 13:24:34 UTC
I believe the problem is that the TeX math fonts use non-Unicode mappings.  That's the part about being a font bug.

However, even then, autohinter should NOT do crazy stuff like this.  The 'r' could be from a cursive handwritten font with huge extents...
Comment 16 Werner Lemberg 2015-09-01 13:36:44 UTC
> However, even then, autohinter should NOT do crazy stuff like this.
> The 'r' could be from a cursive handwritten font with huge extents...

The auto-hinter normally doesn't rely on a single character to derive blue-zones!  In practice, such extreme behaviour can only be seen for incorrect cmaps and not enough sample glyphs to derive the global data, so your argument doesn't hold IMHO.

I might modify the auto-hinter to reject hinting if there is just a single glyph.  However, the font here in question is simply buggy, and in most cases the cmap *is* valid.  By the way, any font that has an incorrect cmap gets rendered badly with the auto-hinter, regardless of the number of available glyphs...
Comment 17 Werner Lemberg 2015-09-01 13:39:49 UTC
On the other hand, I agree it would be a nice project to limit vertical movements done by the auto-hinter.  Please open a `wishlist' bug report!
Comment 18 Jethro Beekman 2015-09-01 17:09:55 UTC
I don't know much about fonts. Are you sure there is an issue with the PDF as well? It might just be an issue with Type 1 -> OpenType conversion. I attached the PDF-embedded Type 1 font to the Firefox bug. I don't know how adapt the testcase to render that (using that in FT_New_Face results in nothing being drawn).
Comment 19 Behdad Esfahbod 2015-09-01 17:13:45 UTC
Oh it's probably pdf.js's fault partially as well, perhaps the bogus cmap is comping from pdf.js, not from the original font.  Someone needs to verify.
Comment 20 Werner Lemberg 2015-09-01 22:12:41 UTC
The original file `cmex10.pfb' (version 003.002) as delivered with TeXLive has a correct encoding vector, using glyph name `radicalbigg' at position 0x72.  The subsetted `CMEX10.pfb' file in the FireFox bug report also has the correct glyph name.
Comment 21 Werner Lemberg 2015-10-13 09:03:14 UTC
(In reply to Werner Lemberg from comment #17)
> On the other hand, I agree it would be a nice project to limit vertical
> movements done by the auto-hinter.  Please open a `wishlist' bug report!

I did this just now.

https://savannah.nongnu.org/bugs/index.php?46195
Comment 22 Werner Lemberg 2015-11-08 07:41:44 UTC
This should now be fixed in FreeType's git repository, please test.

http://git.savannah.gnu.org/cgit/freetype/freetype2.git/commit/?id=be32b168ac42e670e1a8c5c614cce4c3f8232829
Comment 23 Jethro Beekman 2015-11-08 19:09:30 UTC
Works, thanks! Unfortunately, my distro's FreeType is too old (2.5) to easily backport the patch (y_offset is not defined).


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.