Skip to content

bug in font_manager.FontManager.score_family() #4607

Closed

Description

@chadawagner

If a font to be scored is found first in the font alias list, it currently results in a "perfect" score of 0.
For example:

font_manager.FontManager().score_family(['myfont','sans-serif'], 'bitstream vera sans')

will return 0, and 'myfont' will never be found if it happens to appear later in the list of known fonts.

Commit 314a0cf already attempted to address this issue, but didn't solve it in the case I'm running into.

Activity

  1. chadawagner commented on Jul 8, 2015

    @chadawagner
    ContributorAuthor

    The code for the returned score is currently

    ((0.1 * (idx / len(options))) * ((i + 1) / len(families)))
    

    and the issue I'm having occurs when idx is 0. The previous commit addressed the right multiplicand, changing i to i+1 so that it would never be 0, but the overall result is still 0 when the left side is 0.

  2. mdboom commented on Jul 9, 2015

    @mdboom
    Member

    Yeah -- I think changing to (idx + 1) makes sense here.

  3. added this to the milestone on Jul 10, 2015
  4. tacaswell commented on Jul 10, 2015

    @tacaswell
    Member

    @chadawagner Would you like to put in a PR to fix this?

  5. chadawagner commented on Jul 10, 2015

    @chadawagner
    ContributorAuthor

    I could make a PR, but I'm still not sure the right way to fix this scoring algorithm. I think it's broken in more ways than just changing to (idx + 1) would fix.

    For example, assume I have a font family list of ['font1', 'font2', 'sans-serif'], then any font that is part of the sans-serif alias will score at most 0.1, which is lower (better) than font2.

  6. chadawagner commented on Jul 11, 2015

    @chadawagner
    ContributorAuthor

    How about

    i / len(families) + idx / (len(options) * len(families))
    

    That way the returned score is always in the half-open interval [ i/len(families), (i+1)/len(families) )

  7. modified the milestones: , on Aug 14, 2015
  8. modified the milestones: , on Oct 26, 2015
  9. mdboom commented on Mar 21, 2016

    @mdboom
    Member

    Fixed by #4689

  10. modified the milestones: v1.5.0, on Mar 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions