bugThe FreeType Project - Bugs: bug #46195, Prevent auto-hinter from...

 
 

bug #46195: Prevent auto-hinter from distorting glyphs too much

Submitted by:  Werner LEMBERG <wl>
Submitted on:  Tue 13 Oct 2015 09:02:11 AM UTC  
 
Severity: 3 - NormalItem Group: Wishlist
Status: FixedPrivacy: Public
Assigned to: Werner LEMBERG <wl>Open/Closed: Closed
Planned Release: 2.6.2

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission Jump to the original submission)

Sun 08 Nov 2015 07:39:50 AM UTC, comment #8:

Excellent, thanks! Now committed to the git.

Werner LEMBERG <wl>
Project AdministratorIn charge of this item.
Sat 07 Nov 2015 06:20:22 PM UTC, comment #7:

Ok, I tried to implement something that uses rather the ascenders and descenders of the blue zones with the em size as fallback.

(file #35408)

Philipp Knechtges <knechtges>
Fri 06 Nov 2015 05:48:04 AM UTC, comment #6:

This patch looks better, thanks!

However, I think using the value `yMax - yMin' is problematic, since this might include glyphs not used for writing a script but covering a font's generic symbols of arbitrary size. We probably need a more advanced test...

What about this: If we have (reasonable) blue zones for ascenders and descenders of the given script, take the maxima, then compare. Otherwise use the EM size for comparison.

And please enclose the `else' part into `#ifdef FT_DEBUG_LEVEL_TRACE ... #endif' to avoid clang warnings.

Werner LEMBERG <wl>
Project AdministratorIn charge of this item.
Thu 05 Nov 2015 10:26:45 PM UTC, comment #5:

Here is my second attempt. Using a pixel-based criteria of course shifts the check to a later (and more frequently executed) point in the hinting process, but I guess that a certain trade-off between accuracy and performance has to be made.

(file #35395)

Philipp Knechtges <knechtges>
Tue 03 Nov 2015 04:42:03 PM UTC, comment #4:

What I want is simple: Don't check the ascender and descender values of the x-height blue zone. Instead, check whether the resulting scaling value yields a global glyph size that differs to the original global glyph size by more than two pixels.

Does this sound reasonable?

Werner LEMBERG <wl>
Project AdministratorIn charge of this item.
Mon 02 Nov 2015 08:48:46 PM UTC, comment #3:

In principle, I like the idea to limit the changes to two pixels, and in fact this is what I also initially wanted to implement :). But the autohinter seems to work a bit different than I expected.

My understanding is that there are two classes of blue zones:
- Those that are flagged with AF_BLUE_PROPERTY_LATIN_X_HEIGHT, like "xzroesc" in standard latin.
- And the rest.

For both, blue zones are detected in af_latin_metrics_init_blues, oblivious of a specific scaling to device units.

Then af_latin_metrics_scale_dim uses the first class of characters, with the AF_BLUE_PROPERTY_LATIN_X_HEIGHT property, to scale the whole character class, such that the upper end of, e.g., "xzroesc" snap to the grid. The central assumption here in the code is that the corresponding glyphs of these characters do not have a substantial extent beneath the baseline. This is where the math fonts fail, since there the baseline is close to the upper end of the glyph, such that the code always tries to snap this small part to the grid, which results in the large scaling factor.

In a last step the hints are applied, including also the remaining blue zones. Without having looked at this code in detail, it seems that the code is quite aware of the surrounding grid and probably respects the required two pixel property.

In any case, these two steps are superpositional and if there would be a bug in both, they probably would need to be fixed separately. The submitted patch is a first attempt to fix the scaling issue in the first part. Nonetheless, there might still be a smarter fix, which may also work for other character classes than latin, but I probably lack the necessary knowledge about the code :) If you have any idea for a better criteria than comparing the extent above and below the baseline, I'm open for suggestions.

Philipp Knechtges <knechtges>
Mon 02 Nov 2015 06:08:33 AM UTC, comment #2:

Thanks for the patch, but this is not what I had in mind, since it only solves a special case. What I want is ignoring all results that change the glyph height or depth by more than a given threshold, which is around 2.0 pixels (or even less). Ideally, the auto-hinter should recognize such problems as early as possible, e.g., by ignoring blue zones that would lead to such large distortions, or applying a too large or too small x-height scaling.

Can you work on that?

Werner LEMBERG <wl>
Project AdministratorIn charge of this item.
Sun 01 Nov 2015 11:10:06 PM UTC, comment #1:

Resulting from my investigations of a similar issue with poppler (https://bugs.freedesktop.org/show_bug.cgi?id=91772), I come to the conclusion that mostly the scaling of small letters (xzroesc) is the issue. The code basically assume that the characters have some substantial extent above the baseline, which is just not the case for several math fonts. I have attached a patch that adds a simple sanity check.

(file #35361)

Philipp Knechtges <knechtges>
Tue 13 Oct 2015 09:02:11 AM UTC, original submission:

In case of invalid or buggy fonts, prevent the auto-hinter from distorting the glyphs too much, cf.

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

`Invalid' here means cheating to the auto-hinter, e.g., mapping character `A' to glyph `udieresis', or having not enough characters to derive reliable blue zones.

Werner LEMBERG <wl>
Project AdministratorIn charge of this item.

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by knechtges (Updated the item)
  • -unavailable- added by wl (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 6 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sun 08 Nov 2015 07:39:50 AM UTCwlStatusConfirmed=>Fixed
      Open/ClosedOpen=>Closed
      Planned ReleaseNone=>2.6.2
    Sat 07 Nov 2015 06:20:22 PM UTCknechtgesAttached File-=>Added 0001-autofit-limit-x-height-blue-zone-scaling-to-at-most-.patch, #35408
    Thu 05 Nov 2015 10:26:45 PM UTCknechtgesAttached File-=>Added 0001-autofit-limit-x-height-blue-zone-scaling-to-at-most-.patch, #35395
    Sun 01 Nov 2015 11:10:05 PM UTCknechtgesAttached File-=>Added 0001-autofit-add-sanity-check-to-prevent-scaling-issues-w.patch, #35361

    Back to the top


    Powered by Savane 3.1-cleanup1