Adding custom fonts

Issue #67 resolved
Former user created an issue

Is there a way to add a font file so that we can configure schemdraw with a custom font ? If not, what are the supported fonts ? Thank you!

Comments (6)

  1. cdelker repo owner

    You can set the font on a single label:

    d += elm.Resistor().label('1K', font='Arial')
    

    or as the default for an entire drawing:

    d.config(font='Arial')
    

    The font can be a named font installed on the system, or a family like “serif” or “sans-serif”. The font parameter is a pass-through to Matplotlib’s fontfamily, so check there for more on what fonts are available.

    I’ll keep this issue here since this needs to be better defined in the documentation.

  2. Harsha Pamidipalli

    This is great. However, is there a way to specify font using a .ttf file ? Basically point schemdraw to a .ttf file and then use it in the above mentioned manner ? Thank you

  3. cdelker repo owner

    Here’s what I just figured out.. Matplotlib’s font_manager needs to cache the font first:

    from matplotlib import font_manager
    
    fpath = '/path/to/Peralta-Regular.ttf'
    font_manager.fontManager.addfont(fpath)
    

    Then, it will be found by font name just as if it was installed in the system fonts path:

    with schemdraw.Drawing() as d:
        d.config(font='Peralta')
    

    It would be neat if Schemdraw could do this for you when the font parameter is a ttf and not in the cache already.

  4. cdelker repo owner

    7945134 will make this automatic, just set font=”path/to/font.ttf”. Works with Matplotlib backend, and SVG backend when Ziamath is installed.

  5. Log in to comment